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