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

Side by Side Diff: chrome/browser/password_manager/password_store_mac_unittest.cc

Issue 454083002: Fix a memory leak in PasswordStoreMac (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 4 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 | Annotate | Revision Log
OLDNEW
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 "chrome/browser/password_manager/password_store_mac.h" 5 #include "chrome/browser/password_manager/password_store_mac.h"
6 6
7 #include "base/basictypes.h" 7 #include "base/basictypes.h"
8 #include "base/files/scoped_temp_dir.h" 8 #include "base/files/scoped_temp_dir.h"
9 #include "base/memory/scoped_vector.h" 9 #include "base/memory/scoped_vector.h"
10 #include "base/path_service.h" 10 #include "base/path_service.h"
(...skipping 484 matching lines...) Expand 10 before | Expand all | Expand 10 after
495 { PasswordForm::SCHEME_DIGEST, "https://some.domain.com/high_security", 495 { PasswordForm::SCHEME_DIGEST, "https://some.domain.com/high_security",
496 "https://some.domain.com", 496 "https://some.domain.com",
497 NULL, NULL, NULL, NULL, L"digest_auth_user", NULL, true, true, 0 }, 497 NULL, NULL, NULL, NULL, L"digest_auth_user", NULL, true, true, 0 },
498 }; 498 };
499 499
500 for (unsigned int i = 0; i < arraysize(base_form_data); ++i) { 500 for (unsigned int i = 0; i < arraysize(base_form_data); ++i) {
501 // Create a base form and make sure we find a match. 501 // Create a base form and make sure we find a match.
502 scoped_ptr<PasswordForm> base_form(CreatePasswordFormFromData( 502 scoped_ptr<PasswordForm> base_form(CreatePasswordFormFromData(
503 base_form_data[i])); 503 base_form_data[i]));
504 EXPECT_TRUE(keychain_adapter.HasPasswordsMergeableWithForm(*base_form)); 504 EXPECT_TRUE(keychain_adapter.HasPasswordsMergeableWithForm(*base_form));
505 PasswordForm* match = 505 scoped_ptr<PasswordForm> match =
506 keychain_adapter.PasswordExactlyMatchingForm(*base_form); 506 keychain_adapter.PasswordExactlyMatchingForm(*base_form);
507 EXPECT_TRUE(match != NULL); 507 EXPECT_TRUE(match);
508 if (match) { 508 if (match) {
509 EXPECT_EQ(base_form->scheme, match->scheme); 509 EXPECT_EQ(base_form->scheme, match->scheme);
510 EXPECT_EQ(base_form->origin, match->origin); 510 EXPECT_EQ(base_form->origin, match->origin);
511 EXPECT_EQ(base_form->username_value, match->username_value); 511 EXPECT_EQ(base_form->username_value, match->username_value);
512 delete match;
513 } 512 }
514 513
515 // Make sure that the matching isn't looser than it should be by checking 514 // Make sure that the matching isn't looser than it should be by checking
516 // that slightly altered forms don't match. 515 // that slightly altered forms don't match.
517 std::vector<PasswordForm*> modified_forms; 516 std::vector<PasswordForm*> modified_forms;
518 517
519 modified_forms.push_back(new PasswordForm(*base_form)); 518 modified_forms.push_back(new PasswordForm(*base_form));
520 modified_forms.back()->username_value = ASCIIToUTF16("wrong_user"); 519 modified_forms.back()->username_value = ASCIIToUTF16("wrong_user");
521 520
522 modified_forms.push_back(new PasswordForm(*base_form)); 521 modified_forms.push_back(new PasswordForm(*base_form));
523 SetPasswordFormPath(modified_forms.back(), "elsewhere.html"); 522 SetPasswordFormPath(modified_forms.back(), "elsewhere.html");
524 523
525 modified_forms.push_back(new PasswordForm(*base_form)); 524 modified_forms.push_back(new PasswordForm(*base_form));
526 modified_forms.back()->scheme = PasswordForm::SCHEME_OTHER; 525 modified_forms.back()->scheme = PasswordForm::SCHEME_OTHER;
527 526
528 modified_forms.push_back(new PasswordForm(*base_form)); 527 modified_forms.push_back(new PasswordForm(*base_form));
529 SetPasswordFormPort(modified_forms.back(), "1234"); 528 SetPasswordFormPort(modified_forms.back(), "1234");
530 529
531 modified_forms.push_back(new PasswordForm(*base_form)); 530 modified_forms.push_back(new PasswordForm(*base_form));
532 modified_forms.back()->blacklisted_by_user = true; 531 modified_forms.back()->blacklisted_by_user = true;
533 532
534 if (base_form->scheme == PasswordForm::SCHEME_BASIC || 533 if (base_form->scheme == PasswordForm::SCHEME_BASIC ||
535 base_form->scheme == PasswordForm::SCHEME_DIGEST) { 534 base_form->scheme == PasswordForm::SCHEME_DIGEST) {
536 modified_forms.push_back(new PasswordForm(*base_form)); 535 modified_forms.push_back(new PasswordForm(*base_form));
537 SetPasswordFormRealm(modified_forms.back(), "incorrect"); 536 SetPasswordFormRealm(modified_forms.back(), "incorrect");
538 } 537 }
539 538
540 for (unsigned int j = 0; j < modified_forms.size(); ++j) { 539 for (unsigned int j = 0; j < modified_forms.size(); ++j) {
541 PasswordForm* match = 540 scoped_ptr<PasswordForm> match =
542 keychain_adapter.PasswordExactlyMatchingForm(*modified_forms[j]); 541 keychain_adapter.PasswordExactlyMatchingForm(*modified_forms[j]);
543 EXPECT_EQ(NULL, match) << "In modified version " << j << " of base form " 542 EXPECT_EQ(NULL, match.get()) << "In modified version " << j
544 << i; 543 << " of base form " << i;
545 } 544 }
546 STLDeleteElements(&modified_forms); 545 STLDeleteElements(&modified_forms);
547 } 546 }
548 } 547 }
549 548
550 TEST_F(PasswordStoreMacInternalsTest, TestKeychainAdd) { 549 TEST_F(PasswordStoreMacInternalsTest, TestKeychainAdd) {
551 struct TestDataAndExpectation { 550 struct TestDataAndExpectation {
552 PasswordFormData data; 551 PasswordFormData data;
553 bool should_succeed; 552 bool should_succeed;
554 }; 553 };
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
644 EXPECT_TRUE(owned_keychain_adapter.AddPassword(*add_form)); 643 EXPECT_TRUE(owned_keychain_adapter.AddPassword(*add_form));
645 delete add_form; 644 delete add_form;
646 645
647 for (unsigned int i = 0; i < ARRAYSIZE_UNSAFE(test_data); ++i) { 646 for (unsigned int i = 0; i < ARRAYSIZE_UNSAFE(test_data); ++i) {
648 scoped_ptr<PasswordForm> form(CreatePasswordFormFromData( 647 scoped_ptr<PasswordForm> form(CreatePasswordFormFromData(
649 test_data[i].data)); 648 test_data[i].data));
650 EXPECT_EQ(test_data[i].should_succeed, 649 EXPECT_EQ(test_data[i].should_succeed,
651 owned_keychain_adapter.RemovePassword(*form)); 650 owned_keychain_adapter.RemovePassword(*form));
652 651
653 MacKeychainPasswordFormAdapter keychain_adapter(keychain_); 652 MacKeychainPasswordFormAdapter keychain_adapter(keychain_);
654 PasswordForm* match = keychain_adapter.PasswordExactlyMatchingForm(*form); 653 scoped_ptr<PasswordForm> match =
655 EXPECT_EQ(test_data[i].should_succeed, match == NULL); 654 keychain_adapter.PasswordExactlyMatchingForm(*form);
656 if (match) { 655 EXPECT_EQ(test_data[i].should_succeed, match.get() == NULL);
657 delete match;
658 }
659 } 656 }
660 } 657 }
661 658
662 TEST_F(PasswordStoreMacInternalsTest, TestFormMatch) { 659 TEST_F(PasswordStoreMacInternalsTest, TestFormMatch) {
663 PasswordForm base_form; 660 PasswordForm base_form;
664 base_form.signon_realm = std::string("http://some.domain.com/"); 661 base_form.signon_realm = std::string("http://some.domain.com/");
665 base_form.origin = GURL("http://some.domain.com/page.html"); 662 base_form.origin = GURL("http://some.domain.com/page.html");
666 base_form.username_value = ASCIIToUTF16("joe_user"); 663 base_form.username_value = ASCIIToUTF16("joe_user");
667 664
668 { 665 {
(...skipping 775 matching lines...) Expand 10 before | Expand all | Expand 10 after
1444 ASSERT_EQ(1u, matching_items.size()); 1441 ASSERT_EQ(1u, matching_items.size());
1445 EXPECT_EQ(ASCIIToUTF16("joe_user"), matching_items[0]->username_value); 1442 EXPECT_EQ(ASCIIToUTF16("joe_user"), matching_items[0]->username_value);
1446 matching_items.clear(); 1443 matching_items.clear();
1447 1444
1448 // Check the third-party password is still there. 1445 // Check the third-party password is still there.
1449 owned_keychain_adapter.SetFindsOnlyOwnedItems(false); 1446 owned_keychain_adapter.SetFindsOnlyOwnedItems(false);
1450 matching_items.get() = owned_keychain_adapter.PasswordsFillingForm( 1447 matching_items.get() = owned_keychain_adapter.PasswordsFillingForm(
1451 "http://some.domain.com/insecure.html", PasswordForm::SCHEME_HTML); 1448 "http://some.domain.com/insecure.html", PasswordForm::SCHEME_HTML);
1452 ASSERT_EQ(1u, matching_items.size()); 1449 ASSERT_EQ(1u, matching_items.size());
1453 } 1450 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698