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 490678 e4d47f8261f74e4d19262ac68a79d76ddbd3d8f7
parent 490677 e9ce17673999128f9d5874ce6240b14fd63ffcc6
child 490679 527ac367e301ec8b55b4b226ceeca47cb87d130f
push id247
push userfmarier@mozilla.com
push dateSat, 27 Oct 2018 01:06:44 +0000
reviewersdao
bugs1500818
milestone64.0a1
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