| Index: chrome/browser/password_manager/password_form_manager_unittest.cc
|
| diff --git a/chrome/browser/password_manager/password_form_manager_unittest.cc b/chrome/browser/password_manager/password_form_manager_unittest.cc
|
| index a2d98d34ee7321ccc5015e6ef4337b0aac66bb9b..6cc4f0728e75aa7f8adc0936cb8c658e36214a63 100644
|
| --- a/chrome/browser/password_manager/password_form_manager_unittest.cc
|
| +++ b/chrome/browser/password_manager/password_form_manager_unittest.cc
|
| @@ -50,7 +50,17 @@ class TestPasswordManager : public PasswordManager {
|
| const autofill::PasswordForm& form_for_autofill,
|
| const autofill::PasswordFormMap& best_matches,
|
| const autofill::PasswordForm& preferred_match,
|
| - bool wait_for_username) const OVERRIDE {}
|
| + bool wait_for_username) const OVERRIDE {
|
| + best_matches_ = best_matches;
|
| + }
|
| +
|
| + const autofill::PasswordFormMap& GetLatestBestMatches() {
|
| + return best_matches_;
|
| + }
|
| +
|
| + private:
|
| + // Marked mutable to get around constness of Autofill().
|
| + mutable autofill::PasswordFormMap best_matches_;
|
| };
|
|
|
| } // namespace
|
| @@ -513,6 +523,41 @@ TEST_F(PasswordFormManagerTest, TestSendNotBlacklistedMessage) {
|
| EXPECT_EQ(0u, manager->num_sent_messages());
|
| }
|
|
|
| +TEST_F(PasswordFormManagerTest, TestForceInclusionOfGeneratedPasswords) {
|
| + TestPasswordManagerDelegate delegate(profile());
|
| + TestPasswordManager password_manager(&delegate);
|
| + scoped_ptr<TestPasswordFormManager> manager(new TestPasswordFormManager(
|
| + profile(), &password_manager, *observed_form(), false));
|
| +
|
| + // Simulate having two matches for this origin, one of which was from a form
|
| + // with different HTML tags for elements. Because of scoring differences,
|
| + // only the first form will be sent to Autofill().
|
| + std::vector<PasswordForm*> results;
|
| + results.push_back(CreateSavedMatch(false));
|
| + results.push_back(CreateSavedMatch(false));
|
| + results[1]->username_value = ASCIIToUTF16("other@gmail.com");
|
| + results[1]->password_element = ASCIIToUTF16("signup_password");
|
| + results[1]->username_element = ASCIIToUTF16("signup_username");
|
| + SimulateFetchMatchingLoginsFromPasswordStore(manager.get());
|
| + SimulateResponseFromPasswordStore(manager.get(), results);
|
| + EXPECT_EQ(1u, password_manager.GetLatestBestMatches().size());
|
| + results.clear();
|
| +
|
| + // Same thing, except this time the credentials that don't match quite as
|
| + // well are generated. They should now be sent to Autofill().
|
| + manager.reset(new TestPasswordFormManager(
|
| + profile(), &password_manager, *observed_form(), false));
|
| + results.push_back(CreateSavedMatch(false));
|
| + results.push_back(CreateSavedMatch(false));
|
| + results[1]->username_value = ASCIIToUTF16("other@gmail.com");
|
| + results[1]->password_element = ASCIIToUTF16("signup_password");
|
| + results[1]->username_element = ASCIIToUTF16("signup_username");
|
| + results[1]->type = PasswordForm::TYPE_GENERATED;
|
| + SimulateFetchMatchingLoginsFromPasswordStore(manager.get());
|
| + SimulateResponseFromPasswordStore(manager.get(), results);
|
| + EXPECT_EQ(2u, password_manager.GetLatestBestMatches().size());
|
| +}
|
| +
|
| TEST_F(PasswordFormManagerTest, TestSanitizePossibleUsernames) {
|
| scoped_ptr<PasswordFormManager> manager(new PasswordFormManager(
|
| profile(), NULL, NULL, *observed_form(), false));
|
|
|