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_profile_service.h" | 5 #include "chrome/browser/services/gcm/gcm_profile_service.h" |
6 | 6 |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
54 virtual ~GCMProfileServiceTest(); | 54 virtual ~GCMProfileServiceTest(); |
55 | 55 |
56 // testing::Test: | 56 // testing::Test: |
57 virtual void SetUp() OVERRIDE; | 57 virtual void SetUp() OVERRIDE; |
58 virtual void TearDown() OVERRIDE; | 58 virtual void TearDown() OVERRIDE; |
59 | 59 |
60 FakeGCMClient* GetGCMClient() const; | 60 FakeGCMClient* GetGCMClient() const; |
61 | 61 |
62 void CreateGCMProfileService(); | 62 void CreateGCMProfileService(); |
63 void SignIn(); | 63 void SignIn(); |
| 64 void SignOut(); |
64 | 65 |
65 void RegisterAndWaitForCompletion(const std::vector<std::string>& sender_ids); | 66 void RegisterAndWaitForCompletion(const std::vector<std::string>& sender_ids); |
66 void UnregisterAndWaitForCompletion(); | 67 void UnregisterAndWaitForCompletion(); |
67 void SendAndWaitForCompletion(const GCMClient::OutgoingMessage& message); | 68 void SendAndWaitForCompletion(const GCMClient::OutgoingMessage& message); |
68 | 69 |
69 void RegisterCompleted(const base::Closure& callback, | 70 void RegisterCompleted(const base::Closure& callback, |
70 const std::string& registration_id, | 71 const std::string& registration_id, |
71 GCMClient::Result result); | 72 GCMClient::Result result); |
72 void UnregisterCompleted(const base::Closure& callback, | 73 void UnregisterCompleted(const base::Closure& callback, |
73 GCMClient::Result result); | 74 GCMClient::Result result); |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
134 kTestAppID, gcm_app_handler_.get()); | 135 kTestAppID, gcm_app_handler_.get()); |
135 } | 136 } |
136 | 137 |
137 void GCMProfileServiceTest::SignIn() { | 138 void GCMProfileServiceTest::SignIn() { |
138 FakeSigninManager* signin_manager = static_cast<FakeSigninManager*>( | 139 FakeSigninManager* signin_manager = static_cast<FakeSigninManager*>( |
139 SigninManagerFactory::GetInstance()->GetForProfile(profile_.get())); | 140 SigninManagerFactory::GetInstance()->GetForProfile(profile_.get())); |
140 signin_manager->SignIn(kTestAccountID); | 141 signin_manager->SignIn(kTestAccountID); |
141 base::RunLoop().RunUntilIdle(); | 142 base::RunLoop().RunUntilIdle(); |
142 } | 143 } |
143 | 144 |
| 145 void GCMProfileServiceTest::SignOut() { |
| 146 FakeSigninManager* signin_manager = static_cast<FakeSigninManager*>( |
| 147 SigninManagerFactory::GetInstance()->GetForProfile(profile_.get())); |
| 148 signin_manager->SignOut(signin_metrics::SIGNOUT_TEST); |
| 149 base::RunLoop().RunUntilIdle(); |
| 150 } |
| 151 |
144 void GCMProfileServiceTest::RegisterAndWaitForCompletion( | 152 void GCMProfileServiceTest::RegisterAndWaitForCompletion( |
145 const std::vector<std::string>& sender_ids) { | 153 const std::vector<std::string>& sender_ids) { |
146 base::RunLoop run_loop; | 154 base::RunLoop run_loop; |
147 gcm_profile_service_->driver()->Register( | 155 gcm_profile_service_->driver()->Register( |
148 kTestAppID, | 156 kTestAppID, |
149 sender_ids, | 157 sender_ids, |
150 base::Bind(&GCMProfileServiceTest::RegisterCompleted, | 158 base::Bind(&GCMProfileServiceTest::RegisterCompleted, |
151 base::Unretained(this), | 159 base::Unretained(this), |
152 run_loop.QuitClosure())); | 160 run_loop.QuitClosure())); |
153 run_loop.Run(); | 161 run_loop.Run(); |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
211 | 219 |
212 TEST_F(GCMProfileServiceTest, CreateGCMProfileServiceAfterSignIn) { | 220 TEST_F(GCMProfileServiceTest, CreateGCMProfileServiceAfterSignIn) { |
213 SignIn(); | 221 SignIn(); |
214 // Note that we can't check if GCM is started or not since the | 222 // Note that we can't check if GCM is started or not since the |
215 // GCMProfileService that hosts the GCMDriver is not created yet. | 223 // GCMProfileService that hosts the GCMDriver is not created yet. |
216 | 224 |
217 CreateGCMProfileService(); | 225 CreateGCMProfileService(); |
218 EXPECT_TRUE(driver()->IsStarted()); | 226 EXPECT_TRUE(driver()->IsStarted()); |
219 } | 227 } |
220 | 228 |
| 229 TEST_F(GCMProfileServiceTest, SignInAgain) { |
| 230 CreateGCMProfileService(); |
| 231 SignIn(); |
| 232 EXPECT_TRUE(driver()->IsStarted()); |
| 233 |
| 234 SignOut(); |
| 235 EXPECT_FALSE(driver()->IsStarted()); |
| 236 |
| 237 SignIn(); |
| 238 EXPECT_TRUE(driver()->IsStarted()); |
| 239 } |
| 240 |
221 TEST_F(GCMProfileServiceTest, RegisterAndUnregister) { | 241 TEST_F(GCMProfileServiceTest, RegisterAndUnregister) { |
222 CreateGCMProfileService(); | 242 CreateGCMProfileService(); |
223 SignIn(); | 243 SignIn(); |
224 | 244 |
225 std::vector<std::string> sender_ids; | 245 std::vector<std::string> sender_ids; |
226 sender_ids.push_back("sender"); | 246 sender_ids.push_back("sender"); |
227 RegisterAndWaitForCompletion(sender_ids); | 247 RegisterAndWaitForCompletion(sender_ids); |
228 | 248 |
229 std::string expected_registration_id = | 249 std::string expected_registration_id = |
230 FakeGCMClient::GetRegistrationIdFromSenderIds(sender_ids); | 250 FakeGCMClient::GetRegistrationIdFromSenderIds(sender_ids); |
(...skipping 11 matching lines...) Expand all Loading... |
242 GCMClient::OutgoingMessage message; | 262 GCMClient::OutgoingMessage message; |
243 message.id = "1"; | 263 message.id = "1"; |
244 message.data["key1"] = "value1"; | 264 message.data["key1"] = "value1"; |
245 SendAndWaitForCompletion( message); | 265 SendAndWaitForCompletion( message); |
246 | 266 |
247 EXPECT_EQ(message.id, send_message_id()); | 267 EXPECT_EQ(message.id, send_message_id()); |
248 EXPECT_EQ(GCMClient::SUCCESS, send_result()); | 268 EXPECT_EQ(GCMClient::SUCCESS, send_result()); |
249 } | 269 } |
250 | 270 |
251 } // namespace gcm | 271 } // namespace gcm |
OLD | NEW |