Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(106)

Side by Side Diff: components/password_manager/core/browser/password_manager_unittest.cc

Issue 2900693002: [Password Manager] Convert |pending_login_managers_| to an array of scoped_refptr (Closed)
Patch Set: Rebase Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
54 MockPasswordManagerClient() { 54 MockPasswordManagerClient() {
55 EXPECT_CALL(*this, GetStoreResultFilter()) 55 EXPECT_CALL(*this, GetStoreResultFilter())
56 .Times(AnyNumber()) 56 .Times(AnyNumber())
57 .WillRepeatedly(Return(&filter_)); 57 .WillRepeatedly(Return(&filter_));
58 ON_CALL(filter_, ShouldSave(_)).WillByDefault(Return(true)); 58 ON_CALL(filter_, ShouldSave(_)).WillByDefault(Return(true));
59 } 59 }
60 60
61 MOCK_CONST_METHOD0(IsSavingAndFillingEnabledForCurrentPage, bool()); 61 MOCK_CONST_METHOD0(IsSavingAndFillingEnabledForCurrentPage, bool());
62 MOCK_CONST_METHOD0(DidLastPageLoadEncounterSSLErrors, bool()); 62 MOCK_CONST_METHOD0(DidLastPageLoadEncounterSSLErrors, bool());
63 MOCK_CONST_METHOD0(GetPasswordStore, PasswordStore*()); 63 MOCK_CONST_METHOD0(GetPasswordStore, PasswordStore*());
64 // The code inside EXPECT_CALL for PromptUserToSaveOrUpdatePasswordPtr owns 64 MOCK_METHOD2(PromptUserToSaveOrUpdatePassword,
65 // the PasswordFormManager* argument. 65 bool(scoped_refptr<PasswordFormManager>, bool));
66 MOCK_METHOD1(PromptUserToSaveOrUpdatePasswordPtr, void(PasswordFormManager*));
67 MOCK_METHOD1(NotifySuccessfulLoginWithExistingPassword, 66 MOCK_METHOD1(NotifySuccessfulLoginWithExistingPassword,
68 void(const autofill::PasswordForm&)); 67 void(const autofill::PasswordForm&));
69 MOCK_METHOD0(AutomaticPasswordSaveIndicator, void()); 68 MOCK_METHOD0(AutomaticPasswordSaveIndicator, void());
70 MOCK_METHOD0(GetPrefs, PrefService*()); 69 MOCK_METHOD0(GetPrefs, PrefService*());
71 MOCK_CONST_METHOD0(GetMainFrameURL, const GURL&()); 70 MOCK_CONST_METHOD0(GetMainFrameURL, const GURL&());
72 MOCK_METHOD0(GetDriver, PasswordManagerDriver*()); 71 MOCK_METHOD0(GetDriver, PasswordManagerDriver*());
73 MOCK_CONST_METHOD0(GetStoreResultFilter, const MockStoreResultFilter*()); 72 MOCK_CONST_METHOD0(GetStoreResultFilter, const MockStoreResultFilter*());
74 73
75 // Workaround for std::unique_ptr<> lacking a copy constructor.
76 bool PromptUserToSaveOrUpdatePassword(
77 std::unique_ptr<PasswordFormManager> manager,
78 bool update_password) override {
79 PromptUserToSaveOrUpdatePasswordPtr(manager.release());
80 return false;
81 }
82 void AutomaticPasswordSave( 74 void AutomaticPasswordSave(
83 std::unique_ptr<PasswordFormManager> manager) override { 75 scoped_refptr<PasswordFormManager> manager) override {
84 AutomaticPasswordSaveIndicator(); 76 AutomaticPasswordSaveIndicator();
85 } 77 }
86 78
87 void FilterAllResultsForSaving() { 79 void FilterAllResultsForSaving() {
88 EXPECT_CALL(filter_, ShouldSave(_)).WillRepeatedly(Return(false)); 80 EXPECT_CALL(filter_, ShouldSave(_)).WillRepeatedly(Return(false));
89 } 81 }
90 82
91 private: 83 private:
92 testing::NiceMock<MockStoreResultFilter> filter_; 84 testing::NiceMock<MockStoreResultFilter> filter_;
93 }; 85 };
94 86
95 class MockPasswordManagerDriver : public StubPasswordManagerDriver { 87 class MockPasswordManagerDriver : public StubPasswordManagerDriver {
96 public: 88 public:
97 MOCK_METHOD1(FillPasswordForm, void(const autofill::PasswordFormFillData&)); 89 MOCK_METHOD1(FillPasswordForm, void(const autofill::PasswordFormFillData&));
98 MOCK_METHOD0(GetPasswordManager, PasswordManager*()); 90 MOCK_METHOD0(GetPasswordManager, PasswordManager*());
99 MOCK_METHOD0(GetPasswordAutofillManager, PasswordAutofillManager*()); 91 MOCK_METHOD0(GetPasswordAutofillManager, PasswordAutofillManager*());
100 }; 92 };
101 93
102 // Invokes the password store consumer with a single copy of |form|. 94 // Invokes the password store consumer with a single copy of |form|.
103 ACTION_P(InvokeConsumer, form) { 95 ACTION_P(InvokeConsumer, form) {
104 std::vector<std::unique_ptr<PasswordForm>> result; 96 std::vector<std::unique_ptr<PasswordForm>> result;
105 result.push_back(base::MakeUnique<PasswordForm>(form)); 97 result.push_back(base::MakeUnique<PasswordForm>(form));
106 arg0->OnGetPasswordStoreResults(std::move(result)); 98 arg0->OnGetPasswordStoreResults(std::move(result));
107 } 99 }
108 100
109 ACTION(InvokeEmptyConsumerWithForms) { 101 ACTION(InvokeEmptyConsumerWithForms) {
110 arg0->OnGetPasswordStoreResults(std::vector<std::unique_ptr<PasswordForm>>()); 102 arg0->OnGetPasswordStoreResults(std::vector<std::unique_ptr<PasswordForm>>());
111 } 103 }
112 104
113 ACTION_P(SaveToScopedPtr, scoped) { scoped->reset(arg0); }
114
115 } // namespace 105 } // namespace
116 106
117 class PasswordManagerTest : public testing::Test { 107 class PasswordManagerTest : public testing::Test {
118 protected: 108 protected:
119 void SetUp() override { 109 void SetUp() override {
120 store_ = new testing::StrictMock<MockPasswordStore>; 110 store_ = new testing::StrictMock<MockPasswordStore>;
121 EXPECT_CALL(*store_, ReportMetrics(_, _)).Times(AnyNumber()); 111 EXPECT_CALL(*store_, ReportMetrics(_, _)).Times(AnyNumber());
122 EXPECT_CALL(*store_, GetLoginsForSameOrganizationName(_, _)) 112 EXPECT_CALL(*store_, GetLoginsForSameOrganizationName(_, _))
123 .Times(AnyNumber()); 113 .Times(AnyNumber());
124 CHECK(store_->Init(syncer::SyncableService::StartSyncFlare(), nullptr)); 114 CHECK(store_->Init(syncer::SyncableService::StartSyncFlare(), nullptr));
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
264 observed.push_back(form); 254 observed.push_back(form);
265 EXPECT_CALL(*store_, GetLogins(_, _)) 255 EXPECT_CALL(*store_, GetLogins(_, _))
266 .WillRepeatedly(WithArg<1>(InvokeEmptyConsumerWithForms())); 256 .WillRepeatedly(WithArg<1>(InvokeEmptyConsumerWithForms()));
267 manager()->OnPasswordFormsParsed(&driver_, observed); 257 manager()->OnPasswordFormsParsed(&driver_, observed);
268 manager()->OnPasswordFormsRendered(&driver_, observed, true); 258 manager()->OnPasswordFormsRendered(&driver_, observed, true);
269 259
270 EXPECT_CALL(client_, IsSavingAndFillingEnabledForCurrentPage()) 260 EXPECT_CALL(client_, IsSavingAndFillingEnabledForCurrentPage())
271 .WillRepeatedly(Return(true)); 261 .WillRepeatedly(Return(true));
272 OnPasswordFormSubmitted(form); 262 OnPasswordFormSubmitted(form);
273 263
274 std::unique_ptr<PasswordFormManager> form_manager_to_save; 264 scoped_refptr<PasswordFormManager> form_manager_to_save;
275 EXPECT_CALL(client_, PromptUserToSaveOrUpdatePasswordPtr(_)) 265 EXPECT_CALL(client_, PromptUserToSaveOrUpdatePassword(_, _))
276 .WillOnce(WithArg<0>(SaveToScopedPtr(&form_manager_to_save))); 266 .WillOnce(
267 DoAll(WithArg<0>(SaveArg<0>(&form_manager_to_save)), Return(false)));
vasilii 2017/05/29 13:15:49 No need for WithArg<0>. Maybe it will work without
kolos1 2017/05/29 15:47:06 WithArg is not needed, but w/o "Return(false)" the
277 268
278 // Now the password manager waits for the navigation to complete. 269 // Now the password manager waits for the navigation to complete.
279 observed.clear(); 270 observed.clear();
280 manager()->OnPasswordFormsParsed(&driver_, observed); 271 manager()->OnPasswordFormsParsed(&driver_, observed);
281 manager()->OnPasswordFormsRendered(&driver_, observed, true); 272 manager()->OnPasswordFormsRendered(&driver_, observed, true);
282 273
283 // Simulate saving the form, as if the info bar was accepted. 274 // Simulate saving the form, as if the info bar was accepted.
284 PasswordForm saved_form; 275 PasswordForm saved_form;
285 EXPECT_CALL(*store_, AddLogin(_)).WillOnce(SaveArg<0>(&saved_form)); 276 EXPECT_CALL(*store_, AddLogin(_)).WillOnce(SaveArg<0>(&saved_form));
286 ASSERT_TRUE(form_manager_to_save); 277 ASSERT_TRUE(form_manager_to_save);
(...skipping 19 matching lines...) Expand all
306 // Simulate the user generating the password and submitting the form. 297 // Simulate the user generating the password and submitting the form.
307 EXPECT_CALL(client_, IsSavingAndFillingEnabledForCurrentPage()) 298 EXPECT_CALL(client_, IsSavingAndFillingEnabledForCurrentPage())
308 .WillRepeatedly(Return(true)); 299 .WillRepeatedly(Return(true));
309 manager()->SetHasGeneratedPasswordForForm(&driver_, form, true); 300 manager()->SetHasGeneratedPasswordForForm(&driver_, form, true);
310 OnPasswordFormSubmitted(form); 301 OnPasswordFormSubmitted(form);
311 302
312 // The user should not need to confirm saving as they have already given 303 // The user should not need to confirm saving as they have already given
313 // consent by using the generated password. The form should be saved once 304 // consent by using the generated password. The form should be saved once
314 // navigation occurs. The client will be informed that automatic saving has 305 // navigation occurs. The client will be informed that automatic saving has
315 // occured. 306 // occured.
316 EXPECT_CALL(client_, PromptUserToSaveOrUpdatePasswordPtr(_)).Times(0); 307 EXPECT_CALL(client_, PromptUserToSaveOrUpdatePassword(_, _)).Times(0);
317 PasswordForm form_to_save; 308 PasswordForm form_to_save;
318 EXPECT_CALL(*store_, AddLogin(_)).WillOnce(SaveArg<0>(&form_to_save)); 309 EXPECT_CALL(*store_, AddLogin(_)).WillOnce(SaveArg<0>(&form_to_save));
319 EXPECT_CALL(client_, AutomaticPasswordSaveIndicator()); 310 EXPECT_CALL(client_, AutomaticPasswordSaveIndicator());
320 311
321 // Now the password manager waits for the navigation to complete. 312 // Now the password manager waits for the navigation to complete.
322 observed.clear(); 313 observed.clear();
323 manager()->OnPasswordFormsParsed(&driver_, observed); 314 manager()->OnPasswordFormsParsed(&driver_, observed);
324 manager()->OnPasswordFormsRendered(&driver_, observed, true); 315 manager()->OnPasswordFormsRendered(&driver_, observed, true);
325 EXPECT_EQ(form.username_value, form_to_save.username_value); 316 EXPECT_EQ(form.username_value, form_to_save.username_value);
326 // What was "new password" field in the submitted form, becomes the current 317 // What was "new password" field in the submitted form, becomes the current
(...skipping 15 matching lines...) Expand all
342 EXPECT_CALL(driver_, FillPasswordForm(_)).Times(2); 333 EXPECT_CALL(driver_, FillPasswordForm(_)).Times(2);
343 EXPECT_CALL(*store_, GetLogins(_, _)) 334 EXPECT_CALL(*store_, GetLogins(_, _))
344 .WillOnce(WithArg<1>(InvokeConsumer(existing_different))); 335 .WillOnce(WithArg<1>(InvokeConsumer(existing_different)));
345 manager()->OnPasswordFormsParsed(&driver_, observed); 336 manager()->OnPasswordFormsParsed(&driver_, observed);
346 manager()->OnPasswordFormsRendered(&driver_, observed, true); 337 manager()->OnPasswordFormsRendered(&driver_, observed, true);
347 EXPECT_CALL(client_, IsSavingAndFillingEnabledForCurrentPage()) 338 EXPECT_CALL(client_, IsSavingAndFillingEnabledForCurrentPage())
348 .WillRepeatedly(Return(true)); 339 .WillRepeatedly(Return(true));
349 OnPasswordFormSubmitted(form); 340 OnPasswordFormSubmitted(form);
350 341
351 // We still expect an add, since we didn't have a good match. 342 // We still expect an add, since we didn't have a good match.
352 std::unique_ptr<PasswordFormManager> form_manager_to_save; 343 scoped_refptr<PasswordFormManager> form_manager_to_save;
353 EXPECT_CALL(client_, PromptUserToSaveOrUpdatePasswordPtr(_)) 344 EXPECT_CALL(client_, PromptUserToSaveOrUpdatePassword(_, _))
354 .WillOnce(WithArg<0>(SaveToScopedPtr(&form_manager_to_save))); 345 .WillOnce(
346 DoAll(WithArg<0>(SaveArg<0>(&form_manager_to_save)), Return(false)));
355 347
356 // Now the password manager waits for the navigation to complete. 348 // Now the password manager waits for the navigation to complete.
357 observed.clear(); 349 observed.clear();
358 manager()->OnPasswordFormsParsed(&driver_, observed); 350 manager()->OnPasswordFormsParsed(&driver_, observed);
359 manager()->OnPasswordFormsRendered(&driver_, observed, true); 351 manager()->OnPasswordFormsRendered(&driver_, observed, true);
360 352
361 // Simulate saving the form. 353 // Simulate saving the form.
362 EXPECT_CALL(*store_, AddLogin(FormMatches(form))); 354 EXPECT_CALL(*store_, AddLogin(FormMatches(form)));
363 ASSERT_TRUE(form_manager_to_save); 355 ASSERT_TRUE(form_manager_to_save);
364 form_manager_to_save->Save(); 356 form_manager_to_save->Save();
365 } 357 }
366 358
367 TEST_F(PasswordManagerTest, FormSeenThenLeftPage) { 359 TEST_F(PasswordManagerTest, FormSeenThenLeftPage) {
368 std::vector<PasswordForm> observed; 360 std::vector<PasswordForm> observed;
369 PasswordForm form(MakeSimpleForm()); 361 PasswordForm form(MakeSimpleForm());
370 observed.push_back(form); 362 observed.push_back(form);
371 EXPECT_CALL(*store_, GetLogins(_, _)) 363 EXPECT_CALL(*store_, GetLogins(_, _))
372 .WillRepeatedly(WithArg<1>(InvokeEmptyConsumerWithForms())); 364 .WillRepeatedly(WithArg<1>(InvokeEmptyConsumerWithForms()));
373 manager()->OnPasswordFormsParsed(&driver_, observed); 365 manager()->OnPasswordFormsParsed(&driver_, observed);
374 manager()->OnPasswordFormsRendered(&driver_, observed, true); 366 manager()->OnPasswordFormsRendered(&driver_, observed, true);
375 367
376 // No message from the renderer that a password was submitted. No 368 // No message from the renderer that a password was submitted. No
377 // expected calls. 369 // expected calls.
378 EXPECT_CALL(client_, PromptUserToSaveOrUpdatePasswordPtr(_)).Times(0); 370 EXPECT_CALL(client_, PromptUserToSaveOrUpdatePassword(_, _)).Times(0);
379 observed.clear(); 371 observed.clear();
380 manager()->OnPasswordFormsParsed(&driver_, observed); 372 manager()->OnPasswordFormsParsed(&driver_, observed);
381 manager()->OnPasswordFormsRendered(&driver_, observed, true); 373 manager()->OnPasswordFormsRendered(&driver_, observed, true);
382 } 374 }
383 375
384 TEST_F(PasswordManagerTest, FormSubmit) { 376 TEST_F(PasswordManagerTest, FormSubmit) {
385 // Test that a plain form submit results in offering to save passwords. 377 // Test that a plain form submit results in offering to save passwords.
386 std::vector<PasswordForm> observed; 378 std::vector<PasswordForm> observed;
387 PasswordForm form(MakeSimpleForm()); 379 PasswordForm form(MakeSimpleForm());
388 observed.push_back(form); 380 observed.push_back(form);
389 EXPECT_CALL(*store_, GetLogins(_, _)) 381 EXPECT_CALL(*store_, GetLogins(_, _))
390 .WillRepeatedly(WithArg<1>(InvokeEmptyConsumerWithForms())); 382 .WillRepeatedly(WithArg<1>(InvokeEmptyConsumerWithForms()));
391 EXPECT_FALSE(manager()->IsPasswordFieldDetectedOnPage()); 383 EXPECT_FALSE(manager()->IsPasswordFieldDetectedOnPage());
392 manager()->OnPasswordFormsParsed(&driver_, observed); 384 manager()->OnPasswordFormsParsed(&driver_, observed);
393 EXPECT_TRUE(manager()->IsPasswordFieldDetectedOnPage()); 385 EXPECT_TRUE(manager()->IsPasswordFieldDetectedOnPage());
394 manager()->OnPasswordFormsRendered(&driver_, observed, true); 386 manager()->OnPasswordFormsRendered(&driver_, observed, true);
395 387
396 EXPECT_CALL(client_, IsSavingAndFillingEnabledForCurrentPage()) 388 EXPECT_CALL(client_, IsSavingAndFillingEnabledForCurrentPage())
397 .WillRepeatedly(Return(true)); 389 .WillRepeatedly(Return(true));
398 OnPasswordFormSubmitted(form); 390 OnPasswordFormSubmitted(form);
399 391
400 std::unique_ptr<PasswordFormManager> form_manager_to_save; 392 scoped_refptr<PasswordFormManager> form_manager_to_save;
401 EXPECT_CALL(client_, PromptUserToSaveOrUpdatePasswordPtr(_)) 393 EXPECT_CALL(client_, PromptUserToSaveOrUpdatePassword(_, _))
402 .WillOnce(WithArg<0>(SaveToScopedPtr(&form_manager_to_save))); 394 .WillOnce(
395 DoAll(WithArg<0>(SaveArg<0>(&form_manager_to_save)), Return(false)));
403 396
404 observed.clear(); 397 observed.clear();
405 manager()->OnPasswordFormsParsed(&driver_, observed); 398 manager()->OnPasswordFormsParsed(&driver_, observed);
406 manager()->OnPasswordFormsRendered(&driver_, observed, true); 399 manager()->OnPasswordFormsRendered(&driver_, observed, true);
407 EXPECT_FALSE(manager()->IsPasswordFieldDetectedOnPage()); 400 EXPECT_FALSE(manager()->IsPasswordFieldDetectedOnPage());
408 401
409 // Simulate saving the form, as if the info bar was accepted. 402 // Simulate saving the form, as if the info bar was accepted.
410 EXPECT_CALL(*store_, AddLogin(FormMatches(form))); 403 EXPECT_CALL(*store_, AddLogin(FormMatches(form)));
411 ASSERT_TRUE(form_manager_to_save); 404 ASSERT_TRUE(form_manager_to_save);
412 form_manager_to_save->Save(); 405 form_manager_to_save->Save();
(...skipping 26 matching lines...) Expand all
439 // URL. 432 // URL.
440 observed.push_back(second_form); 433 observed.push_back(second_form);
441 manager()->OnPasswordFormsParsed(&driver_, observed); 434 manager()->OnPasswordFormsParsed(&driver_, observed);
442 manager()->OnPasswordFormsRendered(&driver_, observed, true); 435 manager()->OnPasswordFormsRendered(&driver_, observed, true);
443 436
444 // Now submit this form 437 // Now submit this form
445 EXPECT_CALL(client_, IsSavingAndFillingEnabledForCurrentPage()) 438 EXPECT_CALL(client_, IsSavingAndFillingEnabledForCurrentPage())
446 .WillRepeatedly(Return(true)); 439 .WillRepeatedly(Return(true));
447 OnPasswordFormSubmitted(second_form); 440 OnPasswordFormSubmitted(second_form);
448 441
449 std::unique_ptr<PasswordFormManager> form_manager_to_save; 442 scoped_refptr<PasswordFormManager> form_manager_to_save;
450 EXPECT_CALL(client_, PromptUserToSaveOrUpdatePasswordPtr(_)) 443 EXPECT_CALL(client_, PromptUserToSaveOrUpdatePassword(_, _))
451 .WillOnce(WithArg<0>(SaveToScopedPtr(&form_manager_to_save))); 444 .WillOnce(
445 DoAll(WithArg<0>(SaveArg<0>(&form_manager_to_save)), Return(false)));
452 // Navigation after form submit, no forms appear. 446 // Navigation after form submit, no forms appear.
453 observed.clear(); 447 observed.clear();
454 manager()->OnPasswordFormsParsed(&driver_, observed); 448 manager()->OnPasswordFormsParsed(&driver_, observed);
455 manager()->OnPasswordFormsRendered(&driver_, observed, true); 449 manager()->OnPasswordFormsRendered(&driver_, observed, true);
456 450
457 // Simulate saving the form, as if the info bar was accepted and make sure 451 // Simulate saving the form, as if the info bar was accepted and make sure
458 // that the saved form matches the second form, not the first. 452 // that the saved form matches the second form, not the first.
459 EXPECT_CALL(*store_, AddLogin(FormMatches(second_form))); 453 EXPECT_CALL(*store_, AddLogin(FormMatches(second_form)));
460 ASSERT_TRUE(form_manager_to_save); 454 ASSERT_TRUE(form_manager_to_save);
461 form_manager_to_save->Save(); 455 form_manager_to_save->Save();
462 } 456 }
463 457
464 TEST_F(PasswordManagerTest, FormSubmitInvisibleLogin) { 458 TEST_F(PasswordManagerTest, FormSubmitInvisibleLogin) {
465 // Tests fix of http://crbug.com/28911: if the login form reappears on the 459 // 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. 460 // subsequent page, but is invisible, it shouldn't count as a failed login.
467 std::vector<PasswordForm> observed; 461 std::vector<PasswordForm> observed;
468 PasswordForm form(MakeSimpleForm()); 462 PasswordForm form(MakeSimpleForm());
469 observed.push_back(form); 463 observed.push_back(form);
470 EXPECT_CALL(*store_, GetLogins(_, _)) 464 EXPECT_CALL(*store_, GetLogins(_, _))
471 .WillRepeatedly(WithArg<1>(InvokeEmptyConsumerWithForms())); 465 .WillRepeatedly(WithArg<1>(InvokeEmptyConsumerWithForms()));
472 manager()->OnPasswordFormsParsed(&driver_, observed); 466 manager()->OnPasswordFormsParsed(&driver_, observed);
473 manager()->OnPasswordFormsRendered(&driver_, observed, true); 467 manager()->OnPasswordFormsRendered(&driver_, observed, true);
474 468
475 EXPECT_CALL(client_, IsSavingAndFillingEnabledForCurrentPage()) 469 EXPECT_CALL(client_, IsSavingAndFillingEnabledForCurrentPage())
476 .WillRepeatedly(Return(true)); 470 .WillRepeatedly(Return(true));
477 OnPasswordFormSubmitted(form); 471 OnPasswordFormSubmitted(form);
478 472
479 // Expect info bar to appear: 473 // Expect info bar to appear:
480 std::unique_ptr<PasswordFormManager> form_manager_to_save; 474 scoped_refptr<PasswordFormManager> form_manager_to_save;
481 EXPECT_CALL(client_, PromptUserToSaveOrUpdatePasswordPtr(_)) 475 EXPECT_CALL(client_, PromptUserToSaveOrUpdatePassword(_, _))
482 .WillOnce(WithArg<0>(SaveToScopedPtr(&form_manager_to_save))); 476 .WillOnce(
477 DoAll(WithArg<0>(SaveArg<0>(&form_manager_to_save)), Return(false)));
483 478
484 // The form reappears, but is not visible in the layout: 479 // The form reappears, but is not visible in the layout:
485 manager()->OnPasswordFormsParsed(&driver_, observed); 480 manager()->OnPasswordFormsParsed(&driver_, observed);
486 observed.clear(); 481 observed.clear();
487 manager()->OnPasswordFormsRendered(&driver_, observed, true); 482 manager()->OnPasswordFormsRendered(&driver_, observed, true);
488 483
489 // Simulate saving the form. 484 // Simulate saving the form.
490 EXPECT_CALL(*store_, AddLogin(FormMatches(form))); 485 EXPECT_CALL(*store_, AddLogin(FormMatches(form)));
491 ASSERT_TRUE(form_manager_to_save); 486 ASSERT_TRUE(form_manager_to_save);
492 form_manager_to_save->Save(); 487 form_manager_to_save->Save();
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
544 manager()->OnPasswordFormsRendered(&driver_, observed, true); 539 manager()->OnPasswordFormsRendered(&driver_, observed, true);
545 540
546 EXPECT_CALL(client_, IsSavingAndFillingEnabledForCurrentPage()) 541 EXPECT_CALL(client_, IsSavingAndFillingEnabledForCurrentPage())
547 .WillRepeatedly(Return(true)); 542 .WillRepeatedly(Return(true));
548 OnPasswordFormSubmitted(login_form); 543 OnPasswordFormSubmitted(login_form);
549 544
550 observed.clear(); 545 observed.clear();
551 observed.push_back(MakeTwitterFailedLoginForm()); 546 observed.push_back(MakeTwitterFailedLoginForm());
552 // A PasswordForm appears, and is visible in the layout: 547 // A PasswordForm appears, and is visible in the layout:
553 // No expected calls to the PasswordStore... 548 // No expected calls to the PasswordStore...
554 EXPECT_CALL(client_, PromptUserToSaveOrUpdatePasswordPtr(_)).Times(0); 549 EXPECT_CALL(client_, PromptUserToSaveOrUpdatePassword(_, _)).Times(0);
555 EXPECT_CALL(client_, AutomaticPasswordSaveIndicator()).Times(0); 550 EXPECT_CALL(client_, AutomaticPasswordSaveIndicator()).Times(0);
556 EXPECT_CALL(*store_, AddLogin(_)).Times(0); 551 EXPECT_CALL(*store_, AddLogin(_)).Times(0);
557 EXPECT_CALL(*store_, UpdateLogin(_)).Times(0); 552 EXPECT_CALL(*store_, UpdateLogin(_)).Times(0);
558 EXPECT_CALL(*store_, UpdateLoginWithPrimaryKey(_, _)).Times(0); 553 EXPECT_CALL(*store_, UpdateLoginWithPrimaryKey(_, _)).Times(0);
559 manager()->OnPasswordFormsParsed(&driver_, observed); 554 manager()->OnPasswordFormsParsed(&driver_, observed);
560 manager()->OnPasswordFormsRendered(&driver_, observed, true); 555 manager()->OnPasswordFormsRendered(&driver_, observed, true);
561 } 556 }
562 557
563 TEST_F(PasswordManagerTest, SyncCredentialsNotSaved) { 558 TEST_F(PasswordManagerTest, SyncCredentialsNotSaved) {
564 // Simulate loading a simple form with no existing stored password. 559 // Simulate loading a simple form with no existing stored password.
565 std::vector<PasswordForm> observed; 560 std::vector<PasswordForm> observed;
566 PasswordForm form(MakeSimpleGAIAForm()); 561 PasswordForm form(MakeSimpleGAIAForm());
567 observed.push_back(form); 562 observed.push_back(form);
568 EXPECT_CALL(*store_, GetLogins(_, _)) 563 EXPECT_CALL(*store_, GetLogins(_, _))
569 .WillRepeatedly(WithArg<1>(InvokeEmptyConsumerWithForms())); 564 .WillRepeatedly(WithArg<1>(InvokeEmptyConsumerWithForms()));
570 manager()->OnPasswordFormsParsed(&driver_, observed); 565 manager()->OnPasswordFormsParsed(&driver_, observed);
571 manager()->OnPasswordFormsRendered(&driver_, observed, true); 566 manager()->OnPasswordFormsRendered(&driver_, observed, true);
572 567
573 // User should not be prompted and password should not be saved. 568 // User should not be prompted and password should not be saved.
574 EXPECT_CALL(client_, PromptUserToSaveOrUpdatePasswordPtr(_)).Times(0); 569 EXPECT_CALL(client_, PromptUserToSaveOrUpdatePassword(_, _)).Times(0);
575 EXPECT_CALL(*store_, AddLogin(_)).Times(0); 570 EXPECT_CALL(*store_, AddLogin(_)).Times(0);
576 // Prefs are needed for failure logging about sync credentials. 571 // Prefs are needed for failure logging about sync credentials.
577 EXPECT_CALL(client_, GetPrefs()).WillRepeatedly(Return(nullptr)); 572 EXPECT_CALL(client_, GetPrefs()).WillRepeatedly(Return(nullptr));
578 EXPECT_CALL(client_, IsSavingAndFillingEnabledForCurrentPage()) 573 EXPECT_CALL(client_, IsSavingAndFillingEnabledForCurrentPage())
579 .WillRepeatedly(Return(true)); 574 .WillRepeatedly(Return(true));
580 575
581 client_.FilterAllResultsForSaving(); 576 client_.FilterAllResultsForSaving();
582 577
583 OnPasswordFormSubmitted(form); 578 OnPasswordFormSubmitted(form);
584 observed.clear(); 579 observed.clear();
585 manager()->OnPasswordFormsParsed(&driver_, observed); 580 manager()->OnPasswordFormsParsed(&driver_, observed);
586 manager()->OnPasswordFormsRendered(&driver_, observed, true); 581 manager()->OnPasswordFormsRendered(&driver_, observed, true);
587 } 582 }
588 583
589 // On a successful login with an updated password, 584 // On a successful login with an updated password,
590 // CredentialsFilter::ReportFormLoginSuccess and CredentialsFilter::ShouldSave 585 // CredentialsFilter::ReportFormLoginSuccess and CredentialsFilter::ShouldSave
591 // should be called. The argument of ShouldSave shold be the submitted form. 586 // should be called. The argument of ShouldSave shold be the submitted form.
592 TEST_F(PasswordManagerTest, ReportFormLoginSuccessAndShouldSaveCalled) { 587 TEST_F(PasswordManagerTest, ReportFormLoginSuccessAndShouldSaveCalled) {
593 PasswordForm stored_form(MakeSimpleForm()); 588 PasswordForm stored_form(MakeSimpleForm());
594 589
595 std::vector<PasswordForm> observed; 590 std::vector<PasswordForm> observed;
596 PasswordForm observed_form = stored_form; 591 PasswordForm observed_form = stored_form;
597 // Different values of |username_element| needed to ensure that it is the 592 // Different values of |username_element| needed to ensure that it is the
598 // |observed_form| and not the |stored_form| what is passed to ShouldSave. 593 // |observed_form| and not the |stored_form| what is passed to ShouldSave.
599 observed_form.username_element += ASCIIToUTF16("1"); 594 observed_form.username_element += ASCIIToUTF16("1");
600 observed.push_back(observed_form); 595 observed.push_back(observed_form);
601 EXPECT_CALL(driver_, FillPasswordForm(_)).Times(2); 596 EXPECT_CALL(driver_, FillPasswordForm(_)).Times(3);
vasilii 2017/05/29 13:15:49 What has changed?
kolos1 2017/05/29 15:47:06 In |manager()->ProvisionallySavePassword(observed_
602 // Simulate that |form| is already in the store, making this an update. 597 // Simulate that |form| is already in the store, making this an update.
603 EXPECT_CALL(*store_, GetLogins(_, _)) 598 EXPECT_CALL(*store_, GetLogins(_, _))
604 .WillRepeatedly(WithArg<1>(InvokeConsumer(stored_form))); 599 .WillRepeatedly(WithArg<1>(InvokeConsumer(stored_form)));
605 manager()->OnPasswordFormsParsed(&driver_, observed); 600 manager()->OnPasswordFormsParsed(&driver_, observed);
606 manager()->OnPasswordFormsRendered(&driver_, observed, true); 601 manager()->OnPasswordFormsRendered(&driver_, observed, true);
607 602
608 // Submit form and finish navigation. 603 // Submit form and finish navigation.
609 EXPECT_CALL(client_, IsSavingAndFillingEnabledForCurrentPage()) 604 EXPECT_CALL(client_, IsSavingAndFillingEnabledForCurrentPage())
610 .WillRepeatedly(Return(true)); 605 .WillRepeatedly(Return(true));
611 EXPECT_CALL(client_, GetPrefs()).WillRepeatedly(Return(nullptr)); 606 EXPECT_CALL(client_, GetPrefs()).WillRepeatedly(Return(nullptr));
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
677 EXPECT_CALL(client_, IsSavingAndFillingEnabledForCurrentPage()) 672 EXPECT_CALL(client_, IsSavingAndFillingEnabledForCurrentPage())
678 .WillRepeatedly(Return(true)); 673 .WillRepeatedly(Return(true));
679 EXPECT_CALL(client_, GetPrefs()).WillRepeatedly(Return(nullptr)); 674 EXPECT_CALL(client_, GetPrefs()).WillRepeatedly(Return(nullptr));
680 manager()->ProvisionallySavePassword(updated_form, nullptr); 675 manager()->ProvisionallySavePassword(updated_form, nullptr);
681 676
682 client_.FilterAllResultsForSaving(); 677 client_.FilterAllResultsForSaving();
683 678
684 // Because the user successfully uses an updated sync password, Chrome should 679 // Because the user successfully uses an updated sync password, Chrome should
685 // remove the obsolete copy of it. 680 // remove the obsolete copy of it.
686 EXPECT_CALL(*store_, RemoveLogin(form)); 681 EXPECT_CALL(*store_, RemoveLogin(form));
687 EXPECT_CALL(client_, PromptUserToSaveOrUpdatePasswordPtr(_)).Times(0); 682 EXPECT_CALL(client_, PromptUserToSaveOrUpdatePassword(_, _)).Times(0);
688 observed.clear(); 683 observed.clear();
689 manager()->OnPasswordFormsParsed(&driver_, observed); 684 manager()->OnPasswordFormsParsed(&driver_, observed);
690 manager()->OnPasswordFormsRendered(&driver_, observed, true); 685 manager()->OnPasswordFormsRendered(&driver_, observed, true);
691 } 686 }
692 687
693 // While sync credentials are not saved, they are still filled to avoid users 688 // While sync credentials are not saved, they are still filled to avoid users
694 // thinking they lost access to their accounts. 689 // thinking they lost access to their accounts.
695 TEST_F(PasswordManagerTest, SyncCredentialsStillFilled) { 690 TEST_F(PasswordManagerTest, SyncCredentialsStillFilled) {
696 PasswordForm form(MakeSimpleForm()); 691 PasswordForm form(MakeSimpleForm());
697 // Pretend that the password store contains credentials stored for |form|. 692 // Pretend that the password store contains credentials stored for |form|.
(...skipping 16 matching lines...) Expand all
714 // considered equal to the original login form, and the attempt recognised as a 709 // considered equal to the original login form, and the attempt recognised as a
715 // failure. 710 // failure.
716 TEST_F(PasswordManagerTest, 711 TEST_F(PasswordManagerTest,
717 SeeingFormActionWithOnlyHttpHttpsChangeIsLoginFailure) { 712 SeeingFormActionWithOnlyHttpHttpsChangeIsLoginFailure) {
718 EXPECT_CALL(driver_, FillPasswordForm(_)).Times(0); 713 EXPECT_CALL(driver_, FillPasswordForm(_)).Times(0);
719 714
720 PasswordForm first_form(MakeSimpleForm()); 715 PasswordForm first_form(MakeSimpleForm());
721 first_form.origin = GURL("http://www.xda-developers.com/"); 716 first_form.origin = GURL("http://www.xda-developers.com/");
722 first_form.action = GURL("http://forum.xda-developers.com/login.php"); 717 first_form.action = GURL("http://forum.xda-developers.com/login.php");
723 718
724 // |second_form|'s action differs only with it's scheme i.e. *https://*. 719 // |second_form|'s action differs only with it's scheme i.e. "https://".
725 PasswordForm second_form(first_form); 720 PasswordForm second_form(first_form);
726 second_form.action = GURL("https://forum.xda-developers.com/login.php"); 721 second_form.action = GURL("https://forum.xda-developers.com/login.php");
727 722
728 std::vector<PasswordForm> observed; 723 std::vector<PasswordForm> observed;
729 observed.push_back(first_form); 724 observed.push_back(first_form);
730 EXPECT_CALL(*store_, GetLogins(_, _)) 725 EXPECT_CALL(*store_, GetLogins(_, _))
731 .WillRepeatedly(WithArg<1>(InvokeEmptyConsumerWithForms())); 726 .WillRepeatedly(WithArg<1>(InvokeEmptyConsumerWithForms()));
732 manager()->OnPasswordFormsParsed(&driver_, observed); 727 manager()->OnPasswordFormsParsed(&driver_, observed);
733 manager()->OnPasswordFormsRendered(&driver_, observed, true); 728 manager()->OnPasswordFormsRendered(&driver_, observed, true);
734 729
735 EXPECT_CALL(client_, IsSavingAndFillingEnabledForCurrentPage()) 730 EXPECT_CALL(client_, IsSavingAndFillingEnabledForCurrentPage())
736 .WillRepeatedly(Return(true)); 731 .WillRepeatedly(Return(true));
737 OnPasswordFormSubmitted(first_form); 732 OnPasswordFormSubmitted(first_form);
738 733
739 // Simulate loading a page, which contains |second_form| instead of 734 // Simulate loading a page, which contains |second_form| instead of
740 // |first_form|. 735 // |first_form|.
741 observed.clear(); 736 observed.clear();
742 observed.push_back(second_form); 737 observed.push_back(second_form);
743 738
744 // Verify that no prompt to save the password is shown. 739 // Verify that no prompt to save the password is shown.
745 EXPECT_CALL(client_, PromptUserToSaveOrUpdatePasswordPtr(_)).Times(0); 740 EXPECT_CALL(client_, PromptUserToSaveOrUpdatePassword(_, _)).Times(0);
746 manager()->OnPasswordFormsParsed(&driver_, observed); 741 manager()->OnPasswordFormsParsed(&driver_, observed);
747 manager()->OnPasswordFormsRendered(&driver_, observed, true); 742 manager()->OnPasswordFormsRendered(&driver_, observed, true);
748 } 743 }
749 744
750 TEST_F(PasswordManagerTest, 745 TEST_F(PasswordManagerTest,
751 ShouldBlockPasswordForSameOriginButDifferentSchemeTest) { 746 ShouldBlockPasswordForSameOriginButDifferentSchemeTest) {
752 constexpr struct { 747 constexpr struct {
753 const char* old_origin; 748 const char* old_origin;
754 const char* new_origin; 749 const char* new_origin;
755 bool result; 750 bool result;
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
807 .WillRepeatedly(ReturnRef(secure_form.origin)); 802 .WillRepeatedly(ReturnRef(secure_form.origin));
808 803
809 // Parse, render and submit the secure form. 804 // Parse, render and submit the secure form.
810 std::vector<PasswordForm> observed = {secure_form}; 805 std::vector<PasswordForm> observed = {secure_form};
811 manager()->OnPasswordFormsParsed(&driver_, observed); 806 manager()->OnPasswordFormsParsed(&driver_, observed);
812 manager()->OnPasswordFormsRendered(&driver_, observed, true); 807 manager()->OnPasswordFormsRendered(&driver_, observed, true);
813 OnPasswordFormSubmitted(secure_form); 808 OnPasswordFormSubmitted(secure_form);
814 809
815 // Make sure |PromptUserToSaveOrUpdatePassword| gets called, and the resulting 810 // Make sure |PromptUserToSaveOrUpdatePassword| gets called, and the resulting
816 // form manager is saved. 811 // form manager is saved.
817 std::unique_ptr<PasswordFormManager> form_manager_to_save; 812 scoped_refptr<PasswordFormManager> form_manager_to_save;
818 EXPECT_CALL(client_, PromptUserToSaveOrUpdatePasswordPtr(_)) 813 EXPECT_CALL(client_, PromptUserToSaveOrUpdatePassword(_, _))
819 .WillOnce(WithArg<0>(SaveToScopedPtr(&form_manager_to_save))); 814 .WillOnce(
815 DoAll(WithArg<0>(SaveArg<0>(&form_manager_to_save)), Return(false)));
820 816
821 EXPECT_CALL(client_, GetMainFrameURL()) 817 EXPECT_CALL(client_, GetMainFrameURL())
822 .WillRepeatedly(ReturnRef(insecure_form.origin)); 818 .WillRepeatedly(ReturnRef(insecure_form.origin));
823 819
824 // Parse, render and submit the insecure form. 820 // Parse, render and submit the insecure form.
825 observed = {insecure_form}; 821 observed = {insecure_form};
826 manager()->OnPasswordFormsParsed(&driver_, observed); 822 manager()->OnPasswordFormsParsed(&driver_, observed);
827 manager()->OnPasswordFormsRendered(&driver_, observed, true); 823 manager()->OnPasswordFormsRendered(&driver_, observed, true);
828 OnPasswordFormSubmitted(insecure_form); 824 OnPasswordFormSubmitted(insecure_form);
829 825
830 // Expect no further calls to |ProptUserToSaveOrUpdatePassword| due to 826 // Expect no further calls to |ProptUserToSaveOrUpdatePassword| due to
831 // insecure origin. 827 // insecure origin.
832 EXPECT_CALL(client_, PromptUserToSaveOrUpdatePasswordPtr(_)).Times(0); 828 EXPECT_CALL(client_, PromptUserToSaveOrUpdatePassword(_, _)).Times(0);
833 829
834 // Trigger call to |ProvisionalSavePassword| by rendering a page without 830 // Trigger call to |ProvisionalSavePassword| by rendering a page without
835 // forms. 831 // forms.
836 observed.clear(); 832 observed.clear();
837 manager()->OnPasswordFormsParsed(&driver_, observed); 833 manager()->OnPasswordFormsParsed(&driver_, observed);
838 manager()->OnPasswordFormsRendered(&driver_, observed, true); 834 manager()->OnPasswordFormsRendered(&driver_, observed, true);
839 835
840 // Make sure that the form saved by the user is indeed the secure form. 836 // Make sure that the form saved by the user is indeed the secure form.
841 ASSERT_TRUE(form_manager_to_save); 837 ASSERT_TRUE(form_manager_to_save);
842 EXPECT_THAT(form_manager_to_save->pending_credentials(), 838 EXPECT_THAT(form_manager_to_save->pending_credentials(),
(...skipping 15 matching lines...) Expand all
858 observed.push_back(form); 854 observed.push_back(form);
859 EXPECT_CALL(*store_, GetLogins(_, _)) 855 EXPECT_CALL(*store_, GetLogins(_, _))
860 .WillOnce(WithArg<1>(InvokeEmptyConsumerWithForms())); 856 .WillOnce(WithArg<1>(InvokeEmptyConsumerWithForms()));
861 manager()->OnPasswordFormsParsed(&driver_, observed); 857 manager()->OnPasswordFormsParsed(&driver_, observed);
862 manager()->OnPasswordFormsRendered(&driver_, observed, true); 858 manager()->OnPasswordFormsRendered(&driver_, observed, true);
863 859
864 EXPECT_CALL(client_, IsSavingAndFillingEnabledForCurrentPage()) 860 EXPECT_CALL(client_, IsSavingAndFillingEnabledForCurrentPage())
865 .WillRepeatedly(Return(true)); 861 .WillRepeatedly(Return(true));
866 OnPasswordFormSubmitted(form); 862 OnPasswordFormSubmitted(form);
867 863
868 std::unique_ptr<PasswordFormManager> form_manager_to_save; 864 scoped_refptr<PasswordFormManager> form_manager_to_save;
869 EXPECT_CALL(client_, PromptUserToSaveOrUpdatePasswordPtr(_)) 865 EXPECT_CALL(client_, PromptUserToSaveOrUpdatePassword(_, _))
870 .WillOnce(WithArg<0>(SaveToScopedPtr(&form_manager_to_save))); 866 .WillOnce(
867 DoAll(WithArg<0>(SaveArg<0>(&form_manager_to_save)), Return(false)));
871 868
872 // Now the password manager waits for the login to complete successfully. 869 // Now the password manager waits for the login to complete successfully.
873 observed.clear(); 870 observed.clear();
874 manager()->OnPasswordFormsParsed(&driver_, observed); 871 manager()->OnPasswordFormsParsed(&driver_, observed);
875 manager()->OnPasswordFormsRendered(&driver_, observed, true); 872 manager()->OnPasswordFormsRendered(&driver_, observed, true);
876 ASSERT_TRUE(form_manager_to_save); 873 ASSERT_TRUE(form_manager_to_save);
877 EXPECT_EQ(form.password_value, 874 EXPECT_EQ(form.password_value,
878 PasswordFormManager::PasswordToSave( 875 PasswordFormManager::PasswordToSave(
879 form_manager_to_save->pending_credentials())); 876 form_manager_to_save->pending_credentials()));
880 } 877 }
(...skipping 10 matching lines...) Expand all
891 observed.push_back(form); 888 observed.push_back(form);
892 EXPECT_CALL(*store_, GetLogins(_, _)) 889 EXPECT_CALL(*store_, GetLogins(_, _))
893 .WillOnce(WithArg<1>(InvokeEmptyConsumerWithForms())); 890 .WillOnce(WithArg<1>(InvokeEmptyConsumerWithForms()));
894 manager()->OnPasswordFormsParsed(&driver_, observed); 891 manager()->OnPasswordFormsParsed(&driver_, observed);
895 manager()->OnPasswordFormsRendered(&driver_, observed, true); 892 manager()->OnPasswordFormsRendered(&driver_, observed, true);
896 893
897 EXPECT_CALL(client_, IsSavingAndFillingEnabledForCurrentPage()) 894 EXPECT_CALL(client_, IsSavingAndFillingEnabledForCurrentPage())
898 .WillRepeatedly(Return(true)); 895 .WillRepeatedly(Return(true));
899 OnPasswordFormSubmitted(form); 896 OnPasswordFormSubmitted(form);
900 897
901 std::unique_ptr<PasswordFormManager> form_manager_to_save; 898 scoped_refptr<PasswordFormManager> form_manager_to_save;
902 EXPECT_CALL(client_, PromptUserToSaveOrUpdatePasswordPtr(_)) 899 EXPECT_CALL(client_, PromptUserToSaveOrUpdatePassword(_, _))
903 .WillOnce(WithArg<0>(SaveToScopedPtr(&form_manager_to_save))); 900 .WillOnce(
901 DoAll(WithArg<0>(SaveArg<0>(&form_manager_to_save)), Return(false)));
904 902
905 // Now the password manager waits for the navigation to complete. 903 // Now the password manager waits for the navigation to complete.
906 observed.clear(); 904 observed.clear();
907 manager()->OnPasswordFormsParsed(&driver_, observed); 905 manager()->OnPasswordFormsParsed(&driver_, observed);
908 manager()->OnPasswordFormsRendered(&driver_, observed, true); 906 manager()->OnPasswordFormsRendered(&driver_, observed, true);
909 907
910 // Simulate saving the form, as if the info bar was accepted. 908 // Simulate saving the form, as if the info bar was accepted.
911 EXPECT_CALL(*store_, AddLogin(FormMatches(form))); 909 EXPECT_CALL(*store_, AddLogin(FormMatches(form)));
912 ASSERT_TRUE(form_manager_to_save); 910 ASSERT_TRUE(form_manager_to_save);
913 form_manager_to_save->Save(); 911 form_manager_to_save->Save();
(...skipping 20 matching lines...) Expand all
934 manager()->OnPasswordFormsParsed(&driver_b, observed); 932 manager()->OnPasswordFormsParsed(&driver_b, observed);
935 } 933 }
936 934
937 TEST_F(PasswordManagerTest, InPageNavigation) { 935 TEST_F(PasswordManagerTest, InPageNavigation) {
938 // Test that observing a newly submitted form shows the save password bar on 936 // Test that observing a newly submitted form shows the save password bar on
939 // call in page navigation. 937 // call in page navigation.
940 std::vector<PasswordForm> observed; 938 std::vector<PasswordForm> observed;
941 PasswordForm form(MakeSimpleForm()); 939 PasswordForm form(MakeSimpleForm());
942 observed.push_back(form); 940 observed.push_back(form);
943 EXPECT_CALL(*store_, GetLogins(_, _)) 941 EXPECT_CALL(*store_, GetLogins(_, _))
944 .WillOnce(WithArg<1>(InvokeEmptyConsumerWithForms())); 942 .Times(2)
vasilii 2017/05/29 13:15:49 Why twice?
kolos1 2017/05/29 15:47:06 We don't remove the matched PasswordFormManager fr
943 .WillRepeatedly(WithArg<1>(InvokeEmptyConsumerWithForms()));
945 manager()->OnPasswordFormsParsed(&driver_, observed); 944 manager()->OnPasswordFormsParsed(&driver_, observed);
946 manager()->OnPasswordFormsRendered(&driver_, observed, true); 945 manager()->OnPasswordFormsRendered(&driver_, observed, true);
947 946
948 EXPECT_CALL(client_, IsSavingAndFillingEnabledForCurrentPage()) 947 EXPECT_CALL(client_, IsSavingAndFillingEnabledForCurrentPage())
949 .WillRepeatedly(Return(true)); 948 .WillRepeatedly(Return(true));
950 949
951 std::unique_ptr<PasswordFormManager> form_manager_to_save; 950 scoped_refptr<PasswordFormManager> form_manager_to_save;
952 EXPECT_CALL(client_, PromptUserToSaveOrUpdatePasswordPtr(_)) 951 EXPECT_CALL(client_, PromptUserToSaveOrUpdatePassword(_, _))
953 .WillOnce(WithArg<0>(SaveToScopedPtr(&form_manager_to_save))); 952 .WillOnce(
953 DoAll(WithArg<0>(SaveArg<0>(&form_manager_to_save)), Return(false)));
954 954
955 manager()->OnInPageNavigation(&driver_, form); 955 manager()->OnInPageNavigation(&driver_, form);
956 956
957 // Checks |form_manager_to_save| is still in |pending_login_managers_|.
958 EXPECT_EQ(1u, manager()->pending_login_managers().size());
959
957 // Simulate saving the form, as if the info bar was accepted. 960 // Simulate saving the form, as if the info bar was accepted.
958 EXPECT_CALL(*store_, AddLogin(FormMatches(form))); 961 EXPECT_CALL(*store_, AddLogin(FormMatches(form)));
959 ASSERT_TRUE(form_manager_to_save); 962 ASSERT_TRUE(form_manager_to_save);
960 form_manager_to_save->Save(); 963 form_manager_to_save->Save();
961 } 964 }
962 965
963 TEST_F(PasswordManagerTest, InPageNavigationBlacklistedSite) { 966 TEST_F(PasswordManagerTest, InPageNavigationBlacklistedSite) {
964 // Test that observing a newly submitted form on blacklisted site does notify 967 // Test that observing a newly submitted form on blacklisted site does notify
965 // the embedder on call in page navigation. 968 // the embedder on call in page navigation.
966 std::vector<PasswordForm> observed; 969 std::vector<PasswordForm> observed;
967 PasswordForm form(MakeSimpleForm()); 970 PasswordForm form(MakeSimpleForm());
968 observed.push_back(form); 971 observed.push_back(form);
969 // Simulate that blacklisted form stored in store. 972 // Simulate that blacklisted form stored in store.
970 PasswordForm blacklisted_form(form); 973 PasswordForm blacklisted_form(form);
971 blacklisted_form.username_value = ASCIIToUTF16(""); 974 blacklisted_form.username_value = ASCIIToUTF16("");
972 blacklisted_form.blacklisted_by_user = true; 975 blacklisted_form.blacklisted_by_user = true;
973 EXPECT_CALL(*store_, GetLogins(_, _)) 976 EXPECT_CALL(*store_, GetLogins(_, _))
974 .WillOnce(WithArg<1>(InvokeConsumer(blacklisted_form))); 977 .WillOnce(WithArg<1>(InvokeConsumer(blacklisted_form)));
975 manager()->OnPasswordFormsParsed(&driver_, observed); 978 manager()->OnPasswordFormsParsed(&driver_, observed);
976 manager()->OnPasswordFormsRendered(&driver_, observed, true); 979 manager()->OnPasswordFormsRendered(&driver_, observed, true);
977 980
978 EXPECT_CALL(client_, IsSavingAndFillingEnabledForCurrentPage()) 981 EXPECT_CALL(client_, IsSavingAndFillingEnabledForCurrentPage())
979 .WillRepeatedly(Return(true)); 982 .WillRepeatedly(Return(true));
980 // Prefs are needed for failure logging about blacklisting. 983 // Prefs are needed for failure logging about blacklisting.
981 EXPECT_CALL(client_, GetPrefs()).WillRepeatedly(Return(nullptr)); 984 EXPECT_CALL(client_, GetPrefs()).WillRepeatedly(Return(nullptr));
982 985
983 std::unique_ptr<PasswordFormManager> form_manager_to_save; 986 scoped_refptr<PasswordFormManager> form_manager_to_save;
984 EXPECT_CALL(client_, PromptUserToSaveOrUpdatePasswordPtr(_)) 987 EXPECT_CALL(client_, PromptUserToSaveOrUpdatePassword(_, _))
985 .WillOnce(WithArg<0>(SaveToScopedPtr(&form_manager_to_save))); 988 .WillOnce(
989 DoAll(WithArg<0>(SaveArg<0>(&form_manager_to_save)), Return(false)));
986 990
987 manager()->OnInPageNavigation(&driver_, form); 991 manager()->OnInPageNavigation(&driver_, form);
988 EXPECT_TRUE(form_manager_to_save->IsBlacklisted()); 992 EXPECT_TRUE(form_manager_to_save->IsBlacklisted());
989 } 993 }
990 994
991 TEST_F(PasswordManagerTest, SavingSignupForms_NoHTMLMatch) { 995 TEST_F(PasswordManagerTest, SavingSignupForms_NoHTMLMatch) {
992 // Signup forms don't require HTML attributes match in order to save. 996 // Signup forms don't require HTML attributes match in order to save.
993 // Verify that we prefer a better match (action + origin vs. origin). 997 // Verify that we prefer a better match (action + origin vs. origin).
994 std::vector<PasswordForm> observed; 998 std::vector<PasswordForm> observed;
995 PasswordForm form(MakeSimpleForm()); 999 PasswordForm form(MakeSimpleForm());
(...skipping 12 matching lines...) Expand all
1008 PasswordForm submitted_form(form); 1012 PasswordForm submitted_form(form);
1009 submitted_form.new_password_element = ASCIIToUTF16("new_password"); 1013 submitted_form.new_password_element = ASCIIToUTF16("new_password");
1010 submitted_form.new_password_value = form.password_value; 1014 submitted_form.new_password_value = form.password_value;
1011 submitted_form.password_element.clear(); 1015 submitted_form.password_element.clear();
1012 submitted_form.password_value.clear(); 1016 submitted_form.password_value.clear();
1013 1017
1014 EXPECT_CALL(client_, IsSavingAndFillingEnabledForCurrentPage()) 1018 EXPECT_CALL(client_, IsSavingAndFillingEnabledForCurrentPage())
1015 .WillRepeatedly(Return(true)); 1019 .WillRepeatedly(Return(true));
1016 OnPasswordFormSubmitted(submitted_form); 1020 OnPasswordFormSubmitted(submitted_form);
1017 1021
1018 std::unique_ptr<PasswordFormManager> form_manager_to_save; 1022 scoped_refptr<PasswordFormManager> form_manager_to_save;
1019 EXPECT_CALL(client_, PromptUserToSaveOrUpdatePasswordPtr(_)) 1023 EXPECT_CALL(client_, PromptUserToSaveOrUpdatePassword(_, _))
1020 .WillOnce(WithArg<0>(SaveToScopedPtr(&form_manager_to_save))); 1024 .WillOnce(
1025 DoAll(WithArg<0>(SaveArg<0>(&form_manager_to_save)), Return(false)));
1021 1026
1022 // Now the password manager waits for the navigation to complete. 1027 // Now the password manager waits for the navigation to complete.
1023 observed.clear(); 1028 observed.clear();
1024 manager()->OnPasswordFormsParsed(&driver_, observed); 1029 manager()->OnPasswordFormsParsed(&driver_, observed);
1025 manager()->OnPasswordFormsRendered(&driver_, observed, true); 1030 manager()->OnPasswordFormsRendered(&driver_, observed, true);
1026 1031
1027 // Simulate saving the form, as if the info bar was accepted. 1032 // Simulate saving the form, as if the info bar was accepted.
1028 PasswordForm form_to_save; 1033 PasswordForm form_to_save;
1029 EXPECT_CALL(*store_, AddLogin(_)).WillOnce(SaveArg<0>(&form_to_save)); 1034 EXPECT_CALL(*store_, AddLogin(_)).WillOnce(SaveArg<0>(&form_to_save));
1030 ASSERT_TRUE(form_manager_to_save); 1035 ASSERT_TRUE(form_manager_to_save);
(...skipping 30 matching lines...) Expand all
1061 manager()->OnPasswordFormsParsed(&driver_, observed); 1066 manager()->OnPasswordFormsParsed(&driver_, observed);
1062 manager()->OnPasswordFormsRendered(&driver_, observed, true); 1067 manager()->OnPasswordFormsRendered(&driver_, observed, true);
1063 1068
1064 PasswordForm submitted_form(form); 1069 PasswordForm submitted_form(form);
1065 submitted_form.action = GURL("http://www.google.com/other/action"); 1070 submitted_form.action = GURL("http://www.google.com/other/action");
1066 1071
1067 EXPECT_CALL(client_, IsSavingAndFillingEnabledForCurrentPage()) 1072 EXPECT_CALL(client_, IsSavingAndFillingEnabledForCurrentPage())
1068 .WillRepeatedly(Return(true)); 1073 .WillRepeatedly(Return(true));
1069 OnPasswordFormSubmitted(submitted_form); 1074 OnPasswordFormSubmitted(submitted_form);
1070 1075
1071 std::unique_ptr<PasswordFormManager> form_manager_to_save; 1076 scoped_refptr<PasswordFormManager> form_manager_to_save;
1072 EXPECT_CALL(client_, PromptUserToSaveOrUpdatePasswordPtr(_)) 1077 EXPECT_CALL(client_, PromptUserToSaveOrUpdatePassword(_, _))
1073 .WillOnce(WithArg<0>(SaveToScopedPtr(&form_manager_to_save))); 1078 .WillOnce(
1079 DoAll(WithArg<0>(SaveArg<0>(&form_manager_to_save)), Return(false)));
1074 1080
1075 // Now the password manager waits for the navigation to complete. 1081 // Now the password manager waits for the navigation to complete.
1076 observed.clear(); 1082 observed.clear();
1077 manager()->OnPasswordFormsParsed(&driver_, observed); 1083 manager()->OnPasswordFormsParsed(&driver_, observed);
1078 manager()->OnPasswordFormsRendered(&driver_, observed, true); 1084 manager()->OnPasswordFormsRendered(&driver_, observed, true);
1079 1085
1080 // Simulate saving the form, as if the info bar was accepted. 1086 // Simulate saving the form, as if the info bar was accepted.
1081 PasswordForm form_to_save; 1087 PasswordForm form_to_save;
1082 EXPECT_CALL(*store_, AddLogin(_)).WillOnce(SaveArg<0>(&form_to_save)); 1088 EXPECT_CALL(*store_, AddLogin(_)).WillOnce(SaveArg<0>(&form_to_save));
1083 ASSERT_TRUE(form_manager_to_save); 1089 ASSERT_TRUE(form_manager_to_save);
(...skipping 29 matching lines...) Expand all
1113 // choice of username is accepted by PasswordManager, otherwise the the form 1119 // choice of username is accepted by PasswordManager, otherwise the the form
1114 // will be rejected as not equal to the observed one. Note that during 1120 // will be rejected as not equal to the observed one. Note that during
1115 // initial parsing we don't have autofill server predictions yet, that's why 1121 // initial parsing we don't have autofill server predictions yet, that's why
1116 // observed form and submitted form may be different. 1122 // observed form and submitted form may be different.
1117 form.username_element = ASCIIToUTF16("Username"); 1123 form.username_element = ASCIIToUTF16("Username");
1118 form.was_parsed_using_autofill_predictions = true; 1124 form.was_parsed_using_autofill_predictions = true;
1119 EXPECT_CALL(client_, IsSavingAndFillingEnabledForCurrentPage()) 1125 EXPECT_CALL(client_, IsSavingAndFillingEnabledForCurrentPage())
1120 .WillRepeatedly(Return(true)); 1126 .WillRepeatedly(Return(true));
1121 OnPasswordFormSubmitted(form); 1127 OnPasswordFormSubmitted(form);
1122 1128
1123 std::unique_ptr<PasswordFormManager> form_manager_to_save; 1129 scoped_refptr<PasswordFormManager> form_manager_to_save;
1124 EXPECT_CALL(client_, PromptUserToSaveOrUpdatePasswordPtr(_)) 1130 EXPECT_CALL(client_, PromptUserToSaveOrUpdatePassword(_, _))
1125 .WillOnce(WithArg<0>(SaveToScopedPtr(&form_manager_to_save))); 1131 .WillOnce(
1132 DoAll(WithArg<0>(SaveArg<0>(&form_manager_to_save)), Return(false)));
1126 1133
1127 // Now the password manager waits for the navigation to complete. 1134 // Now the password manager waits for the navigation to complete.
1128 observed.clear(); 1135 observed.clear();
1129 manager()->OnPasswordFormsParsed(&driver_, observed); 1136 manager()->OnPasswordFormsParsed(&driver_, observed);
1130 manager()->OnPasswordFormsRendered(&driver_, observed, true); 1137 manager()->OnPasswordFormsRendered(&driver_, observed, true);
1131 1138
1132 // Simulate saving the form, as if the info bar was accepted. 1139 // Simulate saving the form, as if the info bar was accepted.
1133 EXPECT_CALL(*store_, AddLogin(FormMatches(form))); 1140 EXPECT_CALL(*store_, AddLogin(FormMatches(form)));
1134 ASSERT_TRUE(form_manager_to_save); 1141 ASSERT_TRUE(form_manager_to_save);
1135 form_manager_to_save->Save(); 1142 form_manager_to_save->Save();
(...skipping 10 matching lines...) Expand all
1146 .WillOnce(WithArg<1>(InvokeConsumer(form))); 1153 .WillOnce(WithArg<1>(InvokeConsumer(form)));
1147 manager()->OnPasswordFormsParsed(&driver_, observed); 1154 manager()->OnPasswordFormsParsed(&driver_, observed);
1148 manager()->OnPasswordFormsRendered(&driver_, observed, true); 1155 manager()->OnPasswordFormsRendered(&driver_, observed, true);
1149 1156
1150 EXPECT_CALL(client_, IsSavingAndFillingEnabledForCurrentPage()) 1157 EXPECT_CALL(client_, IsSavingAndFillingEnabledForCurrentPage())
1151 .WillRepeatedly(Return(true)); 1158 .WillRepeatedly(Return(true));
1152 OnPasswordFormSubmitted(form); 1159 OnPasswordFormSubmitted(form);
1153 1160
1154 autofill::PasswordForm updated_form; 1161 autofill::PasswordForm updated_form;
1155 autofill::PasswordForm notified_form; 1162 autofill::PasswordForm notified_form;
1156 EXPECT_CALL(client_, PromptUserToSaveOrUpdatePasswordPtr(_)).Times(0); 1163 EXPECT_CALL(client_, PromptUserToSaveOrUpdatePassword(_, _)).Times(0);
1157 EXPECT_CALL(*store_, UpdateLogin(_)).WillOnce(SaveArg<0>(&updated_form)); 1164 EXPECT_CALL(*store_, UpdateLogin(_)).WillOnce(SaveArg<0>(&updated_form));
1158 EXPECT_CALL(client_, NotifySuccessfulLoginWithExistingPassword(_)) 1165 EXPECT_CALL(client_, NotifySuccessfulLoginWithExistingPassword(_))
1159 .WillOnce(SaveArg<0>(&notified_form)); 1166 .WillOnce(SaveArg<0>(&notified_form));
1160 1167
1161 // Now the password manager waits for the navigation to complete. 1168 // Now the password manager waits for the navigation to complete.
1162 observed.clear(); 1169 observed.clear();
1163 manager()->OnPasswordFormsParsed(&driver_, observed); 1170 manager()->OnPasswordFormsParsed(&driver_, observed);
1164 manager()->OnPasswordFormsRendered(&driver_, observed, true); 1171 manager()->OnPasswordFormsRendered(&driver_, observed, true);
1165 1172
1166 EXPECT_THAT(form, FormMatches(updated_form)); 1173 EXPECT_THAT(form, FormMatches(updated_form));
(...skipping 19 matching lines...) Expand all
1186 EXPECT_CALL(client_, IsSavingAndFillingEnabledForCurrentPage()) 1193 EXPECT_CALL(client_, IsSavingAndFillingEnabledForCurrentPage())
1187 .WillRepeatedly(Return(true)); 1194 .WillRepeatedly(Return(true));
1188 OnPasswordFormSubmitted(form); 1195 OnPasswordFormSubmitted(form);
1189 1196
1190 // Emulate fetching password form from PasswordStore after submission but 1197 // Emulate fetching password form from PasswordStore after submission but
1191 // before post-navigation load. 1198 // before post-navigation load.
1192 ASSERT_TRUE(form_manager); 1199 ASSERT_TRUE(form_manager);
1193 static_cast<FormFetcherImpl*>(form_manager->form_fetcher()) 1200 static_cast<FormFetcherImpl*>(form_manager->form_fetcher())
1194 ->OnGetPasswordStoreResults(std::vector<std::unique_ptr<PasswordForm>>()); 1201 ->OnGetPasswordStoreResults(std::vector<std::unique_ptr<PasswordForm>>());
1195 1202
1196 std::unique_ptr<PasswordFormManager> form_manager_to_save; 1203 scoped_refptr<PasswordFormManager> form_manager_to_save;
1197 EXPECT_CALL(client_, PromptUserToSaveOrUpdatePasswordPtr(_)) 1204 EXPECT_CALL(client_, PromptUserToSaveOrUpdatePassword(_, _))
1198 .WillOnce(WithArg<0>(SaveToScopedPtr(&form_manager_to_save))); 1205 .WillOnce(
1206 DoAll(WithArg<0>(SaveArg<0>(&form_manager_to_save)), Return(false)));
1199 1207
1200 // Now the password manager waits for the navigation to complete. 1208 // Now the password manager waits for the navigation to complete.
1201 observed.clear(); 1209 observed.clear();
1202 manager()->OnPasswordFormsParsed(&driver_, observed); 1210 manager()->OnPasswordFormsParsed(&driver_, observed);
1203 manager()->OnPasswordFormsRendered(&driver_, observed, true); 1211 manager()->OnPasswordFormsRendered(&driver_, observed, true);
1204 1212
1205 // Simulate saving the form, as if the info bar was accepted. 1213 // Simulate saving the form, as if the info bar was accepted.
1206 EXPECT_CALL(*store_, AddLogin(FormMatches(form))); 1214 EXPECT_CALL(*store_, AddLogin(FormMatches(form)));
1207 ASSERT_TRUE(form_manager_to_save); 1215 ASSERT_TRUE(form_manager_to_save);
1208 form_manager_to_save->Save(); 1216 form_manager_to_save->Save();
1209 } 1217 }
1210 1218
1211 TEST_F(PasswordManagerTest, PasswordGeneration_FailedSubmission) { 1219 TEST_F(PasswordManagerTest, PasswordGeneration_FailedSubmission) {
1212 std::vector<PasswordForm> observed; 1220 std::vector<PasswordForm> observed;
1213 PasswordForm form(MakeFormWithOnlyNewPasswordField()); 1221 PasswordForm form(MakeFormWithOnlyNewPasswordField());
1214 observed.push_back(form); 1222 observed.push_back(form);
1215 EXPECT_CALL(*store_, GetLogins(_, _)) 1223 EXPECT_CALL(*store_, GetLogins(_, _))
1216 .WillRepeatedly(WithArg<1>(InvokeEmptyConsumerWithForms())); 1224 .WillRepeatedly(WithArg<1>(InvokeEmptyConsumerWithForms()));
1217 manager()->OnPasswordFormsParsed(&driver_, observed); 1225 manager()->OnPasswordFormsParsed(&driver_, observed);
1218 manager()->OnPasswordFormsRendered(&driver_, observed, true); 1226 manager()->OnPasswordFormsRendered(&driver_, observed, true);
1219 1227
1220 EXPECT_CALL(client_, IsSavingAndFillingEnabledForCurrentPage()) 1228 EXPECT_CALL(client_, IsSavingAndFillingEnabledForCurrentPage())
1221 .WillRepeatedly(Return(true)); 1229 .WillRepeatedly(Return(true));
1222 manager()->SetHasGeneratedPasswordForForm(&driver_, form, true); 1230 manager()->SetHasGeneratedPasswordForForm(&driver_, form, true);
1223 1231
1224 // Do not save generated password when the password form reappears. 1232 // Do not save generated password when the password form reappears.
1225 EXPECT_CALL(client_, PromptUserToSaveOrUpdatePasswordPtr(_)).Times(0); 1233 EXPECT_CALL(client_, PromptUserToSaveOrUpdatePassword(_, _)).Times(0);
1226 EXPECT_CALL(*store_, AddLogin(_)).Times(0); 1234 EXPECT_CALL(*store_, AddLogin(_)).Times(0);
1227 EXPECT_CALL(client_, AutomaticPasswordSaveIndicator()).Times(0); 1235 EXPECT_CALL(client_, AutomaticPasswordSaveIndicator()).Times(0);
1228 1236
1229 // Simulate submission failing, with the same form being visible after 1237 // Simulate submission failing, with the same form being visible after
1230 // navigation. 1238 // navigation.
1231 OnPasswordFormSubmitted(form); 1239 OnPasswordFormSubmitted(form);
1232 manager()->OnPasswordFormsParsed(&driver_, observed); 1240 manager()->OnPasswordFormsParsed(&driver_, observed);
1233 manager()->OnPasswordFormsRendered(&driver_, observed, true); 1241 manager()->OnPasswordFormsRendered(&driver_, observed, true);
1234 } 1242 }
1235 1243
(...skipping 11 matching lines...) Expand all
1247 EXPECT_CALL(client_, IsSavingAndFillingEnabledForCurrentPage()) 1255 EXPECT_CALL(client_, IsSavingAndFillingEnabledForCurrentPage())
1248 .WillRepeatedly(Return(true)); 1256 .WillRepeatedly(Return(true));
1249 manager()->SetHasGeneratedPasswordForForm(&driver_, form, true); 1257 manager()->SetHasGeneratedPasswordForForm(&driver_, form, true);
1250 1258
1251 // Simulate user editing and submitting a different password. Verify that 1259 // Simulate user editing and submitting a different password. Verify that
1252 // the edited password is the one that is saved. 1260 // the edited password is the one that is saved.
1253 form.new_password_value = ASCIIToUTF16("different_password"); 1261 form.new_password_value = ASCIIToUTF16("different_password");
1254 OnPasswordFormSubmitted(form); 1262 OnPasswordFormSubmitted(form);
1255 1263
1256 // Do not save generated password when the password form reappears. 1264 // Do not save generated password when the password form reappears.
1257 EXPECT_CALL(client_, PromptUserToSaveOrUpdatePasswordPtr(_)).Times(0); 1265 EXPECT_CALL(client_, PromptUserToSaveOrUpdatePassword(_, _)).Times(0);
1258 EXPECT_CALL(*store_, AddLogin(_)).Times(0); 1266 EXPECT_CALL(*store_, AddLogin(_)).Times(0);
1259 EXPECT_CALL(client_, AutomaticPasswordSaveIndicator()).Times(0); 1267 EXPECT_CALL(client_, AutomaticPasswordSaveIndicator()).Times(0);
1260 1268
1261 // Simulate submission failing, with the same form being visible after 1269 // Simulate submission failing, with the same form being visible after
1262 // navigation. 1270 // navigation.
1263 manager()->OnPasswordFormsParsed(&driver_, observed); 1271 manager()->OnPasswordFormsParsed(&driver_, observed);
1264 manager()->OnPasswordFormsRendered(&driver_, observed, true); 1272 manager()->OnPasswordFormsRendered(&driver_, observed, true);
1265 } 1273 }
1266 1274
1267 // Generated password are saved even if it looks like the submit failed (the 1275 // Generated password are saved even if it looks like the submit failed (the
(...skipping 13 matching lines...) Expand all
1281 .WillRepeatedly(Return(true)); 1289 .WillRepeatedly(Return(true));
1282 manager()->SetHasGeneratedPasswordForForm(&driver_, form, true); 1290 manager()->SetHasGeneratedPasswordForForm(&driver_, form, true);
1283 1291
1284 // Simulate user removing generated password and adding a new one. 1292 // Simulate user removing generated password and adding a new one.
1285 form.new_password_value = ASCIIToUTF16("different_password"); 1293 form.new_password_value = ASCIIToUTF16("different_password");
1286 manager()->SetHasGeneratedPasswordForForm(&driver_, form, false); 1294 manager()->SetHasGeneratedPasswordForForm(&driver_, form, false);
1287 1295
1288 OnPasswordFormSubmitted(form); 1296 OnPasswordFormSubmitted(form);
1289 1297
1290 // No infobar or prompt is shown if submission fails. 1298 // No infobar or prompt is shown if submission fails.
1291 EXPECT_CALL(client_, PromptUserToSaveOrUpdatePasswordPtr(_)).Times(0); 1299 EXPECT_CALL(client_, PromptUserToSaveOrUpdatePassword(_, _)).Times(0);
1292 EXPECT_CALL(client_, AutomaticPasswordSaveIndicator()).Times(0); 1300 EXPECT_CALL(client_, AutomaticPasswordSaveIndicator()).Times(0);
1293 1301
1294 // Simulate submission failing, with the same form being visible after 1302 // Simulate submission failing, with the same form being visible after
1295 // navigation. 1303 // navigation.
1296 manager()->OnPasswordFormsParsed(&driver_, observed); 1304 manager()->OnPasswordFormsParsed(&driver_, observed);
1297 manager()->OnPasswordFormsRendered(&driver_, observed, true); 1305 manager()->OnPasswordFormsRendered(&driver_, observed, true);
1298 } 1306 }
1299 1307
1300 // Verify that passwords which are no longer generated trigger the confirmation 1308 // Verify that passwords which are no longer generated trigger the confirmation
1301 // dialog when submitted. 1309 // dialog when submitted.
(...skipping 11 matching lines...) Expand all
1313 .WillRepeatedly(Return(true)); 1321 .WillRepeatedly(Return(true));
1314 manager()->SetHasGeneratedPasswordForForm(&driver_, form, true); 1322 manager()->SetHasGeneratedPasswordForForm(&driver_, form, true);
1315 1323
1316 // Simulate user removing generated password and adding a new one. 1324 // Simulate user removing generated password and adding a new one.
1317 form.new_password_value = ASCIIToUTF16("different_password"); 1325 form.new_password_value = ASCIIToUTF16("different_password");
1318 manager()->SetHasGeneratedPasswordForForm(&driver_, form, false); 1326 manager()->SetHasGeneratedPasswordForForm(&driver_, form, false);
1319 1327
1320 OnPasswordFormSubmitted(form); 1328 OnPasswordFormSubmitted(form);
1321 1329
1322 // Verify that a normal prompt is shown instead of the force saving UI. 1330 // Verify that a normal prompt is shown instead of the force saving UI.
1323 std::unique_ptr<PasswordFormManager> form_to_save; 1331 scoped_refptr<PasswordFormManager> form_to_save;
1324 EXPECT_CALL(client_, PromptUserToSaveOrUpdatePasswordPtr(_)) 1332 EXPECT_CALL(client_, PromptUserToSaveOrUpdatePassword(_, _))
1325 .WillOnce(WithArg<0>(SaveToScopedPtr(&form_to_save))); 1333 .WillOnce(DoAll(WithArg<0>(SaveArg<0>(&form_to_save)), Return(false)));
1326 EXPECT_CALL(client_, AutomaticPasswordSaveIndicator()).Times(0); 1334 EXPECT_CALL(client_, AutomaticPasswordSaveIndicator()).Times(0);
1327 1335
1328 // Simulate a successful submission. 1336 // Simulate a successful submission.
1329 observed.clear(); 1337 observed.clear();
1330 manager()->OnPasswordFormsParsed(&driver_, observed); 1338 manager()->OnPasswordFormsParsed(&driver_, observed);
1331 manager()->OnPasswordFormsRendered(&driver_, observed, true); 1339 manager()->OnPasswordFormsRendered(&driver_, observed, true);
1332 } 1340 }
1333 1341
1334 TEST_F(PasswordManagerTest, PasswordGenerationUsernameChanged) { 1342 TEST_F(PasswordManagerTest, PasswordGenerationUsernameChanged) {
1335 std::vector<PasswordForm> observed; 1343 std::vector<PasswordForm> observed;
1336 PasswordForm form(MakeFormWithOnlyNewPasswordField()); 1344 PasswordForm form(MakeFormWithOnlyNewPasswordField());
1337 observed.push_back(form); 1345 observed.push_back(form);
1338 EXPECT_CALL(*store_, GetLogins(_, _)) 1346 EXPECT_CALL(*store_, GetLogins(_, _))
1339 .WillRepeatedly(WithArg<1>(InvokeEmptyConsumerWithForms())); 1347 .WillRepeatedly(WithArg<1>(InvokeEmptyConsumerWithForms()));
1340 manager()->OnPasswordFormsParsed(&driver_, observed); 1348 manager()->OnPasswordFormsParsed(&driver_, observed);
1341 manager()->OnPasswordFormsRendered(&driver_, observed, true); 1349 manager()->OnPasswordFormsRendered(&driver_, observed, true);
1342 1350
1343 EXPECT_CALL(client_, IsSavingAndFillingEnabledForCurrentPage()) 1351 EXPECT_CALL(client_, IsSavingAndFillingEnabledForCurrentPage())
1344 .WillRepeatedly(Return(true)); 1352 .WillRepeatedly(Return(true));
1345 manager()->SetHasGeneratedPasswordForForm(&driver_, form, true); 1353 manager()->SetHasGeneratedPasswordForForm(&driver_, form, true);
1346 1354
1347 // Simulate user changing the password and username, without ever completely 1355 // Simulate user changing the password and username, without ever completely
1348 // deleting the password. 1356 // deleting the password.
1349 form.new_password_value = ASCIIToUTF16("different_password"); 1357 form.new_password_value = ASCIIToUTF16("different_password");
1350 form.username_value = ASCIIToUTF16("new_username"); 1358 form.username_value = ASCIIToUTF16("new_username");
1351 OnPasswordFormSubmitted(form); 1359 OnPasswordFormSubmitted(form);
1352 1360
1353 EXPECT_CALL(client_, PromptUserToSaveOrUpdatePasswordPtr(_)).Times(0); 1361 EXPECT_CALL(client_, PromptUserToSaveOrUpdatePassword(_, _)).Times(0);
1354 PasswordForm form_to_save; 1362 PasswordForm form_to_save;
1355 EXPECT_CALL(*store_, AddLogin(_)).WillOnce(SaveArg<0>(&form_to_save)); 1363 EXPECT_CALL(*store_, AddLogin(_)).WillOnce(SaveArg<0>(&form_to_save));
1356 EXPECT_CALL(client_, AutomaticPasswordSaveIndicator()); 1364 EXPECT_CALL(client_, AutomaticPasswordSaveIndicator());
1357 1365
1358 observed.clear(); 1366 observed.clear();
1359 manager()->OnPasswordFormsParsed(&driver_, observed); 1367 manager()->OnPasswordFormsParsed(&driver_, observed);
1360 manager()->OnPasswordFormsRendered(&driver_, observed, true); 1368 manager()->OnPasswordFormsRendered(&driver_, observed, true);
1361 EXPECT_EQ(form.username_value, form_to_save.username_value); 1369 EXPECT_EQ(form.username_value, form_to_save.username_value);
1362 // What was "new password" field in the submitted form, becomes the current 1370 // What was "new password" field in the submitted form, becomes the current
1363 // password field in the form to save. 1371 // password field in the form to save.
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
1406 if (found_matched_logins_in_store) { 1414 if (found_matched_logins_in_store) {
1407 EXPECT_CALL(*store_, GetLogins(_, _)) 1415 EXPECT_CALL(*store_, GetLogins(_, _))
1408 .WillRepeatedly(WithArg<1>(InvokeConsumer(form))); 1416 .WillRepeatedly(WithArg<1>(InvokeConsumer(form)));
1409 EXPECT_CALL(*store_, GetLoginsForSameOrganizationName(_, _)); 1417 EXPECT_CALL(*store_, GetLoginsForSameOrganizationName(_, _));
1410 EXPECT_CALL(driver_, FillPasswordForm(_)).Times(2); 1418 EXPECT_CALL(driver_, FillPasswordForm(_)).Times(2);
1411 } else { 1419 } else {
1412 EXPECT_CALL(*store_, GetLogins(_, _)) 1420 EXPECT_CALL(*store_, GetLogins(_, _))
1413 .WillRepeatedly(WithArg<1>(InvokeEmptyConsumerWithForms())); 1421 .WillRepeatedly(WithArg<1>(InvokeEmptyConsumerWithForms()));
1414 EXPECT_CALL(*store_, GetLoginsForSameOrganizationName(_, _)); 1422 EXPECT_CALL(*store_, GetLoginsForSameOrganizationName(_, _));
1415 } 1423 }
1416 std::unique_ptr<PasswordFormManager> form_manager; 1424 scoped_refptr<PasswordFormManager> form_manager;
1417 if (found_matched_logins_in_store) { 1425 if (found_matched_logins_in_store) {
1418 EXPECT_CALL(client_, PromptUserToSaveOrUpdatePasswordPtr(_)) 1426 EXPECT_CALL(client_, PromptUserToSaveOrUpdatePassword(_, _))
1419 .WillOnce(WithArg<0>(SaveToScopedPtr(&form_manager))); 1427 .WillOnce(
1428 DoAll(WithArg<0>(SaveArg<0>(&form_manager)), Return(false)));
1420 } else { 1429 } else {
1421 EXPECT_CALL(client_, PromptUserToSaveOrUpdatePasswordPtr(_)).Times(0); 1430 EXPECT_CALL(client_, PromptUserToSaveOrUpdatePassword(_, _)).Times(0);
1422 } 1431 }
1423 EXPECT_CALL(client_, AutomaticPasswordSaveIndicator()) 1432 EXPECT_CALL(client_, AutomaticPasswordSaveIndicator())
1424 .Times(found_matched_logins_in_store ? 0 : 1); 1433 .Times(found_matched_logins_in_store ? 0 : 1);
1425 manager()->OnPasswordFormsParsed(&driver_, observed); 1434 manager()->OnPasswordFormsParsed(&driver_, observed);
1426 manager()->OnPasswordFormsRendered(&driver_, observed, true); 1435 manager()->OnPasswordFormsRendered(&driver_, observed, true);
1427 1436
1428 // The user accepts generated password and makes successful login. 1437 // The user accepts generated password and makes successful login.
1429 EXPECT_CALL(*store_, AddLogin(form)).WillOnce(Return()); 1438 EXPECT_CALL(*store_, AddLogin(form)).WillOnce(Return());
1430 manager()->OnPresaveGeneratedPassword(form); 1439 manager()->OnPresaveGeneratedPassword(form);
1431 manager()->SetHasGeneratedPasswordForForm(&driver_, form, true); 1440 manager()->SetHasGeneratedPasswordForForm(&driver_, form, true);
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
1478 features::kEnablePasswordForceSaving); 1487 features::kEnablePasswordForceSaving);
1479 PasswordForm form(MakeSimpleForm()); 1488 PasswordForm form(MakeSimpleForm());
1480 1489
1481 std::vector<PasswordForm> observed; 1490 std::vector<PasswordForm> observed;
1482 observed.push_back(form); 1491 observed.push_back(form);
1483 EXPECT_CALL(*store_, GetLogins(_, _)) 1492 EXPECT_CALL(*store_, GetLogins(_, _))
1484 .WillRepeatedly(WithArg<1>(InvokeEmptyConsumerWithForms())); 1493 .WillRepeatedly(WithArg<1>(InvokeEmptyConsumerWithForms()));
1485 manager()->OnPasswordFormsParsed(&driver_, observed); 1494 manager()->OnPasswordFormsParsed(&driver_, observed);
1486 manager()->OnPasswordFormsRendered(&driver_, observed, true); 1495 manager()->OnPasswordFormsRendered(&driver_, observed, true);
1487 1496
1488 std::unique_ptr<PasswordFormManager> form_manager_to_save; 1497 scoped_refptr<PasswordFormManager> form_manager_to_save;
1489 EXPECT_CALL(client_, IsSavingAndFillingEnabledForCurrentPage()) 1498 EXPECT_CALL(client_, IsSavingAndFillingEnabledForCurrentPage())
1490 .WillRepeatedly(Return(true)); 1499 .WillRepeatedly(Return(true));
1491 EXPECT_CALL(client_, PromptUserToSaveOrUpdatePasswordPtr(_)) 1500 EXPECT_CALL(client_, PromptUserToSaveOrUpdatePassword(_, _))
1492 .WillOnce(WithArg<0>(SaveToScopedPtr(&form_manager_to_save))); 1501 .WillOnce(
1502 DoAll(WithArg<0>(SaveArg<0>(&form_manager_to_save)), Return(false)));
1493 manager()->OnPasswordFormForceSaveRequested(&driver_, form); 1503 manager()->OnPasswordFormForceSaveRequested(&driver_, form);
1494 ASSERT_TRUE(form_manager_to_save); 1504 ASSERT_TRUE(form_manager_to_save);
1495 EXPECT_EQ(form.password_value, 1505 EXPECT_EQ(form.password_value,
1496 PasswordFormManager::PasswordToSave( 1506 PasswordFormManager::PasswordToSave(
1497 form_manager_to_save->pending_credentials())); 1507 form_manager_to_save->pending_credentials()));
1498 } 1508 }
1499 1509
1500 // Forcing Chrome to save an empty passwords should fail without a crash. 1510 // Forcing Chrome to save an empty passwords should fail without a crash.
1501 TEST_F(PasswordManagerTest, ForceSavingPasswords_Empty) { 1511 TEST_F(PasswordManagerTest, ForceSavingPasswords_Empty) {
1502 // Add the enable-password-force-saving feature. 1512 // Add the enable-password-force-saving feature.
1503 base::test::ScopedFeatureList scoped_feature_list; 1513 base::test::ScopedFeatureList scoped_feature_list;
1504 scoped_feature_list.InitAndEnableFeature( 1514 scoped_feature_list.InitAndEnableFeature(
1505 features::kEnablePasswordForceSaving); 1515 features::kEnablePasswordForceSaving);
1506 PasswordForm empty_password_form; 1516 PasswordForm empty_password_form;
1507 1517
1508 std::vector<PasswordForm> observed; 1518 std::vector<PasswordForm> observed;
1509 observed.push_back(empty_password_form); 1519 observed.push_back(empty_password_form);
1510 EXPECT_CALL(*store_, GetLogins(_, _)) 1520 EXPECT_CALL(*store_, GetLogins(_, _))
1511 .WillRepeatedly(WithArg<1>(InvokeEmptyConsumerWithForms())); 1521 .WillRepeatedly(WithArg<1>(InvokeEmptyConsumerWithForms()));
1512 manager()->OnPasswordFormsParsed(&driver_, observed); 1522 manager()->OnPasswordFormsParsed(&driver_, observed);
1513 manager()->OnPasswordFormsRendered(&driver_, observed, true); 1523 manager()->OnPasswordFormsRendered(&driver_, observed, true);
1514 1524
1515 EXPECT_CALL(client_, IsSavingAndFillingEnabledForCurrentPage()) 1525 EXPECT_CALL(client_, IsSavingAndFillingEnabledForCurrentPage())
1516 .WillRepeatedly(Return(true)); 1526 .WillRepeatedly(Return(true));
1517 EXPECT_CALL(client_, PromptUserToSaveOrUpdatePasswordPtr(_)).Times(0); 1527 EXPECT_CALL(client_, PromptUserToSaveOrUpdatePassword(_, _)).Times(0);
1518 manager()->OnPasswordFormForceSaveRequested(&driver_, empty_password_form); 1528 manager()->OnPasswordFormForceSaveRequested(&driver_, empty_password_form);
1519 } 1529 }
1520 1530
1521 TEST_F(PasswordManagerTest, UpdateFormManagers) { 1531 TEST_F(PasswordManagerTest, UpdateFormManagers) {
1522 // Seeing some forms should result in creating PasswordFormManagers and 1532 // Seeing some forms should result in creating PasswordFormManagers and
1523 // querying PasswordStore. Calling UpdateFormManagers should result in 1533 // querying PasswordStore. Calling UpdateFormManagers should result in
1524 // querying the store again. 1534 // querying the store again.
1525 EXPECT_CALL(*store_, GetLogins(_, _)); 1535 EXPECT_CALL(*store_, GetLogins(_, _));
1526 1536
1527 PasswordForm form; 1537 PasswordForm form;
(...skipping 20 matching lines...) Expand all
1548 EXPECT_CALL(*store_, GetLogins(_, _)) 1558 EXPECT_CALL(*store_, GetLogins(_, _))
1549 .WillRepeatedly(WithArg<1>(InvokeEmptyConsumerWithForms())); 1559 .WillRepeatedly(WithArg<1>(InvokeEmptyConsumerWithForms()));
1550 manager()->OnPasswordFormsParsed(&driver_, observed); 1560 manager()->OnPasswordFormsParsed(&driver_, observed);
1551 manager()->OnPasswordFormsRendered(&driver_, observed, true); 1561 manager()->OnPasswordFormsRendered(&driver_, observed, true);
1552 1562
1553 manager()->DropFormManagers(); 1563 manager()->DropFormManagers();
1554 EXPECT_CALL(client_, IsSavingAndFillingEnabledForCurrentPage()) 1564 EXPECT_CALL(client_, IsSavingAndFillingEnabledForCurrentPage())
1555 .WillRepeatedly(Return(true)); 1565 .WillRepeatedly(Return(true));
1556 OnPasswordFormSubmitted(form); 1566 OnPasswordFormSubmitted(form);
1557 1567
1558 EXPECT_CALL(client_, PromptUserToSaveOrUpdatePasswordPtr(_)).Times(0); 1568 EXPECT_CALL(client_, PromptUserToSaveOrUpdatePassword(_, _)).Times(0);
1559 observed.clear(); 1569 observed.clear();
1560 manager()->OnPasswordFormsParsed(&driver_, observed); 1570 manager()->OnPasswordFormsParsed(&driver_, observed);
1561 manager()->OnPasswordFormsRendered(&driver_, observed, true); 1571 manager()->OnPasswordFormsRendered(&driver_, observed, true);
1562 } 1572 }
1563 1573
1564 TEST_F(PasswordManagerTest, AutofillingOfAffiliatedCredentials) { 1574 TEST_F(PasswordManagerTest, AutofillingOfAffiliatedCredentials) {
1565 PasswordForm android_form(MakeAndroidCredential()); 1575 PasswordForm android_form(MakeAndroidCredential());
1566 PasswordForm observed_form(MakeSimpleForm()); 1576 PasswordForm observed_form(MakeSimpleForm());
1567 std::vector<PasswordForm> observed_forms; 1577 std::vector<PasswordForm> observed_forms;
1568 observed_forms.push_back(observed_form); 1578 observed_forms.push_back(observed_form);
(...skipping 15 matching lines...) Expand all
1584 .WillRepeatedly(Return(true)); 1594 .WillRepeatedly(Return(true));
1585 1595
1586 PasswordForm filled_form(observed_form); 1596 PasswordForm filled_form(observed_form);
1587 filled_form.username_value = android_form.username_value; 1597 filled_form.username_value = android_form.username_value;
1588 filled_form.password_value = android_form.password_value; 1598 filled_form.password_value = android_form.password_value;
1589 OnPasswordFormSubmitted(filled_form); 1599 OnPasswordFormSubmitted(filled_form);
1590 1600
1591 PasswordForm saved_form; 1601 PasswordForm saved_form;
1592 PasswordForm saved_notified_form; 1602 PasswordForm saved_notified_form;
1593 EXPECT_CALL(*store_, UpdateLogin(_)).WillOnce(SaveArg<0>(&saved_form)); 1603 EXPECT_CALL(*store_, UpdateLogin(_)).WillOnce(SaveArg<0>(&saved_form));
1594 EXPECT_CALL(client_, PromptUserToSaveOrUpdatePasswordPtr(_)).Times(0); 1604 EXPECT_CALL(client_, PromptUserToSaveOrUpdatePassword(_, _)).Times(0);
1595 EXPECT_CALL(client_, NotifySuccessfulLoginWithExistingPassword(_)) 1605 EXPECT_CALL(client_, NotifySuccessfulLoginWithExistingPassword(_))
1596 .WillOnce(SaveArg<0>(&saved_notified_form)); 1606 .WillOnce(SaveArg<0>(&saved_notified_form));
1597 EXPECT_CALL(*store_, AddLogin(_)).Times(0); 1607 EXPECT_CALL(*store_, AddLogin(_)).Times(0);
1598 EXPECT_CALL(*store_, UpdateLoginWithPrimaryKey(_, _)).Times(0); 1608 EXPECT_CALL(*store_, UpdateLoginWithPrimaryKey(_, _)).Times(0);
1599 1609
1600 observed_forms.clear(); 1610 observed_forms.clear();
1601 manager()->OnPasswordFormsParsed(&driver_, observed_forms); 1611 manager()->OnPasswordFormsParsed(&driver_, observed_forms);
1602 manager()->OnPasswordFormsRendered(&driver_, observed_forms, true); 1612 manager()->OnPasswordFormsRendered(&driver_, observed_forms, true);
1603 EXPECT_THAT(saved_form, FormMatches(android_form)); 1613 EXPECT_THAT(saved_form, FormMatches(android_form));
1604 EXPECT_THAT(saved_form, FormMatches(saved_notified_form)); 1614 EXPECT_THAT(saved_form, FormMatches(saved_notified_form));
(...skipping 17 matching lines...) Expand all
1622 manager()->OnPasswordFormsRendered(&driver_, observed_forms, true); 1632 manager()->OnPasswordFormsRendered(&driver_, observed_forms, true);
1623 1633
1624 EXPECT_CALL(client_, IsSavingAndFillingEnabledForCurrentPage()) 1634 EXPECT_CALL(client_, IsSavingAndFillingEnabledForCurrentPage())
1625 .WillRepeatedly(Return(true)); 1635 .WillRepeatedly(Return(true));
1626 1636
1627 PasswordForm filled_form(observed_form); 1637 PasswordForm filled_form(observed_form);
1628 filled_form.username_value = android_form.username_value; 1638 filled_form.username_value = android_form.username_value;
1629 filled_form.password_value = ASCIIToUTF16("new_password"); 1639 filled_form.password_value = ASCIIToUTF16("new_password");
1630 OnPasswordFormSubmitted(filled_form); 1640 OnPasswordFormSubmitted(filled_form);
1631 1641
1632 std::unique_ptr<PasswordFormManager> form_manager_to_save; 1642 scoped_refptr<PasswordFormManager> form_manager_to_save;
1633 EXPECT_CALL(client_, PromptUserToSaveOrUpdatePasswordPtr(_)) 1643 EXPECT_CALL(client_, PromptUserToSaveOrUpdatePassword(_, _))
1634 .WillOnce(WithArg<0>(SaveToScopedPtr(&form_manager_to_save))); 1644 .WillOnce(
1645 DoAll(WithArg<0>(SaveArg<0>(&form_manager_to_save)), Return(false)));
1635 1646
1636 observed_forms.clear(); 1647 observed_forms.clear();
1637 manager()->OnPasswordFormsParsed(&driver_, observed_forms); 1648 manager()->OnPasswordFormsParsed(&driver_, observed_forms);
1638 manager()->OnPasswordFormsRendered(&driver_, observed_forms, true); 1649 manager()->OnPasswordFormsRendered(&driver_, observed_forms, true);
1639 1650
1640 PasswordForm saved_form; 1651 PasswordForm saved_form;
1641 EXPECT_CALL(*store_, AddLogin(_)).Times(0); 1652 EXPECT_CALL(*store_, AddLogin(_)).Times(0);
1642 EXPECT_CALL(*store_, UpdateLoginWithPrimaryKey(_, _)).Times(0); 1653 EXPECT_CALL(*store_, UpdateLoginWithPrimaryKey(_, _)).Times(0);
1643 EXPECT_CALL(*store_, UpdateLogin(_)).WillOnce(SaveArg<0>(&saved_form)); 1654 EXPECT_CALL(*store_, UpdateLogin(_)).WillOnce(SaveArg<0>(&saved_form));
1644 ASSERT_TRUE(form_manager_to_save); 1655 ASSERT_TRUE(form_manager_to_save);
(...skipping 28 matching lines...) Expand all
1673 static_cast<FormFetcherImpl*>(form_manager->form_fetcher()) 1684 static_cast<FormFetcherImpl*>(form_manager->form_fetcher())
1674 ->OnGetPasswordStoreResults(std::vector<std::unique_ptr<PasswordForm>>()); 1685 ->OnGetPasswordStoreResults(std::vector<std::unique_ptr<PasswordForm>>());
1675 1686
1676 OnPasswordFormSubmitted(form); 1687 OnPasswordFormSubmitted(form);
1677 1688
1678 // JavaScript cleared field values. 1689 // JavaScript cleared field values.
1679 observed[0].password_value.clear(); 1690 observed[0].password_value.clear();
1680 observed[0].new_password_value.clear(); 1691 observed[0].new_password_value.clear();
1681 1692
1682 // Check success of the submission. 1693 // Check success of the submission.
1683 std::unique_ptr<PasswordFormManager> form_manager_to_save; 1694 scoped_refptr<PasswordFormManager> form_manager_to_save;
1684 EXPECT_CALL(client_, PromptUserToSaveOrUpdatePasswordPtr(_)) 1695 EXPECT_CALL(client_, PromptUserToSaveOrUpdatePassword(_, _))
1685 .WillOnce(WithArg<0>(SaveToScopedPtr(&form_manager_to_save))); 1696 .WillOnce(
1697 DoAll(WithArg<0>(SaveArg<0>(&form_manager_to_save)), Return(false)));
1686 1698
1687 manager()->OnPasswordFormsParsed(&driver_, observed); 1699 manager()->OnPasswordFormsParsed(&driver_, observed);
1688 manager()->OnPasswordFormsRendered(&driver_, observed, true); 1700 manager()->OnPasswordFormsRendered(&driver_, observed, true);
1689 } 1701 }
1690 1702
1691 } // namespace password_manager 1703 } // namespace password_manager
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698