Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(352)

Side by Side Diff: google_apis/gcm/engine/gcm_store_impl_unittest.cc

Issue 429073002: [GCM] Persistence of account mappings. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fixing the gn build Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « google_apis/gcm/engine/gcm_store_impl.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 27 matching lines...) Expand all
38 const char kCategoryName[] = "my_category"; 38 const char kCategoryName[] = "my_category";
39 39
40 const uint64 kDeviceId = 22; 40 const uint64 kDeviceId = 22;
41 const uint64 kDeviceToken = 55; 41 const uint64 kDeviceToken = 55;
42 42
43 class GCMStoreImplTest : public testing::Test { 43 class GCMStoreImplTest : public testing::Test {
44 public: 44 public:
45 GCMStoreImplTest(); 45 GCMStoreImplTest();
46 virtual ~GCMStoreImplTest(); 46 virtual ~GCMStoreImplTest();
47 47
48 virtual void SetUp() OVERRIDE;
49
50 scoped_ptr<GCMStore> BuildGCMStore(); 48 scoped_ptr<GCMStore> BuildGCMStore();
51 49
52 std::string GetNextPersistentId(); 50 std::string GetNextPersistentId();
53 51
54 void PumpLoop(); 52 void PumpLoop();
55 53
56 void LoadCallback(scoped_ptr<GCMStore::LoadResult>* result_dst, 54 void LoadCallback(scoped_ptr<GCMStore::LoadResult>* result_dst,
57 scoped_ptr<GCMStore::LoadResult> result); 55 scoped_ptr<GCMStore::LoadResult> result);
58 void UpdateCallback(bool success); 56 void UpdateCallback(bool success);
59 57
60 protected: 58 protected:
61 base::MessageLoop message_loop_; 59 base::MessageLoop message_loop_;
62 base::ScopedTempDir temp_directory_; 60 base::ScopedTempDir temp_directory_;
63 bool expected_success_; 61 bool expected_success_;
64 uint64 next_persistent_id_; 62 uint64 next_persistent_id_;
65 scoped_ptr<base::RunLoop> run_loop_; 63 scoped_ptr<base::RunLoop> run_loop_;
66 }; 64 };
67 65
68 GCMStoreImplTest::GCMStoreImplTest() 66 GCMStoreImplTest::GCMStoreImplTest()
69 : expected_success_(true), 67 : expected_success_(true),
70 next_persistent_id_(base::Time::Now().ToInternalValue()) { 68 next_persistent_id_(base::Time::Now().ToInternalValue()) {
71 EXPECT_TRUE(temp_directory_.CreateUniqueTempDir()); 69 EXPECT_TRUE(temp_directory_.CreateUniqueTempDir());
72 run_loop_.reset(new base::RunLoop()); 70 run_loop_.reset(new base::RunLoop());
73 } 71 }
74 72
75 GCMStoreImplTest::~GCMStoreImplTest() {} 73 GCMStoreImplTest::~GCMStoreImplTest() {}
76 74
77 void GCMStoreImplTest::SetUp() {
78 testing::Test::SetUp();
79 }
80
81 scoped_ptr<GCMStore> GCMStoreImplTest::BuildGCMStore() { 75 scoped_ptr<GCMStore> GCMStoreImplTest::BuildGCMStore() {
82 return scoped_ptr<GCMStore>(new GCMStoreImpl( 76 return scoped_ptr<GCMStore>(new GCMStoreImpl(
83 temp_directory_.path(), 77 temp_directory_.path(),
84 message_loop_.message_loop_proxy(), 78 message_loop_.message_loop_proxy(),
85 make_scoped_ptr<Encryptor>(new FakeEncryptor))); 79 make_scoped_ptr<Encryptor>(new FakeEncryptor)));
86 } 80 }
87 81
88 std::string GCMStoreImplTest::GetNextPersistentId() { 82 std::string GCMStoreImplTest::GetNextPersistentId() {
89 return base::Uint64ToString(next_persistent_id_++); 83 return base::Uint64ToString(next_persistent_id_++);
90 } 84 }
(...skipping 408 matching lines...) Expand 10 before | Expand all | Expand 10 after
499 message.set_category(kCategoryName); 493 message.set_category(kCategoryName);
500 EXPECT_TRUE(gcm_store->AddOutgoingMessage( 494 EXPECT_TRUE(gcm_store->AddOutgoingMessage(
501 base::IntToString(i + kNumMessagesPerApp), 495 base::IntToString(i + kNumMessagesPerApp),
502 MCSMessage(message), 496 MCSMessage(message),
503 base::Bind(&GCMStoreImplTest::UpdateCallback, 497 base::Bind(&GCMStoreImplTest::UpdateCallback,
504 base::Unretained(this)))); 498 base::Unretained(this))));
505 PumpLoop(); 499 PumpLoop();
506 } 500 }
507 } 501 }
508 502
503 TEST_F(GCMStoreImplTest, AccountMapping) {
504 scoped_ptr<GCMStore> gcm_store(BuildGCMStore());
505 scoped_ptr<GCMStore::LoadResult> load_result;
506 gcm_store->Load(base::Bind(
507 &GCMStoreImplTest::LoadCallback, base::Unretained(this), &load_result));
508
509 // Add account mappings.
510 AccountInfo account_info1;
511 account_info1.account_id = "account_id_1";
512 account_info1.email = "account_id_1@gmail.com";
513 account_info1.last_message_type = AccountInfo::MSG_ADD;
514 account_info1.last_message_id = "message_1";
515 account_info1.last_message_timestamp =
516 base::Time::FromInternalValue(1305797421259935LL);
517 AccountInfo account_info2;
518 account_info2.account_id = "account_id_2";
519 account_info2.email = "account_id_2@gmail.com";
520 account_info2.last_message_type = AccountInfo::MSG_REMOVE;
521 account_info2.last_message_id = "message_2";
522 account_info2.last_message_timestamp =
523 base::Time::FromInternalValue(1305734521259935LL);
524
525 gcm_store->AddAccountMapping(
526 account_info1,
527 base::Bind(&GCMStoreImplTest::UpdateCallback, base::Unretained(this)));
528 PumpLoop();
529 gcm_store->AddAccountMapping(
530 account_info2,
531 base::Bind(&GCMStoreImplTest::UpdateCallback, base::Unretained(this)));
532 PumpLoop();
533
534 gcm_store = BuildGCMStore().Pass();
535 gcm_store->Load(base::Bind(
536 &GCMStoreImplTest::LoadCallback, base::Unretained(this), &load_result));
537 PumpLoop();
538
539 EXPECT_EQ(2UL, load_result->account_infos.size());
540 GCMStore::AccountInfoMap::iterator iter = load_result->account_infos.begin();
541 EXPECT_EQ("account_id_1", iter->first);
542 EXPECT_EQ(account_info1.account_id, iter->second.account_id);
543 EXPECT_EQ(account_info1.email, iter->second.email);
544 EXPECT_EQ(account_info1.last_message_type, iter->second.last_message_type);
545 EXPECT_EQ(account_info1.last_message_id, iter->second.last_message_id);
546 EXPECT_EQ(account_info1.last_message_timestamp,
547 iter->second.last_message_timestamp);
548 ++iter;
549 EXPECT_EQ("account_id_2", iter->first);
550 EXPECT_EQ(account_info2.account_id, iter->second.account_id);
551 EXPECT_EQ(account_info2.email, iter->second.email);
552 EXPECT_EQ(account_info2.last_message_type, iter->second.last_message_type);
553 EXPECT_EQ(account_info2.last_message_id, iter->second.last_message_id);
554 EXPECT_EQ(account_info2.last_message_timestamp,
555 iter->second.last_message_timestamp);
556
557 gcm_store->RemoveAccountMapping(
558 account_info1.account_id,
559 base::Bind(&GCMStoreImplTest::UpdateCallback, base::Unretained(this)));
560 PumpLoop();
561
562 gcm_store = BuildGCMStore().Pass();
563 gcm_store->Load(base::Bind(
564 &GCMStoreImplTest::LoadCallback, base::Unretained(this), &load_result));
565 PumpLoop();
566
567 EXPECT_EQ(1UL, load_result->account_infos.size());
568 iter = load_result->account_infos.begin();
569 EXPECT_EQ("account_id_2", iter->first);
570 EXPECT_EQ(account_info2.account_id, iter->second.account_id);
571 EXPECT_EQ(account_info2.email, iter->second.email);
572 EXPECT_EQ(account_info2.last_message_type, iter->second.last_message_type);
573 EXPECT_EQ(account_info2.last_message_id, iter->second.last_message_id);
574 EXPECT_EQ(account_info2.last_message_timestamp,
575 iter->second.last_message_timestamp);
576 }
577
509 // When the database is destroyed, all database updates should fail. At the 578 // When the database is destroyed, all database updates should fail. At the
510 // same time, they per-app message counts should not go up, as failures should 579 // same time, they per-app message counts should not go up, as failures should
511 // result in decrementing the counts. 580 // result in decrementing the counts.
512 TEST_F(GCMStoreImplTest, AddMessageAfterDestroy) { 581 TEST_F(GCMStoreImplTest, AddMessageAfterDestroy) {
513 scoped_ptr<GCMStore> gcm_store(BuildGCMStore()); 582 scoped_ptr<GCMStore> gcm_store(BuildGCMStore());
514 scoped_ptr<GCMStore::LoadResult> load_result; 583 scoped_ptr<GCMStore::LoadResult> load_result;
515 gcm_store->Load(base::Bind(&GCMStoreImplTest::LoadCallback, 584 gcm_store->Load(base::Bind(&GCMStoreImplTest::LoadCallback,
516 base::Unretained(this), 585 base::Unretained(this),
517 &load_result)); 586 &load_result));
518 PumpLoop(); 587 PumpLoop();
(...skipping 29 matching lines...) Expand all
548 617
549 gcm_store->Load(base::Bind(&GCMStoreImplTest::LoadCallback, 618 gcm_store->Load(base::Bind(&GCMStoreImplTest::LoadCallback,
550 base::Unretained(this), 619 base::Unretained(this),
551 &load_result)); 620 &load_result));
552 PumpLoop(); 621 PumpLoop();
553 } 622 }
554 623
555 } // namespace 624 } // namespace
556 625
557 } // namespace gcm 626 } // namespace gcm
OLDNEW
« no previous file with comments | « google_apis/gcm/engine/gcm_store_impl.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698