Commit b7f468df authored by Michael van Ouwerkerk's avatar Michael van Ouwerkerk Committed by Commit Bot

Add basic RemoteCopyBrowserTest for text content.

Get NotificationDisplayService lazily so that browser
tests can use NotificationDisplayServiceTester.

Bug: 1020582
Change-Id: Ifc85c2e63e6ca1c17eb29fdbfa91624802220ecd
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1899847Reviewed-by: default avatarRichard Knoll <knollr@chromium.org>
Commit-Queue: Michael van Ouwerkerk <mvanouwerkerk@chromium.org>
Cr-Commit-Position: refs/heads/master@{#712610}
parent a8300672
...@@ -85,6 +85,7 @@ class ClickToCallUtilsTest : public testing::Test { ...@@ -85,6 +85,7 @@ class ClickToCallUtilsTest : public testing::Test {
return nullptr; return nullptr;
return std::make_unique<SharingService>( return std::make_unique<SharingService>(
&profile_,
/* sync_prefs= */ nullptr, /* sync_prefs= */ nullptr,
/* vapid_key_manager= */ nullptr, /* vapid_key_manager= */ nullptr,
std::make_unique<MockSharingDeviceRegistration>(), std::make_unique<MockSharingDeviceRegistration>(),
...@@ -96,8 +97,7 @@ class ClickToCallUtilsTest : public testing::Test { ...@@ -96,8 +97,7 @@ class ClickToCallUtilsTest : public testing::Test {
/* gcm_driver= */ nullptr, /* gcm_driver= */ nullptr,
/* device_info_tracker= */ nullptr, /* device_info_tracker= */ nullptr,
/* local_device_info_provider= */ nullptr, /* local_device_info_provider= */ nullptr,
/* sync_service */ nullptr, /* sync_service */ nullptr);
/* notification_display_service= */ nullptr);
} }
base::test::ScopedFeatureList scoped_feature_list_; base::test::ScopedFeatureList scoped_feature_list_;
......
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
MockSharingService::MockSharingService() MockSharingService::MockSharingService()
: SharingService( : SharingService(
/*profile=*/nullptr,
/*sync_prefs=*/nullptr, /*sync_prefs=*/nullptr,
/*vapid_key_manager=*/nullptr, /*vapid_key_manager=*/nullptr,
std::make_unique<SharingDeviceRegistration>( std::make_unique<SharingDeviceRegistration>(
...@@ -26,7 +27,6 @@ MockSharingService::MockSharingService() ...@@ -26,7 +27,6 @@ MockSharingService::MockSharingService()
/*gcm_driver=*/nullptr, /*gcm_driver=*/nullptr,
/*device_info_tracker=*/nullptr, /*device_info_tracker=*/nullptr,
/*local_device_info_provider=*/nullptr, /*local_device_info_provider=*/nullptr,
/*sync_service*/ nullptr, /*sync_service*/ nullptr) {}
/*notification_display_service=*/nullptr) {}
MockSharingService::~MockSharingService() = default; MockSharingService::~MockSharingService() = default;
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include <memory>
#include <string>
#include "base/guid.h"
#include "base/macros.h"
#include "base/strings/utf_string_conversions.h"
#include "base/test/scoped_feature_list.h"
#include "chrome/browser/notifications/notification_display_service_tester.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/sharing/shared_clipboard/feature_flags.h"
#include "chrome/browser/sharing/sharing_constants.h"
#include "chrome/browser/sharing/sharing_fcm_handler.h"
#include "chrome/browser/sharing/sharing_service.h"
#include "chrome/browser/sharing/sharing_service_factory.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/grit/generated_resources.h"
#include "chrome/test/base/in_process_browser_test.h"
#include "ui/base/clipboard/clipboard.h"
#include "ui/base/clipboard/test/test_clipboard.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/message_center/public/cpp/notification.h"
namespace {
const char kText[] = "clipboard text";
const char kDeviceName[] = "DeviceName";
} // namespace
// Browser tests for the Remote Copy feature.
class RemoteCopyBrowserTestBase : public InProcessBrowserTest {
public:
RemoteCopyBrowserTestBase() = default;
~RemoteCopyBrowserTestBase() override = default;
void SetUpOnMainThread() override {
ui::TestClipboard::CreateForCurrentThread();
notification_tester_ = std::make_unique<NotificationDisplayServiceTester>(
browser()->profile());
sharing_service_ =
SharingServiceFactory::GetForBrowserContext(browser()->profile());
}
void TearDownOnMainThread() override {
notification_tester_.reset();
ui::Clipboard::DestroyClipboardForCurrentThread();
}
gcm::IncomingMessage CreateMessage(std::string guid,
std::string device_name,
std::string text) {
chrome_browser_sharing::SharingMessage sharing_message;
sharing_message.set_sender_guid(guid);
sharing_message.set_sender_device_name(device_name);
sharing_message.mutable_remote_copy_message()->set_text(text);
gcm::IncomingMessage incoming_message;
std::string serialized_sharing_message;
sharing_message.SerializeToString(&serialized_sharing_message);
incoming_message.raw_data = serialized_sharing_message;
return incoming_message;
}
std::string GetClipboardText() {
base::string16 text;
ui::Clipboard::GetForCurrentThread()->ReadText(
ui::ClipboardBuffer::kCopyPaste, &text);
return base::UTF16ToUTF8(text);
}
message_center::Notification GetNotification() {
auto notifications = notification_tester_->GetDisplayedNotificationsForType(
NotificationHandler::Type::SHARING);
EXPECT_EQ(notifications.size(), 1u);
const message_center::Notification& notification = notifications[0];
EXPECT_EQ(message_center::NOTIFICATION_TYPE_SIMPLE, notification.type());
return notification;
}
protected:
base::test::ScopedFeatureList feature_list_;
std::unique_ptr<NotificationDisplayServiceTester> notification_tester_;
SharingService* sharing_service_;
private:
DISALLOW_COPY_AND_ASSIGN(RemoteCopyBrowserTestBase);
};
class RemoteCopyBrowserTest : public RemoteCopyBrowserTestBase {
public:
RemoteCopyBrowserTest() {
feature_list_.InitWithFeatures({kRemoteCopyReceiver}, {});
}
};
IN_PROC_BROWSER_TEST_F(RemoteCopyBrowserTest, HandleMessage) {
sharing_service_->GetFCMHandlerForTesting()->OnMessage(
kSharingFCMAppID,
CreateMessage(base::GenerateGUID(), kDeviceName, kText));
EXPECT_EQ(GetClipboardText(), kText);
EXPECT_EQ(l10n_util::GetStringFUTF16(
IDS_CONTENT_CONTEXT_SHARING_SHARED_CLIPBOARD_NOTIFICATION_TITLE,
base::ASCIIToUTF16(kDeviceName)),
GetNotification().title());
}
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
#include "base/strings/string16.h" #include "base/strings/string16.h"
#include "base/strings/utf_string_conversions.h" #include "base/strings/utf_string_conversions.h"
#include "chrome/browser/notifications/notification_display_service.h" #include "chrome/browser/notifications/notification_display_service.h"
#include "chrome/browser/notifications/notification_display_service_factory.h"
#include "chrome/grit/generated_resources.h" #include "chrome/grit/generated_resources.h"
#include "components/sync/protocol/sharing_message.pb.h" #include "components/sync/protocol/sharing_message.pb.h"
#include "components/sync/protocol/sharing_remote_copy_message.pb.h" #include "components/sync/protocol/sharing_remote_copy_message.pb.h"
...@@ -22,9 +23,8 @@ ...@@ -22,9 +23,8 @@
#include "ui/message_center/public/cpp/notifier_id.h" #include "ui/message_center/public/cpp/notifier_id.h"
#include "url/gurl.h" #include "url/gurl.h"
RemoteCopyMessageHandler::RemoteCopyMessageHandler( RemoteCopyMessageHandler::RemoteCopyMessageHandler(Profile* profile)
NotificationDisplayService* notification_display_service) : profile_(profile) {}
: notification_display_service_(notification_display_service) {}
RemoteCopyMessageHandler::~RemoteCopyMessageHandler() = default; RemoteCopyMessageHandler::~RemoteCopyMessageHandler() = default;
...@@ -43,8 +43,6 @@ void RemoteCopyMessageHandler::OnMessage( ...@@ -43,8 +43,6 @@ void RemoteCopyMessageHandler::OnMessage(
void RemoteCopyMessageHandler::ShowNotification( void RemoteCopyMessageHandler::ShowNotification(
const std::string& device_name) { const std::string& device_name) {
DCHECK(notification_display_service_);
std::string notification_id = base::GenerateGUID(); std::string notification_id = base::GenerateGUID();
// TODO(mvanouwerkerk): Adjust notification text and icon once we have mocks. // TODO(mvanouwerkerk): Adjust notification text and icon once we have mocks.
...@@ -67,6 +65,6 @@ void RemoteCopyMessageHandler::ShowNotification( ...@@ -67,6 +65,6 @@ void RemoteCopyMessageHandler::ShowNotification(
message_center::RichNotificationData(), message_center::RichNotificationData(),
/*delegate=*/nullptr); /*delegate=*/nullptr);
notification_display_service_->Display(NotificationHandler::Type::SHARING, NotificationDisplayServiceFactory::GetForProfile(profile_)->Display(
notification, /*metadata=*/nullptr); NotificationHandler::Type::SHARING, notification, /*metadata=*/nullptr);
} }
...@@ -10,13 +10,12 @@ ...@@ -10,13 +10,12 @@
#include "base/macros.h" #include "base/macros.h"
#include "chrome/browser/sharing/sharing_message_handler.h" #include "chrome/browser/sharing/sharing_message_handler.h"
class NotificationDisplayService; class Profile;
// Handles incoming messages for the remote copy feature. // Handles incoming messages for the remote copy feature.
class RemoteCopyMessageHandler : public SharingMessageHandler { class RemoteCopyMessageHandler : public SharingMessageHandler {
public: public:
explicit RemoteCopyMessageHandler( explicit RemoteCopyMessageHandler(Profile* profile);
NotificationDisplayService* notification_display_service);
~RemoteCopyMessageHandler() override; ~RemoteCopyMessageHandler() override;
// SharingMessageHandler implementation: // SharingMessageHandler implementation:
...@@ -26,7 +25,7 @@ class RemoteCopyMessageHandler : public SharingMessageHandler { ...@@ -26,7 +25,7 @@ class RemoteCopyMessageHandler : public SharingMessageHandler {
private: private:
void ShowNotification(const std::string& device_name); void ShowNotification(const std::string& device_name);
NotificationDisplayService* notification_display_service_ = nullptr; Profile* profile_ = nullptr;
DISALLOW_COPY_AND_ASSIGN(RemoteCopyMessageHandler); DISALLOW_COPY_AND_ASSIGN(RemoteCopyMessageHandler);
}; };
......
...@@ -7,13 +7,14 @@ ...@@ -7,13 +7,14 @@
#include "base/bind_helpers.h" #include "base/bind_helpers.h"
#include "base/guid.h" #include "base/guid.h"
#include "base/strings/utf_string_conversions.h" #include "base/strings/utf_string_conversions.h"
#include "chrome/browser/notifications/stub_notification_display_service.h"
#include "chrome/browser/sharing/shared_clipboard/shared_clipboard_test_base.h" #include "chrome/browser/sharing/shared_clipboard/shared_clipboard_test_base.h"
#include "chrome/grit/generated_resources.h" #include "chrome/grit/generated_resources.h"
#include "chrome/test/base/testing_profile.h"
#include "components/sync/protocol/sharing_message.pb.h" #include "components/sync/protocol/sharing_message.pb.h"
#include "components/sync/protocol/sharing_remote_copy_message.pb.h" #include "components/sync/protocol/sharing_remote_copy_message.pb.h"
#include "components/sync/protocol/sync_enums.pb.h" #include "components/sync/protocol/sync_enums.pb.h"
#include "ui/base/l10n/l10n_util.h" #include "ui/base/l10n/l10n_util.h"
#include "ui/message_center/public/cpp/notification.h"
namespace { namespace {
...@@ -29,8 +30,7 @@ class RemoteCopyMessageHandlerTest : public SharedClipboardTestBase { ...@@ -29,8 +30,7 @@ class RemoteCopyMessageHandlerTest : public SharedClipboardTestBase {
void SetUp() override { void SetUp() override {
SharedClipboardTestBase::SetUp(); SharedClipboardTestBase::SetUp();
message_handler_ = std::make_unique<RemoteCopyMessageHandler>( message_handler_ = std::make_unique<RemoteCopyMessageHandler>(&profile_);
notification_display_service_.get());
} }
chrome_browser_sharing::SharingMessage CreateMessage(std::string guid, chrome_browser_sharing::SharingMessage CreateMessage(std::string guid,
......
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
#include "base/strings/string16.h" #include "base/strings/string16.h"
#include "base/strings/utf_string_conversions.h" #include "base/strings/utf_string_conversions.h"
#include "chrome/browser/notifications/notification_display_service.h" #include "chrome/browser/notifications/notification_display_service.h"
#include "chrome/browser/notifications/notification_display_service_factory.h"
#include "chrome/grit/generated_resources.h" #include "chrome/grit/generated_resources.h"
#include "ui/base/l10n/l10n_util.h" #include "ui/base/l10n/l10n_util.h"
#include "ui/gfx/image/image.h" #include "ui/gfx/image/image.h"
...@@ -17,17 +18,14 @@ ...@@ -17,17 +18,14 @@
SharedClipboardMessageHandlerDesktop::SharedClipboardMessageHandlerDesktop( SharedClipboardMessageHandlerDesktop::SharedClipboardMessageHandlerDesktop(
SharingService* sharing_service, SharingService* sharing_service,
NotificationDisplayService* notification_display_service) Profile* profile)
: SharedClipboardMessageHandler(sharing_service), : SharedClipboardMessageHandler(sharing_service), profile_(profile) {}
notification_display_service_(notification_display_service) {}
SharedClipboardMessageHandlerDesktop::~SharedClipboardMessageHandlerDesktop() = SharedClipboardMessageHandlerDesktop::~SharedClipboardMessageHandlerDesktop() =
default; default;
void SharedClipboardMessageHandlerDesktop::ShowNotification( void SharedClipboardMessageHandlerDesktop::ShowNotification(
const std::string& device_name) { const std::string& device_name) {
DCHECK(notification_display_service_);
std::string notification_id = base::GenerateGUID(); std::string notification_id = base::GenerateGUID();
base::string16 notification_title = base::string16 notification_title =
...@@ -49,6 +47,7 @@ void SharedClipboardMessageHandlerDesktop::ShowNotification( ...@@ -49,6 +47,7 @@ void SharedClipboardMessageHandlerDesktop::ShowNotification(
message_center::RichNotificationData(), message_center::RichNotificationData(),
/* delegate= */ nullptr); /* delegate= */ nullptr);
notification_display_service_->Display(NotificationHandler::Type::SHARING, NotificationDisplayServiceFactory::GetForProfile(profile_)->Display(
notification, /* metadata= */ nullptr); NotificationHandler::Type::SHARING, notification,
/* metadata= */ nullptr);
} }
...@@ -8,23 +8,22 @@ ...@@ -8,23 +8,22 @@
#include "base/macros.h" #include "base/macros.h"
#include "chrome/browser/sharing/shared_clipboard/shared_clipboard_message_handler.h" #include "chrome/browser/sharing/shared_clipboard/shared_clipboard_message_handler.h"
class NotificationDisplayService; class Profile;
class SharingService; class SharingService;
// Handles incoming messages for the shared clipboard feature. // Handles incoming messages for the shared clipboard feature.
class SharedClipboardMessageHandlerDesktop class SharedClipboardMessageHandlerDesktop
: public SharedClipboardMessageHandler { : public SharedClipboardMessageHandler {
public: public:
SharedClipboardMessageHandlerDesktop( SharedClipboardMessageHandlerDesktop(SharingService* sharing_service,
SharingService* sharing_service, Profile* profile);
NotificationDisplayService* notification_display_service);
~SharedClipboardMessageHandlerDesktop() override; ~SharedClipboardMessageHandlerDesktop() override;
private: private:
// SharedClipboardMessageHandler implementation. // SharedClipboardMessageHandler implementation.
void ShowNotification(const std::string& device_name) override; void ShowNotification(const std::string& device_name) override;
NotificationDisplayService* notification_display_service_ = nullptr; Profile* profile_ = nullptr;
DISALLOW_COPY_AND_ASSIGN(SharedClipboardMessageHandlerDesktop); DISALLOW_COPY_AND_ASSIGN(SharedClipboardMessageHandlerDesktop);
}; };
......
...@@ -7,15 +7,16 @@ ...@@ -7,15 +7,16 @@
#include "base/guid.h" #include "base/guid.h"
#include "base/strings/utf_string_conversions.h" #include "base/strings/utf_string_conversions.h"
#include "base/test/mock_callback.h" #include "base/test/mock_callback.h"
#include "chrome/browser/notifications/stub_notification_display_service.h"
#include "chrome/browser/sharing/mock_sharing_service.h" #include "chrome/browser/sharing/mock_sharing_service.h"
#include "chrome/browser/sharing/shared_clipboard/shared_clipboard_test_base.h" #include "chrome/browser/sharing/shared_clipboard/shared_clipboard_test_base.h"
#include "chrome/grit/generated_resources.h" #include "chrome/grit/generated_resources.h"
#include "chrome/test/base/testing_profile.h"
#include "components/sync/protocol/sharing_shared_clipboard_message.pb.h" #include "components/sync/protocol/sharing_shared_clipboard_message.pb.h"
#include "components/sync/protocol/sync_enums.pb.h" #include "components/sync/protocol/sync_enums.pb.h"
#include "components/sync_device_info/device_info.h" #include "components/sync_device_info/device_info.h"
#include "testing/gmock/include/gmock/gmock.h" #include "testing/gmock/include/gmock/gmock.h"
#include "ui/base/l10n/l10n_util.h" #include "ui/base/l10n/l10n_util.h"
#include "ui/message_center/public/cpp/notification.h"
namespace { namespace {
...@@ -33,7 +34,7 @@ class SharedClipboardMessageHandlerTest : public SharedClipboardTestBase { ...@@ -33,7 +34,7 @@ class SharedClipboardMessageHandlerTest : public SharedClipboardTestBase {
void SetUp() override { void SetUp() override {
SharedClipboardTestBase::SetUp(); SharedClipboardTestBase::SetUp();
message_handler_ = std::make_unique<SharedClipboardMessageHandlerDesktop>( message_handler_ = std::make_unique<SharedClipboardMessageHandlerDesktop>(
sharing_service_.get(), notification_display_service_.get()); sharing_service_.get(), &profile_);
} }
chrome_browser_sharing::SharingMessage CreateMessage(std::string guid, chrome_browser_sharing::SharingMessage CreateMessage(std::string guid,
......
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
#include "chrome/browser/sharing/shared_clipboard/shared_clipboard_test_base.h" #include "chrome/browser/sharing/shared_clipboard/shared_clipboard_test_base.h"
#include "base/strings/utf_string_conversions.h" #include "base/strings/utf_string_conversions.h"
#include "chrome/browser/notifications/stub_notification_display_service.h" #include "chrome/browser/notifications/notification_display_service_tester.h"
#include "chrome/browser/sharing/mock_sharing_service.h" #include "chrome/browser/sharing/mock_sharing_service.h"
#include "components/sync/protocol/sharing_message.pb.h" #include "components/sync/protocol/sharing_message.pb.h"
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
...@@ -18,8 +18,8 @@ SharedClipboardTestBase::SharedClipboardTestBase() = default; ...@@ -18,8 +18,8 @@ SharedClipboardTestBase::SharedClipboardTestBase() = default;
SharedClipboardTestBase::~SharedClipboardTestBase() = default; SharedClipboardTestBase::~SharedClipboardTestBase() = default;
void SharedClipboardTestBase::SetUp() { void SharedClipboardTestBase::SetUp() {
notification_display_service_ = notification_tester_ =
std::make_unique<StubNotificationDisplayService>(&profile_); std::make_unique<NotificationDisplayServiceTester>(&profile_);
sharing_service_ = std::make_unique<MockSharingService>(); sharing_service_ = std::make_unique<MockSharingService>();
ui::TestClipboard::CreateForCurrentThread(); ui::TestClipboard::CreateForCurrentThread();
} }
...@@ -45,9 +45,8 @@ std::string SharedClipboardTestBase::GetClipboardText() { ...@@ -45,9 +45,8 @@ std::string SharedClipboardTestBase::GetClipboardText() {
} }
message_center::Notification SharedClipboardTestBase::GetNotification() { message_center::Notification SharedClipboardTestBase::GetNotification() {
auto notifications = auto notifications = notification_tester_->GetDisplayedNotificationsForType(
notification_display_service_->GetDisplayedNotificationsForType( NotificationHandler::Type::SHARING);
NotificationHandler::Type::SHARING);
EXPECT_EQ(notifications.size(), 1u); EXPECT_EQ(notifications.size(), 1u);
const message_center::Notification& notification = notifications[0]; const message_center::Notification& notification = notifications[0];
......
...@@ -14,7 +14,7 @@ ...@@ -14,7 +14,7 @@
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
class MockSharingService; class MockSharingService;
class StubNotificationDisplayService; class NotificationDisplayServiceTester;
namespace chrome_browser_sharing { namespace chrome_browser_sharing {
class SharingMessage; class SharingMessage;
...@@ -42,9 +42,9 @@ class SharedClipboardTestBase : public testing::Test { ...@@ -42,9 +42,9 @@ class SharedClipboardTestBase : public testing::Test {
protected: protected:
content::BrowserTaskEnvironment task_environment_; content::BrowserTaskEnvironment task_environment_;
std::unique_ptr<StubNotificationDisplayService> notification_display_service_;
std::unique_ptr<MockSharingService> sharing_service_;
TestingProfile profile_; TestingProfile profile_;
std::unique_ptr<NotificationDisplayServiceTester> notification_tester_;
std::unique_ptr<MockSharingService> sharing_service_;
private: private:
DISALLOW_COPY_AND_ASSIGN(SharedClipboardTestBase); DISALLOW_COPY_AND_ASSIGN(SharedClipboardTestBase);
......
...@@ -69,6 +69,7 @@ class SharedClipboardUtilsTest : public testing::Test { ...@@ -69,6 +69,7 @@ class SharedClipboardUtilsTest : public testing::Test {
return nullptr; return nullptr;
return std::make_unique<SharingService>( return std::make_unique<SharingService>(
&profile_,
/* sync_prefs= */ nullptr, /* sync_prefs= */ nullptr,
/* vapid_key_manager= */ nullptr, /* vapid_key_manager= */ nullptr,
std::make_unique<MockSharingDeviceRegistration>(), std::make_unique<MockSharingDeviceRegistration>(),
...@@ -80,8 +81,7 @@ class SharedClipboardUtilsTest : public testing::Test { ...@@ -80,8 +81,7 @@ class SharedClipboardUtilsTest : public testing::Test {
/* gcm_driver= */ nullptr, /* gcm_driver= */ nullptr,
/* device_info_tracker= */ nullptr, /* device_info_tracker= */ nullptr,
/* local_device_info_provider= */ nullptr, /* local_device_info_provider= */ nullptr,
/* sync_service */ nullptr, /* sync_service */ nullptr);
/* notification_display_service= */ nullptr);
} }
base::test::ScopedFeatureList scoped_feature_list_; base::test::ScopedFeatureList scoped_feature_list_;
......
...@@ -50,6 +50,7 @@ ...@@ -50,6 +50,7 @@
#endif #endif
SharingService::SharingService( SharingService::SharingService(
Profile* profile,
std::unique_ptr<SharingSyncPreference> sync_prefs, std::unique_ptr<SharingSyncPreference> sync_prefs,
std::unique_ptr<VapidKeyManager> vapid_key_manager, std::unique_ptr<VapidKeyManager> vapid_key_manager,
std::unique_ptr<SharingDeviceRegistration> sharing_device_registration, std::unique_ptr<SharingDeviceRegistration> sharing_device_registration,
...@@ -59,8 +60,7 @@ SharingService::SharingService( ...@@ -59,8 +60,7 @@ SharingService::SharingService(
gcm::GCMDriver* gcm_driver, gcm::GCMDriver* gcm_driver,
syncer::DeviceInfoTracker* device_info_tracker, syncer::DeviceInfoTracker* device_info_tracker,
syncer::LocalDeviceInfoProvider* local_device_info_provider, syncer::LocalDeviceInfoProvider* local_device_info_provider,
syncer::SyncService* sync_service, syncer::SyncService* sync_service)
NotificationDisplayService* notification_display_service)
: sync_prefs_(std::move(sync_prefs)), : sync_prefs_(std::move(sync_prefs)),
vapid_key_manager_(std::move(vapid_key_manager)), vapid_key_manager_(std::move(vapid_key_manager)),
sharing_device_registration_(std::move(sharing_device_registration)), sharing_device_registration_(std::move(sharing_device_registration)),
...@@ -118,8 +118,7 @@ SharingService::SharingService( ...@@ -118,8 +118,7 @@ SharingService::SharingService(
std::make_unique<SharedClipboardMessageHandlerAndroid>(this); std::make_unique<SharedClipboardMessageHandlerAndroid>(this);
#else #else
shared_clipboard_message_handler_ = shared_clipboard_message_handler_ =
std::make_unique<SharedClipboardMessageHandlerDesktop>( std::make_unique<SharedClipboardMessageHandlerDesktop>(this, profile);
this, notification_display_service);
#endif // defined(OS_ANDROID) #endif // defined(OS_ANDROID)
fcm_handler_->AddSharingHandler( fcm_handler_->AddSharingHandler(
chrome_browser_sharing::SharingMessage::kSharedClipboardMessage, chrome_browser_sharing::SharingMessage::kSharedClipboardMessage,
...@@ -129,8 +128,8 @@ SharingService::SharingService( ...@@ -129,8 +128,8 @@ SharingService::SharingService(
#if defined(OS_WIN) || defined(OS_MACOSX) || defined(OS_LINUX) || \ #if defined(OS_WIN) || defined(OS_MACOSX) || defined(OS_LINUX) || \
defined(OS_CHROMEOS) defined(OS_CHROMEOS)
if (sharing_device_registration_->IsRemoteCopySupported()) { if (sharing_device_registration_->IsRemoteCopySupported()) {
remote_copy_message_handler_ = std::make_unique<RemoteCopyMessageHandler>( remote_copy_message_handler_ =
notification_display_service); std::make_unique<RemoteCopyMessageHandler>(profile);
fcm_handler_->AddSharingHandler( fcm_handler_->AddSharingHandler(
chrome_browser_sharing::SharingMessage::kRemoteCopyMessage, chrome_browser_sharing::SharingMessage::kRemoteCopyMessage,
remote_copy_message_handler_.get()); remote_copy_message_handler_.get());
...@@ -244,6 +243,10 @@ SharingSyncPreference* SharingService::GetSyncPreferencesForTesting() const { ...@@ -244,6 +243,10 @@ SharingSyncPreference* SharingService::GetSyncPreferencesForTesting() const {
return sync_prefs_.get(); return sync_prefs_.get();
} }
SharingFCMHandler* SharingService::GetFCMHandlerForTesting() const {
return fcm_handler_.get();
}
void SharingService::OnDeviceInfoChange() { void SharingService::OnDeviceInfoChange() {
if (!device_info_tracker_->IsSyncing() || if (!device_info_tracker_->IsSyncing() ||
!local_device_info_provider_->GetLocalDeviceInfo()) { !local_device_info_provider_->GetLocalDeviceInfo()) {
......
...@@ -43,7 +43,7 @@ class DeviceInfo; ...@@ -43,7 +43,7 @@ class DeviceInfo;
class SyncService; class SyncService;
} // namespace syncer } // namespace syncer
class NotificationDisplayService; class Profile;
class RemoteCopyMessageHandler; class RemoteCopyMessageHandler;
class SharedClipboardMessageHandler; class SharedClipboardMessageHandler;
class SharingFCMHandler; class SharingFCMHandler;
...@@ -73,6 +73,7 @@ class SharingService : public KeyedService, ...@@ -73,6 +73,7 @@ class SharingService : public KeyedService,
}; };
SharingService( SharingService(
Profile* profile,
std::unique_ptr<SharingSyncPreference> sync_prefs, std::unique_ptr<SharingSyncPreference> sync_prefs,
std::unique_ptr<VapidKeyManager> vapid_key_manager, std::unique_ptr<VapidKeyManager> vapid_key_manager,
std::unique_ptr<SharingDeviceRegistration> sharing_device_registration, std::unique_ptr<SharingDeviceRegistration> sharing_device_registration,
...@@ -82,8 +83,7 @@ class SharingService : public KeyedService, ...@@ -82,8 +83,7 @@ class SharingService : public KeyedService,
gcm::GCMDriver* gcm_driver, gcm::GCMDriver* gcm_driver,
syncer::DeviceInfoTracker* device_info_tracker, syncer::DeviceInfoTracker* device_info_tracker,
syncer::LocalDeviceInfoProvider* local_device_info_provider, syncer::LocalDeviceInfoProvider* local_device_info_provider,
syncer::SyncService* sync_service, syncer::SyncService* sync_service);
NotificationDisplayService* notification_display_service);
~SharingService() override; ~SharingService() override;
// Returns the device matching |guid|, or nullptr if no match was found. // Returns the device matching |guid|, or nullptr if no match was found.
...@@ -126,6 +126,9 @@ class SharingService : public KeyedService, ...@@ -126,6 +126,9 @@ class SharingService : public KeyedService,
// Returns SharingSyncPreference for integration tests. // Returns SharingSyncPreference for integration tests.
SharingSyncPreference* GetSyncPreferencesForTesting() const; SharingSyncPreference* GetSyncPreferencesForTesting() const;
// Returns SharingFCMHandler for testing.
SharingFCMHandler* GetFCMHandlerForTesting() const;
private: private:
// Overrides for syncer::SyncServiceObserver. // Overrides for syncer::SyncServiceObserver.
void OnSyncShutdown(syncer::SyncService* sync) override; void OnSyncShutdown(syncer::SyncService* sync) override;
......
...@@ -9,7 +9,6 @@ ...@@ -9,7 +9,6 @@
#include "base/memory/singleton.h" #include "base/memory/singleton.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/notifications/notification_display_service_factory.h"
#include "chrome/browser/profiles/profile.h" #include "chrome/browser/profiles/profile.h"
#include "chrome/browser/sharing/sharing_device_registration.h" #include "chrome/browser/sharing/sharing_device_registration.h"
#include "chrome/browser/sharing/sharing_fcm_handler.h" #include "chrome/browser/sharing/sharing_fcm_handler.h"
...@@ -53,7 +52,6 @@ SharingServiceFactory::SharingServiceFactory() ...@@ -53,7 +52,6 @@ SharingServiceFactory::SharingServiceFactory()
DependsOn(instance_id::InstanceIDProfileServiceFactory::GetInstance()); DependsOn(instance_id::InstanceIDProfileServiceFactory::GetInstance());
DependsOn(DeviceInfoSyncServiceFactory::GetInstance()); DependsOn(DeviceInfoSyncServiceFactory::GetInstance());
DependsOn(ProfileSyncServiceFactory::GetInstance()); DependsOn(ProfileSyncServiceFactory::GetInstance());
DependsOn(NotificationDisplayServiceFactory::GetInstance());
} }
SharingServiceFactory::~SharingServiceFactory() = default; SharingServiceFactory::~SharingServiceFactory() = default;
...@@ -81,9 +79,6 @@ KeyedService* SharingServiceFactory::BuildServiceInstanceFor( ...@@ -81,9 +79,6 @@ KeyedService* SharingServiceFactory::BuildServiceInstanceFor(
syncer::LocalDeviceInfoProvider* local_device_info_provider = syncer::LocalDeviceInfoProvider* local_device_info_provider =
device_info_sync_service->GetLocalDeviceInfoProvider(); device_info_sync_service->GetLocalDeviceInfoProvider();
NotificationDisplayService* notification_display_service =
NotificationDisplayServiceFactory::GetForProfile(profile);
std::unique_ptr<SharingSyncPreference> sync_prefs = std::unique_ptr<SharingSyncPreference> sync_prefs =
std::make_unique<SharingSyncPreference>(profile->GetPrefs(), std::make_unique<SharingSyncPreference>(profile->GetPrefs(),
device_info_sync_service); device_info_sync_service);
...@@ -103,12 +98,11 @@ KeyedService* SharingServiceFactory::BuildServiceInstanceFor( ...@@ -103,12 +98,11 @@ KeyedService* SharingServiceFactory::BuildServiceInstanceFor(
std::make_unique<SharingMessageSender>(fcm_sender.get(), sync_prefs.get(), std::make_unique<SharingMessageSender>(fcm_sender.get(), sync_prefs.get(),
local_device_info_provider); local_device_info_provider);
return new SharingService(std::move(sync_prefs), std::move(vapid_key_manager), return new SharingService(
std::move(sharing_device_registration), profile, std::move(sync_prefs), std::move(vapid_key_manager),
std::move(fcm_sender), std::move(fcm_handler), std::move(sharing_device_registration), std::move(fcm_sender),
std::move(sharing_message_sender), gcm_driver, std::move(fcm_handler), std::move(sharing_message_sender), gcm_driver,
device_info_tracker, local_device_info_provider, device_info_tracker, local_device_info_provider, sync_service);
sync_service, notification_display_service);
} }
content::BrowserContext* SharingServiceFactory::GetBrowserContextToUse( content::BrowserContext* SharingServiceFactory::GetBrowserContextToUse(
......
...@@ -20,6 +20,7 @@ ...@@ -20,6 +20,7 @@
#include "chrome/browser/sharing/sharing_fcm_sender.h" #include "chrome/browser/sharing/sharing_fcm_sender.h"
#include "chrome/browser/sharing/sharing_sync_preference.h" #include "chrome/browser/sharing/sharing_sync_preference.h"
#include "chrome/browser/sharing/vapid_key_manager.h" #include "chrome/browser/sharing/vapid_key_manager.h"
#include "chrome/test/base/testing_profile.h"
#include "components/gcm_driver/crypto/gcm_encryption_provider.h" #include "components/gcm_driver/crypto/gcm_encryption_provider.h"
#include "components/gcm_driver/instance_id/instance_id_driver.h" #include "components/gcm_driver/instance_id/instance_id_driver.h"
#include "components/sync/driver/test_sync_service.h" #include "components/sync/driver/test_sync_service.h"
...@@ -215,14 +216,14 @@ class SharingServiceTest : public testing::Test { ...@@ -215,14 +216,14 @@ class SharingServiceTest : public testing::Test {
SharingService* GetSharingService() { SharingService* GetSharingService() {
if (!sharing_service_) { if (!sharing_service_) {
sharing_service_ = std::make_unique<SharingService>( sharing_service_ = std::make_unique<SharingService>(
base::WrapUnique(sync_prefs_), base::WrapUnique(vapid_key_manager_), &profile_, base::WrapUnique(sync_prefs_),
base::WrapUnique(vapid_key_manager_),
base::WrapUnique(sharing_device_registration_), nullptr, base::WrapUnique(sharing_device_registration_), nullptr,
base::WrapUnique(fcm_handler_), base::WrapUnique(fcm_handler_),
base::WrapUnique(sharing_message_sender_), nullptr, base::WrapUnique(sharing_message_sender_), nullptr,
fake_device_info_sync_service.GetDeviceInfoTracker(), fake_device_info_sync_service.GetDeviceInfoTracker(),
fake_device_info_sync_service.GetLocalDeviceInfoProvider(), fake_device_info_sync_service.GetLocalDeviceInfoProvider(),
&test_sync_service_, &test_sync_service_);
/* notification_display_service= */ nullptr);
} }
task_environment_.RunUntilIdle(); task_environment_.RunUntilIdle();
return sharing_service_.get(); return sharing_service_.get();
...@@ -231,6 +232,7 @@ class SharingServiceTest : public testing::Test { ...@@ -231,6 +232,7 @@ class SharingServiceTest : public testing::Test {
base::test::ScopedFeatureList scoped_feature_list_; base::test::ScopedFeatureList scoped_feature_list_;
content::BrowserTaskEnvironment task_environment_{ content::BrowserTaskEnvironment task_environment_{
base::test::TaskEnvironment::TimeSource::MOCK_TIME}; base::test::TaskEnvironment::TimeSource::MOCK_TIME};
TestingProfile profile_;
syncer::FakeDeviceInfoSyncService fake_device_info_sync_service; syncer::FakeDeviceInfoSyncService fake_device_info_sync_service;
syncer::TestSyncService test_sync_service_; syncer::TestSyncService test_sync_service_;
......
...@@ -1120,6 +1120,7 @@ if (!is_android) { ...@@ -1120,6 +1120,7 @@ if (!is_android) {
"../browser/sessions/tab_restore_service_load_waiter.cc", "../browser/sessions/tab_restore_service_load_waiter.cc",
"../browser/sessions/tab_restore_service_load_waiter.h", "../browser/sessions/tab_restore_service_load_waiter.h",
"../browser/sharing/click_to_call/click_to_call_browsertest.cc", "../browser/sharing/click_to_call/click_to_call_browsertest.cc",
"../browser/sharing/shared_clipboard/remote_copy_browsertest.cc",
"../browser/sharing/shared_clipboard/shared_clipboard_browsertest.cc", "../browser/sharing/shared_clipboard/shared_clipboard_browsertest.cc",
"../browser/sharing/sharing_browsertest.cc", "../browser/sharing/sharing_browsertest.cc",
"../browser/sharing/sharing_browsertest.h", "../browser/sharing/sharing_browsertest.h",
......
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