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

Side by Side Diff: chrome/browser/services/gcm/gcm_service_unittest.cc

Issue 270873002: Extract GCMClient data types into separate gcm_types.h (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Reupload Created 6 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 | Annotate | Revision Log
« no previous file with comments | « chrome/browser/services/gcm/gcm_service.cc ('k') | google_apis/gcm/gcm.gyp » ('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 "chrome/browser/services/gcm/gcm_service.h" 5 #include "chrome/browser/services/gcm/gcm_service.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/bind_helpers.h" 8 #include "base/bind_helpers.h"
9 #include "base/files/scoped_temp_dir.h" 9 #include "base/files/scoped_temp_dir.h"
10 #include "base/location.h" 10 #include "base/location.h"
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
67 MESSAGE_EVENT, 67 MESSAGE_EVENT,
68 MESSAGES_DELETED_EVENT, 68 MESSAGES_DELETED_EVENT,
69 SEND_ERROR_EVENT 69 SEND_ERROR_EVENT
70 }; 70 };
71 71
72 FakeGCMAppHandler(); 72 FakeGCMAppHandler();
73 virtual ~FakeGCMAppHandler(); 73 virtual ~FakeGCMAppHandler();
74 74
75 const Event& received_event() const { return received_event_; } 75 const Event& received_event() const { return received_event_; }
76 const std::string& app_id() const { return app_id_; } 76 const std::string& app_id() const { return app_id_; }
77 const GCMClient::IncomingMessage& message() const { return message_; } 77 const IncomingMessage& message() const { return message_; }
78 const GCMClient::SendErrorDetails& send_error_details() const { 78 const SendErrorDetails& send_error_details() const {
79 return send_error_details_; 79 return send_error_details_;
80 } 80 }
81 81
82 void WaitForNotification(); 82 void WaitForNotification();
83 83
84 // GCMAppHandler: 84 // GCMAppHandler:
85 virtual void ShutdownHandler() OVERRIDE; 85 virtual void ShutdownHandler() OVERRIDE;
86 virtual void OnMessage(const std::string& app_id, 86 virtual void OnMessage(const std::string& app_id,
87 const GCMClient::IncomingMessage& message) OVERRIDE; 87 const IncomingMessage& message) OVERRIDE;
88 virtual void OnMessagesDeleted(const std::string& app_id) OVERRIDE; 88 virtual void OnMessagesDeleted(const std::string& app_id) OVERRIDE;
89 virtual void OnSendError( 89 virtual void OnSendError(
90 const std::string& app_id, 90 const std::string& app_id,
91 const GCMClient::SendErrorDetails& send_error_details) OVERRIDE; 91 const SendErrorDetails& send_error_details) OVERRIDE;
92 92
93 private: 93 private:
94 void ClearResults(); 94 void ClearResults();
95 95
96 scoped_ptr<base::RunLoop> run_loop_; 96 scoped_ptr<base::RunLoop> run_loop_;
97 97
98 Event received_event_; 98 Event received_event_;
99 std::string app_id_; 99 std::string app_id_;
100 GCMClient::IncomingMessage message_; 100 IncomingMessage message_;
101 GCMClient::SendErrorDetails send_error_details_; 101 SendErrorDetails send_error_details_;
102 102
103 DISALLOW_COPY_AND_ASSIGN(FakeGCMAppHandler); 103 DISALLOW_COPY_AND_ASSIGN(FakeGCMAppHandler);
104 }; 104 };
105 105
106 class TestGCMService : public GCMService { 106 class TestGCMService : public GCMService {
107 public: 107 public:
108 TestGCMService( 108 TestGCMService(
109 bool start_automatically, 109 bool start_automatically,
110 scoped_ptr<IdentityProvider> identity_provider, 110 scoped_ptr<IdentityProvider> identity_provider,
111 const scoped_refptr<net::URLRequestContextGetter>& request_context); 111 const scoped_refptr<net::URLRequestContextGetter>& request_context);
(...skipping 23 matching lines...) Expand all
135 void FakeGCMAppHandler::WaitForNotification() { 135 void FakeGCMAppHandler::WaitForNotification() {
136 run_loop_.reset(new base::RunLoop); 136 run_loop_.reset(new base::RunLoop);
137 run_loop_->Run(); 137 run_loop_->Run();
138 run_loop_.reset(); 138 run_loop_.reset();
139 } 139 }
140 140
141 void FakeGCMAppHandler::ShutdownHandler() { 141 void FakeGCMAppHandler::ShutdownHandler() {
142 } 142 }
143 143
144 void FakeGCMAppHandler::OnMessage(const std::string& app_id, 144 void FakeGCMAppHandler::OnMessage(const std::string& app_id,
145 const GCMClient::IncomingMessage& message) { 145 const IncomingMessage& message) {
146 ClearResults(); 146 ClearResults();
147 received_event_ = MESSAGE_EVENT; 147 received_event_ = MESSAGE_EVENT;
148 app_id_ = app_id; 148 app_id_ = app_id;
149 message_ = message; 149 message_ = message;
150 if (run_loop_) 150 if (run_loop_)
151 run_loop_->Quit(); 151 run_loop_->Quit();
152 } 152 }
153 153
154 void FakeGCMAppHandler::OnMessagesDeleted(const std::string& app_id) { 154 void FakeGCMAppHandler::OnMessagesDeleted(const std::string& app_id) {
155 ClearResults(); 155 ClearResults();
156 received_event_ = MESSAGES_DELETED_EVENT; 156 received_event_ = MESSAGES_DELETED_EVENT;
157 app_id_ = app_id; 157 app_id_ = app_id;
158 if (run_loop_) 158 if (run_loop_)
159 run_loop_->Quit(); 159 run_loop_->Quit();
160 } 160 }
161 161
162 void FakeGCMAppHandler::OnSendError( 162 void FakeGCMAppHandler::OnSendError(
163 const std::string& app_id, 163 const std::string& app_id,
164 const GCMClient::SendErrorDetails& send_error_details) { 164 const SendErrorDetails& send_error_details) {
165 ClearResults(); 165 ClearResults();
166 received_event_ = SEND_ERROR_EVENT; 166 received_event_ = SEND_ERROR_EVENT;
167 app_id_ = app_id; 167 app_id_ = app_id;
168 send_error_details_ = send_error_details; 168 send_error_details_ = send_error_details;
169 if (run_loop_) 169 if (run_loop_)
170 run_loop_->Quit(); 170 run_loop_->Quit();
171 } 171 }
172 172
173 void FakeGCMAppHandler::ClearResults() { 173 void FakeGCMAppHandler::ClearResults() {
174 received_event_ = NO_EVENT; 174 received_event_ = NO_EVENT;
175 app_id_.clear(); 175 app_id_.clear();
176 message_ = GCMClient::IncomingMessage(); 176 message_ = IncomingMessage();
177 send_error_details_ = GCMClient::SendErrorDetails(); 177 send_error_details_ = SendErrorDetails();
178 } 178 }
179 179
180 TestGCMService::TestGCMService( 180 TestGCMService::TestGCMService(
181 bool start_automatically, 181 bool start_automatically,
182 scoped_ptr<IdentityProvider> identity_provider, 182 scoped_ptr<IdentityProvider> identity_provider,
183 const scoped_refptr<net::URLRequestContextGetter>& request_context) 183 const scoped_refptr<net::URLRequestContextGetter>& request_context)
184 : GCMService(identity_provider.Pass()), 184 : GCMService(identity_provider.Pass()),
185 request_context_(request_context), 185 request_context_(request_context),
186 start_automatically_(start_automatically) { 186 start_automatically_(start_automatically) {
187 if (!temp_dir_.CreateUniqueTempDir()) 187 if (!temp_dir_.CreateUniqueTempDir())
(...skipping 25 matching lines...) Expand all
213 WAIT 213 WAIT
214 }; 214 };
215 215
216 explicit TestGCMServiceWrapper( 216 explicit TestGCMServiceWrapper(
217 const scoped_refptr<net::URLRequestContextGetter>& request_context); 217 const scoped_refptr<net::URLRequestContextGetter>& request_context);
218 ~TestGCMServiceWrapper(); 218 ~TestGCMServiceWrapper();
219 219
220 TestGCMService* service() { return service_.get(); } 220 TestGCMService* service() { return service_.get(); }
221 FakeGCMAppHandler* gcm_app_handler() { return gcm_app_handler_.get(); } 221 FakeGCMAppHandler* gcm_app_handler() { return gcm_app_handler_.get(); }
222 const std::string& registration_id() const { return registration_id_; } 222 const std::string& registration_id() const { return registration_id_; }
223 GCMClient::Result registration_result() const { return registration_result_; } 223 Result registration_result() const { return registration_result_; }
224 const std::string& send_message_id() const { return send_message_id_; } 224 const std::string& send_message_id() const { return send_message_id_; }
225 GCMClient::Result send_result() const { return send_result_; } 225 Result send_result() const { return send_result_; }
226 GCMClient::Result unregistration_result() const { 226 Result unregistration_result() const {
227 return unregistration_result_; 227 return unregistration_result_;
228 } 228 }
229 229
230 void ClearRegistrationResult(); 230 void ClearRegistrationResult();
231 void ClearUnregistrationResult(); 231 void ClearUnregistrationResult();
232 232
233 bool ServiceHasAppHandlers() const; 233 bool ServiceHasAppHandlers() const;
234 GCMClientMock* GetGCMClient(); 234 GCMClientMock* GetGCMClient();
235 235
236 void CreateService(bool start_automatically, 236 void CreateService(bool start_automatically,
237 GCMClientMock::LoadingDelay gcm_client_loading_delay); 237 GCMClientMock::LoadingDelay gcm_client_loading_delay);
238 238
239 void SignIn(const std::string& account_id); 239 void SignIn(const std::string& account_id);
240 void SignOut(); 240 void SignOut();
241 241
242 void Register(const std::string& app_id, 242 void Register(const std::string& app_id,
243 const std::vector<std::string>& sender_ids, 243 const std::vector<std::string>& sender_ids,
244 WaitToFinish wait_to_finish); 244 WaitToFinish wait_to_finish);
245 void Send(const std::string& app_id, 245 void Send(const std::string& app_id,
246 const std::string& receiver_id, 246 const std::string& receiver_id,
247 const GCMClient::OutgoingMessage& message, 247 const OutgoingMessage& message,
248 WaitToFinish wait_to_finish); 248 WaitToFinish wait_to_finish);
249 void Unregister(const std::string& app_id, WaitToFinish wait_to_finish); 249 void Unregister(const std::string& app_id, WaitToFinish wait_to_finish);
250 250
251 void WaitForAsyncOperation(); 251 void WaitForAsyncOperation();
252 252
253 private: 253 private:
254 void RegisterCompleted(const std::string& registration_id, 254 void RegisterCompleted(const std::string& registration_id,
255 GCMClient::Result result); 255 Result result);
256 void SendCompleted(const std::string& message_id, GCMClient::Result result); 256 void SendCompleted(const std::string& message_id, Result result);
257 void UnregisterCompleted(GCMClient::Result result); 257 void UnregisterCompleted(Result result);
258 258
259 scoped_refptr<net::URLRequestContextGetter> request_context_; 259 scoped_refptr<net::URLRequestContextGetter> request_context_;
260 FakeOAuth2TokenService token_service_; 260 FakeOAuth2TokenService token_service_;
261 scoped_ptr<FakeIdentityProvider> identity_provider_owner_; 261 scoped_ptr<FakeIdentityProvider> identity_provider_owner_;
262 FakeIdentityProvider* identity_provider_; 262 FakeIdentityProvider* identity_provider_;
263 scoped_ptr<TestGCMService> service_; 263 scoped_ptr<TestGCMService> service_;
264 scoped_ptr<FakeGCMAppHandler> gcm_app_handler_; 264 scoped_ptr<FakeGCMAppHandler> gcm_app_handler_;
265 265
266 base::Closure async_operation_completed_callback_; 266 base::Closure async_operation_completed_callback_;
267 267
268 std::string registration_id_; 268 std::string registration_id_;
269 GCMClient::Result registration_result_; 269 Result registration_result_;
270 std::string send_message_id_; 270 std::string send_message_id_;
271 GCMClient::Result send_result_; 271 Result send_result_;
272 GCMClient::Result unregistration_result_; 272 Result unregistration_result_;
273 273
274 DISALLOW_COPY_AND_ASSIGN(TestGCMServiceWrapper); 274 DISALLOW_COPY_AND_ASSIGN(TestGCMServiceWrapper);
275 }; 275 };
276 276
277 TestGCMServiceWrapper::TestGCMServiceWrapper( 277 TestGCMServiceWrapper::TestGCMServiceWrapper(
278 const scoped_refptr<net::URLRequestContextGetter>& request_context) 278 const scoped_refptr<net::URLRequestContextGetter>& request_context)
279 : request_context_(request_context), 279 : request_context_(request_context),
280 identity_provider_(NULL), 280 identity_provider_(NULL),
281 registration_result_(GCMClient::UNKNOWN_ERROR), 281 registration_result_(RESULT_UNKNOWN_ERROR),
282 send_result_(GCMClient::UNKNOWN_ERROR), 282 send_result_(RESULT_UNKNOWN_ERROR),
283 unregistration_result_(GCMClient::UNKNOWN_ERROR) { 283 unregistration_result_(RESULT_UNKNOWN_ERROR) {
284 identity_provider_owner_.reset(new FakeIdentityProvider(&token_service_)); 284 identity_provider_owner_.reset(new FakeIdentityProvider(&token_service_));
285 identity_provider_ = identity_provider_owner_.get(); 285 identity_provider_ = identity_provider_owner_.get();
286 } 286 }
287 287
288 TestGCMServiceWrapper::~TestGCMServiceWrapper() { 288 TestGCMServiceWrapper::~TestGCMServiceWrapper() {
289 if (!service_) 289 if (!service_)
290 return; 290 return;
291 291
292 service_->ShutdownService(); 292 service_->ShutdownService();
293 service_.reset(); 293 service_.reset();
294 PumpIOLoop(); 294 PumpIOLoop();
295 } 295 }
296 296
297 void TestGCMServiceWrapper::ClearRegistrationResult() { 297 void TestGCMServiceWrapper::ClearRegistrationResult() {
298 registration_id_.clear(); 298 registration_id_.clear();
299 registration_result_ = GCMClient::UNKNOWN_ERROR; 299 registration_result_ = RESULT_UNKNOWN_ERROR;
300 } 300 }
301 301
302 void TestGCMServiceWrapper::ClearUnregistrationResult() { 302 void TestGCMServiceWrapper::ClearUnregistrationResult() {
303 unregistration_result_ = GCMClient::UNKNOWN_ERROR; 303 unregistration_result_ = RESULT_UNKNOWN_ERROR;
304 } 304 }
305 305
306 bool TestGCMServiceWrapper::ServiceHasAppHandlers() const { 306 bool TestGCMServiceWrapper::ServiceHasAppHandlers() const {
307 return !service_->app_handlers_.empty(); 307 return !service_->app_handlers_.empty();
308 } 308 }
309 309
310 GCMClientMock* TestGCMServiceWrapper::GetGCMClient() { 310 GCMClientMock* TestGCMServiceWrapper::GetGCMClient() {
311 return static_cast<GCMClientMock*>(service_->GetGCMClientForTesting()); 311 return static_cast<GCMClientMock*>(service_->GetGCMClientForTesting());
312 } 312 }
313 313
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
347 service_->Register(app_id, 347 service_->Register(app_id,
348 sender_ids, 348 sender_ids,
349 base::Bind(&TestGCMServiceWrapper::RegisterCompleted, 349 base::Bind(&TestGCMServiceWrapper::RegisterCompleted,
350 base::Unretained(this))); 350 base::Unretained(this)));
351 if (wait_to_finish == WAIT) 351 if (wait_to_finish == WAIT)
352 run_loop.Run(); 352 run_loop.Run();
353 } 353 }
354 354
355 void TestGCMServiceWrapper::Send(const std::string& app_id, 355 void TestGCMServiceWrapper::Send(const std::string& app_id,
356 const std::string& receiver_id, 356 const std::string& receiver_id,
357 const GCMClient::OutgoingMessage& message, 357 const OutgoingMessage& message,
358 WaitToFinish wait_to_finish) { 358 WaitToFinish wait_to_finish) {
359 base::RunLoop run_loop; 359 base::RunLoop run_loop;
360 async_operation_completed_callback_ = run_loop.QuitClosure(); 360 async_operation_completed_callback_ = run_loop.QuitClosure();
361 service_->Send(app_id, 361 service_->Send(app_id,
362 receiver_id, 362 receiver_id,
363 message, 363 message,
364 base::Bind(&TestGCMServiceWrapper::SendCompleted, 364 base::Bind(&TestGCMServiceWrapper::SendCompleted,
365 base::Unretained(this))); 365 base::Unretained(this)));
366 if (wait_to_finish == WAIT) 366 if (wait_to_finish == WAIT)
367 run_loop.Run(); 367 run_loop.Run();
(...skipping 11 matching lines...) Expand all
379 } 379 }
380 380
381 void TestGCMServiceWrapper::WaitForAsyncOperation() { 381 void TestGCMServiceWrapper::WaitForAsyncOperation() {
382 base::RunLoop run_loop; 382 base::RunLoop run_loop;
383 async_operation_completed_callback_ = run_loop.QuitClosure(); 383 async_operation_completed_callback_ = run_loop.QuitClosure();
384 run_loop.Run(); 384 run_loop.Run();
385 } 385 }
386 386
387 void TestGCMServiceWrapper::RegisterCompleted( 387 void TestGCMServiceWrapper::RegisterCompleted(
388 const std::string& registration_id, 388 const std::string& registration_id,
389 GCMClient::Result result) { 389 Result result) {
390 registration_id_ = registration_id; 390 registration_id_ = registration_id;
391 registration_result_ = result; 391 registration_result_ = result;
392 if (!async_operation_completed_callback_.is_null()) 392 if (!async_operation_completed_callback_.is_null())
393 async_operation_completed_callback_.Run(); 393 async_operation_completed_callback_.Run();
394 } 394 }
395 395
396 void TestGCMServiceWrapper::SendCompleted(const std::string& message_id, 396 void TestGCMServiceWrapper::SendCompleted(const std::string& message_id,
397 GCMClient::Result result) { 397 Result result) {
398 send_message_id_ = message_id; 398 send_message_id_ = message_id;
399 send_result_ = result; 399 send_result_ = result;
400 if (!async_operation_completed_callback_.is_null()) 400 if (!async_operation_completed_callback_.is_null())
401 async_operation_completed_callback_.Run(); 401 async_operation_completed_callback_.Run();
402 } 402 }
403 403
404 void TestGCMServiceWrapper::UnregisterCompleted(GCMClient::Result result) { 404 void TestGCMServiceWrapper::UnregisterCompleted(Result result) {
405 unregistration_result_ = result; 405 unregistration_result_ = result;
406 if (!async_operation_completed_callback_.is_null()) 406 if (!async_operation_completed_callback_.is_null())
407 async_operation_completed_callback_.Run(); 407 async_operation_completed_callback_.Run();
408 } 408 }
409 409
410 class GCMServiceTest : public testing::Test { 410 class GCMServiceTest : public testing::Test {
411 protected: 411 protected:
412 GCMServiceTest(); 412 GCMServiceTest();
413 virtual ~GCMServiceTest(); 413 virtual ~GCMServiceTest();
414 414
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after
568 } 568 }
569 569
570 TEST_F(GCMServiceTest, RegisterWhenNotSignedIn) { 570 TEST_F(GCMServiceTest, RegisterWhenNotSignedIn) {
571 wrapper_->CreateService(true, GCMClientMock::NO_DELAY_LOADING); 571 wrapper_->CreateService(true, GCMClientMock::NO_DELAY_LOADING);
572 572
573 std::vector<std::string> sender_ids; 573 std::vector<std::string> sender_ids;
574 sender_ids.push_back("sender1"); 574 sender_ids.push_back("sender1");
575 wrapper_->Register(kTestAppID1, sender_ids, TestGCMServiceWrapper::WAIT); 575 wrapper_->Register(kTestAppID1, sender_ids, TestGCMServiceWrapper::WAIT);
576 576
577 EXPECT_TRUE(wrapper_->registration_id().empty()); 577 EXPECT_TRUE(wrapper_->registration_id().empty());
578 EXPECT_EQ(GCMClient::NOT_SIGNED_IN, wrapper_->registration_result()); 578 EXPECT_EQ(RESULT_NOT_SIGNED_IN, wrapper_->registration_result());
579 } 579 }
580 580
581 TEST_F(GCMServiceTest, RegisterUnderNonPositiveChannelSignal) { 581 TEST_F(GCMServiceTest, RegisterUnderNonPositiveChannelSignal) {
582 // Non-positive channel signal will prevent GCMClient from checking in during 582 // Non-positive channel signal will prevent GCMClient from checking in during
583 // sign-in. 583 // sign-in.
584 wrapper_->CreateService(false, GCMClientMock::NO_DELAY_LOADING); 584 wrapper_->CreateService(false, GCMClientMock::NO_DELAY_LOADING);
585 wrapper_->SignIn(kTestAccountID1); 585 wrapper_->SignIn(kTestAccountID1);
586 586
587 // GCMClient should not be checked in. 587 // GCMClient should not be checked in.
588 EXPECT_FALSE(wrapper_->service()->IsGCMClientReady()); 588 EXPECT_FALSE(wrapper_->service()->IsGCMClientReady());
589 EXPECT_EQ(GCMClientMock::UNINITIALIZED, wrapper_->GetGCMClient()->status()); 589 EXPECT_EQ(GCMClientMock::UNINITIALIZED, wrapper_->GetGCMClient()->status());
590 590
591 // Invoking register will make GCMClient checked in. 591 // Invoking register will make GCMClient checked in.
592 std::vector<std::string> sender_ids; 592 std::vector<std::string> sender_ids;
593 sender_ids.push_back("sender1"); 593 sender_ids.push_back("sender1");
594 wrapper_->Register(kTestAppID1, sender_ids, TestGCMServiceWrapper::WAIT); 594 wrapper_->Register(kTestAppID1, sender_ids, TestGCMServiceWrapper::WAIT);
595 595
596 // GCMClient should be checked in. 596 // GCMClient should be checked in.
597 EXPECT_TRUE(wrapper_->service()->IsGCMClientReady()); 597 EXPECT_TRUE(wrapper_->service()->IsGCMClientReady());
598 EXPECT_EQ(GCMClientMock::LOADED, wrapper_->GetGCMClient()->status()); 598 EXPECT_EQ(GCMClientMock::LOADED, wrapper_->GetGCMClient()->status());
599 599
600 // Registration should succeed. 600 // Registration should succeed.
601 const std::string expected_registration_id = 601 const std::string expected_registration_id =
602 GCMClientMock::GetRegistrationIdFromSenderIds(sender_ids); 602 GCMClientMock::GetRegistrationIdFromSenderIds(sender_ids);
603 EXPECT_EQ(expected_registration_id, wrapper_->registration_id()); 603 EXPECT_EQ(expected_registration_id, wrapper_->registration_id());
604 EXPECT_EQ(GCMClient::SUCCESS, wrapper_->registration_result()); 604 EXPECT_EQ(RESULT_SUCCESS, wrapper_->registration_result());
605 } 605 }
606 606
607 TEST_F(GCMServiceTest, SendWhenNotSignedIn) { 607 TEST_F(GCMServiceTest, SendWhenNotSignedIn) {
608 wrapper_->CreateService(true, GCMClientMock::NO_DELAY_LOADING); 608 wrapper_->CreateService(true, GCMClientMock::NO_DELAY_LOADING);
609 609
610 GCMClient::OutgoingMessage message; 610 OutgoingMessage message;
611 message.id = "1"; 611 message.id = "1";
612 message.data["key1"] = "value1"; 612 message.data["key1"] = "value1";
613 wrapper_->Send(kTestAppID1, kUserID1, message, TestGCMServiceWrapper::WAIT); 613 wrapper_->Send(kTestAppID1, kUserID1, message, TestGCMServiceWrapper::WAIT);
614 614
615 EXPECT_TRUE(wrapper_->send_message_id().empty()); 615 EXPECT_TRUE(wrapper_->send_message_id().empty());
616 EXPECT_EQ(GCMClient::NOT_SIGNED_IN, wrapper_->send_result()); 616 EXPECT_EQ(RESULT_NOT_SIGNED_IN, wrapper_->send_result());
617 } 617 }
618 618
619 TEST_F(GCMServiceTest, SendUnderNonPositiveChannelSignal) { 619 TEST_F(GCMServiceTest, SendUnderNonPositiveChannelSignal) {
620 // Non-positive channel signal will prevent GCMClient from checking in during 620 // Non-positive channel signal will prevent GCMClient from checking in during
621 // sign-in. 621 // sign-in.
622 wrapper_->CreateService(false, GCMClientMock::NO_DELAY_LOADING); 622 wrapper_->CreateService(false, GCMClientMock::NO_DELAY_LOADING);
623 wrapper_->SignIn(kTestAccountID1); 623 wrapper_->SignIn(kTestAccountID1);
624 624
625 // GCMClient should not be checked in. 625 // GCMClient should not be checked in.
626 EXPECT_FALSE(wrapper_->service()->IsGCMClientReady()); 626 EXPECT_FALSE(wrapper_->service()->IsGCMClientReady());
627 EXPECT_EQ(GCMClientMock::UNINITIALIZED, wrapper_->GetGCMClient()->status()); 627 EXPECT_EQ(GCMClientMock::UNINITIALIZED, wrapper_->GetGCMClient()->status());
628 628
629 // Invoking send will make GCMClient checked in. 629 // Invoking send will make GCMClient checked in.
630 GCMClient::OutgoingMessage message; 630 OutgoingMessage message;
631 message.id = "1"; 631 message.id = "1";
632 message.data["key1"] = "value1"; 632 message.data["key1"] = "value1";
633 wrapper_->Send(kTestAppID1, kUserID1, message, TestGCMServiceWrapper::WAIT); 633 wrapper_->Send(kTestAppID1, kUserID1, message, TestGCMServiceWrapper::WAIT);
634 634
635 // GCMClient should be checked in. 635 // GCMClient should be checked in.
636 EXPECT_TRUE(wrapper_->service()->IsGCMClientReady()); 636 EXPECT_TRUE(wrapper_->service()->IsGCMClientReady());
637 EXPECT_EQ(GCMClientMock::LOADED, wrapper_->GetGCMClient()->status()); 637 EXPECT_EQ(GCMClientMock::LOADED, wrapper_->GetGCMClient()->status());
638 638
639 // Sending should succeed. 639 // Sending should succeed.
640 EXPECT_EQ(message.id, wrapper_->send_message_id()); 640 EXPECT_EQ(message.id, wrapper_->send_message_id());
641 EXPECT_EQ(GCMClient::SUCCESS, wrapper_->send_result()); 641 EXPECT_EQ(RESULT_SUCCESS, wrapper_->send_result());
642 } 642 }
643 643
644 // Tests a single instance of GCMService. 644 // Tests a single instance of GCMService.
645 class GCMServiceSingleInstanceTest : public GCMServiceTest { 645 class GCMServiceSingleInstanceTest : public GCMServiceTest {
646 public: 646 public:
647 GCMServiceSingleInstanceTest(); 647 GCMServiceSingleInstanceTest();
648 virtual ~GCMServiceSingleInstanceTest(); 648 virtual ~GCMServiceSingleInstanceTest();
649 649
650 // GCMServiceTest: 650 // GCMServiceTest:
651 virtual void SetUp() OVERRIDE; 651 virtual void SetUp() OVERRIDE;
(...skipping 16 matching lines...) Expand all
668 } 668 }
669 669
670 TEST_F(GCMServiceSingleInstanceTest, Register) { 670 TEST_F(GCMServiceSingleInstanceTest, Register) {
671 std::vector<std::string> sender_ids; 671 std::vector<std::string> sender_ids;
672 sender_ids.push_back("sender1"); 672 sender_ids.push_back("sender1");
673 wrapper_->Register(kTestAppID1, sender_ids, TestGCMServiceWrapper::WAIT); 673 wrapper_->Register(kTestAppID1, sender_ids, TestGCMServiceWrapper::WAIT);
674 const std::string expected_registration_id = 674 const std::string expected_registration_id =
675 GCMClientMock::GetRegistrationIdFromSenderIds(sender_ids); 675 GCMClientMock::GetRegistrationIdFromSenderIds(sender_ids);
676 676
677 EXPECT_EQ(expected_registration_id, wrapper_->registration_id()); 677 EXPECT_EQ(expected_registration_id, wrapper_->registration_id());
678 EXPECT_EQ(GCMClient::SUCCESS, wrapper_->registration_result()); 678 EXPECT_EQ(RESULT_SUCCESS, wrapper_->registration_result());
679 } 679 }
680 680
681 TEST_F(GCMServiceSingleInstanceTest, RegisterError) { 681 TEST_F(GCMServiceSingleInstanceTest, RegisterError) {
682 std::vector<std::string> sender_ids; 682 std::vector<std::string> sender_ids;
683 sender_ids.push_back("sender1@error"); 683 sender_ids.push_back("sender1@error");
684 wrapper_->Register(kTestAppID1, sender_ids, TestGCMServiceWrapper::WAIT); 684 wrapper_->Register(kTestAppID1, sender_ids, TestGCMServiceWrapper::WAIT);
685 685
686 EXPECT_TRUE(wrapper_->registration_id().empty()); 686 EXPECT_TRUE(wrapper_->registration_id().empty());
687 EXPECT_NE(GCMClient::SUCCESS, wrapper_->registration_result()); 687 EXPECT_NE(RESULT_SUCCESS, wrapper_->registration_result());
688 } 688 }
689 689
690 TEST_F(GCMServiceSingleInstanceTest, RegisterAgainWithSameSenderIDs) { 690 TEST_F(GCMServiceSingleInstanceTest, RegisterAgainWithSameSenderIDs) {
691 std::vector<std::string> sender_ids; 691 std::vector<std::string> sender_ids;
692 sender_ids.push_back("sender1"); 692 sender_ids.push_back("sender1");
693 sender_ids.push_back("sender2"); 693 sender_ids.push_back("sender2");
694 wrapper_->Register(kTestAppID1, sender_ids, TestGCMServiceWrapper::WAIT); 694 wrapper_->Register(kTestAppID1, sender_ids, TestGCMServiceWrapper::WAIT);
695 const std::string expected_registration_id = 695 const std::string expected_registration_id =
696 GCMClientMock::GetRegistrationIdFromSenderIds(sender_ids); 696 GCMClientMock::GetRegistrationIdFromSenderIds(sender_ids);
697 697
698 EXPECT_EQ(expected_registration_id, wrapper_->registration_id()); 698 EXPECT_EQ(expected_registration_id, wrapper_->registration_id());
699 EXPECT_EQ(GCMClient::SUCCESS, wrapper_->registration_result()); 699 EXPECT_EQ(RESULT_SUCCESS, wrapper_->registration_result());
700 700
701 // Clears the results the would be set by the Register callback in preparation 701 // Clears the results the would be set by the Register callback in preparation
702 // to call register 2nd time. 702 // to call register 2nd time.
703 wrapper_->ClearRegistrationResult(); 703 wrapper_->ClearRegistrationResult();
704 704
705 // Calling register 2nd time with the same set of sender IDs but different 705 // Calling register 2nd time with the same set of sender IDs but different
706 // ordering will get back the same registration ID. 706 // ordering will get back the same registration ID.
707 std::vector<std::string> another_sender_ids; 707 std::vector<std::string> another_sender_ids;
708 another_sender_ids.push_back("sender2"); 708 another_sender_ids.push_back("sender2");
709 another_sender_ids.push_back("sender1"); 709 another_sender_ids.push_back("sender1");
710 wrapper_->Register(kTestAppID1, 710 wrapper_->Register(kTestAppID1,
711 another_sender_ids, 711 another_sender_ids,
712 TestGCMServiceWrapper::WAIT); 712 TestGCMServiceWrapper::WAIT);
713 713
714 EXPECT_EQ(expected_registration_id, wrapper_->registration_id()); 714 EXPECT_EQ(expected_registration_id, wrapper_->registration_id());
715 EXPECT_EQ(GCMClient::SUCCESS, wrapper_->registration_result()); 715 EXPECT_EQ(RESULT_SUCCESS, wrapper_->registration_result());
716 } 716 }
717 717
718 TEST_F(GCMServiceSingleInstanceTest, RegisterAgainWithDifferentSenderIDs) { 718 TEST_F(GCMServiceSingleInstanceTest, RegisterAgainWithDifferentSenderIDs) {
719 std::vector<std::string> sender_ids; 719 std::vector<std::string> sender_ids;
720 sender_ids.push_back("sender1"); 720 sender_ids.push_back("sender1");
721 wrapper_->Register(kTestAppID1, sender_ids, TestGCMServiceWrapper::WAIT); 721 wrapper_->Register(kTestAppID1, sender_ids, TestGCMServiceWrapper::WAIT);
722 const std::string expected_registration_id = 722 const std::string expected_registration_id =
723 GCMClientMock::GetRegistrationIdFromSenderIds(sender_ids); 723 GCMClientMock::GetRegistrationIdFromSenderIds(sender_ids);
724 724
725 EXPECT_EQ(expected_registration_id, wrapper_->registration_id()); 725 EXPECT_EQ(expected_registration_id, wrapper_->registration_id());
726 EXPECT_EQ(GCMClient::SUCCESS, wrapper_->registration_result()); 726 EXPECT_EQ(RESULT_SUCCESS, wrapper_->registration_result());
727 727
728 // Make sender IDs different. 728 // Make sender IDs different.
729 sender_ids.push_back("sender2"); 729 sender_ids.push_back("sender2");
730 const std::string expected_registration_id2 = 730 const std::string expected_registration_id2 =
731 GCMClientMock::GetRegistrationIdFromSenderIds(sender_ids); 731 GCMClientMock::GetRegistrationIdFromSenderIds(sender_ids);
732 732
733 // Calling register 2nd time with the different sender IDs will get back a new 733 // Calling register 2nd time with the different sender IDs will get back a new
734 // registration ID. 734 // registration ID.
735 wrapper_->Register(kTestAppID1, sender_ids, TestGCMServiceWrapper::WAIT); 735 wrapper_->Register(kTestAppID1, sender_ids, TestGCMServiceWrapper::WAIT);
736 EXPECT_EQ(expected_registration_id2, wrapper_->registration_id()); 736 EXPECT_EQ(expected_registration_id2, wrapper_->registration_id());
737 EXPECT_EQ(GCMClient::SUCCESS, wrapper_->registration_result()); 737 EXPECT_EQ(RESULT_SUCCESS, wrapper_->registration_result());
738 } 738 }
739 739
740 TEST_F(GCMServiceSingleInstanceTest, GCMClientNotReadyBeforeRegistration) { 740 TEST_F(GCMServiceSingleInstanceTest, GCMClientNotReadyBeforeRegistration) {
741 // Make GCMClient not ready initially. 741 // Make GCMClient not ready initially.
742 wrapper_.reset(new TestGCMServiceWrapper(request_context_)); 742 wrapper_.reset(new TestGCMServiceWrapper(request_context_));
743 wrapper_->CreateService(true, GCMClientMock::DELAY_LOADING); 743 wrapper_->CreateService(true, GCMClientMock::DELAY_LOADING);
744 wrapper_->SignIn(kTestAccountID1); 744 wrapper_->SignIn(kTestAccountID1);
745 745
746 // The registration is on hold until GCMClient is ready. 746 // The registration is on hold until GCMClient is ready.
747 std::vector<std::string> sender_ids; 747 std::vector<std::string> sender_ids;
748 sender_ids.push_back("sender1"); 748 sender_ids.push_back("sender1");
749 wrapper_->Register(kTestAppID1, 749 wrapper_->Register(kTestAppID1,
750 sender_ids, 750 sender_ids,
751 TestGCMServiceWrapper::DO_NOT_WAIT); 751 TestGCMServiceWrapper::DO_NOT_WAIT);
752 PumpIOLoop(); 752 PumpIOLoop();
753 PumpUILoop(); 753 PumpUILoop();
754 EXPECT_TRUE(wrapper_->registration_id().empty()); 754 EXPECT_TRUE(wrapper_->registration_id().empty());
755 EXPECT_EQ(GCMClient::UNKNOWN_ERROR, wrapper_->registration_result()); 755 EXPECT_EQ(RESULT_UNKNOWN_ERROR, wrapper_->registration_result());
756 756
757 // Register operation will be invoked after GCMClient becomes ready. 757 // Register operation will be invoked after GCMClient becomes ready.
758 wrapper_->GetGCMClient()->PerformDelayedLoading(); 758 wrapper_->GetGCMClient()->PerformDelayedLoading();
759 wrapper_->WaitForAsyncOperation(); 759 wrapper_->WaitForAsyncOperation();
760 EXPECT_FALSE(wrapper_->registration_id().empty()); 760 EXPECT_FALSE(wrapper_->registration_id().empty());
761 EXPECT_EQ(GCMClient::SUCCESS, wrapper_->registration_result()); 761 EXPECT_EQ(RESULT_SUCCESS, wrapper_->registration_result());
762 } 762 }
763 763
764 TEST_F(GCMServiceSingleInstanceTest, RegisterAfterSignOut) { 764 TEST_F(GCMServiceSingleInstanceTest, RegisterAfterSignOut) {
765 // This will trigger check-out. 765 // This will trigger check-out.
766 wrapper_->SignOut(); 766 wrapper_->SignOut();
767 767
768 std::vector<std::string> sender_ids; 768 std::vector<std::string> sender_ids;
769 sender_ids.push_back("sender1"); 769 sender_ids.push_back("sender1");
770 wrapper_->Register(kTestAppID1, sender_ids, TestGCMServiceWrapper::WAIT); 770 wrapper_->Register(kTestAppID1, sender_ids, TestGCMServiceWrapper::WAIT);
771 771
772 EXPECT_TRUE(wrapper_->registration_id().empty()); 772 EXPECT_TRUE(wrapper_->registration_id().empty());
773 EXPECT_EQ(GCMClient::NOT_SIGNED_IN, wrapper_->registration_result()); 773 EXPECT_EQ(RESULT_NOT_SIGNED_IN, wrapper_->registration_result());
774 } 774 }
775 775
776 TEST_F(GCMServiceSingleInstanceTest, UnregisterExplicitly) { 776 TEST_F(GCMServiceSingleInstanceTest, UnregisterExplicitly) {
777 std::vector<std::string> sender_ids; 777 std::vector<std::string> sender_ids;
778 sender_ids.push_back("sender1"); 778 sender_ids.push_back("sender1");
779 wrapper_->Register(kTestAppID1, sender_ids, TestGCMServiceWrapper::WAIT); 779 wrapper_->Register(kTestAppID1, sender_ids, TestGCMServiceWrapper::WAIT);
780 780
781 EXPECT_FALSE(wrapper_->registration_id().empty()); 781 EXPECT_FALSE(wrapper_->registration_id().empty());
782 EXPECT_EQ(GCMClient::SUCCESS, wrapper_->registration_result()); 782 EXPECT_EQ(RESULT_SUCCESS, wrapper_->registration_result());
783 783
784 wrapper_->Unregister(kTestAppID1, TestGCMServiceWrapper::WAIT); 784 wrapper_->Unregister(kTestAppID1, TestGCMServiceWrapper::WAIT);
785 785
786 EXPECT_EQ(GCMClient::SUCCESS, wrapper_->unregistration_result()); 786 EXPECT_EQ(RESULT_SUCCESS, wrapper_->unregistration_result());
787 } 787 }
788 788
789 TEST_F(GCMServiceSingleInstanceTest, UnregisterWhenAsyncOperationPending) { 789 TEST_F(GCMServiceSingleInstanceTest, UnregisterWhenAsyncOperationPending) {
790 std::vector<std::string> sender_ids; 790 std::vector<std::string> sender_ids;
791 sender_ids.push_back("sender1"); 791 sender_ids.push_back("sender1");
792 // First start registration without waiting for it to complete. 792 // First start registration without waiting for it to complete.
793 wrapper_->Register(kTestAppID1, 793 wrapper_->Register(kTestAppID1,
794 sender_ids, 794 sender_ids,
795 TestGCMServiceWrapper::DO_NOT_WAIT); 795 TestGCMServiceWrapper::DO_NOT_WAIT);
796 796
797 // Test that unregistration fails with async operation pending when there is a 797 // Test that unregistration fails with async operation pending when there is a
798 // registration already in progress. 798 // registration already in progress.
799 wrapper_->Unregister(kTestAppID1, TestGCMServiceWrapper::WAIT); 799 wrapper_->Unregister(kTestAppID1, TestGCMServiceWrapper::WAIT);
800 EXPECT_EQ(GCMClient::ASYNC_OPERATION_PENDING, 800 EXPECT_EQ(RESULT_ASYNC_OPERATION_PENDING,
801 wrapper_->unregistration_result()); 801 wrapper_->unregistration_result());
802 802
803 // Complete the unregistration. 803 // Complete the unregistration.
804 wrapper_->WaitForAsyncOperation(); 804 wrapper_->WaitForAsyncOperation();
805 EXPECT_EQ(GCMClient::SUCCESS, wrapper_->registration_result()); 805 EXPECT_EQ(RESULT_SUCCESS, wrapper_->registration_result());
806 806
807 // Start unregistration without waiting for it to complete. This time no async 807 // Start unregistration without waiting for it to complete. This time no async
808 // operation is pending. 808 // operation is pending.
809 wrapper_->Unregister(kTestAppID1, TestGCMServiceWrapper::DO_NOT_WAIT); 809 wrapper_->Unregister(kTestAppID1, TestGCMServiceWrapper::DO_NOT_WAIT);
810 810
811 // Test that unregistration fails with async operation pending when there is 811 // Test that unregistration fails with async operation pending when there is
812 // an unregistration already in progress. 812 // an unregistration already in progress.
813 wrapper_->Unregister(kTestAppID1, TestGCMServiceWrapper::WAIT); 813 wrapper_->Unregister(kTestAppID1, TestGCMServiceWrapper::WAIT);
814 EXPECT_EQ(GCMClient::ASYNC_OPERATION_PENDING, 814 EXPECT_EQ(RESULT_ASYNC_OPERATION_PENDING,
815 wrapper_->unregistration_result()); 815 wrapper_->unregistration_result());
816 wrapper_->ClearUnregistrationResult(); 816 wrapper_->ClearUnregistrationResult();
817 817
818 // Complete unregistration. 818 // Complete unregistration.
819 wrapper_->WaitForAsyncOperation(); 819 wrapper_->WaitForAsyncOperation();
820 EXPECT_EQ(GCMClient::SUCCESS, wrapper_->unregistration_result()); 820 EXPECT_EQ(RESULT_SUCCESS, wrapper_->unregistration_result());
821 } 821 }
822 822
823 TEST_F(GCMServiceSingleInstanceTest, RegisterWhenAsyncOperationPending) { 823 TEST_F(GCMServiceSingleInstanceTest, RegisterWhenAsyncOperationPending) {
824 std::vector<std::string> sender_ids; 824 std::vector<std::string> sender_ids;
825 sender_ids.push_back("sender1"); 825 sender_ids.push_back("sender1");
826 // First start registration without waiting for it to complete. 826 // First start registration without waiting for it to complete.
827 wrapper_->Register(kTestAppID1, 827 wrapper_->Register(kTestAppID1,
828 sender_ids, 828 sender_ids,
829 TestGCMServiceWrapper::DO_NOT_WAIT); 829 TestGCMServiceWrapper::DO_NOT_WAIT);
830 830
831 // Test that registration fails with async operation pending when there is a 831 // Test that registration fails with async operation pending when there is a
832 // registration already in progress. 832 // registration already in progress.
833 wrapper_->Register(kTestAppID1, sender_ids, TestGCMServiceWrapper::WAIT); 833 wrapper_->Register(kTestAppID1, sender_ids, TestGCMServiceWrapper::WAIT);
834 EXPECT_EQ(GCMClient::ASYNC_OPERATION_PENDING, 834 EXPECT_EQ(RESULT_ASYNC_OPERATION_PENDING,
835 wrapper_->registration_result()); 835 wrapper_->registration_result());
836 wrapper_->ClearRegistrationResult(); 836 wrapper_->ClearRegistrationResult();
837 837
838 // Complete the registration. 838 // Complete the registration.
839 wrapper_->WaitForAsyncOperation(); 839 wrapper_->WaitForAsyncOperation();
840 EXPECT_EQ(GCMClient::SUCCESS, wrapper_->registration_result()); 840 EXPECT_EQ(RESULT_SUCCESS, wrapper_->registration_result());
841 841
842 // Start unregistration without waiting for it to complete. This time no async 842 // Start unregistration without waiting for it to complete. This time no async
843 // operation is pending. 843 // operation is pending.
844 wrapper_->Unregister(kTestAppID1, TestGCMServiceWrapper::DO_NOT_WAIT); 844 wrapper_->Unregister(kTestAppID1, TestGCMServiceWrapper::DO_NOT_WAIT);
845 845
846 // Test that registration fails with async operation pending when there is an 846 // Test that registration fails with async operation pending when there is an
847 // unregistration already in progress. 847 // unregistration already in progress.
848 wrapper_->Register(kTestAppID1, sender_ids, TestGCMServiceWrapper::WAIT); 848 wrapper_->Register(kTestAppID1, sender_ids, TestGCMServiceWrapper::WAIT);
849 EXPECT_EQ(GCMClient::ASYNC_OPERATION_PENDING, 849 EXPECT_EQ(RESULT_ASYNC_OPERATION_PENDING,
850 wrapper_->registration_result()); 850 wrapper_->registration_result());
851 851
852 // Complete the first unregistration expecting success. 852 // Complete the first unregistration expecting success.
853 wrapper_->WaitForAsyncOperation(); 853 wrapper_->WaitForAsyncOperation();
854 EXPECT_EQ(GCMClient::SUCCESS, wrapper_->unregistration_result()); 854 EXPECT_EQ(RESULT_SUCCESS, wrapper_->unregistration_result());
855 855
856 // Test that it is ok to register again after unregistration. 856 // Test that it is ok to register again after unregistration.
857 wrapper_->Register(kTestAppID1, sender_ids, TestGCMServiceWrapper::WAIT); 857 wrapper_->Register(kTestAppID1, sender_ids, TestGCMServiceWrapper::WAIT);
858 EXPECT_EQ(GCMClient::SUCCESS, wrapper_->registration_result()); 858 EXPECT_EQ(RESULT_SUCCESS, wrapper_->registration_result());
859 } 859 }
860 860
861 TEST_F(GCMServiceSingleInstanceTest, Send) { 861 TEST_F(GCMServiceSingleInstanceTest, Send) {
862 GCMClient::OutgoingMessage message; 862 OutgoingMessage message;
863 message.id = "1"; 863 message.id = "1";
864 message.data["key1"] = "value1"; 864 message.data["key1"] = "value1";
865 message.data["key2"] = "value2"; 865 message.data["key2"] = "value2";
866 wrapper_->Send(kTestAppID1, kUserID1, message, TestGCMServiceWrapper::WAIT); 866 wrapper_->Send(kTestAppID1, kUserID1, message, TestGCMServiceWrapper::WAIT);
867 867
868 EXPECT_EQ(message.id, wrapper_->send_message_id()); 868 EXPECT_EQ(message.id, wrapper_->send_message_id());
869 EXPECT_EQ(GCMClient::SUCCESS, wrapper_->send_result()); 869 EXPECT_EQ(RESULT_SUCCESS, wrapper_->send_result());
870 } 870 }
871 871
872 TEST_F(GCMServiceSingleInstanceTest, GCMClientNotReadyBeforeSending) { 872 TEST_F(GCMServiceSingleInstanceTest, GCMClientNotReadyBeforeSending) {
873 // Make GCMClient not ready initially. 873 // Make GCMClient not ready initially.
874 wrapper_.reset(new TestGCMServiceWrapper(request_context_)); 874 wrapper_.reset(new TestGCMServiceWrapper(request_context_));
875 wrapper_->CreateService(true, GCMClientMock::DELAY_LOADING); 875 wrapper_->CreateService(true, GCMClientMock::DELAY_LOADING);
876 wrapper_->SignIn(kTestAccountID1); 876 wrapper_->SignIn(kTestAccountID1);
877 877
878 // The sending is on hold until GCMClient is ready. 878 // The sending is on hold until GCMClient is ready.
879 GCMClient::OutgoingMessage message; 879 OutgoingMessage message;
880 message.id = "1"; 880 message.id = "1";
881 message.data["key1"] = "value1"; 881 message.data["key1"] = "value1";
882 message.data["key2"] = "value2"; 882 message.data["key2"] = "value2";
883 wrapper_->Send(kTestAppID1, 883 wrapper_->Send(kTestAppID1,
884 kUserID1, 884 kUserID1,
885 message, 885 message,
886 TestGCMServiceWrapper::DO_NOT_WAIT); 886 TestGCMServiceWrapper::DO_NOT_WAIT);
887 PumpIOLoop(); 887 PumpIOLoop();
888 PumpUILoop(); 888 PumpUILoop();
889 889
890 EXPECT_TRUE(wrapper_->send_message_id().empty()); 890 EXPECT_TRUE(wrapper_->send_message_id().empty());
891 EXPECT_EQ(GCMClient::UNKNOWN_ERROR, wrapper_->send_result()); 891 EXPECT_EQ(RESULT_UNKNOWN_ERROR, wrapper_->send_result());
892 892
893 // Send operation will be invoked after GCMClient becomes ready. 893 // Send operation will be invoked after GCMClient becomes ready.
894 wrapper_->GetGCMClient()->PerformDelayedLoading(); 894 wrapper_->GetGCMClient()->PerformDelayedLoading();
895 wrapper_->WaitForAsyncOperation(); 895 wrapper_->WaitForAsyncOperation();
896 EXPECT_EQ(message.id, wrapper_->send_message_id()); 896 EXPECT_EQ(message.id, wrapper_->send_message_id());
897 EXPECT_EQ(GCMClient::SUCCESS, wrapper_->send_result()); 897 EXPECT_EQ(RESULT_SUCCESS, wrapper_->send_result());
898 } 898 }
899 899
900 TEST_F(GCMServiceSingleInstanceTest, SendAfterSignOut) { 900 TEST_F(GCMServiceSingleInstanceTest, SendAfterSignOut) {
901 // This will trigger check-out. 901 // This will trigger check-out.
902 wrapper_->SignOut(); 902 wrapper_->SignOut();
903 903
904 GCMClient::OutgoingMessage message; 904 OutgoingMessage message;
905 message.id = "1"; 905 message.id = "1";
906 message.data["key1"] = "value1"; 906 message.data["key1"] = "value1";
907 message.data["key2"] = "value2"; 907 message.data["key2"] = "value2";
908 wrapper_->Send(kTestAppID1, kUserID1, message, TestGCMServiceWrapper::WAIT); 908 wrapper_->Send(kTestAppID1, kUserID1, message, TestGCMServiceWrapper::WAIT);
909 909
910 EXPECT_TRUE(wrapper_->send_message_id().empty()); 910 EXPECT_TRUE(wrapper_->send_message_id().empty());
911 EXPECT_EQ(GCMClient::NOT_SIGNED_IN, wrapper_->send_result()); 911 EXPECT_EQ(RESULT_NOT_SIGNED_IN, wrapper_->send_result());
912 } 912 }
913 913
914 TEST_F(GCMServiceSingleInstanceTest, SendError) { 914 TEST_F(GCMServiceSingleInstanceTest, SendError) {
915 GCMClient::OutgoingMessage message; 915 OutgoingMessage message;
916 // Embedding error in id will tell the mock to simulate the send error. 916 // Embedding error in id will tell the mock to simulate the send error.
917 message.id = "1@error"; 917 message.id = "1@error";
918 message.data["key1"] = "value1"; 918 message.data["key1"] = "value1";
919 message.data["key2"] = "value2"; 919 message.data["key2"] = "value2";
920 wrapper_->Send(kTestAppID1, kUserID1, message, TestGCMServiceWrapper::WAIT); 920 wrapper_->Send(kTestAppID1, kUserID1, message, TestGCMServiceWrapper::WAIT);
921 921
922 EXPECT_EQ(message.id, wrapper_->send_message_id()); 922 EXPECT_EQ(message.id, wrapper_->send_message_id());
923 EXPECT_EQ(GCMClient::SUCCESS, wrapper_->send_result()); 923 EXPECT_EQ(RESULT_SUCCESS, wrapper_->send_result());
924 924
925 // Wait for the send error. 925 // Wait for the send error.
926 wrapper_->gcm_app_handler()->WaitForNotification(); 926 wrapper_->gcm_app_handler()->WaitForNotification();
927 EXPECT_EQ(FakeGCMAppHandler::SEND_ERROR_EVENT, 927 EXPECT_EQ(FakeGCMAppHandler::SEND_ERROR_EVENT,
928 wrapper_->gcm_app_handler()->received_event()); 928 wrapper_->gcm_app_handler()->received_event());
929 EXPECT_EQ(kTestAppID1, wrapper_->gcm_app_handler()->app_id()); 929 EXPECT_EQ(kTestAppID1, wrapper_->gcm_app_handler()->app_id());
930 EXPECT_EQ(message.id, 930 EXPECT_EQ(message.id,
931 wrapper_->gcm_app_handler()->send_error_details().message_id); 931 wrapper_->gcm_app_handler()->send_error_details().message_id);
932 EXPECT_NE(GCMClient::SUCCESS, 932 EXPECT_NE(RESULT_SUCCESS,
933 wrapper_->gcm_app_handler()->send_error_details().result); 933 wrapper_->gcm_app_handler()->send_error_details().result);
934 EXPECT_EQ(message.data, 934 EXPECT_EQ(message.data,
935 wrapper_->gcm_app_handler()->send_error_details().additional_data); 935 wrapper_->gcm_app_handler()->send_error_details().additional_data);
936 } 936 }
937 937
938 TEST_F(GCMServiceSingleInstanceTest, MessageReceived) { 938 TEST_F(GCMServiceSingleInstanceTest, MessageReceived) {
939 wrapper_->Register(kTestAppID1, 939 wrapper_->Register(kTestAppID1,
940 ToSenderList("sender"), 940 ToSenderList("sender"),
941 TestGCMServiceWrapper::WAIT); 941 TestGCMServiceWrapper::WAIT);
942 GCMClient::IncomingMessage message; 942 IncomingMessage message;
943 message.data["key1"] = "value1"; 943 message.data["key1"] = "value1";
944 message.data["key2"] = "value2"; 944 message.data["key2"] = "value2";
945 message.sender_id = "sender"; 945 message.sender_id = "sender";
946 wrapper_->GetGCMClient()->ReceiveMessage(kTestAppID1, message); 946 wrapper_->GetGCMClient()->ReceiveMessage(kTestAppID1, message);
947 wrapper_->gcm_app_handler()->WaitForNotification(); 947 wrapper_->gcm_app_handler()->WaitForNotification();
948 EXPECT_EQ(FakeGCMAppHandler::MESSAGE_EVENT, 948 EXPECT_EQ(FakeGCMAppHandler::MESSAGE_EVENT,
949 wrapper_->gcm_app_handler()->received_event()); 949 wrapper_->gcm_app_handler()->received_event());
950 EXPECT_EQ(kTestAppID1, wrapper_->gcm_app_handler()->app_id()); 950 EXPECT_EQ(kTestAppID1, wrapper_->gcm_app_handler()->app_id());
951 EXPECT_EQ(message.data, wrapper_->gcm_app_handler()->message().data); 951 EXPECT_EQ(message.data, wrapper_->gcm_app_handler()->message().data);
952 EXPECT_TRUE(wrapper_->gcm_app_handler()->message().collapse_key.empty()); 952 EXPECT_TRUE(wrapper_->gcm_app_handler()->message().collapse_key.empty());
953 EXPECT_EQ(message.sender_id, 953 EXPECT_EQ(message.sender_id,
954 wrapper_->gcm_app_handler()->message().sender_id); 954 wrapper_->gcm_app_handler()->message().sender_id);
955 } 955 }
956 956
957 TEST_F(GCMServiceSingleInstanceTest, MessageWithCollapseKeyReceived) { 957 TEST_F(GCMServiceSingleInstanceTest, MessageWithCollapseKeyReceived) {
958 wrapper_->Register(kTestAppID1, 958 wrapper_->Register(kTestAppID1,
959 ToSenderList("sender"), 959 ToSenderList("sender"),
960 TestGCMServiceWrapper::WAIT); 960 TestGCMServiceWrapper::WAIT);
961 GCMClient::IncomingMessage message; 961 IncomingMessage message;
962 message.data["key1"] = "value1"; 962 message.data["key1"] = "value1";
963 message.collapse_key = "collapse_key_value"; 963 message.collapse_key = "collapse_key_value";
964 message.sender_id = "sender"; 964 message.sender_id = "sender";
965 wrapper_->GetGCMClient()->ReceiveMessage(kTestAppID1, message); 965 wrapper_->GetGCMClient()->ReceiveMessage(kTestAppID1, message);
966 wrapper_->gcm_app_handler()->WaitForNotification(); 966 wrapper_->gcm_app_handler()->WaitForNotification();
967 EXPECT_EQ(FakeGCMAppHandler::MESSAGE_EVENT, 967 EXPECT_EQ(FakeGCMAppHandler::MESSAGE_EVENT,
968 wrapper_->gcm_app_handler()->received_event()); 968 wrapper_->gcm_app_handler()->received_event());
969 EXPECT_EQ(kTestAppID1, wrapper_->gcm_app_handler()->app_id()); 969 EXPECT_EQ(kTestAppID1, wrapper_->gcm_app_handler()->app_id());
970 EXPECT_EQ(message.data, wrapper_->gcm_app_handler()->message().data); 970 EXPECT_EQ(message.data, wrapper_->gcm_app_handler()->message().data);
971 EXPECT_EQ(message.collapse_key, 971 EXPECT_EQ(message.collapse_key,
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
1027 wrapper_->Register(kTestAppID1, sender_ids, TestGCMServiceWrapper::WAIT); 1027 wrapper_->Register(kTestAppID1, sender_ids, TestGCMServiceWrapper::WAIT);
1028 1028
1029 // Register the same app in a different instance. 1029 // Register the same app in a different instance.
1030 std::vector<std::string> sender_ids2; 1030 std::vector<std::string> sender_ids2;
1031 sender_ids2.push_back("foo"); 1031 sender_ids2.push_back("foo");
1032 sender_ids2.push_back("bar"); 1032 sender_ids2.push_back("bar");
1033 wrapper2_->Register(kTestAppID1, sender_ids2, TestGCMServiceWrapper::WAIT); 1033 wrapper2_->Register(kTestAppID1, sender_ids2, TestGCMServiceWrapper::WAIT);
1034 1034
1035 EXPECT_EQ(GCMClientMock::GetRegistrationIdFromSenderIds(sender_ids), 1035 EXPECT_EQ(GCMClientMock::GetRegistrationIdFromSenderIds(sender_ids),
1036 wrapper_->registration_id()); 1036 wrapper_->registration_id());
1037 EXPECT_EQ(GCMClient::SUCCESS, wrapper_->registration_result()); 1037 EXPECT_EQ(RESULT_SUCCESS, wrapper_->registration_result());
1038 1038
1039 EXPECT_EQ(GCMClientMock::GetRegistrationIdFromSenderIds(sender_ids2), 1039 EXPECT_EQ(GCMClientMock::GetRegistrationIdFromSenderIds(sender_ids2),
1040 wrapper2_->registration_id()); 1040 wrapper2_->registration_id());
1041 EXPECT_EQ(GCMClient::SUCCESS, wrapper2_->registration_result()); 1041 EXPECT_EQ(RESULT_SUCCESS, wrapper2_->registration_result());
1042 1042
1043 // Register a different app in a different instance. 1043 // Register a different app in a different instance.
1044 std::vector<std::string> sender_ids3; 1044 std::vector<std::string> sender_ids3;
1045 sender_ids3.push_back("sender1"); 1045 sender_ids3.push_back("sender1");
1046 sender_ids3.push_back("sender2"); 1046 sender_ids3.push_back("sender2");
1047 sender_ids3.push_back("sender3"); 1047 sender_ids3.push_back("sender3");
1048 wrapper2_->Register(kTestAppID2, sender_ids3, TestGCMServiceWrapper::WAIT); 1048 wrapper2_->Register(kTestAppID2, sender_ids3, TestGCMServiceWrapper::WAIT);
1049 1049
1050 EXPECT_EQ(GCMClientMock::GetRegistrationIdFromSenderIds(sender_ids3), 1050 EXPECT_EQ(GCMClientMock::GetRegistrationIdFromSenderIds(sender_ids3),
1051 wrapper2_->registration_id()); 1051 wrapper2_->registration_id());
1052 EXPECT_EQ(GCMClient::SUCCESS, wrapper2_->registration_result()); 1052 EXPECT_EQ(RESULT_SUCCESS, wrapper2_->registration_result());
1053 } 1053 }
1054 1054
1055 TEST_F(GCMServiceMultipleInstanceTest, Send) { 1055 TEST_F(GCMServiceMultipleInstanceTest, Send) {
1056 // Send a message from one app in one instance. 1056 // Send a message from one app in one instance.
1057 GCMClient::OutgoingMessage message; 1057 OutgoingMessage message;
1058 message.id = "1"; 1058 message.id = "1";
1059 message.data["key1"] = "value1"; 1059 message.data["key1"] = "value1";
1060 message.data["key2"] = "value2"; 1060 message.data["key2"] = "value2";
1061 wrapper_->Send(kTestAppID1, kUserID1, message, TestGCMServiceWrapper::WAIT); 1061 wrapper_->Send(kTestAppID1, kUserID1, message, TestGCMServiceWrapper::WAIT);
1062 1062
1063 // Send a message from same app in another instance. 1063 // Send a message from same app in another instance.
1064 GCMClient::OutgoingMessage message2; 1064 OutgoingMessage message2;
1065 message2.id = "2"; 1065 message2.id = "2";
1066 message2.data["foo"] = "bar"; 1066 message2.data["foo"] = "bar";
1067 wrapper2_->Send(kTestAppID1, kUserID2, message2, TestGCMServiceWrapper::WAIT); 1067 wrapper2_->Send(kTestAppID1, kUserID2, message2, TestGCMServiceWrapper::WAIT);
1068 1068
1069 EXPECT_EQ(message.id, wrapper_->send_message_id()); 1069 EXPECT_EQ(message.id, wrapper_->send_message_id());
1070 EXPECT_EQ(GCMClient::SUCCESS, wrapper_->send_result()); 1070 EXPECT_EQ(RESULT_SUCCESS, wrapper_->send_result());
1071 1071
1072 EXPECT_EQ(message2.id, wrapper2_->send_message_id()); 1072 EXPECT_EQ(message2.id, wrapper2_->send_message_id());
1073 EXPECT_EQ(GCMClient::SUCCESS, wrapper2_->send_result()); 1073 EXPECT_EQ(RESULT_SUCCESS, wrapper2_->send_result());
1074 1074
1075 // Send another message from different app in another instance. 1075 // Send another message from different app in another instance.
1076 GCMClient::OutgoingMessage message3; 1076 OutgoingMessage message3;
1077 message3.id = "3"; 1077 message3.id = "3";
1078 message3.data["hello"] = "world"; 1078 message3.data["hello"] = "world";
1079 wrapper2_->Send(kTestAppID2, kUserID1, message3, TestGCMServiceWrapper::WAIT); 1079 wrapper2_->Send(kTestAppID2, kUserID1, message3, TestGCMServiceWrapper::WAIT);
1080 1080
1081 EXPECT_EQ(message3.id, wrapper2_->send_message_id()); 1081 EXPECT_EQ(message3.id, wrapper2_->send_message_id());
1082 EXPECT_EQ(GCMClient::SUCCESS, wrapper2_->send_result()); 1082 EXPECT_EQ(RESULT_SUCCESS, wrapper2_->send_result());
1083 } 1083 }
1084 1084
1085 TEST_F(GCMServiceMultipleInstanceTest, MessageReceived) { 1085 TEST_F(GCMServiceMultipleInstanceTest, MessageReceived) {
1086 wrapper_->Register(kTestAppID1, 1086 wrapper_->Register(kTestAppID1,
1087 ToSenderList("sender"), 1087 ToSenderList("sender"),
1088 TestGCMServiceWrapper::WAIT); 1088 TestGCMServiceWrapper::WAIT);
1089 wrapper2_->Register(kTestAppID1, 1089 wrapper2_->Register(kTestAppID1,
1090 ToSenderList("sender"), 1090 ToSenderList("sender"),
1091 TestGCMServiceWrapper::WAIT); 1091 TestGCMServiceWrapper::WAIT);
1092 wrapper2_->Register(kTestAppID2, 1092 wrapper2_->Register(kTestAppID2,
1093 ToSenderList("sender2"), 1093 ToSenderList("sender2"),
1094 TestGCMServiceWrapper::WAIT); 1094 TestGCMServiceWrapper::WAIT);
1095 1095
1096 // Trigger an incoming message for an app in one instance. 1096 // Trigger an incoming message for an app in one instance.
1097 GCMClient::IncomingMessage message; 1097 IncomingMessage message;
1098 message.data["key1"] = "value1"; 1098 message.data["key1"] = "value1";
1099 message.data["key2"] = "value2"; 1099 message.data["key2"] = "value2";
1100 message.sender_id = "sender"; 1100 message.sender_id = "sender";
1101 wrapper_->GetGCMClient()->ReceiveMessage(kTestAppID1, message); 1101 wrapper_->GetGCMClient()->ReceiveMessage(kTestAppID1, message);
1102 wrapper_->gcm_app_handler()->WaitForNotification(); 1102 wrapper_->gcm_app_handler()->WaitForNotification();
1103 1103
1104 // Trigger an incoming message for the same app in another instance. 1104 // Trigger an incoming message for the same app in another instance.
1105 GCMClient::IncomingMessage message2; 1105 IncomingMessage message2;
1106 message2.data["foo"] = "bar"; 1106 message2.data["foo"] = "bar";
1107 message2.sender_id = "sender"; 1107 message2.sender_id = "sender";
1108 wrapper2_->GetGCMClient()->ReceiveMessage(kTestAppID1, message2); 1108 wrapper2_->GetGCMClient()->ReceiveMessage(kTestAppID1, message2);
1109 wrapper2_->gcm_app_handler()->WaitForNotification(); 1109 wrapper2_->gcm_app_handler()->WaitForNotification();
1110 1110
1111 EXPECT_EQ(FakeGCMAppHandler::MESSAGE_EVENT, 1111 EXPECT_EQ(FakeGCMAppHandler::MESSAGE_EVENT,
1112 wrapper_->gcm_app_handler()->received_event()); 1112 wrapper_->gcm_app_handler()->received_event());
1113 EXPECT_EQ(kTestAppID1, wrapper_->gcm_app_handler()->app_id()); 1113 EXPECT_EQ(kTestAppID1, wrapper_->gcm_app_handler()->app_id());
1114 EXPECT_EQ(message.data, wrapper_->gcm_app_handler()->message().data); 1114 EXPECT_EQ(message.data, wrapper_->gcm_app_handler()->message().data);
1115 EXPECT_EQ("sender", wrapper_->gcm_app_handler()->message().sender_id); 1115 EXPECT_EQ("sender", wrapper_->gcm_app_handler()->message().sender_id);
1116 1116
1117 EXPECT_EQ(FakeGCMAppHandler::MESSAGE_EVENT, 1117 EXPECT_EQ(FakeGCMAppHandler::MESSAGE_EVENT,
1118 wrapper2_->gcm_app_handler()->received_event()); 1118 wrapper2_->gcm_app_handler()->received_event());
1119 EXPECT_EQ(kTestAppID1, wrapper2_->gcm_app_handler()->app_id()); 1119 EXPECT_EQ(kTestAppID1, wrapper2_->gcm_app_handler()->app_id());
1120 EXPECT_EQ(message2.data, wrapper2_->gcm_app_handler()->message().data); 1120 EXPECT_EQ(message2.data, wrapper2_->gcm_app_handler()->message().data);
1121 EXPECT_EQ("sender", wrapper2_->gcm_app_handler()->message().sender_id); 1121 EXPECT_EQ("sender", wrapper2_->gcm_app_handler()->message().sender_id);
1122 1122
1123 // Trigger another incoming message for a different app in another instance. 1123 // Trigger another incoming message for a different app in another instance.
1124 GCMClient::IncomingMessage message3; 1124 IncomingMessage message3;
1125 message3.data["bar1"] = "foo1"; 1125 message3.data["bar1"] = "foo1";
1126 message3.data["bar2"] = "foo2"; 1126 message3.data["bar2"] = "foo2";
1127 message3.sender_id = "sender2"; 1127 message3.sender_id = "sender2";
1128 wrapper2_->GetGCMClient()->ReceiveMessage(kTestAppID2, message3); 1128 wrapper2_->GetGCMClient()->ReceiveMessage(kTestAppID2, message3);
1129 wrapper2_->gcm_app_handler()->WaitForNotification(); 1129 wrapper2_->gcm_app_handler()->WaitForNotification();
1130 1130
1131 EXPECT_EQ(FakeGCMAppHandler::MESSAGE_EVENT, 1131 EXPECT_EQ(FakeGCMAppHandler::MESSAGE_EVENT,
1132 wrapper2_->gcm_app_handler()->received_event()); 1132 wrapper2_->gcm_app_handler()->received_event());
1133 EXPECT_EQ(kTestAppID2, wrapper2_->gcm_app_handler()->app_id()); 1133 EXPECT_EQ(kTestAppID2, wrapper2_->gcm_app_handler()->app_id());
1134 EXPECT_EQ(message3.data, wrapper2_->gcm_app_handler()->message().data); 1134 EXPECT_EQ(message3.data, wrapper2_->gcm_app_handler()->message().data);
(...skipping 25 matching lines...) Expand all
1160 1160
1161 // Register a different app in a different instance. 1161 // Register a different app in a different instance.
1162 std::vector<std::string> sender_ids3; 1162 std::vector<std::string> sender_ids3;
1163 sender_ids3.push_back("sender1"); 1163 sender_ids3.push_back("sender1");
1164 sender_ids3.push_back("sender2"); 1164 sender_ids3.push_back("sender2");
1165 sender_ids3.push_back("sender3"); 1165 sender_ids3.push_back("sender3");
1166 wrapper2_->Register(kTestAppID2, sender_ids3, TestGCMServiceWrapper::WAIT); 1166 wrapper2_->Register(kTestAppID2, sender_ids3, TestGCMServiceWrapper::WAIT);
1167 1167
1168 EXPECT_EQ(GCMClientMock::GetRegistrationIdFromSenderIds(sender_ids), 1168 EXPECT_EQ(GCMClientMock::GetRegistrationIdFromSenderIds(sender_ids),
1169 wrapper_->registration_id()); 1169 wrapper_->registration_id());
1170 EXPECT_EQ(GCMClient::SUCCESS, wrapper_->registration_result()); 1170 EXPECT_EQ(RESULT_SUCCESS, wrapper_->registration_result());
1171 1171
1172 EXPECT_EQ(GCMClientMock::GetRegistrationIdFromSenderIds(sender_ids3), 1172 EXPECT_EQ(GCMClientMock::GetRegistrationIdFromSenderIds(sender_ids3),
1173 wrapper2_->registration_id()); 1173 wrapper2_->registration_id());
1174 EXPECT_EQ(GCMClient::SUCCESS, wrapper2_->registration_result()); 1174 EXPECT_EQ(RESULT_SUCCESS, wrapper2_->registration_result());
1175 1175
1176 // Send a message from one instance. 1176 // Send a message from one instance.
1177 GCMClient::OutgoingMessage out_message; 1177 OutgoingMessage out_message;
1178 out_message.id = "1"; 1178 out_message.id = "1";
1179 out_message.data["out1"] = "out_data1"; 1179 out_message.data["out1"] = "out_data1";
1180 out_message.data["out1_2"] = "out_data1_2"; 1180 out_message.data["out1_2"] = "out_data1_2";
1181 wrapper_->Send(kTestAppID1, 1181 wrapper_->Send(kTestAppID1,
1182 kUserID1, 1182 kUserID1,
1183 out_message, 1183 out_message,
1184 TestGCMServiceWrapper::WAIT); 1184 TestGCMServiceWrapper::WAIT);
1185 1185
1186 EXPECT_EQ(out_message.id, wrapper_->send_message_id()); 1186 EXPECT_EQ(out_message.id, wrapper_->send_message_id());
1187 EXPECT_EQ(GCMClient::SUCCESS, wrapper_->send_result()); 1187 EXPECT_EQ(RESULT_SUCCESS, wrapper_->send_result());
1188 1188
1189 // Trigger an incoming message for an app in one instance. 1189 // Trigger an incoming message for an app in one instance.
1190 GCMClient::IncomingMessage in_message; 1190 IncomingMessage in_message;
1191 in_message.data["in1"] = "in_data1"; 1191 in_message.data["in1"] = "in_data1";
1192 in_message.data["in1_2"] = "in_data1_2"; 1192 in_message.data["in1_2"] = "in_data1_2";
1193 in_message.sender_id = "sender1"; 1193 in_message.sender_id = "sender1";
1194 wrapper_->GetGCMClient()->ReceiveMessage(kTestAppID1, in_message); 1194 wrapper_->GetGCMClient()->ReceiveMessage(kTestAppID1, in_message);
1195 wrapper_->gcm_app_handler()->WaitForNotification(); 1195 wrapper_->gcm_app_handler()->WaitForNotification();
1196 1196
1197 EXPECT_EQ(FakeGCMAppHandler::MESSAGE_EVENT, 1197 EXPECT_EQ(FakeGCMAppHandler::MESSAGE_EVENT,
1198 wrapper_->gcm_app_handler()->received_event()); 1198 wrapper_->gcm_app_handler()->received_event());
1199 EXPECT_EQ(kTestAppID1, wrapper_->gcm_app_handler()->app_id()); 1199 EXPECT_EQ(kTestAppID1, wrapper_->gcm_app_handler()->app_id());
1200 EXPECT_EQ(in_message.data, wrapper_->gcm_app_handler()->message().data); 1200 EXPECT_EQ(in_message.data, wrapper_->gcm_app_handler()->message().data);
1201 1201
1202 // Trigger 2 incoming messages, one for each app respectively, in another 1202 // Trigger 2 incoming messages, one for each app respectively, in another
1203 // instance. 1203 // instance.
1204 GCMClient::IncomingMessage in_message2; 1204 IncomingMessage in_message2;
1205 in_message2.data["in2"] = "in_data2"; 1205 in_message2.data["in2"] = "in_data2";
1206 in_message2.sender_id = "sender3"; 1206 in_message2.sender_id = "sender3";
1207 wrapper2_->GetGCMClient()->ReceiveMessage(kTestAppID2, in_message2); 1207 wrapper2_->GetGCMClient()->ReceiveMessage(kTestAppID2, in_message2);
1208 1208
1209 GCMClient::IncomingMessage in_message3; 1209 IncomingMessage in_message3;
1210 in_message3.data["in3"] = "in_data3"; 1210 in_message3.data["in3"] = "in_data3";
1211 in_message3.data["in3_2"] = "in_data3_2"; 1211 in_message3.data["in3_2"] = "in_data3_2";
1212 in_message3.sender_id = "foo"; 1212 in_message3.sender_id = "foo";
1213 wrapper2_->GetGCMClient()->ReceiveMessage(kTestAppID1, in_message3); 1213 wrapper2_->GetGCMClient()->ReceiveMessage(kTestAppID1, in_message3);
1214 1214
1215 wrapper2_->gcm_app_handler()->WaitForNotification(); 1215 wrapper2_->gcm_app_handler()->WaitForNotification();
1216 1216
1217 EXPECT_EQ(FakeGCMAppHandler::MESSAGE_EVENT, 1217 EXPECT_EQ(FakeGCMAppHandler::MESSAGE_EVENT,
1218 wrapper2_->gcm_app_handler()->received_event()); 1218 wrapper2_->gcm_app_handler()->received_event());
1219 EXPECT_EQ(kTestAppID2, wrapper2_->gcm_app_handler()->app_id()); 1219 EXPECT_EQ(kTestAppID2, wrapper2_->gcm_app_handler()->app_id());
1220 EXPECT_EQ(in_message2.data, wrapper2_->gcm_app_handler()->message().data); 1220 EXPECT_EQ(in_message2.data, wrapper2_->gcm_app_handler()->message().data);
1221 1221
1222 wrapper2_->gcm_app_handler()->WaitForNotification(); 1222 wrapper2_->gcm_app_handler()->WaitForNotification();
1223 1223
1224 EXPECT_EQ(FakeGCMAppHandler::MESSAGE_EVENT, 1224 EXPECT_EQ(FakeGCMAppHandler::MESSAGE_EVENT,
1225 wrapper2_->gcm_app_handler()->received_event()); 1225 wrapper2_->gcm_app_handler()->received_event());
1226 EXPECT_EQ(kTestAppID1, wrapper2_->gcm_app_handler()->app_id()); 1226 EXPECT_EQ(kTestAppID1, wrapper2_->gcm_app_handler()->app_id());
1227 EXPECT_EQ(in_message3.data, wrapper2_->gcm_app_handler()->message().data); 1227 EXPECT_EQ(in_message3.data, wrapper2_->gcm_app_handler()->message().data);
1228 1228
1229 // Send two messages, one for each app respectively, from another instance. 1229 // Send two messages, one for each app respectively, from another instance.
1230 GCMClient::OutgoingMessage out_message2; 1230 OutgoingMessage out_message2;
1231 out_message2.id = "2"; 1231 out_message2.id = "2";
1232 out_message2.data["out2"] = "out_data2"; 1232 out_message2.data["out2"] = "out_data2";
1233 wrapper2_->Send(kTestAppID1, 1233 wrapper2_->Send(kTestAppID1,
1234 kUserID2, 1234 kUserID2,
1235 out_message2, 1235 out_message2,
1236 TestGCMServiceWrapper::WAIT); 1236 TestGCMServiceWrapper::WAIT);
1237 1237
1238 GCMClient::OutgoingMessage out_message3; 1238 OutgoingMessage out_message3;
1239 out_message3.id = "3"; 1239 out_message3.id = "3";
1240 out_message3.data["out3"] = "out_data3"; 1240 out_message3.data["out3"] = "out_data3";
1241 wrapper2_->Send(kTestAppID2, 1241 wrapper2_->Send(kTestAppID2,
1242 kUserID2, 1242 kUserID2,
1243 out_message3, 1243 out_message3,
1244 TestGCMServiceWrapper::DO_NOT_WAIT); 1244 TestGCMServiceWrapper::DO_NOT_WAIT);
1245 1245
1246 EXPECT_EQ(out_message2.id, wrapper2_->send_message_id()); 1246 EXPECT_EQ(out_message2.id, wrapper2_->send_message_id());
1247 EXPECT_EQ(GCMClient::SUCCESS, wrapper2_->send_result()); 1247 EXPECT_EQ(RESULT_SUCCESS, wrapper2_->send_result());
1248 1248
1249 wrapper2_->WaitForAsyncOperation(); 1249 wrapper2_->WaitForAsyncOperation();
1250 1250
1251 EXPECT_EQ(out_message3.id, wrapper2_->send_message_id()); 1251 EXPECT_EQ(out_message3.id, wrapper2_->send_message_id());
1252 EXPECT_EQ(GCMClient::SUCCESS, wrapper2_->send_result()); 1252 EXPECT_EQ(RESULT_SUCCESS, wrapper2_->send_result());
1253 1253
1254 // Sign out of one instance. 1254 // Sign out of one instance.
1255 wrapper_->SignOut(); 1255 wrapper_->SignOut();
1256 1256
1257 // Register/send stops working for signed-out instance. 1257 // Register/send stops working for signed-out instance.
1258 wrapper_->Register(kTestAppID1, sender_ids, TestGCMServiceWrapper::WAIT); 1258 wrapper_->Register(kTestAppID1, sender_ids, TestGCMServiceWrapper::WAIT);
1259 EXPECT_TRUE(wrapper_->registration_id().empty()); 1259 EXPECT_TRUE(wrapper_->registration_id().empty());
1260 EXPECT_EQ(GCMClient::NOT_SIGNED_IN, wrapper_->registration_result()); 1260 EXPECT_EQ(RESULT_NOT_SIGNED_IN, wrapper_->registration_result());
1261 1261
1262 wrapper_->Send(kTestAppID2, 1262 wrapper_->Send(kTestAppID2,
1263 kUserID2, 1263 kUserID2,
1264 out_message3, 1264 out_message3,
1265 TestGCMServiceWrapper::WAIT); 1265 TestGCMServiceWrapper::WAIT);
1266 EXPECT_TRUE(wrapper_->send_message_id().empty()); 1266 EXPECT_TRUE(wrapper_->send_message_id().empty());
1267 EXPECT_EQ(GCMClient::NOT_SIGNED_IN, wrapper_->send_result()); 1267 EXPECT_EQ(RESULT_NOT_SIGNED_IN, wrapper_->send_result());
1268 1268
1269 // Deleted messages event will go through for another signed-in instance. 1269 // Deleted messages event will go through for another signed-in instance.
1270 wrapper2_->GetGCMClient()->DeleteMessages(kTestAppID2); 1270 wrapper2_->GetGCMClient()->DeleteMessages(kTestAppID2);
1271 wrapper2_->gcm_app_handler()->WaitForNotification(); 1271 wrapper2_->gcm_app_handler()->WaitForNotification();
1272 1272
1273 EXPECT_EQ(FakeGCMAppHandler::MESSAGES_DELETED_EVENT, 1273 EXPECT_EQ(FakeGCMAppHandler::MESSAGES_DELETED_EVENT,
1274 wrapper2_->gcm_app_handler()->received_event()); 1274 wrapper2_->gcm_app_handler()->received_event());
1275 EXPECT_EQ(kTestAppID2, wrapper2_->gcm_app_handler()->app_id()); 1275 EXPECT_EQ(kTestAppID2, wrapper2_->gcm_app_handler()->app_id());
1276 1276
1277 // Send error event will go through for another signed-in instance. 1277 // Send error event will go through for another signed-in instance.
1278 GCMClient::OutgoingMessage out_message4; 1278 OutgoingMessage out_message4;
1279 out_message4.id = "1@error"; 1279 out_message4.id = "1@error";
1280 out_message4.data["out4"] = "out_data4"; 1280 out_message4.data["out4"] = "out_data4";
1281 wrapper2_->Send(kTestAppID1, 1281 wrapper2_->Send(kTestAppID1,
1282 kUserID1, 1282 kUserID1,
1283 out_message4, 1283 out_message4,
1284 TestGCMServiceWrapper::WAIT); 1284 TestGCMServiceWrapper::WAIT);
1285 1285
1286 EXPECT_EQ(out_message4.id, wrapper2_->send_message_id()); 1286 EXPECT_EQ(out_message4.id, wrapper2_->send_message_id());
1287 EXPECT_EQ(GCMClient::SUCCESS, wrapper2_->send_result()); 1287 EXPECT_EQ(RESULT_SUCCESS, wrapper2_->send_result());
1288 1288
1289 wrapper2_->gcm_app_handler()->WaitForNotification(); 1289 wrapper2_->gcm_app_handler()->WaitForNotification();
1290 EXPECT_EQ(FakeGCMAppHandler::SEND_ERROR_EVENT, 1290 EXPECT_EQ(FakeGCMAppHandler::SEND_ERROR_EVENT,
1291 wrapper2_->gcm_app_handler()->received_event()); 1291 wrapper2_->gcm_app_handler()->received_event());
1292 EXPECT_EQ(kTestAppID1, wrapper2_->gcm_app_handler()->app_id()); 1292 EXPECT_EQ(kTestAppID1, wrapper2_->gcm_app_handler()->app_id());
1293 EXPECT_EQ(out_message4.id, 1293 EXPECT_EQ(out_message4.id,
1294 wrapper2_->gcm_app_handler()->send_error_details().message_id); 1294 wrapper2_->gcm_app_handler()->send_error_details().message_id);
1295 EXPECT_NE(GCMClient::SUCCESS, 1295 EXPECT_NE(RESULT_SUCCESS,
1296 wrapper2_->gcm_app_handler()->send_error_details().result); 1296 wrapper2_->gcm_app_handler()->send_error_details().result);
1297 EXPECT_EQ(out_message4.data, 1297 EXPECT_EQ(out_message4.data,
1298 wrapper2_->gcm_app_handler()->send_error_details().additional_data); 1298 wrapper2_->gcm_app_handler()->send_error_details().additional_data);
1299 1299
1300 // Sign in with a different account. 1300 // Sign in with a different account.
1301 wrapper_->SignIn(kTestAccountID3); 1301 wrapper_->SignIn(kTestAccountID3);
1302 1302
1303 // Signing out cleared all registrations, so we need to register again. 1303 // Signing out cleared all registrations, so we need to register again.
1304 wrapper_->Register(kTestAppID1, 1304 wrapper_->Register(kTestAppID1,
1305 ToSenderList("sender1"), 1305 ToSenderList("sender1"),
1306 TestGCMServiceWrapper::WAIT); 1306 TestGCMServiceWrapper::WAIT);
1307 1307
1308 // Incoming message will go through for the new signed-in account. 1308 // Incoming message will go through for the new signed-in account.
1309 GCMClient::IncomingMessage in_message5; 1309 IncomingMessage in_message5;
1310 in_message5.data["in5"] = "in_data5"; 1310 in_message5.data["in5"] = "in_data5";
1311 in_message5.sender_id = "sender1"; 1311 in_message5.sender_id = "sender1";
1312 wrapper_->GetGCMClient()->ReceiveMessage(kTestAppID1, in_message5); 1312 wrapper_->GetGCMClient()->ReceiveMessage(kTestAppID1, in_message5);
1313 1313
1314 wrapper_->gcm_app_handler()->WaitForNotification(); 1314 wrapper_->gcm_app_handler()->WaitForNotification();
1315 1315
1316 EXPECT_EQ(FakeGCMAppHandler::MESSAGE_EVENT, 1316 EXPECT_EQ(FakeGCMAppHandler::MESSAGE_EVENT,
1317 wrapper_->gcm_app_handler()->received_event()); 1317 wrapper_->gcm_app_handler()->received_event());
1318 EXPECT_EQ(in_message5.data, wrapper_->gcm_app_handler()->message().data); 1318 EXPECT_EQ(in_message5.data, wrapper_->gcm_app_handler()->message().data);
1319 } 1319 }
1320 1320
1321 } // namespace gcm 1321 } // namespace gcm
OLDNEW
« no previous file with comments | « chrome/browser/services/gcm/gcm_service.cc ('k') | google_apis/gcm/gcm.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698