Bug 1268163 - Fix intermittent browser_capture_doorhanger_window_open.js by waiting for <input> changes. r=dolske draft
authorMatthew Noorenberghe <mozilla@noorenberghe.ca>
Thu, 28 Apr 2016 21:49:54 -0700
changeset 357710 37a4ad56750a071122224e674aa498c3fb22b819
parent 357266 2157fe6b6efd14c217404bf3fe7d28699dc47ce4
child 519681 e38938a95d9435cff7072ee331c28262f49ff768
push id16819
push usermozilla@noorenberghe.ca
push dateFri, 29 Apr 2016 04:50:24 +0000
reviewersdolske
bugs1268163
milestone49.0a1
Bug 1268163 - Fix intermittent browser_capture_doorhanger_window_open.js by waiting for <input> changes. r=dolske nsLoginManagerPrompter.js' writeDataToUI() populates the doorhanger <input> on popupshown so we need to give it a chance to do so before clicking the doorhanger button in case the test listener happens first. MozReview-Commit-ID: GkhYNpFunkp
toolkit/components/passwordmgr/test/browser/browser_capture_doorhanger_window_open.js
--- a/toolkit/components/passwordmgr/test/browser/browser_capture_doorhanger_window_open.js
+++ b/toolkit/components/passwordmgr/test/browser/browser_capture_doorhanger_window_open.js
@@ -28,32 +28,43 @@ function withTestTabUntilStorageChange(a
     ok(true, "loaded " + aPageFile);
     info("running test case task");
     yield* aTaskFn();
     info("waiting for storage change");
     yield storageChangedPromised;
   });
 }
 
+function* checkDoorhangerUsernamePassword(username, password) {
+  yield BrowserTestUtils.waitForCondition(() => {
+    return document.getElementById("password-notification-username").value == username;
+  }, "Wait for nsLoginManagerPrompter writeDataToUI()");
+  is(document.getElementById("password-notification-username").value, username,
+     "Check doorhanger username");
+  is(document.getElementById("password-notification-password").value, password,
+     "Check doorhanger password");
+}
+
 
 add_task(function* setup() {
   yield SimpleTest.promiseFocus(window);
 });
 
 add_task(function* test_saveChromeHiddenAutoClose() {
   let notifShownPromise = BrowserTestUtils.waitForEvent(PopupNotifications.panel, "popupshown");
   // query arguments are: username, password, features, auto-close (delimited by '|')
   let url = "subtst_notifications_11.html?notifyu1|notifyp1|" +
             "menubar=no,toolbar=no,location=no|autoclose";
   yield withTestTabUntilStorageChange(url, function*() {
     info("waiting for popupshown");
     yield notifShownPromise;
     // the popup closes and the doorhanger should appear in the opener
     let popup = getCaptureDoorhanger("password-save");
     ok(popup, "got notification popup");
+    yield* checkDoorhangerUsernamePassword("notifyu1", "notifyp1");
     // Sanity check, no logins should exist yet.
     let logins = Services.logins.getAllLogins();
     is(logins.length, 0, "Should not have any logins yet");
 
     clickDoorhangerButton(popup, REMEMBER_BUTTON);
   });
   // Check result of clicking Remember
   let logins = Services.logins.getAllLogins();
@@ -67,16 +78,17 @@ add_task(function* test_saveChromeHidden
 add_task(function* test_changeChromeHiddenAutoClose() {
   let notifShownPromise = BrowserTestUtils.waitForEvent(PopupNotifications.panel, "popupshown");
   let url = "subtst_notifications_11.html?notifyu1|pass2|menubar=no,toolbar=no,location=no|autoclose";
   yield withTestTabUntilStorageChange(url, function*() {
     info("waiting for popupshown");
     yield notifShownPromise;
     let popup = getCaptureDoorhanger("password-change");
     ok(popup, "got notification popup");
+    yield* checkDoorhangerUsernamePassword("notifyu1", "pass2");
     clickDoorhangerButton(popup, CHANGE_BUTTON);
   });
 
   // Check to make sure we updated the password, timestamps and use count for
   // the login being changed with this form.
   let logins = Services.logins.getAllLogins();
   is(logins.length, 1, "Should only have 1 login");
   let login = logins[0].QueryInterface(Ci.nsILoginMetaInfo);
@@ -94,16 +106,17 @@ add_task(function* test_changeChromeHidd
 add_task(function* test_saveChromeVisibleSameWindow() {
   // This test actually opens a new tab in the same window with default browser settings.
   let url = "subtst_notifications_11.html?notifyu2|notifyp2||";
   let notifShownPromise = BrowserTestUtils.waitForEvent(PopupNotifications.panel, "popupshown");
   yield withTestTabUntilStorageChange(url, function*() {
     yield notifShownPromise;
     let popup = getCaptureDoorhanger("password-save");
     ok(popup, "got notification popup");
+    yield* checkDoorhangerUsernamePassword("notifyu2", "notifyp2");
     clickDoorhangerButton(popup, REMEMBER_BUTTON);
     yield BrowserTestUtils.removeTab(gBrowser.selectedTab);
   });
 
   // Check result of clicking Remember
   let logins = Services.logins.getAllLogins();
   is(logins.length, 1, "Should only have 1 login now");
   let login = logins[0].QueryInterface(Ci.nsILoginMetaInfo);
@@ -114,16 +127,17 @@ add_task(function* test_saveChromeVisibl
 
 add_task(function* test_changeChromeVisibleSameWindow() {
   let url = "subtst_notifications_11.html?notifyu2|pass2||";
   let notifShownPromise = BrowserTestUtils.waitForEvent(PopupNotifications.panel, "popupshown");
   yield withTestTabUntilStorageChange(url, function*() {
     yield notifShownPromise;
     let popup = getCaptureDoorhanger("password-change");
     ok(popup, "got notification popup");
+    yield* checkDoorhangerUsernamePassword("notifyu2", "pass2");
     clickDoorhangerButton(popup, CHANGE_BUTTON);
     yield BrowserTestUtils.removeTab(gBrowser.selectedTab);
   });
 
   // Check to make sure we updated the password, timestamps and use count for
   // the login being changed with this form.
   let logins = Services.logins.getAllLogins();
   is(logins.length, 1, "Should have 1 login");