OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "google_apis/gcm/engine/gcm_store_impl.h" | 5 #include "google_apis/gcm/engine/gcm_store_impl.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 489 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
500 } | 500 } |
501 } | 501 } |
502 | 502 |
503 TEST_F(GCMStoreImplTest, AccountMapping) { | 503 TEST_F(GCMStoreImplTest, AccountMapping) { |
504 scoped_ptr<GCMStore> gcm_store(BuildGCMStore()); | 504 scoped_ptr<GCMStore> gcm_store(BuildGCMStore()); |
505 scoped_ptr<GCMStore::LoadResult> load_result; | 505 scoped_ptr<GCMStore::LoadResult> load_result; |
506 gcm_store->Load(base::Bind( | 506 gcm_store->Load(base::Bind( |
507 &GCMStoreImplTest::LoadCallback, base::Unretained(this), &load_result)); | 507 &GCMStoreImplTest::LoadCallback, base::Unretained(this), &load_result)); |
508 | 508 |
509 // Add account mappings. | 509 // Add account mappings. |
510 AccountInfo account_info1; | 510 AccountMapping account_mapping1; |
511 account_info1.account_id = "account_id_1"; | 511 account_mapping1.account_id = "account_id_1"; |
512 account_info1.email = "account_id_1@gmail.com"; | 512 account_mapping1.email = "account_id_1@gmail.com"; |
513 account_info1.last_message_type = AccountInfo::MSG_ADD; | 513 account_mapping1.access_token = "account_token1"; |
514 account_info1.last_message_id = "message_1"; | 514 account_mapping1.status = AccountMapping::ADDING; |
515 account_info1.last_message_timestamp = | 515 account_mapping1.status_change_timestamp = |
516 base::Time::FromInternalValue(1305797421259935LL); | 516 base::Time::FromInternalValue(1305797421259935LL); |
517 AccountInfo account_info2; | 517 account_mapping1.last_message_type = AccountMapping::MSG_ADD; |
518 account_info2.account_id = "account_id_2"; | 518 account_mapping1.last_message_id = "message_1"; |
519 account_info2.email = "account_id_2@gmail.com"; | 519 |
520 account_info2.last_message_type = AccountInfo::MSG_REMOVE; | 520 AccountMapping account_mapping2; |
521 account_info2.last_message_id = "message_2"; | 521 account_mapping2.account_id = "account_id_2"; |
522 account_info2.last_message_timestamp = | 522 account_mapping2.email = "account_id_2@gmail.com"; |
| 523 account_mapping2.access_token = "account_token1"; |
| 524 account_mapping2.status = AccountMapping::REMOVING; |
| 525 account_mapping2.status_change_timestamp = |
523 base::Time::FromInternalValue(1305734521259935LL); | 526 base::Time::FromInternalValue(1305734521259935LL); |
| 527 account_mapping2.last_message_type = AccountMapping::MSG_REMOVE; |
| 528 account_mapping2.last_message_id = "message_2"; |
524 | 529 |
525 gcm_store->AddAccountMapping( | 530 gcm_store->AddAccountMapping( |
526 account_info1, | 531 account_mapping1, |
527 base::Bind(&GCMStoreImplTest::UpdateCallback, base::Unretained(this))); | 532 base::Bind(&GCMStoreImplTest::UpdateCallback, base::Unretained(this))); |
528 PumpLoop(); | 533 PumpLoop(); |
529 gcm_store->AddAccountMapping( | 534 gcm_store->AddAccountMapping( |
530 account_info2, | 535 account_mapping2, |
531 base::Bind(&GCMStoreImplTest::UpdateCallback, base::Unretained(this))); | 536 base::Bind(&GCMStoreImplTest::UpdateCallback, base::Unretained(this))); |
532 PumpLoop(); | 537 PumpLoop(); |
533 | 538 |
534 gcm_store = BuildGCMStore().Pass(); | 539 gcm_store = BuildGCMStore().Pass(); |
535 gcm_store->Load(base::Bind( | 540 gcm_store->Load(base::Bind( |
536 &GCMStoreImplTest::LoadCallback, base::Unretained(this), &load_result)); | 541 &GCMStoreImplTest::LoadCallback, base::Unretained(this), &load_result)); |
537 PumpLoop(); | 542 PumpLoop(); |
538 | 543 |
539 EXPECT_EQ(2UL, load_result->account_infos.size()); | 544 EXPECT_EQ(2UL, load_result->account_mappings.size()); |
540 GCMStore::AccountInfoMap::iterator iter = load_result->account_infos.begin(); | 545 GCMStore::AccountMappingMap::iterator iter = |
| 546 load_result->account_mappings.begin(); |
541 EXPECT_EQ("account_id_1", iter->first); | 547 EXPECT_EQ("account_id_1", iter->first); |
542 EXPECT_EQ(account_info1.account_id, iter->second.account_id); | 548 EXPECT_EQ(account_mapping1.account_id, iter->second.account_id); |
543 EXPECT_EQ(account_info1.email, iter->second.email); | 549 EXPECT_EQ(account_mapping1.email, iter->second.email); |
544 EXPECT_EQ(account_info1.last_message_type, iter->second.last_message_type); | 550 EXPECT_TRUE(iter->second.access_token.empty()); |
545 EXPECT_EQ(account_info1.last_message_id, iter->second.last_message_id); | 551 EXPECT_EQ(AccountMapping::ADDING, iter->second.status); |
546 EXPECT_EQ(account_info1.last_message_timestamp, | 552 EXPECT_EQ(account_mapping1.status_change_timestamp, |
547 iter->second.last_message_timestamp); | 553 iter->second.status_change_timestamp); |
| 554 EXPECT_EQ(account_mapping1.last_message_type, iter->second.last_message_type); |
| 555 EXPECT_EQ(account_mapping1.last_message_id, iter->second.last_message_id); |
548 ++iter; | 556 ++iter; |
549 EXPECT_EQ("account_id_2", iter->first); | 557 EXPECT_EQ("account_id_2", iter->first); |
550 EXPECT_EQ(account_info2.account_id, iter->second.account_id); | 558 EXPECT_EQ(account_mapping2.account_id, iter->second.account_id); |
551 EXPECT_EQ(account_info2.email, iter->second.email); | 559 EXPECT_EQ(account_mapping2.email, iter->second.email); |
552 EXPECT_EQ(account_info2.last_message_type, iter->second.last_message_type); | 560 EXPECT_TRUE(iter->second.access_token.empty()); |
553 EXPECT_EQ(account_info2.last_message_id, iter->second.last_message_id); | 561 EXPECT_EQ(AccountMapping::REMOVING, iter->second.status); |
554 EXPECT_EQ(account_info2.last_message_timestamp, | 562 EXPECT_EQ(account_mapping2.status_change_timestamp, |
555 iter->second.last_message_timestamp); | 563 iter->second.status_change_timestamp); |
| 564 EXPECT_EQ(account_mapping2.last_message_type, iter->second.last_message_type); |
| 565 EXPECT_EQ(account_mapping2.last_message_id, iter->second.last_message_id); |
556 | 566 |
557 gcm_store->RemoveAccountMapping( | 567 gcm_store->RemoveAccountMapping( |
558 account_info1.account_id, | 568 account_mapping1.account_id, |
559 base::Bind(&GCMStoreImplTest::UpdateCallback, base::Unretained(this))); | 569 base::Bind(&GCMStoreImplTest::UpdateCallback, base::Unretained(this))); |
560 PumpLoop(); | 570 PumpLoop(); |
561 | 571 |
562 gcm_store = BuildGCMStore().Pass(); | 572 gcm_store = BuildGCMStore().Pass(); |
563 gcm_store->Load(base::Bind( | 573 gcm_store->Load(base::Bind( |
564 &GCMStoreImplTest::LoadCallback, base::Unretained(this), &load_result)); | 574 &GCMStoreImplTest::LoadCallback, base::Unretained(this), &load_result)); |
565 PumpLoop(); | 575 PumpLoop(); |
566 | 576 |
567 EXPECT_EQ(1UL, load_result->account_infos.size()); | 577 EXPECT_EQ(1UL, load_result->account_mappings.size()); |
568 iter = load_result->account_infos.begin(); | 578 iter = load_result->account_mappings.begin(); |
569 EXPECT_EQ("account_id_2", iter->first); | 579 EXPECT_EQ("account_id_2", iter->first); |
570 EXPECT_EQ(account_info2.account_id, iter->second.account_id); | 580 EXPECT_EQ(account_mapping2.account_id, iter->second.account_id); |
571 EXPECT_EQ(account_info2.email, iter->second.email); | 581 EXPECT_EQ(account_mapping2.email, iter->second.email); |
572 EXPECT_EQ(account_info2.last_message_type, iter->second.last_message_type); | 582 EXPECT_TRUE(iter->second.access_token.empty()); |
573 EXPECT_EQ(account_info2.last_message_id, iter->second.last_message_id); | 583 EXPECT_EQ(AccountMapping::REMOVING, iter->second.status); |
574 EXPECT_EQ(account_info2.last_message_timestamp, | 584 EXPECT_EQ(account_mapping2.status_change_timestamp, |
575 iter->second.last_message_timestamp); | 585 iter->second.status_change_timestamp); |
| 586 EXPECT_EQ(account_mapping2.last_message_type, iter->second.last_message_type); |
| 587 EXPECT_EQ(account_mapping2.last_message_id, iter->second.last_message_id); |
576 } | 588 } |
577 | 589 |
578 // When the database is destroyed, all database updates should fail. At the | 590 // When the database is destroyed, all database updates should fail. At the |
579 // same time, they per-app message counts should not go up, as failures should | 591 // same time, they per-app message counts should not go up, as failures should |
580 // result in decrementing the counts. | 592 // result in decrementing the counts. |
581 TEST_F(GCMStoreImplTest, AddMessageAfterDestroy) { | 593 TEST_F(GCMStoreImplTest, AddMessageAfterDestroy) { |
582 scoped_ptr<GCMStore> gcm_store(BuildGCMStore()); | 594 scoped_ptr<GCMStore> gcm_store(BuildGCMStore()); |
583 scoped_ptr<GCMStore::LoadResult> load_result; | 595 scoped_ptr<GCMStore::LoadResult> load_result; |
584 gcm_store->Load(base::Bind(&GCMStoreImplTest::LoadCallback, | 596 gcm_store->Load(base::Bind(&GCMStoreImplTest::LoadCallback, |
585 base::Unretained(this), | 597 base::Unretained(this), |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
617 | 629 |
618 gcm_store->Load(base::Bind(&GCMStoreImplTest::LoadCallback, | 630 gcm_store->Load(base::Bind(&GCMStoreImplTest::LoadCallback, |
619 base::Unretained(this), | 631 base::Unretained(this), |
620 &load_result)); | 632 &load_result)); |
621 PumpLoop(); | 633 PumpLoop(); |
622 } | 634 } |
623 | 635 |
624 } // namespace | 636 } // namespace |
625 | 637 |
626 } // namespace gcm | 638 } // namespace gcm |
OLD | NEW |