Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 363 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 374 | 374 |
| 375 // Can't verify time, so ignore it. | 375 // Can't verify time, so ignore it. |
| 376 actual_saved_form.date_created = base::Time(); | 376 actual_saved_form.date_created = base::Time(); |
| 377 EXPECT_EQ(expected_saved_form, actual_saved_form); | 377 EXPECT_EQ(expected_saved_form, actual_saved_form); |
| 378 } | 378 } |
| 379 | 379 |
| 380 TEST_F(PasswordFormManagerTest, TestNewLoginFromNewPasswordElement) { | 380 TEST_F(PasswordFormManagerTest, TestNewLoginFromNewPasswordElement) { |
| 381 // Add a new password field to the test form. The PasswordFormManager should | 381 // Add a new password field to the test form. The PasswordFormManager should |
| 382 // save the password from this field, instead of the current password field. | 382 // save the password from this field, instead of the current password field. |
| 383 observed_form()->new_password_element = ASCIIToUTF16("NewPasswd"); | 383 observed_form()->new_password_element = ASCIIToUTF16("NewPasswd"); |
| 384 observed_form()->username_marked_by_site = true; | |
| 384 | 385 |
| 385 PasswordFormManager manager(NULL, client(), kNoDriver, *observed_form(), | 386 PasswordFormManager manager(NULL, client(), kNoDriver, *observed_form(), |
| 386 false); | 387 false); |
| 387 SimulateMatchingPhase(&manager, RESULT_NO_MATCH); | 388 SimulateMatchingPhase(&manager, RESULT_NO_MATCH); |
| 388 | 389 |
| 389 // User enters current and new credentials to the observed form. | 390 // User enters current and new credentials to the observed form. |
| 390 PasswordForm credentials(*observed_form()); | 391 PasswordForm credentials(*observed_form()); |
| 391 credentials.username_value = saved_match()->username_value; | 392 credentials.username_value = saved_match()->username_value; |
| 392 credentials.password_value = saved_match()->password_value; | 393 credentials.password_value = saved_match()->password_value; |
| 393 credentials.new_password_value = ASCIIToUTF16("newpassword"); | 394 credentials.new_password_value = ASCIIToUTF16("newpassword"); |
| (...skipping 945 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1339 | 1340 |
| 1340 form_manager.OnGetPasswordStoreResults(simulated_results.Pass()); | 1341 form_manager.OnGetPasswordStoreResults(simulated_results.Pass()); |
| 1341 EXPECT_EQ(1u, form_manager.best_matches().size()); | 1342 EXPECT_EQ(1u, form_manager.best_matches().size()); |
| 1342 EXPECT_EQ(form_manager.preferred_match(), | 1343 EXPECT_EQ(form_manager.preferred_match(), |
| 1343 form_manager.best_matches().begin()->second); | 1344 form_manager.best_matches().begin()->second); |
| 1344 // Make sure to access all fields of preferred_match; this way if it was | 1345 // Make sure to access all fields of preferred_match; this way if it was |
| 1345 // deleted, ASAN might notice it. | 1346 // deleted, ASAN might notice it. |
| 1346 PasswordForm dummy(*form_manager.preferred_match()); | 1347 PasswordForm dummy(*form_manager.preferred_match()); |
| 1347 } | 1348 } |
| 1348 | 1349 |
| 1350 TEST_F(PasswordFormManagerTest, | |
| 1351 SubmitIngnorableChangePasswordForm_MatchingUsernameAndPassword) { | |
|
vabr (Chromium)
2015/02/23 10:15:26
nit: Please rename the new tests by replacing "Sub
Pritam Nikam
2015/02/23 11:27:52
Done.
| |
| 1352 observed_form()->new_password_element = | |
| 1353 base::ASCIIToUTF16("new_password_field"); | |
| 1354 | |
| 1355 TestPasswordManagerClient client_with_store(mock_store()); | |
| 1356 PasswordFormManager manager(nullptr, &client_with_store, | |
| 1357 client_with_store.driver(), *observed_form(), | |
| 1358 false); | |
| 1359 SimulateMatchingPhase(&manager, RESULT_MATCH_FOUND); | |
| 1360 | |
| 1361 // The user submits a password on a change-password form, which does not use | |
| 1362 // the "autocomplete=username" mark-up (therefore Chrome had to guess what is | |
| 1363 // the username), but the user-typed credentials match something already | |
| 1364 // stored (which confirms that the guess was right). | |
| 1365 PasswordForm credentials(*observed_form()); | |
| 1366 credentials.username_value = saved_match()->username_value; | |
| 1367 credentials.password_value = saved_match()->password_value; | |
| 1368 credentials.new_password_value = ASCIIToUTF16("NewPassword"); | |
| 1369 | |
| 1370 EXPECT_FALSE(manager.IsIgnorableChangePasswordForm( | |
| 1371 credentials.username_value, credentials.password_value)); | |
| 1372 manager.ProvisionallySave( | |
|
vabr (Chromium)
2015/02/23 10:15:26
I suggest to drop the lines 1372-1383. They don't
Pritam Nikam
2015/02/23 11:27:52
Done.
| |
| 1373 credentials, PasswordFormManager::IGNORE_OTHER_POSSIBLE_USERNAMES); | |
| 1374 | |
| 1375 EXPECT_EQ(credentials.signon_realm, | |
| 1376 GetPendingCredentials(&manager)->signon_realm); | |
| 1377 EXPECT_EQ(credentials.username_value, | |
| 1378 GetPendingCredentials(&manager)->username_value); | |
| 1379 | |
| 1380 // By this point, the PasswordFormManager should have overwritten the new | |
| 1381 // password value to be the current password. | |
| 1382 EXPECT_EQ(credentials.new_password_value, | |
| 1383 GetPendingCredentials(&manager)->password_value); | |
| 1384 } | |
| 1385 | |
| 1386 TEST_F(PasswordFormManagerTest, | |
| 1387 SubmitIngnorableChangePasswordForm_NotMatchingPassword) { | |
| 1388 observed_form()->new_password_element = | |
| 1389 base::ASCIIToUTF16("new_password_field"); | |
| 1390 | |
| 1391 TestPasswordManagerClient client_with_store(mock_store()); | |
| 1392 PasswordFormManager manager(nullptr, &client_with_store, | |
| 1393 client_with_store.driver(), *observed_form(), | |
| 1394 false); | |
| 1395 SimulateMatchingPhase(&manager, RESULT_MATCH_FOUND); | |
| 1396 | |
| 1397 // The user submits a password on a change-password form, which does not use | |
| 1398 // the "autocomplete=username" mark-up (therefore Chrome had to guess what is | |
| 1399 // the username), and the user-typed password do not match anything already | |
| 1400 // stored. There is not much confidence in the guess being right, so the | |
| 1401 // password should not be stored. | |
| 1402 EXPECT_TRUE(manager.IsIgnorableChangePasswordForm( | |
| 1403 saved_match()->username_value, ASCIIToUTF16("DifferentPassword"))); | |
| 1404 } | |
| 1405 | |
| 1406 TEST_F(PasswordFormManagerTest, | |
| 1407 SubmitIngnorableChangePasswordForm_NotMatchingUsername) { | |
| 1408 observed_form()->new_password_element = | |
| 1409 base::ASCIIToUTF16("new_password_field"); | |
| 1410 | |
| 1411 TestPasswordManagerClient client_with_store(mock_store()); | |
| 1412 PasswordFormManager manager(nullptr, &client_with_store, | |
| 1413 client_with_store.driver(), *observed_form(), | |
| 1414 false); | |
| 1415 SimulateMatchingPhase(&manager, RESULT_MATCH_FOUND); | |
| 1416 | |
| 1417 // The user submits a password on a change-password form, which does not use | |
| 1418 // the "autocomplete=username" mark-up (therefore Chrome had to guess what is | |
| 1419 // the username), and the user-typed username does not match anything already | |
| 1420 // stored. There is not much confidence in the guess being right, so the | |
| 1421 // password should not be stored. | |
| 1422 EXPECT_TRUE(manager.IsIgnorableChangePasswordForm( | |
| 1423 ASCIIToUTF16("DifferentUsername"), saved_match()->password_value)); | |
| 1424 } | |
| 1425 | |
| 1349 } // namespace password_manager | 1426 } // namespace password_manager |
| OLD | NEW |