| 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 "base/memory/ptr_util.h" | 5 #include "base/memory/ptr_util.h" |
| 6 #include "base/rand_util.h" |
| 6 #include "base/sys_byteorder.h" | 7 #include "base/sys_byteorder.h" |
| 7 #include "blimp/net/common.h" | 8 #include "blimp/net/common.h" |
| 8 #include "blimp/net/compressed_packet_reader.h" | 9 #include "blimp/net/compressed_packet_reader.h" |
| 9 #include "blimp/net/compressed_packet_writer.h" | 10 #include "blimp/net/compressed_packet_writer.h" |
| 10 #include "blimp/net/test_common.h" | 11 #include "blimp/net/test_common.h" |
| 11 #include "net/base/test_completion_callback.h" | 12 #include "net/base/test_completion_callback.h" |
| 12 #include "testing/gmock/include/gmock/gmock.h" | 13 #include "testing/gmock/include/gmock/gmock.h" |
| 13 #include "testing/gtest/include/gtest/gtest.h" | 14 #include "testing/gtest/include/gtest/gtest.h" |
| 14 | 15 |
| 15 using testing::_; | 16 using testing::_; |
| (...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 146 int size_1 = Compress("1234").size(); | 147 int size_1 = Compress("1234").size(); |
| 147 int size_2 = Compress("1234").size(); | 148 int size_2 = Compress("1234").size(); |
| 148 EXPECT_GT(size_1, size_2); | 149 EXPECT_GT(size_1, size_2); |
| 149 } | 150 } |
| 150 | 151 |
| 151 TEST_F(CompressedPacketTest, LargeInput) { | 152 TEST_F(CompressedPacketTest, LargeInput) { |
| 152 std::string big_str(kMaxPacketPayloadSizeBytes, 'A'); // 3MB of A's. | 153 std::string big_str(kMaxPacketPayloadSizeBytes, 'A'); // 3MB of A's. |
| 153 EXPECT_TRUE(CheckRoundTrip(big_str)); | 154 EXPECT_TRUE(CheckRoundTrip(big_str)); |
| 154 } | 155 } |
| 155 | 156 |
| 157 TEST_F(CompressedPacketTest, LowCompressionRatio) { |
| 158 // This size (2338) was found "in the wild" to repro an issue with output |
| 159 // buffer overflows. |
| 160 const int data_size = 2338; |
| 161 |
| 162 EXPECT_TRUE(CheckRoundTrip(base::RandBytesAsString(data_size))); |
| 163 EXPECT_TRUE(CheckRoundTrip(base::RandBytesAsString(data_size))); |
| 164 } |
| 165 |
| 156 TEST_F(CompressedPacketTest, DecompressIllegallyLargePayload) { | 166 TEST_F(CompressedPacketTest, DecompressIllegallyLargePayload) { |
| 157 // We can't use the compressor to compress an illegally sized payload, however | 167 // 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. | 168 // we can concatenate the output of smaller payloads to form an uber-payload. |
| 159 std::string huge_block = | 169 std::string huge_block = |
| 160 Compress(std::string(kMaxPacketPayloadSizeBytes, 'A')) + | 170 Compress(std::string(kMaxPacketPayloadSizeBytes, 'A')) + |
| 161 Compress("1337 payl0ad 0verfl0w 'spl0it"); | 171 Compress("1337 payl0ad 0verfl0w 'spl0it"); |
| 162 | 172 |
| 163 scoped_refptr<net::StringIOBuffer> compressed_str_buf( | 173 scoped_refptr<net::StringIOBuffer> compressed_str_buf( |
| 164 new net::StringIOBuffer(huge_block)); | 174 new net::StringIOBuffer(huge_block)); |
| 165 scoped_refptr<net::DrainableIOBuffer> compressed_buf( | 175 scoped_refptr<net::DrainableIOBuffer> compressed_buf( |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 208 DoAll(CopyBuffer<0>(compressed_buf), | 218 DoAll(CopyBuffer<0>(compressed_buf), |
| 209 InvokeCompletionCallback<1>(compressed_buf->BytesRemaining()))); | 219 InvokeCompletionCallback<1>(compressed_buf->BytesRemaining()))); |
| 210 net::TestCompletionCallback completion_cb_2; | 220 net::TestCompletionCallback completion_cb_2; |
| 211 compressed_reader_->ReadPacket(make_scoped_refptr(new net::GrowableIOBuffer), | 221 compressed_reader_->ReadPacket(make_scoped_refptr(new net::GrowableIOBuffer), |
| 212 completion_cb_2.callback()); | 222 completion_cb_2.callback()); |
| 213 EXPECT_EQ(net::ERR_UNEXPECTED, completion_cb_2.WaitForResult()); | 223 EXPECT_EQ(net::ERR_UNEXPECTED, completion_cb_2.WaitForResult()); |
| 214 } | 224 } |
| 215 | 225 |
| 216 } // namespace | 226 } // namespace |
| 217 } // namespace blimp | 227 } // namespace blimp |
| OLD | NEW |