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

Unified 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 side-by-side diff with in-line comments
Download patch
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..121a3a70eeb980345a2387196d827ac5b1af0003 100644
--- a/chrome/browser/password_manager/password_form_manager_unittest.cc
+++ b/chrome/browser/password_manager/password_form_manager_unittest.cc
@@ -50,7 +50,15 @@ 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;
+ }
+
+ 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
+
+ private:
+ // 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
+ mutable autofill::PasswordFormMap best_matches_;
};
} // namespace
@@ -513,6 +521,43 @@ 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);
+ autofill::PasswordFormMap best_matches =
+ password_manager.GetLatestBestMatches();
+ EXPECT_EQ(1u, best_matches.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));

Powered by Google App Engine
This is Rietveld 408576698