| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "net/filter/sdch_filter.h" |
| 6 |
| 5 #include <limits.h> | 7 #include <limits.h> |
| 6 | 8 |
| 7 #include <algorithm> | 9 #include <algorithm> |
| 10 #include <memory> |
| 8 #include <string> | 11 #include <string> |
| 9 #include <vector> | 12 #include <vector> |
| 10 | 13 |
| 11 #include "base/bit_cast.h" | 14 #include "base/bit_cast.h" |
| 12 #include "base/logging.h" | 15 #include "base/logging.h" |
| 13 #include "base/macros.h" | 16 #include "base/macros.h" |
| 14 #include "base/memory/scoped_ptr.h" | |
| 15 #include "base/test/histogram_tester.h" | 17 #include "base/test/histogram_tester.h" |
| 16 #include "base/test/simple_test_clock.h" | 18 #include "base/test/simple_test_clock.h" |
| 17 #include "net/base/io_buffer.h" | 19 #include "net/base/io_buffer.h" |
| 18 #include "net/base/sdch_dictionary.h" | 20 #include "net/base/sdch_dictionary.h" |
| 19 #include "net/base/sdch_manager.h" | 21 #include "net/base/sdch_manager.h" |
| 20 #include "net/base/sdch_observer.h" | 22 #include "net/base/sdch_observer.h" |
| 21 #include "net/filter/mock_filter_context.h" | 23 #include "net/filter/mock_filter_context.h" |
| 22 #include "net/filter/sdch_filter.h" | |
| 23 #include "net/url_request/url_request_context.h" | 24 #include "net/url_request/url_request_context.h" |
| 24 #include "net/url_request/url_request_http_job.h" | 25 #include "net/url_request/url_request_http_job.h" |
| 25 #include "testing/gtest/include/gtest/gtest.h" | 26 #include "testing/gtest/include/gtest/gtest.h" |
| 26 #include "third_party/zlib/zlib.h" | 27 #include "third_party/zlib/zlib.h" |
| 27 | 28 |
| 28 namespace net { | 29 namespace net { |
| 29 | 30 |
| 30 //------------------------------------------------------------------------------ | 31 //------------------------------------------------------------------------------ |
| 31 // Provide sample data and compression results with a sample VCDIFF dictionary. | 32 // Provide sample data and compression results with a sample VCDIFF dictionary. |
| 32 // Note an SDCH dictionary has extra meta-data before the VCDIFF dictionary. | 33 // Note an SDCH dictionary has extra meta-data before the VCDIFF dictionary. |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 95 std::string compressed(server_hash); | 96 std::string compressed(server_hash); |
| 96 compressed.append("\0", 1); | 97 compressed.append("\0", 1); |
| 97 compressed.append(vcdiff_compressed_data_); | 98 compressed.append(vcdiff_compressed_data_); |
| 98 return compressed; | 99 return compressed; |
| 99 } | 100 } |
| 100 | 101 |
| 101 const std::string test_vcdiff_dictionary_; | 102 const std::string test_vcdiff_dictionary_; |
| 102 const std::string vcdiff_compressed_data_; | 103 const std::string vcdiff_compressed_data_; |
| 103 const std::string expanded_; // Desired final, decompressed data. | 104 const std::string expanded_; // Desired final, decompressed data. |
| 104 | 105 |
| 105 scoped_ptr<SdchManager> sdch_manager_; | 106 std::unique_ptr<SdchManager> sdch_manager_; |
| 106 scoped_ptr<MockFilterContext> filter_context_; | 107 std::unique_ptr<MockFilterContext> filter_context_; |
| 107 }; | 108 }; |
| 108 | 109 |
| 109 TEST_F(SdchFilterTest, Hashing) { | 110 TEST_F(SdchFilterTest, Hashing) { |
| 110 std::string client_hash, server_hash; | 111 std::string client_hash, server_hash; |
| 111 std::string dictionary("test contents"); | 112 std::string dictionary("test contents"); |
| 112 SdchManager::GenerateHash(dictionary, &client_hash, &server_hash); | 113 SdchManager::GenerateHash(dictionary, &client_hash, &server_hash); |
| 113 | 114 |
| 114 EXPECT_EQ(client_hash, "lMQBjS3P"); | 115 EXPECT_EQ(client_hash, "lMQBjS3P"); |
| 115 EXPECT_EQ(server_hash, "MyciMVll"); | 116 EXPECT_EQ(server_hash, "MyciMVll"); |
| 116 } | 117 } |
| 117 | 118 |
| 118 //------------------------------------------------------------------------------ | 119 //------------------------------------------------------------------------------ |
| 119 // Provide a generic helper function for trying to filter data. | 120 // Provide a generic helper function for trying to filter data. |
| 120 // This function repeatedly calls the filter to process data, until the entire | 121 // This function repeatedly calls the filter to process data, until the entire |
| 121 // source is consumed. The return value from the filter is appended to output. | 122 // source is consumed. The return value from the filter is appended to output. |
| 122 // This allows us to vary input and output block sizes in order to test for edge | 123 // This allows us to vary input and output block sizes in order to test for edge |
| 123 // effects (boundary effects?) during the filtering process. | 124 // effects (boundary effects?) during the filtering process. |
| 124 // This function provides data to the filter in blocks of no-more-than the | 125 // This function provides data to the filter in blocks of no-more-than the |
| 125 // specified input_block_length. It allows the filter to fill no more than | 126 // specified input_block_length. It allows the filter to fill no more than |
| 126 // output_buffer_length in any one call to proccess (a.k.a., Read) data, and | 127 // output_buffer_length in any one call to proccess (a.k.a., Read) data, and |
| 127 // concatenates all these little output blocks into the singular output string. | 128 // concatenates all these little output blocks into the singular output string. |
| 128 static bool FilterTestData(const std::string& source, | 129 static bool FilterTestData(const std::string& source, |
| 129 size_t input_block_length, | 130 size_t input_block_length, |
| 130 const size_t output_buffer_length, | 131 const size_t output_buffer_length, |
| 131 Filter* filter, std::string* output) { | 132 Filter* filter, std::string* output) { |
| 132 CHECK_GT(input_block_length, 0u); | 133 CHECK_GT(input_block_length, 0u); |
| 133 Filter::FilterStatus status(Filter::FILTER_NEED_MORE_DATA); | 134 Filter::FilterStatus status(Filter::FILTER_NEED_MORE_DATA); |
| 134 size_t source_index = 0; | 135 size_t source_index = 0; |
| 135 scoped_ptr<char[]> output_buffer(new char[output_buffer_length]); | 136 std::unique_ptr<char[]> output_buffer(new char[output_buffer_length]); |
| 136 size_t input_amount = std::min(input_block_length, | 137 size_t input_amount = std::min(input_block_length, |
| 137 static_cast<size_t>(filter->stream_buffer_size())); | 138 static_cast<size_t>(filter->stream_buffer_size())); |
| 138 | 139 |
| 139 do { | 140 do { |
| 140 int copy_amount = std::min(input_amount, source.size() - source_index); | 141 int copy_amount = std::min(input_amount, source.size() - source_index); |
| 141 if (copy_amount > 0 && status == Filter::FILTER_NEED_MORE_DATA) { | 142 if (copy_amount > 0 && status == Filter::FILTER_NEED_MORE_DATA) { |
| 142 memcpy(filter->stream_buffer()->data(), source.data() + source_index, | 143 memcpy(filter->stream_buffer()->data(), source.data() + source_index, |
| 143 copy_amount); | 144 copy_amount); |
| 144 filter->FlushStreamBuffer(copy_amount); | 145 filter->FlushStreamBuffer(copy_amount); |
| 145 source_index += copy_amount; | 146 source_index += copy_amount; |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 181 dictionary.append(kTestVcdiffDictionary, sizeof(kTestVcdiffDictionary) - 1); | 182 dictionary.append(kTestVcdiffDictionary, sizeof(kTestVcdiffDictionary) - 1); |
| 182 return dictionary; | 183 return dictionary; |
| 183 } | 184 } |
| 184 | 185 |
| 185 TEST_F(SdchFilterTest, EmptyInputOk) { | 186 TEST_F(SdchFilterTest, EmptyInputOk) { |
| 186 std::vector<Filter::FilterType> filter_types; | 187 std::vector<Filter::FilterType> filter_types; |
| 187 filter_types.push_back(Filter::FILTER_TYPE_SDCH); | 188 filter_types.push_back(Filter::FILTER_TYPE_SDCH); |
| 188 char output_buffer[20]; | 189 char output_buffer[20]; |
| 189 std::string url_string("http://ignore.com"); | 190 std::string url_string("http://ignore.com"); |
| 190 filter_context()->SetURL(GURL(url_string)); | 191 filter_context()->SetURL(GURL(url_string)); |
| 191 scoped_ptr<Filter> filter(Filter::Factory(filter_types, *filter_context())); | 192 std::unique_ptr<Filter> filter( |
| 193 Filter::Factory(filter_types, *filter_context())); |
| 192 | 194 |
| 193 // With no input data, try to read output. | 195 // With no input data, try to read output. |
| 194 int output_bytes_or_buffer_size = sizeof(output_buffer); | 196 int output_bytes_or_buffer_size = sizeof(output_buffer); |
| 195 Filter::FilterStatus status = filter->ReadData(output_buffer, | 197 Filter::FilterStatus status = filter->ReadData(output_buffer, |
| 196 &output_bytes_or_buffer_size); | 198 &output_bytes_or_buffer_size); |
| 197 | 199 |
| 198 EXPECT_EQ(0, output_bytes_or_buffer_size); | 200 EXPECT_EQ(0, output_bytes_or_buffer_size); |
| 199 EXPECT_EQ(Filter::FILTER_NEED_MORE_DATA, status); | 201 EXPECT_EQ(Filter::FILTER_NEED_MORE_DATA, status); |
| 200 } | 202 } |
| 201 | 203 |
| 202 // Make sure that the filter context has everything that might be | 204 // Make sure that the filter context has everything that might be |
| 203 // nuked from it during URLRequest teardown before the SdchFilter | 205 // nuked from it during URLRequest teardown before the SdchFilter |
| 204 // destructor. | 206 // destructor. |
| 205 TEST_F(SdchFilterTest, SparseContextOk) { | 207 TEST_F(SdchFilterTest, SparseContextOk) { |
| 206 std::vector<Filter::FilterType> filter_types; | 208 std::vector<Filter::FilterType> filter_types; |
| 207 filter_types.push_back(Filter::FILTER_TYPE_SDCH); | 209 filter_types.push_back(Filter::FILTER_TYPE_SDCH); |
| 208 char output_buffer[20]; | 210 char output_buffer[20]; |
| 209 std::string url_string("http://ignore.com"); | 211 std::string url_string("http://ignore.com"); |
| 210 filter_context()->SetURL(GURL(url_string)); | 212 filter_context()->SetURL(GURL(url_string)); |
| 211 scoped_ptr<Filter> filter(Filter::Factory(filter_types, *filter_context())); | 213 std::unique_ptr<Filter> filter( |
| 214 Filter::Factory(filter_types, *filter_context())); |
| 212 | 215 |
| 213 // With no input data, try to read output. | 216 // With no input data, try to read output. |
| 214 int output_bytes_or_buffer_size = sizeof(output_buffer); | 217 int output_bytes_or_buffer_size = sizeof(output_buffer); |
| 215 Filter::FilterStatus status = filter->ReadData(output_buffer, | 218 Filter::FilterStatus status = filter->ReadData(output_buffer, |
| 216 &output_bytes_or_buffer_size); | 219 &output_bytes_or_buffer_size); |
| 217 | 220 |
| 218 EXPECT_EQ(0, output_bytes_or_buffer_size); | 221 EXPECT_EQ(0, output_bytes_or_buffer_size); |
| 219 EXPECT_EQ(Filter::FILTER_NEED_MORE_DATA, status); | 222 EXPECT_EQ(Filter::FILTER_NEED_MORE_DATA, status); |
| 220 | 223 |
| 221 // Partially tear down context. Anything that goes through request() | 224 // Partially tear down context. Anything that goes through request() |
| 222 // without checking it for null in the URLRequestJob::HttpFilterContext | 225 // without checking it for null in the URLRequestJob::HttpFilterContext |
| 223 // implementation is suspect. Everything that does check it for null should | 226 // implementation is suspect. Everything that does check it for null should |
| 224 // return null. This is to test for incorrectly relying on filter_context() | 227 // return null. This is to test for incorrectly relying on filter_context() |
| 225 // from the SdchFilter destructor. | 228 // from the SdchFilter destructor. |
| 226 filter_context()->NukeUnstableInterfaces(); | 229 filter_context()->NukeUnstableInterfaces(); |
| 227 } | 230 } |
| 228 | 231 |
| 229 TEST_F(SdchFilterTest, PassThroughWhenTentative) { | 232 TEST_F(SdchFilterTest, PassThroughWhenTentative) { |
| 230 std::vector<Filter::FilterType> filter_types; | 233 std::vector<Filter::FilterType> filter_types; |
| 231 // Selective a tentative filter (which can fall back to pass through). | 234 // Selective a tentative filter (which can fall back to pass through). |
| 232 filter_types.push_back(Filter::FILTER_TYPE_GZIP_HELPING_SDCH); | 235 filter_types.push_back(Filter::FILTER_TYPE_GZIP_HELPING_SDCH); |
| 233 char output_buffer[20]; | 236 char output_buffer[20]; |
| 234 // Response code needs to be 200 to allow a pass through. | 237 // Response code needs to be 200 to allow a pass through. |
| 235 filter_context()->SetResponseCode(200); | 238 filter_context()->SetResponseCode(200); |
| 236 std::string url_string("http://ignore.com"); | 239 std::string url_string("http://ignore.com"); |
| 237 filter_context()->SetURL(GURL(url_string)); | 240 filter_context()->SetURL(GURL(url_string)); |
| 238 scoped_ptr<Filter> filter(Filter::Factory(filter_types, *filter_context())); | 241 std::unique_ptr<Filter> filter( |
| 242 Filter::Factory(filter_types, *filter_context())); |
| 239 | 243 |
| 240 // Supply enough data to force a pass-through mode.. | 244 // Supply enough data to force a pass-through mode.. |
| 241 std::string non_gzip_content("not GZIPed data"); | 245 std::string non_gzip_content("not GZIPed data"); |
| 242 | 246 |
| 243 char* input_buffer = filter->stream_buffer()->data(); | 247 char* input_buffer = filter->stream_buffer()->data(); |
| 244 int input_buffer_size = filter->stream_buffer_size(); | 248 int input_buffer_size = filter->stream_buffer_size(); |
| 245 | 249 |
| 246 EXPECT_LT(static_cast<int>(non_gzip_content.size()), | 250 EXPECT_LT(static_cast<int>(non_gzip_content.size()), |
| 247 input_buffer_size); | 251 input_buffer_size); |
| 248 memcpy(input_buffer, non_gzip_content.data(), | 252 memcpy(input_buffer, non_gzip_content.data(), |
| (...skipping 18 matching lines...) Expand all Loading... |
| 267 std::vector<Filter::FilterType> filter_types; | 271 std::vector<Filter::FilterType> filter_types; |
| 268 // Selective a tentative filter (which can fall back to pass through). | 272 // Selective a tentative filter (which can fall back to pass through). |
| 269 filter_types.push_back(Filter::FILTER_TYPE_SDCH_POSSIBLE); | 273 filter_types.push_back(Filter::FILTER_TYPE_SDCH_POSSIBLE); |
| 270 char output_buffer[20]; | 274 char output_buffer[20]; |
| 271 // Response code needs to be 200 to allow a pass through. | 275 // Response code needs to be 200 to allow a pass through. |
| 272 filter_context()->SetResponseCode(403); | 276 filter_context()->SetResponseCode(403); |
| 273 // Meta refresh will only appear for html content | 277 // Meta refresh will only appear for html content |
| 274 filter_context()->SetMimeType("text/html"); | 278 filter_context()->SetMimeType("text/html"); |
| 275 std::string url_string("http://ignore.com"); | 279 std::string url_string("http://ignore.com"); |
| 276 filter_context()->SetURL(GURL(url_string)); | 280 filter_context()->SetURL(GURL(url_string)); |
| 277 scoped_ptr<Filter> filter(Filter::Factory(filter_types, *filter_context())); | 281 std::unique_ptr<Filter> filter( |
| 282 Filter::Factory(filter_types, *filter_context())); |
| 278 | 283 |
| 279 // Supply enough data to force a pass-through mode, which means we have | 284 // Supply enough data to force a pass-through mode, which means we have |
| 280 // provided more than 9 characters that can't be a dictionary hash. | 285 // provided more than 9 characters that can't be a dictionary hash. |
| 281 std::string non_sdch_content("This is not SDCH"); | 286 std::string non_sdch_content("This is not SDCH"); |
| 282 | 287 |
| 283 char* input_buffer = filter->stream_buffer()->data(); | 288 char* input_buffer = filter->stream_buffer()->data(); |
| 284 int input_buffer_size = filter->stream_buffer_size(); | 289 int input_buffer_size = filter->stream_buffer_size(); |
| 285 | 290 |
| 286 EXPECT_LT(static_cast<int>(non_sdch_content.size()), | 291 EXPECT_LT(static_cast<int>(non_sdch_content.size()), |
| 287 input_buffer_size); | 292 input_buffer_size); |
| (...skipping 20 matching lines...) Expand all Loading... |
| 308 // Selective a tentative filter (which can fall back to pass through). | 313 // Selective a tentative filter (which can fall back to pass through). |
| 309 filter_types.push_back(Filter::FILTER_TYPE_SDCH_POSSIBLE); | 314 filter_types.push_back(Filter::FILTER_TYPE_SDCH_POSSIBLE); |
| 310 char output_buffer[20]; | 315 char output_buffer[20]; |
| 311 // Response code needs to be 200 to allow a pass through. | 316 // Response code needs to be 200 to allow a pass through. |
| 312 filter_context()->SetResponseCode(403); | 317 filter_context()->SetResponseCode(403); |
| 313 // Meta refresh will only appear for html content, so set to something else | 318 // Meta refresh will only appear for html content, so set to something else |
| 314 // to induce an error (we can't meta refresh). | 319 // to induce an error (we can't meta refresh). |
| 315 filter_context()->SetMimeType("anything"); | 320 filter_context()->SetMimeType("anything"); |
| 316 std::string url_string("http://ignore.com"); | 321 std::string url_string("http://ignore.com"); |
| 317 filter_context()->SetURL(GURL(url_string)); | 322 filter_context()->SetURL(GURL(url_string)); |
| 318 scoped_ptr<Filter> filter(Filter::Factory(filter_types, *filter_context())); | 323 std::unique_ptr<Filter> filter( |
| 324 Filter::Factory(filter_types, *filter_context())); |
| 319 | 325 |
| 320 // Supply enough data to force a pass-through mode, which means we have | 326 // Supply enough data to force a pass-through mode, which means we have |
| 321 // provided more than 9 characters that can't be a dictionary hash. | 327 // provided more than 9 characters that can't be a dictionary hash. |
| 322 std::string non_sdch_content("This is not SDCH"); | 328 std::string non_sdch_content("This is not SDCH"); |
| 323 | 329 |
| 324 char* input_buffer = filter->stream_buffer()->data(); | 330 char* input_buffer = filter->stream_buffer()->data(); |
| 325 int input_buffer_size = filter->stream_buffer_size(); | 331 int input_buffer_size = filter->stream_buffer_size(); |
| 326 | 332 |
| 327 EXPECT_LT(static_cast<int>(non_sdch_content.size()), | 333 EXPECT_LT(static_cast<int>(non_sdch_content.size()), |
| 328 input_buffer_size); | 334 input_buffer_size); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 343 std::vector<Filter::FilterType> filter_types; | 349 std::vector<Filter::FilterType> filter_types; |
| 344 // Selective a tentative filter (which can fall back to pass through). | 350 // Selective a tentative filter (which can fall back to pass through). |
| 345 filter_types.push_back(Filter::FILTER_TYPE_SDCH_POSSIBLE); | 351 filter_types.push_back(Filter::FILTER_TYPE_SDCH_POSSIBLE); |
| 346 char output_buffer[20]; | 352 char output_buffer[20]; |
| 347 // Response code needs to be 200 to allow a pass through. | 353 // Response code needs to be 200 to allow a pass through. |
| 348 filter_context()->SetResponseCode(403); | 354 filter_context()->SetResponseCode(403); |
| 349 // Meta refresh will only appear for html content | 355 // Meta refresh will only appear for html content |
| 350 filter_context()->SetMimeType("text/html"); | 356 filter_context()->SetMimeType("text/html"); |
| 351 std::string url_string("http://ignore.com"); | 357 std::string url_string("http://ignore.com"); |
| 352 filter_context()->SetURL(GURL(url_string)); | 358 filter_context()->SetURL(GURL(url_string)); |
| 353 scoped_ptr<Filter> filter(Filter::Factory(filter_types, *filter_context())); | 359 std::unique_ptr<Filter> filter( |
| 360 Filter::Factory(filter_types, *filter_context())); |
| 354 | 361 |
| 355 // Supply enough data to force a pass-through mode, which means we have | 362 // Supply enough data to force a pass-through mode, which means we have |
| 356 // provided more than 9 characters that can't be a dictionary hash. | 363 // provided more than 9 characters that can't be a dictionary hash. |
| 357 std::string non_sdch_content("This is not SDCH"); | 364 std::string non_sdch_content("This is not SDCH"); |
| 358 | 365 |
| 359 char* input_buffer = filter->stream_buffer()->data(); | 366 char* input_buffer = filter->stream_buffer()->data(); |
| 360 int input_buffer_size = filter->stream_buffer_size(); | 367 int input_buffer_size = filter->stream_buffer_size(); |
| 361 | 368 |
| 362 EXPECT_LT(static_cast<int>(non_sdch_content.size()), | 369 EXPECT_LT(static_cast<int>(non_sdch_content.size()), |
| 363 input_buffer_size); | 370 input_buffer_size); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 379 sizeof(output_buffer))); | 386 sizeof(output_buffer))); |
| 380 EXPECT_EQ(Filter::FILTER_OK, status); | 387 EXPECT_EQ(Filter::FILTER_OK, status); |
| 381 } | 388 } |
| 382 | 389 |
| 383 TEST_F(SdchFilterTest, BasicBadDictionary) { | 390 TEST_F(SdchFilterTest, BasicBadDictionary) { |
| 384 std::vector<Filter::FilterType> filter_types; | 391 std::vector<Filter::FilterType> filter_types; |
| 385 filter_types.push_back(Filter::FILTER_TYPE_SDCH); | 392 filter_types.push_back(Filter::FILTER_TYPE_SDCH); |
| 386 char output_buffer[20]; | 393 char output_buffer[20]; |
| 387 std::string url_string("http://ignore.com"); | 394 std::string url_string("http://ignore.com"); |
| 388 filter_context()->SetURL(GURL(url_string)); | 395 filter_context()->SetURL(GURL(url_string)); |
| 389 scoped_ptr<Filter> filter(Filter::Factory(filter_types, *filter_context())); | 396 std::unique_ptr<Filter> filter( |
| 397 Filter::Factory(filter_types, *filter_context())); |
| 390 | 398 |
| 391 // Supply bogus data (which doesn't yet specify a full dictionary hash). | 399 // Supply bogus data (which doesn't yet specify a full dictionary hash). |
| 392 // Dictionary hash is 8 characters followed by a null. | 400 // Dictionary hash is 8 characters followed by a null. |
| 393 std::string dictionary_hash_prefix("123"); | 401 std::string dictionary_hash_prefix("123"); |
| 394 | 402 |
| 395 char* input_buffer = filter->stream_buffer()->data(); | 403 char* input_buffer = filter->stream_buffer()->data(); |
| 396 int input_buffer_size = filter->stream_buffer_size(); | 404 int input_buffer_size = filter->stream_buffer_size(); |
| 397 | 405 |
| 398 EXPECT_LT(static_cast<int>(dictionary_hash_prefix.size()), | 406 EXPECT_LT(static_cast<int>(dictionary_hash_prefix.size()), |
| 399 input_buffer_size); | 407 input_buffer_size); |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 464 GURL url(url_string); | 472 GURL url(url_string); |
| 465 EXPECT_TRUE(AddSdchDictionary(dictionary, url)); | 473 EXPECT_TRUE(AddSdchDictionary(dictionary, url)); |
| 466 | 474 |
| 467 std::string compressed(NewSdchCompressedData(dictionary)); | 475 std::string compressed(NewSdchCompressedData(dictionary)); |
| 468 | 476 |
| 469 std::vector<Filter::FilterType> filter_types; | 477 std::vector<Filter::FilterType> filter_types; |
| 470 filter_types.push_back(Filter::FILTER_TYPE_SDCH); | 478 filter_types.push_back(Filter::FILTER_TYPE_SDCH); |
| 471 | 479 |
| 472 SetupFilterContextWithGURL(url); | 480 SetupFilterContextWithGURL(url); |
| 473 | 481 |
| 474 scoped_ptr<Filter> filter(Filter::Factory(filter_types, *filter_context())); | 482 std::unique_ptr<Filter> filter( |
| 483 Filter::Factory(filter_types, *filter_context())); |
| 475 | 484 |
| 476 size_t feed_block_size = 100; | 485 size_t feed_block_size = 100; |
| 477 size_t output_block_size = 100; | 486 size_t output_block_size = 100; |
| 478 std::string output; | 487 std::string output; |
| 479 EXPECT_TRUE(FilterTestData(compressed, feed_block_size, output_block_size, | 488 EXPECT_TRUE(FilterTestData(compressed, feed_block_size, output_block_size, |
| 480 filter.get(), &output)); | 489 filter.get(), &output)); |
| 481 EXPECT_EQ(output, expanded_); | 490 EXPECT_EQ(output, expanded_); |
| 482 | 491 |
| 483 // Decode with really small buffers (size 1) to check for edge effects. | 492 // Decode with really small buffers (size 1) to check for edge effects. |
| 484 filter.reset(Filter::Factory(filter_types, *filter_context())); | 493 filter.reset(Filter::Factory(filter_types, *filter_context())); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 501 GURL url(url_string); | 510 GURL url(url_string); |
| 502 EXPECT_TRUE(AddSdchDictionary(dictionary, url)); | 511 EXPECT_TRUE(AddSdchDictionary(dictionary, url)); |
| 503 | 512 |
| 504 std::string compressed(NewSdchCompressedData(dictionary)); | 513 std::string compressed(NewSdchCompressedData(dictionary)); |
| 505 | 514 |
| 506 std::vector<Filter::FilterType> filter_types; | 515 std::vector<Filter::FilterType> filter_types; |
| 507 filter_types.push_back(Filter::FILTER_TYPE_SDCH); | 516 filter_types.push_back(Filter::FILTER_TYPE_SDCH); |
| 508 | 517 |
| 509 GURL filter_context_gurl("https://" + kSampleDomain); | 518 GURL filter_context_gurl("https://" + kSampleDomain); |
| 510 SetupFilterContextWithGURL(GURL("https://" + kSampleDomain)); | 519 SetupFilterContextWithGURL(GURL("https://" + kSampleDomain)); |
| 511 scoped_ptr<Filter> filter(Filter::Factory(filter_types, *filter_context())); | 520 std::unique_ptr<Filter> filter( |
| 521 Filter::Factory(filter_types, *filter_context())); |
| 512 | 522 |
| 513 const size_t feed_block_size(100); | 523 const size_t feed_block_size(100); |
| 514 const size_t output_block_size(100); | 524 const size_t output_block_size(100); |
| 515 std::string output; | 525 std::string output; |
| 516 | 526 |
| 517 EXPECT_FALSE(FilterTestData(compressed, feed_block_size, output_block_size, | 527 EXPECT_FALSE(FilterTestData(compressed, feed_block_size, output_block_size, |
| 518 filter.get(), &output)); | 528 filter.get(), &output)); |
| 519 } | 529 } |
| 520 | 530 |
| 521 // Current failsafe TODO/hack refuses to decode any content that doesn't use | 531 // Current failsafe TODO/hack refuses to decode any content that doesn't use |
| 522 // http as the scheme (see use of DICTIONARY_SELECTED_FOR_NON_HTTP). | 532 // http as the scheme (see use of DICTIONARY_SELECTED_FOR_NON_HTTP). |
| 523 // The following tests this blockage. Note that blacklisting results, so we | 533 // The following tests this blockage. Note that blacklisting results, so we |
| 524 // we need separate tests for each of these. | 534 // we need separate tests for each of these. |
| 525 TEST_F(SdchFilterTest, NoDecodeFtp) { | 535 TEST_F(SdchFilterTest, NoDecodeFtp) { |
| 526 // Construct a valid SDCH dictionary from a VCDIFF dictionary. | 536 // Construct a valid SDCH dictionary from a VCDIFF dictionary. |
| 527 const std::string kSampleDomain = "sdchtest.com"; | 537 const std::string kSampleDomain = "sdchtest.com"; |
| 528 std::string dictionary(NewSdchDictionary(kSampleDomain)); | 538 std::string dictionary(NewSdchDictionary(kSampleDomain)); |
| 529 | 539 |
| 530 std::string url_string = "http://" + kSampleDomain; | 540 std::string url_string = "http://" + kSampleDomain; |
| 531 | 541 |
| 532 GURL url(url_string); | 542 GURL url(url_string); |
| 533 EXPECT_TRUE(AddSdchDictionary(dictionary, url)); | 543 EXPECT_TRUE(AddSdchDictionary(dictionary, url)); |
| 534 | 544 |
| 535 std::string compressed(NewSdchCompressedData(dictionary)); | 545 std::string compressed(NewSdchCompressedData(dictionary)); |
| 536 | 546 |
| 537 std::vector<Filter::FilterType> filter_types; | 547 std::vector<Filter::FilterType> filter_types; |
| 538 filter_types.push_back(Filter::FILTER_TYPE_SDCH); | 548 filter_types.push_back(Filter::FILTER_TYPE_SDCH); |
| 539 | 549 |
| 540 SetupFilterContextWithGURL(GURL("ftp://" + kSampleDomain)); | 550 SetupFilterContextWithGURL(GURL("ftp://" + kSampleDomain)); |
| 541 scoped_ptr<Filter> filter(Filter::Factory(filter_types, *filter_context())); | 551 std::unique_ptr<Filter> filter( |
| 552 Filter::Factory(filter_types, *filter_context())); |
| 542 | 553 |
| 543 const size_t feed_block_size(100); | 554 const size_t feed_block_size(100); |
| 544 const size_t output_block_size(100); | 555 const size_t output_block_size(100); |
| 545 std::string output; | 556 std::string output; |
| 546 | 557 |
| 547 EXPECT_FALSE(FilterTestData(compressed, feed_block_size, output_block_size, | 558 EXPECT_FALSE(FilterTestData(compressed, feed_block_size, output_block_size, |
| 548 filter.get(), &output)); | 559 filter.get(), &output)); |
| 549 } | 560 } |
| 550 | 561 |
| 551 TEST_F(SdchFilterTest, NoDecodeFileColon) { | 562 TEST_F(SdchFilterTest, NoDecodeFileColon) { |
| 552 // Construct a valid SDCH dictionary from a VCDIFF dictionary. | 563 // Construct a valid SDCH dictionary from a VCDIFF dictionary. |
| 553 const std::string kSampleDomain = "sdchtest.com"; | 564 const std::string kSampleDomain = "sdchtest.com"; |
| 554 std::string dictionary(NewSdchDictionary(kSampleDomain)); | 565 std::string dictionary(NewSdchDictionary(kSampleDomain)); |
| 555 | 566 |
| 556 std::string url_string = "http://" + kSampleDomain; | 567 std::string url_string = "http://" + kSampleDomain; |
| 557 | 568 |
| 558 GURL url(url_string); | 569 GURL url(url_string); |
| 559 EXPECT_TRUE(AddSdchDictionary(dictionary, url)); | 570 EXPECT_TRUE(AddSdchDictionary(dictionary, url)); |
| 560 | 571 |
| 561 std::string compressed(NewSdchCompressedData(dictionary)); | 572 std::string compressed(NewSdchCompressedData(dictionary)); |
| 562 | 573 |
| 563 std::vector<Filter::FilterType> filter_types; | 574 std::vector<Filter::FilterType> filter_types; |
| 564 filter_types.push_back(Filter::FILTER_TYPE_SDCH); | 575 filter_types.push_back(Filter::FILTER_TYPE_SDCH); |
| 565 | 576 |
| 566 SetupFilterContextWithGURL(GURL("file://" + kSampleDomain)); | 577 SetupFilterContextWithGURL(GURL("file://" + kSampleDomain)); |
| 567 scoped_ptr<Filter> filter(Filter::Factory(filter_types, *filter_context())); | 578 std::unique_ptr<Filter> filter( |
| 579 Filter::Factory(filter_types, *filter_context())); |
| 568 | 580 |
| 569 const size_t feed_block_size(100); | 581 const size_t feed_block_size(100); |
| 570 const size_t output_block_size(100); | 582 const size_t output_block_size(100); |
| 571 std::string output; | 583 std::string output; |
| 572 | 584 |
| 573 EXPECT_FALSE(FilterTestData(compressed, feed_block_size, output_block_size, | 585 EXPECT_FALSE(FilterTestData(compressed, feed_block_size, output_block_size, |
| 574 filter.get(), &output)); | 586 filter.get(), &output)); |
| 575 } | 587 } |
| 576 | 588 |
| 577 TEST_F(SdchFilterTest, NoDecodeAboutColon) { | 589 TEST_F(SdchFilterTest, NoDecodeAboutColon) { |
| 578 // Construct a valid SDCH dictionary from a VCDIFF dictionary. | 590 // Construct a valid SDCH dictionary from a VCDIFF dictionary. |
| 579 const std::string kSampleDomain = "sdchtest.com"; | 591 const std::string kSampleDomain = "sdchtest.com"; |
| 580 std::string dictionary(NewSdchDictionary(kSampleDomain)); | 592 std::string dictionary(NewSdchDictionary(kSampleDomain)); |
| 581 | 593 |
| 582 std::string url_string = "http://" + kSampleDomain; | 594 std::string url_string = "http://" + kSampleDomain; |
| 583 | 595 |
| 584 GURL url(url_string); | 596 GURL url(url_string); |
| 585 EXPECT_TRUE(AddSdchDictionary(dictionary, url)); | 597 EXPECT_TRUE(AddSdchDictionary(dictionary, url)); |
| 586 | 598 |
| 587 std::string compressed(NewSdchCompressedData(dictionary)); | 599 std::string compressed(NewSdchCompressedData(dictionary)); |
| 588 | 600 |
| 589 std::vector<Filter::FilterType> filter_types; | 601 std::vector<Filter::FilterType> filter_types; |
| 590 filter_types.push_back(Filter::FILTER_TYPE_SDCH); | 602 filter_types.push_back(Filter::FILTER_TYPE_SDCH); |
| 591 | 603 |
| 592 SetupFilterContextWithGURL(GURL("about://" + kSampleDomain)); | 604 SetupFilterContextWithGURL(GURL("about://" + kSampleDomain)); |
| 593 scoped_ptr<Filter> filter(Filter::Factory(filter_types, *filter_context())); | 605 std::unique_ptr<Filter> filter( |
| 606 Filter::Factory(filter_types, *filter_context())); |
| 594 | 607 |
| 595 const size_t feed_block_size(100); | 608 const size_t feed_block_size(100); |
| 596 const size_t output_block_size(100); | 609 const size_t output_block_size(100); |
| 597 std::string output; | 610 std::string output; |
| 598 | 611 |
| 599 EXPECT_FALSE(FilterTestData(compressed, feed_block_size, output_block_size, | 612 EXPECT_FALSE(FilterTestData(compressed, feed_block_size, output_block_size, |
| 600 filter.get(), &output)); | 613 filter.get(), &output)); |
| 601 } | 614 } |
| 602 | 615 |
| 603 TEST_F(SdchFilterTest, NoDecodeJavaScript) { | 616 TEST_F(SdchFilterTest, NoDecodeJavaScript) { |
| 604 // Construct a valid SDCH dictionary from a VCDIFF dictionary. | 617 // Construct a valid SDCH dictionary from a VCDIFF dictionary. |
| 605 const std::string kSampleDomain = "sdchtest.com"; | 618 const std::string kSampleDomain = "sdchtest.com"; |
| 606 std::string dictionary(NewSdchDictionary(kSampleDomain)); | 619 std::string dictionary(NewSdchDictionary(kSampleDomain)); |
| 607 | 620 |
| 608 std::string url_string = "http://" + kSampleDomain; | 621 std::string url_string = "http://" + kSampleDomain; |
| 609 | 622 |
| 610 GURL url(url_string); | 623 GURL url(url_string); |
| 611 EXPECT_TRUE(AddSdchDictionary(dictionary, url)); | 624 EXPECT_TRUE(AddSdchDictionary(dictionary, url)); |
| 612 | 625 |
| 613 std::string compressed(NewSdchCompressedData(dictionary)); | 626 std::string compressed(NewSdchCompressedData(dictionary)); |
| 614 | 627 |
| 615 std::vector<Filter::FilterType> filter_types; | 628 std::vector<Filter::FilterType> filter_types; |
| 616 filter_types.push_back(Filter::FILTER_TYPE_SDCH); | 629 filter_types.push_back(Filter::FILTER_TYPE_SDCH); |
| 617 | 630 |
| 618 SetupFilterContextWithGURL(GURL("javascript://" + kSampleDomain)); | 631 SetupFilterContextWithGURL(GURL("javascript://" + kSampleDomain)); |
| 619 scoped_ptr<Filter> filter(Filter::Factory(filter_types, *filter_context())); | 632 std::unique_ptr<Filter> filter( |
| 633 Filter::Factory(filter_types, *filter_context())); |
| 620 | 634 |
| 621 const size_t feed_block_size(100); | 635 const size_t feed_block_size(100); |
| 622 const size_t output_block_size(100); | 636 const size_t output_block_size(100); |
| 623 std::string output; | 637 std::string output; |
| 624 | 638 |
| 625 EXPECT_FALSE(FilterTestData(compressed, feed_block_size, output_block_size, | 639 EXPECT_FALSE(FilterTestData(compressed, feed_block_size, output_block_size, |
| 626 filter.get(), &output)); | 640 filter.get(), &output)); |
| 627 } | 641 } |
| 628 | 642 |
| 629 TEST_F(SdchFilterTest, CanStillDecodeHttp) { | 643 TEST_F(SdchFilterTest, CanStillDecodeHttp) { |
| 630 // Construct a valid SDCH dictionary from a VCDIFF dictionary. | 644 // Construct a valid SDCH dictionary from a VCDIFF dictionary. |
| 631 const std::string kSampleDomain = "sdchtest.com"; | 645 const std::string kSampleDomain = "sdchtest.com"; |
| 632 std::string dictionary(NewSdchDictionary(kSampleDomain)); | 646 std::string dictionary(NewSdchDictionary(kSampleDomain)); |
| 633 | 647 |
| 634 std::string url_string = "http://" + kSampleDomain; | 648 std::string url_string = "http://" + kSampleDomain; |
| 635 | 649 |
| 636 GURL url(url_string); | 650 GURL url(url_string); |
| 637 EXPECT_TRUE(AddSdchDictionary(dictionary, url)); | 651 EXPECT_TRUE(AddSdchDictionary(dictionary, url)); |
| 638 | 652 |
| 639 std::string compressed(NewSdchCompressedData(dictionary)); | 653 std::string compressed(NewSdchCompressedData(dictionary)); |
| 640 | 654 |
| 641 std::vector<Filter::FilterType> filter_types; | 655 std::vector<Filter::FilterType> filter_types; |
| 642 filter_types.push_back(Filter::FILTER_TYPE_SDCH); | 656 filter_types.push_back(Filter::FILTER_TYPE_SDCH); |
| 643 | 657 |
| 644 SetupFilterContextWithGURL(GURL("http://" + kSampleDomain)); | 658 SetupFilterContextWithGURL(GURL("http://" + kSampleDomain)); |
| 645 scoped_ptr<Filter> filter(Filter::Factory(filter_types, *filter_context())); | 659 std::unique_ptr<Filter> filter( |
| 660 Filter::Factory(filter_types, *filter_context())); |
| 646 | 661 |
| 647 const size_t feed_block_size(100); | 662 const size_t feed_block_size(100); |
| 648 const size_t output_block_size(100); | 663 const size_t output_block_size(100); |
| 649 std::string output; | 664 std::string output; |
| 650 | 665 |
| 651 base::HistogramTester tester; | 666 base::HistogramTester tester; |
| 652 | 667 |
| 653 EXPECT_TRUE(FilterTestData(compressed, feed_block_size, output_block_size, | 668 EXPECT_TRUE(FilterTestData(compressed, feed_block_size, output_block_size, |
| 654 filter.get(), &output)); | 669 filter.get(), &output)); |
| 655 // The filter's destructor is responsible for uploading total ratio | 670 // The filter's destructor is responsible for uploading total ratio |
| (...skipping 16 matching lines...) Expand all Loading... |
| 672 | 687 |
| 673 std::string compressed(NewSdchCompressedData(dictionary)); | 688 std::string compressed(NewSdchCompressedData(dictionary)); |
| 674 | 689 |
| 675 std::vector<Filter::FilterType> filter_types; | 690 std::vector<Filter::FilterType> filter_types; |
| 676 filter_types.push_back(Filter::FILTER_TYPE_SDCH); | 691 filter_types.push_back(Filter::FILTER_TYPE_SDCH); |
| 677 | 692 |
| 678 // Decode with content arriving from the "wrong" domain. | 693 // Decode with content arriving from the "wrong" domain. |
| 679 // This tests SdchManager::CanSet(). | 694 // This tests SdchManager::CanSet(). |
| 680 GURL wrong_domain_url("http://www.wrongdomain.com"); | 695 GURL wrong_domain_url("http://www.wrongdomain.com"); |
| 681 SetupFilterContextWithGURL(wrong_domain_url); | 696 SetupFilterContextWithGURL(wrong_domain_url); |
| 682 scoped_ptr<Filter> filter(Filter::Factory(filter_types, *filter_context())); | 697 std::unique_ptr<Filter> filter( |
| 698 Filter::Factory(filter_types, *filter_context())); |
| 683 | 699 |
| 684 size_t feed_block_size = 100; | 700 size_t feed_block_size = 100; |
| 685 size_t output_block_size = 100; | 701 size_t output_block_size = 100; |
| 686 std::string output; | 702 std::string output; |
| 687 EXPECT_FALSE(FilterTestData(compressed, feed_block_size, output_block_size, | 703 EXPECT_FALSE(FilterTestData(compressed, feed_block_size, output_block_size, |
| 688 filter.get(), &output)); | 704 filter.get(), &output)); |
| 689 EXPECT_EQ(output.size(), 0u); // No output written. | 705 EXPECT_EQ(output.size(), 0u); // No output written. |
| 690 | 706 |
| 691 EXPECT_EQ(SDCH_OK, sdch_manager_->IsInSupportedDomain(GURL(url_string))); | 707 EXPECT_EQ(SDCH_OK, sdch_manager_->IsInSupportedDomain(GURL(url_string))); |
| 692 EXPECT_EQ(SDCH_DOMAIN_BLACKLIST_INCLUDES_TARGET, | 708 EXPECT_EQ(SDCH_DOMAIN_BLACKLIST_INCLUDES_TARGET, |
| (...skipping 19 matching lines...) Expand all Loading... |
| 712 GURL url2(url_string + path); | 728 GURL url2(url_string + path); |
| 713 EXPECT_TRUE(AddSdchDictionary(dictionary_with_path, url2)); | 729 EXPECT_TRUE(AddSdchDictionary(dictionary_with_path, url2)); |
| 714 | 730 |
| 715 std::string compressed_for_path(NewSdchCompressedData(dictionary_with_path)); | 731 std::string compressed_for_path(NewSdchCompressedData(dictionary_with_path)); |
| 716 | 732 |
| 717 std::vector<Filter::FilterType> filter_types; | 733 std::vector<Filter::FilterType> filter_types; |
| 718 filter_types.push_back(Filter::FILTER_TYPE_SDCH); | 734 filter_types.push_back(Filter::FILTER_TYPE_SDCH); |
| 719 | 735 |
| 720 // Test decode the path data, arriving from a valid path. | 736 // Test decode the path data, arriving from a valid path. |
| 721 SetupFilterContextWithGURL(GURL(url_string + path)); | 737 SetupFilterContextWithGURL(GURL(url_string + path)); |
| 722 scoped_ptr<Filter> filter(Filter::Factory(filter_types, *filter_context())); | 738 std::unique_ptr<Filter> filter( |
| 739 Filter::Factory(filter_types, *filter_context())); |
| 723 | 740 |
| 724 size_t feed_block_size = 100; | 741 size_t feed_block_size = 100; |
| 725 size_t output_block_size = 100; | 742 size_t output_block_size = 100; |
| 726 std::string output; | 743 std::string output; |
| 727 | 744 |
| 728 EXPECT_TRUE(FilterTestData(compressed_for_path, feed_block_size, | 745 EXPECT_TRUE(FilterTestData(compressed_for_path, feed_block_size, |
| 729 output_block_size, filter.get(), &output)); | 746 output_block_size, filter.get(), &output)); |
| 730 EXPECT_EQ(output, expanded_); | 747 EXPECT_EQ(output, expanded_); |
| 731 | 748 |
| 732 // Test decode the path data, arriving from a invalid path. | 749 // Test decode the path data, arriving from a invalid path. |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 764 EXPECT_TRUE(AddSdchDictionary(dictionary_with_port, | 781 EXPECT_TRUE(AddSdchDictionary(dictionary_with_port, |
| 765 GURL(url_string + ":" + port))); | 782 GURL(url_string + ":" + port))); |
| 766 | 783 |
| 767 std::string compressed_for_port(NewSdchCompressedData(dictionary_with_port)); | 784 std::string compressed_for_port(NewSdchCompressedData(dictionary_with_port)); |
| 768 | 785 |
| 769 std::vector<Filter::FilterType> filter_types; | 786 std::vector<Filter::FilterType> filter_types; |
| 770 filter_types.push_back(Filter::FILTER_TYPE_SDCH); | 787 filter_types.push_back(Filter::FILTER_TYPE_SDCH); |
| 771 | 788 |
| 772 // Test decode the port data, arriving from a valid port. | 789 // Test decode the port data, arriving from a valid port. |
| 773 SetupFilterContextWithGURL(GURL(url_string + ":" + port)); | 790 SetupFilterContextWithGURL(GURL(url_string + ":" + port)); |
| 774 scoped_ptr<Filter> filter(Filter::Factory(filter_types, *filter_context())); | 791 std::unique_ptr<Filter> filter( |
| 792 Filter::Factory(filter_types, *filter_context())); |
| 775 | 793 |
| 776 size_t feed_block_size = 100; | 794 size_t feed_block_size = 100; |
| 777 size_t output_block_size = 100; | 795 size_t output_block_size = 100; |
| 778 std::string output; | 796 std::string output; |
| 779 EXPECT_TRUE(FilterTestData(compressed_for_port, feed_block_size, | 797 EXPECT_TRUE(FilterTestData(compressed_for_port, feed_block_size, |
| 780 output_block_size, filter.get(), &output)); | 798 output_block_size, filter.get(), &output)); |
| 781 EXPECT_EQ(output, expanded_); | 799 EXPECT_EQ(output, expanded_); |
| 782 | 800 |
| 783 // Test decode the port data, arriving from a valid (default) port. | 801 // Test decode the port data, arriving from a valid (default) port. |
| 784 SetupFilterContextWithGURL(GURL(url_string)); // Default port. | 802 SetupFilterContextWithGURL(GURL(url_string)); // Default port. |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 821 Z_DEFAULT_STRATEGY); | 839 Z_DEFAULT_STRATEGY); |
| 822 | 840 |
| 823 CHECK_EQ(Z_OK, code); | 841 CHECK_EQ(Z_OK, code); |
| 824 | 842 |
| 825 // Fill in zlib control block | 843 // Fill in zlib control block |
| 826 zlib_stream.next_in = bit_cast<Bytef*>(input.data()); | 844 zlib_stream.next_in = bit_cast<Bytef*>(input.data()); |
| 827 zlib_stream.avail_in = input.size(); | 845 zlib_stream.avail_in = input.size(); |
| 828 | 846 |
| 829 // Assume we can compress into similar buffer (add 100 bytes to be sure). | 847 // Assume we can compress into similar buffer (add 100 bytes to be sure). |
| 830 size_t gzip_compressed_length = zlib_stream.avail_in + 100; | 848 size_t gzip_compressed_length = zlib_stream.avail_in + 100; |
| 831 scoped_ptr<char[]> gzip_compressed(new char[gzip_compressed_length]); | 849 std::unique_ptr<char[]> gzip_compressed(new char[gzip_compressed_length]); |
| 832 zlib_stream.next_out = bit_cast<Bytef*>(gzip_compressed.get()); | 850 zlib_stream.next_out = bit_cast<Bytef*>(gzip_compressed.get()); |
| 833 zlib_stream.avail_out = gzip_compressed_length; | 851 zlib_stream.avail_out = gzip_compressed_length; |
| 834 | 852 |
| 835 // The GZIP header (see RFC 1952): | 853 // The GZIP header (see RFC 1952): |
| 836 // +---+---+---+---+---+---+---+---+---+---+ | 854 // +---+---+---+---+---+---+---+---+---+---+ |
| 837 // |ID1|ID2|CM |FLG| MTIME |XFL|OS | | 855 // |ID1|ID2|CM |FLG| MTIME |XFL|OS | |
| 838 // +---+---+---+---+---+---+---+---+---+---+ | 856 // +---+---+---+---+---+---+---+---+---+---+ |
| 839 // ID1 \037 | 857 // ID1 \037 |
| 840 // ID2 \213 | 858 // ID2 \213 |
| 841 // CM \010 (compression method == DEFLATE) | 859 // CM \010 (compression method == DEFLATE) |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 893 std::vector<Filter::FilterType> filter_types; | 911 std::vector<Filter::FilterType> filter_types; |
| 894 filter_types.push_back(Filter::FILTER_TYPE_SDCH); | 912 filter_types.push_back(Filter::FILTER_TYPE_SDCH); |
| 895 filter_types.push_back(Filter::FILTER_TYPE_GZIP); | 913 filter_types.push_back(Filter::FILTER_TYPE_GZIP); |
| 896 | 914 |
| 897 // First try with a large buffer (larger than test input, or compressed data). | 915 // First try with a large buffer (larger than test input, or compressed data). |
| 898 const size_t kLargeInputBufferSize(1000); // Used internally in filters. | 916 const size_t kLargeInputBufferSize(1000); // Used internally in filters. |
| 899 CHECK_GT(kLargeInputBufferSize, gzip_compressed_sdch.size()); | 917 CHECK_GT(kLargeInputBufferSize, gzip_compressed_sdch.size()); |
| 900 CHECK_GT(kLargeInputBufferSize, sdch_compressed.size()); | 918 CHECK_GT(kLargeInputBufferSize, sdch_compressed.size()); |
| 901 CHECK_GT(kLargeInputBufferSize, expanded_.size()); | 919 CHECK_GT(kLargeInputBufferSize, expanded_.size()); |
| 902 SetupFilterContextWithGURL(url); | 920 SetupFilterContextWithGURL(url); |
| 903 scoped_ptr<Filter> filter( | 921 std::unique_ptr<Filter> filter(SdchFilterChainingTest::Factory( |
| 904 SdchFilterChainingTest::Factory(filter_types, *filter_context(), | 922 filter_types, *filter_context(), kLargeInputBufferSize)); |
| 905 kLargeInputBufferSize)); | |
| 906 EXPECT_EQ(static_cast<int>(kLargeInputBufferSize), | 923 EXPECT_EQ(static_cast<int>(kLargeInputBufferSize), |
| 907 filter->stream_buffer_size()); | 924 filter->stream_buffer_size()); |
| 908 | 925 |
| 909 // Verify that chained filter is waiting for data. | 926 // Verify that chained filter is waiting for data. |
| 910 char tiny_output_buffer[10]; | 927 char tiny_output_buffer[10]; |
| 911 int tiny_output_size = sizeof(tiny_output_buffer); | 928 int tiny_output_size = sizeof(tiny_output_buffer); |
| 912 EXPECT_EQ(Filter::FILTER_NEED_MORE_DATA, | 929 EXPECT_EQ(Filter::FILTER_NEED_MORE_DATA, |
| 913 filter->ReadData(tiny_output_buffer, &tiny_output_size)); | 930 filter->ReadData(tiny_output_buffer, &tiny_output_size)); |
| 914 | 931 |
| 915 // Make chain process all data. | 932 // Make chain process all data. |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 978 | 995 |
| 979 filter_context()->SetMimeType("anything/mime"); | 996 filter_context()->SetMimeType("anything/mime"); |
| 980 SetupFilterContextWithGURL(url); | 997 SetupFilterContextWithGURL(url); |
| 981 | 998 |
| 982 Filter::FixupEncodingTypes(*filter_context(), &filter_types); | 999 Filter::FixupEncodingTypes(*filter_context(), &filter_types); |
| 983 ASSERT_EQ(filter_types.size(), 2u); | 1000 ASSERT_EQ(filter_types.size(), 2u); |
| 984 EXPECT_EQ(filter_types[0], Filter::FILTER_TYPE_SDCH); | 1001 EXPECT_EQ(filter_types[0], Filter::FILTER_TYPE_SDCH); |
| 985 EXPECT_EQ(filter_types[1], Filter::FILTER_TYPE_GZIP_HELPING_SDCH); | 1002 EXPECT_EQ(filter_types[1], Filter::FILTER_TYPE_GZIP_HELPING_SDCH); |
| 986 | 1003 |
| 987 // First try with a large buffer (larger than test input, or compressed data). | 1004 // First try with a large buffer (larger than test input, or compressed data). |
| 988 scoped_ptr<Filter> filter(Filter::Factory(filter_types, *filter_context())); | 1005 std::unique_ptr<Filter> filter( |
| 1006 Filter::Factory(filter_types, *filter_context())); |
| 989 | 1007 |
| 990 // Verify that chained filter is waiting for data. | 1008 // Verify that chained filter is waiting for data. |
| 991 char tiny_output_buffer[10]; | 1009 char tiny_output_buffer[10]; |
| 992 int tiny_output_size = sizeof(tiny_output_buffer); | 1010 int tiny_output_size = sizeof(tiny_output_buffer); |
| 993 EXPECT_EQ(Filter::FILTER_NEED_MORE_DATA, | 1011 EXPECT_EQ(Filter::FILTER_NEED_MORE_DATA, |
| 994 filter->ReadData(tiny_output_buffer, &tiny_output_size)); | 1012 filter->ReadData(tiny_output_buffer, &tiny_output_size)); |
| 995 | 1013 |
| 996 size_t feed_block_size = 100; | 1014 size_t feed_block_size = 100; |
| 997 size_t output_block_size = 100; | 1015 size_t output_block_size = 100; |
| 998 std::string output; | 1016 std::string output; |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1035 | 1053 |
| 1036 filter_context()->SetMimeType("anything/mime"); | 1054 filter_context()->SetMimeType("anything/mime"); |
| 1037 SetupFilterContextWithGURL(url); | 1055 SetupFilterContextWithGURL(url); |
| 1038 Filter::FixupEncodingTypes(*filter_context(), &filter_types); | 1056 Filter::FixupEncodingTypes(*filter_context(), &filter_types); |
| 1039 ASSERT_EQ(filter_types.size(), 3u); | 1057 ASSERT_EQ(filter_types.size(), 3u); |
| 1040 EXPECT_EQ(filter_types[0], Filter::FILTER_TYPE_SDCH_POSSIBLE); | 1058 EXPECT_EQ(filter_types[0], Filter::FILTER_TYPE_SDCH_POSSIBLE); |
| 1041 EXPECT_EQ(filter_types[1], Filter::FILTER_TYPE_GZIP_HELPING_SDCH); | 1059 EXPECT_EQ(filter_types[1], Filter::FILTER_TYPE_GZIP_HELPING_SDCH); |
| 1042 EXPECT_EQ(filter_types[2], Filter::FILTER_TYPE_GZIP); | 1060 EXPECT_EQ(filter_types[2], Filter::FILTER_TYPE_GZIP); |
| 1043 | 1061 |
| 1044 // First try with a large buffer (larger than test input, or compressed data). | 1062 // First try with a large buffer (larger than test input, or compressed data). |
| 1045 scoped_ptr<Filter> filter(Filter::Factory(filter_types, *filter_context())); | 1063 std::unique_ptr<Filter> filter( |
| 1064 Filter::Factory(filter_types, *filter_context())); |
| 1046 | 1065 |
| 1047 // Verify that chained filter is waiting for data. | 1066 // Verify that chained filter is waiting for data. |
| 1048 char tiny_output_buffer[10]; | 1067 char tiny_output_buffer[10]; |
| 1049 int tiny_output_size = sizeof(tiny_output_buffer); | 1068 int tiny_output_size = sizeof(tiny_output_buffer); |
| 1050 EXPECT_EQ(Filter::FILTER_NEED_MORE_DATA, | 1069 EXPECT_EQ(Filter::FILTER_NEED_MORE_DATA, |
| 1051 filter->ReadData(tiny_output_buffer, &tiny_output_size)); | 1070 filter->ReadData(tiny_output_buffer, &tiny_output_size)); |
| 1052 | 1071 |
| 1053 size_t feed_block_size = 100; | 1072 size_t feed_block_size = 100; |
| 1054 size_t output_block_size = 100; | 1073 size_t output_block_size = 100; |
| 1055 std::string output; | 1074 std::string output; |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1089 std::vector<Filter::FilterType> filter_types; | 1108 std::vector<Filter::FilterType> filter_types; |
| 1090 | 1109 |
| 1091 filter_context()->SetMimeType("anything/mime"); | 1110 filter_context()->SetMimeType("anything/mime"); |
| 1092 SetupFilterContextWithGURL(url); | 1111 SetupFilterContextWithGURL(url); |
| 1093 Filter::FixupEncodingTypes(*filter_context(), &filter_types); | 1112 Filter::FixupEncodingTypes(*filter_context(), &filter_types); |
| 1094 ASSERT_EQ(filter_types.size(), 2u); | 1113 ASSERT_EQ(filter_types.size(), 2u); |
| 1095 EXPECT_EQ(filter_types[0], Filter::FILTER_TYPE_SDCH_POSSIBLE); | 1114 EXPECT_EQ(filter_types[0], Filter::FILTER_TYPE_SDCH_POSSIBLE); |
| 1096 EXPECT_EQ(filter_types[1], Filter::FILTER_TYPE_GZIP_HELPING_SDCH); | 1115 EXPECT_EQ(filter_types[1], Filter::FILTER_TYPE_GZIP_HELPING_SDCH); |
| 1097 | 1116 |
| 1098 // First try with a large buffer (larger than test input, or compressed data). | 1117 // First try with a large buffer (larger than test input, or compressed data). |
| 1099 scoped_ptr<Filter> filter(Filter::Factory(filter_types, *filter_context())); | 1118 std::unique_ptr<Filter> filter( |
| 1119 Filter::Factory(filter_types, *filter_context())); |
| 1100 | 1120 |
| 1101 // Verify that chained filter is waiting for data. | 1121 // Verify that chained filter is waiting for data. |
| 1102 char tiny_output_buffer[10]; | 1122 char tiny_output_buffer[10]; |
| 1103 int tiny_output_size = sizeof(tiny_output_buffer); | 1123 int tiny_output_size = sizeof(tiny_output_buffer); |
| 1104 EXPECT_EQ(Filter::FILTER_NEED_MORE_DATA, | 1124 EXPECT_EQ(Filter::FILTER_NEED_MORE_DATA, |
| 1105 filter->ReadData(tiny_output_buffer, &tiny_output_size)); | 1125 filter->ReadData(tiny_output_buffer, &tiny_output_size)); |
| 1106 | 1126 |
| 1107 size_t feed_block_size = 100; | 1127 size_t feed_block_size = 100; |
| 1108 size_t output_block_size = 100; | 1128 size_t output_block_size = 100; |
| 1109 std::string output; | 1129 std::string output; |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1149 | 1169 |
| 1150 filter_context()->SetMimeType("anything/mime"); | 1170 filter_context()->SetMimeType("anything/mime"); |
| 1151 SetupFilterContextWithGURL(url); | 1171 SetupFilterContextWithGURL(url); |
| 1152 Filter::FixupEncodingTypes(*filter_context(), &filter_types); | 1172 Filter::FixupEncodingTypes(*filter_context(), &filter_types); |
| 1153 ASSERT_EQ(filter_types.size(), 3u); | 1173 ASSERT_EQ(filter_types.size(), 3u); |
| 1154 EXPECT_EQ(filter_types[0], Filter::FILTER_TYPE_SDCH_POSSIBLE); | 1174 EXPECT_EQ(filter_types[0], Filter::FILTER_TYPE_SDCH_POSSIBLE); |
| 1155 EXPECT_EQ(filter_types[1], Filter::FILTER_TYPE_GZIP_HELPING_SDCH); | 1175 EXPECT_EQ(filter_types[1], Filter::FILTER_TYPE_GZIP_HELPING_SDCH); |
| 1156 EXPECT_EQ(filter_types[2], Filter::FILTER_TYPE_GZIP); | 1176 EXPECT_EQ(filter_types[2], Filter::FILTER_TYPE_GZIP); |
| 1157 | 1177 |
| 1158 // First try with a large buffer (larger than test input, or compressed data). | 1178 // First try with a large buffer (larger than test input, or compressed data). |
| 1159 scoped_ptr<Filter> filter(Filter::Factory(filter_types, *filter_context())); | 1179 std::unique_ptr<Filter> filter( |
| 1180 Filter::Factory(filter_types, *filter_context())); |
| 1160 | 1181 |
| 1161 // Verify that chained filter is waiting for data. | 1182 // Verify that chained filter is waiting for data. |
| 1162 char tiny_output_buffer[10]; | 1183 char tiny_output_buffer[10]; |
| 1163 int tiny_output_size = sizeof(tiny_output_buffer); | 1184 int tiny_output_size = sizeof(tiny_output_buffer); |
| 1164 EXPECT_EQ(Filter::FILTER_NEED_MORE_DATA, | 1185 EXPECT_EQ(Filter::FILTER_NEED_MORE_DATA, |
| 1165 filter->ReadData(tiny_output_buffer, &tiny_output_size)); | 1186 filter->ReadData(tiny_output_buffer, &tiny_output_size)); |
| 1166 | 1187 |
| 1167 size_t feed_block_size = 100; | 1188 size_t feed_block_size = 100; |
| 1168 size_t output_block_size = 100; | 1189 size_t output_block_size = 100; |
| 1169 std::string output; | 1190 std::string output; |
| (...skipping 19 matching lines...) Expand all Loading... |
| 1189 const std::string kSampleDomain = "sdchtest.com"; | 1210 const std::string kSampleDomain = "sdchtest.com"; |
| 1190 std::string dictionary(NewSdchDictionary(kSampleDomain)); | 1211 std::string dictionary(NewSdchDictionary(kSampleDomain)); |
| 1191 std::string url_string = "http://" + kSampleDomain; | 1212 std::string url_string = "http://" + kSampleDomain; |
| 1192 GURL url(url_string); | 1213 GURL url(url_string); |
| 1193 EXPECT_TRUE(AddSdchDictionary(dictionary, url)); | 1214 EXPECT_TRUE(AddSdchDictionary(dictionary, url)); |
| 1194 | 1215 |
| 1195 SetupFilterContextWithGURL(url); | 1216 SetupFilterContextWithGURL(url); |
| 1196 | 1217 |
| 1197 std::vector<Filter::FilterType> filter_types; | 1218 std::vector<Filter::FilterType> filter_types; |
| 1198 filter_types.push_back(Filter::FILTER_TYPE_SDCH); | 1219 filter_types.push_back(Filter::FILTER_TYPE_SDCH); |
| 1199 scoped_ptr<Filter> filter(Filter::Factory(filter_types, *filter_context())); | 1220 std::unique_ptr<Filter> filter( |
| 1221 Filter::Factory(filter_types, *filter_context())); |
| 1200 | 1222 |
| 1201 // Setup another dictionary, expired. Don't add it to the filter context. | 1223 // Setup another dictionary, expired. Don't add it to the filter context. |
| 1202 // Delete stored dictionaries first to handle platforms which only | 1224 // Delete stored dictionaries first to handle platforms which only |
| 1203 // have room for a single dictionary. | 1225 // have room for a single dictionary. |
| 1204 sdch_manager_->ClearData(); | 1226 sdch_manager_->ClearData(); |
| 1205 std::string expired_dictionary(NewSdchExpiredDictionary(kSampleDomain)); | 1227 std::string expired_dictionary(NewSdchExpiredDictionary(kSampleDomain)); |
| 1206 | 1228 |
| 1207 // Don't use the Helper function since its insertion check is indeterminate | 1229 // Don't use the Helper function since its insertion check is indeterminate |
| 1208 // for a Max-Age: 0 dictionary. | 1230 // for a Max-Age: 0 dictionary. |
| 1209 sdch_manager_->AddSdchDictionary(expired_dictionary, url, nullptr); | 1231 sdch_manager_->AddSdchDictionary(expired_dictionary, url, nullptr); |
| 1210 | 1232 |
| 1211 std::string client_hash; | 1233 std::string client_hash; |
| 1212 std::string server_hash; | 1234 std::string server_hash; |
| 1213 SdchManager::GenerateHash(expired_dictionary, &client_hash, &server_hash); | 1235 SdchManager::GenerateHash(expired_dictionary, &client_hash, &server_hash); |
| 1214 | 1236 |
| 1215 SdchProblemCode problem_code; | 1237 SdchProblemCode problem_code; |
| 1216 scoped_ptr<SdchManager::DictionarySet> hash_set( | 1238 std::unique_ptr<SdchManager::DictionarySet> hash_set( |
| 1217 sdch_manager_->GetDictionarySetByHash(url, server_hash, &problem_code)); | 1239 sdch_manager_->GetDictionarySetByHash(url, server_hash, &problem_code)); |
| 1218 ASSERT_TRUE(hash_set); | 1240 ASSERT_TRUE(hash_set); |
| 1219 ASSERT_EQ(SDCH_OK, problem_code); | 1241 ASSERT_EQ(SDCH_OK, problem_code); |
| 1220 | 1242 |
| 1221 // Encode output with the second dictionary. | 1243 // Encode output with the second dictionary. |
| 1222 std::string sdch_compressed(NewSdchCompressedData(expired_dictionary)); | 1244 std::string sdch_compressed(NewSdchCompressedData(expired_dictionary)); |
| 1223 | 1245 |
| 1224 // See if the filter decodes it. | 1246 // See if the filter decodes it. |
| 1225 std::string output; | 1247 std::string output; |
| 1226 EXPECT_TRUE(FilterTestData(sdch_compressed, 100, 100, filter.get(), &output)); | 1248 EXPECT_TRUE(FilterTestData(sdch_compressed, 100, 100, filter.get(), &output)); |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1274 std::string server_hash; | 1296 std::string server_hash; |
| 1275 SdchManager::GenerateHash(dictionary, &client_hash, &server_hash); | 1297 SdchManager::GenerateHash(dictionary, &client_hash, &server_hash); |
| 1276 | 1298 |
| 1277 std::string compressed(NewSdchCompressedData(dictionary)); | 1299 std::string compressed(NewSdchCompressedData(dictionary)); |
| 1278 | 1300 |
| 1279 std::vector<Filter::FilterType> filter_types; | 1301 std::vector<Filter::FilterType> filter_types; |
| 1280 filter_types.push_back(Filter::FILTER_TYPE_SDCH); | 1302 filter_types.push_back(Filter::FILTER_TYPE_SDCH); |
| 1281 | 1303 |
| 1282 SetupFilterContextWithGURL(url); | 1304 SetupFilterContextWithGURL(url); |
| 1283 | 1305 |
| 1284 scoped_ptr<Filter> filter(Filter::Factory(filter_types, *filter_context())); | 1306 std::unique_ptr<Filter> filter( |
| 1307 Filter::Factory(filter_types, *filter_context())); |
| 1285 | 1308 |
| 1286 size_t feed_block_size = 100; | 1309 size_t feed_block_size = 100; |
| 1287 size_t output_block_size = 100; | 1310 size_t output_block_size = 100; |
| 1288 std::string output; | 1311 std::string output; |
| 1289 EXPECT_TRUE(FilterTestData(compressed, feed_block_size, output_block_size, | 1312 EXPECT_TRUE(FilterTestData(compressed, feed_block_size, output_block_size, |
| 1290 filter.get(), &output)); | 1313 filter.get(), &output)); |
| 1291 EXPECT_EQ(output, expanded_); | 1314 EXPECT_EQ(output, expanded_); |
| 1292 | 1315 |
| 1293 filter.reset(nullptr); | 1316 filter.reset(nullptr); |
| 1294 | 1317 |
| 1295 // Confirm that we got a "DictionaryUsed" signal from the SdchManager | 1318 // Confirm that we got a "DictionaryUsed" signal from the SdchManager |
| 1296 // for our dictionary. | 1319 // for our dictionary. |
| 1297 EXPECT_EQ(1, observer.dictionary_used_calls()); | 1320 EXPECT_EQ(1, observer.dictionary_used_calls()); |
| 1298 EXPECT_EQ(server_hash, observer.last_server_hash()); | 1321 EXPECT_EQ(server_hash, observer.last_server_hash()); |
| 1299 } | 1322 } |
| 1300 | 1323 |
| 1301 } // namespace net | 1324 } // namespace net |
| OLD | NEW |