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

Side by Side Diff: components/autofill/browser/personal_data_manager_unittest.cc

Issue 16034018: [Autofill] Support "importing" verified profiles and credit cards. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Improve variable name Created 7 years, 6 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
« no previous file with comments | « components/autofill/browser/personal_data_manager.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 <string> 5 #include <string>
6 6
7 #include "base/basictypes.h" 7 #include "base/basictypes.h"
8 #include "base/guid.h" 8 #include "base/guid.h"
9 #include "base/memory/scoped_ptr.h" 9 #include "base/memory/scoped_ptr.h"
10 #include "base/message_loop.h" 10 #include "base/message_loop.h"
(...skipping 2002 matching lines...) Expand 10 before | Expand all | Expand 10 after
2013 // Since no refresh is expected, reload the data from the database to make 2013 // Since no refresh is expected, reload the data from the database to make
2014 // sure no changes were written out. 2014 // sure no changes were written out.
2015 ResetPersonalDataManager(); 2015 ResetPersonalDataManager();
2016 2016
2017 // Expect that the saved credit card is not modified. 2017 // Expect that the saved credit card is not modified.
2018 const std::vector<CreditCard*>& results = personal_data_->GetCreditCards(); 2018 const std::vector<CreditCard*>& results = personal_data_->GetCreditCards();
2019 ASSERT_EQ(1U, results.size()); 2019 ASSERT_EQ(1U, results.size());
2020 EXPECT_EQ(0, credit_card.Compare(*results[0])); 2020 EXPECT_EQ(0, credit_card.Compare(*results[0]));
2021 } 2021 }
2022 2022
2023 // Ensure that verified profiles can be saved via SaveImportedProfile,
2024 // overwriting existing unverified profiles.
2025 TEST_F(PersonalDataManagerTest, SaveImportedProfileWithVerifiedData) {
2026 // Start with an unverified profile.
2027 AutofillProfile profile(base::GenerateGUID(), "https://www.example.com");
2028 test::SetProfileInfo(&profile,
2029 "Marion", "Mitchell", "Morrison",
2030 "johnwayne@me.xyz", "Fox", "123 Zoo St.", "unit 5", "Hollywood", "CA",
2031 "91601", "US", "12345678910");
2032 EXPECT_FALSE(profile.IsVerified());
2033
2034 // Add the profile to the database.
2035 personal_data_->AddProfile(profile);
2036
2037 // Verify that the web database has been updated and the notification sent.
2038 EXPECT_CALL(personal_data_observer_,
2039 OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop());
2040 base::MessageLoop::current()->Run();
2041
2042 AutofillProfile new_verified_profile = profile;
2043 new_verified_profile.set_guid(base::GenerateGUID());
2044 new_verified_profile.set_origin("Chrome settings");
2045 new_verified_profile.SetRawInfo(COMPANY_NAME, ASCIIToUTF16("Fizzbang, Inc."));
2046 EXPECT_TRUE(new_verified_profile.IsVerified());
2047
2048 personal_data_->SaveImportedProfile(new_verified_profile);
2049
2050 // Verify that the web database has been updated and the notification sent.
2051 EXPECT_CALL(personal_data_observer_,
2052 OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop());
2053 base::MessageLoop::current()->Run();
2054
2055 // Expect that the existing profile is not modified, and instead the new
2056 // profile is added.
2057 const std::vector<AutofillProfile*>& results = personal_data_->GetProfiles();
2058 ASSERT_EQ(1U, results.size());
2059 EXPECT_EQ(0, new_verified_profile.Compare(*results[0]));
2060 }
2061
2062 // Ensure that verified profiles can be saved via SaveImportedProfile,
2063 // overwriting existing verified profiles as well.
2064 TEST_F(PersonalDataManagerTest, SaveImportedProfileWithExistingVerifiedData) {
2065 // Start with a verified profile.
2066 AutofillProfile profile(base::GenerateGUID(), "Chrome settings");
2067 test::SetProfileInfo(&profile,
2068 "Marion", "Mitchell", "Morrison",
2069 "johnwayne@me.xyz", "Fox", "123 Zoo St.", "unit 5", "Hollywood", "CA",
2070 "91601", "US", "12345678910");
2071 EXPECT_TRUE(profile.IsVerified());
2072
2073 // Add the profile to the database.
2074 personal_data_->AddProfile(profile);
2075
2076 // Verify that the web database has been updated and the notification sent.
2077 EXPECT_CALL(personal_data_observer_,
2078 OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop());
2079 base::MessageLoop::current()->Run();
2080
2081 AutofillProfile new_verified_profile = profile;
2082 new_verified_profile.set_guid(base::GenerateGUID());
2083 new_verified_profile.SetRawInfo(COMPANY_NAME, ASCIIToUTF16("Fizzbang, Inc."));
2084 new_verified_profile.SetRawInfo(NAME_MIDDLE, base::string16());
2085 EXPECT_TRUE(new_verified_profile.IsVerified());
2086
2087 personal_data_->SaveImportedProfile(new_verified_profile);
2088
2089 // Verify that the web database has been updated and the notification sent.
2090 EXPECT_CALL(personal_data_observer_,
2091 OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop());
2092 base::MessageLoop::current()->Run();
2093
2094 // The new profile should be merged into the existing one.
2095 AutofillProfile expected_profile = new_verified_profile;
2096 expected_profile.set_guid(profile.guid());
2097 std::vector<base::string16> names;
2098 expected_profile.GetRawMultiInfo(NAME_FULL, &names);
2099 names.insert(names.begin(), ASCIIToUTF16("Marion Mitchell Morrison"));
2100 expected_profile.SetRawMultiInfo(NAME_FULL, names);
2101
2102 const std::vector<AutofillProfile*>& results = personal_data_->GetProfiles();
2103 ASSERT_EQ(1U, results.size());
2104 EXPECT_EQ(expected_profile, *results[0]);
2105 }
2106
2107 // Ensure that verified credit cards can be saved via SaveImportedCreditCard.
2108 TEST_F(PersonalDataManagerTest, SaveImportedCreditCardWithVerifiedData) {
2109 // Start with a verified credit card.
2110 CreditCard credit_card(base::GenerateGUID(), "Chrome settings");
2111 test::SetCreditCardInfo(&credit_card,
2112 "Biggie Smalls", "4111 1111 1111 1111" /* Visa */, "01", "2011");
2113 EXPECT_TRUE(credit_card.IsVerified());
2114
2115 // Add the credit card to the database.
2116 personal_data_->AddCreditCard(credit_card);
2117
2118 // Verify that the web database has been updated and the notification sent.
2119 EXPECT_CALL(personal_data_observer_,
2120 OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop());
2121 base::MessageLoop::current()->Run();
2122
2123 CreditCard new_verified_card = credit_card;
2124 new_verified_card.set_guid(base::GenerateGUID());
2125 new_verified_card.SetRawInfo(CREDIT_CARD_NAME, ASCIIToUTF16("B. Small"));
2126 EXPECT_TRUE(new_verified_card.IsVerified());
2127
2128 personal_data_->SaveImportedCreditCard(new_verified_card);
2129
2130 // Verify that the web database has been updated and the notification sent.
2131 EXPECT_CALL(personal_data_observer_,
2132 OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop());
2133 base::MessageLoop::current()->Run();
2134
2135 // Expect that the saved credit card is updated.
2136 const std::vector<CreditCard*>& results = personal_data_->GetCreditCards();
2137 ASSERT_EQ(1U, results.size());
2138 EXPECT_EQ(ASCIIToUTF16("B. Small"), results[0]->GetRawInfo(CREDIT_CARD_NAME));
2139 }
2140
2023 TEST_F(PersonalDataManagerTest, GetNonEmptyTypes) { 2141 TEST_F(PersonalDataManagerTest, GetNonEmptyTypes) {
2024 // Check that there are no available types with no profiles stored. 2142 // Check that there are no available types with no profiles stored.
2025 FieldTypeSet non_empty_types; 2143 FieldTypeSet non_empty_types;
2026 personal_data_->GetNonEmptyTypes(&non_empty_types); 2144 personal_data_->GetNonEmptyTypes(&non_empty_types);
2027 EXPECT_EQ(0U, non_empty_types.size()); 2145 EXPECT_EQ(0U, non_empty_types.size());
2028 2146
2029 // Test with one profile stored. 2147 // Test with one profile stored.
2030 AutofillProfile profile0(base::GenerateGUID(), "https://www.example.com"); 2148 AutofillProfile profile0(base::GenerateGUID(), "https://www.example.com");
2031 test::SetProfileInfo(&profile0, 2149 test::SetProfileInfo(&profile0,
2032 "Marion", NULL, "Morrison", 2150 "Marion", NULL, "Morrison",
(...skipping 265 matching lines...) Expand 10 before | Expand all | Expand 10 after
2298 // Removing shouldn't work. 2416 // Removing shouldn't work.
2299 personal_data_->RemoveByGUID(steve_jobs.guid()); 2417 personal_data_->RemoveByGUID(steve_jobs.guid());
2300 personal_data_->RemoveByGUID(bill_gates.guid()); 2418 personal_data_->RemoveByGUID(bill_gates.guid());
2301 2419
2302 ResetPersonalDataManager(); 2420 ResetPersonalDataManager();
2303 EXPECT_EQ(1U, personal_data_->GetProfiles().size()); 2421 EXPECT_EQ(1U, personal_data_->GetProfiles().size());
2304 EXPECT_EQ(1U, personal_data_->GetCreditCards().size()); 2422 EXPECT_EQ(1U, personal_data_->GetCreditCards().size());
2305 } 2423 }
2306 2424
2307 } // namespace autofill 2425 } // namespace autofill
OLDNEW
« no previous file with comments | « components/autofill/browser/personal_data_manager.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698