summaryrefslogtreecommitdiffstats
path: root/toolkit/components/passwordmgr/test/browser/browser_capture_doorhanger.js
blob: b6bfdbf50489b9a3609528ed6efaf54b0aceb9b7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
/*
 * Test capture popup notifications
 */

const BRAND_BUNDLE = Services.strings.createBundle("chrome://branding/locale/brand.properties");
const BRAND_SHORT_NAME = BRAND_BUNDLE.GetStringFromName("brandShortName");

let nsLoginInfo = new Components.Constructor("@mozilla.org/login-manager/loginInfo;1",
                                             Ci.nsILoginInfo, "init");
let login1 = new nsLoginInfo("http://example.com", "http://example.com", null,
                             "notifyu1", "notifyp1", "user", "pass");
let login2 = new nsLoginInfo("http://example.com", "http://example.com", null,
                             "", "notifyp1", "", "pass");
let login1B = new nsLoginInfo("http://example.com", "http://example.com", null,
                              "notifyu1B", "notifyp1B", "user", "pass");
let login2B = new nsLoginInfo("http://example.com", "http://example.com", null,
                              "", "notifyp1B", "", "pass");

requestLongerTimeout(2);

add_task(function* setup() {
  // Load recipes for this test.
  let recipeParent = yield LoginManagerParent.recipeParentPromise;
  yield recipeParent.load({
    siteRecipes: [{
      hosts: ["example.org"],
      usernameSelector: "#user",
      passwordSelector: "#pass",
    }],
  });
});

add_task(function* test_remember_opens() {
  yield testSubmittingLoginForm("subtst_notifications_1.html", function*(fieldValues) {
    is(fieldValues.username, "notifyu1", "Checking submitted username");
    is(fieldValues.password, "notifyp1", "Checking submitted password");
    let notif = getCaptureDoorhanger("password-save");
    ok(notif, "got notification popup");
    notif.remove();
  });
});

add_task(function* test_clickNever() {
  yield testSubmittingLoginForm("subtst_notifications_1.html", function*(fieldValues) {
    is(fieldValues.username, "notifyu1", "Checking submitted username");
    is(fieldValues.password, "notifyp1", "Checking submitted password");
    let notif = getCaptureDoorhanger("password-save");
    ok(notif, "got notification popup");
    is(true, Services.logins.getLoginSavingEnabled("http://example.com"),
       "Checking for login saving enabled");

    yield* checkDoorhangerUsernamePassword("notifyu1", "notifyp1");
    clickDoorhangerButton(notif, NEVER_BUTTON);
  });

  is(Services.logins.getAllLogins().length, 0, "Should not have any logins yet");

  info("Make sure Never took effect");
  yield testSubmittingLoginForm("subtst_notifications_1.html", function*(fieldValues) {
    is(fieldValues.username, "notifyu1", "Checking submitted username");
    is(fieldValues.password, "notifyp1", "Checking submitted password");
    let notif = getCaptureDoorhanger("password-save");
    ok(!notif, "checking for no notification popup");
    is(false, Services.logins.getLoginSavingEnabled("http://example.com"),
       "Checking for login saving disabled");
    Services.logins.setLoginSavingEnabled("http://example.com", true);
  });

  is(Services.logins.getAllLogins().length, 0, "Should not have any logins yet");
});

add_task(function* test_clickRemember() {
  yield testSubmittingLoginForm("subtst_notifications_1.html", function*(fieldValues) {
    is(fieldValues.username, "notifyu1", "Checking submitted username");
    is(fieldValues.password, "notifyp1", "Checking submitted password");
    let notif = getCaptureDoorhanger("password-save");
    ok(notif, "got notification popup");

    is(Services.logins.getAllLogins().length, 0, "Should not have any logins yet");

    yield* checkDoorhangerUsernamePassword("notifyu1", "notifyp1");
    clickDoorhangerButton(notif, REMEMBER_BUTTON);
  });

  let logins = Services.logins.getAllLogins();
  is(logins.length, 1, "Should only have 1 login");
  let login = logins[0].QueryInterface(Ci.nsILoginMetaInfo);
  is(login.username, "notifyu1", "Check the username used on the new entry");
  is(login.password, "notifyp1", "Check the password used on the new entry");
  is(login.timesUsed, 1, "Check times used on new entry");

  info("Make sure Remember took effect and we don't prompt for an existing login");
  yield testSubmittingLoginForm("subtst_notifications_1.html", function*(fieldValues) {
    is(fieldValues.username, "notifyu1", "Checking submitted username");
    is(fieldValues.password, "notifyp1", "Checking submitted password");
    let notif = getCaptureDoorhanger("password-save");
    ok(!notif, "checking for no notification popup");
  });

  logins = Services.logins.getAllLogins();
  is(logins.length, 1, "Should only have 1 login");
  login = logins[0].QueryInterface(Ci.nsILoginMetaInfo);
  is(login.username, "notifyu1", "Check the username used");
  is(login.password, "notifyp1", "Check the password used");
  is(login.timesUsed, 2, "Check times used incremented");

  checkOnlyLoginWasUsedTwice({ justChanged: false });

  // remove that login
  Services.logins.removeLogin(login1);
});

