| 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..5c713a5ac2c4f31cf0f58e7221265df5180e3b92 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::CheckinDelay gcm_client_checkin_delay,
|
| GCMClientMock::ErrorSimulation gcm_client_error_simulation)
|
| - : gcm_client_initial_status_(gcm_client_initial_status),
|
| + : gcm_client_checkin_delay_(gcm_client_checkin_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_checkin_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::CheckinDelay gcm_client_checkin_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_checkin_delay_(GCMClientMock::NO_CHECKIN_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_checkin_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_checkin_delay(GCMClientMock::CheckinDelay delay) {
|
| + gcm_client_checkin_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::CheckinDelay gcm_client_checkin_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 checked in.
|
| + EXPECT_TRUE(consumer()->IsGCMClientReady());
|
| + EXPECT_EQ(GCMClientMock::CHECKED_IN, 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 checked in.
|
| + 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 checked in.
|
| + EXPECT_TRUE(consumer()->IsGCMClientReady());
|
| + EXPECT_EQ(GCMClientMock::CHECKED_IN, 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 not be checked in again.
|
| + EXPECT_TRUE(consumer()->IsGCMClientReady());
|
| + EXPECT_EQ(GCMClientMock::CHECKED_IN, 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);
|
| @@ -593,7 +654,38 @@ TEST_F(GCMProfileServiceTest, RegsiterWhenNotSignedIn) {
|
| EXPECT_EQ(GCMClient::NOT_SIGNED_IN, consumer()->registration_result());
|
| }
|
|
|
| +TEST_F(GCMProfileServiceTest, RegisterUnderNegativeChannelSignal) {
|
| + // 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 checked in.
|
| + EXPECT_FALSE(consumer()->IsGCMClientReady());
|
| + EXPECT_EQ(GCMClientMock::UNINITIALIZED, consumer()->GetGCMClient()->status());
|
| +
|
| + // Invoking register will make GCMClient checked in.
|
| + std::vector<std::string> sender_ids;
|
| + sender_ids.push_back("sender1");
|
| + consumer()->Register(kTestingAppId, sender_ids);
|
| + WaitUntilCompleted();
|
| +
|
| + // GCMClient should be checked in.
|
| + EXPECT_TRUE(consumer()->IsGCMClientReady());
|
| + EXPECT_EQ(GCMClientMock::CHECKED_IN, consumer()->GetGCMClient()->status());
|
| +
|
| + // Registration should succeed.
|
| + std::string expected_registration_id =
|
| + GCMClientMock::GetRegistrationIdFromSenderIds(sender_ids);
|
| + EXPECT_EQ(expected_registration_id, consumer()->registration_id());
|
| + EXPECT_EQ(GCMClient::SUCCESS, consumer()->registration_result());
|
| +}
|
| +
|
| TEST_F(GCMProfileServiceTest, SendWhenNotSignedIn) {
|
| + consumer()->CreateGCMProfileServiceInstance();
|
| +
|
| GCMClient::OutgoingMessage message;
|
| message.id = "1";
|
| message.data["key1"] = "value1";
|
| @@ -603,6 +695,34 @@ TEST_F(GCMProfileServiceTest, SendWhenNotSignedIn) {
|
| EXPECT_EQ(GCMClient::NOT_SIGNED_IN, consumer()->send_result());
|
| }
|
|
|
| +TEST_F(GCMProfileServiceTest, SendUnderNegativeChannelSignal) {
|
| + // 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 checked in.
|
| + EXPECT_FALSE(consumer()->IsGCMClientReady());
|
| + EXPECT_EQ(GCMClientMock::UNINITIALIZED, consumer()->GetGCMClient()->status());
|
| +
|
| + // Invoking send will make GCMClient checked in.
|
| + GCMClient::OutgoingMessage message;
|
| + message.id = "1";
|
| + message.data["key1"] = "value1";
|
| + consumer()->Send(kTestingAppId, kUserId, message);
|
| + WaitUntilCompleted();
|
| +
|
| + // GCMClient should be checked in.
|
| + EXPECT_TRUE(consumer()->IsGCMClientReady());
|
| + EXPECT_EQ(GCMClientMock::CHECKED_IN, consumer()->GetGCMClient()->status());
|
| +
|
| + // Sending should succeed.
|
| + EXPECT_EQ(consumer()->send_message_id(), message.id);
|
| + EXPECT_EQ(GCMClient::SUCCESS, consumer()->send_result());
|
| +}
|
| +
|
| // Tests single-profile.
|
| class GCMProfileServiceSingleProfileTest : public GCMProfileServiceTest {
|
| public:
|
| @@ -620,29 +740,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 +885,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_checkin_delay(GCMClientMock::CHECKIN_DELAY);
|
| consumer()->CreateGCMProfileServiceInstance();
|
|
|
| // Simulate start-up by reloading extension.
|
| @@ -805,7 +900,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()->PerformDelayedCheckIn();
|
| WaitUntilCompleted();
|
| EXPECT_EQ(old_registration_id, consumer()->registration_id());
|
| EXPECT_EQ(GCMClient::SUCCESS, consumer()->registration_result());
|
|
|