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

Side by Side Diff: components/password_manager/core/browser/password_form_manager_unittest.cc

Issue 548953002: [Password Manager] Modified to support saving passwords on forms without username fields. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixed breakages. Created 6 years, 2 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 "base/memory/scoped_ptr.h" 5 #include "base/memory/scoped_ptr.h"
6 #include "base/message_loop/message_loop.h" 6 #include "base/message_loop/message_loop.h"
7 #include "base/prefs/pref_registry_simple.h" 7 #include "base/prefs/pref_registry_simple.h"
8 #include "base/prefs/pref_service.h" 8 #include "base/prefs/pref_service.h"
9 #include "base/prefs/testing_pref_service.h" 9 #include "base/prefs/testing_pref_service.h"
10 #include "base/run_loop.h" 10 #include "base/run_loop.h"
(...skipping 606 matching lines...) Expand 10 before | Expand all | Expand 10 after
617 // Form with username_element and only new_password_element. 617 // Form with username_element and only new_password_element.
618 new_credentials.password_element.clear(); 618 new_credentials.password_element.clear();
619 PasswordFormManager manager3(NULL, NULL, NULL, new_credentials, false); 619 PasswordFormManager manager3(NULL, NULL, NULL, new_credentials, false);
620 SimulateMatchingPhase(&manager3, RESULT_NO_MATCH); 620 SimulateMatchingPhase(&manager3, RESULT_NO_MATCH);
621 EXPECT_TRUE(manager3.HasValidPasswordForm()); 621 EXPECT_TRUE(manager3.HasValidPasswordForm());
622 622
623 // Form without a username_element but with a password_element. 623 // Form without a username_element but with a password_element.
624 credentials.username_element.clear(); 624 credentials.username_element.clear();
625 PasswordFormManager manager4(NULL, NULL, NULL, credentials, false); 625 PasswordFormManager manager4(NULL, NULL, NULL, credentials, false);
626 SimulateMatchingPhase(&manager4, RESULT_NO_MATCH); 626 SimulateMatchingPhase(&manager4, RESULT_NO_MATCH);
627 EXPECT_FALSE(manager4.HasValidPasswordForm()); 627 EXPECT_TRUE(manager4.HasValidPasswordForm());
628 628
629 // Form without a username_element but with a new_password_element. 629 // Form without a username_element but with a new_password_element.
630 new_credentials.username_element.clear(); 630 new_credentials.username_element.clear();
631 PasswordFormManager manager5(NULL, NULL, NULL, new_credentials, false); 631 PasswordFormManager manager5(NULL, NULL, NULL, new_credentials, false);
632 SimulateMatchingPhase(&manager5, RESULT_NO_MATCH); 632 SimulateMatchingPhase(&manager5, RESULT_NO_MATCH);
633 EXPECT_FALSE(manager5.HasValidPasswordForm()); 633 EXPECT_TRUE(manager5.HasValidPasswordForm());
634 634
635 // Form without a password_element but with a username_element. 635 // Form without a password_element but with a username_element.
636 credentials.username_element = saved_match()->username_element; 636 credentials.username_element = saved_match()->username_element;
637 credentials.password_element.clear(); 637 credentials.password_element.clear();
638 PasswordFormManager manager6(NULL, NULL, NULL, credentials, false); 638 PasswordFormManager manager6(NULL, NULL, NULL, credentials, false);
639 SimulateMatchingPhase(&manager6, RESULT_NO_MATCH); 639 SimulateMatchingPhase(&manager6, RESULT_NO_MATCH);
640 EXPECT_FALSE(manager6.HasValidPasswordForm()); 640 EXPECT_FALSE(manager6.HasValidPasswordForm());
641 641
642 // Form with neither a password_element nor a username_element. 642 // Form with neither a password_element nor a username_element.
643 credentials.username_element.clear(); 643 credentials.username_element.clear();
(...skipping 591 matching lines...) Expand 10 before | Expand all | Expand 10 after
1235 1235
1236 EXPECT_CALL(form_manager, 1236 EXPECT_CALL(form_manager,
1237 UploadPasswordForm(_, 1237 UploadPasswordForm(_,
1238 autofill::ACCOUNT_CREATION_PASSWORD)).Times(1); 1238 autofill::ACCOUNT_CREATION_PASSWORD)).Times(1);
1239 form_manager.ProvisionallySave( 1239 form_manager.ProvisionallySave(
1240 form_to_save, 1240 form_to_save,
1241 PasswordFormManager::IGNORE_OTHER_POSSIBLE_USERNAMES); 1241 PasswordFormManager::IGNORE_OTHER_POSSIBLE_USERNAMES);
1242 form_manager.Save(); 1242 form_manager.Save();
1243 } 1243 }
1244 1244
1245 TEST_F(PasswordFormManagerTest, CorrectlySavePasswordWithoutUsernameFields) {
1246 // Need a MessageLoop for callbacks.
1247 base::MessageLoop message_loop;
1248 scoped_refptr<TestPasswordStore> password_store = new TestPasswordStore;
1249 CHECK(password_store->Init(syncer::SyncableService::StartSyncFlare(), ""));
1250
1251 TestPasswordManagerClient client_with_store(password_store.get());
1252 TestPasswordManager password_manager(&client_with_store);
1253 EXPECT_CALL(*client_with_store.GetMockDriver(),
1254 AllowPasswordGenerationForForm(_)).Times(2);
1255 EXPECT_CALL(*client_with_store.GetMockDriver(), IsOffTheRecord())
1256 .WillRepeatedly(Return(false));
1257
1258 PasswordForm form(*observed_form());
1259 form.username_element.clear();
1260 form.password_value = ASCIIToUTF16("password");
1261 form.preferred = true;
1262
1263 PasswordFormManager storing_manager(&password_manager,
1264 &client_with_store,
1265 client_with_store.GetDriver(),
1266 *observed_form(),
1267 false);
1268 storing_manager.FetchMatchingLoginsFromPasswordStore(
1269 PasswordStore::ALLOW_PROMPT);
1270 RunAllPendingTasks();
1271
1272 storing_manager.ProvisionallySave(
1273 form, PasswordFormManager::IGNORE_OTHER_POSSIBLE_USERNAMES);
1274
1275 EXPECT_TRUE(storing_manager.IsNewLogin());
1276 storing_manager.Save();
1277 RunAllPendingTasks();
1278
1279 PasswordFormManager retrieving_manager(&password_manager,
1280 &client_with_store,
1281 client_with_store.GetDriver(),
1282 *observed_form(),
1283 false);
1284
1285 retrieving_manager.FetchMatchingLoginsFromPasswordStore(
1286 PasswordStore::ALLOW_PROMPT);
1287 RunAllPendingTasks();
1288
1289 // Make sure that the preferred match is updated appropriately.
1290 EXPECT_EQ(ASCIIToUTF16("password"),
1291 retrieving_manager.preferred_match()->password_value);
1292 password_store->Shutdown();
1293 }
1294
1245 } // namespace password_manager 1295 } // namespace password_manager
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698