4 <title>Test for Login Manager
</title>
5 <script type=
"text/javascript" src=
"/MochiKit/MochiKit.js"></script>
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" />
12 Login Manager test: notifications
15 <div id=
"content" style=
"display: none">
16 <iframe id=
"iframe"></iframe>
20 <script class=
"testbody" type=
"text/javascript">
22 /** Test for Login Manager: notifications. **/
25 "subtst_notifications_1.html", //
1
26 "subtst_notifications_1.html", //
2
27 "subtst_notifications_1.html", //
3
28 "subtst_notifications_1.html", //
4
29 "subtst_notifications_1.html", //
5
30 "subtst_notifications_1.html", //
6
31 "subtst_notifications_1.html", //
7
32 "subtst_notifications_1.html", //
8
33 "subtst_notifications_2.html", //
9
34 "subtst_notifications_3.html", //
10
35 "subtst_notifications_4.html", //
11
36 "subtst_notifications_5.html", //
12
37 "subtst_notifications_1.html", //
13
38 "subtst_notifications_6.html", //
14
39 "subtst_notifications_1.html", //
15
40 "subtst_notifications_6.html", //
16
41 "subtst_notifications_8.html", //
17
42 "subtst_notifications_8.html", //
18
43 "subtst_notifications_9.html", //
19
44 "subtst_notifications_10.html" //
20
48 var ignoreLoad = false;
49 function handleLoad(aEvent) {
50 netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
52 // ignore every other load event ... We get one for loading the subtest (which
53 // we want to ignore), and another when the subtest's form submits itself
54 // (which we want to handle, to start the next test).
55 ignoreLoad = !ignoreLoad;
57 ok(true,
"Ignoring load of subtest #" + testNum);
60 ok(true,
"Processing submission of subtest #" + testNum);
67 // Remove any notification bar that might be lingering from a failed test.
68 notifyBox.removeAllNotifications(true);
70 if (testNum <= subtests.length) {
71 ok(true,
"Starting test #" + testNum);
72 iframe.src = subtests[testNum-
1];
74 ok(true,
"notification tests finished.");
80 // Remember, Never for This Site, Not Now
81 function checkTest() {
84 // The document generated from formsubmit.sjs contains the user/pass it
85 // received inside
<span id=
"blah">value
</span>
86 var gotUser = iframe.contentDocument.getElementById(
"user").textContent;
87 var gotPass = iframe.contentDocument.getElementById(
"pass").textContent;
92 /* Basic Yes/No/Never tests... */
95 is(gotUser,
"notifyu1",
"Checking submitted username");
96 is(gotPass,
"notifyp1",
"Checking submitted password");
97 bar = getNotificationBar(notifyBox,
"password-save");
98 ok(bar,
"got notification bar");
99 clickNotificationButton(bar,
"Not Now");
103 // Same subtest, this time click Never
104 is(gotUser,
"notifyu1",
"Checking submitted username");
105 is(gotPass,
"notifyp1",
"Checking submitted password");
106 bar = getNotificationBar(notifyBox,
"password-save");
107 ok(bar,
"got notification bar");
108 is(true, pwmgr.getLoginSavingEnabled(
"http://localhost:8888"),
109 "Checking for login saving enabled");
110 clickNotificationButton(bar,
"Never for This Site");
114 // Same subtest, make sure Never took effect
115 is(gotUser,
"notifyu1",
"Checking submitted username");
116 is(gotPass,
"notifyp1",
"Checking submitted password");
117 bar = getNotificationBar(notifyBox,
"password-save");
118 ok(!bar,
"checking for no notification bar");
119 is(false, pwmgr.getLoginSavingEnabled(
"http://localhost:8888"),
120 "Checking for login saving disabled");
121 // reenable login saving.
122 pwmgr.setLoginSavingEnabled(
"http://localhost:8888", true);
126 // Same subtest, this time click Remember
127 is(gotUser,
"notifyu1",
"Checking submitted username");
128 is(gotPass,
"notifyp1",
"Checking submitted password");
129 bar = getNotificationBar(notifyBox,
"password-save");
130 ok(bar,
"got notification bar");
131 clickNotificationButton(bar,
"Remember");
135 // Same subtest, make sure we didn't prompt for an existing login.
136 is(gotUser,
"notifyu1",
"Checking submitted username");
137 is(gotPass,
"notifyp1",
"Checking submitted password");
138 bar = getNotificationBar(notifyBox,
"password-save");
139 ok(!bar,
"checking for no notification bar");
141 pwmgr.removeLogin(login1);
144 /* signons.rememberSignons pref tests... */
147 // Same subtest, make sure we're getting the bar again.
148 is(gotUser,
"notifyu1",
"Checking submitted username");
149 is(gotPass,
"notifyp1",
"Checking submitted password");
150 bar = getNotificationBar(notifyBox,
"password-save");
151 ok(bar,
"got notification bar");
152 clickNotificationButton(bar,
"Not Now");
153 // Change prefs to no longer remember signons
154 prefs.setBoolPref(
"rememberSignons", false);
158 // Same subtest, make sure we're not prompting.
159 is(gotUser,
"notifyu1",
"Checking submitted username");
160 is(gotPass,
"notifyp1",
"Checking submitted password");
161 bar = getNotificationBar(notifyBox,
"password-save");
162 ok(!bar,
"checking for no notification bar");
163 // Change prefs to remember signons again
164 prefs.setBoolPref(
"rememberSignons", true);
168 // Same subtest, make sure we're getting the bar again.
169 is(gotUser,
"notifyu1",
"Checking submitted username");
170 is(gotPass,
"notifyp1",
"Checking submitted password");
171 bar = getNotificationBar(notifyBox,
"password-save");
172 ok(bar,
"got notification bar");
173 clickNotificationButton(bar,
"Not Now");
176 /* autocomplete=off tests... */
179 // Check for no notification bar when autocomplete=off present
180 is(gotUser,
"notifyu1",
"Checking submitted username");
181 is(gotPass,
"notifyp1",
"Checking submitted password");
182 bar = getNotificationBar(notifyBox,
"password-save");
183 ok(!bar,
"checking for no notification bar");
187 // Check for no notification bar when autocomplete=off present
188 is(gotUser,
"notifyu1",
"Checking submitted username");
189 is(gotPass,
"notifyp1",
"Checking submitted password");
190 bar = getNotificationBar(notifyBox,
"password-save");
191 ok(!bar,
"checking for no notification bar");
195 // Check for no notification bar when autocomplete=off present
196 is(gotUser,
"notifyu1",
"Checking submitted username");
197 is(gotPass,
"notifyp1",
"Checking submitted password");
198 bar = getNotificationBar(notifyBox,
"password-save");
199 ok(!bar,
"checking for no notification bar");
202 /* no password field test... */
205 // Check for no notification bar when no password field present
206 is(gotUser,
"notifyu1",
"Checking submitted username");
207 is(gotPass,
"null",
"Checking submitted password");
208 bar = getNotificationBar(notifyBox,
"password-save");
209 ok(!bar,
"checking for no notification bar");
211 // Add login for the next test.
212 pwmgr.addLogin(login2);
216 // Check for no notification bar when existing pw-only login matches form.
217 is(gotUser,
"notifyu1",
"Checking submitted username");
218 is(gotPass,
"notifyp1",
"Checking submitted password");
219 bar = getNotificationBar(notifyBox,
"password-save");
220 ok(!bar,
"checking for no notification bar");
221 pwmgr.removeLogin(login2);
223 // Add login for the next test
224 pwmgr.addLogin(login1);
228 // Check for no notification bar when pw-only form matches existing login.
229 is(gotUser,
"null",
"Checking submitted username");
230 is(gotPass,
"notifyp1",
"Checking submitted password");
231 bar = getNotificationBar(notifyBox,
"password-save");
232 ok(!bar,
"checking for no notification bar");
233 pwmgr.removeLogin(login1);
235 // Add login for the next test
236 pwmgr.addLogin(login2B);
240 // Check for notification bar when existing pw-only login doesn't match form.
241 is(gotUser,
"notifyu1",
"Checking submitted username");
242 is(gotPass,
"notifyp1",
"Checking submitted password");
243 bar = getNotificationBar(notifyBox,
"password-save");
244 ok(bar,
"got notification bar");
245 clickNotificationButton(bar,
"Not Now");
246 pwmgr.removeLogin(login2B);
248 // Add login for the next test
249 pwmgr.addLogin(login1B);
253 // Check for notification bar when pw-only form doesn't match existing login.
254 is(gotUser,
"null",
"Checking submitted username");
255 is(gotPass,
"notifyp1",
"Checking submitted password");
256 bar = getNotificationBar(notifyBox,
"password-save");
257 ok(bar,
"got notification bar");
258 clickNotificationButton(bar,
"Not Now");
259 pwmgr.removeLogin(login1B);
261 // Add login for the next tests
262 pwmgr.addLogin(login1);
266 // Check for change-password bar, u+p login on u+p form. (not changed)
267 is(gotUser,
"notifyu1",
"Checking submitted username");
268 is(gotPass,
"pass2",
"Checking submitted password");
269 bar = getNotificationBar(notifyBox,
"password-change");
270 ok(bar,
"got notification bar");
271 clickNotificationButton(bar,
"Don't Change");
275 // Check for change-password bar, u+p login on u+p form.
276 is(gotUser,
"notifyu1",
"Checking submitted username");
277 is(gotPass,
"pass2",
"Checking submitted password");
278 bar = getNotificationBar(notifyBox,
"password-change");
279 ok(bar,
"got notification bar");
280 clickNotificationButton(bar,
"Change");
283 login1.password =
"pass2";
284 pwmgr.removeLogin(login1);
285 login1.password =
"notifyp1";
287 // Add login for the next test
288 pwmgr.addLogin(login2);
291 // ...can't change a u+p login on a p-only form...
294 // Check for change-password bar, p-only login on u+p form.
295 // (needed a different subtest for this because the login created in
296 // test_0init was interfering)
297 is(gotUser,
"",
"Checking submitted username");
298 is(gotPass,
"pass2",
"Checking submitted password");
299 bar = getNotificationBar(notifyBox,
"password-change");
300 ok(bar,
"got notification bar");
301 clickNotificationButton(bar,
"Change");
305 // Check for change-password bar, p-only login on p-only form.
306 is(gotUser,
"null",
"Checking submitted username");
307 is(gotPass,
"notifyp1",
"Checking submitted password");
308 bar = getNotificationBar(notifyBox,
"password-change");
309 ok(bar,
"got notification bar");
310 clickNotificationButton(bar,
"Change");
312 pwmgr.removeLogin(login2);
316 ok(false,
"Unexpected call to checkTest for test #" + testNum);
321 // * existing login test, form has different password --> change password, no save prompt
325 netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
327 const Ci = Components.interfaces;
328 const Cc = Components.classes;
329 ok(Ci != null,
"Access Ci");
330 ok(Cc != null,
"Access Cc");
332 var pwmgr = Cc[
"@mozilla.org/login-manager;1"].
333 getService(Ci.nsILoginManager);
334 ok(pwmgr != null,
"Access pwmgr");
336 var prefs = Cc[
"@mozilla.org/preferences-service;1"].
337 getService(Ci.nsIPrefService);
338 ok(prefs != null,
"Access prefs");
339 prefs = prefs.getBranch(
"signon.");
340 ok(prefs != null,
"Access pref branch");
342 var nsLoginInfo = new Components.Constructor(
"@mozilla.org/login-manager/loginInfo;1",
343 Ci.nsILoginInfo,
"init");
344 var login1 = new nsLoginInfo(
"http://localhost:8888",
"http://localhost:8888", null,
345 "notifyu1",
"notifyp1",
"user",
"pass");
346 var login2 = new nsLoginInfo(
"http://localhost:8888",
"http://localhost:8888", null,
347 "",
"notifyp1",
"",
"pass");
348 var login1B = new nsLoginInfo(
"http://localhost:8888",
"http://localhost:8888", null,
349 "notifyu1B",
"notifyp1B",
"user",
"pass");
350 var login2B = new nsLoginInfo(
"http://localhost:8888",
"http://localhost:8888", null,
351 "",
"notifyp1B",
"",
"pass");
353 var iframe = document.getElementById(
"iframe");
354 iframe.onload = handleLoad;
356 // The notification box (not *bar*) is a constant, per-tab container. So, we
357 // only need to fetch it once.
358 var notifyBox = getNotificationBox(window.top);
359 ok(notifyBox,
"Got notification box");
361 // Remove any notification bars that might be left over from other tests.
362 notifyBox.removeAllNotifications(true);
365 ok(true,
"Starting test #" + testNum);
366 iframe.src = subtests[testNum-
1];
368 SimpleTest.waitForExplicitFinish();