OLD | NEW |
---|---|
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 Loading... | |
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 " | |
vabr (Chromium)
2015/03/27 10:13:35
Note that clangformat discarded the space characte
Pritam Nikam
2015/03/27 14:57:43
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 are not matched when the field contents spans multiple | |
vabr (Chromium)
2015/03/27 10:13:35
I'm sorry, when I was suggesting this comment, I g
Pritam Nikam
2015/03/27 14:57:43
Done.
| |
406 // tokens (substrings separated by characters from " .,-_@"). | |
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 that suggestion tokens (substrings separated by characters from " | |
vabr (Chromium)
2015/03/27 10:13:35
Again: the space in the token separator list got d
Pritam Nikam
2015/03/27 14:57:43
Done.
| |
448 // .,-_@") are matched against field contents containing tokens along the token | |
vabr (Chromium)
2015/03/27 10:13:35
I don't understand this sentence. What does "conta
Pritam Nikam
2015/03/27 14:57:43
Done.
| |
449 // separators. | |
450 TEST_F(PasswordAutofillManagerTest, | |
451 DisplaySuggestionsWithMatchingTokensAndContentsHaveSeperator) { | |
vabr (Chromium)
2015/03/27 10:13:35
typo: Seperator
Also, proposed simplification of t
Pritam Nikam
2015/03/27 14:57:43
Done.
| |
452 // Token matching is currently behind a flag. | |
453 base::CommandLine::ForCurrentProcess()->AppendSwitch( | |
454 autofill::switches::kEnableSuggestionsWithSubstringMatch); | |
455 | |
456 scoped_ptr<TestPasswordManagerClient> client(new TestPasswordManagerClient); | |
457 scoped_ptr<MockAutofillClient> autofill_client(new MockAutofillClient); | |
458 InitializePasswordAutofillManager(client.get(), autofill_client.get()); | |
459 | |
460 gfx::RectF element_bounds; | |
461 autofill::PasswordFormFillData data; | |
462 base::string16 username = base::ASCIIToUTF16("foo.bar@example.com"); | |
463 data.username_field.value = username; | |
464 data.password_field.value = base::ASCIIToUTF16("foobar"); | |
465 data.preferred_realm = "http://foo.com/"; | |
466 | |
467 autofill::PasswordAndRealm additional; | |
468 additional.realm = "https://foobarrealm.org"; | |
469 base::string16 additional_username(base::ASCIIToUTF16("bar.foo@example.com")); | |
470 data.additional_logins[additional_username] = additional; | |
471 | |
472 autofill::UsernamesCollectionKey usernames_key; | |
473 usernames_key.realm = "http://yetanother.net"; | |
474 std::vector<base::string16> other_names; | |
475 base::string16 other_username(base::ASCIIToUTF16("example@foo.com")); | |
476 other_names.push_back(other_username); | |
477 data.other_possible_usernames[usernames_key] = other_names; | |
478 | |
479 int dummy_key = 0; | |
480 password_autofill_manager_->OnAddPasswordFormMapping(dummy_key, data); | |
481 | |
482 // Simulate displaying suggestions for field contents "foo@exam", check that | |
483 // matching ones are displayed. | |
vabr (Chromium)
2015/03/27 10:13:35
nit: It is slightly confusing, that you use plural
Pritam Nikam
2015/03/27 14:57:43
Done.
I've rephrased it as below:
// Simulate di
| |
484 EXPECT_CALL( | |
485 *autofill_client, | |
486 ShowAutofillPopup(element_bounds, _, | |
487 SuggestionVectorValuesAre( | |
488 testing::UnorderedElementsAre(additional_username)), | |
489 _)); | |
490 password_autofill_manager_->OnShowPasswordSuggestions( | |
491 dummy_key, base::i18n::RIGHT_TO_LEFT, base::ASCIIToUTF16("foo@exam"), | |
492 false, element_bounds); | |
493 } | |
494 | |
357 } // namespace password_manager | 495 } // namespace password_manager |
OLD | NEW |