| 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/setup/me2me_native_messaging_host.h" | 5 #include "remoting/host/setup/me2me_native_messaging_host.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include <stdint.h> | |
| 9 | 8 |
| 9 #include <cstdint> |
| 10 #include <memory> |
| 11 #include <string> |
| 10 #include <utility> | 12 #include <utility> |
| 11 | 13 |
| 12 #include "base/compiler_specific.h" | 14 #include "base/compiler_specific.h" |
| 13 #include "base/json/json_reader.h" | 15 #include "base/json/json_reader.h" |
| 14 #include "base/json/json_writer.h" | 16 #include "base/json/json_writer.h" |
| 15 #include "base/macros.h" | 17 #include "base/macros.h" |
| 16 #include "base/memory/ptr_util.h" | 18 #include "base/memory/ptr_util.h" |
| 17 #include "base/message_loop/message_loop.h" | 19 #include "base/message_loop/message_loop.h" |
| 18 #include "base/run_loop.h" | 20 #include "base/run_loop.h" |
| 19 #include "base/stl_util.h" | 21 #include "base/stl_util.h" |
| 20 #include "base/strings/stringize_macros.h" | 22 #include "base/strings/stringize_macros.h" |
| 21 #include "base/values.h" | 23 #include "base/values.h" |
| 22 #include "google_apis/gaia/gaia_oauth_client.h" | 24 #include "google_apis/gaia/gaia_oauth_client.h" |
| 23 #include "net/base/file_stream.h" | 25 #include "net/base/file_stream.h" |
| 24 #include "net/base/network_interfaces.h" | 26 #include "net/base/network_interfaces.h" |
| 25 #include "remoting/base/auto_thread_task_runner.h" | 27 #include "remoting/base/auto_thread_task_runner.h" |
| 28 #include "remoting/host/chromoting_host_context.h" |
| 26 #include "remoting/host/native_messaging/log_message_handler.h" | 29 #include "remoting/host/native_messaging/log_message_handler.h" |
| 30 #include "remoting/host/native_messaging/native_messaging_pipe.h" |
| 27 #include "remoting/host/native_messaging/pipe_messaging_channel.h" | 31 #include "remoting/host/native_messaging/pipe_messaging_channel.h" |
| 28 #include "remoting/host/pin_hash.h" | 32 #include "remoting/host/pin_hash.h" |
| 29 #include "remoting/host/setup/mock_oauth_client.h" | 33 #include "remoting/host/setup/mock_oauth_client.h" |
| 30 #include "remoting/host/setup/test_util.h" | 34 #include "remoting/host/setup/test_util.h" |
| 31 #include "remoting/protocol/pairing_registry.h" | 35 #include "remoting/protocol/pairing_registry.h" |
| 32 #include "remoting/protocol/protocol_mock_objects.h" | 36 #include "remoting/protocol/protocol_mock_objects.h" |
| 33 #include "testing/gtest/include/gtest/gtest.h" | 37 #include "testing/gtest/include/gtest/gtest.h" |
| 34 | 38 |
| 35 using remoting::protocol::MockPairingRegistryDelegate; | 39 using remoting::protocol::MockPairingRegistryDelegate; |
| 36 using remoting::protocol::PairingRegistry; | 40 using remoting::protocol::PairingRegistry; |
| (...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 272 | 276 |
| 273 // Message loop of the test thread. | 277 // Message loop of the test thread. |
| 274 std::unique_ptr<base::MessageLoop> test_message_loop_; | 278 std::unique_ptr<base::MessageLoop> test_message_loop_; |
| 275 std::unique_ptr<base::RunLoop> test_run_loop_; | 279 std::unique_ptr<base::RunLoop> test_run_loop_; |
| 276 | 280 |
| 277 std::unique_ptr<base::Thread> host_thread_; | 281 std::unique_ptr<base::Thread> host_thread_; |
| 278 std::unique_ptr<base::RunLoop> host_run_loop_; | 282 std::unique_ptr<base::RunLoop> host_run_loop_; |
| 279 | 283 |
| 280 // Task runner of the host thread. | 284 // Task runner of the host thread. |
| 281 scoped_refptr<AutoThreadTaskRunner> host_task_runner_; | 285 scoped_refptr<AutoThreadTaskRunner> host_task_runner_; |
| 282 std::unique_ptr<remoting::Me2MeNativeMessagingHost> host_; | 286 std::unique_ptr<NativeMessagingPipe> native_messaging_pipe_; |
| 283 | 287 |
| 284 DISALLOW_COPY_AND_ASSIGN(Me2MeNativeMessagingHostTest); | 288 DISALLOW_COPY_AND_ASSIGN(Me2MeNativeMessagingHostTest); |
| 285 }; | 289 }; |
| 286 | 290 |
| 287 Me2MeNativeMessagingHostTest::Me2MeNativeMessagingHostTest() {} | 291 Me2MeNativeMessagingHostTest::Me2MeNativeMessagingHostTest() {} |
| 288 | 292 |
| 289 Me2MeNativeMessagingHostTest::~Me2MeNativeMessagingHostTest() {} | 293 Me2MeNativeMessagingHostTest::~Me2MeNativeMessagingHostTest() {} |
| 290 | 294 |
| 291 void Me2MeNativeMessagingHostTest::SetUp() { | 295 void Me2MeNativeMessagingHostTest::SetUp() { |
| 292 base::File input_read_file; | 296 base::File input_read_file; |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 327 ASSERT_TRUE(MakePipe(&output_read_file_, &output_write_file)); | 331 ASSERT_TRUE(MakePipe(&output_read_file_, &output_write_file)); |
| 328 | 332 |
| 329 daemon_controller_delegate_ = new MockDaemonControllerDelegate(); | 333 daemon_controller_delegate_ = new MockDaemonControllerDelegate(); |
| 330 scoped_refptr<DaemonController> daemon_controller( | 334 scoped_refptr<DaemonController> daemon_controller( |
| 331 new DaemonController(base::WrapUnique(daemon_controller_delegate_))); | 335 new DaemonController(base::WrapUnique(daemon_controller_delegate_))); |
| 332 | 336 |
| 333 scoped_refptr<PairingRegistry> pairing_registry = | 337 scoped_refptr<PairingRegistry> pairing_registry = |
| 334 new SynchronousPairingRegistry( | 338 new SynchronousPairingRegistry( |
| 335 base::WrapUnique(new MockPairingRegistryDelegate())); | 339 base::WrapUnique(new MockPairingRegistryDelegate())); |
| 336 | 340 |
| 341 native_messaging_pipe_.reset(new NativeMessagingPipe()); |
| 342 |
| 337 std::unique_ptr<extensions::NativeMessagingChannel> channel( | 343 std::unique_ptr<extensions::NativeMessagingChannel> channel( |
| 338 new PipeMessagingChannel(std::move(input_read_file), | 344 new PipeMessagingChannel(std::move(input_read_file), |
| 339 std::move(output_write_file))); | 345 std::move(output_write_file))); |
| 340 | 346 |
| 341 std::unique_ptr<OAuthClient> oauth_client( | 347 std::unique_ptr<OAuthClient> oauth_client( |
| 342 new MockOAuthClient("fake_user_email", "fake_refresh_token")); | 348 new MockOAuthClient("fake_user_email", "fake_refresh_token")); |
| 343 | 349 |
| 344 host_.reset(new Me2MeNativeMessagingHost(false, 0, std::move(channel), | 350 std::unique_ptr<ChromotingHostContext> context = |
| 345 daemon_controller, pairing_registry, | 351 ChromotingHostContext::Create(new remoting::AutoThreadTaskRunner( |
| 346 std::move(oauth_client))); | 352 host_task_runner_, base::Bind(&Me2MeNativeMessagingHostTest::StopHost, |
| 347 host_->Start(base::Bind(&Me2MeNativeMessagingHostTest::StopHost, | 353 base::Unretained(this)))); |
| 348 base::Unretained(this))); | 354 |
| 355 std::unique_ptr<remoting::Me2MeNativeMessagingHost> host( |
| 356 new Me2MeNativeMessagingHost(false, 0, std::move(context), |
| 357 daemon_controller, pairing_registry, |
| 358 std::move(oauth_client))); |
| 359 host->Start(native_messaging_pipe_.get()); |
| 360 |
| 361 native_messaging_pipe_->Start(std::move(host), std::move(channel)); |
| 349 | 362 |
| 350 // Notify the test that the host has finished starting up. | 363 // Notify the test that the host has finished starting up. |
| 351 test_message_loop_->task_runner()->PostTask( | 364 test_message_loop_->task_runner()->PostTask( |
| 352 FROM_HERE, test_run_loop_->QuitClosure()); | 365 FROM_HERE, test_run_loop_->QuitClosure()); |
| 353 } | 366 } |
| 354 | 367 |
| 355 void Me2MeNativeMessagingHostTest::StopHost() { | 368 void Me2MeNativeMessagingHostTest::StopHost() { |
| 356 DCHECK(host_task_runner_->RunsTasksOnCurrentThread()); | 369 DCHECK(host_task_runner_->RunsTasksOnCurrentThread()); |
| 357 | 370 |
| 358 host_.reset(); | 371 native_messaging_pipe_.reset(); |
| 359 | 372 |
| 360 // Wait till all shutdown tasks have completed. | 373 // Wait till all shutdown tasks have completed. |
| 361 base::RunLoop().RunUntilIdle(); | 374 base::RunLoop().RunUntilIdle(); |
| 362 | 375 |
| 363 // Trigger a test shutdown via ExitTest(). | 376 // Trigger a test shutdown via ExitTest(). |
| 364 host_task_runner_ = nullptr; | 377 host_task_runner_ = nullptr; |
| 365 } | 378 } |
| 366 | 379 |
| 367 void Me2MeNativeMessagingHostTest::ExitTest() { | 380 void Me2MeNativeMessagingHostTest::ExitTest() { |
| 368 if (!test_message_loop_->task_runner()->RunsTasksOnCurrentThread()) { | 381 if (!test_message_loop_->task_runner()->RunsTasksOnCurrentThread()) { |
| (...skipping 261 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 630 } | 643 } |
| 631 | 644 |
| 632 // Verify rejection if getCredentialsFromAuthCode has no auth code. | 645 // Verify rejection if getCredentialsFromAuthCode has no auth code. |
| 633 TEST_F(Me2MeNativeMessagingHostTest, GetCredentialsFromAuthCodeNoAuthCode) { | 646 TEST_F(Me2MeNativeMessagingHostTest, GetCredentialsFromAuthCodeNoAuthCode) { |
| 634 base::DictionaryValue message; | 647 base::DictionaryValue message; |
| 635 message.SetString("type", "getCredentialsFromAuthCode"); | 648 message.SetString("type", "getCredentialsFromAuthCode"); |
| 636 TestBadRequest(message); | 649 TestBadRequest(message); |
| 637 } | 650 } |
| 638 | 651 |
| 639 } // namespace remoting | 652 } // namespace remoting |
| OLD | NEW |