OLD | NEW |
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 "base/basictypes.h" | 7 #include "base/basictypes.h" |
8 #include "base/compiler_specific.h" | 8 #include "base/compiler_specific.h" |
9 #include "base/json/json_reader.h" | 9 #include "base/json/json_reader.h" |
10 #include "base/json/json_writer.h" | 10 #include "base/json/json_writer.h" |
11 #include "base/message_loop/message_loop.h" | 11 #include "base/message_loop/message_loop.h" |
12 #include "base/run_loop.h" | 12 #include "base/run_loop.h" |
13 #include "base/stl_util.h" | 13 #include "base/stl_util.h" |
14 #include "base/strings/stringize_macros.h" | 14 #include "base/strings/stringize_macros.h" |
15 #include "base/values.h" | 15 #include "base/values.h" |
16 #include "net/base/file_stream.h" | 16 #include "net/base/file_stream.h" |
17 #include "net/base/net_util.h" | 17 #include "net/base/net_util.h" |
18 #include "remoting/base/auto_thread_task_runner.h" | 18 #include "remoting/base/auto_thread_task_runner.h" |
19 #include "remoting/host/chromoting_host_context.h" | 19 #include "remoting/host/chromoting_host_context.h" |
20 #include "remoting/host/native_messaging/native_messaging_pipe.h" | 20 #include "remoting/host/native_messaging/native_messaging_pipe.h" |
21 #include "remoting/host/native_messaging/pipe_messaging_channel.h" | 21 #include "remoting/host/native_messaging/pipe_messaging_channel.h" |
22 #include "remoting/host/policy_hack/policy_watcher.h" | |
23 #include "remoting/host/setup/test_util.h" | 22 #include "remoting/host/setup/test_util.h" |
24 #include "testing/gtest/include/gtest/gtest.h" | 23 #include "testing/gtest/include/gtest/gtest.h" |
25 | 24 |
26 namespace remoting { | 25 namespace remoting { |
27 | 26 |
28 namespace { | 27 namespace { |
29 | 28 |
30 const char kTestAccessCode[] = "888888"; | 29 const char kTestAccessCode[] = "888888"; |
31 const int kTestAccessCodeLifetimeInSeconds = 666; | 30 const int kTestAccessCodeLifetimeInSeconds = 666; |
32 const char kTestClientUsername[] = "some_user@gmail.com"; | 31 const char kTestClientUsername[] = "some_user@gmail.com"; |
(...skipping 28 matching lines...) Expand all Loading... |
61 | 60 |
62 int int_value; | 61 int int_value; |
63 EXPECT_TRUE(response->GetInteger("id", &int_value)); | 62 EXPECT_TRUE(response->GetInteger("id", &int_value)); |
64 EXPECT_EQ(id, int_value); | 63 EXPECT_EQ(id, int_value); |
65 } | 64 } |
66 | 65 |
67 } // namespace | 66 } // namespace |
68 | 67 |
69 class MockIt2MeHost : public It2MeHost { | 68 class MockIt2MeHost : public It2MeHost { |
70 public: | 69 public: |
71 MockIt2MeHost(scoped_ptr<ChromotingHostContext> context, | 70 MockIt2MeHost(ChromotingHostContext* context, |
72 scoped_ptr<policy_hack::PolicyWatcher> policy_watcher, | 71 scoped_refptr<base::SingleThreadTaskRunner> task_runner, |
73 base::WeakPtr<It2MeHost::Observer> observer, | 72 base::WeakPtr<It2MeHost::Observer> observer, |
74 const XmppSignalStrategy::XmppServerConfig& xmpp_server_config, | 73 const XmppSignalStrategy::XmppServerConfig& xmpp_server_config, |
75 const std::string& directory_bot_jid) | 74 const std::string& directory_bot_jid) |
76 : It2MeHost(context.Pass(), | 75 : It2MeHost(context, |
77 policy_watcher.Pass(), | 76 task_runner, |
78 observer, | 77 observer, |
79 xmpp_server_config, | 78 xmpp_server_config, |
80 directory_bot_jid) {} | 79 directory_bot_jid) {} |
81 | 80 |
82 // It2MeHost overrides | 81 // It2MeHost overrides |
83 void Connect() override; | 82 void Connect() override; |
84 void Disconnect() override; | 83 void Disconnect() override; |
85 void RequestNatPolicy() override; | 84 void RequestNatPolicy() override; |
86 | 85 |
87 private: | 86 private: |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
142 if (!host_context()->network_task_runner()->BelongsToCurrentThread()) { | 141 if (!host_context()->network_task_runner()->BelongsToCurrentThread()) { |
143 host_context()->network_task_runner()->PostTask( | 142 host_context()->network_task_runner()->PostTask( |
144 FROM_HERE, base::Bind(&It2MeHost::SetStateForTesting, this, state)); | 143 FROM_HERE, base::Bind(&It2MeHost::SetStateForTesting, this, state)); |
145 } else { | 144 } else { |
146 SetStateForTesting(state); | 145 SetStateForTesting(state); |
147 } | 146 } |
148 } | 147 } |
149 | 148 |
150 class MockIt2MeHostFactory : public It2MeHostFactory { | 149 class MockIt2MeHostFactory : public It2MeHostFactory { |
151 public: | 150 public: |
152 MockIt2MeHostFactory() : It2MeHostFactory() {} | 151 MockIt2MeHostFactory() {} |
153 scoped_refptr<It2MeHost> CreateIt2MeHost( | 152 scoped_refptr<It2MeHost> CreateIt2MeHost( |
154 scoped_ptr<ChromotingHostContext> context, | 153 ChromotingHostContext* context, |
| 154 scoped_refptr<base::SingleThreadTaskRunner> task_runner, |
155 base::WeakPtr<It2MeHost::Observer> observer, | 155 base::WeakPtr<It2MeHost::Observer> observer, |
156 const XmppSignalStrategy::XmppServerConfig& xmpp_server_config, | 156 const XmppSignalStrategy::XmppServerConfig& xmpp_server_config, |
157 const std::string& directory_bot_jid) override { | 157 const std::string& directory_bot_jid) override { |
158 return new MockIt2MeHost(context.Pass(), nullptr, observer, | 158 return new MockIt2MeHost( |
159 xmpp_server_config, directory_bot_jid); | 159 context, task_runner, observer, xmpp_server_config, directory_bot_jid); |
160 } | 160 } |
161 | 161 |
162 private: | 162 private: |
163 DISALLOW_COPY_AND_ASSIGN(MockIt2MeHostFactory); | 163 DISALLOW_COPY_AND_ASSIGN(MockIt2MeHostFactory); |
164 }; // MockIt2MeHostFactory | 164 }; // MockIt2MeHostFactory |
165 | 165 |
166 class It2MeNativeMessagingHostTest : public testing::Test { | 166 class It2MeNativeMessagingHostTest : public testing::Test { |
167 public: | 167 public: |
168 It2MeNativeMessagingHostTest() {} | 168 It2MeNativeMessagingHostTest() {} |
169 ~It2MeNativeMessagingHostTest() override {} | 169 ~It2MeNativeMessagingHostTest() override {} |
(...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
422 | 422 |
423 void It2MeNativeMessagingHostTest::StartHost() { | 423 void It2MeNativeMessagingHostTest::StartHost() { |
424 DCHECK(host_task_runner_->RunsTasksOnCurrentThread()); | 424 DCHECK(host_task_runner_->RunsTasksOnCurrentThread()); |
425 | 425 |
426 base::File input_read_file; | 426 base::File input_read_file; |
427 base::File output_write_file; | 427 base::File output_write_file; |
428 | 428 |
429 ASSERT_TRUE(MakePipe(&input_read_file, &input_write_file_)); | 429 ASSERT_TRUE(MakePipe(&input_read_file, &input_write_file_)); |
430 ASSERT_TRUE(MakePipe(&output_read_file_, &output_write_file)); | 430 ASSERT_TRUE(MakePipe(&output_read_file_, &output_write_file)); |
431 | 431 |
| 432 // Creating a native messaging host with a mock It2MeHostFactory. |
| 433 scoped_ptr<It2MeHostFactory> factory(new MockIt2MeHostFactory()); |
| 434 |
432 pipe_.reset(new NativeMessagingPipe()); | 435 pipe_.reset(new NativeMessagingPipe()); |
433 | 436 |
434 scoped_ptr<extensions::NativeMessagingChannel> channel( | 437 scoped_ptr<extensions::NativeMessagingChannel> channel( |
435 new PipeMessagingChannel(input_read_file.Pass(), | 438 new PipeMessagingChannel(input_read_file.Pass(), |
436 output_write_file.Pass())); | 439 output_write_file.Pass())); |
437 | 440 |
438 // Creating a native messaging host with a mock It2MeHostFactory. | |
439 scoped_ptr<extensions::NativeMessageHost> it2me_host( | 441 scoped_ptr<extensions::NativeMessageHost> it2me_host( |
440 new It2MeNativeMessagingHost( | 442 new It2MeNativeMessagingHost( |
441 ChromotingHostContext::Create(host_task_runner_), | 443 host_task_runner_, |
442 make_scoped_ptr(new MockIt2MeHostFactory()))); | 444 factory.Pass())); |
443 it2me_host->Start(pipe_.get()); | 445 it2me_host->Start(pipe_.get()); |
444 | 446 |
445 pipe_->Start(it2me_host.Pass(), | 447 pipe_->Start(it2me_host.Pass(), |
446 channel.Pass(), | 448 channel.Pass(), |
447 base::Bind(&It2MeNativeMessagingHostTest::StopHost, | 449 base::Bind(&It2MeNativeMessagingHostTest::StopHost, |
448 base::Unretained(this))); | 450 base::Unretained(this))); |
449 | 451 |
450 // Notify the test that the host has finished starting up. | 452 // Notify the test that the host has finished starting up. |
451 test_message_loop_->message_loop_proxy()->PostTask( | 453 test_message_loop_->message_loop_proxy()->PostTask( |
452 FROM_HERE, test_run_loop_->QuitClosure()); | 454 FROM_HERE, test_run_loop_->QuitClosure()); |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
552 | 554 |
553 // Verify rejection if type is unrecognized. | 555 // Verify rejection if type is unrecognized. |
554 TEST_F(It2MeNativeMessagingHostTest, InvalidType) { | 556 TEST_F(It2MeNativeMessagingHostTest, InvalidType) { |
555 base::DictionaryValue message; | 557 base::DictionaryValue message; |
556 message.SetString("type", "xxx"); | 558 message.SetString("type", "xxx"); |
557 TestBadRequest(message, true); | 559 TestBadRequest(message, true); |
558 } | 560 } |
559 | 561 |
560 } // namespace remoting | 562 } // namespace remoting |
561 | 563 |
OLD | NEW |