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

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: 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
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 autofill::PasswordFormMap GetLatestBestMatches() { return best_matches_; }
Ilya Sherman 2013/09/19 01:02:20 Return by const-ref?
Garrett Casto 2013/09/19 17:40:14 I'm generally wary of returning references as it c
58
59 private:
60 // Marked mutable to get around constness of Autofill().
Ilya Sherman 2013/09/19 01:02:20 Hmm, it's rather odd for the Autofill() method to
Garrett Casto 2013/09/19 17:40:14 Yeah, I had a similar thought as I was writing thi
61 mutable autofill::PasswordFormMap best_matches_;
54 }; 62 };
55 63
56 } // namespace 64 } // namespace
57 65
58 class TestPasswordFormManager : public PasswordFormManager { 66 class TestPasswordFormManager : public PasswordFormManager {
59 public: 67 public:
60 TestPasswordFormManager(Profile* profile, 68 TestPasswordFormManager(Profile* profile,
61 PasswordManager* manager, 69 PasswordManager* manager,
62 const autofill::PasswordForm& observed_form, 70 const autofill::PasswordForm& observed_form,
63 bool ssl_valid) 71 bool ssl_valid)
(...skipping 442 matching lines...) Expand 10 before | Expand all | Expand 10 after
506 // message. 514 // message.
507 manager.reset(new TestPasswordFormManager( 515 manager.reset(new TestPasswordFormManager(
508 profile(), &password_manager, *observed_form(), false)); 516 profile(), &password_manager, *observed_form(), false));
509 SimulateFetchMatchingLoginsFromPasswordStore(manager.get()); 517 SimulateFetchMatchingLoginsFromPasswordStore(manager.get());
510 result.clear(); 518 result.clear();
511 result.push_back(CreateSavedMatch(true)); 519 result.push_back(CreateSavedMatch(true));
512 SimulateResponseFromPasswordStore(manager.get(), result); 520 SimulateResponseFromPasswordStore(manager.get(), result);
513 EXPECT_EQ(0u, manager->num_sent_messages()); 521 EXPECT_EQ(0u, manager->num_sent_messages());
514 } 522 }
515 523
524 TEST_F(PasswordFormManagerTest, TestForceInclusionOfGeneratedPasswords) {
525 TestPasswordManagerDelegate delegate(profile());
526 TestPasswordManager password_manager(&delegate);
527 scoped_ptr<TestPasswordFormManager> manager(new TestPasswordFormManager(
528 profile(), &password_manager, *observed_form(), false));
529
530 // Simulate having two matches for this origin, one of which was from a form
531 // with different HTML tags for elements. Because of scoring differences,
532 // only the first form will be sent to Autofill().
533 std::vector<PasswordForm*> results;
534 results.push_back(CreateSavedMatch(false));
535 results.push_back(CreateSavedMatch(false));
536 results[1]->username_value = ASCIIToUTF16("other@gmail.com");
537 results[1]->password_element = ASCIIToUTF16("signup_password");
538 results[1]->username_element = ASCIIToUTF16("signup_username");
539 SimulateFetchMatchingLoginsFromPasswordStore(manager.get());
540 SimulateResponseFromPasswordStore(manager.get(), results);
541 autofill::PasswordFormMap best_matches =
542 password_manager.GetLatestBestMatches();
543 EXPECT_EQ(1u, best_matches.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

Powered by Google App Engine
This is Rietveld 408576698