Chromium Code Reviews| 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 c5fb250ed50518476a9f72149d140c7dda428f53..3002b064bb94b36584caeb43e5d355d4d1ec5eba 100644 |
| --- a/chrome/browser/services/gcm/gcm_profile_service_unittest.cc |
| +++ b/chrome/browser/services/gcm/gcm_profile_service_unittest.cc |
| @@ -59,6 +59,9 @@ class GCMProfileServiceTest : public testing::Test { |
| FakeGCMClient* GetGCMClient() const; |
| + void CreateGCMProfileService(); |
| + void SignIn(); |
| + |
| void RegisterAndWaitForCompletion(const std::vector<std::string>& sender_ids); |
| void UnregisterAndWaitForCompletion(); |
| void SendAndWaitForCompletion(const GCMClient::OutgoingMessage& message); |
| @@ -116,24 +119,28 @@ void GCMProfileServiceTest::SetUp() { |
| builder.AddTestingFactory(SigninManagerFactory::GetInstance(), |
| FakeSigninManager::Build); |
| profile_ = builder.Build(); |
| +} |
| + |
| +void GCMProfileServiceTest::TearDown() { |
| + gcm_profile_service_->driver()->RemoveAppHandler(kTestAppID); |
| +} |
| +void GCMProfileServiceTest::CreateGCMProfileService() { |
| gcm_profile_service_ = static_cast<GCMProfileService*>( |
| GCMProfileServiceFactory::GetInstance()->SetTestingFactoryAndUse( |
| profile_.get(), |
| &BuildGCMProfileService)); |
| gcm_profile_service_->driver()->AddAppHandler( |
| kTestAppID, gcm_app_handler_.get()); |
| +} |
| +void GCMProfileServiceTest::SignIn() { |
| FakeSigninManager* signin_manager = static_cast<FakeSigninManager*>( |
| SigninManagerFactory::GetInstance()->GetForProfile(profile_.get())); |
| signin_manager->SignIn(kTestAccountID); |
| base::RunLoop().RunUntilIdle(); |
| } |
| -void GCMProfileServiceTest::TearDown() { |
| - gcm_profile_service_->driver()->RemoveAppHandler(kTestAppID); |
| -} |
| - |
| void GCMProfileServiceTest::RegisterAndWaitForCompletion( |
| const std::vector<std::string>& sender_ids) { |
| base::RunLoop run_loop; |
| @@ -194,7 +201,27 @@ void GCMProfileServiceTest::SendCompleted( |
| callback.Run(); |
| } |
| +TEST_F(GCMProfileServiceTest, CreateGCMProfileServiceBeforeSignIn) { |
| + CreateGCMProfileService(); |
| + EXPECT_FALSE(driver()->IsStarted()); |
| + |
| + SignIn(); |
| + EXPECT_TRUE(driver()->IsStarted()); |
| +} |
| + |
| +TEST_F(GCMProfileServiceTest, CreateGCMProfileServiceAfterSignIn) { |
| + SignIn(); |
| + // Note that we can't check if the GCM is started or not since the |
|
bartfab (slow)
2014/06/13 11:27:21
Nit: s/the GCM/GCM/
jianli
2014/06/13 18:04:48
Done.
|
| + // GCMProfileService that hosts the GCMDriver is not created yet. |
| + |
| + CreateGCMProfileService(); |
| + EXPECT_TRUE(driver()->IsStarted()); |
| +} |
| + |
| TEST_F(GCMProfileServiceTest, RegisterAndUnregister) { |
| + CreateGCMProfileService(); |
| + SignIn(); |
| + |
| std::vector<std::string> sender_ids; |
| sender_ids.push_back("sender"); |
| RegisterAndWaitForCompletion(sender_ids); |
| @@ -209,6 +236,9 @@ TEST_F(GCMProfileServiceTest, RegisterAndUnregister) { |
| } |
| TEST_F(GCMProfileServiceTest, Send) { |
| + CreateGCMProfileService(); |
| + SignIn(); |
| + |
| GCMClient::OutgoingMessage message; |
| message.id = "1"; |
| message.data["key1"] = "value1"; |