toolkit/components/passwordmgr/test/test_notifications_popup.html

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

mercurial