Bug 1500818 - wait for focus and activate of new windows in BTU.waitForNewWindow, r=dao
authorGijs Kruitbosch <gijskruitbosch@gmail.com>
Mon, 22 Oct 2018 13:10:35 +0000
changeset 442322 e4d47f8261f74e4d19262ac68a79d76ddbd3d8f7
parent 442321 e9ce17673999128f9d5874ce6240b14fd63ffcc6
child 442323 527ac367e301ec8b55b4b226ceeca47cb87d130f
push id71443
push usergijskruitbosch@gmail.com
push dateMon, 22 Oct 2018 13:11:53 +0000
treeherderautoland@e4d47f8261f7 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdao
bugs1500818
milestone64.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 1500818 - wait for focus and activate of new windows in BTU.waitForNewWindow, r=dao Differential Revision: https://phabricator.services.mozilla.com/D9364
browser/base/content/test/contextMenu/browser_contextmenu_linkopen.js
testing/mochitest/BrowserTestUtils/BrowserTestUtils.jsm
--- a/browser/base/content/test/contextMenu/browser_contextmenu_linkopen.js
+++ b/browser/base/content/test/contextMenu/browser_contextmenu_linkopen.js
@@ -2,16 +2,17 @@
    http://creativecommons.org/publicdomain/zero/1.0/ */
 
 "use strict";
 
 const TEST_LINK = "https://example.com/";
 const RESOURCE_LINK = getRootDirectory(gTestPath).replace("chrome://mochitests/content", "https://example.com") + "test_contextmenu_links.html";
 
 async function activateContextAndWaitFor(selector, where) {
+  info("Starting test for " + where);
   let contextMenuItem = "openlink";
   let openPromise;
   let closeMethod;
   switch (where) {
     case "tab":
       contextMenuItem += "intab";
       openPromise = BrowserTestUtils.waitForNewTab(gBrowser, TEST_LINK, false);
       closeMethod = async (tab) => BrowserTestUtils.removeTab(tab);
@@ -49,17 +50,19 @@ async function activateContextAndWaitFor
   info("Going to click item " + domItem.id);
   let bounds = domItem.getBoundingClientRect();
   ok(bounds.height && bounds.width, "DOM context menu item " + where + " should be visible");
   ok(!domItem.disabled, "DOM context menu item " + where + " shouldn't be disabled");
   domItem.click();
   contextMenu.hidePopup();
   await awaitPopupHidden;
 
+  info("Waiting for the link to open");
   let openedThing = await openPromise;
+  info("Waiting for the opened window/tab to close");
   await closeMethod(openedThing);
 }
 
 add_task(async function test_select_text_link() {
   let testTab = await BrowserTestUtils.openNewForegroundTab(gBrowser, RESOURCE_LINK);
   for (let elementID of ["test-link", "test-image-link", "svg-with-link", "svg-with-relative-link"]) {
     for (let where of ["tab", "window", "privatewindow"]) {
       await activateContextAndWaitFor("#" + elementID, where);
--- a/testing/mochitest/BrowserTestUtils/BrowserTestUtils.jsm
+++ b/testing/mochitest/BrowserTestUtils/BrowserTestUtils.jsm
@@ -584,16 +584,18 @@ var BrowserTestUtils = {
           if (win.document.documentURI != AppConstants.BROWSER_CHROME_URL) {
             return;
           }
         }
 
         let promises = [
           TestUtils.topicObserved("browser-delayed-startup-finished",
                                   subject => subject == win),
+          this.waitForEvent(win, "focus"),
+          this.waitForEvent(win, "activate"),
         ];
 
         if (url) {
           let browser = win.gBrowser.selectedBrowser;
 
           // Retrieve the given browser's current process type.
           let process =
               browser.isRemoteBrowser ? Ci.nsIXULRuntime.PROCESS_TYPE_CONTENT