| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 #include <vector> | 6 #include <vector> |
| 7 | 7 |
| 8 #include "base/basictypes.h" | 8 #include "base/basictypes.h" |
| 9 #include "base/file_util.h" | 9 #include "base/file_util.h" |
| 10 #include "base/message_loop.h" | 10 #include "base/message_loop.h" |
| (...skipping 304 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 315 // Check that it was removed. | 315 // Check that it was removed. |
| 316 AutofillWebDataServiceConsumer<std::vector<AutofillProfile*> > consumer2; | 316 AutofillWebDataServiceConsumer<std::vector<AutofillProfile*> > consumer2; |
| 317 WebDataService::Handle handle2 = wds_->GetAutofillProfiles(&consumer2); | 317 WebDataService::Handle handle2 = wds_->GetAutofillProfiles(&consumer2); |
| 318 MessageLoop::current()->Run(); | 318 MessageLoop::current()->Run(); |
| 319 EXPECT_EQ(handle2, consumer2.handle()); | 319 EXPECT_EQ(handle2, consumer2.handle()); |
| 320 ASSERT_EQ(0U, consumer2.result().size()); | 320 ASSERT_EQ(0U, consumer2.result().size()); |
| 321 } | 321 } |
| 322 | 322 |
| 323 TEST_F(WebDataServiceAutofillTest, ProfileUpdate) { | 323 TEST_F(WebDataServiceAutofillTest, ProfileUpdate) { |
| 324 AutofillProfile profile1; | 324 AutofillProfile profile1; |
| 325 profile1.SetInfo(AutofillType(NAME_FIRST), ASCIIToUTF16("Abe")); | 325 profile1.SetInfo(NAME_FIRST, ASCIIToUTF16("Abe")); |
| 326 AutofillProfile profile2; | 326 AutofillProfile profile2; |
| 327 profile2.SetInfo(AutofillType(NAME_FIRST), ASCIIToUTF16("Alice")); | 327 profile2.SetInfo(NAME_FIRST, ASCIIToUTF16("Alice")); |
| 328 | 328 |
| 329 EXPECT_CALL(*observer_helper_->observer(), Observe(_, _, _)). | 329 EXPECT_CALL(*observer_helper_->observer(), Observe(_, _, _)). |
| 330 WillOnce(DoDefault()). | 330 WillOnce(DoDefault()). |
| 331 WillOnce(SignalEvent(&done_event_)); | 331 WillOnce(SignalEvent(&done_event_)); |
| 332 wds_->AddAutofillProfile(profile1); | 332 wds_->AddAutofillProfile(profile1); |
| 333 wds_->AddAutofillProfile(profile2); | 333 wds_->AddAutofillProfile(profile2); |
| 334 done_event_.TimedWait(test_timeout_); | 334 done_event_.TimedWait(test_timeout_); |
| 335 | 335 |
| 336 // Check that they were added. | 336 // Check that they were added. |
| 337 AutofillWebDataServiceConsumer<std::vector<AutofillProfile*> > consumer; | 337 AutofillWebDataServiceConsumer<std::vector<AutofillProfile*> > consumer; |
| 338 WebDataService::Handle handle = wds_->GetAutofillProfiles(&consumer); | 338 WebDataService::Handle handle = wds_->GetAutofillProfiles(&consumer); |
| 339 MessageLoop::current()->Run(); | 339 MessageLoop::current()->Run(); |
| 340 EXPECT_EQ(handle, consumer.handle()); | 340 EXPECT_EQ(handle, consumer.handle()); |
| 341 ASSERT_EQ(2U, consumer.result().size()); | 341 ASSERT_EQ(2U, consumer.result().size()); |
| 342 EXPECT_EQ(profile1, *consumer.result()[0]); | 342 EXPECT_EQ(profile1, *consumer.result()[0]); |
| 343 EXPECT_EQ(profile2, *consumer.result()[1]); | 343 EXPECT_EQ(profile2, *consumer.result()[1]); |
| 344 STLDeleteElements(&consumer.result()); | 344 STLDeleteElements(&consumer.result()); |
| 345 | 345 |
| 346 AutofillProfile profile1_changed(profile1); | 346 AutofillProfile profile1_changed(profile1); |
| 347 profile1_changed.SetInfo(AutofillType(NAME_FIRST), ASCIIToUTF16("Bill")); | 347 profile1_changed.SetInfo(NAME_FIRST, ASCIIToUTF16("Bill")); |
| 348 const AutofillProfileChange expected_change( | 348 const AutofillProfileChange expected_change( |
| 349 AutofillProfileChange::UPDATE, profile1.guid(), &profile1_changed); | 349 AutofillProfileChange::UPDATE, profile1.guid(), &profile1_changed); |
| 350 | 350 |
| 351 EXPECT_CALL( | 351 EXPECT_CALL( |
| 352 *observer_helper_->observer(), | 352 *observer_helper_->observer(), |
| 353 Observe(NotificationType(NotificationType::AUTOFILL_PROFILE_CHANGED), | 353 Observe(NotificationType(NotificationType::AUTOFILL_PROFILE_CHANGED), |
| 354 Source<WebDataService>(wds_.get()), | 354 Source<WebDataService>(wds_.get()), |
| 355 Property(&Details<const AutofillProfileChange>::ptr, | 355 Property(&Details<const AutofillProfileChange>::ptr, |
| 356 Pointee(expected_change)))). | 356 Pointee(expected_change)))). |
| 357 WillOnce(SignalEvent(&done_event_)); | 357 WillOnce(SignalEvent(&done_event_)); |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 434 // Check that it was removed. | 434 // Check that it was removed. |
| 435 AutofillWebDataServiceConsumer<std::vector<CreditCard*> > consumer2; | 435 AutofillWebDataServiceConsumer<std::vector<CreditCard*> > consumer2; |
| 436 WebDataService::Handle handle2 = wds_->GetCreditCards(&consumer2); | 436 WebDataService::Handle handle2 = wds_->GetCreditCards(&consumer2); |
| 437 MessageLoop::current()->Run(); | 437 MessageLoop::current()->Run(); |
| 438 EXPECT_EQ(handle2, consumer2.handle()); | 438 EXPECT_EQ(handle2, consumer2.handle()); |
| 439 ASSERT_EQ(0U, consumer2.result().size()); | 439 ASSERT_EQ(0U, consumer2.result().size()); |
| 440 } | 440 } |
| 441 | 441 |
| 442 TEST_F(WebDataServiceAutofillTest, CreditUpdate) { | 442 TEST_F(WebDataServiceAutofillTest, CreditUpdate) { |
| 443 CreditCard card1; | 443 CreditCard card1; |
| 444 card1.SetInfo(AutofillType(CREDIT_CARD_NAME), ASCIIToUTF16("Abe")); | 444 card1.SetInfo(CREDIT_CARD_NAME, ASCIIToUTF16("Abe")); |
| 445 CreditCard card2; | 445 CreditCard card2; |
| 446 card2.SetInfo(AutofillType(CREDIT_CARD_NAME), ASCIIToUTF16("Alice")); | 446 card2.SetInfo(CREDIT_CARD_NAME, ASCIIToUTF16("Alice")); |
| 447 | 447 |
| 448 EXPECT_CALL(*observer_helper_->observer(), Observe(_, _, _)). | 448 EXPECT_CALL(*observer_helper_->observer(), Observe(_, _, _)). |
| 449 Times(2). | 449 Times(2). |
| 450 WillOnce(DoDefault()). | 450 WillOnce(DoDefault()). |
| 451 WillOnce(SignalEvent(&done_event_)); | 451 WillOnce(SignalEvent(&done_event_)); |
| 452 wds_->AddCreditCard(card1); | 452 wds_->AddCreditCard(card1); |
| 453 wds_->AddCreditCard(card2); | 453 wds_->AddCreditCard(card2); |
| 454 done_event_.TimedWait(test_timeout_); | 454 done_event_.TimedWait(test_timeout_); |
| 455 | 455 |
| 456 // Check that they got added. | 456 // Check that they got added. |
| 457 AutofillWebDataServiceConsumer<std::vector<CreditCard*> > consumer; | 457 AutofillWebDataServiceConsumer<std::vector<CreditCard*> > consumer; |
| 458 WebDataService::Handle handle = wds_->GetCreditCards(&consumer); | 458 WebDataService::Handle handle = wds_->GetCreditCards(&consumer); |
| 459 MessageLoop::current()->Run(); | 459 MessageLoop::current()->Run(); |
| 460 EXPECT_EQ(handle, consumer.handle()); | 460 EXPECT_EQ(handle, consumer.handle()); |
| 461 ASSERT_EQ(2U, consumer.result().size()); | 461 ASSERT_EQ(2U, consumer.result().size()); |
| 462 EXPECT_EQ(card1, *consumer.result()[0]); | 462 EXPECT_EQ(card1, *consumer.result()[0]); |
| 463 EXPECT_EQ(card2, *consumer.result()[1]); | 463 EXPECT_EQ(card2, *consumer.result()[1]); |
| 464 STLDeleteElements(&consumer.result()); | 464 STLDeleteElements(&consumer.result()); |
| 465 | 465 |
| 466 CreditCard card1_changed(card1); | 466 CreditCard card1_changed(card1); |
| 467 card1_changed.SetInfo(AutofillType(CREDIT_CARD_NAME), ASCIIToUTF16("Bill")); | 467 card1_changed.SetInfo(CREDIT_CARD_NAME, ASCIIToUTF16("Bill")); |
| 468 const AutofillCreditCardChange expected_change( | 468 const AutofillCreditCardChange expected_change( |
| 469 AutofillCreditCardChange::UPDATE, card1.guid(), &card1_changed); | 469 AutofillCreditCardChange::UPDATE, card1.guid(), &card1_changed); |
| 470 | 470 |
| 471 EXPECT_CALL( | 471 EXPECT_CALL( |
| 472 *observer_helper_->observer(), | 472 *observer_helper_->observer(), |
| 473 Observe( | 473 Observe( |
| 474 NotificationType(NotificationType::AUTOFILL_CREDIT_CARD_CHANGED), | 474 NotificationType(NotificationType::AUTOFILL_CREDIT_CARD_CHANGED), |
| 475 Source<WebDataService>(wds_.get()), | 475 Source<WebDataService>(wds_.get()), |
| 476 Property(&Details<const AutofillCreditCardChange>::ptr, | 476 Property(&Details<const AutofillCreditCardChange>::ptr, |
| 477 Pointee(expected_change)))). | 477 Pointee(expected_change)))). |
| 478 WillOnce(SignalEvent(&done_event_)); | 478 WillOnce(SignalEvent(&done_event_)); |
| 479 | 479 |
| 480 wds_->UpdateCreditCard(card1_changed); | 480 wds_->UpdateCreditCard(card1_changed); |
| 481 done_event_.TimedWait(test_timeout_); | 481 done_event_.TimedWait(test_timeout_); |
| 482 | 482 |
| 483 // Check that the updates were made. | 483 // Check that the updates were made. |
| 484 AutofillWebDataServiceConsumer<std::vector<CreditCard*> > consumer2; | 484 AutofillWebDataServiceConsumer<std::vector<CreditCard*> > consumer2; |
| 485 WebDataService::Handle handle2 = wds_->GetCreditCards(&consumer2); | 485 WebDataService::Handle handle2 = wds_->GetCreditCards(&consumer2); |
| 486 MessageLoop::current()->Run(); | 486 MessageLoop::current()->Run(); |
| 487 EXPECT_EQ(handle2, consumer2.handle()); | 487 EXPECT_EQ(handle2, consumer2.handle()); |
| 488 ASSERT_EQ(2U, consumer2.result().size()); | 488 ASSERT_EQ(2U, consumer2.result().size()); |
| 489 EXPECT_NE(card1, *consumer2.result()[0]); | 489 EXPECT_NE(card1, *consumer2.result()[0]); |
| 490 EXPECT_EQ(card1_changed, *consumer2.result()[0]); | 490 EXPECT_EQ(card1_changed, *consumer2.result()[0]); |
| 491 EXPECT_EQ(card2, *consumer2.result()[1]); | 491 EXPECT_EQ(card2, *consumer2.result()[1]); |
| 492 STLDeleteElements(&consumer2.result()); | 492 STLDeleteElements(&consumer2.result()); |
| 493 } | 493 } |
| OLD | NEW |