| 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 "testing/gtest/include/gtest/gtest.h" | 5 #include "testing/gtest/include/gtest/gtest.h" |
| 6 | 6 |
| 7 #include "base/memory/scoped_ptr.h" | 7 #include "base/memory/scoped_ptr.h" |
| 8 #include "base/string_util.h" | 8 #include "base/string_util.h" |
| 9 #include "base/utf_string_conversions.h" | 9 #include "base/utf_string_conversions.h" |
| 10 #include "chrome/browser/password_manager/password_form_manager.h" | 10 #include "chrome/browser/password_manager/password_form_manager.h" |
| (...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 156 | 156 |
| 157 // Successful login. The PasswordManager would instruct PasswordFormManager | 157 // Successful login. The PasswordManager would instruct PasswordFormManager |
| 158 // to save, which should know this is a new login. | 158 // to save, which should know this is a new login. |
| 159 EXPECT_TRUE(manager->IsNewLogin()); | 159 EXPECT_TRUE(manager->IsNewLogin()); |
| 160 // Make sure the credentials that would be submitted on successful login | 160 // Make sure the credentials that would be submitted on successful login |
| 161 // are going to match the stored entry in the db. | 161 // are going to match the stored entry in the db. |
| 162 EXPECT_EQ(observed_form()->origin.spec(), | 162 EXPECT_EQ(observed_form()->origin.spec(), |
| 163 GetPendingCredentials(manager)->origin.spec()); | 163 GetPendingCredentials(manager)->origin.spec()); |
| 164 EXPECT_EQ(observed_form()->signon_realm, | 164 EXPECT_EQ(observed_form()->signon_realm, |
| 165 GetPendingCredentials(manager)->signon_realm); | 165 GetPendingCredentials(manager)->signon_realm); |
| 166 EXPECT_EQ(observed_form()->action, |
| 167 GetPendingCredentials(manager)->action); |
| 166 EXPECT_TRUE(GetPendingCredentials(manager)->preferred); | 168 EXPECT_TRUE(GetPendingCredentials(manager)->preferred); |
| 167 EXPECT_EQ(saved_match()->password_value, | 169 EXPECT_EQ(saved_match()->password_value, |
| 168 GetPendingCredentials(manager)->password_value); | 170 GetPendingCredentials(manager)->password_value); |
| 169 EXPECT_EQ(saved_match()->username_value, | 171 EXPECT_EQ(saved_match()->username_value, |
| 170 GetPendingCredentials(manager)->username_value); | 172 GetPendingCredentials(manager)->username_value); |
| 171 | 173 |
| 172 // Now, suppose the user re-visits the site and wants to save an additional | 174 // Now, suppose the user re-visits the site and wants to save an additional |
| 173 // login for the site with a new username. In this case, the matching phase | 175 // login for the site with a new username. In this case, the matching phase |
| 174 // will yield the previously saved login. | 176 // will yield the previously saved login. |
| 175 SimulateMatchingPhase(manager, true); | 177 SimulateMatchingPhase(manager, true); |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 263 login.username_value = saved_match()->username_value; | 265 login.username_value = saved_match()->username_value; |
| 264 login.password_value = saved_match()->password_value; | 266 login.password_value = saved_match()->password_value; |
| 265 manager->ProvisionallySave(login); | 267 manager->ProvisionallySave(login); |
| 266 EXPECT_FALSE(manager->IsNewLogin()); | 268 EXPECT_FALSE(manager->IsNewLogin()); |
| 267 // We bless our saved PasswordForm entry with the action URL of the | 269 // We bless our saved PasswordForm entry with the action URL of the |
| 268 // observed form. | 270 // observed form. |
| 269 EXPECT_EQ(observed_form()->action, | 271 EXPECT_EQ(observed_form()->action, |
| 270 GetPendingCredentials(manager.get())->action); | 272 GetPendingCredentials(manager.get())->action); |
| 271 } | 273 } |
| 272 | 274 |
| 275 TEST_F(PasswordFormManagerTest, TestUpdateAction) { |
| 276 scoped_ptr<PasswordFormManager> manager(new PasswordFormManager( |
| 277 profile(), NULL, NULL, *observed_form(), false)); |
| 278 |
| 279 SimulateMatchingPhase(manager.get(), true); |
| 280 // User logs in with the autofilled username / password from saved_match. |
| 281 PasswordForm login = *observed_form(); |
| 282 login.username_value = saved_match()->username_value; |
| 283 login.password_value = saved_match()->password_value; |
| 284 |
| 285 manager->ProvisionallySave(login); |
| 286 EXPECT_FALSE(manager->IsNewLogin()); |
| 287 // The observed action URL is different from the previously saved one, and |
| 288 // is the same as the one that would be submitted on successful login. |
| 289 EXPECT_NE(observed_form()->action, saved_match()->action); |
| 290 EXPECT_EQ(observed_form()->action, |
| 291 GetPendingCredentials(manager.get())->action); |
| 292 } |
| 293 |
| 294 TEST_F(PasswordFormManagerTest, TestDynamicAction) { |
| 295 scoped_ptr<PasswordFormManager> manager(new PasswordFormManager( |
| 296 profile(), NULL, NULL, *observed_form(), false)); |
| 297 |
| 298 SimulateMatchingPhase(manager.get(), false); |
| 299 PasswordForm login(*observed_form()); |
| 300 // The submitted action URL is different from the one observed on page load. |
| 301 GURL new_action = GURL("http://www.google.com/new_action"); |
| 302 login.action = new_action; |
| 303 |
| 304 manager->ProvisionallySave(login); |
| 305 EXPECT_TRUE(manager->IsNewLogin()); |
| 306 // Check that the provisionally saved action URL is the same as the submitted |
| 307 // action URL, not the one observed on page load. |
| 308 EXPECT_EQ(new_action, |
| 309 GetPendingCredentials(manager.get())->action); |
| 310 } |
| 311 |
| 273 TEST_F(PasswordFormManagerTest, TestValidForms) { | 312 TEST_F(PasswordFormManagerTest, TestValidForms) { |
| 274 // User submits credentials for the observed form. | 313 // User submits credentials for the observed form. |
| 275 PasswordForm credentials = *observed_form(); | 314 PasswordForm credentials = *observed_form(); |
| 276 credentials.scheme = PasswordForm::SCHEME_HTML; | 315 credentials.scheme = PasswordForm::SCHEME_HTML; |
| 277 credentials.username_value = saved_match()->username_value; | 316 credentials.username_value = saved_match()->username_value; |
| 278 credentials.password_value = saved_match()->password_value; | 317 credentials.password_value = saved_match()->password_value; |
| 279 | 318 |
| 280 // Form with both username_element and password_element. | 319 // Form with both username_element and password_element. |
| 281 PasswordFormManager manager1(profile(), NULL, NULL, credentials, false); | 320 PasswordFormManager manager1(profile(), NULL, NULL, credentials, false); |
| 282 SimulateMatchingPhase(&manager1, false); | 321 SimulateMatchingPhase(&manager1, false); |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 365 // password store, but is blacklisted; We should not send the not blacklisted | 404 // password store, but is blacklisted; We should not send the not blacklisted |
| 366 // message. | 405 // message. |
| 367 manager.reset(new TestPasswordFormManager( | 406 manager.reset(new TestPasswordFormManager( |
| 368 profile(), &password_manager, *observed_form(), false)); | 407 profile(), &password_manager, *observed_form(), false)); |
| 369 SimulateFetchMatchingLoginsFromPasswordStore(manager.get(), 3); | 408 SimulateFetchMatchingLoginsFromPasswordStore(manager.get(), 3); |
| 370 result.clear(); | 409 result.clear(); |
| 371 result.push_back(CreateSavedMatch(true)); | 410 result.push_back(CreateSavedMatch(true)); |
| 372 SimulateResponseFromPasswordStore(manager.get(), 3, result); | 411 SimulateResponseFromPasswordStore(manager.get(), 3, result); |
| 373 EXPECT_EQ(0u, manager->num_sent_messages()); | 412 EXPECT_EQ(0u, manager->num_sent_messages()); |
| 374 } | 413 } |
| OLD | NEW |