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/gcm_client_impl.h" | 5 #include "google_apis/gcm/gcm_client_impl.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/test/simple_test_clock.h" | 10 #include "base/test/simple_test_clock.h" |
(...skipping 19 matching lines...) Expand all Loading... |
30 LOADING_COMPLETED, | 30 LOADING_COMPLETED, |
31 REGISTRATION_COMPLETED, | 31 REGISTRATION_COMPLETED, |
32 UNREGISTRATION_COMPLETED, | 32 UNREGISTRATION_COMPLETED, |
33 MESSAGE_SEND_ERROR, | 33 MESSAGE_SEND_ERROR, |
34 MESSAGE_RECEIVED, | 34 MESSAGE_RECEIVED, |
35 MESSAGES_DELETED, | 35 MESSAGES_DELETED, |
36 }; | 36 }; |
37 | 37 |
38 const uint64 kDeviceAndroidId = 54321; | 38 const uint64 kDeviceAndroidId = 54321; |
39 const uint64 kDeviceSecurityToken = 12345; | 39 const uint64 kDeviceSecurityToken = 12345; |
| 40 const char kAppId[] = "app_id"; |
| 41 const char kSender[] = "project_id"; |
| 42 const char kSender2[] = "project_id2"; |
| 43 const char kSender3[] = "project_id3"; |
40 const char kRegistrationResponsePrefix[] = "token="; | 44 const char kRegistrationResponsePrefix[] = "token="; |
41 const char kUnregistrationResponsePrefix[] = "deleted="; | 45 const char kUnregistrationResponsePrefix[] = "deleted="; |
42 | 46 |
43 // Helper for building arbitrary data messages. | 47 // Helper for building arbitrary data messages. |
44 MCSMessage BuildDownstreamMessage( | 48 MCSMessage BuildDownstreamMessage( |
45 const std::string& project_id, | 49 const std::string& project_id, |
46 const std::string& app_id, | 50 const std::string& app_id, |
47 const std::map<std::string, std::string>& data) { | 51 const std::map<std::string, std::string>& data) { |
48 mcs_proto::DataMessageStanza data_message; | 52 mcs_proto::DataMessageStanza data_message; |
49 data_message.set_from(project_id); | 53 data_message.set_from(project_id); |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
120 | 124 |
121 virtual void SetUp() OVERRIDE; | 125 virtual void SetUp() OVERRIDE; |
122 | 126 |
123 void BuildGCMClient(); | 127 void BuildGCMClient(); |
124 void InitializeGCMClient(); | 128 void InitializeGCMClient(); |
125 void ReceiveMessageFromMCS(const MCSMessage& message); | 129 void ReceiveMessageFromMCS(const MCSMessage& message); |
126 void CompleteCheckin(uint64 android_id, uint64 security_token); | 130 void CompleteCheckin(uint64 android_id, uint64 security_token); |
127 void CompleteRegistration(const std::string& registration_id); | 131 void CompleteRegistration(const std::string& registration_id); |
128 void CompleteUnregistration(const std::string& app_id); | 132 void CompleteUnregistration(const std::string& app_id); |
129 | 133 |
| 134 bool ExistsRegistration(const std::string& app_id) const; |
| 135 void AddRegistration(const std::string& app_id, |
| 136 const std::vector<std::string>& sender_ids, |
| 137 const std::string& registration_id); |
| 138 |
130 // GCMClient::Delegate overrides (for verification). | 139 // GCMClient::Delegate overrides (for verification). |
131 virtual void OnRegisterFinished(const std::string& app_id, | 140 virtual void OnRegisterFinished(const std::string& app_id, |
132 const std::string& registration_id, | 141 const std::string& registration_id, |
133 GCMClient::Result result) OVERRIDE; | 142 GCMClient::Result result) OVERRIDE; |
134 virtual void OnUnregisterFinished(const std::string& app_id, | 143 virtual void OnUnregisterFinished(const std::string& app_id, |
135 GCMClient::Result result) OVERRIDE; | 144 GCMClient::Result result) OVERRIDE; |
136 virtual void OnSendFinished(const std::string& app_id, | 145 virtual void OnSendFinished(const std::string& app_id, |
137 const std::string& message_id, | 146 const std::string& message_id, |
138 GCMClient::Result result) OVERRIDE {} | 147 GCMClient::Result result) OVERRIDE {} |
139 virtual void OnMessageReceived(const std::string& registration_id, | 148 virtual void OnMessageReceived(const std::string& registration_id, |
140 const GCMClient::IncomingMessage& message) | 149 const GCMClient::IncomingMessage& message) |
141 OVERRIDE; | 150 OVERRIDE; |
142 virtual void OnMessagesDeleted(const std::string& app_id) OVERRIDE; | 151 virtual void OnMessagesDeleted(const std::string& app_id) OVERRIDE; |
143 virtual void OnMessageSendError( | 152 virtual void OnMessageSendError( |
144 const std::string& app_id, | 153 const std::string& app_id, |
145 const gcm::GCMClient::SendErrorDetails& send_error_details) OVERRIDE; | 154 const gcm::GCMClient::SendErrorDetails& send_error_details) OVERRIDE; |
146 virtual void OnGCMReady() OVERRIDE; | 155 virtual void OnGCMReady() OVERRIDE; |
147 | 156 |
148 GCMClientImpl* gcm_client() const { return gcm_client_.get(); } | 157 GCMClientImpl* gcm_client() const { return gcm_client_.get(); } |
149 FakeMCSClient* mcs_client() const { | 158 FakeMCSClient* mcs_client() const { |
150 return reinterpret_cast<FakeMCSClient*>(gcm_client_->mcs_client_.get()); | 159 return reinterpret_cast<FakeMCSClient*>(gcm_client_->mcs_client_.get()); |
151 } | 160 } |
152 | 161 |
| 162 void reset_last_event() { |
| 163 last_event_ = NONE; |
| 164 last_app_id_.clear(); |
| 165 last_registration_id_.clear(); |
| 166 last_message_id_.clear(); |
| 167 last_result_ = GCMClient::UNKNOWN_ERROR; |
| 168 } |
| 169 |
153 LastEvent last_event() const { return last_event_; } | 170 LastEvent last_event() const { return last_event_; } |
154 const std::string& last_app_id() const { return last_app_id_; } | 171 const std::string& last_app_id() const { return last_app_id_; } |
155 const std::string& last_registration_id() const { | 172 const std::string& last_registration_id() const { |
156 return last_registration_id_; | 173 return last_registration_id_; |
157 } | 174 } |
158 const std::string& last_message_id() const { return last_message_id_; } | 175 const std::string& last_message_id() const { return last_message_id_; } |
159 GCMClient::Result last_result() const { return last_result_; } | 176 GCMClient::Result last_result() const { return last_result_; } |
160 const GCMClient::IncomingMessage& last_message() const { | 177 const GCMClient::IncomingMessage& last_message() const { |
161 return last_message_; | 178 return last_message_; |
162 } | 179 } |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
204 message_loop_.message_loop_proxy())) { | 221 message_loop_.message_loop_proxy())) { |
205 } | 222 } |
206 | 223 |
207 GCMClientImplTest::~GCMClientImplTest() {} | 224 GCMClientImplTest::~GCMClientImplTest() {} |
208 | 225 |
209 void GCMClientImplTest::SetUp() { | 226 void GCMClientImplTest::SetUp() { |
210 ASSERT_TRUE(temp_directory_.CreateUniqueTempDir()); | 227 ASSERT_TRUE(temp_directory_.CreateUniqueTempDir()); |
211 run_loop_.reset(new base::RunLoop); | 228 run_loop_.reset(new base::RunLoop); |
212 BuildGCMClient(); | 229 BuildGCMClient(); |
213 InitializeGCMClient(); | 230 InitializeGCMClient(); |
| 231 CompleteCheckin(kDeviceAndroidId, kDeviceSecurityToken); |
214 } | 232 } |
215 | 233 |
216 void GCMClientImplTest::PumpLoop() { | 234 void GCMClientImplTest::PumpLoop() { |
217 run_loop_->Run(); | 235 run_loop_->Run(); |
218 run_loop_.reset(new base::RunLoop()); | 236 run_loop_.reset(new base::RunLoop()); |
219 } | 237 } |
220 | 238 |
221 void GCMClientImplTest::PumpLoopUntilIdle() { | 239 void GCMClientImplTest::PumpLoopUntilIdle() { |
222 run_loop_->RunUntilIdle(); | 240 run_loop_->RunUntilIdle(); |
223 run_loop_.reset(new base::RunLoop()); | 241 run_loop_.reset(new base::RunLoop()); |
(...skipping 28 matching lines...) Expand all Loading... |
252 | 270 |
253 void GCMClientImplTest::CompleteRegistration( | 271 void GCMClientImplTest::CompleteRegistration( |
254 const std::string& registration_id) { | 272 const std::string& registration_id) { |
255 std::string response(kRegistrationResponsePrefix); | 273 std::string response(kRegistrationResponsePrefix); |
256 response.append(registration_id); | 274 response.append(registration_id); |
257 net::TestURLFetcher* fetcher = url_fetcher_factory_.GetFetcherByID(0); | 275 net::TestURLFetcher* fetcher = url_fetcher_factory_.GetFetcherByID(0); |
258 ASSERT_TRUE(fetcher); | 276 ASSERT_TRUE(fetcher); |
259 fetcher->set_response_code(net::HTTP_OK); | 277 fetcher->set_response_code(net::HTTP_OK); |
260 fetcher->SetResponseString(response); | 278 fetcher->SetResponseString(response); |
261 fetcher->delegate()->OnURLFetchComplete(fetcher); | 279 fetcher->delegate()->OnURLFetchComplete(fetcher); |
| 280 url_fetcher_factory_.RemoveFetcherFromMap(0); |
262 } | 281 } |
263 | 282 |
264 void GCMClientImplTest::CompleteUnregistration( | 283 void GCMClientImplTest::CompleteUnregistration( |
265 const std::string& app_id) { | 284 const std::string& app_id) { |
266 std::string response(kUnregistrationResponsePrefix); | 285 std::string response(kUnregistrationResponsePrefix); |
267 response.append(app_id); | 286 response.append(app_id); |
268 net::TestURLFetcher* fetcher = url_fetcher_factory_.GetFetcherByID(0); | 287 net::TestURLFetcher* fetcher = url_fetcher_factory_.GetFetcherByID(0); |
269 ASSERT_TRUE(fetcher); | 288 ASSERT_TRUE(fetcher); |
270 fetcher->set_response_code(net::HTTP_OK); | 289 fetcher->set_response_code(net::HTTP_OK); |
271 fetcher->SetResponseString(response); | 290 fetcher->SetResponseString(response); |
272 fetcher->delegate()->OnURLFetchComplete(fetcher); | 291 fetcher->delegate()->OnURLFetchComplete(fetcher); |
| 292 url_fetcher_factory_.RemoveFetcherFromMap(0); |
| 293 } |
| 294 |
| 295 bool GCMClientImplTest::ExistsRegistration(const std::string& app_id) const { |
| 296 return gcm_client_->registrations_.count(app_id) > 0; |
| 297 } |
| 298 |
| 299 void GCMClientImplTest::AddRegistration( |
| 300 const std::string& app_id, |
| 301 const std::vector<std::string>& sender_ids, |
| 302 const std::string& registration_id) { |
| 303 linked_ptr<RegistrationInfo> registration(new RegistrationInfo); |
| 304 registration->sender_ids = sender_ids; |
| 305 registration->registration_id = registration_id; |
| 306 gcm_client_->registrations_[app_id] = registration; |
273 } | 307 } |
274 | 308 |
275 void GCMClientImplTest::InitializeGCMClient() { | 309 void GCMClientImplTest::InitializeGCMClient() { |
276 // Creating and advancing the clock. | 310 // Creating and advancing the clock. |
277 gcm_client_->clock_.reset(new base::SimpleTestClock); | 311 gcm_client_->clock_.reset(new base::SimpleTestClock); |
278 clock()->Advance(base::TimeDelta::FromMilliseconds(1)); | 312 clock()->Advance(base::TimeDelta::FromMilliseconds(1)); |
279 // Creating and injecting the mcs_client. | 313 // Creating and injecting the mcs_client. |
280 connection_factory_.reset(new FakeConnectionFactory()); | 314 connection_factory_.reset(new FakeConnectionFactory()); |
281 gcm_client_->SetMCSClientForTesting(scoped_ptr<MCSClient>( | 315 gcm_client_->SetMCSClientForTesting(scoped_ptr<MCSClient>( |
282 new FakeMCSClient(clock(), connection_factory_.get())).Pass()); | 316 new FakeMCSClient(clock(), connection_factory_.get())).Pass()); |
(...skipping 10 matching lines...) Expand all Loading... |
293 // On OSX, prevent the Keychain permissions popup during unit tests. | 327 // On OSX, prevent the Keychain permissions popup during unit tests. |
294 OSCrypt::UseMockKeychain(true); // Must be after Initialize. | 328 OSCrypt::UseMockKeychain(true); // Must be after Initialize. |
295 #endif | 329 #endif |
296 | 330 |
297 // Starting loading and check-in. | 331 // Starting loading and check-in. |
298 gcm_client_->Load(); | 332 gcm_client_->Load(); |
299 | 333 |
300 // Ensuring that mcs_client is using the same gcm_store as gcm_client. | 334 // Ensuring that mcs_client is using the same gcm_store as gcm_client. |
301 mcs_client()->set_gcm_store(gcm_client_->gcm_store_.get()); | 335 mcs_client()->set_gcm_store(gcm_client_->gcm_store_.get()); |
302 PumpLoopUntilIdle(); | 336 PumpLoopUntilIdle(); |
303 CompleteCheckin(kDeviceAndroidId, kDeviceSecurityToken); | |
304 } | 337 } |
305 | 338 |
306 void GCMClientImplTest::ReceiveMessageFromMCS(const MCSMessage& message) { | 339 void GCMClientImplTest::ReceiveMessageFromMCS(const MCSMessage& message) { |
307 gcm_client_->OnMessageReceivedFromMCS(message); | 340 gcm_client_->OnMessageReceivedFromMCS(message); |
308 } | 341 } |
309 | 342 |
310 void GCMClientImplTest::OnGCMReady() { | 343 void GCMClientImplTest::OnGCMReady() { |
311 last_event_ = LOADING_COMPLETED; | 344 last_event_ = LOADING_COMPLETED; |
312 QuitLoop(); | 345 QuitLoop(); |
313 } | 346 } |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
360 EXPECT_EQ(kDeviceSecurityToken, mcs_client()->last_security_token()); | 393 EXPECT_EQ(kDeviceSecurityToken, mcs_client()->last_security_token()); |
361 } | 394 } |
362 | 395 |
363 TEST_F(GCMClientImplTest, CheckOut) { | 396 TEST_F(GCMClientImplTest, CheckOut) { |
364 EXPECT_TRUE(mcs_client()); | 397 EXPECT_TRUE(mcs_client()); |
365 gcm_client()->CheckOut(); | 398 gcm_client()->CheckOut(); |
366 EXPECT_FALSE(mcs_client()); | 399 EXPECT_FALSE(mcs_client()); |
367 } | 400 } |
368 | 401 |
369 TEST_F(GCMClientImplTest, RegisterApp) { | 402 TEST_F(GCMClientImplTest, RegisterApp) { |
| 403 EXPECT_FALSE(ExistsRegistration(kAppId)); |
| 404 |
370 std::vector<std::string> senders; | 405 std::vector<std::string> senders; |
371 senders.push_back("sender"); | 406 senders.push_back("sender"); |
372 gcm_client()->Register("app_id", senders); | 407 gcm_client()->Register(kAppId, senders); |
373 CompleteRegistration("reg_id"); | 408 CompleteRegistration("reg_id"); |
374 | 409 |
375 EXPECT_EQ(REGISTRATION_COMPLETED, last_event()); | 410 EXPECT_EQ(REGISTRATION_COMPLETED, last_event()); |
376 EXPECT_EQ("app_id", last_app_id()); | 411 EXPECT_EQ(kAppId, last_app_id()); |
377 EXPECT_EQ("reg_id", last_registration_id()); | 412 EXPECT_EQ("reg_id", last_registration_id()); |
378 EXPECT_EQ(GCMClient::SUCCESS, last_result()); | 413 EXPECT_EQ(GCMClient::SUCCESS, last_result()); |
| 414 EXPECT_TRUE(ExistsRegistration(kAppId)); |
| 415 } |
| 416 |
| 417 TEST_F(GCMClientImplTest, RegisterAppFromCache) { |
| 418 EXPECT_FALSE(ExistsRegistration(kAppId)); |
| 419 |
| 420 std::vector<std::string> senders; |
| 421 senders.push_back("sender"); |
| 422 gcm_client()->Register(kAppId, senders); |
| 423 CompleteRegistration("reg_id"); |
| 424 EXPECT_TRUE(ExistsRegistration(kAppId)); |
| 425 |
| 426 EXPECT_EQ(kAppId, last_app_id()); |
| 427 EXPECT_EQ("reg_id", last_registration_id()); |
| 428 EXPECT_EQ(GCMClient::SUCCESS, last_result()); |
| 429 EXPECT_EQ(REGISTRATION_COMPLETED, last_event()); |
| 430 |
| 431 // Recreate GCMClient in order to load from the persistent store. |
| 432 BuildGCMClient(); |
| 433 InitializeGCMClient(); |
| 434 |
| 435 EXPECT_TRUE(ExistsRegistration(kAppId)); |
379 } | 436 } |
380 | 437 |
381 TEST_F(GCMClientImplTest, UnregisterApp) { | 438 TEST_F(GCMClientImplTest, UnregisterApp) { |
382 gcm_client()->Unregister("app_id"); | 439 EXPECT_FALSE(ExistsRegistration(kAppId)); |
383 CompleteUnregistration("app_id"); | 440 |
| 441 std::vector<std::string> senders; |
| 442 senders.push_back("sender"); |
| 443 gcm_client()->Register(kAppId, senders); |
| 444 CompleteRegistration("reg_id"); |
| 445 EXPECT_TRUE(ExistsRegistration(kAppId)); |
| 446 |
| 447 gcm_client()->Unregister(kAppId); |
| 448 CompleteUnregistration(kAppId); |
384 | 449 |
385 EXPECT_EQ(UNREGISTRATION_COMPLETED, last_event()); | 450 EXPECT_EQ(UNREGISTRATION_COMPLETED, last_event()); |
386 EXPECT_EQ("app_id", last_app_id()); | 451 EXPECT_EQ(kAppId, last_app_id()); |
387 EXPECT_EQ(GCMClient::SUCCESS, last_result()); | 452 EXPECT_EQ(GCMClient::SUCCESS, last_result()); |
| 453 EXPECT_FALSE(ExistsRegistration(kAppId)); |
388 } | 454 } |
389 | 455 |
390 TEST_F(GCMClientImplTest, DispatchDownstreamMessage) { | 456 TEST_F(GCMClientImplTest, DispatchDownstreamMessage) { |
| 457 // Register to receive messages from kSender and kSender2 only. |
| 458 std::vector<std::string> senders; |
| 459 senders.push_back(kSender); |
| 460 senders.push_back(kSender2); |
| 461 AddRegistration(kAppId, senders, "reg_id"); |
| 462 |
391 std::map<std::string, std::string> expected_data; | 463 std::map<std::string, std::string> expected_data; |
392 expected_data["message_type"] = "gcm"; | 464 expected_data["message_type"] = "gcm"; |
393 expected_data["key"] = "value"; | 465 expected_data["key"] = "value"; |
394 expected_data["key2"] = "value2"; | 466 expected_data["key2"] = "value2"; |
395 MCSMessage message(BuildDownstreamMessage( | 467 |
396 "project_id", "app_id", expected_data)); | 468 // Message for kSender will be received. |
| 469 MCSMessage message(BuildDownstreamMessage(kSender, kAppId, expected_data)); |
397 EXPECT_TRUE(message.IsValid()); | 470 EXPECT_TRUE(message.IsValid()); |
398 ReceiveMessageFromMCS(message); | 471 ReceiveMessageFromMCS(message); |
399 | 472 |
400 expected_data.erase(expected_data.find("message_type")); | 473 expected_data.erase(expected_data.find("message_type")); |
401 EXPECT_EQ(MESSAGE_RECEIVED, last_event()); | 474 EXPECT_EQ(MESSAGE_RECEIVED, last_event()); |
402 EXPECT_EQ("app_id", last_app_id()); | 475 EXPECT_EQ(kAppId, last_app_id()); |
403 EXPECT_EQ(expected_data.size(), last_message().data.size()); | 476 EXPECT_EQ(expected_data.size(), last_message().data.size()); |
404 EXPECT_EQ(expected_data, last_message().data); | 477 EXPECT_EQ(expected_data, last_message().data); |
405 EXPECT_EQ("project_id", last_message().sender_id); | 478 EXPECT_EQ(kSender, last_message().sender_id); |
| 479 |
| 480 reset_last_event(); |
| 481 |
| 482 // Message for kSender2 will be received. |
| 483 MCSMessage message2(BuildDownstreamMessage(kSender2, kAppId, expected_data)); |
| 484 EXPECT_TRUE(message2.IsValid()); |
| 485 ReceiveMessageFromMCS(message2); |
| 486 |
| 487 EXPECT_EQ(MESSAGE_RECEIVED, last_event()); |
| 488 EXPECT_EQ(kAppId, last_app_id()); |
| 489 EXPECT_EQ(expected_data.size(), last_message().data.size()); |
| 490 EXPECT_EQ(expected_data, last_message().data); |
| 491 EXPECT_EQ(kSender2, last_message().sender_id); |
| 492 |
| 493 reset_last_event(); |
| 494 |
| 495 // Message from kSender3 will be dropped. |
| 496 MCSMessage message3(BuildDownstreamMessage(kSender3, kAppId, expected_data)); |
| 497 EXPECT_TRUE(message3.IsValid()); |
| 498 ReceiveMessageFromMCS(message3); |
| 499 |
| 500 EXPECT_NE(MESSAGE_RECEIVED, last_event()); |
| 501 EXPECT_NE(kAppId, last_app_id()); |
406 } | 502 } |
407 | 503 |
408 TEST_F(GCMClientImplTest, DispatchDownstreamMessageSendError) { | 504 TEST_F(GCMClientImplTest, DispatchDownstreamMessageSendError) { |
409 std::map<std::string, std::string> expected_data; | 505 std::map<std::string, std::string> expected_data; |
410 expected_data["message_type"] = "send_error"; | 506 expected_data["message_type"] = "send_error"; |
411 expected_data["google.message_id"] = "007"; | 507 expected_data["google.message_id"] = "007"; |
412 expected_data["error_details"] = "some details"; | 508 expected_data["error_details"] = "some details"; |
413 MCSMessage message(BuildDownstreamMessage( | 509 MCSMessage message(BuildDownstreamMessage( |
414 "project_id", "app_id", expected_data)); | 510 kSender, kAppId, expected_data)); |
415 EXPECT_TRUE(message.IsValid()); | 511 EXPECT_TRUE(message.IsValid()); |
416 ReceiveMessageFromMCS(message); | 512 ReceiveMessageFromMCS(message); |
417 | 513 |
418 EXPECT_EQ(MESSAGE_SEND_ERROR, last_event()); | 514 EXPECT_EQ(MESSAGE_SEND_ERROR, last_event()); |
419 EXPECT_EQ("app_id", last_app_id()); | 515 EXPECT_EQ(kAppId, last_app_id()); |
420 EXPECT_EQ("007", last_error_details().message_id); | 516 EXPECT_EQ("007", last_error_details().message_id); |
421 EXPECT_EQ(1UL, last_error_details().additional_data.size()); | 517 EXPECT_EQ(1UL, last_error_details().additional_data.size()); |
422 GCMClient::MessageData::const_iterator iter = | 518 GCMClient::MessageData::const_iterator iter = |
423 last_error_details().additional_data.find("error_details"); | 519 last_error_details().additional_data.find("error_details"); |
424 EXPECT_TRUE(iter != last_error_details().additional_data.end()); | 520 EXPECT_TRUE(iter != last_error_details().additional_data.end()); |
425 EXPECT_EQ("some details", iter->second); | 521 EXPECT_EQ("some details", iter->second); |
426 } | 522 } |
427 | 523 |
428 TEST_F(GCMClientImplTest, DispatchDownstreamMessgaesDeleted) { | 524 TEST_F(GCMClientImplTest, DispatchDownstreamMessgaesDeleted) { |
429 std::map<std::string, std::string> expected_data; | 525 std::map<std::string, std::string> expected_data; |
430 expected_data["message_type"] = "deleted_messages"; | 526 expected_data["message_type"] = "deleted_messages"; |
431 MCSMessage message(BuildDownstreamMessage( | 527 MCSMessage message(BuildDownstreamMessage( |
432 "project_id", "app_id", expected_data)); | 528 kSender, kAppId, expected_data)); |
433 EXPECT_TRUE(message.IsValid()); | 529 EXPECT_TRUE(message.IsValid()); |
434 ReceiveMessageFromMCS(message); | 530 ReceiveMessageFromMCS(message); |
435 | 531 |
436 EXPECT_EQ(MESSAGES_DELETED, last_event()); | 532 EXPECT_EQ(MESSAGES_DELETED, last_event()); |
437 EXPECT_EQ("app_id", last_app_id()); | 533 EXPECT_EQ(kAppId, last_app_id()); |
438 } | 534 } |
439 | 535 |
440 TEST_F(GCMClientImplTest, SendMessage) { | 536 TEST_F(GCMClientImplTest, SendMessage) { |
441 mcs_proto::DataMessageStanza stanza; | 537 mcs_proto::DataMessageStanza stanza; |
442 stanza.set_ttl(500); | 538 stanza.set_ttl(500); |
443 | 539 |
444 GCMClient::OutgoingMessage message; | 540 GCMClient::OutgoingMessage message; |
445 message.id = "007"; | 541 message.id = "007"; |
446 message.time_to_live = 500; | 542 message.time_to_live = 500; |
447 message.data["key"] = "value"; | 543 message.data["key"] = "value"; |
448 gcm_client()->Send("app_id", "project_id", message); | 544 gcm_client()->Send(kAppId, kSender, message); |
449 | 545 |
450 EXPECT_EQ(kDataMessageStanzaTag, mcs_client()->last_message_tag()); | 546 EXPECT_EQ(kDataMessageStanzaTag, mcs_client()->last_message_tag()); |
451 EXPECT_EQ("app_id", mcs_client()->last_data_message_stanza().category()); | 547 EXPECT_EQ(kAppId, mcs_client()->last_data_message_stanza().category()); |
452 EXPECT_EQ("project_id", mcs_client()->last_data_message_stanza().to()); | 548 EXPECT_EQ(kSender, mcs_client()->last_data_message_stanza().to()); |
453 EXPECT_EQ(500, mcs_client()->last_data_message_stanza().ttl()); | 549 EXPECT_EQ(500, mcs_client()->last_data_message_stanza().ttl()); |
454 EXPECT_EQ(CurrentTime(), mcs_client()->last_data_message_stanza().sent()); | 550 EXPECT_EQ(CurrentTime(), mcs_client()->last_data_message_stanza().sent()); |
455 EXPECT_EQ("007", mcs_client()->last_data_message_stanza().id()); | 551 EXPECT_EQ("007", mcs_client()->last_data_message_stanza().id()); |
456 EXPECT_EQ("gcm@chrome.com", mcs_client()->last_data_message_stanza().from()); | 552 EXPECT_EQ("gcm@chrome.com", mcs_client()->last_data_message_stanza().from()); |
457 EXPECT_EQ("project_id", mcs_client()->last_data_message_stanza().to()); | 553 EXPECT_EQ(kSender, mcs_client()->last_data_message_stanza().to()); |
458 EXPECT_EQ("key", mcs_client()->last_data_message_stanza().app_data(0).key()); | 554 EXPECT_EQ("key", mcs_client()->last_data_message_stanza().app_data(0).key()); |
459 EXPECT_EQ("value", | 555 EXPECT_EQ("value", |
460 mcs_client()->last_data_message_stanza().app_data(0).value()); | 556 mcs_client()->last_data_message_stanza().app_data(0).value()); |
461 } | 557 } |
462 | 558 |
463 } // namespace gcm | 559 } // namespace gcm |
OLD | NEW |