| 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_channel.h" | 20 #include "remoting/host/native_messaging/pipe_messaging_channel.h" |
| 21 #include "remoting/host/setup/test_util.h" | 21 #include "remoting/host/setup/test_util.h" |
| 22 #include "testing/gtest/include/gtest/gtest.h" | 22 #include "testing/gtest/include/gtest/gtest.h" |
| 23 | 23 |
| 24 namespace remoting { | 24 namespace remoting { |
| 25 | 25 |
| 26 namespace { | 26 namespace { |
| 27 | 27 |
| 28 const char kTestAccessCode[] = "888888"; | 28 const char kTestAccessCode[] = "888888"; |
| 29 const int kTestAccessCodeLifetimeInSeconds = 666; | 29 const int kTestAccessCodeLifetimeInSeconds = 666; |
| 30 const char kTestClientUsername[] = "some_user@gmail.com"; | 30 const char kTestClientUsername[] = "some_user@gmail.com"; |
| (...skipping 393 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 424 | 424 |
| 425 base::File input_read_file; | 425 base::File input_read_file; |
| 426 base::File output_write_file; | 426 base::File output_write_file; |
| 427 | 427 |
| 428 ASSERT_TRUE(MakePipe(&input_read_file, &input_write_file_)); | 428 ASSERT_TRUE(MakePipe(&input_read_file, &input_write_file_)); |
| 429 ASSERT_TRUE(MakePipe(&output_read_file_, &output_write_file)); | 429 ASSERT_TRUE(MakePipe(&output_read_file_, &output_write_file)); |
| 430 | 430 |
| 431 // Creating a native messaging host with a mock It2MeHostFactory. | 431 // Creating a native messaging host with a mock It2MeHostFactory. |
| 432 scoped_ptr<It2MeHostFactory> factory(new MockIt2MeHostFactory()); | 432 scoped_ptr<It2MeHostFactory> factory(new MockIt2MeHostFactory()); |
| 433 | 433 |
| 434 scoped_ptr<NativeMessagingChannel> channel( | 434 scoped_ptr<extensions::NativeMessagingChannel> channel( |
| 435 new NativeMessagingChannel(input_read_file.Pass(), | 435 new PipeMessagingChannel(input_read_file.Pass(), |
| 436 output_write_file.Pass())); | 436 output_write_file.Pass())); |
| 437 | 437 |
| 438 host_.reset( | 438 host_.reset(new It2MeNativeMessagingHost( |
| 439 new It2MeNativeMessagingHost( | 439 host_task_runner_, |
| 440 host_task_runner_, channel.Pass(), factory.Pass())); | 440 channel.Pass(), |
| 441 factory.Pass())); |
| 441 host_->Start(base::Bind(&It2MeNativeMessagingHostTest::StopHost, | 442 host_->Start(base::Bind(&It2MeNativeMessagingHostTest::StopHost, |
| 442 base::Unretained(this))); | 443 base::Unretained(this))); |
| 443 | 444 |
| 444 // Notify the test that the host has finished starting up. | 445 // Notify the test that the host has finished starting up. |
| 445 test_message_loop_->message_loop_proxy()->PostTask( | 446 test_message_loop_->message_loop_proxy()->PostTask( |
| 446 FROM_HERE, test_run_loop_->QuitClosure()); | 447 FROM_HERE, test_run_loop_->QuitClosure()); |
| 447 } | 448 } |
| 448 | 449 |
| 449 void It2MeNativeMessagingHostTest::StopHost() { | 450 void It2MeNativeMessagingHostTest::StopHost() { |
| 450 DCHECK(host_task_runner_->RunsTasksOnCurrentThread()); | 451 DCHECK(host_task_runner_->RunsTasksOnCurrentThread()); |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 546 | 547 |
| 547 // Verify rejection if type is unrecognized. | 548 // Verify rejection if type is unrecognized. |
| 548 TEST_F(It2MeNativeMessagingHostTest, InvalidType) { | 549 TEST_F(It2MeNativeMessagingHostTest, InvalidType) { |
| 549 base::DictionaryValue message; | 550 base::DictionaryValue message; |
| 550 message.SetString("type", "xxx"); | 551 message.SetString("type", "xxx"); |
| 551 TestBadRequest(message, true); | 552 TestBadRequest(message, true); |
| 552 } | 553 } |
| 553 | 554 |
| 554 } // namespace remoting | 555 } // namespace remoting |
| 555 | 556 |
| OLD | NEW |