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

Side by Side Diff: blimp/net/compressed_packet_unittest.cc

Issue 1882043003: Blimp: add padding for zlib framing to buffer preallocation calculations. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: wez feedback 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
« no previous file with comments | « no previous file | blimp/net/compressed_packet_writer.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 <stdlib.h>
6
5 #include "base/memory/ptr_util.h" 7 #include "base/memory/ptr_util.h"
6 #include "base/sys_byteorder.h" 8 #include "base/sys_byteorder.h"
7 #include "blimp/net/common.h" 9 #include "blimp/net/common.h"
8 #include "blimp/net/compressed_packet_reader.h" 10 #include "blimp/net/compressed_packet_reader.h"
9 #include "blimp/net/compressed_packet_writer.h" 11 #include "blimp/net/compressed_packet_writer.h"
10 #include "blimp/net/test_common.h" 12 #include "blimp/net/test_common.h"
11 #include "net/base/test_completion_callback.h" 13 #include "net/base/test_completion_callback.h"
12 #include "testing/gmock/include/gmock/gmock.h" 14 #include "testing/gmock/include/gmock/gmock.h"
13 #include "testing/gtest/include/gtest/gtest.h" 15 #include "testing/gtest/include/gtest/gtest.h"
14 16
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
146 int size_1 = Compress("1234").size(); 148 int size_1 = Compress("1234").size();
147 int size_2 = Compress("1234").size(); 149 int size_2 = Compress("1234").size();
148 EXPECT_GT(size_1, size_2); 150 EXPECT_GT(size_1, size_2);
149 } 151 }
150 152
151 TEST_F(CompressedPacketTest, LargeInput) { 153 TEST_F(CompressedPacketTest, LargeInput) {
152 std::string big_str(kMaxPacketPayloadSizeBytes, 'A'); // 3MB of A's. 154 std::string big_str(kMaxPacketPayloadSizeBytes, 'A'); // 3MB of A's.
153 EXPECT_TRUE(CheckRoundTrip(big_str)); 155 EXPECT_TRUE(CheckRoundTrip(big_str));
154 } 156 }
155 157
158 TEST_F(CompressedPacketTest, LowCompressionRatio) {
159 // This size (2338) was found "in the wild" to repro an issue with output
160 // buffer overflows.
161 std::vector<uint8_t> source_data(2338);
162 unsigned int rand_seed = 0;
163
164 // Write two incompressible (high entropy) blocks.
Wez 2016/04/13 01:11:02 nit: Why two?
165 for (size_t i = 0; i < source_data.size(); ++i) {
166 source_data[i] = rand_r(&rand_seed);
167 }
168 EXPECT_TRUE(
169 CheckRoundTrip(std::string(source_data.begin(), source_data.end())));
170
171 for (size_t i = 0; i < source_data.size(); ++i) {
172 source_data[i] = rand_r(&rand_seed);
173 }
174 EXPECT_TRUE(
175 CheckRoundTrip(std::string(source_data.begin(), source_data.end())));
176 }
177
156 TEST_F(CompressedPacketTest, DecompressIllegallyLargePayload) { 178 TEST_F(CompressedPacketTest, DecompressIllegallyLargePayload) {
157 // We can't use the compressor to compress an illegally sized payload, however 179 // We can't use the compressor to compress an illegally sized payload, however
158 // we can concatenate the output of smaller payloads to form an uber-payload. 180 // we can concatenate the output of smaller payloads to form an uber-payload.
159 std::string huge_block = 181 std::string huge_block =
160 Compress(std::string(kMaxPacketPayloadSizeBytes, 'A')) + 182 Compress(std::string(kMaxPacketPayloadSizeBytes, 'A')) +
161 Compress("1337 payl0ad 0verfl0w 'spl0it"); 183 Compress("1337 payl0ad 0verfl0w 'spl0it");
162 184
163 scoped_refptr<net::StringIOBuffer> compressed_str_buf( 185 scoped_refptr<net::StringIOBuffer> compressed_str_buf(
164 new net::StringIOBuffer(huge_block)); 186 new net::StringIOBuffer(huge_block));
165 scoped_refptr<net::DrainableIOBuffer> compressed_buf( 187 scoped_refptr<net::DrainableIOBuffer> compressed_buf(
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
208 DoAll(CopyBuffer<0>(compressed_buf), 230 DoAll(CopyBuffer<0>(compressed_buf),
209 InvokeCompletionCallback<1>(compressed_buf->BytesRemaining()))); 231 InvokeCompletionCallback<1>(compressed_buf->BytesRemaining())));
210 net::TestCompletionCallback completion_cb_2; 232 net::TestCompletionCallback completion_cb_2;
211 compressed_reader_->ReadPacket(make_scoped_refptr(new net::GrowableIOBuffer), 233 compressed_reader_->ReadPacket(make_scoped_refptr(new net::GrowableIOBuffer),
212 completion_cb_2.callback()); 234 completion_cb_2.callback());
213 EXPECT_EQ(net::ERR_UNEXPECTED, completion_cb_2.WaitForResult()); 235 EXPECT_EQ(net::ERR_UNEXPECTED, completion_cb_2.WaitForResult());
214 } 236 }
215 237
216 } // namespace 238 } // namespace
217 } // namespace blimp 239 } // namespace blimp
OLDNEW
« no previous file with comments | « no previous file | blimp/net/compressed_packet_writer.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698