| 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 <limits.h> | 5 #include <limits.h> |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <string> | 8 #include <string> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| 11 #if defined(USE_SYSTEM_ZLIB) | 11 #if defined(USE_SYSTEM_ZLIB) |
| 12 #include <zlib.h> | 12 #include <zlib.h> |
| 13 #else | 13 #else |
| 14 #include "third_party/zlib/zlib.h" | 14 #include "third_party/zlib/zlib.h" |
| 15 #endif | 15 #endif |
| 16 | 16 |
| 17 #include "base/logging.h" | 17 #include "base/logging.h" |
| 18 #include "base/scoped_ptr.h" | 18 #include "base/scoped_ptr.h" |
| 19 #include "net/base/filter.h" | 19 #include "net/base/filter.h" |
| 20 #include "net/base/filter_unittest.h" | |
| 21 #include "net/base/io_buffer.h" | 20 #include "net/base/io_buffer.h" |
| 21 #include "net/base/mock_filter_context.h" |
| 22 #include "net/base/sdch_filter.h" | 22 #include "net/base/sdch_filter.h" |
| 23 #include "net/url_request/url_request_http_job.h" | 23 #include "net/url_request/url_request_http_job.h" |
| 24 #include "testing/gtest/include/gtest/gtest.h" | 24 #include "testing/gtest/include/gtest/gtest.h" |
| 25 | 25 |
| 26 //------------------------------------------------------------------------------ | 26 //------------------------------------------------------------------------------ |
| 27 // Provide sample data and compression results with a sample VCDIFF dictionary. | 27 // Provide sample data and compression results with a sample VCDIFF dictionary. |
| 28 // Note an SDCH dictionary has extra meta-data before the VCDIFF dictionary. | 28 // Note an SDCH dictionary has extra meta-data before the VCDIFF dictionary. |
| 29 static const char kTestVcdiffDictionary[] = "DictionaryFor" | 29 static const char kTestVcdiffDictionary[] = "DictionaryFor" |
| 30 "SdchCompression1SdchCompression2SdchCompression3SdchCompression\n"; | 30 "SdchCompression1SdchCompression2SdchCompression3SdchCompression\n"; |
| 31 // Pre-compression test data. Note that we pad with a lot of highly gzip | 31 // Pre-compression test data. Note that we pad with a lot of highly gzip |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 151 return dictionary; | 151 return dictionary; |
| 152 } | 152 } |
| 153 | 153 |
| 154 //------------------------------------------------------------------------------ | 154 //------------------------------------------------------------------------------ |
| 155 | 155 |
| 156 TEST_F(SdchFilterTest, EmptyInputOk) { | 156 TEST_F(SdchFilterTest, EmptyInputOk) { |
| 157 std::vector<Filter::FilterType> filter_types; | 157 std::vector<Filter::FilterType> filter_types; |
| 158 filter_types.push_back(Filter::FILTER_TYPE_SDCH); | 158 filter_types.push_back(Filter::FILTER_TYPE_SDCH); |
| 159 const int kInputBufferSize(30); | 159 const int kInputBufferSize(30); |
| 160 char output_buffer[20]; | 160 char output_buffer[20]; |
| 161 MockFilterContext filter_context(kInputBufferSize); | 161 net::MockFilterContext filter_context(kInputBufferSize); |
| 162 std::string url_string("http://ignore.com"); | 162 std::string url_string("http://ignore.com"); |
| 163 filter_context.SetURL(GURL(url_string)); | 163 filter_context.SetURL(GURL(url_string)); |
| 164 scoped_ptr<Filter> filter(Filter::Factory(filter_types, filter_context)); | 164 scoped_ptr<Filter> filter(Filter::Factory(filter_types, filter_context)); |
| 165 | 165 |
| 166 | 166 |
| 167 // With no input data, try to read output. | 167 // With no input data, try to read output. |
| 168 int output_bytes_or_buffer_size = sizeof(output_buffer); | 168 int output_bytes_or_buffer_size = sizeof(output_buffer); |
| 169 Filter::FilterStatus status = filter->ReadData(output_buffer, | 169 Filter::FilterStatus status = filter->ReadData(output_buffer, |
| 170 &output_bytes_or_buffer_size); | 170 &output_bytes_or_buffer_size); |
| 171 | 171 |
| 172 EXPECT_EQ(0, output_bytes_or_buffer_size); | 172 EXPECT_EQ(0, output_bytes_or_buffer_size); |
| 173 EXPECT_EQ(Filter::FILTER_NEED_MORE_DATA, status); | 173 EXPECT_EQ(Filter::FILTER_NEED_MORE_DATA, status); |
| 174 } | 174 } |
| 175 | 175 |
| 176 TEST_F(SdchFilterTest, PassThroughWhenTentative) { | 176 TEST_F(SdchFilterTest, PassThroughWhenTentative) { |
| 177 std::vector<Filter::FilterType> filter_types; | 177 std::vector<Filter::FilterType> filter_types; |
| 178 // Selective a tentative filter (which can fall back to pass through). | 178 // Selective a tentative filter (which can fall back to pass through). |
| 179 filter_types.push_back(Filter::FILTER_TYPE_GZIP_HELPING_SDCH); | 179 filter_types.push_back(Filter::FILTER_TYPE_GZIP_HELPING_SDCH); |
| 180 const int kInputBufferSize(30); | 180 const int kInputBufferSize(30); |
| 181 char output_buffer[20]; | 181 char output_buffer[20]; |
| 182 MockFilterContext filter_context(kInputBufferSize); | 182 net::MockFilterContext filter_context(kInputBufferSize); |
| 183 // Response code needs to be 200 to allow a pass through. | 183 // Response code needs to be 200 to allow a pass through. |
| 184 filter_context.SetResponseCode(200); | 184 filter_context.SetResponseCode(200); |
| 185 std::string url_string("http://ignore.com"); | 185 std::string url_string("http://ignore.com"); |
| 186 filter_context.SetURL(GURL(url_string)); | 186 filter_context.SetURL(GURL(url_string)); |
| 187 scoped_ptr<Filter> filter(Filter::Factory(filter_types, filter_context)); | 187 scoped_ptr<Filter> filter(Filter::Factory(filter_types, filter_context)); |
| 188 | 188 |
| 189 // Supply enough data to force a pass-through mode.. | 189 // Supply enough data to force a pass-through mode.. |
| 190 std::string non_gzip_content("not GZIPed data"); | 190 std::string non_gzip_content("not GZIPed data"); |
| 191 | 191 |
| 192 char* input_buffer = filter->stream_buffer()->data(); | 192 char* input_buffer = filter->stream_buffer()->data(); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 212 EXPECT_TRUE(non_gzip_content == output_buffer); | 212 EXPECT_TRUE(non_gzip_content == output_buffer); |
| 213 EXPECT_EQ(Filter::FILTER_NEED_MORE_DATA, status); | 213 EXPECT_EQ(Filter::FILTER_NEED_MORE_DATA, status); |
| 214 } | 214 } |
| 215 | 215 |
| 216 TEST_F(SdchFilterTest, RefreshBadReturnCode) { | 216 TEST_F(SdchFilterTest, RefreshBadReturnCode) { |
| 217 std::vector<Filter::FilterType> filter_types; | 217 std::vector<Filter::FilterType> filter_types; |
| 218 // Selective a tentative filter (which can fall back to pass through). | 218 // Selective a tentative filter (which can fall back to pass through). |
| 219 filter_types.push_back(Filter::FILTER_TYPE_SDCH_POSSIBLE); | 219 filter_types.push_back(Filter::FILTER_TYPE_SDCH_POSSIBLE); |
| 220 const int kInputBufferSize(30); | 220 const int kInputBufferSize(30); |
| 221 char output_buffer[20]; | 221 char output_buffer[20]; |
| 222 MockFilterContext filter_context(kInputBufferSize); | 222 net::MockFilterContext filter_context(kInputBufferSize); |
| 223 // Response code needs to be 200 to allow a pass through. | 223 // Response code needs to be 200 to allow a pass through. |
| 224 filter_context.SetResponseCode(403); | 224 filter_context.SetResponseCode(403); |
| 225 // Meta refresh will only appear for html content | 225 // Meta refresh will only appear for html content |
| 226 filter_context.SetMimeType("text/html"); | 226 filter_context.SetMimeType("text/html"); |
| 227 std::string url_string("http://ignore.com"); | 227 std::string url_string("http://ignore.com"); |
| 228 filter_context.SetURL(GURL(url_string)); | 228 filter_context.SetURL(GURL(url_string)); |
| 229 scoped_ptr<Filter> filter(Filter::Factory(filter_types, filter_context)); | 229 scoped_ptr<Filter> filter(Filter::Factory(filter_types, filter_context)); |
| 230 | 230 |
| 231 // Supply enough data to force a pass-through mode, which means we have | 231 // Supply enough data to force a pass-through mode, which means we have |
| 232 // provided more than 9 characters that can't be a dictionary hash. | 232 // provided more than 9 characters that can't be a dictionary hash. |
| (...skipping 22 matching lines...) Expand all Loading... |
| 255 sizeof(output_buffer))); | 255 sizeof(output_buffer))); |
| 256 EXPECT_EQ(Filter::FILTER_OK, status); | 256 EXPECT_EQ(Filter::FILTER_OK, status); |
| 257 } | 257 } |
| 258 | 258 |
| 259 TEST_F(SdchFilterTest, ErrorOnBadReturnCode) { | 259 TEST_F(SdchFilterTest, ErrorOnBadReturnCode) { |
| 260 std::vector<Filter::FilterType> filter_types; | 260 std::vector<Filter::FilterType> filter_types; |
| 261 // Selective a tentative filter (which can fall back to pass through). | 261 // Selective a tentative filter (which can fall back to pass through). |
| 262 filter_types.push_back(Filter::FILTER_TYPE_SDCH_POSSIBLE); | 262 filter_types.push_back(Filter::FILTER_TYPE_SDCH_POSSIBLE); |
| 263 const int kInputBufferSize(30); | 263 const int kInputBufferSize(30); |
| 264 char output_buffer[20]; | 264 char output_buffer[20]; |
| 265 MockFilterContext filter_context(kInputBufferSize); | 265 net::MockFilterContext filter_context(kInputBufferSize); |
| 266 // Response code needs to be 200 to allow a pass through. | 266 // Response code needs to be 200 to allow a pass through. |
| 267 filter_context.SetResponseCode(403); | 267 filter_context.SetResponseCode(403); |
| 268 // Meta refresh will only appear for html content, so set to something else | 268 // Meta refresh will only appear for html content, so set to something else |
| 269 // to induce an error (we can't meta refresh). | 269 // to induce an error (we can't meta refresh). |
| 270 filter_context.SetMimeType("anything"); | 270 filter_context.SetMimeType("anything"); |
| 271 std::string url_string("http://ignore.com"); | 271 std::string url_string("http://ignore.com"); |
| 272 filter_context.SetURL(GURL(url_string)); | 272 filter_context.SetURL(GURL(url_string)); |
| 273 scoped_ptr<Filter> filter(Filter::Factory(filter_types, filter_context)); | 273 scoped_ptr<Filter> filter(Filter::Factory(filter_types, filter_context)); |
| 274 | 274 |
| 275 // Supply enough data to force a pass-through mode, which means we have | 275 // Supply enough data to force a pass-through mode, which means we have |
| (...skipping 18 matching lines...) Expand all Loading... |
| 294 EXPECT_EQ(0, output_bytes_or_buffer_size); | 294 EXPECT_EQ(0, output_bytes_or_buffer_size); |
| 295 EXPECT_EQ(Filter::FILTER_ERROR, status); | 295 EXPECT_EQ(Filter::FILTER_ERROR, status); |
| 296 } | 296 } |
| 297 | 297 |
| 298 TEST_F(SdchFilterTest, ErrorOnBadReturnCodeWithHtml) { | 298 TEST_F(SdchFilterTest, ErrorOnBadReturnCodeWithHtml) { |
| 299 std::vector<Filter::FilterType> filter_types; | 299 std::vector<Filter::FilterType> filter_types; |
| 300 // Selective a tentative filter (which can fall back to pass through). | 300 // Selective a tentative filter (which can fall back to pass through). |
| 301 filter_types.push_back(Filter::FILTER_TYPE_SDCH_POSSIBLE); | 301 filter_types.push_back(Filter::FILTER_TYPE_SDCH_POSSIBLE); |
| 302 const int kInputBufferSize(30); | 302 const int kInputBufferSize(30); |
| 303 char output_buffer[20]; | 303 char output_buffer[20]; |
| 304 MockFilterContext filter_context(kInputBufferSize); | 304 net::MockFilterContext filter_context(kInputBufferSize); |
| 305 // Response code needs to be 200 to allow a pass through. | 305 // Response code needs to be 200 to allow a pass through. |
| 306 filter_context.SetResponseCode(403); | 306 filter_context.SetResponseCode(403); |
| 307 // Meta refresh will only appear for html content | 307 // Meta refresh will only appear for html content |
| 308 filter_context.SetMimeType("text/html"); | 308 filter_context.SetMimeType("text/html"); |
| 309 std::string url_string("http://ignore.com"); | 309 std::string url_string("http://ignore.com"); |
| 310 filter_context.SetURL(GURL(url_string)); | 310 filter_context.SetURL(GURL(url_string)); |
| 311 scoped_ptr<Filter> filter(Filter::Factory(filter_types, filter_context)); | 311 scoped_ptr<Filter> filter(Filter::Factory(filter_types, filter_context)); |
| 312 | 312 |
| 313 // Supply enough data to force a pass-through mode, which means we have | 313 // Supply enough data to force a pass-through mode, which means we have |
| 314 // provided more than 9 characters that can't be a dictionary hash. | 314 // provided more than 9 characters that can't be a dictionary hash. |
| (...skipping 22 matching lines...) Expand all Loading... |
| 337 "<head><META HTTP-EQUIV=\"Refresh\" CONTENT=\"0\"></head>", | 337 "<head><META HTTP-EQUIV=\"Refresh\" CONTENT=\"0\"></head>", |
| 338 sizeof(output_buffer))); | 338 sizeof(output_buffer))); |
| 339 EXPECT_EQ(Filter::FILTER_OK, status); | 339 EXPECT_EQ(Filter::FILTER_OK, status); |
| 340 } | 340 } |
| 341 | 341 |
| 342 TEST_F(SdchFilterTest, BasicBadDictionary) { | 342 TEST_F(SdchFilterTest, BasicBadDictionary) { |
| 343 std::vector<Filter::FilterType> filter_types; | 343 std::vector<Filter::FilterType> filter_types; |
| 344 filter_types.push_back(Filter::FILTER_TYPE_SDCH); | 344 filter_types.push_back(Filter::FILTER_TYPE_SDCH); |
| 345 const int kInputBufferSize(30); | 345 const int kInputBufferSize(30); |
| 346 char output_buffer[20]; | 346 char output_buffer[20]; |
| 347 MockFilterContext filter_context(kInputBufferSize); | 347 net::MockFilterContext filter_context(kInputBufferSize); |
| 348 std::string url_string("http://ignore.com"); | 348 std::string url_string("http://ignore.com"); |
| 349 filter_context.SetURL(GURL(url_string)); | 349 filter_context.SetURL(GURL(url_string)); |
| 350 scoped_ptr<Filter> filter(Filter::Factory(filter_types, filter_context)); | 350 scoped_ptr<Filter> filter(Filter::Factory(filter_types, filter_context)); |
| 351 | 351 |
| 352 // Supply bogus data (which doesn't yet specify a full dictionary hash). | 352 // Supply bogus data (which doesn't yet specify a full dictionary hash). |
| 353 // Dictionary hash is 8 characters followed by a null. | 353 // Dictionary hash is 8 characters followed by a null. |
| 354 std::string dictionary_hash_prefix("123"); | 354 std::string dictionary_hash_prefix("123"); |
| 355 | 355 |
| 356 char* input_buffer = filter->stream_buffer()->data(); | 356 char* input_buffer = filter->stream_buffer()->data(); |
| 357 int input_buffer_size = filter->stream_buffer_size(); | 357 int input_buffer_size = filter->stream_buffer_size(); |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 425 GURL url(url_string); | 425 GURL url(url_string); |
| 426 EXPECT_TRUE(sdch_manager_->AddSdchDictionary(dictionary, url)); | 426 EXPECT_TRUE(sdch_manager_->AddSdchDictionary(dictionary, url)); |
| 427 | 427 |
| 428 std::string compressed(NewSdchCompressedData(dictionary)); | 428 std::string compressed(NewSdchCompressedData(dictionary)); |
| 429 | 429 |
| 430 std::vector<Filter::FilterType> filter_types; | 430 std::vector<Filter::FilterType> filter_types; |
| 431 filter_types.push_back(Filter::FILTER_TYPE_SDCH); | 431 filter_types.push_back(Filter::FILTER_TYPE_SDCH); |
| 432 | 432 |
| 433 // Decode with a large buffer (larger than test input, or compressed data). | 433 // Decode with a large buffer (larger than test input, or compressed data). |
| 434 const int kInputBufferSize(100); | 434 const int kInputBufferSize(100); |
| 435 MockFilterContext filter_context(kInputBufferSize); | 435 net::MockFilterContext filter_context(kInputBufferSize); |
| 436 filter_context.SetURL(url); | 436 filter_context.SetURL(url); |
| 437 | 437 |
| 438 scoped_ptr<Filter> filter(Filter::Factory(filter_types, filter_context)); | 438 scoped_ptr<Filter> filter(Filter::Factory(filter_types, filter_context)); |
| 439 | 439 |
| 440 size_t feed_block_size = 100; | 440 size_t feed_block_size = 100; |
| 441 size_t output_block_size = 100; | 441 size_t output_block_size = 100; |
| 442 std::string output; | 442 std::string output; |
| 443 EXPECT_TRUE(FilterTestData(compressed, feed_block_size, output_block_size, | 443 EXPECT_TRUE(FilterTestData(compressed, feed_block_size, output_block_size, |
| 444 filter.get(), &output)); | 444 filter.get(), &output)); |
| 445 EXPECT_EQ(output, expanded_); | 445 EXPECT_EQ(output, expanded_); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 464 | 464 |
| 465 GURL url(url_string); | 465 GURL url(url_string); |
| 466 EXPECT_TRUE(sdch_manager_->AddSdchDictionary(dictionary, url)); | 466 EXPECT_TRUE(sdch_manager_->AddSdchDictionary(dictionary, url)); |
| 467 | 467 |
| 468 std::string compressed(NewSdchCompressedData(dictionary)); | 468 std::string compressed(NewSdchCompressedData(dictionary)); |
| 469 | 469 |
| 470 std::vector<Filter::FilterType> filter_types; | 470 std::vector<Filter::FilterType> filter_types; |
| 471 filter_types.push_back(Filter::FILTER_TYPE_SDCH); | 471 filter_types.push_back(Filter::FILTER_TYPE_SDCH); |
| 472 | 472 |
| 473 const int kInputBufferSize(100); | 473 const int kInputBufferSize(100); |
| 474 MockFilterContext filter_context(kInputBufferSize); | 474 net::MockFilterContext filter_context(kInputBufferSize); |
| 475 filter_context.SetURL(GURL("https://" + kSampleDomain)); | 475 filter_context.SetURL(GURL("https://" + kSampleDomain)); |
| 476 scoped_ptr<Filter> filter(Filter::Factory(filter_types, filter_context)); | 476 scoped_ptr<Filter> filter(Filter::Factory(filter_types, filter_context)); |
| 477 | 477 |
| 478 const size_t feed_block_size(100); | 478 const size_t feed_block_size(100); |
| 479 const size_t output_block_size(100); | 479 const size_t output_block_size(100); |
| 480 std::string output; | 480 std::string output; |
| 481 | 481 |
| 482 EXPECT_FALSE(FilterTestData(compressed, feed_block_size, output_block_size, | 482 EXPECT_FALSE(FilterTestData(compressed, feed_block_size, output_block_size, |
| 483 filter.get(), &output)); | 483 filter.get(), &output)); |
| 484 } | 484 } |
| (...skipping 11 matching lines...) Expand all Loading... |
| 496 | 496 |
| 497 GURL url(url_string); | 497 GURL url(url_string); |
| 498 EXPECT_TRUE(sdch_manager_->AddSdchDictionary(dictionary, url)); | 498 EXPECT_TRUE(sdch_manager_->AddSdchDictionary(dictionary, url)); |
| 499 | 499 |
| 500 std::string compressed(NewSdchCompressedData(dictionary)); | 500 std::string compressed(NewSdchCompressedData(dictionary)); |
| 501 | 501 |
| 502 std::vector<Filter::FilterType> filter_types; | 502 std::vector<Filter::FilterType> filter_types; |
| 503 filter_types.push_back(Filter::FILTER_TYPE_SDCH); | 503 filter_types.push_back(Filter::FILTER_TYPE_SDCH); |
| 504 | 504 |
| 505 const int kInputBufferSize(100); | 505 const int kInputBufferSize(100); |
| 506 MockFilterContext filter_context(kInputBufferSize); | 506 net::MockFilterContext filter_context(kInputBufferSize); |
| 507 filter_context.SetURL(GURL("ftp://" + kSampleDomain)); | 507 filter_context.SetURL(GURL("ftp://" + kSampleDomain)); |
| 508 scoped_ptr<Filter> filter(Filter::Factory(filter_types, filter_context)); | 508 scoped_ptr<Filter> filter(Filter::Factory(filter_types, filter_context)); |
| 509 | 509 |
| 510 const size_t feed_block_size(100); | 510 const size_t feed_block_size(100); |
| 511 const size_t output_block_size(100); | 511 const size_t output_block_size(100); |
| 512 std::string output; | 512 std::string output; |
| 513 | 513 |
| 514 EXPECT_FALSE(FilterTestData(compressed, feed_block_size, output_block_size, | 514 EXPECT_FALSE(FilterTestData(compressed, feed_block_size, output_block_size, |
| 515 filter.get(), &output)); | 515 filter.get(), &output)); |
| 516 } | 516 } |
| 517 | 517 |
| 518 TEST_F(SdchFilterTest, NoDecodeFileColon) { | 518 TEST_F(SdchFilterTest, NoDecodeFileColon) { |
| 519 // Construct a valid SDCH dictionary from a VCDIFF dictionary. | 519 // Construct a valid SDCH dictionary from a VCDIFF dictionary. |
| 520 const std::string kSampleDomain = "sdchtest.com"; | 520 const std::string kSampleDomain = "sdchtest.com"; |
| 521 std::string dictionary(NewSdchDictionary(kSampleDomain)); | 521 std::string dictionary(NewSdchDictionary(kSampleDomain)); |
| 522 | 522 |
| 523 std::string url_string = "http://" + kSampleDomain; | 523 std::string url_string = "http://" + kSampleDomain; |
| 524 | 524 |
| 525 GURL url(url_string); | 525 GURL url(url_string); |
| 526 EXPECT_TRUE(sdch_manager_->AddSdchDictionary(dictionary, url)); | 526 EXPECT_TRUE(sdch_manager_->AddSdchDictionary(dictionary, url)); |
| 527 | 527 |
| 528 std::string compressed(NewSdchCompressedData(dictionary)); | 528 std::string compressed(NewSdchCompressedData(dictionary)); |
| 529 | 529 |
| 530 std::vector<Filter::FilterType> filter_types; | 530 std::vector<Filter::FilterType> filter_types; |
| 531 filter_types.push_back(Filter::FILTER_TYPE_SDCH); | 531 filter_types.push_back(Filter::FILTER_TYPE_SDCH); |
| 532 | 532 |
| 533 const int kInputBufferSize(100); | 533 const int kInputBufferSize(100); |
| 534 MockFilterContext filter_context(kInputBufferSize); | 534 net::MockFilterContext filter_context(kInputBufferSize); |
| 535 filter_context.SetURL(GURL("file://" + kSampleDomain)); | 535 filter_context.SetURL(GURL("file://" + kSampleDomain)); |
| 536 scoped_ptr<Filter> filter(Filter::Factory(filter_types, filter_context)); | 536 scoped_ptr<Filter> filter(Filter::Factory(filter_types, filter_context)); |
| 537 | 537 |
| 538 const size_t feed_block_size(100); | 538 const size_t feed_block_size(100); |
| 539 const size_t output_block_size(100); | 539 const size_t output_block_size(100); |
| 540 std::string output; | 540 std::string output; |
| 541 | 541 |
| 542 EXPECT_FALSE(FilterTestData(compressed, feed_block_size, output_block_size, | 542 EXPECT_FALSE(FilterTestData(compressed, feed_block_size, output_block_size, |
| 543 filter.get(), &output)); | 543 filter.get(), &output)); |
| 544 } | 544 } |
| 545 | 545 |
| 546 TEST_F(SdchFilterTest, NoDecodeAboutColon) { | 546 TEST_F(SdchFilterTest, NoDecodeAboutColon) { |
| 547 // Construct a valid SDCH dictionary from a VCDIFF dictionary. | 547 // Construct a valid SDCH dictionary from a VCDIFF dictionary. |
| 548 const std::string kSampleDomain = "sdchtest.com"; | 548 const std::string kSampleDomain = "sdchtest.com"; |
| 549 std::string dictionary(NewSdchDictionary(kSampleDomain)); | 549 std::string dictionary(NewSdchDictionary(kSampleDomain)); |
| 550 | 550 |
| 551 std::string url_string = "http://" + kSampleDomain; | 551 std::string url_string = "http://" + kSampleDomain; |
| 552 | 552 |
| 553 GURL url(url_string); | 553 GURL url(url_string); |
| 554 EXPECT_TRUE(sdch_manager_->AddSdchDictionary(dictionary, url)); | 554 EXPECT_TRUE(sdch_manager_->AddSdchDictionary(dictionary, url)); |
| 555 | 555 |
| 556 std::string compressed(NewSdchCompressedData(dictionary)); | 556 std::string compressed(NewSdchCompressedData(dictionary)); |
| 557 | 557 |
| 558 std::vector<Filter::FilterType> filter_types; | 558 std::vector<Filter::FilterType> filter_types; |
| 559 filter_types.push_back(Filter::FILTER_TYPE_SDCH); | 559 filter_types.push_back(Filter::FILTER_TYPE_SDCH); |
| 560 | 560 |
| 561 const int kInputBufferSize(100); | 561 const int kInputBufferSize(100); |
| 562 MockFilterContext filter_context(kInputBufferSize); | 562 net::MockFilterContext filter_context(kInputBufferSize); |
| 563 filter_context.SetURL(GURL("about://" + kSampleDomain)); | 563 filter_context.SetURL(GURL("about://" + kSampleDomain)); |
| 564 scoped_ptr<Filter> filter(Filter::Factory(filter_types, filter_context)); | 564 scoped_ptr<Filter> filter(Filter::Factory(filter_types, filter_context)); |
| 565 | 565 |
| 566 const size_t feed_block_size(100); | 566 const size_t feed_block_size(100); |
| 567 const size_t output_block_size(100); | 567 const size_t output_block_size(100); |
| 568 std::string output; | 568 std::string output; |
| 569 | 569 |
| 570 EXPECT_FALSE(FilterTestData(compressed, feed_block_size, output_block_size, | 570 EXPECT_FALSE(FilterTestData(compressed, feed_block_size, output_block_size, |
| 571 filter.get(), &output)); | 571 filter.get(), &output)); |
| 572 } | 572 } |
| 573 | 573 |
| 574 TEST_F(SdchFilterTest, NoDecodeJavaScript) { | 574 TEST_F(SdchFilterTest, NoDecodeJavaScript) { |
| 575 // Construct a valid SDCH dictionary from a VCDIFF dictionary. | 575 // Construct a valid SDCH dictionary from a VCDIFF dictionary. |
| 576 const std::string kSampleDomain = "sdchtest.com"; | 576 const std::string kSampleDomain = "sdchtest.com"; |
| 577 std::string dictionary(NewSdchDictionary(kSampleDomain)); | 577 std::string dictionary(NewSdchDictionary(kSampleDomain)); |
| 578 | 578 |
| 579 std::string url_string = "http://" + kSampleDomain; | 579 std::string url_string = "http://" + kSampleDomain; |
| 580 | 580 |
| 581 GURL url(url_string); | 581 GURL url(url_string); |
| 582 EXPECT_TRUE(sdch_manager_->AddSdchDictionary(dictionary, url)); | 582 EXPECT_TRUE(sdch_manager_->AddSdchDictionary(dictionary, url)); |
| 583 | 583 |
| 584 std::string compressed(NewSdchCompressedData(dictionary)); | 584 std::string compressed(NewSdchCompressedData(dictionary)); |
| 585 | 585 |
| 586 std::vector<Filter::FilterType> filter_types; | 586 std::vector<Filter::FilterType> filter_types; |
| 587 filter_types.push_back(Filter::FILTER_TYPE_SDCH); | 587 filter_types.push_back(Filter::FILTER_TYPE_SDCH); |
| 588 | 588 |
| 589 const int kInputBufferSize(100); | 589 const int kInputBufferSize(100); |
| 590 MockFilterContext filter_context(kInputBufferSize); | 590 net::MockFilterContext filter_context(kInputBufferSize); |
| 591 filter_context.SetURL(GURL("javascript://" + kSampleDomain)); | 591 filter_context.SetURL(GURL("javascript://" + kSampleDomain)); |
| 592 scoped_ptr<Filter> filter(Filter::Factory(filter_types, filter_context)); | 592 scoped_ptr<Filter> filter(Filter::Factory(filter_types, filter_context)); |
| 593 | 593 |
| 594 const size_t feed_block_size(100); | 594 const size_t feed_block_size(100); |
| 595 const size_t output_block_size(100); | 595 const size_t output_block_size(100); |
| 596 std::string output; | 596 std::string output; |
| 597 | 597 |
| 598 EXPECT_FALSE(FilterTestData(compressed, feed_block_size, output_block_size, | 598 EXPECT_FALSE(FilterTestData(compressed, feed_block_size, output_block_size, |
| 599 filter.get(), &output)); | 599 filter.get(), &output)); |
| 600 } | 600 } |
| 601 | 601 |
| 602 TEST_F(SdchFilterTest, CanStillDecodeHttp) { | 602 TEST_F(SdchFilterTest, CanStillDecodeHttp) { |
| 603 // Construct a valid SDCH dictionary from a VCDIFF dictionary. | 603 // Construct a valid SDCH dictionary from a VCDIFF dictionary. |
| 604 const std::string kSampleDomain = "sdchtest.com"; | 604 const std::string kSampleDomain = "sdchtest.com"; |
| 605 std::string dictionary(NewSdchDictionary(kSampleDomain)); | 605 std::string dictionary(NewSdchDictionary(kSampleDomain)); |
| 606 | 606 |
| 607 std::string url_string = "http://" + kSampleDomain; | 607 std::string url_string = "http://" + kSampleDomain; |
| 608 | 608 |
| 609 GURL url(url_string); | 609 GURL url(url_string); |
| 610 EXPECT_TRUE(sdch_manager_->AddSdchDictionary(dictionary, url)); | 610 EXPECT_TRUE(sdch_manager_->AddSdchDictionary(dictionary, url)); |
| 611 | 611 |
| 612 std::string compressed(NewSdchCompressedData(dictionary)); | 612 std::string compressed(NewSdchCompressedData(dictionary)); |
| 613 | 613 |
| 614 std::vector<Filter::FilterType> filter_types; | 614 std::vector<Filter::FilterType> filter_types; |
| 615 filter_types.push_back(Filter::FILTER_TYPE_SDCH); | 615 filter_types.push_back(Filter::FILTER_TYPE_SDCH); |
| 616 | 616 |
| 617 const int kInputBufferSize(100); | 617 const int kInputBufferSize(100); |
| 618 MockFilterContext filter_context(kInputBufferSize); | 618 net::MockFilterContext filter_context(kInputBufferSize); |
| 619 filter_context.SetURL(GURL("http://" + kSampleDomain)); | 619 filter_context.SetURL(GURL("http://" + kSampleDomain)); |
| 620 scoped_ptr<Filter> filter(Filter::Factory(filter_types, filter_context)); | 620 scoped_ptr<Filter> filter(Filter::Factory(filter_types, filter_context)); |
| 621 | 621 |
| 622 const size_t feed_block_size(100); | 622 const size_t feed_block_size(100); |
| 623 const size_t output_block_size(100); | 623 const size_t output_block_size(100); |
| 624 std::string output; | 624 std::string output; |
| 625 | 625 |
| 626 EXPECT_TRUE(FilterTestData(compressed, feed_block_size, output_block_size, | 626 EXPECT_TRUE(FilterTestData(compressed, feed_block_size, output_block_size, |
| 627 filter.get(), &output)); | 627 filter.get(), &output)); |
| 628 } | 628 } |
| 629 | 629 |
| 630 TEST_F(SdchFilterTest, CrossDomainDictionaryUse) { | 630 TEST_F(SdchFilterTest, CrossDomainDictionaryUse) { |
| 631 // Construct a valid SDCH dictionary from a VCDIFF dictionary. | 631 // Construct a valid SDCH dictionary from a VCDIFF dictionary. |
| 632 const std::string kSampleDomain = "sdchtest.com"; | 632 const std::string kSampleDomain = "sdchtest.com"; |
| 633 std::string dictionary(NewSdchDictionary(kSampleDomain)); | 633 std::string dictionary(NewSdchDictionary(kSampleDomain)); |
| 634 | 634 |
| 635 std::string url_string = "http://" + kSampleDomain; | 635 std::string url_string = "http://" + kSampleDomain; |
| 636 | 636 |
| 637 GURL url(url_string); | 637 GURL url(url_string); |
| 638 EXPECT_TRUE(sdch_manager_->AddSdchDictionary(dictionary, url)); | 638 EXPECT_TRUE(sdch_manager_->AddSdchDictionary(dictionary, url)); |
| 639 | 639 |
| 640 std::string compressed(NewSdchCompressedData(dictionary)); | 640 std::string compressed(NewSdchCompressedData(dictionary)); |
| 641 | 641 |
| 642 std::vector<Filter::FilterType> filter_types; | 642 std::vector<Filter::FilterType> filter_types; |
| 643 filter_types.push_back(Filter::FILTER_TYPE_SDCH); | 643 filter_types.push_back(Filter::FILTER_TYPE_SDCH); |
| 644 const int kInputBufferSize(100); | 644 const int kInputBufferSize(100); |
| 645 | 645 |
| 646 // Decode with content arriving from the "wrong" domain. | 646 // Decode with content arriving from the "wrong" domain. |
| 647 // This tests SdchManager::CanSet(). | 647 // This tests SdchManager::CanSet(). |
| 648 MockFilterContext filter_context(kInputBufferSize); | 648 net::MockFilterContext filter_context(kInputBufferSize); |
| 649 GURL wrong_domain_url("http://www.wrongdomain.com"); | 649 GURL wrong_domain_url("http://www.wrongdomain.com"); |
| 650 filter_context.SetURL(wrong_domain_url); | 650 filter_context.SetURL(wrong_domain_url); |
| 651 scoped_ptr<Filter> filter((Filter::Factory(filter_types, filter_context))); | 651 scoped_ptr<Filter> filter((Filter::Factory(filter_types, filter_context))); |
| 652 | 652 |
| 653 size_t feed_block_size = 100; | 653 size_t feed_block_size = 100; |
| 654 size_t output_block_size = 100; | 654 size_t output_block_size = 100; |
| 655 std::string output; | 655 std::string output; |
| 656 EXPECT_FALSE(FilterTestData(compressed, feed_block_size, output_block_size, | 656 EXPECT_FALSE(FilterTestData(compressed, feed_block_size, output_block_size, |
| 657 filter.get(), &output)); | 657 filter.get(), &output)); |
| 658 EXPECT_EQ(output.size(), 0u); // No output written. | 658 EXPECT_EQ(output.size(), 0u); // No output written. |
| (...skipping 20 matching lines...) Expand all Loading... |
| 679 dictionary_with_path.append(dictionary); | 679 dictionary_with_path.append(dictionary); |
| 680 EXPECT_TRUE(sdch_manager_->AddSdchDictionary(dictionary_with_path, url)); | 680 EXPECT_TRUE(sdch_manager_->AddSdchDictionary(dictionary_with_path, url)); |
| 681 | 681 |
| 682 std::string compressed_for_path(NewSdchCompressedData(dictionary_with_path)); | 682 std::string compressed_for_path(NewSdchCompressedData(dictionary_with_path)); |
| 683 | 683 |
| 684 std::vector<Filter::FilterType> filter_types; | 684 std::vector<Filter::FilterType> filter_types; |
| 685 filter_types.push_back(Filter::FILTER_TYPE_SDCH); | 685 filter_types.push_back(Filter::FILTER_TYPE_SDCH); |
| 686 const int kInputBufferSize(100); | 686 const int kInputBufferSize(100); |
| 687 | 687 |
| 688 // Test decode the path data, arriving from a valid path. | 688 // Test decode the path data, arriving from a valid path. |
| 689 MockFilterContext filter_context(kInputBufferSize); | 689 net::MockFilterContext filter_context(kInputBufferSize); |
| 690 filter_context.SetURL(GURL(url_string + path)); | 690 filter_context.SetURL(GURL(url_string + path)); |
| 691 scoped_ptr<Filter> filter((Filter::Factory(filter_types, filter_context))); | 691 scoped_ptr<Filter> filter((Filter::Factory(filter_types, filter_context))); |
| 692 | 692 |
| 693 size_t feed_block_size = 100; | 693 size_t feed_block_size = 100; |
| 694 size_t output_block_size = 100; | 694 size_t output_block_size = 100; |
| 695 std::string output; | 695 std::string output; |
| 696 | 696 |
| 697 EXPECT_TRUE(FilterTestData(compressed_for_path, feed_block_size, | 697 EXPECT_TRUE(FilterTestData(compressed_for_path, feed_block_size, |
| 698 output_block_size, filter.get(), &output)); | 698 output_block_size, filter.get(), &output)); |
| 699 EXPECT_EQ(output, expanded_); | 699 EXPECT_EQ(output, expanded_); |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 733 EXPECT_TRUE(sdch_manager_->AddSdchDictionary(dictionary_with_port, | 733 EXPECT_TRUE(sdch_manager_->AddSdchDictionary(dictionary_with_port, |
| 734 GURL(url_string + ":" + port))); | 734 GURL(url_string + ":" + port))); |
| 735 | 735 |
| 736 std::string compressed_for_port(NewSdchCompressedData(dictionary_with_port)); | 736 std::string compressed_for_port(NewSdchCompressedData(dictionary_with_port)); |
| 737 | 737 |
| 738 std::vector<Filter::FilterType> filter_types; | 738 std::vector<Filter::FilterType> filter_types; |
| 739 filter_types.push_back(Filter::FILTER_TYPE_SDCH); | 739 filter_types.push_back(Filter::FILTER_TYPE_SDCH); |
| 740 const int kInputBufferSize(100); | 740 const int kInputBufferSize(100); |
| 741 | 741 |
| 742 // Test decode the port data, arriving from a valid port. | 742 // Test decode the port data, arriving from a valid port. |
| 743 MockFilterContext filter_context(kInputBufferSize); | 743 net::MockFilterContext filter_context(kInputBufferSize); |
| 744 filter_context.SetURL(GURL(url_string + ":" + port)); | 744 filter_context.SetURL(GURL(url_string + ":" + port)); |
| 745 scoped_ptr<Filter> filter((Filter::Factory(filter_types, filter_context))); | 745 scoped_ptr<Filter> filter((Filter::Factory(filter_types, filter_context))); |
| 746 | 746 |
| 747 size_t feed_block_size = 100; | 747 size_t feed_block_size = 100; |
| 748 size_t output_block_size = 100; | 748 size_t output_block_size = 100; |
| 749 std::string output; | 749 std::string output; |
| 750 EXPECT_TRUE(FilterTestData(compressed_for_port, feed_block_size, | 750 EXPECT_TRUE(FilterTestData(compressed_for_port, feed_block_size, |
| 751 output_block_size, filter.get(), &output)); | 751 output_block_size, filter.get(), &output)); |
| 752 EXPECT_EQ(output, expanded_); | 752 EXPECT_EQ(output, expanded_); |
| 753 | 753 |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 856 // Construct a chained filter. | 856 // Construct a chained filter. |
| 857 std::vector<Filter::FilterType> filter_types; | 857 std::vector<Filter::FilterType> filter_types; |
| 858 filter_types.push_back(Filter::FILTER_TYPE_SDCH); | 858 filter_types.push_back(Filter::FILTER_TYPE_SDCH); |
| 859 filter_types.push_back(Filter::FILTER_TYPE_GZIP); | 859 filter_types.push_back(Filter::FILTER_TYPE_GZIP); |
| 860 | 860 |
| 861 // First try with a large buffer (larger than test input, or compressed data). | 861 // First try with a large buffer (larger than test input, or compressed data). |
| 862 const size_t kLargeInputBufferSize(1000); // Used internally in filters. | 862 const size_t kLargeInputBufferSize(1000); // Used internally in filters. |
| 863 CHECK_GT(kLargeInputBufferSize, gzip_compressed_sdch.size()); | 863 CHECK_GT(kLargeInputBufferSize, gzip_compressed_sdch.size()); |
| 864 CHECK_GT(kLargeInputBufferSize, sdch_compressed.size()); | 864 CHECK_GT(kLargeInputBufferSize, sdch_compressed.size()); |
| 865 CHECK_GT(kLargeInputBufferSize, expanded_.size()); | 865 CHECK_GT(kLargeInputBufferSize, expanded_.size()); |
| 866 MockFilterContext filter_context(kLargeInputBufferSize); | 866 net::MockFilterContext filter_context(kLargeInputBufferSize); |
| 867 filter_context.SetURL(url); | 867 filter_context.SetURL(url); |
| 868 scoped_ptr<Filter> filter(Filter::Factory(filter_types, filter_context)); | 868 scoped_ptr<Filter> filter(Filter::Factory(filter_types, filter_context)); |
| 869 | 869 |
| 870 // Verify that chained filter is waiting for data. | 870 // Verify that chained filter is waiting for data. |
| 871 char tiny_output_buffer[10]; | 871 char tiny_output_buffer[10]; |
| 872 int tiny_output_size = sizeof(tiny_output_buffer); | 872 int tiny_output_size = sizeof(tiny_output_buffer); |
| 873 EXPECT_EQ(Filter::FILTER_NEED_MORE_DATA, | 873 EXPECT_EQ(Filter::FILTER_NEED_MORE_DATA, |
| 874 filter->ReadData(tiny_output_buffer, &tiny_output_size)); | 874 filter->ReadData(tiny_output_buffer, &tiny_output_size)); |
| 875 | 875 |
| 876 // Make chain process all data. | 876 // Make chain process all data. |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 926 | 926 |
| 927 // Use Gzip to compress the sdch sdch_compressed data. | 927 // Use Gzip to compress the sdch sdch_compressed data. |
| 928 std::string gzip_compressed_sdch = gzip_compress(sdch_compressed); | 928 std::string gzip_compressed_sdch = gzip_compress(sdch_compressed); |
| 929 | 929 |
| 930 // Only claim to have sdch content, but really use the gzipped sdch content. | 930 // Only claim to have sdch content, but really use the gzipped sdch content. |
| 931 // System should automatically add the missing (optional) gzip. | 931 // System should automatically add the missing (optional) gzip. |
| 932 std::vector<Filter::FilterType> filter_types; | 932 std::vector<Filter::FilterType> filter_types; |
| 933 filter_types.push_back(Filter::FILTER_TYPE_SDCH); | 933 filter_types.push_back(Filter::FILTER_TYPE_SDCH); |
| 934 | 934 |
| 935 const int kInputBufferSize(100); | 935 const int kInputBufferSize(100); |
| 936 MockFilterContext filter_context(kInputBufferSize); | 936 net::MockFilterContext filter_context(kInputBufferSize); |
| 937 filter_context.SetMimeType("anything/mime"); | 937 filter_context.SetMimeType("anything/mime"); |
| 938 filter_context.SetSdchResponse(true); | 938 filter_context.SetSdchResponse(true); |
| 939 Filter::FixupEncodingTypes(filter_context, &filter_types); | 939 Filter::FixupEncodingTypes(filter_context, &filter_types); |
| 940 ASSERT_EQ(filter_types.size(), 2u); | 940 ASSERT_EQ(filter_types.size(), 2u); |
| 941 EXPECT_EQ(filter_types[0], Filter::FILTER_TYPE_SDCH); | 941 EXPECT_EQ(filter_types[0], Filter::FILTER_TYPE_SDCH); |
| 942 EXPECT_EQ(filter_types[1], Filter::FILTER_TYPE_GZIP_HELPING_SDCH); | 942 EXPECT_EQ(filter_types[1], Filter::FILTER_TYPE_GZIP_HELPING_SDCH); |
| 943 | 943 |
| 944 // First try with a large buffer (larger than test input, or compressed data). | 944 // First try with a large buffer (larger than test input, or compressed data). |
| 945 filter_context.SetURL(url); | 945 filter_context.SetURL(url); |
| 946 scoped_ptr<Filter> filter(Filter::Factory(filter_types, filter_context)); | 946 scoped_ptr<Filter> filter(Filter::Factory(filter_types, filter_context)); |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 986 std::string gzip_compressed_sdch = gzip_compress(sdch_compressed); | 986 std::string gzip_compressed_sdch = gzip_compress(sdch_compressed); |
| 987 | 987 |
| 988 // Some proxies strip the content encoding statement down to a mere gzip, but | 988 // Some proxies strip the content encoding statement down to a mere gzip, but |
| 989 // pass through the original content (with full sdch,gzip encoding). | 989 // pass through the original content (with full sdch,gzip encoding). |
| 990 // Only claim to have gzip content, but really use the gzipped sdch content. | 990 // Only claim to have gzip content, but really use the gzipped sdch content. |
| 991 // System should automatically add the missing (optional) sdch. | 991 // System should automatically add the missing (optional) sdch. |
| 992 std::vector<Filter::FilterType> filter_types; | 992 std::vector<Filter::FilterType> filter_types; |
| 993 filter_types.push_back(Filter::FILTER_TYPE_GZIP); | 993 filter_types.push_back(Filter::FILTER_TYPE_GZIP); |
| 994 | 994 |
| 995 const int kInputBufferSize(100); | 995 const int kInputBufferSize(100); |
| 996 MockFilterContext filter_context(kInputBufferSize); | 996 net::MockFilterContext filter_context(kInputBufferSize); |
| 997 filter_context.SetMimeType("anything/mime"); | 997 filter_context.SetMimeType("anything/mime"); |
| 998 filter_context.SetSdchResponse(true); | 998 filter_context.SetSdchResponse(true); |
| 999 Filter::FixupEncodingTypes(filter_context, &filter_types); | 999 Filter::FixupEncodingTypes(filter_context, &filter_types); |
| 1000 ASSERT_EQ(filter_types.size(), 3u); | 1000 ASSERT_EQ(filter_types.size(), 3u); |
| 1001 EXPECT_EQ(filter_types[0], Filter::FILTER_TYPE_SDCH_POSSIBLE); | 1001 EXPECT_EQ(filter_types[0], Filter::FILTER_TYPE_SDCH_POSSIBLE); |
| 1002 EXPECT_EQ(filter_types[1], Filter::FILTER_TYPE_GZIP_HELPING_SDCH); | 1002 EXPECT_EQ(filter_types[1], Filter::FILTER_TYPE_GZIP_HELPING_SDCH); |
| 1003 EXPECT_EQ(filter_types[2], Filter::FILTER_TYPE_GZIP); | 1003 EXPECT_EQ(filter_types[2], Filter::FILTER_TYPE_GZIP); |
| 1004 | 1004 |
| 1005 // First try with a large buffer (larger than test input, or compressed data). | 1005 // First try with a large buffer (larger than test input, or compressed data). |
| 1006 filter_context.SetURL(url); | 1006 filter_context.SetURL(url); |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1045 | 1045 |
| 1046 // Use Gzip to compress the sdch sdch_compressed data. | 1046 // Use Gzip to compress the sdch sdch_compressed data. |
| 1047 std::string gzip_compressed_sdch = gzip_compress(sdch_compressed); | 1047 std::string gzip_compressed_sdch = gzip_compress(sdch_compressed); |
| 1048 | 1048 |
| 1049 // Only claim to have non-encoded content, but really use the gzipped sdch | 1049 // Only claim to have non-encoded content, but really use the gzipped sdch |
| 1050 // content. | 1050 // content. |
| 1051 // System should automatically add the missing (optional) sdch,gzip. | 1051 // System should automatically add the missing (optional) sdch,gzip. |
| 1052 std::vector<Filter::FilterType> filter_types; | 1052 std::vector<Filter::FilterType> filter_types; |
| 1053 | 1053 |
| 1054 const int kInputBufferSize(100); | 1054 const int kInputBufferSize(100); |
| 1055 MockFilterContext filter_context(kInputBufferSize); | 1055 net::MockFilterContext filter_context(kInputBufferSize); |
| 1056 filter_context.SetMimeType("anything/mime"); | 1056 filter_context.SetMimeType("anything/mime"); |
| 1057 filter_context.SetSdchResponse(true); | 1057 filter_context.SetSdchResponse(true); |
| 1058 Filter::FixupEncodingTypes(filter_context, &filter_types); | 1058 Filter::FixupEncodingTypes(filter_context, &filter_types); |
| 1059 ASSERT_EQ(filter_types.size(), 2u); | 1059 ASSERT_EQ(filter_types.size(), 2u); |
| 1060 EXPECT_EQ(filter_types[0], Filter::FILTER_TYPE_SDCH_POSSIBLE); | 1060 EXPECT_EQ(filter_types[0], Filter::FILTER_TYPE_SDCH_POSSIBLE); |
| 1061 EXPECT_EQ(filter_types[1], Filter::FILTER_TYPE_GZIP_HELPING_SDCH); | 1061 EXPECT_EQ(filter_types[1], Filter::FILTER_TYPE_GZIP_HELPING_SDCH); |
| 1062 | 1062 |
| 1063 // First try with a large buffer (larger than test input, or compressed data). | 1063 // First try with a large buffer (larger than test input, or compressed data). |
| 1064 filter_context.SetURL(url); | 1064 filter_context.SetURL(url); |
| 1065 scoped_ptr<Filter> filter(Filter::Factory(filter_types, filter_context)); | 1065 scoped_ptr<Filter> filter(Filter::Factory(filter_types, filter_context)); |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1108 std::string double_gzip_compressed_sdch = gzip_compress(gzip_compress( | 1108 std::string double_gzip_compressed_sdch = gzip_compress(gzip_compress( |
| 1109 sdch_compressed)); | 1109 sdch_compressed)); |
| 1110 | 1110 |
| 1111 // Only claim to have gzip content, but really use the double gzipped sdch | 1111 // Only claim to have gzip content, but really use the double gzipped sdch |
| 1112 // content. | 1112 // content. |
| 1113 // System should automatically add the missing (optional) sdch, gzip decoders. | 1113 // System should automatically add the missing (optional) sdch, gzip decoders. |
| 1114 std::vector<Filter::FilterType> filter_types; | 1114 std::vector<Filter::FilterType> filter_types; |
| 1115 filter_types.push_back(Filter::FILTER_TYPE_GZIP); | 1115 filter_types.push_back(Filter::FILTER_TYPE_GZIP); |
| 1116 | 1116 |
| 1117 const int kInputBufferSize(100); | 1117 const int kInputBufferSize(100); |
| 1118 MockFilterContext filter_context(kInputBufferSize); | 1118 net::MockFilterContext filter_context(kInputBufferSize); |
| 1119 filter_context.SetMimeType("anything/mime"); | 1119 filter_context.SetMimeType("anything/mime"); |
| 1120 filter_context.SetSdchResponse(true); | 1120 filter_context.SetSdchResponse(true); |
| 1121 Filter::FixupEncodingTypes(filter_context, &filter_types); | 1121 Filter::FixupEncodingTypes(filter_context, &filter_types); |
| 1122 ASSERT_EQ(filter_types.size(), 3u); | 1122 ASSERT_EQ(filter_types.size(), 3u); |
| 1123 EXPECT_EQ(filter_types[0], Filter::FILTER_TYPE_SDCH_POSSIBLE); | 1123 EXPECT_EQ(filter_types[0], Filter::FILTER_TYPE_SDCH_POSSIBLE); |
| 1124 EXPECT_EQ(filter_types[1], Filter::FILTER_TYPE_GZIP_HELPING_SDCH); | 1124 EXPECT_EQ(filter_types[1], Filter::FILTER_TYPE_GZIP_HELPING_SDCH); |
| 1125 EXPECT_EQ(filter_types[2], Filter::FILTER_TYPE_GZIP); | 1125 EXPECT_EQ(filter_types[2], Filter::FILTER_TYPE_GZIP); |
| 1126 | 1126 |
| 1127 // First try with a large buffer (larger than test input, or compressed data). | 1127 // First try with a large buffer (larger than test input, or compressed data). |
| 1128 filter_context.SetURL(url); | 1128 filter_context.SetURL(url); |
| (...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1397 | 1397 |
| 1398 // And can reset them to false. | 1398 // And can reset them to false. |
| 1399 sdch_manager_->SetAllowLatencyExperiment(url, false); | 1399 sdch_manager_->SetAllowLatencyExperiment(url, false); |
| 1400 EXPECT_FALSE(sdch_manager_->AllowLatencyExperiment(url)); | 1400 EXPECT_FALSE(sdch_manager_->AllowLatencyExperiment(url)); |
| 1401 EXPECT_TRUE(sdch_manager_->AllowLatencyExperiment(url2)); | 1401 EXPECT_TRUE(sdch_manager_->AllowLatencyExperiment(url2)); |
| 1402 | 1402 |
| 1403 sdch_manager_->SetAllowLatencyExperiment(url2, false); | 1403 sdch_manager_->SetAllowLatencyExperiment(url2, false); |
| 1404 EXPECT_FALSE(sdch_manager_->AllowLatencyExperiment(url)); | 1404 EXPECT_FALSE(sdch_manager_->AllowLatencyExperiment(url)); |
| 1405 EXPECT_FALSE(sdch_manager_->AllowLatencyExperiment(url2)); | 1405 EXPECT_FALSE(sdch_manager_->AllowLatencyExperiment(url2)); |
| 1406 } | 1406 } |
| OLD | NEW |