Bug 1531347 - Port switch to tab tests to QuantumBar. r=mak
authorMark Banner <standard8@mozilla.com>
Sat, 02 Mar 2019 22:02:25 +0000
changeset 520045 86e68f4e34fe93009b122cf92012b1d1efd32817
parent 520044 922daa7856228500ecad60dfba4442f8f3707588
child 520046 f3fc563074f5758d353d414e221f8eb94acc94f8
push id10862
push userffxbld-merge
push dateMon, 11 Mar 2019 13:01:11 +0000
treeherdermozilla-beta@a2e7f5c935da [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmak
bugs1531347
milestone67.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 1531347 - Port switch to tab tests to QuantumBar. r=mak Differential Revision: https://phabricator.services.mozilla.com/D21709
browser/components/urlbar/tests/browser/browser.ini
browser/components/urlbar/tests/browser/browser_switchTab_decodeuri.js
browser/components/urlbar/tests/browser/browser_switchTab_override.js
browser/components/urlbar/tests/legacy/browser.ini
browser/components/urlbar/tests/legacy/browser_switchtab_decodeuri.js
browser/components/urlbar/tests/legacy/browser_switchtab_override.js
--- a/browser/components/urlbar/tests/browser/browser.ini
+++ b/browser/components/urlbar/tests/browser/browser.ini
@@ -40,17 +40,21 @@ subsuite = clipboard
 [browser_redirect_error.js]
 support-files = redirect_error.sjs
 [browser_remotetab.js]
 [browser_removeUnsafeProtocolsFromURLBarPaste.js]
 subsuite = clipboard
 [browser_search_favicon.js]
 skip-if = true # Bug 1526222 - Doesn't currently work with QuantumBar
 [browser_switchTab_closesUrlbarPopup.js]
+[browser_switchTab_decodeuri.js]
+[browser_switchTab_override.js]
+skip-if = ((os == 'win') && verify && debug)
 [browser_switchToTab_closes_newtab.js]
+skip-if = true # Bug 1531737 - fails when run after browser_switchTab_override.js
 [browser_switchToTabHavingURI_aOpenParams.js]
 [browser_tabMatchesInAwesomebar_perwindowpb.js]
 skip-if = os == 'linux' # Bug 1104755 (Intermittent failure)
 [browser_tabMatchesInAwesomebar.js]
 support-files =
   moz.png
 [browser_urlbar_blanking.js]
 support-files =
rename from browser/components/urlbar/tests/legacy/browser_switchtab_decodeuri.js
rename to browser/components/urlbar/tests/browser/browser_switchTab_decodeuri.js
--- a/browser/components/urlbar/tests/legacy/browser_switchtab_decodeuri.js
+++ b/browser/components/urlbar/tests/browser/browser_switchTab_decodeuri.js
@@ -1,31 +1,40 @@
+/* Any copyright is dedicated to the Public Domain.
+ * http://creativecommons.org/publicdomain/zero/1.0/ */
+
+/**
+ * This test ensures that switch to tab still works when the URI contains an
+ * encoded part.
+ */
+
+"use strict";
+
 const TEST_PATH = getRootDirectory(gTestPath)
   .replace("chrome://mochitests/content", "http://example.org");
 const TEST_URL = `${TEST_PATH}dummy_page.html#test%7C1`;
 
 add_task(async function test_switchtab_decodeuri() {
   info("Opening first tab");
   let tab = await BrowserTestUtils.openNewForegroundTab(gBrowser, TEST_URL);
 
   info("Opening and selecting second tab");
   gBrowser.selectedTab = BrowserTestUtils.addTab(gBrowser);
 
   info("Wait for autocomplete");
   await promiseAutocompleteResultPopup("dummy_page");
 
   info("Select autocomplete popup entry");
   EventUtils.synthesizeKey("KEY_ArrowDown");
-  ok(gURLBar.value.startsWith("moz-action:switchtab"), "switch to tab entry found");
+  let result = await UrlbarTestUtils.getDetailsOfResultAt(window,
+    UrlbarTestUtils.getSelectedIndex(window));
+  Assert.equal(result.type, UrlbarUtils.RESULT_TYPE.TAB_SWITCH);
 
   info("switch-to-tab");
-  await new Promise((resolve, reject) => {
-    // In case of success it should switch tab.
-    gBrowser.tabContainer.addEventListener("TabSelect", function() {
-      is(gBrowser.selectedTab, tab, "Should have switched to the right tab");
-      resolve();
-    }, {once: true});
-    EventUtils.synthesizeKey("KEY_Enter");
-  });
+  let tabSelectPromise = BrowserTestUtils.waitForEvent(window, "TabSelect", false);
+  EventUtils.synthesizeKey("KEY_Enter");
+  await tabSelectPromise;
+
+  Assert.equal(gBrowser.selectedTab, tab, "Should have switched to the right tab");
 
   gBrowser.removeCurrentTab();
   await PlacesUtils.history.clear();
 });
rename from browser/components/urlbar/tests/legacy/browser_switchtab_override.js
rename to browser/components/urlbar/tests/browser/browser_switchTab_override.js
--- a/browser/components/urlbar/tests/legacy/browser_switchtab_override.js
+++ b/browser/components/urlbar/tests/browser/browser_switchTab_override.js
@@ -1,12 +1,19 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
+/**
+ * This test ensures that overriding switch-to-tab correctly loads the page
+ * rather than switching to it.
+ */
+
+"use strict";
+
 const TEST_PATH = getRootDirectory(gTestPath)
   .replace("chrome://mochitests/content", "http://example.org/");
 const TEST_URL = `${TEST_PATH}dummy_page.html`;
 
 
 add_task(async function test_switchtab_override() {
   info("Opening first tab");
   let tab = await BrowserTestUtils.openNewForegroundTab(gBrowser, TEST_URL);
@@ -16,38 +23,26 @@ add_task(async function test_switchtab_o
   registerCleanupFunction(() => {
     try {
       gBrowser.removeTab(tab);
       gBrowser.removeTab(secondTab);
     } catch (ex) { /* tabs may have already been closed in case of failure */ }
   });
 
   info("Wait for autocomplete");
-  let deferred = PromiseUtils.defer();
-  let onSearchComplete = gURLBar.onSearchComplete;
-  registerCleanupFunction(() => {
-    gURLBar.onSearchComplete = onSearchComplete;
-  });
-  gURLBar.onSearchComplete = function() {
-    ok(gURLBar.popupOpen, "The autocomplete popup is correctly open");
-    onSearchComplete.apply(gURLBar);
-    deferred.resolve();
-  };
-
-  gURLBar.focus();
-  gURLBar.value = "dummy_pag";
-  EventUtils.sendString("e");
-  await deferred.promise;
+  await promiseAutocompleteResultPopup("dummy_page");
 
   info("Select second autocomplete popup entry");
   EventUtils.synthesizeKey("KEY_ArrowDown");
-  ok(/moz-action:switchtab/.test(gURLBar.value), "switch to tab entry found");
+  let result = await UrlbarTestUtils.getDetailsOfResultAt(window,
+    UrlbarTestUtils.getSelectedIndex(window));
+  Assert.equal(result.type, UrlbarUtils.RESULT_TYPE.TAB_SWITCH);
 
   info("Override switch-to-tab");
-  deferred = PromiseUtils.defer();
+  let deferred = PromiseUtils.defer();
   // In case of failure this would switch tab.
   let onTabSelect = event => {
     deferred.reject(new Error("Should have overridden switch to tab"));
   };
   gBrowser.tabContainer.addEventListener("TabSelect", onTabSelect);
   registerCleanupFunction(() => {
     gBrowser.tabContainer.removeEventListener("TabSelect", onTabSelect);
   });
--- a/browser/components/urlbar/tests/legacy/browser.ini
+++ b/browser/components/urlbar/tests/legacy/browser.ini
@@ -7,22 +7,23 @@ support-files =
   head.js
 
 # XXX Bug 1514162: These are tests that have not yet been ported to the new
 # QuantumBar.
 #
 # If you port a test, please move it to the section below to make it clearer
 # to identify the remaining tests.
 
+# Not porting browser_switchtab_override_keynav.js/browser_switchtab_copy.js
+# to QuantumBar as we no longer have moz-action uris, so they aren't relevant
+# any more.
 [browser_switchtab_copy.js]
 subsuite = clipboard
-[browser_switchtab_decodeuri.js]
 [browser_switchtab_override_keynav.js]
-[browser_switchtab_override.js]
-skip-if = (verify && debug && (os == 'win'))
+
 [browser_urlbarAddonIframe.js]
 support-files =
   ../browser/Panel.jsm
   ../browser/urlbarAddonIframe.html
   ../browser/urlbarAddonIframe.js
   ../browser/urlbarAddonIframeContentScript.js
 [browser_urlbarAutofillPreserveCase.js]
 [browser_urlbarAutoFillTrimURLs.js]
@@ -79,16 +80,19 @@ subsuite = clipboard
 [../browser/browser_populateAfterPushState.js]
 [../browser/browser_redirect_error.js]
 support-files = ../browser/redirect_error.sjs
 [../browser/browser_remotetab.js]
 [../browser/browser_removeUnsafeProtocolsFromURLBarPaste.js]
 subsuite = clipboard
 [../browser/browser_search_favicon.js]
 [../browser/browser_switchTab_closesUrlbarPopup.js]
+[../browser/browser_switchTab_decodeuri.js]
+[../browser/browser_switchTab_override.js]
+skip-if = ((os == 'win') && verify && debug)
 [../browser/browser_switchToTab_closes_newtab.js]
 [../browser/browser_switchToTabHavingURI_aOpenParams.js]
 [../browser/browser_tabMatchesInAwesomebar_perwindowpb.js]
 skip-if = os == 'linux' # Bug 1104755
 [../browser/browser_tabMatchesInAwesomebar.js]
 support-files =
   ../browser/moz.png
 [../browser/browser_urlbarAboutHomeLoading.js]