Commit 3413946b authored by Peter Beverloo's avatar Peter Beverloo Committed by Commit Bot

Move the FakeGCMProfileService helper to the GCM Driver component

TBR=jianli, finnur and jamescook for include path changes

Bug: 829604
Change-Id: Icb53714ede7a4ce40ca38ee4c79740b64c70997a
Reviewed-on: https://chromium-review.googlesource.com/1001894Reviewed-by: default avatarPeter Beverloo <peter@chromium.org>
Reviewed-by: default avatarFinnur Thorarinsson <finnur@chromium.org>
Reviewed-by: default avatarAvi Drissman <avi@chromium.org>
Reviewed-by: default avatarNicolas Zea (slow) <zea@chromium.org>
Commit-Queue: Peter Beverloo <peter@chromium.org>
Cr-Commit-Position: refs/heads/master@{#549519}
parent 19d2ae60
...@@ -4622,8 +4622,6 @@ static_library("test_support") { ...@@ -4622,8 +4622,6 @@ static_library("test_support") {
"consent_auditor/consent_auditor_test_utils.h", "consent_auditor/consent_auditor_test_utils.h",
"download/download_test_file_activity_observer.cc", "download/download_test_file_activity_observer.cc",
"download/download_test_file_activity_observer.h", "download/download_test_file_activity_observer.h",
"gcm/fake_gcm_profile_service.cc",
"gcm/fake_gcm_profile_service.h",
"history/history_test_utils.cc", "history/history_test_utils.cc",
"history/history_test_utils.h", "history/history_test_utils.h",
"media/webrtc/fake_desktop_media_list.cc", "media/webrtc/fake_desktop_media_list.cc",
......
...@@ -3,10 +3,10 @@ ...@@ -3,10 +3,10 @@
// found in the LICENSE file. // found in the LICENSE file.
#include "chrome/browser/chromeos/net/wake_on_wifi_connection_observer.h" #include "chrome/browser/chromeos/net/wake_on_wifi_connection_observer.h"
#include "chrome/browser/gcm/fake_gcm_profile_service.h"
#include "chrome/browser/gcm/gcm_profile_service_factory.h" #include "chrome/browser/gcm/gcm_profile_service_factory.h"
#include "chrome/test/base/testing_profile.h" #include "chrome/test/base/testing_profile.h"
#include "chromeos/network/mock_network_device_handler.h" #include "chromeos/network/mock_network_device_handler.h"
#include "components/gcm_driver/fake_gcm_profile_service.h"
#include "content/public/test/test_browser_thread_bundle.h" #include "content/public/test/test_browser_thread_bundle.h"
#include "testing/gmock/include/gmock/gmock.h" #include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
......
...@@ -7,12 +7,12 @@ ...@@ -7,12 +7,12 @@
#include "chrome/browser/extensions/api/gcm/gcm_api.h" #include "chrome/browser/extensions/api/gcm/gcm_api.h"
#include "chrome/browser/extensions/extension_apitest.h" #include "chrome/browser/extensions/extension_apitest.h"
#include "chrome/browser/extensions/extension_gcm_app_handler.h" #include "chrome/browser/extensions/extension_gcm_app_handler.h"
#include "chrome/browser/gcm/fake_gcm_profile_service.h"
#include "chrome/browser/gcm/gcm_profile_service_factory.h" #include "chrome/browser/gcm/gcm_profile_service_factory.h"
#include "chrome/browser/profiles/profile.h" #include "chrome/browser/profiles/profile.h"
#include "chrome/common/chrome_switches.h" #include "chrome/common/chrome_switches.h"
#include "chrome/test/base/ui_test_utils.h" #include "chrome/test/base/ui_test_utils.h"
#include "components/browser_sync/browser_sync_switches.h" #include "components/browser_sync/browser_sync_switches.h"
#include "components/gcm_driver/fake_gcm_profile_service.h"
#include "extensions/test/result_catcher.h" #include "extensions/test/result_catcher.h"
using extensions::ResultCatcher; using extensions::ResultCatcher;
......
...@@ -10,11 +10,11 @@ ...@@ -10,11 +10,11 @@
#include "chrome/browser/extensions/api/instance_id/instance_id_api.h" #include "chrome/browser/extensions/api/instance_id/instance_id_api.h"
#include "chrome/browser/extensions/extension_apitest.h" #include "chrome/browser/extensions/extension_apitest.h"
#include "chrome/browser/extensions/extension_gcm_app_handler.h" #include "chrome/browser/extensions/extension_gcm_app_handler.h"
#include "chrome/browser/gcm/fake_gcm_profile_service.h"
#include "chrome/browser/gcm/gcm_profile_service_factory.h" #include "chrome/browser/gcm/gcm_profile_service_factory.h"
#include "chrome/browser/gcm/instance_id/instance_id_profile_service_factory.h" #include "chrome/browser/gcm/instance_id/instance_id_profile_service_factory.h"
#include "chrome/browser/profiles/profile.h" #include "chrome/browser/profiles/profile.h"
#include "chrome/test/base/ui_test_utils.h" #include "chrome/test/base/ui_test_utils.h"
#include "components/gcm_driver/fake_gcm_profile_service.h"
#include "components/gcm_driver/instance_id/fake_gcm_driver_for_instance_id.h" #include "components/gcm_driver/instance_id/fake_gcm_driver_for_instance_id.h"
#include "components/version_info/version_info.h" #include "components/version_info/version_info.h"
#include "extensions/test/result_catcher.h" #include "extensions/test/result_catcher.h"
......
...@@ -14,7 +14,6 @@ ...@@ -14,7 +14,6 @@
#include "chrome/browser/extensions/extension_apitest.h" #include "chrome/browser/extensions/extension_apitest.h"
#include "chrome/browser/extensions/extension_service.h" #include "chrome/browser/extensions/extension_service.h"
#include "chrome/browser/extensions/lazy_background_page_test_util.h" #include "chrome/browser/extensions/lazy_background_page_test_util.h"
#include "chrome/browser/gcm/fake_gcm_profile_service.h"
#include "chrome/browser/gcm/gcm_profile_service_factory.h" #include "chrome/browser/gcm/gcm_profile_service_factory.h"
#include "chrome/browser/notifications/desktop_notification_profile_util.h" #include "chrome/browser/notifications/desktop_notification_profile_util.h"
#include "chrome/browser/notifications/notification_display_service_factory.h" #include "chrome/browser/notifications/notification_display_service_factory.h"
...@@ -28,6 +27,7 @@ ...@@ -28,6 +27,7 @@
#include "chrome/common/chrome_switches.h" #include "chrome/common/chrome_switches.h"
#include "chrome/test/base/ui_test_utils.h" #include "chrome/test/base/ui_test_utils.h"
#include "components/content_settings/core/common/content_settings_types.h" #include "components/content_settings/core/common/content_settings_types.h"
#include "components/gcm_driver/fake_gcm_profile_service.h"
#include "components/gcm_driver/instance_id/fake_gcm_driver_for_instance_id.h" #include "components/gcm_driver/instance_id/fake_gcm_driver_for_instance_id.h"
#include "components/version_info/version_info.h" #include "components/version_info/version_info.h"
#include "content/public/browser/navigation_controller.h" #include "content/public/browser/navigation_controller.h"
......
...@@ -7,9 +7,9 @@ ...@@ -7,9 +7,9 @@
#include "base/run_loop.h" #include "base/run_loop.h"
#include "base/test/scoped_feature_list.h" #include "base/test/scoped_feature_list.h"
#include "base/test/scoped_task_environment.h" #include "base/test/scoped_task_environment.h"
#include "chrome/browser/gcm/fake_gcm_profile_service.h"
#include "chrome/browser/gcm/gcm_profile_service_factory.h" #include "chrome/browser/gcm/gcm_profile_service_factory.h"
#include "chrome/test/base/testing_profile.h" #include "chrome/test/base/testing_profile.h"
#include "components/gcm_driver/fake_gcm_profile_service.h"
#include "components/gcm_driver/instance_id/instance_id.h" #include "components/gcm_driver/instance_id/instance_id.h"
#include "components/offline_pages/core/offline_page_feature.h" #include "components/offline_pages/core/offline_page_feature.h"
#include "content/public/test/test_browser_thread_bundle.h" #include "content/public/test/test_browser_thread_bundle.h"
......
...@@ -25,7 +25,6 @@ ...@@ -25,7 +25,6 @@
#include "chrome/browser/content_settings/host_content_settings_map_factory.h" #include "chrome/browser/content_settings/host_content_settings_map_factory.h"
#include "chrome/browser/engagement/site_engagement_score.h" #include "chrome/browser/engagement/site_engagement_score.h"
#include "chrome/browser/engagement/site_engagement_service.h" #include "chrome/browser/engagement/site_engagement_service.h"
#include "chrome/browser/gcm/fake_gcm_profile_service.h"
#include "chrome/browser/gcm/gcm_profile_service_factory.h" #include "chrome/browser/gcm/gcm_profile_service_factory.h"
#include "chrome/browser/gcm/instance_id/instance_id_profile_service.h" #include "chrome/browser/gcm/instance_id/instance_id_profile_service.h"
#include "chrome/browser/gcm/instance_id/instance_id_profile_service_factory.h" #include "chrome/browser/gcm/instance_id/instance_id_profile_service_factory.h"
...@@ -47,6 +46,7 @@ ...@@ -47,6 +46,7 @@
#include "components/content_settings/core/common/content_settings.h" #include "components/content_settings/core/common/content_settings.h"
#include "components/content_settings/core/common/content_settings_types.h" #include "components/content_settings/core/common/content_settings_types.h"
#include "components/gcm_driver/common/gcm_messages.h" #include "components/gcm_driver/common/gcm_messages.h"
#include "components/gcm_driver/fake_gcm_profile_service.h"
#include "components/gcm_driver/gcm_client.h" #include "components/gcm_driver/gcm_client.h"
#include "components/gcm_driver/instance_id/fake_gcm_driver_for_instance_id.h" #include "components/gcm_driver/instance_id/fake_gcm_driver_for_instance_id.h"
#include "components/gcm_driver/instance_id/instance_id_driver.h" #include "components/gcm_driver/instance_id/instance_id_driver.h"
......
...@@ -14,7 +14,6 @@ ...@@ -14,7 +14,6 @@
#include "base/run_loop.h" #include "base/run_loop.h"
#include "base/threading/thread_task_runner_handle.h" #include "base/threading/thread_task_runner_handle.h"
#include "chrome/browser/content_settings/host_content_settings_map_factory.h" #include "chrome/browser/content_settings/host_content_settings_map_factory.h"
#include "chrome/browser/gcm/fake_gcm_profile_service.h"
#include "chrome/browser/gcm/gcm_profile_service_factory.h" #include "chrome/browser/gcm/gcm_profile_service_factory.h"
#include "chrome/browser/permissions/permission_manager.h" #include "chrome/browser/permissions/permission_manager.h"
#include "chrome/browser/permissions/permission_manager_factory.h" #include "chrome/browser/permissions/permission_manager_factory.h"
...@@ -25,6 +24,7 @@ ...@@ -25,6 +24,7 @@
#include "components/content_settings/core/browser/host_content_settings_map.h" #include "components/content_settings/core/browser/host_content_settings_map.h"
#include "components/gcm_driver/crypto/gcm_crypto_test_helpers.h" #include "components/gcm_driver/crypto/gcm_crypto_test_helpers.h"
#include "components/gcm_driver/fake_gcm_client_factory.h" #include "components/gcm_driver/fake_gcm_client_factory.h"
#include "components/gcm_driver/fake_gcm_profile_service.h"
#include "components/gcm_driver/gcm_profile_service.h" #include "components/gcm_driver/gcm_profile_service.h"
#include "content/public/common/push_event_payload.h" #include "content/public/common/push_event_payload.h"
#include "content/public/common/push_messaging_status.mojom.h" #include "content/public/common/push_messaging_status.mojom.h"
......
...@@ -123,6 +123,8 @@ static_library("test_support") { ...@@ -123,6 +123,8 @@ static_library("test_support") {
"fake_gcm_app_handler.h", "fake_gcm_app_handler.h",
"fake_gcm_driver.cc", "fake_gcm_driver.cc",
"fake_gcm_driver.h", "fake_gcm_driver.h",
"fake_gcm_profile_service.cc",
"fake_gcm_profile_service.h",
] ]
public_deps = [ public_deps = [
...@@ -130,11 +132,27 @@ static_library("test_support") { ...@@ -130,11 +132,27 @@ static_library("test_support") {
] ]
deps = [ deps = [
"//base", "//base",
"//components/gcm_driver/instance_id:test_support",
"//content/public/browser",
"//google_apis/gcm:test_support", "//google_apis/gcm:test_support",
"//net", "//net",
"//testing/gtest", "//testing/gtest",
] ]
# This target goes with Instance ID and they can include headers from each
# other.
allow_circular_includes_from =
[ "//components/gcm_driver/instance_id:test_support" ]
if (is_ios) {
sources -= [
"fake_gcm_profile_service.cc",
"fake_gcm_profile_service.h",
]
deps -= [ "//content/public/browser" ]
}
if (!use_gcm_from_platform) { if (!use_gcm_from_platform) {
sources += [ sources += [
"fake_gcm_client.cc", "fake_gcm_client.cc",
......
...@@ -10,6 +10,7 @@ include_rules = [ ...@@ -10,6 +10,7 @@ include_rules = [
"+components/sync/protocol", "+components/sync/protocol",
"+components/timers", # Only used for Chrome OS builds. "+components/timers", # Only used for Chrome OS builds.
"+components/version_info", "+components/version_info",
"+content/public/browser/browser_context.h",
"+google_apis/gaia", "+google_apis/gaia",
"+google_apis/gcm", "+google_apis/gcm",
"+jni", "+jni",
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#include "chrome/browser/gcm/fake_gcm_profile_service.h" #include "components/gcm_driver/fake_gcm_profile_service.h"
#include <utility> #include <utility>
...@@ -16,11 +16,9 @@ ...@@ -16,11 +16,9 @@
#include "base/strings/stringprintf.h" #include "base/strings/stringprintf.h"
#include "base/threading/thread_task_runner_handle.h" #include "base/threading/thread_task_runner_handle.h"
#include "base/time/time.h" #include "base/time/time.h"
#include "chrome/browser/profiles/profile.h"
#include "components/gcm_driver/fake_gcm_client_factory.h" #include "components/gcm_driver/fake_gcm_client_factory.h"
#include "components/gcm_driver/gcm_driver.h" #include "components/gcm_driver/gcm_driver.h"
#include "components/gcm_driver/instance_id/fake_gcm_driver_for_instance_id.h" #include "components/gcm_driver/instance_id/fake_gcm_driver_for_instance_id.h"
#include "content/public/browser/browser_context.h"
namespace gcm { namespace gcm {
...@@ -199,16 +197,17 @@ void FakeGCMProfileService::CustomFakeGCMDriver::OnDispatchMessage( ...@@ -199,16 +197,17 @@ void FakeGCMProfileService::CustomFakeGCMDriver::OnDispatchMessage(
// static // static
std::unique_ptr<KeyedService> FakeGCMProfileService::Build( std::unique_ptr<KeyedService> FakeGCMProfileService::Build(
content::BrowserContext* context) { content::BrowserContext* context) {
Profile* profile = static_cast<Profile*>(context); std::unique_ptr<FakeGCMProfileService> service =
std::unique_ptr<FakeGCMProfileService> service( std::make_unique<FakeGCMProfileService>();
new FakeGCMProfileService(profile)); service->SetDriverForTesting(
service->SetDriverForTesting(new CustomFakeGCMDriver(service.get())); std::make_unique<CustomFakeGCMDriver>(service.get()));
return std::move(service);
return service;
} }
FakeGCMProfileService::FakeGCMProfileService(Profile* profile) {} FakeGCMProfileService::FakeGCMProfileService() = default;
FakeGCMProfileService::~FakeGCMProfileService() {} FakeGCMProfileService::~FakeGCMProfileService() = default;
void FakeGCMProfileService::AddExpectedUnregisterResponse( void FakeGCMProfileService::AddExpectedUnregisterResponse(
GCMClient::Result result) { GCMClient::Result result) {
......
...@@ -2,8 +2,8 @@ ...@@ -2,8 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#ifndef CHROME_BROWSER_GCM_FAKE_GCM_PROFILE_SERVICE_H_ #ifndef COMPONENTS_GCM_DRIVER_FAKE_GCM_PROFILE_SERVICE_H_
#define CHROME_BROWSER_GCM_FAKE_GCM_PROFILE_SERVICE_H_ #define COMPONENTS_GCM_DRIVER_FAKE_GCM_PROFILE_SERVICE_H_
#include <list> #include <list>
#include <memory> #include <memory>
...@@ -13,23 +13,17 @@ ...@@ -13,23 +13,17 @@
#include "components/gcm_driver/common/gcm_messages.h" #include "components/gcm_driver/common/gcm_messages.h"
#include "components/gcm_driver/gcm_client.h" #include "components/gcm_driver/gcm_client.h"
#include "components/gcm_driver/gcm_profile_service.h" #include "components/gcm_driver/gcm_profile_service.h"
#include "content/public/browser/browser_context.h"
class Profile;
namespace content {
class BrowserContext;
} // namespace content
namespace gcm { namespace gcm {
// Acts as a bridge between GCM API and GCMClient layer for testing purposes. // Acts as a bridge between GCM API and GCM Client layer for testing purposes.
class FakeGCMProfileService : public GCMProfileService { class FakeGCMProfileService : public GCMProfileService {
public: public:
// Helper function to be used with // Helper function to be used with KeyedServiceFactory::SetTestingFactory().
// KeyedService::SetTestingFactory().
static std::unique_ptr<KeyedService> Build(content::BrowserContext* context); static std::unique_ptr<KeyedService> Build(content::BrowserContext* context);
explicit FakeGCMProfileService(Profile* profile); FakeGCMProfileService();
~FakeGCMProfileService() override; ~FakeGCMProfileService() override;
void AddExpectedUnregisterResponse(GCMClient::Result result); void AddExpectedUnregisterResponse(GCMClient::Result result);
...@@ -41,9 +35,7 @@ class FakeGCMProfileService : public GCMProfileService { ...@@ -41,9 +35,7 @@ class FakeGCMProfileService : public GCMProfileService {
return last_sent_message_; return last_sent_message_;
} }
const std::string& last_receiver_id() const { const std::string& last_receiver_id() const { return last_receiver_id_; }
return last_receiver_id_;
}
const std::string& last_registered_app_id() const { const std::string& last_registered_app_id() const {
return last_registered_app_id_; return last_registered_app_id_;
...@@ -79,4 +71,4 @@ class FakeGCMProfileService : public GCMProfileService { ...@@ -79,4 +71,4 @@ class FakeGCMProfileService : public GCMProfileService {
} // namespace gcm } // namespace gcm
#endif // CHROME_BROWSER_GCM_FAKE_GCM_PROFILE_SERVICE_H_ #endif // COMPONENTS_GCM_DRIVER_FAKE_GCM_PROFILE_SERVICE_H_
...@@ -173,12 +173,13 @@ void GCMProfileService::Shutdown() { ...@@ -173,12 +173,13 @@ void GCMProfileService::Shutdown() {
} }
} }
void GCMProfileService::SetDriverForTesting(GCMDriver* driver) { void GCMProfileService::SetDriverForTesting(std::unique_ptr<GCMDriver> driver) {
driver_.reset(driver); driver_ = std::move(driver);
#if !BUILDFLAG(USE_GCM_FROM_PLATFORM) #if !BUILDFLAG(USE_GCM_FROM_PLATFORM)
if (identity_observer_) { if (identity_observer_) {
identity_observer_.reset(new IdentityObserver( identity_observer_ = std::make_unique<IdentityObserver>(
profile_identity_provider_.get(), request_context_, driver)); profile_identity_provider_.get(), request_context_, driver_.get());
} }
#endif // !BUILDFLAG(USE_GCM_FROM_PLATFORM) #endif // !BUILDFLAG(USE_GCM_FROM_PLATFORM)
} }
......
...@@ -62,8 +62,8 @@ class GCMProfileService : public KeyedService { ...@@ -62,8 +62,8 @@ class GCMProfileService : public KeyedService {
// KeyedService: // KeyedService:
void Shutdown() override; void Shutdown() override;
// For testing purpose. // For testing purposes.
void SetDriverForTesting(GCMDriver* driver); void SetDriverForTesting(std::unique_ptr<GCMDriver> driver);
GCMDriver* driver() const { return driver_.get(); } GCMDriver* driver() const { return driver_.get(); }
......
...@@ -46,7 +46,7 @@ static_library("test_support") { ...@@ -46,7 +46,7 @@ static_library("test_support") {
] ]
deps = [ deps = [
"//base", "//base",
"//components/gcm_driver:test_support", "//components/gcm_driver",
"//testing/gtest", "//testing/gtest",
] ]
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment