| 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 "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 216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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::StartMode gcm_client_start_mode); |
| 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 GCMClient::OutgoingMessage& message, |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 |
| 314 void TestGCMServiceWrapper::CreateService( | 314 void TestGCMServiceWrapper::CreateService( |
| 315 bool start_automatically, | 315 bool start_automatically, |
| 316 GCMClientMock::LoadingDelay gcm_client_loading_delay) { | 316 GCMClientMock::StartMode gcm_client_start_mode) { |
| 317 service_.reset(new TestGCMService( | 317 service_.reset(new TestGCMService( |
| 318 start_automatically, | 318 start_automatically, |
| 319 identity_provider_owner_.PassAs<IdentityProvider>(), | 319 identity_provider_owner_.PassAs<IdentityProvider>(), |
| 320 request_context_)); | 320 request_context_)); |
| 321 service_->Initialize(scoped_ptr<GCMClientFactory>( | 321 service_->Initialize(scoped_ptr<GCMClientFactory>( |
| 322 new FakeGCMClientFactory(gcm_client_loading_delay))); | 322 new FakeGCMClientFactory(gcm_client_start_mode))); |
| 323 | 323 |
| 324 gcm_app_handler_.reset(new FakeGCMAppHandler); | 324 gcm_app_handler_.reset(new FakeGCMAppHandler); |
| 325 service_->AddAppHandler(kTestAppID1, gcm_app_handler_.get()); | 325 service_->AddAppHandler(kTestAppID1, gcm_app_handler_.get()); |
| 326 service_->AddAppHandler(kTestAppID2, gcm_app_handler_.get()); | 326 service_->AddAppHandler(kTestAppID2, gcm_app_handler_.get()); |
| 327 } | 327 } |
| 328 | 328 |
| 329 void TestGCMServiceWrapper::SignIn(const std::string& account_id) { | 329 void TestGCMServiceWrapper::SignIn(const std::string& account_id) { |
| 330 token_service_.AddAccount(account_id); | 330 token_service_.AddAccount(account_id); |
| 331 identity_provider_->LogIn(account_id); | 331 identity_provider_->LogIn(account_id); |
| 332 PumpIOLoop(); | 332 PumpIOLoop(); |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 438 content::BrowserThread::IO)); | 438 content::BrowserThread::IO)); |
| 439 wrapper_.reset(new TestGCMServiceWrapper(request_context_)); | 439 wrapper_.reset(new TestGCMServiceWrapper(request_context_)); |
| 440 } | 440 } |
| 441 | 441 |
| 442 void GCMServiceTest::TearDown() { | 442 void GCMServiceTest::TearDown() { |
| 443 wrapper_.reset(); | 443 wrapper_.reset(); |
| 444 } | 444 } |
| 445 | 445 |
| 446 TEST_F(GCMServiceTest, CreateGCMServiceBeforeSignIn) { | 446 TEST_F(GCMServiceTest, CreateGCMServiceBeforeSignIn) { |
| 447 // Create CreateGMCService first. | 447 // Create CreateGMCService first. |
| 448 wrapper_->CreateService(true, GCMClientMock::NO_DELAY_LOADING); | 448 wrapper_->CreateService(true, GCMClientMock::NO_DELAY_START); |
| 449 EXPECT_FALSE(wrapper_->service()->IsStarted()); | 449 EXPECT_FALSE(wrapper_->service()->IsStarted()); |
| 450 | 450 |
| 451 // Sign in. This will kick off the check-in. | 451 // Sign in. This will kick off the check-in. |
| 452 wrapper_->SignIn(kTestAccountID1); | 452 wrapper_->SignIn(kTestAccountID1); |
| 453 EXPECT_TRUE(wrapper_->service()->IsStarted()); | 453 EXPECT_TRUE(wrapper_->service()->IsStarted()); |
| 454 } | 454 } |
| 455 | 455 |
| 456 TEST_F(GCMServiceTest, CreateGCMServiceAfterSignIn) { | 456 TEST_F(GCMServiceTest, CreateGCMServiceAfterSignIn) { |
| 457 // Sign in. This will not initiate the check-in. | 457 // Sign in. This will not initiate the check-in. |
| 458 wrapper_->SignIn(kTestAccountID1); | 458 wrapper_->SignIn(kTestAccountID1); |
| 459 | 459 |
| 460 // Create GCMeService after sign-in. | 460 // Create GCMeService after sign-in. |
| 461 wrapper_->CreateService(true, GCMClientMock::NO_DELAY_LOADING); | 461 wrapper_->CreateService(true, GCMClientMock::NO_DELAY_START); |
| 462 EXPECT_TRUE(wrapper_->service()->IsStarted()); | 462 EXPECT_TRUE(wrapper_->service()->IsStarted()); |
| 463 } | 463 } |
| 464 | 464 |
| 465 TEST_F(GCMServiceTest, Shutdown) { | 465 TEST_F(GCMServiceTest, Shutdown) { |
| 466 wrapper_->CreateService(true, GCMClientMock::NO_DELAY_LOADING); | 466 wrapper_->CreateService(true, GCMClientMock::NO_DELAY_START); |
| 467 EXPECT_TRUE(wrapper_->ServiceHasAppHandlers()); | 467 EXPECT_TRUE(wrapper_->ServiceHasAppHandlers()); |
| 468 | 468 |
| 469 wrapper_->service()->ShutdownService(); | 469 wrapper_->service()->ShutdownService(); |
| 470 EXPECT_FALSE(wrapper_->ServiceHasAppHandlers()); | 470 EXPECT_FALSE(wrapper_->ServiceHasAppHandlers()); |
| 471 } | 471 } |
| 472 | 472 |
| 473 TEST_F(GCMServiceTest, SignInAndSignOutUnderPositiveChannelSignal) { | 473 TEST_F(GCMServiceTest, SignInAndSignOutUnderPositiveChannelSignal) { |
| 474 wrapper_->CreateService(true, GCMClientMock::NO_DELAY_LOADING); | 474 wrapper_->CreateService(true, GCMClientMock::NO_DELAY_START); |
| 475 wrapper_->SignIn(kTestAccountID1); | 475 wrapper_->SignIn(kTestAccountID1); |
| 476 | 476 |
| 477 // GCMClient should be loaded. | 477 // GCMClient should be loaded. |
| 478 EXPECT_TRUE(wrapper_->service()->IsGCMClientReady()); | 478 EXPECT_TRUE(wrapper_->service()->IsGCMClientReady()); |
| 479 EXPECT_EQ(GCMClientMock::LOADED, wrapper_->GetGCMClient()->status()); | 479 EXPECT_EQ(GCMClientMock::STARTED, wrapper_->GetGCMClient()->status()); |
| 480 | 480 |
| 481 wrapper_->SignOut(); | 481 wrapper_->SignOut(); |
| 482 | 482 |
| 483 // GCMClient should be checked out. | 483 // GCMClient should be checked out. |
| 484 EXPECT_FALSE(wrapper_->service()->IsGCMClientReady()); | 484 EXPECT_FALSE(wrapper_->service()->IsGCMClientReady()); |
| 485 EXPECT_EQ(GCMClientMock::CHECKED_OUT, wrapper_->GetGCMClient()->status()); | 485 EXPECT_EQ(GCMClientMock::CHECKED_OUT, wrapper_->GetGCMClient()->status()); |
| 486 } | 486 } |
| 487 | 487 |
| 488 TEST_F(GCMServiceTest, SignInAndSignOutUnderNonPositiveChannelSignal) { | 488 TEST_F(GCMServiceTest, SignInAndSignOutUnderNonPositiveChannelSignal) { |
| 489 // Non-positive channel signal will prevent GCMClient from checking in during | 489 // Non-positive channel signal will prevent GCMClient from checking in during |
| 490 // sign-in. | 490 // sign-in. |
| 491 wrapper_->CreateService(false, GCMClientMock::NO_DELAY_LOADING); | 491 wrapper_->CreateService(false, GCMClientMock::NO_DELAY_START); |
| 492 wrapper_->SignIn(kTestAccountID1); | 492 wrapper_->SignIn(kTestAccountID1); |
| 493 | 493 |
| 494 // GCMClient should not be loaded. | 494 // GCMClient should not be loaded. |
| 495 EXPECT_FALSE(wrapper_->service()->IsGCMClientReady()); | 495 EXPECT_FALSE(wrapper_->service()->IsGCMClientReady()); |
| 496 EXPECT_EQ(GCMClientMock::UNINITIALIZED, wrapper_->GetGCMClient()->status()); | 496 EXPECT_EQ(GCMClientMock::UNINITIALIZED, wrapper_->GetGCMClient()->status()); |
| 497 | 497 |
| 498 wrapper_->SignOut(); | 498 wrapper_->SignOut(); |
| 499 | 499 |
| 500 // Check-out should still be performed. | 500 // Check-out should still be performed. |
| 501 EXPECT_FALSE(wrapper_->service()->IsGCMClientReady()); | 501 EXPECT_FALSE(wrapper_->service()->IsGCMClientReady()); |
| 502 EXPECT_EQ(GCMClientMock::CHECKED_OUT, wrapper_->GetGCMClient()->status()); | 502 EXPECT_EQ(GCMClientMock::CHECKED_OUT, wrapper_->GetGCMClient()->status()); |
| 503 } | 503 } |
| 504 | 504 |
| 505 TEST_F(GCMServiceTest, SignOutAndThenSignIn) { | 505 TEST_F(GCMServiceTest, SignOutAndThenSignIn) { |
| 506 wrapper_->CreateService(true, GCMClientMock::NO_DELAY_LOADING); | 506 wrapper_->CreateService(true, GCMClientMock::NO_DELAY_START); |
| 507 wrapper_->SignIn(kTestAccountID1); | 507 wrapper_->SignIn(kTestAccountID1); |
| 508 | 508 |
| 509 // GCMClient should be loaded. | 509 // GCMClient should be loaded. |
| 510 EXPECT_TRUE(wrapper_->service()->IsGCMClientReady()); | 510 EXPECT_TRUE(wrapper_->service()->IsGCMClientReady()); |
| 511 EXPECT_EQ(GCMClientMock::LOADED, wrapper_->GetGCMClient()->status()); | 511 EXPECT_EQ(GCMClientMock::STARTED, wrapper_->GetGCMClient()->status()); |
| 512 | 512 |
| 513 wrapper_->SignOut(); | 513 wrapper_->SignOut(); |
| 514 | 514 |
| 515 // GCMClient should be checked out. | 515 // GCMClient should be checked out. |
| 516 EXPECT_FALSE(wrapper_->service()->IsGCMClientReady()); | 516 EXPECT_FALSE(wrapper_->service()->IsGCMClientReady()); |
| 517 EXPECT_EQ(GCMClientMock::CHECKED_OUT, wrapper_->GetGCMClient()->status()); | 517 EXPECT_EQ(GCMClientMock::CHECKED_OUT, wrapper_->GetGCMClient()->status()); |
| 518 | 518 |
| 519 // Sign-in with a different account. | 519 // Sign-in with a different account. |
| 520 wrapper_->SignIn(kTestAccountID2); | 520 wrapper_->SignIn(kTestAccountID2); |
| 521 | 521 |
| 522 // GCMClient should be loaded again. | 522 // GCMClient should be loaded again. |
| 523 EXPECT_TRUE(wrapper_->service()->IsGCMClientReady()); | 523 EXPECT_TRUE(wrapper_->service()->IsGCMClientReady()); |
| 524 EXPECT_EQ(GCMClientMock::LOADED, wrapper_->GetGCMClient()->status()); | 524 EXPECT_EQ(GCMClientMock::STARTED, wrapper_->GetGCMClient()->status()); |
| 525 } | 525 } |
| 526 | 526 |
| 527 TEST_F(GCMServiceTest, StopAndRestartGCM) { | 527 TEST_F(GCMServiceTest, StopAndRestartGCM) { |
| 528 wrapper_->CreateService(true, GCMClientMock::NO_DELAY_LOADING); | 528 wrapper_->CreateService(true, GCMClientMock::NO_DELAY_START); |
| 529 wrapper_->SignIn(kTestAccountID1); | 529 wrapper_->SignIn(kTestAccountID1); |
| 530 | 530 |
| 531 // GCMClient should be loaded. | 531 // GCMClient should be loaded. |
| 532 EXPECT_TRUE(wrapper_->service()->IsGCMClientReady()); | 532 EXPECT_TRUE(wrapper_->service()->IsGCMClientReady()); |
| 533 EXPECT_EQ(GCMClientMock::LOADED, wrapper_->GetGCMClient()->status()); | 533 EXPECT_EQ(GCMClientMock::STARTED, wrapper_->GetGCMClient()->status()); |
| 534 | 534 |
| 535 // Stops the GCM. | 535 // Stops the GCM. |
| 536 wrapper_->service()->Stop(); | 536 wrapper_->service()->Stop(); |
| 537 PumpIOLoop(); | 537 PumpIOLoop(); |
| 538 PumpUILoop(); | 538 PumpUILoop(); |
| 539 | 539 |
| 540 // GCMClient should be stopped. | 540 // GCMClient should be stopped. |
| 541 EXPECT_FALSE(wrapper_->service()->IsGCMClientReady()); | 541 EXPECT_FALSE(wrapper_->service()->IsGCMClientReady()); |
| 542 EXPECT_EQ(GCMClientMock::STOPPED, wrapper_->GetGCMClient()->status()); | 542 EXPECT_EQ(GCMClientMock::STOPPED, wrapper_->GetGCMClient()->status()); |
| 543 | 543 |
| 544 // Restarts the GCM. | 544 // Restarts the GCM. |
| 545 wrapper_->service()->Start(); | 545 wrapper_->service()->Start(); |
| 546 PumpIOLoop(); | 546 PumpIOLoop(); |
| 547 PumpUILoop(); | 547 PumpUILoop(); |
| 548 | 548 |
| 549 // GCMClient should be loaded. | 549 // GCMClient should be loaded. |
| 550 EXPECT_TRUE(wrapper_->service()->IsGCMClientReady()); | 550 EXPECT_TRUE(wrapper_->service()->IsGCMClientReady()); |
| 551 EXPECT_EQ(GCMClientMock::LOADED, wrapper_->GetGCMClient()->status()); | 551 EXPECT_EQ(GCMClientMock::STARTED, wrapper_->GetGCMClient()->status()); |
| 552 | 552 |
| 553 // Stops the GCM. | 553 // Stops the GCM. |
| 554 wrapper_->service()->Stop(); | 554 wrapper_->service()->Stop(); |
| 555 PumpIOLoop(); | 555 PumpIOLoop(); |
| 556 PumpUILoop(); | 556 PumpUILoop(); |
| 557 | 557 |
| 558 // GCMClient should be stopped. | 558 // GCMClient should be stopped. |
| 559 EXPECT_FALSE(wrapper_->service()->IsGCMClientReady()); | 559 EXPECT_FALSE(wrapper_->service()->IsGCMClientReady()); |
| 560 EXPECT_EQ(GCMClientMock::STOPPED, wrapper_->GetGCMClient()->status()); | 560 EXPECT_EQ(GCMClientMock::STOPPED, wrapper_->GetGCMClient()->status()); |
| 561 | 561 |
| 562 // Sign out. | 562 // Sign out. |
| 563 wrapper_->SignOut(); | 563 wrapper_->SignOut(); |
| 564 | 564 |
| 565 // GCMClient should be checked out. | 565 // GCMClient should be checked out. |
| 566 EXPECT_FALSE(wrapper_->service()->IsGCMClientReady()); | 566 EXPECT_FALSE(wrapper_->service()->IsGCMClientReady()); |
| 567 EXPECT_EQ(GCMClientMock::CHECKED_OUT, wrapper_->GetGCMClient()->status()); | 567 EXPECT_EQ(GCMClientMock::CHECKED_OUT, wrapper_->GetGCMClient()->status()); |
| 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_START); |
| 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(GCMClient::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_START); |
| 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::STARTED, 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(GCMClient::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_START); |
| 609 | 609 |
| 610 GCMClient::OutgoingMessage message; | 610 GCMClient::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(GCMClient::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_START); |
| 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 GCMClient::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::STARTED, 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(GCMClient::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; |
| 652 | 652 |
| 653 private: | 653 private: |
| 654 DISALLOW_COPY_AND_ASSIGN(GCMServiceSingleInstanceTest); | 654 DISALLOW_COPY_AND_ASSIGN(GCMServiceSingleInstanceTest); |
| 655 }; | 655 }; |
| 656 | 656 |
| 657 GCMServiceSingleInstanceTest::GCMServiceSingleInstanceTest() { | 657 GCMServiceSingleInstanceTest::GCMServiceSingleInstanceTest() { |
| 658 } | 658 } |
| 659 | 659 |
| 660 GCMServiceSingleInstanceTest::~GCMServiceSingleInstanceTest() { | 660 GCMServiceSingleInstanceTest::~GCMServiceSingleInstanceTest() { |
| 661 } | 661 } |
| 662 | 662 |
| 663 void GCMServiceSingleInstanceTest::SetUp() { | 663 void GCMServiceSingleInstanceTest::SetUp() { |
| 664 GCMServiceTest::SetUp(); | 664 GCMServiceTest::SetUp(); |
| 665 | 665 |
| 666 wrapper_->CreateService(true, GCMClientMock::NO_DELAY_LOADING); | 666 wrapper_->CreateService(true, GCMClientMock::NO_DELAY_START); |
| 667 wrapper_->SignIn(kTestAccountID1); | 667 wrapper_->SignIn(kTestAccountID1); |
| 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 |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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(GCMClient::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_START); |
| 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(); |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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(GCMClient::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_START); |
| 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 GCMClient::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, |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1001 } | 1001 } |
| 1002 | 1002 |
| 1003 GCMServiceMultipleInstanceTest::~GCMServiceMultipleInstanceTest() { | 1003 GCMServiceMultipleInstanceTest::~GCMServiceMultipleInstanceTest() { |
| 1004 } | 1004 } |
| 1005 | 1005 |
| 1006 void GCMServiceMultipleInstanceTest::SetUp() { | 1006 void GCMServiceMultipleInstanceTest::SetUp() { |
| 1007 GCMServiceTest::SetUp(); | 1007 GCMServiceTest::SetUp(); |
| 1008 | 1008 |
| 1009 wrapper2_.reset(new TestGCMServiceWrapper(request_context_)); | 1009 wrapper2_.reset(new TestGCMServiceWrapper(request_context_)); |
| 1010 | 1010 |
| 1011 wrapper_->CreateService(true, GCMClientMock::NO_DELAY_LOADING); | 1011 wrapper_->CreateService(true, GCMClientMock::NO_DELAY_START); |
| 1012 wrapper2_->CreateService(true, GCMClientMock::NO_DELAY_LOADING); | 1012 wrapper2_->CreateService(true, GCMClientMock::NO_DELAY_START); |
| 1013 | 1013 |
| 1014 // Initiate check-in for each instance. | 1014 // Initiate check-in for each instance. |
| 1015 wrapper_->SignIn(kTestAccountID1); | 1015 wrapper_->SignIn(kTestAccountID1); |
| 1016 wrapper2_->SignIn(kTestAccountID2); | 1016 wrapper2_->SignIn(kTestAccountID2); |
| 1017 } | 1017 } |
| 1018 | 1018 |
| 1019 void GCMServiceMultipleInstanceTest::TearDown() { | 1019 void GCMServiceMultipleInstanceTest::TearDown() { |
| 1020 wrapper2_.reset(); | 1020 wrapper2_.reset(); |
| 1021 } | 1021 } |
| 1022 | 1022 |
| (...skipping 289 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 |
| OLD | NEW |