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 <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
11 #include "base/prefs/pref_registry_simple.h" | 11 #include "base/prefs/pref_registry_simple.h" |
12 #include "base/prefs/pref_service.h" | 12 #include "base/prefs/pref_service.h" |
13 #include "base/prefs/testing_pref_service.h" | 13 #include "base/prefs/testing_pref_service.h" |
14 #include "base/strings/string_util.h" | 14 #include "base/strings/string_util.h" |
15 #include "base/strings/utf_string_conversions.h" | 15 #include "base/strings/utf_string_conversions.h" |
16 #include "components/password_manager/core/browser/mock_password_store.h" | 16 #include "components/password_manager/core/browser/mock_password_store.h" |
17 #include "components/password_manager/core/browser/password_autofill_manager.h" | 17 #include "components/password_manager/core/browser/password_autofill_manager.h" |
18 #include "components/password_manager/core/browser/password_manager_driver.h" | 18 #include "components/password_manager/core/browser/password_manager_driver.h" |
19 #include "components/password_manager/core/browser/password_store.h" | 19 #include "components/password_manager/core/browser/password_store.h" |
20 #include "components/password_manager/core/browser/stub_password_manager_client.
h" | 20 #include "components/password_manager/core/browser/stub_password_manager_client.
h" |
21 #include "components/password_manager/core/browser/stub_password_manager_driver.
h" | 21 #include "components/password_manager/core/browser/stub_password_manager_driver.
h" |
22 #include "components/password_manager/core/common/password_manager_pref_names.h" | 22 #include "components/password_manager/core/common/password_manager_pref_names.h" |
23 #include "testing/gmock/include/gmock/gmock.h" | 23 #include "testing/gmock/include/gmock/gmock.h" |
24 #include "testing/gtest/include/gtest/gtest.h" | 24 #include "testing/gtest/include/gtest/gtest.h" |
25 | 25 |
26 using autofill::PasswordForm; | 26 using autofill::PasswordForm; |
27 using base::ASCIIToUTF16; | 27 using base::ASCIIToUTF16; |
28 using testing::_; | 28 using testing::_; |
29 using testing::AnyNumber; | 29 using testing::AnyNumber; |
30 using testing::DoAll; | |
31 using testing::Exactly; | 30 using testing::Exactly; |
32 using testing::Return; | 31 using testing::Return; |
33 using testing::WithArg; | 32 using testing::WithArg; |
34 | 33 |
35 namespace password_manager { | 34 namespace password_manager { |
36 | 35 |
37 namespace { | 36 namespace { |
38 | 37 |
39 class MockPasswordManagerClient : public StubPasswordManagerClient { | 38 class MockPasswordManagerClient : public StubPasswordManagerClient { |
40 public: | 39 public: |
(...skipping 19 matching lines...) Expand all Loading... |
60 } | 59 } |
61 }; | 60 }; |
62 | 61 |
63 class MockPasswordManagerDriver : public StubPasswordManagerDriver { | 62 class MockPasswordManagerDriver : public StubPasswordManagerDriver { |
64 public: | 63 public: |
65 MOCK_METHOD1(FillPasswordForm, void(const autofill::PasswordFormFillData&)); | 64 MOCK_METHOD1(FillPasswordForm, void(const autofill::PasswordFormFillData&)); |
66 MOCK_METHOD0(GetPasswordManager, PasswordManager*()); | 65 MOCK_METHOD0(GetPasswordManager, PasswordManager*()); |
67 MOCK_METHOD0(GetPasswordAutofillManager, PasswordAutofillManager*()); | 66 MOCK_METHOD0(GetPasswordAutofillManager, PasswordAutofillManager*()); |
68 }; | 67 }; |
69 | 68 |
70 ACTION_P(InvokeConsumer, forms) { arg0->OnGetPasswordStoreResults(forms); } | 69 ACTION_P(InvokeConsumer, forms) { |
| 70 arg0->OnGetPasswordStoreResults(forms->Pass()); |
| 71 } |
| 72 |
| 73 ACTION(InvokeEmptyConsumer) { |
| 74 arg0->OnGetPasswordStoreResults(ScopedVector<autofill::PasswordForm>()); |
| 75 } |
71 | 76 |
72 ACTION_P(SaveToScopedPtr, scoped) { scoped->reset(arg0); } | 77 ACTION_P(SaveToScopedPtr, scoped) { scoped->reset(arg0); } |
73 | 78 |
74 class TestPasswordManager : public PasswordManager { | 79 class TestPasswordManager : public PasswordManager { |
75 public: | 80 public: |
76 explicit TestPasswordManager(PasswordManagerClient* client) | 81 explicit TestPasswordManager(PasswordManagerClient* client) |
77 : PasswordManager(client) {} | 82 : PasswordManager(client) {} |
78 ~TestPasswordManager() override {} | 83 ~TestPasswordManager() override {} |
79 | 84 |
80 private: | 85 private: |
81 DISALLOW_COPY_AND_ASSIGN(TestPasswordManager); | 86 DISALLOW_COPY_AND_ASSIGN(TestPasswordManager); |
82 }; | 87 }; |
83 | 88 |
84 } // namespace | 89 } // namespace |
85 | 90 |
86 class PasswordManagerTest : public testing::Test { | 91 class PasswordManagerTest : public testing::Test { |
87 protected: | 92 protected: |
88 void SetUp() override { | 93 void SetUp() override { |
89 prefs_.registry()->RegisterBooleanPref(prefs::kPasswordManagerSavingEnabled, | 94 prefs_.registry()->RegisterBooleanPref(prefs::kPasswordManagerSavingEnabled, |
90 true); | 95 true); |
91 | 96 |
92 store_ = new MockPasswordStore; | 97 store_ = new MockPasswordStore; |
93 EXPECT_CALL(*store_.get(), ReportMetrics(_, _)).Times(AnyNumber()); | 98 EXPECT_CALL(*store_, ReportMetrics(_, _)).Times(AnyNumber()); |
94 CHECK(store_->Init(syncer::SyncableService::StartSyncFlare())); | 99 CHECK(store_->Init(syncer::SyncableService::StartSyncFlare())); |
95 | 100 |
96 EXPECT_CALL(client_, IsPasswordManagerEnabledForCurrentPage()) | 101 EXPECT_CALL(client_, IsPasswordManagerEnabledForCurrentPage()) |
97 .WillRepeatedly(Return(true)); | 102 .WillRepeatedly(Return(true)); |
98 EXPECT_CALL(client_, IsSyncAccountCredential(_, _)) | 103 EXPECT_CALL(client_, IsSyncAccountCredential(_, _)) |
99 .WillRepeatedly(Return(false)); | 104 .WillRepeatedly(Return(false)); |
100 EXPECT_CALL(client_, GetPasswordStore()) | 105 EXPECT_CALL(client_, GetPasswordStore()) |
101 .WillRepeatedly(Return(store_.get())); | 106 .WillRepeatedly(Return(store_.get())); |
102 EXPECT_CALL(client_, GetPrefs()).WillRepeatedly(Return(&prefs_)); | 107 EXPECT_CALL(client_, GetPrefs()).WillRepeatedly(Return(&prefs_)); |
103 EXPECT_CALL(client_, GetDriver()).WillRepeatedly(Return(&driver_)); | 108 EXPECT_CALL(client_, GetDriver()).WillRepeatedly(Return(&driver_)); |
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
235 form.action == arg.action && | 240 form.action == arg.action && |
236 form.username_element == arg.username_element && | 241 form.username_element == arg.username_element && |
237 form.password_element == arg.password_element && | 242 form.password_element == arg.password_element && |
238 form.new_password_element == arg.new_password_element && | 243 form.new_password_element == arg.new_password_element && |
239 form.password_autocomplete_set == arg.password_autocomplete_set && | 244 form.password_autocomplete_set == arg.password_autocomplete_set && |
240 form.submit_element == arg.submit_element; | 245 form.submit_element == arg.submit_element; |
241 } | 246 } |
242 | 247 |
243 TEST_F(PasswordManagerTest, FormSubmitEmptyStore) { | 248 TEST_F(PasswordManagerTest, FormSubmitEmptyStore) { |
244 // Test that observing a newly submitted form shows the save password bar. | 249 // Test that observing a newly submitted form shows the save password bar. |
245 std::vector<PasswordForm*> result; // Empty password store. | |
246 EXPECT_CALL(driver_, FillPasswordForm(_)).Times(Exactly(0)); | 250 EXPECT_CALL(driver_, FillPasswordForm(_)).Times(Exactly(0)); |
247 EXPECT_CALL(*store_.get(), GetLogins(_, _, _)) | 251 EXPECT_CALL(*store_, GetLogins(_, _, _)) |
248 .WillOnce(DoAll(WithArg<2>(InvokeConsumer(result)), Return())); | 252 .WillOnce(WithArg<2>(InvokeEmptyConsumer())); |
249 std::vector<PasswordForm> observed; | 253 std::vector<PasswordForm> observed; |
250 PasswordForm form(MakeSimpleForm()); | 254 PasswordForm form(MakeSimpleForm()); |
251 observed.push_back(form); | 255 observed.push_back(form); |
252 // The initial load. | 256 // The initial load. |
253 manager()->OnPasswordFormsParsed(&driver_, observed); | 257 manager()->OnPasswordFormsParsed(&driver_, observed); |
254 // The initial layout. | 258 // The initial layout. |
255 manager()->OnPasswordFormsRendered(&driver_, observed, true); | 259 manager()->OnPasswordFormsRendered(&driver_, observed, true); |
256 | 260 |
257 // And the form submit contract is to call ProvisionallySavePassword. | 261 // And the form submit contract is to call ProvisionallySavePassword. |
258 manager()->ProvisionallySavePassword(form); | 262 manager()->ProvisionallySavePassword(form); |
259 | 263 |
260 scoped_ptr<PasswordFormManager> form_to_save; | 264 scoped_ptr<PasswordFormManager> form_to_save; |
261 EXPECT_CALL(client_, PromptUserToSavePasswordPtr(_)) | 265 EXPECT_CALL(client_, PromptUserToSavePasswordPtr(_)) |
262 .WillOnce(WithArg<0>(SaveToScopedPtr(&form_to_save))); | 266 .WillOnce(WithArg<0>(SaveToScopedPtr(&form_to_save))); |
263 | 267 |
264 // Now the password manager waits for the navigation to complete. | 268 // Now the password manager waits for the navigation to complete. |
265 observed.clear(); | 269 observed.clear(); |
266 // The post-navigation load. | 270 // The post-navigation load. |
267 manager()->OnPasswordFormsParsed(&driver_, observed); | 271 manager()->OnPasswordFormsParsed(&driver_, observed); |
268 // The post-navigation layout. | 272 // The post-navigation layout. |
269 manager()->OnPasswordFormsRendered(&driver_, observed, true); | 273 manager()->OnPasswordFormsRendered(&driver_, observed, true); |
270 | 274 |
271 ASSERT_TRUE(form_to_save.get()); | 275 ASSERT_TRUE(form_to_save.get()); |
272 EXPECT_CALL(*store_.get(), AddLogin(FormMatches(form))); | 276 EXPECT_CALL(*store_, AddLogin(FormMatches(form))); |
273 | 277 |
274 // Simulate saving the form, as if the info bar was accepted. | 278 // Simulate saving the form, as if the info bar was accepted. |
275 form_to_save->Save(); | 279 form_to_save->Save(); |
276 } | 280 } |
277 | 281 |
278 TEST_F(PasswordManagerTest, FormSubmitWithOnlyNewPasswordField) { | 282 TEST_F(PasswordManagerTest, FormSubmitWithOnlyNewPasswordField) { |
279 // This test is the same as FormSubmitEmptyStore, except that it simulates the | 283 // This test is the same as FormSubmitEmptyStore, except that it simulates the |
280 // user entering credentials into a sign-up form that only has a new password | 284 // user entering credentials into a sign-up form that only has a new password |
281 // field. | 285 // field. |
282 EXPECT_CALL(driver_, FillPasswordForm(_)).Times(Exactly(0)); | 286 EXPECT_CALL(driver_, FillPasswordForm(_)).Times(Exactly(0)); |
(...skipping 12 matching lines...) Expand all Loading... |
295 | 299 |
296 // Now the password manager waits for the navigation to complete. | 300 // Now the password manager waits for the navigation to complete. |
297 observed.clear(); | 301 observed.clear(); |
298 manager()->OnPasswordFormsParsed(&driver_, observed); | 302 manager()->OnPasswordFormsParsed(&driver_, observed); |
299 manager()->OnPasswordFormsRendered(&driver_, observed, true); | 303 manager()->OnPasswordFormsRendered(&driver_, observed, true); |
300 | 304 |
301 ASSERT_TRUE(form_to_save.get()); | 305 ASSERT_TRUE(form_to_save.get()); |
302 | 306 |
303 // Simulate saving the form, as if the info bar was accepted. | 307 // Simulate saving the form, as if the info bar was accepted. |
304 PasswordForm saved_form; | 308 PasswordForm saved_form; |
305 EXPECT_CALL(*store_.get(), AddLogin(_)) | 309 EXPECT_CALL(*store_, AddLogin(_)).WillOnce(testing::SaveArg<0>(&saved_form)); |
306 .WillOnce(testing::SaveArg<0>(&saved_form)); | |
307 form_to_save->Save(); | 310 form_to_save->Save(); |
308 | 311 |
309 // The value of the new password field should have been promoted to, and saved | 312 // The value of the new password field should have been promoted to, and saved |
310 // to the password store as the current password, and no password element name | 313 // to the password store as the current password, and no password element name |
311 // should have been saved. | 314 // should have been saved. |
312 PasswordForm expected_form(form); | 315 PasswordForm expected_form(form); |
313 expected_form.password_value.swap(expected_form.new_password_value); | 316 expected_form.password_value.swap(expected_form.new_password_value); |
314 expected_form.new_password_element.clear(); | 317 expected_form.new_password_element.clear(); |
315 EXPECT_THAT(saved_form, FormMatches(expected_form)); | 318 EXPECT_THAT(saved_form, FormMatches(expected_form)); |
316 EXPECT_EQ(expected_form.password_value, saved_form.password_value); | 319 EXPECT_EQ(expected_form.password_value, saved_form.password_value); |
317 EXPECT_EQ(expected_form.new_password_value, saved_form.new_password_value); | 320 EXPECT_EQ(expected_form.new_password_value, saved_form.new_password_value); |
318 } | 321 } |
319 | 322 |
320 TEST_F(PasswordManagerTest, GeneratedPasswordFormSubmitEmptyStore) { | 323 TEST_F(PasswordManagerTest, GeneratedPasswordFormSubmitEmptyStore) { |
321 // This test is the same as FormSubmitEmptyStore, except that it simulates the | 324 // This test is the same as FormSubmitEmptyStore, except that it simulates the |
322 // user generating the password through the browser. | 325 // user generating the password through the browser. |
323 std::vector<PasswordForm*> result; // Empty password store. | |
324 EXPECT_CALL(driver_, FillPasswordForm(_)).Times(Exactly(0)); | 326 EXPECT_CALL(driver_, FillPasswordForm(_)).Times(Exactly(0)); |
325 EXPECT_CALL(*store_.get(), GetLogins(_, _, _)) | 327 EXPECT_CALL(*store_, GetLogins(_, _, _)) |
326 .WillOnce(DoAll(WithArg<2>(InvokeConsumer(result)), Return())); | 328 .WillOnce(WithArg<2>(InvokeEmptyConsumer())); |
327 std::vector<PasswordForm> observed; | 329 std::vector<PasswordForm> observed; |
328 PasswordForm form(MakeSimpleForm()); | 330 PasswordForm form(MakeSimpleForm()); |
329 observed.push_back(form); | 331 observed.push_back(form); |
330 // The initial load. | 332 // The initial load. |
331 manager()->OnPasswordFormsParsed(&driver_, observed); | 333 manager()->OnPasswordFormsParsed(&driver_, observed); |
332 // The initial layout. | 334 // The initial layout. |
333 manager()->OnPasswordFormsRendered(&driver_, observed, true); | 335 manager()->OnPasswordFormsRendered(&driver_, observed, true); |
334 | 336 |
335 // Simulate the user generating the password and submitting the form. | 337 // Simulate the user generating the password and submitting the form. |
336 manager()->SetFormHasGeneratedPassword(&driver_, form); | 338 manager()->SetFormHasGeneratedPassword(&driver_, form); |
337 manager()->ProvisionallySavePassword(form); | 339 manager()->ProvisionallySavePassword(form); |
338 | 340 |
339 // The user should not be presented with an infobar as they have already given | 341 // The user should not be presented with an infobar as they have already given |
340 // consent by using the generated password. The form should be saved once | 342 // consent by using the generated password. The form should be saved once |
341 // navigation occurs. The client will be informed that automatic saving has | 343 // navigation occurs. The client will be informed that automatic saving has |
342 // occured. | 344 // occured. |
343 EXPECT_CALL(client_, PromptUserToSavePasswordPtr(_)).Times(Exactly(0)); | 345 EXPECT_CALL(client_, PromptUserToSavePasswordPtr(_)).Times(Exactly(0)); |
344 EXPECT_CALL(*store_.get(), AddLogin(FormMatches(form))); | 346 EXPECT_CALL(*store_, AddLogin(FormMatches(form))); |
345 scoped_ptr<PasswordFormManager> saved_form_manager; | 347 scoped_ptr<PasswordFormManager> saved_form_manager; |
346 EXPECT_CALL(client_, AutomaticPasswordSavePtr(_)) | 348 EXPECT_CALL(client_, AutomaticPasswordSavePtr(_)) |
347 .Times(Exactly(1)) | 349 .Times(Exactly(1)) |
348 .WillOnce(WithArg<0>(SaveToScopedPtr(&saved_form_manager))); | 350 .WillOnce(WithArg<0>(SaveToScopedPtr(&saved_form_manager))); |
349 | 351 |
350 // Now the password manager waits for the navigation to complete. | 352 // Now the password manager waits for the navigation to complete. |
351 observed.clear(); | 353 observed.clear(); |
352 manager()->OnPasswordFormsParsed(&driver_, | 354 manager()->OnPasswordFormsParsed(&driver_, |
353 observed); // The post-navigation load. | 355 observed); // The post-navigation load. |
354 manager()->OnPasswordFormsRendered(&driver_, observed, | 356 manager()->OnPasswordFormsRendered(&driver_, observed, |
355 true); // The post-navigation layout. | 357 true); // The post-navigation layout. |
356 } | 358 } |
357 | 359 |
358 TEST_F(PasswordManagerTest, FormSubmitNoGoodMatch) { | 360 TEST_F(PasswordManagerTest, FormSubmitNoGoodMatch) { |
359 // Same as above, except with an existing form for the same signon realm, | 361 // Same as above, except with an existing form for the same signon realm, |
360 // but different origin. Detailed cases like this are covered by | 362 // but different origin. Detailed cases like this are covered by |
361 // PasswordFormManagerTest. | 363 // PasswordFormManagerTest. |
362 std::vector<PasswordForm*> result; | 364 ScopedVector<PasswordForm> result; |
363 PasswordForm* existing_different = new PasswordForm(MakeSimpleForm()); | 365 scoped_ptr<PasswordForm> existing_different( |
| 366 new PasswordForm(MakeSimpleForm())); |
364 existing_different->username_value = ASCIIToUTF16("google2"); | 367 existing_different->username_value = ASCIIToUTF16("google2"); |
365 result.push_back(existing_different); | 368 result.push_back(existing_different.release()); |
366 EXPECT_CALL(driver_, FillPasswordForm(_)).Times(2); | 369 EXPECT_CALL(driver_, FillPasswordForm(_)).Times(2); |
367 EXPECT_CALL(*store_.get(), GetLogins(_, _, _)) | 370 EXPECT_CALL(*store_, GetLogins(_, _, _)) |
368 .WillOnce(DoAll(WithArg<2>(InvokeConsumer(result)), Return())); | 371 .WillOnce(WithArg<2>(InvokeConsumer(&result))); |
369 | 372 |
370 std::vector<PasswordForm> observed; | 373 std::vector<PasswordForm> observed; |
371 PasswordForm form(MakeSimpleForm()); | 374 PasswordForm form(MakeSimpleForm()); |
372 observed.push_back(form); | 375 observed.push_back(form); |
373 manager()->OnPasswordFormsParsed(&driver_, observed); // The initial load. | 376 manager()->OnPasswordFormsParsed(&driver_, observed); // The initial load. |
374 manager()->OnPasswordFormsRendered(&driver_, observed, | 377 manager()->OnPasswordFormsRendered(&driver_, observed, |
375 true); // The initial layout. | 378 true); // The initial layout. |
376 manager()->ProvisionallySavePassword(form); | 379 manager()->ProvisionallySavePassword(form); |
377 | 380 |
378 // We still expect an add, since we didn't have a good match. | 381 // We still expect an add, since we didn't have a good match. |
379 scoped_ptr<PasswordFormManager> form_to_save; | 382 scoped_ptr<PasswordFormManager> form_to_save; |
380 EXPECT_CALL(client_, PromptUserToSavePasswordPtr(_)) | 383 EXPECT_CALL(client_, PromptUserToSavePasswordPtr(_)) |
381 .WillOnce(WithArg<0>(SaveToScopedPtr(&form_to_save))); | 384 .WillOnce(WithArg<0>(SaveToScopedPtr(&form_to_save))); |
382 | 385 |
383 // Now the password manager waits for the navigation to complete. | 386 // Now the password manager waits for the navigation to complete. |
384 observed.clear(); | 387 observed.clear(); |
385 manager()->OnPasswordFormsParsed(&driver_, | 388 manager()->OnPasswordFormsParsed(&driver_, |
386 observed); // The post-navigation load. | 389 observed); // The post-navigation load. |
387 manager()->OnPasswordFormsRendered(&driver_, observed, | 390 manager()->OnPasswordFormsRendered(&driver_, observed, |
388 true); // The post-navigation layout. | 391 true); // The post-navigation layout. |
389 | 392 |
390 ASSERT_TRUE(form_to_save.get()); | 393 ASSERT_TRUE(form_to_save.get()); |
391 EXPECT_CALL(*store_.get(), AddLogin(FormMatches(form))); | 394 EXPECT_CALL(*store_, AddLogin(FormMatches(form))); |
392 | 395 |
393 // Simulate saving the form. | 396 // Simulate saving the form. |
394 form_to_save->Save(); | 397 form_to_save->Save(); |
395 } | 398 } |
396 | 399 |
397 TEST_F(PasswordManagerTest, FormSeenThenLeftPage) { | 400 TEST_F(PasswordManagerTest, FormSeenThenLeftPage) { |
398 std::vector<PasswordForm*> result; // Empty password store. | |
399 EXPECT_CALL(driver_, FillPasswordForm(_)).Times(Exactly(0)); | 401 EXPECT_CALL(driver_, FillPasswordForm(_)).Times(Exactly(0)); |
400 EXPECT_CALL(*store_.get(), GetLogins(_, _, _)) | 402 EXPECT_CALL(*store_, GetLogins(_, _, _)) |
401 .WillOnce(DoAll(WithArg<2>(InvokeConsumer(result)), Return())); | 403 .WillOnce(WithArg<2>(InvokeEmptyConsumer())); |
402 std::vector<PasswordForm> observed; | 404 std::vector<PasswordForm> observed; |
403 PasswordForm form(MakeSimpleForm()); | 405 PasswordForm form(MakeSimpleForm()); |
404 observed.push_back(form); | 406 observed.push_back(form); |
405 manager()->OnPasswordFormsParsed(&driver_, observed); // The initial load. | 407 manager()->OnPasswordFormsParsed(&driver_, observed); // The initial load. |
406 manager()->OnPasswordFormsRendered(&driver_, observed, | 408 manager()->OnPasswordFormsRendered(&driver_, observed, |
407 true); // The initial layout. | 409 true); // The initial layout. |
408 | 410 |
409 // No message from the renderer that a password was submitted. No | 411 // No message from the renderer that a password was submitted. No |
410 // expected calls. | 412 // expected calls. |
411 EXPECT_CALL(client_, PromptUserToSavePasswordPtr(_)).Times(0); | 413 EXPECT_CALL(client_, PromptUserToSavePasswordPtr(_)).Times(0); |
412 observed.clear(); | 414 observed.clear(); |
413 manager()->OnPasswordFormsParsed(&driver_, | 415 manager()->OnPasswordFormsParsed(&driver_, |
414 observed); // The post-navigation load. | 416 observed); // The post-navigation load. |
415 manager()->OnPasswordFormsRendered(&driver_, observed, | 417 manager()->OnPasswordFormsRendered(&driver_, observed, |
416 true); // The post-navigation layout. | 418 true); // The post-navigation layout. |
417 } | 419 } |
418 | 420 |
419 TEST_F(PasswordManagerTest, FormSubmitAfterNavigateInPage) { | 421 TEST_F(PasswordManagerTest, FormSubmitAfterNavigateInPage) { |
420 // Test that navigating in the page does not prevent us from showing the save | 422 // Test that navigating in the page does not prevent us from showing the save |
421 // password infobar. | 423 // password infobar. |
422 std::vector<PasswordForm*> result; // Empty password store. | |
423 EXPECT_CALL(driver_, FillPasswordForm(_)).Times(Exactly(0)); | 424 EXPECT_CALL(driver_, FillPasswordForm(_)).Times(Exactly(0)); |
424 EXPECT_CALL(*store_.get(), GetLogins(_, _, _)) | 425 EXPECT_CALL(*store_, GetLogins(_, _, _)) |
425 .WillOnce(DoAll(WithArg<2>(InvokeConsumer(result)), Return())); | 426 .WillOnce(WithArg<2>(InvokeEmptyConsumer())); |
426 std::vector<PasswordForm> observed; | 427 std::vector<PasswordForm> observed; |
427 PasswordForm form(MakeSimpleForm()); | 428 PasswordForm form(MakeSimpleForm()); |
428 observed.push_back(form); | 429 observed.push_back(form); |
429 manager()->OnPasswordFormsParsed(&driver_, observed); // The initial load. | 430 manager()->OnPasswordFormsParsed(&driver_, observed); // The initial load. |
430 manager()->OnPasswordFormsRendered(&driver_, observed, | 431 manager()->OnPasswordFormsRendered(&driver_, observed, |
431 true); // The initial layout. | 432 true); // The initial layout. |
432 | 433 |
433 // Simulate submitting the password. | 434 // Simulate submitting the password. |
434 OnPasswordFormSubmitted(form); | 435 OnPasswordFormSubmitted(form); |
435 | 436 |
436 // Now the password manager waits for the navigation to complete. | 437 // Now the password manager waits for the navigation to complete. |
437 scoped_ptr<PasswordFormManager> form_to_save; | 438 scoped_ptr<PasswordFormManager> form_to_save; |
438 EXPECT_CALL(client_, PromptUserToSavePasswordPtr(_)) | 439 EXPECT_CALL(client_, PromptUserToSavePasswordPtr(_)) |
439 .WillOnce(WithArg<0>(SaveToScopedPtr(&form_to_save))); | 440 .WillOnce(WithArg<0>(SaveToScopedPtr(&form_to_save))); |
440 | 441 |
441 observed.clear(); | 442 observed.clear(); |
442 manager()->OnPasswordFormsParsed(&driver_, | 443 manager()->OnPasswordFormsParsed(&driver_, |
443 observed); // The post-navigation load. | 444 observed); // The post-navigation load. |
444 manager()->OnPasswordFormsRendered(&driver_, observed, | 445 manager()->OnPasswordFormsRendered(&driver_, observed, |
445 true); // The post-navigation layout. | 446 true); // The post-navigation layout. |
446 | 447 |
447 ASSERT_FALSE(NULL == form_to_save.get()); | 448 ASSERT_FALSE(NULL == form_to_save.get()); |
448 EXPECT_CALL(*store_.get(), AddLogin(FormMatches(form))); | 449 EXPECT_CALL(*store_, AddLogin(FormMatches(form))); |
449 | 450 |
450 // Simulate saving the form, as if the info bar was accepted. | 451 // Simulate saving the form, as if the info bar was accepted. |
451 form_to_save->Save(); | 452 form_to_save->Save(); |
452 } | 453 } |
453 | 454 |
454 // This test verifies a fix for http://crbug.com/236673 | 455 // This test verifies a fix for http://crbug.com/236673 |
455 TEST_F(PasswordManagerTest, FormSubmitWithFormOnPreviousPage) { | 456 TEST_F(PasswordManagerTest, FormSubmitWithFormOnPreviousPage) { |
456 std::vector<PasswordForm*> result; // Empty password store. | |
457 EXPECT_CALL(driver_, FillPasswordForm(_)).Times(Exactly(0)); | 457 EXPECT_CALL(driver_, FillPasswordForm(_)).Times(Exactly(0)); |
458 EXPECT_CALL(*store_.get(), GetLogins(_, _, _)) | 458 EXPECT_CALL(*store_, GetLogins(_, _, _)) |
459 .WillRepeatedly(DoAll(WithArg<2>(InvokeConsumer(result)), Return())); | 459 .WillRepeatedly(WithArg<2>(InvokeEmptyConsumer())); |
460 PasswordForm first_form(MakeSimpleForm()); | 460 PasswordForm first_form(MakeSimpleForm()); |
461 first_form.origin = GURL("http://www.nytimes.com/"); | 461 first_form.origin = GURL("http://www.nytimes.com/"); |
462 first_form.action = GURL("https://myaccount.nytimes.com/auth/login"); | 462 first_form.action = GURL("https://myaccount.nytimes.com/auth/login"); |
463 first_form.signon_realm = "http://www.nytimes.com/"; | 463 first_form.signon_realm = "http://www.nytimes.com/"; |
464 PasswordForm second_form(MakeSimpleForm()); | 464 PasswordForm second_form(MakeSimpleForm()); |
465 second_form.origin = GURL("https://myaccount.nytimes.com/auth/login"); | 465 second_form.origin = GURL("https://myaccount.nytimes.com/auth/login"); |
466 second_form.action = GURL("https://myaccount.nytimes.com/auth/login"); | 466 second_form.action = GURL("https://myaccount.nytimes.com/auth/login"); |
467 second_form.signon_realm = "https://myaccount.nytimes.com/"; | 467 second_form.signon_realm = "https://myaccount.nytimes.com/"; |
468 | 468 |
469 // Pretend that the form is hidden on the first page. | 469 // Pretend that the form is hidden on the first page. |
(...skipping 18 matching lines...) Expand all Loading... |
488 // Navigation after form submit. | 488 // Navigation after form submit. |
489 scoped_ptr<PasswordFormManager> form_to_save; | 489 scoped_ptr<PasswordFormManager> form_to_save; |
490 EXPECT_CALL(client_, PromptUserToSavePasswordPtr(_)) | 490 EXPECT_CALL(client_, PromptUserToSavePasswordPtr(_)) |
491 .WillOnce(WithArg<0>(SaveToScopedPtr(&form_to_save))); | 491 .WillOnce(WithArg<0>(SaveToScopedPtr(&form_to_save))); |
492 observed.clear(); | 492 observed.clear(); |
493 manager()->OnPasswordFormsParsed(&driver_, observed); | 493 manager()->OnPasswordFormsParsed(&driver_, observed); |
494 manager()->OnPasswordFormsRendered(&driver_, observed, true); | 494 manager()->OnPasswordFormsRendered(&driver_, observed, true); |
495 | 495 |
496 // Make sure that the saved form matches the second form, not the first. | 496 // Make sure that the saved form matches the second form, not the first. |
497 ASSERT_TRUE(form_to_save.get()); | 497 ASSERT_TRUE(form_to_save.get()); |
498 EXPECT_CALL(*store_.get(), AddLogin(FormMatches(second_form))); | 498 EXPECT_CALL(*store_, AddLogin(FormMatches(second_form))); |
499 | 499 |
500 // Simulate saving the form, as if the info bar was accepted. | 500 // Simulate saving the form, as if the info bar was accepted. |
501 form_to_save->Save(); | 501 form_to_save->Save(); |
502 } | 502 } |
503 | 503 |
504 TEST_F(PasswordManagerTest, FormSubmitFailedLogin) { | 504 TEST_F(PasswordManagerTest, FormSubmitFailedLogin) { |
505 std::vector<PasswordForm*> result; // Empty password store. | |
506 EXPECT_CALL(driver_, FillPasswordForm(_)).Times(Exactly(0)); | 505 EXPECT_CALL(driver_, FillPasswordForm(_)).Times(Exactly(0)); |
507 EXPECT_CALL(*store_.get(), GetLogins(_, _, _)) | 506 EXPECT_CALL(*store_, GetLogins(_, _, _)) |
508 .WillRepeatedly(DoAll(WithArg<2>(InvokeConsumer(result)), Return())); | 507 .WillRepeatedly(WithArg<2>(InvokeEmptyConsumer())); |
509 std::vector<PasswordForm> observed; | 508 std::vector<PasswordForm> observed; |
510 PasswordForm form(MakeSimpleForm()); | 509 PasswordForm form(MakeSimpleForm()); |
511 observed.push_back(form); | 510 observed.push_back(form); |
512 manager()->OnPasswordFormsParsed(&driver_, observed); // The initial load. | 511 manager()->OnPasswordFormsParsed(&driver_, observed); // The initial load. |
513 manager()->OnPasswordFormsRendered(&driver_, observed, | 512 manager()->OnPasswordFormsRendered(&driver_, observed, |
514 true); // The initial layout. | 513 true); // The initial layout. |
515 | 514 |
516 manager()->ProvisionallySavePassword(form); | 515 manager()->ProvisionallySavePassword(form); |
517 | 516 |
518 // The form reappears, and is visible in the layout: | 517 // The form reappears, and is visible in the layout: |
519 // No expected calls to the PasswordStore... | 518 // No expected calls to the PasswordStore... |
520 manager()->OnPasswordFormsParsed(&driver_, observed); | 519 manager()->OnPasswordFormsParsed(&driver_, observed); |
521 manager()->OnPasswordFormsRendered(&driver_, observed, true); | 520 manager()->OnPasswordFormsRendered(&driver_, observed, true); |
522 } | 521 } |
523 | 522 |
524 TEST_F(PasswordManagerTest, FormSubmitInvisibleLogin) { | 523 TEST_F(PasswordManagerTest, FormSubmitInvisibleLogin) { |
525 // Tests fix of issue 28911: if the login form reappears on the subsequent | 524 // Tests fix of issue 28911: if the login form reappears on the subsequent |
526 // page, but is invisible, it shouldn't count as a failed login. | 525 // page, but is invisible, it shouldn't count as a failed login. |
527 std::vector<PasswordForm*> result; // Empty password store. | |
528 EXPECT_CALL(driver_, FillPasswordForm(_)).Times(Exactly(0)); | 526 EXPECT_CALL(driver_, FillPasswordForm(_)).Times(Exactly(0)); |
529 EXPECT_CALL(*store_.get(), GetLogins(_, _, _)) | 527 EXPECT_CALL(*store_, GetLogins(_, _, _)) |
530 .WillRepeatedly(DoAll(WithArg<2>(InvokeConsumer(result)), Return())); | 528 .WillRepeatedly(WithArg<2>(InvokeEmptyConsumer())); |
531 std::vector<PasswordForm> observed; | 529 std::vector<PasswordForm> observed; |
532 PasswordForm form(MakeSimpleForm()); | 530 PasswordForm form(MakeSimpleForm()); |
533 observed.push_back(form); | 531 observed.push_back(form); |
534 manager()->OnPasswordFormsParsed(&driver_, observed); // The initial load. | 532 manager()->OnPasswordFormsParsed(&driver_, observed); // The initial load. |
535 manager()->OnPasswordFormsRendered(&driver_, observed, | 533 manager()->OnPasswordFormsRendered(&driver_, observed, |
536 true); // The initial layout. | 534 true); // The initial layout. |
537 | 535 |
538 manager()->ProvisionallySavePassword(form); | 536 manager()->ProvisionallySavePassword(form); |
539 | 537 |
540 // Expect info bar to appear: | 538 // Expect info bar to appear: |
541 scoped_ptr<PasswordFormManager> form_to_save; | 539 scoped_ptr<PasswordFormManager> form_to_save; |
542 EXPECT_CALL(client_, PromptUserToSavePasswordPtr(_)) | 540 EXPECT_CALL(client_, PromptUserToSavePasswordPtr(_)) |
543 .WillOnce(WithArg<0>(SaveToScopedPtr(&form_to_save))); | 541 .WillOnce(WithArg<0>(SaveToScopedPtr(&form_to_save))); |
544 | 542 |
545 // The form reappears, but is not visible in the layout: | 543 // The form reappears, but is not visible in the layout: |
546 manager()->OnPasswordFormsParsed(&driver_, observed); | 544 manager()->OnPasswordFormsParsed(&driver_, observed); |
547 observed.clear(); | 545 observed.clear(); |
548 manager()->OnPasswordFormsRendered(&driver_, observed, true); | 546 manager()->OnPasswordFormsRendered(&driver_, observed, true); |
549 | 547 |
550 ASSERT_TRUE(form_to_save.get()); | 548 ASSERT_TRUE(form_to_save.get()); |
551 EXPECT_CALL(*store_.get(), AddLogin(FormMatches(form))); | 549 EXPECT_CALL(*store_, AddLogin(FormMatches(form))); |
552 | 550 |
553 // Simulate saving the form. | 551 // Simulate saving the form. |
554 form_to_save->Save(); | 552 form_to_save->Save(); |
555 } | 553 } |
556 | 554 |
557 TEST_F(PasswordManagerTest, InitiallyInvisibleForm) { | 555 TEST_F(PasswordManagerTest, InitiallyInvisibleForm) { |
558 // Make sure an invisible login form still gets autofilled. | 556 // Make sure an invisible login form still gets autofilled. |
559 std::vector<PasswordForm*> result; | 557 ScopedVector<PasswordForm> result; |
560 PasswordForm* existing = new PasswordForm(MakeSimpleForm()); | 558 result.push_back(new PasswordForm(MakeSimpleForm())); |
561 result.push_back(existing); | |
562 EXPECT_CALL(driver_, FillPasswordForm(_)); | 559 EXPECT_CALL(driver_, FillPasswordForm(_)); |
563 EXPECT_CALL(*store_.get(), GetLogins(_, _, _)) | 560 EXPECT_CALL(*store_, GetLogins(_, _, _)) |
564 .WillOnce(DoAll(WithArg<2>(InvokeConsumer(result)), Return())); | 561 .WillOnce(WithArg<2>(InvokeConsumer(&result))); |
565 std::vector<PasswordForm> observed; | 562 std::vector<PasswordForm> observed; |
566 PasswordForm form(MakeSimpleForm()); | 563 PasswordForm form(MakeSimpleForm()); |
567 observed.push_back(form); | 564 observed.push_back(form); |
568 manager()->OnPasswordFormsParsed(&driver_, observed); // The initial load. | 565 manager()->OnPasswordFormsParsed(&driver_, observed); // The initial load. |
569 observed.clear(); | 566 observed.clear(); |
570 manager()->OnPasswordFormsRendered(&driver_, observed, | 567 manager()->OnPasswordFormsRendered(&driver_, observed, |
571 true); // The initial layout. | 568 true); // The initial layout. |
572 | 569 |
573 manager()->OnPasswordFormsParsed(&driver_, | 570 manager()->OnPasswordFormsParsed(&driver_, |
574 observed); // The post-navigation load. | 571 observed); // The post-navigation load. |
575 manager()->OnPasswordFormsRendered(&driver_, observed, | 572 manager()->OnPasswordFormsRendered(&driver_, observed, |
576 true); // The post-navigation layout. | 573 true); // The post-navigation layout. |
577 } | 574 } |
578 | 575 |
579 TEST_F(PasswordManagerTest, SavingDependsOnManagerEnabledPreference) { | 576 TEST_F(PasswordManagerTest, SavingDependsOnManagerEnabledPreference) { |
580 // Test that saving passwords depends on the password manager enabled | 577 // Test that saving passwords depends on the password manager enabled |
581 // preference. | 578 // preference. |
582 prefs_.SetUserPref(prefs::kPasswordManagerSavingEnabled, | 579 prefs_.SetUserPref(prefs::kPasswordManagerSavingEnabled, |
583 new base::FundamentalValue(true)); | 580 new base::FundamentalValue(true)); |
584 EXPECT_TRUE(manager()->IsSavingEnabledForCurrentPage()); | 581 EXPECT_TRUE(manager()->IsSavingEnabledForCurrentPage()); |
585 prefs_.SetUserPref(prefs::kPasswordManagerSavingEnabled, | 582 prefs_.SetUserPref(prefs::kPasswordManagerSavingEnabled, |
586 new base::FundamentalValue(false)); | 583 new base::FundamentalValue(false)); |
587 EXPECT_FALSE(manager()->IsSavingEnabledForCurrentPage()); | 584 EXPECT_FALSE(manager()->IsSavingEnabledForCurrentPage()); |
588 } | 585 } |
589 | 586 |
590 TEST_F(PasswordManagerTest, FillPasswordsOnDisabledManager) { | 587 TEST_F(PasswordManagerTest, FillPasswordsOnDisabledManager) { |
591 // Test fix for issue 158296: Passwords must be filled even if the password | 588 // Test fix for issue 158296: Passwords must be filled even if the password |
592 // manager is disabled. | 589 // manager is disabled. |
593 std::vector<PasswordForm*> result; | 590 ScopedVector<PasswordForm> result; |
594 PasswordForm* existing = new PasswordForm(MakeSimpleForm()); | 591 result.push_back(new PasswordForm(MakeSimpleForm())); |
595 result.push_back(existing); | |
596 prefs_.SetUserPref(prefs::kPasswordManagerSavingEnabled, | 592 prefs_.SetUserPref(prefs::kPasswordManagerSavingEnabled, |
597 new base::FundamentalValue(false)); | 593 new base::FundamentalValue(false)); |
598 EXPECT_CALL(driver_, FillPasswordForm(_)); | 594 EXPECT_CALL(driver_, FillPasswordForm(_)); |
599 EXPECT_CALL(*store_.get(), | 595 EXPECT_CALL(*store_, |
600 GetLogins(_, testing::Eq(PasswordStore::DISALLOW_PROMPT), _)) | 596 GetLogins(_, testing::Eq(PasswordStore::DISALLOW_PROMPT), _)) |
601 .WillOnce(DoAll(WithArg<2>(InvokeConsumer(result)), Return())); | 597 .WillOnce(WithArg<2>(InvokeConsumer(&result))); |
602 std::vector<PasswordForm> observed; | 598 std::vector<PasswordForm> observed; |
603 PasswordForm form(MakeSimpleForm()); | 599 PasswordForm form(MakeSimpleForm()); |
604 observed.push_back(form); | 600 observed.push_back(form); |
605 manager()->OnPasswordFormsParsed(&driver_, observed); | 601 manager()->OnPasswordFormsParsed(&driver_, observed); |
606 } | 602 } |
607 | 603 |
608 TEST_F(PasswordManagerTest, FormSavedWithAutocompleteOff) { | 604 TEST_F(PasswordManagerTest, FormSavedWithAutocompleteOff) { |
609 // Test password form with non-generated password will be saved even if | 605 // Test password form with non-generated password will be saved even if |
610 // autocomplete=off. | 606 // autocomplete=off. |
611 std::vector<PasswordForm*> result; // Empty password store. | |
612 EXPECT_CALL(driver_, FillPasswordForm(_)).Times(Exactly(0)); | 607 EXPECT_CALL(driver_, FillPasswordForm(_)).Times(Exactly(0)); |
613 EXPECT_CALL(*store_.get(), GetLogins(_, _, _)) | 608 EXPECT_CALL(*store_, GetLogins(_, _, _)) |
614 .WillOnce(DoAll(WithArg<2>(InvokeConsumer(result)), Return())); | 609 .WillRepeatedly(WithArg<2>(InvokeEmptyConsumer())); |
615 std::vector<PasswordForm> observed; | 610 std::vector<PasswordForm> observed; |
616 PasswordForm form(MakeSimpleForm()); | 611 PasswordForm form(MakeSimpleForm()); |
617 form.password_autocomplete_set = false; | 612 form.password_autocomplete_set = false; |
618 observed.push_back(form); | 613 observed.push_back(form); |
619 manager()->OnPasswordFormsParsed(&driver_, observed); // The initial load. | 614 manager()->OnPasswordFormsParsed(&driver_, observed); // The initial load. |
620 manager()->OnPasswordFormsRendered(&driver_, observed, | 615 manager()->OnPasswordFormsRendered(&driver_, observed, |
621 true); // The initial layout. | 616 true); // The initial layout. |
622 | 617 |
623 // And the form submit contract is to call ProvisionallySavePassword. | 618 // And the form submit contract is to call ProvisionallySavePassword. |
624 manager()->ProvisionallySavePassword(form); | 619 manager()->ProvisionallySavePassword(form); |
625 | 620 |
626 // Password form should be saved. | 621 // Password form should be saved. |
627 scoped_ptr<PasswordFormManager> form_to_save; | 622 scoped_ptr<PasswordFormManager> form_to_save; |
628 EXPECT_CALL(client_, PromptUserToSavePasswordPtr(_)) | 623 EXPECT_CALL(client_, PromptUserToSavePasswordPtr(_)) |
629 .Times(Exactly(1)) | 624 .Times(Exactly(1)) |
630 .WillOnce(WithArg<0>(SaveToScopedPtr(&form_to_save))); | 625 .WillOnce(WithArg<0>(SaveToScopedPtr(&form_to_save))); |
631 EXPECT_CALL(*store_.get(), AddLogin(FormMatches(form))).Times(Exactly(0)); | 626 EXPECT_CALL(*store_, AddLogin(FormMatches(form))).Times(Exactly(0)); |
632 | 627 |
633 // Now the password manager waits for the navigation to complete. | 628 // Now the password manager waits for the navigation to complete. |
634 observed.clear(); | 629 observed.clear(); |
635 manager()->OnPasswordFormsParsed(&driver_, | 630 manager()->OnPasswordFormsParsed(&driver_, |
636 observed); // The post-navigation load. | 631 observed); // The post-navigation load. |
637 manager()->OnPasswordFormsRendered(&driver_, observed, | 632 manager()->OnPasswordFormsRendered(&driver_, observed, |
638 true); // The post-navigation layout. | 633 true); // The post-navigation layout. |
639 | 634 |
640 ASSERT_TRUE(form_to_save.get()); | 635 ASSERT_TRUE(form_to_save.get()); |
641 } | 636 } |
642 | 637 |
643 TEST_F(PasswordManagerTest, GeneratedPasswordFormSavedAutocompleteOff) { | 638 TEST_F(PasswordManagerTest, GeneratedPasswordFormSavedAutocompleteOff) { |
644 // Test password form with generated password will still be saved if | 639 // Test password form with generated password will still be saved if |
645 // autocomplete=off. | 640 // autocomplete=off. |
646 std::vector<PasswordForm*> result; // Empty password store. | |
647 EXPECT_CALL(driver_, FillPasswordForm(_)).Times(Exactly(0)); | 641 EXPECT_CALL(driver_, FillPasswordForm(_)).Times(Exactly(0)); |
648 EXPECT_CALL(*store_.get(), GetLogins(_, _, _)) | 642 EXPECT_CALL(*store_, GetLogins(_, _, _)) |
649 .WillOnce(DoAll(WithArg<2>(InvokeConsumer(result)), Return())); | 643 .WillRepeatedly(WithArg<2>(InvokeEmptyConsumer())); |
650 std::vector<PasswordForm> observed; | 644 std::vector<PasswordForm> observed; |
651 PasswordForm form(MakeSimpleForm()); | 645 PasswordForm form(MakeSimpleForm()); |
652 form.password_autocomplete_set = false; | 646 form.password_autocomplete_set = false; |
653 observed.push_back(form); | 647 observed.push_back(form); |
654 manager()->OnPasswordFormsParsed(&driver_, observed); // The initial load. | 648 manager()->OnPasswordFormsParsed(&driver_, observed); // The initial load. |
655 manager()->OnPasswordFormsRendered(&driver_, observed, | 649 manager()->OnPasswordFormsRendered(&driver_, observed, |
656 true); // The initial layout. | 650 true); // The initial layout. |
657 | 651 |
658 // Simulate the user generating the password and submitting the form. | 652 // Simulate the user generating the password and submitting the form. |
659 manager()->SetFormHasGeneratedPassword(&driver_, form); | 653 manager()->SetFormHasGeneratedPassword(&driver_, form); |
660 manager()->ProvisionallySavePassword(form); | 654 manager()->ProvisionallySavePassword(form); |
661 | 655 |
662 // The user should not be presented with an infobar as they have already given | 656 // The user should not be presented with an infobar as they have already given |
663 // consent by using the generated password. The form should be saved once | 657 // consent by using the generated password. The form should be saved once |
664 // navigation occurs. The client will be informed that automatic saving has | 658 // navigation occurs. The client will be informed that automatic saving has |
665 // occured. | 659 // occured. |
666 EXPECT_CALL(client_, PromptUserToSavePasswordPtr(_)).Times(Exactly(0)); | 660 EXPECT_CALL(client_, PromptUserToSavePasswordPtr(_)).Times(Exactly(0)); |
667 EXPECT_CALL(*store_.get(), AddLogin(FormMatches(form))); | 661 EXPECT_CALL(*store_, AddLogin(FormMatches(form))); |
668 scoped_ptr<PasswordFormManager> saved_form_manager; | 662 scoped_ptr<PasswordFormManager> saved_form_manager; |
669 EXPECT_CALL(client_, AutomaticPasswordSavePtr(_)) | 663 EXPECT_CALL(client_, AutomaticPasswordSavePtr(_)) |
670 .Times(Exactly(1)) | 664 .Times(Exactly(1)) |
671 .WillOnce(WithArg<0>(SaveToScopedPtr(&saved_form_manager))); | 665 .WillOnce(WithArg<0>(SaveToScopedPtr(&saved_form_manager))); |
672 | 666 |
673 // Now the password manager waits for the navigation to complete. | 667 // Now the password manager waits for the navigation to complete. |
674 observed.clear(); | 668 observed.clear(); |
675 manager()->OnPasswordFormsParsed(&driver_, | 669 manager()->OnPasswordFormsParsed(&driver_, |
676 observed); // The post-navigation load. | 670 observed); // The post-navigation load. |
677 manager()->OnPasswordFormsRendered(&driver_, observed, | 671 manager()->OnPasswordFormsRendered(&driver_, observed, |
678 true); // The post-navigation layout. | 672 true); // The post-navigation layout. |
679 } | 673 } |
680 | 674 |
681 TEST_F(PasswordManagerTest, SubmissionCallbackTest) { | 675 TEST_F(PasswordManagerTest, SubmissionCallbackTest) { |
682 manager()->AddSubmissionCallback(SubmissionCallback()); | 676 manager()->AddSubmissionCallback(SubmissionCallback()); |
683 PasswordForm form = MakeSimpleForm(); | 677 PasswordForm form = MakeSimpleForm(); |
684 OnPasswordFormSubmitted(form); | 678 OnPasswordFormSubmitted(form); |
685 EXPECT_TRUE(FormsAreEqual(form, submitted_form_)); | 679 EXPECT_TRUE(FormsAreEqual(form, submitted_form_)); |
686 } | 680 } |
687 | 681 |
688 TEST_F(PasswordManagerTest, PasswordFormReappearance) { | 682 TEST_F(PasswordManagerTest, PasswordFormReappearance) { |
689 // Test the heuristic to know if a password form reappears. | 683 // Test the heuristic to know if a password form reappears. |
690 // We assume that if we send our credentials and there | 684 // We assume that if we send our credentials and there |
691 // is at least one visible password form in the next page that | 685 // is at least one visible password form in the next page that |
692 // means that our previous login attempt failed. | 686 // means that our previous login attempt failed. |
693 std::vector<PasswordForm*> result; // Empty password store. | |
694 EXPECT_CALL(driver_, FillPasswordForm(_)).Times(0); | 687 EXPECT_CALL(driver_, FillPasswordForm(_)).Times(0); |
695 EXPECT_CALL(*store_.get(), GetLogins(_, _, _)) | 688 EXPECT_CALL(*store_, GetLogins(_, _, _)) |
696 .WillRepeatedly(DoAll(WithArg<2>(InvokeConsumer(result)), Return())); | 689 .WillRepeatedly(WithArg<2>(InvokeEmptyConsumer())); |
697 std::vector<PasswordForm> observed; | 690 std::vector<PasswordForm> observed; |
698 PasswordForm login_form(MakeTwitterLoginForm()); | 691 PasswordForm login_form(MakeTwitterLoginForm()); |
699 observed.push_back(login_form); | 692 observed.push_back(login_form); |
700 manager()->OnPasswordFormsParsed(&driver_, observed); // The initial load. | 693 manager()->OnPasswordFormsParsed(&driver_, observed); // The initial load. |
701 manager()->OnPasswordFormsRendered(&driver_, observed, | 694 manager()->OnPasswordFormsRendered(&driver_, observed, |
702 true); // The initial layout. | 695 true); // The initial layout. |
703 | 696 |
704 manager()->ProvisionallySavePassword(login_form); | 697 manager()->ProvisionallySavePassword(login_form); |
705 | 698 |
706 PasswordForm failed_login_form(MakeTwitterFailedLoginForm()); | 699 PasswordForm failed_login_form(MakeTwitterFailedLoginForm()); |
(...skipping 16 matching lines...) Expand all Loading... |
723 // attempt to autofill forms found on a website. | 716 // attempt to autofill forms found on a website. |
724 EXPECT_CALL(client_, DidLastPageLoadEncounterSSLErrors()) | 717 EXPECT_CALL(client_, DidLastPageLoadEncounterSSLErrors()) |
725 .WillRepeatedly(Return(true)); | 718 .WillRepeatedly(Return(true)); |
726 | 719 |
727 // Let us pretend some forms were found on a website. | 720 // Let us pretend some forms were found on a website. |
728 std::vector<PasswordForm> forms; | 721 std::vector<PasswordForm> forms; |
729 forms.push_back(MakeSimpleForm()); | 722 forms.push_back(MakeSimpleForm()); |
730 | 723 |
731 // Feed those forms to |manager()| and check that it does not try to find | 724 // Feed those forms to |manager()| and check that it does not try to find |
732 // matching saved credentials for the forms. | 725 // matching saved credentials for the forms. |
733 EXPECT_CALL(*store_.get(), GetLogins(_, _, _)).Times(Exactly(0)); | 726 EXPECT_CALL(*store_, GetLogins(_, _, _)).Times(Exactly(0)); |
734 manager()->OnPasswordFormsParsed(&driver_, forms); | 727 manager()->OnPasswordFormsParsed(&driver_, forms); |
735 } | 728 } |
736 | 729 |
737 TEST_F(PasswordManagerTest, SavingDisabledIfManagerDisabled) { | 730 TEST_F(PasswordManagerTest, SavingDisabledIfManagerDisabled) { |
738 EXPECT_CALL(client_, IsPasswordManagerEnabledForCurrentPage()) | 731 EXPECT_CALL(client_, IsPasswordManagerEnabledForCurrentPage()) |
739 .WillRepeatedly(Return(false)); | 732 .WillRepeatedly(Return(false)); |
740 EXPECT_FALSE(manager()->IsSavingEnabledForCurrentPage()); | 733 EXPECT_FALSE(manager()->IsSavingEnabledForCurrentPage()); |
741 } | 734 } |
742 | 735 |
743 TEST_F(PasswordManagerTest, AutofillingDisabledIfManagerDisabled) { | 736 TEST_F(PasswordManagerTest, AutofillingDisabledIfManagerDisabled) { |
744 EXPECT_CALL(client_, IsPasswordManagerEnabledForCurrentPage()) | 737 EXPECT_CALL(client_, IsPasswordManagerEnabledForCurrentPage()) |
745 .WillRepeatedly(Return(false)); | 738 .WillRepeatedly(Return(false)); |
746 | 739 |
747 // Let us pretend some forms were found on a website. | 740 // Let us pretend some forms were found on a website. |
748 std::vector<PasswordForm> forms; | 741 std::vector<PasswordForm> forms; |
749 forms.push_back(MakeSimpleForm()); | 742 forms.push_back(MakeSimpleForm()); |
750 | 743 |
751 // Feed those forms to |manager()| and check that it does not try to find | 744 // Feed those forms to |manager()| and check that it does not try to find |
752 // matching saved credentials for the forms. | 745 // matching saved credentials for the forms. |
753 EXPECT_CALL(*store_.get(), GetLogins(_, _, _)).Times(Exactly(0)); | 746 EXPECT_CALL(*store_, GetLogins(_, _, _)).Times(Exactly(0)); |
754 manager()->OnPasswordFormsParsed(&driver_, forms); | 747 manager()->OnPasswordFormsParsed(&driver_, forms); |
755 } | 748 } |
756 | 749 |
757 TEST_F(PasswordManagerTest, SyncCredentialsNotSaved) { | 750 TEST_F(PasswordManagerTest, SyncCredentialsNotSaved) { |
758 EXPECT_CALL(client_, IsSyncAccountCredential(_, _)) | 751 EXPECT_CALL(client_, IsSyncAccountCredential(_, _)) |
759 .WillRepeatedly(Return(true)); | 752 .WillRepeatedly(Return(true)); |
760 | 753 |
761 // Simulate loading a simple form with no existing stored password. | 754 // Simulate loading a simple form with no existing stored password. |
762 std::vector<PasswordForm*> result; // Empty password store. | |
763 EXPECT_CALL(driver_, FillPasswordForm(_)).Times(Exactly(0)); | 755 EXPECT_CALL(driver_, FillPasswordForm(_)).Times(Exactly(0)); |
764 EXPECT_CALL(*store_.get(), GetLogins(_, _, _)) | 756 EXPECT_CALL(*store_, GetLogins(_, _, _)) |
765 .WillOnce(DoAll(WithArg<2>(InvokeConsumer(result)), Return())); | 757 .WillRepeatedly(WithArg<2>(InvokeEmptyConsumer())); |
766 std::vector<PasswordForm> observed; | 758 std::vector<PasswordForm> observed; |
767 PasswordForm form(MakeSimpleForm()); | 759 PasswordForm form(MakeSimpleForm()); |
768 form.password_autocomplete_set = false; | 760 form.password_autocomplete_set = false; |
769 observed.push_back(form); | 761 observed.push_back(form); |
770 manager()->OnPasswordFormsParsed(&driver_, observed); // The initial load. | 762 manager()->OnPasswordFormsParsed(&driver_, observed); // The initial load. |
771 manager()->OnPasswordFormsRendered(&driver_, observed, | 763 manager()->OnPasswordFormsRendered(&driver_, observed, |
772 true); // The initial layout. | 764 true); // The initial layout. |
773 | 765 |
774 // User should not be prompted and password should not be saved. | 766 // User should not be prompted and password should not be saved. |
775 EXPECT_CALL(client_, PromptUserToSavePasswordPtr(_)).Times(Exactly(0)); | 767 EXPECT_CALL(client_, PromptUserToSavePasswordPtr(_)).Times(Exactly(0)); |
776 EXPECT_CALL(*store_.get(), AddLogin(FormMatches(form))).Times(Exactly(0)); | 768 EXPECT_CALL(*store_, AddLogin(FormMatches(form))).Times(Exactly(0)); |
777 | 769 |
778 // Submit form and finish navigation. | 770 // Submit form and finish navigation. |
779 manager()->ProvisionallySavePassword(form); | 771 manager()->ProvisionallySavePassword(form); |
780 observed.clear(); | 772 observed.clear(); |
781 manager()->OnPasswordFormsParsed(&driver_, observed); | 773 manager()->OnPasswordFormsParsed(&driver_, observed); |
782 manager()->OnPasswordFormsRendered(&driver_, observed, true); | 774 manager()->OnPasswordFormsRendered(&driver_, observed, true); |
783 } | 775 } |
784 | 776 |
785 // On failed login attempts, the retry-form can have action scheme changed from | 777 // On failed login attempts, the retry-form can have action scheme changed from |
786 // HTTP to HTTPS (see http://crbug.com/400769). Check that such retry-form is | 778 // HTTP to HTTPS (see http://crbug.com/400769). Check that such retry-form is |
787 // considered equal to the original login form, and the attempt recognised as a | 779 // considered equal to the original login form, and the attempt recognised as a |
788 // failure. | 780 // failure. |
789 TEST_F(PasswordManagerTest, | 781 TEST_F(PasswordManagerTest, |
790 SeeingFormActionWithOnlyHttpHttpsChangeIsLoginFailure) { | 782 SeeingFormActionWithOnlyHttpHttpsChangeIsLoginFailure) { |
791 std::vector<PasswordForm*> result; // Empty password store. | |
792 EXPECT_CALL(driver_, FillPasswordForm(_)).Times(Exactly(0)); | 783 EXPECT_CALL(driver_, FillPasswordForm(_)).Times(Exactly(0)); |
793 EXPECT_CALL(*store_.get(), GetLogins(_, _, _)) | 784 EXPECT_CALL(*store_, GetLogins(_, _, _)) |
794 .WillRepeatedly(DoAll(WithArg<2>(InvokeConsumer(result)), Return())); | 785 .WillRepeatedly(WithArg<2>(InvokeEmptyConsumer())); |
795 | 786 |
796 PasswordForm first_form(MakeSimpleForm()); | 787 PasswordForm first_form(MakeSimpleForm()); |
797 first_form.origin = GURL("http://www.xda-developers.com/"); | 788 first_form.origin = GURL("http://www.xda-developers.com/"); |
798 first_form.action = GURL("http://forum.xda-developers.com/login.php"); | 789 first_form.action = GURL("http://forum.xda-developers.com/login.php"); |
799 | 790 |
800 // |second_form|'s action differs only with it's scheme i.e. *https://*. | 791 // |second_form|'s action differs only with it's scheme i.e. *https://*. |
801 PasswordForm second_form(first_form); | 792 PasswordForm second_form(first_form); |
802 second_form.action = GURL("https://forum.xda-developers.com/login.php"); | 793 second_form.action = GURL("https://forum.xda-developers.com/login.php"); |
803 | 794 |
804 std::vector<PasswordForm> observed; | 795 std::vector<PasswordForm> observed; |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
843 manager()->OnPasswordFormsParsed(&driver_, | 834 manager()->OnPasswordFormsParsed(&driver_, |
844 observed); // The post-navigation load. | 835 observed); // The post-navigation load. |
845 manager()->OnPasswordFormsRendered(&driver_, observed, | 836 manager()->OnPasswordFormsRendered(&driver_, observed, |
846 true); // The post-navigation layout. | 837 true); // The post-navigation layout. |
847 } | 838 } |
848 | 839 |
849 TEST_F(PasswordManagerTest, FormSubmitWithOnlyPassowrdField) { | 840 TEST_F(PasswordManagerTest, FormSubmitWithOnlyPassowrdField) { |
850 // Test to verify that on submitting the HTML password form without having | 841 // Test to verify that on submitting the HTML password form without having |
851 // username input filed shows password save promt and saves the password to | 842 // username input filed shows password save promt and saves the password to |
852 // store. | 843 // store. |
853 std::vector<PasswordForm*> result; // Empty password store. | |
854 EXPECT_CALL(driver_, FillPasswordForm(_)).Times(Exactly(0)); | 844 EXPECT_CALL(driver_, FillPasswordForm(_)).Times(Exactly(0)); |
855 EXPECT_CALL(*store_.get(), GetLogins(_, _, _)) | 845 EXPECT_CALL(*store_, GetLogins(_, _, _)) |
856 .WillOnce(DoAll(WithArg<2>(InvokeConsumer(result)), Return())); | 846 .WillRepeatedly(WithArg<2>(InvokeEmptyConsumer())); |
857 std::vector<PasswordForm> observed; | 847 std::vector<PasswordForm> observed; |
858 | 848 |
859 // Loads passsword form without username input field. | 849 // Loads passsword form without username input field. |
860 PasswordForm form(MakeSimpleFormWithOnlyPasswordField()); | 850 PasswordForm form(MakeSimpleFormWithOnlyPasswordField()); |
861 observed.push_back(form); | 851 observed.push_back(form); |
862 manager()->OnPasswordFormsParsed(&driver_, observed); // The initial load. | 852 manager()->OnPasswordFormsParsed(&driver_, observed); // The initial load. |
863 manager()->OnPasswordFormsRendered(&driver_, observed, | 853 manager()->OnPasswordFormsRendered(&driver_, observed, |
864 true); // The initial layout. | 854 true); // The initial layout. |
865 | 855 |
866 // And the form submit contract is to call ProvisionallySavePassword. | 856 // And the form submit contract is to call ProvisionallySavePassword. |
867 manager()->ProvisionallySavePassword(form); | 857 manager()->ProvisionallySavePassword(form); |
868 | 858 |
869 scoped_ptr<PasswordFormManager> form_to_save; | 859 scoped_ptr<PasswordFormManager> form_to_save; |
870 EXPECT_CALL(client_, PromptUserToSavePasswordPtr(_)) | 860 EXPECT_CALL(client_, PromptUserToSavePasswordPtr(_)) |
871 .WillOnce(WithArg<0>(SaveToScopedPtr(&form_to_save))); | 861 .WillOnce(WithArg<0>(SaveToScopedPtr(&form_to_save))); |
872 | 862 |
873 // Now the password manager waits for the navigation to complete. | 863 // Now the password manager waits for the navigation to complete. |
874 observed.clear(); | 864 observed.clear(); |
875 manager()->OnPasswordFormsParsed(&driver_, | 865 manager()->OnPasswordFormsParsed(&driver_, |
876 observed); // The post-navigation load. | 866 observed); // The post-navigation load. |
877 manager()->OnPasswordFormsRendered(&driver_, observed, | 867 manager()->OnPasswordFormsRendered(&driver_, observed, |
878 true); // The post-navigation layout. | 868 true); // The post-navigation layout. |
879 | 869 |
880 ASSERT_TRUE(form_to_save.get()); | 870 ASSERT_TRUE(form_to_save.get()); |
881 EXPECT_CALL(*store_.get(), AddLogin(FormMatches(form))); | 871 EXPECT_CALL(*store_, AddLogin(FormMatches(form))); |
882 | 872 |
883 // Simulate saving the form, as if the info bar was accepted. | 873 // Simulate saving the form, as if the info bar was accepted. |
884 form_to_save->Save(); | 874 form_to_save->Save(); |
885 } | 875 } |
886 | 876 |
887 TEST_F(PasswordManagerTest, FillPasswordOnManyFrames) { | 877 TEST_F(PasswordManagerTest, FillPasswordOnManyFrames) { |
888 // If one password form appears in more frames, it should be filled in all of | 878 // If one password form appears in more frames, it should be filled in all of |
889 // them. | 879 // them. |
890 PasswordForm form(MakeSimpleForm()); // The observed and saved form. | 880 PasswordForm form(MakeSimpleForm()); // The observed and saved form. |
891 | 881 |
892 // "Save" the form. | 882 // "Save" the form. |
893 std::vector<PasswordForm*> result; | 883 ScopedVector<PasswordForm> result; |
894 result.push_back(new PasswordForm(form)); // Calee owns the form. | 884 result.push_back(new PasswordForm(form)); |
895 EXPECT_CALL(*store_.get(), | 885 EXPECT_CALL(*store_, |
896 GetLogins(_, testing::Eq(PasswordStore::DISALLOW_PROMPT), _)) | 886 GetLogins(_, testing::Eq(PasswordStore::DISALLOW_PROMPT), _)) |
897 .WillOnce(DoAll(WithArg<2>(InvokeConsumer(result)), Return())); | 887 .WillOnce(WithArg<2>(InvokeConsumer(&result))); |
898 | 888 |
899 // The form will be seen the first time. | 889 // The form will be seen the first time. |
900 EXPECT_CALL(driver_, FillPasswordForm(_)).Times(1); | 890 EXPECT_CALL(driver_, FillPasswordForm(_)).Times(1); |
901 std::vector<PasswordForm> observed; | 891 std::vector<PasswordForm> observed; |
902 observed.push_back(form); | 892 observed.push_back(form); |
903 manager()->OnPasswordFormsParsed(&driver_, observed); | 893 manager()->OnPasswordFormsParsed(&driver_, observed); |
904 | 894 |
905 // Now the form will be seen the second time, in a different frame. The driver | 895 // Now the form will be seen the second time, in a different frame. The driver |
906 // for that frame should be told to fill it, but the store should not be asked | 896 // for that frame should be told to fill it, but the store should not be asked |
907 // for it again. | 897 // for it again. |
908 MockPasswordManagerDriver driver_b; | 898 MockPasswordManagerDriver driver_b; |
909 EXPECT_CALL(driver_b, FillPasswordForm(_)).Times(1); | 899 EXPECT_CALL(driver_b, FillPasswordForm(_)).Times(1); |
910 manager()->OnPasswordFormsParsed(&driver_b, observed); | 900 manager()->OnPasswordFormsParsed(&driver_b, observed); |
911 } | 901 } |
912 | 902 |
913 TEST_F(PasswordManagerTest, InPageNavigation) { | 903 TEST_F(PasswordManagerTest, InPageNavigation) { |
914 // Test that observing a newly submitted form shows the save password bar on | 904 // Test that observing a newly submitted form shows the save password bar on |
915 // call in page navigation. | 905 // call in page navigation. |
916 std::vector<PasswordForm*> result; // Empty password store. | |
917 EXPECT_CALL(driver_, FillPasswordForm(_)).Times(Exactly(0)); | 906 EXPECT_CALL(driver_, FillPasswordForm(_)).Times(Exactly(0)); |
918 EXPECT_CALL(*store_.get(), GetLogins(_, _, _)) | 907 EXPECT_CALL(*store_, GetLogins(_, _, _)) |
919 .WillOnce(DoAll(WithArg<2>(InvokeConsumer(result)), Return())); | 908 .WillRepeatedly(WithArg<2>(InvokeEmptyConsumer())); |
920 std::vector<PasswordForm> observed; | 909 std::vector<PasswordForm> observed; |
921 PasswordForm form(MakeSimpleForm()); | 910 PasswordForm form(MakeSimpleForm()); |
922 observed.push_back(form); | 911 observed.push_back(form); |
923 // The initial load. | 912 // The initial load. |
924 manager()->OnPasswordFormsParsed(&driver_, observed); | 913 manager()->OnPasswordFormsParsed(&driver_, observed); |
925 // The initial layout. | 914 // The initial layout. |
926 manager()->OnPasswordFormsRendered(&driver_, observed, true); | 915 manager()->OnPasswordFormsRendered(&driver_, observed, true); |
927 | 916 |
928 // And the form submit contract is to call ProvisionallySavePassword. | 917 // And the form submit contract is to call ProvisionallySavePassword. |
929 manager()->ProvisionallySavePassword(form); | 918 manager()->ProvisionallySavePassword(form); |
930 | 919 |
931 scoped_ptr<PasswordFormManager> form_to_save; | 920 scoped_ptr<PasswordFormManager> form_to_save; |
932 EXPECT_CALL(client_, PromptUserToSavePasswordPtr(_)) | 921 EXPECT_CALL(client_, PromptUserToSavePasswordPtr(_)) |
933 .WillOnce(WithArg<0>(SaveToScopedPtr(&form_to_save))); | 922 .WillOnce(WithArg<0>(SaveToScopedPtr(&form_to_save))); |
934 | 923 |
935 manager()->OnInPageNavigation(&driver_, form); | 924 manager()->OnInPageNavigation(&driver_, form); |
936 } | 925 } |
937 | 926 |
938 } // namespace password_manager | 927 } // namespace password_manager |
OLD | NEW |