Commit 89ea6939 authored by Yasmin's avatar Yasmin Committed by Commit Bot

Check enterprise policy on the receiver side for Sharing Service.

Bug: 1005288
Change-Id: I336f17fa43b7d0db0b4d16657fd3d14a925deedf
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1837771Reviewed-by: default avatarMichael van Ouwerkerk <mvanouwerkerk@chromium.org>
Commit-Queue: Yasmin Molazadeh <yasmo@chromium.org>
Cr-Commit-Position: refs/heads/master@{#702855}
parent 47b95e96
...@@ -47,12 +47,28 @@ const char kPhoneNumber[] = "+9876543210"; ...@@ -47,12 +47,28 @@ const char kPhoneNumber[] = "+9876543210";
constexpr int kSeparatorCommandId = -1; constexpr int kSeparatorCommandId = -1;
class MockSharingDeviceRegistration : public SharingDeviceRegistration {
public:
explicit MockSharingDeviceRegistration()
: SharingDeviceRegistration(/* pref_service_= */ nullptr,
/* sharing_sync_preference_= */ nullptr,
/* instance_id_driver_= */ nullptr,
/* vapid_key_manager_= */ nullptr) {}
~MockSharingDeviceRegistration() override = default;
MOCK_CONST_METHOD0(IsSharedClipboardSupported, bool());
private:
DISALLOW_COPY_AND_ASSIGN(MockSharingDeviceRegistration);
};
class MockSharingService : public SharingService { class MockSharingService : public SharingService {
public: public:
explicit MockSharingService(std::unique_ptr<SharingFCMHandler> fcm_handler) explicit MockSharingService(std::unique_ptr<SharingFCMHandler> fcm_handler)
: SharingService(/* sync_prefs= */ nullptr, : SharingService(/* sync_prefs= */ nullptr,
/* vapid_key_manager= */ nullptr, /* vapid_key_manager= */ nullptr,
/* sharing_device_registration= */ nullptr, std::make_unique<MockSharingDeviceRegistration>(),
/* fcm_sender= */ nullptr, /* fcm_sender= */ nullptr,
std::move(fcm_handler), std::move(fcm_handler),
/* gcm_driver= */ nullptr, /* gcm_driver= */ nullptr,
......
...@@ -40,12 +40,28 @@ const char kExpectedPhoneNumber[] = "073 87 2525 78"; ...@@ -40,12 +40,28 @@ const char kExpectedPhoneNumber[] = "073 87 2525 78";
const char kReceiverGuid[] = "test_receiver_guid"; const char kReceiverGuid[] = "test_receiver_guid";
const char kReceiverName[] = "test_receiver_name"; const char kReceiverName[] = "test_receiver_name";
class MockSharingDeviceRegistration : public SharingDeviceRegistration {
public:
explicit MockSharingDeviceRegistration()
: SharingDeviceRegistration(/* pref_service_= */ nullptr,
/* sharing_sync_preference_= */ nullptr,
/* instance_id_driver_= */ nullptr,
/* vapid_key_manager_= */ nullptr) {}
~MockSharingDeviceRegistration() override = default;
MOCK_CONST_METHOD0(IsSharedClipboardSupported, bool());
private:
DISALLOW_COPY_AND_ASSIGN(MockSharingDeviceRegistration);
};
class MockSharingService : public SharingService { class MockSharingService : public SharingService {
public: public:
explicit MockSharingService(std::unique_ptr<SharingFCMHandler> fcm_handler) explicit MockSharingService(std::unique_ptr<SharingFCMHandler> fcm_handler)
: SharingService(/* sync_prefs= */ nullptr, : SharingService(/* sync_prefs= */ nullptr,
/* vapid_key_manager= */ nullptr, /* vapid_key_manager= */ nullptr,
/* sharing_device_registration= */ nullptr, std::make_unique<MockSharingDeviceRegistration>(),
/* fcm_sender= */ nullptr, /* fcm_sender= */ nullptr,
std::move(fcm_handler), std::move(fcm_handler),
/* gcm_driver= */ nullptr, /* gcm_driver= */ nullptr,
......
...@@ -38,12 +38,28 @@ const char kNonTelUrl[] = "https://google.com"; ...@@ -38,12 +38,28 @@ const char kNonTelUrl[] = "https://google.com";
const char kSelectionTextWithNumber[] = "9876543210"; const char kSelectionTextWithNumber[] = "9876543210";
class MockSharingDeviceRegistration : public SharingDeviceRegistration {
public:
explicit MockSharingDeviceRegistration()
: SharingDeviceRegistration(/* pref_service_= */ nullptr,
/* sharing_sync_preference_= */ nullptr,
/* instance_id_driver_= */ nullptr,
/* vapid_key_manager_= */ nullptr) {}
~MockSharingDeviceRegistration() override = default;
MOCK_CONST_METHOD0(IsSharedClipboardSupported, bool());
private:
DISALLOW_COPY_AND_ASSIGN(MockSharingDeviceRegistration);
};
class MockSharingService : public SharingService { class MockSharingService : public SharingService {
public: public:
explicit MockSharingService(std::unique_ptr<SharingFCMHandler> fcm_handler) explicit MockSharingService(std::unique_ptr<SharingFCMHandler> fcm_handler)
: SharingService(/* sync_prefs= */ nullptr, : SharingService(/* sync_prefs= */ nullptr,
/* vapid_key_manager= */ nullptr, /* vapid_key_manager= */ nullptr,
/* sharing_device_registration= */ nullptr, std::make_unique<MockSharingDeviceRegistration>(),
/* fcm_sender= */ nullptr, /* fcm_sender= */ nullptr,
std::move(fcm_handler), std::move(fcm_handler),
/* gcm_driver= */ nullptr, /* gcm_driver= */ nullptr,
......
...@@ -43,12 +43,28 @@ const char kText[] = "Some random text to be copied."; ...@@ -43,12 +43,28 @@ const char kText[] = "Some random text to be copied.";
constexpr int kSeparatorCommandId = -1; constexpr int kSeparatorCommandId = -1;
class MockSharingDeviceRegistration : public SharingDeviceRegistration {
public:
explicit MockSharingDeviceRegistration()
: SharingDeviceRegistration(/* pref_service_= */ nullptr,
/* sharing_sync_preference_= */ nullptr,
/* instance_id_driver_= */ nullptr,
/* vapid_key_manager_= */ nullptr) {}
~MockSharingDeviceRegistration() override = default;
MOCK_CONST_METHOD0(IsSharedClipboardSupported, bool());
private:
DISALLOW_COPY_AND_ASSIGN(MockSharingDeviceRegistration);
};
class MockSharingService : public SharingService { class MockSharingService : public SharingService {
public: public:
explicit MockSharingService(std::unique_ptr<SharingFCMHandler> fcm_handler) explicit MockSharingService(std::unique_ptr<SharingFCMHandler> fcm_handler)
: SharingService(/* sync_prefs= */ nullptr, : SharingService(/* sync_prefs= */ nullptr,
/* vapid_key_manager= */ nullptr, /* vapid_key_manager= */ nullptr,
/* sharing_device_registration= */ nullptr, std::make_unique<MockSharingDeviceRegistration>(),
/* fcm_sender= */ nullptr, /* fcm_sender= */ nullptr,
std::move(fcm_handler), std::move(fcm_handler),
/* gcm_driver= */ nullptr, /* gcm_driver= */ nullptr,
......
...@@ -32,6 +32,22 @@ const char kEmptyDeviceName[] = ""; ...@@ -32,6 +32,22 @@ const char kEmptyDeviceName[] = "";
const char kDeviceNameInDeviceInfo[] = "DeviceNameInDeviceInfo"; const char kDeviceNameInDeviceInfo[] = "DeviceNameInDeviceInfo";
const char kDeviceNameInMessage[] = "DeviceNameInMessage"; const char kDeviceNameInMessage[] = "DeviceNameInMessage";
class MockSharingDeviceRegistration : public SharingDeviceRegistration {
public:
explicit MockSharingDeviceRegistration()
: SharingDeviceRegistration(/* pref_service_= */ nullptr,
/* sharing_sync_preference_= */ nullptr,
/* instance_id_driver_= */ nullptr,
/* vapid_key_manager_= */ nullptr) {}
~MockSharingDeviceRegistration() override = default;
MOCK_CONST_METHOD0(IsSharedClipboardSupported, bool());
private:
DISALLOW_COPY_AND_ASSIGN(MockSharingDeviceRegistration);
};
class MockSharingService : public SharingService { class MockSharingService : public SharingService {
public: public:
explicit MockSharingService( explicit MockSharingService(
...@@ -39,7 +55,7 @@ class MockSharingService : public SharingService { ...@@ -39,7 +55,7 @@ class MockSharingService : public SharingService {
: SharingService( : SharingService(
/* sync_prefs= */ nullptr, /* sync_prefs= */ nullptr,
/* vapid_key_manager= */ nullptr, /* vapid_key_manager= */ nullptr,
/* sharing_device_registration= */ nullptr, std::make_unique<MockSharingDeviceRegistration>(),
/* fcm_sender= */ nullptr, /* fcm_sender= */ nullptr,
std::make_unique<SharingFCMHandler>(nullptr, nullptr, nullptr), std::make_unique<SharingFCMHandler>(nullptr, nullptr, nullptr),
/* gcm_driver= */ nullptr, /* gcm_driver= */ nullptr,
......
...@@ -40,12 +40,28 @@ const char kExpectedText[] = "Text to be copied"; ...@@ -40,12 +40,28 @@ const char kExpectedText[] = "Text to be copied";
const char kReceiverGuid[] = "test_receiver_guid"; const char kReceiverGuid[] = "test_receiver_guid";
const char kReceiverName[] = "test_receiver_name"; const char kReceiverName[] = "test_receiver_name";
class MockSharingDeviceRegistration : public SharingDeviceRegistration {
public:
explicit MockSharingDeviceRegistration()
: SharingDeviceRegistration(/* pref_service_= */ nullptr,
/* sharing_sync_preference_= */ nullptr,
/* instance_id_driver_= */ nullptr,
/* vapid_key_manager_= */ nullptr) {}
~MockSharingDeviceRegistration() override = default;
MOCK_CONST_METHOD0(IsSharedClipboardSupported, bool());
private:
DISALLOW_COPY_AND_ASSIGN(MockSharingDeviceRegistration);
};
class MockSharingService : public SharingService { class MockSharingService : public SharingService {
public: public:
explicit MockSharingService(std::unique_ptr<SharingFCMHandler> fcm_handler) explicit MockSharingService(std::unique_ptr<SharingFCMHandler> fcm_handler)
: SharingService(/* sync_prefs= */ nullptr, : SharingService(/* sync_prefs= */ nullptr,
/* vapid_key_manager= */ nullptr, /* vapid_key_manager= */ nullptr,
/* sharing_device_registration= */ nullptr, std::make_unique<MockSharingDeviceRegistration>(),
/* fcm_sender= */ nullptr, /* fcm_sender= */ nullptr,
std::move(fcm_handler), std::move(fcm_handler),
/* gcm_driver= */ nullptr, /* gcm_driver= */ nullptr,
......
...@@ -34,12 +34,28 @@ namespace { ...@@ -34,12 +34,28 @@ namespace {
const char kEmptyText[] = ""; const char kEmptyText[] = "";
const char kText[] = "Some text to copy to phone device."; const char kText[] = "Some text to copy to phone device.";
class MockSharingDeviceRegistration : public SharingDeviceRegistration {
public:
explicit MockSharingDeviceRegistration()
: SharingDeviceRegistration(/* pref_service_= */ nullptr,
/* sharing_sync_preference_= */ nullptr,
/* instance_id_driver_= */ nullptr,
/* vapid_key_manager_= */ nullptr) {}
~MockSharingDeviceRegistration() override = default;
MOCK_CONST_METHOD0(IsSharedClipboardSupported, bool());
private:
DISALLOW_COPY_AND_ASSIGN(MockSharingDeviceRegistration);
};
class MockSharingService : public SharingService { class MockSharingService : public SharingService {
public: public:
explicit MockSharingService(std::unique_ptr<SharingFCMHandler> fcm_handler) explicit MockSharingService(std::unique_ptr<SharingFCMHandler> fcm_handler)
: SharingService(/* sync_prefs= */ nullptr, : SharingService(/* sync_prefs= */ nullptr,
/* vapid_key_manager= */ nullptr, /* vapid_key_manager= */ nullptr,
/* sharing_device_registration= */ nullptr, std::make_unique<MockSharingDeviceRegistration>(),
/* fcm_sender= */ nullptr, /* fcm_sender= */ nullptr,
std::move(fcm_handler), std::move(fcm_handler),
/* gcm_driver= */ nullptr, /* gcm_driver= */ nullptr,
......
...@@ -45,14 +45,14 @@ class SharingDeviceRegistration { ...@@ -45,14 +45,14 @@ class SharingDeviceRegistration {
// Un-registers device with sharing sync preferences. // Un-registers device with sharing sync preferences.
virtual void UnregisterDevice(RegistrationCallback callback); virtual void UnregisterDevice(RegistrationCallback callback);
// Returns if device can handle receiving of shared clipboard contents.
virtual bool IsSharedClipboardSupported() const;
// For testing // For testing
void SetEnabledFeaturesForTesting( void SetEnabledFeaturesForTesting(
std::set<sync_pb::SharingSpecificFields_EnabledFeatures> std::set<sync_pb::SharingSpecificFields_EnabledFeatures>
enabled_feautres); enabled_feautres);
// Returns if device can handle receiving of shared clipboard contents.
bool IsSharedClipboardSupported() const;
private: private:
FRIEND_TEST_ALL_PREFIXES(SharingDeviceRegistrationTest, FRIEND_TEST_ALL_PREFIXES(SharingDeviceRegistrationTest,
RegisterDeviceTest_Success); RegisterDeviceTest_Success);
......
...@@ -91,7 +91,7 @@ SharingService::SharingService( ...@@ -91,7 +91,7 @@ SharingService::SharingService(
this, notification_display_service); this, notification_display_service);
#endif // defined(OS_ANDROID) #endif // defined(OS_ANDROID)
if (base::FeatureList::IsEnabled(kSharedClipboardReceiver)) { if (sharing_device_registration_->IsSharedClipboardSupported()) {
fcm_handler_->AddSharingHandler( fcm_handler_->AddSharingHandler(
chrome_browser_sharing::SharingMessage::kSharedClipboardMessage, chrome_browser_sharing::SharingMessage::kSharedClipboardMessage,
shared_clipboard_message_handler_.get()); shared_clipboard_message_handler_.get());
......
...@@ -159,11 +159,20 @@ class FakeSharingDeviceRegistration : public SharingDeviceRegistration { ...@@ -159,11 +159,20 @@ class FakeSharingDeviceRegistration : public SharingDeviceRegistration {
int registration_attempts() { return registration_attempts_; } int registration_attempts() { return registration_attempts_; }
int unregistration_attempts() { return unregistration_attempts_; } int unregistration_attempts() { return unregistration_attempts_; }
bool IsSharedClipboardSupported() const override {
return shared_clipboard_supported_;
}
void SetIsSharedClipboardSupported(bool supported) {
shared_clipboard_supported_ = supported;
}
private: private:
SharingDeviceRegistrationResult result_ = SharingDeviceRegistrationResult result_ =
SharingDeviceRegistrationResult::kSuccess; SharingDeviceRegistrationResult::kSuccess;
int registration_attempts_ = 0; int registration_attempts_ = 0;
int unregistration_attempts_ = 0; int unregistration_attempts_ = 0;
bool shared_clipboard_supported_ = false;
}; };
class SharingServiceTest : public testing::Test { class SharingServiceTest : public testing::Test {
...@@ -255,6 +264,24 @@ class SharingServiceTest : public testing::Test { ...@@ -255,6 +264,24 @@ class SharingServiceTest : public testing::Test {
} // namespace } // namespace
TEST_F(SharingServiceTest, SharedClipboard_IsAdded) {
sharing_device_registration_->SetIsSharedClipboardSupported(true);
GetSharingService();
SharingMessageHandler* shared_clipboard_handler =
fcm_handler_->GetSharingHandler(
chrome_browser_sharing::SharingMessage::kSharedClipboardMessage);
EXPECT_TRUE(shared_clipboard_handler);
}
TEST_F(SharingServiceTest, SharedClipboard_NotAdded) {
sharing_device_registration_->SetIsSharedClipboardSupported(false);
GetSharingService();
SharingMessageHandler* shared_clipboard_handler =
fcm_handler_->GetSharingHandler(
chrome_browser_sharing::SharingMessage::kSharedClipboardMessage);
EXPECT_FALSE(shared_clipboard_handler);
}
TEST_F(SharingServiceTest, GetDeviceCandidates_Empty) { TEST_F(SharingServiceTest, GetDeviceCandidates_Empty) {
std::vector<std::unique_ptr<syncer::DeviceInfo>> candidates = std::vector<std::unique_ptr<syncer::DeviceInfo>> candidates =
GetSharingService()->GetDeviceCandidates( GetSharingService()->GetDeviceCandidates(
......
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