Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(278)

Side by Side Diff: remoting/host/security_key/remote_security_key_message_reader_impl_unittest.cc

Issue 1900733002: Fixing a Dr. Memory hang in the remoting_unittests (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixing up a callsite where we passed the message string Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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_reader_impl.h" 5 #include "remoting/host/security_key/remote_security_key_message_reader_impl.h"
6 6
7 #include <cstdint> 7 #include <cstdint>
8 #include <memory> 8 #include <memory>
9 #include <string> 9 #include <string>
10 #include <utility> 10 #include <utility>
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
141 std::string payload("I AM A VALID MESSAGE PAYLOAD!!!!!!!!!!!!!!!!!!!!!!"); 141 std::string payload("I AM A VALID MESSAGE PAYLOAD!!!!!!!!!!!!!!!!!!!!!!");
142 WriteMessage(kTestMessageType, payload); 142 WriteMessage(kTestMessageType, payload);
143 RunLoop(); 143 RunLoop();
144 ASSERT_EQ(1u, messages_received_.size()); 144 ASSERT_EQ(1u, messages_received_.size());
145 ASSERT_EQ(kTestMessageType, messages_received_[0]->type()); 145 ASSERT_EQ(kTestMessageType, messages_received_[0]->type());
146 ASSERT_EQ(payload, messages_received_[0]->payload()); 146 ASSERT_EQ(payload, messages_received_[0]->payload());
147 147
148 CloseWriteFileAndRunLoop(); 148 CloseWriteFileAndRunLoop();
149 } 149 }
150 150
151 TEST_F(RemoteSecurityKeyMessageReaderImplTest, SingleMessageViaSingleWrite) {
152 // All other tests write in 2-3 chunks, this writes the message in one shot.
153 std::string payload("LLLLTI am the best payload in the history of testing.");
154 // Overwite the 'L' values with the actual length.
155 uint8_t length = payload.size() - SecurityKeyMessage::kHeaderSizeBytes;
156 payload[0] = static_cast<char>(length);
157 payload[1] = 0;
158 payload[2] = 0;
159 payload[3] = 0;
160 // Overwite the 'T' value with the actual type.
161 payload[4] = static_cast<char>(kTestMessageType);
162 WriteData(payload.data(), payload.size());
163 RunLoop();
164 ASSERT_EQ(1u, messages_received_.size());
165 ASSERT_EQ(kTestMessageType, messages_received_[0]->type());
166 ASSERT_EQ(payload.substr(5), messages_received_[0]->payload());
167
168 CloseWriteFileAndRunLoop();
169 }
170
171 TEST_F(RemoteSecurityKeyMessageReaderImplTest, SingleMessageViaMultipleWrites) {
172 // All other tests write in 2-3 chunks, this writes the message byte by byte.
173 std::string payload("LLLLTI am the worst payload in the history of testing.");
174 // Overwite the 'L' values with the actual length.
175 uint8_t length = payload.size() - SecurityKeyMessage::kHeaderSizeBytes;
176 payload[0] = static_cast<char>(length);
177 payload[1] = 0;
178 payload[2] = 0;
179 payload[3] = 0;
180 // Overwite the 'T' value with the actual type.
181 payload[4] = static_cast<char>(kTestMessageType);
182
183 for (uint32_t i = 0; i < payload.size(); i++) {
184 WriteData(&payload[i], 1);
185 }
186 RunLoop();
187 ASSERT_EQ(1u, messages_received_.size());
188 ASSERT_EQ(kTestMessageType, messages_received_[0]->type());
189 ASSERT_EQ(payload.substr(5), messages_received_[0]->payload());
190
191 CloseWriteFileAndRunLoop();
192 }
193
151 TEST_F(RemoteSecurityKeyMessageReaderImplTest, SingleMessageWithLargePayload) { 194 TEST_F(RemoteSecurityKeyMessageReaderImplTest, SingleMessageWithLargePayload) {
152 std::string payload(kMaxSecurityKeyMessageByteCount - 195 std::string payload(kMaxSecurityKeyMessageByteCount -
153 SecurityKeyMessage::kMessageTypeSizeBytes, 196 SecurityKeyMessage::kMessageTypeSizeBytes,
154 'Y'); 197 'Y');
155 WriteMessage(kTestMessageType, payload); 198 WriteMessage(kTestMessageType, payload);
156 RunLoop(); 199 RunLoop();
157 ASSERT_EQ(1u, messages_received_.size()); 200 ASSERT_EQ(1u, messages_received_.size());
158 ASSERT_EQ(kTestMessageType, messages_received_[0]->type()); 201 ASSERT_EQ(kTestMessageType, messages_received_[0]->type());
159 ASSERT_EQ(payload, messages_received_[0]->payload()); 202 ASSERT_EQ(payload, messages_received_[0]->payload());
160 203
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
203 WriteData(&test_control_code, sizeof(test_control_code)); 246 WriteData(&test_control_code, sizeof(test_control_code));
204 CloseWriteFileAndRunLoop(); 247 CloseWriteFileAndRunLoop();
205 ASSERT_EQ(0u, messages_received_.size()); 248 ASSERT_EQ(0u, messages_received_.size());
206 } 249 }
207 250
208 TEST_F(RemoteSecurityKeyMessageReaderImplTest, MultipleMessages) { 251 TEST_F(RemoteSecurityKeyMessageReaderImplTest, MultipleMessages) {
209 std::vector<std::string> payloads({"", "S", // Really short 252 std::vector<std::string> payloads({"", "S", // Really short
210 "", "Short", "", "Medium Length", "", 253 "", "Short", "", "Medium Length", "",
211 "Longer than medium, but not super long", 254 "Longer than medium, but not super long",
212 "", std::string(2048, 'Y'), ""}); 255 "", std::string(2048, 'Y'), ""});
213 256 for (size_t i = 0; i < payloads.size(); i++) {
214 for (auto& payload : payloads) { 257 WriteMessage(kTestMessageType, payloads[i]);
215 WriteMessage(kTestMessageType, payload);
216 RunLoop(); 258 RunLoop();
259 ASSERT_EQ(i + 1, messages_received_.size());
217 } 260 }
218
219 ASSERT_EQ(payloads.size(), messages_received_.size());
220 CloseWriteFileAndRunLoop(); 261 CloseWriteFileAndRunLoop();
221 262
222 for (size_t i = 0; i < payloads.size(); i++) { 263 for (size_t i = 0; i < payloads.size(); i++) {
223 ASSERT_EQ(kTestMessageType, messages_received_[i]->type()); 264 ASSERT_EQ(kTestMessageType, messages_received_[i]->type());
224 ASSERT_EQ(payloads[i], messages_received_[i]->payload()); 265 ASSERT_EQ(payloads[i], messages_received_[i]->payload());
225 } 266 }
226 } 267 }
227 268
228 } // namespace remoting 269 } // namespace remoting
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698