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

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

Issue 202083005: Add activity recording capability to gcm internals page. User can refresh, start/stop recording, an… (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Resolving another merge conflict. Created 6 years, 8 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
OLDNEW
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 "google_apis/gcm/engine/mcs_client.h" 5 #include "google_apis/gcm/engine/mcs_client.h"
6 6
7 #include "base/files/scoped_temp_dir.h" 7 #include "base/files/scoped_temp_dir.h"
8 #include "base/message_loop/message_loop.h" 8 #include "base/message_loop/message_loop.h"
9 #include "base/run_loop.h" 9 #include "base/run_loop.h"
10 #include "base/strings/string_number_conversions.h" 10 #include "base/strings/string_number_conversions.h"
11 #include "base/test/simple_test_clock.h" 11 #include "base/test/simple_test_clock.h"
12 #include "components/os_crypt/os_crypt.h" 12 #include "components/os_crypt/os_crypt.h"
13 #include "google_apis/gcm/base/mcs_util.h" 13 #include "google_apis/gcm/base/mcs_util.h"
14 #include "google_apis/gcm/engine/fake_connection_factory.h" 14 #include "google_apis/gcm/engine/fake_connection_factory.h"
15 #include "google_apis/gcm/engine/fake_connection_handler.h" 15 #include "google_apis/gcm/engine/fake_connection_handler.h"
16 #include "google_apis/gcm/engine/gcm_store_impl.h" 16 #include "google_apis/gcm/engine/gcm_store_impl.h"
17 #include "google_apis/gcm/gcm_stats_recorder.h"
17 #include "testing/gtest/include/gtest/gtest.h" 18 #include "testing/gtest/include/gtest/gtest.h"
18 19
19 namespace gcm { 20 namespace gcm {
20 21
21 namespace { 22 namespace {
22 23
23 const uint64 kAndroidId = 54321; 24 const uint64 kAndroidId = 54321;
24 const uint64 kSecurityToken = 12345; 25 const uint64 kSecurityToken = 12345;
25 26
26 // Number of messages to send when testing batching. 27 // Number of messages to send when testing batching.
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
59 data_message.set_token(token); 60 data_message.set_token(token);
60 data_message.set_device_user_id(user_id); 61 data_message.set_device_user_id(user_id);
61 return MCSMessage(kDataMessageStanzaTag, data_message); 62 return MCSMessage(kDataMessageStanzaTag, data_message);
62 } 63 }
63 64
64 // MCSClient with overriden exposed persistent id logic. 65 // MCSClient with overriden exposed persistent id logic.
65 class TestMCSClient : public MCSClient { 66 class TestMCSClient : public MCSClient {
66 public: 67 public:
67 TestMCSClient(base::Clock* clock, 68 TestMCSClient(base::Clock* clock,
68 ConnectionFactory* connection_factory, 69 ConnectionFactory* connection_factory,
69 GCMStore* gcm_store) 70 GCMStore* gcm_store,
70 : MCSClient("", clock, connection_factory, gcm_store), 71 gcm::GCMStatsRecorder* recorder)
72 : MCSClient("", clock, connection_factory, gcm_store, recorder),
71 next_id_(0) { 73 next_id_(0) {
72 } 74 }
73 75
74 virtual std::string GetNextPersistentId() OVERRIDE { 76 virtual std::string GetNextPersistentId() OVERRIDE {
75 return base::UintToString(++next_id_); 77 return base::UintToString(++next_id_);
76 } 78 }
77 79
78 private: 80 private:
79 uint32 next_id_; 81 uint32 next_id_;
80 }; 82 };
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
126 scoped_ptr<GCMStore> gcm_store_; 128 scoped_ptr<GCMStore> gcm_store_;
127 129
128 FakeConnectionFactory connection_factory_; 130 FakeConnectionFactory connection_factory_;
129 scoped_ptr<TestMCSClient> mcs_client_; 131 scoped_ptr<TestMCSClient> mcs_client_;
130 bool init_success_; 132 bool init_success_;
131 uint64 restored_android_id_; 133 uint64 restored_android_id_;
132 uint64 restored_security_token_; 134 uint64 restored_security_token_;
133 scoped_ptr<MCSMessage> received_message_; 135 scoped_ptr<MCSMessage> received_message_;
134 std::string sent_message_id_; 136 std::string sent_message_id_;
135 MCSClient::MessageSendStatus message_send_status_; 137 MCSClient::MessageSendStatus message_send_status_;
138
139 gcm::GCMStatsRecorder recorder_;
136 }; 140 };
137 141
138 MCSClientTest::MCSClientTest() 142 MCSClientTest::MCSClientTest()
139 : run_loop_(new base::RunLoop()), 143 : run_loop_(new base::RunLoop()),
140 init_success_(true), 144 init_success_(true),
141 restored_android_id_(0), 145 restored_android_id_(0),
142 restored_security_token_(0), 146 restored_security_token_(0),
143 message_send_status_(MCSClient::SENT) { 147 message_send_status_(MCSClient::SENT) {
144 EXPECT_TRUE(temp_directory_.CreateUniqueTempDir()); 148 EXPECT_TRUE(temp_directory_.CreateUniqueTempDir());
145 run_loop_.reset(new base::RunLoop()); 149 run_loop_.reset(new base::RunLoop());
146 150
147 // On OSX, prevent the Keychain permissions popup during unit tests. 151 // On OSX, prevent the Keychain permissions popup during unit tests.
148 #if defined(OS_MACOSX) 152 #if defined(OS_MACOSX)
149 OSCrypt::UseMockKeychain(true); 153 OSCrypt::UseMockKeychain(true);
150 #endif 154 #endif
151 155
152 // Advance the clock to a non-zero time. 156 // Advance the clock to a non-zero time.
153 clock_.Advance(base::TimeDelta::FromSeconds(1)); 157 clock_.Advance(base::TimeDelta::FromSeconds(1));
154 } 158 }
155 159
156 MCSClientTest::~MCSClientTest() {} 160 MCSClientTest::~MCSClientTest() {}
157 161
158 void MCSClientTest::BuildMCSClient() { 162 void MCSClientTest::BuildMCSClient() {
159 gcm_store_.reset(new GCMStoreImpl(true, 163 gcm_store_.reset(new GCMStoreImpl(true,
160 temp_directory_.path(), 164 temp_directory_.path(),
161 message_loop_.message_loop_proxy())); 165 message_loop_.message_loop_proxy()));
162 mcs_client_.reset(new TestMCSClient(&clock_, 166 mcs_client_.reset(new TestMCSClient(&clock_,
163 &connection_factory_, 167 &connection_factory_,
164 gcm_store_.get())); 168 gcm_store_.get(),
169 &recorder_));
165 } 170 }
166 171
167 void MCSClientTest::InitializeClient() { 172 void MCSClientTest::InitializeClient() {
168 gcm_store_->Load(base::Bind( 173 gcm_store_->Load(base::Bind(
169 &MCSClient::Initialize, 174 &MCSClient::Initialize,
170 base::Unretained(mcs_client_.get()), 175 base::Unretained(mcs_client_.get()),
171 base::Bind(&MCSClientTest::ErrorCallback, 176 base::Bind(&MCSClientTest::ErrorCallback,
172 base::Unretained(this)), 177 base::Unretained(this)),
173 base::Bind(&MCSClientTest::MessageReceivedCallback, 178 base::Bind(&MCSClientTest::MessageReceivedCallback,
174 base::Unretained(this)), 179 base::Unretained(this)),
(...skipping 607 matching lines...) Expand 10 before | Expand all | Expand 10 after
782 787
783 LoginClient(std::vector<std::string>()); 788 LoginClient(std::vector<std::string>());
784 GetFakeHandler()->ExpectOutgoingMessage(message); 789 GetFakeHandler()->ExpectOutgoingMessage(message);
785 GetFakeHandler()->ExpectOutgoingMessage(message2); 790 GetFakeHandler()->ExpectOutgoingMessage(message2);
786 PumpLoop(); 791 PumpLoop();
787 } 792 }
788 793
789 } // namespace 794 } // namespace
790 795
791 } // namespace gcm 796 } // namespace gcm
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698