| Index: net/filter/sdch_filter_unittest.cc
|
| diff --git a/net/filter/sdch_filter_unittest.cc b/net/filter/sdch_filter_unittest.cc
|
| index 37f48866707bfece16ba4c183b33f7d3f603d43c..75d7bb23a5f40cd419f05ee23cf141eb6c260e78 100644
|
| --- a/net/filter/sdch_filter_unittest.cc
|
| +++ b/net/filter/sdch_filter_unittest.cc
|
| @@ -22,7 +22,8 @@ namespace net {
|
| //------------------------------------------------------------------------------
|
| // Provide sample data and compression results with a sample VCDIFF dictionary.
|
| // Note an SDCH dictionary has extra meta-data before the VCDIFF dictionary.
|
| -static const char kTestVcdiffDictionary[] = "DictionaryFor"
|
| +static const char kTestVcdiffDictionary[] =
|
| + "DictionaryFor"
|
| "SdchCompression1SdchCompression2SdchCompression3SdchCompression\n";
|
| // Pre-compression test data. Note that we pad with a lot of highly gzip
|
| // compressible content to help to exercise the chaining pipeline. That is why
|
| @@ -31,7 +32,8 @@ static const char kTestVcdiffDictionary[] = "DictionaryFor"
|
| // gulp, but (with careful selection of intermediate buffers) that it takes
|
| // several sdch buffers worth of data to satisfy the sdch filter. See detailed
|
| // CHECK() calls in FilterChaining test for specifics.
|
| -static const char kTestData[] = "0000000000000000000000000000000000000000000000"
|
| +static const char kTestData[] =
|
| + "0000000000000000000000000000000000000000000000"
|
| "0000000000000000000000000000TestData "
|
| "SdchCompression1SdchCompression2SdchCompression3SdchCompression"
|
| "00000000000000000000000000000000000000000000000000000000000000000000000000"
|
| @@ -49,13 +51,12 @@ static const char kSdchCompressedTestData[] =
|
| class SdchFilterTest : public testing::Test {
|
| protected:
|
| SdchFilterTest()
|
| - : test_vcdiff_dictionary_(kTestVcdiffDictionary,
|
| - sizeof(kTestVcdiffDictionary) - 1),
|
| - vcdiff_compressed_data_(kSdchCompressedTestData,
|
| - sizeof(kSdchCompressedTestData) - 1),
|
| - expanded_(kTestData, sizeof(kTestData) - 1),
|
| - sdch_manager_(new SdchManager) {
|
| - }
|
| + : test_vcdiff_dictionary_(kTestVcdiffDictionary,
|
| + sizeof(kTestVcdiffDictionary) - 1),
|
| + vcdiff_compressed_data_(kSdchCompressedTestData,
|
| + sizeof(kSdchCompressedTestData) - 1),
|
| + expanded_(kTestData, sizeof(kTestData) - 1),
|
| + sdch_manager_(new SdchManager) {}
|
|
|
| std::string NewSdchCompressedData(const std::string dictionary);
|
|
|
| @@ -81,7 +82,6 @@ std::string SdchFilterTest::NewSdchCompressedData(
|
|
|
| //------------------------------------------------------------------------------
|
|
|
| -
|
| TEST_F(SdchFilterTest, Hashing) {
|
| std::string client_hash, server_hash;
|
| std::string dictionary("test contents");
|
| @@ -91,7 +91,6 @@ TEST_F(SdchFilterTest, Hashing) {
|
| EXPECT_EQ(server_hash, "MyciMVll");
|
| }
|
|
|
| -
|
| //------------------------------------------------------------------------------
|
| // Provide a generic helper function for trying to filter data.
|
| // This function repeatedly calls the filter to process data, until the entire
|
| @@ -105,18 +104,20 @@ TEST_F(SdchFilterTest, Hashing) {
|
| static bool FilterTestData(const std::string& source,
|
| size_t input_block_length,
|
| const size_t output_buffer_length,
|
| - Filter* filter, std::string* output) {
|
| + Filter* filter,
|
| + std::string* output) {
|
| CHECK_GT(input_block_length, 0u);
|
| Filter::FilterStatus status(Filter::FILTER_NEED_MORE_DATA);
|
| size_t source_index = 0;
|
| scoped_ptr<char[]> output_buffer(new char[output_buffer_length]);
|
| - size_t input_amount = std::min(input_block_length,
|
| - static_cast<size_t>(filter->stream_buffer_size()));
|
| + size_t input_amount = std::min(
|
| + input_block_length, static_cast<size_t>(filter->stream_buffer_size()));
|
|
|
| do {
|
| int copy_amount = std::min(input_amount, source.size() - source_index);
|
| if (copy_amount > 0 && status == Filter::FILTER_NEED_MORE_DATA) {
|
| - memcpy(filter->stream_buffer()->data(), source.data() + source_index,
|
| + memcpy(filter->stream_buffer()->data(),
|
| + source.data() + source_index,
|
| copy_amount);
|
| filter->FlushStreamBuffer(copy_amount);
|
| source_index += copy_amount;
|
| @@ -157,11 +158,10 @@ TEST_F(SdchFilterTest, EmptyInputOk) {
|
| filter_context.SetURL(GURL(url_string));
|
| scoped_ptr<Filter> filter(Filter::Factory(filter_types, filter_context));
|
|
|
| -
|
| // With no input data, try to read output.
|
| int output_bytes_or_buffer_size = sizeof(output_buffer);
|
| - Filter::FilterStatus status = filter->ReadData(output_buffer,
|
| - &output_bytes_or_buffer_size);
|
| + Filter::FilterStatus status =
|
| + filter->ReadData(output_buffer, &output_bytes_or_buffer_size);
|
|
|
| EXPECT_EQ(0, output_bytes_or_buffer_size);
|
| EXPECT_EQ(Filter::FILTER_NEED_MORE_DATA, status);
|
| @@ -185,21 +185,19 @@ TEST_F(SdchFilterTest, PassThroughWhenTentative) {
|
| char* input_buffer = filter->stream_buffer()->data();
|
| int input_buffer_size = filter->stream_buffer_size();
|
|
|
| - EXPECT_LT(static_cast<int>(non_gzip_content.size()),
|
| - input_buffer_size);
|
| - memcpy(input_buffer, non_gzip_content.data(),
|
| - non_gzip_content.size());
|
| + EXPECT_LT(static_cast<int>(non_gzip_content.size()), input_buffer_size);
|
| + memcpy(input_buffer, non_gzip_content.data(), non_gzip_content.size());
|
| filter->FlushStreamBuffer(non_gzip_content.size());
|
|
|
| // Try to read output.
|
| int output_bytes_or_buffer_size = sizeof(output_buffer);
|
| - Filter::FilterStatus status = filter->ReadData(output_buffer,
|
| - &output_bytes_or_buffer_size);
|
| + Filter::FilterStatus status =
|
| + filter->ReadData(output_buffer, &output_bytes_or_buffer_size);
|
|
|
| EXPECT_EQ(non_gzip_content.size(),
|
| - static_cast<size_t>(output_bytes_or_buffer_size));
|
| + static_cast<size_t>(output_bytes_or_buffer_size));
|
| ASSERT_GT(sizeof(output_buffer),
|
| - static_cast<size_t>(output_bytes_or_buffer_size));
|
| + static_cast<size_t>(output_bytes_or_buffer_size));
|
| output_buffer[output_bytes_or_buffer_size] = '\0';
|
| EXPECT_TRUE(non_gzip_content == output_buffer);
|
| EXPECT_EQ(Filter::FILTER_NEED_MORE_DATA, status);
|
| @@ -226,23 +224,22 @@ TEST_F(SdchFilterTest, RefreshBadReturnCode) {
|
| char* input_buffer = filter->stream_buffer()->data();
|
| int input_buffer_size = filter->stream_buffer_size();
|
|
|
| - EXPECT_LT(static_cast<int>(non_sdch_content.size()),
|
| - input_buffer_size);
|
| - memcpy(input_buffer, non_sdch_content.data(),
|
| - non_sdch_content.size());
|
| + EXPECT_LT(static_cast<int>(non_sdch_content.size()), input_buffer_size);
|
| + memcpy(input_buffer, non_sdch_content.data(), non_sdch_content.size());
|
| filter->FlushStreamBuffer(non_sdch_content.size());
|
|
|
| // Try to read output.
|
| int output_bytes_or_buffer_size = sizeof(output_buffer);
|
| - Filter::FilterStatus status = filter->ReadData(output_buffer,
|
| - &output_bytes_or_buffer_size);
|
| + Filter::FilterStatus status =
|
| + filter->ReadData(output_buffer, &output_bytes_or_buffer_size);
|
|
|
| // We should have read a long and complicated meta-refresh request.
|
| EXPECT_TRUE(sizeof(output_buffer) == output_bytes_or_buffer_size);
|
| // Check at least the prefix of the return.
|
| - EXPECT_EQ(0, strncmp(output_buffer,
|
| - "<head><META HTTP-EQUIV=\"Refresh\" CONTENT=\"0\"></head>",
|
| - sizeof(output_buffer)));
|
| + EXPECT_EQ(0,
|
| + strncmp(output_buffer,
|
| + "<head><META HTTP-EQUIV=\"Refresh\" CONTENT=\"0\"></head>",
|
| + sizeof(output_buffer)));
|
| EXPECT_EQ(Filter::FILTER_OK, status);
|
| }
|
|
|
| @@ -268,16 +265,14 @@ TEST_F(SdchFilterTest, ErrorOnBadReturnCode) {
|
| char* input_buffer = filter->stream_buffer()->data();
|
| int input_buffer_size = filter->stream_buffer_size();
|
|
|
| - EXPECT_LT(static_cast<int>(non_sdch_content.size()),
|
| - input_buffer_size);
|
| - memcpy(input_buffer, non_sdch_content.data(),
|
| - non_sdch_content.size());
|
| + EXPECT_LT(static_cast<int>(non_sdch_content.size()), input_buffer_size);
|
| + memcpy(input_buffer, non_sdch_content.data(), non_sdch_content.size());
|
| filter->FlushStreamBuffer(non_sdch_content.size());
|
|
|
| // Try to read output.
|
| int output_bytes_or_buffer_size = sizeof(output_buffer);
|
| - Filter::FilterStatus status = filter->ReadData(output_buffer,
|
| - &output_bytes_or_buffer_size);
|
| + Filter::FilterStatus status =
|
| + filter->ReadData(output_buffer, &output_bytes_or_buffer_size);
|
|
|
| EXPECT_EQ(0, output_bytes_or_buffer_size);
|
| EXPECT_EQ(Filter::FILTER_ERROR, status);
|
| @@ -304,24 +299,23 @@ TEST_F(SdchFilterTest, ErrorOnBadReturnCodeWithHtml) {
|
| char* input_buffer = filter->stream_buffer()->data();
|
| int input_buffer_size = filter->stream_buffer_size();
|
|
|
| - EXPECT_LT(static_cast<int>(non_sdch_content.size()),
|
| - input_buffer_size);
|
| - memcpy(input_buffer, non_sdch_content.data(),
|
| - non_sdch_content.size());
|
| + EXPECT_LT(static_cast<int>(non_sdch_content.size()), input_buffer_size);
|
| + memcpy(input_buffer, non_sdch_content.data(), non_sdch_content.size());
|
| filter->FlushStreamBuffer(non_sdch_content.size());
|
|
|
| // Try to read output.
|
| int output_bytes_or_buffer_size = sizeof(output_buffer);
|
| - Filter::FilterStatus status = filter->ReadData(output_buffer,
|
| - &output_bytes_or_buffer_size);
|
| + Filter::FilterStatus status =
|
| + filter->ReadData(output_buffer, &output_bytes_or_buffer_size);
|
|
|
| // We should have read a long and complicated meta-refresh request.
|
| EXPECT_EQ(sizeof(output_buffer),
|
| static_cast<size_t>(output_bytes_or_buffer_size));
|
| // Check at least the prefix of the return.
|
| - EXPECT_EQ(0, strncmp(output_buffer,
|
| - "<head><META HTTP-EQUIV=\"Refresh\" CONTENT=\"0\"></head>",
|
| - sizeof(output_buffer)));
|
| + EXPECT_EQ(0,
|
| + strncmp(output_buffer,
|
| + "<head><META HTTP-EQUIV=\"Refresh\" CONTENT=\"0\"></head>",
|
| + sizeof(output_buffer)));
|
| EXPECT_EQ(Filter::FILTER_OK, status);
|
| }
|
|
|
| @@ -341,16 +335,16 @@ TEST_F(SdchFilterTest, BasicBadDictionary) {
|
| char* input_buffer = filter->stream_buffer()->data();
|
| int input_buffer_size = filter->stream_buffer_size();
|
|
|
| - EXPECT_LT(static_cast<int>(dictionary_hash_prefix.size()),
|
| - input_buffer_size);
|
| - memcpy(input_buffer, dictionary_hash_prefix.data(),
|
| + EXPECT_LT(static_cast<int>(dictionary_hash_prefix.size()), input_buffer_size);
|
| + memcpy(input_buffer,
|
| + dictionary_hash_prefix.data(),
|
| dictionary_hash_prefix.size());
|
| filter->FlushStreamBuffer(dictionary_hash_prefix.size());
|
|
|
| // With less than a dictionary specifier, try to read output.
|
| int output_bytes_or_buffer_size = sizeof(output_buffer);
|
| - Filter::FilterStatus status = filter->ReadData(output_buffer,
|
| - &output_bytes_or_buffer_size);
|
| + Filter::FilterStatus status =
|
| + filter->ReadData(output_buffer, &output_bytes_or_buffer_size);
|
|
|
| EXPECT_EQ(0, output_bytes_or_buffer_size);
|
| EXPECT_EQ(Filter::FILTER_NEED_MORE_DATA, status);
|
| @@ -361,7 +355,8 @@ TEST_F(SdchFilterTest, BasicBadDictionary) {
|
|
|
| CHECK_LT(dictionary_hash_postfix.size(),
|
| static_cast<size_t>(input_buffer_size));
|
| - memcpy(input_buffer, dictionary_hash_postfix.data(),
|
| + memcpy(input_buffer,
|
| + dictionary_hash_postfix.data(),
|
| dictionary_hash_postfix.size());
|
| filter->FlushStreamBuffer(dictionary_hash_postfix.size());
|
|
|
| @@ -422,8 +417,8 @@ TEST_F(SdchFilterTest, BasicDictionary) {
|
| size_t feed_block_size = 100;
|
| size_t output_block_size = 100;
|
| std::string output;
|
| - EXPECT_TRUE(FilterTestData(compressed, feed_block_size, output_block_size,
|
| - filter.get(), &output));
|
| + EXPECT_TRUE(FilterTestData(
|
| + compressed, feed_block_size, output_block_size, filter.get(), &output));
|
| EXPECT_EQ(output, expanded_);
|
|
|
| // Decode with really small buffers (size 1) to check for edge effects.
|
| @@ -432,8 +427,8 @@ TEST_F(SdchFilterTest, BasicDictionary) {
|
| feed_block_size = 1;
|
| output_block_size = 1;
|
| output.clear();
|
| - EXPECT_TRUE(FilterTestData(compressed, feed_block_size, output_block_size,
|
| - filter.get(), &output));
|
| + EXPECT_TRUE(FilterTestData(
|
| + compressed, feed_block_size, output_block_size, filter.get(), &output));
|
| EXPECT_EQ(output, expanded_);
|
| }
|
|
|
| @@ -460,8 +455,8 @@ TEST_F(SdchFilterTest, NoDecodeHttps) {
|
| const size_t output_block_size(100);
|
| std::string output;
|
|
|
| - EXPECT_FALSE(FilterTestData(compressed, feed_block_size, output_block_size,
|
| - filter.get(), &output));
|
| + EXPECT_FALSE(FilterTestData(
|
| + compressed, feed_block_size, output_block_size, filter.get(), &output));
|
| }
|
|
|
| // Current failsafe TODO/hack refuses to decode any content that doesn't use
|
| @@ -491,8 +486,8 @@ TEST_F(SdchFilterTest, NoDecodeFtp) {
|
| const size_t output_block_size(100);
|
| std::string output;
|
|
|
| - EXPECT_FALSE(FilterTestData(compressed, feed_block_size, output_block_size,
|
| - filter.get(), &output));
|
| + EXPECT_FALSE(FilterTestData(
|
| + compressed, feed_block_size, output_block_size, filter.get(), &output));
|
| }
|
|
|
| TEST_F(SdchFilterTest, NoDecodeFileColon) {
|
| @@ -518,8 +513,8 @@ TEST_F(SdchFilterTest, NoDecodeFileColon) {
|
| const size_t output_block_size(100);
|
| std::string output;
|
|
|
| - EXPECT_FALSE(FilterTestData(compressed, feed_block_size, output_block_size,
|
| - filter.get(), &output));
|
| + EXPECT_FALSE(FilterTestData(
|
| + compressed, feed_block_size, output_block_size, filter.get(), &output));
|
| }
|
|
|
| TEST_F(SdchFilterTest, NoDecodeAboutColon) {
|
| @@ -545,8 +540,8 @@ TEST_F(SdchFilterTest, NoDecodeAboutColon) {
|
| const size_t output_block_size(100);
|
| std::string output;
|
|
|
| - EXPECT_FALSE(FilterTestData(compressed, feed_block_size, output_block_size,
|
| - filter.get(), &output));
|
| + EXPECT_FALSE(FilterTestData(
|
| + compressed, feed_block_size, output_block_size, filter.get(), &output));
|
| }
|
|
|
| TEST_F(SdchFilterTest, NoDecodeJavaScript) {
|
| @@ -572,8 +567,8 @@ TEST_F(SdchFilterTest, NoDecodeJavaScript) {
|
| const size_t output_block_size(100);
|
| std::string output;
|
|
|
| - EXPECT_FALSE(FilterTestData(compressed, feed_block_size, output_block_size,
|
| - filter.get(), &output));
|
| + EXPECT_FALSE(FilterTestData(
|
| + compressed, feed_block_size, output_block_size, filter.get(), &output));
|
| }
|
|
|
| TEST_F(SdchFilterTest, CanStillDecodeHttp) {
|
| @@ -599,8 +594,8 @@ TEST_F(SdchFilterTest, CanStillDecodeHttp) {
|
| const size_t output_block_size(100);
|
| std::string output;
|
|
|
| - EXPECT_TRUE(FilterTestData(compressed, feed_block_size, output_block_size,
|
| - filter.get(), &output));
|
| + EXPECT_TRUE(FilterTestData(
|
| + compressed, feed_block_size, output_block_size, filter.get(), &output));
|
| }
|
|
|
| TEST_F(SdchFilterTest, CrossDomainDictionaryUse) {
|
| @@ -623,13 +618,13 @@ TEST_F(SdchFilterTest, CrossDomainDictionaryUse) {
|
| MockFilterContext filter_context;
|
| GURL wrong_domain_url("http://www.wrongdomain.com");
|
| filter_context.SetURL(wrong_domain_url);
|
| - scoped_ptr<Filter> filter(Filter::Factory(filter_types, filter_context));
|
| + scoped_ptr<Filter> filter(Filter::Factory(filter_types, filter_context));
|
|
|
| size_t feed_block_size = 100;
|
| size_t output_block_size = 100;
|
| std::string output;
|
| - EXPECT_FALSE(FilterTestData(compressed, feed_block_size, output_block_size,
|
| - filter.get(), &output));
|
| + EXPECT_FALSE(FilterTestData(
|
| + compressed, feed_block_size, output_block_size, filter.get(), &output));
|
| EXPECT_EQ(output.size(), 0u); // No output written.
|
|
|
| EXPECT_TRUE(SdchManager::Global()->IsInSupportedDomain(GURL(url_string)));
|
| @@ -668,8 +663,11 @@ TEST_F(SdchFilterTest, DictionaryPathValidation) {
|
| size_t output_block_size = 100;
|
| std::string output;
|
|
|
| - EXPECT_TRUE(FilterTestData(compressed_for_path, feed_block_size,
|
| - output_block_size, filter.get(), &output));
|
| + EXPECT_TRUE(FilterTestData(compressed_for_path,
|
| + feed_block_size,
|
| + output_block_size,
|
| + filter.get(),
|
| + &output));
|
| EXPECT_EQ(output, expanded_);
|
|
|
| // Test decode the path data, arriving from a invalid path.
|
| @@ -679,8 +677,11 @@ TEST_F(SdchFilterTest, DictionaryPathValidation) {
|
| feed_block_size = 100;
|
| output_block_size = 100;
|
| output.clear();
|
| - EXPECT_FALSE(FilterTestData(compressed_for_path, feed_block_size,
|
| - output_block_size, filter.get(), &output));
|
| + EXPECT_FALSE(FilterTestData(compressed_for_path,
|
| + feed_block_size,
|
| + output_block_size,
|
| + filter.get(),
|
| + &output));
|
| EXPECT_EQ(output.size(), 0u); // No output written.
|
|
|
| EXPECT_FALSE(SdchManager::Global()->IsInSupportedDomain(GURL(url_string)));
|
| @@ -698,14 +699,13 @@ TEST_F(SdchFilterTest, DictionaryPortValidation) {
|
| GURL url(url_string);
|
| EXPECT_TRUE(sdch_manager_->AddSdchDictionary(dictionary, url));
|
|
|
| -
|
| // Create a dictionary with a port restriction, by prefixing old dictionary.
|
| const std::string port("502");
|
| std::string dictionary_with_port("Port: " + port + "\n");
|
| dictionary_with_port.append("Port: 80\n"); // Add default port.
|
| dictionary_with_port.append(dictionary);
|
| EXPECT_TRUE(sdch_manager_->AddSdchDictionary(dictionary_with_port,
|
| - GURL(url_string + ":" + port)));
|
| + GURL(url_string + ":" + port)));
|
|
|
| std::string compressed_for_port(NewSdchCompressedData(dictionary_with_port));
|
|
|
| @@ -720,8 +720,11 @@ TEST_F(SdchFilterTest, DictionaryPortValidation) {
|
| size_t feed_block_size = 100;
|
| size_t output_block_size = 100;
|
| std::string output;
|
| - EXPECT_TRUE(FilterTestData(compressed_for_port, feed_block_size,
|
| - output_block_size, filter.get(), &output));
|
| + EXPECT_TRUE(FilterTestData(compressed_for_port,
|
| + feed_block_size,
|
| + output_block_size,
|
| + filter.get(),
|
| + &output));
|
| EXPECT_EQ(output, expanded_);
|
|
|
| // Test decode the port data, arriving from a valid (default) port.
|
| @@ -731,8 +734,11 @@ TEST_F(SdchFilterTest, DictionaryPortValidation) {
|
| feed_block_size = 100;
|
| output_block_size = 100;
|
| output.clear();
|
| - EXPECT_TRUE(FilterTestData(compressed_for_port, feed_block_size,
|
| - output_block_size, filter.get(), &output));
|
| + EXPECT_TRUE(FilterTestData(compressed_for_port,
|
| + feed_block_size,
|
| + output_block_size,
|
| + filter.get(),
|
| + &output));
|
| EXPECT_EQ(output, expanded_);
|
|
|
| // Test decode the port data, arriving from a invalid port.
|
| @@ -742,8 +748,11 @@ TEST_F(SdchFilterTest, DictionaryPortValidation) {
|
| feed_block_size = 100;
|
| output_block_size = 100;
|
| output.clear();
|
| - EXPECT_FALSE(FilterTestData(compressed_for_port, feed_block_size,
|
| - output_block_size, filter.get(), &output));
|
| + EXPECT_FALSE(FilterTestData(compressed_for_port,
|
| + feed_block_size,
|
| + output_block_size,
|
| + filter.get(),
|
| + &output));
|
| EXPECT_EQ(output.size(), 0u); // No output written.
|
|
|
| EXPECT_FALSE(SdchManager::Global()->IsInSupportedDomain(GURL(url_string)));
|
| @@ -754,13 +763,15 @@ TEST_F(SdchFilterTest, DictionaryPortValidation) {
|
| //------------------------------------------------------------------------------
|
| // Helper function to perform gzip compression of data.
|
|
|
| -static std::string gzip_compress(const std::string &input) {
|
| +static std::string gzip_compress(const std::string& input) {
|
| z_stream zlib_stream;
|
| memset(&zlib_stream, 0, sizeof(zlib_stream));
|
| int code;
|
|
|
| // Initialize zlib
|
| - code = deflateInit2(&zlib_stream, Z_DEFAULT_COMPRESSION, Z_DEFLATED,
|
| + code = deflateInit2(&zlib_stream,
|
| + Z_DEFAULT_COMPRESSION,
|
| + Z_DEFLATED,
|
| -MAX_WBITS,
|
| 8, // DEF_MEM_LEVEL
|
| Z_DEFAULT_STRATEGY);
|
| @@ -790,8 +801,8 @@ static std::string gzip_compress(const std::string &input) {
|
| // OS ???? Operating system indicator (255 means unknown)
|
| //
|
| // Header value we generate:
|
| - const char kGZipHeader[] = { '\037', '\213', '\010', '\000', '\000',
|
| - '\000', '\000', '\000', '\002', '\377' };
|
| + const char kGZipHeader[] = {'\037', '\213', '\010', '\000', '\000',
|
| + '\000', '\000', '\000', '\002', '\377'};
|
| CHECK_GT(zlib_stream.avail_out, sizeof(kGZipHeader));
|
| memcpy(zlib_stream.next_out, kGZipHeader, sizeof(kGZipHeader));
|
| zlib_stream.next_out += sizeof(kGZipHeader);
|
| @@ -810,7 +821,8 @@ static std::string gzip_compress(const std::string &input) {
|
| class SdchFilterChainingTest {
|
| public:
|
| static Filter* Factory(const std::vector<Filter::FilterType>& types,
|
| - const FilterContext& context, int size) {
|
| + const FilterContext& context,
|
| + int size) {
|
| return Filter::FactoryForTests(types, context, size);
|
| }
|
| };
|
| @@ -846,9 +858,8 @@ TEST_F(SdchFilterTest, FilterChaining) {
|
| CHECK_GT(kLargeInputBufferSize, expanded_.size());
|
| MockFilterContext filter_context;
|
| filter_context.SetURL(url);
|
| - scoped_ptr<Filter> filter(
|
| - SdchFilterChainingTest::Factory(filter_types, filter_context,
|
| - kLargeInputBufferSize));
|
| + scoped_ptr<Filter> filter(SdchFilterChainingTest::Factory(
|
| + filter_types, filter_context, kLargeInputBufferSize));
|
| EXPECT_EQ(static_cast<int>(kLargeInputBufferSize),
|
| filter->stream_buffer_size());
|
|
|
| @@ -862,8 +873,11 @@ TEST_F(SdchFilterTest, FilterChaining) {
|
| size_t feed_block_size = kLargeInputBufferSize;
|
| size_t output_block_size = kLargeInputBufferSize;
|
| std::string output;
|
| - EXPECT_TRUE(FilterTestData(gzip_compressed_sdch, feed_block_size,
|
| - output_block_size, filter.get(), &output));
|
| + EXPECT_TRUE(FilterTestData(gzip_compressed_sdch,
|
| + feed_block_size,
|
| + output_block_size,
|
| + filter.get(),
|
| + &output));
|
| EXPECT_EQ(output, expanded_);
|
|
|
| // Next try with a mid-sized internal buffer size.
|
| @@ -875,30 +889,35 @@ TEST_F(SdchFilterTest, FilterChaining) {
|
| // two filters more than once (that is why we multiply by 2).
|
| CHECK_LT(kMidSizedInputBufferSize * 2, sdch_compressed.size());
|
| filter_context.SetURL(url);
|
| - filter.reset(
|
| - SdchFilterChainingTest::Factory(filter_types, filter_context,
|
| - kMidSizedInputBufferSize));
|
| + filter.reset(SdchFilterChainingTest::Factory(
|
| + filter_types, filter_context, kMidSizedInputBufferSize));
|
| EXPECT_EQ(static_cast<int>(kMidSizedInputBufferSize),
|
| filter->stream_buffer_size());
|
|
|
| feed_block_size = kMidSizedInputBufferSize;
|
| output_block_size = kMidSizedInputBufferSize;
|
| output.clear();
|
| - EXPECT_TRUE(FilterTestData(gzip_compressed_sdch, feed_block_size,
|
| - output_block_size, filter.get(), &output));
|
| + EXPECT_TRUE(FilterTestData(gzip_compressed_sdch,
|
| + feed_block_size,
|
| + output_block_size,
|
| + filter.get(),
|
| + &output));
|
| EXPECT_EQ(output, expanded_);
|
|
|
| // Next try with a tiny input and output buffer to cover edge effects.
|
| - filter.reset(SdchFilterChainingTest::Factory(filter_types, filter_context,
|
| - kLargeInputBufferSize));
|
| + filter.reset(SdchFilterChainingTest::Factory(
|
| + filter_types, filter_context, kLargeInputBufferSize));
|
| EXPECT_EQ(static_cast<int>(kLargeInputBufferSize),
|
| filter->stream_buffer_size());
|
|
|
| feed_block_size = 1;
|
| output_block_size = 1;
|
| output.clear();
|
| - EXPECT_TRUE(FilterTestData(gzip_compressed_sdch, feed_block_size,
|
| - output_block_size, filter.get(), &output));
|
| + EXPECT_TRUE(FilterTestData(gzip_compressed_sdch,
|
| + feed_block_size,
|
| + output_block_size,
|
| + filter.get(),
|
| + &output));
|
| EXPECT_EQ(output, expanded_);
|
| }
|
|
|
| @@ -934,7 +953,6 @@ TEST_F(SdchFilterTest, DefaultGzipIfSdch) {
|
| filter_context.SetURL(url);
|
| scoped_ptr<Filter> filter(Filter::Factory(filter_types, filter_context));
|
|
|
| -
|
| // Verify that chained filter is waiting for data.
|
| char tiny_output_buffer[10];
|
| int tiny_output_size = sizeof(tiny_output_buffer);
|
| @@ -944,8 +962,11 @@ TEST_F(SdchFilterTest, DefaultGzipIfSdch) {
|
| size_t feed_block_size = 100;
|
| size_t output_block_size = 100;
|
| std::string output;
|
| - EXPECT_TRUE(FilterTestData(gzip_compressed_sdch, feed_block_size,
|
| - output_block_size, filter.get(), &output));
|
| + EXPECT_TRUE(FilterTestData(gzip_compressed_sdch,
|
| + feed_block_size,
|
| + output_block_size,
|
| + filter.get(),
|
| + &output));
|
| EXPECT_EQ(output, expanded_);
|
|
|
| // Next try with a tiny buffer to cover edge effects.
|
| @@ -954,8 +975,11 @@ TEST_F(SdchFilterTest, DefaultGzipIfSdch) {
|
| feed_block_size = 1;
|
| output_block_size = 1;
|
| output.clear();
|
| - EXPECT_TRUE(FilterTestData(gzip_compressed_sdch, feed_block_size,
|
| - output_block_size, filter.get(), &output));
|
| + EXPECT_TRUE(FilterTestData(gzip_compressed_sdch,
|
| + feed_block_size,
|
| + output_block_size,
|
| + filter.get(),
|
| + &output));
|
| EXPECT_EQ(output, expanded_);
|
| }
|
|
|
| @@ -994,7 +1018,6 @@ TEST_F(SdchFilterTest, AcceptGzipSdchIfGzip) {
|
| filter_context.SetURL(url);
|
| scoped_ptr<Filter> filter(Filter::Factory(filter_types, filter_context));
|
|
|
| -
|
| // Verify that chained filter is waiting for data.
|
| char tiny_output_buffer[10];
|
| int tiny_output_size = sizeof(tiny_output_buffer);
|
| @@ -1004,8 +1027,11 @@ TEST_F(SdchFilterTest, AcceptGzipSdchIfGzip) {
|
| size_t feed_block_size = 100;
|
| size_t output_block_size = 100;
|
| std::string output;
|
| - EXPECT_TRUE(FilterTestData(gzip_compressed_sdch, feed_block_size,
|
| - output_block_size, filter.get(), &output));
|
| + EXPECT_TRUE(FilterTestData(gzip_compressed_sdch,
|
| + feed_block_size,
|
| + output_block_size,
|
| + filter.get(),
|
| + &output));
|
| EXPECT_EQ(output, expanded_);
|
|
|
| // Next try with a tiny buffer to cover edge effects.
|
| @@ -1014,8 +1040,11 @@ TEST_F(SdchFilterTest, AcceptGzipSdchIfGzip) {
|
| feed_block_size = 1;
|
| output_block_size = 1;
|
| output.clear();
|
| - EXPECT_TRUE(FilterTestData(gzip_compressed_sdch, feed_block_size,
|
| - output_block_size, filter.get(), &output));
|
| + EXPECT_TRUE(FilterTestData(gzip_compressed_sdch,
|
| + feed_block_size,
|
| + output_block_size,
|
| + filter.get(),
|
| + &output));
|
| EXPECT_EQ(output, expanded_);
|
| }
|
|
|
| @@ -1051,7 +1080,6 @@ TEST_F(SdchFilterTest, DefaultSdchGzipIfEmpty) {
|
| filter_context.SetURL(url);
|
| scoped_ptr<Filter> filter(Filter::Factory(filter_types, filter_context));
|
|
|
| -
|
| // Verify that chained filter is waiting for data.
|
| char tiny_output_buffer[10];
|
| int tiny_output_size = sizeof(tiny_output_buffer);
|
| @@ -1061,8 +1089,11 @@ TEST_F(SdchFilterTest, DefaultSdchGzipIfEmpty) {
|
| size_t feed_block_size = 100;
|
| size_t output_block_size = 100;
|
| std::string output;
|
| - EXPECT_TRUE(FilterTestData(gzip_compressed_sdch, feed_block_size,
|
| - output_block_size, filter.get(), &output));
|
| + EXPECT_TRUE(FilterTestData(gzip_compressed_sdch,
|
| + feed_block_size,
|
| + output_block_size,
|
| + filter.get(),
|
| + &output));
|
| EXPECT_EQ(output, expanded_);
|
|
|
| // Next try with a tiny buffer to cover edge effects.
|
| @@ -1071,8 +1102,11 @@ TEST_F(SdchFilterTest, DefaultSdchGzipIfEmpty) {
|
| feed_block_size = 1;
|
| output_block_size = 1;
|
| output.clear();
|
| - EXPECT_TRUE(FilterTestData(gzip_compressed_sdch, feed_block_size,
|
| - output_block_size, filter.get(), &output));
|
| + EXPECT_TRUE(FilterTestData(gzip_compressed_sdch,
|
| + feed_block_size,
|
| + output_block_size,
|
| + filter.get(),
|
| + &output));
|
| EXPECT_EQ(output, expanded_);
|
| }
|
|
|
| @@ -1092,8 +1126,8 @@ TEST_F(SdchFilterTest, AcceptGzipGzipSdchIfGzip) {
|
| // encoding of merely gzip (apparently, only listing the extra level of
|
| // wrapper compression they added, but discarding the actual content encoding.
|
| // Use Gzip to double compress the sdch sdch_compressed data.
|
| - std::string double_gzip_compressed_sdch = gzip_compress(gzip_compress(
|
| - sdch_compressed));
|
| + std::string double_gzip_compressed_sdch =
|
| + gzip_compress(gzip_compress(sdch_compressed));
|
|
|
| // Only claim to have gzip content, but really use the double gzipped sdch
|
| // content.
|
| @@ -1123,8 +1157,11 @@ TEST_F(SdchFilterTest, AcceptGzipGzipSdchIfGzip) {
|
| size_t feed_block_size = 100;
|
| size_t output_block_size = 100;
|
| std::string output;
|
| - EXPECT_TRUE(FilterTestData(double_gzip_compressed_sdch, feed_block_size,
|
| - output_block_size, filter.get(), &output));
|
| + EXPECT_TRUE(FilterTestData(double_gzip_compressed_sdch,
|
| + feed_block_size,
|
| + output_block_size,
|
| + filter.get(),
|
| + &output));
|
| EXPECT_EQ(output, expanded_);
|
|
|
| // Next try with a tiny buffer to cover edge effects.
|
| @@ -1133,8 +1170,11 @@ TEST_F(SdchFilterTest, AcceptGzipGzipSdchIfGzip) {
|
| feed_block_size = 1;
|
| output_block_size = 1;
|
| output.clear();
|
| - EXPECT_TRUE(FilterTestData(double_gzip_compressed_sdch, feed_block_size,
|
| - output_block_size, filter.get(), &output));
|
| + EXPECT_TRUE(FilterTestData(double_gzip_compressed_sdch,
|
| + feed_block_size,
|
| + output_block_size,
|
| + filter.get(),
|
| + &output));
|
| EXPECT_EQ(output, expanded_);
|
| }
|
|
|
|
|