OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include <vector> | 5 #include <vector> |
6 | 6 |
7 #include "base/message_loop/message_loop.h" | 7 #include "base/message_loop/message_loop.h" |
8 #include "base/strings/string_util.h" | 8 #include "base/strings/string_util.h" |
9 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
10 #include "chrome/browser/password_manager/mock_password_store.h" | 10 #include "chrome/browser/password_manager/mock_password_store.h" |
11 #include "chrome/browser/password_manager/password_manager.h" | 11 #include "chrome/browser/password_manager/password_manager.h" |
12 #include "chrome/browser/password_manager/password_manager_delegate.h" | 12 #include "chrome/browser/password_manager/password_manager_delegate.h" |
| 13 #include "chrome/browser/password_manager/password_manager_driver.h" |
13 #include "chrome/browser/password_manager/password_store.h" | 14 #include "chrome/browser/password_manager/password_store.h" |
14 #include "chrome/browser/password_manager/password_store_factory.h" | 15 #include "chrome/browser/password_manager/password_store_factory.h" |
15 #include "chrome/common/pref_names.h" | 16 #include "chrome/common/pref_names.h" |
16 #include "chrome/common/url_constants.h" | 17 #include "chrome/common/url_constants.h" |
17 #include "chrome/test/base/chrome_render_view_host_test_harness.h" | 18 #include "chrome/test/base/chrome_render_view_host_test_harness.h" |
18 #include "chrome/test/base/testing_pref_service_syncable.h" | 19 #include "chrome/test/base/testing_pref_service_syncable.h" |
19 #include "chrome/test/base/testing_profile.h" | 20 #include "chrome/test/base/testing_profile.h" |
20 #include "content/public/browser/navigation_details.h" | 21 #include "content/public/browser/navigation_details.h" |
21 #include "content/public/common/frame_navigate_params.h" | 22 #include "content/public/common/frame_navigate_params.h" |
22 #include "content/public/test/test_browser_thread.h" | 23 #include "content/public/test/test_browser_thread.h" |
23 #include "testing/gmock/include/gmock/gmock.h" | 24 #include "testing/gmock/include/gmock/gmock.h" |
24 #include "testing/gtest/include/gtest/gtest.h" | 25 #include "testing/gtest/include/gtest/gtest.h" |
25 | 26 |
26 using autofill::PasswordForm; | 27 using autofill::PasswordForm; |
27 using base::ASCIIToUTF16; | 28 using base::ASCIIToUTF16; |
28 using testing::_; | 29 using testing::_; |
29 using testing::DoAll; | 30 using testing::DoAll; |
30 using testing::Exactly; | 31 using testing::Exactly; |
31 using testing::Return; | 32 using testing::Return; |
32 using testing::WithArg; | 33 using testing::WithArg; |
33 | 34 |
34 namespace { | 35 namespace { |
35 | 36 |
36 class MockPasswordManagerDelegate : public PasswordManagerDelegate { | 37 class MockPasswordManagerDelegate : public PasswordManagerDelegate { |
37 public: | 38 public: |
38 MOCK_METHOD1(FillPasswordForm, void(const autofill::PasswordFormFillData&)); | |
39 MOCK_METHOD1(AddSavePasswordInfoBarIfPermitted, void(PasswordFormManager*)); | 39 MOCK_METHOD1(AddSavePasswordInfoBarIfPermitted, void(PasswordFormManager*)); |
40 MOCK_METHOD0(GetProfile, Profile*()); | 40 MOCK_METHOD0(GetProfile, Profile*()); |
| 41 MOCK_METHOD0(GetDriver, PasswordManagerDriver*()); |
| 42 }; |
| 43 |
| 44 class MockPasswordManagerDriver : public PasswordManagerDriver { |
| 45 public: |
| 46 MOCK_METHOD1(FillPasswordForm, void(const autofill::PasswordFormFillData&)); |
41 MOCK_METHOD0(DidLastPageLoadEncounterSSLErrors, bool()); | 47 MOCK_METHOD0(DidLastPageLoadEncounterSSLErrors, bool()); |
42 }; | 48 }; |
43 | 49 |
44 ACTION_P(InvokeConsumer, forms) { | 50 ACTION_P(InvokeConsumer, forms) { |
45 arg0->OnGetPasswordStoreResults(forms); | 51 arg0->OnGetPasswordStoreResults(forms); |
46 } | 52 } |
47 | 53 |
48 ACTION_P(SaveToScopedPtr, scoped) { | 54 ACTION_P(SaveToScopedPtr, scoped) { |
49 scoped->reset(arg0); | 55 scoped->reset(arg0); |
50 } | 56 } |
(...skipping 25 matching lines...) Expand all Loading... |
76 | 82 |
77 class PasswordManagerTest : public ChromeRenderViewHostTestHarness { | 83 class PasswordManagerTest : public ChromeRenderViewHostTestHarness { |
78 protected: | 84 protected: |
79 virtual void SetUp() { | 85 virtual void SetUp() { |
80 ChromeRenderViewHostTestHarness::SetUp(); | 86 ChromeRenderViewHostTestHarness::SetUp(); |
81 store_ = static_cast<MockPasswordStore*>( | 87 store_ = static_cast<MockPasswordStore*>( |
82 PasswordStoreFactory::GetInstance()->SetTestingFactoryAndUse( | 88 PasswordStoreFactory::GetInstance()->SetTestingFactoryAndUse( |
83 profile(), MockPasswordStore::Build).get()); | 89 profile(), MockPasswordStore::Build).get()); |
84 | 90 |
85 EXPECT_CALL(delegate_, GetProfile()).WillRepeatedly(Return(profile())); | 91 EXPECT_CALL(delegate_, GetProfile()).WillRepeatedly(Return(profile())); |
| 92 EXPECT_CALL(delegate_, GetDriver()).WillRepeatedly(Return(&driver_)); |
86 manager_ = TestPasswordManager::CreateForWebContentsAndDelegate( | 93 manager_ = TestPasswordManager::CreateForWebContentsAndDelegate( |
87 web_contents(), &delegate_); | 94 web_contents(), &delegate_); |
88 EXPECT_CALL(delegate_, DidLastPageLoadEncounterSSLErrors()) | 95 EXPECT_CALL(driver_, DidLastPageLoadEncounterSSLErrors()) |
89 .WillRepeatedly(Return(false)); | 96 .WillRepeatedly(Return(false)); |
90 } | 97 } |
91 | 98 |
92 virtual void TearDown() { | 99 virtual void TearDown() { |
93 store_ = NULL; | 100 store_ = NULL; |
94 ChromeRenderViewHostTestHarness::TearDown(); | 101 ChromeRenderViewHostTestHarness::TearDown(); |
95 } | 102 } |
96 | 103 |
97 PasswordForm MakeSimpleForm() { | 104 PasswordForm MakeSimpleForm() { |
98 PasswordForm form; | 105 PasswordForm form; |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
176 base::Unretained(this)); | 183 base::Unretained(this)); |
177 } | 184 } |
178 | 185 |
179 void FormSubmitted(const autofill::PasswordForm& form) { | 186 void FormSubmitted(const autofill::PasswordForm& form) { |
180 submitted_form_ = form; | 187 submitted_form_ = form; |
181 } | 188 } |
182 | 189 |
183 scoped_refptr<MockPasswordStore> store_; | 190 scoped_refptr<MockPasswordStore> store_; |
184 TestPasswordManager* manager_; | 191 TestPasswordManager* manager_; |
185 MockPasswordManagerDelegate delegate_; // Owned by manager_. | 192 MockPasswordManagerDelegate delegate_; // Owned by manager_. |
| 193 MockPasswordManagerDriver driver_; |
186 PasswordForm submitted_form_; | 194 PasswordForm submitted_form_; |
187 }; | 195 }; |
188 | 196 |
189 MATCHER_P(FormMatches, form, "") { | 197 MATCHER_P(FormMatches, form, "") { |
190 return form.signon_realm == arg.signon_realm && | 198 return form.signon_realm == arg.signon_realm && |
191 form.origin == arg.origin && | 199 form.origin == arg.origin && |
192 form.action == arg.action && | 200 form.action == arg.action && |
193 form.username_element == arg.username_element && | 201 form.username_element == arg.username_element && |
194 form.password_element == arg.password_element && | 202 form.password_element == arg.password_element && |
195 form.password_autocomplete_set == | 203 form.password_autocomplete_set == |
196 arg.password_autocomplete_set && | 204 arg.password_autocomplete_set && |
197 form.submit_element == arg.submit_element; | 205 form.submit_element == arg.submit_element; |
198 } | 206 } |
199 | 207 |
200 TEST_F(PasswordManagerTest, FormSubmitEmptyStore) { | 208 TEST_F(PasswordManagerTest, FormSubmitEmptyStore) { |
201 // Test that observing a newly submitted form shows the save password bar. | 209 // Test that observing a newly submitted form shows the save password bar. |
202 std::vector<PasswordForm*> result; // Empty password store. | 210 std::vector<PasswordForm*> result; // Empty password store. |
203 EXPECT_CALL(delegate_, FillPasswordForm(_)).Times(Exactly(0)); | 211 EXPECT_CALL(driver_, FillPasswordForm(_)).Times(Exactly(0)); |
204 EXPECT_CALL(*store_.get(), GetLogins(_, _, _)) | 212 EXPECT_CALL(*store_.get(), GetLogins(_, _, _)) |
205 .WillOnce(DoAll(WithArg<2>(InvokeConsumer(result)), Return())); | 213 .WillOnce(DoAll(WithArg<2>(InvokeConsumer(result)), Return())); |
206 std::vector<PasswordForm> observed; | 214 std::vector<PasswordForm> observed; |
207 PasswordForm form(MakeSimpleForm()); | 215 PasswordForm form(MakeSimpleForm()); |
208 observed.push_back(form); | 216 observed.push_back(form); |
209 manager()->OnPasswordFormsParsed(observed); // The initial load. | 217 manager()->OnPasswordFormsParsed(observed); // The initial load. |
210 manager()->OnPasswordFormsRendered(observed); // The initial layout. | 218 manager()->OnPasswordFormsRendered(observed); // The initial layout. |
211 | 219 |
212 // And the form submit contract is to call ProvisionallySavePassword. | 220 // And the form submit contract is to call ProvisionallySavePassword. |
213 manager()->ProvisionallySavePassword(form); | 221 manager()->ProvisionallySavePassword(form); |
(...skipping 11 matching lines...) Expand all Loading... |
225 EXPECT_CALL(*store_.get(), AddLogin(FormMatches(form))); | 233 EXPECT_CALL(*store_.get(), AddLogin(FormMatches(form))); |
226 | 234 |
227 // Simulate saving the form, as if the info bar was accepted. | 235 // Simulate saving the form, as if the info bar was accepted. |
228 form_to_save->Save(); | 236 form_to_save->Save(); |
229 } | 237 } |
230 | 238 |
231 TEST_F(PasswordManagerTest, GeneratedPasswordFormSubmitEmptyStore) { | 239 TEST_F(PasswordManagerTest, GeneratedPasswordFormSubmitEmptyStore) { |
232 // This test is the same FormSubmitEmptyStore, except that it simulates the | 240 // This test is the same FormSubmitEmptyStore, except that it simulates the |
233 // user generating the password through the browser. | 241 // user generating the password through the browser. |
234 std::vector<PasswordForm*> result; // Empty password store. | 242 std::vector<PasswordForm*> result; // Empty password store. |
235 EXPECT_CALL(delegate_, FillPasswordForm(_)).Times(Exactly(0)); | 243 EXPECT_CALL(driver_, FillPasswordForm(_)).Times(Exactly(0)); |
236 EXPECT_CALL(*store_.get(), GetLogins(_, _, _)) | 244 EXPECT_CALL(*store_.get(), GetLogins(_, _, _)) |
237 .WillOnce(DoAll(WithArg<2>(InvokeConsumer(result)), Return())); | 245 .WillOnce(DoAll(WithArg<2>(InvokeConsumer(result)), Return())); |
238 std::vector<PasswordForm> observed; | 246 std::vector<PasswordForm> observed; |
239 PasswordForm form(MakeSimpleForm()); | 247 PasswordForm form(MakeSimpleForm()); |
240 observed.push_back(form); | 248 observed.push_back(form); |
241 manager()->OnPasswordFormsParsed(observed); // The initial load. | 249 manager()->OnPasswordFormsParsed(observed); // The initial load. |
242 manager()->OnPasswordFormsRendered(observed); // The initial layout. | 250 manager()->OnPasswordFormsRendered(observed); // The initial layout. |
243 | 251 |
244 // Simulate the user generating the password and submitting the form. | 252 // Simulate the user generating the password and submitting the form. |
245 manager()->SetFormHasGeneratedPassword(form); | 253 manager()->SetFormHasGeneratedPassword(form); |
(...skipping 13 matching lines...) Expand all Loading... |
259 } | 267 } |
260 | 268 |
261 TEST_F(PasswordManagerTest, FormSubmitNoGoodMatch) { | 269 TEST_F(PasswordManagerTest, FormSubmitNoGoodMatch) { |
262 // Same as above, except with an existing form for the same signon realm, | 270 // Same as above, except with an existing form for the same signon realm, |
263 // but different origin. Detailed cases like this are covered by | 271 // but different origin. Detailed cases like this are covered by |
264 // PasswordFormManagerTest. | 272 // PasswordFormManagerTest. |
265 std::vector<PasswordForm*> result; | 273 std::vector<PasswordForm*> result; |
266 PasswordForm* existing_different = new PasswordForm(MakeSimpleForm()); | 274 PasswordForm* existing_different = new PasswordForm(MakeSimpleForm()); |
267 existing_different->username_value = ASCIIToUTF16("google2"); | 275 existing_different->username_value = ASCIIToUTF16("google2"); |
268 result.push_back(existing_different); | 276 result.push_back(existing_different); |
269 EXPECT_CALL(delegate_, FillPasswordForm(_)); | 277 EXPECT_CALL(driver_, FillPasswordForm(_)); |
270 EXPECT_CALL(*store_.get(), GetLogins(_, _, _)) | 278 EXPECT_CALL(*store_.get(), GetLogins(_, _, _)) |
271 .WillOnce(DoAll(WithArg<2>(InvokeConsumer(result)), Return())); | 279 .WillOnce(DoAll(WithArg<2>(InvokeConsumer(result)), Return())); |
272 | 280 |
273 std::vector<PasswordForm> observed; | 281 std::vector<PasswordForm> observed; |
274 PasswordForm form(MakeSimpleForm()); | 282 PasswordForm form(MakeSimpleForm()); |
275 observed.push_back(form); | 283 observed.push_back(form); |
276 manager()->OnPasswordFormsParsed(observed); // The initial load. | 284 manager()->OnPasswordFormsParsed(observed); // The initial load. |
277 manager()->OnPasswordFormsRendered(observed); // The initial layout. | 285 manager()->OnPasswordFormsRendered(observed); // The initial layout. |
278 manager()->ProvisionallySavePassword(form); | 286 manager()->ProvisionallySavePassword(form); |
279 | 287 |
280 // We still expect an add, since we didn't have a good match. | 288 // We still expect an add, since we didn't have a good match. |
281 scoped_ptr<PasswordFormManager> form_to_save; | 289 scoped_ptr<PasswordFormManager> form_to_save; |
282 EXPECT_CALL(delegate_, AddSavePasswordInfoBarIfPermitted(_)) | 290 EXPECT_CALL(delegate_, AddSavePasswordInfoBarIfPermitted(_)) |
283 .WillOnce(WithArg<0>(SaveToScopedPtr(&form_to_save))); | 291 .WillOnce(WithArg<0>(SaveToScopedPtr(&form_to_save))); |
284 | 292 |
285 // Now the password manager waits for the navigation to complete. | 293 // Now the password manager waits for the navigation to complete. |
286 observed.clear(); | 294 observed.clear(); |
287 manager()->OnPasswordFormsParsed(observed); // The post-navigation load. | 295 manager()->OnPasswordFormsParsed(observed); // The post-navigation load. |
288 manager()->OnPasswordFormsRendered(observed); // The post-navigation layout. | 296 manager()->OnPasswordFormsRendered(observed); // The post-navigation layout. |
289 | 297 |
290 ASSERT_TRUE(form_to_save.get()); | 298 ASSERT_TRUE(form_to_save.get()); |
291 EXPECT_CALL(*store_.get(), AddLogin(FormMatches(form))); | 299 EXPECT_CALL(*store_.get(), AddLogin(FormMatches(form))); |
292 | 300 |
293 // Simulate saving the form. | 301 // Simulate saving the form. |
294 form_to_save->Save(); | 302 form_to_save->Save(); |
295 } | 303 } |
296 | 304 |
297 TEST_F(PasswordManagerTest, FormSeenThenLeftPage) { | 305 TEST_F(PasswordManagerTest, FormSeenThenLeftPage) { |
298 std::vector<PasswordForm*> result; // Empty password store. | 306 std::vector<PasswordForm*> result; // Empty password store. |
299 EXPECT_CALL(delegate_, FillPasswordForm(_)).Times(Exactly(0)); | 307 EXPECT_CALL(driver_, FillPasswordForm(_)).Times(Exactly(0)); |
300 EXPECT_CALL(*store_.get(), GetLogins(_, _, _)) | 308 EXPECT_CALL(*store_.get(), GetLogins(_, _, _)) |
301 .WillOnce(DoAll(WithArg<2>(InvokeConsumer(result)), Return())); | 309 .WillOnce(DoAll(WithArg<2>(InvokeConsumer(result)), Return())); |
302 std::vector<PasswordForm> observed; | 310 std::vector<PasswordForm> observed; |
303 PasswordForm form(MakeSimpleForm()); | 311 PasswordForm form(MakeSimpleForm()); |
304 observed.push_back(form); | 312 observed.push_back(form); |
305 manager()->OnPasswordFormsParsed(observed); // The initial load. | 313 manager()->OnPasswordFormsParsed(observed); // The initial load. |
306 manager()->OnPasswordFormsRendered(observed); // The initial layout. | 314 manager()->OnPasswordFormsRendered(observed); // The initial layout. |
307 | 315 |
308 // No message from the renderer that a password was submitted. No | 316 // No message from the renderer that a password was submitted. No |
309 // expected calls. | 317 // expected calls. |
310 EXPECT_CALL(delegate_, AddSavePasswordInfoBarIfPermitted(_)).Times(0); | 318 EXPECT_CALL(delegate_, AddSavePasswordInfoBarIfPermitted(_)).Times(0); |
311 observed.clear(); | 319 observed.clear(); |
312 manager()->OnPasswordFormsParsed(observed); // The post-navigation load. | 320 manager()->OnPasswordFormsParsed(observed); // The post-navigation load. |
313 manager()->OnPasswordFormsRendered(observed); // The post-navigation layout. | 321 manager()->OnPasswordFormsRendered(observed); // The post-navigation layout. |
314 } | 322 } |
315 | 323 |
316 TEST_F(PasswordManagerTest, FormSubmitAfterNavigateSubframe) { | 324 TEST_F(PasswordManagerTest, FormSubmitAfterNavigateSubframe) { |
317 // Test that navigating a subframe does not prevent us from showing the save | 325 // Test that navigating a subframe does not prevent us from showing the save |
318 // password infobar. | 326 // password infobar. |
319 std::vector<PasswordForm*> result; // Empty password store. | 327 std::vector<PasswordForm*> result; // Empty password store. |
320 EXPECT_CALL(delegate_, FillPasswordForm(_)).Times(Exactly(0)); | 328 EXPECT_CALL(driver_, FillPasswordForm(_)).Times(Exactly(0)); |
321 EXPECT_CALL(*store_.get(), GetLogins(_, _, _)) | 329 EXPECT_CALL(*store_.get(), GetLogins(_, _, _)) |
322 .WillOnce(DoAll(WithArg<2>(InvokeConsumer(result)), Return())); | 330 .WillOnce(DoAll(WithArg<2>(InvokeConsumer(result)), Return())); |
323 std::vector<PasswordForm> observed; | 331 std::vector<PasswordForm> observed; |
324 PasswordForm form(MakeSimpleForm()); | 332 PasswordForm form(MakeSimpleForm()); |
325 observed.push_back(form); | 333 observed.push_back(form); |
326 manager()->OnPasswordFormsParsed(observed); // The initial load. | 334 manager()->OnPasswordFormsParsed(observed); // The initial load. |
327 manager()->OnPasswordFormsRendered(observed); // The initial layout. | 335 manager()->OnPasswordFormsRendered(observed); // The initial layout. |
328 | 336 |
329 // Simulate navigating a sub-frame. | 337 // Simulate navigating a sub-frame. |
330 content::LoadCommittedDetails details; | 338 content::LoadCommittedDetails details; |
(...skipping 15 matching lines...) Expand all Loading... |
346 ASSERT_FALSE(NULL == form_to_save.get()); | 354 ASSERT_FALSE(NULL == form_to_save.get()); |
347 EXPECT_CALL(*store_.get(), AddLogin(FormMatches(form))); | 355 EXPECT_CALL(*store_.get(), AddLogin(FormMatches(form))); |
348 | 356 |
349 // Simulate saving the form, as if the info bar was accepted. | 357 // Simulate saving the form, as if the info bar was accepted. |
350 form_to_save->Save(); | 358 form_to_save->Save(); |
351 } | 359 } |
352 | 360 |
353 // This test verifies a fix for http://crbug.com/236673 | 361 // This test verifies a fix for http://crbug.com/236673 |
354 TEST_F(PasswordManagerTest, FormSubmitWithFormOnPreviousPage) { | 362 TEST_F(PasswordManagerTest, FormSubmitWithFormOnPreviousPage) { |
355 std::vector<PasswordForm*> result; // Empty password store. | 363 std::vector<PasswordForm*> result; // Empty password store. |
356 EXPECT_CALL(delegate_, FillPasswordForm(_)).Times(Exactly(0)); | 364 EXPECT_CALL(driver_, FillPasswordForm(_)).Times(Exactly(0)); |
357 EXPECT_CALL(*store_.get(), GetLogins(_, _, _)) | 365 EXPECT_CALL(*store_.get(), GetLogins(_, _, _)) |
358 .WillRepeatedly(DoAll(WithArg<2>(InvokeConsumer(result)), Return())); | 366 .WillRepeatedly(DoAll(WithArg<2>(InvokeConsumer(result)), Return())); |
359 PasswordForm first_form(MakeSimpleForm()); | 367 PasswordForm first_form(MakeSimpleForm()); |
360 first_form.origin = GURL("http://www.nytimes.com/"); | 368 first_form.origin = GURL("http://www.nytimes.com/"); |
361 first_form.action = GURL("https://myaccount.nytimes.com/auth/login"); | 369 first_form.action = GURL("https://myaccount.nytimes.com/auth/login"); |
362 first_form.signon_realm = "http://www.nytimes.com/"; | 370 first_form.signon_realm = "http://www.nytimes.com/"; |
363 PasswordForm second_form(MakeSimpleForm()); | 371 PasswordForm second_form(MakeSimpleForm()); |
364 second_form.origin = GURL("https://myaccount.nytimes.com/auth/login"); | 372 second_form.origin = GURL("https://myaccount.nytimes.com/auth/login"); |
365 second_form.action = GURL("https://myaccount.nytimes.com/auth/login"); | 373 second_form.action = GURL("https://myaccount.nytimes.com/auth/login"); |
366 second_form.signon_realm = "https://myaccount.nytimes.com/"; | 374 second_form.signon_realm = "https://myaccount.nytimes.com/"; |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
398 // Make sure that the saved form matches the second form, not the first. | 406 // Make sure that the saved form matches the second form, not the first. |
399 ASSERT_TRUE(form_to_save.get()); | 407 ASSERT_TRUE(form_to_save.get()); |
400 EXPECT_CALL(*store_.get(), AddLogin(FormMatches(second_form))); | 408 EXPECT_CALL(*store_.get(), AddLogin(FormMatches(second_form))); |
401 | 409 |
402 // Simulate saving the form, as if the info bar was accepted. | 410 // Simulate saving the form, as if the info bar was accepted. |
403 form_to_save->Save(); | 411 form_to_save->Save(); |
404 } | 412 } |
405 | 413 |
406 TEST_F(PasswordManagerTest, FormSubmitFailedLogin) { | 414 TEST_F(PasswordManagerTest, FormSubmitFailedLogin) { |
407 std::vector<PasswordForm*> result; // Empty password store. | 415 std::vector<PasswordForm*> result; // Empty password store. |
408 EXPECT_CALL(delegate_, FillPasswordForm(_)).Times(Exactly(0)); | 416 EXPECT_CALL(driver_, FillPasswordForm(_)).Times(Exactly(0)); |
409 EXPECT_CALL(*store_.get(), GetLogins(_, _, _)) | 417 EXPECT_CALL(*store_.get(), GetLogins(_, _, _)) |
410 .WillRepeatedly(DoAll(WithArg<2>(InvokeConsumer(result)), Return())); | 418 .WillRepeatedly(DoAll(WithArg<2>(InvokeConsumer(result)), Return())); |
411 std::vector<PasswordForm> observed; | 419 std::vector<PasswordForm> observed; |
412 PasswordForm form(MakeSimpleForm()); | 420 PasswordForm form(MakeSimpleForm()); |
413 observed.push_back(form); | 421 observed.push_back(form); |
414 manager()->OnPasswordFormsParsed(observed); // The initial load. | 422 manager()->OnPasswordFormsParsed(observed); // The initial load. |
415 manager()->OnPasswordFormsRendered(observed); // The initial layout. | 423 manager()->OnPasswordFormsRendered(observed); // The initial layout. |
416 | 424 |
417 manager()->ProvisionallySavePassword(form); | 425 manager()->ProvisionallySavePassword(form); |
418 | 426 |
419 // The form reappears, and is visible in the layout: | 427 // The form reappears, and is visible in the layout: |
420 // No expected calls to the PasswordStore... | 428 // No expected calls to the PasswordStore... |
421 manager()->OnPasswordFormsParsed(observed); | 429 manager()->OnPasswordFormsParsed(observed); |
422 manager()->OnPasswordFormsRendered(observed); | 430 manager()->OnPasswordFormsRendered(observed); |
423 } | 431 } |
424 | 432 |
425 TEST_F(PasswordManagerTest, FormSubmitInvisibleLogin) { | 433 TEST_F(PasswordManagerTest, FormSubmitInvisibleLogin) { |
426 // Tests fix of issue 28911: if the login form reappears on the subsequent | 434 // Tests fix of issue 28911: if the login form reappears on the subsequent |
427 // page, but is invisible, it shouldn't count as a failed login. | 435 // page, but is invisible, it shouldn't count as a failed login. |
428 std::vector<PasswordForm*> result; // Empty password store. | 436 std::vector<PasswordForm*> result; // Empty password store. |
429 EXPECT_CALL(delegate_, FillPasswordForm(_)).Times(Exactly(0)); | 437 EXPECT_CALL(driver_, FillPasswordForm(_)).Times(Exactly(0)); |
430 EXPECT_CALL(*store_.get(), GetLogins(_, _, _)) | 438 EXPECT_CALL(*store_.get(), GetLogins(_, _, _)) |
431 .WillRepeatedly(DoAll(WithArg<2>(InvokeConsumer(result)), Return())); | 439 .WillRepeatedly(DoAll(WithArg<2>(InvokeConsumer(result)), Return())); |
432 std::vector<PasswordForm> observed; | 440 std::vector<PasswordForm> observed; |
433 PasswordForm form(MakeSimpleForm()); | 441 PasswordForm form(MakeSimpleForm()); |
434 observed.push_back(form); | 442 observed.push_back(form); |
435 manager()->OnPasswordFormsParsed(observed); // The initial load. | 443 manager()->OnPasswordFormsParsed(observed); // The initial load. |
436 manager()->OnPasswordFormsRendered(observed); // The initial layout. | 444 manager()->OnPasswordFormsRendered(observed); // The initial layout. |
437 | 445 |
438 manager()->ProvisionallySavePassword(form); | 446 manager()->ProvisionallySavePassword(form); |
439 | 447 |
(...skipping 12 matching lines...) Expand all Loading... |
452 | 460 |
453 // Simulate saving the form. | 461 // Simulate saving the form. |
454 form_to_save->Save(); | 462 form_to_save->Save(); |
455 } | 463 } |
456 | 464 |
457 TEST_F(PasswordManagerTest, InitiallyInvisibleForm) { | 465 TEST_F(PasswordManagerTest, InitiallyInvisibleForm) { |
458 // Make sure an invisible login form still gets autofilled. | 466 // Make sure an invisible login form still gets autofilled. |
459 std::vector<PasswordForm*> result; | 467 std::vector<PasswordForm*> result; |
460 PasswordForm* existing = new PasswordForm(MakeSimpleForm()); | 468 PasswordForm* existing = new PasswordForm(MakeSimpleForm()); |
461 result.push_back(existing); | 469 result.push_back(existing); |
462 EXPECT_CALL(delegate_, FillPasswordForm(_)); | 470 EXPECT_CALL(driver_, FillPasswordForm(_)); |
463 EXPECT_CALL(*store_.get(), GetLogins(_, _, _)) | 471 EXPECT_CALL(*store_.get(), GetLogins(_, _, _)) |
464 .WillRepeatedly(DoAll(WithArg<2>(InvokeConsumer(result)), Return())); | 472 .WillRepeatedly(DoAll(WithArg<2>(InvokeConsumer(result)), Return())); |
465 std::vector<PasswordForm> observed; | 473 std::vector<PasswordForm> observed; |
466 PasswordForm form(MakeSimpleForm()); | 474 PasswordForm form(MakeSimpleForm()); |
467 observed.push_back(form); | 475 observed.push_back(form); |
468 manager()->OnPasswordFormsParsed(observed); // The initial load. | 476 manager()->OnPasswordFormsParsed(observed); // The initial load. |
469 observed.clear(); | 477 observed.clear(); |
470 manager()->OnPasswordFormsRendered(observed); // The initial layout. | 478 manager()->OnPasswordFormsRendered(observed); // The initial layout. |
471 | 479 |
472 manager()->OnPasswordFormsParsed(observed); // The post-navigation load. | 480 manager()->OnPasswordFormsParsed(observed); // The post-navigation load. |
(...skipping 14 matching lines...) Expand all Loading... |
487 | 495 |
488 TEST_F(PasswordManagerTest, FillPasswordsOnDisabledManager) { | 496 TEST_F(PasswordManagerTest, FillPasswordsOnDisabledManager) { |
489 // Test fix for issue 158296: Passwords must be filled even if the password | 497 // Test fix for issue 158296: Passwords must be filled even if the password |
490 // manager is disabled. | 498 // manager is disabled. |
491 std::vector<PasswordForm*> result; | 499 std::vector<PasswordForm*> result; |
492 PasswordForm* existing = new PasswordForm(MakeSimpleForm()); | 500 PasswordForm* existing = new PasswordForm(MakeSimpleForm()); |
493 result.push_back(existing); | 501 result.push_back(existing); |
494 TestingPrefServiceSyncable* prefService = profile()->GetTestingPrefService(); | 502 TestingPrefServiceSyncable* prefService = profile()->GetTestingPrefService(); |
495 prefService->SetUserPref(prefs::kPasswordManagerEnabled, | 503 prefService->SetUserPref(prefs::kPasswordManagerEnabled, |
496 base::Value::CreateBooleanValue(false)); | 504 base::Value::CreateBooleanValue(false)); |
497 EXPECT_CALL(delegate_, FillPasswordForm(_)); | 505 EXPECT_CALL(driver_, FillPasswordForm(_)); |
498 EXPECT_CALL(*store_.get(), | 506 EXPECT_CALL(*store_.get(), |
499 GetLogins(_, testing::Eq(PasswordStore::DISALLOW_PROMPT), _)) | 507 GetLogins(_, testing::Eq(PasswordStore::DISALLOW_PROMPT), _)) |
500 .WillRepeatedly(DoAll(WithArg<2>(InvokeConsumer(result)), Return())); | 508 .WillRepeatedly(DoAll(WithArg<2>(InvokeConsumer(result)), Return())); |
501 std::vector<PasswordForm> observed; | 509 std::vector<PasswordForm> observed; |
502 PasswordForm form(MakeSimpleForm()); | 510 PasswordForm form(MakeSimpleForm()); |
503 observed.push_back(form); | 511 observed.push_back(form); |
504 manager()->OnPasswordFormsParsed(observed); | 512 manager()->OnPasswordFormsParsed(observed); |
505 } | 513 } |
506 | 514 |
507 TEST_F(PasswordManagerTest, FormNotSavedAutocompleteOff) { | 515 TEST_F(PasswordManagerTest, FormNotSavedAutocompleteOff) { |
508 // Test password form with non-generated password will not be saved if | 516 // Test password form with non-generated password will not be saved if |
509 // autocomplete=off. | 517 // autocomplete=off. |
510 std::vector<PasswordForm*> result; // Empty password store. | 518 std::vector<PasswordForm*> result; // Empty password store. |
511 EXPECT_CALL(delegate_, FillPasswordForm(_)).Times(Exactly(0)); | 519 EXPECT_CALL(driver_, FillPasswordForm(_)).Times(Exactly(0)); |
512 EXPECT_CALL(*store_.get(), GetLogins(_, _, _)) | 520 EXPECT_CALL(*store_.get(), GetLogins(_, _, _)) |
513 .WillOnce(DoAll(WithArg<2>(InvokeConsumer(result)), Return())); | 521 .WillOnce(DoAll(WithArg<2>(InvokeConsumer(result)), Return())); |
514 std::vector<PasswordForm> observed; | 522 std::vector<PasswordForm> observed; |
515 PasswordForm form(MakeSimpleForm()); | 523 PasswordForm form(MakeSimpleForm()); |
516 form.password_autocomplete_set = false; | 524 form.password_autocomplete_set = false; |
517 observed.push_back(form); | 525 observed.push_back(form); |
518 manager()->OnPasswordFormsParsed(observed); // The initial load. | 526 manager()->OnPasswordFormsParsed(observed); // The initial load. |
519 manager()->OnPasswordFormsRendered(observed); // The initial layout. | 527 manager()->OnPasswordFormsRendered(observed); // The initial layout. |
520 | 528 |
521 // And the form submit contract is to call ProvisionallySavePassword. | 529 // And the form submit contract is to call ProvisionallySavePassword. |
522 manager()->ProvisionallySavePassword(form); | 530 manager()->ProvisionallySavePassword(form); |
523 | 531 |
524 // Password form should not be saved. | 532 // Password form should not be saved. |
525 EXPECT_CALL(delegate_, | 533 EXPECT_CALL(delegate_, |
526 AddSavePasswordInfoBarIfPermitted(_)).Times(Exactly(0)); | 534 AddSavePasswordInfoBarIfPermitted(_)).Times(Exactly(0)); |
527 EXPECT_CALL(*store_.get(), AddLogin(FormMatches(form))).Times(Exactly(0)); | 535 EXPECT_CALL(*store_.get(), AddLogin(FormMatches(form))).Times(Exactly(0)); |
528 | 536 |
529 // Now the password manager waits for the navigation to complete. | 537 // Now the password manager waits for the navigation to complete. |
530 observed.clear(); | 538 observed.clear(); |
531 manager()->OnPasswordFormsParsed(observed); // The post-navigation load. | 539 manager()->OnPasswordFormsParsed(observed); // The post-navigation load. |
532 manager()->OnPasswordFormsRendered(observed); // The post-navigation layout. | 540 manager()->OnPasswordFormsRendered(observed); // The post-navigation layout. |
533 } | 541 } |
534 | 542 |
535 TEST_F(PasswordManagerTest, GeneratedPasswordFormSavedAutocompleteOff) { | 543 TEST_F(PasswordManagerTest, GeneratedPasswordFormSavedAutocompleteOff) { |
536 // Test password form with generated password will still be saved if | 544 // Test password form with generated password will still be saved if |
537 // autocomplete=off. | 545 // autocomplete=off. |
538 std::vector<PasswordForm*> result; // Empty password store. | 546 std::vector<PasswordForm*> result; // Empty password store. |
539 EXPECT_CALL(delegate_, FillPasswordForm(_)).Times(Exactly(0)); | 547 EXPECT_CALL(driver_, FillPasswordForm(_)).Times(Exactly(0)); |
540 EXPECT_CALL(*store_.get(), GetLogins(_, _, _)) | 548 EXPECT_CALL(*store_.get(), GetLogins(_, _, _)) |
541 .WillOnce(DoAll(WithArg<2>(InvokeConsumer(result)), Return())); | 549 .WillOnce(DoAll(WithArg<2>(InvokeConsumer(result)), Return())); |
542 std::vector<PasswordForm> observed; | 550 std::vector<PasswordForm> observed; |
543 PasswordForm form(MakeSimpleForm()); | 551 PasswordForm form(MakeSimpleForm()); |
544 form.password_autocomplete_set = false; | 552 form.password_autocomplete_set = false; |
545 observed.push_back(form); | 553 observed.push_back(form); |
546 manager()->OnPasswordFormsParsed(observed); // The initial load. | 554 manager()->OnPasswordFormsParsed(observed); // The initial load. |
547 manager()->OnPasswordFormsRendered(observed); // The initial layout. | 555 manager()->OnPasswordFormsRendered(observed); // The initial layout. |
548 | 556 |
549 // Simulate the user generating the password and submitting the form. | 557 // Simulate the user generating the password and submitting the form. |
(...skipping 19 matching lines...) Expand all Loading... |
569 OnPasswordFormSubmitted(form); | 577 OnPasswordFormSubmitted(form); |
570 EXPECT_TRUE(FormsAreEqual(form, submitted_form_)); | 578 EXPECT_TRUE(FormsAreEqual(form, submitted_form_)); |
571 } | 579 } |
572 | 580 |
573 TEST_F(PasswordManagerTest, PasswordFormReappearance) { | 581 TEST_F(PasswordManagerTest, PasswordFormReappearance) { |
574 // Test the heuristic to know if a password form reappears. | 582 // Test the heuristic to know if a password form reappears. |
575 // We assume that if we send our credentials and there | 583 // We assume that if we send our credentials and there |
576 // is at least one visible password form in the next page that | 584 // is at least one visible password form in the next page that |
577 // means that our previous login attempt failed. | 585 // means that our previous login attempt failed. |
578 std::vector<PasswordForm*> result; // Empty password store. | 586 std::vector<PasswordForm*> result; // Empty password store. |
579 EXPECT_CALL(delegate_, FillPasswordForm(_)).Times(0); | 587 EXPECT_CALL(driver_, FillPasswordForm(_)).Times(0); |
580 EXPECT_CALL(*store_.get(), GetLogins(_, _, _)) | 588 EXPECT_CALL(*store_.get(), GetLogins(_, _, _)) |
581 .WillRepeatedly(DoAll(WithArg<2>(InvokeConsumer(result)), Return())); | 589 .WillRepeatedly(DoAll(WithArg<2>(InvokeConsumer(result)), Return())); |
582 std::vector<PasswordForm> observed; | 590 std::vector<PasswordForm> observed; |
583 PasswordForm login_form(MakeTwitterLoginForm()); | 591 PasswordForm login_form(MakeTwitterLoginForm()); |
584 observed.push_back(login_form); | 592 observed.push_back(login_form); |
585 manager()->OnPasswordFormsParsed(observed); // The initial load. | 593 manager()->OnPasswordFormsParsed(observed); // The initial load. |
586 manager()->OnPasswordFormsRendered(observed); // The initial layout. | 594 manager()->OnPasswordFormsRendered(observed); // The initial layout. |
587 | 595 |
588 manager()->ProvisionallySavePassword(login_form); | 596 manager()->ProvisionallySavePassword(login_form); |
589 | 597 |
590 PasswordForm failed_login_form(MakeTwitterFailedLoginForm()); | 598 PasswordForm failed_login_form(MakeTwitterFailedLoginForm()); |
591 observed.clear(); | 599 observed.clear(); |
592 observed.push_back(failed_login_form); | 600 observed.push_back(failed_login_form); |
593 // A PasswordForm appears, and is visible in the layout: | 601 // A PasswordForm appears, and is visible in the layout: |
594 // No expected calls to the PasswordStore... | 602 // No expected calls to the PasswordStore... |
595 manager()->OnPasswordFormsParsed(observed); | 603 manager()->OnPasswordFormsParsed(observed); |
596 manager()->OnPasswordFormsRendered(observed); | 604 manager()->OnPasswordFormsRendered(observed); |
597 } | 605 } |
OLD | NEW |