/* signons.rememberSignons pref tests... */

add_task(function* test_rememberSignonsFalse() {
  info("Make sure we don't prompt with rememberSignons=false");
  Services.prefs.setBoolPref("signon.rememberSignons", false);

  yield testSubmittingLoginForm("subtst_notifications_1.html", function*(fieldValues) {
    is(fieldValues.username, "notifyu1", "Checking submitted username");
    is(fieldValues.password, "notifyp1", "Checking submitted password");
    let notif = getCaptureDoorhanger("password-save");
    ok(!notif, "checking for no notification popup");
  });

  is(Services.logins.getAllLogins().length, 0, "Should not have any logins yet");
});

add_task(function* test_rememberSignonsTrue() {
  info("Make sure we prompt with rememberSignons=true");
  Services.prefs.setBoolPref("signon.rememberSignons", true);

  yield testSubmittingLoginForm("subtst_notifications_1.html", function*(fieldValues) {
    is(fieldValues.username, "notifyu1", "Checking submitted username");
    is(fieldValues.password, "notifyp1", "Checking submitted password");
    let notif = getCaptureDoorhanger("password-save");
    ok(notif, "got notification popup");
    notif.remove();
  });

  is(Services.logins.getAllLogins().length, 0, "Should not have any logins yet");
});

/* autocomplete=off tests... */

add_task(function* test_autocompleteOffUsername() {
  info("Check for notification popup when autocomplete=off present on username");

  yield testSubmittingLoginForm("subtst_notifications_2.html", function*(fieldValues) {
    is(fieldValues.username, "notifyu1", "Checking submitted username");
    is(fieldValues.password, "notifyp1", "Checking submitted password");
    let notif = getCaptureDoorhanger("password-save");
    ok(notif, "checking for notification popup");
    notif.remove();
  });

  is(Services.logins.getAllLogins().length, 0, "Should not have any logins yet");
});

add_task(function* test_autocompleteOffPassword() {
  info("Check for notification popup when autocomplete=off present on password");

  yield testSubmittingLoginForm("subtst_notifications_3.html", function*(fieldValues) {
    is(fieldValues.username, "notifyu1", "Checking submitted username");
    is(fieldValues.password, "notifyp1", "Checking submitted password");
    let notif = getCaptureDoorhanger("password-save");
    ok(notif, "checking for notification popup");
    notif.remove();
  });

  is(Services.logins.getAllLogins().length, 0, "Should not have any logins yet");
});

add_task(function* test_autocompleteOffForm() {
  info("Check for notification popup when autocomplete=off present on form");

  yield testSubmittingLoginForm("subtst_notifications_4.html", function*(fieldValues) {
    is(fieldValues.username, "notifyu1", "Checking submitted username");
    is(fieldValues.password, "notifyp1", "Checking submitted password");
    let notif = getCaptureDoorhanger("password-save");
    ok(notif, "checking for notification popup");
    notif.remove();
  });

  is(Services.logins.getAllLogins().length, 0, "Should not have any logins yet");
});


add_task(function* test_noPasswordField() {
  info("Check for no notification popup when no password field present");

  yield testSubmittingLoginForm("subtst_notifications_5.html", function*(fieldValues) {
    is(fieldValues.username, "notifyu1", "Checking submitted username");
    is(fieldValues.password, "null", "Checking submitted password");
    let notif = getCaptureDoorhanger("password-save");
    ok(!notif, "checking for no notification popup");
  });

  is(Services.logins.getAllLogins().length, 0, "Should not have any logins yet");
});

