Bug 1525548 - Centralise closing the address bar popup into the head file for urlbar tests. r=mak
authorMark Banner <standard8@mozilla.com>
Fri, 12 Apr 2019 12:52:50 +0000
changeset 469277 c261aea0226a3f60a31923b9a98e80826eb18833
parent 469276 31aea004045a5572adb1a665fca15f19531b4a42
child 469278 412447b6149e347e8745b1480537726b0c5b02a5
child 469284 9517981892925f44013aff6ab06d63b8ad6c9220
push id112776
push usershindli@mozilla.com
push dateFri, 12 Apr 2019 16:20:17 +0000
treeherdermozilla-inbound@b4501ced5619 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmak
bugs1525548
milestone68.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1525548 - Centralise closing the address bar popup into the head file for urlbar tests. r=mak Differential Revision: https://phabricator.services.mozilla.com/D26759
browser/components/urlbar/tests/browser/browser_action_searchengine.js
browser/components/urlbar/tests/browser/browser_action_searchengine_alias.js
browser/components/urlbar/tests/browser/browser_autoFill_caretNotAtEnd.js
browser/components/urlbar/tests/browser/browser_autocomplete_a11y_label.js
browser/components/urlbar/tests/browser/browser_autocomplete_autoselect.js
browser/components/urlbar/tests/browser/browser_autocomplete_no_title.js
browser/components/urlbar/tests/browser/browser_autocomplete_readline_navigation.js
browser/components/urlbar/tests/browser/browser_dropmarker.js
browser/components/urlbar/tests/browser/browser_keyword_override.js
browser/components/urlbar/tests/browser/browser_keyword_select_and_type.js
browser/components/urlbar/tests/browser/browser_searchTelemetry.js
browser/components/urlbar/tests/browser/browser_textruns.js
browser/components/urlbar/tests/browser/browser_urlbarOneOffs.js
browser/components/urlbar/tests/browser/browser_urlbarOneOffs_searchSuggestions.js
browser/components/urlbar/tests/browser/browser_urlbarOneOffs_settings.js
browser/components/urlbar/tests/browser/browser_urlbarSearchFunction.js
browser/components/urlbar/tests/browser/browser_urlbarSearchSuggestions.js
browser/components/urlbar/tests/browser/browser_urlbarStopSearchOnSelection.js
browser/components/urlbar/tests/browser/browser_urlbarTokenAlias.js
browser/components/urlbar/tests/browser/browser_urlbar_remove_match.js
browser/components/urlbar/tests/browser/head.js
--- a/browser/components/urlbar/tests/browser/browser_action_searchengine.js
+++ b/browser/components/urlbar/tests/browser/browser_action_searchengine.js
@@ -45,11 +45,9 @@ add_task(async function() {
 
   let tabPromise = BrowserTestUtils.browserLoaded(gBrowser.selectedBrowser);
   let element = await UrlbarTestUtils.waitForAutocompleteResultAt(window, 0);
   EventUtils.synthesizeMouseAtCenter(element, {}, window);
   await tabPromise;
 
   Assert.equal(gBrowser.selectedBrowser.currentURI.spec,
     "http://example.com/?q=open+a+search", "Should have loaded the correct page");
-
-  await UrlbarTestUtils.promisePopupClose(window);
 });
--- a/browser/components/urlbar/tests/browser/browser_action_searchengine_alias.js
+++ b/browser/components/urlbar/tests/browser/browser_action_searchengine_alias.js
@@ -40,11 +40,9 @@ add_task(async function() {
   Assert.equal(result.image, ICON_URI, "Should have the correct image");
 
   let tabPromise = BrowserTestUtils.browserLoaded(gBrowser.selectedBrowser);
   EventUtils.synthesizeKey("KEY_Enter");
   await tabPromise;
 
   Assert.equal(gBrowser.selectedBrowser.currentURI.spec,
     "http://example.com/?q=open+a+search", "Should have loaded the correct page");
-
-  await UrlbarTestUtils.promisePopupClose(window);
 });
