| 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 233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 244 | 244 |
| 245 // Add two test credit cards to the database. | 245 // Add two test credit cards to the database. |
| 246 personal_data_->AddCreditCard(credit_card0); | 246 personal_data_->AddCreditCard(credit_card0); |
| 247 personal_data_->AddCreditCard(credit_card1); | 247 personal_data_->AddCreditCard(credit_card1); |
| 248 | 248 |
| 249 // Verify that the web database has been updated and the notification sent. | 249 // Verify that the web database has been updated and the notification sent. |
| 250 EXPECT_CALL(personal_data_observer_, | 250 EXPECT_CALL(personal_data_observer_, |
| 251 OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop()); | 251 OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop()); |
| 252 MessageLoop::current()->Run(); | 252 MessageLoop::current()->Run(); |
| 253 | 253 |
| 254 const std::vector<CreditCard*>& results1 = personal_data_->credit_cards(); | 254 const std::vector<CreditCard*>& results1 = personal_data_->GetCreditCards(); |
| 255 ASSERT_EQ(2U, results1.size()); | 255 ASSERT_EQ(2U, results1.size()); |
| 256 EXPECT_EQ(0, credit_card0.Compare(*results1[0])); | 256 EXPECT_EQ(0, credit_card0.Compare(*results1[0])); |
| 257 EXPECT_EQ(0, credit_card1.Compare(*results1[1])); | 257 EXPECT_EQ(0, credit_card1.Compare(*results1[1])); |
| 258 | 258 |
| 259 // Update, remove, and add. | 259 // Update, remove, and add. |
| 260 credit_card0.SetRawInfo(CREDIT_CARD_NAME, ASCIIToUTF16("Joe")); | 260 credit_card0.SetRawInfo(CREDIT_CARD_NAME, ASCIIToUTF16("Joe")); |
| 261 personal_data_->UpdateCreditCard(credit_card0); | 261 personal_data_->UpdateCreditCard(credit_card0); |
| 262 personal_data_->RemoveByGUID(credit_card1.guid()); | 262 personal_data_->RemoveByGUID(credit_card1.guid()); |
| 263 personal_data_->AddCreditCard(credit_card2); | 263 personal_data_->AddCreditCard(credit_card2); |
| 264 | 264 |
| 265 // Verify that the web database has been updated and the notification sent. | 265 // Verify that the web database has been updated and the notification sent. |
| 266 EXPECT_CALL(personal_data_observer_, | 266 EXPECT_CALL(personal_data_observer_, |
| 267 OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop()); | 267 OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop()); |
| 268 MessageLoop::current()->Run(); | 268 MessageLoop::current()->Run(); |
| 269 | 269 |
| 270 const std::vector<CreditCard*>& results2 = personal_data_->credit_cards(); | 270 const std::vector<CreditCard*>& results2 = personal_data_->GetCreditCards(); |
| 271 ASSERT_EQ(2U, results2.size()); | 271 ASSERT_EQ(2U, results2.size()); |
| 272 EXPECT_EQ(credit_card0, *results2[0]); | 272 EXPECT_EQ(credit_card0, *results2[0]); |
| 273 EXPECT_EQ(credit_card2, *results2[1]); | 273 EXPECT_EQ(credit_card2, *results2[1]); |
| 274 | 274 |
| 275 // Reset the PersonalDataManager. This tests that the personal data was saved | 275 // Reset the PersonalDataManager. This tests that the personal data was saved |
| 276 // to the web database, and that we can load the credit cards from the web | 276 // to the web database, and that we can load the credit cards from the web |
| 277 // database. | 277 // database. |
| 278 ResetPersonalDataManager(); | 278 ResetPersonalDataManager(); |
| 279 | 279 |
| 280 // Verify that we've loaded the credit cards from the web database. | 280 // Verify that we've loaded the credit cards from the web database. |
| 281 const std::vector<CreditCard*>& results3 = personal_data_->credit_cards(); | 281 const std::vector<CreditCard*>& results3 = personal_data_->GetCreditCards(); |
| 282 ASSERT_EQ(2U, results3.size()); | 282 ASSERT_EQ(2U, results3.size()); |
| 283 EXPECT_EQ(credit_card0, *results3[0]); | 283 EXPECT_EQ(credit_card0, *results3[0]); |
| 284 EXPECT_EQ(credit_card2, *results3[1]); | 284 EXPECT_EQ(credit_card2, *results3[1]); |
| 285 } | 285 } |
| 286 | 286 |
| 287 TEST_F(PersonalDataManagerTest, AddProfilesAndCreditCards) { | 287 TEST_F(PersonalDataManagerTest, AddProfilesAndCreditCards) { |
| 288 AutofillProfile profile0; | 288 AutofillProfile profile0; |
| 289 test::SetProfileInfo(&profile0, | 289 test::SetProfileInfo(&profile0, |
| 290 "Marion", "Mitchell", "Morrison", | 290 "Marion", "Mitchell", "Morrison", |
| 291 "johnwayne@me.xyz", "Fox", "123 Zoo St.", "unit 5", "Hollywood", "CA", | 291 "johnwayne@me.xyz", "Fox", "123 Zoo St.", "unit 5", "Hollywood", "CA", |
| (...skipping 29 matching lines...) Expand all Loading... |
| 321 | 321 |
| 322 // Add two test credit cards to the database. | 322 // Add two test credit cards to the database. |
| 323 personal_data_->AddCreditCard(credit_card0); | 323 personal_data_->AddCreditCard(credit_card0); |
| 324 personal_data_->AddCreditCard(credit_card1); | 324 personal_data_->AddCreditCard(credit_card1); |
| 325 | 325 |
| 326 // Verify that the web database has been updated and the notification sent. | 326 // Verify that the web database has been updated and the notification sent. |
| 327 EXPECT_CALL(personal_data_observer_, | 327 EXPECT_CALL(personal_data_observer_, |
| 328 OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop()); | 328 OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop()); |
| 329 MessageLoop::current()->Run(); | 329 MessageLoop::current()->Run(); |
| 330 | 330 |
| 331 const std::vector<CreditCard*>& results2 = personal_data_->credit_cards(); | 331 const std::vector<CreditCard*>& results2 = personal_data_->GetCreditCards(); |
| 332 ASSERT_EQ(2U, results2.size()); | 332 ASSERT_EQ(2U, results2.size()); |
| 333 EXPECT_EQ(credit_card0, *results2[0]); | 333 EXPECT_EQ(credit_card0, *results2[0]); |
| 334 EXPECT_EQ(credit_card1, *results2[1]); | 334 EXPECT_EQ(credit_card1, *results2[1]); |
| 335 | 335 |
| 336 // Determine uniqueness by inserting all of the GUIDs into a set and verifying | 336 // Determine uniqueness by inserting all of the GUIDs into a set and verifying |
| 337 // the size of the set matches the number of GUIDs. | 337 // the size of the set matches the number of GUIDs. |
| 338 std::set<std::string> guids; | 338 std::set<std::string> guids; |
| 339 guids.insert(profile0.guid()); | 339 guids.insert(profile0.guid()); |
| 340 guids.insert(profile1.guid()); | 340 guids.insert(profile1.guid()); |
| 341 guids.insert(credit_card0.guid()); | 341 guids.insert(credit_card0.guid()); |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 410 personal_data_->AddCreditCard(credit_card0); | 410 personal_data_->AddCreditCard(credit_card0); |
| 411 | 411 |
| 412 // Note: no refresh here. | 412 // Note: no refresh here. |
| 413 | 413 |
| 414 // Reset the PersonalDataManager. This tests that the personal data was saved | 414 // Reset the PersonalDataManager. This tests that the personal data was saved |
| 415 // to the web database, and that we can load the credit cards from the web | 415 // to the web database, and that we can load the credit cards from the web |
| 416 // database. | 416 // database. |
| 417 ResetPersonalDataManager(); | 417 ResetPersonalDataManager(); |
| 418 | 418 |
| 419 // Verify that we've loaded the credit cards from the web database. | 419 // Verify that we've loaded the credit cards from the web database. |
| 420 const std::vector<CreditCard*>& results2 = personal_data_->credit_cards(); | 420 const std::vector<CreditCard*>& results2 = personal_data_->GetCreditCards(); |
| 421 ASSERT_EQ(0U, results2.size()); | 421 ASSERT_EQ(0U, results2.size()); |
| 422 } | 422 } |
| 423 | 423 |
| 424 TEST_F(PersonalDataManagerTest, Refresh) { | 424 TEST_F(PersonalDataManagerTest, Refresh) { |
| 425 AutofillProfile profile0; | 425 AutofillProfile profile0; |
| 426 test::SetProfileInfo(&profile0, | 426 test::SetProfileInfo(&profile0, |
| 427 "Marion", "Mitchell", "Morrison", | 427 "Marion", "Mitchell", "Morrison", |
| 428 "johnwayne@me.xyz", "Fox", "123 Zoo St.", "unit 5", "Hollywood", "CA", | 428 "johnwayne@me.xyz", "Fox", "123 Zoo St.", "unit 5", "Hollywood", "CA", |
| 429 "91601", "US", "12345678910"); | 429 "91601", "US", "12345678910"); |
| 430 | 430 |
| (...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 654 form.fields.push_back(field); | 654 form.fields.push_back(field); |
| 655 FormStructure form_structure(form, std::string()); | 655 FormStructure form_structure(form, std::string()); |
| 656 form_structure.DetermineHeuristicTypes(TestAutofillMetrics()); | 656 form_structure.DetermineHeuristicTypes(TestAutofillMetrics()); |
| 657 const CreditCard* imported_credit_card; | 657 const CreditCard* imported_credit_card; |
| 658 EXPECT_FALSE(personal_data_->ImportFormData(form_structure, | 658 EXPECT_FALSE(personal_data_->ImportFormData(form_structure, |
| 659 &imported_credit_card)); | 659 &imported_credit_card)); |
| 660 ASSERT_FALSE(imported_credit_card); | 660 ASSERT_FALSE(imported_credit_card); |
| 661 | 661 |
| 662 const std::vector<AutofillProfile*>& profiles = personal_data_->GetProfiles(); | 662 const std::vector<AutofillProfile*>& profiles = personal_data_->GetProfiles(); |
| 663 ASSERT_EQ(0U, profiles.size()); | 663 ASSERT_EQ(0U, profiles.size()); |
| 664 const std::vector<CreditCard*>& credit_cards = personal_data_->credit_cards(); | 664 const std::vector<CreditCard*>& cards = personal_data_->GetCreditCards(); |
| 665 ASSERT_EQ(0U, credit_cards.size()); | 665 ASSERT_EQ(0U, cards.size()); |
| 666 } | 666 } |
| 667 | 667 |
| 668 TEST_F(PersonalDataManagerTest, ImportFormMinimumAddressUSA) { | 668 TEST_F(PersonalDataManagerTest, ImportFormMinimumAddressUSA) { |
| 669 // United States addresses must specifiy one address line, a city, state and | 669 // United States addresses must specifiy one address line, a city, state and |
| 670 // zip code. | 670 // zip code. |
| 671 FormData form; | 671 FormData form; |
| 672 FormFieldData field; | 672 FormFieldData field; |
| 673 test::CreateTestFormField("Name:", "name", "Barack Obama", "text", &field); | 673 test::CreateTestFormField("Name:", "name", "Barack Obama", "text", &field); |
| 674 form.fields.push_back(field); | 674 form.fields.push_back(field); |
| 675 test::CreateTestFormField( | 675 test::CreateTestFormField( |
| (...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 812 personal_data_->AddCreditCard(credit_card2); | 812 personal_data_->AddCreditCard(credit_card2); |
| 813 personal_data_->AddCreditCard(credit_card3); | 813 personal_data_->AddCreditCard(credit_card3); |
| 814 personal_data_->AddCreditCard(credit_card4); | 814 personal_data_->AddCreditCard(credit_card4); |
| 815 personal_data_->AddCreditCard(credit_card5); | 815 personal_data_->AddCreditCard(credit_card5); |
| 816 | 816 |
| 817 // Reset the PersonalDataManager. This tests that the personal data was saved | 817 // Reset the PersonalDataManager. This tests that the personal data was saved |
| 818 // to the web database, and that we can load the credit cards from the web | 818 // to the web database, and that we can load the credit cards from the web |
| 819 // database. | 819 // database. |
| 820 ResetPersonalDataManager(); | 820 ResetPersonalDataManager(); |
| 821 | 821 |
| 822 const std::vector<CreditCard*>& results = personal_data_->credit_cards(); | 822 const std::vector<CreditCard*>& results = personal_data_->GetCreditCards(); |
| 823 ASSERT_EQ(6U, results.size()); | 823 ASSERT_EQ(6U, results.size()); |
| 824 EXPECT_EQ(credit_card0.guid(), results[0]->guid()); | 824 EXPECT_EQ(credit_card0.guid(), results[0]->guid()); |
| 825 EXPECT_EQ(credit_card1.guid(), results[1]->guid()); | 825 EXPECT_EQ(credit_card1.guid(), results[1]->guid()); |
| 826 EXPECT_EQ(credit_card2.guid(), results[2]->guid()); | 826 EXPECT_EQ(credit_card2.guid(), results[2]->guid()); |
| 827 EXPECT_EQ(credit_card3.guid(), results[3]->guid()); | 827 EXPECT_EQ(credit_card3.guid(), results[3]->guid()); |
| 828 EXPECT_EQ(credit_card4.guid(), results[4]->guid()); | 828 EXPECT_EQ(credit_card4.guid(), results[4]->guid()); |
| 829 EXPECT_EQ(credit_card5.guid(), results[5]->guid()); | 829 EXPECT_EQ(credit_card5.guid(), results[5]->guid()); |
| 830 } | 830 } |
| 831 | 831 |
| 832 TEST_F(PersonalDataManagerTest, AggregateTwoDifferentProfiles) { | 832 TEST_F(PersonalDataManagerTest, AggregateTwoDifferentProfiles) { |
| (...skipping 461 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1294 form_structure1.DetermineHeuristicTypes(TestAutofillMetrics()); | 1294 form_structure1.DetermineHeuristicTypes(TestAutofillMetrics()); |
| 1295 const CreditCard* imported_credit_card; | 1295 const CreditCard* imported_credit_card; |
| 1296 EXPECT_FALSE(personal_data_->ImportFormData(form_structure1, | 1296 EXPECT_FALSE(personal_data_->ImportFormData(form_structure1, |
| 1297 &imported_credit_card)); | 1297 &imported_credit_card)); |
| 1298 ASSERT_FALSE(imported_credit_card); | 1298 ASSERT_FALSE(imported_credit_card); |
| 1299 | 1299 |
| 1300 // Note: no refresh here. | 1300 // Note: no refresh here. |
| 1301 | 1301 |
| 1302 const std::vector<AutofillProfile*>& profiles = personal_data_->GetProfiles(); | 1302 const std::vector<AutofillProfile*>& profiles = personal_data_->GetProfiles(); |
| 1303 ASSERT_EQ(0U, profiles.size()); | 1303 ASSERT_EQ(0U, profiles.size()); |
| 1304 const std::vector<CreditCard*>& credit_cards = personal_data_->credit_cards(); | 1304 const std::vector<CreditCard*>& cards = personal_data_->GetCreditCards(); |
| 1305 ASSERT_EQ(0U, credit_cards.size()); | 1305 ASSERT_EQ(0U, cards.size()); |
| 1306 } | 1306 } |
| 1307 | 1307 |
| 1308 TEST_F(PersonalDataManagerTest, AggregateExistingAuxiliaryProfile) { | 1308 TEST_F(PersonalDataManagerTest, AggregateExistingAuxiliaryProfile) { |
| 1309 // Simulate having access to an auxiliary profile. | 1309 // Simulate having access to an auxiliary profile. |
| 1310 // |auxiliary_profile| will be owned by |personal_data_|. | 1310 // |auxiliary_profile| will be owned by |personal_data_|. |
| 1311 AutofillProfile* auxiliary_profile = new AutofillProfile; | 1311 AutofillProfile* auxiliary_profile = new AutofillProfile; |
| 1312 test::SetProfileInfo(auxiliary_profile, | 1312 test::SetProfileInfo(auxiliary_profile, |
| 1313 "Tester", "Frederick", "McAddressBookTesterson", | 1313 "Tester", "Frederick", "McAddressBookTesterson", |
| 1314 "tester@example.com", "Acme Inc.", "1 Main", "Apt A", "San Francisco", | 1314 "tester@example.com", "Acme Inc.", "1 Main", "Apt A", "San Francisco", |
| 1315 "CA", "94102", "US", "1.415.888.9999"); | 1315 "CA", "94102", "US", "1.415.888.9999"); |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1384 delete imported_credit_card; | 1384 delete imported_credit_card; |
| 1385 | 1385 |
| 1386 // Verify that the web database has been updated and the notification sent. | 1386 // Verify that the web database has been updated and the notification sent. |
| 1387 EXPECT_CALL(personal_data_observer_, | 1387 EXPECT_CALL(personal_data_observer_, |
| 1388 OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop()); | 1388 OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop()); |
| 1389 MessageLoop::current()->Run(); | 1389 MessageLoop::current()->Run(); |
| 1390 | 1390 |
| 1391 CreditCard expected; | 1391 CreditCard expected; |
| 1392 test::SetCreditCardInfo(&expected, | 1392 test::SetCreditCardInfo(&expected, |
| 1393 "Biggie Smalls", "4111111111111111", "01", "2011"); | 1393 "Biggie Smalls", "4111111111111111", "01", "2011"); |
| 1394 const std::vector<CreditCard*>& results = personal_data_->credit_cards(); | 1394 const std::vector<CreditCard*>& results = personal_data_->GetCreditCards(); |
| 1395 ASSERT_EQ(1U, results.size()); | 1395 ASSERT_EQ(1U, results.size()); |
| 1396 EXPECT_EQ(0, expected.Compare(*results[0])); | 1396 EXPECT_EQ(0, expected.Compare(*results[0])); |
| 1397 | 1397 |
| 1398 // Add a second different valid credit card. | 1398 // Add a second different valid credit card. |
| 1399 FormData form2; | 1399 FormData form2; |
| 1400 test::CreateTestFormField( | 1400 test::CreateTestFormField( |
| 1401 "Name on card:", "name_on_card", "", "text", &field); | 1401 "Name on card:", "name_on_card", "", "text", &field); |
| 1402 form2.fields.push_back(field); | 1402 form2.fields.push_back(field); |
| 1403 test::CreateTestFormField( | 1403 test::CreateTestFormField( |
| 1404 "Card Number:", "card_number", "5500 0000 0000 0004", "text", &field); | 1404 "Card Number:", "card_number", "5500 0000 0000 0004", "text", &field); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 1416 personal_data_->SaveImportedCreditCard(*imported_credit_card); | 1416 personal_data_->SaveImportedCreditCard(*imported_credit_card); |
| 1417 delete imported_credit_card; | 1417 delete imported_credit_card; |
| 1418 | 1418 |
| 1419 // Verify that the web database has been updated and the notification sent. | 1419 // Verify that the web database has been updated and the notification sent. |
| 1420 EXPECT_CALL(personal_data_observer_, | 1420 EXPECT_CALL(personal_data_observer_, |
| 1421 OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop()); | 1421 OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop()); |
| 1422 MessageLoop::current()->Run(); | 1422 MessageLoop::current()->Run(); |
| 1423 | 1423 |
| 1424 CreditCard expected2; | 1424 CreditCard expected2; |
| 1425 test::SetCreditCardInfo(&expected2,"", "5500000000000004", "02", "2012"); | 1425 test::SetCreditCardInfo(&expected2,"", "5500000000000004", "02", "2012"); |
| 1426 const std::vector<CreditCard*>& results2 = personal_data_->credit_cards(); | 1426 const std::vector<CreditCard*>& results2 = personal_data_->GetCreditCards(); |
| 1427 ASSERT_EQ(2U, results2.size()); | 1427 ASSERT_EQ(2U, results2.size()); |
| 1428 EXPECT_EQ(0, expected.Compare(*results2[0])); | 1428 EXPECT_EQ(0, expected.Compare(*results2[0])); |
| 1429 EXPECT_EQ(0, expected2.Compare(*results2[1])); | 1429 EXPECT_EQ(0, expected2.Compare(*results2[1])); |
| 1430 } | 1430 } |
| 1431 | 1431 |
| 1432 TEST_F(PersonalDataManagerTest, AggregateInvalidCreditCard) { | 1432 TEST_F(PersonalDataManagerTest, AggregateInvalidCreditCard) { |
| 1433 FormData form1; | 1433 FormData form1; |
| 1434 | 1434 |
| 1435 // Start with a single valid credit card form. | 1435 // Start with a single valid credit card form. |
| 1436 FormFieldData field; | 1436 FormFieldData field; |
| (...skipping 18 matching lines...) Expand all Loading... |
| 1455 delete imported_credit_card; | 1455 delete imported_credit_card; |
| 1456 | 1456 |
| 1457 // Verify that the web database has been updated and the notification sent. | 1457 // Verify that the web database has been updated and the notification sent. |
| 1458 EXPECT_CALL(personal_data_observer_, | 1458 EXPECT_CALL(personal_data_observer_, |
| 1459 OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop()); | 1459 OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop()); |
| 1460 MessageLoop::current()->Run(); | 1460 MessageLoop::current()->Run(); |
| 1461 | 1461 |
| 1462 CreditCard expected; | 1462 CreditCard expected; |
| 1463 test::SetCreditCardInfo(&expected, | 1463 test::SetCreditCardInfo(&expected, |
| 1464 "Biggie Smalls", "4111111111111111", "01", "2011"); | 1464 "Biggie Smalls", "4111111111111111", "01", "2011"); |
| 1465 const std::vector<CreditCard*>& results = personal_data_->credit_cards(); | 1465 const std::vector<CreditCard*>& results = personal_data_->GetCreditCards(); |
| 1466 ASSERT_EQ(1U, results.size()); | 1466 ASSERT_EQ(1U, results.size()); |
| 1467 EXPECT_EQ(0, expected.Compare(*results[0])); | 1467 EXPECT_EQ(0, expected.Compare(*results[0])); |
| 1468 | 1468 |
| 1469 // Add a second different invalid credit card. | 1469 // Add a second different invalid credit card. |
| 1470 FormData form2; | 1470 FormData form2; |
| 1471 test::CreateTestFormField( | 1471 test::CreateTestFormField( |
| 1472 "Name on card:", "name_on_card", "Jim Johansen", "text", &field); | 1472 "Name on card:", "name_on_card", "Jim Johansen", "text", &field); |
| 1473 form2.fields.push_back(field); | 1473 form2.fields.push_back(field); |
| 1474 test::CreateTestFormField( | 1474 test::CreateTestFormField( |
| 1475 "Card Number:", "card_number", "1000000000000000", "text", &field); | 1475 "Card Number:", "card_number", "1000000000000000", "text", &field); |
| 1476 form2.fields.push_back(field); | 1476 form2.fields.push_back(field); |
| 1477 test::CreateTestFormField("Exp Month:", "exp_month", "02", "text", &field); | 1477 test::CreateTestFormField("Exp Month:", "exp_month", "02", "text", &field); |
| 1478 form2.fields.push_back(field); | 1478 form2.fields.push_back(field); |
| 1479 test::CreateTestFormField("Exp Year:", "exp_year", "2012", "text", &field); | 1479 test::CreateTestFormField("Exp Year:", "exp_year", "2012", "text", &field); |
| 1480 form2.fields.push_back(field); | 1480 form2.fields.push_back(field); |
| 1481 | 1481 |
| 1482 FormStructure form_structure2(form2, std::string()); | 1482 FormStructure form_structure2(form2, std::string()); |
| 1483 form_structure2.DetermineHeuristicTypes(TestAutofillMetrics()); | 1483 form_structure2.DetermineHeuristicTypes(TestAutofillMetrics()); |
| 1484 EXPECT_FALSE(personal_data_->ImportFormData(form_structure2, | 1484 EXPECT_FALSE(personal_data_->ImportFormData(form_structure2, |
| 1485 &imported_credit_card)); | 1485 &imported_credit_card)); |
| 1486 ASSERT_FALSE(imported_credit_card); | 1486 ASSERT_FALSE(imported_credit_card); |
| 1487 | 1487 |
| 1488 // Note: no refresh here. | 1488 // Note: no refresh here. |
| 1489 | 1489 |
| 1490 const std::vector<CreditCard*>& results2 = personal_data_->credit_cards(); | 1490 const std::vector<CreditCard*>& results2 = personal_data_->GetCreditCards(); |
| 1491 ASSERT_EQ(1U, results2.size()); | 1491 ASSERT_EQ(1U, results2.size()); |
| 1492 EXPECT_EQ(0, expected.Compare(*results2[0])); | 1492 EXPECT_EQ(0, expected.Compare(*results2[0])); |
| 1493 } | 1493 } |
| 1494 | 1494 |
| 1495 TEST_F(PersonalDataManagerTest, AggregateSameCreditCardWithConflict) { | 1495 TEST_F(PersonalDataManagerTest, AggregateSameCreditCardWithConflict) { |
| 1496 FormData form1; | 1496 FormData form1; |
| 1497 | 1497 |
| 1498 // Start with a single valid credit card form. | 1498 // Start with a single valid credit card form. |
| 1499 FormFieldData field; | 1499 FormFieldData field; |
| 1500 test::CreateTestFormField( | 1500 test::CreateTestFormField( |
| (...skipping 17 matching lines...) Expand all Loading... |
| 1518 delete imported_credit_card; | 1518 delete imported_credit_card; |
| 1519 | 1519 |
| 1520 // Verify that the web database has been updated and the notification sent. | 1520 // Verify that the web database has been updated and the notification sent. |
| 1521 EXPECT_CALL(personal_data_observer_, | 1521 EXPECT_CALL(personal_data_observer_, |
| 1522 OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop()); | 1522 OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop()); |
| 1523 MessageLoop::current()->Run(); | 1523 MessageLoop::current()->Run(); |
| 1524 | 1524 |
| 1525 CreditCard expected; | 1525 CreditCard expected; |
| 1526 test::SetCreditCardInfo(&expected, | 1526 test::SetCreditCardInfo(&expected, |
| 1527 "Biggie Smalls", "4111111111111111", "01", "2011"); | 1527 "Biggie Smalls", "4111111111111111", "01", "2011"); |
| 1528 const std::vector<CreditCard*>& results = personal_data_->credit_cards(); | 1528 const std::vector<CreditCard*>& results = personal_data_->GetCreditCards(); |
| 1529 ASSERT_EQ(1U, results.size()); | 1529 ASSERT_EQ(1U, results.size()); |
| 1530 EXPECT_EQ(0, expected.Compare(*results[0])); | 1530 EXPECT_EQ(0, expected.Compare(*results[0])); |
| 1531 | 1531 |
| 1532 // Add a second different valid credit card where the year is different but | 1532 // Add a second different valid credit card where the year is different but |
| 1533 // the credit card number matches. | 1533 // the credit card number matches. |
| 1534 FormData form2; | 1534 FormData form2; |
| 1535 test::CreateTestFormField( | 1535 test::CreateTestFormField( |
| 1536 "Name on card:", "name_on_card", "Biggie Smalls", "text", &field); | 1536 "Name on card:", "name_on_card", "Biggie Smalls", "text", &field); |
| 1537 form2.fields.push_back(field); | 1537 form2.fields.push_back(field); |
| 1538 test::CreateTestFormField( | 1538 test::CreateTestFormField( |
| (...skipping 13 matching lines...) Expand all Loading... |
| 1552 // Verify that the web database has been updated and the notification sent. | 1552 // Verify that the web database has been updated and the notification sent. |
| 1553 EXPECT_CALL(personal_data_observer_, | 1553 EXPECT_CALL(personal_data_observer_, |
| 1554 OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop()); | 1554 OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop()); |
| 1555 MessageLoop::current()->Run(); | 1555 MessageLoop::current()->Run(); |
| 1556 | 1556 |
| 1557 // Expect that the newer information is saved. In this case the year is | 1557 // Expect that the newer information is saved. In this case the year is |
| 1558 // updated to "2012". | 1558 // updated to "2012". |
| 1559 CreditCard expected2; | 1559 CreditCard expected2; |
| 1560 test::SetCreditCardInfo(&expected2, | 1560 test::SetCreditCardInfo(&expected2, |
| 1561 "Biggie Smalls", "4111111111111111", "01", "2012"); | 1561 "Biggie Smalls", "4111111111111111", "01", "2012"); |
| 1562 const std::vector<CreditCard*>& results2 = personal_data_->credit_cards(); | 1562 const std::vector<CreditCard*>& results2 = personal_data_->GetCreditCards(); |
| 1563 ASSERT_EQ(1U, results2.size()); | 1563 ASSERT_EQ(1U, results2.size()); |
| 1564 EXPECT_EQ(0, expected2.Compare(*results2[0])); | 1564 EXPECT_EQ(0, expected2.Compare(*results2[0])); |
| 1565 } | 1565 } |
| 1566 | 1566 |
| 1567 TEST_F(PersonalDataManagerTest, AggregateEmptyCreditCardWithConflict) { | 1567 TEST_F(PersonalDataManagerTest, AggregateEmptyCreditCardWithConflict) { |
| 1568 FormData form1; | 1568 FormData form1; |
| 1569 | 1569 |
| 1570 // Start with a single valid credit card form. | 1570 // Start with a single valid credit card form. |
| 1571 FormFieldData field; | 1571 FormFieldData field; |
| 1572 test::CreateTestFormField( | 1572 test::CreateTestFormField( |
| (...skipping 17 matching lines...) Expand all Loading... |
| 1590 delete imported_credit_card; | 1590 delete imported_credit_card; |
| 1591 | 1591 |
| 1592 // Verify that the web database has been updated and the notification sent. | 1592 // Verify that the web database has been updated and the notification sent. |
| 1593 EXPECT_CALL(personal_data_observer_, | 1593 EXPECT_CALL(personal_data_observer_, |
| 1594 OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop()); | 1594 OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop()); |
| 1595 MessageLoop::current()->Run(); | 1595 MessageLoop::current()->Run(); |
| 1596 | 1596 |
| 1597 CreditCard expected; | 1597 CreditCard expected; |
| 1598 test::SetCreditCardInfo(&expected, | 1598 test::SetCreditCardInfo(&expected, |
| 1599 "Biggie Smalls", "4111111111111111", "01", "2011"); | 1599 "Biggie Smalls", "4111111111111111", "01", "2011"); |
| 1600 const std::vector<CreditCard*>& results = personal_data_->credit_cards(); | 1600 const std::vector<CreditCard*>& results = personal_data_->GetCreditCards(); |
| 1601 ASSERT_EQ(1U, results.size()); | 1601 ASSERT_EQ(1U, results.size()); |
| 1602 EXPECT_EQ(0, expected.Compare(*results[0])); | 1602 EXPECT_EQ(0, expected.Compare(*results[0])); |
| 1603 | 1603 |
| 1604 // Add a second credit card with no number. | 1604 // Add a second credit card with no number. |
| 1605 FormData form2; | 1605 FormData form2; |
| 1606 test::CreateTestFormField( | 1606 test::CreateTestFormField( |
| 1607 "Name on card:", "name_on_card", "Biggie Smalls", "text", &field); | 1607 "Name on card:", "name_on_card", "Biggie Smalls", "text", &field); |
| 1608 form2.fields.push_back(field); | 1608 form2.fields.push_back(field); |
| 1609 test::CreateTestFormField("Exp Month:", "exp_month", "01", "text", &field); | 1609 test::CreateTestFormField("Exp Month:", "exp_month", "01", "text", &field); |
| 1610 form2.fields.push_back(field); | 1610 form2.fields.push_back(field); |
| 1611 test::CreateTestFormField("Exp Year:", "exp_year", "2012", "text", &field); | 1611 test::CreateTestFormField("Exp Year:", "exp_year", "2012", "text", &field); |
| 1612 form2.fields.push_back(field); | 1612 form2.fields.push_back(field); |
| 1613 | 1613 |
| 1614 FormStructure form_structure2(form2, std::string()); | 1614 FormStructure form_structure2(form2, std::string()); |
| 1615 form_structure2.DetermineHeuristicTypes(TestAutofillMetrics()); | 1615 form_structure2.DetermineHeuristicTypes(TestAutofillMetrics()); |
| 1616 EXPECT_FALSE(personal_data_->ImportFormData(form_structure2, | 1616 EXPECT_FALSE(personal_data_->ImportFormData(form_structure2, |
| 1617 &imported_credit_card)); | 1617 &imported_credit_card)); |
| 1618 EXPECT_FALSE(imported_credit_card); | 1618 EXPECT_FALSE(imported_credit_card); |
| 1619 | 1619 |
| 1620 // Note: no refresh here. | 1620 // Note: no refresh here. |
| 1621 | 1621 |
| 1622 // No change is expected. | 1622 // No change is expected. |
| 1623 CreditCard expected2; | 1623 CreditCard expected2; |
| 1624 test::SetCreditCardInfo(&expected2, | 1624 test::SetCreditCardInfo(&expected2, |
| 1625 "Biggie Smalls", "4111111111111111", "01", "2011"); | 1625 "Biggie Smalls", "4111111111111111", "01", "2011"); |
| 1626 const std::vector<CreditCard*>& results2 = personal_data_->credit_cards(); | 1626 const std::vector<CreditCard*>& results2 = personal_data_->GetCreditCards(); |
| 1627 ASSERT_EQ(1U, results2.size()); | 1627 ASSERT_EQ(1U, results2.size()); |
| 1628 EXPECT_EQ(0, expected2.Compare(*results2[0])); | 1628 EXPECT_EQ(0, expected2.Compare(*results2[0])); |
| 1629 } | 1629 } |
| 1630 | 1630 |
| 1631 TEST_F(PersonalDataManagerTest, AggregateCreditCardWithMissingInfoInNew) { | 1631 TEST_F(PersonalDataManagerTest, AggregateCreditCardWithMissingInfoInNew) { |
| 1632 FormData form1; | 1632 FormData form1; |
| 1633 | 1633 |
| 1634 // Start with a single valid credit card form. | 1634 // Start with a single valid credit card form. |
| 1635 FormFieldData field; | 1635 FormFieldData field; |
| 1636 test::CreateTestFormField( | 1636 test::CreateTestFormField( |
| (...skipping 17 matching lines...) Expand all Loading... |
| 1654 delete imported_credit_card; | 1654 delete imported_credit_card; |
| 1655 | 1655 |
| 1656 // Verify that the web database has been updated and the notification sent. | 1656 // Verify that the web database has been updated and the notification sent. |
| 1657 EXPECT_CALL(personal_data_observer_, | 1657 EXPECT_CALL(personal_data_observer_, |
| 1658 OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop()); | 1658 OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop()); |
| 1659 MessageLoop::current()->Run(); | 1659 MessageLoop::current()->Run(); |
| 1660 | 1660 |
| 1661 CreditCard expected; | 1661 CreditCard expected; |
| 1662 test::SetCreditCardInfo(&expected, | 1662 test::SetCreditCardInfo(&expected, |
| 1663 "Biggie Smalls", "4111111111111111", "01", "2011"); | 1663 "Biggie Smalls", "4111111111111111", "01", "2011"); |
| 1664 const std::vector<CreditCard*>& results = personal_data_->credit_cards(); | 1664 const std::vector<CreditCard*>& results = personal_data_->GetCreditCards(); |
| 1665 ASSERT_EQ(1U, results.size()); | 1665 ASSERT_EQ(1U, results.size()); |
| 1666 EXPECT_EQ(0, expected.Compare(*results[0])); | 1666 EXPECT_EQ(0, expected.Compare(*results[0])); |
| 1667 | 1667 |
| 1668 // Add a second different valid credit card where the name is missing but | 1668 // Add a second different valid credit card where the name is missing but |
| 1669 // the credit card number matches. | 1669 // the credit card number matches. |
| 1670 FormData form2; | 1670 FormData form2; |
| 1671 // Note missing name. | 1671 // Note missing name. |
| 1672 test::CreateTestFormField( | 1672 test::CreateTestFormField( |
| 1673 "Card Number:", "card_number", "4111111111111111", "text", &field); | 1673 "Card Number:", "card_number", "4111111111111111", "text", &field); |
| 1674 form2.fields.push_back(field); | 1674 form2.fields.push_back(field); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 1685 | 1685 |
| 1686 // Wait for the refresh, which in this case is a no-op. | 1686 // Wait for the refresh, which in this case is a no-op. |
| 1687 EXPECT_CALL(personal_data_observer_, | 1687 EXPECT_CALL(personal_data_observer_, |
| 1688 OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop()); | 1688 OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop()); |
| 1689 MessageLoop::current()->Run(); | 1689 MessageLoop::current()->Run(); |
| 1690 | 1690 |
| 1691 // No change is expected. | 1691 // No change is expected. |
| 1692 CreditCard expected2; | 1692 CreditCard expected2; |
| 1693 test::SetCreditCardInfo(&expected2, | 1693 test::SetCreditCardInfo(&expected2, |
| 1694 "Biggie Smalls", "4111111111111111", "01", "2011"); | 1694 "Biggie Smalls", "4111111111111111", "01", "2011"); |
| 1695 const std::vector<CreditCard*>& results2 = personal_data_->credit_cards(); | 1695 const std::vector<CreditCard*>& results2 = personal_data_->GetCreditCards(); |
| 1696 ASSERT_EQ(1U, results2.size()); | 1696 ASSERT_EQ(1U, results2.size()); |
| 1697 EXPECT_EQ(0, expected2.Compare(*results2[0])); | 1697 EXPECT_EQ(0, expected2.Compare(*results2[0])); |
| 1698 | 1698 |
| 1699 // Add a third credit card where the expiration date is missing. | 1699 // Add a third credit card where the expiration date is missing. |
| 1700 FormData form3; | 1700 FormData form3; |
| 1701 test::CreateTestFormField( | 1701 test::CreateTestFormField( |
| 1702 "Name on card:", "name_on_card", "Johnny McEnroe", "text", &field); | 1702 "Name on card:", "name_on_card", "Johnny McEnroe", "text", &field); |
| 1703 form3.fields.push_back(field); | 1703 form3.fields.push_back(field); |
| 1704 test::CreateTestFormField( | 1704 test::CreateTestFormField( |
| 1705 "Card Number:", "card_number", "5555555555554444", "text", &field); | 1705 "Card Number:", "card_number", "5555555555554444", "text", &field); |
| 1706 form3.fields.push_back(field); | 1706 form3.fields.push_back(field); |
| 1707 // Note missing expiration month and year.. | 1707 // Note missing expiration month and year.. |
| 1708 | 1708 |
| 1709 FormStructure form_structure3(form3, std::string()); | 1709 FormStructure form_structure3(form3, std::string()); |
| 1710 form_structure3.DetermineHeuristicTypes(TestAutofillMetrics()); | 1710 form_structure3.DetermineHeuristicTypes(TestAutofillMetrics()); |
| 1711 EXPECT_FALSE(personal_data_->ImportFormData(form_structure3, | 1711 EXPECT_FALSE(personal_data_->ImportFormData(form_structure3, |
| 1712 &imported_credit_card)); | 1712 &imported_credit_card)); |
| 1713 ASSERT_FALSE(imported_credit_card); | 1713 ASSERT_FALSE(imported_credit_card); |
| 1714 | 1714 |
| 1715 // Note: no refresh here. | 1715 // Note: no refresh here. |
| 1716 | 1716 |
| 1717 // No change is expected. | 1717 // No change is expected. |
| 1718 CreditCard expected3; | 1718 CreditCard expected3; |
| 1719 test::SetCreditCardInfo(&expected3, | 1719 test::SetCreditCardInfo(&expected3, |
| 1720 "Biggie Smalls", "4111111111111111", "01", "2011"); | 1720 "Biggie Smalls", "4111111111111111", "01", "2011"); |
| 1721 const std::vector<CreditCard*>& results3 = personal_data_->credit_cards(); | 1721 const std::vector<CreditCard*>& results3 = personal_data_->GetCreditCards(); |
| 1722 ASSERT_EQ(1U, results3.size()); | 1722 ASSERT_EQ(1U, results3.size()); |
| 1723 EXPECT_EQ(0, expected3.Compare(*results2[0])); | 1723 EXPECT_EQ(0, expected3.Compare(*results2[0])); |
| 1724 } | 1724 } |
| 1725 | 1725 |
| 1726 TEST_F(PersonalDataManagerTest, AggregateCreditCardWithMissingInfoInOld) { | 1726 TEST_F(PersonalDataManagerTest, AggregateCreditCardWithMissingInfoInOld) { |
| 1727 // Start with a single valid credit card stored via the preferences. | 1727 // Start with a single valid credit card stored via the preferences. |
| 1728 // Note the empty name. | 1728 // Note the empty name. |
| 1729 CreditCard saved_credit_card; | 1729 CreditCard saved_credit_card; |
| 1730 test::SetCreditCardInfo(&saved_credit_card, | 1730 test::SetCreditCardInfo(&saved_credit_card, |
| 1731 "", "4111111111111111" /* Visa */, "01", "2011"); | 1731 "", "4111111111111111" /* Visa */, "01", "2011"); |
| 1732 personal_data_->AddCreditCard(saved_credit_card); | 1732 personal_data_->AddCreditCard(saved_credit_card); |
| 1733 | 1733 |
| 1734 // Verify that the web database has been updated and the notification sent. | 1734 // Verify that the web database has been updated and the notification sent. |
| 1735 EXPECT_CALL(personal_data_observer_, | 1735 EXPECT_CALL(personal_data_observer_, |
| 1736 OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop()); | 1736 OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop()); |
| 1737 MessageLoop::current()->Run(); | 1737 MessageLoop::current()->Run(); |
| 1738 | 1738 |
| 1739 const std::vector<CreditCard*>& results1 = personal_data_->credit_cards(); | 1739 const std::vector<CreditCard*>& results1 = personal_data_->GetCreditCards(); |
| 1740 ASSERT_EQ(1U, results1.size()); | 1740 ASSERT_EQ(1U, results1.size()); |
| 1741 EXPECT_EQ(saved_credit_card, *results1[0]); | 1741 EXPECT_EQ(saved_credit_card, *results1[0]); |
| 1742 | 1742 |
| 1743 | 1743 |
| 1744 // Add a second different valid credit card where the year is different but | 1744 // Add a second different valid credit card where the year is different but |
| 1745 // the credit card number matches. | 1745 // the credit card number matches. |
| 1746 FormData form; | 1746 FormData form; |
| 1747 FormFieldData field; | 1747 FormFieldData field; |
| 1748 test::CreateTestFormField( | 1748 test::CreateTestFormField( |
| 1749 "Name on card:", "name_on_card", "Biggie Smalls", "text", &field); | 1749 "Name on card:", "name_on_card", "Biggie Smalls", "text", &field); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 1766 // Verify that the web database has been updated and the notification sent. | 1766 // Verify that the web database has been updated and the notification sent. |
| 1767 EXPECT_CALL(personal_data_observer_, | 1767 EXPECT_CALL(personal_data_observer_, |
| 1768 OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop()); | 1768 OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop()); |
| 1769 MessageLoop::current()->Run(); | 1769 MessageLoop::current()->Run(); |
| 1770 | 1770 |
| 1771 // Expect that the newer information is saved. In this case the year is | 1771 // Expect that the newer information is saved. In this case the year is |
| 1772 // added to the existing credit card. | 1772 // added to the existing credit card. |
| 1773 CreditCard expected2; | 1773 CreditCard expected2; |
| 1774 test::SetCreditCardInfo(&expected2, | 1774 test::SetCreditCardInfo(&expected2, |
| 1775 "Biggie Smalls", "4111111111111111", "01", "2012"); | 1775 "Biggie Smalls", "4111111111111111", "01", "2012"); |
| 1776 const std::vector<CreditCard*>& results2 = personal_data_->credit_cards(); | 1776 const std::vector<CreditCard*>& results2 = personal_data_->GetCreditCards(); |
| 1777 ASSERT_EQ(1U, results2.size()); | 1777 ASSERT_EQ(1U, results2.size()); |
| 1778 EXPECT_EQ(0, expected2.Compare(*results2[0])); | 1778 EXPECT_EQ(0, expected2.Compare(*results2[0])); |
| 1779 } | 1779 } |
| 1780 | 1780 |
| 1781 // We allow the user to store a credit card number with separators via the UI. | 1781 // We allow the user to store a credit card number with separators via the UI. |
| 1782 // We should not try to re-aggregate the same card with the separators stripped. | 1782 // We should not try to re-aggregate the same card with the separators stripped. |
| 1783 TEST_F(PersonalDataManagerTest, AggregateSameCreditCardWithSeparators) { | 1783 TEST_F(PersonalDataManagerTest, AggregateSameCreditCardWithSeparators) { |
| 1784 // Start with a single valid credit card stored via the preferences. | 1784 // Start with a single valid credit card stored via the preferences. |
| 1785 // Note the separators in the credit card number. | 1785 // Note the separators in the credit card number. |
| 1786 CreditCard saved_credit_card; | 1786 CreditCard saved_credit_card; |
| 1787 test::SetCreditCardInfo(&saved_credit_card, | 1787 test::SetCreditCardInfo(&saved_credit_card, |
| 1788 "Biggie Smalls", "4111 1111 1111 1111" /* Visa */, "01", "2011"); | 1788 "Biggie Smalls", "4111 1111 1111 1111" /* Visa */, "01", "2011"); |
| 1789 personal_data_->AddCreditCard(saved_credit_card); | 1789 personal_data_->AddCreditCard(saved_credit_card); |
| 1790 | 1790 |
| 1791 // Verify that the web database has been updated and the notification sent. | 1791 // Verify that the web database has been updated and the notification sent. |
| 1792 EXPECT_CALL(personal_data_observer_, | 1792 EXPECT_CALL(personal_data_observer_, |
| 1793 OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop()); | 1793 OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop()); |
| 1794 MessageLoop::current()->Run(); | 1794 MessageLoop::current()->Run(); |
| 1795 | 1795 |
| 1796 const std::vector<CreditCard*>& results1 = personal_data_->credit_cards(); | 1796 const std::vector<CreditCard*>& results1 = personal_data_->GetCreditCards(); |
| 1797 ASSERT_EQ(1U, results1.size()); | 1797 ASSERT_EQ(1U, results1.size()); |
| 1798 EXPECT_EQ(0, saved_credit_card.Compare(*results1[0])); | 1798 EXPECT_EQ(0, saved_credit_card.Compare(*results1[0])); |
| 1799 | 1799 |
| 1800 // Import the same card info, but with different separators in the number. | 1800 // Import the same card info, but with different separators in the number. |
| 1801 FormData form; | 1801 FormData form; |
| 1802 FormFieldData field; | 1802 FormFieldData field; |
| 1803 test::CreateTestFormField( | 1803 test::CreateTestFormField( |
| 1804 "Name on card:", "name_on_card", "Biggie Smalls", "text", &field); | 1804 "Name on card:", "name_on_card", "Biggie Smalls", "text", &field); |
| 1805 form.fields.push_back(field); | 1805 form.fields.push_back(field); |
| 1806 test::CreateTestFormField( | 1806 test::CreateTestFormField( |
| (...skipping 10 matching lines...) Expand all Loading... |
| 1817 EXPECT_TRUE(personal_data_->ImportFormData(form_structure, | 1817 EXPECT_TRUE(personal_data_->ImportFormData(form_structure, |
| 1818 &imported_credit_card)); | 1818 &imported_credit_card)); |
| 1819 EXPECT_FALSE(imported_credit_card); | 1819 EXPECT_FALSE(imported_credit_card); |
| 1820 | 1820 |
| 1821 // Wait for the refresh, which in this case is a no-op. | 1821 // Wait for the refresh, which in this case is a no-op. |
| 1822 EXPECT_CALL(personal_data_observer_, | 1822 EXPECT_CALL(personal_data_observer_, |
| 1823 OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop()); | 1823 OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop()); |
| 1824 MessageLoop::current()->Run(); | 1824 MessageLoop::current()->Run(); |
| 1825 | 1825 |
| 1826 // Expect that no new card is saved. | 1826 // Expect that no new card is saved. |
| 1827 const std::vector<CreditCard*>& results2 = personal_data_->credit_cards(); | 1827 const std::vector<CreditCard*>& results2 = personal_data_->GetCreditCards(); |
| 1828 ASSERT_EQ(1U, results2.size()); | 1828 ASSERT_EQ(1U, results2.size()); |
| 1829 EXPECT_EQ(0, saved_credit_card.Compare(*results2[0])); | 1829 EXPECT_EQ(0, saved_credit_card.Compare(*results2[0])); |
| 1830 } | 1830 } |
| 1831 | 1831 |
| 1832 TEST_F(PersonalDataManagerTest, GetNonEmptyTypes) { | 1832 TEST_F(PersonalDataManagerTest, GetNonEmptyTypes) { |
| 1833 // Check that there are no available types with no profiles stored. | 1833 // Check that there are no available types with no profiles stored. |
| 1834 FieldTypeSet non_empty_types; | 1834 FieldTypeSet non_empty_types; |
| 1835 personal_data_->GetNonEmptyTypes(&non_empty_types); | 1835 personal_data_->GetNonEmptyTypes(&non_empty_types); |
| 1836 EXPECT_EQ(0U, non_empty_types.size()); | 1836 EXPECT_EQ(0U, non_empty_types.size()); |
| 1837 | 1837 |
| (...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2038 expected.GetRawMultiInfo(PHONE_HOME_WHOLE_NUMBER, &values); | 2038 expected.GetRawMultiInfo(PHONE_HOME_WHOLE_NUMBER, &values); |
| 2039 values.push_back(ASCIIToUTF16("(214) 555-1234")); | 2039 values.push_back(ASCIIToUTF16("(214) 555-1234")); |
| 2040 expected.SetRawMultiInfo(PHONE_HOME_WHOLE_NUMBER, values); | 2040 expected.SetRawMultiInfo(PHONE_HOME_WHOLE_NUMBER, values); |
| 2041 | 2041 |
| 2042 ASSERT_EQ(1U, results2.size()); | 2042 ASSERT_EQ(1U, results2.size()); |
| 2043 EXPECT_EQ(0, expected.Compare(*results2[0])); | 2043 EXPECT_EQ(0, expected.Compare(*results2[0])); |
| 2044 } | 2044 } |
| 2045 | 2045 |
| 2046 TEST_F(PersonalDataManagerTest, IncognitoReadOnly) { | 2046 TEST_F(PersonalDataManagerTest, IncognitoReadOnly) { |
| 2047 ASSERT_TRUE(personal_data_->GetProfiles().empty()); | 2047 ASSERT_TRUE(personal_data_->GetProfiles().empty()); |
| 2048 ASSERT_TRUE(personal_data_->credit_cards().empty()); | 2048 ASSERT_TRUE(personal_data_->GetCreditCards().empty()); |
| 2049 | 2049 |
| 2050 AutofillProfile steve_jobs; | 2050 AutofillProfile steve_jobs; |
| 2051 test::SetProfileInfo(&steve_jobs, "Steven", "Paul", "Jobs", "sjobs@apple.com", | 2051 test::SetProfileInfo(&steve_jobs, "Steven", "Paul", "Jobs", "sjobs@apple.com", |
| 2052 "Apple Computer, Inc.", "1 Infinite Loop", "", "Cupertino", "CA", "95014", | 2052 "Apple Computer, Inc.", "1 Infinite Loop", "", "Cupertino", "CA", "95014", |
| 2053 "US", "(800) 275-2273"); | 2053 "US", "(800) 275-2273"); |
| 2054 personal_data_->AddProfile(steve_jobs); | 2054 personal_data_->AddProfile(steve_jobs); |
| 2055 | 2055 |
| 2056 CreditCard bill_gates; | 2056 CreditCard bill_gates; |
| 2057 test::SetCreditCardInfo( | 2057 test::SetCreditCardInfo( |
| 2058 &bill_gates, "William H. Gates", "5555555555554444", "1", "2020"); | 2058 &bill_gates, "William H. Gates", "5555555555554444", "1", "2020"); |
| 2059 personal_data_->AddCreditCard(bill_gates); | 2059 personal_data_->AddCreditCard(bill_gates); |
| 2060 | 2060 |
| 2061 ResetPersonalDataManager(); | 2061 ResetPersonalDataManager(); |
| 2062 ASSERT_EQ(1U, personal_data_->GetProfiles().size()); | 2062 ASSERT_EQ(1U, personal_data_->GetProfiles().size()); |
| 2063 ASSERT_EQ(1U, personal_data_->credit_cards().size()); | 2063 ASSERT_EQ(1U, personal_data_->GetCreditCards().size()); |
| 2064 | 2064 |
| 2065 // After this point no adds, saves, or updates should take effect. | 2065 // After this point no adds, saves, or updates should take effect. |
| 2066 MakeProfileIncognito(); | 2066 MakeProfileIncognito(); |
| 2067 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()).Times(0); | 2067 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()).Times(0); |
| 2068 | 2068 |
| 2069 // Add profiles or credit card shouldn't work. | 2069 // Add profiles or credit card shouldn't work. |
| 2070 personal_data_->AddProfile(test::GetFullProfile()); | 2070 personal_data_->AddProfile(test::GetFullProfile()); |
| 2071 | 2071 |
| 2072 CreditCard larry_page; | 2072 CreditCard larry_page; |
| 2073 test::SetCreditCardInfo( | 2073 test::SetCreditCardInfo( |
| 2074 &larry_page, "Lawrence Page", "4111111111111111", "10", "2025"); | 2074 &larry_page, "Lawrence Page", "4111111111111111", "10", "2025"); |
| 2075 personal_data_->AddCreditCard(larry_page); | 2075 personal_data_->AddCreditCard(larry_page); |
| 2076 | 2076 |
| 2077 ResetPersonalDataManager(); | 2077 ResetPersonalDataManager(); |
| 2078 EXPECT_EQ(1U, personal_data_->GetProfiles().size()); | 2078 EXPECT_EQ(1U, personal_data_->GetProfiles().size()); |
| 2079 EXPECT_EQ(1U, personal_data_->credit_cards().size()); | 2079 EXPECT_EQ(1U, personal_data_->GetCreditCards().size()); |
| 2080 | 2080 |
| 2081 // Saving or creating profiles from imported profiles shouldn't work. | 2081 // Saving or creating profiles from imported profiles shouldn't work. |
| 2082 steve_jobs.SetRawInfo(NAME_FIRST, ASCIIToUTF16("Steve")); | 2082 steve_jobs.SetRawInfo(NAME_FIRST, ASCIIToUTF16("Steve")); |
| 2083 personal_data_->SaveImportedProfile(steve_jobs); | 2083 personal_data_->SaveImportedProfile(steve_jobs); |
| 2084 | 2084 |
| 2085 bill_gates.SetRawInfo(CREDIT_CARD_NAME, ASCIIToUTF16("Bill Gates")); | 2085 bill_gates.SetRawInfo(CREDIT_CARD_NAME, ASCIIToUTF16("Bill Gates")); |
| 2086 personal_data_->SaveImportedCreditCard(bill_gates); | 2086 personal_data_->SaveImportedCreditCard(bill_gates); |
| 2087 | 2087 |
| 2088 ResetPersonalDataManager(); | 2088 ResetPersonalDataManager(); |
| 2089 EXPECT_EQ(ASCIIToUTF16("Steven"), | 2089 EXPECT_EQ(ASCIIToUTF16("Steven"), |
| 2090 personal_data_->GetProfiles()[0]->GetRawInfo(NAME_FIRST)); | 2090 personal_data_->GetProfiles()[0]->GetRawInfo(NAME_FIRST)); |
| 2091 EXPECT_EQ(ASCIIToUTF16("William H. Gates"), | 2091 EXPECT_EQ(ASCIIToUTF16("William H. Gates"), |
| 2092 personal_data_->credit_cards()[0]->GetRawInfo(CREDIT_CARD_NAME)); | 2092 personal_data_->GetCreditCards()[0]->GetRawInfo(CREDIT_CARD_NAME)); |
| 2093 | 2093 |
| 2094 // Updating existing profiles shouldn't work. | 2094 // Updating existing profiles shouldn't work. |
| 2095 steve_jobs.SetRawInfo(NAME_FIRST, ASCIIToUTF16("Steve")); | 2095 steve_jobs.SetRawInfo(NAME_FIRST, ASCIIToUTF16("Steve")); |
| 2096 personal_data_->UpdateProfile(steve_jobs); | 2096 personal_data_->UpdateProfile(steve_jobs); |
| 2097 | 2097 |
| 2098 bill_gates.SetRawInfo(CREDIT_CARD_NAME, ASCIIToUTF16("Bill Gates")); | 2098 bill_gates.SetRawInfo(CREDIT_CARD_NAME, ASCIIToUTF16("Bill Gates")); |
| 2099 personal_data_->UpdateCreditCard(bill_gates); | 2099 personal_data_->UpdateCreditCard(bill_gates); |
| 2100 | 2100 |
| 2101 ResetPersonalDataManager(); | 2101 ResetPersonalDataManager(); |
| 2102 EXPECT_EQ(ASCIIToUTF16("Steven"), | 2102 EXPECT_EQ(ASCIIToUTF16("Steven"), |
| 2103 personal_data_->GetProfiles()[0]->GetRawInfo(NAME_FIRST)); | 2103 personal_data_->GetProfiles()[0]->GetRawInfo(NAME_FIRST)); |
| 2104 EXPECT_EQ(ASCIIToUTF16("William H. Gates"), | 2104 EXPECT_EQ(ASCIIToUTF16("William H. Gates"), |
| 2105 personal_data_->credit_cards()[0]->GetRawInfo(CREDIT_CARD_NAME)); | 2105 personal_data_->GetCreditCards()[0]->GetRawInfo(CREDIT_CARD_NAME)); |
| 2106 | 2106 |
| 2107 // Removing shouldn't work. | 2107 // Removing shouldn't work. |
| 2108 personal_data_->RemoveByGUID(steve_jobs.guid()); | 2108 personal_data_->RemoveByGUID(steve_jobs.guid()); |
| 2109 personal_data_->RemoveByGUID(bill_gates.guid()); | 2109 personal_data_->RemoveByGUID(bill_gates.guid()); |
| 2110 | 2110 |
| 2111 ResetPersonalDataManager(); | 2111 ResetPersonalDataManager(); |
| 2112 EXPECT_EQ(1U, personal_data_->GetProfiles().size()); | 2112 EXPECT_EQ(1U, personal_data_->GetProfiles().size()); |
| 2113 EXPECT_EQ(1U, personal_data_->credit_cards().size()); | 2113 EXPECT_EQ(1U, personal_data_->GetCreditCards().size()); |
| 2114 } | 2114 } |
| 2115 | 2115 |
| 2116 } // namespace autofill | 2116 } // namespace autofill |
| OLD | NEW |