Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(327)

Side by Side Diff: chrome/browser/ui/passwords/manage_passwords_state_unittest.cc

Issue 1096983002: Update usages of std::map to use ScopedPtrMap. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@passwordmanager-scopedmemory
Patch Set: Rebase. Created 5 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 "chrome/browser/ui/passwords/manage_passwords_state.h" 5 #include "chrome/browser/ui/passwords/manage_passwords_state.h"
6 6
7 #include "base/strings/utf_string_conversions.h" 7 #include "base/strings/utf_string_conversions.h"
8 #include "components/password_manager/core/browser/password_form_manager.h" 8 #include "components/password_manager/core/browser/password_form_manager.h"
9 #include "components/password_manager/core/browser/stub_password_manager_client. h" 9 #include "components/password_manager/core/browser/stub_password_manager_client. h"
10 #include "components/password_manager/core/common/credential_manager_types.h" 10 #include "components/password_manager/core/common/credential_manager_types.h"
(...skipping 306 matching lines...) Expand 10 before | Expand all | Expand 10 after
317 EXPECT_THAT(passwords_data().GetCurrentForms(), 317 EXPECT_THAT(passwords_data().GetCurrentForms(),
318 ElementsAre(Pointee(test_local_form()))); 318 ElementsAre(Pointee(test_local_form())));
319 EXPECT_THAT(passwords_data().federated_credentials_forms(), IsEmpty()); 319 EXPECT_THAT(passwords_data().federated_credentials_forms(), IsEmpty());
320 EXPECT_EQ(password_manager::ui::BLACKLIST_STATE, passwords_data().state()); 320 EXPECT_EQ(password_manager::ui::BLACKLIST_STATE, passwords_data().state());
321 EXPECT_EQ(test_submitted_form().origin, passwords_data().origin()); 321 EXPECT_EQ(test_submitted_form().origin, passwords_data().origin());
322 TestAllUpdates(); 322 TestAllUpdates();
323 } 323 }
324 324
325 TEST_F(ManagePasswordsStateTest, PasswordAutofilled) { 325 TEST_F(ManagePasswordsStateTest, PasswordAutofilled) {
326 autofill::PasswordFormMap password_form_map; 326 autofill::PasswordFormMap password_form_map;
327 password_form_map[test_local_form().username_value] = &test_local_form(); 327 password_form_map.insert(
328 test_local_form().username_value,
329 make_scoped_ptr(new autofill::PasswordForm(test_local_form())));
328 passwords_data().OnPasswordAutofilled(password_form_map); 330 passwords_data().OnPasswordAutofilled(password_form_map);
329 331
330 EXPECT_THAT(passwords_data().GetCurrentForms(), 332 EXPECT_THAT(passwords_data().GetCurrentForms(),
331 ElementsAre(Pointee(test_local_form()))); 333 ElementsAre(Pointee(test_local_form())));
332 EXPECT_THAT(passwords_data().federated_credentials_forms(), IsEmpty()); 334 EXPECT_THAT(passwords_data().federated_credentials_forms(), IsEmpty());
333 EXPECT_EQ(password_manager::ui::MANAGE_STATE, passwords_data().state()); 335 EXPECT_EQ(password_manager::ui::MANAGE_STATE, passwords_data().state());
334 EXPECT_EQ(test_local_form().origin, passwords_data().origin()); 336 EXPECT_EQ(test_local_form().origin, passwords_data().origin());
335 337
336 // |passwords_data| should hold a separate copy of test_local_form(). 338 // |passwords_data| should hold a separate copy of test_local_form().
337 EXPECT_THAT(passwords_data().GetCurrentForms(), 339 EXPECT_THAT(passwords_data().GetCurrentForms(),
338 Not(Contains(&test_local_form()))); 340 Not(Contains(&test_local_form())));
339 TestAllUpdates(); 341 TestAllUpdates();
340 } 342 }
341 343
342 TEST_F(ManagePasswordsStateTest, InactiveOnPSLMatched) { 344 TEST_F(ManagePasswordsStateTest, InactiveOnPSLMatched) {
343 autofill::PasswordForm psl_matched_test_form = test_local_form(); 345 autofill::PasswordForm psl_matched_test_form = test_local_form();
344 psl_matched_test_form.original_signon_realm = "http://pslmatched.example.com"; 346 psl_matched_test_form.original_signon_realm = "http://pslmatched.example.com";
345 autofill::PasswordFormMap password_form_map; 347 autofill::PasswordFormMap password_form_map;
346 password_form_map[psl_matched_test_form.username_value] = 348 password_form_map.insert(
347 &psl_matched_test_form; 349 psl_matched_test_form.username_value,
350 make_scoped_ptr(new autofill::PasswordForm(psl_matched_test_form)));
348 passwords_data().OnPasswordAutofilled(password_form_map); 351 passwords_data().OnPasswordAutofilled(password_form_map);
349 352
350 EXPECT_THAT(passwords_data().GetCurrentForms(), IsEmpty()); 353 EXPECT_THAT(passwords_data().GetCurrentForms(), IsEmpty());
351 EXPECT_THAT(passwords_data().federated_credentials_forms(), IsEmpty()); 354 EXPECT_THAT(passwords_data().federated_credentials_forms(), IsEmpty());
352 EXPECT_EQ(password_manager::ui::INACTIVE_STATE, passwords_data().state()); 355 EXPECT_EQ(password_manager::ui::INACTIVE_STATE, passwords_data().state());
353 EXPECT_EQ(GURL::EmptyGURL(), passwords_data().origin()); 356 EXPECT_EQ(GURL::EmptyGURL(), passwords_data().origin());
354 EXPECT_FALSE(passwords_data().form_manager()); 357 EXPECT_FALSE(passwords_data().form_manager());
355 } 358 }
356 359
357 TEST_F(ManagePasswordsStateTest, BlacklistBlockedAutofill) { 360 TEST_F(ManagePasswordsStateTest, BlacklistBlockedAutofill) {
358 autofill::PasswordForm blacklisted; 361 scoped_ptr<autofill::PasswordForm> blacklisted(new autofill::PasswordForm);
359 blacklisted.blacklisted_by_user = true; 362 autofill::PasswordForm& blacklisted_ref = *blacklisted;
360 blacklisted.origin = GURL("http://example.com/bad"); 363 blacklisted_ref.blacklisted_by_user = true;
364 blacklisted_ref.origin = GURL("http://example.com/bad");
361 autofill::PasswordFormMap password_form_map; 365 autofill::PasswordFormMap password_form_map;
362 password_form_map[blacklisted.username_value] = &blacklisted; 366 password_form_map.insert(blacklisted_ref.username_value, blacklisted.Pass());
363 password_form_map[test_local_form().username_value] = &test_local_form(); 367 scoped_ptr<autofill::PasswordForm> test_form(
368 new autofill::PasswordForm(test_local_form()));
369 autofill::PasswordForm* test_form_ptr = test_form.get();
370 password_form_map.insert(test_form_ptr->username_value, test_form.Pass());
364 passwords_data().OnBlacklistBlockedAutofill(password_form_map); 371 passwords_data().OnBlacklistBlockedAutofill(password_form_map);
365 372
366 EXPECT_THAT(passwords_data().GetCurrentForms(), 373 EXPECT_THAT(passwords_data().GetCurrentForms(),
367 ElementsAre(Pointee(blacklisted), Pointee(test_local_form()))); 374 ElementsAre(Pointee(blacklisted_ref), Pointee(*test_form_ptr)));
368 EXPECT_THAT(passwords_data().federated_credentials_forms(), IsEmpty()); 375 EXPECT_THAT(passwords_data().federated_credentials_forms(), IsEmpty());
369 EXPECT_EQ(password_manager::ui::BLACKLIST_STATE, passwords_data().state()); 376 EXPECT_EQ(password_manager::ui::BLACKLIST_STATE, passwords_data().state());
370 EXPECT_EQ(blacklisted.origin, passwords_data().origin()); 377 EXPECT_EQ(blacklisted_ref.origin, passwords_data().origin());
371 378
372 // |passwords_data| should hold a separate copy of test_local_form(). 379 // |passwords_data| should hold a separate copy of test_form.
373 EXPECT_THAT(passwords_data().GetCurrentForms(), 380 EXPECT_THAT(passwords_data().GetCurrentForms(), Not(Contains(test_form_ptr)));
374 Not(Contains(&test_local_form())));
375 TestAllUpdates(); 381 TestAllUpdates();
376 } 382 }
377 383
378 TEST_F(ManagePasswordsStateTest, Unblacklist) { 384 TEST_F(ManagePasswordsStateTest, Unblacklist) {
379 autofill::PasswordForm blacklisted; 385 scoped_ptr<autofill::PasswordForm> blacklisted(new autofill::PasswordForm);
380 blacklisted.blacklisted_by_user = true; 386 autofill::PasswordForm& blacklisted_ref = *blacklisted;
381 blacklisted.origin = test_local_form().origin; 387 blacklisted_ref.blacklisted_by_user = true;
388 blacklisted_ref.origin = test_local_form().origin;
382 autofill::PasswordFormMap password_form_map; 389 autofill::PasswordFormMap password_form_map;
383 password_form_map[blacklisted.username_value] = &blacklisted; 390 password_form_map.insert(blacklisted_ref.username_value, blacklisted.Pass());
384 passwords_data().OnBlacklistBlockedAutofill(password_form_map); 391 passwords_data().OnBlacklistBlockedAutofill(password_form_map);
385 EXPECT_EQ(password_manager::ui::BLACKLIST_STATE, passwords_data().state()); 392 EXPECT_EQ(password_manager::ui::BLACKLIST_STATE, passwords_data().state());
386 passwords_data().TransitionToState(password_manager::ui::MANAGE_STATE); 393 passwords_data().TransitionToState(password_manager::ui::MANAGE_STATE);
387 394
388 EXPECT_THAT(passwords_data().GetCurrentForms(), 395 EXPECT_THAT(passwords_data().GetCurrentForms(),
389 ElementsAre(Pointee(blacklisted))); 396 ElementsAre(Pointee(blacklisted_ref)));
390 EXPECT_THAT(passwords_data().federated_credentials_forms(), IsEmpty()); 397 EXPECT_THAT(passwords_data().federated_credentials_forms(), IsEmpty());
391 EXPECT_EQ(password_manager::ui::MANAGE_STATE, passwords_data().state()); 398 EXPECT_EQ(password_manager::ui::MANAGE_STATE, passwords_data().state());
392 EXPECT_EQ(blacklisted.origin, passwords_data().origin()); 399 EXPECT_EQ(blacklisted_ref.origin, passwords_data().origin());
393 TestAllUpdates(); 400 TestAllUpdates();
394 } 401 }
395 402
396 TEST_F(ManagePasswordsStateTest, OnInactive) { 403 TEST_F(ManagePasswordsStateTest, OnInactive) {
397 scoped_ptr<password_manager::PasswordFormManager> test_form_manager( 404 scoped_ptr<password_manager::PasswordFormManager> test_form_manager(
398 CreateFormManager()); 405 CreateFormManager());
399 test_form_manager->ProvisionallySave( 406 test_form_manager->ProvisionallySave(
400 test_submitted_form(), 407 test_submitted_form(),
401 password_manager::PasswordFormManager::IGNORE_OTHER_POSSIBLE_USERNAMES); 408 password_manager::PasswordFormManager::IGNORE_OTHER_POSSIBLE_USERNAMES);
402 passwords_data().OnPendingPassword(test_form_manager.Pass()); 409 passwords_data().OnPendingPassword(test_form_manager.Pass());
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after
550 EXPECT_THAT(passwords_data().GetCurrentForms(), 557 EXPECT_THAT(passwords_data().GetCurrentForms(),
551 UnorderedElementsAre(Pointee(test_local_form()), 558 UnorderedElementsAre(Pointee(test_local_form()),
552 Pointee(test_submitted_form()))); 559 Pointee(test_submitted_form())));
553 EXPECT_THAT(passwords_data().federated_credentials_forms(), IsEmpty()); 560 EXPECT_THAT(passwords_data().federated_credentials_forms(), IsEmpty());
554 EXPECT_EQ(password_manager::ui::MANAGE_STATE, passwords_data().state()); 561 EXPECT_EQ(password_manager::ui::MANAGE_STATE, passwords_data().state());
555 EXPECT_EQ(test_submitted_form().origin, passwords_data().origin()); 562 EXPECT_EQ(test_submitted_form().origin, passwords_data().origin());
556 } 563 }
557 564
558 TEST_F(ManagePasswordsStateTest, BackgroundAutofilledToBlacklisted) { 565 TEST_F(ManagePasswordsStateTest, BackgroundAutofilledToBlacklisted) {
559 autofill::PasswordFormMap password_form_map; 566 autofill::PasswordFormMap password_form_map;
560 password_form_map[test_local_form().username_value] = &test_local_form(); 567 password_form_map.insert(
568 test_local_form().username_value,
569 make_scoped_ptr(new autofill::PasswordForm(test_local_form())));
561 passwords_data().OnPasswordAutofilled(password_form_map); 570 passwords_data().OnPasswordAutofilled(password_form_map);
562 EXPECT_EQ(password_manager::ui::MANAGE_STATE, passwords_data().state()); 571 EXPECT_EQ(password_manager::ui::MANAGE_STATE, passwords_data().state());
563 572
564 // Process the blacklisted form. 573 // Process the blacklisted form.
565 autofill::PasswordForm blacklisted = test_local_form(); 574 autofill::PasswordForm blacklisted = test_local_form();
566 blacklisted.blacklisted_by_user = true; 575 blacklisted.blacklisted_by_user = true;
567 blacklisted.username_value = base::string16(); 576 blacklisted.username_value = base::string16();
568 password_manager::PasswordStoreChange change( 577 password_manager::PasswordStoreChange change(
569 password_manager::PasswordStoreChange::ADD, blacklisted); 578 password_manager::PasswordStoreChange::ADD, blacklisted);
570 password_manager::PasswordStoreChangeList list(1, change); 579 password_manager::PasswordStoreChangeList list(1, change);
(...skipping 10 matching lines...) Expand all
581 passwords_data().ProcessLoginsChanged(list); 590 passwords_data().ProcessLoginsChanged(list);
582 EXPECT_THAT(passwords_data().GetCurrentForms(), 591 EXPECT_THAT(passwords_data().GetCurrentForms(),
583 ElementsAre(Pointee(test_local_form()))); 592 ElementsAre(Pointee(test_local_form())));
584 EXPECT_THAT(passwords_data().federated_credentials_forms(), IsEmpty()); 593 EXPECT_THAT(passwords_data().federated_credentials_forms(), IsEmpty());
585 EXPECT_EQ(password_manager::ui::MANAGE_STATE, passwords_data().state()); 594 EXPECT_EQ(password_manager::ui::MANAGE_STATE, passwords_data().state());
586 EXPECT_EQ(test_local_form().origin, passwords_data().origin()); 595 EXPECT_EQ(test_local_form().origin, passwords_data().origin());
587 } 596 }
588 597
589 TEST_F(ManagePasswordsStateTest, BlacklistedToAutofilled) { 598 TEST_F(ManagePasswordsStateTest, BlacklistedToAutofilled) {
590 autofill::PasswordFormMap password_form_map; 599 autofill::PasswordFormMap password_form_map;
591 password_form_map[test_local_form().username_value] = &test_local_form(); 600 password_form_map.insert(
592 autofill::PasswordForm blacklisted; 601 test_local_form().username_value,
593 blacklisted.blacklisted_by_user = true; 602 make_scoped_ptr(new autofill::PasswordForm(test_local_form())));
594 blacklisted.origin = GURL("http://example.com/bad"); 603 scoped_ptr<autofill::PasswordForm> blacklisted(new autofill::PasswordForm);
595 password_form_map[blacklisted.username_value] = &blacklisted; 604 autofill::PasswordForm& blacklisted_ref = *blacklisted;
605 blacklisted_ref.blacklisted_by_user = true;
606 blacklisted_ref.origin = GURL("http://example.com/bad");
607 password_form_map.insert(blacklisted_ref.username_value, blacklisted.Pass());
596 passwords_data().OnBlacklistBlockedAutofill(password_form_map); 608 passwords_data().OnBlacklistBlockedAutofill(password_form_map);
597 EXPECT_EQ(password_manager::ui::BLACKLIST_STATE, passwords_data().state()); 609 EXPECT_EQ(password_manager::ui::BLACKLIST_STATE, passwords_data().state());
598 EXPECT_EQ(blacklisted.origin, passwords_data().origin()); 610 EXPECT_EQ(blacklisted_ref.origin, passwords_data().origin());
599 611
600 // Delete the blacklisted form. 612 // Delete the blacklisted form.
601 password_manager::PasswordStoreChangeList list; 613 password_manager::PasswordStoreChangeList list;
602 list.push_back(password_manager::PasswordStoreChange( 614 list.push_back(password_manager::PasswordStoreChange(
603 password_manager::PasswordStoreChange::REMOVE, blacklisted)); 615 password_manager::PasswordStoreChange::REMOVE, blacklisted_ref));
604 passwords_data().ProcessLoginsChanged(list); 616 passwords_data().ProcessLoginsChanged(list);
605 EXPECT_THAT(passwords_data().GetCurrentForms(), 617 EXPECT_THAT(passwords_data().GetCurrentForms(),
606 ElementsAre(Pointee(test_local_form()))); 618 ElementsAre(Pointee(test_local_form())));
607 EXPECT_THAT(passwords_data().federated_credentials_forms(), IsEmpty()); 619 EXPECT_THAT(passwords_data().federated_credentials_forms(), IsEmpty());
608 EXPECT_EQ(password_manager::ui::MANAGE_STATE, passwords_data().state()); 620 EXPECT_EQ(password_manager::ui::MANAGE_STATE, passwords_data().state());
609 EXPECT_EQ(blacklisted.origin, passwords_data().origin()); 621 EXPECT_EQ(blacklisted_ref.origin, passwords_data().origin());
610 } 622 }
611 623
612 } // namespace 624 } // namespace
OLDNEW
« no previous file with comments | « chrome/browser/ui/passwords/manage_passwords_state.cc ('k') | chrome/browser/ui/passwords/manage_passwords_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698