toolkit/components/passwordmgr/test/test_notifications_popup.html

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

michael@0 1 <!DOCTYPE html>
michael@0 2 <html>
michael@0 3 <head>
michael@0 4 <meta charset="utf-8"/>
michael@0 5 <title>Test for Login Manager in popup Windows</title>
michael@0 6 <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
michael@0 7 <script type="text/javascript" src="pwmgr_common.js"></script>
michael@0 8 <script type="text/javascript" src="notification_common.js"></script>
michael@0 9 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
michael@0 10 </head>
michael@0 11 <body>
michael@0 12 Login Manager test: notifications in popup windows
michael@0 13 <p id="display"></p>
michael@0 14
michael@0 15 <div id="content" style="display: none">
michael@0 16 <iframe id="iframe"></iframe>
michael@0 17 </div>
michael@0 18
michael@0 19 <pre id="test">
michael@0 20 <script class="testbody" type="text/javascript">
michael@0 21
michael@0 22 /** Test for Login Manager: notifications in popup windows.
michael@0 23
michael@0 24 Test flow:
michael@0 25 1) runNextTest starts the sub-tests by loading them into the iframe.
michael@0 26 2) The subtests trigger a PopupNotification which trigger checkTest (from the
michael@0 27 panel event listener).
michael@0 28 3) An action is taken on the notification which triggers the
michael@0 29 passwordmgr-storage-changed observer that calls runNextTest (from step 1).
michael@0 30 **/
michael@0 31
michael@0 32
michael@0 33 var subtests = [
michael@0 34 // query arguments are: username, password, features, auto-close (delimited by '|')
michael@0 35 "subtst_notifications_11.html?notifyu1|notifyp1|menubar=no,toolbar=no,location=no|autoclose", // 1
michael@0 36 "subtst_notifications_11.html?notifyu1|pass2|menubar=no,toolbar=no,location=no|autoclose", // 2
michael@0 37 "subtst_notifications_11.html?notifyu2|notifyp2||", // 3
michael@0 38 "subtst_notifications_11.html?notifyu2|pass2||", // 4
michael@0 39 ];
michael@0 40
michael@0 41 function runNextTest() {
michael@0 42 testNum++;
michael@0 43 ok(true, "Starting test #" + testNum);
michael@0 44 if (testNum <= subtests.length) {
michael@0 45 iframe.src = subtests[testNum-1];
michael@0 46 } else {
michael@0 47 // final check which will call finish
michael@0 48 checkTest();
michael@0 49 }
michael@0 50 }
michael@0 51
michael@0 52 PasswordMgrObserver = {
michael@0 53 observe: function passwordMgrObserver_observe(subject, topic, data) {
michael@0 54 // Only run the next test for actions triggered from a doorhanger (rather
michael@0 55 // than cleanup with removeLogin)
michael@0 56 if (data == "removeLogin")
michael@0 57 return;
michael@0 58 runNextTest();
michael@0 59 },
michael@0 60 };
michael@0 61
michael@0 62 // Remember, Never for This Site, Not Now
michael@0 63 function checkTest() {
michael@0 64 var popup, login, logins;
michael@0 65
michael@0 66 switch(testNum) {
michael@0 67
michael@0 68 case 1:
michael@0 69 popup = getPopup(popupNotifications, "password-save");
michael@0 70 ok(popup, "got notification popup");
michael@0 71 // Sanity check, no logins should exist yet.
michael@0 72 logins = pwmgr.getAllLogins();
michael@0 73 is(logins.length, 0, "Should not have any logins yet");
michael@0 74
michael@0 75 // password-save with chrome hidden
michael@0 76 clickPopupButton(popup, kRememberButton);
michael@0 77 break;
michael@0 78
michael@0 79 case 2:
michael@0 80 // Check result of clicking kRememberButton
michael@0 81 logins = pwmgr.getAllLogins();
michael@0 82 is(logins.length, 1, "Should only have 1 login");
michael@0 83 login = SpecialPowers.wrap(logins[0]).QueryInterface(Ci.nsILoginMetaInfo);
michael@0 84 ok(login.timesUsed, 1, "Check times used on new entry");
michael@0 85
michael@0 86 // password-change with chrome hidden
michael@0 87 popup = getPopup(popupNotifications, "password-change");
michael@0 88 ok(popup, "got notification popup");
michael@0 89 clickPopupButton(popup, kChangeButton);
michael@0 90 break;
michael@0 91
michael@0 92 case 3:
michael@0 93 // Check to make sure we updated the password, timestamps and use count for
michael@0 94 // the login being changed with this form.
michael@0 95 logins = pwmgr.getAllLogins();
michael@0 96 is(logins.length, 1, "Should only have 1 login");
michael@0 97 login = SpecialPowers.wrap(logins[0]).QueryInterface(Ci.nsILoginMetaInfo);
michael@0 98 is(login.password, "pass2", "Check password changed");
michael@0 99 is(login.timesUsed, 2, "check .timesUsed incremented on change");
michael@0 100 ok(login.timeCreated < login.timeLastUsed, "timeLastUsed bumped");
michael@0 101 ok(login.timeLastUsed == login.timePasswordChanged, "timeUsed == timeChanged");
michael@0 102
michael@0 103 login1.password = "pass2";
michael@0 104 pwmgr.removeLogin(login1);
michael@0 105 login1.password = "notifyp1";
michael@0 106
michael@0 107 // password-save with chrome visible
michael@0 108 var popupWin = iframe.contentWindow.popupWin;
michael@0 109 ok(popupWin, "Check popupWin is accessible");
michael@0 110 var popupNotificationsInPopup = getPopupNotifications(popupWin);
michael@0 111 ok(popupNotificationsInPopup, "Got popupNotificationsInPopup");
michael@0 112 popup = getPopup(popupNotificationsInPopup, "password-save");
michael@0 113 ok(popup, "got notification popup");
michael@0 114 clickPopupButton(popup, kRememberButton);
michael@0 115 popupWin.close();
michael@0 116 break;
michael@0 117
michael@0 118 case 4:
michael@0 119 // Check result of clicking kRememberButton
michael@0 120 logins = pwmgr.getAllLogins();
michael@0 121 is(logins.length, 1, "Should only have 1 login now");
michael@0 122 login = SpecialPowers.wrap(logins[0]).QueryInterface(Ci.nsILoginMetaInfo);
michael@0 123 ok(login.timesUsed, 1, "Check times used on new entry");
michael@0 124
michael@0 125 // password-change with chrome visible
michael@0 126 var popupWin = iframe.contentWindow.popupWin;
michael@0 127 ok(popupWin, "Check popupWin is accessible");
michael@0 128 var popupNotificationsInPopup = getPopupNotifications(popupWin);
michael@0 129 ok(popupNotificationsInPopup, "Got popupNotificationsInPopup");
michael@0 130 popup = getPopup(popupNotificationsInPopup, "password-change");
michael@0 131 ok(popup, "got notification popup");
michael@0 132 clickPopupButton(popup, kChangeButton);
michael@0 133 popupWin.close();
michael@0 134 break;
michael@0 135
michael@0 136 case 5:
michael@0 137 // Check to make sure we updated the password, timestamps and use count for
michael@0 138 // the login being changed with this form.
michael@0 139 logins = pwmgr.getAllLogins();
michael@0 140 is(logins.length, 1, "Should have 1 login");
michael@0 141 login = SpecialPowers.wrap(logins[0]).QueryInterface(Ci.nsILoginMetaInfo);
michael@0 142 is(login.password, "pass2", "Check password changed");
michael@0 143 is(login.timesUsed, 2, "check .timesUsed incremented on change");
michael@0 144 ok(login.timeCreated < login.timeLastUsed, "timeLastUsed bumped");
michael@0 145 ok(login.timeLastUsed == login.timePasswordChanged, "timeUsed == timeChanged");
michael@0 146
michael@0 147 // cleanup
michael@0 148 SpecialPowers.removeObserver(PasswordMgrObserver, "passwordmgr-storage-changed");
michael@0 149 popupNotifications.panel.removeEventListener("popupshown", checkTest, false);
michael@0 150
michael@0 151 login2.password = "pass2";
michael@0 152 pwmgr.removeLogin(login2);
michael@0 153 login2.password = "notifyp2";
michael@0 154
michael@0 155 ok(true, "notification tests finished.");
michael@0 156 SimpleTest.finish();
michael@0 157
michael@0 158 break;
michael@0 159
michael@0 160 default:
michael@0 161 ok(false, "Unexpected call to checkTest for test #" + testNum);
michael@0 162
michael@0 163 }
michael@0 164 }
michael@0 165
michael@0 166 const Ci = SpecialPowers.Ci;
michael@0 167 const Cc = SpecialPowers.Cc;
michael@0 168 ok(Ci != null, "Access Ci");
michael@0 169 ok(Cc != null, "Access Cc");
michael@0 170
michael@0 171 var pwmgr = Cc["@mozilla.org/login-manager;1"].
michael@0 172 getService(Ci.nsILoginManager);
michael@0 173 ok(pwmgr != null, "Access pwmgr");
michael@0 174
michael@0 175 pwmgr.removeAllLogins();
michael@0 176
michael@0 177 var nsLoginInfo = new SpecialPowers.wrap(SpecialPowers.Components).
michael@0 178 Constructor("@mozilla.org/login-manager/loginInfo;1",
michael@0 179 Ci.nsILoginInfo, "init");
michael@0 180 var login1 = new nsLoginInfo("http://mochi.test:8888", "http://mochi.test:8888", null,
michael@0 181 "notifyu1", "notifyp1", "user", "pass");
michael@0 182 var login2 = new nsLoginInfo("http://mochi.test:8888", "http://mochi.test:8888", null,
michael@0 183 "notifyu2", "notifyp2", "user", "pass");
michael@0 184
michael@0 185 SpecialPowers.addObserver(PasswordMgrObserver, "passwordmgr-storage-changed", false);
michael@0 186
michael@0 187 // popupNotifications (not *popup*) is a constant, per-tab container. So, we
michael@0 188 // only need to fetch it once.
michael@0 189 var popupNotifications = getPopupNotifications(window.top);
michael@0 190 ok(popupNotifications, "Got popupNotifications");
michael@0 191
michael@0 192 popupNotifications.panel.addEventListener("popupshown", checkTest, false);
michael@0 193
michael@0 194 var iframe = document.getElementById("iframe");
michael@0 195 var testNum = 0;
michael@0 196
michael@0 197 SimpleTest.waitForFocus(runNextTest);
michael@0 198
michael@0 199 SimpleTest.waitForExplicitFinish();
michael@0 200 </script>
michael@0 201 </pre>
michael@0 202 </body>
michael@0 203 </html>

mercurial