OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/security_key/security_key_ipc_server.h" | 5 #include "remoting/host/security_key/security_key_ipc_server.h" |
6 | 6 |
7 #include <memory> | 7 #include <memory> |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
11 #include "base/bind_helpers.h" | 11 #include "base/bind_helpers.h" |
12 #include "base/callback.h" | 12 #include "base/callback.h" |
13 #include "base/macros.h" | 13 #include "base/macros.h" |
14 #include "base/message_loop/message_loop.h" | 14 #include "base/message_loop/message_loop.h" |
15 #include "base/run_loop.h" | 15 #include "base/run_loop.h" |
16 #include "ipc/ipc_channel.h" | 16 #include "ipc/ipc_channel.h" |
17 #include "mojo/edk/embedder/embedder.h" | 17 #include "mojo/edk/embedder/embedder.h" |
18 #include "mojo/edk/embedder/named_platform_handle_utils.h" | 18 #include "mojo/edk/embedder/named_platform_handle_utils.h" |
19 #include "mojo/edk/test/scoped_ipc_support.h" | 19 #include "mojo/edk/embedder/scoped_ipc_support.h" |
20 #include "remoting/host/client_session_details.h" | 20 #include "remoting/host/client_session_details.h" |
21 #include "remoting/host/security_key/fake_security_key_ipc_client.h" | 21 #include "remoting/host/security_key/fake_security_key_ipc_client.h" |
22 #include "remoting/host/security_key/security_key_ipc_constants.h" | 22 #include "remoting/host/security_key/security_key_ipc_constants.h" |
23 #include "testing/gtest/include/gtest/gtest.h" | 23 #include "testing/gtest/include/gtest/gtest.h" |
24 | 24 |
25 namespace { | 25 namespace { |
26 const int kTestConnectionId = 42; | 26 const int kTestConnectionId = 42; |
27 const int kInitialConnectTimeoutMs = 250; | 27 const int kInitialConnectTimeoutMs = 250; |
28 const int kConnectionTimeoutErrorDeltaMs = 100; | 28 const int kConnectionTimeoutErrorDeltaMs = 100; |
29 const int kLargeMessageSizeBytes = 256 * 1024; | 29 const int kLargeMessageSizeBytes = 256 * 1024; |
(...skipping 22 matching lines...) Expand all Loading... |
52 // Waits until the current |run_loop_| instance is signaled, then resets it. | 52 // Waits until the current |run_loop_| instance is signaled, then resets it. |
53 void WaitForOperationComplete(); | 53 void WaitForOperationComplete(); |
54 | 54 |
55 // ClientSessionControl overrides: | 55 // ClientSessionControl overrides: |
56 ClientSessionControl* session_control() override { return nullptr; } | 56 ClientSessionControl* session_control() override { return nullptr; } |
57 uint32_t desktop_session_id() const override { return peer_session_id_; } | 57 uint32_t desktop_session_id() const override { return peer_session_id_; } |
58 | 58 |
59 // IPC tests require a valid MessageLoop to run. | 59 // IPC tests require a valid MessageLoop to run. |
60 base::MessageLoopForIO message_loop_; | 60 base::MessageLoopForIO message_loop_; |
61 | 61 |
62 mojo::edk::test::ScopedIPCSupport ipc_support_; | 62 mojo::edk::ScopedIPCSupport ipc_support_; |
63 | 63 |
64 // Used to allow |message_loop_| to run during tests. The instance is reset | 64 // Used to allow |message_loop_| to run during tests. The instance is reset |
65 // after each stage of the tests has been completed. | 65 // after each stage of the tests has been completed. |
66 std::unique_ptr<base::RunLoop> run_loop_; | 66 std::unique_ptr<base::RunLoop> run_loop_; |
67 | 67 |
68 // The object under test. | 68 // The object under test. |
69 std::unique_ptr<SecurityKeyIpcServer> security_key_ipc_server_; | 69 std::unique_ptr<SecurityKeyIpcServer> security_key_ipc_server_; |
70 | 70 |
71 // Used to validate the object under test uses the correct ID when | 71 // Used to validate the object under test uses the correct ID when |
72 // communicating over the IPC channel. | 72 // communicating over the IPC channel. |
73 int last_connection_id_received_ = -1; | 73 int last_connection_id_received_ = -1; |
74 | 74 |
75 // Stores the contents of the last IPC message received for validation. | 75 // Stores the contents of the last IPC message received for validation. |
76 std::string last_message_received_; | 76 std::string last_message_received_; |
77 | 77 |
78 uint32_t peer_session_id_ = UINT32_MAX; | 78 uint32_t peer_session_id_ = UINT32_MAX; |
79 | 79 |
80 private: | 80 private: |
81 DISALLOW_COPY_AND_ASSIGN(SecurityKeyIpcServerTest); | 81 DISALLOW_COPY_AND_ASSIGN(SecurityKeyIpcServerTest); |
82 }; | 82 }; |
83 | 83 |
84 SecurityKeyIpcServerTest::SecurityKeyIpcServerTest() | 84 SecurityKeyIpcServerTest::SecurityKeyIpcServerTest() |
85 : ipc_support_(message_loop_.task_runner()), | 85 : ipc_support_(message_loop_.task_runner(), |
| 86 mojo::edk::ScopedIPCSupport::ShutdownPolicy::FAST), |
86 run_loop_(new base::RunLoop()) { | 87 run_loop_(new base::RunLoop()) { |
87 #if defined(OS_WIN) | 88 #if defined(OS_WIN) |
88 EXPECT_TRUE(ProcessIdToSessionId( | 89 EXPECT_TRUE(ProcessIdToSessionId( |
89 GetCurrentProcessId(), reinterpret_cast<DWORD*>(&peer_session_id_))); | 90 GetCurrentProcessId(), reinterpret_cast<DWORD*>(&peer_session_id_))); |
90 #endif // defined(OS_WIN) | 91 #endif // defined(OS_WIN) |
91 | 92 |
92 security_key_ipc_server_ = remoting::SecurityKeyIpcServer::Create( | 93 security_key_ipc_server_ = remoting::SecurityKeyIpcServer::Create( |
93 kTestConnectionId, this, | 94 kTestConnectionId, this, |
94 base::TimeDelta::FromMilliseconds(kInitialConnectTimeoutMs), | 95 base::TimeDelta::FromMilliseconds(kInitialConnectTimeoutMs), |
95 base::Bind(&SecurityKeyIpcServerTest::SendRequestToClient, | 96 base::Bind(&SecurityKeyIpcServerTest::SendRequestToClient, |
(...skipping 400 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
496 WaitForOperationComplete(); | 497 WaitForOperationComplete(); |
497 | 498 |
498 // Verify the connection failed. | 499 // Verify the connection failed. |
499 ASSERT_TRUE(fake_ipc_client.invalid_session_error()); | 500 ASSERT_TRUE(fake_ipc_client.invalid_session_error()); |
500 ASSERT_FALSE(fake_ipc_client.connection_ready()); | 501 ASSERT_FALSE(fake_ipc_client.connection_ready()); |
501 ASSERT_FALSE(fake_ipc_client.ipc_channel_connected()); | 502 ASSERT_FALSE(fake_ipc_client.ipc_channel_connected()); |
502 } | 503 } |
503 #endif // defined(OS_WIN) | 504 #endif // defined(OS_WIN) |
504 | 505 |
505 } // namespace remoting | 506 } // namespace remoting |
OLD | NEW |