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 <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 Loading... |
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, and do |
| 2063 // not overwrite existing verified profiles. |
| 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 EXPECT_TRUE(new_verified_profile.IsVerified()); |
| 2085 |
| 2086 personal_data_->SaveImportedProfile(new_verified_profile); |
| 2087 |
| 2088 // Verify that the web database has been updated and the notification sent. |
| 2089 EXPECT_CALL(personal_data_observer_, |
| 2090 OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop()); |
| 2091 base::MessageLoop::current()->Run(); |
| 2092 |
| 2093 // Expect that the existing profile is not modified, and instead the new |
| 2094 // profile is added. |
| 2095 const std::vector<AutofillProfile*>& results = personal_data_->GetProfiles(); |
| 2096 ASSERT_EQ(2U, results.size()); |
| 2097 EXPECT_EQ(0, profile.Compare(*results[0])); |
| 2098 EXPECT_EQ(0, new_verified_profile.Compare(*results[1])); |
| 2099 } |
| 2100 |
| 2101 // Ensure that verified credit cards can be saved via SaveImportedCreditCard. |
| 2102 TEST_F(PersonalDataManagerTest, SaveImportedCreditCardWithVerifiedData) { |
| 2103 // Start with a verified credit card. |
| 2104 CreditCard credit_card(base::GenerateGUID(), "Chrome settings"); |
| 2105 test::SetCreditCardInfo(&credit_card, |
| 2106 "Biggie Smalls", "4111 1111 1111 1111" /* Visa */, "01", "2011"); |
| 2107 EXPECT_TRUE(credit_card.IsVerified()); |
| 2108 |
| 2109 // Add the credit card to the database. |
| 2110 personal_data_->AddCreditCard(credit_card); |
| 2111 |
| 2112 // Verify that the web database has been updated and the notification sent. |
| 2113 EXPECT_CALL(personal_data_observer_, |
| 2114 OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop()); |
| 2115 base::MessageLoop::current()->Run(); |
| 2116 |
| 2117 CreditCard new_verified_card = credit_card; |
| 2118 new_verified_card.set_guid(base::GenerateGUID()); |
| 2119 new_verified_card.SetRawInfo(CREDIT_CARD_NAME, ASCIIToUTF16("B. Small")); |
| 2120 EXPECT_TRUE(new_verified_card.IsVerified()); |
| 2121 |
| 2122 personal_data_->SaveImportedCreditCard(new_verified_card); |
| 2123 |
| 2124 // Verify that the web database has been updated and the notification sent. |
| 2125 EXPECT_CALL(personal_data_observer_, |
| 2126 OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop()); |
| 2127 base::MessageLoop::current()->Run(); |
| 2128 |
| 2129 // Expect that the saved credit card is updated. |
| 2130 const std::vector<CreditCard*>& results = personal_data_->GetCreditCards(); |
| 2131 ASSERT_EQ(1U, results.size()); |
| 2132 EXPECT_EQ(ASCIIToUTF16("B. Small"), results[0]->GetRawInfo(CREDIT_CARD_NAME)); |
| 2133 } |
| 2134 |
2023 TEST_F(PersonalDataManagerTest, GetNonEmptyTypes) { | 2135 TEST_F(PersonalDataManagerTest, GetNonEmptyTypes) { |
2024 // Check that there are no available types with no profiles stored. | 2136 // Check that there are no available types with no profiles stored. |
2025 FieldTypeSet non_empty_types; | 2137 FieldTypeSet non_empty_types; |
2026 personal_data_->GetNonEmptyTypes(&non_empty_types); | 2138 personal_data_->GetNonEmptyTypes(&non_empty_types); |
2027 EXPECT_EQ(0U, non_empty_types.size()); | 2139 EXPECT_EQ(0U, non_empty_types.size()); |
2028 | 2140 |
2029 // Test with one profile stored. | 2141 // Test with one profile stored. |
2030 AutofillProfile profile0(base::GenerateGUID(), "https://www.example.com"); | 2142 AutofillProfile profile0(base::GenerateGUID(), "https://www.example.com"); |
2031 test::SetProfileInfo(&profile0, | 2143 test::SetProfileInfo(&profile0, |
2032 "Marion", NULL, "Morrison", | 2144 "Marion", NULL, "Morrison", |
(...skipping 265 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2298 // Removing shouldn't work. | 2410 // Removing shouldn't work. |
2299 personal_data_->RemoveByGUID(steve_jobs.guid()); | 2411 personal_data_->RemoveByGUID(steve_jobs.guid()); |
2300 personal_data_->RemoveByGUID(bill_gates.guid()); | 2412 personal_data_->RemoveByGUID(bill_gates.guid()); |
2301 | 2413 |
2302 ResetPersonalDataManager(); | 2414 ResetPersonalDataManager(); |
2303 EXPECT_EQ(1U, personal_data_->GetProfiles().size()); | 2415 EXPECT_EQ(1U, personal_data_->GetProfiles().size()); |
2304 EXPECT_EQ(1U, personal_data_->GetCreditCards().size()); | 2416 EXPECT_EQ(1U, personal_data_->GetCreditCards().size()); |
2305 } | 2417 } |
2306 | 2418 |
2307 } // namespace autofill | 2419 } // namespace autofill |
OLD | NEW |