add_task(function* test_pwOnlyLoginMatchesForm() {
  info("Check for update popup when existing pw-only login matches form.");
  Services.logins.addLogin(login2);

  yield testSubmittingLoginForm("subtst_notifications_1.html", function*(fieldValues) {
    is(fieldValues.username, "notifyu1", "Checking submitted username");
    is(fieldValues.password, "notifyp1", "Checking submitted password");
    let notif = getCaptureDoorhanger("password-change");
    ok(notif, "checking for notification popup");
    notif.remove();
  });

  let logins = Services.logins.getAllLogins();
  is(logins.length, 1, "Should only have 1 login");
  let login = logins[0].QueryInterface(Ci.nsILoginMetaInfo);
  is(login.username, "", "Check the username");
  is(login.password, "notifyp1", "Check the password");
  is(login.timesUsed, 1, "Check times used");

  Services.logins.removeLogin(login2);
});

add_task(function* test_pwOnlyFormMatchesLogin() {
  info("Check for no notification popup when pw-only form matches existing login.");
  Services.logins.addLogin(login1);

  yield testSubmittingLoginForm("subtst_notifications_6.html", function*(fieldValues) {
    is(fieldValues.username, "null", "Checking submitted username");
    is(fieldValues.password, "notifyp1", "Checking submitted password");
    let notif = getCaptureDoorhanger("password-save");
    ok(!notif, "checking for no notification popup");
  });

  let logins = Services.logins.getAllLogins();
  is(logins.length, 1, "Should only have 1 login");
  let login = logins[0].QueryInterface(Ci.nsILoginMetaInfo);
  is(login.username, "notifyu1", "Check the username");
  is(login.password, "notifyp1", "Check the password");
  is(login.timesUsed, 2, "Check times used");

  Services.logins.removeLogin(login1);
});

add_task(function* test_pwOnlyFormDoesntMatchExisting() {
  info("Check for notification popup when pw-only form doesn't match existing login.");
  Services.logins.addLogin(login1B);

  yield testSubmittingLoginForm("subtst_notifications_6.html", function*(fieldValues) {
    is(fieldValues.username, "null", "Checking submitted username");
    is(fieldValues.password, "notifyp1", "Checking submitted password");
    let notif = getCaptureDoorhanger("password-save");
    ok(notif, "got notification popup");
    notif.remove();
  });

  let logins = Services.logins.getAllLogins();
  is(logins.length, 1, "Should only have 1 login");
  let login = logins[0].QueryInterface(Ci.nsILoginMetaInfo);
  is(login.username, "notifyu1B", "Check the username unchanged");
  is(login.password, "notifyp1B", "Check the password unchanged");
  is(login.timesUsed, 1, "Check times used");

  Services.logins.removeLogin(login1B);
});

add_task(function* test_changeUPLoginOnUPForm_dont() {
  info("Check for change-password popup, u+p login on u+p form. (not changed)");
  Services.logins.addLogin(login1);

  yield testSubmittingLoginForm("subtst_notifications_8.html", function*(fieldValues) {
    is(fieldValues.username, "notifyu1", "Checking submitted username");
    is(fieldValues.password, "pass2", "Checking submitted password");
    let notif = getCaptureDoorhanger("password-change");
    ok(notif, "got notification popup");

    yield* checkDoorhangerUsernamePassword("notifyu1", "pass2");
    clickDoorhangerButton(notif, DONT_CHANGE_BUTTON);
  });

  let logins = Services.logins.getAllLogins();
  is(logins.length, 1, "Should only have 1 login");
  let login = logins[0].QueryInterface(Ci.nsILoginMetaInfo);
  is(login.username, "notifyu1", "Check the username unchanged");
  is(login.password, "notifyp1", "Check the password unchanged");
  is(login.timesUsed, 1, "Check times used");

  Services.logins.removeLogin(login1);
});

