Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(16)

Side by Side Diff: net/base/sdch_filter_unittest.cc

Issue 8018: Clean up filter and content encoding handling ... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 12 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « net/base/sdch_filter.cc ('k') | net/base/sdch_manager.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 // TODO(jar): Change file name to *_unittest.cc (with double "t').
6
7 #include <algorithm> 5 #include <algorithm>
8 #include <string> 6 #include <string>
9 #include <vector> 7 #include <vector>
10 8
11 #include "base/logging.h" 9 #include "base/logging.h"
12 #include "base/scoped_ptr.h" 10 #include "base/scoped_ptr.h"
13 #include "net/base/filter.h" 11 #include "net/base/filter.h"
14 #include "net/base/sdch_filter.h" 12 #include "net/base/sdch_filter.h"
15 #include "net/url_request/url_request_http_job.cc" 13 #include "net/url_request/url_request_http_job.cc"
16 #include "testing/gtest/include/gtest/gtest.h" 14 #include "testing/gtest/include/gtest/gtest.h"
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
123 dictionary.append("\n"); 121 dictionary.append("\n");
124 } 122 }
125 dictionary.append("\n"); 123 dictionary.append("\n");
126 dictionary.append(kTestVcdiffDictionary, sizeof(kTestVcdiffDictionary) - 1); 124 dictionary.append(kTestVcdiffDictionary, sizeof(kTestVcdiffDictionary) - 1);
127 return dictionary; 125 return dictionary;
128 } 126 }
129 127
130 //------------------------------------------------------------------------------ 128 //------------------------------------------------------------------------------
131 129
132 TEST_F(SdchFilterTest, BasicBadDictionary) { 130 TEST_F(SdchFilterTest, BasicBadDictionary) {
133 std::vector<std::string> filters; 131 std::vector<Filter::FilterType> filter_types;
134 filters.push_back("sdch"); 132 filter_types.push_back(Filter::FILTER_TYPE_SDCH);
135 const int kInputBufferSize(30); 133 const int kInputBufferSize(30);
136 char output_buffer[20]; 134 char output_buffer[20];
137 scoped_ptr<Filter> filter(Filter::Factory(filters, "missing-mime", 135 scoped_ptr<Filter> filter(Filter::Factory(filter_types, kInputBufferSize));
138 kInputBufferSize));
139 std::string url_string("http://ignore.com"); 136 std::string url_string("http://ignore.com");
140 filter->SetURL(GURL(url_string)); 137 filter->SetURL(GURL(url_string));
141 138
142 139
143 // With no input data, try to read output. 140 // With no input data, try to read output.
144 int output_bytes_or_buffer_size = sizeof(output_buffer); 141 int output_bytes_or_buffer_size = sizeof(output_buffer);
145 Filter::FilterStatus status = filter->ReadData(output_buffer, 142 Filter::FilterStatus status = filter->ReadData(output_buffer,
146 &output_bytes_or_buffer_size); 143 &output_bytes_or_buffer_size);
147 144
148 EXPECT_EQ(0, output_bytes_or_buffer_size); 145 EXPECT_EQ(0, output_bytes_or_buffer_size);
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
218 const std::string kSampleDomain = "sdchtest.com"; 215 const std::string kSampleDomain = "sdchtest.com";
219 std::string dictionary(NewSdchDictionary(kSampleDomain)); 216 std::string dictionary(NewSdchDictionary(kSampleDomain));
220 217
221 std::string url_string = "http://" + kSampleDomain; 218 std::string url_string = "http://" + kSampleDomain;
222 219
223 GURL url(url_string); 220 GURL url(url_string);
224 EXPECT_TRUE(sdch_manager_->AddSdchDictionary(dictionary, url)); 221 EXPECT_TRUE(sdch_manager_->AddSdchDictionary(dictionary, url));
225 222
226 std::string compressed(NewSdchCompressedData(dictionary)); 223 std::string compressed(NewSdchCompressedData(dictionary));
227 224
228 std::vector<std::string> filters; 225 std::vector<Filter::FilterType> filter_types;
229 filters.push_back("sdch"); 226 filter_types.push_back(Filter::FILTER_TYPE_SDCH);
230 227
231 // Decode with a large buffer (larger than test input, or compressed data). 228 // Decode with a large buffer (larger than test input, or compressed data).
232 const int kInputBufferSize(100); 229 const int kInputBufferSize(100);
233 scoped_ptr<Filter> filter(Filter::Factory(filters, "missing-mime", 230 scoped_ptr<Filter> filter(Filter::Factory(filter_types, kInputBufferSize));
234 kInputBufferSize));
235 filter->SetURL(url); 231 filter->SetURL(url);
236 232
237 size_t feed_block_size = 100; 233 size_t feed_block_size = 100;
238 size_t output_block_size = 100; 234 size_t output_block_size = 100;
239 std::string output; 235 std::string output;
240 EXPECT_TRUE(FilterTestData(compressed, feed_block_size, output_block_size, 236 EXPECT_TRUE(FilterTestData(compressed, feed_block_size, output_block_size,
241 filter.get(), &output)); 237 filter.get(), &output));
242 EXPECT_EQ(output, expanded_); 238 EXPECT_EQ(output, expanded_);
243 239
244 // Decode with really small buffers (size 1) to check for edge effects. 240 // Decode with really small buffers (size 1) to check for edge effects.
245 filter.reset((Filter::Factory(filters, "missing-mime", kInputBufferSize))); 241 filter.reset((Filter::Factory(filter_types, kInputBufferSize)));
246 filter->SetURL(url); 242 filter->SetURL(url);
247 243
248 feed_block_size = 1; 244 feed_block_size = 1;
249 output_block_size = 1; 245 output_block_size = 1;
250 output.clear(); 246 output.clear();
251 EXPECT_TRUE(FilterTestData(compressed, feed_block_size, output_block_size, 247 EXPECT_TRUE(FilterTestData(compressed, feed_block_size, output_block_size,
252 filter.get(), &output)); 248 filter.get(), &output));
253 EXPECT_EQ(output, expanded_); 249 EXPECT_EQ(output, expanded_);
254 } 250 }
255 251
256 TEST_F(SdchFilterTest, CrossDomainDictionaryUse) { 252 TEST_F(SdchFilterTest, CrossDomainDictionaryUse) {
257 // Construct a valid SDCH dictionary from a VCDIFF dictionary. 253 // Construct a valid SDCH dictionary from a VCDIFF dictionary.
258 const std::string kSampleDomain = "sdchtest.com"; 254 const std::string kSampleDomain = "sdchtest.com";
259 std::string dictionary(NewSdchDictionary(kSampleDomain)); 255 std::string dictionary(NewSdchDictionary(kSampleDomain));
260 256
261 std::string url_string = "http://" + kSampleDomain; 257 std::string url_string = "http://" + kSampleDomain;
262 258
263 GURL url(url_string); 259 GURL url(url_string);
264 EXPECT_TRUE(sdch_manager_->AddSdchDictionary(dictionary, url)); 260 EXPECT_TRUE(sdch_manager_->AddSdchDictionary(dictionary, url));
265 261
266 std::string compressed(NewSdchCompressedData(dictionary)); 262 std::string compressed(NewSdchCompressedData(dictionary));
267 263
268 std::vector<std::string> filters; 264 std::vector<Filter::FilterType> filter_types;
269 filters.push_back("sdch"); 265 filter_types.push_back(Filter::FILTER_TYPE_SDCH);
270 const int kInputBufferSize(100); 266 const int kInputBufferSize(100);
271 267
272 // Decode with content arriving from the "wrong" domain. 268 // Decode with content arriving from the "wrong" domain.
273 // This tests CanSet() in the sdch_manager_-> 269 // This tests CanSet() in the sdch_manager_->
274 scoped_ptr<Filter> filter((Filter::Factory(filters, "missing-mime", 270 scoped_ptr<Filter> filter((Filter::Factory(filter_types, kInputBufferSize)));
275 kInputBufferSize)));
276 GURL wrong_domain_url("http://www.wrongdomain.com"); 271 GURL wrong_domain_url("http://www.wrongdomain.com");
277 filter->SetURL(wrong_domain_url); 272 filter->SetURL(wrong_domain_url);
278 273
279 size_t feed_block_size = 100; 274 size_t feed_block_size = 100;
280 size_t output_block_size = 100; 275 size_t output_block_size = 100;
281 std::string output; 276 std::string output;
282 EXPECT_FALSE(FilterTestData(compressed, feed_block_size, output_block_size, 277 EXPECT_FALSE(FilterTestData(compressed, feed_block_size, output_block_size,
283 filter.get(), &output)); 278 filter.get(), &output));
284 EXPECT_EQ(output.size(), 0u); // No output written. 279 EXPECT_EQ(output.size(), 0u); // No output written.
285 280
(...skipping 14 matching lines...) Expand all
300 EXPECT_TRUE(sdch_manager_->AddSdchDictionary(dictionary, url)); 295 EXPECT_TRUE(sdch_manager_->AddSdchDictionary(dictionary, url));
301 296
302 // Create a dictionary with a path restriction, by prefixing dictionary. 297 // Create a dictionary with a path restriction, by prefixing dictionary.
303 const std::string path("/special_path/bin"); 298 const std::string path("/special_path/bin");
304 std::string dictionary_with_path("Path: " + path + "\n"); 299 std::string dictionary_with_path("Path: " + path + "\n");
305 dictionary_with_path.append(dictionary); 300 dictionary_with_path.append(dictionary);
306 EXPECT_TRUE(sdch_manager_->AddSdchDictionary(dictionary_with_path, url)); 301 EXPECT_TRUE(sdch_manager_->AddSdchDictionary(dictionary_with_path, url));
307 302
308 std::string compressed_for_path(NewSdchCompressedData(dictionary_with_path)); 303 std::string compressed_for_path(NewSdchCompressedData(dictionary_with_path));
309 304
310 std::vector<std::string> filters; 305 std::vector<Filter::FilterType> filter_types;
311 filters.push_back("sdch"); 306 filter_types.push_back(Filter::FILTER_TYPE_SDCH);
312 const int kInputBufferSize(100); 307 const int kInputBufferSize(100);
313 308
314 // Test decode the path data, arriving from a valid path. 309 // Test decode the path data, arriving from a valid path.
315 scoped_ptr<Filter> filter((Filter::Factory(filters, "missing-mime", 310 scoped_ptr<Filter> filter((Filter::Factory(filter_types, kInputBufferSize)));
316 kInputBufferSize)));
317 filter->SetURL(GURL(url_string + path)); 311 filter->SetURL(GURL(url_string + path));
318 312
319 size_t feed_block_size = 100; 313 size_t feed_block_size = 100;
320 size_t output_block_size = 100; 314 size_t output_block_size = 100;
321 std::string output; 315 std::string output;
322 316
323 EXPECT_TRUE(FilterTestData(compressed_for_path, feed_block_size, 317 EXPECT_TRUE(FilterTestData(compressed_for_path, feed_block_size,
324 output_block_size, filter.get(), &output)); 318 output_block_size, filter.get(), &output));
325 EXPECT_EQ(output, expanded_); 319 EXPECT_EQ(output, expanded_);
326 320
327 // Test decode the path data, arriving from a invalid path. 321 // Test decode the path data, arriving from a invalid path.
328 filter.reset((Filter::Factory(filters, "missing-mime", kInputBufferSize))); 322 filter.reset((Filter::Factory(filter_types, kInputBufferSize)));
329 filter->SetURL(GURL(url_string)); 323 filter->SetURL(GURL(url_string));
330 324
331 feed_block_size = 100; 325 feed_block_size = 100;
332 output_block_size = 100; 326 output_block_size = 100;
333 output.clear(); 327 output.clear();
334 EXPECT_FALSE(FilterTestData(compressed_for_path, feed_block_size, 328 EXPECT_FALSE(FilterTestData(compressed_for_path, feed_block_size,
335 output_block_size, filter.get(), &output)); 329 output_block_size, filter.get(), &output));
336 EXPECT_EQ(output.size(), 0u); // No output written. 330 EXPECT_EQ(output.size(), 0u); // No output written.
337 331
338 EXPECT_FALSE(SdchManager::Global()->IsInSupportedDomain(GURL(url_string))); 332 EXPECT_FALSE(SdchManager::Global()->IsInSupportedDomain(GURL(url_string)));
(...skipping 15 matching lines...) Expand all
354 // Create a dictionary with a port restriction, by prefixing old dictionary. 348 // Create a dictionary with a port restriction, by prefixing old dictionary.
355 const std::string port("502"); 349 const std::string port("502");
356 std::string dictionary_with_port("Port: " + port + "\n"); 350 std::string dictionary_with_port("Port: " + port + "\n");
357 dictionary_with_port.append("Port: 80\n"); // Add default port. 351 dictionary_with_port.append("Port: 80\n"); // Add default port.
358 dictionary_with_port.append(dictionary); 352 dictionary_with_port.append(dictionary);
359 EXPECT_TRUE(sdch_manager_->AddSdchDictionary(dictionary_with_port, 353 EXPECT_TRUE(sdch_manager_->AddSdchDictionary(dictionary_with_port,
360 GURL(url_string + ":" + port))); 354 GURL(url_string + ":" + port)));
361 355
362 std::string compressed_for_port(NewSdchCompressedData(dictionary_with_port)); 356 std::string compressed_for_port(NewSdchCompressedData(dictionary_with_port));
363 357
364 std::vector<std::string> filters; 358 std::vector<Filter::FilterType> filter_types;
365 filters.push_back("sdch"); 359 filter_types.push_back(Filter::FILTER_TYPE_SDCH);
366 const int kInputBufferSize(100); 360 const int kInputBufferSize(100);
367 361
368 // Test decode the port data, arriving from a valid port. 362 // Test decode the port data, arriving from a valid port.
369 scoped_ptr<Filter> filter((Filter::Factory(filters, "missing-mime", 363 scoped_ptr<Filter> filter((Filter::Factory(filter_types, kInputBufferSize)));
370 kInputBufferSize)));
371 filter->SetURL(GURL(url_string + ":" + port)); 364 filter->SetURL(GURL(url_string + ":" + port));
372 365
373 size_t feed_block_size = 100; 366 size_t feed_block_size = 100;
374 size_t output_block_size = 100; 367 size_t output_block_size = 100;
375 std::string output; 368 std::string output;
376 EXPECT_TRUE(FilterTestData(compressed_for_port, feed_block_size, 369 EXPECT_TRUE(FilterTestData(compressed_for_port, feed_block_size,
377 output_block_size, filter.get(), &output)); 370 output_block_size, filter.get(), &output));
378 EXPECT_EQ(output, expanded_); 371 EXPECT_EQ(output, expanded_);
379 372
380 // Test decode the port data, arriving from a valid (default) port. 373 // Test decode the port data, arriving from a valid (default) port.
381 filter.reset((Filter::Factory(filters, "missing-mime", kInputBufferSize))); 374 filter.reset((Filter::Factory(filter_types, kInputBufferSize)));
382 filter->SetURL(GURL(url_string)); // Default port. 375 filter->SetURL(GURL(url_string)); // Default port.
383 376
384 feed_block_size = 100; 377 feed_block_size = 100;
385 output_block_size = 100; 378 output_block_size = 100;
386 output.clear(); 379 output.clear();
387 EXPECT_TRUE(FilterTestData(compressed_for_port, feed_block_size, 380 EXPECT_TRUE(FilterTestData(compressed_for_port, feed_block_size,
388 output_block_size, filter.get(), &output)); 381 output_block_size, filter.get(), &output));
389 EXPECT_EQ(output, expanded_); 382 EXPECT_EQ(output, expanded_);
390 383
391 // Test decode the port data, arriving from a invalid port. 384 // Test decode the port data, arriving from a invalid port.
392 filter.reset((Filter::Factory(filters, "missing-mime", kInputBufferSize))); 385 filter.reset((Filter::Factory(filter_types, kInputBufferSize)));
393 filter->SetURL(GURL(url_string + ":" + port + "1")); 386 filter->SetURL(GURL(url_string + ":" + port + "1"));
394 387
395 feed_block_size = 100; 388 feed_block_size = 100;
396 output_block_size = 100; 389 output_block_size = 100;
397 output.clear(); 390 output.clear();
398 EXPECT_FALSE(FilterTestData(compressed_for_port, feed_block_size, 391 EXPECT_FALSE(FilterTestData(compressed_for_port, feed_block_size,
399 output_block_size, filter.get(), &output)); 392 output_block_size, filter.get(), &output));
400 EXPECT_EQ(output.size(), 0u); // No output written. 393 EXPECT_EQ(output.size(), 0u); // No output written.
401 394
402 EXPECT_FALSE(SdchManager::Global()->IsInSupportedDomain(GURL(url_string))); 395 EXPECT_FALSE(SdchManager::Global()->IsInSupportedDomain(GURL(url_string)));
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
473 466
474 GURL url(url_string); 467 GURL url(url_string);
475 EXPECT_TRUE(sdch_manager_->AddSdchDictionary(dictionary, url)); 468 EXPECT_TRUE(sdch_manager_->AddSdchDictionary(dictionary, url));
476 469
477 std::string sdch_compressed(NewSdchCompressedData(dictionary)); 470 std::string sdch_compressed(NewSdchCompressedData(dictionary));
478 471
479 // Use Gzip to compress the sdch sdch_compressed data. 472 // Use Gzip to compress the sdch sdch_compressed data.
480 std::string gzip_compressed_sdch = gzip_compress(sdch_compressed); 473 std::string gzip_compressed_sdch = gzip_compress(sdch_compressed);
481 474
482 // Construct a chained filter. 475 // Construct a chained filter.
483 std::vector<std::string> filters; 476 std::vector<Filter::FilterType> filter_types;
484 filters.push_back("sdch"); 477 filter_types.push_back(Filter::FILTER_TYPE_SDCH);
485 filters.push_back("gzip"); 478 filter_types.push_back(Filter::FILTER_TYPE_GZIP);
486 479
487 // First try with a large buffer (larger than test input, or compressed data). 480 // First try with a large buffer (larger than test input, or compressed data).
488 const int kInputBufferSize(100); 481 const int kInputBufferSize(100);
489 scoped_ptr<Filter> filter(Filter::Factory(filters, "missing-mime", 482 scoped_ptr<Filter> filter(Filter::Factory(filter_types, kInputBufferSize));
490 kInputBufferSize));
491 filter->SetURL(url); 483 filter->SetURL(url);
492 484
493 // Verify that chained filter is waiting for data. 485 // Verify that chained filter is waiting for data.
494 char tiny_output_buffer[10]; 486 char tiny_output_buffer[10];
495 int tiny_output_size = sizeof(tiny_output_buffer); 487 int tiny_output_size = sizeof(tiny_output_buffer);
496 EXPECT_EQ(Filter::FILTER_NEED_MORE_DATA, 488 EXPECT_EQ(Filter::FILTER_NEED_MORE_DATA,
497 filter->ReadData(tiny_output_buffer, &tiny_output_size)); 489 filter->ReadData(tiny_output_buffer, &tiny_output_size));
498 490
499 size_t feed_block_size = 100; 491 size_t feed_block_size = 100;
500 size_t output_block_size = 100; 492 size_t output_block_size = 100;
501 std::string output; 493 std::string output;
502 EXPECT_TRUE(FilterTestData(gzip_compressed_sdch, feed_block_size, 494 EXPECT_TRUE(FilterTestData(gzip_compressed_sdch, feed_block_size,
503 output_block_size, filter.get(), &output)); 495 output_block_size, filter.get(), &output));
504 EXPECT_EQ(output, expanded_); 496 EXPECT_EQ(output, expanded_);
505 497
506 // Next try with a tiny buffer to cover edge effects. 498 // Next try with a tiny buffer to cover edge effects.
507 filter.reset(Filter::Factory(filters, "missing-mime", kInputBufferSize)); 499 filter.reset(Filter::Factory(filter_types, kInputBufferSize));
508 filter->SetURL(url); 500 filter->SetURL(url);
509 501
510 feed_block_size = 1; 502 feed_block_size = 1;
511 output_block_size = 1; 503 output_block_size = 1;
512 output.clear(); 504 output.clear();
513 EXPECT_TRUE(FilterTestData(gzip_compressed_sdch, feed_block_size, 505 EXPECT_TRUE(FilterTestData(gzip_compressed_sdch, feed_block_size,
514 output_block_size, filter.get(), &output)); 506 output_block_size, filter.get(), &output));
515 EXPECT_EQ(output, expanded_); 507 EXPECT_EQ(output, expanded_);
516 } 508 }
517 509
518 TEST_F(SdchFilterTest, DefaultGzipIfSdch) { 510 TEST_F(SdchFilterTest, DefaultGzipIfSdch) {
519 // Construct a valid SDCH dictionary from a VCDIFF dictionary. 511 // Construct a valid SDCH dictionary from a VCDIFF dictionary.
520 const std::string kSampleDomain = "sdchtest.com"; 512 const std::string kSampleDomain = "sdchtest.com";
521 std::string dictionary(NewSdchDictionary(kSampleDomain)); 513 std::string dictionary(NewSdchDictionary(kSampleDomain));
522 514
523 std::string url_string = "http://" + kSampleDomain; 515 std::string url_string = "http://" + kSampleDomain;
524 516
525 GURL url(url_string); 517 GURL url(url_string);
526 EXPECT_TRUE(sdch_manager_->AddSdchDictionary(dictionary, url)); 518 EXPECT_TRUE(sdch_manager_->AddSdchDictionary(dictionary, url));
527 519
528 std::string sdch_compressed(NewSdchCompressedData(dictionary)); 520 std::string sdch_compressed(NewSdchCompressedData(dictionary));
529 521
530 // Use Gzip to compress the sdch sdch_compressed data. 522 // Use Gzip to compress the sdch sdch_compressed data.
531 std::string gzip_compressed_sdch = gzip_compress(sdch_compressed); 523 std::string gzip_compressed_sdch = gzip_compress(sdch_compressed);
532 524
533 // Only claim to have sdch content, but really usethe gzipped sdch content. 525 // Only claim to have sdch content, but really use the gzipped sdch content.
534 // System should automatically add the missing (optional) gzip. 526 // System should automatically add the missing (optional) gzip.
535 std::vector<std::string> filters; 527 std::vector<Filter::FilterType> filter_types;
536 filters.push_back("sdch"); 528 filter_types.push_back(Filter::FILTER_TYPE_SDCH);
529 Filter::FixupEncodingTypes(true, "anything/mime", &filter_types);
537 530
538 // First try with a large buffer (larger than test input, or compressed data). 531 // First try with a large buffer (larger than test input, or compressed data).
539 const int kInputBufferSize(100); 532 const int kInputBufferSize(100);
540 scoped_ptr<Filter> filter(Filter::Factory(filters, "missing-mime", 533 scoped_ptr<Filter> filter(Filter::Factory(filter_types, kInputBufferSize));
541 kInputBufferSize));
542 filter->SetURL(url); 534 filter->SetURL(url);
543 535
544 // Verify that chained filter is waiting for data. 536 // Verify that chained filter is waiting for data.
545 char tiny_output_buffer[10]; 537 char tiny_output_buffer[10];
546 int tiny_output_size = sizeof(tiny_output_buffer); 538 int tiny_output_size = sizeof(tiny_output_buffer);
547 EXPECT_EQ(Filter::FILTER_NEED_MORE_DATA, 539 EXPECT_EQ(Filter::FILTER_NEED_MORE_DATA,
548 filter->ReadData(tiny_output_buffer, &tiny_output_size)); 540 filter->ReadData(tiny_output_buffer, &tiny_output_size));
549 541
550 size_t feed_block_size = 100; 542 size_t feed_block_size = 100;
551 size_t output_block_size = 100; 543 size_t output_block_size = 100;
552 std::string output; 544 std::string output;
553 EXPECT_TRUE(FilterTestData(gzip_compressed_sdch, feed_block_size, 545 EXPECT_TRUE(FilterTestData(gzip_compressed_sdch, feed_block_size,
554 output_block_size, filter.get(), &output)); 546 output_block_size, filter.get(), &output));
555 EXPECT_EQ(output, expanded_); 547 EXPECT_EQ(output, expanded_);
556 548
557 // Next try with a tiny buffer to cover edge effects. 549 // Next try with a tiny buffer to cover edge effects.
558 filter.reset(Filter::Factory(filters, "missing-mime", kInputBufferSize)); 550 filter.reset(Filter::Factory(filter_types, kInputBufferSize));
559 filter->SetURL(url); 551 filter->SetURL(url);
560 552
561 feed_block_size = 1; 553 feed_block_size = 1;
562 output_block_size = 1; 554 output_block_size = 1;
563 output.clear(); 555 output.clear();
564 EXPECT_TRUE(FilterTestData(gzip_compressed_sdch, feed_block_size, 556 EXPECT_TRUE(FilterTestData(gzip_compressed_sdch, feed_block_size,
565 output_block_size, filter.get(), &output)); 557 output_block_size, filter.get(), &output));
566 EXPECT_EQ(output, expanded_); 558 EXPECT_EQ(output, expanded_);
567 } 559 }
568 560
(...skipping 13 matching lines...) Expand all
582 GURL google_url("http://www.google.com"); 574 GURL google_url("http://www.google.com");
583 575
584 SdchManager::BlacklistDomain(test_url); 576 SdchManager::BlacklistDomain(test_url);
585 EXPECT_FALSE(SdchManager::Global()->IsInSupportedDomain(test_url)); 577 EXPECT_FALSE(SdchManager::Global()->IsInSupportedDomain(test_url));
586 EXPECT_TRUE(SdchManager::Global()->IsInSupportedDomain(google_url)); 578 EXPECT_TRUE(SdchManager::Global()->IsInSupportedDomain(google_url));
587 579
588 SdchManager::BlacklistDomain(google_url); 580 SdchManager::BlacklistDomain(google_url);
589 EXPECT_FALSE(SdchManager::Global()->IsInSupportedDomain(test_url)); 581 EXPECT_FALSE(SdchManager::Global()->IsInSupportedDomain(test_url));
590 EXPECT_FALSE(SdchManager::Global()->IsInSupportedDomain(google_url)); 582 EXPECT_FALSE(SdchManager::Global()->IsInSupportedDomain(google_url));
591 } 583 }
592
593
594 // TODO(jar): move this sort of test into filter_unittest.cc, or
595 // url_request_http_job_unittest.cc if that is more applicable after refactoring
596 // to use array of enums rather than array of strings to express content
597 // encodings.
598 TEST_F(SdchFilterTest, ContentTypeId) {
599 // Check for basic translation of Content-Encoding, including case variations.
600 EXPECT_EQ(Filter::FILTER_TYPE_DEFLATE,
601 Filter::ConvertEncodingToType("deflate", "nothing"));
602 EXPECT_EQ(Filter::FILTER_TYPE_DEFLATE,
603 Filter::ConvertEncodingToType("deflAte", "nothing"));
604 EXPECT_EQ(Filter::FILTER_TYPE_GZIP,
605 Filter::ConvertEncodingToType("gzip", "nothing"));
606 EXPECT_EQ(Filter::FILTER_TYPE_GZIP,
607 Filter::ConvertEncodingToType("GzIp", "nothing"));
608 EXPECT_EQ(Filter::FILTER_TYPE_GZIP,
609 Filter::ConvertEncodingToType("x-gzip", "nothing"));
610 EXPECT_EQ(Filter::FILTER_TYPE_GZIP,
611 Filter::ConvertEncodingToType("X-GzIp", "nothing"));
612 EXPECT_EQ(Filter::FILTER_TYPE_BZIP2,
613 Filter::ConvertEncodingToType("bzip2", "nothing"));
614 EXPECT_EQ(Filter::FILTER_TYPE_BZIP2,
615 Filter::ConvertEncodingToType("BZiP2", "nothing"));
616 EXPECT_EQ(Filter::FILTER_TYPE_BZIP2,
617 Filter::ConvertEncodingToType("x-bzip2", "nothing"));
618 EXPECT_EQ(Filter::FILTER_TYPE_BZIP2,
619 Filter::ConvertEncodingToType("X-BZiP2", "nothing"));
620 EXPECT_EQ(Filter::FILTER_TYPE_SDCH,
621 Filter::ConvertEncodingToType("sdch", "nothing"));
622 EXPECT_EQ(Filter::FILTER_TYPE_SDCH,
623 Filter::ConvertEncodingToType("sDcH", "nothing"));
624 EXPECT_EQ(Filter::FILTER_TYPE_UNSUPPORTED,
625 Filter::ConvertEncodingToType("weird", "nothing"));
626 EXPECT_EQ(Filter::FILTER_TYPE_UNSUPPORTED,
627 Filter::ConvertEncodingToType("strange", "nothing"));
628
629 // Check to see that apache bug (marking things as gzipped because of their
630 // on-disk file type) is ignored.
631 EXPECT_EQ(Filter::FILTER_TYPE_UNSUPPORTED,
632 Filter::ConvertEncodingToType("gzip", "application/x-gzip"));
633 EXPECT_EQ(Filter::FILTER_TYPE_UNSUPPORTED,
634 Filter::ConvertEncodingToType("gzip", "application/gzip"));
635 EXPECT_EQ(Filter::FILTER_TYPE_UNSUPPORTED,
636 Filter::ConvertEncodingToType("gzip", "application/x-gunzip"));
637
638 EXPECT_EQ(Filter::FILTER_TYPE_UNSUPPORTED,
639 Filter::ConvertEncodingToType("x-gzip", "application/x-gzip"));
640 EXPECT_EQ(Filter::FILTER_TYPE_UNSUPPORTED,
641 Filter::ConvertEncodingToType("x-gzip", "application/gzip"));
642 EXPECT_EQ(Filter::FILTER_TYPE_UNSUPPORTED,
643 Filter::ConvertEncodingToType("x-gzip", "application/x-gunzip"));
644 }
OLDNEW
« no previous file with comments | « net/base/sdch_filter.cc ('k') | net/base/sdch_manager.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698