OLD | NEW |
---|---|
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "components/autofill/core/browser/personal_data_manager.h" | 5 #include "components/autofill/core/browser/personal_data_manager.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <algorithm> | 9 #include <algorithm> |
10 #include <list> | 10 #include <list> |
(...skipping 2120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2131 base::MessageLoop::current()->Run(); | 2131 base::MessageLoop::current()->Run(); |
2132 | 2132 |
2133 CreditCard expected2(base::GenerateGUID(), "https://www.example.com"); | 2133 CreditCard expected2(base::GenerateGUID(), "https://www.example.com"); |
2134 test::SetCreditCardInfo(&expected2, "", "5500000000000004", "02", "3999"); | 2134 test::SetCreditCardInfo(&expected2, "", "5500000000000004", "02", "3999"); |
2135 std::vector<CreditCard*> cards; | 2135 std::vector<CreditCard*> cards; |
2136 cards.push_back(&expected); | 2136 cards.push_back(&expected); |
2137 cards.push_back(&expected2); | 2137 cards.push_back(&expected2); |
2138 ExpectSameElements(cards, personal_data_->GetCreditCards()); | 2138 ExpectSameElements(cards, personal_data_->GetCreditCards()); |
2139 } | 2139 } |
2140 | 2140 |
2141 // This form has the expiration year as one field with MM/YY. | |
2142 TEST_F(PersonalDataManagerTest, ImportCreditCard_Month2DigitYearCombination) { | |
sebsg
2016/07/08 10:01:45
There seems to be a some duplicate code between th
Mathieu
2016/07/08 14:27:05
reused code when possible. I think the struct abst
| |
2143 FormData form; | |
2144 FormFieldData field; | |
2145 test::CreateTestFormField("Name on card:", "name_on_card", "John MMYY", | |
2146 "text", &field); | |
2147 form.fields.push_back(field); | |
2148 test::CreateTestFormField("Card Number:", "card_number", "4111111111111111", | |
2149 "text", &field); | |
2150 form.fields.push_back(field); | |
2151 test::CreateTestFormField("Exp Date:", "exp_date", "05/45", "text", &field); | |
2152 field.autocomplete_attribute = "cc-exp"; | |
2153 field.max_length = 5; | |
2154 form.fields.push_back(field); | |
2155 | |
2156 FormStructure form_structure(form); | |
2157 form_structure.DetermineHeuristicTypes(); | |
2158 std::unique_ptr<CreditCard> imported_credit_card; | |
2159 EXPECT_TRUE(ImportCreditCard(form_structure, false, &imported_credit_card)); | |
2160 ASSERT_TRUE(imported_credit_card); | |
2161 personal_data_->SaveImportedCreditCard(*imported_credit_card); | |
2162 | |
2163 // Verify that the web database has been updated and the notification sent. | |
2164 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) | |
2165 .WillOnce(QuitMainMessageLoop()); | |
2166 base::MessageLoop::current()->Run(); | |
2167 | |
2168 CreditCard expected(base::GenerateGUID(), "https://www.example.com"); | |
2169 test::SetCreditCardInfo(&expected, "John MMYY", "4111111111111111", "05", | |
2170 "2045"); | |
2171 const std::vector<CreditCard*>& results = personal_data_->GetCreditCards(); | |
2172 ASSERT_EQ(1U, results.size()); | |
2173 EXPECT_EQ(0, expected.Compare(*results[0])); | |
2174 } | |
2175 | |
2176 // This form has the expiration year as one field with MM/YYYY. | |
2177 TEST_F(PersonalDataManagerTest, ImportCreditCard_Month4DigitYearCombination) { | |
2178 FormData form; | |
2179 FormFieldData field; | |
2180 test::CreateTestFormField("Name on card:", "name_on_card", "John MMYYYY", | |
2181 "text", &field); | |
2182 form.fields.push_back(field); | |
2183 test::CreateTestFormField("Card Number:", "card_number", "4111111111111111", | |
2184 "text", &field); | |
2185 form.fields.push_back(field); | |
2186 test::CreateTestFormField("Exp Date:", "exp_date", "05/2045", "text", &field); | |
2187 field.autocomplete_attribute = "cc-exp"; | |
2188 field.max_length = 7; | |
2189 form.fields.push_back(field); | |
2190 | |
2191 FormStructure form_structure(form); | |
2192 form_structure.DetermineHeuristicTypes(); | |
2193 std::unique_ptr<CreditCard> imported_credit_card; | |
2194 EXPECT_TRUE(ImportCreditCard(form_structure, false, &imported_credit_card)); | |
2195 ASSERT_TRUE(imported_credit_card); | |
2196 personal_data_->SaveImportedCreditCard(*imported_credit_card); | |
2197 | |
2198 // Verify that the web database has been updated and the notification sent. | |
2199 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) | |
2200 .WillOnce(QuitMainMessageLoop()); | |
2201 base::MessageLoop::current()->Run(); | |
2202 | |
2203 CreditCard expected(base::GenerateGUID(), "https://www.example.com"); | |
2204 test::SetCreditCardInfo(&expected, "John MMYYYY", "4111111111111111", "05", | |
2205 "2045"); | |
2206 const std::vector<CreditCard*>& results = personal_data_->GetCreditCards(); | |
2207 ASSERT_EQ(1U, results.size()); | |
2208 EXPECT_EQ(0, expected.Compare(*results[0])); | |
2209 } | |
2210 | |
2211 // This form has the expiration year as one field with M/YYYY. | |
2212 TEST_F(PersonalDataManagerTest, ImportCreditCard_1DigitMonth4DigitYear) { | |
2213 FormData form; | |
2214 FormFieldData field; | |
2215 test::CreateTestFormField("Name on card:", "name_on_card", "John MYYYY", | |
2216 "text", &field); | |
2217 form.fields.push_back(field); | |
2218 test::CreateTestFormField("Card Number:", "card_number", "4111111111111111", | |
2219 "text", &field); | |
2220 form.fields.push_back(field); | |
2221 test::CreateTestFormField("Exp Date:", "exp_date", "5/2045", "text", &field); | |
2222 field.autocomplete_attribute = "cc-exp"; | |
2223 form.fields.push_back(field); | |
2224 | |
2225 FormStructure form_structure(form); | |
2226 form_structure.DetermineHeuristicTypes(); | |
2227 std::unique_ptr<CreditCard> imported_credit_card; | |
2228 EXPECT_TRUE(ImportCreditCard(form_structure, false, &imported_credit_card)); | |
2229 ASSERT_TRUE(imported_credit_card); | |
2230 personal_data_->SaveImportedCreditCard(*imported_credit_card); | |
2231 | |
2232 // Verify that the web database has been updated and the notification sent. | |
2233 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) | |
2234 .WillOnce(QuitMainMessageLoop()); | |
2235 base::MessageLoop::current()->Run(); | |
2236 | |
2237 CreditCard expected(base::GenerateGUID(), "https://www.example.com"); | |
2238 test::SetCreditCardInfo(&expected, "John MYYYY", "4111111111111111", "05", | |
2239 "2045"); | |
2240 const std::vector<CreditCard*>& results = personal_data_->GetCreditCards(); | |
2241 ASSERT_EQ(1U, results.size()); | |
2242 EXPECT_EQ(0, expected.Compare(*results[0])); | |
2243 } | |
2244 | |
2245 // This form has the expiration year as a 2-digit field. | |
2246 TEST_F(PersonalDataManagerTest, ImportCreditCard_2DigitYear) { | |
2247 FormData form; | |
2248 FormFieldData field; | |
2249 test::CreateTestFormField("Name on card:", "name_on_card", "John Smith", | |
2250 "text", &field); | |
2251 form.fields.push_back(field); | |
2252 test::CreateTestFormField("Card Number:", "card_number", "4111111111111111", | |
2253 "text", &field); | |
2254 form.fields.push_back(field); | |
2255 test::CreateTestFormField("Exp Month:", "exp_month", "05", "text", &field); | |
2256 form.fields.push_back(field); | |
2257 test::CreateTestFormField("Exp Year:", "exp_year", "45", "text", &field); | |
2258 field.max_length = 2; | |
2259 form.fields.push_back(field); | |
2260 | |
2261 FormStructure form_structure(form); | |
2262 form_structure.DetermineHeuristicTypes(); | |
2263 std::unique_ptr<CreditCard> imported_credit_card; | |
2264 EXPECT_TRUE(ImportCreditCard(form_structure, false, &imported_credit_card)); | |
2265 ASSERT_TRUE(imported_credit_card); | |
2266 personal_data_->SaveImportedCreditCard(*imported_credit_card); | |
2267 | |
2268 // Verify that the web database has been updated and the notification sent. | |
2269 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) | |
2270 .WillOnce(QuitMainMessageLoop()); | |
2271 base::MessageLoop::current()->Run(); | |
2272 | |
2273 CreditCard expected(base::GenerateGUID(), "https://www.example.com"); | |
2274 test::SetCreditCardInfo(&expected, "John Smith", "4111111111111111", "05", | |
2275 "2045"); | |
2276 const std::vector<CreditCard*>& results = personal_data_->GetCreditCards(); | |
2277 ASSERT_EQ(1U, results.size()); | |
2278 EXPECT_EQ(0, expected.Compare(*results[0])); | |
2279 } | |
2280 | |
2141 // Tests that a credit card is extracted because it only matches a masked server | 2281 // Tests that a credit card is extracted because it only matches a masked server |
2142 // card. | 2282 // card. |
2143 TEST_F(PersonalDataManagerTest, | 2283 TEST_F(PersonalDataManagerTest, |
2144 ImportCreditCard_DuplicateServerCards_MaskedCard) { | 2284 ImportCreditCard_DuplicateServerCards_MaskedCard) { |
2145 // Add a masked server card. | 2285 // Add a masked server card. |
2146 std::vector<CreditCard> server_cards; | 2286 std::vector<CreditCard> server_cards; |
2147 server_cards.push_back(CreditCard(CreditCard::MASKED_SERVER_CARD, "a123")); | 2287 server_cards.push_back(CreditCard(CreditCard::MASKED_SERVER_CARD, "a123")); |
2148 test::SetCreditCardInfo(&server_cards.back(), "John Dillinger", | 2288 test::SetCreditCardInfo(&server_cards.back(), "John Dillinger", |
2149 "1111" /* Visa */, "01", "2999"); | 2289 "1111" /* Visa */, "01", "2999"); |
2150 server_cards.back().SetTypeForMaskedCard(kVisaCard); | 2290 server_cards.back().SetTypeForMaskedCard(kVisaCard); |
(...skipping 2474 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
4625 EXPECT_EQ(profile1.use_count() + profile2.use_count() + | 4765 EXPECT_EQ(profile1.use_count() + profile2.use_count() + |
4626 imported_profile.use_count(), | 4766 imported_profile.use_count(), |
4627 profiles[0]->use_count()); | 4767 profiles[0]->use_count()); |
4628 // The use date that results from the merge should be the one from the | 4768 // The use date that results from the merge should be the one from the |
4629 // imported profile since it was used just now. | 4769 // imported profile since it was used just now. |
4630 EXPECT_LT(base::Time::Now() - base::TimeDelta::FromSeconds(10), | 4770 EXPECT_LT(base::Time::Now() - base::TimeDelta::FromSeconds(10), |
4631 profiles[0]->use_date()); | 4771 profiles[0]->use_date()); |
4632 } | 4772 } |
4633 | 4773 |
4634 } // namespace autofill | 4774 } // namespace autofill |
OLD | NEW |