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" |
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
193 form.password_element == arg.password_element && | 193 form.password_element == arg.password_element && |
194 form.password_autocomplete_set == | 194 form.password_autocomplete_set == |
195 arg.password_autocomplete_set && | 195 arg.password_autocomplete_set && |
196 form.submit_element == arg.submit_element; | 196 form.submit_element == arg.submit_element; |
197 } | 197 } |
198 | 198 |
199 TEST_F(PasswordManagerTest, FormSubmitEmptyStore) { | 199 TEST_F(PasswordManagerTest, FormSubmitEmptyStore) { |
200 // Test that observing a newly submitted form shows the save password bar. | 200 // Test that observing a newly submitted form shows the save password bar. |
201 std::vector<PasswordForm*> result; // Empty password store. | 201 std::vector<PasswordForm*> result; // Empty password store. |
202 EXPECT_CALL(delegate_, FillPasswordForm(_)).Times(Exactly(0)); | 202 EXPECT_CALL(delegate_, FillPasswordForm(_)).Times(Exactly(0)); |
203 EXPECT_CALL(*store_.get(), GetLogins(_, _)) | 203 EXPECT_CALL(*store_.get(), GetLogins(_, _, _)) |
204 .WillOnce(DoAll(WithArg<1>(InvokeConsumer(result)), Return(1))); | 204 .WillOnce(DoAll(WithArg<2>(InvokeConsumer(result)), Return(1))); |
205 std::vector<PasswordForm> observed; | 205 std::vector<PasswordForm> observed; |
206 PasswordForm form(MakeSimpleForm()); | 206 PasswordForm form(MakeSimpleForm()); |
207 observed.push_back(form); | 207 observed.push_back(form); |
208 manager()->OnPasswordFormsParsed(observed); // The initial load. | 208 manager()->OnPasswordFormsParsed(observed); // The initial load. |
209 manager()->OnPasswordFormsRendered(observed); // The initial layout. | 209 manager()->OnPasswordFormsRendered(observed); // The initial layout. |
210 | 210 |
211 // And the form submit contract is to call ProvisionallySavePassword. | 211 // And the form submit contract is to call ProvisionallySavePassword. |
212 manager()->ProvisionallySavePassword(form); | 212 manager()->ProvisionallySavePassword(form); |
213 | 213 |
214 scoped_ptr<PasswordFormManager> form_to_save; | 214 scoped_ptr<PasswordFormManager> form_to_save; |
(...skipping 10 matching lines...) Expand all Loading... |
225 | 225 |
226 // Simulate saving the form, as if the info bar was accepted. | 226 // Simulate saving the form, as if the info bar was accepted. |
227 form_to_save->Save(); | 227 form_to_save->Save(); |
228 } | 228 } |
229 | 229 |
230 TEST_F(PasswordManagerTest, GeneratedPasswordFormSubmitEmptyStore) { | 230 TEST_F(PasswordManagerTest, GeneratedPasswordFormSubmitEmptyStore) { |
231 // This test is the same FormSubmitEmptyStore, except that it simulates the | 231 // This test is the same FormSubmitEmptyStore, except that it simulates the |
232 // user generating the password through the browser. | 232 // user generating the password through the browser. |
233 std::vector<PasswordForm*> result; // Empty password store. | 233 std::vector<PasswordForm*> result; // Empty password store. |
234 EXPECT_CALL(delegate_, FillPasswordForm(_)).Times(Exactly(0)); | 234 EXPECT_CALL(delegate_, FillPasswordForm(_)).Times(Exactly(0)); |
235 EXPECT_CALL(*store_.get(), GetLogins(_, _)) | 235 EXPECT_CALL(*store_.get(), GetLogins(_, _, _)) |
236 .WillOnce(DoAll(WithArg<1>(InvokeConsumer(result)), Return(1))); | 236 .WillOnce(DoAll(WithArg<2>(InvokeConsumer(result)), Return(1))); |
237 std::vector<PasswordForm> observed; | 237 std::vector<PasswordForm> observed; |
238 PasswordForm form(MakeSimpleForm()); | 238 PasswordForm form(MakeSimpleForm()); |
239 observed.push_back(form); | 239 observed.push_back(form); |
240 manager()->OnPasswordFormsParsed(observed); // The initial load. | 240 manager()->OnPasswordFormsParsed(observed); // The initial load. |
241 manager()->OnPasswordFormsRendered(observed); // The initial layout. | 241 manager()->OnPasswordFormsRendered(observed); // The initial layout. |
242 | 242 |
243 // Simulate the user generating the password and submitting the form. | 243 // Simulate the user generating the password and submitting the form. |
244 manager()->SetFormHasGeneratedPassword(form); | 244 manager()->SetFormHasGeneratedPassword(form); |
245 manager()->ProvisionallySavePassword(form); | 245 manager()->ProvisionallySavePassword(form); |
246 | 246 |
(...skipping 12 matching lines...) Expand all Loading... |
259 | 259 |
260 TEST_F(PasswordManagerTest, FormSubmitNoGoodMatch) { | 260 TEST_F(PasswordManagerTest, FormSubmitNoGoodMatch) { |
261 // Same as above, except with an existing form for the same signon realm, | 261 // Same as above, except with an existing form for the same signon realm, |
262 // but different origin. Detailed cases like this are covered by | 262 // but different origin. Detailed cases like this are covered by |
263 // PasswordFormManagerTest. | 263 // PasswordFormManagerTest. |
264 std::vector<PasswordForm*> result; | 264 std::vector<PasswordForm*> result; |
265 PasswordForm* existing_different = new PasswordForm(MakeSimpleForm()); | 265 PasswordForm* existing_different = new PasswordForm(MakeSimpleForm()); |
266 existing_different->username_value = ASCIIToUTF16("google2"); | 266 existing_different->username_value = ASCIIToUTF16("google2"); |
267 result.push_back(existing_different); | 267 result.push_back(existing_different); |
268 EXPECT_CALL(delegate_, FillPasswordForm(_)); | 268 EXPECT_CALL(delegate_, FillPasswordForm(_)); |
269 EXPECT_CALL(*store_.get(), GetLogins(_, _)) | 269 EXPECT_CALL(*store_.get(), GetLogins(_, _, _)) |
270 .WillOnce(DoAll(WithArg<1>(InvokeConsumer(result)), Return(1))); | 270 .WillOnce(DoAll(WithArg<2>(InvokeConsumer(result)), Return(1))); |
271 | 271 |
272 std::vector<PasswordForm> observed; | 272 std::vector<PasswordForm> observed; |
273 PasswordForm form(MakeSimpleForm()); | 273 PasswordForm form(MakeSimpleForm()); |
274 observed.push_back(form); | 274 observed.push_back(form); |
275 manager()->OnPasswordFormsParsed(observed); // The initial load. | 275 manager()->OnPasswordFormsParsed(observed); // The initial load. |
276 manager()->OnPasswordFormsRendered(observed); // The initial layout. | 276 manager()->OnPasswordFormsRendered(observed); // The initial layout. |
277 manager()->ProvisionallySavePassword(form); | 277 manager()->ProvisionallySavePassword(form); |
278 | 278 |
279 // We still expect an add, since we didn't have a good match. | 279 // We still expect an add, since we didn't have a good match. |
280 scoped_ptr<PasswordFormManager> form_to_save; | 280 scoped_ptr<PasswordFormManager> form_to_save; |
281 EXPECT_CALL(delegate_, AddSavePasswordInfoBarIfPermitted(_)) | 281 EXPECT_CALL(delegate_, AddSavePasswordInfoBarIfPermitted(_)) |
282 .WillOnce(WithArg<0>(SaveToScopedPtr(&form_to_save))); | 282 .WillOnce(WithArg<0>(SaveToScopedPtr(&form_to_save))); |
283 | 283 |
284 // Now the password manager waits for the navigation to complete. | 284 // Now the password manager waits for the navigation to complete. |
285 observed.clear(); | 285 observed.clear(); |
286 manager()->OnPasswordFormsParsed(observed); // The post-navigation load. | 286 manager()->OnPasswordFormsParsed(observed); // The post-navigation load. |
287 manager()->OnPasswordFormsRendered(observed); // The post-navigation layout. | 287 manager()->OnPasswordFormsRendered(observed); // The post-navigation layout. |
288 | 288 |
289 ASSERT_TRUE(form_to_save.get()); | 289 ASSERT_TRUE(form_to_save.get()); |
290 EXPECT_CALL(*store_.get(), AddLogin(FormMatches(form))); | 290 EXPECT_CALL(*store_.get(), AddLogin(FormMatches(form))); |
291 | 291 |
292 // Simulate saving the form. | 292 // Simulate saving the form. |
293 form_to_save->Save(); | 293 form_to_save->Save(); |
294 } | 294 } |
295 | 295 |
296 TEST_F(PasswordManagerTest, FormSeenThenLeftPage) { | 296 TEST_F(PasswordManagerTest, FormSeenThenLeftPage) { |
297 std::vector<PasswordForm*> result; // Empty password store. | 297 std::vector<PasswordForm*> result; // Empty password store. |
298 EXPECT_CALL(delegate_, FillPasswordForm(_)).Times(Exactly(0)); | 298 EXPECT_CALL(delegate_, FillPasswordForm(_)).Times(Exactly(0)); |
299 EXPECT_CALL(*store_.get(), GetLogins(_, _)) | 299 EXPECT_CALL(*store_.get(), GetLogins(_, _, _)) |
300 .WillOnce(DoAll(WithArg<1>(InvokeConsumer(result)), Return(1))); | 300 .WillOnce(DoAll(WithArg<2>(InvokeConsumer(result)), Return(1))); |
301 std::vector<PasswordForm> observed; | 301 std::vector<PasswordForm> observed; |
302 PasswordForm form(MakeSimpleForm()); | 302 PasswordForm form(MakeSimpleForm()); |
303 observed.push_back(form); | 303 observed.push_back(form); |
304 manager()->OnPasswordFormsParsed(observed); // The initial load. | 304 manager()->OnPasswordFormsParsed(observed); // The initial load. |
305 manager()->OnPasswordFormsRendered(observed); // The initial layout. | 305 manager()->OnPasswordFormsRendered(observed); // The initial layout. |
306 | 306 |
307 // No message from the renderer that a password was submitted. No | 307 // No message from the renderer that a password was submitted. No |
308 // expected calls. | 308 // expected calls. |
309 EXPECT_CALL(delegate_, AddSavePasswordInfoBarIfPermitted(_)).Times(0); | 309 EXPECT_CALL(delegate_, AddSavePasswordInfoBarIfPermitted(_)).Times(0); |
310 observed.clear(); | 310 observed.clear(); |
311 manager()->OnPasswordFormsParsed(observed); // The post-navigation load. | 311 manager()->OnPasswordFormsParsed(observed); // The post-navigation load. |
312 manager()->OnPasswordFormsRendered(observed); // The post-navigation layout. | 312 manager()->OnPasswordFormsRendered(observed); // The post-navigation layout. |
313 } | 313 } |
314 | 314 |
315 TEST_F(PasswordManagerTest, FormSubmitAfterNavigateSubframe) { | 315 TEST_F(PasswordManagerTest, FormSubmitAfterNavigateSubframe) { |
316 // Test that navigating a subframe does not prevent us from showing the save | 316 // Test that navigating a subframe does not prevent us from showing the save |
317 // password infobar. | 317 // password infobar. |
318 std::vector<PasswordForm*> result; // Empty password store. | 318 std::vector<PasswordForm*> result; // Empty password store. |
319 EXPECT_CALL(delegate_, FillPasswordForm(_)).Times(Exactly(0)); | 319 EXPECT_CALL(delegate_, FillPasswordForm(_)).Times(Exactly(0)); |
320 EXPECT_CALL(*store_.get(), GetLogins(_, _)) | 320 EXPECT_CALL(*store_.get(), GetLogins(_, _, _)) |
321 .WillOnce(DoAll(WithArg<1>(InvokeConsumer(result)), Return(1))); | 321 .WillOnce(DoAll(WithArg<2>(InvokeConsumer(result)), Return(1))); |
322 std::vector<PasswordForm> observed; | 322 std::vector<PasswordForm> observed; |
323 PasswordForm form(MakeSimpleForm()); | 323 PasswordForm form(MakeSimpleForm()); |
324 observed.push_back(form); | 324 observed.push_back(form); |
325 manager()->OnPasswordFormsParsed(observed); // The initial load. | 325 manager()->OnPasswordFormsParsed(observed); // The initial load. |
326 manager()->OnPasswordFormsRendered(observed); // The initial layout. | 326 manager()->OnPasswordFormsRendered(observed); // The initial layout. |
327 | 327 |
328 // Simulate navigating a sub-frame. | 328 // Simulate navigating a sub-frame. |
329 content::LoadCommittedDetails details; | 329 content::LoadCommittedDetails details; |
330 content::FrameNavigateParams params; | 330 content::FrameNavigateParams params; |
331 manager()->DidNavigateAnyFrame(details, params); | 331 manager()->DidNavigateAnyFrame(details, params); |
(...skipping 14 matching lines...) Expand all Loading... |
346 EXPECT_CALL(*store_.get(), AddLogin(FormMatches(form))); | 346 EXPECT_CALL(*store_.get(), AddLogin(FormMatches(form))); |
347 | 347 |
348 // Simulate saving the form, as if the info bar was accepted. | 348 // Simulate saving the form, as if the info bar was accepted. |
349 form_to_save->Save(); | 349 form_to_save->Save(); |
350 } | 350 } |
351 | 351 |
352 // This test verifies a fix for http://crbug.com/236673 | 352 // This test verifies a fix for http://crbug.com/236673 |
353 TEST_F(PasswordManagerTest, FormSubmitWithFormOnPreviousPage) { | 353 TEST_F(PasswordManagerTest, FormSubmitWithFormOnPreviousPage) { |
354 std::vector<PasswordForm*> result; // Empty password store. | 354 std::vector<PasswordForm*> result; // Empty password store. |
355 EXPECT_CALL(delegate_, FillPasswordForm(_)).Times(Exactly(0)); | 355 EXPECT_CALL(delegate_, FillPasswordForm(_)).Times(Exactly(0)); |
356 EXPECT_CALL(*store_.get(), GetLogins(_, _)) | 356 EXPECT_CALL(*store_.get(), GetLogins(_, _, _)) |
357 .WillRepeatedly(DoAll(WithArg<1>(InvokeConsumer(result)), Return(1))); | 357 .WillRepeatedly(DoAll(WithArg<2>(InvokeConsumer(result)), Return(1))); |
358 PasswordForm first_form(MakeSimpleForm()); | 358 PasswordForm first_form(MakeSimpleForm()); |
359 first_form.origin = GURL("http://www.nytimes.com/"); | 359 first_form.origin = GURL("http://www.nytimes.com/"); |
360 first_form.action = GURL("https://myaccount.nytimes.com/auth/login"); | 360 first_form.action = GURL("https://myaccount.nytimes.com/auth/login"); |
361 first_form.signon_realm = "http://www.nytimes.com/"; | 361 first_form.signon_realm = "http://www.nytimes.com/"; |
362 PasswordForm second_form(MakeSimpleForm()); | 362 PasswordForm second_form(MakeSimpleForm()); |
363 second_form.origin = GURL("https://myaccount.nytimes.com/auth/login"); | 363 second_form.origin = GURL("https://myaccount.nytimes.com/auth/login"); |
364 second_form.action = GURL("https://myaccount.nytimes.com/auth/login"); | 364 second_form.action = GURL("https://myaccount.nytimes.com/auth/login"); |
365 second_form.signon_realm = "https://myaccount.nytimes.com/"; | 365 second_form.signon_realm = "https://myaccount.nytimes.com/"; |
366 | 366 |
367 // Pretend that the form is hidden on the first page. | 367 // Pretend that the form is hidden on the first page. |
(...skipping 30 matching lines...) Expand all Loading... |
398 ASSERT_TRUE(form_to_save.get()); | 398 ASSERT_TRUE(form_to_save.get()); |
399 EXPECT_CALL(*store_.get(), AddLogin(FormMatches(second_form))); | 399 EXPECT_CALL(*store_.get(), AddLogin(FormMatches(second_form))); |
400 | 400 |
401 // Simulate saving the form, as if the info bar was accepted. | 401 // Simulate saving the form, as if the info bar was accepted. |
402 form_to_save->Save(); | 402 form_to_save->Save(); |
403 } | 403 } |
404 | 404 |
405 TEST_F(PasswordManagerTest, FormSubmitFailedLogin) { | 405 TEST_F(PasswordManagerTest, FormSubmitFailedLogin) { |
406 std::vector<PasswordForm*> result; // Empty password store. | 406 std::vector<PasswordForm*> result; // Empty password store. |
407 EXPECT_CALL(delegate_, FillPasswordForm(_)).Times(Exactly(0)); | 407 EXPECT_CALL(delegate_, FillPasswordForm(_)).Times(Exactly(0)); |
408 EXPECT_CALL(*store_.get(), GetLogins(_, _)) | 408 EXPECT_CALL(*store_.get(), GetLogins(_, _, _)) |
409 .WillRepeatedly(DoAll(WithArg<1>(InvokeConsumer(result)), Return(1))); | 409 .WillRepeatedly(DoAll(WithArg<2>(InvokeConsumer(result)), Return(1))); |
410 std::vector<PasswordForm> observed; | 410 std::vector<PasswordForm> observed; |
411 PasswordForm form(MakeSimpleForm()); | 411 PasswordForm form(MakeSimpleForm()); |
412 observed.push_back(form); | 412 observed.push_back(form); |
413 manager()->OnPasswordFormsParsed(observed); // The initial load. | 413 manager()->OnPasswordFormsParsed(observed); // The initial load. |
414 manager()->OnPasswordFormsRendered(observed); // The initial layout. | 414 manager()->OnPasswordFormsRendered(observed); // The initial layout. |
415 | 415 |
416 manager()->ProvisionallySavePassword(form); | 416 manager()->ProvisionallySavePassword(form); |
417 | 417 |
418 // The form reappears, and is visible in the layout: | 418 // The form reappears, and is visible in the layout: |
419 // No expected calls to the PasswordStore... | 419 // No expected calls to the PasswordStore... |
420 manager()->OnPasswordFormsParsed(observed); | 420 manager()->OnPasswordFormsParsed(observed); |
421 manager()->OnPasswordFormsRendered(observed); | 421 manager()->OnPasswordFormsRendered(observed); |
422 } | 422 } |
423 | 423 |
424 TEST_F(PasswordManagerTest, FormSubmitInvisibleLogin) { | 424 TEST_F(PasswordManagerTest, FormSubmitInvisibleLogin) { |
425 // Tests fix of issue 28911: if the login form reappears on the subsequent | 425 // Tests fix of issue 28911: if the login form reappears on the subsequent |
426 // page, but is invisible, it shouldn't count as a failed login. | 426 // page, but is invisible, it shouldn't count as a failed login. |
427 std::vector<PasswordForm*> result; // Empty password store. | 427 std::vector<PasswordForm*> result; // Empty password store. |
428 EXPECT_CALL(delegate_, FillPasswordForm(_)).Times(Exactly(0)); | 428 EXPECT_CALL(delegate_, FillPasswordForm(_)).Times(Exactly(0)); |
429 EXPECT_CALL(*store_.get(), GetLogins(_, _)) | 429 EXPECT_CALL(*store_.get(), GetLogins(_, _, _)) |
430 .WillRepeatedly(DoAll(WithArg<1>(InvokeConsumer(result)), Return(1))); | 430 .WillRepeatedly(DoAll(WithArg<2>(InvokeConsumer(result)), Return(1))); |
431 std::vector<PasswordForm> observed; | 431 std::vector<PasswordForm> observed; |
432 PasswordForm form(MakeSimpleForm()); | 432 PasswordForm form(MakeSimpleForm()); |
433 observed.push_back(form); | 433 observed.push_back(form); |
434 manager()->OnPasswordFormsParsed(observed); // The initial load. | 434 manager()->OnPasswordFormsParsed(observed); // The initial load. |
435 manager()->OnPasswordFormsRendered(observed); // The initial layout. | 435 manager()->OnPasswordFormsRendered(observed); // The initial layout. |
436 | 436 |
437 manager()->ProvisionallySavePassword(form); | 437 manager()->ProvisionallySavePassword(form); |
438 | 438 |
439 // Expect info bar to appear: | 439 // Expect info bar to appear: |
440 scoped_ptr<PasswordFormManager> form_to_save; | 440 scoped_ptr<PasswordFormManager> form_to_save; |
(...skipping 11 matching lines...) Expand all Loading... |
452 // Simulate saving the form. | 452 // Simulate saving the form. |
453 form_to_save->Save(); | 453 form_to_save->Save(); |
454 } | 454 } |
455 | 455 |
456 TEST_F(PasswordManagerTest, InitiallyInvisibleForm) { | 456 TEST_F(PasswordManagerTest, InitiallyInvisibleForm) { |
457 // Make sure an invisible login form still gets autofilled. | 457 // Make sure an invisible login form still gets autofilled. |
458 std::vector<PasswordForm*> result; | 458 std::vector<PasswordForm*> result; |
459 PasswordForm* existing = new PasswordForm(MakeSimpleForm()); | 459 PasswordForm* existing = new PasswordForm(MakeSimpleForm()); |
460 result.push_back(existing); | 460 result.push_back(existing); |
461 EXPECT_CALL(delegate_, FillPasswordForm(_)); | 461 EXPECT_CALL(delegate_, FillPasswordForm(_)); |
462 EXPECT_CALL(*store_.get(), GetLogins(_, _)) | 462 EXPECT_CALL(*store_.get(), GetLogins(_, _, _)) |
463 .WillRepeatedly(DoAll(WithArg<1>(InvokeConsumer(result)), Return(1))); | 463 .WillRepeatedly(DoAll(WithArg<2>(InvokeConsumer(result)), Return(1))); |
464 std::vector<PasswordForm> observed; | 464 std::vector<PasswordForm> observed; |
465 PasswordForm form(MakeSimpleForm()); | 465 PasswordForm form(MakeSimpleForm()); |
466 observed.push_back(form); | 466 observed.push_back(form); |
467 manager()->OnPasswordFormsParsed(observed); // The initial load. | 467 manager()->OnPasswordFormsParsed(observed); // The initial load. |
468 observed.clear(); | 468 observed.clear(); |
469 manager()->OnPasswordFormsRendered(observed); // The initial layout. | 469 manager()->OnPasswordFormsRendered(observed); // The initial layout. |
470 | 470 |
471 manager()->OnPasswordFormsParsed(observed); // The post-navigation load. | 471 manager()->OnPasswordFormsParsed(observed); // The post-navigation load. |
472 manager()->OnPasswordFormsRendered(observed); // The post-navigation layout. | 472 manager()->OnPasswordFormsRendered(observed); // The post-navigation layout. |
473 } | 473 } |
(...skipping 13 matching lines...) Expand all Loading... |
487 TEST_F(PasswordManagerTest, FillPasswordsOnDisabledManager) { | 487 TEST_F(PasswordManagerTest, FillPasswordsOnDisabledManager) { |
488 // Test fix for issue 158296: Passwords must be filled even if the password | 488 // Test fix for issue 158296: Passwords must be filled even if the password |
489 // manager is disabled. | 489 // manager is disabled. |
490 std::vector<PasswordForm*> result; | 490 std::vector<PasswordForm*> result; |
491 PasswordForm* existing = new PasswordForm(MakeSimpleForm()); | 491 PasswordForm* existing = new PasswordForm(MakeSimpleForm()); |
492 result.push_back(existing); | 492 result.push_back(existing); |
493 TestingPrefServiceSyncable* prefService = profile()->GetTestingPrefService(); | 493 TestingPrefServiceSyncable* prefService = profile()->GetTestingPrefService(); |
494 prefService->SetUserPref(prefs::kPasswordManagerEnabled, | 494 prefService->SetUserPref(prefs::kPasswordManagerEnabled, |
495 Value::CreateBooleanValue(false)); | 495 Value::CreateBooleanValue(false)); |
496 EXPECT_CALL(delegate_, FillPasswordForm(_)); | 496 EXPECT_CALL(delegate_, FillPasswordForm(_)); |
497 EXPECT_CALL(*store_.get(), GetLogins(_, _)) | 497 EXPECT_CALL(*store_.get(), |
498 .WillRepeatedly(DoAll(WithArg<1>(InvokeConsumer(result)), Return(1))); | 498 GetLogins(_, testing::Eq(PasswordStore::DISALLOW_PROMPT), _)) |
| 499 .WillRepeatedly(DoAll(WithArg<2>(InvokeConsumer(result)), Return(1))); |
499 std::vector<PasswordForm> observed; | 500 std::vector<PasswordForm> observed; |
500 PasswordForm form(MakeSimpleForm()); | 501 PasswordForm form(MakeSimpleForm()); |
501 observed.push_back(form); | 502 observed.push_back(form); |
502 manager()->OnPasswordFormsParsed(observed); | 503 manager()->OnPasswordFormsParsed(observed); |
503 } | 504 } |
504 | 505 |
505 TEST_F(PasswordManagerTest, FormNotSavedAutocompleteOff) { | 506 TEST_F(PasswordManagerTest, FormNotSavedAutocompleteOff) { |
506 // Test password form with non-generated password will not be saved if | 507 // Test password form with non-generated password will not be saved if |
507 // autocomplete=off. | 508 // autocomplete=off. |
508 std::vector<PasswordForm*> result; // Empty password store. | 509 std::vector<PasswordForm*> result; // Empty password store. |
509 EXPECT_CALL(delegate_, FillPasswordForm(_)).Times(Exactly(0)); | 510 EXPECT_CALL(delegate_, FillPasswordForm(_)).Times(Exactly(0)); |
510 EXPECT_CALL(*store_.get(), GetLogins(_, _)) | 511 EXPECT_CALL(*store_.get(), GetLogins(_, _, _)) |
511 .WillOnce(DoAll(WithArg<1>(InvokeConsumer(result)), Return(1))); | 512 .WillOnce(DoAll(WithArg<2>(InvokeConsumer(result)), Return(1))); |
512 std::vector<PasswordForm> observed; | 513 std::vector<PasswordForm> observed; |
513 PasswordForm form(MakeSimpleForm()); | 514 PasswordForm form(MakeSimpleForm()); |
514 form.password_autocomplete_set = false; | 515 form.password_autocomplete_set = false; |
515 observed.push_back(form); | 516 observed.push_back(form); |
516 manager()->OnPasswordFormsParsed(observed); // The initial load. | 517 manager()->OnPasswordFormsParsed(observed); // The initial load. |
517 manager()->OnPasswordFormsRendered(observed); // The initial layout. | 518 manager()->OnPasswordFormsRendered(observed); // The initial layout. |
518 | 519 |
519 // And the form submit contract is to call ProvisionallySavePassword. | 520 // And the form submit contract is to call ProvisionallySavePassword. |
520 manager()->ProvisionallySavePassword(form); | 521 manager()->ProvisionallySavePassword(form); |
521 | 522 |
522 // Password form should not be saved. | 523 // Password form should not be saved. |
523 EXPECT_CALL(delegate_, | 524 EXPECT_CALL(delegate_, |
524 AddSavePasswordInfoBarIfPermitted(_)).Times(Exactly(0)); | 525 AddSavePasswordInfoBarIfPermitted(_)).Times(Exactly(0)); |
525 EXPECT_CALL(*store_.get(), AddLogin(FormMatches(form))).Times(Exactly(0)); | 526 EXPECT_CALL(*store_.get(), AddLogin(FormMatches(form))).Times(Exactly(0)); |
526 | 527 |
527 // Now the password manager waits for the navigation to complete. | 528 // Now the password manager waits for the navigation to complete. |
528 observed.clear(); | 529 observed.clear(); |
529 manager()->OnPasswordFormsParsed(observed); // The post-navigation load. | 530 manager()->OnPasswordFormsParsed(observed); // The post-navigation load. |
530 manager()->OnPasswordFormsRendered(observed); // The post-navigation layout. | 531 manager()->OnPasswordFormsRendered(observed); // The post-navigation layout. |
531 } | 532 } |
532 | 533 |
533 TEST_F(PasswordManagerTest, GeneratedPasswordFormSavedAutocompleteOff) { | 534 TEST_F(PasswordManagerTest, GeneratedPasswordFormSavedAutocompleteOff) { |
534 // Test password form with generated password will still be saved if | 535 // Test password form with generated password will still be saved if |
535 // autocomplete=off. | 536 // autocomplete=off. |
536 std::vector<PasswordForm*> result; // Empty password store. | 537 std::vector<PasswordForm*> result; // Empty password store. |
537 EXPECT_CALL(delegate_, FillPasswordForm(_)).Times(Exactly(0)); | 538 EXPECT_CALL(delegate_, FillPasswordForm(_)).Times(Exactly(0)); |
538 EXPECT_CALL(*store_.get(), GetLogins(_, _)) | 539 EXPECT_CALL(*store_.get(), GetLogins(_, _, _)) |
539 .WillOnce(DoAll(WithArg<1>(InvokeConsumer(result)), Return(1))); | 540 .WillOnce(DoAll(WithArg<2>(InvokeConsumer(result)), Return(1))); |
540 std::vector<PasswordForm> observed; | 541 std::vector<PasswordForm> observed; |
541 PasswordForm form(MakeSimpleForm()); | 542 PasswordForm form(MakeSimpleForm()); |
542 form.password_autocomplete_set = false; | 543 form.password_autocomplete_set = false; |
543 observed.push_back(form); | 544 observed.push_back(form); |
544 manager()->OnPasswordFormsParsed(observed); // The initial load. | 545 manager()->OnPasswordFormsParsed(observed); // The initial load. |
545 manager()->OnPasswordFormsRendered(observed); // The initial layout. | 546 manager()->OnPasswordFormsRendered(observed); // The initial layout. |
546 | 547 |
547 // Simulate the user generating the password and submitting the form. | 548 // Simulate the user generating the password and submitting the form. |
548 manager()->SetFormHasGeneratedPassword(form); | 549 manager()->SetFormHasGeneratedPassword(form); |
549 manager()->ProvisionallySavePassword(form); | 550 manager()->ProvisionallySavePassword(form); |
(...skipping 18 matching lines...) Expand all Loading... |
568 EXPECT_TRUE(FormsAreEqual(form, submitted_form_)); | 569 EXPECT_TRUE(FormsAreEqual(form, submitted_form_)); |
569 } | 570 } |
570 | 571 |
571 TEST_F(PasswordManagerTest, PasswordFormReappearance) { | 572 TEST_F(PasswordManagerTest, PasswordFormReappearance) { |
572 // Test the heuristic to know if a password form reappears. | 573 // Test the heuristic to know if a password form reappears. |
573 // We assume that if we send our credentials and there | 574 // We assume that if we send our credentials and there |
574 // is at least one visible password form in the next page that | 575 // is at least one visible password form in the next page that |
575 // means that our previous login attempt failed. | 576 // means that our previous login attempt failed. |
576 std::vector<PasswordForm*> result; // Empty password store. | 577 std::vector<PasswordForm*> result; // Empty password store. |
577 EXPECT_CALL(delegate_, FillPasswordForm(_)).Times(0); | 578 EXPECT_CALL(delegate_, FillPasswordForm(_)).Times(0); |
578 EXPECT_CALL(*store_.get(), GetLogins(_, _)) | 579 EXPECT_CALL(*store_.get(), GetLogins(_, _, _)) |
579 .WillRepeatedly(DoAll(WithArg<1>(InvokeConsumer(result)), Return(1))); | 580 .WillRepeatedly(DoAll(WithArg<2>(InvokeConsumer(result)), Return(1))); |
580 std::vector<PasswordForm> observed; | 581 std::vector<PasswordForm> observed; |
581 PasswordForm login_form(MakeTwitterLoginForm()); | 582 PasswordForm login_form(MakeTwitterLoginForm()); |
582 observed.push_back(login_form); | 583 observed.push_back(login_form); |
583 manager()->OnPasswordFormsParsed(observed); // The initial load. | 584 manager()->OnPasswordFormsParsed(observed); // The initial load. |
584 manager()->OnPasswordFormsRendered(observed); // The initial layout. | 585 manager()->OnPasswordFormsRendered(observed); // The initial layout. |
585 | 586 |
586 manager()->ProvisionallySavePassword(login_form); | 587 manager()->ProvisionallySavePassword(login_form); |
587 | 588 |
588 PasswordForm failed_login_form(MakeTwitterFailedLoginForm()); | 589 PasswordForm failed_login_form(MakeTwitterFailedLoginForm()); |
589 observed.clear(); | 590 observed.clear(); |
590 observed.push_back(failed_login_form); | 591 observed.push_back(failed_login_form); |
591 // A PasswordForm appears, and is visible in the layout: | 592 // A PasswordForm appears, and is visible in the layout: |
592 // No expected calls to the PasswordStore... | 593 // No expected calls to the PasswordStore... |
593 manager()->OnPasswordFormsParsed(observed); | 594 manager()->OnPasswordFormsParsed(observed); |
594 manager()->OnPasswordFormsRendered(observed); | 595 manager()->OnPasswordFormsRendered(observed); |
595 } | 596 } |
OLD | NEW |