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

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

Issue 1548673002: Switch to standard integer types in google_apis/. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix Created 4 years, 12 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/mcs_client.cc ('k') | google_apis/gcm/engine/registration_request.h » ('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 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 <stddef.h>
8 #include <stdint.h>
9
7 #include "base/bind.h" 10 #include "base/bind.h"
8 #include "base/bind_helpers.h" 11 #include "base/bind_helpers.h"
9 #include "base/command_line.h" 12 #include "base/command_line.h"
10 #include "base/files/scoped_temp_dir.h" 13 #include "base/files/scoped_temp_dir.h"
11 #include "base/memory/scoped_ptr.h" 14 #include "base/memory/scoped_ptr.h"
12 #include "base/message_loop/message_loop.h" 15 #include "base/message_loop/message_loop.h"
13 #include "base/run_loop.h" 16 #include "base/run_loop.h"
14 #include "base/strings/string_number_conversions.h" 17 #include "base/strings/string_number_conversions.h"
15 #include "base/test/simple_test_clock.h" 18 #include "base/test/simple_test_clock.h"
16 #include "base/timer/timer.h" 19 #include "base/timer/timer.h"
17 #include "google_apis/gcm/base/fake_encryptor.h" 20 #include "google_apis/gcm/base/fake_encryptor.h"
18 #include "google_apis/gcm/base/mcs_util.h" 21 #include "google_apis/gcm/base/mcs_util.h"
19 #include "google_apis/gcm/engine/fake_connection_factory.h" 22 #include "google_apis/gcm/engine/fake_connection_factory.h"
20 #include "google_apis/gcm/engine/fake_connection_handler.h" 23 #include "google_apis/gcm/engine/fake_connection_handler.h"
21 #include "google_apis/gcm/engine/gcm_store_impl.h" 24 #include "google_apis/gcm/engine/gcm_store_impl.h"
22 #include "google_apis/gcm/monitoring/fake_gcm_stats_recorder.h" 25 #include "google_apis/gcm/monitoring/fake_gcm_stats_recorder.h"
23 #include "testing/gtest/include/gtest/gtest.h" 26 #include "testing/gtest/include/gtest/gtest.h"
24 27
25 namespace gcm { 28 namespace gcm {
26 29
27 namespace { 30 namespace {
28 31
29 const uint64 kAndroidId = 54321; 32 const uint64_t kAndroidId = 54321;
30 const uint64 kSecurityToken = 12345; 33 const uint64_t kSecurityToken = 12345;
31 34
32 // Number of messages to send when testing batching. 35 // Number of messages to send when testing batching.
33 // Note: must be even for tests that split batches in half. 36 // Note: must be even for tests that split batches in half.
34 const int kMessageBatchSize = 6; 37 const int kMessageBatchSize = 6;
35 38
36 // The number of unacked messages the client will receive before sending a 39 // The number of unacked messages the client will receive before sending a
37 // stream ack. 40 // stream ack.
38 // TODO(zea): get this (and other constants) directly from the mcs client. 41 // TODO(zea): get this (and other constants) directly from the mcs client.
39 const int kAckLimitSize = 10; 42 const int kAckLimitSize = 10;
40 43
41 // TTL value for reliable messages. 44 // TTL value for reliable messages.
42 const int kTTLValue = 5 * 60; // 5 minutes. 45 const int kTTLValue = 5 * 60; // 5 minutes.
43 46
44 // Specifies whether immediate ACK should be requested. 47 // Specifies whether immediate ACK should be requested.
45 enum RequestImmediateAck { 48 enum RequestImmediateAck {
46 IMMEDIATE_ACK_IGNORE, // Ignores the field and does not set it. 49 IMMEDIATE_ACK_IGNORE, // Ignores the field and does not set it.
47 IMMEDIATE_ACK_NO, // Sets the field to false. 50 IMMEDIATE_ACK_NO, // Sets the field to false.
48 IMMEDIATE_ACK_YES // Sets the field to true. 51 IMMEDIATE_ACK_YES // Sets the field to true.
49 }; 52 };
50 53
51 // Helper for building arbitrary data messages. 54 // Helper for building arbitrary data messages.
52 MCSMessage BuildDataMessage(const std::string& from, 55 MCSMessage BuildDataMessage(const std::string& from,
53 const std::string& category, 56 const std::string& category,
54 const std::string& message_id, 57 const std::string& message_id,
55 int last_stream_id_received, 58 int last_stream_id_received,
56 const std::string& persistent_id, 59 const std::string& persistent_id,
57 int ttl, 60 int ttl,
58 uint64 sent, 61 uint64_t sent,
59 int queued, 62 int queued,
60 const std::string& token, 63 const std::string& token,
61 const uint64& user_id, 64 const uint64_t& user_id,
62 RequestImmediateAck immediate_ack) { 65 RequestImmediateAck immediate_ack) {
63 mcs_proto::DataMessageStanza data_message; 66 mcs_proto::DataMessageStanza data_message;
64 data_message.set_id(message_id); 67 data_message.set_id(message_id);
65 data_message.set_from(from); 68 data_message.set_from(from);
66 data_message.set_category(category); 69 data_message.set_category(category);
67 data_message.set_last_stream_id_received(last_stream_id_received); 70 data_message.set_last_stream_id_received(last_stream_id_received);
68 if (!persistent_id.empty()) 71 if (!persistent_id.empty())
69 data_message.set_persistent_id(persistent_id); 72 data_message.set_persistent_id(persistent_id);
70 data_message.set_ttl(ttl); 73 data_message.set_ttl(ttl);
71 data_message.set_sent(sent); 74 data_message.set_sent(sent);
(...skipping 15 matching lines...) Expand all
87 gcm::GCMStatsRecorder* recorder) 90 gcm::GCMStatsRecorder* recorder)
88 : MCSClient("", clock, connection_factory, gcm_store, recorder), 91 : MCSClient("", clock, connection_factory, gcm_store, recorder),
89 next_id_(0) { 92 next_id_(0) {
90 } 93 }
91 94
92 std::string GetNextPersistentId() override { 95 std::string GetNextPersistentId() override {
93 return base::UintToString(++next_id_); 96 return base::UintToString(++next_id_);
94 } 97 }
95 98
96 private: 99 private:
97 uint32 next_id_; 100 uint32_t next_id_;
98 }; 101 };
99 102
100 class TestConnectionListener : public ConnectionFactory::ConnectionListener { 103 class TestConnectionListener : public ConnectionFactory::ConnectionListener {
101 public: 104 public:
102 TestConnectionListener() : disconnect_counter_(0) { } 105 TestConnectionListener() : disconnect_counter_(0) { }
103 ~TestConnectionListener() override { } 106 ~TestConnectionListener() override { }
104 107
105 void OnConnected(const GURL& current_server, 108 void OnConnected(const GURL& current_server,
106 const net::IPEndPoint& ip_endpoint) override { } 109 const net::IPEndPoint& ip_endpoint) override { }
107 void OnDisconnected() override { 110 void OnDisconnected() override {
(...skipping 21 matching lines...) Expand all
129 int heartbeat_interval_ms); 132 int heartbeat_interval_ms);
130 void AddExpectedLoginRequest(const std::vector<std::string>& acknowledged_ids, 133 void AddExpectedLoginRequest(const std::vector<std::string>& acknowledged_ids,
131 int heartbeat_interval_ms); 134 int heartbeat_interval_ms);
132 135
133 base::SimpleTestClock* clock() { return &clock_; } 136 base::SimpleTestClock* clock() { return &clock_; }
134 TestMCSClient* mcs_client() const { return mcs_client_.get(); } 137 TestMCSClient* mcs_client() const { return mcs_client_.get(); }
135 FakeConnectionFactory* connection_factory() { 138 FakeConnectionFactory* connection_factory() {
136 return &connection_factory_; 139 return &connection_factory_;
137 } 140 }
138 bool init_success() const { return init_success_; } 141 bool init_success() const { return init_success_; }
139 uint64 restored_android_id() const { return restored_android_id_; } 142 uint64_t restored_android_id() const { return restored_android_id_; }
140 uint64 restored_security_token() const { return restored_security_token_; } 143 uint64_t restored_security_token() const { return restored_security_token_; }
141 MCSMessage* received_message() const { return received_message_.get(); } 144 MCSMessage* received_message() const { return received_message_.get(); }
142 std::string sent_message_id() const { return sent_message_id_;} 145 std::string sent_message_id() const { return sent_message_id_;}
143 MCSClient::MessageSendStatus message_send_status() const { 146 MCSClient::MessageSendStatus message_send_status() const {
144 return message_send_status_; 147 return message_send_status_;
145 } 148 }
146 149
147 void SetDeviceCredentialsCallback(bool success); 150 void SetDeviceCredentialsCallback(bool success);
148 151
149 FakeConnectionHandler* GetFakeHandler() const; 152 FakeConnectionHandler* GetFakeHandler() const;
150 153
151 void WaitForMCSEvent(); 154 void WaitForMCSEvent();
152 void PumpLoop(); 155 void PumpLoop();
153 156
154 private: 157 private:
155 void ErrorCallback(); 158 void ErrorCallback();
156 void MessageReceivedCallback(const MCSMessage& message); 159 void MessageReceivedCallback(const MCSMessage& message);
157 void MessageSentCallback(int64 user_serial_number, 160 void MessageSentCallback(int64_t user_serial_number,
158 const std::string& app_id, 161 const std::string& app_id,
159 const std::string& message_id, 162 const std::string& message_id,
160 MCSClient::MessageSendStatus status); 163 MCSClient::MessageSendStatus status);
161 164
162 base::SimpleTestClock clock_; 165 base::SimpleTestClock clock_;
163 166
164 base::ScopedTempDir temp_directory_; 167 base::ScopedTempDir temp_directory_;
165 base::MessageLoop message_loop_; 168 base::MessageLoop message_loop_;
166 scoped_ptr<base::RunLoop> run_loop_; 169 scoped_ptr<base::RunLoop> run_loop_;
167 scoped_ptr<GCMStore> gcm_store_; 170 scoped_ptr<GCMStore> gcm_store_;
168 171
169 FakeConnectionFactory connection_factory_; 172 FakeConnectionFactory connection_factory_;
170 scoped_ptr<TestMCSClient> mcs_client_; 173 scoped_ptr<TestMCSClient> mcs_client_;
171 bool init_success_; 174 bool init_success_;
172 uint64 restored_android_id_; 175 uint64_t restored_android_id_;
173 uint64 restored_security_token_; 176 uint64_t restored_security_token_;
174 scoped_ptr<MCSMessage> received_message_; 177 scoped_ptr<MCSMessage> received_message_;
175 std::string sent_message_id_; 178 std::string sent_message_id_;
176 MCSClient::MessageSendStatus message_send_status_; 179 MCSClient::MessageSendStatus message_send_status_;
177 180
178 gcm::FakeGCMStatsRecorder recorder_; 181 gcm::FakeGCMStatsRecorder recorder_;
179 }; 182 };
180 183
181 MCSClientTest::MCSClientTest() 184 MCSClientTest::MCSClientTest()
182 : run_loop_(new base::RunLoop()), 185 : run_loop_(new base::RunLoop()),
183 init_success_(true), 186 init_success_(true),
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
280 DVLOG(1) << "Error callback invoked, killing loop."; 283 DVLOG(1) << "Error callback invoked, killing loop.";
281 run_loop_->Quit(); 284 run_loop_->Quit();
282 } 285 }
283 286
284 void MCSClientTest::MessageReceivedCallback(const MCSMessage& message) { 287 void MCSClientTest::MessageReceivedCallback(const MCSMessage& message) {
285 received_message_.reset(new MCSMessage(message)); 288 received_message_.reset(new MCSMessage(message));
286 DVLOG(1) << "Message received callback invoked, killing loop."; 289 DVLOG(1) << "Message received callback invoked, killing loop.";
287 run_loop_->Quit(); 290 run_loop_->Quit();
288 } 291 }
289 292
290 void MCSClientTest::MessageSentCallback(int64 user_serial_number, 293 void MCSClientTest::MessageSentCallback(int64_t user_serial_number,
291 const std::string& app_id, 294 const std::string& app_id,
292 const std::string& message_id, 295 const std::string& message_id,
293 MCSClient::MessageSendStatus status) { 296 MCSClient::MessageSendStatus status) {
294 DVLOG(1) << "Message sent callback invoked, killing loop."; 297 DVLOG(1) << "Message sent callback invoked, killing loop.";
295 sent_message_id_ = message_id; 298 sent_message_id_ = message_id;
296 message_send_status_ = status; 299 message_send_status_ = status;
297 run_loop_->Quit(); 300 run_loop_->Quit();
298 } 301 }
299 302
300 void MCSClientTest::SetDeviceCredentialsCallback(bool success) { 303 void MCSClientTest::SetDeviceCredentialsCallback(bool success) {
(...skipping 872 matching lines...) Expand 10 before | Expand all | Expand 10 after
1173 GetFakeHandler()->ReceiveMessage(message); 1176 GetFakeHandler()->ReceiveMessage(message);
1174 WaitForMCSEvent(); 1177 WaitForMCSEvent();
1175 PumpLoop(); 1178 PumpLoop();
1176 1179
1177 EXPECT_TRUE(GetFakeHandler()->AllOutgoingMessagesReceived()); 1180 EXPECT_TRUE(GetFakeHandler()->AllOutgoingMessagesReceived());
1178 } 1181 }
1179 1182
1180 } // namespace 1183 } // namespace
1181 1184
1182 } // namespace gcm 1185 } // namespace gcm
OLDNEW
« no previous file with comments | « google_apis/gcm/engine/mcs_client.cc ('k') | google_apis/gcm/engine/registration_request.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698