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_impl.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/setup/test_util.h" | 22 #include "remoting/host/setup/test_util.h" |
23 #include "testing/gtest/include/gtest/gtest.h" | 23 #include "testing/gtest/include/gtest/gtest.h" |
24 | 24 |
25 namespace remoting { | 25 namespace remoting { |
26 | 26 |
27 namespace { | 27 namespace { |
28 | 28 |
29 const char kTestAccessCode[] = "888888"; | 29 const char kTestAccessCode[] = "888888"; |
(...skipping 30 matching lines...) Expand all Loading... |
60 | 60 |
61 int int_value; | 61 int int_value; |
62 EXPECT_TRUE(response->GetInteger("id", &int_value)); | 62 EXPECT_TRUE(response->GetInteger("id", &int_value)); |
63 EXPECT_EQ(id, int_value); | 63 EXPECT_EQ(id, int_value); |
64 } | 64 } |
65 | 65 |
66 } // namespace | 66 } // namespace |
67 | 67 |
68 class MockIt2MeHost : public It2MeHost { | 68 class MockIt2MeHost : public It2MeHost { |
69 public: | 69 public: |
70 MockIt2MeHost(ChromotingHostContext* context, | 70 MockIt2MeHost(scoped_refptr<ChromotingHostContext> context, |
71 scoped_refptr<base::SingleThreadTaskRunner> task_runner, | 71 scoped_refptr<base::SingleThreadTaskRunner> task_runner, |
72 base::WeakPtr<It2MeHost::Observer> observer, | 72 base::WeakPtr<It2MeHost::Observer> observer, |
73 const XmppSignalStrategy::XmppServerConfig& xmpp_server_config, | 73 const XmppSignalStrategy::XmppServerConfig& xmpp_server_config, |
74 const std::string& directory_bot_jid) | 74 const std::string& directory_bot_jid) |
75 : It2MeHost(context, | 75 : It2MeHost(context, |
76 task_runner, | 76 task_runner, |
77 observer, | 77 observer, |
78 xmpp_server_config, | 78 xmpp_server_config, |
79 directory_bot_jid) {} | 79 directory_bot_jid) {} |
80 | 80 |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
143 FROM_HERE, base::Bind(&It2MeHost::SetStateForTesting, this, state)); | 143 FROM_HERE, base::Bind(&It2MeHost::SetStateForTesting, this, state)); |
144 } else { | 144 } else { |
145 SetStateForTesting(state); | 145 SetStateForTesting(state); |
146 } | 146 } |
147 } | 147 } |
148 | 148 |
149 class MockIt2MeHostFactory : public It2MeHostFactory { | 149 class MockIt2MeHostFactory : public It2MeHostFactory { |
150 public: | 150 public: |
151 MockIt2MeHostFactory() {} | 151 MockIt2MeHostFactory() {} |
152 virtual scoped_refptr<It2MeHost> CreateIt2MeHost( | 152 virtual scoped_refptr<It2MeHost> CreateIt2MeHost( |
153 ChromotingHostContext* context, | 153 scoped_refptr<ChromotingHostContext> context, |
154 scoped_refptr<base::SingleThreadTaskRunner> task_runner, | 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( | 158 return new MockIt2MeHost(context, |
159 context, task_runner, observer, xmpp_server_config, directory_bot_jid); | 159 task_runner, |
| 160 observer, |
| 161 xmpp_server_config, |
| 162 directory_bot_jid); |
160 } | 163 } |
161 | 164 |
162 private: | 165 private: |
163 DISALLOW_COPY_AND_ASSIGN(MockIt2MeHostFactory); | 166 DISALLOW_COPY_AND_ASSIGN(MockIt2MeHostFactory); |
164 }; // MockIt2MeHostFactory | 167 }; // MockIt2MeHostFactory |
165 | 168 |
166 class It2MeNativeMessagingHostTest : public testing::Test { | 169 class It2MeNativeMessagingHostTest : public testing::Test { |
167 public: | 170 public: |
168 It2MeNativeMessagingHostTest() {} | 171 It2MeNativeMessagingHostTest() {} |
169 virtual ~It2MeNativeMessagingHostTest() {} | 172 virtual ~It2MeNativeMessagingHostTest() {} |
(...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
433 scoped_ptr<It2MeHostFactory> factory(new MockIt2MeHostFactory()); | 436 scoped_ptr<It2MeHostFactory> factory(new MockIt2MeHostFactory()); |
434 | 437 |
435 pipe_.reset(new NativeMessagingPipe()); | 438 pipe_.reset(new NativeMessagingPipe()); |
436 | 439 |
437 scoped_ptr<extensions::NativeMessagingChannel> channel( | 440 scoped_ptr<extensions::NativeMessagingChannel> channel( |
438 new PipeMessagingChannel(input_read_file.Pass(), | 441 new PipeMessagingChannel(input_read_file.Pass(), |
439 output_write_file.Pass())); | 442 output_write_file.Pass())); |
440 | 443 |
441 scoped_ptr<extensions::NativeMessageHost> it2me_host( | 444 scoped_ptr<extensions::NativeMessageHost> it2me_host( |
442 new It2MeNativeMessagingHost( | 445 new It2MeNativeMessagingHost( |
443 host_task_runner_, | 446 new ChromotingHostContextImpl(host_task_runner_.get()), |
444 factory.Pass())); | 447 factory.Pass())); |
445 it2me_host->Start(pipe_.get()); | 448 it2me_host->Start(pipe_.get()); |
446 | 449 |
447 pipe_->Start(it2me_host.Pass(), | 450 pipe_->Start(it2me_host.Pass(), |
448 channel.Pass(), | 451 channel.Pass(), |
449 base::Bind(&It2MeNativeMessagingHostTest::StopHost, | 452 base::Bind(&It2MeNativeMessagingHostTest::StopHost, |
450 base::Unretained(this))); | 453 base::Unretained(this))); |
451 | 454 |
452 // Notify the test that the host has finished starting up. | 455 // Notify the test that the host has finished starting up. |
453 test_message_loop_->message_loop_proxy()->PostTask( | 456 test_message_loop_->message_loop_proxy()->PostTask( |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
554 | 557 |
555 // Verify rejection if type is unrecognized. | 558 // Verify rejection if type is unrecognized. |
556 TEST_F(It2MeNativeMessagingHostTest, InvalidType) { | 559 TEST_F(It2MeNativeMessagingHostTest, InvalidType) { |
557 base::DictionaryValue message; | 560 base::DictionaryValue message; |
558 message.SetString("type", "xxx"); | 561 message.SetString("type", "xxx"); |
559 TestBadRequest(message, true); | 562 TestBadRequest(message, true); |
560 } | 563 } |
561 | 564 |
562 } // namespace remoting | 565 } // namespace remoting |
563 | 566 |
OLD | NEW |