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 <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 |
(...skipping 369 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
380 EXPECT_TRUE(sdch_manager_->IsInSupportedDomain(GURL(url_string))); | 380 EXPECT_TRUE(sdch_manager_->IsInSupportedDomain(GURL(url_string))); |
381 } | 381 } |
382 | 382 |
383 TEST_F(SdchFilterTest, DictionaryAddOnce) { | 383 TEST_F(SdchFilterTest, DictionaryAddOnce) { |
384 // Construct a valid SDCH dictionary from a VCDIFF dictionary. | 384 // Construct a valid SDCH dictionary from a VCDIFF dictionary. |
385 const std::string kSampleDomain = "sdchtest.com"; | 385 const std::string kSampleDomain = "sdchtest.com"; |
386 std::string dictionary(NewSdchDictionary(kSampleDomain)); | 386 std::string dictionary(NewSdchDictionary(kSampleDomain)); |
387 | 387 |
388 std::string url_string = "http://" + kSampleDomain; | 388 std::string url_string = "http://" + kSampleDomain; |
389 GURL url(url_string); | 389 GURL url(url_string); |
390 EXPECT_TRUE(sdch_manager_->AddSdchDictionary(dictionary, url)); | 390 SdchManager::ProblemCodes problem; |
| 391 EXPECT_TRUE(sdch_manager_->AddSdchDictionary(dictionary, url, &problem)); |
391 | 392 |
392 // Check we can't add it twice. | 393 // Check we can't add it twice. |
393 EXPECT_FALSE(sdch_manager_->AddSdchDictionary(dictionary, url)); | 394 EXPECT_FALSE(sdch_manager_->AddSdchDictionary(dictionary, url, &problem)); |
| 395 EXPECT_EQ(SdchManager::DICTIONARY_ALREADY_LOADED, problem); |
394 | 396 |
395 const std::string kSampleDomain2 = "sdchtest2.com"; | 397 const std::string kSampleDomain2 = "sdchtest2.com"; |
396 | 398 |
397 // Don't test adding a second dictionary if our limits are tight. | 399 // Don't test adding a second dictionary if our limits are tight. |
398 if (SdchManager::kMaxDictionaryCount > 1) { | 400 if (SdchManager::kMaxDictionaryCount > 1) { |
399 // Construct a second SDCH dictionary from a VCDIFF dictionary. | 401 // Construct a second SDCH dictionary from a VCDIFF dictionary. |
400 std::string dictionary2(NewSdchDictionary(kSampleDomain2)); | 402 std::string dictionary2(NewSdchDictionary(kSampleDomain2)); |
401 | 403 |
402 std::string url_string2 = "http://" + kSampleDomain2; | 404 std::string url_string2 = "http://" + kSampleDomain2; |
403 GURL url2(url_string2); | 405 GURL url2(url_string2); |
404 EXPECT_TRUE(sdch_manager_->AddSdchDictionary(dictionary2, url2)); | 406 EXPECT_TRUE(sdch_manager_->AddSdchDictionary(dictionary2, url2, &problem)); |
405 } | 407 } |
406 } | 408 } |
407 | 409 |
408 TEST_F(SdchFilterTest, BasicDictionary) { | 410 TEST_F(SdchFilterTest, BasicDictionary) { |
409 // Construct a valid SDCH dictionary from a VCDIFF dictionary. | 411 // Construct a valid SDCH dictionary from a VCDIFF dictionary. |
410 const std::string kSampleDomain = "sdchtest.com"; | 412 const std::string kSampleDomain = "sdchtest.com"; |
411 std::string dictionary(NewSdchDictionary(kSampleDomain)); | 413 std::string dictionary(NewSdchDictionary(kSampleDomain)); |
412 | 414 |
413 std::string url_string = "http://" + kSampleDomain; | 415 std::string url_string = "http://" + kSampleDomain; |
414 | 416 |
415 GURL url(url_string); | 417 GURL url(url_string); |
416 EXPECT_TRUE(sdch_manager_->AddSdchDictionary(dictionary, url)); | 418 SdchManager::ProblemCodes problem; |
| 419 EXPECT_TRUE(sdch_manager_->AddSdchDictionary(dictionary, url, &problem)); |
417 | 420 |
418 std::string compressed(NewSdchCompressedData(dictionary)); | 421 std::string compressed(NewSdchCompressedData(dictionary)); |
419 | 422 |
420 std::vector<Filter::FilterType> filter_types; | 423 std::vector<Filter::FilterType> filter_types; |
421 filter_types.push_back(Filter::FILTER_TYPE_SDCH); | 424 filter_types.push_back(Filter::FILTER_TYPE_SDCH); |
422 | 425 |
423 filter_context()->SetURL(url); | 426 filter_context()->SetURL(url); |
424 | 427 |
425 scoped_ptr<Filter> filter(Filter::Factory(filter_types, *filter_context())); | 428 scoped_ptr<Filter> filter(Filter::Factory(filter_types, *filter_context())); |
426 | 429 |
(...skipping 16 matching lines...) Expand all Loading... |
443 } | 446 } |
444 | 447 |
445 TEST_F(SdchFilterTest, NoDecodeHttps) { | 448 TEST_F(SdchFilterTest, NoDecodeHttps) { |
446 // Construct a valid SDCH dictionary from a VCDIFF dictionary. | 449 // Construct a valid SDCH dictionary from a VCDIFF dictionary. |
447 const std::string kSampleDomain = "sdchtest.com"; | 450 const std::string kSampleDomain = "sdchtest.com"; |
448 std::string dictionary(NewSdchDictionary(kSampleDomain)); | 451 std::string dictionary(NewSdchDictionary(kSampleDomain)); |
449 | 452 |
450 std::string url_string = "http://" + kSampleDomain; | 453 std::string url_string = "http://" + kSampleDomain; |
451 | 454 |
452 GURL url(url_string); | 455 GURL url(url_string); |
453 EXPECT_TRUE(sdch_manager_->AddSdchDictionary(dictionary, url)); | 456 SdchManager::ProblemCodes problem; |
| 457 EXPECT_TRUE(sdch_manager_->AddSdchDictionary(dictionary, url, &problem)); |
454 | 458 |
455 std::string compressed(NewSdchCompressedData(dictionary)); | 459 std::string compressed(NewSdchCompressedData(dictionary)); |
456 | 460 |
457 std::vector<Filter::FilterType> filter_types; | 461 std::vector<Filter::FilterType> filter_types; |
458 filter_types.push_back(Filter::FILTER_TYPE_SDCH); | 462 filter_types.push_back(Filter::FILTER_TYPE_SDCH); |
459 | 463 |
460 filter_context()->SetURL(GURL("https://" + kSampleDomain)); | 464 filter_context()->SetURL(GURL("https://" + kSampleDomain)); |
461 scoped_ptr<Filter> filter(Filter::Factory(filter_types, *filter_context())); | 465 scoped_ptr<Filter> filter(Filter::Factory(filter_types, *filter_context())); |
462 | 466 |
463 const size_t feed_block_size(100); | 467 const size_t feed_block_size(100); |
464 const size_t output_block_size(100); | 468 const size_t output_block_size(100); |
465 std::string output; | 469 std::string output; |
466 | 470 |
467 EXPECT_FALSE(FilterTestData(compressed, feed_block_size, output_block_size, | 471 EXPECT_FALSE(FilterTestData(compressed, feed_block_size, output_block_size, |
468 filter.get(), &output)); | 472 filter.get(), &output)); |
469 } | 473 } |
470 | 474 |
471 // Current failsafe TODO/hack refuses to decode any content that doesn't use | 475 // Current failsafe TODO/hack refuses to decode any content that doesn't use |
472 // http as the scheme (see use of DICTIONARY_SELECTED_FOR_NON_HTTP). | 476 // http as the scheme (see use of DICTIONARY_SELECTED_FOR_NON_HTTP). |
473 // The following tests this blockage. Note that blacklisting results, so we | 477 // The following tests this blockage. Note that blacklisting results, so we |
474 // we need separate tests for each of these. | 478 // we need separate tests for each of these. |
475 TEST_F(SdchFilterTest, NoDecodeFtp) { | 479 TEST_F(SdchFilterTest, NoDecodeFtp) { |
476 // Construct a valid SDCH dictionary from a VCDIFF dictionary. | 480 // Construct a valid SDCH dictionary from a VCDIFF dictionary. |
477 const std::string kSampleDomain = "sdchtest.com"; | 481 const std::string kSampleDomain = "sdchtest.com"; |
478 std::string dictionary(NewSdchDictionary(kSampleDomain)); | 482 std::string dictionary(NewSdchDictionary(kSampleDomain)); |
479 | 483 |
480 std::string url_string = "http://" + kSampleDomain; | 484 std::string url_string = "http://" + kSampleDomain; |
481 | 485 |
482 GURL url(url_string); | 486 GURL url(url_string); |
483 EXPECT_TRUE(sdch_manager_->AddSdchDictionary(dictionary, url)); | 487 SdchManager::ProblemCodes problem; |
| 488 EXPECT_TRUE(sdch_manager_->AddSdchDictionary(dictionary, url, &problem)); |
484 | 489 |
485 std::string compressed(NewSdchCompressedData(dictionary)); | 490 std::string compressed(NewSdchCompressedData(dictionary)); |
486 | 491 |
487 std::vector<Filter::FilterType> filter_types; | 492 std::vector<Filter::FilterType> filter_types; |
488 filter_types.push_back(Filter::FILTER_TYPE_SDCH); | 493 filter_types.push_back(Filter::FILTER_TYPE_SDCH); |
489 | 494 |
490 filter_context()->SetURL(GURL("ftp://" + kSampleDomain)); | 495 filter_context()->SetURL(GURL("ftp://" + kSampleDomain)); |
491 scoped_ptr<Filter> filter(Filter::Factory(filter_types, *filter_context())); | 496 scoped_ptr<Filter> filter(Filter::Factory(filter_types, *filter_context())); |
492 | 497 |
493 const size_t feed_block_size(100); | 498 const size_t feed_block_size(100); |
494 const size_t output_block_size(100); | 499 const size_t output_block_size(100); |
495 std::string output; | 500 std::string output; |
496 | 501 |
497 EXPECT_FALSE(FilterTestData(compressed, feed_block_size, output_block_size, | 502 EXPECT_FALSE(FilterTestData(compressed, feed_block_size, output_block_size, |
498 filter.get(), &output)); | 503 filter.get(), &output)); |
499 } | 504 } |
500 | 505 |
501 TEST_F(SdchFilterTest, NoDecodeFileColon) { | 506 TEST_F(SdchFilterTest, NoDecodeFileColon) { |
502 // Construct a valid SDCH dictionary from a VCDIFF dictionary. | 507 // Construct a valid SDCH dictionary from a VCDIFF dictionary. |
503 const std::string kSampleDomain = "sdchtest.com"; | 508 const std::string kSampleDomain = "sdchtest.com"; |
504 std::string dictionary(NewSdchDictionary(kSampleDomain)); | 509 std::string dictionary(NewSdchDictionary(kSampleDomain)); |
505 | 510 |
506 std::string url_string = "http://" + kSampleDomain; | 511 std::string url_string = "http://" + kSampleDomain; |
507 | 512 |
508 GURL url(url_string); | 513 GURL url(url_string); |
509 EXPECT_TRUE(sdch_manager_->AddSdchDictionary(dictionary, url)); | 514 SdchManager::ProblemCodes problem; |
| 515 EXPECT_TRUE(sdch_manager_->AddSdchDictionary(dictionary, url, &problem)); |
510 | 516 |
511 std::string compressed(NewSdchCompressedData(dictionary)); | 517 std::string compressed(NewSdchCompressedData(dictionary)); |
512 | 518 |
513 std::vector<Filter::FilterType> filter_types; | 519 std::vector<Filter::FilterType> filter_types; |
514 filter_types.push_back(Filter::FILTER_TYPE_SDCH); | 520 filter_types.push_back(Filter::FILTER_TYPE_SDCH); |
515 | 521 |
516 filter_context()->SetURL(GURL("file://" + kSampleDomain)); | 522 filter_context()->SetURL(GURL("file://" + kSampleDomain)); |
517 scoped_ptr<Filter> filter(Filter::Factory(filter_types, *filter_context())); | 523 scoped_ptr<Filter> filter(Filter::Factory(filter_types, *filter_context())); |
518 | 524 |
519 const size_t feed_block_size(100); | 525 const size_t feed_block_size(100); |
520 const size_t output_block_size(100); | 526 const size_t output_block_size(100); |
521 std::string output; | 527 std::string output; |
522 | 528 |
523 EXPECT_FALSE(FilterTestData(compressed, feed_block_size, output_block_size, | 529 EXPECT_FALSE(FilterTestData(compressed, feed_block_size, output_block_size, |
524 filter.get(), &output)); | 530 filter.get(), &output)); |
525 } | 531 } |
526 | 532 |
527 TEST_F(SdchFilterTest, NoDecodeAboutColon) { | 533 TEST_F(SdchFilterTest, NoDecodeAboutColon) { |
528 // Construct a valid SDCH dictionary from a VCDIFF dictionary. | 534 // Construct a valid SDCH dictionary from a VCDIFF dictionary. |
529 const std::string kSampleDomain = "sdchtest.com"; | 535 const std::string kSampleDomain = "sdchtest.com"; |
530 std::string dictionary(NewSdchDictionary(kSampleDomain)); | 536 std::string dictionary(NewSdchDictionary(kSampleDomain)); |
531 | 537 |
532 std::string url_string = "http://" + kSampleDomain; | 538 std::string url_string = "http://" + kSampleDomain; |
533 | 539 |
534 GURL url(url_string); | 540 GURL url(url_string); |
535 EXPECT_TRUE(sdch_manager_->AddSdchDictionary(dictionary, url)); | 541 SdchManager::ProblemCodes problem; |
| 542 EXPECT_TRUE(sdch_manager_->AddSdchDictionary(dictionary, url, &problem)); |
536 | 543 |
537 std::string compressed(NewSdchCompressedData(dictionary)); | 544 std::string compressed(NewSdchCompressedData(dictionary)); |
538 | 545 |
539 std::vector<Filter::FilterType> filter_types; | 546 std::vector<Filter::FilterType> filter_types; |
540 filter_types.push_back(Filter::FILTER_TYPE_SDCH); | 547 filter_types.push_back(Filter::FILTER_TYPE_SDCH); |
541 | 548 |
542 filter_context()->SetURL(GURL("about://" + kSampleDomain)); | 549 filter_context()->SetURL(GURL("about://" + kSampleDomain)); |
543 scoped_ptr<Filter> filter(Filter::Factory(filter_types, *filter_context())); | 550 scoped_ptr<Filter> filter(Filter::Factory(filter_types, *filter_context())); |
544 | 551 |
545 const size_t feed_block_size(100); | 552 const size_t feed_block_size(100); |
546 const size_t output_block_size(100); | 553 const size_t output_block_size(100); |
547 std::string output; | 554 std::string output; |
548 | 555 |
549 EXPECT_FALSE(FilterTestData(compressed, feed_block_size, output_block_size, | 556 EXPECT_FALSE(FilterTestData(compressed, feed_block_size, output_block_size, |
550 filter.get(), &output)); | 557 filter.get(), &output)); |
551 } | 558 } |
552 | 559 |
553 TEST_F(SdchFilterTest, NoDecodeJavaScript) { | 560 TEST_F(SdchFilterTest, NoDecodeJavaScript) { |
554 // Construct a valid SDCH dictionary from a VCDIFF dictionary. | 561 // Construct a valid SDCH dictionary from a VCDIFF dictionary. |
555 const std::string kSampleDomain = "sdchtest.com"; | 562 const std::string kSampleDomain = "sdchtest.com"; |
556 std::string dictionary(NewSdchDictionary(kSampleDomain)); | 563 std::string dictionary(NewSdchDictionary(kSampleDomain)); |
557 | 564 |
558 std::string url_string = "http://" + kSampleDomain; | 565 std::string url_string = "http://" + kSampleDomain; |
559 | 566 |
560 GURL url(url_string); | 567 GURL url(url_string); |
561 EXPECT_TRUE(sdch_manager_->AddSdchDictionary(dictionary, url)); | 568 SdchManager::ProblemCodes problem; |
| 569 EXPECT_TRUE(sdch_manager_->AddSdchDictionary(dictionary, url, &problem)); |
562 | 570 |
563 std::string compressed(NewSdchCompressedData(dictionary)); | 571 std::string compressed(NewSdchCompressedData(dictionary)); |
564 | 572 |
565 std::vector<Filter::FilterType> filter_types; | 573 std::vector<Filter::FilterType> filter_types; |
566 filter_types.push_back(Filter::FILTER_TYPE_SDCH); | 574 filter_types.push_back(Filter::FILTER_TYPE_SDCH); |
567 | 575 |
568 filter_context()->SetURL(GURL("javascript://" + kSampleDomain)); | 576 filter_context()->SetURL(GURL("javascript://" + kSampleDomain)); |
569 scoped_ptr<Filter> filter(Filter::Factory(filter_types, *filter_context())); | 577 scoped_ptr<Filter> filter(Filter::Factory(filter_types, *filter_context())); |
570 | 578 |
571 const size_t feed_block_size(100); | 579 const size_t feed_block_size(100); |
572 const size_t output_block_size(100); | 580 const size_t output_block_size(100); |
573 std::string output; | 581 std::string output; |
574 | 582 |
575 EXPECT_FALSE(FilterTestData(compressed, feed_block_size, output_block_size, | 583 EXPECT_FALSE(FilterTestData(compressed, feed_block_size, output_block_size, |
576 filter.get(), &output)); | 584 filter.get(), &output)); |
577 } | 585 } |
578 | 586 |
579 TEST_F(SdchFilterTest, CanStillDecodeHttp) { | 587 TEST_F(SdchFilterTest, CanStillDecodeHttp) { |
580 // Construct a valid SDCH dictionary from a VCDIFF dictionary. | 588 // Construct a valid SDCH dictionary from a VCDIFF dictionary. |
581 const std::string kSampleDomain = "sdchtest.com"; | 589 const std::string kSampleDomain = "sdchtest.com"; |
582 std::string dictionary(NewSdchDictionary(kSampleDomain)); | 590 std::string dictionary(NewSdchDictionary(kSampleDomain)); |
583 | 591 |
584 std::string url_string = "http://" + kSampleDomain; | 592 std::string url_string = "http://" + kSampleDomain; |
585 | 593 |
586 GURL url(url_string); | 594 GURL url(url_string); |
587 EXPECT_TRUE(sdch_manager_->AddSdchDictionary(dictionary, url)); | 595 SdchManager::ProblemCodes problem; |
| 596 EXPECT_TRUE(sdch_manager_->AddSdchDictionary(dictionary, url, &problem)); |
588 | 597 |
589 std::string compressed(NewSdchCompressedData(dictionary)); | 598 std::string compressed(NewSdchCompressedData(dictionary)); |
590 | 599 |
591 std::vector<Filter::FilterType> filter_types; | 600 std::vector<Filter::FilterType> filter_types; |
592 filter_types.push_back(Filter::FILTER_TYPE_SDCH); | 601 filter_types.push_back(Filter::FILTER_TYPE_SDCH); |
593 | 602 |
594 filter_context()->SetURL(GURL("http://" + kSampleDomain)); | 603 filter_context()->SetURL(GURL("http://" + kSampleDomain)); |
595 scoped_ptr<Filter> filter(Filter::Factory(filter_types, *filter_context())); | 604 scoped_ptr<Filter> filter(Filter::Factory(filter_types, *filter_context())); |
596 | 605 |
597 const size_t feed_block_size(100); | 606 const size_t feed_block_size(100); |
598 const size_t output_block_size(100); | 607 const size_t output_block_size(100); |
599 std::string output; | 608 std::string output; |
600 | 609 |
601 EXPECT_TRUE(FilterTestData(compressed, feed_block_size, output_block_size, | 610 EXPECT_TRUE(FilterTestData(compressed, feed_block_size, output_block_size, |
602 filter.get(), &output)); | 611 filter.get(), &output)); |
603 } | 612 } |
604 | 613 |
605 TEST_F(SdchFilterTest, CrossDomainDictionaryUse) { | 614 TEST_F(SdchFilterTest, CrossDomainDictionaryUse) { |
606 // Construct a valid SDCH dictionary from a VCDIFF dictionary. | 615 // Construct a valid SDCH dictionary from a VCDIFF dictionary. |
607 const std::string kSampleDomain = "sdchtest.com"; | 616 const std::string kSampleDomain = "sdchtest.com"; |
608 std::string dictionary(NewSdchDictionary(kSampleDomain)); | 617 std::string dictionary(NewSdchDictionary(kSampleDomain)); |
609 | 618 |
610 std::string url_string = "http://" + kSampleDomain; | 619 std::string url_string = "http://" + kSampleDomain; |
611 | 620 |
612 GURL url(url_string); | 621 GURL url(url_string); |
613 EXPECT_TRUE(sdch_manager_->AddSdchDictionary(dictionary, url)); | 622 SdchManager::ProblemCodes problem; |
| 623 EXPECT_TRUE(sdch_manager_->AddSdchDictionary(dictionary, url, &problem)); |
614 | 624 |
615 std::string compressed(NewSdchCompressedData(dictionary)); | 625 std::string compressed(NewSdchCompressedData(dictionary)); |
616 | 626 |
617 std::vector<Filter::FilterType> filter_types; | 627 std::vector<Filter::FilterType> filter_types; |
618 filter_types.push_back(Filter::FILTER_TYPE_SDCH); | 628 filter_types.push_back(Filter::FILTER_TYPE_SDCH); |
619 | 629 |
620 // Decode with content arriving from the "wrong" domain. | 630 // Decode with content arriving from the "wrong" domain. |
621 // This tests SdchManager::CanSet(). | 631 // This tests SdchManager::CanSet(). |
622 GURL wrong_domain_url("http://www.wrongdomain.com"); | 632 GURL wrong_domain_url("http://www.wrongdomain.com"); |
623 filter_context()->SetURL(wrong_domain_url); | 633 filter_context()->SetURL(wrong_domain_url); |
(...skipping 18 matching lines...) Expand all Loading... |
642 if (SdchManager::kMaxDictionaryCount <= 1) | 652 if (SdchManager::kMaxDictionaryCount <= 1) |
643 return; | 653 return; |
644 | 654 |
645 // Construct a valid SDCH dictionary from a VCDIFF dictionary. | 655 // Construct a valid SDCH dictionary from a VCDIFF dictionary. |
646 const std::string kSampleDomain = "sdchtest.com"; | 656 const std::string kSampleDomain = "sdchtest.com"; |
647 std::string dictionary(NewSdchDictionary(kSampleDomain)); | 657 std::string dictionary(NewSdchDictionary(kSampleDomain)); |
648 | 658 |
649 std::string url_string = "http://" + kSampleDomain; | 659 std::string url_string = "http://" + kSampleDomain; |
650 | 660 |
651 GURL url(url_string); | 661 GURL url(url_string); |
652 EXPECT_TRUE(sdch_manager_->AddSdchDictionary(dictionary, url)); | 662 SdchManager::ProblemCodes problem; |
| 663 EXPECT_TRUE(sdch_manager_->AddSdchDictionary(dictionary, url, &problem)); |
653 | 664 |
654 // Create a dictionary with a path restriction, by prefixing dictionary. | 665 // Create a dictionary with a path restriction, by prefixing dictionary. |
655 const std::string path("/special_path/bin"); | 666 const std::string path("/special_path/bin"); |
656 std::string dictionary_with_path("Path: " + path + "\n"); | 667 std::string dictionary_with_path("Path: " + path + "\n"); |
657 dictionary_with_path.append(dictionary); | 668 dictionary_with_path.append(dictionary); |
658 EXPECT_TRUE(sdch_manager_->AddSdchDictionary(dictionary_with_path, url)); | 669 EXPECT_TRUE( |
| 670 sdch_manager_->AddSdchDictionary(dictionary_with_path, url, &problem)); |
659 | 671 |
660 std::string compressed_for_path(NewSdchCompressedData(dictionary_with_path)); | 672 std::string compressed_for_path(NewSdchCompressedData(dictionary_with_path)); |
661 | 673 |
662 std::vector<Filter::FilterType> filter_types; | 674 std::vector<Filter::FilterType> filter_types; |
663 filter_types.push_back(Filter::FILTER_TYPE_SDCH); | 675 filter_types.push_back(Filter::FILTER_TYPE_SDCH); |
664 | 676 |
665 // Test decode the path data, arriving from a valid path. | 677 // Test decode the path data, arriving from a valid path. |
666 filter_context()->SetURL(GURL(url_string + path)); | 678 filter_context()->SetURL(GURL(url_string + path)); |
667 scoped_ptr<Filter> filter(Filter::Factory(filter_types, *filter_context())); | 679 scoped_ptr<Filter> filter(Filter::Factory(filter_types, *filter_context())); |
668 | 680 |
(...skipping 27 matching lines...) Expand all Loading... |
696 if (SdchManager::kMaxDictionaryCount <= 1) | 708 if (SdchManager::kMaxDictionaryCount <= 1) |
697 return; | 709 return; |
698 | 710 |
699 // Construct a valid SDCH dictionary from a VCDIFF dictionary. | 711 // Construct a valid SDCH dictionary from a VCDIFF dictionary. |
700 const std::string kSampleDomain = "sdchtest.com"; | 712 const std::string kSampleDomain = "sdchtest.com"; |
701 std::string dictionary(NewSdchDictionary(kSampleDomain)); | 713 std::string dictionary(NewSdchDictionary(kSampleDomain)); |
702 | 714 |
703 std::string url_string = "http://" + kSampleDomain; | 715 std::string url_string = "http://" + kSampleDomain; |
704 | 716 |
705 GURL url(url_string); | 717 GURL url(url_string); |
706 EXPECT_TRUE(sdch_manager_->AddSdchDictionary(dictionary, url)); | 718 SdchManager::ProblemCodes problem; |
707 | 719 EXPECT_TRUE(sdch_manager_->AddSdchDictionary(dictionary, url, &problem)); |
708 | 720 |
709 // Create a dictionary with a port restriction, by prefixing old dictionary. | 721 // Create a dictionary with a port restriction, by prefixing old dictionary. |
710 const std::string port("502"); | 722 const std::string port("502"); |
711 std::string dictionary_with_port("Port: " + port + "\n"); | 723 std::string dictionary_with_port("Port: " + port + "\n"); |
712 dictionary_with_port.append("Port: 80\n"); // Add default port. | 724 dictionary_with_port.append("Port: 80\n"); // Add default port. |
713 dictionary_with_port.append(dictionary); | 725 dictionary_with_port.append(dictionary); |
714 EXPECT_TRUE(sdch_manager_->AddSdchDictionary(dictionary_with_port, | 726 EXPECT_TRUE(sdch_manager_->AddSdchDictionary( |
715 GURL(url_string + ":" + port))); | 727 dictionary_with_port, GURL(url_string + ":" + port), &problem)); |
716 | 728 |
717 std::string compressed_for_port(NewSdchCompressedData(dictionary_with_port)); | 729 std::string compressed_for_port(NewSdchCompressedData(dictionary_with_port)); |
718 | 730 |
719 std::vector<Filter::FilterType> filter_types; | 731 std::vector<Filter::FilterType> filter_types; |
720 filter_types.push_back(Filter::FILTER_TYPE_SDCH); | 732 filter_types.push_back(Filter::FILTER_TYPE_SDCH); |
721 | 733 |
722 // Test decode the port data, arriving from a valid port. | 734 // Test decode the port data, arriving from a valid port. |
723 filter_context()->SetURL(GURL(url_string + ":" + port)); | 735 filter_context()->SetURL(GURL(url_string + ":" + port)); |
724 scoped_ptr<Filter> filter(Filter::Factory(filter_types, *filter_context())); | 736 scoped_ptr<Filter> filter(Filter::Factory(filter_types, *filter_context())); |
725 | 737 |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
826 // routinely followed by gzip (during encoding). The filter we'll test for will | 838 // routinely followed by gzip (during encoding). The filter we'll test for will |
827 // do the gzip decoding first, and then decode the SDCH content. | 839 // do the gzip decoding first, and then decode the SDCH content. |
828 TEST_F(SdchFilterTest, FilterChaining) { | 840 TEST_F(SdchFilterTest, FilterChaining) { |
829 // Construct a valid SDCH dictionary from a VCDIFF dictionary. | 841 // Construct a valid SDCH dictionary from a VCDIFF dictionary. |
830 const std::string kSampleDomain = "sdchtest.com"; | 842 const std::string kSampleDomain = "sdchtest.com"; |
831 std::string dictionary(NewSdchDictionary(kSampleDomain)); | 843 std::string dictionary(NewSdchDictionary(kSampleDomain)); |
832 | 844 |
833 std::string url_string = "http://" + kSampleDomain; | 845 std::string url_string = "http://" + kSampleDomain; |
834 | 846 |
835 GURL url(url_string); | 847 GURL url(url_string); |
836 EXPECT_TRUE(sdch_manager_->AddSdchDictionary(dictionary, url)); | 848 SdchManager::ProblemCodes problem; |
| 849 EXPECT_TRUE(sdch_manager_->AddSdchDictionary(dictionary, url, &problem)); |
837 | 850 |
838 std::string sdch_compressed(NewSdchCompressedData(dictionary)); | 851 std::string sdch_compressed(NewSdchCompressedData(dictionary)); |
839 | 852 |
840 // Use Gzip to compress the sdch sdch_compressed data. | 853 // Use Gzip to compress the sdch sdch_compressed data. |
841 std::string gzip_compressed_sdch = gzip_compress(sdch_compressed); | 854 std::string gzip_compressed_sdch = gzip_compress(sdch_compressed); |
842 | 855 |
843 // Construct a chained filter. | 856 // Construct a chained filter. |
844 std::vector<Filter::FilterType> filter_types; | 857 std::vector<Filter::FilterType> filter_types; |
845 filter_types.push_back(Filter::FILTER_TYPE_SDCH); | 858 filter_types.push_back(Filter::FILTER_TYPE_SDCH); |
846 filter_types.push_back(Filter::FILTER_TYPE_GZIP); | 859 filter_types.push_back(Filter::FILTER_TYPE_GZIP); |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
908 } | 921 } |
909 | 922 |
910 TEST_F(SdchFilterTest, DefaultGzipIfSdch) { | 923 TEST_F(SdchFilterTest, DefaultGzipIfSdch) { |
911 // Construct a valid SDCH dictionary from a VCDIFF dictionary. | 924 // Construct a valid SDCH dictionary from a VCDIFF dictionary. |
912 const std::string kSampleDomain = "sdchtest.com"; | 925 const std::string kSampleDomain = "sdchtest.com"; |
913 std::string dictionary(NewSdchDictionary(kSampleDomain)); | 926 std::string dictionary(NewSdchDictionary(kSampleDomain)); |
914 | 927 |
915 std::string url_string = "http://" + kSampleDomain; | 928 std::string url_string = "http://" + kSampleDomain; |
916 | 929 |
917 GURL url(url_string); | 930 GURL url(url_string); |
918 EXPECT_TRUE(sdch_manager_->AddSdchDictionary(dictionary, url)); | 931 SdchManager::ProblemCodes problem; |
| 932 EXPECT_TRUE(sdch_manager_->AddSdchDictionary(dictionary, url, &problem)); |
919 | 933 |
920 std::string sdch_compressed(NewSdchCompressedData(dictionary)); | 934 std::string sdch_compressed(NewSdchCompressedData(dictionary)); |
921 | 935 |
922 // Use Gzip to compress the sdch sdch_compressed data. | 936 // Use Gzip to compress the sdch sdch_compressed data. |
923 std::string gzip_compressed_sdch = gzip_compress(sdch_compressed); | 937 std::string gzip_compressed_sdch = gzip_compress(sdch_compressed); |
924 | 938 |
925 // Only claim to have sdch content, but really use the gzipped sdch content. | 939 // Only claim to have sdch content, but really use the gzipped sdch content. |
926 // System should automatically add the missing (optional) gzip. | 940 // System should automatically add the missing (optional) gzip. |
927 std::vector<Filter::FilterType> filter_types; | 941 std::vector<Filter::FilterType> filter_types; |
928 filter_types.push_back(Filter::FILTER_TYPE_SDCH); | 942 filter_types.push_back(Filter::FILTER_TYPE_SDCH); |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
964 } | 978 } |
965 | 979 |
966 TEST_F(SdchFilterTest, AcceptGzipSdchIfGzip) { | 980 TEST_F(SdchFilterTest, AcceptGzipSdchIfGzip) { |
967 // Construct a valid SDCH dictionary from a VCDIFF dictionary. | 981 // Construct a valid SDCH dictionary from a VCDIFF dictionary. |
968 const std::string kSampleDomain = "sdchtest.com"; | 982 const std::string kSampleDomain = "sdchtest.com"; |
969 std::string dictionary(NewSdchDictionary(kSampleDomain)); | 983 std::string dictionary(NewSdchDictionary(kSampleDomain)); |
970 | 984 |
971 std::string url_string = "http://" + kSampleDomain; | 985 std::string url_string = "http://" + kSampleDomain; |
972 | 986 |
973 GURL url(url_string); | 987 GURL url(url_string); |
974 EXPECT_TRUE(sdch_manager_->AddSdchDictionary(dictionary, url)); | 988 SdchManager::ProblemCodes problem; |
| 989 EXPECT_TRUE(sdch_manager_->AddSdchDictionary(dictionary, url, &problem)); |
975 | 990 |
976 std::string sdch_compressed(NewSdchCompressedData(dictionary)); | 991 std::string sdch_compressed(NewSdchCompressedData(dictionary)); |
977 | 992 |
978 // Use Gzip to compress the sdch sdch_compressed data. | 993 // Use Gzip to compress the sdch sdch_compressed data. |
979 std::string gzip_compressed_sdch = gzip_compress(sdch_compressed); | 994 std::string gzip_compressed_sdch = gzip_compress(sdch_compressed); |
980 | 995 |
981 // Some proxies strip the content encoding statement down to a mere gzip, but | 996 // Some proxies strip the content encoding statement down to a mere gzip, but |
982 // pass through the original content (with full sdch,gzip encoding). | 997 // pass through the original content (with full sdch,gzip encoding). |
983 // Only claim to have gzip content, but really use the gzipped sdch content. | 998 // Only claim to have gzip content, but really use the gzipped sdch content. |
984 // System should automatically add the missing (optional) sdch. | 999 // System should automatically add the missing (optional) sdch. |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1023 } | 1038 } |
1024 | 1039 |
1025 TEST_F(SdchFilterTest, DefaultSdchGzipIfEmpty) { | 1040 TEST_F(SdchFilterTest, DefaultSdchGzipIfEmpty) { |
1026 // Construct a valid SDCH dictionary from a VCDIFF dictionary. | 1041 // Construct a valid SDCH dictionary from a VCDIFF dictionary. |
1027 const std::string kSampleDomain = "sdchtest.com"; | 1042 const std::string kSampleDomain = "sdchtest.com"; |
1028 std::string dictionary(NewSdchDictionary(kSampleDomain)); | 1043 std::string dictionary(NewSdchDictionary(kSampleDomain)); |
1029 | 1044 |
1030 std::string url_string = "http://" + kSampleDomain; | 1045 std::string url_string = "http://" + kSampleDomain; |
1031 | 1046 |
1032 GURL url(url_string); | 1047 GURL url(url_string); |
1033 EXPECT_TRUE(sdch_manager_->AddSdchDictionary(dictionary, url)); | 1048 SdchManager::ProblemCodes problem; |
| 1049 EXPECT_TRUE(sdch_manager_->AddSdchDictionary(dictionary, url, &problem)); |
1034 | 1050 |
1035 std::string sdch_compressed(NewSdchCompressedData(dictionary)); | 1051 std::string sdch_compressed(NewSdchCompressedData(dictionary)); |
1036 | 1052 |
1037 // Use Gzip to compress the sdch sdch_compressed data. | 1053 // Use Gzip to compress the sdch sdch_compressed data. |
1038 std::string gzip_compressed_sdch = gzip_compress(sdch_compressed); | 1054 std::string gzip_compressed_sdch = gzip_compress(sdch_compressed); |
1039 | 1055 |
1040 // Only claim to have non-encoded content, but really use the gzipped sdch | 1056 // Only claim to have non-encoded content, but really use the gzipped sdch |
1041 // content. | 1057 // content. |
1042 // System should automatically add the missing (optional) sdch,gzip. | 1058 // System should automatically add the missing (optional) sdch,gzip. |
1043 std::vector<Filter::FilterType> filter_types; | 1059 std::vector<Filter::FilterType> filter_types; |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1079 } | 1095 } |
1080 | 1096 |
1081 TEST_F(SdchFilterTest, AcceptGzipGzipSdchIfGzip) { | 1097 TEST_F(SdchFilterTest, AcceptGzipGzipSdchIfGzip) { |
1082 // Construct a valid SDCH dictionary from a VCDIFF dictionary. | 1098 // Construct a valid SDCH dictionary from a VCDIFF dictionary. |
1083 const std::string kSampleDomain = "sdchtest.com"; | 1099 const std::string kSampleDomain = "sdchtest.com"; |
1084 std::string dictionary(NewSdchDictionary(kSampleDomain)); | 1100 std::string dictionary(NewSdchDictionary(kSampleDomain)); |
1085 | 1101 |
1086 std::string url_string = "http://" + kSampleDomain; | 1102 std::string url_string = "http://" + kSampleDomain; |
1087 | 1103 |
1088 GURL url(url_string); | 1104 GURL url(url_string); |
1089 EXPECT_TRUE(sdch_manager_->AddSdchDictionary(dictionary, url)); | 1105 SdchManager::ProblemCodes problem; |
| 1106 EXPECT_TRUE(sdch_manager_->AddSdchDictionary(dictionary, url, &problem)); |
1090 | 1107 |
1091 std::string sdch_compressed(NewSdchCompressedData(dictionary)); | 1108 std::string sdch_compressed(NewSdchCompressedData(dictionary)); |
1092 | 1109 |
1093 // Vodaphone (UK) Mobile Broadband provides double gzipped sdch with a content | 1110 // Vodaphone (UK) Mobile Broadband provides double gzipped sdch with a content |
1094 // encoding of merely gzip (apparently, only listing the extra level of | 1111 // encoding of merely gzip (apparently, only listing the extra level of |
1095 // wrapper compression they added, but discarding the actual content encoding. | 1112 // wrapper compression they added, but discarding the actual content encoding. |
1096 // Use Gzip to double compress the sdch sdch_compressed data. | 1113 // Use Gzip to double compress the sdch sdch_compressed data. |
1097 std::string double_gzip_compressed_sdch = gzip_compress(gzip_compress( | 1114 std::string double_gzip_compressed_sdch = gzip_compress(gzip_compress( |
1098 sdch_compressed)); | 1115 sdch_compressed)); |
1099 | 1116 |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1133 | 1150 |
1134 feed_block_size = 1; | 1151 feed_block_size = 1; |
1135 output_block_size = 1; | 1152 output_block_size = 1; |
1136 output.clear(); | 1153 output.clear(); |
1137 EXPECT_TRUE(FilterTestData(double_gzip_compressed_sdch, feed_block_size, | 1154 EXPECT_TRUE(FilterTestData(double_gzip_compressed_sdch, feed_block_size, |
1138 output_block_size, filter.get(), &output)); | 1155 output_block_size, filter.get(), &output)); |
1139 EXPECT_EQ(output, expanded_); | 1156 EXPECT_EQ(output, expanded_); |
1140 } | 1157 } |
1141 | 1158 |
1142 } // namespace net | 1159 } // namespace net |
OLD | NEW |