OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/message_loop.h" | 8 #include "base/message_loop.h" |
9 #include "base/ref_counted.h" | 9 #include "base/ref_counted.h" |
10 #include "base/scoped_ptr.h" | 10 #include "base/scoped_ptr.h" |
(...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
273 update_cc.push_back(creditcard0); | 273 update_cc.push_back(creditcard0); |
274 update_cc.push_back(creditcard1); | 274 update_cc.push_back(creditcard1); |
275 personal_data_->SetCreditCards(&update_cc); | 275 personal_data_->SetCreditCards(&update_cc); |
276 | 276 |
277 | 277 |
278 const std::vector<CreditCard*>& results2 = personal_data_->credit_cards(); | 278 const std::vector<CreditCard*>& results2 = personal_data_->credit_cards(); |
279 ASSERT_EQ(2U, results2.size()); | 279 ASSERT_EQ(2U, results2.size()); |
280 EXPECT_EQ(creditcard0, *results2.at(0)); | 280 EXPECT_EQ(creditcard0, *results2.at(0)); |
281 EXPECT_EQ(creditcard1, *results2.at(1)); | 281 EXPECT_EQ(creditcard1, *results2.at(1)); |
282 | 282 |
| 283 // The message loop will exit when the mock observer is notified. |
| 284 MessageLoop::current()->Run(); |
| 285 |
283 // Determine uniqueness by inserting all of the GUIDs into a set and verifying | 286 // Determine uniqueness by inserting all of the GUIDs into a set and verifying |
284 // the size of the set matches the number of GUIDs. | 287 // the size of the set matches the number of GUIDs. |
285 std::set<std::string> guids; | 288 std::set<std::string> guids; |
286 guids.insert(profile0.guid()); | 289 guids.insert(profile0.guid()); |
287 guids.insert(profile1.guid()); | 290 guids.insert(profile1.guid()); |
288 guids.insert(creditcard0.guid()); | 291 guids.insert(creditcard0.guid()); |
289 guids.insert(creditcard1.guid()); | 292 guids.insert(creditcard1.guid()); |
290 EXPECT_EQ(4U, guids.size()); | 293 EXPECT_EQ(4U, guids.size()); |
291 } | 294 } |
292 | 295 |
(...skipping 23 matching lines...) Expand all Loading... |
316 | 319 |
317 // The message loop will exit when the PersonalDataLoadedObserver is notified. | 320 // The message loop will exit when the PersonalDataLoadedObserver is notified. |
318 MessageLoop::current()->Run(); | 321 MessageLoop::current()->Run(); |
319 | 322 |
320 // Verify that we've loaded the profiles from the web database. | 323 // Verify that we've loaded the profiles from the web database. |
321 const std::vector<AutoFillProfile*>& results2 = personal_data_->profiles(); | 324 const std::vector<AutoFillProfile*>& results2 = personal_data_->profiles(); |
322 ASSERT_EQ(1U, results2.size()); | 325 ASSERT_EQ(1U, results2.size()); |
323 | 326 |
324 // Add a new profile. | 327 // Add a new profile. |
325 AutoFillProfile profile1; | 328 AutoFillProfile profile1; |
| 329 // Need to be different from results2[0] by contents or it will be dropped. |
326 autofill_test::SetProfileInfo(&profile1, | 330 autofill_test::SetProfileInfo(&profile1, |
327 "", "y", "", "", "", "", "", "", "", "", "", "", "", ""); | 331 "", "y", "1", "", "", "", "", "", "", "", "", "", "", ""); |
328 update.clear(); | 332 update.clear(); |
329 update.push_back(*results2[0]); | 333 update.push_back(*results2[0]); |
330 update.push_back(profile1); | 334 update.push_back(profile1); |
331 personal_data_->SetProfiles(&update); | 335 personal_data_->SetProfiles(&update); |
332 | 336 |
| 337 // The message loop will exit when the PersonalDataLoadedObserver is notified. |
| 338 MessageLoop::current()->Run(); |
| 339 |
333 // Make sure the two profiles have different ids (and neither equal to 0, | 340 // Make sure the two profiles have different ids (and neither equal to 0, |
334 // which is an invalid id). | 341 // which is an invalid id). |
335 const std::vector<AutoFillProfile*>& results3 = personal_data_->profiles(); | 342 const std::vector<AutoFillProfile*>& results3 = personal_data_->profiles(); |
336 ASSERT_EQ(2U, results3.size()); | 343 ASSERT_EQ(2U, results3.size()); |
337 EXPECT_NE(results3[0]->guid(), results3[1]->guid()); | 344 EXPECT_NE(results3[0]->guid(), results3[1]->guid()); |
338 EXPECT_TRUE(guid::IsValidGUID(results3[0]->guid())); | 345 EXPECT_TRUE(guid::IsValidGUID(results3[0]->guid())); |
339 EXPECT_TRUE(guid::IsValidGUID(results3[1]->guid())); | 346 EXPECT_TRUE(guid::IsValidGUID(results3[1]->guid())); |
340 } | 347 } |
341 | 348 |
342 TEST_F(PersonalDataManagerTest, SetEmptyProfile) { | 349 TEST_F(PersonalDataManagerTest, SetEmptyProfile) { |
(...skipping 1038 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1381 | 1388 |
1382 // Expect that the newer information is saved. In this case the year is | 1389 // Expect that the newer information is saved. In this case the year is |
1383 // added to the existing credit card. | 1390 // added to the existing credit card. |
1384 CreditCard expected2; | 1391 CreditCard expected2; |
1385 autofill_test::SetCreditCardInfo(&expected2, | 1392 autofill_test::SetCreditCardInfo(&expected2, |
1386 "L1", "Biggie Smalls", "4111111111111111", "01", "2011"); | 1393 "L1", "Biggie Smalls", "4111111111111111", "01", "2011"); |
1387 const std::vector<CreditCard*>& results2 = personal_data_->credit_cards(); | 1394 const std::vector<CreditCard*>& results2 = personal_data_->credit_cards(); |
1388 ASSERT_EQ(1U, results2.size()); | 1395 ASSERT_EQ(1U, results2.size()); |
1389 EXPECT_EQ(0, expected2.Compare(*results2[0])); | 1396 EXPECT_EQ(0, expected2.Compare(*results2[0])); |
1390 } | 1397 } |
| 1398 |
| 1399 TEST_F(PersonalDataManagerTest, CheckPresentData) { |
| 1400 AutoFillProfile profile0; |
| 1401 autofill_test::SetProfileInfo(&profile0, |
| 1402 "Billing", "Marion", "Mitchell", "Morrison", |
| 1403 "johnwayne@me.xyz", "", "123 Zoo St.", "unit 5", "Hollywood", "CA", |
| 1404 "91601", "US", "12345678910", NULL); |
| 1405 |
| 1406 AutoFillProfile profile1; |
| 1407 autofill_test::SetProfileInfo(&profile1, |
| 1408 "Home", "Josephine", "Alicia", "Saenz", |
| 1409 "joewayne@me.xyz", "Fox", "903 Apple Ct.", NULL, "Orlando", "FL", "32801", |
| 1410 "US", "19482937549", NULL); |
| 1411 |
| 1412 AutoFillProfile profile2; |
| 1413 autofill_test::SetProfileInfo(&profile2, |
| 1414 "Home", "Jouhn", NULL, "Doe", |
| 1415 "johm@me.xyz", NULL, NULL, NULL, NULL, NULL, NULL, |
| 1416 "US", NULL, "13502849239"); |
| 1417 |
| 1418 CreditCard creditcard0; |
| 1419 autofill_test::SetCreditCardInfo(&creditcard0, "Corporate", |
| 1420 "John Dillinger", "423456789012" /* Visa */, "01", "2010"); |
| 1421 |
| 1422 CreditCard creditcard1; |
| 1423 autofill_test::SetCreditCardInfo(&creditcard1, "Personal", |
| 1424 "Bonnie Parker", "518765432109" /* Mastercard */, "12", "2012"); |
| 1425 |
| 1426 // This will verify that the web database has been loaded and the notification |
| 1427 // sent out. |
| 1428 EXPECT_CALL( |
| 1429 personal_data_observer_, |
| 1430 OnPersonalDataLoaded()).WillRepeatedly(QuitUIMessageLoop()); |
| 1431 |
| 1432 std::vector<AutoFillProfile> update; |
| 1433 update.push_back(profile0); |
| 1434 update.push_back(profile1); |
| 1435 update.push_back(profile2); |
| 1436 personal_data_->SetProfiles(&update); |
| 1437 |
| 1438 std::vector<CreditCard> update_cc; |
| 1439 update_cc.push_back(creditcard0); |
| 1440 update_cc.push_back(creditcard1); |
| 1441 personal_data_->SetCreditCards(&update_cc); |
| 1442 |
| 1443 // The message loop will exit when the mock observer is notified. |
| 1444 MessageLoop::current()->Run(); |
| 1445 |
| 1446 EXPECT_EQ("", personal_data_->PresentData(std::string(), std::string())); |
| 1447 EXPECT_EQ("1f7e00037ef0", |
| 1448 personal_data_->PresentData(profile0.guid(), std::string())); |
| 1449 EXPECT_EQ("1f7e00027cf00008", |
| 1450 personal_data_->PresentData(profile1.guid(), std::string())); |
| 1451 EXPECT_EQ("15400f800810", |
| 1452 personal_data_->PresentData(profile2.guid(), std::string())); |
| 1453 EXPECT_EQ("0000000000001fc0", |
| 1454 personal_data_->PresentData(std::string(), creditcard0.guid())); |
| 1455 EXPECT_EQ("0000000000001fc0", |
| 1456 personal_data_->PresentData(std::string(), creditcard1.guid())); |
| 1457 EXPECT_EQ("1f7e00037ef01fc0", |
| 1458 personal_data_->PresentData(profile0.guid(), creditcard0.guid())); |
| 1459 EXPECT_EQ("1f7e00027cf01fc8", |
| 1460 personal_data_->PresentData(profile1.guid(), creditcard0.guid())); |
| 1461 EXPECT_EQ("15400f8008101fc0", |
| 1462 personal_data_->PresentData(profile2.guid(), creditcard0.guid())); |
| 1463 EXPECT_EQ("1f7e00037ef01fc0", |
| 1464 personal_data_->PresentData(profile0.guid(), creditcard1.guid())); |
| 1465 } |
OLD | NEW |