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/remote_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 |
11 #include "base/bind.h" | 11 #include "base/bind.h" |
12 #include "base/memory/weak_ptr.h" | 12 #include "base/memory/weak_ptr.h" |
13 #include "base/message_loop/message_loop.h" | 13 #include "base/message_loop/message_loop.h" |
14 #include "base/run_loop.h" | 14 #include "base/run_loop.h" |
15 #include "remoting/host/security_key/fake_remote_security_key_ipc_client.h" | 15 #include "remoting/host/security_key/fake_security_key_ipc_client.h" |
16 #include "remoting/host/security_key/fake_remote_security_key_message_reader.h" | 16 #include "remoting/host/security_key/fake_security_key_message_reader.h" |
17 #include "remoting/host/security_key/fake_remote_security_key_message_writer.h" | 17 #include "remoting/host/security_key/fake_security_key_message_writer.h" |
18 #include "remoting/host/security_key/remote_security_key_ipc_constants.h" | 18 #include "remoting/host/security_key/security_key_ipc_constants.h" |
19 #include "remoting/host/security_key/security_key_message.h" | 19 #include "remoting/host/security_key/security_key_message.h" |
20 #include "remoting/host/setup/test_util.h" | 20 #include "remoting/host/setup/test_util.h" |
21 #include "testing/gtest/include/gtest/gtest.h" | 21 #include "testing/gtest/include/gtest/gtest.h" |
22 | 22 |
23 namespace remoting { | 23 namespace remoting { |
24 | 24 |
25 class RemoteSecurityKeyMessageHandlerTest : public testing::Test { | 25 class SecurityKeyMessageHandlerTest : public testing::Test { |
26 public: | 26 public: |
27 RemoteSecurityKeyMessageHandlerTest(); | 27 SecurityKeyMessageHandlerTest(); |
28 ~RemoteSecurityKeyMessageHandlerTest() override; | 28 ~SecurityKeyMessageHandlerTest() override; |
29 | 29 |
30 // Passed to the object used for testing to be called back to signal | 30 // Passed to the object used for testing to be called back to signal |
31 // completion of an action. | 31 // completion of an action. |
32 void OperationComplete(); | 32 void OperationComplete(); |
33 | 33 |
34 protected: | 34 protected: |
35 // testing::Test interface. | 35 // testing::Test interface. |
36 void SetUp() override; | 36 void SetUp() override; |
37 | 37 |
38 // Waits until the current |run_loop_| instance is signaled, then resets it. | 38 // Waits until the current |run_loop_| instance is signaled, then resets it. |
39 void WaitForOperationComplete(); | 39 void WaitForOperationComplete(); |
40 | 40 |
41 // Passed to |message_channel_| and called back when a message is received. | 41 // Passed to |message_channel_| and called back when a message is received. |
42 void OnSecurityKeyMessage(RemoteSecurityKeyMessageType message_type, | 42 void OnSecurityKeyMessage(SecurityKeyMessageType message_type, |
43 const std::string& message_payload); | 43 const std::string& message_payload); |
44 | 44 |
45 bool last_operation_failed_ = false; | 45 bool last_operation_failed_ = false; |
46 RemoteSecurityKeyMessageType last_message_type_received_ = | 46 SecurityKeyMessageType last_message_type_received_ = |
47 RemoteSecurityKeyMessageType::INVALID; | 47 SecurityKeyMessageType::INVALID; |
48 std::string last_message_payload_received_; | 48 std::string last_message_payload_received_; |
49 | 49 |
50 base::WeakPtr<FakeRemoteSecurityKeyIpcClient> ipc_client_weak_ptr_; | 50 base::WeakPtr<FakeSecurityKeyIpcClient> ipc_client_weak_ptr_; |
51 base::WeakPtr<FakeRemoteSecurityKeyMessageReader> reader_weak_ptr_; | 51 base::WeakPtr<FakeSecurityKeyMessageReader> reader_weak_ptr_; |
52 base::WeakPtr<FakeRemoteSecurityKeyMessageWriter> writer_weak_ptr_; | 52 base::WeakPtr<FakeSecurityKeyMessageWriter> writer_weak_ptr_; |
53 std::unique_ptr<RemoteSecurityKeyMessageHandler> message_handler_; | 53 std::unique_ptr<SecurityKeyMessageHandler> message_handler_; |
54 | 54 |
55 private: | 55 private: |
56 base::MessageLoopForIO message_loop_; | 56 base::MessageLoopForIO message_loop_; |
57 std::unique_ptr<base::RunLoop> run_loop_; | 57 std::unique_ptr<base::RunLoop> run_loop_; |
58 | 58 |
59 DISALLOW_COPY_AND_ASSIGN(RemoteSecurityKeyMessageHandlerTest); | 59 DISALLOW_COPY_AND_ASSIGN(SecurityKeyMessageHandlerTest); |
60 }; | 60 }; |
61 | 61 |
62 RemoteSecurityKeyMessageHandlerTest::RemoteSecurityKeyMessageHandlerTest() {} | 62 SecurityKeyMessageHandlerTest::SecurityKeyMessageHandlerTest() {} |
63 | 63 |
64 RemoteSecurityKeyMessageHandlerTest::~RemoteSecurityKeyMessageHandlerTest() {} | 64 SecurityKeyMessageHandlerTest::~SecurityKeyMessageHandlerTest() {} |
65 | 65 |
66 void RemoteSecurityKeyMessageHandlerTest::OperationComplete() { | 66 void SecurityKeyMessageHandlerTest::OperationComplete() { |
67 run_loop_->Quit(); | 67 run_loop_->Quit(); |
68 } | 68 } |
69 | 69 |
70 void RemoteSecurityKeyMessageHandlerTest::SetUp() { | 70 void SecurityKeyMessageHandlerTest::SetUp() { |
71 run_loop_.reset(new base::RunLoop()); | 71 run_loop_.reset(new base::RunLoop()); |
72 message_handler_.reset(new RemoteSecurityKeyMessageHandler()); | 72 message_handler_.reset(new SecurityKeyMessageHandler()); |
73 | 73 |
74 std::unique_ptr<FakeRemoteSecurityKeyIpcClient> ipc_client( | 74 std::unique_ptr<FakeSecurityKeyIpcClient> ipc_client( |
75 new FakeRemoteSecurityKeyIpcClient( | 75 new FakeSecurityKeyIpcClient( |
76 base::Bind(&RemoteSecurityKeyMessageHandlerTest::OperationComplete, | 76 base::Bind(&SecurityKeyMessageHandlerTest::OperationComplete, |
77 base::Unretained(this)))); | 77 base::Unretained(this)))); |
78 ipc_client_weak_ptr_ = ipc_client->AsWeakPtr(); | 78 ipc_client_weak_ptr_ = ipc_client->AsWeakPtr(); |
79 | 79 |
80 std::unique_ptr<FakeRemoteSecurityKeyMessageReader> reader( | 80 std::unique_ptr<FakeSecurityKeyMessageReader> reader( |
81 new FakeRemoteSecurityKeyMessageReader()); | 81 new FakeSecurityKeyMessageReader()); |
82 reader_weak_ptr_ = reader->AsWeakPtr(); | 82 reader_weak_ptr_ = reader->AsWeakPtr(); |
83 | 83 |
84 std::unique_ptr<FakeRemoteSecurityKeyMessageWriter> writer( | 84 std::unique_ptr<FakeSecurityKeyMessageWriter> writer( |
85 new FakeRemoteSecurityKeyMessageWriter( | 85 new FakeSecurityKeyMessageWriter( |
86 base::Bind(&RemoteSecurityKeyMessageHandlerTest::OperationComplete, | 86 base::Bind(&SecurityKeyMessageHandlerTest::OperationComplete, |
87 base::Unretained(this)))); | 87 base::Unretained(this)))); |
88 writer_weak_ptr_ = writer->AsWeakPtr(); | 88 writer_weak_ptr_ = writer->AsWeakPtr(); |
89 | 89 |
90 message_handler_->SetRemoteSecurityKeyMessageReaderForTest(std::move(reader)); | 90 message_handler_->SetSecurityKeyMessageReaderForTest(std::move(reader)); |
91 | 91 |
92 message_handler_->SetRemoteSecurityKeyMessageWriterForTest(std::move(writer)); | 92 message_handler_->SetSecurityKeyMessageWriterForTest(std::move(writer)); |
93 | 93 |
94 base::File read_file; | 94 base::File read_file; |
95 base::File write_file; | 95 base::File write_file; |
96 ASSERT_TRUE(MakePipe(&read_file, &write_file)); | 96 ASSERT_TRUE(MakePipe(&read_file, &write_file)); |
97 message_handler_->Start( | 97 message_handler_->Start( |
98 std::move(read_file), std::move(write_file), std::move(ipc_client), | 98 std::move(read_file), std::move(write_file), std::move(ipc_client), |
99 base::Bind(&RemoteSecurityKeyMessageHandlerTest::OperationComplete, | 99 base::Bind(&SecurityKeyMessageHandlerTest::OperationComplete, |
100 base::Unretained(this))); | 100 base::Unretained(this))); |
101 } | 101 } |
102 | 102 |
103 void RemoteSecurityKeyMessageHandlerTest::WaitForOperationComplete() { | 103 void SecurityKeyMessageHandlerTest::WaitForOperationComplete() { |
104 run_loop_->Run(); | 104 run_loop_->Run(); |
105 run_loop_.reset(new base::RunLoop()); | 105 run_loop_.reset(new base::RunLoop()); |
106 } | 106 } |
107 | 107 |
108 void RemoteSecurityKeyMessageHandlerTest::OnSecurityKeyMessage( | 108 void SecurityKeyMessageHandlerTest::OnSecurityKeyMessage( |
109 RemoteSecurityKeyMessageType 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(RemoteSecurityKeyMessageHandlerTest, | 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_wait_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( | 123 SecurityKeyMessage::CreateMessageForTest(SecurityKeyMessageType::CONNECT, |
124 RemoteSecurityKeyMessageType::CONNECT, std::string())); | 124 std::string())); |
125 WaitForOperationComplete(); | 125 WaitForOperationComplete(); |
126 | 126 |
127 ASSERT_EQ(RemoteSecurityKeyMessageType::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(RemoteSecurityKeyMessageHandlerTest, | 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_wait_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( | 140 SecurityKeyMessage::CreateMessageForTest(SecurityKeyMessageType::CONNECT, |
141 RemoteSecurityKeyMessageType::CONNECT, 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(RemoteSecurityKeyMessageHandlerTest, | 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_wait_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( | 155 SecurityKeyMessage::CreateMessageForTest(SecurityKeyMessageType::CONNECT, |
156 RemoteSecurityKeyMessageType::CONNECT, std::string())); | 156 std::string())); |
157 WaitForOperationComplete(); | 157 WaitForOperationComplete(); |
158 | 158 |
159 ASSERT_EQ(RemoteSecurityKeyMessageType::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(RemoteSecurityKeyMessageHandlerTest, | 164 TEST_F(SecurityKeyMessageHandlerTest, ProcessConnectMessage_NoSessionExists) { |
165 ProcessConnectMessage_NoSessionExists) { | |
166 ipc_client_weak_ptr_->set_wait_for_ipc_channel_return_value(false); | 165 ipc_client_weak_ptr_->set_wait_for_ipc_channel_return_value(false); |
167 ipc_client_weak_ptr_->set_establish_ipc_connection_should_succeed(false); | 166 ipc_client_weak_ptr_->set_establish_ipc_connection_should_succeed(false); |
168 | 167 |
169 reader_weak_ptr_->message_callback().Run( | 168 reader_weak_ptr_->message_callback().Run( |
170 SecurityKeyMessage::CreateMessageForTest( | 169 SecurityKeyMessage::CreateMessageForTest(SecurityKeyMessageType::CONNECT, |
171 RemoteSecurityKeyMessageType::CONNECT, std::string())); | 170 std::string())); |
172 WaitForOperationComplete(); | 171 WaitForOperationComplete(); |
173 | 172 |
174 ASSERT_EQ(RemoteSecurityKeyMessageType::CONNECT_RESPONSE, | 173 ASSERT_EQ(SecurityKeyMessageType::CONNECT_RESPONSE, |
175 writer_weak_ptr_->last_message_type()); | 174 writer_weak_ptr_->last_message_type()); |
176 ASSERT_EQ(std::string(1, kConnectResponseNoSession), | 175 ASSERT_EQ(std::string(1, kConnectResponseNoSession), |
177 writer_weak_ptr_->last_message_payload()); | 176 writer_weak_ptr_->last_message_payload()); |
178 } | 177 } |
179 | 178 |
180 TEST_F(RemoteSecurityKeyMessageHandlerTest, | 179 TEST_F(SecurityKeyMessageHandlerTest, ProcessConnectMessage_IncorrectPayload) { |
181 ProcessConnectMessage_IncorrectPayload) { | |
182 ipc_client_weak_ptr_->set_wait_for_ipc_channel_return_value(true); | 180 ipc_client_weak_ptr_->set_wait_for_ipc_channel_return_value(true); |
183 ipc_client_weak_ptr_->set_establish_ipc_connection_should_succeed(false); | 181 ipc_client_weak_ptr_->set_establish_ipc_connection_should_succeed(false); |
184 | 182 |
185 reader_weak_ptr_->message_callback().Run( | 183 reader_weak_ptr_->message_callback().Run( |
186 SecurityKeyMessage::CreateMessageForTest( | 184 SecurityKeyMessage::CreateMessageForTest(SecurityKeyMessageType::CONNECT, |
187 RemoteSecurityKeyMessageType::CONNECT, "Invalid request payload")); | 185 "Invalid request payload")); |
188 WaitForOperationComplete(); | 186 WaitForOperationComplete(); |
189 | 187 |
190 ASSERT_EQ(RemoteSecurityKeyMessageType::CONNECT_ERROR, | 188 ASSERT_EQ(SecurityKeyMessageType::CONNECT_ERROR, |
191 writer_weak_ptr_->last_message_type()); | 189 writer_weak_ptr_->last_message_type()); |
192 ASSERT_FALSE(writer_weak_ptr_->last_message_payload().empty()); | 190 ASSERT_FALSE(writer_weak_ptr_->last_message_payload().empty()); |
193 } | 191 } |
194 | 192 |
195 TEST_F(RemoteSecurityKeyMessageHandlerTest, | 193 TEST_F(SecurityKeyMessageHandlerTest, |
196 ProcessRequestMessage_ValidPayload_IpcSendSuccess) { | 194 ProcessRequestMessage_ValidPayload_IpcSendSuccess) { |
197 std::string request_payload("I AM A VALID REQUEST PAYLOAD!"); | 195 std::string request_payload("I AM A VALID REQUEST PAYLOAD!"); |
198 std::string response_payload("I AM A VALID RESPONSE PAYLOAD!"); | 196 std::string response_payload("I AM A VALID RESPONSE PAYLOAD!"); |
199 ipc_client_weak_ptr_->set_send_security_request_should_succeed(true); | 197 ipc_client_weak_ptr_->set_send_security_request_should_succeed(true); |
200 ipc_client_weak_ptr_->set_security_key_response_payload(response_payload); | 198 ipc_client_weak_ptr_->set_security_key_response_payload(response_payload); |
201 | 199 |
202 reader_weak_ptr_->message_callback().Run( | 200 reader_weak_ptr_->message_callback().Run( |
203 SecurityKeyMessage::CreateMessageForTest( | 201 SecurityKeyMessage::CreateMessageForTest(SecurityKeyMessageType::REQUEST, |
204 RemoteSecurityKeyMessageType::REQUEST, request_payload)); | 202 request_payload)); |
205 WaitForOperationComplete(); | 203 WaitForOperationComplete(); |
206 | 204 |
207 ASSERT_EQ(RemoteSecurityKeyMessageType::REQUEST_RESPONSE, | 205 ASSERT_EQ(SecurityKeyMessageType::REQUEST_RESPONSE, |
208 writer_weak_ptr_->last_message_type()); | 206 writer_weak_ptr_->last_message_type()); |
209 ASSERT_EQ(response_payload, writer_weak_ptr_->last_message_payload()); | 207 ASSERT_EQ(response_payload, writer_weak_ptr_->last_message_payload()); |
210 } | 208 } |
211 | 209 |
212 TEST_F(RemoteSecurityKeyMessageHandlerTest, ProcessRequestMessage_WriteFails) { | 210 TEST_F(SecurityKeyMessageHandlerTest, ProcessRequestMessage_WriteFails) { |
213 std::string request_payload("I AM A VALID REQUEST PAYLOAD!"); | 211 std::string request_payload("I AM A VALID REQUEST PAYLOAD!"); |
214 std::string response_payload("I AM A VALID RESPONSE PAYLOAD!"); | 212 std::string response_payload("I AM A VALID RESPONSE PAYLOAD!"); |
215 | 213 |
216 ipc_client_weak_ptr_->set_send_security_request_should_succeed(true); | 214 ipc_client_weak_ptr_->set_send_security_request_should_succeed(true); |
217 ipc_client_weak_ptr_->set_security_key_response_payload(response_payload); | 215 ipc_client_weak_ptr_->set_security_key_response_payload(response_payload); |
218 writer_weak_ptr_->set_write_request_succeeded(/*should_succeed=*/false); | 216 writer_weak_ptr_->set_write_request_succeeded(/*should_succeed=*/false); |
219 | 217 |
220 reader_weak_ptr_->message_callback().Run( | 218 reader_weak_ptr_->message_callback().Run( |
221 SecurityKeyMessage::CreateMessageForTest( | 219 SecurityKeyMessage::CreateMessageForTest(SecurityKeyMessageType::REQUEST, |
222 RemoteSecurityKeyMessageType::REQUEST, request_payload)); | 220 request_payload)); |
223 WaitForOperationComplete(); | 221 WaitForOperationComplete(); |
224 | 222 |
225 ASSERT_FALSE(ipc_client_weak_ptr_.get()); | 223 ASSERT_FALSE(ipc_client_weak_ptr_.get()); |
226 ASSERT_FALSE(reader_weak_ptr_.get()); | 224 ASSERT_FALSE(reader_weak_ptr_.get()); |
227 ASSERT_FALSE(writer_weak_ptr_.get()); | 225 ASSERT_FALSE(writer_weak_ptr_.get()); |
228 } | 226 } |
229 | 227 |
230 TEST_F(RemoteSecurityKeyMessageHandlerTest, | 228 TEST_F(SecurityKeyMessageHandlerTest, |
231 ProcessRequestMessage_ValidPayload_IpcSendFailure) { | 229 ProcessRequestMessage_ValidPayload_IpcSendFailure) { |
232 std::string request_payload("I AM A VALID REQUEST PAYLOAD!"); | 230 std::string request_payload("I AM A VALID REQUEST PAYLOAD!"); |
233 ipc_client_weak_ptr_->set_send_security_request_should_succeed(false); | 231 ipc_client_weak_ptr_->set_send_security_request_should_succeed(false); |
234 | 232 |
235 reader_weak_ptr_->message_callback().Run( | 233 reader_weak_ptr_->message_callback().Run( |
236 SecurityKeyMessage::CreateMessageForTest( | 234 SecurityKeyMessage::CreateMessageForTest(SecurityKeyMessageType::REQUEST, |
237 RemoteSecurityKeyMessageType::REQUEST, request_payload)); | 235 request_payload)); |
238 WaitForOperationComplete(); | 236 WaitForOperationComplete(); |
239 | 237 |
240 ASSERT_EQ(RemoteSecurityKeyMessageType::REQUEST_ERROR, | 238 ASSERT_EQ(SecurityKeyMessageType::REQUEST_ERROR, |
241 writer_weak_ptr_->last_message_type()); | 239 writer_weak_ptr_->last_message_type()); |
242 ASSERT_FALSE(writer_weak_ptr_->last_message_payload().empty()); | 240 ASSERT_FALSE(writer_weak_ptr_->last_message_payload().empty()); |
243 } | 241 } |
244 | 242 |
245 TEST_F(RemoteSecurityKeyMessageHandlerTest, | 243 TEST_F(SecurityKeyMessageHandlerTest, |
246 ProcessRequestMessage_ValidPayload_EmptyClientResponse) { | 244 ProcessRequestMessage_ValidPayload_EmptyClientResponse) { |
247 std::string request_payload("I AM A VALID REQUEST PAYLOAD!"); | 245 std::string request_payload("I AM A VALID REQUEST PAYLOAD!"); |
248 std::string response_payload(""); | 246 std::string response_payload(""); |
249 ipc_client_weak_ptr_->set_send_security_request_should_succeed(true); | 247 ipc_client_weak_ptr_->set_send_security_request_should_succeed(true); |
250 ipc_client_weak_ptr_->set_security_key_response_payload(response_payload); | 248 ipc_client_weak_ptr_->set_security_key_response_payload(response_payload); |
251 | 249 |
252 reader_weak_ptr_->message_callback().Run( | 250 reader_weak_ptr_->message_callback().Run( |
253 SecurityKeyMessage::CreateMessageForTest( | 251 SecurityKeyMessage::CreateMessageForTest(SecurityKeyMessageType::REQUEST, |
254 RemoteSecurityKeyMessageType::REQUEST, request_payload)); | 252 request_payload)); |
255 WaitForOperationComplete(); | 253 WaitForOperationComplete(); |
256 | 254 |
257 ASSERT_EQ(RemoteSecurityKeyMessageType::REQUEST_ERROR, | 255 ASSERT_EQ(SecurityKeyMessageType::REQUEST_ERROR, |
258 writer_weak_ptr_->last_message_type()); | 256 writer_weak_ptr_->last_message_type()); |
259 ASSERT_FALSE(writer_weak_ptr_->last_message_payload().empty()); | 257 ASSERT_FALSE(writer_weak_ptr_->last_message_payload().empty()); |
260 } | 258 } |
261 | 259 |
262 TEST_F(RemoteSecurityKeyMessageHandlerTest, | 260 TEST_F(SecurityKeyMessageHandlerTest, |
263 ProcessRequestMessage_ValidPayload_ClientResponseError) { | 261 ProcessRequestMessage_ValidPayload_ClientResponseError) { |
264 std::string request_payload("I AM A VALID REQUEST PAYLOAD!"); | 262 std::string request_payload("I AM A VALID REQUEST PAYLOAD!"); |
265 std::string response_payload(kRemoteSecurityKeyConnectionError); | 263 std::string response_payload(kSecurityKeyConnectionError); |
266 ipc_client_weak_ptr_->set_send_security_request_should_succeed(true); | 264 ipc_client_weak_ptr_->set_send_security_request_should_succeed(true); |
267 ipc_client_weak_ptr_->set_security_key_response_payload(response_payload); | 265 ipc_client_weak_ptr_->set_security_key_response_payload(response_payload); |
268 | 266 |
269 reader_weak_ptr_->message_callback().Run( | 267 reader_weak_ptr_->message_callback().Run( |
270 SecurityKeyMessage::CreateMessageForTest( | 268 SecurityKeyMessage::CreateMessageForTest(SecurityKeyMessageType::REQUEST, |
271 RemoteSecurityKeyMessageType::REQUEST, request_payload)); | 269 request_payload)); |
272 WaitForOperationComplete(); | 270 WaitForOperationComplete(); |
273 | 271 |
274 ASSERT_EQ(RemoteSecurityKeyMessageType::REQUEST_ERROR, | 272 ASSERT_EQ(SecurityKeyMessageType::REQUEST_ERROR, |
275 writer_weak_ptr_->last_message_type()); | 273 writer_weak_ptr_->last_message_type()); |
276 ASSERT_FALSE(writer_weak_ptr_->last_message_payload().empty()); | 274 ASSERT_FALSE(writer_weak_ptr_->last_message_payload().empty()); |
277 } | 275 } |
278 | 276 |
279 TEST_F(RemoteSecurityKeyMessageHandlerTest, | 277 TEST_F(SecurityKeyMessageHandlerTest, ProcessRequestMessage_InvalidPayload) { |
280 ProcessRequestMessage_InvalidPayload) { | |
281 std::string invalid_payload(""); | 278 std::string invalid_payload(""); |
282 reader_weak_ptr_->message_callback().Run( | 279 reader_weak_ptr_->message_callback().Run( |
283 SecurityKeyMessage::CreateMessageForTest( | 280 SecurityKeyMessage::CreateMessageForTest(SecurityKeyMessageType::REQUEST, |
284 RemoteSecurityKeyMessageType::REQUEST, invalid_payload)); | 281 invalid_payload)); |
285 WaitForOperationComplete(); | 282 WaitForOperationComplete(); |
286 | 283 |
287 ASSERT_EQ(RemoteSecurityKeyMessageType::REQUEST_ERROR, | 284 ASSERT_EQ(SecurityKeyMessageType::REQUEST_ERROR, |
288 writer_weak_ptr_->last_message_type()); | 285 writer_weak_ptr_->last_message_type()); |
289 ASSERT_FALSE(writer_weak_ptr_->last_message_payload().empty()); | 286 ASSERT_FALSE(writer_weak_ptr_->last_message_payload().empty()); |
290 } | 287 } |
291 | 288 |
292 TEST_F(RemoteSecurityKeyMessageHandlerTest, ProcessUnknownMessage) { | 289 TEST_F(SecurityKeyMessageHandlerTest, ProcessUnknownMessage) { |
293 reader_weak_ptr_->message_callback().Run( | 290 reader_weak_ptr_->message_callback().Run( |
294 SecurityKeyMessage::CreateMessageForTest( | 291 SecurityKeyMessage::CreateMessageForTest( |
295 RemoteSecurityKeyMessageType::UNKNOWN_ERROR, std::string())); | 292 SecurityKeyMessageType::UNKNOWN_ERROR, std::string())); |
296 WaitForOperationComplete(); | 293 WaitForOperationComplete(); |
297 | 294 |
298 ASSERT_EQ(RemoteSecurityKeyMessageType::UNKNOWN_COMMAND, | 295 ASSERT_EQ(SecurityKeyMessageType::UNKNOWN_COMMAND, |
299 writer_weak_ptr_->last_message_type()); | 296 writer_weak_ptr_->last_message_type()); |
300 } | 297 } |
301 | 298 |
302 } // namespace remoting | 299 } // namespace remoting |
OLD | NEW |