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" |
11 #include "base/run_loop.h" | 11 #include "base/run_loop.h" |
12 #include "chrome/browser/extensions/state_store.h" | 12 #include "chrome/browser/extensions/state_store.h" |
13 #include "chrome/browser/extensions/test_extension_service.h" | 13 #include "chrome/browser/extensions/test_extension_service.h" |
14 #include "chrome/browser/extensions/test_extension_system.h" | 14 #include "chrome/browser/extensions/test_extension_system.h" |
| 15 #include "chrome/browser/services/gcm/gcm_client_factory.h" |
15 #include "chrome/browser/services/gcm/gcm_client_mock.h" | 16 #include "chrome/browser/services/gcm/gcm_client_mock.h" |
16 #include "chrome/browser/services/gcm/gcm_event_router.h" | 17 #include "chrome/browser/services/gcm/gcm_event_router.h" |
17 #include "chrome/browser/services/gcm/gcm_profile_service.h" | 18 #include "chrome/browser/services/gcm/gcm_profile_service.h" |
18 #include "chrome/browser/services/gcm/gcm_profile_service_factory.h" | 19 #include "chrome/browser/services/gcm/gcm_profile_service_factory.h" |
19 #include "chrome/browser/signin/fake_signin_manager.h" | 20 #include "chrome/browser/signin/fake_signin_manager.h" |
20 #include "chrome/browser/signin/signin_manager_factory.h" | 21 #include "chrome/browser/signin/signin_manager_factory.h" |
21 #include "chrome/browser/ui/browser.h" | 22 #include "chrome/browser/ui/browser.h" |
22 #include "chrome/common/extensions/features/feature_channel.h" | 23 #include "chrome/common/extensions/features/feature_channel.h" |
23 #include "chrome/common/pref_names.h" | 24 #include "chrome/common/pref_names.h" |
24 #include "chrome/test/base/testing_profile.h" | 25 #include "chrome/test/base/testing_profile.h" |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
128 SigninManagerFactory::GetForProfile(profile()); | 129 SigninManagerFactory::GetForProfile(profile()); |
129 signin_manager->SetAuthenticatedUsername(kTestingUsername); | 130 signin_manager->SetAuthenticatedUsername(kTestingUsername); |
130 | 131 |
131 // Encryptor ends up needing access to the keychain on OS X. So use the mock | 132 // Encryptor ends up needing access to the keychain on OS X. So use the mock |
132 // keychain to prevent prompts. | 133 // keychain to prevent prompts. |
133 #if defined(OS_MACOSX) | 134 #if defined(OS_MACOSX) |
134 Encryptor::UseMockKeychain(true); | 135 Encryptor::UseMockKeychain(true); |
135 #endif | 136 #endif |
136 | 137 |
137 // Mock a GCMClient. | 138 // Mock a GCMClient. |
138 GCMClient::SetTestingFactory(&GCMProfileServiceTest::BuildGCMClient); | 139 GCMClientFactory::SetTestingFactory(&GCMProfileServiceTest::BuildGCMClient); |
139 | 140 |
140 // Mock a GCMEventRouter. | 141 // Mock a GCMEventRouter. |
141 gcm_event_router_mock_.reset(new GCMEventRouterMock(this)); | 142 gcm_event_router_mock_.reset(new GCMEventRouterMock(this)); |
142 | 143 |
143 // Set |gps_testing_delegate_| for it to be picked up by | 144 // Set |gps_testing_delegate_| for it to be picked up by |
144 // BuildGCMProfileService and pass it to GCMProfileService. | 145 // BuildGCMProfileService and pass it to GCMProfileService. |
145 gps_testing_delegate_ = this; | 146 gps_testing_delegate_ = this; |
146 | 147 |
147 // This will create GCMProfileService that causes check-in to be initiated. | 148 // This will create GCMProfileService that causes check-in to be initiated. |
148 GCMProfileService::enable_gcm_for_testing_ = true; | 149 GCMProfileService::enable_gcm_for_testing_ = true; |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
237 scoped_ptr<chromeos::ScopedTestUserManager> test_user_manager_; | 238 scoped_ptr<chromeos::ScopedTestUserManager> test_user_manager_; |
238 #endif | 239 #endif |
239 | 240 |
240 private: | 241 private: |
241 static GCMProfileService::TestingDelegate* gps_testing_delegate_; | 242 static GCMProfileService::TestingDelegate* gps_testing_delegate_; |
242 | 243 |
243 DISALLOW_COPY_AND_ASSIGN(GCMProfileServiceTest); | 244 DISALLOW_COPY_AND_ASSIGN(GCMProfileServiceTest); |
244 }; | 245 }; |
245 | 246 |
246 static GCMClientMock* GetGCMClientMock() { | 247 static GCMClientMock* GetGCMClientMock() { |
247 return static_cast<GCMClientMock*>(GCMClient::Get()); | 248 return static_cast<GCMClientMock*>(GCMClientFactory::GetClient()); |
248 } | 249 } |
249 | 250 |
250 class ScopedGCMClientMockSimulateServerError { | 251 class ScopedGCMClientMockSimulateServerError { |
251 public: | 252 public: |
252 ScopedGCMClientMockSimulateServerError() { | 253 ScopedGCMClientMockSimulateServerError() { |
253 GetGCMClientMock()->set_simulate_server_error(true); | 254 GetGCMClientMock()->set_simulate_server_error(true); |
254 } | 255 } |
255 | 256 |
256 ~ScopedGCMClientMockSimulateServerError() { | 257 ~ScopedGCMClientMockSimulateServerError() { |
257 GetGCMClientMock()->set_simulate_server_error(false); | 258 GetGCMClientMock()->set_simulate_server_error(false); |
(...skipping 442 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
700 | 701 |
701 TEST_F(GCMProfileServiceTest, MessagesDeleted) { | 702 TEST_F(GCMProfileServiceTest, MessagesDeleted) { |
702 GetGCMClientMock()->DeleteMessages(kTestingUsername, kTestingAppId); | 703 GetGCMClientMock()->DeleteMessages(kTestingUsername, kTestingAppId); |
703 WaitForCompleted(); | 704 WaitForCompleted(); |
704 EXPECT_EQ(GCMEventRouterMock::MESSAGES_DELETED_EVENT, | 705 EXPECT_EQ(GCMEventRouterMock::MESSAGES_DELETED_EVENT, |
705 gcm_event_router_mock_->received_event()); | 706 gcm_event_router_mock_->received_event()); |
706 EXPECT_EQ(kTestingAppId, gcm_event_router_mock_->app_id()); | 707 EXPECT_EQ(kTestingAppId, gcm_event_router_mock_->app_id()); |
707 } | 708 } |
708 | 709 |
709 } // namespace gcm | 710 } // namespace gcm |
OLD | NEW |