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 <memory> | 5 #include <memory> |
6 #include <string> | 6 #include <string> |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/files/scoped_temp_dir.h" | 10 #include "base/files/scoped_temp_dir.h" |
(...skipping 290 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
301 wds_->AddAutofillProfile(profile); | 301 wds_->AddAutofillProfile(profile); |
302 done_event_.TimedWait(test_timeout_); | 302 done_event_.TimedWait(test_timeout_); |
303 | 303 |
304 // Check that it was added. | 304 // Check that it was added. |
305 AutofillWebDataServiceConsumer<std::vector<AutofillProfile*> > consumer; | 305 AutofillWebDataServiceConsumer<std::vector<AutofillProfile*> > consumer; |
306 WebDataServiceBase::Handle handle = wds_->GetAutofillProfiles(&consumer); | 306 WebDataServiceBase::Handle handle = wds_->GetAutofillProfiles(&consumer); |
307 base::RunLoop().Run(); | 307 base::RunLoop().Run(); |
308 EXPECT_EQ(handle, consumer.handle()); | 308 EXPECT_EQ(handle, consumer.handle()); |
309 ASSERT_EQ(1U, consumer.result().size()); | 309 ASSERT_EQ(1U, consumer.result().size()); |
310 EXPECT_EQ(profile, *consumer.result()[0]); | 310 EXPECT_EQ(profile, *consumer.result()[0]); |
311 STLDeleteElements(&consumer.result()); | 311 base::STLDeleteElements(&consumer.result()); |
312 } | 312 } |
313 | 313 |
314 TEST_F(WebDataServiceAutofillTest, ProfileRemove) { | 314 TEST_F(WebDataServiceAutofillTest, ProfileRemove) { |
315 AutofillProfile profile; | 315 AutofillProfile profile; |
316 | 316 |
317 // Add a profile. | 317 // Add a profile. |
318 EXPECT_CALL(observer_, AutofillProfileChanged(_)) | 318 EXPECT_CALL(observer_, AutofillProfileChanged(_)) |
319 .WillOnce(SignalEvent(&done_event_)); | 319 .WillOnce(SignalEvent(&done_event_)); |
320 wds_->AddAutofillProfile(profile); | 320 wds_->AddAutofillProfile(profile); |
321 done_event_.TimedWait(test_timeout_); | 321 done_event_.TimedWait(test_timeout_); |
322 | 322 |
323 // Check that it was added. | 323 // Check that it was added. |
324 AutofillWebDataServiceConsumer<std::vector<AutofillProfile*> > consumer; | 324 AutofillWebDataServiceConsumer<std::vector<AutofillProfile*> > consumer; |
325 WebDataServiceBase::Handle handle = wds_->GetAutofillProfiles(&consumer); | 325 WebDataServiceBase::Handle handle = wds_->GetAutofillProfiles(&consumer); |
326 base::RunLoop().Run(); | 326 base::RunLoop().Run(); |
327 EXPECT_EQ(handle, consumer.handle()); | 327 EXPECT_EQ(handle, consumer.handle()); |
328 ASSERT_EQ(1U, consumer.result().size()); | 328 ASSERT_EQ(1U, consumer.result().size()); |
329 EXPECT_EQ(profile, *consumer.result()[0]); | 329 EXPECT_EQ(profile, *consumer.result()[0]); |
330 STLDeleteElements(&consumer.result()); | 330 base::STLDeleteElements(&consumer.result()); |
331 | 331 |
332 // Check that GUID-based notification was sent. | 332 // Check that GUID-based notification was sent. |
333 const AutofillProfileChange expected_change( | 333 const AutofillProfileChange expected_change( |
334 AutofillProfileChange::REMOVE, profile.guid(), NULL); | 334 AutofillProfileChange::REMOVE, profile.guid(), NULL); |
335 EXPECT_CALL(observer_, AutofillProfileChanged(expected_change)) | 335 EXPECT_CALL(observer_, AutofillProfileChanged(expected_change)) |
336 .WillOnce(SignalEvent(&done_event_)); | 336 .WillOnce(SignalEvent(&done_event_)); |
337 | 337 |
338 // Remove the profile. | 338 // Remove the profile. |
339 wds_->RemoveAutofillProfile(profile.guid()); | 339 wds_->RemoveAutofillProfile(profile.guid()); |
340 done_event_.TimedWait(test_timeout_); | 340 done_event_.TimedWait(test_timeout_); |
(...skipping 24 matching lines...) Expand all Loading... |
365 done_event_.TimedWait(test_timeout_); | 365 done_event_.TimedWait(test_timeout_); |
366 | 366 |
367 // Check that they were added. | 367 // Check that they were added. |
368 AutofillWebDataServiceConsumer<std::vector<AutofillProfile*> > consumer; | 368 AutofillWebDataServiceConsumer<std::vector<AutofillProfile*> > consumer; |
369 WebDataServiceBase::Handle handle = wds_->GetAutofillProfiles(&consumer); | 369 WebDataServiceBase::Handle handle = wds_->GetAutofillProfiles(&consumer); |
370 base::RunLoop().Run(); | 370 base::RunLoop().Run(); |
371 EXPECT_EQ(handle, consumer.handle()); | 371 EXPECT_EQ(handle, consumer.handle()); |
372 ASSERT_EQ(2U, consumer.result().size()); | 372 ASSERT_EQ(2U, consumer.result().size()); |
373 EXPECT_EQ(profile2, *consumer.result()[0]); | 373 EXPECT_EQ(profile2, *consumer.result()[0]); |
374 EXPECT_EQ(profile1, *consumer.result()[1]); | 374 EXPECT_EQ(profile1, *consumer.result()[1]); |
375 STLDeleteElements(&consumer.result()); | 375 base::STLDeleteElements(&consumer.result()); |
376 | 376 |
377 AutofillProfile profile2_changed(profile2); | 377 AutofillProfile profile2_changed(profile2); |
378 profile2_changed.SetRawInfo(NAME_FIRST, ASCIIToUTF16("Bill")); | 378 profile2_changed.SetRawInfo(NAME_FIRST, ASCIIToUTF16("Bill")); |
379 const AutofillProfileChange expected_change( | 379 const AutofillProfileChange expected_change( |
380 AutofillProfileChange::UPDATE, profile2.guid(), &profile2_changed); | 380 AutofillProfileChange::UPDATE, profile2.guid(), &profile2_changed); |
381 | 381 |
382 EXPECT_CALL(observer_, AutofillProfileChanged(expected_change)) | 382 EXPECT_CALL(observer_, AutofillProfileChanged(expected_change)) |
383 .WillOnce(SignalEvent(&done_event_)); | 383 .WillOnce(SignalEvent(&done_event_)); |
384 | 384 |
385 // Update the profile. | 385 // Update the profile. |
386 wds_->UpdateAutofillProfile(profile2_changed); | 386 wds_->UpdateAutofillProfile(profile2_changed); |
387 done_event_.TimedWait(test_timeout_); | 387 done_event_.TimedWait(test_timeout_); |
388 | 388 |
389 // Check that the updates were made. | 389 // Check that the updates were made. |
390 AutofillWebDataServiceConsumer<std::vector<AutofillProfile*> > consumer2; | 390 AutofillWebDataServiceConsumer<std::vector<AutofillProfile*> > consumer2; |
391 WebDataServiceBase::Handle handle2 = wds_->GetAutofillProfiles(&consumer2); | 391 WebDataServiceBase::Handle handle2 = wds_->GetAutofillProfiles(&consumer2); |
392 base::RunLoop().Run(); | 392 base::RunLoop().Run(); |
393 EXPECT_EQ(handle2, consumer2.handle()); | 393 EXPECT_EQ(handle2, consumer2.handle()); |
394 ASSERT_EQ(2U, consumer2.result().size()); | 394 ASSERT_EQ(2U, consumer2.result().size()); |
395 EXPECT_EQ(profile2_changed, *consumer2.result()[0]); | 395 EXPECT_EQ(profile2_changed, *consumer2.result()[0]); |
396 EXPECT_NE(profile2, *consumer2.result()[0]); | 396 EXPECT_NE(profile2, *consumer2.result()[0]); |
397 EXPECT_EQ(profile1, *consumer2.result()[1]); | 397 EXPECT_EQ(profile1, *consumer2.result()[1]); |
398 STLDeleteElements(&consumer2.result()); | 398 base::STLDeleteElements(&consumer2.result()); |
399 } | 399 } |
400 | 400 |
401 TEST_F(WebDataServiceAutofillTest, CreditAdd) { | 401 TEST_F(WebDataServiceAutofillTest, CreditAdd) { |
402 CreditCard card; | 402 CreditCard card; |
403 wds_->AddCreditCard(card); | 403 wds_->AddCreditCard(card); |
404 WaitForDatabaseThread(); | 404 WaitForDatabaseThread(); |
405 | 405 |
406 // Check that it was added. | 406 // Check that it was added. |
407 AutofillWebDataServiceConsumer<std::vector<CreditCard*> > consumer; | 407 AutofillWebDataServiceConsumer<std::vector<CreditCard*> > consumer; |
408 WebDataServiceBase::Handle handle = wds_->GetCreditCards(&consumer); | 408 WebDataServiceBase::Handle handle = wds_->GetCreditCards(&consumer); |
409 base::RunLoop().Run(); | 409 base::RunLoop().Run(); |
410 EXPECT_EQ(handle, consumer.handle()); | 410 EXPECT_EQ(handle, consumer.handle()); |
411 ASSERT_EQ(1U, consumer.result().size()); | 411 ASSERT_EQ(1U, consumer.result().size()); |
412 EXPECT_EQ(card, *consumer.result()[0]); | 412 EXPECT_EQ(card, *consumer.result()[0]); |
413 STLDeleteElements(&consumer.result()); | 413 base::STLDeleteElements(&consumer.result()); |
414 } | 414 } |
415 | 415 |
416 TEST_F(WebDataServiceAutofillTest, CreditCardRemove) { | 416 TEST_F(WebDataServiceAutofillTest, CreditCardRemove) { |
417 CreditCard credit_card; | 417 CreditCard credit_card; |
418 | 418 |
419 // Add a credit card. | 419 // Add a credit card. |
420 wds_->AddCreditCard(credit_card); | 420 wds_->AddCreditCard(credit_card); |
421 WaitForDatabaseThread(); | 421 WaitForDatabaseThread(); |
422 | 422 |
423 // Check that it was added. | 423 // Check that it was added. |
424 AutofillWebDataServiceConsumer<std::vector<CreditCard*> > consumer; | 424 AutofillWebDataServiceConsumer<std::vector<CreditCard*> > consumer; |
425 WebDataServiceBase::Handle handle = wds_->GetCreditCards(&consumer); | 425 WebDataServiceBase::Handle handle = wds_->GetCreditCards(&consumer); |
426 base::RunLoop().Run(); | 426 base::RunLoop().Run(); |
427 EXPECT_EQ(handle, consumer.handle()); | 427 EXPECT_EQ(handle, consumer.handle()); |
428 ASSERT_EQ(1U, consumer.result().size()); | 428 ASSERT_EQ(1U, consumer.result().size()); |
429 EXPECT_EQ(credit_card, *consumer.result()[0]); | 429 EXPECT_EQ(credit_card, *consumer.result()[0]); |
430 STLDeleteElements(&consumer.result()); | 430 base::STLDeleteElements(&consumer.result()); |
431 | 431 |
432 // Remove the credit card. | 432 // Remove the credit card. |
433 wds_->RemoveCreditCard(credit_card.guid()); | 433 wds_->RemoveCreditCard(credit_card.guid()); |
434 WaitForDatabaseThread(); | 434 WaitForDatabaseThread(); |
435 | 435 |
436 // Check that it was removed. | 436 // Check that it was removed. |
437 AutofillWebDataServiceConsumer<std::vector<CreditCard*> > consumer2; | 437 AutofillWebDataServiceConsumer<std::vector<CreditCard*> > consumer2; |
438 WebDataServiceBase::Handle handle2 = wds_->GetCreditCards(&consumer2); | 438 WebDataServiceBase::Handle handle2 = wds_->GetCreditCards(&consumer2); |
439 base::RunLoop().Run(); | 439 base::RunLoop().Run(); |
440 EXPECT_EQ(handle2, consumer2.handle()); | 440 EXPECT_EQ(handle2, consumer2.handle()); |
(...skipping 13 matching lines...) Expand all Loading... |
454 WaitForDatabaseThread(); | 454 WaitForDatabaseThread(); |
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 WebDataServiceBase::Handle handle = wds_->GetCreditCards(&consumer); | 458 WebDataServiceBase::Handle handle = wds_->GetCreditCards(&consumer); |
459 base::RunLoop().Run(); | 459 base::RunLoop().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(card2, *consumer.result()[0]); | 462 EXPECT_EQ(card2, *consumer.result()[0]); |
463 EXPECT_EQ(card1, *consumer.result()[1]); | 463 EXPECT_EQ(card1, *consumer.result()[1]); |
464 STLDeleteElements(&consumer.result()); | 464 base::STLDeleteElements(&consumer.result()); |
465 | 465 |
466 CreditCard card2_changed(card2); | 466 CreditCard card2_changed(card2); |
467 card2_changed.SetRawInfo(CREDIT_CARD_NAME_FULL, ASCIIToUTF16("Bill")); | 467 card2_changed.SetRawInfo(CREDIT_CARD_NAME_FULL, ASCIIToUTF16("Bill")); |
468 | 468 |
469 wds_->UpdateCreditCard(card2_changed); | 469 wds_->UpdateCreditCard(card2_changed); |
470 WaitForDatabaseThread(); | 470 WaitForDatabaseThread(); |
471 | 471 |
472 // Check that the updates were made. | 472 // Check that the updates were made. |
473 AutofillWebDataServiceConsumer<std::vector<CreditCard*> > consumer2; | 473 AutofillWebDataServiceConsumer<std::vector<CreditCard*> > consumer2; |
474 WebDataServiceBase::Handle handle2 = wds_->GetCreditCards(&consumer2); | 474 WebDataServiceBase::Handle handle2 = wds_->GetCreditCards(&consumer2); |
475 base::RunLoop().Run(); | 475 base::RunLoop().Run(); |
476 EXPECT_EQ(handle2, consumer2.handle()); | 476 EXPECT_EQ(handle2, consumer2.handle()); |
477 ASSERT_EQ(2U, consumer2.result().size()); | 477 ASSERT_EQ(2U, consumer2.result().size()); |
478 EXPECT_NE(card2, *consumer2.result()[0]); | 478 EXPECT_NE(card2, *consumer2.result()[0]); |
479 EXPECT_EQ(card2_changed, *consumer2.result()[0]); | 479 EXPECT_EQ(card2_changed, *consumer2.result()[0]); |
480 EXPECT_EQ(card1, *consumer2.result()[1]); | 480 EXPECT_EQ(card1, *consumer2.result()[1]); |
481 STLDeleteElements(&consumer2.result()); | 481 base::STLDeleteElements(&consumer2.result()); |
482 } | 482 } |
483 | 483 |
484 TEST_F(WebDataServiceAutofillTest, AutofillRemoveModifiedBetween) { | 484 TEST_F(WebDataServiceAutofillTest, AutofillRemoveModifiedBetween) { |
485 // Add a profile. | 485 // Add a profile. |
486 EXPECT_CALL(observer_, AutofillProfileChanged(_)) | 486 EXPECT_CALL(observer_, AutofillProfileChanged(_)) |
487 .WillOnce(SignalEvent(&done_event_)); | 487 .WillOnce(SignalEvent(&done_event_)); |
488 AutofillProfile profile; | 488 AutofillProfile profile; |
489 wds_->AddAutofillProfile(profile); | 489 wds_->AddAutofillProfile(profile); |
490 done_event_.TimedWait(test_timeout_); | 490 done_event_.TimedWait(test_timeout_); |
491 | 491 |
492 // Check that it was added. | 492 // Check that it was added. |
493 AutofillWebDataServiceConsumer<std::vector<AutofillProfile*> > | 493 AutofillWebDataServiceConsumer<std::vector<AutofillProfile*> > |
494 profile_consumer; | 494 profile_consumer; |
495 WebDataServiceBase::Handle handle = | 495 WebDataServiceBase::Handle handle = |
496 wds_->GetAutofillProfiles(&profile_consumer); | 496 wds_->GetAutofillProfiles(&profile_consumer); |
497 base::RunLoop().Run(); | 497 base::RunLoop().Run(); |
498 EXPECT_EQ(handle, profile_consumer.handle()); | 498 EXPECT_EQ(handle, profile_consumer.handle()); |
499 ASSERT_EQ(1U, profile_consumer.result().size()); | 499 ASSERT_EQ(1U, profile_consumer.result().size()); |
500 EXPECT_EQ(profile, *profile_consumer.result()[0]); | 500 EXPECT_EQ(profile, *profile_consumer.result()[0]); |
501 STLDeleteElements(&profile_consumer.result()); | 501 base::STLDeleteElements(&profile_consumer.result()); |
502 | 502 |
503 // Add a credit card. | 503 // Add a credit card. |
504 CreditCard credit_card; | 504 CreditCard credit_card; |
505 wds_->AddCreditCard(credit_card); | 505 wds_->AddCreditCard(credit_card); |
506 WaitForDatabaseThread(); | 506 WaitForDatabaseThread(); |
507 | 507 |
508 // Check that it was added. | 508 // Check that it was added. |
509 AutofillWebDataServiceConsumer<std::vector<CreditCard*> > card_consumer; | 509 AutofillWebDataServiceConsumer<std::vector<CreditCard*> > card_consumer; |
510 handle = wds_->GetCreditCards(&card_consumer); | 510 handle = wds_->GetCreditCards(&card_consumer); |
511 base::RunLoop().Run(); | 511 base::RunLoop().Run(); |
512 EXPECT_EQ(handle, card_consumer.handle()); | 512 EXPECT_EQ(handle, card_consumer.handle()); |
513 ASSERT_EQ(1U, card_consumer.result().size()); | 513 ASSERT_EQ(1U, card_consumer.result().size()); |
514 EXPECT_EQ(credit_card, *card_consumer.result()[0]); | 514 EXPECT_EQ(credit_card, *card_consumer.result()[0]); |
515 STLDeleteElements(&card_consumer.result()); | 515 base::STLDeleteElements(&card_consumer.result()); |
516 | 516 |
517 // Check that GUID-based notification was sent for the profile. | 517 // Check that GUID-based notification was sent for the profile. |
518 const AutofillProfileChange expected_profile_change( | 518 const AutofillProfileChange expected_profile_change( |
519 AutofillProfileChange::REMOVE, profile.guid(), NULL); | 519 AutofillProfileChange::REMOVE, profile.guid(), NULL); |
520 EXPECT_CALL(observer_, AutofillProfileChanged(expected_profile_change)) | 520 EXPECT_CALL(observer_, AutofillProfileChanged(expected_profile_change)) |
521 .WillOnce(SignalEvent(&done_event_)); | 521 .WillOnce(SignalEvent(&done_event_)); |
522 | 522 |
523 // Remove the profile using time range of "all time". | 523 // Remove the profile using time range of "all time". |
524 wds_->RemoveAutofillDataModifiedBetween(Time(), Time()); | 524 wds_->RemoveAutofillDataModifiedBetween(Time(), Time()); |
525 done_event_.TimedWait(test_timeout_); | 525 done_event_.TimedWait(test_timeout_); |
(...skipping 10 matching lines...) Expand all Loading... |
536 | 536 |
537 // Check that the credit card was removed. | 537 // Check that the credit card was removed. |
538 AutofillWebDataServiceConsumer<std::vector<CreditCard*> > card_consumer2; | 538 AutofillWebDataServiceConsumer<std::vector<CreditCard*> > card_consumer2; |
539 handle2 = wds_->GetCreditCards(&card_consumer2); | 539 handle2 = wds_->GetCreditCards(&card_consumer2); |
540 base::RunLoop().Run(); | 540 base::RunLoop().Run(); |
541 EXPECT_EQ(handle2, card_consumer2.handle()); | 541 EXPECT_EQ(handle2, card_consumer2.handle()); |
542 ASSERT_EQ(0U, card_consumer2.result().size()); | 542 ASSERT_EQ(0U, card_consumer2.result().size()); |
543 } | 543 } |
544 | 544 |
545 } // namespace autofill | 545 } // namespace autofill |
OLD | NEW |