Bug 1501079 - fix various tests to not race with window focus/activate, r=dao
authorGijs Kruitbosch <gijskruitbosch@gmail.com>
Tue, 23 Oct 2018 10:16:35 +0000
changeset 442546 f8615bd92bc605151a21266c148a9254e666d40d
parent 442545 480b34db3172d2456b619681d4a05216221066f0
child 442547 02067918a4d85206c71f73fd9fe0a0ebfd8e1d60
push id34913
push useraciure@mozilla.com
push dateTue, 23 Oct 2018 16:49:58 +0000
treeherdermozilla-central@ff3ed362e82f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdao
bugs1501079
milestone65.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 1501079 - fix various tests to not race with window focus/activate, r=dao Differential Revision: https://phabricator.services.mozilla.com/D9437
browser/base/content/test/sidebar/browser_sidebar_adopt.js
browser/base/content/test/urlbar/browser_locationBarCommand.js
browser/components/contextualidentity/test/browser/browser_windowOpen.js
browser/modules/test/browser/browser_PermissionUI.js
dom/tests/browser/browser_test_new_window_from_content.js
dom/tests/browser/browser_test_toolbars_visibility.js
uriloader/exthandler/tests/mochitest/browser_web_protocol_handlers.js
--- a/browser/base/content/test/sidebar/browser_sidebar_adopt.js
+++ b/browser/base/content/test/sidebar/browser_sidebar_adopt.js
@@ -41,22 +41,21 @@ add_task(async function testEventsReceiv
 
   ok(true, "SidebarShown and SidebarFocused events fired on a new window");
 });
 
 add_task(async function testEventReceivedInNewWindow() {
   info("Opening a new window and expecting the SidebarFocused event to not fire");
 
   let promiseNewWindow = BrowserTestUtils.waitForNewWindow();
-  BrowserTestUtils.openNewBrowserWindow();
-  let win = await promiseNewWindow;
+  let win = OpenBrowserWindow();
 
   let adoptedShown = BrowserTestUtils.waitForEvent(win, "SidebarShown");
   win.addEventListener("SidebarFocused", failIfSidebarFocusedFires);
-
   registerCleanupFunction(async function() {
     win.removeEventListener("SidebarFocused", failIfSidebarFocusedFires);
     await BrowserTestUtils.closeWindow(win);
   });
 
+  await promiseNewWindow;
   await adoptedShown;
   ok(true, "SidebarShown event fired on an adopted window");
 });
