Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(17)

Side by Side Diff: components/password_manager/core/browser/password_autofill_manager_unittest.cc

Issue 962673004: [Autofill/Autocomplete Feature] Substring matching instead of prefix matching. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Incorporated Rouslan's review comments. Created 5 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "components/password_manager/core/browser/password_autofill_manager.h" 5 #include "components/password_manager/core/browser/password_autofill_manager.h"
6 6
7 #include "base/command_line.h"
7 #include "base/compiler_specific.h" 8 #include "base/compiler_specific.h"
8 #include "base/message_loop/message_loop.h" 9 #include "base/message_loop/message_loop.h"
9 #include "base/strings/utf_string_conversions.h" 10 #include "base/strings/utf_string_conversions.h"
10 #include "components/autofill/core/browser/popup_item_ids.h" 11 #include "components/autofill/core/browser/popup_item_ids.h"
11 #include "components/autofill/core/browser/suggestion_test_helpers.h" 12 #include "components/autofill/core/browser/suggestion_test_helpers.h"
12 #include "components/autofill/core/browser/test_autofill_client.h" 13 #include "components/autofill/core/browser/test_autofill_client.h"
13 #include "components/autofill/core/browser/test_autofill_driver.h" 14 #include "components/autofill/core/browser/test_autofill_driver.h"
14 #include "components/autofill/core/common/autofill_constants.h" 15 #include "components/autofill/core/common/autofill_constants.h"
16 #include "components/autofill/core/common/autofill_switches.h"
15 #include "components/autofill/core/common/form_field_data.h" 17 #include "components/autofill/core/common/form_field_data.h"
16 #include "components/autofill/core/common/password_form_fill_data.h" 18 #include "components/autofill/core/common/password_form_fill_data.h"
17 #include "components/password_manager/core/browser/stub_password_manager_client. h" 19 #include "components/password_manager/core/browser/stub_password_manager_client. h"
18 #include "components/password_manager/core/browser/stub_password_manager_driver. h" 20 #include "components/password_manager/core/browser/stub_password_manager_driver. h"
19 #include "components/strings/grit/components_strings.h" 21 #include "components/strings/grit/components_strings.h"
20 #include "testing/gmock/include/gmock/gmock.h" 22 #include "testing/gmock/include/gmock/gmock.h"
21 #include "testing/gtest/include/gtest/gtest.h" 23 #include "testing/gtest/include/gtest/gtest.h"
22 #include "ui/base/l10n/l10n_util.h" 24 #include "ui/base/l10n/l10n_util.h"
23 #include "ui/gfx/geometry/rect_f.h" 25 #include "ui/gfx/geometry/rect_f.h"
24 26
(...skipping 322 matching lines...) Expand 10 before | Expand all | Expand 10 after
347 element_bounds, _, 349 element_bounds, _,
348 SuggestionVectorValuesAre(testing::UnorderedElementsAre( 350 SuggestionVectorValuesAre(testing::UnorderedElementsAre(
349 title, 351 title,
350 test_username_)), 352 test_username_)),
351 _)); 353 _));
352 password_autofill_manager_->OnShowPasswordSuggestions( 354 password_autofill_manager_->OnShowPasswordSuggestions(
353 dummy_key, base::i18n::RIGHT_TO_LEFT, test_username_, 355 dummy_key, base::i18n::RIGHT_TO_LEFT, test_username_,
354 autofill::IS_PASSWORD_FIELD, element_bounds); 356 autofill::IS_PASSWORD_FIELD, element_bounds);
355 } 357 }
356 358
359 // Verify that typing "foo" into the username field will match usernames
360 // "foo.bar@example.com", "bar.foo@example.com" and "example@foo.com".
361 TEST_F(PasswordAutofillManagerTest, DisplaySuggestionsWithMatchingTokens) {
362 // Token matching is currently behind a flag.
363 base::CommandLine::ForCurrentProcess()->AppendSwitch(
364 autofill::switches::kEnableSuggestionsWithSubstringMatch);
365
366 scoped_ptr<TestPasswordManagerClient> client(new TestPasswordManagerClient);
367 scoped_ptr<MockAutofillClient> autofill_client(new MockAutofillClient);
368 InitializePasswordAutofillManager(client.get(), autofill_client.get());
369
370 gfx::RectF element_bounds;
371 autofill::PasswordFormFillData data;
372 base::string16 username = base::ASCIIToUTF16("foo.bar@example.com");
373 data.username_field.value = username;
374 data.password_field.value = base::ASCIIToUTF16("foobar");
375 data.preferred_realm = "http://foo.com/";
376
377 autofill::PasswordAndRealm additional;
378 additional.realm = "https://foobarrealm.org";
379 base::string16 additional_username(base::ASCIIToUTF16("bar.foo@example.com"));
380 data.additional_logins[additional_username] = additional;
381
382 autofill::UsernamesCollectionKey usernames_key;
383 usernames_key.realm = "http://yetanother.net";
384 std::vector<base::string16> other_names;
385 base::string16 other_username(base::ASCIIToUTF16("example@foo.com"));
386 other_names.push_back(other_username);
387 data.other_possible_usernames[usernames_key] = other_names;
388
389 int dummy_key = 0;
390 password_autofill_manager_->OnAddPasswordFormMapping(dummy_key, data);
391
392 // Simulate displaying suggestions for username field contents "foo", check
393 // that matching usernames "foo.bar@example.com", "bar.foo@example.com" and
394 // "example@foo.com" are displayed.
please use gerrit instead 2015/06/30 19:06:23 Redundant comment. Please delete.
Pritam Nikam 2015/07/01 17:26:00 Done.
395 EXPECT_CALL(
396 *autofill_client,
397 ShowAutofillPopup(element_bounds, _,
398 SuggestionVectorValuesAre(testing::UnorderedElementsAre(
399 username, additional_username, other_username)),
400 _));
401 password_autofill_manager_->OnShowPasswordSuggestions(
402 dummy_key, base::i18n::RIGHT_TO_LEFT, base::ASCIIToUTF16("foo"), false,
403 element_bounds);
404 }
405
406 // Verify that typing "oo" into the username field will not match any usernames
407 // "foo.bar@example.com", "bar.foo@example.com" or "example@foo.com".
408 TEST_F(PasswordAutofillManagerTest, NoSuggestionForNonPrefixTokenMatch) {
409 // Token matching is currently behind a flag.
410 base::CommandLine::ForCurrentProcess()->AppendSwitch(
411 autofill::switches::kEnableSuggestionsWithSubstringMatch);
412
413 scoped_ptr<TestPasswordManagerClient> client(new TestPasswordManagerClient);
414 scoped_ptr<MockAutofillClient> autofill_client(new MockAutofillClient);
415 InitializePasswordAutofillManager(client.get(), autofill_client.get());
416
417 gfx::RectF element_bounds;
418 autofill::PasswordFormFillData data;
419 base::string16 username = base::ASCIIToUTF16("foo.bar@example.com");
420 data.username_field.value = username;
421 data.password_field.value = base::ASCIIToUTF16("foobar");
422 data.preferred_realm = "http://foo.com/";
423
424 autofill::PasswordAndRealm additional;
425 additional.realm = "https://foobarrealm.org";
426 base::string16 additional_username(base::ASCIIToUTF16("bar.foo@example.com"));
427 data.additional_logins[additional_username] = additional;
428
429 autofill::UsernamesCollectionKey usernames_key;
430 usernames_key.realm = "http://yetanother.net";
431 std::vector<base::string16> other_names;
432 base::string16 other_username(base::ASCIIToUTF16("example@foo.com"));
433 other_names.push_back(other_username);
434 data.other_possible_usernames[usernames_key] = other_names;
435
436 int dummy_key = 0;
437 password_autofill_manager_->OnAddPasswordFormMapping(dummy_key, data);
438
439 // Simulate displaying suggestions for username field contents "oo". Check
440 // that none appear, because none of the usernames "foo.bar@example.com",
441 // "bar.foo@example.com" or "example@foo.com" has a token with a prefix "oo".
please use gerrit instead 2015/06/30 19:06:23 Redundant comment. Please delete.
Pritam Nikam 2015/07/01 17:26:00 Done.
442 EXPECT_CALL(*autofill_client, ShowAutofillPopup(_, _, _, _)).Times(0);
443
444 password_autofill_manager_->OnShowPasswordSuggestions(
445 dummy_key, base::i18n::RIGHT_TO_LEFT, base::ASCIIToUTF16("oo"), false,
446 element_bounds);
447 }
448
449 // Verify that typing "foo@exam" into the username field will not match username
450 // "bar.foo@example.com" as filed containts span accross multiple tokens.
please use gerrit instead 2015/06/30 19:06:23 s/field contains/field contents
Pritam Nikam 2015/07/01 17:26:00 Done.
451 TEST_F(PasswordAutofillManagerTest,
452 MatchingContentsWithSuggestionTokenSeparator) {
453 // Token matching is currently behind a flag.
454 base::CommandLine::ForCurrentProcess()->AppendSwitch(
455 autofill::switches::kEnableSuggestionsWithSubstringMatch);
456
457 scoped_ptr<TestPasswordManagerClient> client(new TestPasswordManagerClient);
458 scoped_ptr<MockAutofillClient> autofill_client(new MockAutofillClient);
459 InitializePasswordAutofillManager(client.get(), autofill_client.get());
460
461 gfx::RectF element_bounds;
462 autofill::PasswordFormFillData data;
463 base::string16 username = base::ASCIIToUTF16("foo.bar@example.com");
464 data.username_field.value = username;
465 data.password_field.value = base::ASCIIToUTF16("foobar");
466 data.preferred_realm = "http://foo.com/";
467
468 autofill::PasswordAndRealm additional;
469 additional.realm = "https://foobarrealm.org";
470 base::string16 additional_username(base::ASCIIToUTF16("bar.foo@example.com"));
471 data.additional_logins[additional_username] = additional;
472
473 autofill::UsernamesCollectionKey usernames_key;
474 usernames_key.realm = "http://yetanother.net";
475 std::vector<base::string16> other_names;
476 base::string16 other_username(base::ASCIIToUTF16("example@foo.com"));
477 other_names.push_back(other_username);
478 data.other_possible_usernames[usernames_key] = other_names;
479
480 int dummy_key = 0;
481 password_autofill_manager_->OnAddPasswordFormMapping(dummy_key, data);
482
483 // Simulate displaying suggestions for field contents "foo@exam". Because "@"
484 // is a token separator, the field contents cannot be a prefix of any
485 // suggestion token. Moreover, no suggestion starts with "foo@exam".
486 // Therefore, no suggestions should match.
487 EXPECT_CALL(*autofill_client, ShowAutofillPopup(_, _, _, _)).Times(0);
488 password_autofill_manager_->OnShowPasswordSuggestions(
489 dummy_key, base::i18n::RIGHT_TO_LEFT, base::ASCIIToUTF16("foo@exam"),
490 false, element_bounds);
491
492 // Simulate displaying suggestions for field contents "foo.bar@ex". Because
493 // "@" is a token separator, the field contents cannot be a prefix of any
494 // suggestion token. However, the suggestion "foo.bar@example.com" starts with
495 // "foo.bar@ex". That suggestion should be the only match.
please use gerrit instead 2015/06/30 19:06:23 Redundant comment. Please delete.
Pritam Nikam 2015/07/01 17:26:00 Done.
496 EXPECT_CALL(*autofill_client,
497 ShowAutofillPopup(element_bounds, _,
498 SuggestionVectorValuesAre(
499 testing::UnorderedElementsAre(username)),
500 _));
501 password_autofill_manager_->OnShowPasswordSuggestions(
502 dummy_key, base::i18n::RIGHT_TO_LEFT, base::ASCIIToUTF16("foo.bar@ex"),
503 false, element_bounds);
504 }
505
506 // Verify that typing "example" into the username field will match and order
507 // usernames "example@foo.com", "foo.bar@example.com" and "bar.foo@example.com"
508 // i.e. prefix matched followed by substring matched.
509 TEST_F(PasswordAutofillManagerTest,
510 DisplaySuggestionsWithPrefixesPrecedeSubstringMatched) {
511 // Token matching is currently behind a flag.
512 base::CommandLine::ForCurrentProcess()->AppendSwitch(
513 autofill::switches::kEnableSuggestionsWithSubstringMatch);
514
515 scoped_ptr<TestPasswordManagerClient> client(new TestPasswordManagerClient);
516 scoped_ptr<MockAutofillClient> autofill_client(new MockAutofillClient);
517 InitializePasswordAutofillManager(client.get(), autofill_client.get());
518
519 gfx::RectF element_bounds;
520 autofill::PasswordFormFillData data;
521 base::string16 username = base::ASCIIToUTF16("foo.bar@example.com");
522 data.username_field.value = username;
523 data.password_field.value = base::ASCIIToUTF16("foobar");
524 data.preferred_realm = "http://foo.com/";
525
526 autofill::PasswordAndRealm additional;
527 additional.realm = "https://foobarrealm.org";
528 base::string16 additional_username(base::ASCIIToUTF16("bar.foo@example.com"));
529 data.additional_logins[additional_username] = additional;
530
531 autofill::UsernamesCollectionKey usernames_key;
532 usernames_key.realm = "http://yetanother.net";
533 std::vector<base::string16> other_names;
534 base::string16 other_username(base::ASCIIToUTF16("example@foo.com"));
535 other_names.push_back(other_username);
536 data.other_possible_usernames[usernames_key] = other_names;
537
538 int dummy_key = 0;
539 password_autofill_manager_->OnAddPasswordFormMapping(dummy_key, data);
540
541 // Simulate displaying suggestions for field contents "example", check that
542 // matching ones are displayed with prefix matched username "example@foo.com"
543 // placed before substring matched usernames "foo.bar@example.com" and
544 // "bar.foo@example.com".
please use gerrit instead 2015/06/30 19:06:23 Redundant comment. Please delete.
Pritam Nikam 2015/07/01 17:26:00 Done.
545 EXPECT_CALL(
546 *autofill_client,
547 ShowAutofillPopup(element_bounds, _,
548 SuggestionVectorValuesAre(testing::UnorderedElementsAre(
549 other_username, username, additional_username)),
550 _));
551 password_autofill_manager_->OnShowPasswordSuggestions(
552 dummy_key, base::i18n::RIGHT_TO_LEFT, base::ASCIIToUTF16("foo"), false,
553 element_bounds);
554 }
555
357 } // namespace password_manager 556 } // namespace password_manager
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698