| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 <fstream> | 5 #include <fstream> |
| 6 #include <iostream> | 6 #include <iostream> |
| 7 | 7 |
| 8 #include "base/file_util.h" | 8 #include "base/file_util.h" |
| 9 #include "base/path_service.h" | 9 #include "base/path_service.h" |
| 10 #include "base/scoped_ptr.h" | 10 #include "base/scoped_ptr.h" |
| (...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 261 | 261 |
| 262 char gzip_decode_buffer[kDefaultBufferSize]; | 262 char gzip_decode_buffer[kDefaultBufferSize]; |
| 263 int gzip_decode_size = kDefaultBufferSize; | 263 int gzip_decode_size = kDefaultBufferSize; |
| 264 filter->ReadData(gzip_decode_buffer, &gzip_decode_size); | 264 filter->ReadData(gzip_decode_buffer, &gzip_decode_size); |
| 265 | 265 |
| 266 // Compare the decoding result with source data | 266 // Compare the decoding result with source data |
| 267 EXPECT_TRUE(gzip_decode_size == source_len()); | 267 EXPECT_TRUE(gzip_decode_size == source_len()); |
| 268 EXPECT_EQ(memcmp(source_buffer(), gzip_decode_buffer, source_len()), 0); | 268 EXPECT_EQ(memcmp(source_buffer(), gzip_decode_buffer, source_len()), 0); |
| 269 } | 269 } |
| 270 | 270 |
| 271 // SDCH scenario: decoding gzip data when content type says sdch,gzip. | |
| 272 // This tests that sdch will degrade to pass through, and is what allows robust | |
| 273 // handling when the response *might* be sdch,gzip by simply adding in the | |
| 274 // tentative sdch decode. | |
| 275 // All test code is otherwise modeled after the "basic" scenario above. | |
| 276 TEST_F(GZipUnitTest, DecodeGZipWithMistakenSdch) { | |
| 277 // Decode the compressed data with filter | |
| 278 std::vector<Filter::FilterType> filter_types; | |
| 279 filter_types.push_back(Filter::FILTER_TYPE_SDCH); | |
| 280 filter_types.push_back(Filter::FILTER_TYPE_GZIP); | |
| 281 MockFilterContext filter_context(kDefaultBufferSize); | |
| 282 // We need a good response code to be sure that a proxy isn't injecting an | |
| 283 // error page (As is done by BlueCoat proxies and described in bug 8916). | |
| 284 filter_context.SetResponseCode(200); | |
| 285 scoped_ptr<Filter> filter(Filter::Factory(filter_types, filter_context)); | |
| 286 ASSERT_TRUE(filter.get()); | |
| 287 memcpy(filter->stream_buffer()->data(), gzip_encode_buffer_, | |
| 288 gzip_encode_len_); | |
| 289 filter->FlushStreamBuffer(gzip_encode_len_); | |
| 290 | |
| 291 char gzip_decode_buffer[kDefaultBufferSize]; | |
| 292 int gzip_decode_size = kDefaultBufferSize; | |
| 293 filter->ReadData(gzip_decode_buffer, &gzip_decode_size); | |
| 294 | |
| 295 // Compare the decoding result with source data | |
| 296 EXPECT_TRUE(gzip_decode_size == source_len()); | |
| 297 EXPECT_EQ(memcmp(source_buffer(), gzip_decode_buffer, source_len()), 0); | |
| 298 } | |
| 299 | |
| 300 // Tests we can call filter repeatedly to get all the data decoded. | 271 // Tests we can call filter repeatedly to get all the data decoded. |
| 301 // To do that, we create a filter with a small buffer that can not hold all | 272 // To do that, we create a filter with a small buffer that can not hold all |
| 302 // the input data. | 273 // the input data. |
| 303 TEST_F(GZipUnitTest, DecodeWithSmallBuffer) { | 274 TEST_F(GZipUnitTest, DecodeWithSmallBuffer) { |
| 304 std::vector<Filter::FilterType> filter_types; | 275 std::vector<Filter::FilterType> filter_types; |
| 305 filter_types.push_back(Filter::FILTER_TYPE_DEFLATE); | 276 filter_types.push_back(Filter::FILTER_TYPE_DEFLATE); |
| 306 MockFilterContext filter_context(kSmallBufferSize); | 277 MockFilterContext filter_context(kSmallBufferSize); |
| 307 scoped_ptr<Filter> filter(Filter::Factory(filter_types, filter_context)); | 278 scoped_ptr<Filter> filter(Filter::Factory(filter_types, filter_context)); |
| 308 ASSERT_TRUE(filter.get()); | 279 ASSERT_TRUE(filter.get()); |
| 309 DecodeAndCompareWithFilter(filter.get(), source_buffer(), source_len(), | 280 DecodeAndCompareWithFilter(filter.get(), source_buffer(), source_len(), |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 420 int corrupt_decode_size = kDefaultBufferSize; | 391 int corrupt_decode_size = kDefaultBufferSize; |
| 421 | 392 |
| 422 int code = DecodeAllWithFilter(filter.get(), corrupt_data, corrupt_data_len, | 393 int code = DecodeAllWithFilter(filter.get(), corrupt_data, corrupt_data_len, |
| 423 corrupt_decode_buffer, &corrupt_decode_size); | 394 corrupt_decode_buffer, &corrupt_decode_size); |
| 424 | 395 |
| 425 // Expect failures | 396 // Expect failures |
| 426 EXPECT_TRUE(code == Filter::FILTER_ERROR); | 397 EXPECT_TRUE(code == Filter::FILTER_ERROR); |
| 427 } | 398 } |
| 428 | 399 |
| 429 } // namespace | 400 } // namespace |
| OLD | NEW |