--- a/browser/base/content/test/urlbar/browser_locationBarCommand.js
+++ b/browser/base/content/test/urlbar/browser_locationBarCommand.js
@@ -29,28 +29,21 @@ add_task(async function alt_left_click_t
   await saveURLPromise;
   ok(true, "SaveURL was called");
   is(gURLBar.value, "", "Urlbar reverted to original value");
 });
 
 add_task(async function shift_left_click_test() {
   info("Running test: Shift left click");
 
-  let newWindowPromise = BrowserTestUtils.waitForNewWindow();
+  let destinationURL = "http://" + TEST_VALUE + "/";
+  let newWindowPromise = BrowserTestUtils.waitForNewWindow({url: destinationURL});
   triggerCommand(true, {shiftKey: true});
   let win = await newWindowPromise;
 
-  // Wait for the initial browser to load.
-  let browser = win.gBrowser.selectedBrowser;
-  let destinationURL = "http://" + TEST_VALUE + "/";
-  await Promise.all([
-    BrowserTestUtils.browserLoaded(browser),
-    BrowserTestUtils.waitForLocationChange(win.gBrowser, destinationURL),
-  ]);
-
   info("URL should be loaded in a new window");
   is(gURLBar.value, "", "Urlbar reverted to original value");
   await promiseCheckChildNoFocusedElement(gBrowser.selectedBrowser);
   is(document.activeElement, gBrowser.selectedBrowser, "Content window should be focused");
   is(win.gURLBar.textValue, TEST_VALUE, "New URL is loaded in new window");
 
   // Cleanup.
   await BrowserTestUtils.closeWindow(win);
--- a/browser/components/contextualidentity/test/browser/browser_windowOpen.js
+++ b/browser/components/contextualidentity/test/browser/browser_windowOpen.js
@@ -18,22 +18,22 @@ add_task(async function test() {
   info("Creating a tab with UCI = 1...");
   let tab = BrowserTestUtils.addTab(gBrowser, BASE_URI, {userContextId: 1});
   is(tab.getAttribute("usercontextid"), 1, "New tab has UCI equal 1");
 
   let browser = gBrowser.getBrowserForTab(tab);
   await BrowserTestUtils.browserLoaded(browser);
 
   info("Opening a new window from this tab...");
+  let newWinPromise = BrowserTestUtils.waitForNewWindow({url: BASE_URI});
   ContentTask.spawn(browser, BASE_URI, function(url) {
     content.window.newWindow = content.window.open(url, "_blank");
   });
 
-  let newWin = await BrowserTestUtils.waitForNewWindow();
+  let newWin = await newWinPromise;
   let newTab = newWin.gBrowser.selectedTab;
 
-  await BrowserTestUtils.browserLoaded(newTab.linkedBrowser);
   is(newTab.getAttribute("usercontextid"), 1, "New tab has UCI equal 1");
 
   info("Closing the new window and tab...");
   await BrowserTestUtils.closeWindow(newWin);
   BrowserTestUtils.removeTab(tab);
 });
--- a/browser/modules/test/browser/browser_PermissionUI.js
+++ b/browser/modules/test/browser/browser_PermissionUI.js
@@ -432,20 +432,23 @@ add_task(async function test_window_swap
     let shownPromise =
       BrowserTestUtils.waitForEvent(PopupNotifications.panel, "popupshown");
     TestPrompt.prompt();
     await shownPromise;
 
     let newWindowOpened = BrowserTestUtils.waitForNewWindow();
     gBrowser.replaceTabWithWindow(gBrowser.selectedTab);
     let newWindow = await newWindowOpened;
-    shownPromise =
-      BrowserTestUtils.waitForEvent(newWindow.PopupNotifications.panel, "popupshown");
-    TestPrompt.prompt();
-    await shownPromise;
+    // We may have already opened the panel, because it was open before we moved the tab.
+    if (newWindow.PopupNotifications.panel.state != "open") {
+      shownPromise =
+        BrowserTestUtils.waitForEvent(newWindow.PopupNotifications.panel, "popupshown");
+      TestPrompt.prompt();
+      await shownPromise;
+    }
 
     let notification =
       newWindow.PopupNotifications.getNotification(kTestNotificationID,
                                                    newWindow.gBrowser.selectedBrowser);
     Assert.ok(notification, "Should have gotten the notification");
 
     Assert.equal(notification.message, kTestMessage,
                  "Should be showing the right message");
--- a/dom/tests/browser/browser_test_new_window_from_content.js
+++ b/dom/tests/browser/browser_test_new_window_from_content.js
@@ -113,19 +113,18 @@ function prepareForResult(aBrowser, aExp
         is(aBrowser.currentURI.spec, expectedSpec, "Should be at dummy.html");
         // Now put the browser back where it came from
         await BrowserTestUtils.loadURI(aBrowser, kContentDoc);
         await BrowserTestUtils.browserLoaded(aBrowser);
       })();
       break;
     case kNewWin:
       return (async function() {
-        let newWin = await BrowserTestUtils.waitForNewWindow();
+        let newWin = await BrowserTestUtils.waitForNewWindow({url: expectedSpec});
         let newBrowser = newWin.gBrowser.selectedBrowser;
-        await BrowserTestUtils.browserLoaded(newBrowser);
         is(newBrowser.currentURI.spec, expectedSpec, "Should be at dummy.html");
         await BrowserTestUtils.closeWindow(newWin);
       })();
       break;
     case kNewTab:
       return (async function() {
         let newTab = await BrowserTestUtils.waitForNewTab(gBrowser);
         is(newTab.linkedBrowser.currentURI.spec, expectedSpec,
--- a/dom/tests/browser/browser_test_toolbars_visibility.js
+++ b/dom/tests/browser/browser_test_toolbars_visibility.js
@@ -133,22 +133,21 @@ add_task(async function() {
     // Check that all toolbars are visible
     let toolbars = await getToolbarsFromBrowserContent(gBrowser.selectedBrowser);
     testDefaultToolbars(toolbars);
 
     // Cleanup
     BrowserTestUtils.removeTab(tab);
 
     // Now let's open a window with toolbars hidden
-    let winPromise = BrowserTestUtils.waitForNewWindow();
+    let winPromise = BrowserTestUtils.waitForNewWindow({url: TARGET_PAGE});
     await BrowserTestUtils.synthesizeMouseAtCenter("#winOpenNonDefault", {}, browser);
     let popupWindow = await winPromise;
 
     let popupBrowser = popupWindow.gBrowser.selectedBrowser;
-    await BrowserTestUtils.browserLoaded(popupBrowser);
 
     // Test toolbars visibility
     let popupToolbars = await getToolbarsFromBrowserContent(popupBrowser);
     testNonDefaultContentToolbars(popupToolbars);
 
     // Ensure that chrome toolbars agree with content
     let chromeToolbars = getToolbarsFromWindowChrome(popupWindow);
     testNonDefaultContentToolbars(chromeToolbars);
@@ -195,27 +194,27 @@ add_task(async function() {
  *
  * A window opened with default parameters should have all toolbars visible.
  *
  * A window opened with "location=no, personalbar=no, toolbar=no, scrollbars=no,
  * menubar=no, status=no", should not have any toolbar visible.
  */
 add_task(async function() {
   // First open a default window from this chrome context
-  let defaultWindowPromise = BrowserTestUtils.waitForNewWindow();
+  let defaultWindowPromise = BrowserTestUtils.waitForNewWindow({url: TARGET_PAGE});
   window.open(TARGET_PAGE, "_blank");
   let defaultWindow = await defaultWindowPromise;
 
   // Check that all toolbars are visible
   let toolbars = getToolbarsFromWindowChrome(defaultWindow);
   testDefaultToolbars(toolbars);
 
   // Now lets open a window with toolbars hidden from this chrome context
   let features = "location=no, personalbar=no, toolbar=no, scrollbars=no, menubar=no, status=no";
-  let popupWindowPromise = BrowserTestUtils.waitForNewWindow();
+  let popupWindowPromise = BrowserTestUtils.waitForNewWindow({url: TARGET_PAGE});
   window.open(TARGET_PAGE, "_blank", features);
   let popupWindow = await popupWindowPromise;
 
   // Test none of the tooolbars are visible
   let hiddenToolbars = getToolbarsFromWindowChrome(popupWindow);
   testNonDefaultChromeToolbars(hiddenToolbars);
 
   // Cleanup
--- a/uriloader/exthandler/tests/mochitest/browser_web_protocol_handlers.js
+++ b/uriloader/exthandler/tests/mochitest/browser_web_protocol_handlers.js
@@ -46,21 +46,20 @@ add_task(async function() {
   await BrowserTestUtils.synthesizeMouseAtCenter(link, {button: 1}, browser);
   let tab = await promiseTabOpened;
   gBrowser.selectedTab = tab;
   is(gURLBar.value, expectedURL,
      "the expected URL is displayed in the location bar");
   BrowserTestUtils.removeTab(tab);
 
   // Shift-click the testprotocol link and check the new window.
-  let newWindowPromise = BrowserTestUtils.waitForNewWindow();
+  let newWindowPromise = BrowserTestUtils.waitForNewWindow({url: expectedURL});
   await BrowserTestUtils.synthesizeMouseAtCenter(link, {shiftKey: true},
                                                  browser);
   let win = await newWindowPromise;
-  await BrowserTestUtils.browserLoaded(win.gBrowser.selectedBrowser);
   await BrowserTestUtils.waitForCondition(() => win.gBrowser.currentURI.spec == expectedURL);
   is(win.gURLBar.value, expectedURL,
      "the expected URL is displayed in the location bar");
   await BrowserTestUtils.closeWindow(win);
 
   // Click the testprotocol link and check the url in the current tab.
   let loadPromise = BrowserTestUtils.browserLoaded(browser);
   await BrowserTestUtils.synthesizeMouseAtCenter(link, {}, browser);