@@ -245,7 +245,6 @@ class PasswordAccessoryControllerTest : public ChromeRenderViewHostTestHarness {
245
245
std::make_unique<StrictMock<MockPasswordAccessoryView>>(),
246
246
mock_dialog_factory_.Get ());
247
247
NavigateAndCommit (GURL (" https://example.com" ));
248
- FocusWebContentsOnMainFrame ();
249
248
}
250
249
251
250
PasswordAccessoryController* controller () {
@@ -287,8 +286,10 @@ TEST_F(PasswordAccessoryControllerTest, TransformsMatchesToSuggestions) {
287
286
288
287
controller ()->SavePasswordsForOrigin ({CreateEntry (" Ben" , " S3cur3" ).first },
289
288
url::Origin::Create (GURL (kExampleSite )));
290
- controller ()->RefreshSuggestionsForField (/* is_fillable=*/ true ,
291
- /* is_password_field=*/ false );
289
+ controller ()->RefreshSuggestionsForField (
290
+ url::Origin::Create (GURL (kExampleSite )),
291
+ /* is_fillable=*/ true ,
292
+ /* is_password_field=*/ false );
292
293
}
293
294
294
295
TEST_F (PasswordAccessoryControllerTest, HintsToEmptyUserNames) {
@@ -304,8 +305,10 @@ TEST_F(PasswordAccessoryControllerTest, HintsToEmptyUserNames) {
304
305
305
306
controller ()->SavePasswordsForOrigin ({CreateEntry (" " , " S3cur3" ).first },
306
307
url::Origin::Create (GURL (kExampleSite )));
307
- controller ()->RefreshSuggestionsForField (/* is_fillable=*/ true ,
308
- /* is_password_field=*/ false );
308
+ controller ()->RefreshSuggestionsForField (
309
+ url::Origin::Create (GURL (kExampleSite )),
310
+ /* is_fillable=*/ true ,
311
+ /* is_password_field=*/ false );
309
312
}
310
313
311
314
TEST_F (PasswordAccessoryControllerTest, SortsAlphabeticalDuringTransform) {
@@ -338,8 +341,10 @@ TEST_F(PasswordAccessoryControllerTest, SortsAlphabeticalDuringTransform) {
338
341
{CreateEntry (" Ben" , " S3cur3" ).first , CreateEntry (" Zebra" , " M3h" ).first ,
339
342
CreateEntry (" Alf" , " PWD" ).first , CreateEntry (" Cat" , " M1@u" ).first },
340
343
url::Origin::Create (GURL (kExampleSite )));
341
- controller ()->RefreshSuggestionsForField (/* is_fillable=*/ true ,
342
- /* is_password_field=*/ false );
344
+ controller ()->RefreshSuggestionsForField (
345
+ url::Origin::Create (GURL (kExampleSite )),
346
+ /* is_fillable=*/ true ,
347
+ /* is_password_field=*/ false );
343
348
}
344
349
345
350
TEST_F (PasswordAccessoryControllerTest, RepeatsSuggestionsForSameFrame) {
@@ -357,8 +362,10 @@ TEST_F(PasswordAccessoryControllerTest, RepeatsSuggestionsForSameFrame) {
357
362
url::Origin::Create (GURL (kExampleSite )));
358
363
359
364
// Pretend that any input in the same frame was focused.
360
- controller ()->RefreshSuggestionsForField (/* is_fillable=*/ true ,
361
- /* is_fillable=*/ false );
365
+ controller ()->RefreshSuggestionsForField (
366
+ url::Origin::Create (GURL (kExampleSite )),
367
+ /* is_fillable=*/ true ,
368
+ /* is_fillable=*/ false );
362
369
}
363
370
364
371
TEST_F (PasswordAccessoryControllerTest, ProvidesEmptySuggestionsMessage) {
@@ -370,8 +377,10 @@ TEST_F(PasswordAccessoryControllerTest, ProvidesEmptySuggestionsMessage) {
370
377
371
378
controller ()->SavePasswordsForOrigin ({},
372
379
url::Origin::Create (GURL (kExampleSite )));
373
- controller ()->RefreshSuggestionsForField (/* is_fillable=*/ true ,
374
- /* is_password_field=*/ false );
380
+ controller ()->RefreshSuggestionsForField (
381
+ url::Origin::Create (GURL (kExampleSite )),
382
+ /* is_fillable=*/ true ,
383
+ /* is_password_field=*/ false );
375
384
}
376
385
377
386
TEST_F (PasswordAccessoryControllerTest, RelaysAutomaticGenerationAvailable) {
@@ -439,8 +448,10 @@ TEST_F(PasswordAccessoryControllerTest, PasswordFieldChangesSuggestionType) {
439
448
// This should result in the non-interactive suggestion expected above.
440
449
controller ()->SavePasswordsForOrigin ({CreateEntry (" Ben" , " S3cur3" ).first },
441
450
url::Origin::Create (GURL (kExampleSite )));
442
- controller ()->RefreshSuggestionsForField (/* is_fillable=*/ true ,
443
- /* is_password_field=*/ false );
451
+ controller ()->RefreshSuggestionsForField (
452
+ url::Origin::Create (GURL (kExampleSite )),
453
+ /* is_fillable=*/ true ,
454
+ /* is_password_field=*/ false );
444
455
445
456
// Pretend that we focus a password field now: By triggering a refresh with
446
457
// |is_password_field| set to true, all suggestions should become interactive.
@@ -452,8 +463,10 @@ TEST_F(PasswordAccessoryControllerTest, PasswordFieldChangesSuggestionType) {
452
463
MatchesItem (ASCIIToUTF16 (" S3cur3" ), password_for_str (" Ben" ),
453
464
true , ItemType::SUGGESTION),
454
465
IsDivider (), MatchesOption (manage_passwords_str ()))));
455
- controller ()->RefreshSuggestionsForField (/* is_fillable=*/ true ,
456
- /* is_password_field=*/ true );
466
+ controller ()->RefreshSuggestionsForField (
467
+ url::Origin::Create (GURL (kExampleSite )),
468
+ /* is_fillable=*/ true ,
469
+ /* is_password_field=*/ true );
457
470
}
458
471
459
472
TEST_F (PasswordAccessoryControllerTest, CachesIsReplacedByNewPasswords) {
@@ -467,8 +480,10 @@ TEST_F(PasswordAccessoryControllerTest, CachesIsReplacedByNewPasswords) {
467
480
IsDivider (), MatchesOption (manage_passwords_str ()))));
468
481
controller ()->SavePasswordsForOrigin ({CreateEntry (" Ben" , " S3cur3" ).first },
469
482
url::Origin::Create (GURL (kExampleSite )));
470
- controller ()->RefreshSuggestionsForField (/* is_fillable=*/ true ,
471
- /* is_password_field=*/ false );
483
+ controller ()->RefreshSuggestionsForField (
484
+ url::Origin::Create (GURL (kExampleSite )),
485
+ /* is_fillable=*/ true ,
486
+ /* is_password_field=*/ false );
472
487
473
488
EXPECT_CALL (*view (),
474
489
OnItemsAvailable (ElementsAre (
@@ -480,6 +495,38 @@ TEST_F(PasswordAccessoryControllerTest, CachesIsReplacedByNewPasswords) {
480
495
IsDivider (), MatchesOption (manage_passwords_str ()))));
481
496
controller ()->SavePasswordsForOrigin ({CreateEntry (" Alf" , " M3lm4k" ).first },
482
497
url::Origin::Create (GURL (kExampleSite )));
483
- controller ()->RefreshSuggestionsForField (/* is_fillable=*/ true ,
484
- /* is_password_field=*/ false );
498
+ controller ()->RefreshSuggestionsForField (
499
+ url::Origin::Create (GURL (kExampleSite )),
500
+ /* is_fillable=*/ true ,
501
+ /* is_password_field=*/ false );
502
+ }
503
+
504
+ TEST_F (PasswordAccessoryControllerTest, UnfillableFieldClearsSuggestions) {
505
+ EXPECT_CALL (*view (),
506
+ OnItemsAvailable (ElementsAre (
507
+ MatchesLabel (passwords_title_str (kExampleDomain )),
508
+ MatchesItem (ASCIIToUTF16 (" Ben" ), ASCIIToUTF16 (" Ben" ), false ,
509
+ ItemType::SUGGESTION),
510
+ MatchesItem (ASCIIToUTF16 (" S3cur3" ), password_for_str (" Ben" ),
511
+ true , ItemType::NON_INTERACTIVE_SUGGESTION),
512
+ IsDivider (), MatchesOption (manage_passwords_str ()))));
513
+ // Set any, non-empty password list and pretend a username field was focused.
514
+ // This should result in the non-emtpy suggestions expected above.
515
+ controller ()->SavePasswordsForOrigin ({CreateEntry (" Ben" , " S3cur3" ).first },
516
+ url::Origin::Create (GURL (kExampleSite )));
517
+ controller ()->RefreshSuggestionsForField (
518
+ url::Origin::Create (GURL (kExampleSite )),
519
+ /* is_fillable=*/ true ,
520
+ /* is_password_field=*/ false );
521
+
522
+ // Pretend that the focus was lost or moved to an unfillable field. Now, only
523
+ // the empty state message should be sent.
524
+ EXPECT_CALL (*view (),
525
+ OnItemsAvailable (ElementsAre (
526
+ MatchesLabel (passwords_empty_str (kExampleDomain )),
527
+ IsDivider (), MatchesOption (manage_passwords_str ()))));
528
+ controller ()->RefreshSuggestionsForField (
529
+ url::Origin::Create (GURL (kExampleSite )),
530
+ /* is_fillable=*/ false ,
531
+ /* is_password_field=*/ false ); // Unused.
485
532
}
0 commit comments