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_message_handler.h" | 5 #include "remoting/host/security_key/security_key_message_handler.h" |
6 | 6 |
7 #include <memory> | 7 #include <memory> |
8 #include <string> | 8 #include <string> |
9 #include <utility> | 9 #include <utility> |
10 | 10 |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
109 SecurityKeyMessageType message_type, | 109 SecurityKeyMessageType message_type, |
110 const std::string& message_payload) { | 110 const std::string& message_payload) { |
111 last_message_type_received_ = message_type; | 111 last_message_type_received_ = message_type; |
112 last_message_payload_received_ = message_payload; | 112 last_message_payload_received_ = message_payload; |
113 | 113 |
114 OperationComplete(); | 114 OperationComplete(); |
115 } | 115 } |
116 | 116 |
117 TEST_F(SecurityKeyMessageHandlerTest, | 117 TEST_F(SecurityKeyMessageHandlerTest, |
118 ProcessConnectMessage_SessionExists_ConnectionAttemptSuccess) { | 118 ProcessConnectMessage_SessionExists_ConnectionAttemptSuccess) { |
119 ipc_client_weak_ptr_->set_wait_for_ipc_channel_return_value(true); | 119 ipc_client_weak_ptr_->set_check_for_ipc_channel_return_value(true); |
120 ipc_client_weak_ptr_->set_establish_ipc_connection_should_succeed(true); | 120 ipc_client_weak_ptr_->set_establish_ipc_connection_should_succeed(true); |
121 | 121 |
122 reader_weak_ptr_->message_callback().Run( | 122 reader_weak_ptr_->message_callback().Run( |
123 SecurityKeyMessage::CreateMessageForTest(SecurityKeyMessageType::CONNECT, | 123 SecurityKeyMessage::CreateMessageForTest(SecurityKeyMessageType::CONNECT, |
124 std::string())); | 124 std::string())); |
125 WaitForOperationComplete(); | 125 WaitForOperationComplete(); |
126 | 126 |
127 ASSERT_EQ(SecurityKeyMessageType::CONNECT_RESPONSE, | 127 ASSERT_EQ(SecurityKeyMessageType::CONNECT_RESPONSE, |
128 writer_weak_ptr_->last_message_type()); | 128 writer_weak_ptr_->last_message_type()); |
129 ASSERT_EQ(std::string(1, kConnectResponseActiveSession), | 129 ASSERT_EQ(std::string(1, kConnectResponseActiveSession), |
130 writer_weak_ptr_->last_message_payload()); | 130 writer_weak_ptr_->last_message_payload()); |
131 } | 131 } |
132 | 132 |
133 TEST_F(SecurityKeyMessageHandlerTest, | 133 TEST_F(SecurityKeyMessageHandlerTest, |
134 ProcessConnectMessage_SessionExists_WriteFails) { | 134 ProcessConnectMessage_SessionExists_WriteFails) { |
135 ipc_client_weak_ptr_->set_wait_for_ipc_channel_return_value(true); | 135 ipc_client_weak_ptr_->set_check_for_ipc_channel_return_value(true); |
136 ipc_client_weak_ptr_->set_establish_ipc_connection_should_succeed(true); | 136 ipc_client_weak_ptr_->set_establish_ipc_connection_should_succeed(true); |
137 writer_weak_ptr_->set_write_request_succeeded(/*should_succeed=*/false); | 137 writer_weak_ptr_->set_write_request_succeeded(/*should_succeed=*/false); |
138 | 138 |
139 reader_weak_ptr_->message_callback().Run( | 139 reader_weak_ptr_->message_callback().Run( |
140 SecurityKeyMessage::CreateMessageForTest(SecurityKeyMessageType::CONNECT, | 140 SecurityKeyMessage::CreateMessageForTest(SecurityKeyMessageType::CONNECT, |
141 std::string())); | 141 std::string())); |
142 WaitForOperationComplete(); | 142 WaitForOperationComplete(); |
143 | 143 |
144 ASSERT_FALSE(ipc_client_weak_ptr_.get()); | 144 ASSERT_FALSE(ipc_client_weak_ptr_.get()); |
145 ASSERT_FALSE(reader_weak_ptr_.get()); | 145 ASSERT_FALSE(reader_weak_ptr_.get()); |
146 ASSERT_FALSE(writer_weak_ptr_.get()); | 146 ASSERT_FALSE(writer_weak_ptr_.get()); |
147 } | 147 } |
148 | 148 |
149 TEST_F(SecurityKeyMessageHandlerTest, | 149 TEST_F(SecurityKeyMessageHandlerTest, |
150 ProcessConnectMessage_SessionExists_ConnectionAttemptFailure) { | 150 ProcessConnectMessage_SessionExists_ConnectionAttemptFailure) { |
151 ipc_client_weak_ptr_->set_wait_for_ipc_channel_return_value(true); | 151 ipc_client_weak_ptr_->set_check_for_ipc_channel_return_value(true); |
152 ipc_client_weak_ptr_->set_establish_ipc_connection_should_succeed(false); | 152 ipc_client_weak_ptr_->set_establish_ipc_connection_should_succeed(false); |
153 | 153 |
154 reader_weak_ptr_->message_callback().Run( | 154 reader_weak_ptr_->message_callback().Run( |
155 SecurityKeyMessage::CreateMessageForTest(SecurityKeyMessageType::CONNECT, | 155 SecurityKeyMessage::CreateMessageForTest(SecurityKeyMessageType::CONNECT, |
156 std::string())); | 156 std::string())); |
157 WaitForOperationComplete(); | 157 WaitForOperationComplete(); |
158 | 158 |
159 ASSERT_EQ(SecurityKeyMessageType::CONNECT_ERROR, | 159 ASSERT_EQ(SecurityKeyMessageType::CONNECT_ERROR, |
160 writer_weak_ptr_->last_message_type()); | 160 writer_weak_ptr_->last_message_type()); |
161 ASSERT_FALSE(writer_weak_ptr_->last_message_payload().empty()); | 161 ASSERT_FALSE(writer_weak_ptr_->last_message_payload().empty()); |
162 } | 162 } |
163 | 163 |
164 TEST_F(SecurityKeyMessageHandlerTest, ProcessConnectMessage_NoSessionExists) { | 164 TEST_F(SecurityKeyMessageHandlerTest, ProcessConnectMessage_NoSessionExists) { |
165 ipc_client_weak_ptr_->set_wait_for_ipc_channel_return_value(false); | 165 ipc_client_weak_ptr_->set_check_for_ipc_channel_return_value(false); |
166 ipc_client_weak_ptr_->set_establish_ipc_connection_should_succeed(false); | 166 ipc_client_weak_ptr_->set_establish_ipc_connection_should_succeed(false); |
167 | 167 |
168 reader_weak_ptr_->message_callback().Run( | 168 reader_weak_ptr_->message_callback().Run( |
169 SecurityKeyMessage::CreateMessageForTest(SecurityKeyMessageType::CONNECT, | 169 SecurityKeyMessage::CreateMessageForTest(SecurityKeyMessageType::CONNECT, |
170 std::string())); | 170 std::string())); |
171 WaitForOperationComplete(); | 171 WaitForOperationComplete(); |
172 | 172 |
173 ASSERT_EQ(SecurityKeyMessageType::CONNECT_RESPONSE, | 173 ASSERT_EQ(SecurityKeyMessageType::CONNECT_RESPONSE, |
174 writer_weak_ptr_->last_message_type()); | 174 writer_weak_ptr_->last_message_type()); |
175 ASSERT_EQ(std::string(1, kConnectResponseNoSession), | 175 ASSERT_EQ(std::string(1, kConnectResponseNoSession), |
176 writer_weak_ptr_->last_message_payload()); | 176 writer_weak_ptr_->last_message_payload()); |
177 } | 177 } |
178 | 178 |
179 TEST_F(SecurityKeyMessageHandlerTest, ProcessConnectMessage_IncorrectPayload) { | 179 TEST_F(SecurityKeyMessageHandlerTest, ProcessConnectMessage_IncorrectPayload) { |
180 ipc_client_weak_ptr_->set_wait_for_ipc_channel_return_value(true); | 180 ipc_client_weak_ptr_->set_check_for_ipc_channel_return_value(true); |
181 ipc_client_weak_ptr_->set_establish_ipc_connection_should_succeed(false); | 181 ipc_client_weak_ptr_->set_establish_ipc_connection_should_succeed(false); |
182 | 182 |
183 reader_weak_ptr_->message_callback().Run( | 183 reader_weak_ptr_->message_callback().Run( |
184 SecurityKeyMessage::CreateMessageForTest(SecurityKeyMessageType::CONNECT, | 184 SecurityKeyMessage::CreateMessageForTest(SecurityKeyMessageType::CONNECT, |
185 "Invalid request payload")); | 185 "Invalid request payload")); |
186 WaitForOperationComplete(); | 186 WaitForOperationComplete(); |
187 | 187 |
188 ASSERT_EQ(SecurityKeyMessageType::CONNECT_ERROR, | 188 ASSERT_EQ(SecurityKeyMessageType::CONNECT_ERROR, |
189 writer_weak_ptr_->last_message_type()); | 189 writer_weak_ptr_->last_message_type()); |
190 ASSERT_FALSE(writer_weak_ptr_->last_message_payload().empty()); | 190 ASSERT_FALSE(writer_weak_ptr_->last_message_payload().empty()); |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
290 reader_weak_ptr_->message_callback().Run( | 290 reader_weak_ptr_->message_callback().Run( |
291 SecurityKeyMessage::CreateMessageForTest( | 291 SecurityKeyMessage::CreateMessageForTest( |
292 SecurityKeyMessageType::UNKNOWN_ERROR, std::string())); | 292 SecurityKeyMessageType::UNKNOWN_ERROR, std::string())); |
293 WaitForOperationComplete(); | 293 WaitForOperationComplete(); |
294 | 294 |
295 ASSERT_EQ(SecurityKeyMessageType::UNKNOWN_COMMAND, | 295 ASSERT_EQ(SecurityKeyMessageType::UNKNOWN_COMMAND, |
296 writer_weak_ptr_->last_message_type()); | 296 writer_weak_ptr_->last_message_type()); |
297 } | 297 } |
298 | 298 |
299 } // namespace remoting | 299 } // namespace remoting |
OLD | NEW |