Bug 1142110 - Add a simple browser-chrome test for the popup notifications. r=MattN
authorPaolo Amadini <paolo.mozmail@amadzone.org>
Wed, 18 Mar 2015 18:24:59 -0700
changeset 263237 62f338d8f747c9289cb7e146dd29ebf7b3d51059
parent 263236 890e93b28bd08f3aba16726acd8f0252cfc6af06
child 263238 dd7c2ecaca68c4b2844ddd5db0cbb00dfc9567a6
push id4718
push userraliiev@mozilla.com
push dateMon, 11 May 2015 18:39:53 +0000
treeherdermozilla-beta@c20c4ef55f08 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersMattN
bugs1142110
milestone39.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 1142110 - Add a simple browser-chrome test for the popup notifications. r=MattN
toolkit/components/passwordmgr/test/browser/browser.ini
toolkit/components/passwordmgr/test/browser/browser_notifications.js
toolkit/components/passwordmgr/test/browser/form_basic.html
toolkit/modules/PopupNotifications.jsm
--- a/toolkit/components/passwordmgr/test/browser/browser.ini
+++ b/toolkit/components/passwordmgr/test/browser/browser.ini
@@ -1,10 +1,12 @@
 [DEFAULT]
 support-files =
   authenticate.sjs
+  form_basic.html
 
+[browser_notifications.js]
 [browser_passwordmgr_fields.js]
 [browser_passwordmgr_observers.js]
 [browser_passwordmgr_sort.js]
 [browser_passwordmgr_switchtab.js]
 [browser_passwordmgrcopypwd.js]
 [browser_passwordmgrdlg.js]
new file mode 100644
--- /dev/null
+++ b/toolkit/components/passwordmgr/test/browser/browser_notifications.js
@@ -0,0 +1,33 @@
+/* Any copyright is dedicated to the Public Domain.
+ * http://creativecommons.org/publicdomain/zero/1.0/ */
+
+add_task(function* test_save() {
+  let tab = gBrowser.addTab("https://example.com/browser/toolkit/components/" +
+                            "passwordmgr/test/browser/form_basic.html");
+  let browser = tab.linkedBrowser;
+  yield BrowserTestUtils.browserLoaded(browser);
+  gBrowser.selectedTab = tab;
+
+  let promiseShown = BrowserTestUtils.waitForEvent(PopupNotifications.panel,
+                                                   "Shown");
+  yield ContentTask.spawn(browser, null, function* () {
+    content.document.getElementById("form-basic-username").value = "username";
+    content.document.getElementById("form-basic-password").value = "password";
+    content.document.getElementById("form-basic").submit();
+  });
+  yield promiseShown;
+  let notificationElement = PopupNotifications.panel.childNodes[0];
+
+  let promiseLogin = TestUtils.topicObserved("passwordmgr-storage-changed",
+                                             (_, data) => data == "addLogin");
+  notificationElement.button.doCommand();
+  let [login] = yield promiseLogin;
+  login.QueryInterface(Ci.nsILoginInfo);
+
+  Assert.equal(login.username, "username");
+  Assert.equal(login.password, "password");
+
+  // Cleanup.
+  Services.logins.removeAllLogins();
+  gBrowser.removeTab(tab);
+});
new file mode 100644
--- /dev/null
+++ b/toolkit/components/passwordmgr/test/browser/form_basic.html
@@ -0,0 +1,12 @@
+<!DOCTYPE html><html><head><meta charset="utf-8"></head><body>
+<!-- Any copyright is dedicated to the Public Domain.
+   - http://creativecommons.org/publicdomain/zero/1.0/ -->
+
+<!-- Simplest form with username and password fields. -->
+<form id="form-basic">
+  <input id="form-basic-username" name="username">
+  <input id="form-basic-password" name="password" type="password">
+  <input id="form-basic-submit" type="submit">
+</form>
+
+</body></html>
--- a/toolkit/modules/PopupNotifications.jsm
+++ b/toolkit/modules/PopupNotifications.jsm
@@ -639,16 +639,19 @@ PopupNotifications.prototype = {
       notificationsToShow.forEach(function (n) {
         // Remember the time the notification was shown for the security delay.
         n.timeShown = this.window.performance.now();
       }, this);
       this.panel.openPopup(anchorElement, "bottomcenter topleft");
       notificationsToShow.forEach(function (n) {
         this._fireCallback(n, NOTIFICATION_EVENT_SHOWN);
       }, this);
+      // This notification is used by tests to know when all the processing
+      // required to display the panel has happened.
+      this.panel.dispatchEvent(new this.window.CustomEvent("Shown"));
     });
   },
 
   /**
    * Updates the notification state in response to window activation or tab
    * selection changes.
    *
    * @param notifications an array of Notification instances. if null,