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 "components/password_manager/core/browser/password_manager.h" | 5 #include "components/password_manager/core/browser/password_manager.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 #include <utility> | 8 #include <utility> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
250 } | 250 } |
251 | 251 |
252 TEST_F(PasswordManagerTest, FormSubmitWithOnlyNewPasswordField) { | 252 TEST_F(PasswordManagerTest, FormSubmitWithOnlyNewPasswordField) { |
253 // Test that when a form only contains a "new password" field, the form gets | 253 // Test that when a form only contains a "new password" field, the form gets |
254 // saved and in password store, the new password value is saved as a current | 254 // saved and in password store, the new password value is saved as a current |
255 // password value, without specifying the password field name (so that | 255 // password value, without specifying the password field name (so that |
256 // credentials from sign-up forms can be filled in login forms). | 256 // credentials from sign-up forms can be filled in login forms). |
257 std::vector<PasswordForm> observed; | 257 std::vector<PasswordForm> observed; |
258 PasswordForm form(MakeFormWithOnlyNewPasswordField()); | 258 PasswordForm form(MakeFormWithOnlyNewPasswordField()); |
259 observed.push_back(form); | 259 observed.push_back(form); |
260 EXPECT_CALL(*store_, GetLogins(_, _, _)) | 260 EXPECT_CALL(*store_, GetLogins(_, _)) |
261 .WillRepeatedly(WithArg<2>(InvokeEmptyConsumerWithForms())); | 261 .WillRepeatedly(WithArg<1>(InvokeEmptyConsumerWithForms())); |
262 manager()->OnPasswordFormsParsed(&driver_, observed); | 262 manager()->OnPasswordFormsParsed(&driver_, observed); |
263 manager()->OnPasswordFormsRendered(&driver_, observed, true); | 263 manager()->OnPasswordFormsRendered(&driver_, observed, true); |
264 | 264 |
265 EXPECT_CALL(client_, IsSavingAndFillingEnabledForCurrentPage()) | 265 EXPECT_CALL(client_, IsSavingAndFillingEnabledForCurrentPage()) |
266 .WillRepeatedly(Return(true)); | 266 .WillRepeatedly(Return(true)); |
267 OnPasswordFormSubmitted(form); | 267 OnPasswordFormSubmitted(form); |
268 | 268 |
269 scoped_ptr<PasswordFormManager> form_manager_to_save; | 269 scoped_ptr<PasswordFormManager> form_manager_to_save; |
270 EXPECT_CALL(client_, | 270 EXPECT_CALL(client_, |
271 PromptUserToSaveOrUpdatePasswordPtr( | 271 PromptUserToSaveOrUpdatePasswordPtr( |
(...skipping 16 matching lines...) Expand all Loading... |
288 PasswordForm expected_form(form); | 288 PasswordForm expected_form(form); |
289 expected_form.password_value.swap(expected_form.new_password_value); | 289 expected_form.password_value.swap(expected_form.new_password_value); |
290 EXPECT_THAT(saved_form, FormMatches(expected_form)); | 290 EXPECT_THAT(saved_form, FormMatches(expected_form)); |
291 } | 291 } |
292 | 292 |
293 TEST_F(PasswordManagerTest, GeneratedPasswordFormSubmitEmptyStore) { | 293 TEST_F(PasswordManagerTest, GeneratedPasswordFormSubmitEmptyStore) { |
294 // Test that generated passwords are stored without asking the user. | 294 // Test that generated passwords are stored without asking the user. |
295 std::vector<PasswordForm> observed; | 295 std::vector<PasswordForm> observed; |
296 PasswordForm form(MakeFormWithOnlyNewPasswordField()); | 296 PasswordForm form(MakeFormWithOnlyNewPasswordField()); |
297 observed.push_back(form); | 297 observed.push_back(form); |
298 EXPECT_CALL(*store_, GetLogins(_, _, _)) | 298 EXPECT_CALL(*store_, GetLogins(_, _)) |
299 .WillRepeatedly(WithArg<2>(InvokeEmptyConsumerWithForms())); | 299 .WillRepeatedly(WithArg<1>(InvokeEmptyConsumerWithForms())); |
300 manager()->OnPasswordFormsParsed(&driver_, observed); | 300 manager()->OnPasswordFormsParsed(&driver_, observed); |
301 manager()->OnPasswordFormsRendered(&driver_, observed, true); | 301 manager()->OnPasswordFormsRendered(&driver_, observed, true); |
302 | 302 |
303 // Simulate the user generating the password and submitting the form. | 303 // Simulate the user generating the password and submitting the form. |
304 EXPECT_CALL(client_, IsSavingAndFillingEnabledForCurrentPage()) | 304 EXPECT_CALL(client_, IsSavingAndFillingEnabledForCurrentPage()) |
305 .WillRepeatedly(Return(true)); | 305 .WillRepeatedly(Return(true)); |
306 manager()->SetHasGeneratedPasswordForForm(&driver_, form, true); | 306 manager()->SetHasGeneratedPasswordForForm(&driver_, form, true); |
307 OnPasswordFormSubmitted(form); | 307 OnPasswordFormSubmitted(form); |
308 | 308 |
309 // The user should not need to confirm saving as they have already given | 309 // The user should not need to confirm saving as they have already given |
(...skipping 20 matching lines...) Expand all Loading... |
330 // credentials get still added, as long as they differ in username from the | 330 // credentials get still added, as long as they differ in username from the |
331 // stored ones. | 331 // stored ones. |
332 ScopedVector<PasswordForm> result; | 332 ScopedVector<PasswordForm> result; |
333 PasswordForm existing_different(MakeSimpleForm()); | 333 PasswordForm existing_different(MakeSimpleForm()); |
334 existing_different.username_value = ASCIIToUTF16("google2"); | 334 existing_different.username_value = ASCIIToUTF16("google2"); |
335 | 335 |
336 std::vector<PasswordForm> observed; | 336 std::vector<PasswordForm> observed; |
337 PasswordForm form(MakeSimpleForm()); | 337 PasswordForm form(MakeSimpleForm()); |
338 observed.push_back(form); | 338 observed.push_back(form); |
339 EXPECT_CALL(driver_, FillPasswordForm(_)).Times(2); | 339 EXPECT_CALL(driver_, FillPasswordForm(_)).Times(2); |
340 EXPECT_CALL(*store_, GetLogins(_, _, _)) | 340 EXPECT_CALL(*store_, GetLogins(_, _)) |
341 .WillOnce(WithArg<2>(InvokeConsumer(existing_different))); | 341 .WillOnce(WithArg<1>(InvokeConsumer(existing_different))); |
342 manager()->OnPasswordFormsParsed(&driver_, observed); | 342 manager()->OnPasswordFormsParsed(&driver_, observed); |
343 manager()->OnPasswordFormsRendered(&driver_, observed, true); | 343 manager()->OnPasswordFormsRendered(&driver_, observed, true); |
344 EXPECT_CALL(client_, IsSavingAndFillingEnabledForCurrentPage()) | 344 EXPECT_CALL(client_, IsSavingAndFillingEnabledForCurrentPage()) |
345 .WillRepeatedly(Return(true)); | 345 .WillRepeatedly(Return(true)); |
346 OnPasswordFormSubmitted(form); | 346 OnPasswordFormSubmitted(form); |
347 | 347 |
348 // We still expect an add, since we didn't have a good match. | 348 // We still expect an add, since we didn't have a good match. |
349 scoped_ptr<PasswordFormManager> form_manager_to_save; | 349 scoped_ptr<PasswordFormManager> form_manager_to_save; |
350 EXPECT_CALL(client_, | 350 EXPECT_CALL(client_, |
351 PromptUserToSaveOrUpdatePasswordPtr( | 351 PromptUserToSaveOrUpdatePasswordPtr( |
352 _, CredentialSourceType::CREDENTIAL_SOURCE_PASSWORD_MANAGER)) | 352 _, CredentialSourceType::CREDENTIAL_SOURCE_PASSWORD_MANAGER)) |
353 .WillOnce(WithArg<0>(SaveToScopedPtr(&form_manager_to_save))); | 353 .WillOnce(WithArg<0>(SaveToScopedPtr(&form_manager_to_save))); |
354 | 354 |
355 // Now the password manager waits for the navigation to complete. | 355 // Now the password manager waits for the navigation to complete. |
356 observed.clear(); | 356 observed.clear(); |
357 manager()->OnPasswordFormsParsed(&driver_, observed); | 357 manager()->OnPasswordFormsParsed(&driver_, observed); |
358 manager()->OnPasswordFormsRendered(&driver_, observed, true); | 358 manager()->OnPasswordFormsRendered(&driver_, observed, true); |
359 | 359 |
360 // Simulate saving the form. | 360 // Simulate saving the form. |
361 EXPECT_CALL(*store_, AddLogin(FormMatches(form))); | 361 EXPECT_CALL(*store_, AddLogin(FormMatches(form))); |
362 ASSERT_TRUE(form_manager_to_save); | 362 ASSERT_TRUE(form_manager_to_save); |
363 form_manager_to_save->Save(); | 363 form_manager_to_save->Save(); |
364 } | 364 } |
365 | 365 |
366 TEST_F(PasswordManagerTest, FormSeenThenLeftPage) { | 366 TEST_F(PasswordManagerTest, FormSeenThenLeftPage) { |
367 std::vector<PasswordForm> observed; | 367 std::vector<PasswordForm> observed; |
368 PasswordForm form(MakeSimpleForm()); | 368 PasswordForm form(MakeSimpleForm()); |
369 observed.push_back(form); | 369 observed.push_back(form); |
370 EXPECT_CALL(*store_, GetLogins(_, _, _)) | 370 EXPECT_CALL(*store_, GetLogins(_, _)) |
371 .WillRepeatedly(WithArg<2>(InvokeEmptyConsumerWithForms())); | 371 .WillRepeatedly(WithArg<1>(InvokeEmptyConsumerWithForms())); |
372 manager()->OnPasswordFormsParsed(&driver_, observed); | 372 manager()->OnPasswordFormsParsed(&driver_, observed); |
373 manager()->OnPasswordFormsRendered(&driver_, observed, true); | 373 manager()->OnPasswordFormsRendered(&driver_, observed, true); |
374 | 374 |
375 // No message from the renderer that a password was submitted. No | 375 // No message from the renderer that a password was submitted. No |
376 // expected calls. | 376 // expected calls. |
377 EXPECT_CALL(client_, PromptUserToSaveOrUpdatePasswordPtr(_, _)).Times(0); | 377 EXPECT_CALL(client_, PromptUserToSaveOrUpdatePasswordPtr(_, _)).Times(0); |
378 observed.clear(); | 378 observed.clear(); |
379 manager()->OnPasswordFormsParsed(&driver_, observed); | 379 manager()->OnPasswordFormsParsed(&driver_, observed); |
380 manager()->OnPasswordFormsRendered(&driver_, observed, true); | 380 manager()->OnPasswordFormsRendered(&driver_, observed, true); |
381 } | 381 } |
382 | 382 |
383 TEST_F(PasswordManagerTest, FormSubmit) { | 383 TEST_F(PasswordManagerTest, FormSubmit) { |
384 // Test that a plain form submit results in offering to save passwords. | 384 // Test that a plain form submit results in offering to save passwords. |
385 std::vector<PasswordForm> observed; | 385 std::vector<PasswordForm> observed; |
386 PasswordForm form(MakeSimpleForm()); | 386 PasswordForm form(MakeSimpleForm()); |
387 observed.push_back(form); | 387 observed.push_back(form); |
388 EXPECT_CALL(*store_, GetLogins(_, _, _)) | 388 EXPECT_CALL(*store_, GetLogins(_, _)) |
389 .WillRepeatedly(WithArg<2>(InvokeEmptyConsumerWithForms())); | 389 .WillRepeatedly(WithArg<1>(InvokeEmptyConsumerWithForms())); |
390 manager()->OnPasswordFormsParsed(&driver_, observed); | 390 manager()->OnPasswordFormsParsed(&driver_, observed); |
391 manager()->OnPasswordFormsRendered(&driver_, observed, true); | 391 manager()->OnPasswordFormsRendered(&driver_, observed, true); |
392 | 392 |
393 EXPECT_CALL(client_, IsSavingAndFillingEnabledForCurrentPage()) | 393 EXPECT_CALL(client_, IsSavingAndFillingEnabledForCurrentPage()) |
394 .WillRepeatedly(Return(true)); | 394 .WillRepeatedly(Return(true)); |
395 OnPasswordFormSubmitted(form); | 395 OnPasswordFormSubmitted(form); |
396 | 396 |
397 scoped_ptr<PasswordFormManager> form_manager_to_save; | 397 scoped_ptr<PasswordFormManager> form_manager_to_save; |
398 EXPECT_CALL(client_, | 398 EXPECT_CALL(client_, |
399 PromptUserToSaveOrUpdatePasswordPtr( | 399 PromptUserToSaveOrUpdatePasswordPtr( |
(...skipping 17 matching lines...) Expand all Loading... |
417 first_form.action = GURL("https://myaccount.nytimes.com/auth/login"); | 417 first_form.action = GURL("https://myaccount.nytimes.com/auth/login"); |
418 first_form.signon_realm = "http://www.nytimes.com/"; | 418 first_form.signon_realm = "http://www.nytimes.com/"; |
419 PasswordForm second_form(MakeSimpleForm()); | 419 PasswordForm second_form(MakeSimpleForm()); |
420 second_form.origin = GURL("https://myaccount.nytimes.com/auth/login"); | 420 second_form.origin = GURL("https://myaccount.nytimes.com/auth/login"); |
421 second_form.action = GURL("https://myaccount.nytimes.com/auth/login"); | 421 second_form.action = GURL("https://myaccount.nytimes.com/auth/login"); |
422 second_form.signon_realm = "https://myaccount.nytimes.com/"; | 422 second_form.signon_realm = "https://myaccount.nytimes.com/"; |
423 | 423 |
424 // Pretend that the form is hidden on the first page. | 424 // Pretend that the form is hidden on the first page. |
425 std::vector<PasswordForm> observed; | 425 std::vector<PasswordForm> observed; |
426 observed.push_back(first_form); | 426 observed.push_back(first_form); |
427 EXPECT_CALL(*store_, GetLogins(_, _, _)) | 427 EXPECT_CALL(*store_, GetLogins(_, _)) |
428 .WillRepeatedly(WithArg<2>(InvokeEmptyConsumerWithForms())); | 428 .WillRepeatedly(WithArg<1>(InvokeEmptyConsumerWithForms())); |
429 manager()->OnPasswordFormsParsed(&driver_, observed); | 429 manager()->OnPasswordFormsParsed(&driver_, observed); |
430 observed.clear(); | 430 observed.clear(); |
431 manager()->OnPasswordFormsRendered(&driver_, observed, true); | 431 manager()->OnPasswordFormsRendered(&driver_, observed, true); |
432 | 432 |
433 // Now navigate to a second page. | 433 // Now navigate to a second page. |
434 manager()->DidNavigateMainFrame(); | 434 manager()->DidNavigateMainFrame(); |
435 | 435 |
436 // This page contains a form with the same markup, but on a different | 436 // This page contains a form with the same markup, but on a different |
437 // URL. | 437 // URL. |
438 observed.push_back(second_form); | 438 observed.push_back(second_form); |
(...skipping 21 matching lines...) Expand all Loading... |
460 ASSERT_TRUE(form_manager_to_save); | 460 ASSERT_TRUE(form_manager_to_save); |
461 form_manager_to_save->Save(); | 461 form_manager_to_save->Save(); |
462 } | 462 } |
463 | 463 |
464 TEST_F(PasswordManagerTest, FormSubmitInvisibleLogin) { | 464 TEST_F(PasswordManagerTest, FormSubmitInvisibleLogin) { |
465 // Tests fix of http://crbug.com/28911: if the login form reappears on the | 465 // Tests fix of http://crbug.com/28911: if the login form reappears on the |
466 // subsequent page, but is invisible, it shouldn't count as a failed login. | 466 // subsequent page, but is invisible, it shouldn't count as a failed login. |
467 std::vector<PasswordForm> observed; | 467 std::vector<PasswordForm> observed; |
468 PasswordForm form(MakeSimpleForm()); | 468 PasswordForm form(MakeSimpleForm()); |
469 observed.push_back(form); | 469 observed.push_back(form); |
470 EXPECT_CALL(*store_, GetLogins(_, _, _)) | 470 EXPECT_CALL(*store_, GetLogins(_, _)) |
471 .WillRepeatedly(WithArg<2>(InvokeEmptyConsumerWithForms())); | 471 .WillRepeatedly(WithArg<1>(InvokeEmptyConsumerWithForms())); |
472 manager()->OnPasswordFormsParsed(&driver_, observed); | 472 manager()->OnPasswordFormsParsed(&driver_, observed); |
473 manager()->OnPasswordFormsRendered(&driver_, observed, true); | 473 manager()->OnPasswordFormsRendered(&driver_, observed, true); |
474 | 474 |
475 EXPECT_CALL(client_, IsSavingAndFillingEnabledForCurrentPage()) | 475 EXPECT_CALL(client_, IsSavingAndFillingEnabledForCurrentPage()) |
476 .WillRepeatedly(Return(true)); | 476 .WillRepeatedly(Return(true)); |
477 OnPasswordFormSubmitted(form); | 477 OnPasswordFormSubmitted(form); |
478 | 478 |
479 // Expect info bar to appear: | 479 // Expect info bar to appear: |
480 scoped_ptr<PasswordFormManager> form_manager_to_save; | 480 scoped_ptr<PasswordFormManager> form_manager_to_save; |
481 EXPECT_CALL(client_, | 481 EXPECT_CALL(client_, |
(...skipping 11 matching lines...) Expand all Loading... |
493 ASSERT_TRUE(form_manager_to_save); | 493 ASSERT_TRUE(form_manager_to_save); |
494 form_manager_to_save->Save(); | 494 form_manager_to_save->Save(); |
495 } | 495 } |
496 | 496 |
497 TEST_F(PasswordManagerTest, InitiallyInvisibleForm) { | 497 TEST_F(PasswordManagerTest, InitiallyInvisibleForm) { |
498 // Make sure an invisible login form still gets autofilled. | 498 // Make sure an invisible login form still gets autofilled. |
499 PasswordForm form(MakeSimpleForm()); | 499 PasswordForm form(MakeSimpleForm()); |
500 std::vector<PasswordForm> observed; | 500 std::vector<PasswordForm> observed; |
501 observed.push_back(form); | 501 observed.push_back(form); |
502 EXPECT_CALL(driver_, FillPasswordForm(_)); | 502 EXPECT_CALL(driver_, FillPasswordForm(_)); |
503 EXPECT_CALL(*store_, GetLogins(_, _, _)) | 503 EXPECT_CALL(*store_, GetLogins(_, _)) |
504 .WillOnce(WithArg<2>(InvokeConsumer(form))); | 504 .WillOnce(WithArg<1>(InvokeConsumer(form))); |
505 manager()->OnPasswordFormsParsed(&driver_, observed); | 505 manager()->OnPasswordFormsParsed(&driver_, observed); |
506 observed.clear(); | 506 observed.clear(); |
507 manager()->OnPasswordFormsRendered(&driver_, observed, true); | 507 manager()->OnPasswordFormsRendered(&driver_, observed, true); |
508 } | 508 } |
509 | 509 |
510 | 510 |
511 TEST_F(PasswordManagerTest, FillPasswordsOnDisabledManager) { | 511 TEST_F(PasswordManagerTest, FillPasswordsOnDisabledManager) { |
512 // Test fix for http://crbug.com/158296: Passwords must be filled even if the | 512 // Test fix for http://crbug.com/158296: Passwords must be filled even if the |
513 // password manager is disabled. | 513 // password manager is disabled. |
514 PasswordForm form(MakeSimpleForm()); | 514 PasswordForm form(MakeSimpleForm()); |
515 EXPECT_CALL(client_, IsSavingAndFillingEnabledForCurrentPage()) | 515 EXPECT_CALL(client_, IsSavingAndFillingEnabledForCurrentPage()) |
516 .WillRepeatedly(Return(false)); | 516 .WillRepeatedly(Return(false)); |
517 std::vector<PasswordForm> observed; | 517 std::vector<PasswordForm> observed; |
518 observed.push_back(form); | 518 observed.push_back(form); |
519 EXPECT_CALL(driver_, FillPasswordForm(_)); | 519 EXPECT_CALL(driver_, FillPasswordForm(_)); |
520 EXPECT_CALL(*store_, GetLogins(_, PasswordStore::DISALLOW_PROMPT, _)) | 520 EXPECT_CALL(*store_, GetLogins(_, _)) |
521 .WillOnce(WithArg<2>(InvokeConsumer(form))); | 521 .WillOnce(WithArg<1>(InvokeConsumer(form))); |
522 manager()->OnPasswordFormsParsed(&driver_, observed); | 522 manager()->OnPasswordFormsParsed(&driver_, observed); |
523 } | 523 } |
524 | 524 |
525 TEST_F(PasswordManagerTest, SubmissionCallbackTest) { | 525 TEST_F(PasswordManagerTest, SubmissionCallbackTest) { |
526 manager()->AddSubmissionCallback(SubmissionCallback()); | 526 manager()->AddSubmissionCallback(SubmissionCallback()); |
527 PasswordForm form = MakeSimpleForm(); | 527 PasswordForm form = MakeSimpleForm(); |
528 // Prefs are needed for failure logging about having no matching observed | 528 // Prefs are needed for failure logging about having no matching observed |
529 // form. | 529 // form. |
530 EXPECT_CALL(client_, GetPrefs()).WillRepeatedly(Return(nullptr)); | 530 EXPECT_CALL(client_, GetPrefs()).WillRepeatedly(Return(nullptr)); |
531 EXPECT_CALL(client_, IsSavingAndFillingEnabledForCurrentPage()) | 531 EXPECT_CALL(client_, IsSavingAndFillingEnabledForCurrentPage()) |
532 .WillRepeatedly(Return(true)); | 532 .WillRepeatedly(Return(true)); |
533 OnPasswordFormSubmitted(form); | 533 OnPasswordFormSubmitted(form); |
534 EXPECT_EQ(form, submitted_form_); | 534 EXPECT_EQ(form, submitted_form_); |
535 } | 535 } |
536 | 536 |
537 TEST_F(PasswordManagerTest, PasswordFormReappearance) { | 537 TEST_F(PasswordManagerTest, PasswordFormReappearance) { |
538 // If the password form reappears after submit, PasswordManager should deduce | 538 // If the password form reappears after submit, PasswordManager should deduce |
539 // that the login failed and not offer saving. | 539 // that the login failed and not offer saving. |
540 std::vector<PasswordForm> observed; | 540 std::vector<PasswordForm> observed; |
541 PasswordForm login_form(MakeTwitterLoginForm()); | 541 PasswordForm login_form(MakeTwitterLoginForm()); |
542 observed.push_back(login_form); | 542 observed.push_back(login_form); |
543 EXPECT_CALL(*store_, GetLogins(_, _, _)) | 543 EXPECT_CALL(*store_, GetLogins(_, _)) |
544 .WillRepeatedly(WithArg<2>(InvokeEmptyConsumerWithForms())); | 544 .WillRepeatedly(WithArg<1>(InvokeEmptyConsumerWithForms())); |
545 manager()->OnPasswordFormsParsed(&driver_, observed); | 545 manager()->OnPasswordFormsParsed(&driver_, observed); |
546 manager()->OnPasswordFormsRendered(&driver_, observed, true); | 546 manager()->OnPasswordFormsRendered(&driver_, observed, true); |
547 | 547 |
548 EXPECT_CALL(client_, IsSavingAndFillingEnabledForCurrentPage()) | 548 EXPECT_CALL(client_, IsSavingAndFillingEnabledForCurrentPage()) |
549 .WillRepeatedly(Return(true)); | 549 .WillRepeatedly(Return(true)); |
550 OnPasswordFormSubmitted(login_form); | 550 OnPasswordFormSubmitted(login_form); |
551 | 551 |
552 observed.clear(); | 552 observed.clear(); |
553 observed.push_back(MakeTwitterFailedLoginForm()); | 553 observed.push_back(MakeTwitterFailedLoginForm()); |
554 // A PasswordForm appears, and is visible in the layout: | 554 // A PasswordForm appears, and is visible in the layout: |
555 // No expected calls to the PasswordStore... | 555 // No expected calls to the PasswordStore... |
556 EXPECT_CALL(client_, PromptUserToSaveOrUpdatePasswordPtr(_, _)).Times(0); | 556 EXPECT_CALL(client_, PromptUserToSaveOrUpdatePasswordPtr(_, _)).Times(0); |
557 EXPECT_CALL(client_, AutomaticPasswordSaveIndicator()).Times(0); | 557 EXPECT_CALL(client_, AutomaticPasswordSaveIndicator()).Times(0); |
558 EXPECT_CALL(*store_, AddLogin(_)).Times(0); | 558 EXPECT_CALL(*store_, AddLogin(_)).Times(0); |
559 EXPECT_CALL(*store_, UpdateLogin(_)).Times(0); | 559 EXPECT_CALL(*store_, UpdateLogin(_)).Times(0); |
560 EXPECT_CALL(*store_, UpdateLoginWithPrimaryKey(_, _)).Times(0); | 560 EXPECT_CALL(*store_, UpdateLoginWithPrimaryKey(_, _)).Times(0); |
561 manager()->OnPasswordFormsParsed(&driver_, observed); | 561 manager()->OnPasswordFormsParsed(&driver_, observed); |
562 manager()->OnPasswordFormsRendered(&driver_, observed, true); | 562 manager()->OnPasswordFormsRendered(&driver_, observed, true); |
563 } | 563 } |
564 | 564 |
565 TEST_F(PasswordManagerTest, SyncCredentialsNotSaved) { | 565 TEST_F(PasswordManagerTest, SyncCredentialsNotSaved) { |
566 // Simulate loading a simple form with no existing stored password. | 566 // Simulate loading a simple form with no existing stored password. |
567 std::vector<PasswordForm> observed; | 567 std::vector<PasswordForm> observed; |
568 PasswordForm form(MakeSimpleForm()); | 568 PasswordForm form(MakeSimpleForm()); |
569 observed.push_back(form); | 569 observed.push_back(form); |
570 EXPECT_CALL(*store_, GetLogins(_, _, _)) | 570 EXPECT_CALL(*store_, GetLogins(_, _)) |
571 .WillRepeatedly(WithArg<2>(InvokeEmptyConsumerWithForms())); | 571 .WillRepeatedly(WithArg<1>(InvokeEmptyConsumerWithForms())); |
572 manager()->OnPasswordFormsParsed(&driver_, observed); | 572 manager()->OnPasswordFormsParsed(&driver_, observed); |
573 manager()->OnPasswordFormsRendered(&driver_, observed, true); | 573 manager()->OnPasswordFormsRendered(&driver_, observed, true); |
574 | 574 |
575 // User should not be prompted and password should not be saved. | 575 // User should not be prompted and password should not be saved. |
576 EXPECT_CALL(client_, PromptUserToSaveOrUpdatePasswordPtr(_, _)).Times(0); | 576 EXPECT_CALL(client_, PromptUserToSaveOrUpdatePasswordPtr(_, _)).Times(0); |
577 EXPECT_CALL(*store_, AddLogin(_)).Times(0); | 577 EXPECT_CALL(*store_, AddLogin(_)).Times(0); |
578 // Prefs are needed for failure logging about sync credentials. | 578 // Prefs are needed for failure logging about sync credentials. |
579 EXPECT_CALL(client_, GetPrefs()).WillRepeatedly(Return(nullptr)); | 579 EXPECT_CALL(client_, GetPrefs()).WillRepeatedly(Return(nullptr)); |
580 EXPECT_CALL(client_, IsSavingAndFillingEnabledForCurrentPage()) | 580 EXPECT_CALL(client_, IsSavingAndFillingEnabledForCurrentPage()) |
581 .WillRepeatedly(Return(true)); | 581 .WillRepeatedly(Return(true)); |
582 | 582 |
583 client_.FilterAllResultsForSaving(); | 583 client_.FilterAllResultsForSaving(); |
584 | 584 |
585 OnPasswordFormSubmitted(form); | 585 OnPasswordFormSubmitted(form); |
586 observed.clear(); | 586 observed.clear(); |
587 manager()->OnPasswordFormsParsed(&driver_, observed); | 587 manager()->OnPasswordFormsParsed(&driver_, observed); |
588 manager()->OnPasswordFormsRendered(&driver_, observed, true); | 588 manager()->OnPasswordFormsRendered(&driver_, observed, true); |
589 } | 589 } |
590 | 590 |
591 // When there is a sync password saved, and the user successfully uses the | 591 // When there is a sync password saved, and the user successfully uses the |
592 // stored version of it, PasswordManager should not drop that password. | 592 // stored version of it, PasswordManager should not drop that password. |
593 TEST_F(PasswordManagerTest, SyncCredentialsNotDroppedIfUpToDate) { | 593 TEST_F(PasswordManagerTest, SyncCredentialsNotDroppedIfUpToDate) { |
594 PasswordForm form(MakeSimpleForm()); | 594 PasswordForm form(MakeSimpleForm()); |
595 EXPECT_CALL(*store_, GetLogins(_, _, _)) | 595 EXPECT_CALL(*store_, GetLogins(_, _)) |
596 .WillRepeatedly(WithArg<2>(InvokeConsumer(form))); | 596 .WillRepeatedly(WithArg<1>(InvokeConsumer(form))); |
597 | 597 |
598 client_.FilterAllResultsForSaving(); | 598 client_.FilterAllResultsForSaving(); |
599 | 599 |
600 std::vector<PasswordForm> observed; | 600 std::vector<PasswordForm> observed; |
601 observed.push_back(form); | 601 observed.push_back(form); |
602 EXPECT_CALL(driver_, FillPasswordForm(_)).Times(2); | 602 EXPECT_CALL(driver_, FillPasswordForm(_)).Times(2); |
603 manager()->OnPasswordFormsParsed(&driver_, observed); | 603 manager()->OnPasswordFormsParsed(&driver_, observed); |
604 manager()->OnPasswordFormsRendered(&driver_, observed, true); | 604 manager()->OnPasswordFormsRendered(&driver_, observed, true); |
605 | 605 |
606 // Submit form and finish navigation. | 606 // Submit form and finish navigation. |
(...skipping 10 matching lines...) Expand all Loading... |
617 manager()->OnPasswordFormsRendered(&driver_, observed, true); | 617 manager()->OnPasswordFormsRendered(&driver_, observed, true); |
618 } | 618 } |
619 | 619 |
620 // When there is a sync password saved, and the user successfully uses an | 620 // When there is a sync password saved, and the user successfully uses an |
621 // updated version of it, the obsolete one should be dropped, to avoid filling | 621 // updated version of it, the obsolete one should be dropped, to avoid filling |
622 // it later. | 622 // it later. |
623 TEST_F(PasswordManagerTest, SyncCredentialsDroppedWhenObsolete) { | 623 TEST_F(PasswordManagerTest, SyncCredentialsDroppedWhenObsolete) { |
624 PasswordForm form(MakeSimpleForm()); | 624 PasswordForm form(MakeSimpleForm()); |
625 form.password_value = ASCIIToUTF16("old pa55word"); | 625 form.password_value = ASCIIToUTF16("old pa55word"); |
626 // Pretend that the password store contains "old pa55word" stored for |form|. | 626 // Pretend that the password store contains "old pa55word" stored for |form|. |
627 EXPECT_CALL(*store_, GetLogins(_, _, _)) | 627 EXPECT_CALL(*store_, GetLogins(_, _)) |
628 .WillRepeatedly(WithArg<2>(InvokeConsumer(form))); | 628 .WillRepeatedly(WithArg<1>(InvokeConsumer(form))); |
629 | 629 |
630 // Load the page, pretend the password was updated. | 630 // Load the page, pretend the password was updated. |
631 PasswordForm updated_form(form); | 631 PasswordForm updated_form(form); |
632 updated_form.password_value = ASCIIToUTF16("n3w passw0rd"); | 632 updated_form.password_value = ASCIIToUTF16("n3w passw0rd"); |
633 std::vector<PasswordForm> observed; | 633 std::vector<PasswordForm> observed; |
634 observed.push_back(updated_form); | 634 observed.push_back(updated_form); |
635 EXPECT_CALL(driver_, FillPasswordForm(_)).Times(2); | 635 EXPECT_CALL(driver_, FillPasswordForm(_)).Times(2); |
636 manager()->OnPasswordFormsParsed(&driver_, observed); | 636 manager()->OnPasswordFormsParsed(&driver_, observed); |
637 manager()->OnPasswordFormsRendered(&driver_, observed, true); | 637 manager()->OnPasswordFormsRendered(&driver_, observed, true); |
638 | 638 |
(...skipping 12 matching lines...) Expand all Loading... |
651 observed.clear(); | 651 observed.clear(); |
652 manager()->OnPasswordFormsParsed(&driver_, observed); | 652 manager()->OnPasswordFormsParsed(&driver_, observed); |
653 manager()->OnPasswordFormsRendered(&driver_, observed, true); | 653 manager()->OnPasswordFormsRendered(&driver_, observed, true); |
654 } | 654 } |
655 | 655 |
656 // While sync credentials are not saved, they are still filled to avoid users | 656 // While sync credentials are not saved, they are still filled to avoid users |
657 // thinking they lost access to their accounts. | 657 // thinking they lost access to their accounts. |
658 TEST_F(PasswordManagerTest, SyncCredentialsStillFilled) { | 658 TEST_F(PasswordManagerTest, SyncCredentialsStillFilled) { |
659 PasswordForm form(MakeSimpleForm()); | 659 PasswordForm form(MakeSimpleForm()); |
660 // Pretend that the password store contains credentials stored for |form|. | 660 // Pretend that the password store contains credentials stored for |form|. |
661 EXPECT_CALL(*store_, GetLogins(_, _, _)) | 661 EXPECT_CALL(*store_, GetLogins(_, _)) |
662 .WillRepeatedly(WithArg<2>(InvokeConsumer(form))); | 662 .WillRepeatedly(WithArg<1>(InvokeConsumer(form))); |
663 | 663 |
664 client_.FilterAllResultsForSaving(); | 664 client_.FilterAllResultsForSaving(); |
665 | 665 |
666 // Load the page. | 666 // Load the page. |
667 autofill::PasswordFormFillData form_data; | 667 autofill::PasswordFormFillData form_data; |
668 EXPECT_CALL(driver_, FillPasswordForm(_)).WillOnce(SaveArg<0>(&form_data)); | 668 EXPECT_CALL(driver_, FillPasswordForm(_)).WillOnce(SaveArg<0>(&form_data)); |
669 std::vector<PasswordForm> observed; | 669 std::vector<PasswordForm> observed; |
670 observed.push_back(form); | 670 observed.push_back(form); |
671 manager()->OnPasswordFormsParsed(&driver_, observed); | 671 manager()->OnPasswordFormsParsed(&driver_, observed); |
672 EXPECT_EQ(form.password_value, form_data.password_field.value); | 672 EXPECT_EQ(form.password_value, form_data.password_field.value); |
(...skipping 10 matching lines...) Expand all Loading... |
683 PasswordForm first_form(MakeSimpleForm()); | 683 PasswordForm first_form(MakeSimpleForm()); |
684 first_form.origin = GURL("http://www.xda-developers.com/"); | 684 first_form.origin = GURL("http://www.xda-developers.com/"); |
685 first_form.action = GURL("http://forum.xda-developers.com/login.php"); | 685 first_form.action = GURL("http://forum.xda-developers.com/login.php"); |
686 | 686 |
687 // |second_form|'s action differs only with it's scheme i.e. *https://*. | 687 // |second_form|'s action differs only with it's scheme i.e. *https://*. |
688 PasswordForm second_form(first_form); | 688 PasswordForm second_form(first_form); |
689 second_form.action = GURL("https://forum.xda-developers.com/login.php"); | 689 second_form.action = GURL("https://forum.xda-developers.com/login.php"); |
690 | 690 |
691 std::vector<PasswordForm> observed; | 691 std::vector<PasswordForm> observed; |
692 observed.push_back(first_form); | 692 observed.push_back(first_form); |
693 EXPECT_CALL(*store_, GetLogins(_, _, _)) | 693 EXPECT_CALL(*store_, GetLogins(_, _)) |
694 .WillRepeatedly(WithArg<2>(InvokeEmptyConsumerWithForms())); | 694 .WillRepeatedly(WithArg<1>(InvokeEmptyConsumerWithForms())); |
695 manager()->OnPasswordFormsParsed(&driver_, observed); | 695 manager()->OnPasswordFormsParsed(&driver_, observed); |
696 manager()->OnPasswordFormsRendered(&driver_, observed, true); | 696 manager()->OnPasswordFormsRendered(&driver_, observed, true); |
697 | 697 |
698 EXPECT_CALL(client_, IsSavingAndFillingEnabledForCurrentPage()) | 698 EXPECT_CALL(client_, IsSavingAndFillingEnabledForCurrentPage()) |
699 .WillRepeatedly(Return(true)); | 699 .WillRepeatedly(Return(true)); |
700 OnPasswordFormSubmitted(first_form); | 700 OnPasswordFormSubmitted(first_form); |
701 | 701 |
702 // Simulate loading a page, which contains |second_form| instead of | 702 // Simulate loading a page, which contains |second_form| instead of |
703 // |first_form|. | 703 // |first_form|. |
704 observed.clear(); | 704 observed.clear(); |
(...skipping 11 matching lines...) Expand all Loading... |
716 // password forms, that would be the reasonable choice), if the new password is | 716 // password forms, that would be the reasonable choice), if the new password is |
717 // empty, this is likely just a slightly misunderstood form, and Chrome should | 717 // empty, this is likely just a slightly misunderstood form, and Chrome should |
718 // save the non-empty current password field. | 718 // save the non-empty current password field. |
719 TEST_F(PasswordManagerTest, DoNotSaveWithEmptyNewPasswordAndNonemptyPassword) { | 719 TEST_F(PasswordManagerTest, DoNotSaveWithEmptyNewPasswordAndNonemptyPassword) { |
720 std::vector<PasswordForm> observed; | 720 std::vector<PasswordForm> observed; |
721 PasswordForm form(MakeSimpleForm()); | 721 PasswordForm form(MakeSimpleForm()); |
722 ASSERT_FALSE(form.password_value.empty()); | 722 ASSERT_FALSE(form.password_value.empty()); |
723 form.new_password_element = ASCIIToUTF16("new_password_element"); | 723 form.new_password_element = ASCIIToUTF16("new_password_element"); |
724 form.new_password_value.clear(); | 724 form.new_password_value.clear(); |
725 observed.push_back(form); | 725 observed.push_back(form); |
726 EXPECT_CALL(*store_, GetLogins(_, _, _)) | 726 EXPECT_CALL(*store_, GetLogins(_, _)) |
727 .WillOnce(WithArg<2>(InvokeEmptyConsumerWithForms())); | 727 .WillOnce(WithArg<1>(InvokeEmptyConsumerWithForms())); |
728 manager()->OnPasswordFormsParsed(&driver_, observed); | 728 manager()->OnPasswordFormsParsed(&driver_, observed); |
729 manager()->OnPasswordFormsRendered(&driver_, observed, true); | 729 manager()->OnPasswordFormsRendered(&driver_, observed, true); |
730 | 730 |
731 EXPECT_CALL(client_, IsSavingAndFillingEnabledForCurrentPage()) | 731 EXPECT_CALL(client_, IsSavingAndFillingEnabledForCurrentPage()) |
732 .WillRepeatedly(Return(true)); | 732 .WillRepeatedly(Return(true)); |
733 OnPasswordFormSubmitted(form); | 733 OnPasswordFormSubmitted(form); |
734 | 734 |
735 scoped_ptr<PasswordFormManager> form_manager_to_save; | 735 scoped_ptr<PasswordFormManager> form_manager_to_save; |
736 EXPECT_CALL(client_, | 736 EXPECT_CALL(client_, |
737 PromptUserToSaveOrUpdatePasswordPtr( | 737 PromptUserToSaveOrUpdatePasswordPtr( |
(...skipping 13 matching lines...) Expand all Loading... |
751 TEST_F(PasswordManagerTest, FormSubmitWithOnlyPasswordField) { | 751 TEST_F(PasswordManagerTest, FormSubmitWithOnlyPasswordField) { |
752 // Test to verify that on submitting the HTML password form without having | 752 // Test to verify that on submitting the HTML password form without having |
753 // username input filed shows password save promt and saves the password to | 753 // username input filed shows password save promt and saves the password to |
754 // store. | 754 // store. |
755 EXPECT_CALL(driver_, FillPasswordForm(_)).Times(0); | 755 EXPECT_CALL(driver_, FillPasswordForm(_)).Times(0); |
756 std::vector<PasswordForm> observed; | 756 std::vector<PasswordForm> observed; |
757 | 757 |
758 // Loads passsword form without username input field. | 758 // Loads passsword form without username input field. |
759 PasswordForm form(MakeSimpleFormWithOnlyPasswordField()); | 759 PasswordForm form(MakeSimpleFormWithOnlyPasswordField()); |
760 observed.push_back(form); | 760 observed.push_back(form); |
761 EXPECT_CALL(*store_, GetLogins(_, _, _)) | 761 EXPECT_CALL(*store_, GetLogins(_, _)) |
762 .WillOnce(WithArg<2>(InvokeEmptyConsumerWithForms())); | 762 .WillOnce(WithArg<1>(InvokeEmptyConsumerWithForms())); |
763 manager()->OnPasswordFormsParsed(&driver_, observed); | 763 manager()->OnPasswordFormsParsed(&driver_, observed); |
764 manager()->OnPasswordFormsRendered(&driver_, observed, true); | 764 manager()->OnPasswordFormsRendered(&driver_, observed, true); |
765 | 765 |
766 EXPECT_CALL(client_, IsSavingAndFillingEnabledForCurrentPage()) | 766 EXPECT_CALL(client_, IsSavingAndFillingEnabledForCurrentPage()) |
767 .WillRepeatedly(Return(true)); | 767 .WillRepeatedly(Return(true)); |
768 OnPasswordFormSubmitted(form); | 768 OnPasswordFormSubmitted(form); |
769 | 769 |
770 scoped_ptr<PasswordFormManager> form_manager_to_save; | 770 scoped_ptr<PasswordFormManager> form_manager_to_save; |
771 EXPECT_CALL(client_, | 771 EXPECT_CALL(client_, |
772 PromptUserToSaveOrUpdatePasswordPtr( | 772 PromptUserToSaveOrUpdatePasswordPtr( |
(...skipping 12 matching lines...) Expand all Loading... |
785 } | 785 } |
786 | 786 |
787 TEST_F(PasswordManagerTest, FillPasswordOnManyFrames) { | 787 TEST_F(PasswordManagerTest, FillPasswordOnManyFrames) { |
788 // A password form should be filled in all frames it appears in. | 788 // A password form should be filled in all frames it appears in. |
789 PasswordForm form(MakeSimpleForm()); // The observed and saved form. | 789 PasswordForm form(MakeSimpleForm()); // The observed and saved form. |
790 | 790 |
791 // Observe the form in the first frame. | 791 // Observe the form in the first frame. |
792 std::vector<PasswordForm> observed; | 792 std::vector<PasswordForm> observed; |
793 observed.push_back(form); | 793 observed.push_back(form); |
794 EXPECT_CALL(driver_, FillPasswordForm(_)); | 794 EXPECT_CALL(driver_, FillPasswordForm(_)); |
795 EXPECT_CALL(*store_, GetLogins(_, PasswordStore::DISALLOW_PROMPT, _)) | 795 EXPECT_CALL(*store_, GetLogins(_, _)) |
796 .WillOnce(WithArg<2>(InvokeConsumer(form))); | 796 .WillOnce(WithArg<1>(InvokeConsumer(form))); |
797 manager()->OnPasswordFormsParsed(&driver_, observed); | 797 manager()->OnPasswordFormsParsed(&driver_, observed); |
798 | 798 |
799 // Now the form will be seen the second time, in a different frame. The driver | 799 // Now the form will be seen the second time, in a different frame. The driver |
800 // for that frame should be told to fill it, but the store should not be asked | 800 // for that frame should be told to fill it, but the store should not be asked |
801 // for it again. | 801 // for it again. |
802 MockPasswordManagerDriver driver_b; | 802 MockPasswordManagerDriver driver_b; |
803 EXPECT_CALL(driver_b, FillPasswordForm(_)); | 803 EXPECT_CALL(driver_b, FillPasswordForm(_)); |
804 EXPECT_CALL(*store_, GetLogins(_, _, _)).Times(0); | 804 EXPECT_CALL(*store_, GetLogins(_, _)).Times(0); |
805 manager()->OnPasswordFormsParsed(&driver_b, observed); | 805 manager()->OnPasswordFormsParsed(&driver_b, observed); |
806 } | 806 } |
807 | 807 |
808 TEST_F(PasswordManagerTest, InPageNavigation) { | 808 TEST_F(PasswordManagerTest, InPageNavigation) { |
809 // Test that observing a newly submitted form shows the save password bar on | 809 // Test that observing a newly submitted form shows the save password bar on |
810 // call in page navigation. | 810 // call in page navigation. |
811 std::vector<PasswordForm> observed; | 811 std::vector<PasswordForm> observed; |
812 PasswordForm form(MakeSimpleForm()); | 812 PasswordForm form(MakeSimpleForm()); |
813 observed.push_back(form); | 813 observed.push_back(form); |
814 EXPECT_CALL(*store_, GetLogins(_, _, _)) | 814 EXPECT_CALL(*store_, GetLogins(_, _)) |
815 .WillOnce(WithArg<2>(InvokeEmptyConsumerWithForms())); | 815 .WillOnce(WithArg<1>(InvokeEmptyConsumerWithForms())); |
816 manager()->OnPasswordFormsParsed(&driver_, observed); | 816 manager()->OnPasswordFormsParsed(&driver_, observed); |
817 manager()->OnPasswordFormsRendered(&driver_, observed, true); | 817 manager()->OnPasswordFormsRendered(&driver_, observed, true); |
818 | 818 |
819 EXPECT_CALL(client_, IsSavingAndFillingEnabledForCurrentPage()) | 819 EXPECT_CALL(client_, IsSavingAndFillingEnabledForCurrentPage()) |
820 .WillRepeatedly(Return(true)); | 820 .WillRepeatedly(Return(true)); |
821 | 821 |
822 scoped_ptr<PasswordFormManager> form_manager_to_save; | 822 scoped_ptr<PasswordFormManager> form_manager_to_save; |
823 EXPECT_CALL(client_, | 823 EXPECT_CALL(client_, |
824 PromptUserToSaveOrUpdatePasswordPtr( | 824 PromptUserToSaveOrUpdatePasswordPtr( |
825 _, CredentialSourceType::CREDENTIAL_SOURCE_PASSWORD_MANAGER)) | 825 _, CredentialSourceType::CREDENTIAL_SOURCE_PASSWORD_MANAGER)) |
(...skipping 10 matching lines...) Expand all Loading... |
836 TEST_F(PasswordManagerTest, InPageNavigationBlacklistedSite) { | 836 TEST_F(PasswordManagerTest, InPageNavigationBlacklistedSite) { |
837 // Test that observing a newly submitted form on blacklisted site does notify | 837 // Test that observing a newly submitted form on blacklisted site does notify |
838 // the embedder on call in page navigation. | 838 // the embedder on call in page navigation. |
839 std::vector<PasswordForm> observed; | 839 std::vector<PasswordForm> observed; |
840 PasswordForm form(MakeSimpleForm()); | 840 PasswordForm form(MakeSimpleForm()); |
841 observed.push_back(form); | 841 observed.push_back(form); |
842 // Simulate that blacklisted form stored in store. | 842 // Simulate that blacklisted form stored in store. |
843 PasswordForm blacklisted_form(form); | 843 PasswordForm blacklisted_form(form); |
844 blacklisted_form.username_value = ASCIIToUTF16(""); | 844 blacklisted_form.username_value = ASCIIToUTF16(""); |
845 blacklisted_form.blacklisted_by_user = true; | 845 blacklisted_form.blacklisted_by_user = true; |
846 EXPECT_CALL(*store_, GetLogins(_, _, _)) | 846 EXPECT_CALL(*store_, GetLogins(_, _)) |
847 .WillOnce(WithArg<2>(InvokeConsumer(blacklisted_form))); | 847 .WillOnce(WithArg<1>(InvokeConsumer(blacklisted_form))); |
848 manager()->OnPasswordFormsParsed(&driver_, observed); | 848 manager()->OnPasswordFormsParsed(&driver_, observed); |
849 manager()->OnPasswordFormsRendered(&driver_, observed, true); | 849 manager()->OnPasswordFormsRendered(&driver_, observed, true); |
850 | 850 |
851 EXPECT_CALL(client_, IsSavingAndFillingEnabledForCurrentPage()) | 851 EXPECT_CALL(client_, IsSavingAndFillingEnabledForCurrentPage()) |
852 .WillRepeatedly(Return(true)); | 852 .WillRepeatedly(Return(true)); |
853 // Prefs are needed for failure logging about blacklisting. | 853 // Prefs are needed for failure logging about blacklisting. |
854 EXPECT_CALL(client_, GetPrefs()).WillRepeatedly(Return(nullptr)); | 854 EXPECT_CALL(client_, GetPrefs()).WillRepeatedly(Return(nullptr)); |
855 | 855 |
856 scoped_ptr<PasswordFormManager> form_manager_to_save; | 856 scoped_ptr<PasswordFormManager> form_manager_to_save; |
857 EXPECT_CALL(client_, | 857 EXPECT_CALL(client_, |
858 PromptUserToSaveOrUpdatePasswordPtr( | 858 PromptUserToSaveOrUpdatePasswordPtr( |
859 _, CredentialSourceType::CREDENTIAL_SOURCE_PASSWORD_MANAGER)) | 859 _, CredentialSourceType::CREDENTIAL_SOURCE_PASSWORD_MANAGER)) |
860 .WillOnce(WithArg<0>(SaveToScopedPtr(&form_manager_to_save))); | 860 .WillOnce(WithArg<0>(SaveToScopedPtr(&form_manager_to_save))); |
861 | 861 |
862 manager()->OnInPageNavigation(&driver_, form); | 862 manager()->OnInPageNavigation(&driver_, form); |
863 EXPECT_TRUE(form_manager_to_save->IsBlacklisted()); | 863 EXPECT_TRUE(form_manager_to_save->IsBlacklisted()); |
864 } | 864 } |
865 | 865 |
866 TEST_F(PasswordManagerTest, SavingSignupForms_NoHTMLMatch) { | 866 TEST_F(PasswordManagerTest, SavingSignupForms_NoHTMLMatch) { |
867 // Signup forms don't require HTML attributes match in order to save. | 867 // Signup forms don't require HTML attributes match in order to save. |
868 // Verify that we prefer a better match (action + origin vs. origin). | 868 // Verify that we prefer a better match (action + origin vs. origin). |
869 std::vector<PasswordForm> observed; | 869 std::vector<PasswordForm> observed; |
870 PasswordForm form(MakeSimpleForm()); | 870 PasswordForm form(MakeSimpleForm()); |
871 observed.push_back(form); | 871 observed.push_back(form); |
872 PasswordForm wrong_action_form(form); | 872 PasswordForm wrong_action_form(form); |
873 wrong_action_form.action = GURL("http://www.google.com/other/action"); | 873 wrong_action_form.action = GURL("http://www.google.com/other/action"); |
874 observed.push_back(wrong_action_form); | 874 observed.push_back(wrong_action_form); |
875 | 875 |
876 EXPECT_CALL(*store_, GetLogins(_, _, _)) | 876 EXPECT_CALL(*store_, GetLogins(_, _)) |
877 .WillRepeatedly(WithArg<2>(InvokeEmptyConsumerWithForms())); | 877 .WillRepeatedly(WithArg<1>(InvokeEmptyConsumerWithForms())); |
878 manager()->OnPasswordFormsParsed(&driver_, observed); | 878 manager()->OnPasswordFormsParsed(&driver_, observed); |
879 manager()->OnPasswordFormsRendered(&driver_, observed, true); | 879 manager()->OnPasswordFormsRendered(&driver_, observed, true); |
880 | 880 |
881 // Simulate either form changing or heuristics choosing other fields | 881 // Simulate either form changing or heuristics choosing other fields |
882 // after the user has entered their information. | 882 // after the user has entered their information. |
883 PasswordForm submitted_form(form); | 883 PasswordForm submitted_form(form); |
884 submitted_form.new_password_element = ASCIIToUTF16("new_password"); | 884 submitted_form.new_password_element = ASCIIToUTF16("new_password"); |
885 submitted_form.new_password_value = form.password_value; | 885 submitted_form.new_password_value = form.password_value; |
886 submitted_form.password_element.clear(); | 886 submitted_form.password_element.clear(); |
887 submitted_form.password_value.clear(); | 887 submitted_form.password_value.clear(); |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
926 // Change the submit element so we can track which of the two forms is | 926 // Change the submit element so we can track which of the two forms is |
927 // chosen as a better match. | 927 // chosen as a better match. |
928 PasswordForm wrong_submit_form(form); | 928 PasswordForm wrong_submit_form(form); |
929 wrong_submit_form.submit_element = ASCIIToUTF16("different_signin"); | 929 wrong_submit_form.submit_element = ASCIIToUTF16("different_signin"); |
930 wrong_submit_form.new_password_element = ASCIIToUTF16("new_password"); | 930 wrong_submit_form.new_password_element = ASCIIToUTF16("new_password"); |
931 wrong_submit_form.new_password_value = form.password_value; | 931 wrong_submit_form.new_password_value = form.password_value; |
932 wrong_submit_form.password_element.clear(); | 932 wrong_submit_form.password_element.clear(); |
933 wrong_submit_form.password_value.clear(); | 933 wrong_submit_form.password_value.clear(); |
934 observed.push_back(wrong_submit_form); | 934 observed.push_back(wrong_submit_form); |
935 | 935 |
936 EXPECT_CALL(*store_, GetLogins(_, _, _)) | 936 EXPECT_CALL(*store_, GetLogins(_, _)) |
937 .WillRepeatedly(WithArg<2>(InvokeEmptyConsumerWithForms())); | 937 .WillRepeatedly(WithArg<1>(InvokeEmptyConsumerWithForms())); |
938 manager()->OnPasswordFormsParsed(&driver_, observed); | 938 manager()->OnPasswordFormsParsed(&driver_, observed); |
939 manager()->OnPasswordFormsRendered(&driver_, observed, true); | 939 manager()->OnPasswordFormsRendered(&driver_, observed, true); |
940 | 940 |
941 PasswordForm submitted_form(form); | 941 PasswordForm submitted_form(form); |
942 submitted_form.action = GURL("http://www.google.com/other/action"); | 942 submitted_form.action = GURL("http://www.google.com/other/action"); |
943 | 943 |
944 EXPECT_CALL(client_, IsSavingAndFillingEnabledForCurrentPage()) | 944 EXPECT_CALL(client_, IsSavingAndFillingEnabledForCurrentPage()) |
945 .WillRepeatedly(Return(true)); | 945 .WillRepeatedly(Return(true)); |
946 OnPasswordFormSubmitted(submitted_form); | 946 OnPasswordFormSubmitted(submitted_form); |
947 | 947 |
(...skipping 26 matching lines...) Expand all Loading... |
974 EXPECT_TRUE(form_to_save.new_password_value.empty()); | 974 EXPECT_TRUE(form_to_save.new_password_value.empty()); |
975 } | 975 } |
976 | 976 |
977 TEST_F(PasswordManagerTest, FormSubmittedChangedWithAutofillResponse) { | 977 TEST_F(PasswordManagerTest, FormSubmittedChangedWithAutofillResponse) { |
978 // This tests verifies that if the observed forms and provisionally saved | 978 // This tests verifies that if the observed forms and provisionally saved |
979 // differ in the choice of the username, the saving still succeeds, as long as | 979 // differ in the choice of the username, the saving still succeeds, as long as |
980 // the changed form is marked "parsed using autofill predictions". | 980 // the changed form is marked "parsed using autofill predictions". |
981 std::vector<PasswordForm> observed; | 981 std::vector<PasswordForm> observed; |
982 PasswordForm form(MakeSimpleForm()); | 982 PasswordForm form(MakeSimpleForm()); |
983 observed.push_back(form); | 983 observed.push_back(form); |
984 EXPECT_CALL(*store_, GetLogins(_, _, _)) | 984 EXPECT_CALL(*store_, GetLogins(_, _)) |
985 .WillRepeatedly(WithArg<2>(InvokeEmptyConsumerWithForms())); | 985 .WillRepeatedly(WithArg<1>(InvokeEmptyConsumerWithForms())); |
986 manager()->OnPasswordFormsParsed(&driver_, observed); | 986 manager()->OnPasswordFormsParsed(&driver_, observed); |
987 manager()->OnPasswordFormsRendered(&driver_, observed, true); | 987 manager()->OnPasswordFormsRendered(&driver_, observed, true); |
988 | 988 |
989 // Simulate that based on autofill server username prediction, the username | 989 // Simulate that based on autofill server username prediction, the username |
990 // of the form changed from the default candidate("Email") to something else. | 990 // of the form changed from the default candidate("Email") to something else. |
991 // Set the parsed_using_autofill_predictions bit to true to make sure that | 991 // Set the parsed_using_autofill_predictions bit to true to make sure that |
992 // choice of username is accepted by PasswordManager, otherwise the the form | 992 // choice of username is accepted by PasswordManager, otherwise the the form |
993 // will be rejected as not equal to the observed one. Note that during | 993 // will be rejected as not equal to the observed one. Note that during |
994 // initial parsing we don't have autofill server predictions yet, that's why | 994 // initial parsing we don't have autofill server predictions yet, that's why |
995 // observed form and submitted form may be different. | 995 // observed form and submitted form may be different. |
(...skipping 20 matching lines...) Expand all Loading... |
1016 form_manager_to_save->Save(); | 1016 form_manager_to_save->Save(); |
1017 } | 1017 } |
1018 | 1018 |
1019 TEST_F(PasswordManagerTest, FormSubmittedUnchangedNotifiesClient) { | 1019 TEST_F(PasswordManagerTest, FormSubmittedUnchangedNotifiesClient) { |
1020 // This tests verifies that if the observed forms and provisionally saved | 1020 // This tests verifies that if the observed forms and provisionally saved |
1021 // forms are the same, then successful submission notifies the client. | 1021 // forms are the same, then successful submission notifies the client. |
1022 std::vector<PasswordForm> observed; | 1022 std::vector<PasswordForm> observed; |
1023 PasswordForm form(MakeSimpleForm()); | 1023 PasswordForm form(MakeSimpleForm()); |
1024 observed.push_back(form); | 1024 observed.push_back(form); |
1025 EXPECT_CALL(driver_, FillPasswordForm(_)).Times(2); | 1025 EXPECT_CALL(driver_, FillPasswordForm(_)).Times(2); |
1026 EXPECT_CALL(*store_, GetLogins(_, _, _)) | 1026 EXPECT_CALL(*store_, GetLogins(_, _)) |
1027 .WillOnce(WithArg<2>(InvokeConsumer(form))); | 1027 .WillOnce(WithArg<1>(InvokeConsumer(form))); |
1028 manager()->OnPasswordFormsParsed(&driver_, observed); | 1028 manager()->OnPasswordFormsParsed(&driver_, observed); |
1029 manager()->OnPasswordFormsRendered(&driver_, observed, true); | 1029 manager()->OnPasswordFormsRendered(&driver_, observed, true); |
1030 | 1030 |
1031 EXPECT_CALL(client_, IsSavingAndFillingEnabledForCurrentPage()) | 1031 EXPECT_CALL(client_, IsSavingAndFillingEnabledForCurrentPage()) |
1032 .WillRepeatedly(Return(true)); | 1032 .WillRepeatedly(Return(true)); |
1033 OnPasswordFormSubmitted(form); | 1033 OnPasswordFormSubmitted(form); |
1034 | 1034 |
1035 autofill::PasswordForm updated_form; | 1035 autofill::PasswordForm updated_form; |
1036 autofill::PasswordForm notified_form; | 1036 autofill::PasswordForm notified_form; |
1037 EXPECT_CALL(client_, PromptUserToSaveOrUpdatePasswordPtr(_, _)).Times(0); | 1037 EXPECT_CALL(client_, PromptUserToSaveOrUpdatePasswordPtr(_, _)).Times(0); |
(...skipping 13 matching lines...) Expand all Loading... |
1051 TEST_F(PasswordManagerTest, SaveFormFetchedAfterSubmit) { | 1051 TEST_F(PasswordManagerTest, SaveFormFetchedAfterSubmit) { |
1052 // Test that a password is offered for saving even if the response from the | 1052 // Test that a password is offered for saving even if the response from the |
1053 // PasswordStore comes after submit. | 1053 // PasswordStore comes after submit. |
1054 std::vector<PasswordForm> observed; | 1054 std::vector<PasswordForm> observed; |
1055 PasswordForm form(MakeSimpleForm()); | 1055 PasswordForm form(MakeSimpleForm()); |
1056 observed.push_back(form); | 1056 observed.push_back(form); |
1057 | 1057 |
1058 PasswordStoreConsumer* form_manager = nullptr; | 1058 PasswordStoreConsumer* form_manager = nullptr; |
1059 // No call-back from store after GetLogins is called emulates that | 1059 // No call-back from store after GetLogins is called emulates that |
1060 // PasswordStore did not fetch a form in time before submission. | 1060 // PasswordStore did not fetch a form in time before submission. |
1061 EXPECT_CALL(*store_, GetLogins(_, _, _)).WillOnce(SaveArg<2>(&form_manager)); | 1061 EXPECT_CALL(*store_, GetLogins(_, _)).WillOnce(SaveArg<1>(&form_manager)); |
1062 manager()->OnPasswordFormsParsed(&driver_, observed); | 1062 manager()->OnPasswordFormsParsed(&driver_, observed); |
1063 manager()->OnPasswordFormsRendered(&driver_, observed, true); | 1063 manager()->OnPasswordFormsRendered(&driver_, observed, true); |
1064 | 1064 |
1065 EXPECT_CALL(client_, IsSavingAndFillingEnabledForCurrentPage()) | 1065 EXPECT_CALL(client_, IsSavingAndFillingEnabledForCurrentPage()) |
1066 .WillRepeatedly(Return(true)); | 1066 .WillRepeatedly(Return(true)); |
1067 OnPasswordFormSubmitted(form); | 1067 OnPasswordFormSubmitted(form); |
1068 | 1068 |
1069 // Emulate fetching password form from PasswordStore after submission but | 1069 // Emulate fetching password form from PasswordStore after submission but |
1070 // before post-navigation load. | 1070 // before post-navigation load. |
1071 ASSERT_TRUE(form_manager); | 1071 ASSERT_TRUE(form_manager); |
(...skipping 17 matching lines...) Expand all Loading... |
1089 } | 1089 } |
1090 | 1090 |
1091 TEST_F(PasswordManagerTest, PasswordGenerationForceSaving) { | 1091 TEST_F(PasswordManagerTest, PasswordGenerationForceSaving) { |
1092 // Test the safety net against password loss during generation | 1092 // Test the safety net against password loss during generation |
1093 // (http://crbug.com/506307) -- out of the two rules (1) "always save | 1093 // (http://crbug.com/506307) -- out of the two rules (1) "always save |
1094 // generated passwords" and (2) "do not save passwords when the password form | 1094 // generated passwords" and (2) "do not save passwords when the password form |
1095 // reappears", rule (1) takes precedence. | 1095 // reappears", rule (1) takes precedence. |
1096 std::vector<PasswordForm> observed; | 1096 std::vector<PasswordForm> observed; |
1097 PasswordForm form(MakeFormWithOnlyNewPasswordField()); | 1097 PasswordForm form(MakeFormWithOnlyNewPasswordField()); |
1098 observed.push_back(form); | 1098 observed.push_back(form); |
1099 EXPECT_CALL(*store_, GetLogins(_, _, _)) | 1099 EXPECT_CALL(*store_, GetLogins(_, _)) |
1100 .WillRepeatedly(WithArg<2>(InvokeEmptyConsumerWithForms())); | 1100 .WillRepeatedly(WithArg<1>(InvokeEmptyConsumerWithForms())); |
1101 manager()->OnPasswordFormsParsed(&driver_, observed); | 1101 manager()->OnPasswordFormsParsed(&driver_, observed); |
1102 manager()->OnPasswordFormsRendered(&driver_, observed, true); | 1102 manager()->OnPasswordFormsRendered(&driver_, observed, true); |
1103 | 1103 |
1104 EXPECT_CALL(client_, IsSavingAndFillingEnabledForCurrentPage()) | 1104 EXPECT_CALL(client_, IsSavingAndFillingEnabledForCurrentPage()) |
1105 .WillRepeatedly(Return(true)); | 1105 .WillRepeatedly(Return(true)); |
1106 manager()->SetHasGeneratedPasswordForForm(&driver_, form, true); | 1106 manager()->SetHasGeneratedPasswordForForm(&driver_, form, true); |
1107 | 1107 |
1108 // The user should not need to confirm saving as they have already given | 1108 // The user should not need to confirm saving as they have already given |
1109 // consent by using the generated password. The form should be saved once | 1109 // consent by using the generated password. The form should be saved once |
1110 // navigation occurs. The client will be informed that automatic saving has | 1110 // navigation occurs. The client will be informed that automatic saving has |
(...skipping 13 matching lines...) Expand all Loading... |
1124 // password field in the form to save. | 1124 // password field in the form to save. |
1125 EXPECT_EQ(form.new_password_value, form_to_save.password_value); | 1125 EXPECT_EQ(form.new_password_value, form_to_save.password_value); |
1126 } | 1126 } |
1127 | 1127 |
1128 // If the user edits the generated password, but does not remove it completely, | 1128 // If the user edits the generated password, but does not remove it completely, |
1129 // it should stay treated as a generated password. | 1129 // it should stay treated as a generated password. |
1130 TEST_F(PasswordManagerTest, PasswordGenerationPasswordEdited) { | 1130 TEST_F(PasswordManagerTest, PasswordGenerationPasswordEdited) { |
1131 std::vector<PasswordForm> observed; | 1131 std::vector<PasswordForm> observed; |
1132 PasswordForm form(MakeFormWithOnlyNewPasswordField()); | 1132 PasswordForm form(MakeFormWithOnlyNewPasswordField()); |
1133 observed.push_back(form); | 1133 observed.push_back(form); |
1134 EXPECT_CALL(*store_, GetLogins(_, _, _)) | 1134 EXPECT_CALL(*store_, GetLogins(_, _)) |
1135 .WillRepeatedly(WithArg<2>(InvokeEmptyConsumerWithForms())); | 1135 .WillRepeatedly(WithArg<1>(InvokeEmptyConsumerWithForms())); |
1136 manager()->OnPasswordFormsParsed(&driver_, observed); | 1136 manager()->OnPasswordFormsParsed(&driver_, observed); |
1137 manager()->OnPasswordFormsRendered(&driver_, observed, true); | 1137 manager()->OnPasswordFormsRendered(&driver_, observed, true); |
1138 | 1138 |
1139 EXPECT_CALL(client_, IsSavingAndFillingEnabledForCurrentPage()) | 1139 EXPECT_CALL(client_, IsSavingAndFillingEnabledForCurrentPage()) |
1140 .WillRepeatedly(Return(true)); | 1140 .WillRepeatedly(Return(true)); |
1141 manager()->SetHasGeneratedPasswordForForm(&driver_, form, true); | 1141 manager()->SetHasGeneratedPasswordForForm(&driver_, form, true); |
1142 | 1142 |
1143 // Simulate user editing and submitting a different password. Verify that | 1143 // Simulate user editing and submitting a different password. Verify that |
1144 // the edited password is the one that is saved. | 1144 // the edited password is the one that is saved. |
1145 form.new_password_value = ASCIIToUTF16("different_password"); | 1145 form.new_password_value = ASCIIToUTF16("different_password"); |
(...skipping 19 matching lines...) Expand all Loading... |
1165 } | 1165 } |
1166 | 1166 |
1167 // Generated password are saved even if it looks like the submit failed (the | 1167 // Generated password are saved even if it looks like the submit failed (the |
1168 // form reappeared). Verify that passwords which are no longer marked as | 1168 // form reappeared). Verify that passwords which are no longer marked as |
1169 // generated will not be automatically saved. | 1169 // generated will not be automatically saved. |
1170 TEST_F(PasswordManagerTest, | 1170 TEST_F(PasswordManagerTest, |
1171 PasswordGenerationNoLongerGeneratedPasswordNotForceSaved_FailedSubmit) { | 1171 PasswordGenerationNoLongerGeneratedPasswordNotForceSaved_FailedSubmit) { |
1172 std::vector<PasswordForm> observed; | 1172 std::vector<PasswordForm> observed; |
1173 PasswordForm form(MakeFormWithOnlyNewPasswordField()); | 1173 PasswordForm form(MakeFormWithOnlyNewPasswordField()); |
1174 observed.push_back(form); | 1174 observed.push_back(form); |
1175 EXPECT_CALL(*store_, GetLogins(_, _, _)) | 1175 EXPECT_CALL(*store_, GetLogins(_, _)) |
1176 .WillRepeatedly(WithArg<2>(InvokeEmptyConsumerWithForms())); | 1176 .WillRepeatedly(WithArg<1>(InvokeEmptyConsumerWithForms())); |
1177 manager()->OnPasswordFormsParsed(&driver_, observed); | 1177 manager()->OnPasswordFormsParsed(&driver_, observed); |
1178 manager()->OnPasswordFormsRendered(&driver_, observed, true); | 1178 manager()->OnPasswordFormsRendered(&driver_, observed, true); |
1179 | 1179 |
1180 EXPECT_CALL(client_, IsSavingAndFillingEnabledForCurrentPage()) | 1180 EXPECT_CALL(client_, IsSavingAndFillingEnabledForCurrentPage()) |
1181 .WillRepeatedly(Return(true)); | 1181 .WillRepeatedly(Return(true)); |
1182 manager()->SetHasGeneratedPasswordForForm(&driver_, form, true); | 1182 manager()->SetHasGeneratedPasswordForForm(&driver_, form, true); |
1183 | 1183 |
1184 // Simulate user removing generated password and adding a new one. | 1184 // Simulate user removing generated password and adding a new one. |
1185 form.new_password_value = ASCIIToUTF16("different_password"); | 1185 form.new_password_value = ASCIIToUTF16("different_password"); |
1186 manager()->SetHasGeneratedPasswordForForm(&driver_, form, false); | 1186 manager()->SetHasGeneratedPasswordForForm(&driver_, form, false); |
(...skipping 10 matching lines...) Expand all Loading... |
1197 manager()->OnPasswordFormsRendered(&driver_, observed, true); | 1197 manager()->OnPasswordFormsRendered(&driver_, observed, true); |
1198 } | 1198 } |
1199 | 1199 |
1200 // Verify that passwords which are no longer generated trigger the confirmation | 1200 // Verify that passwords which are no longer generated trigger the confirmation |
1201 // dialog when submitted. | 1201 // dialog when submitted. |
1202 TEST_F(PasswordManagerTest, | 1202 TEST_F(PasswordManagerTest, |
1203 PasswordGenerationNoLongerGeneratedPasswordNotForceSaved) { | 1203 PasswordGenerationNoLongerGeneratedPasswordNotForceSaved) { |
1204 std::vector<PasswordForm> observed; | 1204 std::vector<PasswordForm> observed; |
1205 PasswordForm form(MakeFormWithOnlyNewPasswordField()); | 1205 PasswordForm form(MakeFormWithOnlyNewPasswordField()); |
1206 observed.push_back(form); | 1206 observed.push_back(form); |
1207 EXPECT_CALL(*store_, GetLogins(_, _, _)) | 1207 EXPECT_CALL(*store_, GetLogins(_, _)) |
1208 .WillRepeatedly(WithArg<2>(InvokeEmptyConsumerWithForms())); | 1208 .WillRepeatedly(WithArg<1>(InvokeEmptyConsumerWithForms())); |
1209 manager()->OnPasswordFormsParsed(&driver_, observed); | 1209 manager()->OnPasswordFormsParsed(&driver_, observed); |
1210 manager()->OnPasswordFormsRendered(&driver_, observed, true); | 1210 manager()->OnPasswordFormsRendered(&driver_, observed, true); |
1211 | 1211 |
1212 EXPECT_CALL(client_, IsSavingAndFillingEnabledForCurrentPage()) | 1212 EXPECT_CALL(client_, IsSavingAndFillingEnabledForCurrentPage()) |
1213 .WillRepeatedly(Return(true)); | 1213 .WillRepeatedly(Return(true)); |
1214 manager()->SetHasGeneratedPasswordForForm(&driver_, form, true); | 1214 manager()->SetHasGeneratedPasswordForForm(&driver_, form, true); |
1215 | 1215 |
1216 // Simulate user removing generated password and adding a new one. | 1216 // Simulate user removing generated password and adding a new one. |
1217 form.new_password_value = ASCIIToUTF16("different_password"); | 1217 form.new_password_value = ASCIIToUTF16("different_password"); |
1218 manager()->SetHasGeneratedPasswordForForm(&driver_, form, false); | 1218 manager()->SetHasGeneratedPasswordForForm(&driver_, form, false); |
(...skipping 11 matching lines...) Expand all Loading... |
1230 // Simulate a successful submission. | 1230 // Simulate a successful submission. |
1231 observed.clear(); | 1231 observed.clear(); |
1232 manager()->OnPasswordFormsParsed(&driver_, observed); | 1232 manager()->OnPasswordFormsParsed(&driver_, observed); |
1233 manager()->OnPasswordFormsRendered(&driver_, observed, true); | 1233 manager()->OnPasswordFormsRendered(&driver_, observed, true); |
1234 } | 1234 } |
1235 | 1235 |
1236 TEST_F(PasswordManagerTest, PasswordGenerationUsernameChanged) { | 1236 TEST_F(PasswordManagerTest, PasswordGenerationUsernameChanged) { |
1237 std::vector<PasswordForm> observed; | 1237 std::vector<PasswordForm> observed; |
1238 PasswordForm form(MakeFormWithOnlyNewPasswordField()); | 1238 PasswordForm form(MakeFormWithOnlyNewPasswordField()); |
1239 observed.push_back(form); | 1239 observed.push_back(form); |
1240 EXPECT_CALL(*store_, GetLogins(_, _, _)) | 1240 EXPECT_CALL(*store_, GetLogins(_, _)) |
1241 .WillRepeatedly(WithArg<2>(InvokeEmptyConsumerWithForms())); | 1241 .WillRepeatedly(WithArg<1>(InvokeEmptyConsumerWithForms())); |
1242 manager()->OnPasswordFormsParsed(&driver_, observed); | 1242 manager()->OnPasswordFormsParsed(&driver_, observed); |
1243 manager()->OnPasswordFormsRendered(&driver_, observed, true); | 1243 manager()->OnPasswordFormsRendered(&driver_, observed, true); |
1244 | 1244 |
1245 EXPECT_CALL(client_, IsSavingAndFillingEnabledForCurrentPage()) | 1245 EXPECT_CALL(client_, IsSavingAndFillingEnabledForCurrentPage()) |
1246 .WillRepeatedly(Return(true)); | 1246 .WillRepeatedly(Return(true)); |
1247 manager()->SetHasGeneratedPasswordForForm(&driver_, form, true); | 1247 manager()->SetHasGeneratedPasswordForForm(&driver_, form, true); |
1248 | 1248 |
1249 // Simulate user changing the password and username, without ever completely | 1249 // Simulate user changing the password and username, without ever completely |
1250 // deleting the password. | 1250 // deleting the password. |
1251 form.new_password_value = ASCIIToUTF16("different_password"); | 1251 form.new_password_value = ASCIIToUTF16("different_password"); |
(...skipping 18 matching lines...) Expand all Loading... |
1270 // Add the enable-password-force-saving feature. | 1270 // Add the enable-password-force-saving feature. |
1271 base::FeatureList::ClearInstanceForTesting(); | 1271 base::FeatureList::ClearInstanceForTesting(); |
1272 scoped_ptr<base::FeatureList> feature_list(new base::FeatureList); | 1272 scoped_ptr<base::FeatureList> feature_list(new base::FeatureList); |
1273 feature_list->InitializeFromCommandLine( | 1273 feature_list->InitializeFromCommandLine( |
1274 password_manager::features::kEnablePasswordForceSaving.name, ""); | 1274 password_manager::features::kEnablePasswordForceSaving.name, ""); |
1275 base::FeatureList::SetInstance(std::move(feature_list)); | 1275 base::FeatureList::SetInstance(std::move(feature_list)); |
1276 PasswordForm form(MakeSimpleForm()); | 1276 PasswordForm form(MakeSimpleForm()); |
1277 | 1277 |
1278 std::vector<PasswordForm> observed; | 1278 std::vector<PasswordForm> observed; |
1279 observed.push_back(form); | 1279 observed.push_back(form); |
1280 EXPECT_CALL(*store_, GetLogins(_, _, _)) | 1280 EXPECT_CALL(*store_, GetLogins(_, _)) |
1281 .WillRepeatedly(WithArg<2>(InvokeEmptyConsumerWithForms())); | 1281 .WillRepeatedly(WithArg<1>(InvokeEmptyConsumerWithForms())); |
1282 manager()->OnPasswordFormsParsed(&driver_, observed); | 1282 manager()->OnPasswordFormsParsed(&driver_, observed); |
1283 manager()->OnPasswordFormsRendered(&driver_, observed, true); | 1283 manager()->OnPasswordFormsRendered(&driver_, observed, true); |
1284 | 1284 |
1285 scoped_ptr<PasswordFormManager> form_manager_to_save; | 1285 scoped_ptr<PasswordFormManager> form_manager_to_save; |
1286 EXPECT_CALL(client_, IsSavingAndFillingEnabledForCurrentPage()) | 1286 EXPECT_CALL(client_, IsSavingAndFillingEnabledForCurrentPage()) |
1287 .WillRepeatedly(Return(true)); | 1287 .WillRepeatedly(Return(true)); |
1288 EXPECT_CALL(client_, | 1288 EXPECT_CALL(client_, |
1289 PromptUserToSaveOrUpdatePasswordPtr( | 1289 PromptUserToSaveOrUpdatePasswordPtr( |
1290 _, CredentialSourceType::CREDENTIAL_SOURCE_PASSWORD_MANAGER)) | 1290 _, CredentialSourceType::CREDENTIAL_SOURCE_PASSWORD_MANAGER)) |
1291 .WillOnce(WithArg<0>(SaveToScopedPtr(&form_manager_to_save))); | 1291 .WillOnce(WithArg<0>(SaveToScopedPtr(&form_manager_to_save))); |
1292 manager()->OnPasswordFormForceSaveRequested(&driver_, form); | 1292 manager()->OnPasswordFormForceSaveRequested(&driver_, form); |
1293 ASSERT_TRUE(form_manager_to_save); | 1293 ASSERT_TRUE(form_manager_to_save); |
1294 EXPECT_EQ(form.password_value, | 1294 EXPECT_EQ(form.password_value, |
1295 PasswordFormManager::PasswordToSave( | 1295 PasswordFormManager::PasswordToSave( |
1296 form_manager_to_save->pending_credentials())); | 1296 form_manager_to_save->pending_credentials())); |
1297 } | 1297 } |
1298 | 1298 |
1299 // Forcing Chrome to save an empty passwords should fail without a crash. | 1299 // Forcing Chrome to save an empty passwords should fail without a crash. |
1300 TEST_F(PasswordManagerTest, ForceSavingPasswords_Empty) { | 1300 TEST_F(PasswordManagerTest, ForceSavingPasswords_Empty) { |
1301 // Add the enable-password-force-saving feature. | 1301 // Add the enable-password-force-saving feature. |
1302 base::FeatureList::ClearInstanceForTesting(); | 1302 base::FeatureList::ClearInstanceForTesting(); |
1303 scoped_ptr<base::FeatureList> feature_list(new base::FeatureList); | 1303 scoped_ptr<base::FeatureList> feature_list(new base::FeatureList); |
1304 feature_list->InitializeFromCommandLine( | 1304 feature_list->InitializeFromCommandLine( |
1305 password_manager::features::kEnablePasswordForceSaving.name, ""); | 1305 password_manager::features::kEnablePasswordForceSaving.name, ""); |
1306 base::FeatureList::SetInstance(std::move(feature_list)); | 1306 base::FeatureList::SetInstance(std::move(feature_list)); |
1307 PasswordForm empty_password_form; | 1307 PasswordForm empty_password_form; |
1308 | 1308 |
1309 std::vector<PasswordForm> observed; | 1309 std::vector<PasswordForm> observed; |
1310 observed.push_back(empty_password_form); | 1310 observed.push_back(empty_password_form); |
1311 EXPECT_CALL(*store_, GetLogins(_, _, _)) | 1311 EXPECT_CALL(*store_, GetLogins(_, _)) |
1312 .WillRepeatedly(WithArg<2>(InvokeEmptyConsumerWithForms())); | 1312 .WillRepeatedly(WithArg<1>(InvokeEmptyConsumerWithForms())); |
1313 manager()->OnPasswordFormsParsed(&driver_, observed); | 1313 manager()->OnPasswordFormsParsed(&driver_, observed); |
1314 manager()->OnPasswordFormsRendered(&driver_, observed, true); | 1314 manager()->OnPasswordFormsRendered(&driver_, observed, true); |
1315 | 1315 |
1316 EXPECT_CALL(client_, IsSavingAndFillingEnabledForCurrentPage()) | 1316 EXPECT_CALL(client_, IsSavingAndFillingEnabledForCurrentPage()) |
1317 .WillRepeatedly(Return(true)); | 1317 .WillRepeatedly(Return(true)); |
1318 EXPECT_CALL(client_, PromptUserToSaveOrUpdatePasswordPtr(_, _)).Times(0); | 1318 EXPECT_CALL(client_, PromptUserToSaveOrUpdatePasswordPtr(_, _)).Times(0); |
1319 manager()->OnPasswordFormForceSaveRequested(&driver_, empty_password_form); | 1319 manager()->OnPasswordFormForceSaveRequested(&driver_, empty_password_form); |
1320 } | 1320 } |
1321 | 1321 |
1322 TEST_F(PasswordManagerTest, UpdateFormManagers) { | 1322 TEST_F(PasswordManagerTest, UpdateFormManagers) { |
1323 // Seeing some forms should result in creating PasswordFormManagers and | 1323 // Seeing some forms should result in creating PasswordFormManagers and |
1324 // querying PasswordStore. Calling UpdateFormManagers should result in | 1324 // querying PasswordStore. Calling UpdateFormManagers should result in |
1325 // querying the store again. | 1325 // querying the store again. |
1326 PasswordStoreConsumer* consumer = nullptr; | 1326 PasswordStoreConsumer* consumer = nullptr; |
1327 EXPECT_CALL(*store_, GetLogins(_, _, _)).WillOnce(SaveArg<2>(&consumer)); | 1327 EXPECT_CALL(*store_, GetLogins(_, _)).WillOnce(SaveArg<1>(&consumer)); |
1328 | 1328 |
1329 PasswordForm form; | 1329 PasswordForm form; |
1330 std::vector<PasswordForm> observed; | 1330 std::vector<PasswordForm> observed; |
1331 observed.push_back(form); | 1331 observed.push_back(form); |
1332 manager()->OnPasswordFormsParsed(&driver_, observed); | 1332 manager()->OnPasswordFormsParsed(&driver_, observed); |
1333 | 1333 |
1334 // The first GetLogins should have fired, but to unblock the second, we need | 1334 // The first GetLogins should have fired, but to unblock the second, we need |
1335 // to first send a response from the store (to be ignored). | 1335 // to first send a response from the store (to be ignored). |
1336 ASSERT_TRUE(consumer); | 1336 ASSERT_TRUE(consumer); |
1337 consumer->OnGetPasswordStoreResults(ScopedVector<PasswordForm>()); | 1337 consumer->OnGetPasswordStoreResults(ScopedVector<PasswordForm>()); |
1338 EXPECT_CALL(*store_, GetLogins(_, _, _)); | 1338 EXPECT_CALL(*store_, GetLogins(_, _)); |
1339 manager()->UpdateFormManagers(); | 1339 manager()->UpdateFormManagers(); |
1340 } | 1340 } |
1341 | 1341 |
1342 TEST_F(PasswordManagerTest, AutofillingOfAffiliatedCredentials) { | 1342 TEST_F(PasswordManagerTest, AutofillingOfAffiliatedCredentials) { |
1343 PasswordForm android_form(MakeAndroidCredential()); | 1343 PasswordForm android_form(MakeAndroidCredential()); |
1344 PasswordForm observed_form(MakeSimpleForm()); | 1344 PasswordForm observed_form(MakeSimpleForm()); |
1345 std::vector<PasswordForm> observed_forms; | 1345 std::vector<PasswordForm> observed_forms; |
1346 observed_forms.push_back(observed_form); | 1346 observed_forms.push_back(observed_form); |
1347 | 1347 |
1348 autofill::PasswordFormFillData form_data; | 1348 autofill::PasswordFormFillData form_data; |
1349 EXPECT_CALL(driver_, FillPasswordForm(_)).WillOnce(SaveArg<0>(&form_data)); | 1349 EXPECT_CALL(driver_, FillPasswordForm(_)).WillOnce(SaveArg<0>(&form_data)); |
1350 EXPECT_CALL(*store_, GetLogins(_, _, _)) | 1350 EXPECT_CALL(*store_, GetLogins(_, _)) |
1351 .WillOnce(WithArg<2>(InvokeConsumer(android_form))); | 1351 .WillOnce(WithArg<1>(InvokeConsumer(android_form))); |
1352 manager()->OnPasswordFormsParsed(&driver_, observed_forms); | 1352 manager()->OnPasswordFormsParsed(&driver_, observed_forms); |
1353 observed_forms.clear(); | 1353 observed_forms.clear(); |
1354 manager()->OnPasswordFormsRendered(&driver_, observed_forms, true); | 1354 manager()->OnPasswordFormsRendered(&driver_, observed_forms, true); |
1355 | 1355 |
1356 EXPECT_EQ(android_form.username_value, form_data.username_field.value); | 1356 EXPECT_EQ(android_form.username_value, form_data.username_field.value); |
1357 EXPECT_EQ(android_form.password_value, form_data.password_field.value); | 1357 EXPECT_EQ(android_form.password_value, form_data.password_field.value); |
1358 EXPECT_FALSE(form_data.wait_for_username); | 1358 EXPECT_FALSE(form_data.wait_for_username); |
1359 EXPECT_EQ(android_form.signon_realm, form_data.preferred_realm); | 1359 EXPECT_EQ(android_form.signon_realm, form_data.preferred_realm); |
1360 | 1360 |
1361 EXPECT_CALL(client_, IsSavingAndFillingEnabledForCurrentPage()) | 1361 EXPECT_CALL(client_, IsSavingAndFillingEnabledForCurrentPage()) |
(...skipping 24 matching lines...) Expand all Loading... |
1386 // application, and the user overwrites the password, they should be prompted if | 1386 // application, and the user overwrites the password, they should be prompted if |
1387 // they want to update. If so, the Android credential itself should be updated. | 1387 // they want to update. If so, the Android credential itself should be updated. |
1388 TEST_F(PasswordManagerTest, UpdatePasswordOfAffiliatedCredential) { | 1388 TEST_F(PasswordManagerTest, UpdatePasswordOfAffiliatedCredential) { |
1389 PasswordForm android_form(MakeAndroidCredential()); | 1389 PasswordForm android_form(MakeAndroidCredential()); |
1390 PasswordForm observed_form(MakeSimpleForm()); | 1390 PasswordForm observed_form(MakeSimpleForm()); |
1391 std::vector<PasswordForm> observed_forms; | 1391 std::vector<PasswordForm> observed_forms; |
1392 observed_forms.push_back(observed_form); | 1392 observed_forms.push_back(observed_form); |
1393 | 1393 |
1394 autofill::PasswordFormFillData form_data; | 1394 autofill::PasswordFormFillData form_data; |
1395 EXPECT_CALL(driver_, FillPasswordForm(_)).WillOnce(SaveArg<0>(&form_data)); | 1395 EXPECT_CALL(driver_, FillPasswordForm(_)).WillOnce(SaveArg<0>(&form_data)); |
1396 EXPECT_CALL(*store_, GetLogins(_, _, _)) | 1396 EXPECT_CALL(*store_, GetLogins(_, _)) |
1397 .WillOnce(WithArg<2>(InvokeConsumer(android_form))); | 1397 .WillOnce(WithArg<1>(InvokeConsumer(android_form))); |
1398 manager()->OnPasswordFormsParsed(&driver_, observed_forms); | 1398 manager()->OnPasswordFormsParsed(&driver_, observed_forms); |
1399 observed_forms.clear(); | 1399 observed_forms.clear(); |
1400 manager()->OnPasswordFormsRendered(&driver_, observed_forms, true); | 1400 manager()->OnPasswordFormsRendered(&driver_, observed_forms, true); |
1401 | 1401 |
1402 EXPECT_CALL(client_, IsSavingAndFillingEnabledForCurrentPage()) | 1402 EXPECT_CALL(client_, IsSavingAndFillingEnabledForCurrentPage()) |
1403 .WillRepeatedly(Return(true)); | 1403 .WillRepeatedly(Return(true)); |
1404 | 1404 |
1405 PasswordForm filled_form(observed_form); | 1405 PasswordForm filled_form(observed_form); |
1406 filled_form.username_value = android_form.username_value; | 1406 filled_form.username_value = android_form.username_value; |
1407 filled_form.password_value = ASCIIToUTF16("new_password"); | 1407 filled_form.password_value = ASCIIToUTF16("new_password"); |
(...skipping 15 matching lines...) Expand all Loading... |
1423 EXPECT_CALL(*store_, UpdateLogin(_)).WillOnce(SaveArg<0>(&saved_form)); | 1423 EXPECT_CALL(*store_, UpdateLogin(_)).WillOnce(SaveArg<0>(&saved_form)); |
1424 ASSERT_TRUE(form_manager_to_save); | 1424 ASSERT_TRUE(form_manager_to_save); |
1425 form_manager_to_save->Save(); | 1425 form_manager_to_save->Save(); |
1426 | 1426 |
1427 PasswordForm expected_form(android_form); | 1427 PasswordForm expected_form(android_form); |
1428 expected_form.password_value = filled_form.password_value; | 1428 expected_form.password_value = filled_form.password_value; |
1429 EXPECT_THAT(saved_form, FormMatches(expected_form)); | 1429 EXPECT_THAT(saved_form, FormMatches(expected_form)); |
1430 } | 1430 } |
1431 | 1431 |
1432 } // namespace password_manager | 1432 } // namespace password_manager |
OLD | NEW |