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/pipe_messaging_channel.h" | 21 #include "remoting/host/native_messaging/pipe_messaging_channel.h" |
21 #include "remoting/host/setup/test_util.h" | 22 #include "remoting/host/setup/test_util.h" |
22 #include "testing/gtest/include/gtest/gtest.h" | 23 #include "testing/gtest/include/gtest/gtest.h" |
23 | 24 |
24 namespace remoting { | 25 namespace remoting { |
25 | 26 |
26 namespace { | 27 namespace { |
27 | 28 |
28 const char kTestAccessCode[] = "888888"; | 29 const char kTestAccessCode[] = "888888"; |
29 const int kTestAccessCodeLifetimeInSeconds = 666; | 30 const int kTestAccessCodeLifetimeInSeconds = 666; |
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
202 | 203 |
203 // Message loop of the test thread. | 204 // Message loop of the test thread. |
204 scoped_ptr<base::MessageLoop> test_message_loop_; | 205 scoped_ptr<base::MessageLoop> test_message_loop_; |
205 scoped_ptr<base::RunLoop> test_run_loop_; | 206 scoped_ptr<base::RunLoop> test_run_loop_; |
206 | 207 |
207 scoped_ptr<base::Thread> host_thread_; | 208 scoped_ptr<base::Thread> host_thread_; |
208 scoped_ptr<base::RunLoop> host_run_loop_; | 209 scoped_ptr<base::RunLoop> host_run_loop_; |
209 | 210 |
210 // Task runner of the host thread. | 211 // Task runner of the host thread. |
211 scoped_refptr<AutoThreadTaskRunner> host_task_runner_; | 212 scoped_refptr<AutoThreadTaskRunner> host_task_runner_; |
212 scoped_ptr<remoting::It2MeNativeMessagingHost> host_; | 213 scoped_ptr<remoting::NativeMessagingPipe> host_; |
Sergey Ulanov
2014/09/27 00:24:10
rename this, e.g. pipe_?
kelvinp
2014/09/29 22:59:40
Done.
| |
213 | 214 |
214 DISALLOW_COPY_AND_ASSIGN(It2MeNativeMessagingHostTest); | 215 DISALLOW_COPY_AND_ASSIGN(It2MeNativeMessagingHostTest); |
215 }; | 216 }; |
216 | 217 |
217 void It2MeNativeMessagingHostTest::SetUp() { | 218 void It2MeNativeMessagingHostTest::SetUp() { |
218 test_message_loop_.reset(new base::MessageLoop()); | 219 test_message_loop_.reset(new base::MessageLoop()); |
219 test_run_loop_.reset(new base::RunLoop()); | 220 test_run_loop_.reset(new base::RunLoop()); |
220 | 221 |
221 // Run the host on a dedicated thread. | 222 // Run the host on a dedicated thread. |
222 host_thread_.reset(new base::Thread("host_thread")); | 223 host_thread_.reset(new base::Thread("host_thread")); |
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
424 | 425 |
425 base::File input_read_file; | 426 base::File input_read_file; |
426 base::File output_write_file; | 427 base::File output_write_file; |
427 | 428 |
428 ASSERT_TRUE(MakePipe(&input_read_file, &input_write_file_)); | 429 ASSERT_TRUE(MakePipe(&input_read_file, &input_write_file_)); |
429 ASSERT_TRUE(MakePipe(&output_read_file_, &output_write_file)); | 430 ASSERT_TRUE(MakePipe(&output_read_file_, &output_write_file)); |
430 | 431 |
431 // Creating a native messaging host with a mock It2MeHostFactory. | 432 // Creating a native messaging host with a mock It2MeHostFactory. |
432 scoped_ptr<It2MeHostFactory> factory(new MockIt2MeHostFactory()); | 433 scoped_ptr<It2MeHostFactory> factory(new MockIt2MeHostFactory()); |
433 | 434 |
435 host_.reset(new NativeMessagingPipe()); | |
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 host_.reset(new It2MeNativeMessagingHost( | 441 scoped_ptr<extensions::NativeMessageHost> it2meHost( |
Sergey Ulanov
2014/09/27 00:24:10
it2me_host
kelvinp
2014/09/29 22:59:40
Done.
| |
439 host_task_runner_, | 442 new It2MeNativeMessagingHost( |
440 channel.Pass(), | 443 host_task_runner_, |
441 factory.Pass())); | 444 factory.Pass())); |
445 it2meHost->set_client(host_->AsWeakPtr()); | |
446 | |
442 host_->Start(base::Bind(&It2MeNativeMessagingHostTest::StopHost, | 447 host_->Start(base::Bind(&It2MeNativeMessagingHostTest::StopHost, |
Sergey Ulanov
2014/09/27 00:24:10
I think you also want to call Init() here. (but it
kelvinp
2014/09/29 22:59:40
Good catch.
I think it is better to keep the const
| |
443 base::Unretained(this))); | 448 base::Unretained(this))); |
444 | 449 |
445 // Notify the test that the host has finished starting up. | 450 // Notify the test that the host has finished starting up. |
446 test_message_loop_->message_loop_proxy()->PostTask( | 451 test_message_loop_->message_loop_proxy()->PostTask( |
447 FROM_HERE, test_run_loop_->QuitClosure()); | 452 FROM_HERE, test_run_loop_->QuitClosure()); |
448 } | 453 } |
449 | 454 |
450 void It2MeNativeMessagingHostTest::StopHost() { | 455 void It2MeNativeMessagingHostTest::StopHost() { |
451 DCHECK(host_task_runner_->RunsTasksOnCurrentThread()); | 456 DCHECK(host_task_runner_->RunsTasksOnCurrentThread()); |
452 | 457 |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
547 | 552 |
548 // Verify rejection if type is unrecognized. | 553 // Verify rejection if type is unrecognized. |
549 TEST_F(It2MeNativeMessagingHostTest, InvalidType) { | 554 TEST_F(It2MeNativeMessagingHostTest, InvalidType) { |
550 base::DictionaryValue message; | 555 base::DictionaryValue message; |
551 message.SetString("type", "xxx"); | 556 message.SetString("type", "xxx"); |
552 TestBadRequest(message, true); | 557 TestBadRequest(message, true); |
553 } | 558 } |
554 | 559 |
555 } // namespace remoting | 560 } // namespace remoting |
556 | 561 |
OLD | NEW |