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 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
216 return form.signon_realm == arg.signon_realm && form.origin == arg.origin && | 216 return form.signon_realm == arg.signon_realm && form.origin == arg.origin && |
217 form.action == arg.action && | 217 form.action == arg.action && |
218 form.username_element == arg.username_element && | 218 form.username_element == arg.username_element && |
219 form.password_element == arg.password_element && | 219 form.password_element == arg.password_element && |
220 form.new_password_element == arg.new_password_element && | 220 form.new_password_element == arg.new_password_element && |
221 form.password_autocomplete_set == arg.password_autocomplete_set && | 221 form.password_autocomplete_set == arg.password_autocomplete_set && |
222 form.submit_element == arg.submit_element; | 222 form.submit_element == arg.submit_element; |
223 } | 223 } |
224 | 224 |
225 TEST_F(PasswordManagerTest, FormSubmitEmptyStore) { | 225 TEST_F(PasswordManagerTest, FormSubmitEmptyStore) { |
| 226 EXPECT_CALL(driver_, DidLastPageLoadEncounterSSLErrors()) |
| 227 .WillRepeatedly(Return(false)); |
| 228 |
226 // Test that observing a newly submitted form shows the save password bar. | 229 // Test that observing a newly submitted form shows the save password bar. |
227 std::vector<PasswordForm*> result; // Empty password store. | 230 std::vector<PasswordForm*> result; // Empty password store. |
228 EXPECT_CALL(driver_, FillPasswordForm(_)).Times(Exactly(0)); | 231 EXPECT_CALL(driver_, FillPasswordForm(_)).Times(Exactly(0)); |
229 EXPECT_CALL(*store_.get(), GetLogins(_, _, _)) | 232 EXPECT_CALL(*store_.get(), GetLogins(_, _, _)) |
230 .WillOnce(DoAll(WithArg<2>(InvokeConsumer(result)), Return())); | 233 .WillOnce(DoAll(WithArg<2>(InvokeConsumer(result)), Return())); |
231 std::vector<PasswordForm> observed; | 234 std::vector<PasswordForm> observed; |
232 PasswordForm form(MakeSimpleForm()); | 235 PasswordForm form(MakeSimpleForm()); |
233 observed.push_back(form); | 236 observed.push_back(form); |
234 manager()->OnPasswordFormsParsed(observed); // The initial load. | 237 manager()->OnPasswordFormsParsed(observed); // The initial load. |
235 manager()->OnPasswordFormsRendered(observed, true); // The initial layout. | 238 manager()->OnPasswordFormsRendered(observed, true); // The initial layout. |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
293 // should have been saved. | 296 // should have been saved. |
294 PasswordForm expected_form(form); | 297 PasswordForm expected_form(form); |
295 expected_form.password_value.swap(expected_form.new_password_value); | 298 expected_form.password_value.swap(expected_form.new_password_value); |
296 expected_form.new_password_element.clear(); | 299 expected_form.new_password_element.clear(); |
297 EXPECT_THAT(saved_form, FormMatches(expected_form)); | 300 EXPECT_THAT(saved_form, FormMatches(expected_form)); |
298 EXPECT_EQ(expected_form.password_value, saved_form.password_value); | 301 EXPECT_EQ(expected_form.password_value, saved_form.password_value); |
299 EXPECT_EQ(expected_form.new_password_value, saved_form.new_password_value); | 302 EXPECT_EQ(expected_form.new_password_value, saved_form.new_password_value); |
300 } | 303 } |
301 | 304 |
302 TEST_F(PasswordManagerTest, GeneratedPasswordFormSubmitEmptyStore) { | 305 TEST_F(PasswordManagerTest, GeneratedPasswordFormSubmitEmptyStore) { |
| 306 EXPECT_CALL(driver_, DidLastPageLoadEncounterSSLErrors()) |
| 307 .WillRepeatedly(Return(false)); |
| 308 |
303 // This test is the same as FormSubmitEmptyStore, except that it simulates the | 309 // This test is the same as FormSubmitEmptyStore, except that it simulates the |
304 // user generating the password through the browser. | 310 // user generating the password through the browser. |
305 std::vector<PasswordForm*> result; // Empty password store. | 311 std::vector<PasswordForm*> result; // Empty password store. |
306 EXPECT_CALL(driver_, FillPasswordForm(_)).Times(Exactly(0)); | 312 EXPECT_CALL(driver_, FillPasswordForm(_)).Times(Exactly(0)); |
307 EXPECT_CALL(*store_.get(), GetLogins(_, _, _)) | 313 EXPECT_CALL(*store_.get(), GetLogins(_, _, _)) |
308 .WillOnce(DoAll(WithArg<2>(InvokeConsumer(result)), Return())); | 314 .WillOnce(DoAll(WithArg<2>(InvokeConsumer(result)), Return())); |
309 std::vector<PasswordForm> observed; | 315 std::vector<PasswordForm> observed; |
310 PasswordForm form(MakeSimpleForm()); | 316 PasswordForm form(MakeSimpleForm()); |
311 observed.push_back(form); | 317 observed.push_back(form); |
312 manager()->OnPasswordFormsParsed(observed); // The initial load. | 318 manager()->OnPasswordFormsParsed(observed); // The initial load. |
(...skipping 10 matching lines...) Expand all Loading... |
323 EXPECT_CALL(*store_.get(), AddLogin(FormMatches(form))); | 329 EXPECT_CALL(*store_.get(), AddLogin(FormMatches(form))); |
324 | 330 |
325 // Now the password manager waits for the navigation to complete. | 331 // Now the password manager waits for the navigation to complete. |
326 observed.clear(); | 332 observed.clear(); |
327 manager()->OnPasswordFormsParsed(observed); // The post-navigation load. | 333 manager()->OnPasswordFormsParsed(observed); // The post-navigation load. |
328 manager()->OnPasswordFormsRendered(observed, | 334 manager()->OnPasswordFormsRendered(observed, |
329 true); // The post-navigation layout. | 335 true); // The post-navigation layout. |
330 } | 336 } |
331 | 337 |
332 TEST_F(PasswordManagerTest, FormSubmitNoGoodMatch) { | 338 TEST_F(PasswordManagerTest, FormSubmitNoGoodMatch) { |
| 339 EXPECT_CALL(driver_, DidLastPageLoadEncounterSSLErrors()) |
| 340 .WillRepeatedly(Return(false)); |
| 341 |
333 // Same as above, except with an existing form for the same signon realm, | 342 // Same as above, except with an existing form for the same signon realm, |
334 // but different origin. Detailed cases like this are covered by | 343 // but different origin. Detailed cases like this are covered by |
335 // PasswordFormManagerTest. | 344 // PasswordFormManagerTest. |
336 std::vector<PasswordForm*> result; | 345 std::vector<PasswordForm*> result; |
337 PasswordForm* existing_different = new PasswordForm(MakeSimpleForm()); | 346 PasswordForm* existing_different = new PasswordForm(MakeSimpleForm()); |
338 existing_different->username_value = ASCIIToUTF16("google2"); | 347 existing_different->username_value = ASCIIToUTF16("google2"); |
339 result.push_back(existing_different); | 348 result.push_back(existing_different); |
340 EXPECT_CALL(driver_, FillPasswordForm(_)); | 349 EXPECT_CALL(driver_, FillPasswordForm(_)); |
341 EXPECT_CALL(*store_.get(), GetLogins(_, _, _)) | 350 EXPECT_CALL(*store_.get(), GetLogins(_, _, _)) |
342 .WillOnce(DoAll(WithArg<2>(InvokeConsumer(result)), Return())); | 351 .WillOnce(DoAll(WithArg<2>(InvokeConsumer(result)), Return())); |
(...skipping 17 matching lines...) Expand all Loading... |
360 true); // The post-navigation layout. | 369 true); // The post-navigation layout. |
361 | 370 |
362 ASSERT_TRUE(form_to_save.get()); | 371 ASSERT_TRUE(form_to_save.get()); |
363 EXPECT_CALL(*store_.get(), AddLogin(FormMatches(form))); | 372 EXPECT_CALL(*store_.get(), AddLogin(FormMatches(form))); |
364 | 373 |
365 // Simulate saving the form. | 374 // Simulate saving the form. |
366 form_to_save->Save(); | 375 form_to_save->Save(); |
367 } | 376 } |
368 | 377 |
369 TEST_F(PasswordManagerTest, FormSeenThenLeftPage) { | 378 TEST_F(PasswordManagerTest, FormSeenThenLeftPage) { |
| 379 EXPECT_CALL(driver_, DidLastPageLoadEncounterSSLErrors()) |
| 380 .WillRepeatedly(Return(false)); |
| 381 |
370 std::vector<PasswordForm*> result; // Empty password store. | 382 std::vector<PasswordForm*> result; // Empty password store. |
371 EXPECT_CALL(driver_, FillPasswordForm(_)).Times(Exactly(0)); | 383 EXPECT_CALL(driver_, FillPasswordForm(_)).Times(Exactly(0)); |
372 EXPECT_CALL(*store_.get(), GetLogins(_, _, _)) | 384 EXPECT_CALL(*store_.get(), GetLogins(_, _, _)) |
373 .WillOnce(DoAll(WithArg<2>(InvokeConsumer(result)), Return())); | 385 .WillOnce(DoAll(WithArg<2>(InvokeConsumer(result)), Return())); |
374 std::vector<PasswordForm> observed; | 386 std::vector<PasswordForm> observed; |
375 PasswordForm form(MakeSimpleForm()); | 387 PasswordForm form(MakeSimpleForm()); |
376 observed.push_back(form); | 388 observed.push_back(form); |
377 manager()->OnPasswordFormsParsed(observed); // The initial load. | 389 manager()->OnPasswordFormsParsed(observed); // The initial load. |
378 manager()->OnPasswordFormsRendered(observed, true); // The initial layout. | 390 manager()->OnPasswordFormsRendered(observed, true); // The initial layout. |
379 | 391 |
380 // No message from the renderer that a password was submitted. No | 392 // No message from the renderer that a password was submitted. No |
381 // expected calls. | 393 // expected calls. |
382 EXPECT_CALL(client_, PromptUserToSavePassword(_)).Times(0); | 394 EXPECT_CALL(client_, PromptUserToSavePassword(_)).Times(0); |
383 observed.clear(); | 395 observed.clear(); |
384 manager()->OnPasswordFormsParsed(observed); // The post-navigation load. | 396 manager()->OnPasswordFormsParsed(observed); // The post-navigation load. |
385 manager()->OnPasswordFormsRendered(observed, | 397 manager()->OnPasswordFormsRendered(observed, |
386 true); // The post-navigation layout. | 398 true); // The post-navigation layout. |
387 } | 399 } |
388 | 400 |
389 TEST_F(PasswordManagerTest, FormSubmitAfterNavigateInPage) { | 401 TEST_F(PasswordManagerTest, FormSubmitAfterNavigateInPage) { |
| 402 EXPECT_CALL(driver_, DidLastPageLoadEncounterSSLErrors()) |
| 403 .WillRepeatedly(Return(false)); |
| 404 |
390 // Test that navigating in the page does not prevent us from showing the save | 405 // Test that navigating in the page does not prevent us from showing the save |
391 // password infobar. | 406 // password infobar. |
392 std::vector<PasswordForm*> result; // Empty password store. | 407 std::vector<PasswordForm*> result; // Empty password store. |
393 EXPECT_CALL(driver_, FillPasswordForm(_)).Times(Exactly(0)); | 408 EXPECT_CALL(driver_, FillPasswordForm(_)).Times(Exactly(0)); |
394 EXPECT_CALL(*store_.get(), GetLogins(_, _, _)) | 409 EXPECT_CALL(*store_.get(), GetLogins(_, _, _)) |
395 .WillOnce(DoAll(WithArg<2>(InvokeConsumer(result)), Return())); | 410 .WillOnce(DoAll(WithArg<2>(InvokeConsumer(result)), Return())); |
396 std::vector<PasswordForm> observed; | 411 std::vector<PasswordForm> observed; |
397 PasswordForm form(MakeSimpleForm()); | 412 PasswordForm form(MakeSimpleForm()); |
398 observed.push_back(form); | 413 observed.push_back(form); |
399 manager()->OnPasswordFormsParsed(observed); // The initial load. | 414 manager()->OnPasswordFormsParsed(observed); // The initial load. |
(...skipping 17 matching lines...) Expand all Loading... |
417 | 432 |
418 ASSERT_FALSE(NULL == form_to_save.get()); | 433 ASSERT_FALSE(NULL == form_to_save.get()); |
419 EXPECT_CALL(*store_.get(), AddLogin(FormMatches(form))); | 434 EXPECT_CALL(*store_.get(), AddLogin(FormMatches(form))); |
420 | 435 |
421 // Simulate saving the form, as if the info bar was accepted. | 436 // Simulate saving the form, as if the info bar was accepted. |
422 form_to_save->Save(); | 437 form_to_save->Save(); |
423 } | 438 } |
424 | 439 |
425 // This test verifies a fix for http://crbug.com/236673 | 440 // This test verifies a fix for http://crbug.com/236673 |
426 TEST_F(PasswordManagerTest, FormSubmitWithFormOnPreviousPage) { | 441 TEST_F(PasswordManagerTest, FormSubmitWithFormOnPreviousPage) { |
| 442 EXPECT_CALL(driver_, DidLastPageLoadEncounterSSLErrors()) |
| 443 .WillRepeatedly(Return(false)); |
| 444 |
427 std::vector<PasswordForm*> result; // Empty password store. | 445 std::vector<PasswordForm*> result; // Empty password store. |
428 EXPECT_CALL(driver_, FillPasswordForm(_)).Times(Exactly(0)); | 446 EXPECT_CALL(driver_, FillPasswordForm(_)).Times(Exactly(0)); |
429 EXPECT_CALL(*store_.get(), GetLogins(_, _, _)) | 447 EXPECT_CALL(*store_.get(), GetLogins(_, _, _)) |
430 .WillRepeatedly(DoAll(WithArg<2>(InvokeConsumer(result)), Return())); | 448 .WillRepeatedly(DoAll(WithArg<2>(InvokeConsumer(result)), Return())); |
431 PasswordForm first_form(MakeSimpleForm()); | 449 PasswordForm first_form(MakeSimpleForm()); |
432 first_form.origin = GURL("http://www.nytimes.com/"); | 450 first_form.origin = GURL("http://www.nytimes.com/"); |
433 first_form.action = GURL("https://myaccount.nytimes.com/auth/login"); | 451 first_form.action = GURL("https://myaccount.nytimes.com/auth/login"); |
434 first_form.signon_realm = "http://www.nytimes.com/"; | 452 first_form.signon_realm = "http://www.nytimes.com/"; |
435 PasswordForm second_form(MakeSimpleForm()); | 453 PasswordForm second_form(MakeSimpleForm()); |
436 second_form.origin = GURL("https://myaccount.nytimes.com/auth/login"); | 454 second_form.origin = GURL("https://myaccount.nytimes.com/auth/login"); |
(...skipping 29 matching lines...) Expand all Loading... |
466 | 484 |
467 // Make sure that the saved form matches the second form, not the first. | 485 // Make sure that the saved form matches the second form, not the first. |
468 ASSERT_TRUE(form_to_save.get()); | 486 ASSERT_TRUE(form_to_save.get()); |
469 EXPECT_CALL(*store_.get(), AddLogin(FormMatches(second_form))); | 487 EXPECT_CALL(*store_.get(), AddLogin(FormMatches(second_form))); |
470 | 488 |
471 // Simulate saving the form, as if the info bar was accepted. | 489 // Simulate saving the form, as if the info bar was accepted. |
472 form_to_save->Save(); | 490 form_to_save->Save(); |
473 } | 491 } |
474 | 492 |
475 TEST_F(PasswordManagerTest, FormSubmitFailedLogin) { | 493 TEST_F(PasswordManagerTest, FormSubmitFailedLogin) { |
| 494 EXPECT_CALL(driver_, DidLastPageLoadEncounterSSLErrors()) |
| 495 .WillRepeatedly(Return(false)); |
| 496 |
476 std::vector<PasswordForm*> result; // Empty password store. | 497 std::vector<PasswordForm*> result; // Empty password store. |
477 EXPECT_CALL(driver_, FillPasswordForm(_)).Times(Exactly(0)); | 498 EXPECT_CALL(driver_, FillPasswordForm(_)).Times(Exactly(0)); |
478 EXPECT_CALL(*store_.get(), GetLogins(_, _, _)) | 499 EXPECT_CALL(*store_.get(), GetLogins(_, _, _)) |
479 .WillRepeatedly(DoAll(WithArg<2>(InvokeConsumer(result)), Return())); | 500 .WillRepeatedly(DoAll(WithArg<2>(InvokeConsumer(result)), Return())); |
480 std::vector<PasswordForm> observed; | 501 std::vector<PasswordForm> observed; |
481 PasswordForm form(MakeSimpleForm()); | 502 PasswordForm form(MakeSimpleForm()); |
482 observed.push_back(form); | 503 observed.push_back(form); |
483 manager()->OnPasswordFormsParsed(observed); // The initial load. | 504 manager()->OnPasswordFormsParsed(observed); // The initial load. |
484 manager()->OnPasswordFormsRendered(observed, true); // The initial layout. | 505 manager()->OnPasswordFormsRendered(observed, true); // The initial layout. |
485 | 506 |
486 manager()->ProvisionallySavePassword(form); | 507 manager()->ProvisionallySavePassword(form); |
487 | 508 |
488 // The form reappears, and is visible in the layout: | 509 // The form reappears, and is visible in the layout: |
489 // No expected calls to the PasswordStore... | 510 // No expected calls to the PasswordStore... |
490 manager()->OnPasswordFormsParsed(observed); | 511 manager()->OnPasswordFormsParsed(observed); |
491 manager()->OnPasswordFormsRendered(observed, true); | 512 manager()->OnPasswordFormsRendered(observed, true); |
492 } | 513 } |
493 | 514 |
494 TEST_F(PasswordManagerTest, FormSubmitInvisibleLogin) { | 515 TEST_F(PasswordManagerTest, FormSubmitInvisibleLogin) { |
| 516 EXPECT_CALL(driver_, DidLastPageLoadEncounterSSLErrors()) |
| 517 .WillRepeatedly(Return(false)); |
| 518 |
495 // Tests fix of issue 28911: if the login form reappears on the subsequent | 519 // Tests fix of issue 28911: if the login form reappears on the subsequent |
496 // page, but is invisible, it shouldn't count as a failed login. | 520 // page, but is invisible, it shouldn't count as a failed login. |
497 std::vector<PasswordForm*> result; // Empty password store. | 521 std::vector<PasswordForm*> result; // Empty password store. |
498 EXPECT_CALL(driver_, FillPasswordForm(_)).Times(Exactly(0)); | 522 EXPECT_CALL(driver_, FillPasswordForm(_)).Times(Exactly(0)); |
499 EXPECT_CALL(*store_.get(), GetLogins(_, _, _)) | 523 EXPECT_CALL(*store_.get(), GetLogins(_, _, _)) |
500 .WillRepeatedly(DoAll(WithArg<2>(InvokeConsumer(result)), Return())); | 524 .WillRepeatedly(DoAll(WithArg<2>(InvokeConsumer(result)), Return())); |
501 std::vector<PasswordForm> observed; | 525 std::vector<PasswordForm> observed; |
502 PasswordForm form(MakeSimpleForm()); | 526 PasswordForm form(MakeSimpleForm()); |
503 observed.push_back(form); | 527 observed.push_back(form); |
504 manager()->OnPasswordFormsParsed(observed); // The initial load. | 528 manager()->OnPasswordFormsParsed(observed); // The initial load. |
(...skipping 12 matching lines...) Expand all Loading... |
517 manager()->OnPasswordFormsRendered(observed, true); | 541 manager()->OnPasswordFormsRendered(observed, true); |
518 | 542 |
519 ASSERT_TRUE(form_to_save.get()); | 543 ASSERT_TRUE(form_to_save.get()); |
520 EXPECT_CALL(*store_.get(), AddLogin(FormMatches(form))); | 544 EXPECT_CALL(*store_.get(), AddLogin(FormMatches(form))); |
521 | 545 |
522 // Simulate saving the form. | 546 // Simulate saving the form. |
523 form_to_save->Save(); | 547 form_to_save->Save(); |
524 } | 548 } |
525 | 549 |
526 TEST_F(PasswordManagerTest, InitiallyInvisibleForm) { | 550 TEST_F(PasswordManagerTest, InitiallyInvisibleForm) { |
| 551 EXPECT_CALL(driver_, DidLastPageLoadEncounterSSLErrors()) |
| 552 .WillRepeatedly(Return(false)); |
| 553 |
527 // Make sure an invisible login form still gets autofilled. | 554 // Make sure an invisible login form still gets autofilled. |
528 std::vector<PasswordForm*> result; | 555 std::vector<PasswordForm*> result; |
529 PasswordForm* existing = new PasswordForm(MakeSimpleForm()); | 556 PasswordForm* existing = new PasswordForm(MakeSimpleForm()); |
530 result.push_back(existing); | 557 result.push_back(existing); |
531 EXPECT_CALL(driver_, FillPasswordForm(_)); | 558 EXPECT_CALL(driver_, FillPasswordForm(_)); |
532 EXPECT_CALL(*store_.get(), GetLogins(_, _, _)) | 559 EXPECT_CALL(*store_.get(), GetLogins(_, _, _)) |
533 .WillRepeatedly(DoAll(WithArg<2>(InvokeConsumer(result)), Return())); | 560 .WillRepeatedly(DoAll(WithArg<2>(InvokeConsumer(result)), Return())); |
534 std::vector<PasswordForm> observed; | 561 std::vector<PasswordForm> observed; |
535 PasswordForm form(MakeSimpleForm()); | 562 PasswordForm form(MakeSimpleForm()); |
536 observed.push_back(form); | 563 observed.push_back(form); |
(...skipping 11 matching lines...) Expand all Loading... |
548 // preference. | 575 // preference. |
549 prefs_.SetUserPref(prefs::kPasswordManagerSavingEnabled, | 576 prefs_.SetUserPref(prefs::kPasswordManagerSavingEnabled, |
550 base::Value::CreateBooleanValue(true)); | 577 base::Value::CreateBooleanValue(true)); |
551 EXPECT_TRUE(manager()->IsSavingEnabledForCurrentPage()); | 578 EXPECT_TRUE(manager()->IsSavingEnabledForCurrentPage()); |
552 prefs_.SetUserPref(prefs::kPasswordManagerSavingEnabled, | 579 prefs_.SetUserPref(prefs::kPasswordManagerSavingEnabled, |
553 base::Value::CreateBooleanValue(false)); | 580 base::Value::CreateBooleanValue(false)); |
554 EXPECT_FALSE(manager()->IsSavingEnabledForCurrentPage()); | 581 EXPECT_FALSE(manager()->IsSavingEnabledForCurrentPage()); |
555 } | 582 } |
556 | 583 |
557 TEST_F(PasswordManagerTest, FillPasswordsOnDisabledManager) { | 584 TEST_F(PasswordManagerTest, FillPasswordsOnDisabledManager) { |
| 585 EXPECT_CALL(driver_, DidLastPageLoadEncounterSSLErrors()) |
| 586 .WillRepeatedly(Return(false)); |
| 587 |
558 // Test fix for issue 158296: Passwords must be filled even if the password | 588 // Test fix for issue 158296: Passwords must be filled even if the password |
559 // manager is disabled. | 589 // manager is disabled. |
560 std::vector<PasswordForm*> result; | 590 std::vector<PasswordForm*> result; |
561 PasswordForm* existing = new PasswordForm(MakeSimpleForm()); | 591 PasswordForm* existing = new PasswordForm(MakeSimpleForm()); |
562 result.push_back(existing); | 592 result.push_back(existing); |
563 prefs_.SetUserPref(prefs::kPasswordManagerSavingEnabled, | 593 prefs_.SetUserPref(prefs::kPasswordManagerSavingEnabled, |
564 base::Value::CreateBooleanValue(false)); | 594 base::Value::CreateBooleanValue(false)); |
565 EXPECT_CALL(driver_, FillPasswordForm(_)); | 595 EXPECT_CALL(driver_, FillPasswordForm(_)); |
566 EXPECT_CALL(*store_.get(), | 596 EXPECT_CALL(*store_.get(), |
567 GetLogins(_, testing::Eq(PasswordStore::DISALLOW_PROMPT), _)) | 597 GetLogins(_, testing::Eq(PasswordStore::DISALLOW_PROMPT), _)) |
568 .WillRepeatedly(DoAll(WithArg<2>(InvokeConsumer(result)), Return())); | 598 .WillRepeatedly(DoAll(WithArg<2>(InvokeConsumer(result)), Return())); |
569 std::vector<PasswordForm> observed; | 599 std::vector<PasswordForm> observed; |
570 PasswordForm form(MakeSimpleForm()); | 600 PasswordForm form(MakeSimpleForm()); |
571 observed.push_back(form); | 601 observed.push_back(form); |
572 manager()->OnPasswordFormsParsed(observed); | 602 manager()->OnPasswordFormsParsed(observed); |
573 } | 603 } |
574 | 604 |
575 TEST_F(PasswordManagerTest, FormSavedWithAutocompleteOff) { | 605 TEST_F(PasswordManagerTest, FormSavedWithAutocompleteOff) { |
| 606 EXPECT_CALL(driver_, DidLastPageLoadEncounterSSLErrors()) |
| 607 .WillRepeatedly(Return(false)); |
| 608 |
576 // Test password form with non-generated password will be saved even if | 609 // Test password form with non-generated password will be saved even if |
577 // autocomplete=off. | 610 // autocomplete=off. |
578 std::vector<PasswordForm*> result; // Empty password store. | 611 std::vector<PasswordForm*> result; // Empty password store. |
579 EXPECT_CALL(driver_, FillPasswordForm(_)).Times(Exactly(0)); | 612 EXPECT_CALL(driver_, FillPasswordForm(_)).Times(Exactly(0)); |
580 EXPECT_CALL(*store_.get(), GetLogins(_, _, _)) | 613 EXPECT_CALL(*store_.get(), GetLogins(_, _, _)) |
581 .WillOnce(DoAll(WithArg<2>(InvokeConsumer(result)), Return())); | 614 .WillOnce(DoAll(WithArg<2>(InvokeConsumer(result)), Return())); |
582 std::vector<PasswordForm> observed; | 615 std::vector<PasswordForm> observed; |
583 PasswordForm form(MakeSimpleForm()); | 616 PasswordForm form(MakeSimpleForm()); |
584 form.password_autocomplete_set = false; | 617 form.password_autocomplete_set = false; |
585 observed.push_back(form); | 618 observed.push_back(form); |
(...skipping 12 matching lines...) Expand all Loading... |
598 // Now the password manager waits for the navigation to complete. | 631 // Now the password manager waits for the navigation to complete. |
599 observed.clear(); | 632 observed.clear(); |
600 manager()->OnPasswordFormsParsed(observed); // The post-navigation load. | 633 manager()->OnPasswordFormsParsed(observed); // The post-navigation load. |
601 manager()->OnPasswordFormsRendered(observed, | 634 manager()->OnPasswordFormsRendered(observed, |
602 true); // The post-navigation layout. | 635 true); // The post-navigation layout. |
603 | 636 |
604 ASSERT_TRUE(form_to_save.get()); | 637 ASSERT_TRUE(form_to_save.get()); |
605 } | 638 } |
606 | 639 |
607 TEST_F(PasswordManagerTest, GeneratedPasswordFormSavedAutocompleteOff) { | 640 TEST_F(PasswordManagerTest, GeneratedPasswordFormSavedAutocompleteOff) { |
| 641 EXPECT_CALL(driver_, DidLastPageLoadEncounterSSLErrors()) |
| 642 .WillRepeatedly(Return(false)); |
| 643 |
608 // Test password form with generated password will still be saved if | 644 // Test password form with generated password will still be saved if |
609 // autocomplete=off. | 645 // autocomplete=off. |
610 std::vector<PasswordForm*> result; // Empty password store. | 646 std::vector<PasswordForm*> result; // Empty password store. |
611 EXPECT_CALL(driver_, FillPasswordForm(_)).Times(Exactly(0)); | 647 EXPECT_CALL(driver_, FillPasswordForm(_)).Times(Exactly(0)); |
612 EXPECT_CALL(*store_.get(), GetLogins(_, _, _)) | 648 EXPECT_CALL(*store_.get(), GetLogins(_, _, _)) |
613 .WillOnce(DoAll(WithArg<2>(InvokeConsumer(result)), Return())); | 649 .WillOnce(DoAll(WithArg<2>(InvokeConsumer(result)), Return())); |
614 std::vector<PasswordForm> observed; | 650 std::vector<PasswordForm> observed; |
615 PasswordForm form(MakeSimpleForm()); | 651 PasswordForm form(MakeSimpleForm()); |
616 form.password_autocomplete_set = false; | 652 form.password_autocomplete_set = false; |
617 observed.push_back(form); | 653 observed.push_back(form); |
(...skipping 11 matching lines...) Expand all Loading... |
629 EXPECT_CALL(*store_.get(), AddLogin(FormMatches(form))); | 665 EXPECT_CALL(*store_.get(), AddLogin(FormMatches(form))); |
630 | 666 |
631 // Now the password manager waits for the navigation to complete. | 667 // Now the password manager waits for the navigation to complete. |
632 observed.clear(); | 668 observed.clear(); |
633 manager()->OnPasswordFormsParsed(observed); // The post-navigation load. | 669 manager()->OnPasswordFormsParsed(observed); // The post-navigation load. |
634 manager()->OnPasswordFormsRendered(observed, | 670 manager()->OnPasswordFormsRendered(observed, |
635 true); // The post-navigation layout. | 671 true); // The post-navigation layout. |
636 } | 672 } |
637 | 673 |
638 TEST_F(PasswordManagerTest, SubmissionCallbackTest) { | 674 TEST_F(PasswordManagerTest, SubmissionCallbackTest) { |
| 675 EXPECT_CALL(driver_, DidLastPageLoadEncounterSSLErrors()) |
| 676 .WillRepeatedly(Return(false)); |
| 677 |
639 manager()->AddSubmissionCallback(SubmissionCallback()); | 678 manager()->AddSubmissionCallback(SubmissionCallback()); |
640 PasswordForm form = MakeSimpleForm(); | 679 PasswordForm form = MakeSimpleForm(); |
641 OnPasswordFormSubmitted(form); | 680 OnPasswordFormSubmitted(form); |
642 EXPECT_TRUE(FormsAreEqual(form, submitted_form_)); | 681 EXPECT_TRUE(FormsAreEqual(form, submitted_form_)); |
643 } | 682 } |
644 | 683 |
645 TEST_F(PasswordManagerTest, PasswordFormReappearance) { | 684 TEST_F(PasswordManagerTest, PasswordFormReappearance) { |
646 // Test the heuristic to know if a password form reappears. | 685 // Test the heuristic to know if a password form reappears. |
647 // We assume that if we send our credentials and there | 686 // We assume that if we send our credentials and there |
648 // is at least one visible password form in the next page that | 687 // is at least one visible password form in the next page that |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
731 EXPECT_CALL(*store_.get(), AddLogin(FormMatches(form))).Times(Exactly(0)); | 770 EXPECT_CALL(*store_.get(), AddLogin(FormMatches(form))).Times(Exactly(0)); |
732 | 771 |
733 // Submit form and finish navigation. | 772 // Submit form and finish navigation. |
734 manager()->ProvisionallySavePassword(form); | 773 manager()->ProvisionallySavePassword(form); |
735 observed.clear(); | 774 observed.clear(); |
736 manager()->OnPasswordFormsParsed(observed); | 775 manager()->OnPasswordFormsParsed(observed); |
737 manager()->OnPasswordFormsRendered(observed, true); | 776 manager()->OnPasswordFormsRendered(observed, true); |
738 } | 777 } |
739 | 778 |
740 } // namespace password_manager | 779 } // namespace password_manager |
OLD | NEW |