| Index: chrome/browser/services/gcm/gcm_profile_service_unittest.cc
|
| diff --git a/chrome/browser/services/gcm/gcm_profile_service_unittest.cc b/chrome/browser/services/gcm/gcm_profile_service_unittest.cc
|
| index 395fa14d47d581cd47fbdc53bc3328eb5eff4677..2474455d3a5070974336059ab2b1a17b5f9d8d33 100644
|
| --- a/chrome/browser/services/gcm/gcm_profile_service_unittest.cc
|
| +++ b/chrome/browser/services/gcm/gcm_profile_service_unittest.cc
|
| @@ -214,9 +214,9 @@ class FakeGCMEventRouter : public GCMEventRouter {
|
| class FakeGCMClientFactory : public GCMClientFactory {
|
| public:
|
| FakeGCMClientFactory(
|
| - GCMClientMock::Status gcm_client_initial_status,
|
| + GCMClientMock::LoadingDelay gcm_client_loading_delay,
|
| GCMClientMock::ErrorSimulation gcm_client_error_simulation)
|
| - : gcm_client_initial_status_(gcm_client_initial_status),
|
| + : gcm_client_loading_delay_(gcm_client_loading_delay),
|
| gcm_client_error_simulation_(gcm_client_error_simulation),
|
| gcm_client_(NULL) {
|
| }
|
| @@ -225,7 +225,7 @@ class FakeGCMClientFactory : public GCMClientFactory {
|
| }
|
|
|
| virtual scoped_ptr<GCMClient> BuildInstance() OVERRIDE {
|
| - gcm_client_ = new GCMClientMock(gcm_client_initial_status_,
|
| + gcm_client_ = new GCMClientMock(gcm_client_loading_delay_,
|
| gcm_client_error_simulation_);
|
| return scoped_ptr<GCMClient>(gcm_client_);
|
| }
|
| @@ -233,7 +233,7 @@ class FakeGCMClientFactory : public GCMClientFactory {
|
| GCMClientMock* gcm_client() const { return gcm_client_; }
|
|
|
| private:
|
| - GCMClientMock::Status gcm_client_initial_status_;
|
| + GCMClientMock::LoadingDelay gcm_client_loading_delay_;
|
| GCMClientMock::ErrorSimulation gcm_client_error_simulation_;
|
| GCMClientMock* gcm_client_;
|
|
|
| @@ -256,7 +256,7 @@ class GCMProfileServiceTestConsumer : public GCMProfileService::TestingDelegate{
|
| : waiter_(waiter),
|
| extension_service_(NULL),
|
| signin_manager_(NULL),
|
| - gcm_client_initial_status_(GCMClientMock::READY),
|
| + gcm_client_loading_delay_(GCMClientMock::NO_LOADING_DELAY),
|
| gcm_client_error_simulation_(GCMClientMock::ALWAYS_SUCCEED),
|
| registration_result_(GCMClient::SUCCESS),
|
| has_persisted_registration_info_(false),
|
| @@ -279,6 +279,7 @@ class GCMProfileServiceTestConsumer : public GCMProfileService::TestingDelegate{
|
|
|
| // Enable GCM such that tests could be run on all channels.
|
| GCMProfileService::enable_gcm_for_testing_ = true;
|
| + profile()->GetPrefs()->SetBoolean(prefs::kGCMChannelEnabled, true);
|
|
|
| // Mock a GCMEventRouter.
|
| gcm_event_router_.reset(new FakeGCMEventRouter(waiter_));
|
| @@ -334,7 +335,7 @@ class GCMProfileServiceTestConsumer : public GCMProfileService::TestingDelegate{
|
| profile(), &GCMProfileServiceTestConsumer::BuildGCMProfileService));
|
| gcm_profile_service->set_testing_delegate(this);
|
| scoped_ptr<GCMClientFactory> gcm_client_factory(
|
| - new FakeGCMClientFactory(gcm_client_initial_status_,
|
| + new FakeGCMClientFactory(gcm_client_loading_delay_,
|
| gcm_client_error_simulation_));
|
| gcm_profile_service->Initialize(gcm_client_factory.Pass());
|
| waiter_->PumpIOLoop();
|
| @@ -411,8 +412,8 @@ class GCMProfileServiceTestConsumer : public GCMProfileService::TestingDelegate{
|
| }
|
|
|
| GCMClientMock* GetGCMClient() const {
|
| - return static_cast<FakeGCMClientFactory*>(
|
| - GetGCMProfileService()->gcm_client_factory_.get())->gcm_client();
|
| + return static_cast<GCMClientMock*>(
|
| + GetGCMProfileService()->GetGCMClientForTesting());
|
| }
|
|
|
| const std::string& GetUsername() const {
|
| @@ -432,8 +433,8 @@ class GCMProfileServiceTestConsumer : public GCMProfileService::TestingDelegate{
|
| return gcm_event_router_.get();
|
| }
|
|
|
| - void set_gcm_client_initial_status(GCMClientMock::Status status) {
|
| - gcm_client_initial_status_ = status;
|
| + void set_gcm_client_loading_delay(GCMClientMock::LoadingDelay delay) {
|
| + gcm_client_loading_delay_ = delay;
|
| }
|
| void set_gcm_client_error_simulation(GCMClientMock::ErrorSimulation error) {
|
| gcm_client_error_simulation_ = error;
|
| @@ -465,7 +466,7 @@ class GCMProfileServiceTestConsumer : public GCMProfileService::TestingDelegate{
|
| FakeSigninManager* signin_manager_; // Not owned.
|
| scoped_ptr<FakeGCMEventRouter> gcm_event_router_;
|
|
|
| - GCMClientMock::Status gcm_client_initial_status_;
|
| + GCMClientMock::LoadingDelay gcm_client_loading_delay_;
|
| GCMClientMock::ErrorSimulation gcm_client_error_simulation_;
|
|
|
| std::string registration_id_;
|
| @@ -584,7 +585,67 @@ TEST_F(GCMProfileServiceTest, CreateGCMProfileServiceAfterProfileSignIn) {
|
| EXPECT_FALSE(consumer()->GetUsername().empty());
|
| }
|
|
|
| -TEST_F(GCMProfileServiceTest, RegsiterWhenNotSignedIn) {
|
| +TEST_F(GCMProfileServiceTest, SignInAndSignOutUnderPositiveChannelSignal) {
|
| + // Positive channel signal is provided in SetUp.
|
| + consumer()->CreateGCMProfileServiceInstance();
|
| + consumer()->SignIn(kTestingUsername);
|
| +
|
| + // GCMClient should be loaded.
|
| + EXPECT_TRUE(consumer()->IsGCMClientReady());
|
| + EXPECT_EQ(GCMClientMock::LOADED, consumer()->GetGCMClient()->status());
|
| +
|
| + consumer()->SignOut();
|
| +
|
| + // GCMClient should be checked out.
|
| + EXPECT_FALSE(consumer()->IsGCMClientReady());
|
| + EXPECT_EQ(GCMClientMock::CHECKED_OUT, consumer()->GetGCMClient()->status());
|
| +}
|
| +
|
| +TEST_F(GCMProfileServiceTest, SignInAndSignOutUnderNegativeChannelSignal) {
|
| + // Negative channel signal will prevent GCMClient from checking in when the
|
| + // profile is signed in.
|
| + profile()->GetPrefs()->SetBoolean(prefs::kGCMChannelEnabled, false);
|
| +
|
| + consumer()->CreateGCMProfileServiceInstance();
|
| + consumer()->SignIn(kTestingUsername);
|
| +
|
| + // GCMClient should not be loaded.
|
| + EXPECT_FALSE(consumer()->IsGCMClientReady());
|
| + EXPECT_EQ(GCMClientMock::UNINITIALIZED, consumer()->GetGCMClient()->status());
|
| +
|
| + consumer()->SignOut();
|
| +
|
| + // Check-out should still be performed.
|
| + EXPECT_FALSE(consumer()->IsGCMClientReady());
|
| + EXPECT_EQ(GCMClientMock::CHECKED_OUT, consumer()->GetGCMClient()->status());
|
| +}
|
| +
|
| +TEST_F(GCMProfileServiceTest, SignOutAndThenSignIn) {
|
| + // Positive channel signal is provided in SetUp.
|
| + consumer()->CreateGCMProfileServiceInstance();
|
| + consumer()->SignIn(kTestingUsername);
|
| +
|
| + // GCMClient should not be loaded.
|
| + EXPECT_TRUE(consumer()->IsGCMClientReady());
|
| + EXPECT_EQ(GCMClientMock::LOADED, consumer()->GetGCMClient()->status());
|
| +
|
| + consumer()->SignOut();
|
| +
|
| + // GCMClient should be checked out.
|
| + EXPECT_FALSE(consumer()->IsGCMClientReady());
|
| + EXPECT_EQ(GCMClientMock::CHECKED_OUT, consumer()->GetGCMClient()->status());
|
| +
|
| + // Sign-in with a different username.
|
| + consumer()->SignIn(kTestingUsername2);
|
| +
|
| + // GCMClient should be loaded again.
|
| + EXPECT_TRUE(consumer()->IsGCMClientReady());
|
| + EXPECT_EQ(GCMClientMock::LOADED, consumer()->GetGCMClient()->status());
|
| +}
|
| +
|
| +TEST_F(GCMProfileServiceTest, RegisterWhenNotSignedIn) {
|
| + consumer()->CreateGCMProfileServiceInstance();
|
| +
|
| std::vector<std::string> sender_ids;
|
| sender_ids.push_back("sender1");
|
| consumer()->Register(kTestingAppId, sender_ids);
|
| @@ -594,6 +655,8 @@ TEST_F(GCMProfileServiceTest, RegsiterWhenNotSignedIn) {
|
| }
|
|
|
| TEST_F(GCMProfileServiceTest, SendWhenNotSignedIn) {
|
| + consumer()->CreateGCMProfileServiceInstance();
|
| +
|
| GCMClient::OutgoingMessage message;
|
| message.id = "1";
|
| message.data["key1"] = "value1";
|
| @@ -620,29 +683,6 @@ class GCMProfileServiceSingleProfileTest : public GCMProfileServiceTest {
|
| }
|
| };
|
|
|
| -TEST_F(GCMProfileServiceSingleProfileTest, SignOut) {
|
| - EXPECT_TRUE(consumer()->IsGCMClientReady());
|
| -
|
| - // This will trigger check-out.
|
| - consumer()->SignOut();
|
| -
|
| - EXPECT_FALSE(consumer()->IsGCMClientReady());
|
| -}
|
| -
|
| -TEST_F(GCMProfileServiceSingleProfileTest, SignOutAndThenSignIn) {
|
| - EXPECT_TRUE(consumer()->IsGCMClientReady());
|
| -
|
| - // This will trigger check-out.
|
| - consumer()->SignOut();
|
| -
|
| - EXPECT_FALSE(consumer()->IsGCMClientReady());
|
| -
|
| - // Sign-in with a different username.
|
| - consumer()->SignIn(kTestingUsername2);
|
| -
|
| - EXPECT_TRUE(consumer()->IsGCMClientReady());
|
| -}
|
| -
|
| TEST_F(GCMProfileServiceSingleProfileTest, Register) {
|
| std::vector<std::string> sender_ids;
|
| sender_ids.push_back("sender1");
|
| @@ -788,10 +828,8 @@ TEST_F(GCMProfileServiceSingleProfileTest,
|
| // preparation to call register 2nd time.
|
| consumer()->clear_registration_result();
|
|
|
| - // Needs to create a GCMClient instance that is not ready initiallly.
|
| - consumer()->set_gcm_client_initial_status(GCMClientMock::NOT_READY);
|
| -
|
| // Simulate start-up by recreating GCMProfileService.
|
| + consumer()->set_gcm_client_loading_delay(GCMClientMock::LOADING_DELAY);
|
| consumer()->CreateGCMProfileServiceInstance();
|
|
|
| // Simulate start-up by reloading extension.
|
| @@ -805,7 +843,7 @@ TEST_F(GCMProfileServiceSingleProfileTest,
|
| EXPECT_EQ(GCMClient::UNKNOWN_ERROR, consumer()->registration_result());
|
|
|
| // Register operation will be invoked after GCMClient becomes ready.
|
| - consumer()->GetGCMClient()->SetReady();
|
| + consumer()->GetGCMClient()->PerformDelayedLoading();
|
| WaitUntilCompleted();
|
| EXPECT_EQ(old_registration_id, consumer()->registration_id());
|
| EXPECT_EQ(GCMClient::SUCCESS, consumer()->registration_result());
|
|
|