OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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 <algorithm> | 5 #include <algorithm> |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
9 #include "base/debug/leak_annotations.h" | 9 #include "base/debug/leak_annotations.h" |
10 #include "base/prefs/pref_service.h" | 10 #include "base/prefs/pref_service.h" |
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
161 extension_service_ = NULL; | 161 extension_service_ = NULL; |
162 profile_.reset(); | 162 profile_.reset(); |
163 base::RunLoop().RunUntilIdle(); | 163 base::RunLoop().RunUntilIdle(); |
164 } | 164 } |
165 | 165 |
166 // Overridden from GCMProfileService::TestingDelegate: | 166 // Overridden from GCMProfileService::TestingDelegate: |
167 virtual GCMEventRouter* GetEventRouter() const OVERRIDE { | 167 virtual GCMEventRouter* GetEventRouter() const OVERRIDE { |
168 return gcm_event_router_mock_.get(); | 168 return gcm_event_router_mock_.get(); |
169 } | 169 } |
170 | 170 |
171 virtual void CheckInFinished(const GCMClient::CheckInInfo& checkin_info, | 171 virtual void CheckInFinished(const GCMClient::CheckinInfo& checkin_info, |
172 GCMClient::Result result) OVERRIDE { | 172 GCMClient::Result result) OVERRIDE { |
173 checkin_info_ = checkin_info; | 173 checkin_info_ = checkin_info; |
174 SignalCompleted(); | 174 SignalCompleted(); |
175 } | 175 } |
176 | 176 |
177 // Waits until the asynchrnous operation finishes. | 177 // Waits until the asynchrnous operation finishes. |
178 void WaitForCompleted() { | 178 void WaitForCompleted() { |
179 run_loop_.reset(new base::RunLoop); | 179 run_loop_.reset(new base::RunLoop); |
180 run_loop_->Run(); | 180 run_loop_->Run(); |
181 } | 181 } |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
222 GCMProfileService* GetGCMProfileService() const { | 222 GCMProfileService* GetGCMProfileService() const { |
223 return GCMProfileServiceFactory::GetForProfile(profile()); | 223 return GCMProfileServiceFactory::GetForProfile(profile()); |
224 } | 224 } |
225 | 225 |
226 protected: | 226 protected: |
227 scoped_ptr<TestingProfile> profile_; | 227 scoped_ptr<TestingProfile> profile_; |
228 scoped_ptr<content::TestBrowserThreadBundle> thread_bundle_; | 228 scoped_ptr<content::TestBrowserThreadBundle> thread_bundle_; |
229 ExtensionService* extension_service_; // Not owned. | 229 ExtensionService* extension_service_; // Not owned. |
230 scoped_ptr<base::RunLoop> run_loop_; | 230 scoped_ptr<base::RunLoop> run_loop_; |
231 scoped_ptr<GCMEventRouterMock> gcm_event_router_mock_; | 231 scoped_ptr<GCMEventRouterMock> gcm_event_router_mock_; |
232 GCMClient::CheckInInfo checkin_info_; | 232 GCMClient::CheckinInfo checkin_info_; |
233 | 233 |
234 #if defined(OS_CHROMEOS) | 234 #if defined(OS_CHROMEOS) |
235 chromeos::ScopedTestDeviceSettingsService test_device_settings_service_; | 235 chromeos::ScopedTestDeviceSettingsService test_device_settings_service_; |
236 chromeos::ScopedTestCrosSettings test_cros_settings_; | 236 chromeos::ScopedTestCrosSettings test_cros_settings_; |
237 scoped_ptr<chromeos::ScopedTestUserManager> test_user_manager_; | 237 scoped_ptr<chromeos::ScopedTestUserManager> test_user_manager_; |
238 #endif | 238 #endif |
239 | 239 |
240 private: | 240 private: |
241 static GCMProfileService::TestingDelegate* gps_testing_delegate_; | 241 static GCMProfileService::TestingDelegate* gps_testing_delegate_; |
242 | 242 |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
293 received_event_ = SEND_ERROR_EVENT; | 293 received_event_ = SEND_ERROR_EVENT; |
294 app_id_ = app_id; | 294 app_id_ = app_id; |
295 send_error_message_id_ = message_id; | 295 send_error_message_id_ = message_id; |
296 send_error_result_ = result; | 296 send_error_result_ = result; |
297 test_->SignalCompleted(); | 297 test_->SignalCompleted(); |
298 } | 298 } |
299 | 299 |
300 TEST_F(GCMProfileServiceTest, CheckIn) { | 300 TEST_F(GCMProfileServiceTest, CheckIn) { |
301 EXPECT_TRUE(checkin_info_.IsValid()); | 301 EXPECT_TRUE(checkin_info_.IsValid()); |
302 | 302 |
303 GCMClient::CheckInInfo expected_checkin_info = | 303 GCMClient::CheckinInfo expected_checkin_info = |
304 GCMClientMock::GetCheckInInfoFromUsername(kTestingUsername); | 304 GCMClientMock::GetCheckinInfoFromUsername(kTestingUsername); |
305 EXPECT_EQ(expected_checkin_info.android_id, checkin_info_.android_id); | 305 EXPECT_EQ(expected_checkin_info.android_id, checkin_info_.android_id); |
306 EXPECT_EQ(expected_checkin_info.secret, checkin_info_.secret); | 306 EXPECT_EQ(expected_checkin_info.secret, checkin_info_.secret); |
307 } | 307 } |
308 | 308 |
309 TEST_F(GCMProfileServiceTest, CheckInFromPrefsStore) { | 309 TEST_F(GCMProfileServiceTest, CheckInFromPrefsStore) { |
310 // The first check-in should be successful. | 310 // The first check-in should be successful. |
311 EXPECT_TRUE(checkin_info_.IsValid()); | 311 EXPECT_TRUE(checkin_info_.IsValid()); |
312 GCMClient::CheckInInfo saved_checkin_info = checkin_info_; | 312 GCMClient::CheckinInfo saved_checkin_info = checkin_info_; |
313 checkin_info_.Reset(); | 313 checkin_info_.Reset(); |
314 | 314 |
315 // Check-in should not reach the server. Forcing GCMClient server error should | 315 // Check-in should not reach the server. Forcing GCMClient server error should |
316 // help catch this. | 316 // help catch this. |
317 ScopedGCMClientMockSimulateServerError gcm_client_simulate_server_error; | 317 ScopedGCMClientMockSimulateServerError gcm_client_simulate_server_error; |
318 | 318 |
319 // Recreate GCMProfileService to test reading the check-in info from the | 319 // Recreate GCMProfileService to test reading the check-in info from the |
320 // prefs store. | 320 // prefs store. |
321 GCMProfileServiceFactory::GetInstance()->SetTestingFactoryAndUse( | 321 GCMProfileServiceFactory::GetInstance()->SetTestingFactoryAndUse( |
322 profile(), &GCMProfileServiceTest::BuildGCMProfileService); | 322 profile(), &GCMProfileServiceTest::BuildGCMProfileService); |
(...skipping 363 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
686 | 686 |
687 TEST_F(GCMProfileServiceTest, MessagesDeleted) { | 687 TEST_F(GCMProfileServiceTest, MessagesDeleted) { |
688 GetGCMClientMock()->DeleteMessages(kTestingUsername, kTestingAppId); | 688 GetGCMClientMock()->DeleteMessages(kTestingUsername, kTestingAppId); |
689 WaitForCompleted(); | 689 WaitForCompleted(); |
690 EXPECT_EQ(GCMEventRouterMock::MESSAGES_DELETED_EVENT, | 690 EXPECT_EQ(GCMEventRouterMock::MESSAGES_DELETED_EVENT, |
691 gcm_event_router_mock_->received_event()); | 691 gcm_event_router_mock_->received_event()); |
692 EXPECT_EQ(kTestingAppId, gcm_event_router_mock_->app_id()); | 692 EXPECT_EQ(kTestingAppId, gcm_event_router_mock_->app_id()); |
693 } | 693 } |
694 | 694 |
695 } // namespace gcm | 695 } // namespace gcm |
OLD | NEW |