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

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: Added comments in autocomplete_history_manager.cc. 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 // Test that suggestion tokens (substrings separated by characters from
please use gerrit instead 2015/06/29 22:06:29 Please be more specific in this comment and the co
Pritam Nikam 2015/06/30 15:05:51 Done.
360 // " .,-_@") are matched against field contents.
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 field contents "foo", check that
393 // matching ones are displayed.
394 EXPECT_CALL(
395 *autofill_client,
396 ShowAutofillPopup(element_bounds, _,
397 SuggestionVectorValuesAre(testing::UnorderedElementsAre(
398 username, additional_username, other_username)),
399 _));
400 password_autofill_manager_->OnShowPasswordSuggestions(
401 dummy_key, base::i18n::RIGHT_TO_LEFT, base::ASCIIToUTF16("foo"), false,
402 element_bounds);
403 }
404
405 // Test that suggestions which do not have a prefix match or prefix-token match
406 // with the field contents are not matched.
407 TEST_F(PasswordAutofillManagerTest, NoSuggestionForNonPrefixTokenMatch) {
408 // Token matching is currently behind a flag.
409 base::CommandLine::ForCurrentProcess()->AppendSwitch(
410 autofill::switches::kEnableSuggestionsWithSubstringMatch);
411
412 scoped_ptr<TestPasswordManagerClient> client(new TestPasswordManagerClient);
413 scoped_ptr<MockAutofillClient> autofill_client(new MockAutofillClient);
414 InitializePasswordAutofillManager(client.get(), autofill_client.get());
415
416 gfx::RectF element_bounds;
417 autofill::PasswordFormFillData data;
418 base::string16 username = base::ASCIIToUTF16("foo.bar@example.com");
419 data.username_field.value = username;
420 data.password_field.value = base::ASCIIToUTF16("foobar");
421 data.preferred_realm = "http://foo.com/";
422
423 autofill::PasswordAndRealm additional;
424 additional.realm = "https://foobarrealm.org";
425 base::string16 additional_username(base::ASCIIToUTF16("bar.foo@example.com"));
426 data.additional_logins[additional_username] = additional;
427
428 autofill::UsernamesCollectionKey usernames_key;
429 usernames_key.realm = "http://yetanother.net";
430 std::vector<base::string16> other_names;
431 base::string16 other_username(base::ASCIIToUTF16("example@foo.com"));
432 other_names.push_back(other_username);
433 data.other_possible_usernames[usernames_key] = other_names;
434
435 int dummy_key = 0;
436 password_autofill_manager_->OnAddPasswordFormMapping(dummy_key, data);
437
438 // Simulate displaying suggestions for field contents "oo". Check that none
439 // appear, because none has a token with a prefix "oo".
440 EXPECT_CALL(*autofill_client, ShowAutofillPopup(_, _, _, _)).Times(0);
441
442 password_autofill_manager_->OnShowPasswordSuggestions(
443 dummy_key, base::i18n::RIGHT_TO_LEFT, base::ASCIIToUTF16("oo"), false,
444 element_bounds);
445 }
446
447 // Test matching when field contents contains suggestion token separators.
448 TEST_F(PasswordAutofillManagerTest,
449 MatchingContentsWithSuggestionTokenSeparator) {
450 // Token matching is currently behind a flag.
451 base::CommandLine::ForCurrentProcess()->AppendSwitch(
452 autofill::switches::kEnableSuggestionsWithSubstringMatch);
453
454 scoped_ptr<TestPasswordManagerClient> client(new TestPasswordManagerClient);
455 scoped_ptr<MockAutofillClient> autofill_client(new MockAutofillClient);
456 InitializePasswordAutofillManager(client.get(), autofill_client.get());
457
458 gfx::RectF element_bounds;
459 autofill::PasswordFormFillData data;
460 base::string16 username = base::ASCIIToUTF16("foo.bar@example.com");
461 data.username_field.value = username;
462 data.password_field.value = base::ASCIIToUTF16("foobar");
463 data.preferred_realm = "http://foo.com/";
464
465 autofill::PasswordAndRealm additional;
466 additional.realm = "https://foobarrealm.org";
467 base::string16 additional_username(base::ASCIIToUTF16("bar.foo@example.com"));
468 data.additional_logins[additional_username] = additional;
469
470 autofill::UsernamesCollectionKey usernames_key;
471 usernames_key.realm = "http://yetanother.net";
472 std::vector<base::string16> other_names;
473 base::string16 other_username(base::ASCIIToUTF16("example@foo.com"));
474 other_names.push_back(other_username);
475 data.other_possible_usernames[usernames_key] = other_names;
476
477 int dummy_key = 0;
478 password_autofill_manager_->OnAddPasswordFormMapping(dummy_key, data);
479
480 // Simulate displaying suggestions for field contents "foo@exam". Because "@"
481 // is a token separator, the field contents cannot be a prefix of any
482 // suggestion token. Moreover, no suggestion starts with "foo@exam".
483 // Therefore, no suggestions should match.
484 EXPECT_CALL(*autofill_client, ShowAutofillPopup(_, _, _, _)).Times(0);
485 password_autofill_manager_->OnShowPasswordSuggestions(
486 dummy_key, base::i18n::RIGHT_TO_LEFT, base::ASCIIToUTF16("foo@exam"),
487 false, element_bounds);
488
489 // Simulate displaying suggestions for field contents "foo.bar@ex". Because
490 // "@" is a token separator, the field contents cannot be a prefix of any
491 // suggestion token. However, the suggestion "foo.bar@example.com" starts with
492 // "foo.bar@ex". That suggestion should be the only match.
493 EXPECT_CALL(*autofill_client,
494 ShowAutofillPopup(element_bounds, _,
495 SuggestionVectorValuesAre(
496 testing::UnorderedElementsAre(username)),
497 _));
498 password_autofill_manager_->OnShowPasswordSuggestions(
499 dummy_key, base::i18n::RIGHT_TO_LEFT, base::ASCIIToUTF16("foo.bar@ex"),
500 false, element_bounds);
501 }
502
503 // Test that suggestion tokens (substrings separated by characters from
504 // " .,-_@") are ordered prefixes precede substring matched.
505 TEST_F(PasswordAutofillManagerTest,
506 DisplaySuggestionsWithPrefixesPrecedeSubstringMatched) {
507 // Token matching is currently behind a flag.
508 base::CommandLine::ForCurrentProcess()->AppendSwitch(
509 autofill::switches::kEnableSuggestionsWithSubstringMatch);
510
511 scoped_ptr<TestPasswordManagerClient> client(new TestPasswordManagerClient);
512 scoped_ptr<MockAutofillClient> autofill_client(new MockAutofillClient);
513 InitializePasswordAutofillManager(client.get(), autofill_client.get());
514
515 gfx::RectF element_bounds;
516 autofill::PasswordFormFillData data;
517 base::string16 username = base::ASCIIToUTF16("foo.bar@example.com");
518 data.username_field.value = username;
519 data.password_field.value = base::ASCIIToUTF16("foobar");
520 data.preferred_realm = "http://foo.com/";
521
522 autofill::PasswordAndRealm additional;
523 additional.realm = "https://foobarrealm.org";
524 base::string16 additional_username(base::ASCIIToUTF16("bar.foo@example.com"));
525 data.additional_logins[additional_username] = additional;
526
527 autofill::UsernamesCollectionKey usernames_key;
528 usernames_key.realm = "http://yetanother.net";
529 std::vector<base::string16> other_names;
530 base::string16 other_username(base::ASCIIToUTF16("example@foo.com"));
531 other_names.push_back(other_username);
532 data.other_possible_usernames[usernames_key] = other_names;
533
534 int dummy_key = 0;
535 password_autofill_manager_->OnAddPasswordFormMapping(dummy_key, data);
536
537 // Simulate displaying suggestions for field contents "example", check that
538 // matching ones are displayed with prefix matched placed before substring
539 // matched.
540 EXPECT_CALL(
541 *autofill_client,
542 ShowAutofillPopup(element_bounds, _,
543 SuggestionVectorValuesAre(testing::UnorderedElementsAre(
544 other_username, username, additional_username)),
545 _));
546 password_autofill_manager_->OnShowPasswordSuggestions(
547 dummy_key, base::i18n::RIGHT_TO_LEFT, base::ASCIIToUTF16("foo"), false,
548 element_bounds);
549 }
550
357 } // namespace password_manager 551 } // namespace password_manager
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698