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

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

Issue 1126233004: Persist Instance ID data to GCM store. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix mac Created 5 years, 7 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
« no previous file with comments | « google_apis/gcm/engine/gcm_store_impl.cc ('k') | tools/metrics/histograms/histograms.xml » ('j') | 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 15 matching lines...) Expand all
26 namespace { 26 namespace {
27 27
28 // Number of persistent ids to use in tests. 28 // Number of persistent ids to use in tests.
29 const int kNumPersistentIds = 10; 29 const int kNumPersistentIds = 10;
30 30
31 // Number of per-app messages in tests. 31 // Number of per-app messages in tests.
32 const int kNumMessagesPerApp = 20; 32 const int kNumMessagesPerApp = 20;
33 33
34 // App name for testing. 34 // App name for testing.
35 const char kAppName[] = "my_app"; 35 const char kAppName[] = "my_app";
36 const char kAppName2[] = "my_app_2";
36 37
37 // Category name for testing. 38 // Category name for testing.
38 const char kCategoryName[] = "my_category"; 39 const char kCategoryName[] = "my_category";
39 40
40 const uint64 kDeviceId = 22; 41 const uint64 kDeviceId = 22;
41 const uint64 kDeviceToken = 55; 42 const uint64 kDeviceToken = 55;
42 43
43 class GCMStoreImplTest : public testing::Test { 44 class GCMStoreImplTest : public testing::Test {
44 public: 45 public:
45 GCMStoreImplTest(); 46 GCMStoreImplTest();
(...skipping 688 matching lines...) Expand 10 before | Expand all | Expand 10 after
734 base::Bind(&GCMStoreImplTest::UpdateCallback, base::Unretained(this))); 735 base::Bind(&GCMStoreImplTest::UpdateCallback, base::Unretained(this)));
735 PumpLoop(); 736 PumpLoop();
736 737
737 gcm_store = BuildGCMStore().Pass(); 738 gcm_store = BuildGCMStore().Pass();
738 gcm_store->Load(base::Bind( 739 gcm_store->Load(base::Bind(
739 &GCMStoreImplTest::LoadCallback, base::Unretained(this), &load_result)); 740 &GCMStoreImplTest::LoadCallback, base::Unretained(this), &load_result));
740 PumpLoop(); 741 PumpLoop();
741 EXPECT_EQ(base::Time(), load_result->last_token_fetch_time); 742 EXPECT_EQ(base::Time(), load_result->last_token_fetch_time);
742 } 743 }
743 744
745 TEST_F(GCMStoreImplTest, InstanceIDData) {
746 scoped_ptr<GCMStore> gcm_store(BuildGCMStore());
747 scoped_ptr<GCMStore::LoadResult> load_result;
748 gcm_store->Load(base::Bind(
749 &GCMStoreImplTest::LoadCallback, base::Unretained(this), &load_result));
750 PumpLoop();
751
752 std::string instance_id_data("Foo");
753 gcm_store->AddInstanceIDData(
754 kAppName,
755 instance_id_data,
756 base::Bind(&GCMStoreImplTest::UpdateCallback, base::Unretained(this)));
757 PumpLoop();
758
759 std::string instance_id_data2("Hello Instance ID");
760 gcm_store->AddInstanceIDData(
761 kAppName2,
762 instance_id_data2,
763 base::Bind(&GCMStoreImplTest::UpdateCallback, base::Unretained(this)));
764 PumpLoop();
765
766 gcm_store = BuildGCMStore().Pass();
767 gcm_store->Load(base::Bind(
768 &GCMStoreImplTest::LoadCallback, base::Unretained(this), &load_result));
769 PumpLoop();
770
771 ASSERT_EQ(2u, load_result->instance_id_data.size());
772 ASSERT_TRUE(load_result->instance_id_data.find(kAppName) !=
773 load_result->instance_id_data.end());
774 ASSERT_TRUE(load_result->instance_id_data.find(kAppName2) !=
775 load_result->instance_id_data.end());
776 EXPECT_EQ(instance_id_data, load_result->instance_id_data[kAppName]);
777 EXPECT_EQ(instance_id_data2, load_result->instance_id_data[kAppName2]);
778
779 gcm_store->RemoveInstanceIDData(
780 kAppName,
781 base::Bind(&GCMStoreImplTest::UpdateCallback, base::Unretained(this)));
782 PumpLoop();
783
784 gcm_store = BuildGCMStore().Pass();
785 gcm_store->Load(base::Bind(
786 &GCMStoreImplTest::LoadCallback, base::Unretained(this), &load_result));
787 PumpLoop();
788
789 ASSERT_EQ(1u, load_result->instance_id_data.size());
790 ASSERT_TRUE(load_result->instance_id_data.find(kAppName2) !=
791 load_result->instance_id_data.end());
792 EXPECT_EQ(instance_id_data2, load_result->instance_id_data[kAppName2]);
793 }
794
744 } // namespace 795 } // namespace
745 796
746 } // namespace gcm 797 } // namespace gcm
OLDNEW
« no previous file with comments | « google_apis/gcm/engine/gcm_store_impl.cc ('k') | tools/metrics/histograms/histograms.xml » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698