add_task(function* test_changeUPLoginOnUPForm_change() {
  info("Check for change-password popup, u+p login on u+p form.");
  Services.logins.addLogin(login1);

  yield testSubmittingLoginForm("subtst_notifications_8.html", function*(fieldValues) {
    is(fieldValues.username, "notifyu1", "Checking submitted username");
    is(fieldValues.password, "pass2", "Checking submitted password");
    let notif = getCaptureDoorhanger("password-change");
    ok(notif, "got notification popup");

    yield* checkDoorhangerUsernamePassword("notifyu1", "pass2");
    clickDoorhangerButton(notif, CHANGE_BUTTON);

    ok(!getCaptureDoorhanger("password-change"), "popup should be gone");
  });

  let logins = Services.logins.getAllLogins();
  is(logins.length, 1, "Should only have 1 login");
  let login = logins[0].QueryInterface(Ci.nsILoginMetaInfo);
  is(login.username, "notifyu1", "Check the username unchanged");
  is(login.password, "pass2", "Check the password changed");
  is(login.timesUsed, 2, "Check times used");

  checkOnlyLoginWasUsedTwice({ justChanged: true });

  // cleanup
  login1.password = "pass2";
  Services.logins.removeLogin(login1);
  login1.password = "notifyp1";
});

add_task(function* test_changePLoginOnUPForm() {
  info("Check for change-password popup, p-only login on u+p form.");
  Services.logins.addLogin(login2);

  yield testSubmittingLoginForm("subtst_notifications_9.html", function*(fieldValues) {
    is(fieldValues.username, "", "Checking submitted username");
    is(fieldValues.password, "pass2", "Checking submitted password");
    let notif = getCaptureDoorhanger("password-change");
    ok(notif, "got notification popup");

    yield* checkDoorhangerUsernamePassword("", "pass2");
    clickDoorhangerButton(notif, CHANGE_BUTTON);

    ok(!getCaptureDoorhanger("password-change"), "popup should be gone");
  });

  let logins = Services.logins.getAllLogins();
  is(logins.length, 1, "Should only have 1 login");
  let login = logins[0].QueryInterface(Ci.nsILoginMetaInfo);
  is(login.username, "", "Check the username unchanged");
  is(login.password, "pass2", "Check the password changed");
  is(login.timesUsed, 2, "Check times used");

  // no cleanup -- saved password to be used in the next test.
});

add_task(function* test_changePLoginOnPForm() {
  info("Check for change-password popup, p-only login on p-only form.");

  yield testSubmittingLoginForm("subtst_notifications_10.html", function*(fieldValues) {
    is(fieldValues.username, "null", "Checking submitted username");
    is(fieldValues.password, "notifyp1", "Checking submitted password");
    let notif = getCaptureDoorhanger("password-change");
    ok(notif, "got notification popup");

    yield* checkDoorhangerUsernamePassword("", "notifyp1");
    clickDoorhangerButton(notif, CHANGE_BUTTON);

    ok(!getCaptureDoorhanger("password-change"), "popup should be gone");
  });

  let logins = Services.logins.getAllLogins();
  is(logins.length, 1, "Should only have 1 login");
  let login = logins[0].QueryInterface(Ci.nsILoginMetaInfo);
  is(login.username, "", "Check the username unchanged");
  is(login.password, "notifyp1", "Check the password changed");
  is(login.timesUsed, 3, "Check times used");

  Services.logins.removeLogin(login2);
});

add_task(function* test_checkUPSaveText() {
  info("Check text on a user+pass notification popup");

  yield testSubmittingLoginForm("subtst_notifications_1.html", function*(fieldValues) {
    is(fieldValues.username, "notifyu1", "Checking submitted username");
    is(fieldValues.password, "notifyp1", "Checking submitted password");
    let notif = getCaptureDoorhanger("password-save");
    ok(notif, "got notification popup");
    // Check the text, which comes from the localized saveLoginText string.
    let notificationText = notif.message;
    let expectedText = "Would you like " + BRAND_SHORT_NAME + " to remember this login?";
    is(expectedText, notificationText, "Checking text: " + notificationText);
    notif.remove();
  });

  is(Services.logins.getAllLogins().length, 0, "Should not have any logins yet");
});

