Bug 1206133 - Fix browser chrome mochitests broken by the popuppositioned patch. r=enndeakin
authorKirk Steuber <ksteuber@mozilla.com>
Fri, 19 Aug 2016 14:31:43 -0700
changeset 315938 06f3f82059c82c6958a27f5c478325f22fdd4a7f
parent 315937 9401602eabf337e087f9723eba1d5d1869d7ba6c
child 315939 b0e0213a3b2bd5f0e449a41984414e7a64a45a8a
push id20634
push usercbook@mozilla.com
push dateFri, 30 Sep 2016 10:10:13 +0000
treeherderfx-team@afe79b010d13 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersenndeakin
bugs1206133
milestone52.0a1
Bug 1206133 - Fix browser chrome mochitests broken by the popuppositioned patch. r=enndeakin MozReview-Commit-ID: F3F9L2rXcys
browser/base/content/test/urlbar/browser_locationBarCommand.js
browser/components/customizableui/test/browser_981418-widget-onbeforecreated-handler.js
browser/components/customizableui/test/browser_988072_sidebar_events.js
testing/mochitest/BrowserTestUtils/BrowserTestUtils.jsm
toolkit/components/passwordmgr/test/browser/browser_notifications.js
toolkit/components/passwordmgr/test/browser/browser_notifications_2.js
toolkit/components/passwordmgr/test/browser/browser_notifications_password.js
toolkit/components/passwordmgr/test/browser/browser_notifications_username.js
--- a/browser/base/content/test/urlbar/browser_locationBarCommand.js
+++ b/browser/base/content/test/urlbar/browser_locationBarCommand.js
@@ -36,17 +36,21 @@ add_task(function* shift_left_click_test
   info("Running test: Shift left click");
 
   let newWindowPromise = BrowserTestUtils.waitForNewWindow();
   triggerCommand(true, {shiftKey: true});
   let win = yield newWindowPromise;
 
   // Wait for the initial browser to load.
   let browser = win.gBrowser.selectedBrowser;
-  yield BrowserTestUtils.browserLoaded(browser);
+  let destinationURL = "http://" + TEST_VALUE + "/";
+  yield 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");
   yield 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.
--- a/browser/components/customizableui/test/browser_981418-widget-onbeforecreated-handler.js
+++ b/browser/components/customizableui/test/browser_981418-widget-onbeforecreated-handler.js
@@ -40,22 +40,25 @@ add_task(function* testAddOnBeforeCreate
   ok(onBeforeCreatedCalled, "onBeforeCreated should have been called");
 
   let widgetNode = document.getElementById(kWidgetId);
   ok(widgetNode, "Widget should exist");
   if (widgetNode) {
     try {
       widgetNode.click();
 
+      let tempPanel = document.getElementById("customizationui-widget-panel");
+      let panelShownPromise = promisePanelElementShown(window, tempPanel);
+
       let shownTimeout = setTimeout(() => viewShownDeferred.reject("Panel not shown within 20s"), 20000);
       yield viewShownDeferred.promise;
+      yield panelShownPromise;
       clearTimeout(shownTimeout);
       ok(true, "Found view shown");
 
-      let tempPanel = document.getElementById("customizationui-widget-panel");
       let panelHiddenPromise = promisePanelElementHidden(window, tempPanel);
       tempPanel.hidePopup();
       yield panelHiddenPromise;
 
       CustomizableUI.addWidgetToArea(kWidgetId, CustomizableUI.AREA_PANEL);
       yield PanelUI.show();
 
       viewShownDeferred = Promise.defer();
--- a/browser/components/customizableui/test/browser_988072_sidebar_events.js
+++ b/browser/components/customizableui/test/browser_988072_sidebar_events.js
@@ -77,19 +77,21 @@ function compareList(original, displayed
     compareElements(displayed[i], original[i]);
   }
 }
 
 var showSidebarPopup = Task.async(function*() {
   let button = document.getElementById("sidebar-button");
   let subview = document.getElementById("PanelUI-sidebar");
 
+  let popupShownPromise = BrowserTestUtils.waitForEvent(document, "popupshown");
+
   let subviewShownPromise = subviewShown(subview);
   EventUtils.synthesizeMouseAtCenter(button, {});
-  return subviewShownPromise;
+  return Promise.all([subviewShownPromise, popupShownPromise]);
 });
 
 // Check the sidebar widget shows the default items
 add_task(function*() {
   addWidget();
 
   yield showSidebarPopup();
 
--- a/testing/mochitest/BrowserTestUtils/BrowserTestUtils.jsm
+++ b/testing/mochitest/BrowserTestUtils/BrowserTestUtils.jsm
@@ -293,16 +293,44 @@ this.BrowserTestUtils = {
         };
         tabbrowser.addTabsProgressListener(progressListener);
 
       });
     });
   },
 
   /**
+   * Waits for onLocationChange.
+   *
+   * @param {tabbrowser} tabbrowser
+   *        The tabbrowser to wait for the location change on.
+   * @param {string} url
+   *        The string URL to look for. The URL must match the URL in the
+   *        location bar exactly.
+   * @return {Promise}
+   * @resolves When onLocationChange fires.
+   */
+  waitForLocationChange(tabbrowser, url) {
+    return new Promise((resolve, reject) => {
+      let progressListener = {
+        onLocationChange(aBrowser) {
+          if ((url && aBrowser.currentURI.spec != url) ||
+              (!url && aBrowser.currentURI.spec == "about:blank")) {
+            return;
+          }
+
+          tabbrowser.removeTabsProgressListener(progressListener);
+          resolve();
+        },
+      };
+      tabbrowser.addTabsProgressListener(progressListener);
+    });
+  },
+
+  /**
    * Waits for the next browser window to open and be fully loaded.
    *
    * @param {bool} delayedStartup (optional)
    *        Whether or not to wait for the browser-delayed-startup-finished
    *        observer notification before resolving. Defaults to true.
    * @param {string} initialBrowserLoaded (optional)
    *        If set, we will wait until the initial browser in the new
    *        window has loaded a particular page. If unset, the initial
--- a/toolkit/components/passwordmgr/test/browser/browser_notifications.js
+++ b/toolkit/components/passwordmgr/test/browser/browser_notifications.js
@@ -33,32 +33,35 @@ add_task(function* test_save_change() {
     yield BrowserTestUtils.withNewTab({
       gBrowser,
       url: "https://example.com/browser/toolkit/components/" +
            "passwordmgr/test/browser/form_basic.html",
     }, function* (browser) {
       // Submit the form in the content page with the credentials from the test
       // case. This will cause the doorhanger notification to be displayed.
       let promiseShown = BrowserTestUtils.waitForEvent(PopupNotifications.panel,
-                                                       "Shown");
+                                                       "popupshown",
+                                                       (event) => event.target == PopupNotifications.panel);
       yield ContentTask.spawn(browser, { username, password },
         function* ({ username, password }) {
           let doc = content.document;
           doc.getElementById("form-basic-username").value = username;
           doc.getElementById("form-basic-password").value = password;
           doc.getElementById("form-basic").submit();
         });
       yield promiseShown;
+      let notificationElement = PopupNotifications.panel.childNodes[0];
+      // Style flush to make sure binding is attached
+      notificationElement.querySelector("#password-notification-password").clientTop;
 
-      let notificationElement = PopupNotifications.panel.childNodes[0];
       // Check the actual content of the popup notification.
       Assert.equal(notificationElement.querySelector("#password-notification-username")
-                           .getAttribute("value"), username);
+                           .value, username);
       Assert.equal(notificationElement.querySelector("#password-notification-password")
-                           .getAttribute("value"), password);
+                           .value, password);
 
       // Simulate the action on the notification to request the login to be
       // saved, and wait for the data to be updated or saved based on the type
       // of operation we expect.
       let expectedNotification = oldPassword ? "modifyLogin" : "addLogin";
       let promiseLogin = TestUtils.topicObserved("passwordmgr-storage-changed",
                          (_, data) => data == expectedNotification);
       notificationElement.button.doCommand();
--- a/toolkit/components/passwordmgr/test/browser/browser_notifications_2.js
+++ b/toolkit/components/passwordmgr/test/browser/browser_notifications_2.js
@@ -14,17 +14,18 @@ add_task(function* test_empty_password()
   yield BrowserTestUtils.withNewTab({
       gBrowser,
       url: "https://example.com/browser/toolkit/components/" +
            "passwordmgr/test/browser/form_basic.html",
     }, function* (browser) {
       // Submit the form in the content page with the credentials from the test
       // case. This will cause the doorhanger notification to be displayed.
       let promiseShown = BrowserTestUtils.waitForEvent(PopupNotifications.panel,
-                                                       "popupshown");
+                                                       "popupshown",
+                                                       (event) => event.target == PopupNotifications.panel);
       yield ContentTask.spawn(browser, null,
         function* () {
           let doc = content.document;
           doc.getElementById("form-basic-username").value = "username";
           doc.getElementById("form-basic-password").value = "p";
           doc.getElementById("form-basic").submit();
         });
       yield promiseShown;
@@ -56,17 +57,18 @@ add_task(function* test_toggle_password(
   yield BrowserTestUtils.withNewTab({
       gBrowser,
       url: "https://example.com/browser/toolkit/components/" +
            "passwordmgr/test/browser/form_basic.html",
     }, function* (browser) {
       // Submit the form in the content page with the credentials from the test
       // case. This will cause the doorhanger notification to be displayed.
       let promiseShown = BrowserTestUtils.waitForEvent(PopupNotifications.panel,
-                                                       "popupshown");
+                                                       "popupshown",
+                                                       (event) => event.target == PopupNotifications.panel);
       yield ContentTask.spawn(browser, null,
         function* () {
           let doc = content.document;
           doc.getElementById("form-basic-username").value = "username";
           doc.getElementById("form-basic-password").value = "p";
           doc.getElementById("form-basic").submit();
         });
       yield promiseShown;
@@ -93,17 +95,18 @@ add_task(function* test_checkbox_disable
   yield BrowserTestUtils.withNewTab({
       gBrowser,
       url: "https://example.com/browser/toolkit/components/" +
            "passwordmgr/test/browser/form_basic.html",
     }, function* (browser) {
       // Submit the form in the content page with the credentials from the test
       // case. This will cause the doorhanger notification to be displayed.
       let promiseShown = BrowserTestUtils.waitForEvent(PopupNotifications.panel,
-                                                       "popupshown");
+                                                       "popupshown",
+                                                       (event) => event.target == PopupNotifications.panel);
 
       LoginTestUtils.masterPassword.enable();
 
       yield ContentTask.spawn(browser, null, function* () {
         let doc = content.document;
         doc.getElementById("form-basic-username").value = "username";
         doc.getElementById("form-basic-password").value = "p";
         doc.getElementById("form-basic").submit();
--- a/toolkit/components/passwordmgr/test/browser/browser_notifications_password.js
+++ b/toolkit/components/passwordmgr/test/browser/browser_notifications_password.js
@@ -73,37 +73,40 @@ add_task(function* test_edit_password() 
     yield BrowserTestUtils.withNewTab({
       gBrowser,
       url: "https://example.com/browser/toolkit/components/" +
            "passwordmgr/test/browser/form_basic.html",
     }, function* (browser) {
       // Submit the form in the content page with the credentials from the test
       // case. This will cause the doorhanger notification to be displayed.
       let promiseShown = BrowserTestUtils.waitForEvent(PopupNotifications.panel,
-                                                       "popupshown");
+                                                       "popupshown",
+                                                       (event) => event.target == PopupNotifications.panel);
       yield ContentTask.spawn(browser, testCase,
         function* (testCase) {
           let doc = content.document;
           doc.getElementById("form-basic-username").value = testCase.usernameInPage;
           doc.getElementById("form-basic-password").value = testCase.passwordInPage;
           doc.getElementById("form-basic").submit();
         });
       yield promiseShown;
+      let notificationElement = PopupNotifications.panel.childNodes[0];
+      // Style flush to make sure binding is attached
+      notificationElement.querySelector("#password-notification-password").clientTop;
 
-      let notificationElement = PopupNotifications.panel.childNodes[0];
       // Modify the username in the dialog if requested.
       if (testCase.usernameChangedTo) {
         notificationElement.querySelector("#password-notification-username")
-                .setAttribute("value", testCase.usernameChangedTo);
+                .value = testCase.usernameChangedTo;
       }
 
       // Modify the password in the dialog if requested.
       if (testCase.passwordChangedTo) {
         notificationElement.querySelector("#password-notification-password")
-                .setAttribute("value", testCase.passwordChangedTo);
+                .value = testCase.passwordChangedTo;
       }
 
       // We expect a modifyLogin notification if the final username used by the
       // dialog exists in the logins database, otherwise an addLogin one.
       let expectModifyLogin = typeof testCase.usernameChangedTo !== "undefined"
                               ? testCase.usernameChangedToExists
                               : testCase.usernameInPageExists;
 
--- a/toolkit/components/passwordmgr/test/browser/browser_notifications_username.js
+++ b/toolkit/components/passwordmgr/test/browser/browser_notifications_username.js
@@ -64,31 +64,34 @@ add_task(function* test_edit_username() 
     yield BrowserTestUtils.withNewTab({
       gBrowser,
       url: "https://example.com/browser/toolkit/components/" +
            "passwordmgr/test/browser/form_basic.html",
     }, function* (browser) {
       // Submit the form in the content page with the credentials from the test
       // case. This will cause the doorhanger notification to be displayed.
       let promiseShown = BrowserTestUtils.waitForEvent(PopupNotifications.panel,
-                                                       "Shown");
+                                                       "popupshown",
+                                                       (event) => event.target == PopupNotifications.panel);
       yield ContentTask.spawn(browser, testCase.usernameInPage,
         function* (usernameInPage) {
           let doc = content.document;
           doc.getElementById("form-basic-username").value = usernameInPage;
           doc.getElementById("form-basic-password").value = "password";
           doc.getElementById("form-basic").submit();
         });
       yield promiseShown;
+      let notificationElement = PopupNotifications.panel.childNodes[0];
+      // Style flush to make sure binding is attached
+      notificationElement.querySelector("#password-notification-password").clientTop;
 
-      let notificationElement = PopupNotifications.panel.childNodes[0];
       // Modify the username in the dialog if requested.
       if (testCase.usernameChangedTo) {
         notificationElement.querySelector("#password-notification-username")
-                .setAttribute("value", testCase.usernameChangedTo);
+                .value = testCase.usernameChangedTo;
       }
 
       // We expect a modifyLogin notification if the final username used by the
       // dialog exists in the logins database, otherwise an addLogin one.
       let expectModifyLogin = testCase.usernameChangedTo
                               ? testCase.usernameChangedToExists
                               : testCase.usernameInPageExists;