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

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: Removing the CHECK assertion and replacing it with LOG(ERROR) instead. 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();
209 ~MockIt2MeHostFactory() override;
210
160 scoped_refptr<It2MeHost> CreateIt2MeHost( 211 scoped_refptr<It2MeHost> CreateIt2MeHost(
161 std::unique_ptr<ChromotingHostContext> context, 212 std::unique_ptr<ChromotingHostContext> context,
213 policy::PolicyService* policy_service,
162 base::WeakPtr<It2MeHost::Observer> observer, 214 base::WeakPtr<It2MeHost::Observer> observer,
163 const XmppSignalStrategy::XmppServerConfig& xmpp_server_config, 215 const XmppSignalStrategy::XmppServerConfig& xmpp_server_config,
164 const std::string& directory_bot_jid) override { 216 const std::string& directory_bot_jid) override;
165 return new MockIt2MeHost(std::move(context),
166 /*confirmation_dialog_factory=*/nullptr, observer,
167 xmpp_server_config, directory_bot_jid);
168 }
169 217
170 private: 218 private:
171 DISALLOW_COPY_AND_ASSIGN(MockIt2MeHostFactory); 219 DISALLOW_COPY_AND_ASSIGN(MockIt2MeHostFactory);
172 }; // MockIt2MeHostFactory 220 };
221
222 MockIt2MeHostFactory::MockIt2MeHostFactory() : It2MeHostFactory() {}
223
224 MockIt2MeHostFactory::~MockIt2MeHostFactory() {}
225
226 scoped_refptr<It2MeHost> MockIt2MeHostFactory::CreateIt2MeHost(
227 std::unique_ptr<ChromotingHostContext> context,
228 policy::PolicyService* policy_service,
229 base::WeakPtr<It2MeHost::Observer> observer,
230 const XmppSignalStrategy::XmppServerConfig& xmpp_server_config,
231 const std::string& directory_bot_jid) {
232 return new MockIt2MeHost(std::move(context),
233 /*policy_watcher=*/nullptr, observer,
234 xmpp_server_config, directory_bot_jid);
235 }
236
237 } // namespace
173 238
174 class It2MeNativeMessagingHostTest : public testing::Test { 239 class It2MeNativeMessagingHostTest : public testing::Test {
175 public: 240 public:
176 It2MeNativeMessagingHostTest() {} 241 It2MeNativeMessagingHostTest() {}
177 ~It2MeNativeMessagingHostTest() override {} 242 ~It2MeNativeMessagingHostTest() override {}
178 243
179 void SetUp() override; 244 void SetUp() override;
180 void TearDown() override; 245 void TearDown() override;
181 246
182 protected: 247 protected:
(...skipping 29 matching lines...) Expand all
212 std::unique_ptr<base::MessageLoop> test_message_loop_; 277 std::unique_ptr<base::MessageLoop> test_message_loop_;
213 std::unique_ptr<base::RunLoop> test_run_loop_; 278 std::unique_ptr<base::RunLoop> test_run_loop_;
214 279
215 std::unique_ptr<base::Thread> host_thread_; 280 std::unique_ptr<base::Thread> host_thread_;
216 std::unique_ptr<base::RunLoop> host_run_loop_; 281 std::unique_ptr<base::RunLoop> host_run_loop_;
217 282
218 // Task runner of the host thread. 283 // Task runner of the host thread.
219 scoped_refptr<AutoThreadTaskRunner> host_task_runner_; 284 scoped_refptr<AutoThreadTaskRunner> host_task_runner_;
220 std::unique_ptr<remoting::NativeMessagingPipe> pipe_; 285 std::unique_ptr<remoting::NativeMessagingPipe> pipe_;
221 286
287 std::unique_ptr<policy::PolicyService> fake_policy_service_;
288
222 DISALLOW_COPY_AND_ASSIGN(It2MeNativeMessagingHostTest); 289 DISALLOW_COPY_AND_ASSIGN(It2MeNativeMessagingHostTest);
223 }; 290 };
224 291
225 void It2MeNativeMessagingHostTest::SetUp() { 292 void It2MeNativeMessagingHostTest::SetUp() {
226 test_message_loop_.reset(new base::MessageLoop()); 293 test_message_loop_.reset(new base::MessageLoop());
227 test_run_loop_.reset(new base::RunLoop()); 294 test_run_loop_.reset(new base::RunLoop());
228 295
296 #if defined(OS_CHROMEOS)
297 // On Chrome OS, the browser owns the PolicyService so simulate that here.
298 fake_policy_service_.reset(new FakePolicyService());
299 #endif // defined(OS_CHROMEOS)
300
229 // Run the host on a dedicated thread. 301 // Run the host on a dedicated thread.
230 host_thread_.reset(new base::Thread("host_thread")); 302 host_thread_.reset(new base::Thread("host_thread"));
231 host_thread_->Start(); 303 host_thread_->Start();
232 304
233 host_task_runner_ = new AutoThreadTaskRunner( 305 host_task_runner_ = new AutoThreadTaskRunner(
234 host_thread_->task_runner(), 306 host_thread_->task_runner(),
235 base::Bind(&It2MeNativeMessagingHostTest::ExitTest, 307 base::Bind(&It2MeNativeMessagingHostTest::ExitTest,
236 base::Unretained(this))); 308 base::Unretained(this)));
237 309
238 host_task_runner_->PostTask( 310 host_task_runner_->PostTask(
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after
446 518
447 pipe_.reset(new NativeMessagingPipe()); 519 pipe_.reset(new NativeMessagingPipe());
448 520
449 std::unique_ptr<extensions::NativeMessagingChannel> channel( 521 std::unique_ptr<extensions::NativeMessagingChannel> channel(
450 new PipeMessagingChannel(std::move(input_read_file), 522 new PipeMessagingChannel(std::move(input_read_file),
451 std::move(output_write_file))); 523 std::move(output_write_file)));
452 524
453 // Creating a native messaging host with a mock It2MeHostFactory. 525 // Creating a native messaging host with a mock It2MeHostFactory.
454 std::unique_ptr<extensions::NativeMessageHost> it2me_host( 526 std::unique_ptr<extensions::NativeMessageHost> it2me_host(
455 new It2MeNativeMessagingHost( 527 new It2MeNativeMessagingHost(
528 /*needs_elevation=*/false, fake_policy_service_.get(),
456 ChromotingHostContext::Create(host_task_runner_), 529 ChromotingHostContext::Create(host_task_runner_),
457 base::WrapUnique(new MockIt2MeHostFactory()))); 530 base::WrapUnique(new MockIt2MeHostFactory())));
458 it2me_host->Start(pipe_.get()); 531 it2me_host->Start(pipe_.get());
459 532
460 pipe_->Start(std::move(it2me_host), std::move(channel)); 533 pipe_->Start(std::move(it2me_host), std::move(channel));
461 534
462 // Notify the test that the host has finished starting up. 535 // Notify the test that the host has finished starting up.
463 test_message_loop_->task_runner()->PostTask( 536 test_message_loop_->task_runner()->PostTask(
464 FROM_HERE, test_run_loop_->QuitClosure()); 537 FROM_HERE, test_run_loop_->QuitClosure());
465 } 538 }
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
551 } 624 }
552 625
553 // Verify rejection if type is unrecognized. 626 // Verify rejection if type is unrecognized.
554 TEST_F(It2MeNativeMessagingHostTest, InvalidType) { 627 TEST_F(It2MeNativeMessagingHostTest, InvalidType) {
555 base::DictionaryValue message; 628 base::DictionaryValue message;
556 message.SetString("type", "xxx"); 629 message.SetString("type", "xxx");
557 TestBadRequest(message, true); 630 TestBadRequest(message, true);
558 } 631 }
559 632
560 } // namespace remoting 633 } // namespace remoting
OLDNEW
« no previous file with comments | « remoting/host/it2me/it2me_native_messaging_host_main.cc ('k') | remoting/host/win/elevation_helpers.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698