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