toolkit/components/passwordmgr/test/test_notifications_popup.html

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/toolkit/components/passwordmgr/test/test_notifications_popup.html	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,203 @@
     1.4 +<!DOCTYPE html>
     1.5 +<html>
     1.6 +<head>
     1.7 +  <meta charset="utf-8"/>
     1.8 +  <title>Test for Login Manager in popup Windows</title>
     1.9 +  <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
    1.10 +  <script type="text/javascript" src="pwmgr_common.js"></script>
    1.11 +  <script type="text/javascript" src="notification_common.js"></script>
    1.12 +  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
    1.13 +</head>
    1.14 +<body>
    1.15 +Login Manager test: notifications in popup windows
    1.16 +<p id="display"></p>
    1.17 +
    1.18 +<div id="content" style="display: none">
    1.19 +  <iframe id="iframe"></iframe>
    1.20 +</div>
    1.21 +
    1.22 +<pre id="test">
    1.23 +<script class="testbody" type="text/javascript">
    1.24 +
    1.25 +/** Test for Login Manager: notifications in popup windows.
    1.26 +
    1.27 +Test flow:
    1.28 +  1) runNextTest starts the sub-tests by loading them into the iframe.
    1.29 +  2) The subtests trigger a PopupNotification which trigger checkTest (from the
    1.30 +     panel event listener).
    1.31 +  3) An action is taken on the notification which triggers the
    1.32 +     passwordmgr-storage-changed observer that calls runNextTest (from step 1).
    1.33 +**/
    1.34 +
    1.35 +
    1.36 +var subtests = [
    1.37 +                // query arguments are: username, password, features, auto-close (delimited by '|')
    1.38 +                "subtst_notifications_11.html?notifyu1|notifyp1|menubar=no,toolbar=no,location=no|autoclose",  // 1
    1.39 +                "subtst_notifications_11.html?notifyu1|pass2|menubar=no,toolbar=no,location=no|autoclose",     // 2
    1.40 +                "subtst_notifications_11.html?notifyu2|notifyp2||",  // 3
    1.41 +                "subtst_notifications_11.html?notifyu2|pass2||",     // 4
    1.42 +               ];
    1.43 +
    1.44 +function runNextTest() {
    1.45 +    testNum++;
    1.46 +    ok(true, "Starting test #" + testNum);
    1.47 +    if (testNum <= subtests.length) {
    1.48 +        iframe.src = subtests[testNum-1];
    1.49 +    } else {
    1.50 +        // final check which will call finish
    1.51 +        checkTest();
    1.52 +    }
    1.53 +}
    1.54 +
    1.55 +PasswordMgrObserver = {
    1.56 +  observe: function passwordMgrObserver_observe(subject, topic, data) {
    1.57 +      // Only run the next test for actions triggered from a doorhanger (rather
    1.58 +      // than cleanup with removeLogin)
    1.59 +      if (data == "removeLogin")
    1.60 +          return;
    1.61 +      runNextTest();
    1.62 +  },
    1.63 +};
    1.64 +
    1.65 +// Remember, Never for This Site, Not Now
    1.66 +function checkTest() {
    1.67 +    var popup, login, logins;
    1.68 +
    1.69 +    switch(testNum) {
    1.70 +
    1.71 +      case 1:
    1.72 +        popup = getPopup(popupNotifications, "password-save");
    1.73 +        ok(popup, "got notification popup");
    1.74 +        // Sanity check, no logins should exist yet.
    1.75 +        logins = pwmgr.getAllLogins();
    1.76 +        is(logins.length, 0, "Should not have any logins yet");
    1.77 +
    1.78 +        // password-save with chrome hidden
    1.79 +        clickPopupButton(popup, kRememberButton);
    1.80 +        break;
    1.81 +
    1.82 +      case 2:
    1.83 +        // Check result of clicking kRememberButton
    1.84 +        logins = pwmgr.getAllLogins();
    1.85 +        is(logins.length, 1, "Should only have 1 login");
    1.86 +        login = SpecialPowers.wrap(logins[0]).QueryInterface(Ci.nsILoginMetaInfo);
    1.87 +        ok(login.timesUsed, 1, "Check times used on new entry");
    1.88 +
    1.89 +        // password-change with chrome hidden
    1.90 +        popup = getPopup(popupNotifications, "password-change");
    1.91 +        ok(popup, "got notification popup");
    1.92 +        clickPopupButton(popup, kChangeButton);
    1.93 +        break;
    1.94 +
    1.95 +      case 3:
    1.96 +        // Check to make sure we updated the password, timestamps and use count for
    1.97 +        // the login being changed with this form.
    1.98 +        logins = pwmgr.getAllLogins();
    1.99 +        is(logins.length, 1, "Should only have 1 login");
   1.100 +        login = SpecialPowers.wrap(logins[0]).QueryInterface(Ci.nsILoginMetaInfo);
   1.101 +        is(login.password, "pass2", "Check password changed");
   1.102 +        is(login.timesUsed, 2, "check .timesUsed incremented on change");
   1.103 +        ok(login.timeCreated < login.timeLastUsed, "timeLastUsed bumped");
   1.104 +        ok(login.timeLastUsed == login.timePasswordChanged, "timeUsed == timeChanged");
   1.105 +
   1.106 +        login1.password = "pass2";
   1.107 +        pwmgr.removeLogin(login1);
   1.108 +        login1.password = "notifyp1";
   1.109 +
   1.110 +        // password-save with chrome visible
   1.111 +        var popupWin = iframe.contentWindow.popupWin;
   1.112 +        ok(popupWin, "Check popupWin is accessible");
   1.113 +        var popupNotificationsInPopup = getPopupNotifications(popupWin);
   1.114 +        ok(popupNotificationsInPopup, "Got popupNotificationsInPopup");
   1.115 +        popup = getPopup(popupNotificationsInPopup, "password-save");
   1.116 +        ok(popup, "got notification popup");
   1.117 +        clickPopupButton(popup, kRememberButton);
   1.118 +        popupWin.close();
   1.119 +        break;
   1.120 +
   1.121 +      case 4:
   1.122 +        // Check result of clicking kRememberButton
   1.123 +        logins = pwmgr.getAllLogins();
   1.124 +        is(logins.length, 1, "Should only have 1 login now");
   1.125 +        login = SpecialPowers.wrap(logins[0]).QueryInterface(Ci.nsILoginMetaInfo);
   1.126 +        ok(login.timesUsed, 1, "Check times used on new entry");
   1.127 +
   1.128 +        // password-change with chrome visible
   1.129 +        var popupWin = iframe.contentWindow.popupWin;
   1.130 +        ok(popupWin, "Check popupWin is accessible");
   1.131 +        var popupNotificationsInPopup = getPopupNotifications(popupWin);
   1.132 +        ok(popupNotificationsInPopup, "Got popupNotificationsInPopup");
   1.133 +        popup = getPopup(popupNotificationsInPopup, "password-change");
   1.134 +        ok(popup, "got notification popup");
   1.135 +        clickPopupButton(popup, kChangeButton);
   1.136 +        popupWin.close();
   1.137 +        break;
   1.138 +
   1.139 +      case 5:
   1.140 +        // Check to make sure we updated the password, timestamps and use count for
   1.141 +        // the login being changed with this form.
   1.142 +        logins = pwmgr.getAllLogins();
   1.143 +        is(logins.length, 1, "Should have 1 login");
   1.144 +        login = SpecialPowers.wrap(logins[0]).QueryInterface(Ci.nsILoginMetaInfo);
   1.145 +        is(login.password, "pass2", "Check password changed");
   1.146 +        is(login.timesUsed, 2, "check .timesUsed incremented on change");
   1.147 +        ok(login.timeCreated < login.timeLastUsed, "timeLastUsed bumped");
   1.148 +        ok(login.timeLastUsed == login.timePasswordChanged, "timeUsed == timeChanged");
   1.149 +
   1.150 +        // cleanup
   1.151 +        SpecialPowers.removeObserver(PasswordMgrObserver, "passwordmgr-storage-changed");
   1.152 +        popupNotifications.panel.removeEventListener("popupshown", checkTest, false);
   1.153 +
   1.154 +        login2.password = "pass2";
   1.155 +        pwmgr.removeLogin(login2);
   1.156 +        login2.password = "notifyp2";
   1.157 +
   1.158 +        ok(true, "notification tests finished.");
   1.159 +        SimpleTest.finish();
   1.160 +
   1.161 +        break;
   1.162 +
   1.163 +      default:
   1.164 +        ok(false, "Unexpected call to checkTest for test #" + testNum);
   1.165 +
   1.166 +    }
   1.167 +}
   1.168 +
   1.169 +const Ci = SpecialPowers.Ci;
   1.170 +const Cc = SpecialPowers.Cc;
   1.171 +ok(Ci != null, "Access Ci");
   1.172 +ok(Cc != null, "Access Cc");
   1.173 +
   1.174 +var pwmgr = Cc["@mozilla.org/login-manager;1"].
   1.175 +            getService(Ci.nsILoginManager);
   1.176 +ok(pwmgr != null, "Access pwmgr");
   1.177 +
   1.178 +pwmgr.removeAllLogins();
   1.179 +
   1.180 +var nsLoginInfo = new SpecialPowers.wrap(SpecialPowers.Components).
   1.181 +                      Constructor("@mozilla.org/login-manager/loginInfo;1",
   1.182 +                                  Ci.nsILoginInfo, "init");
   1.183 +var login1 = new nsLoginInfo("http://mochi.test:8888", "http://mochi.test:8888", null,
   1.184 +                             "notifyu1", "notifyp1", "user", "pass");
   1.185 +var login2 = new nsLoginInfo("http://mochi.test:8888", "http://mochi.test:8888", null,
   1.186 +                             "notifyu2", "notifyp2", "user", "pass");
   1.187 +
   1.188 +SpecialPowers.addObserver(PasswordMgrObserver, "passwordmgr-storage-changed", false);
   1.189 +
   1.190 +// popupNotifications (not *popup*) is a constant, per-tab container. So, we
   1.191 +// only need to fetch it once.
   1.192 +var popupNotifications = getPopupNotifications(window.top);
   1.193 +ok(popupNotifications, "Got popupNotifications");
   1.194 +
   1.195 +popupNotifications.panel.addEventListener("popupshown", checkTest, false);
   1.196 +
   1.197 +var iframe = document.getElementById("iframe");
   1.198 +var testNum = 0;
   1.199 +
   1.200 +SimpleTest.waitForFocus(runNextTest);
   1.201 +
   1.202 +SimpleTest.waitForExplicitFinish();
   1.203 +</script>
   1.204 +</pre>
   1.205 +</body>
   1.206 +</html>

mercurial