--- a/browser/components/urlbar/tests/browser/browser_autoFill_caretNotAtEnd.js
+++ b/browser/components/urlbar/tests/browser/browser_autoFill_caretNotAtEnd.js
@@ -23,11 +23,10 @@ add_task(async function noAutofillWhenCa
   // Check the first result and input.
   let result = await UrlbarTestUtils.getDetailsOfResultAt(window, 0);
   Assert.ok(!result.autofill, "The first result should not be autofill");
 
   Assert.equal(gURLBar.value, "example");
   Assert.equal(gURLBar.selectionStart, 1);
   Assert.equal(gURLBar.selectionEnd, 1);
 
-  await UrlbarTestUtils.promisePopupClose(window);
   await PlacesUtils.history.clear();
 });
--- a/browser/components/urlbar/tests/browser/browser_autocomplete_a11y_label.js
+++ b/browser/components/urlbar/tests/browser/browser_autocomplete_a11y_label.js
@@ -65,10 +65,9 @@ add_task(async function searchSuggestion
       // should update and have this test running on QuantumBar.
       let element = await UrlbarTestUtils.waitForAutocompleteResultAt(window, i);
       Assert.equal(element.label,
         suggestion + " browser_searchSuggestionEngine searchSuggestionEngine.xml Search",
         "Result label should be: <search term> <engine name> Search");
     }
   }
   Assert.ok(expectedSearches.length == 0);
-  await UrlbarTestUtils.promisePopupClose(window);
 });
--- a/browser/components/urlbar/tests/browser/browser_autocomplete_autoselect.js
+++ b/browser/components/urlbar/tests/browser/browser_autocomplete_autoselect.js
@@ -96,13 +96,9 @@ add_task(async function() {
 
   info("Page Up will go up the list, but not wrap");
   EventUtils.synthesizeKey("KEY_PageUp");
   assertSelected(0);
 
   info("Page Up again will wrap around to the end of the list");
   EventUtils.synthesizeKey("KEY_PageUp");
   assertSelected(maxResults - 1);
-
-  await UrlbarTestUtils.promisePopupClose(window, () => {
-    EventUtils.synthesizeKey("KEY_Escape");
-  });
 });
--- a/browser/components/urlbar/tests/browser/browser_autocomplete_no_title.js
+++ b/browser/components/urlbar/tests/browser/browser_autocomplete_no_title.js
@@ -17,11 +17,9 @@
     await PlacesUtils.history.clear();
     BrowserTestUtils.removeTab(tab);
   });
 
   await promiseAutocompleteResultPopup("bug1060642");
   let result = await UrlbarTestUtils.getDetailsOfResultAt(window, 1);
   Assert.equal(result.displayed.title, "bug1060642.example.com",
     "Result title should be as expected");
-
-  await UrlbarTestUtils.promisePopupClose(window);
 });
--- a/browser/components/urlbar/tests/browser/browser_autocomplete_readline_navigation.js
+++ b/browser/components/urlbar/tests/browser/browser_autocomplete_readline_navigation.js
@@ -53,11 +53,9 @@ add_task(async function() {
 
   info("Ctrl-n to select the next item");
   EventUtils.synthesizeKey("n", {ctrlKey: true});
   assertSelected(1);
 
   info("Ctrl-p to select the previous item");
   EventUtils.synthesizeKey("p", {ctrlKey: true});
   assertSelected(0);
-
-  await UrlbarTestUtils.promisePopupClose(window);
 });
--- a/browser/components/urlbar/tests/browser/browser_dropmarker.js
+++ b/browser/components/urlbar/tests/browser/browser_dropmarker.js
@@ -11,11 +11,10 @@ add_task(async function() {
         window.document.getAnonymousElementByAttribute(gURLBar.textbox, "anonid", "historydropmarker");
       EventUtils.synthesizeMouseAtCenter(historyDropMarker, {}, window);
     });
     let queryContext = await gURLBar.lastQueryContextPromise;
     is(queryContext.searchString, "",
        "Clicking the history dropmarker should initiate an empty search instead of searching for the loaded URL");
     is(gURLBar.value, "example.com",
        "Clicking the history dropmarker should not change the input value");
