on xenial help sign in
Fixed a race condition causing search history popup to show up when it shouldn't. Fixes: https://bugs.launchpad.net/bugs/1249369.

Approved by PS Jenkins bot, Albert Astals Cid.

commit677390ce6ac5719921e2f61a59e287249fe7f59e authorNick Dedekind <nicholas.dedekind@gmail.com> dateTue 19 Nov 2013, 03:05 (13 years ago) parentcf5942be0d193f
2 files changed+68−9
Components/PageHeader.qml+25−6 tests/qmltests/Components/tst_PageHeader.qml+43−3
Components/PageHeader.qml+25−6
@@ -44,8 +44,8 @@ Item {
4444 if (!searchHistory) return;
4545
4646 searchHistory.addQuery(searchField.text);
47+ unfocus();
4748 searchField.text = "";
48− searchField.focus = false;
4949 }
5050
5151 function unfocus() {
@@ -112,6 +112,8 @@ Item {
112112 objectName: "searchContainer"
113113
114114 visible: searchEntryEnabled
115+ property bool popoverShouldOpen: false
116+ property bool popoverShouldClose: false
115117
116118 property bool narrowMode: parent.width < label.contentWidth + units.gu(50)
117119
@@ -127,6 +129,16 @@ Item {
127129 else if (active && !narrowMode) "active"
128130 else if (!active && !narrowMode) "inactive"
129131
132+ onStateChanged: {
133+ if (state == "active" || state == "narrowActive") {
134+ popoverShouldOpen = true;
135+ popoverShouldClose = false;
136+ } else {
137+ popoverShouldOpen = false;
138+ popoverShouldClose = true;
139+ }
140+ }
141+
130142 function openPopover() {
131143 if (searchHistory.count > 0) {
132144 searchContainer.popover = PopupUtils.open(popoverComponent, searchField,
@@ -137,10 +149,17 @@ Item {
137149 }
138150 )
139151 }
152+ popoverShouldOpen = false;
153+ popoverShouldClose = false;
140154 }
141155
142156 function closePopover() {
143− if (searchContainer.popover) PopupUtils.close(searchContainer.popover)
157+ if (searchContainer.popover) {
158+ PopupUtils.close(searchContainer.popover);
159+ searchContainer.popover = null;
160+ }
161+ popoverShouldOpen = false;
162+ popoverShouldClose = false;
144163 }
145164
146165 onActiveFocusChanged: if (!activeFocus) { searchHistory.addQuery(searchField.text) }
@@ -283,12 +302,12 @@ Item {
283302 PropertyAction { target: primaryImage; property: "source" }
284303 AnchorAnimation { targets: [searchContainer, textContainer]; duration: 200; easing.type: Easing.InOutQuad }
285304 }
286− ScriptAction { script: searchContainer.openPopover() }
305+ ScriptAction { script: if (searchContainer.popoverShouldOpen) { searchContainer.openPopover(); } }
287306 }
288307 },
289308 Transition {
290309 to: "inactive"
291− ScriptAction { script: searchContainer.closePopover() }
310+ ScriptAction { script: if (searchContainer.popoverShouldClose) { searchContainer.closePopover(); } }
292311 NumberAnimation { targets: [searchContainer, searchField] ; property: "width"; duration: 200; easing.type: Easing.InOutQuad }
293312 AnchorAnimation { targets: [searchContainer, textContainer]; duration: 200; easing.type: Easing.InOutQuad }
294313 },
@@ -299,12 +318,12 @@ Item {
299318 NumberAnimation { targets: [searchContainer, searchField] ; property: "width"; duration: 200; easing.type: Easing.OutQuad }
300319 AnchorAnimation { targets: [searchContainer, textContainer]; duration: 200; easing.type: Easing.InOutQuad }
301320 }
302− ScriptAction { script: searchContainer.openPopover() }
321+ ScriptAction { script: if (searchContainer.popoverShouldOpen) { searchContainer.openPopover(); } }
303322 }
304323 },
305324 Transition {
306325 to: "narrowInactive"
307− ScriptAction { script: searchContainer.closePopover() }
326+ ScriptAction { script: if (searchContainer.popoverShouldClose) { searchContainer.closePopover(); } }
308327 NumberAnimation { targets: [searchContainer, searchField] ; property: "width"; duration: 200; easing.type: Easing.OutQuad }
309328 AnchorAnimation { targets: [searchContainer, textContainer]; duration: 200; easing.type: Easing.InOutQuad }
310329 }
tests/qmltests/Components/tst_PageHeader.qml+43−3
@@ -37,6 +37,10 @@ Item {
3737 property alias searchEnabled : pageHeader.searchEntryEnabled
3838 property alias searchQuery : pageHeader.searchQuery
3939
40+ function init() {
41+ searchEnabled = true;
42+ }
43+
4044 function test_search_disabled() {
4145 searchEnabled = false
4246 pageHeader.resetSearch()
@@ -151,12 +155,48 @@ Item {
151155 scopeMock.searchInProgress = true
152156 compare(searchIndicator.running, true, "Search indicator isn't running.")
153157 tryCompare(primaryImage, "visible", false)
154−
155− pageHeader.resetSearch()
156158 }
157159
158160 function cleanup() {
159− scopeMock.searchInProgress = false
161+ scopeMock.searchInProgress = false;
162+ pageHeader.resetSearch();
163+ }
164+
165+ function test_popover() {
166+ searchEnabled = true;
167+ pageHeader.searchHistory.clear();
168+
169+ pageHeader.searchHistory.addQuery("Search1");
170+ pageHeader.searchHistory.addQuery("Search2");
171+
172+ pageHeader.triggerSearch();
173+
174+ var searchContainer = findChild(pageHeader, "searchContainer");
175+ verify(searchContainer !== undefined, "searchContainer != undefined");
176+ tryCompareFunction(function() { return searchContainer.popover !== null; }, true);
177+
178+ tryCompare(searchContainer.popover, "visible", true);
179+ }
180+
181+ function test_resetSearch_onPopupClose() {
182+ searchEnabled = true;
183+ pageHeader.searchHistory.clear();
184+
185+ pageHeader.searchHistory.addQuery("Search1");
186+ pageHeader.searchHistory.addQuery("Search2");
187+
188+ pageHeader.triggerSearch();
189+
190+ var searchContainer = findChild(pageHeader, "searchContainer");
191+ verify(searchContainer !== undefined, "searchContainer != undefined");
192+ tryCompareFunction(function() { return searchContainer.popover !== null; }, true);
193+ compare(searchContainer.popover.visible, true);
194+
195+ pageHeader.searchQuery = "test";
196+ tryCompareFunction( function() { return (searchContainer.popover===null || !searchContainer.popover.visible) }, true);
197+
198+ pageHeader.resetSearch();
199+ compare((searchContainer.popover===null || !searchContainer.popover.visible), true);
160200 }
161201 }
162202