Bug 1522521 - Port the new browser_switchToTab_closes_newtab.js to QuantumBar. r=adw
authorMark Banner <standard8@mozilla.com>
Wed, 27 Feb 2019 08:05:57 +0000
changeset 519295 374fbf5e2569f94d681e30ef97c9fa1cd5979c2c
parent 519294 af366b1dc82e5eab80a35459fff6f8d94b003999
child 519296 69f963484c0750fcaf37e151b5c910f7ebff9c25
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)
reviewersadw
bugs1522521
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 1522521 - Port the new browser_switchToTab_closes_newtab.js to QuantumBar. r=adw Differential Revision: https://phabricator.services.mozilla.com/D21244
browser/components/urlbar/tests/browser/browser_switchToTab_closes_newtab.js
--- a/browser/components/urlbar/tests/browser/browser_switchToTab_closes_newtab.js
+++ b/browser/components/urlbar/tests/browser/browser_switchToTab_closes_newtab.js
@@ -1,53 +1,47 @@
 /* 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/. */
 
-add_task(async function listener() {
-  let testURL = "http://example.org/browser/browser/base/content/test/general/dummy_page.html";
-  let tabSelected = false;
+/**
+ * This tests that switch to tab from a blank tab switches and then closes
+ * the blank tab.
+ */
+
+"use strict";
+
+add_task(async function test_switchToTab_closes() {
+  let testURL = "http://example.org/browser/browser/components/urlbar/tests/browser/dummy_page.html";
 
   // Open the base tab
-  let baseTab = BrowserTestUtils.addTab(gBrowser, testURL);
+  let baseTab = await BrowserTestUtils.openNewForegroundTab(gBrowser, testURL);
 
-  // Wait for the tab to be fully loaded so matching happens correctly
-  await promiseTabLoaded(baseTab);
   if (baseTab.linkedBrowser.currentURI.spec == "about:blank")
     return;
-  baseTab.linkedBrowser.removeEventListener("load", listener, true);
 
-  let testTab = BrowserTestUtils.addTab(gBrowser);
-
-  // Select the testTab
-  gBrowser.selectedTab = testTab;
-
-  // Set the urlbar to include the moz-action
-  gURLBar.value = "moz-action:switchtab," + JSON.stringify({url: testURL});
-  // Focus the urlbar so we can press enter
-  gURLBar.focus();
+  // Open a blank tab to start the test from.
+  let testTab = await BrowserTestUtils.openNewForegroundTab(gBrowser);
 
   // Functions for TabClose and TabSelect
-  function onTabClose(aEvent) {
-    gBrowser.tabContainer.removeEventListener("TabClose", onTabClose);
-    // Make sure we get the TabClose event for testTab
-    is(aEvent.originalTarget, testTab, "Got the TabClose event for the right tab");
-    // Confirm that we did select the tab
-    ok(tabSelected, "Confirming that the tab was selected");
-    gBrowser.removeTab(baseTab);
-    finish();
-  }
-  function onTabSelect(aEvent) {
-    gBrowser.tabContainer.removeEventListener("TabSelect", onTabSelect);
-    // Make sure we got the TabSelect event for baseTab
-    is(aEvent.originalTarget, baseTab, "Got the TabSelect event for the right tab");
-    // Confirm that the selected tab is in fact base tab
-    is(gBrowser.selectedTab, baseTab, "We've switched to the correct tab");
-    tabSelected = true;
-  }
+  let tabClosePromise = BrowserTestUtils.waitForEvent(gBrowser.tabContainer,
+    "TabClose", false, event => {
+      return event.originalTarget == testTab;
+    });
+  let tabSelectPromise = BrowserTestUtils.waitForEvent(gBrowser.tabContainer,
+    "TabSelect", false, event => {
+      return event.originalTarget == baseTab;
+    });
+
+  await UrlbarTestUtils.promiseAutocompleteResultPopup(window, "dummy", waitForFocus);
 
-  // Add the TabClose, TabSelect event listeners before we press enter
-  gBrowser.tabContainer.addEventListener("TabClose", onTabClose);
-  gBrowser.tabContainer.addEventListener("TabSelect", onTabSelect);
+  // The first result is the heuristic, the second will be the switch to tab.
+  let element = await UrlbarTestUtils.waitForAutocompleteResultAt(window, 1);
+  EventUtils.synthesizeMouseAtCenter(element, {}, window);
+
+  await Promise.all([tabSelectPromise, tabClosePromise]);
 
-  // Press enter!
-  EventUtils.synthesizeKey("KEY_Enter");
+  // Confirm that the selected tab is now the base tab
+  Assert.equal(gBrowser.selectedTab, baseTab,
+    "Should have switched to the correct tab");
+
+  gBrowser.removeTab(baseTab);
 });