add_task(function* test_checkPSaveText() {
  info("Check text on a pass-only notification popup");

  yield testSubmittingLoginForm("subtst_notifications_6.html", function*(fieldValues) {
    is(fieldValues.username, "null", "Checking submitted username");
    is(fieldValues.password, "notifyp1", "Checking submitted password");
    let notif = getCaptureDoorhanger("password-save");
    ok(notif, "got notification popup");
    // Check the text, which comes from the localized saveLoginTextNoUser string.
    let notificationText = notif.message;
    let expectedText = "Would you like " + BRAND_SHORT_NAME + " to remember this password?";
    is(expectedText, notificationText, "Checking text: " + notificationText);
    notif.remove();
  });

  is(Services.logins.getAllLogins().length, 0, "Should not have any logins yet");
});

add_task(function* test_capture2pw0un() {
  info("Check for notification popup when a form with 2 password fields (no username) " +
       "is submitted and there are no saved logins.");

  yield testSubmittingLoginForm("subtst_notifications_2pw_0un.html", function*(fieldValues) {
    is(fieldValues.username, "null", "Checking submitted username");
    is(fieldValues.password, "notifyp1", "Checking submitted password");
    let notif = getCaptureDoorhanger("password-save");
    ok(notif, "got notification popup");
    notif.remove();
  });

  is(Services.logins.getAllLogins().length, 0, "Should not have any logins yet");
});

add_task(function* test_change2pw0unExistingDifferentUP() {
  info("Check for notification popup when a form with 2 password fields (no username) " +
       "is submitted and there is a saved login with a username and different password.");

  Services.logins.addLogin(login1B);

  yield testSubmittingLoginForm("subtst_notifications_2pw_0un.html", function*(fieldValues) {
    is(fieldValues.username, "null", "Checking submitted username");
    is(fieldValues.password, "notifyp1", "Checking submitted password");
    let notif = getCaptureDoorhanger("password-change");
    ok(notif, "got notification popup");
    notif.remove();
  });

  let logins = Services.logins.getAllLogins();
  is(logins.length, 1, "Should only have 1 login");
  let login = logins[0].QueryInterface(Ci.nsILoginMetaInfo);
  is(login.username, "notifyu1B", "Check the username unchanged");
  is(login.password, "notifyp1B", "Check the password unchanged");
  is(login.timesUsed, 1, "Check times used");

  Services.logins.removeLogin(login1B);
});

add_task(function* test_change2pw0unExistingDifferentP() {
  info("Check for notification popup when a form with 2 password fields (no username) " +
       "is submitted and there is a saved login with no username and different password.");

  Services.logins.addLogin(login2B);

  yield testSubmittingLoginForm("subtst_notifications_2pw_0un.html", function*(fieldValues) {
    is(fieldValues.username, "null", "Checking submitted username");
    is(fieldValues.password, "notifyp1", "Checking submitted password");
    let notif = getCaptureDoorhanger("password-change");
    ok(notif, "got notification popup");
    notif.remove();
  });

  let logins = Services.logins.getAllLogins();
  is(logins.length, 1, "Should only have 1 login");
  let login = logins[0].QueryInterface(Ci.nsILoginMetaInfo);
  is(login.username, "", "Check the username unchanged");
  is(login.password, "notifyp1B", "Check the password unchanged");
  is(login.timesUsed, 1, "Check times used");

  Services.logins.removeLogin(login2B);
});

add_task(function* test_change2pw0unExistingWithSameP() {
  info("Check for no notification popup when a form with 2 password fields (no username) " +
       "is submitted and there is a saved login with a username and the same password.");

  Services.logins.addLogin(login2);

  yield testSubmittingLoginForm("subtst_notifications_2pw_0un.html", function*(fieldValues) {
    is(fieldValues.username, "null", "Checking submitted username");
    is(fieldValues.password, "notifyp1", "Checking submitted password");
    let notif = getCaptureDoorhanger("password-change");
    ok(!notif, "checking for no notification popup");
  });

  let logins = Services.logins.getAllLogins();
  is(logins.length, 1, "Should only have 1 login");
  let login = logins[0].QueryInterface(Ci.nsILoginMetaInfo);
  is(login.username, "", "Check the username unchanged");
  is(login.password, "notifyp1", "Check the password unchanged");
  is(login.timesUsed, 2, "Check times used incremented");

  checkOnlyLoginWasUsedTwice({ justChanged: false });

  Services.logins.removeLogin(login2);
});

