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