| 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> pipe_; |
| 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 pipe_.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> it2me_host( |
| 439 host_task_runner_, | 442 new It2MeNativeMessagingHost( |
| 440 channel.Pass(), | 443 host_task_runner_, |
| 441 factory.Pass())); | 444 factory.Pass())); |
| 442 host_->Start(base::Bind(&It2MeNativeMessagingHostTest::StopHost, | 445 it2me_host->set_client(pipe_->AsWeakPtr()); |
| 446 |
| 447 pipe_->Init(it2me_host.Pass(), channel.Pass()); |
| 448 pipe_->Start(base::Bind(&It2MeNativeMessagingHostTest::StopHost, |
| 443 base::Unretained(this))); | 449 base::Unretained(this))); |
| 444 | 450 |
| 445 // Notify the test that the host has finished starting up. | 451 // Notify the test that the host has finished starting up. |
| 446 test_message_loop_->message_loop_proxy()->PostTask( | 452 test_message_loop_->message_loop_proxy()->PostTask( |
| 447 FROM_HERE, test_run_loop_->QuitClosure()); | 453 FROM_HERE, test_run_loop_->QuitClosure()); |
| 448 } | 454 } |
| 449 | 455 |
| 450 void It2MeNativeMessagingHostTest::StopHost() { | 456 void It2MeNativeMessagingHostTest::StopHost() { |
| 451 DCHECK(host_task_runner_->RunsTasksOnCurrentThread()); | 457 DCHECK(host_task_runner_->RunsTasksOnCurrentThread()); |
| 452 | 458 |
| 453 host_.reset(); | 459 pipe_.reset(); |
| 454 | 460 |
| 455 // Wait till all shutdown tasks have completed. | 461 // Wait till all shutdown tasks have completed. |
| 456 base::RunLoop().RunUntilIdle(); | 462 base::RunLoop().RunUntilIdle(); |
| 457 | 463 |
| 458 // Trigger a test shutdown via ExitTest(). | 464 // Trigger a test shutdown via ExitTest(). |
| 459 host_task_runner_ = NULL; | 465 host_task_runner_ = NULL; |
| 460 } | 466 } |
| 461 | 467 |
| 462 void It2MeNativeMessagingHostTest::ExitTest() { | 468 void It2MeNativeMessagingHostTest::ExitTest() { |
| 463 if (!test_message_loop_->message_loop_proxy()->RunsTasksOnCurrentThread()) { | 469 if (!test_message_loop_->message_loop_proxy()->RunsTasksOnCurrentThread()) { |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 547 | 553 |
| 548 // Verify rejection if type is unrecognized. | 554 // Verify rejection if type is unrecognized. |
| 549 TEST_F(It2MeNativeMessagingHostTest, InvalidType) { | 555 TEST_F(It2MeNativeMessagingHostTest, InvalidType) { |
| 550 base::DictionaryValue message; | 556 base::DictionaryValue message; |
| 551 message.SetString("type", "xxx"); | 557 message.SetString("type", "xxx"); |
| 552 TestBadRequest(message, true); | 558 TestBadRequest(message, true); |
| 553 } | 559 } |
| 554 | 560 |
| 555 } // namespace remoting | 561 } // namespace remoting |
| 556 | 562 |
| OLD | NEW |