| Index: remoting/host/it2me/it2me_native_messaging_host_unittest.cc
|
| diff --git a/remoting/host/it2me/it2me_native_messaging_host_unittest.cc b/remoting/host/it2me/it2me_native_messaging_host_unittest.cc
|
| index af68edc35f21b507288626fc6d56196010be857b..8bf6a56dea91b4c4deb8c12c0e8df1eed2a847e1 100644
|
| --- a/remoting/host/it2me/it2me_native_messaging_host_unittest.cc
|
| +++ b/remoting/host/it2me/it2me_native_messaging_host_unittest.cc
|
| @@ -9,16 +9,20 @@
|
| #include <string>
|
| #include <utility>
|
|
|
| +#include "base/bind.h"
|
| #include "base/compiler_specific.h"
|
| #include "base/json/json_reader.h"
|
| #include "base/json/json_writer.h"
|
| +#include "base/location.h"
|
| #include "base/macros.h"
|
| #include "base/memory/ptr_util.h"
|
| #include "base/message_loop/message_loop.h"
|
| #include "base/run_loop.h"
|
| #include "base/stl_util.h"
|
| #include "base/strings/stringize_macros.h"
|
| +#include "base/threading/thread_task_runner_handle.h"
|
| #include "base/values.h"
|
| +#include "components/policy/core/common/mock_policy_service.h"
|
| #include "net/base/file_stream.h"
|
| #include "remoting/base/auto_thread_task_runner.h"
|
| #include "remoting/host/chromoting_host_context.h"
|
| @@ -71,7 +75,52 @@ void VerifyCommonProperties(std::unique_ptr<base::DictionaryValue> response,
|
| EXPECT_EQ(id, int_value);
|
| }
|
|
|
| -} // namespace
|
| +class FakePolicyService : public policy::PolicyService {
|
| + public:
|
| + FakePolicyService();
|
| + ~FakePolicyService() override;
|
| +
|
| + // policy::PolicyService overrides.
|
| + void AddObserver(policy::PolicyDomain domain,
|
| + policy::PolicyService::Observer* observer) override;
|
| + void RemoveObserver(policy::PolicyDomain domain,
|
| + policy::PolicyService::Observer* observer) override;
|
| + const policy::PolicyMap& GetPolicies(
|
| + const policy::PolicyNamespace& ns) const override;
|
| + bool IsInitializationComplete(policy::PolicyDomain domain) const override;
|
| + void RefreshPolicies(const base::Closure& callback) override;
|
| +
|
| + private:
|
| + policy::PolicyMap policy_map_;
|
| +
|
| + DISALLOW_COPY_AND_ASSIGN(FakePolicyService);
|
| +};
|
| +
|
| +FakePolicyService::FakePolicyService() {}
|
| +
|
| +FakePolicyService::~FakePolicyService() {}
|
| +
|
| +void FakePolicyService::AddObserver(policy::PolicyDomain domain,
|
| + policy::PolicyService::Observer* observer) {
|
| +}
|
| +
|
| +void FakePolicyService::RemoveObserver(
|
| + policy::PolicyDomain domain,
|
| + policy::PolicyService::Observer* observer) {}
|
| +
|
| +const policy::PolicyMap& FakePolicyService::GetPolicies(
|
| + const policy::PolicyNamespace& ns) const {
|
| + return policy_map_;
|
| +}
|
| +
|
| +bool FakePolicyService::IsInitializationComplete(
|
| + policy::PolicyDomain domain) const {
|
| + return true;
|
| +}
|
| +
|
| +void FakePolicyService::RefreshPolicies(const base::Closure& callback) {
|
| + base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, callback);
|
| +}
|
|
|
| class MockIt2MeHost : public It2MeHost {
|
| public:
|
| @@ -156,7 +205,14 @@ void MockIt2MeHost::RunSetState(It2MeHostState state) {
|
|
|
| class MockIt2MeHostFactory : public It2MeHostFactory {
|
| public:
|
| - MockIt2MeHostFactory() : It2MeHostFactory() {}
|
| + MockIt2MeHostFactory() : It2MeHostFactory() {
|
| +#if defined(OS_CHROMEOS)
|
| + // On Chrome OS, the browser owns the PolicyService so simulate that here.
|
| + fake_policy_service_.reset(new FakePolicyService());
|
| + set_policy_service(fake_policy_service_.get());
|
| +#endif // defined(OS_CHROMEOS)
|
| + }
|
| +
|
| scoped_refptr<It2MeHost> CreateIt2MeHost(
|
| std::unique_ptr<ChromotingHostContext> context,
|
| base::WeakPtr<It2MeHost::Observer> observer,
|
| @@ -168,8 +224,12 @@ class MockIt2MeHostFactory : public It2MeHostFactory {
|
| }
|
|
|
| private:
|
| + std::unique_ptr<policy::PolicyService> fake_policy_service_;
|
| +
|
| DISALLOW_COPY_AND_ASSIGN(MockIt2MeHostFactory);
|
| -}; // MockIt2MeHostFactory
|
| +};
|
| +
|
| +} // namespace
|
|
|
| class It2MeNativeMessagingHostTest : public testing::Test {
|
| public:
|
| @@ -453,6 +513,7 @@ void It2MeNativeMessagingHostTest::StartHost() {
|
| // Creating a native messaging host with a mock It2MeHostFactory.
|
| std::unique_ptr<extensions::NativeMessageHost> it2me_host(
|
| new It2MeNativeMessagingHost(
|
| + /*needs_elevation=*/false,
|
| ChromotingHostContext::Create(host_task_runner_),
|
| base::WrapUnique(new MockIt2MeHostFactory())));
|
| it2me_host->Start(pipe_.get());
|
|
|