-    await UrlbarTestUtils.promisePopupClose(window);
   });
 });
--- a/browser/components/urlbar/tests/browser/browser_keyword_override.js
+++ b/browser/components/urlbar/tests/browser/browser_keyword_override.js
@@ -52,11 +52,9 @@
 
     // QuantumBar doesn't have separate boxes for items.
     let urlHbox = element._urlText.parentNode.parentNode;
     Assert.ok(urlHbox.classList.contains("ac-url"), "URL hbox element sanity check");
     BrowserTestUtils.is_hidden(urlHbox, "URL element should be hidden");
   }
 
   EventUtils.synthesizeKey("VK_SHIFT", { type: "keyup" });
-
-  await UrlbarTestUtils.promisePopupClose(window);
 });
--- a/browser/components/urlbar/tests/browser/browser_keyword_select_and_type.js
+++ b/browser/components/urlbar/tests/browser/browser_keyword_select_and_type.js
@@ -61,11 +61,10 @@ add_task(async function() {
     Assert.equal(result.url, "http://example.com/?q=ab",
       "Should have the correct url");
   } else {
     Assert.equal(result.url,
       PlacesUtils.mozActionURI("keyword", {url: "http://example.com/?q=ab", keyword: "keyword", input: "keyword ab"}),
       "Should have the correct url");
   }
 
-  await UrlbarTestUtils.promisePopupClose(window);
   gBrowser.removeTab(tab);
 });
--- a/browser/components/urlbar/tests/browser/browser_searchTelemetry.js
+++ b/browser/components/urlbar/tests/browser/browser_searchTelemetry.js
@@ -14,19 +14,16 @@ add_task(async function prepare() {
 
   registerCleanupFunction(async function() {
     Services.prefs.setBoolPref(SUGGEST_URLBAR_PREF, suggestionsEnabled);
     await Services.search.setDefault(oldDefaultEngine);
 
     // Clicking urlbar results causes visits to their associated pages, so clear
     // that history now.
     await PlacesUtils.history.clear();
-
-    // Make sure the popup is closed for the next test.
-    await UrlbarTestUtils.promisePopupClose(window);
   });
 
   // Move the mouse away from the urlbar one-offs so that a one-off engine is
   // not inadvertently selected.
   await new Promise(resolve => {
     EventUtils.synthesizeNativeMouseMove(window.document.documentElement, 0, 0,
                                          resolve);
   });
--- a/browser/components/urlbar/tests/browser/browser_textruns.js
+++ b/browser/components/urlbar/tests/browser/browser_textruns.js
@@ -17,10 +17,9 @@
   });
 
   await promiseAutocompleteResultPopup("textruns");
   let result = await UrlbarTestUtils.getDetailsOfResultAt(window, 1);
   Assert.equal(result.displayed.title.length, UrlbarUtils.MAX_TEXT_LENGTH,
                "Result title should be limited");
   Assert.equal(result.displayed.url.length, UrlbarUtils.MAX_TEXT_LENGTH,
                "Result url should be limited");
-  await UrlbarTestUtils.promisePopupClose(window);
 });
