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

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 the formatting for the changed files. 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
151 TEST_F(RemoteSecurityKeyMessageReaderImplTest, SingleMessageWithLargePayload) { 171 TEST_F(RemoteSecurityKeyMessageReaderImplTest, SingleMessageWithLargePayload) {
152 std::string payload(kMaxSecurityKeyMessageByteCount - 172 std::string payload(kMaxSecurityKeyMessageByteCount -
153 SecurityKeyMessage::kMessageTypeSizeBytes, 173 SecurityKeyMessage::kMessageTypeSizeBytes,
154 'Y'); 174 'Y');
155 WriteMessage(kTestMessageType, payload); 175 WriteMessage(kTestMessageType, payload);
156 RunLoop(); 176 RunLoop();
157 ASSERT_EQ(1u, messages_received_.size()); 177 ASSERT_EQ(1u, messages_received_.size());
158 ASSERT_EQ(kTestMessageType, messages_received_[0]->type()); 178 ASSERT_EQ(kTestMessageType, messages_received_[0]->type());
159 ASSERT_EQ(payload, messages_received_[0]->payload()); 179 ASSERT_EQ(payload, messages_received_[0]->payload());
160 180
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
203 WriteData(&test_control_code, sizeof(test_control_code)); 223 WriteData(&test_control_code, sizeof(test_control_code));
204 CloseWriteFileAndRunLoop(); 224 CloseWriteFileAndRunLoop();
205 ASSERT_EQ(0u, messages_received_.size()); 225 ASSERT_EQ(0u, messages_received_.size());
206 } 226 }
207 227
208 TEST_F(RemoteSecurityKeyMessageReaderImplTest, MultipleMessages) { 228 TEST_F(RemoteSecurityKeyMessageReaderImplTest, MultipleMessages) {
209 std::vector<std::string> payloads({"", "S", // Really short 229 std::vector<std::string> payloads({"", "S", // Really short
210 "", "Short", "", "Medium Length", "", 230 "", "Short", "", "Medium Length", "",
211 "Longer than medium, but not super long", 231 "Longer than medium, but not super long",
212 "", std::string(2048, 'Y'), ""}); 232 "", std::string(2048, 'Y'), ""});
213 233 for (size_t i = 0; i < payloads.size(); i++) {
214 for (auto& payload : payloads) { 234 WriteMessage(kTestMessageType, payloads[i]);
215 WriteMessage(kTestMessageType, payload);
216 RunLoop(); 235 RunLoop();
236 ASSERT_EQ(i + 1, messages_received_.size());
217 } 237 }
218
219 ASSERT_EQ(payloads.size(), messages_received_.size());
220 CloseWriteFileAndRunLoop(); 238 CloseWriteFileAndRunLoop();
221 239
222 for (size_t i = 0; i < payloads.size(); i++) { 240 for (size_t i = 0; i < payloads.size(); i++) {
223 ASSERT_EQ(kTestMessageType, messages_received_[i]->type()); 241 ASSERT_EQ(kTestMessageType, messages_received_[i]->type());
224 ASSERT_EQ(payloads[i], messages_received_[i]->payload()); 242 ASSERT_EQ(payloads[i], messages_received_[i]->payload());
225 } 243 }
226 } 244 }
227 245
228 } // namespace remoting 246 } // namespace remoting
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698