| 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/extensions/extension_gcm_app_handler.h" | 5 #include "chrome/browser/extensions/extension_gcm_app_handler.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" |
| 11 #include "base/command_line.h" | 11 #include "base/command_line.h" |
| 12 #include "base/files/file_path.h" | 12 #include "base/files/file_path.h" |
| 13 #include "base/location.h" | 13 #include "base/location.h" |
| 14 #include "base/logging.h" | 14 #include "base/logging.h" |
| 15 #include "base/memory/ref_counted.h" | 15 #include "base/memory/ref_counted.h" |
| 16 #include "base/message_loop/message_loop.h" | 16 #include "base/message_loop/message_loop.h" |
| 17 #include "base/run_loop.h" | 17 #include "base/run_loop.h" |
| 18 #include "base/values.h" | 18 #include "base/values.h" |
| 19 #include "chrome/browser/extensions/extension_service.h" | 19 #include "chrome/browser/extensions/extension_service.h" |
| 20 #include "chrome/browser/extensions/test_extension_service.h" | 20 #include "chrome/browser/extensions/test_extension_service.h" |
| 21 #include "chrome/browser/extensions/test_extension_system.h" | 21 #include "chrome/browser/extensions/test_extension_system.h" |
| 22 #include "chrome/browser/profiles/profile.h" | 22 #include "chrome/browser/profiles/profile.h" |
| 23 #include "chrome/browser/services/gcm/fake_gcm_client.h" | 23 #include "chrome/browser/services/gcm/fake_gcm_client.h" |
| 24 #include "chrome/browser/services/gcm/fake_gcm_client_factory.h" | 24 #include "chrome/browser/services/gcm/fake_gcm_client_factory.h" |
| 25 #include "chrome/browser/services/gcm/fake_signin_manager.h" | 25 #include "chrome/browser/services/gcm/fake_signin_manager.h" |
| 26 #include "chrome/browser/services/gcm/gcm_driver.h" |
| 26 #include "chrome/browser/services/gcm/gcm_profile_service.h" | 27 #include "chrome/browser/services/gcm/gcm_profile_service.h" |
| 27 #include "chrome/browser/services/gcm/gcm_profile_service_factory.h" | 28 #include "chrome/browser/services/gcm/gcm_profile_service_factory.h" |
| 28 #include "chrome/browser/signin/signin_manager_factory.h" | 29 #include "chrome/browser/signin/signin_manager_factory.h" |
| 29 #include "chrome/common/pref_names.h" | 30 #include "chrome/common/pref_names.h" |
| 30 #include "chrome/test/base/testing_profile.h" | 31 #include "chrome/test/base/testing_profile.h" |
| 31 #include "components/gcm_driver/gcm_client_factory.h" | 32 #include "components/gcm_driver/gcm_client_factory.h" |
| 32 #include "components/keyed_service/core/keyed_service.h" | 33 #include "components/keyed_service/core/keyed_service.h" |
| 33 #include "content/public/browser/browser_context.h" | 34 #include "content/public/browser/browser_context.h" |
| 34 #include "content/public/browser/browser_thread.h" | 35 #include "content/public/browser/browser_thread.h" |
| 35 #include "content/public/test/test_browser_thread_bundle.h" | 36 #include "content/public/test/test_browser_thread_bundle.h" |
| (...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 281 waiter_.PumpIOLoop(); | 282 waiter_.PumpIOLoop(); |
| 282 } | 283 } |
| 283 | 284 |
| 284 void SignOut() { | 285 void SignOut() { |
| 285 signin_manager_->SignOut(); | 286 signin_manager_->SignOut(); |
| 286 waiter_.PumpIOLoop(); | 287 waiter_.PumpIOLoop(); |
| 287 } | 288 } |
| 288 | 289 |
| 289 void Register(const std::string& app_id, | 290 void Register(const std::string& app_id, |
| 290 const std::vector<std::string>& sender_ids) { | 291 const std::vector<std::string>& sender_ids) { |
| 291 GetGCMProfileService()->Register( | 292 GetGCMDriver()->Register( |
| 292 app_id, | 293 app_id, |
| 293 sender_ids, | 294 sender_ids, |
| 294 base::Bind(&ExtensionGCMAppHandlerTest::RegisterCompleted, | 295 base::Bind(&ExtensionGCMAppHandlerTest::RegisterCompleted, |
| 295 base::Unretained(this))); | 296 base::Unretained(this))); |
| 296 } | 297 } |
| 297 | 298 |
| 298 void RegisterCompleted(const std::string& registration_id, | 299 void RegisterCompleted(const std::string& registration_id, |
| 299 gcm::GCMClient::Result result) { | 300 gcm::GCMClient::Result result) { |
| 300 registration_result_ = result; | 301 registration_result_ = result; |
| 301 waiter_.SignalCompleted(); | 302 waiter_.SignalCompleted(); |
| 302 } | 303 } |
| 303 | 304 |
| 304 gcm::GCMProfileService* GetGCMProfileService() const { | 305 gcm::GCMDriver* GetGCMDriver() const { |
| 305 return gcm::GCMProfileServiceFactory::GetForProfile(profile()); | 306 return gcm::GCMProfileServiceFactory::GetForProfile(profile())->driver(); |
| 306 } | 307 } |
| 307 | 308 |
| 308 bool HasAppHandlers(const std::string& app_id) const { | 309 bool HasAppHandlers(const std::string& app_id) const { |
| 309 return GetGCMProfileService()->app_handlers().count(app_id); | 310 return GetGCMDriver()->app_handlers().count(app_id); |
| 310 } | 311 } |
| 311 | 312 |
| 312 Profile* profile() const { return profile_.get(); } | 313 Profile* profile() const { return profile_.get(); } |
| 313 Waiter* waiter() { return &waiter_; } | 314 Waiter* waiter() { return &waiter_; } |
| 314 FakeExtensionGCMAppHandler* gcm_app_handler() const { | 315 FakeExtensionGCMAppHandler* gcm_app_handler() const { |
| 315 return gcm_app_handler_.get(); | 316 return gcm_app_handler_.get(); |
| 316 } | 317 } |
| 317 gcm::GCMClient::Result registration_result() const { | 318 gcm::GCMClient::Result registration_result() const { |
| 318 return registration_result_; | 319 return registration_result_; |
| 319 } | 320 } |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 381 EXPECT_EQ(gcm::GCMClient::SUCCESS, registration_result()); | 382 EXPECT_EQ(gcm::GCMClient::SUCCESS, registration_result()); |
| 382 | 383 |
| 383 // Unregistration should be triggered when the extension is uninstalled. | 384 // Unregistration should be triggered when the extension is uninstalled. |
| 384 UninstallExtension(extension); | 385 UninstallExtension(extension); |
| 385 waiter()->WaitUntilCompleted(); | 386 waiter()->WaitUntilCompleted(); |
| 386 EXPECT_EQ(gcm::GCMClient::SUCCESS, | 387 EXPECT_EQ(gcm::GCMClient::SUCCESS, |
| 387 gcm_app_handler()->unregistration_result()); | 388 gcm_app_handler()->unregistration_result()); |
| 388 } | 389 } |
| 389 | 390 |
| 390 } // namespace extensions | 391 } // namespace extensions |
| OLD | NEW |