| 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 <vector> | 5 #include <vector> |
| 6 | 6 |
| 7 #include "base/message_loop/message_loop.h" | 7 #include "base/message_loop/message_loop.h" |
| 8 #include "base/prefs/pref_registry_simple.h" | 8 #include "base/prefs/pref_registry_simple.h" |
| 9 #include "base/prefs/pref_service.h" | 9 #include "base/prefs/pref_service.h" |
| 10 #include "base/prefs/testing_pref_service.h" | 10 #include "base/prefs/testing_pref_service.h" |
| (...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 205 TEST_F(PasswordManagerTest, FormSubmitEmptyStore) { | 205 TEST_F(PasswordManagerTest, FormSubmitEmptyStore) { |
| 206 // Test that observing a newly submitted form shows the save password bar. | 206 // Test that observing a newly submitted form shows the save password bar. |
| 207 std::vector<PasswordForm*> result; // Empty password store. | 207 std::vector<PasswordForm*> result; // Empty password store. |
| 208 EXPECT_CALL(driver_, FillPasswordForm(_)).Times(Exactly(0)); | 208 EXPECT_CALL(driver_, FillPasswordForm(_)).Times(Exactly(0)); |
| 209 EXPECT_CALL(*store_.get(), GetLogins(_, _, _)) | 209 EXPECT_CALL(*store_.get(), GetLogins(_, _, _)) |
| 210 .WillOnce(DoAll(WithArg<2>(InvokeConsumer(result)), Return())); | 210 .WillOnce(DoAll(WithArg<2>(InvokeConsumer(result)), Return())); |
| 211 std::vector<PasswordForm> observed; | 211 std::vector<PasswordForm> observed; |
| 212 PasswordForm form(MakeSimpleForm()); | 212 PasswordForm form(MakeSimpleForm()); |
| 213 observed.push_back(form); | 213 observed.push_back(form); |
| 214 manager()->OnPasswordFormsParsed(observed); // The initial load. | 214 manager()->OnPasswordFormsParsed(observed); // The initial load. |
| 215 manager()->OnPasswordFormsRendered(observed); // The initial layout. | 215 manager()->OnPasswordFormsRendered(observed, true); // The initial layout. |
| 216 | 216 |
| 217 // And the form submit contract is to call ProvisionallySavePassword. | 217 // And the form submit contract is to call ProvisionallySavePassword. |
| 218 manager()->ProvisionallySavePassword(form); | 218 manager()->ProvisionallySavePassword(form); |
| 219 | 219 |
| 220 scoped_ptr<PasswordFormManager> form_to_save; | 220 scoped_ptr<PasswordFormManager> form_to_save; |
| 221 EXPECT_CALL(client_, PromptUserToSavePassword(_)) | 221 EXPECT_CALL(client_, PromptUserToSavePassword(_)) |
| 222 .WillOnce(WithArg<0>(SaveToScopedPtr(&form_to_save))); | 222 .WillOnce(WithArg<0>(SaveToScopedPtr(&form_to_save))); |
| 223 | 223 |
| 224 // Now the password manager waits for the navigation to complete. | 224 // Now the password manager waits for the navigation to complete. |
| 225 observed.clear(); | 225 observed.clear(); |
| 226 manager()->OnPasswordFormsParsed(observed); // The post-navigation load. | 226 manager()->OnPasswordFormsParsed(observed); // The post-navigation load. |
| 227 manager()->OnPasswordFormsRendered(observed); // The post-navigation layout. | 227 manager()->OnPasswordFormsRendered(observed, |
| 228 true); // The post-navigation layout. |
| 228 | 229 |
| 229 ASSERT_TRUE(form_to_save.get()); | 230 ASSERT_TRUE(form_to_save.get()); |
| 230 EXPECT_CALL(*store_.get(), AddLogin(FormMatches(form))); | 231 EXPECT_CALL(*store_.get(), AddLogin(FormMatches(form))); |
| 231 | 232 |
| 232 // Simulate saving the form, as if the info bar was accepted. | 233 // Simulate saving the form, as if the info bar was accepted. |
| 233 form_to_save->Save(); | 234 form_to_save->Save(); |
| 234 } | 235 } |
| 235 | 236 |
| 236 TEST_F(PasswordManagerTest, GeneratedPasswordFormSubmitEmptyStore) { | 237 TEST_F(PasswordManagerTest, GeneratedPasswordFormSubmitEmptyStore) { |
| 237 // This test is the same FormSubmitEmptyStore, except that it simulates the | 238 // This test is the same FormSubmitEmptyStore, except that it simulates the |
| 238 // user generating the password through the browser. | 239 // user generating the password through the browser. |
| 239 std::vector<PasswordForm*> result; // Empty password store. | 240 std::vector<PasswordForm*> result; // Empty password store. |
| 240 EXPECT_CALL(driver_, FillPasswordForm(_)).Times(Exactly(0)); | 241 EXPECT_CALL(driver_, FillPasswordForm(_)).Times(Exactly(0)); |
| 241 EXPECT_CALL(*store_.get(), GetLogins(_, _, _)) | 242 EXPECT_CALL(*store_.get(), GetLogins(_, _, _)) |
| 242 .WillOnce(DoAll(WithArg<2>(InvokeConsumer(result)), Return())); | 243 .WillOnce(DoAll(WithArg<2>(InvokeConsumer(result)), Return())); |
| 243 std::vector<PasswordForm> observed; | 244 std::vector<PasswordForm> observed; |
| 244 PasswordForm form(MakeSimpleForm()); | 245 PasswordForm form(MakeSimpleForm()); |
| 245 observed.push_back(form); | 246 observed.push_back(form); |
| 246 manager()->OnPasswordFormsParsed(observed); // The initial load. | 247 manager()->OnPasswordFormsParsed(observed); // The initial load. |
| 247 manager()->OnPasswordFormsRendered(observed); // The initial layout. | 248 manager()->OnPasswordFormsRendered(observed, true); // The initial layout. |
| 248 | 249 |
| 249 // Simulate the user generating the password and submitting the form. | 250 // Simulate the user generating the password and submitting the form. |
| 250 manager()->SetFormHasGeneratedPassword(form); | 251 manager()->SetFormHasGeneratedPassword(form); |
| 251 manager()->ProvisionallySavePassword(form); | 252 manager()->ProvisionallySavePassword(form); |
| 252 | 253 |
| 253 // The user should not be presented with an infobar as they have already given | 254 // The user should not be presented with an infobar as they have already given |
| 254 // consent by using the generated password. The form should be saved once | 255 // consent by using the generated password. The form should be saved once |
| 255 // navigation occurs. | 256 // navigation occurs. |
| 256 EXPECT_CALL(client_, PromptUserToSavePassword(_)).Times(Exactly(0)); | 257 EXPECT_CALL(client_, PromptUserToSavePassword(_)).Times(Exactly(0)); |
| 257 EXPECT_CALL(*store_.get(), AddLogin(FormMatches(form))); | 258 EXPECT_CALL(*store_.get(), AddLogin(FormMatches(form))); |
| 258 | 259 |
| 259 // Now the password manager waits for the navigation to complete. | 260 // Now the password manager waits for the navigation to complete. |
| 260 observed.clear(); | 261 observed.clear(); |
| 261 manager()->OnPasswordFormsParsed(observed); // The post-navigation load. | 262 manager()->OnPasswordFormsParsed(observed); // The post-navigation load. |
| 262 manager()->OnPasswordFormsRendered(observed); // The post-navigation layout. | 263 manager()->OnPasswordFormsRendered(observed, |
| 264 true); // The post-navigation layout. |
| 263 } | 265 } |
| 264 | 266 |
| 265 TEST_F(PasswordManagerTest, FormSubmitNoGoodMatch) { | 267 TEST_F(PasswordManagerTest, FormSubmitNoGoodMatch) { |
| 266 // Same as above, except with an existing form for the same signon realm, | 268 // Same as above, except with an existing form for the same signon realm, |
| 267 // but different origin. Detailed cases like this are covered by | 269 // but different origin. Detailed cases like this are covered by |
| 268 // PasswordFormManagerTest. | 270 // PasswordFormManagerTest. |
| 269 std::vector<PasswordForm*> result; | 271 std::vector<PasswordForm*> result; |
| 270 PasswordForm* existing_different = new PasswordForm(MakeSimpleForm()); | 272 PasswordForm* existing_different = new PasswordForm(MakeSimpleForm()); |
| 271 existing_different->username_value = ASCIIToUTF16("google2"); | 273 existing_different->username_value = ASCIIToUTF16("google2"); |
| 272 result.push_back(existing_different); | 274 result.push_back(existing_different); |
| 273 EXPECT_CALL(driver_, FillPasswordForm(_)); | 275 EXPECT_CALL(driver_, FillPasswordForm(_)); |
| 274 EXPECT_CALL(*store_.get(), GetLogins(_, _, _)) | 276 EXPECT_CALL(*store_.get(), GetLogins(_, _, _)) |
| 275 .WillOnce(DoAll(WithArg<2>(InvokeConsumer(result)), Return())); | 277 .WillOnce(DoAll(WithArg<2>(InvokeConsumer(result)), Return())); |
| 276 | 278 |
| 277 std::vector<PasswordForm> observed; | 279 std::vector<PasswordForm> observed; |
| 278 PasswordForm form(MakeSimpleForm()); | 280 PasswordForm form(MakeSimpleForm()); |
| 279 observed.push_back(form); | 281 observed.push_back(form); |
| 280 manager()->OnPasswordFormsParsed(observed); // The initial load. | 282 manager()->OnPasswordFormsParsed(observed); // The initial load. |
| 281 manager()->OnPasswordFormsRendered(observed); // The initial layout. | 283 manager()->OnPasswordFormsRendered(observed, true); // The initial layout. |
| 282 manager()->ProvisionallySavePassword(form); | 284 manager()->ProvisionallySavePassword(form); |
| 283 | 285 |
| 284 // We still expect an add, since we didn't have a good match. | 286 // We still expect an add, since we didn't have a good match. |
| 285 scoped_ptr<PasswordFormManager> form_to_save; | 287 scoped_ptr<PasswordFormManager> form_to_save; |
| 286 EXPECT_CALL(client_, PromptUserToSavePassword(_)) | 288 EXPECT_CALL(client_, PromptUserToSavePassword(_)) |
| 287 .WillOnce(WithArg<0>(SaveToScopedPtr(&form_to_save))); | 289 .WillOnce(WithArg<0>(SaveToScopedPtr(&form_to_save))); |
| 288 | 290 |
| 289 // Now the password manager waits for the navigation to complete. | 291 // Now the password manager waits for the navigation to complete. |
| 290 observed.clear(); | 292 observed.clear(); |
| 291 manager()->OnPasswordFormsParsed(observed); // The post-navigation load. | 293 manager()->OnPasswordFormsParsed(observed); // The post-navigation load. |
| 292 manager()->OnPasswordFormsRendered(observed); // The post-navigation layout. | 294 manager()->OnPasswordFormsRendered(observed, |
| 295 true); // The post-navigation layout. |
| 293 | 296 |
| 294 ASSERT_TRUE(form_to_save.get()); | 297 ASSERT_TRUE(form_to_save.get()); |
| 295 EXPECT_CALL(*store_.get(), AddLogin(FormMatches(form))); | 298 EXPECT_CALL(*store_.get(), AddLogin(FormMatches(form))); |
| 296 | 299 |
| 297 // Simulate saving the form. | 300 // Simulate saving the form. |
| 298 form_to_save->Save(); | 301 form_to_save->Save(); |
| 299 } | 302 } |
| 300 | 303 |
| 301 TEST_F(PasswordManagerTest, FormSeenThenLeftPage) { | 304 TEST_F(PasswordManagerTest, FormSeenThenLeftPage) { |
| 302 std::vector<PasswordForm*> result; // Empty password store. | 305 std::vector<PasswordForm*> result; // Empty password store. |
| 303 EXPECT_CALL(driver_, FillPasswordForm(_)).Times(Exactly(0)); | 306 EXPECT_CALL(driver_, FillPasswordForm(_)).Times(Exactly(0)); |
| 304 EXPECT_CALL(*store_.get(), GetLogins(_, _, _)) | 307 EXPECT_CALL(*store_.get(), GetLogins(_, _, _)) |
| 305 .WillOnce(DoAll(WithArg<2>(InvokeConsumer(result)), Return())); | 308 .WillOnce(DoAll(WithArg<2>(InvokeConsumer(result)), Return())); |
| 306 std::vector<PasswordForm> observed; | 309 std::vector<PasswordForm> observed; |
| 307 PasswordForm form(MakeSimpleForm()); | 310 PasswordForm form(MakeSimpleForm()); |
| 308 observed.push_back(form); | 311 observed.push_back(form); |
| 309 manager()->OnPasswordFormsParsed(observed); // The initial load. | 312 manager()->OnPasswordFormsParsed(observed); // The initial load. |
| 310 manager()->OnPasswordFormsRendered(observed); // The initial layout. | 313 manager()->OnPasswordFormsRendered(observed, true); // The initial layout. |
| 311 | 314 |
| 312 // No message from the renderer that a password was submitted. No | 315 // No message from the renderer that a password was submitted. No |
| 313 // expected calls. | 316 // expected calls. |
| 314 EXPECT_CALL(client_, PromptUserToSavePassword(_)).Times(0); | 317 EXPECT_CALL(client_, PromptUserToSavePassword(_)).Times(0); |
| 315 observed.clear(); | 318 observed.clear(); |
| 316 manager()->OnPasswordFormsParsed(observed); // The post-navigation load. | 319 manager()->OnPasswordFormsParsed(observed); // The post-navigation load. |
| 317 manager()->OnPasswordFormsRendered(observed); // The post-navigation layout. | 320 manager()->OnPasswordFormsRendered(observed, |
| 321 true); // The post-navigation layout. |
| 318 } | 322 } |
| 319 | 323 |
| 320 TEST_F(PasswordManagerTest, FormSubmitAfterNavigateInPage) { | 324 TEST_F(PasswordManagerTest, FormSubmitAfterNavigateInPage) { |
| 321 // Test that navigating in the page does not prevent us from showing the save | 325 // Test that navigating in the page does not prevent us from showing the save |
| 322 // password infobar. | 326 // password infobar. |
| 323 std::vector<PasswordForm*> result; // Empty password store. | 327 std::vector<PasswordForm*> result; // Empty password store. |
| 324 EXPECT_CALL(driver_, FillPasswordForm(_)).Times(Exactly(0)); | 328 EXPECT_CALL(driver_, FillPasswordForm(_)).Times(Exactly(0)); |
| 325 EXPECT_CALL(*store_.get(), GetLogins(_, _, _)) | 329 EXPECT_CALL(*store_.get(), GetLogins(_, _, _)) |
| 326 .WillOnce(DoAll(WithArg<2>(InvokeConsumer(result)), Return())); | 330 .WillOnce(DoAll(WithArg<2>(InvokeConsumer(result)), Return())); |
| 327 std::vector<PasswordForm> observed; | 331 std::vector<PasswordForm> observed; |
| 328 PasswordForm form(MakeSimpleForm()); | 332 PasswordForm form(MakeSimpleForm()); |
| 329 observed.push_back(form); | 333 observed.push_back(form); |
| 330 manager()->OnPasswordFormsParsed(observed); // The initial load. | 334 manager()->OnPasswordFormsParsed(observed); // The initial load. |
| 331 manager()->OnPasswordFormsRendered(observed); // The initial layout. | 335 manager()->OnPasswordFormsRendered(observed, true); // The initial layout. |
| 332 | 336 |
| 333 // Simulate navigating in the page. | 337 // Simulate navigating in the page. |
| 334 manager()->DidNavigateMainFrame(true); | 338 manager()->DidNavigateMainFrame(true); |
| 335 | 339 |
| 336 // Simulate submitting the password. | 340 // Simulate submitting the password. |
| 337 OnPasswordFormSubmitted(form); | 341 OnPasswordFormSubmitted(form); |
| 338 | 342 |
| 339 // Now the password manager waits for the navigation to complete. | 343 // Now the password manager waits for the navigation to complete. |
| 340 scoped_ptr<PasswordFormManager> form_to_save; | 344 scoped_ptr<PasswordFormManager> form_to_save; |
| 341 EXPECT_CALL(client_, PromptUserToSavePassword(_)) | 345 EXPECT_CALL(client_, PromptUserToSavePassword(_)) |
| 342 .WillOnce(WithArg<0>(SaveToScopedPtr(&form_to_save))); | 346 .WillOnce(WithArg<0>(SaveToScopedPtr(&form_to_save))); |
| 343 | 347 |
| 344 observed.clear(); | 348 observed.clear(); |
| 345 manager()->OnPasswordFormsParsed(observed); // The post-navigation load. | 349 manager()->OnPasswordFormsParsed(observed); // The post-navigation load. |
| 346 manager()->OnPasswordFormsRendered(observed); // The post-navigation layout. | 350 manager()->OnPasswordFormsRendered(observed, |
| 351 true); // The post-navigation layout. |
| 347 | 352 |
| 348 ASSERT_FALSE(NULL == form_to_save.get()); | 353 ASSERT_FALSE(NULL == form_to_save.get()); |
| 349 EXPECT_CALL(*store_.get(), AddLogin(FormMatches(form))); | 354 EXPECT_CALL(*store_.get(), AddLogin(FormMatches(form))); |
| 350 | 355 |
| 351 // Simulate saving the form, as if the info bar was accepted. | 356 // Simulate saving the form, as if the info bar was accepted. |
| 352 form_to_save->Save(); | 357 form_to_save->Save(); |
| 353 } | 358 } |
| 354 | 359 |
| 355 // This test verifies a fix for http://crbug.com/236673 | 360 // This test verifies a fix for http://crbug.com/236673 |
| 356 TEST_F(PasswordManagerTest, FormSubmitWithFormOnPreviousPage) { | 361 TEST_F(PasswordManagerTest, FormSubmitWithFormOnPreviousPage) { |
| 357 std::vector<PasswordForm*> result; // Empty password store. | 362 std::vector<PasswordForm*> result; // Empty password store. |
| 358 EXPECT_CALL(driver_, FillPasswordForm(_)).Times(Exactly(0)); | 363 EXPECT_CALL(driver_, FillPasswordForm(_)).Times(Exactly(0)); |
| 359 EXPECT_CALL(*store_.get(), GetLogins(_, _, _)) | 364 EXPECT_CALL(*store_.get(), GetLogins(_, _, _)) |
| 360 .WillRepeatedly(DoAll(WithArg<2>(InvokeConsumer(result)), Return())); | 365 .WillRepeatedly(DoAll(WithArg<2>(InvokeConsumer(result)), Return())); |
| 361 PasswordForm first_form(MakeSimpleForm()); | 366 PasswordForm first_form(MakeSimpleForm()); |
| 362 first_form.origin = GURL("http://www.nytimes.com/"); | 367 first_form.origin = GURL("http://www.nytimes.com/"); |
| 363 first_form.action = GURL("https://myaccount.nytimes.com/auth/login"); | 368 first_form.action = GURL("https://myaccount.nytimes.com/auth/login"); |
| 364 first_form.signon_realm = "http://www.nytimes.com/"; | 369 first_form.signon_realm = "http://www.nytimes.com/"; |
| 365 PasswordForm second_form(MakeSimpleForm()); | 370 PasswordForm second_form(MakeSimpleForm()); |
| 366 second_form.origin = GURL("https://myaccount.nytimes.com/auth/login"); | 371 second_form.origin = GURL("https://myaccount.nytimes.com/auth/login"); |
| 367 second_form.action = GURL("https://myaccount.nytimes.com/auth/login"); | 372 second_form.action = GURL("https://myaccount.nytimes.com/auth/login"); |
| 368 second_form.signon_realm = "https://myaccount.nytimes.com/"; | 373 second_form.signon_realm = "https://myaccount.nytimes.com/"; |
| 369 | 374 |
| 370 // Pretend that the form is hidden on the first page. | 375 // Pretend that the form is hidden on the first page. |
| 371 std::vector<PasswordForm> observed; | 376 std::vector<PasswordForm> observed; |
| 372 observed.push_back(first_form); | 377 observed.push_back(first_form); |
| 373 manager()->OnPasswordFormsParsed(observed); | 378 manager()->OnPasswordFormsParsed(observed); |
| 374 observed.clear(); | 379 observed.clear(); |
| 375 manager()->OnPasswordFormsRendered(observed); | 380 manager()->OnPasswordFormsRendered(observed, true); |
| 376 | 381 |
| 377 // Now navigate to a second page. | 382 // Now navigate to a second page. |
| 378 manager()->DidNavigateMainFrame(false); | 383 manager()->DidNavigateMainFrame(false); |
| 379 | 384 |
| 380 // This page contains a form with the same markup, but on a different | 385 // This page contains a form with the same markup, but on a different |
| 381 // URL. | 386 // URL. |
| 382 observed.push_back(second_form); | 387 observed.push_back(second_form); |
| 383 manager()->OnPasswordFormsParsed(observed); | 388 manager()->OnPasswordFormsParsed(observed); |
| 384 manager()->OnPasswordFormsRendered(observed); | 389 manager()->OnPasswordFormsRendered(observed, true); |
| 385 | 390 |
| 386 // Now submit this form | 391 // Now submit this form |
| 387 OnPasswordFormSubmitted(second_form); | 392 OnPasswordFormSubmitted(second_form); |
| 388 | 393 |
| 389 // Navigation after form submit. | 394 // Navigation after form submit. |
| 390 scoped_ptr<PasswordFormManager> form_to_save; | 395 scoped_ptr<PasswordFormManager> form_to_save; |
| 391 EXPECT_CALL(client_, PromptUserToSavePassword(_)) | 396 EXPECT_CALL(client_, PromptUserToSavePassword(_)) |
| 392 .WillOnce(WithArg<0>(SaveToScopedPtr(&form_to_save))); | 397 .WillOnce(WithArg<0>(SaveToScopedPtr(&form_to_save))); |
| 393 observed.clear(); | 398 observed.clear(); |
| 394 manager()->OnPasswordFormsParsed(observed); | 399 manager()->OnPasswordFormsParsed(observed); |
| 395 manager()->OnPasswordFormsRendered(observed); | 400 manager()->OnPasswordFormsRendered(observed, true); |
| 396 | 401 |
| 397 // Make sure that the saved form matches the second form, not the first. | 402 // Make sure that the saved form matches the second form, not the first. |
| 398 ASSERT_TRUE(form_to_save.get()); | 403 ASSERT_TRUE(form_to_save.get()); |
| 399 EXPECT_CALL(*store_.get(), AddLogin(FormMatches(second_form))); | 404 EXPECT_CALL(*store_.get(), AddLogin(FormMatches(second_form))); |
| 400 | 405 |
| 401 // Simulate saving the form, as if the info bar was accepted. | 406 // Simulate saving the form, as if the info bar was accepted. |
| 402 form_to_save->Save(); | 407 form_to_save->Save(); |
| 403 } | 408 } |
| 404 | 409 |
| 405 TEST_F(PasswordManagerTest, FormSubmitFailedLogin) { | 410 TEST_F(PasswordManagerTest, FormSubmitFailedLogin) { |
| 406 std::vector<PasswordForm*> result; // Empty password store. | 411 std::vector<PasswordForm*> result; // Empty password store. |
| 407 EXPECT_CALL(driver_, FillPasswordForm(_)).Times(Exactly(0)); | 412 EXPECT_CALL(driver_, FillPasswordForm(_)).Times(Exactly(0)); |
| 408 EXPECT_CALL(*store_.get(), GetLogins(_, _, _)) | 413 EXPECT_CALL(*store_.get(), GetLogins(_, _, _)) |
| 409 .WillRepeatedly(DoAll(WithArg<2>(InvokeConsumer(result)), Return())); | 414 .WillRepeatedly(DoAll(WithArg<2>(InvokeConsumer(result)), Return())); |
| 410 std::vector<PasswordForm> observed; | 415 std::vector<PasswordForm> observed; |
| 411 PasswordForm form(MakeSimpleForm()); | 416 PasswordForm form(MakeSimpleForm()); |
| 412 observed.push_back(form); | 417 observed.push_back(form); |
| 413 manager()->OnPasswordFormsParsed(observed); // The initial load. | 418 manager()->OnPasswordFormsParsed(observed); // The initial load. |
| 414 manager()->OnPasswordFormsRendered(observed); // The initial layout. | 419 manager()->OnPasswordFormsRendered(observed, true); // The initial layout. |
| 415 | 420 |
| 416 manager()->ProvisionallySavePassword(form); | 421 manager()->ProvisionallySavePassword(form); |
| 417 | 422 |
| 418 // The form reappears, and is visible in the layout: | 423 // The form reappears, and is visible in the layout: |
| 419 // No expected calls to the PasswordStore... | 424 // No expected calls to the PasswordStore... |
| 420 manager()->OnPasswordFormsParsed(observed); | 425 manager()->OnPasswordFormsParsed(observed); |
| 421 manager()->OnPasswordFormsRendered(observed); | 426 manager()->OnPasswordFormsRendered(observed, true); |
| 422 } | 427 } |
| 423 | 428 |
| 424 TEST_F(PasswordManagerTest, FormSubmitInvisibleLogin) { | 429 TEST_F(PasswordManagerTest, FormSubmitInvisibleLogin) { |
| 425 // Tests fix of issue 28911: if the login form reappears on the subsequent | 430 // Tests fix of issue 28911: if the login form reappears on the subsequent |
| 426 // page, but is invisible, it shouldn't count as a failed login. | 431 // page, but is invisible, it shouldn't count as a failed login. |
| 427 std::vector<PasswordForm*> result; // Empty password store. | 432 std::vector<PasswordForm*> result; // Empty password store. |
| 428 EXPECT_CALL(driver_, FillPasswordForm(_)).Times(Exactly(0)); | 433 EXPECT_CALL(driver_, FillPasswordForm(_)).Times(Exactly(0)); |
| 429 EXPECT_CALL(*store_.get(), GetLogins(_, _, _)) | 434 EXPECT_CALL(*store_.get(), GetLogins(_, _, _)) |
| 430 .WillRepeatedly(DoAll(WithArg<2>(InvokeConsumer(result)), Return())); | 435 .WillRepeatedly(DoAll(WithArg<2>(InvokeConsumer(result)), Return())); |
| 431 std::vector<PasswordForm> observed; | 436 std::vector<PasswordForm> observed; |
| 432 PasswordForm form(MakeSimpleForm()); | 437 PasswordForm form(MakeSimpleForm()); |
| 433 observed.push_back(form); | 438 observed.push_back(form); |
| 434 manager()->OnPasswordFormsParsed(observed); // The initial load. | 439 manager()->OnPasswordFormsParsed(observed); // The initial load. |
| 435 manager()->OnPasswordFormsRendered(observed); // The initial layout. | 440 manager()->OnPasswordFormsRendered(observed, true); // The initial layout. |
| 436 | 441 |
| 437 manager()->ProvisionallySavePassword(form); | 442 manager()->ProvisionallySavePassword(form); |
| 438 | 443 |
| 439 // Expect info bar to appear: | 444 // Expect info bar to appear: |
| 440 scoped_ptr<PasswordFormManager> form_to_save; | 445 scoped_ptr<PasswordFormManager> form_to_save; |
| 441 EXPECT_CALL(client_, PromptUserToSavePassword(_)) | 446 EXPECT_CALL(client_, PromptUserToSavePassword(_)) |
| 442 .WillOnce(WithArg<0>(SaveToScopedPtr(&form_to_save))); | 447 .WillOnce(WithArg<0>(SaveToScopedPtr(&form_to_save))); |
| 443 | 448 |
| 444 // The form reappears, but is not visible in the layout: | 449 // The form reappears, but is not visible in the layout: |
| 445 manager()->OnPasswordFormsParsed(observed); | 450 manager()->OnPasswordFormsParsed(observed); |
| 446 observed.clear(); | 451 observed.clear(); |
| 447 manager()->OnPasswordFormsRendered(observed); | 452 manager()->OnPasswordFormsRendered(observed, true); |
| 448 | 453 |
| 449 ASSERT_TRUE(form_to_save.get()); | 454 ASSERT_TRUE(form_to_save.get()); |
| 450 EXPECT_CALL(*store_.get(), AddLogin(FormMatches(form))); | 455 EXPECT_CALL(*store_.get(), AddLogin(FormMatches(form))); |
| 451 | 456 |
| 452 // Simulate saving the form. | 457 // Simulate saving the form. |
| 453 form_to_save->Save(); | 458 form_to_save->Save(); |
| 454 } | 459 } |
| 455 | 460 |
| 456 TEST_F(PasswordManagerTest, InitiallyInvisibleForm) { | 461 TEST_F(PasswordManagerTest, InitiallyInvisibleForm) { |
| 457 // Make sure an invisible login form still gets autofilled. | 462 // Make sure an invisible login form still gets autofilled. |
| 458 std::vector<PasswordForm*> result; | 463 std::vector<PasswordForm*> result; |
| 459 PasswordForm* existing = new PasswordForm(MakeSimpleForm()); | 464 PasswordForm* existing = new PasswordForm(MakeSimpleForm()); |
| 460 result.push_back(existing); | 465 result.push_back(existing); |
| 461 EXPECT_CALL(driver_, FillPasswordForm(_)); | 466 EXPECT_CALL(driver_, FillPasswordForm(_)); |
| 462 EXPECT_CALL(*store_.get(), GetLogins(_, _, _)) | 467 EXPECT_CALL(*store_.get(), GetLogins(_, _, _)) |
| 463 .WillRepeatedly(DoAll(WithArg<2>(InvokeConsumer(result)), Return())); | 468 .WillRepeatedly(DoAll(WithArg<2>(InvokeConsumer(result)), Return())); |
| 464 std::vector<PasswordForm> observed; | 469 std::vector<PasswordForm> observed; |
| 465 PasswordForm form(MakeSimpleForm()); | 470 PasswordForm form(MakeSimpleForm()); |
| 466 observed.push_back(form); | 471 observed.push_back(form); |
| 467 manager()->OnPasswordFormsParsed(observed); // The initial load. | 472 manager()->OnPasswordFormsParsed(observed); // The initial load. |
| 468 observed.clear(); | 473 observed.clear(); |
| 469 manager()->OnPasswordFormsRendered(observed); // The initial layout. | 474 manager()->OnPasswordFormsRendered(observed, true); // The initial layout. |
| 470 | 475 |
| 471 manager()->OnPasswordFormsParsed(observed); // The post-navigation load. | 476 manager()->OnPasswordFormsParsed(observed); // The post-navigation load. |
| 472 manager()->OnPasswordFormsRendered(observed); // The post-navigation layout. | 477 manager()->OnPasswordFormsRendered(observed, |
| 478 true); // The post-navigation layout. |
| 473 } | 479 } |
| 474 | 480 |
| 475 TEST_F(PasswordManagerTest, SavingDependsOnManagerEnabledPreference) { | 481 TEST_F(PasswordManagerTest, SavingDependsOnManagerEnabledPreference) { |
| 476 // Test that saving passwords depends on the password manager enabled | 482 // Test that saving passwords depends on the password manager enabled |
| 477 // preference. | 483 // preference. |
| 478 prefs_.SetUserPref(prefs::kPasswordManagerEnabled, | 484 prefs_.SetUserPref(prefs::kPasswordManagerEnabled, |
| 479 base::Value::CreateBooleanValue(true)); | 485 base::Value::CreateBooleanValue(true)); |
| 480 EXPECT_TRUE(manager()->IsSavingEnabledForCurrentPage()); | 486 EXPECT_TRUE(manager()->IsSavingEnabledForCurrentPage()); |
| 481 prefs_.SetUserPref(prefs::kPasswordManagerEnabled, | 487 prefs_.SetUserPref(prefs::kPasswordManagerEnabled, |
| 482 base::Value::CreateBooleanValue(false)); | 488 base::Value::CreateBooleanValue(false)); |
| (...skipping 23 matching lines...) Expand all Loading... |
| 506 // autocomplete=off. | 512 // autocomplete=off. |
| 507 std::vector<PasswordForm*> result; // Empty password store. | 513 std::vector<PasswordForm*> result; // Empty password store. |
| 508 EXPECT_CALL(driver_, FillPasswordForm(_)).Times(Exactly(0)); | 514 EXPECT_CALL(driver_, FillPasswordForm(_)).Times(Exactly(0)); |
| 509 EXPECT_CALL(*store_.get(), GetLogins(_, _, _)) | 515 EXPECT_CALL(*store_.get(), GetLogins(_, _, _)) |
| 510 .WillOnce(DoAll(WithArg<2>(InvokeConsumer(result)), Return())); | 516 .WillOnce(DoAll(WithArg<2>(InvokeConsumer(result)), Return())); |
| 511 std::vector<PasswordForm> observed; | 517 std::vector<PasswordForm> observed; |
| 512 PasswordForm form(MakeSimpleForm()); | 518 PasswordForm form(MakeSimpleForm()); |
| 513 form.password_autocomplete_set = false; | 519 form.password_autocomplete_set = false; |
| 514 observed.push_back(form); | 520 observed.push_back(form); |
| 515 manager()->OnPasswordFormsParsed(observed); // The initial load. | 521 manager()->OnPasswordFormsParsed(observed); // The initial load. |
| 516 manager()->OnPasswordFormsRendered(observed); // The initial layout. | 522 manager()->OnPasswordFormsRendered(observed, true); // The initial layout. |
| 517 | 523 |
| 518 // And the form submit contract is to call ProvisionallySavePassword. | 524 // And the form submit contract is to call ProvisionallySavePassword. |
| 519 manager()->ProvisionallySavePassword(form); | 525 manager()->ProvisionallySavePassword(form); |
| 520 | 526 |
| 521 // Password form should be saved. | 527 // Password form should be saved. |
| 522 scoped_ptr<PasswordFormManager> form_to_save; | 528 scoped_ptr<PasswordFormManager> form_to_save; |
| 523 EXPECT_CALL(client_, PromptUserToSavePassword(_)).Times(Exactly(1)).WillOnce( | 529 EXPECT_CALL(client_, PromptUserToSavePassword(_)).Times(Exactly(1)).WillOnce( |
| 524 WithArg<0>(SaveToScopedPtr(&form_to_save))); | 530 WithArg<0>(SaveToScopedPtr(&form_to_save))); |
| 525 EXPECT_CALL(*store_.get(), AddLogin(FormMatches(form))).Times(Exactly(0)); | 531 EXPECT_CALL(*store_.get(), AddLogin(FormMatches(form))).Times(Exactly(0)); |
| 526 | 532 |
| 527 // Now the password manager waits for the navigation to complete. | 533 // Now the password manager waits for the navigation to complete. |
| 528 observed.clear(); | 534 observed.clear(); |
| 529 manager()->OnPasswordFormsParsed(observed); // The post-navigation load. | 535 manager()->OnPasswordFormsParsed(observed); // The post-navigation load. |
| 530 manager()->OnPasswordFormsRendered(observed); // The post-navigation layout. | 536 manager()->OnPasswordFormsRendered(observed, |
| 537 true); // The post-navigation layout. |
| 531 | 538 |
| 532 ASSERT_TRUE(form_to_save.get()); | 539 ASSERT_TRUE(form_to_save.get()); |
| 533 } | 540 } |
| 534 | 541 |
| 535 TEST_F(PasswordManagerTest, GeneratedPasswordFormSavedAutocompleteOff) { | 542 TEST_F(PasswordManagerTest, GeneratedPasswordFormSavedAutocompleteOff) { |
| 536 // Test password form with generated password will still be saved if | 543 // Test password form with generated password will still be saved if |
| 537 // autocomplete=off. | 544 // autocomplete=off. |
| 538 std::vector<PasswordForm*> result; // Empty password store. | 545 std::vector<PasswordForm*> result; // Empty password store. |
| 539 EXPECT_CALL(driver_, FillPasswordForm(_)).Times(Exactly(0)); | 546 EXPECT_CALL(driver_, FillPasswordForm(_)).Times(Exactly(0)); |
| 540 EXPECT_CALL(*store_.get(), GetLogins(_, _, _)) | 547 EXPECT_CALL(*store_.get(), GetLogins(_, _, _)) |
| 541 .WillOnce(DoAll(WithArg<2>(InvokeConsumer(result)), Return())); | 548 .WillOnce(DoAll(WithArg<2>(InvokeConsumer(result)), Return())); |
| 542 std::vector<PasswordForm> observed; | 549 std::vector<PasswordForm> observed; |
| 543 PasswordForm form(MakeSimpleForm()); | 550 PasswordForm form(MakeSimpleForm()); |
| 544 form.password_autocomplete_set = false; | 551 form.password_autocomplete_set = false; |
| 545 observed.push_back(form); | 552 observed.push_back(form); |
| 546 manager()->OnPasswordFormsParsed(observed); // The initial load. | 553 manager()->OnPasswordFormsParsed(observed); // The initial load. |
| 547 manager()->OnPasswordFormsRendered(observed); // The initial layout. | 554 manager()->OnPasswordFormsRendered(observed, true); // The initial layout. |
| 548 | 555 |
| 549 // Simulate the user generating the password and submitting the form. | 556 // Simulate the user generating the password and submitting the form. |
| 550 manager()->SetFormHasGeneratedPassword(form); | 557 manager()->SetFormHasGeneratedPassword(form); |
| 551 manager()->ProvisionallySavePassword(form); | 558 manager()->ProvisionallySavePassword(form); |
| 552 | 559 |
| 553 // The user should not be presented with an infobar as they have already given | 560 // The user should not be presented with an infobar as they have already given |
| 554 // consent by using the generated password. The form should be saved once | 561 // consent by using the generated password. The form should be saved once |
| 555 // navigation occurs. | 562 // navigation occurs. |
| 556 EXPECT_CALL(client_, PromptUserToSavePassword(_)).Times(Exactly(0)); | 563 EXPECT_CALL(client_, PromptUserToSavePassword(_)).Times(Exactly(0)); |
| 557 EXPECT_CALL(*store_.get(), AddLogin(FormMatches(form))); | 564 EXPECT_CALL(*store_.get(), AddLogin(FormMatches(form))); |
| 558 | 565 |
| 559 // Now the password manager waits for the navigation to complete. | 566 // Now the password manager waits for the navigation to complete. |
| 560 observed.clear(); | 567 observed.clear(); |
| 561 manager()->OnPasswordFormsParsed(observed); // The post-navigation load. | 568 manager()->OnPasswordFormsParsed(observed); // The post-navigation load. |
| 562 manager()->OnPasswordFormsRendered(observed); // The post-navigation layout. | 569 manager()->OnPasswordFormsRendered(observed, |
| 570 true); // The post-navigation layout. |
| 563 } | 571 } |
| 564 | 572 |
| 565 TEST_F(PasswordManagerTest, SubmissionCallbackTest) { | 573 TEST_F(PasswordManagerTest, SubmissionCallbackTest) { |
| 566 manager()->AddSubmissionCallback(SubmissionCallback()); | 574 manager()->AddSubmissionCallback(SubmissionCallback()); |
| 567 PasswordForm form = MakeSimpleForm(); | 575 PasswordForm form = MakeSimpleForm(); |
| 568 OnPasswordFormSubmitted(form); | 576 OnPasswordFormSubmitted(form); |
| 569 EXPECT_TRUE(FormsAreEqual(form, submitted_form_)); | 577 EXPECT_TRUE(FormsAreEqual(form, submitted_form_)); |
| 570 } | 578 } |
| 571 | 579 |
| 572 TEST_F(PasswordManagerTest, PasswordFormReappearance) { | 580 TEST_F(PasswordManagerTest, PasswordFormReappearance) { |
| 573 // Test the heuristic to know if a password form reappears. | 581 // Test the heuristic to know if a password form reappears. |
| 574 // We assume that if we send our credentials and there | 582 // We assume that if we send our credentials and there |
| 575 // is at least one visible password form in the next page that | 583 // is at least one visible password form in the next page that |
| 576 // means that our previous login attempt failed. | 584 // means that our previous login attempt failed. |
| 577 std::vector<PasswordForm*> result; // Empty password store. | 585 std::vector<PasswordForm*> result; // Empty password store. |
| 578 EXPECT_CALL(driver_, FillPasswordForm(_)).Times(0); | 586 EXPECT_CALL(driver_, FillPasswordForm(_)).Times(0); |
| 579 EXPECT_CALL(*store_.get(), GetLogins(_, _, _)) | 587 EXPECT_CALL(*store_.get(), GetLogins(_, _, _)) |
| 580 .WillRepeatedly(DoAll(WithArg<2>(InvokeConsumer(result)), Return())); | 588 .WillRepeatedly(DoAll(WithArg<2>(InvokeConsumer(result)), Return())); |
| 581 std::vector<PasswordForm> observed; | 589 std::vector<PasswordForm> observed; |
| 582 PasswordForm login_form(MakeTwitterLoginForm()); | 590 PasswordForm login_form(MakeTwitterLoginForm()); |
| 583 observed.push_back(login_form); | 591 observed.push_back(login_form); |
| 584 manager()->OnPasswordFormsParsed(observed); // The initial load. | 592 manager()->OnPasswordFormsParsed(observed); // The initial load. |
| 585 manager()->OnPasswordFormsRendered(observed); // The initial layout. | 593 manager()->OnPasswordFormsRendered(observed, true); // The initial layout. |
| 586 | 594 |
| 587 manager()->ProvisionallySavePassword(login_form); | 595 manager()->ProvisionallySavePassword(login_form); |
| 588 | 596 |
| 589 PasswordForm failed_login_form(MakeTwitterFailedLoginForm()); | 597 PasswordForm failed_login_form(MakeTwitterFailedLoginForm()); |
| 590 observed.clear(); | 598 observed.clear(); |
| 591 observed.push_back(failed_login_form); | 599 observed.push_back(failed_login_form); |
| 592 // A PasswordForm appears, and is visible in the layout: | 600 // A PasswordForm appears, and is visible in the layout: |
| 593 // No expected calls to the PasswordStore... | 601 // No expected calls to the PasswordStore... |
| 594 manager()->OnPasswordFormsParsed(observed); | 602 manager()->OnPasswordFormsParsed(observed); |
| 595 manager()->OnPasswordFormsRendered(observed); | 603 manager()->OnPasswordFormsRendered(observed, true); |
| 596 } | 604 } |
| 597 | 605 |
| 598 TEST_F(PasswordManagerTest, SavingNotEnabledOnSSLErrors) { | 606 TEST_F(PasswordManagerTest, SavingNotEnabledOnSSLErrors) { |
| 599 EXPECT_CALL(driver_, DidLastPageLoadEncounterSSLErrors()) | 607 EXPECT_CALL(driver_, DidLastPageLoadEncounterSSLErrors()) |
| 600 .WillRepeatedly(Return(true)); | 608 .WillRepeatedly(Return(true)); |
| 601 EXPECT_FALSE(manager()->IsSavingEnabledForCurrentPage()); | 609 EXPECT_FALSE(manager()->IsSavingEnabledForCurrentPage()); |
| 602 } | 610 } |
| 603 | 611 |
| 604 TEST_F(PasswordManagerTest, AutofillingNotEnabledOnSSLErrors) { | 612 TEST_F(PasswordManagerTest, AutofillingNotEnabledOnSSLErrors) { |
| 605 // Test that in the presence of SSL errors, the password manager does not | 613 // Test that in the presence of SSL errors, the password manager does not |
| 606 // attempt to autofill forms found on a website. | 614 // attempt to autofill forms found on a website. |
| 607 EXPECT_CALL(driver_, DidLastPageLoadEncounterSSLErrors()) | 615 EXPECT_CALL(driver_, DidLastPageLoadEncounterSSLErrors()) |
| 608 .WillRepeatedly(Return(true)); | 616 .WillRepeatedly(Return(true)); |
| 609 | 617 |
| 610 // Let us pretend some forms were found on a website. | 618 // Let us pretend some forms were found on a website. |
| 611 std::vector<PasswordForm> forms; | 619 std::vector<PasswordForm> forms; |
| 612 forms.push_back(MakeSimpleForm()); | 620 forms.push_back(MakeSimpleForm()); |
| 613 | 621 |
| 614 // Feed those forms to |manager()| and check that it does not try to find | 622 // Feed those forms to |manager()| and check that it does not try to find |
| 615 // matching saved credentials for the forms. | 623 // matching saved credentials for the forms. |
| 616 EXPECT_CALL(*store_.get(), GetLogins(_, _, _)).Times(Exactly(0)); | 624 EXPECT_CALL(*store_.get(), GetLogins(_, _, _)).Times(Exactly(0)); |
| 617 manager()->OnPasswordFormsParsed(forms); | 625 manager()->OnPasswordFormsParsed(forms); |
| 618 } | 626 } |
| 619 | 627 |
| 620 } // namespace password_manager | 628 } // namespace password_manager |
| OLD | NEW |