Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(375)

Side by Side Diff: remoting/host/it2me/it2me_native_messaging_host_unittest.cc

Issue 2179353004: Update Windows It2Me to allow remote users to interact with elevated windows (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@it2me_uiaccess
Patch Set: Fixing some comments Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 "remoting/host/it2me/it2me_native_messaging_host.h" 5 #include "remoting/host/it2me/it2me_native_messaging_host.h"
6 6
7 #include <cstdint> 7 #include <cstdint>
8 #include <memory> 8 #include <memory>
9 #include <string> 9 #include <string>
10 #include <utility> 10 #include <utility>
11 11
12 #include "base/bind.h"
12 #include "base/compiler_specific.h" 13 #include "base/compiler_specific.h"
13 #include "base/json/json_reader.h" 14 #include "base/json/json_reader.h"
14 #include "base/json/json_writer.h" 15 #include "base/json/json_writer.h"
16 #include "base/location.h"
15 #include "base/macros.h" 17 #include "base/macros.h"
16 #include "base/memory/ptr_util.h" 18 #include "base/memory/ptr_util.h"
17 #include "base/message_loop/message_loop.h" 19 #include "base/message_loop/message_loop.h"
18 #include "base/run_loop.h" 20 #include "base/run_loop.h"
19 #include "base/stl_util.h" 21 #include "base/stl_util.h"
20 #include "base/strings/stringize_macros.h" 22 #include "base/strings/stringize_macros.h"
23 #include "base/threading/thread_task_runner_handle.h"
21 #include "base/values.h" 24 #include "base/values.h"
25 #include "components/policy/core/common/mock_policy_service.h"
22 #include "net/base/file_stream.h" 26 #include "net/base/file_stream.h"
23 #include "remoting/base/auto_thread_task_runner.h" 27 #include "remoting/base/auto_thread_task_runner.h"
24 #include "remoting/host/chromoting_host_context.h" 28 #include "remoting/host/chromoting_host_context.h"
25 #include "remoting/host/native_messaging/log_message_handler.h" 29 #include "remoting/host/native_messaging/log_message_handler.h"
26 #include "remoting/host/native_messaging/native_messaging_pipe.h" 30 #include "remoting/host/native_messaging/native_messaging_pipe.h"
27 #include "remoting/host/native_messaging/pipe_messaging_channel.h" 31 #include "remoting/host/native_messaging/pipe_messaging_channel.h"
28 #include "remoting/host/policy_watcher.h" 32 #include "remoting/host/policy_watcher.h"
29 #include "remoting/host/setup/test_util.h" 33 #include "remoting/host/setup/test_util.h"
30 #include "testing/gtest/include/gtest/gtest.h" 34 #include "testing/gtest/include/gtest/gtest.h"
31 35
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
64 68
65 std::string string_value; 69 std::string string_value;
66 EXPECT_TRUE(response->GetString("type", &string_value)); 70 EXPECT_TRUE(response->GetString("type", &string_value));
67 EXPECT_EQ(type, string_value); 71 EXPECT_EQ(type, string_value);
68 72
69 int int_value; 73 int int_value;
70 EXPECT_TRUE(response->GetInteger("id", &int_value)); 74 EXPECT_TRUE(response->GetInteger("id", &int_value));
71 EXPECT_EQ(id, int_value); 75 EXPECT_EQ(id, int_value);
72 } 76 }
73 77
74 } // namespace 78 class FakePolicyService : public policy::PolicyService {
79 public:
80 FakePolicyService();
81 ~FakePolicyService() override;
82
83 // policy::PolicyService overrides.
84 void AddObserver(policy::PolicyDomain domain,
85 policy::PolicyService::Observer* observer) override;
86 void RemoveObserver(policy::PolicyDomain domain,
87 policy::PolicyService::Observer* observer) override;
88 const policy::PolicyMap& GetPolicies(
89 const policy::PolicyNamespace& ns) const override;
90 bool IsInitializationComplete(policy::PolicyDomain domain) const override;
91 void RefreshPolicies(const base::Closure& callback) override;
92
93 private:
94 policy::PolicyMap policy_map_;
95
96 DISALLOW_COPY_AND_ASSIGN(FakePolicyService);
97 };
98
99 FakePolicyService::FakePolicyService() {}
100
101 FakePolicyService::~FakePolicyService() {}
102
103 void FakePolicyService::AddObserver(policy::PolicyDomain domain,
104 policy::PolicyService::Observer* observer) {
105 }
106
107 void FakePolicyService::RemoveObserver(
108 policy::PolicyDomain domain,
109 policy::PolicyService::Observer* observer) {}
110
111 const policy::PolicyMap& FakePolicyService::GetPolicies(
112 const policy::PolicyNamespace& ns) const {
113 return policy_map_;
114 }
115
116 bool FakePolicyService::IsInitializationComplete(
117 policy::PolicyDomain domain) const {
118 return true;
119 }
120
121 void FakePolicyService::RefreshPolicies(const base::Closure& callback) {
122 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, callback);
123 }
75 124
76 class MockIt2MeHost : public It2MeHost { 125 class MockIt2MeHost : public It2MeHost {
77 public: 126 public:
78 MockIt2MeHost(std::unique_ptr<ChromotingHostContext> context, 127 MockIt2MeHost(std::unique_ptr<ChromotingHostContext> context,
79 std::unique_ptr<PolicyWatcher> policy_watcher, 128 std::unique_ptr<PolicyWatcher> policy_watcher,
80 base::WeakPtr<It2MeHost::Observer> observer, 129 base::WeakPtr<It2MeHost::Observer> observer,
81 const XmppSignalStrategy::XmppServerConfig& xmpp_server_config, 130 const XmppSignalStrategy::XmppServerConfig& xmpp_server_config,
82 const std::string& directory_bot_jid) 131 const std::string& directory_bot_jid)
83 : It2MeHost(std::move(context), 132 : It2MeHost(std::move(context),
84 std::move(policy_watcher), 133 std::move(policy_watcher),
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
149 if (!host_context()->network_task_runner()->BelongsToCurrentThread()) { 198 if (!host_context()->network_task_runner()->BelongsToCurrentThread()) {
150 host_context()->network_task_runner()->PostTask( 199 host_context()->network_task_runner()->PostTask(
151 FROM_HERE, base::Bind(&It2MeHost::SetStateForTesting, this, state, "")); 200 FROM_HERE, base::Bind(&It2MeHost::SetStateForTesting, this, state, ""));
152 } else { 201 } else {
153 SetStateForTesting(state, ""); 202 SetStateForTesting(state, "");
154 } 203 }
155 } 204 }
156 205
157 class MockIt2MeHostFactory : public It2MeHostFactory { 206 class MockIt2MeHostFactory : public It2MeHostFactory {
158 public: 207 public:
159 MockIt2MeHostFactory() : It2MeHostFactory() {} 208 MockIt2MeHostFactory() : It2MeHostFactory() {
209 #if defined(OS_CHROMEOS)
210 // On Chrome OS, the browser owns the PolicyService so simulate that here.
211 fake_policy_service_.reset(new FakePolicyService());
212 set_policy_service(fake_policy_service_.get());
213 #endif // defined(OS_CHROMEOS)
214 }
215
160 scoped_refptr<It2MeHost> CreateIt2MeHost( 216 scoped_refptr<It2MeHost> CreateIt2MeHost(
161 std::unique_ptr<ChromotingHostContext> context, 217 std::unique_ptr<ChromotingHostContext> context,
162 base::WeakPtr<It2MeHost::Observer> observer, 218 base::WeakPtr<It2MeHost::Observer> observer,
163 const XmppSignalStrategy::XmppServerConfig& xmpp_server_config, 219 const XmppSignalStrategy::XmppServerConfig& xmpp_server_config,
164 const std::string& directory_bot_jid) override { 220 const std::string& directory_bot_jid) override {
165 return new MockIt2MeHost(std::move(context), 221 return new MockIt2MeHost(std::move(context),
166 /*confirmation_dialog_factory=*/nullptr, observer, 222 /*confirmation_dialog_factory=*/nullptr, observer,
167 xmpp_server_config, directory_bot_jid); 223 xmpp_server_config, directory_bot_jid);
168 } 224 }
169 225
170 private: 226 private:
227 std::unique_ptr<policy::PolicyService> fake_policy_service_;
228
171 DISALLOW_COPY_AND_ASSIGN(MockIt2MeHostFactory); 229 DISALLOW_COPY_AND_ASSIGN(MockIt2MeHostFactory);
172 }; // MockIt2MeHostFactory 230 };
231
232 } // namespace
173 233
174 class It2MeNativeMessagingHostTest : public testing::Test { 234 class It2MeNativeMessagingHostTest : public testing::Test {
175 public: 235 public:
176 It2MeNativeMessagingHostTest() {} 236 It2MeNativeMessagingHostTest() {}
177 ~It2MeNativeMessagingHostTest() override {} 237 ~It2MeNativeMessagingHostTest() override {}
178 238
179 void SetUp() override; 239 void SetUp() override;
180 void TearDown() override; 240 void TearDown() override;
181 241
182 protected: 242 protected:
(...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after
446 506
447 pipe_.reset(new NativeMessagingPipe()); 507 pipe_.reset(new NativeMessagingPipe());
448 508
449 std::unique_ptr<extensions::NativeMessagingChannel> channel( 509 std::unique_ptr<extensions::NativeMessagingChannel> channel(
450 new PipeMessagingChannel(std::move(input_read_file), 510 new PipeMessagingChannel(std::move(input_read_file),
451 std::move(output_write_file))); 511 std::move(output_write_file)));
452 512
453 // Creating a native messaging host with a mock It2MeHostFactory. 513 // Creating a native messaging host with a mock It2MeHostFactory.
454 std::unique_ptr<extensions::NativeMessageHost> it2me_host( 514 std::unique_ptr<extensions::NativeMessageHost> it2me_host(
455 new It2MeNativeMessagingHost( 515 new It2MeNativeMessagingHost(
516 /*needs_elevation=*/false,
456 ChromotingHostContext::Create(host_task_runner_), 517 ChromotingHostContext::Create(host_task_runner_),
457 base::WrapUnique(new MockIt2MeHostFactory()))); 518 base::WrapUnique(new MockIt2MeHostFactory())));
458 it2me_host->Start(pipe_.get()); 519 it2me_host->Start(pipe_.get());
459 520
460 pipe_->Start(std::move(it2me_host), std::move(channel)); 521 pipe_->Start(std::move(it2me_host), std::move(channel));
461 522
462 // Notify the test that the host has finished starting up. 523 // Notify the test that the host has finished starting up.
463 test_message_loop_->task_runner()->PostTask( 524 test_message_loop_->task_runner()->PostTask(
464 FROM_HERE, test_run_loop_->QuitClosure()); 525 FROM_HERE, test_run_loop_->QuitClosure());
465 } 526 }
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
551 } 612 }
552 613
553 // Verify rejection if type is unrecognized. 614 // Verify rejection if type is unrecognized.
554 TEST_F(It2MeNativeMessagingHostTest, InvalidType) { 615 TEST_F(It2MeNativeMessagingHostTest, InvalidType) {
555 base::DictionaryValue message; 616 base::DictionaryValue message;
556 message.SetString("type", "xxx"); 617 message.SetString("type", "xxx");
557 TestBadRequest(message, true); 618 TestBadRequest(message, true);
558 } 619 }
559 620
560 } // namespace remoting 621 } // namespace remoting
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698