--- a/browser/components/urlbar/tests/browser/browser_urlbarOneOffs.js
+++ b/browser/components/urlbar/tests/browser/browser_urlbarOneOffs.js
@@ -12,17 +12,16 @@ add_task(async function init() {
 
   // Add a search suggestion engine and move it to the front so that it appears
   // as the first one-off.
   let engine = await SearchTestUtils.promiseNewSearchEngine(
     getRootDirectory(gTestPath) + TEST_ENGINE_BASENAME);
   await Services.search.moveEngine(engine, 0);
 
   registerCleanupFunction(async function() {
-    await hidePopup();
     await PlacesUtils.history.clear();
   });
 
   await PlacesUtils.history.clear();
 
   let visits = [];
   for (let i = 0; i < gMaxResults; i++) {
     visits.push({
--- a/browser/components/urlbar/tests/browser/browser_urlbarOneOffs_searchSuggestions.js
+++ b/browser/components/urlbar/tests/browser/browser_urlbarOneOffs_searchSuggestions.js
@@ -29,18 +29,16 @@ add_task(async function init() {
   let oldDefaultEngine = await Services.search.getDefault();
   await Services.search.moveEngine(engine2, 0);
   await Services.search.moveEngine(engine, 0);
   await Services.search.setDefault(engine);
   registerCleanupFunction(async function() {
     await Services.search.setDefault(oldDefaultEngine);
 
     await PlacesUtils.history.clear();
-    // Make sure the popup is closed for the next test.
-    await UrlbarTestUtils.promisePopupClose(window);
   });
 });
 
 async function withSecondSuggestion(testFn) {
   await BrowserTestUtils.withNewTab(gBrowser, async () => {
     let typedValue = "foo";
     await promiseAutocompleteResultPopup(typedValue, window, true);
     await promiseSuggestionsPresent();
--- a/browser/components/urlbar/tests/browser/browser_urlbarOneOffs_settings.js
+++ b/browser/components/urlbar/tests/browser/browser_urlbarOneOffs_settings.js
@@ -10,17 +10,16 @@
 
 let gMaxResults;
 
 add_task(async function init() {
   await SpecialPowers.pushPrefEnv({"set": [["browser.urlbar.oneOffSearches", true]]});
   gMaxResults = Services.prefs.getIntPref("browser.urlbar.maxRichResults");
 
   registerCleanupFunction(async function() {
-    await UrlbarTestUtils.promisePopupClose(window);
     await PlacesUtils.history.clear();
   });
 
   await PlacesUtils.history.clear();
 
   let visits = [];
   for (let i = 0; i < gMaxResults; i++) {
     visits.push({
--- a/browser/components/urlbar/tests/browser/browser_urlbarSearchFunction.js
+++ b/browser/components/urlbar/tests/browser/browser_urlbarSearchFunction.js
@@ -16,17 +16,16 @@ add_task(async function init() {
     if (which === undefined) {
       delete gURLBar._whichSearchSuggestionsNotification;
     } else {
       gURLBar._whichSearchSuggestionsNotification = which;
     }
     Services.prefs.clearUserPref("timesBeforeHidingSuggestionsHint");
 
     gURLBar.handleRevert();
-    await UrlbarTestUtils.promisePopupClose(window);
   });
 });
 
 
 // Calls search() with a normal, non-"@engine" search-string argument.
 add_task(async function basic() {
   let resetNotification = enableSearchSuggestionsNotification();
 
--- a/browser/components/urlbar/tests/browser/browser_urlbarSearchSuggestions.js
+++ b/browser/components/urlbar/tests/browser/browser_urlbarSearchSuggestions.js
@@ -21,18 +21,16 @@ add_task(async function prepare() {
   await Services.search.setDefault(engine);
   registerCleanupFunction(async function() {
     Services.prefs.setBoolPref(SUGGEST_URLBAR_PREF, suggestionsEnabled);
     await Services.search.setDefault(oldDefaultEngine);
 
     // Clicking suggestions causes visits to search results pages, so clear that
     // history now.
     await PlacesUtils.history.clear();
-
-    await UrlbarTestUtils.promisePopupClose(window);
   });
 });
 
 add_task(async function clickSuggestion() {
   let tab = await BrowserTestUtils.openNewForegroundTab(gBrowser);
   gURLBar.focus();
   await promiseAutocompleteResultPopup("foo");
   let [idx, suggestion, engineName] = await promiseFirstSuggestion();
@@ -88,18 +86,16 @@ add_task(async function copySuggestionTe
   let [idx, suggestion] = await promiseFirstSuggestion();
   for (let i = 0; i < idx; ++i) {
     EventUtils.synthesizeKey("KEY_ArrowDown");
   }
   gURLBar.select();
   await new Promise((resolve, reject) => waitForClipboard(suggestion, function() {
     goDoCommand("cmd_copy");
   }, resolve, reject));
-  await UrlbarTestUtils.promisePopupClose(window, () =>
-    EventUtils.synthesizeKey("KEY_Escape"));
 });
 
 async function getFirstSuggestion() {
   let matchCount = UrlbarTestUtils.getResultCount(window);
   for (let i = 0; i < matchCount; i++) {
     let result = await UrlbarTestUtils.getDetailsOfResultAt(window, i);
     if (result.type == UrlbarUtils.RESULT_TYPE.SEARCH &&
         result.searchParams.suggestion) {
--- a/browser/components/urlbar/tests/browser/browser_urlbarStopSearchOnSelection.js
+++ b/browser/components/urlbar/tests/browser/browser_urlbarStopSearchOnSelection.js
@@ -27,18 +27,16 @@ add_task(async function init() {
   let engine = await SearchTestUtils.promiseNewSearchEngine(
     getRootDirectory(gTestPath) + TEST_ENGINE_BASENAME);
   let oldDefaultEngine = await Services.search.getDefault();
   await Services.search.moveEngine(engine, 0);
   await Services.search.setDefault(engine);
   registerCleanupFunction(async () => {
     await Services.search.setDefault(oldDefaultEngine);
     await PlacesUtils.history.clear();
-    // Make sure the popup is closed for the next test.
-    await UrlbarTestUtils.promisePopupClose(window);
   });
 });
 
 add_task(async function mainTest() {
   // Trigger an initial search.  Restrict matches to search suggestions.
   await promiseAutocompleteResultPopup(`${UrlbarTokenizer.RESTRICT.SEARCH} test`, window);
   await promiseSuggestionsPresent("Waiting for initial suggestions");
 
--- a/browser/components/urlbar/tests/browser/browser_urlbarTokenAlias.js
+++ b/browser/components/urlbar/tests/browser/browser_urlbarTokenAlias.js
@@ -10,19 +10,16 @@ const ALIAS = "@test";
 add_task(async function init() {
   await Services.search.addEngineWithDetails("Test", {
     alias: ALIAS,
     template: "http://example.com/?search={searchTerms}",
   });
   registerCleanupFunction(async function() {
     let engine = Services.search.getEngineByName("Test");
     await Services.search.removeEngine(engine);
-    // Make sure the popup is closed for the next test.
-    gURLBar.handleRevert();
-    await UrlbarTestUtils.promisePopupClose(window, () => gURLBar.blur());
   });
 
   // Search results aren't shown in quantumbar unless search suggestions are
   // enabled.
   await SpecialPowers.pushPrefEnv({
     set: [
       ["browser.urlbar.suggest.searches", true],
     ],
--- a/browser/components/urlbar/tests/browser/browser_urlbar_remove_match.js
+++ b/browser/components/urlbar/tests/browser/browser_urlbar_remove_match.js
@@ -61,13 +61,11 @@ add_task(async function test_remove_book
     { shiftKey: true } : {};
   EventUtils.synthesizeKey("KEY_Delete", options);
 
   // We don't have an easy way of determining if the event was process or not,
   // so let any event queues clear before testing.
   await new Promise(resolve => setTimeout(resolve, 0));
   await PlacesTestUtils.promiseAsyncUpdates();
 
-  await UrlbarTestUtils.promisePopupClose(window);
-
   Assert.ok(await PlacesUtils.bookmarks.fetch({url: TEST_URL}),
     "Should still have the URL bookmarked.");
 });
--- a/browser/components/urlbar/tests/browser/head.js
+++ b/browser/components/urlbar/tests/browser/head.js
@@ -21,8 +21,14 @@ XPCOMUtils.defineLazyModuleGetters(this,
 });
 
 /* import-globals-from head-common.js */
 Services.scriptloader.loadSubScript(
   "chrome://mochitests/content/browser/browser/components/urlbar/tests/browser/head-common.js",
   this);
 
 const {sinon} = ChromeUtils.import("resource://testing-common/Sinon.jsm");
+
+registerCleanupFunction(async () => {
+  // Ensure the Urlbar popup is always closed at the end of a test, to save having
+  // to do it within each test.
+  await UrlbarTestUtils.promisePopupClose(window);
+});