Remove unnecessary scoped_ptr in password_form_manager_unittest.cc (Part 2)

Simple test code refactoring, no behaviour change.

Part 1: https://codereview.chromium.org/371743002/

BUG=391487

Review URL: https://codereview.chromium.org/381413002

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@282623 0039d316-1c4b-4281-b951-d872f2087c98
parent 2b02c955
...@@ -460,19 +460,18 @@ TEST_F(PasswordFormManagerTest, TestAlternateUsername) { ...@@ -460,19 +460,18 @@ TEST_F(PasswordFormManagerTest, TestAlternateUsername) {
TestPasswordManagerClient client_with_store(password_store.get()); TestPasswordManagerClient client_with_store(password_store.get());
TestPasswordManager password_manager(&client_with_store); TestPasswordManager password_manager(&client_with_store);
scoped_ptr<PasswordFormManager> manager( PasswordFormManager manager(&password_manager,
new PasswordFormManager(&password_manager,
&client_with_store, &client_with_store,
client_with_store.GetDriver(), client_with_store.GetDriver(),
*observed_form(), *observed_form(),
false)); false);
EXPECT_CALL(*client_with_store.GetMockDriver(), EXPECT_CALL(*client_with_store.GetMockDriver(),
AllowPasswordGenerationForForm(_)).Times(1); AllowPasswordGenerationForForm(_)).Times(1);
EXPECT_CALL(*client_with_store.GetMockDriver(), IsOffTheRecord()) EXPECT_CALL(*client_with_store.GetMockDriver(), IsOffTheRecord())
.WillRepeatedly(Return(false)); .WillRepeatedly(Return(false));
password_store->AddLogin(*saved_match()); password_store->AddLogin(*saved_match());
manager->FetchMatchingLoginsFromPasswordStore(PasswordStore::ALLOW_PROMPT); manager.FetchMatchingLoginsFromPasswordStore(PasswordStore::ALLOW_PROMPT);
RunAllPendingTasks(); RunAllPendingTasks();
// The saved match has the right username already. // The saved match has the right username already.
...@@ -480,11 +479,11 @@ TEST_F(PasswordFormManagerTest, TestAlternateUsername) { ...@@ -480,11 +479,11 @@ TEST_F(PasswordFormManagerTest, TestAlternateUsername) {
login.username_value = saved_match()->username_value; login.username_value = saved_match()->username_value;
login.password_value = saved_match()->password_value; login.password_value = saved_match()->password_value;
login.preferred = true; login.preferred = true;
manager->ProvisionallySave( manager.ProvisionallySave(
login, PasswordFormManager::ALLOW_OTHER_POSSIBLE_USERNAMES); login, PasswordFormManager::ALLOW_OTHER_POSSIBLE_USERNAMES);
EXPECT_FALSE(manager->IsNewLogin()); EXPECT_FALSE(manager.IsNewLogin());
manager->Save(); manager.Save();
RunAllPendingTasks(); RunAllPendingTasks();
// Should be only one password stored, and should not have // Should be only one password stored, and should not have
...@@ -499,25 +498,25 @@ TEST_F(PasswordFormManagerTest, TestAlternateUsername) { ...@@ -499,25 +498,25 @@ TEST_F(PasswordFormManagerTest, TestAlternateUsername) {
.other_possible_usernames.size()); .other_possible_usernames.size());
// This time use an alternate username // This time use an alternate username
manager.reset(new PasswordFormManager(&password_manager, PasswordFormManager manager_alt(&password_manager,
&client_with_store, &client_with_store,
client_with_store.GetDriver(), client_with_store.GetDriver(),
*observed_form(), *observed_form(),
false)); false);
EXPECT_CALL(*client_with_store.GetMockDriver(), EXPECT_CALL(*client_with_store.GetMockDriver(),
AllowPasswordGenerationForForm(_)).Times(1); AllowPasswordGenerationForForm(_)).Times(1);
password_store->Clear(); password_store->Clear();
password_store->AddLogin(*saved_match()); password_store->AddLogin(*saved_match());
manager->FetchMatchingLoginsFromPasswordStore(PasswordStore::ALLOW_PROMPT); manager_alt.FetchMatchingLoginsFromPasswordStore(PasswordStore::ALLOW_PROMPT);
RunAllPendingTasks(); RunAllPendingTasks();
base::string16 new_username = saved_match()->other_possible_usernames[0]; base::string16 new_username = saved_match()->other_possible_usernames[0];
login.username_value = new_username; login.username_value = new_username;
manager->ProvisionallySave( manager_alt.ProvisionallySave(
login, PasswordFormManager::ALLOW_OTHER_POSSIBLE_USERNAMES); login, PasswordFormManager::ALLOW_OTHER_POSSIBLE_USERNAMES);
EXPECT_FALSE(manager->IsNewLogin()); EXPECT_FALSE(manager_alt.IsNewLogin());
manager->Save(); manager_alt.Save();
RunAllPendingTasks(); RunAllPendingTasks();
// |other_possible_usernames| should also be empty, but username_value should // |other_possible_usernames| should also be empty, but username_value should
...@@ -625,93 +624,92 @@ TEST_F(PasswordFormManagerTest, TestSendNotBlacklistedMessage) { ...@@ -625,93 +624,92 @@ TEST_F(PasswordFormManagerTest, TestSendNotBlacklistedMessage) {
base::MessageLoop message_loop; base::MessageLoop message_loop;
TestPasswordManager password_manager(client()); TestPasswordManager password_manager(client());
scoped_ptr<PasswordFormManager> manager( PasswordFormManager manager_no_creds(&password_manager,
new PasswordFormManager(&password_manager,
client(), client(),
client()->GetDriver(), client()->GetDriver(),
*observed_form(), *observed_form(),
false)); false);
// First time sign up attempt; No login result is found from password store; // First time sign-up attempt. Password store does not contain matching
// We should send the not blacklisted message. // credentials. AllowPasswordGenerationForForm should be called to send the
// "not blacklisted" message.
EXPECT_CALL(*(client()->GetMockDriver()), AllowPasswordGenerationForForm(_)) EXPECT_CALL(*(client()->GetMockDriver()), AllowPasswordGenerationForForm(_))
.Times(1); .Times(1);
SimulateFetchMatchingLoginsFromPasswordStore(manager.get()); SimulateFetchMatchingLoginsFromPasswordStore(&manager_no_creds);
std::vector<PasswordForm*> result; std::vector<PasswordForm*> result;
SimulateResponseFromPasswordStore(manager.get(), result); SimulateResponseFromPasswordStore(&manager_no_creds, result);
Mock::VerifyAndClearExpectations(client()->GetMockDriver()); Mock::VerifyAndClearExpectations(client()->GetMockDriver());
// Sign up attempt to previously visited sites; Login result is found from // Signing up on a previously visited site. Credentials are found in the
// password store, and is not blacklisted; We should send the not blacklisted // password store, and are not blacklisted. AllowPasswordGenerationForForm
// message. // should be called to send the "not blacklisted" message.
manager.reset(new PasswordFormManager(&password_manager, PasswordFormManager manager_creds(&password_manager,
client(), client(),
client()->GetDriver(), client()->GetDriver(),
*observed_form(), *observed_form(),
false)); false);
EXPECT_CALL(*(client()->GetMockDriver()), AllowPasswordGenerationForForm(_)) EXPECT_CALL(*(client()->GetMockDriver()), AllowPasswordGenerationForForm(_))
.Times(1); .Times(1);
EXPECT_CALL(*(client()->GetMockDriver()), IsOffTheRecord()) EXPECT_CALL(*(client()->GetMockDriver()), IsOffTheRecord())
.WillRepeatedly(Return(false)); .WillRepeatedly(Return(false));
SimulateFetchMatchingLoginsFromPasswordStore(manager.get()); SimulateFetchMatchingLoginsFromPasswordStore(&manager_creds);
// We need add heap allocated objects to result. // We need add heap allocated objects to result.
result.push_back(CreateSavedMatch(false)); result.push_back(CreateSavedMatch(false));
SimulateResponseFromPasswordStore(manager.get(), result); SimulateResponseFromPasswordStore(&manager_creds, result);
Mock::VerifyAndClearExpectations(client()->GetMockDriver()); Mock::VerifyAndClearExpectations(client()->GetMockDriver());
// Sign up attempt to previously visited sites; Login result is found from // Signing up on a previously visited site. Credentials are found in the
// password store, but is blacklisted; We should not send the not blacklisted // password store, but they are blacklisted. AllowPasswordGenerationForForm
// message. // should not be called and no "not blacklisted" message sent.
manager.reset(new PasswordFormManager(&password_manager, PasswordFormManager manager_blacklisted(&password_manager,
client(), client(),
client()->GetDriver(), client()->GetDriver(),
*observed_form(), *observed_form(),
false)); false);
EXPECT_CALL(*(client()->GetMockDriver()), AllowPasswordGenerationForForm(_)) EXPECT_CALL(*(client()->GetMockDriver()), AllowPasswordGenerationForForm(_))
.Times(0); .Times(0);
SimulateFetchMatchingLoginsFromPasswordStore(manager.get()); SimulateFetchMatchingLoginsFromPasswordStore(&manager_blacklisted);
result.clear(); result.clear();
result.push_back(CreateSavedMatch(true)); result.push_back(CreateSavedMatch(true));
SimulateResponseFromPasswordStore(manager.get(), result); SimulateResponseFromPasswordStore(&manager_blacklisted, result);
Mock::VerifyAndClearExpectations(client()->GetMockDriver()); Mock::VerifyAndClearExpectations(client()->GetMockDriver());
} }
TEST_F(PasswordFormManagerTest, TestForceInclusionOfGeneratedPasswords) { TEST_F(PasswordFormManagerTest, TestForceInclusionOfGeneratedPasswords) {
base::MessageLoop message_loop; base::MessageLoop message_loop;
// 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().
TestPasswordManager password_manager(client()); TestPasswordManager password_manager(client());
scoped_ptr<PasswordFormManager> manager( PasswordFormManager manager_match(&password_manager,
new PasswordFormManager(&password_manager,
client(), client(),
client()->GetDriver(), client()->GetDriver(),
*observed_form(), *observed_form(),
false)); false);
EXPECT_CALL(*(client()->GetMockDriver()), AllowPasswordGenerationForForm(_)) EXPECT_CALL(*(client()->GetMockDriver()), AllowPasswordGenerationForForm(_))
.Times(1); .Times(1);
EXPECT_CALL(*(client()->GetMockDriver()), IsOffTheRecord()) EXPECT_CALL(*(client()->GetMockDriver()), IsOffTheRecord())
.WillRepeatedly(Return(false)); .WillRepeatedly(Return(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; std::vector<PasswordForm*> results;
results.push_back(CreateSavedMatch(false)); results.push_back(CreateSavedMatch(false));
results.push_back(CreateSavedMatch(false)); results.push_back(CreateSavedMatch(false));
results[1]->username_value = ASCIIToUTF16("other@gmail.com"); results[1]->username_value = ASCIIToUTF16("other@gmail.com");
results[1]->password_element = ASCIIToUTF16("signup_password"); results[1]->password_element = ASCIIToUTF16("signup_password");
results[1]->username_element = ASCIIToUTF16("signup_username"); results[1]->username_element = ASCIIToUTF16("signup_username");
SimulateFetchMatchingLoginsFromPasswordStore(manager.get()); SimulateFetchMatchingLoginsFromPasswordStore(&manager_match);
SimulateResponseFromPasswordStore(manager.get(), results); SimulateResponseFromPasswordStore(&manager_match, results);
EXPECT_EQ(1u, password_manager.GetLatestBestMatches().size()); EXPECT_EQ(1u, password_manager.GetLatestBestMatches().size());
results.clear(); results.clear();
// Same thing, except this time the credentials that don't match quite as // Same thing, except this time the credentials that don't match quite as
// well are generated. They should now be sent to Autofill(). // well are generated. They should now be sent to Autofill().
manager.reset(new PasswordFormManager(&password_manager, PasswordFormManager manager_no_match(&password_manager,
client(), client(),
client()->GetDriver(), client()->GetDriver(),
*observed_form(), *observed_form(),
false)); false);
EXPECT_CALL(*(client()->GetMockDriver()), AllowPasswordGenerationForForm(_)) EXPECT_CALL(*(client()->GetMockDriver()), AllowPasswordGenerationForForm(_))
.Times(1); .Times(1);
...@@ -721,8 +719,8 @@ TEST_F(PasswordFormManagerTest, TestForceInclusionOfGeneratedPasswords) { ...@@ -721,8 +719,8 @@ TEST_F(PasswordFormManagerTest, TestForceInclusionOfGeneratedPasswords) {
results[1]->password_element = ASCIIToUTF16("signup_password"); results[1]->password_element = ASCIIToUTF16("signup_password");
results[1]->username_element = ASCIIToUTF16("signup_username"); results[1]->username_element = ASCIIToUTF16("signup_username");
results[1]->type = PasswordForm::TYPE_GENERATED; results[1]->type = PasswordForm::TYPE_GENERATED;
SimulateFetchMatchingLoginsFromPasswordStore(manager.get()); SimulateFetchMatchingLoginsFromPasswordStore(&manager_no_match);
SimulateResponseFromPasswordStore(manager.get(), results); SimulateResponseFromPasswordStore(&manager_no_match, results);
EXPECT_EQ(2u, password_manager.GetLatestBestMatches().size()); EXPECT_EQ(2u, password_manager.GetLatestBestMatches().size());
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment