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

Side by Side Diff: chrome/browser/password_manager/password_form_manager_unittest.cc

Issue 23533069: [password generation] Always allow generated passwords to be shown. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address comments Created 7 years, 3 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
« no previous file with comments | « chrome/browser/password_manager/password_form_manager.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "testing/gtest/include/gtest/gtest.h" 5 #include "testing/gtest/include/gtest/gtest.h"
6 6
7 #include "base/memory/scoped_ptr.h" 7 #include "base/memory/scoped_ptr.h"
8 #include "base/message_loop/message_loop.h" 8 #include "base/message_loop/message_loop.h"
9 #include "base/strings/string_util.h" 9 #include "base/strings/string_util.h"
10 #include "base/strings/utf_string_conversions.h" 10 #include "base/strings/utf_string_conversions.h"
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
43 43
44 class TestPasswordManager : public PasswordManager { 44 class TestPasswordManager : public PasswordManager {
45 public: 45 public:
46 explicit TestPasswordManager(PasswordManagerDelegate* delegate) 46 explicit TestPasswordManager(PasswordManagerDelegate* delegate)
47 : PasswordManager(NULL, delegate) {} 47 : PasswordManager(NULL, delegate) {}
48 48
49 virtual void Autofill( 49 virtual void Autofill(
50 const autofill::PasswordForm& form_for_autofill, 50 const autofill::PasswordForm& form_for_autofill,
51 const autofill::PasswordFormMap& best_matches, 51 const autofill::PasswordFormMap& best_matches,
52 const autofill::PasswordForm& preferred_match, 52 const autofill::PasswordForm& preferred_match,
53 bool wait_for_username) const OVERRIDE {} 53 bool wait_for_username) const OVERRIDE {
54 best_matches_ = best_matches;
55 }
56
57 const autofill::PasswordFormMap& GetLatestBestMatches() {
58 return best_matches_;
59 }
60
61 private:
62 // Marked mutable to get around constness of Autofill().
63 mutable autofill::PasswordFormMap best_matches_;
54 }; 64 };
55 65
56 } // namespace 66 } // namespace
57 67
58 class TestPasswordFormManager : public PasswordFormManager { 68 class TestPasswordFormManager : public PasswordFormManager {
59 public: 69 public:
60 TestPasswordFormManager(Profile* profile, 70 TestPasswordFormManager(Profile* profile,
61 PasswordManager* manager, 71 PasswordManager* manager,
62 const autofill::PasswordForm& observed_form, 72 const autofill::PasswordForm& observed_form,
63 bool ssl_valid) 73 bool ssl_valid)
(...skipping 442 matching lines...) Expand 10 before | Expand all | Expand 10 after
506 // message. 516 // message.
507 manager.reset(new TestPasswordFormManager( 517 manager.reset(new TestPasswordFormManager(
508 profile(), &password_manager, *observed_form(), false)); 518 profile(), &password_manager, *observed_form(), false));
509 SimulateFetchMatchingLoginsFromPasswordStore(manager.get()); 519 SimulateFetchMatchingLoginsFromPasswordStore(manager.get());
510 result.clear(); 520 result.clear();
511 result.push_back(CreateSavedMatch(true)); 521 result.push_back(CreateSavedMatch(true));
512 SimulateResponseFromPasswordStore(manager.get(), result); 522 SimulateResponseFromPasswordStore(manager.get(), result);
513 EXPECT_EQ(0u, manager->num_sent_messages()); 523 EXPECT_EQ(0u, manager->num_sent_messages());
514 } 524 }
515 525
526 TEST_F(PasswordFormManagerTest, TestForceInclusionOfGeneratedPasswords) {
527 TestPasswordManagerDelegate delegate(profile());
528 TestPasswordManager password_manager(&delegate);
529 scoped_ptr<TestPasswordFormManager> manager(new TestPasswordFormManager(
530 profile(), &password_manager, *observed_form(), false));
531
532 // Simulate having two matches for this origin, one of which was from a form
533 // with different HTML tags for elements. Because of scoring differences,
534 // only the first form will be sent to Autofill().
535 std::vector<PasswordForm*> results;
536 results.push_back(CreateSavedMatch(false));
537 results.push_back(CreateSavedMatch(false));
538 results[1]->username_value = ASCIIToUTF16("other@gmail.com");
539 results[1]->password_element = ASCIIToUTF16("signup_password");
540 results[1]->username_element = ASCIIToUTF16("signup_username");
541 SimulateFetchMatchingLoginsFromPasswordStore(manager.get());
542 SimulateResponseFromPasswordStore(manager.get(), results);
543 EXPECT_EQ(1u, password_manager.GetLatestBestMatches().size());
544 results.clear();
545
546 // Same thing, except this time the credentials that don't match quite as
547 // well are generated. They should now be sent to Autofill().
548 manager.reset(new TestPasswordFormManager(
549 profile(), &password_manager, *observed_form(), false));
550 results.push_back(CreateSavedMatch(false));
551 results.push_back(CreateSavedMatch(false));
552 results[1]->username_value = ASCIIToUTF16("other@gmail.com");
553 results[1]->password_element = ASCIIToUTF16("signup_password");
554 results[1]->username_element = ASCIIToUTF16("signup_username");
555 results[1]->type = PasswordForm::TYPE_GENERATED;
556 SimulateFetchMatchingLoginsFromPasswordStore(manager.get());
557 SimulateResponseFromPasswordStore(manager.get(), results);
558 EXPECT_EQ(2u, password_manager.GetLatestBestMatches().size());
559 }
560
516 TEST_F(PasswordFormManagerTest, TestSanitizePossibleUsernames) { 561 TEST_F(PasswordFormManagerTest, TestSanitizePossibleUsernames) {
517 scoped_ptr<PasswordFormManager> manager(new PasswordFormManager( 562 scoped_ptr<PasswordFormManager> manager(new PasswordFormManager(
518 profile(), NULL, NULL, *observed_form(), false)); 563 profile(), NULL, NULL, *observed_form(), false));
519 PasswordForm credentials(*observed_form()); 564 PasswordForm credentials(*observed_form());
520 credentials.other_possible_usernames.push_back(ASCIIToUTF16("543-43-1234")); 565 credentials.other_possible_usernames.push_back(ASCIIToUTF16("543-43-1234"));
521 credentials.other_possible_usernames.push_back( 566 credentials.other_possible_usernames.push_back(
522 ASCIIToUTF16("378282246310005")); 567 ASCIIToUTF16("378282246310005"));
523 credentials.other_possible_usernames.push_back( 568 credentials.other_possible_usernames.push_back(
524 ASCIIToUTF16("other username")); 569 ASCIIToUTF16("other username"));
525 credentials.username_value = ASCIIToUTF16("test@gmail.com"); 570 credentials.username_value = ASCIIToUTF16("test@gmail.com");
(...skipping 15 matching lines...) Expand all
541 586
542 SanitizePossibleUsernames(manager.get(), &credentials); 587 SanitizePossibleUsernames(manager.get(), &credentials);
543 588
544 // SSN, duplicate in |other_possible_usernames| and duplicate of 589 // SSN, duplicate in |other_possible_usernames| and duplicate of
545 // |username_value| all removed. 590 // |username_value| all removed.
546 expected.clear(); 591 expected.clear();
547 expected.push_back(ASCIIToUTF16("duplicate")); 592 expected.push_back(ASCIIToUTF16("duplicate"));
548 expected.push_back(ASCIIToUTF16("random")); 593 expected.push_back(ASCIIToUTF16("random"));
549 EXPECT_THAT(credentials.other_possible_usernames, Eq(expected)); 594 EXPECT_THAT(credentials.other_possible_usernames, Eq(expected));
550 } 595 }
OLDNEW
« no previous file with comments | « chrome/browser/password_manager/password_form_manager.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698