add_task(function* test_changeUPLoginOnPUpdateForm() {
  info("Check for change-password popup, u+p login on password update form.");
  Services.logins.addLogin(login1);

  yield testSubmittingLoginForm("subtst_notifications_change_p.html", function*(fieldValues) {
    is(fieldValues.username, "null", "Checking submitted username");
    is(fieldValues.password, "pass2", "Checking submitted password");
    let notif = getCaptureDoorhanger("password-change");
    ok(notif, "got notification popup");

    yield* checkDoorhangerUsernamePassword("notifyu1", "pass2");
    clickDoorhangerButton(notif, CHANGE_BUTTON);

    ok(!getCaptureDoorhanger("password-change"), "popup should be gone");
  });

  let logins = Services.logins.getAllLogins();
  is(logins.length, 1, "Should only have 1 login");
  let login = logins[0].QueryInterface(Ci.nsILoginMetaInfo);
  is(login.username, "notifyu1", "Check the username unchanged");
  is(login.password, "pass2", "Check the password changed");
  is(login.timesUsed, 2, "Check times used");

  checkOnlyLoginWasUsedTwice({ justChanged: true });

  // cleanup
  login1.password = "pass2";
  Services.logins.removeLogin(login1);
  login1.password = "notifyp1";
});

add_task(function* test_recipeCaptureFields_NewLogin() {
  info("Check that we capture the proper fields when a field recipe is in use.");

  yield testSubmittingLoginForm("subtst_notifications_2pw_1un_1text.html", function*(fieldValues) {
    is(fieldValues.username, "notifyu1", "Checking submitted username");
    is(fieldValues.password, "notifyp1", "Checking submitted password");
    let notif = getCaptureDoorhanger("password-save");
    ok(notif, "got notification popup");

    // Sanity check, no logins should exist yet.
    let logins = Services.logins.getAllLogins();
    is(logins.length, 0, "Should not have any logins yet");

    yield* checkDoorhangerUsernamePassword("notifyu1", "notifyp1");
    clickDoorhangerButton(notif, REMEMBER_BUTTON);

  }, "http://example.org"); // The recipe is for example.org

  let logins = Services.logins.getAllLogins();
  is(logins.length, 1, "Should only have 1 login");
  let login = logins[0].QueryInterface(Ci.nsILoginMetaInfo);
  is(login.username, "notifyu1", "Check the username unchanged");
  is(login.password, "notifyp1", "Check the password unchanged");
  is(login.timesUsed, 1, "Check times used");
});

add_task(function* test_recipeCaptureFields_ExistingLogin() {
  info("Check that we capture the proper fields when a field recipe is in use " +
       "and there is a matching login");

  yield testSubmittingLoginForm("subtst_notifications_2pw_1un_1text.html", function*(fieldValues) {
    is(fieldValues.username, "notifyu1", "Checking submitted username");
    is(fieldValues.password, "notifyp1", "Checking submitted password");
    let notif = getCaptureDoorhanger("password-save");
    ok(!notif, "checking for no notification popup");
  }, "http://example.org");

  checkOnlyLoginWasUsedTwice({ justChanged: false });
  let logins = Services.logins.getAllLogins();
  is(logins.length, 1, "Should only have 1 login");
  let login = logins[0].QueryInterface(Ci.nsILoginMetaInfo);
  is(login.username, "notifyu1", "Check the username unchanged");
  is(login.password, "notifyp1", "Check the password unchanged");
  is(login.timesUsed, 2, "Check times used incremented");

  Services.logins.removeAllLogins();
});

add_task(function* test_noShowPasswordOnDismissal() {
  info("Check for no Show Password field when the doorhanger is dismissed");

  yield testSubmittingLoginForm("subtst_notifications_1.html", function*(fieldValues) {
    info("Opening popup");
    let notif = getCaptureDoorhanger("password-save");
    let { panel } = PopupNotifications;

    info("Hiding popup.");
    let promiseHidden = BrowserTestUtils.waitForEvent(panel, "popuphidden");
    panel.hidePopup();
    yield promiseHidden;

    info("Clicking on anchor to reshow popup.");
    let promiseShown = BrowserTestUtils.waitForEvent(panel, "popupshown");
    notif.anchorElement.click();
    yield promiseShown;

    let passwordVisiblityToggle = panel.querySelector("#password-notification-visibilityToggle");
    is(passwordVisiblityToggle.hidden, true, "Check that the Show Password field is Hidden");
  });
});

// TODO:
// * existing login test, form has different password --> change password, no save prompt