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 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
60 URLRequestContext* url_request_context = | 60 URLRequestContext* url_request_context = |
61 filter_context_->GetModifiableURLRequestContext(); | 61 filter_context_->GetModifiableURLRequestContext(); |
62 | 62 |
63 url_request_context->set_sdch_manager(sdch_manager_.get()); | 63 url_request_context->set_sdch_manager(sdch_manager_.get()); |
64 } | 64 } |
65 | 65 |
66 MockFilterContext* filter_context() { return filter_context_.get(); } | 66 MockFilterContext* filter_context() { return filter_context_.get(); } |
67 | 67 |
68 std::string NewSdchCompressedData(const std::string dictionary); | 68 std::string NewSdchCompressedData(const std::string dictionary); |
69 | 69 |
| 70 bool AddDictionary(const std::string& text, const GURL& url); |
| 71 |
70 const std::string test_vcdiff_dictionary_; | 72 const std::string test_vcdiff_dictionary_; |
71 const std::string vcdiff_compressed_data_; | 73 const std::string vcdiff_compressed_data_; |
72 const std::string expanded_; // Desired final, decompressed data. | 74 const std::string expanded_; // Desired final, decompressed data. |
73 | 75 |
74 scoped_ptr<SdchManager> sdch_manager_; | 76 scoped_ptr<SdchManager> sdch_manager_; |
75 scoped_ptr<MockFilterContext> filter_context_; | 77 scoped_ptr<MockFilterContext> filter_context_; |
76 }; | 78 }; |
77 | 79 |
78 std::string SdchFilterTest::NewSdchCompressedData( | 80 std::string SdchFilterTest::NewSdchCompressedData( |
79 const std::string dictionary) { | 81 const std::string dictionary) { |
80 std::string client_hash; | 82 std::string client_hash; |
81 std::string server_hash; | 83 std::string server_hash; |
82 SdchManager::GenerateHash(dictionary, &client_hash, &server_hash); | 84 SdchManager::GenerateHash(dictionary, &client_hash, &server_hash); |
83 | 85 |
84 // Build compressed data that refers to our dictionary. | 86 // Build compressed data that refers to our dictionary. |
85 std::string compressed(server_hash); | 87 std::string compressed(server_hash); |
86 compressed.append("\0", 1); | 88 compressed.append("\0", 1); |
87 compressed.append(vcdiff_compressed_data_); | 89 compressed.append(vcdiff_compressed_data_); |
88 return compressed; | 90 return compressed; |
89 } | 91 } |
90 | 92 |
| 93 bool SdchFilterTest::AddDictionary(const std::string& text, const GURL& url) { |
| 94 SdchManager::AddResult rv = sdch_manager_->AddSdchDictionary(text, url); |
| 95 return rv.added; |
| 96 } |
| 97 |
91 //------------------------------------------------------------------------------ | 98 //------------------------------------------------------------------------------ |
92 | 99 |
93 | 100 |
94 TEST_F(SdchFilterTest, Hashing) { | 101 TEST_F(SdchFilterTest, Hashing) { |
95 std::string client_hash, server_hash; | 102 std::string client_hash, server_hash; |
96 std::string dictionary("test contents"); | 103 std::string dictionary("test contents"); |
97 SdchManager::GenerateHash(dictionary, &client_hash, &server_hash); | 104 SdchManager::GenerateHash(dictionary, &client_hash, &server_hash); |
98 | 105 |
99 EXPECT_EQ(client_hash, "lMQBjS3P"); | 106 EXPECT_EQ(client_hash, "lMQBjS3P"); |
100 EXPECT_EQ(server_hash, "MyciMVll"); | 107 EXPECT_EQ(server_hash, "MyciMVll"); |
(...skipping 279 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
380 EXPECT_TRUE(sdch_manager_->IsInSupportedDomain(GURL(url_string))); | 387 EXPECT_TRUE(sdch_manager_->IsInSupportedDomain(GURL(url_string))); |
381 } | 388 } |
382 | 389 |
383 TEST_F(SdchFilterTest, DictionaryAddOnce) { | 390 TEST_F(SdchFilterTest, DictionaryAddOnce) { |
384 // Construct a valid SDCH dictionary from a VCDIFF dictionary. | 391 // Construct a valid SDCH dictionary from a VCDIFF dictionary. |
385 const std::string kSampleDomain = "sdchtest.com"; | 392 const std::string kSampleDomain = "sdchtest.com"; |
386 std::string dictionary(NewSdchDictionary(kSampleDomain)); | 393 std::string dictionary(NewSdchDictionary(kSampleDomain)); |
387 | 394 |
388 std::string url_string = "http://" + kSampleDomain; | 395 std::string url_string = "http://" + kSampleDomain; |
389 GURL url(url_string); | 396 GURL url(url_string); |
390 EXPECT_TRUE(sdch_manager_->AddSdchDictionary(dictionary, url)); | 397 EXPECT_TRUE(AddDictionary(dictionary, url)); |
391 | 398 |
392 // Check we can't add it twice. | 399 // Check we can't add it twice. |
393 EXPECT_FALSE(sdch_manager_->AddSdchDictionary(dictionary, url)); | 400 EXPECT_FALSE(AddDictionary(dictionary, url)); |
394 | 401 |
395 const std::string kSampleDomain2 = "sdchtest2.com"; | 402 const std::string kSampleDomain2 = "sdchtest2.com"; |
396 | 403 |
397 // Don't test adding a second dictionary if our limits are tight. | 404 // Don't test adding a second dictionary if our limits are tight. |
398 if (SdchManager::kMaxDictionaryCount > 1) { | 405 if (SdchManager::kMaxDictionaryCount > 1) { |
399 // Construct a second SDCH dictionary from a VCDIFF dictionary. | 406 // Construct a second SDCH dictionary from a VCDIFF dictionary. |
400 std::string dictionary2(NewSdchDictionary(kSampleDomain2)); | 407 std::string dictionary2(NewSdchDictionary(kSampleDomain2)); |
401 | 408 |
402 std::string url_string2 = "http://" + kSampleDomain2; | 409 std::string url_string2 = "http://" + kSampleDomain2; |
403 GURL url2(url_string2); | 410 GURL url2(url_string2); |
404 EXPECT_TRUE(sdch_manager_->AddSdchDictionary(dictionary2, url2)); | 411 EXPECT_TRUE(AddDictionary(dictionary2, url2)); |
405 } | 412 } |
406 } | 413 } |
407 | 414 |
408 TEST_F(SdchFilterTest, BasicDictionary) { | 415 TEST_F(SdchFilterTest, BasicDictionary) { |
409 // Construct a valid SDCH dictionary from a VCDIFF dictionary. | 416 // Construct a valid SDCH dictionary from a VCDIFF dictionary. |
410 const std::string kSampleDomain = "sdchtest.com"; | 417 const std::string kSampleDomain = "sdchtest.com"; |
411 std::string dictionary(NewSdchDictionary(kSampleDomain)); | 418 std::string dictionary(NewSdchDictionary(kSampleDomain)); |
412 | 419 |
413 std::string url_string = "http://" + kSampleDomain; | 420 std::string url_string = "http://" + kSampleDomain; |
414 | 421 |
415 GURL url(url_string); | 422 GURL url(url_string); |
416 EXPECT_TRUE(sdch_manager_->AddSdchDictionary(dictionary, url)); | 423 EXPECT_TRUE(AddDictionary(dictionary, url)); |
417 | 424 |
418 std::string compressed(NewSdchCompressedData(dictionary)); | 425 std::string compressed(NewSdchCompressedData(dictionary)); |
419 | 426 |
420 std::vector<Filter::FilterType> filter_types; | 427 std::vector<Filter::FilterType> filter_types; |
421 filter_types.push_back(Filter::FILTER_TYPE_SDCH); | 428 filter_types.push_back(Filter::FILTER_TYPE_SDCH); |
422 | 429 |
423 filter_context()->SetURL(url); | 430 filter_context()->SetURL(url); |
424 | 431 |
425 scoped_ptr<Filter> filter(Filter::Factory(filter_types, *filter_context())); | 432 scoped_ptr<Filter> filter(Filter::Factory(filter_types, *filter_context())); |
426 | 433 |
(...skipping 16 matching lines...) Expand all Loading... |
443 } | 450 } |
444 | 451 |
445 TEST_F(SdchFilterTest, NoDecodeHttps) { | 452 TEST_F(SdchFilterTest, NoDecodeHttps) { |
446 // Construct a valid SDCH dictionary from a VCDIFF dictionary. | 453 // Construct a valid SDCH dictionary from a VCDIFF dictionary. |
447 const std::string kSampleDomain = "sdchtest.com"; | 454 const std::string kSampleDomain = "sdchtest.com"; |
448 std::string dictionary(NewSdchDictionary(kSampleDomain)); | 455 std::string dictionary(NewSdchDictionary(kSampleDomain)); |
449 | 456 |
450 std::string url_string = "http://" + kSampleDomain; | 457 std::string url_string = "http://" + kSampleDomain; |
451 | 458 |
452 GURL url(url_string); | 459 GURL url(url_string); |
453 EXPECT_TRUE(sdch_manager_->AddSdchDictionary(dictionary, url)); | 460 EXPECT_TRUE(AddDictionary(dictionary, url)); |
454 | 461 |
455 std::string compressed(NewSdchCompressedData(dictionary)); | 462 std::string compressed(NewSdchCompressedData(dictionary)); |
456 | 463 |
457 std::vector<Filter::FilterType> filter_types; | 464 std::vector<Filter::FilterType> filter_types; |
458 filter_types.push_back(Filter::FILTER_TYPE_SDCH); | 465 filter_types.push_back(Filter::FILTER_TYPE_SDCH); |
459 | 466 |
460 filter_context()->SetURL(GURL("https://" + kSampleDomain)); | 467 filter_context()->SetURL(GURL("https://" + kSampleDomain)); |
461 scoped_ptr<Filter> filter(Filter::Factory(filter_types, *filter_context())); | 468 scoped_ptr<Filter> filter(Filter::Factory(filter_types, *filter_context())); |
462 | 469 |
463 const size_t feed_block_size(100); | 470 const size_t feed_block_size(100); |
464 const size_t output_block_size(100); | 471 const size_t output_block_size(100); |
465 std::string output; | 472 std::string output; |
466 | 473 |
467 EXPECT_FALSE(FilterTestData(compressed, feed_block_size, output_block_size, | 474 EXPECT_FALSE(FilterTestData(compressed, feed_block_size, output_block_size, |
468 filter.get(), &output)); | 475 filter.get(), &output)); |
469 } | 476 } |
470 | 477 |
471 // Current failsafe TODO/hack refuses to decode any content that doesn't use | 478 // 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). | 479 // http as the scheme (see use of DICTIONARY_SELECTED_FOR_NON_HTTP). |
473 // The following tests this blockage. Note that blacklisting results, so we | 480 // The following tests this blockage. Note that blacklisting results, so we |
474 // we need separate tests for each of these. | 481 // we need separate tests for each of these. |
475 TEST_F(SdchFilterTest, NoDecodeFtp) { | 482 TEST_F(SdchFilterTest, NoDecodeFtp) { |
476 // Construct a valid SDCH dictionary from a VCDIFF dictionary. | 483 // Construct a valid SDCH dictionary from a VCDIFF dictionary. |
477 const std::string kSampleDomain = "sdchtest.com"; | 484 const std::string kSampleDomain = "sdchtest.com"; |
478 std::string dictionary(NewSdchDictionary(kSampleDomain)); | 485 std::string dictionary(NewSdchDictionary(kSampleDomain)); |
479 | 486 |
480 std::string url_string = "http://" + kSampleDomain; | 487 std::string url_string = "http://" + kSampleDomain; |
481 | 488 |
482 GURL url(url_string); | 489 GURL url(url_string); |
483 EXPECT_TRUE(sdch_manager_->AddSdchDictionary(dictionary, url)); | 490 EXPECT_TRUE(AddDictionary(dictionary, url)); |
484 | 491 |
485 std::string compressed(NewSdchCompressedData(dictionary)); | 492 std::string compressed(NewSdchCompressedData(dictionary)); |
486 | 493 |
487 std::vector<Filter::FilterType> filter_types; | 494 std::vector<Filter::FilterType> filter_types; |
488 filter_types.push_back(Filter::FILTER_TYPE_SDCH); | 495 filter_types.push_back(Filter::FILTER_TYPE_SDCH); |
489 | 496 |
490 filter_context()->SetURL(GURL("ftp://" + kSampleDomain)); | 497 filter_context()->SetURL(GURL("ftp://" + kSampleDomain)); |
491 scoped_ptr<Filter> filter(Filter::Factory(filter_types, *filter_context())); | 498 scoped_ptr<Filter> filter(Filter::Factory(filter_types, *filter_context())); |
492 | 499 |
493 const size_t feed_block_size(100); | 500 const size_t feed_block_size(100); |
494 const size_t output_block_size(100); | 501 const size_t output_block_size(100); |
495 std::string output; | 502 std::string output; |
496 | 503 |
497 EXPECT_FALSE(FilterTestData(compressed, feed_block_size, output_block_size, | 504 EXPECT_FALSE(FilterTestData(compressed, feed_block_size, output_block_size, |
498 filter.get(), &output)); | 505 filter.get(), &output)); |
499 } | 506 } |
500 | 507 |
501 TEST_F(SdchFilterTest, NoDecodeFileColon) { | 508 TEST_F(SdchFilterTest, NoDecodeFileColon) { |
502 // Construct a valid SDCH dictionary from a VCDIFF dictionary. | 509 // Construct a valid SDCH dictionary from a VCDIFF dictionary. |
503 const std::string kSampleDomain = "sdchtest.com"; | 510 const std::string kSampleDomain = "sdchtest.com"; |
504 std::string dictionary(NewSdchDictionary(kSampleDomain)); | 511 std::string dictionary(NewSdchDictionary(kSampleDomain)); |
505 | 512 |
506 std::string url_string = "http://" + kSampleDomain; | 513 std::string url_string = "http://" + kSampleDomain; |
507 | 514 |
508 GURL url(url_string); | 515 GURL url(url_string); |
509 EXPECT_TRUE(sdch_manager_->AddSdchDictionary(dictionary, url)); | 516 EXPECT_TRUE(AddDictionary(dictionary, url)); |
510 | 517 |
511 std::string compressed(NewSdchCompressedData(dictionary)); | 518 std::string compressed(NewSdchCompressedData(dictionary)); |
512 | 519 |
513 std::vector<Filter::FilterType> filter_types; | 520 std::vector<Filter::FilterType> filter_types; |
514 filter_types.push_back(Filter::FILTER_TYPE_SDCH); | 521 filter_types.push_back(Filter::FILTER_TYPE_SDCH); |
515 | 522 |
516 filter_context()->SetURL(GURL("file://" + kSampleDomain)); | 523 filter_context()->SetURL(GURL("file://" + kSampleDomain)); |
517 scoped_ptr<Filter> filter(Filter::Factory(filter_types, *filter_context())); | 524 scoped_ptr<Filter> filter(Filter::Factory(filter_types, *filter_context())); |
518 | 525 |
519 const size_t feed_block_size(100); | 526 const size_t feed_block_size(100); |
520 const size_t output_block_size(100); | 527 const size_t output_block_size(100); |
521 std::string output; | 528 std::string output; |
522 | 529 |
523 EXPECT_FALSE(FilterTestData(compressed, feed_block_size, output_block_size, | 530 EXPECT_FALSE(FilterTestData(compressed, feed_block_size, output_block_size, |
524 filter.get(), &output)); | 531 filter.get(), &output)); |
525 } | 532 } |
526 | 533 |
527 TEST_F(SdchFilterTest, NoDecodeAboutColon) { | 534 TEST_F(SdchFilterTest, NoDecodeAboutColon) { |
528 // Construct a valid SDCH dictionary from a VCDIFF dictionary. | 535 // Construct a valid SDCH dictionary from a VCDIFF dictionary. |
529 const std::string kSampleDomain = "sdchtest.com"; | 536 const std::string kSampleDomain = "sdchtest.com"; |
530 std::string dictionary(NewSdchDictionary(kSampleDomain)); | 537 std::string dictionary(NewSdchDictionary(kSampleDomain)); |
531 | 538 |
532 std::string url_string = "http://" + kSampleDomain; | 539 std::string url_string = "http://" + kSampleDomain; |
533 | 540 |
534 GURL url(url_string); | 541 GURL url(url_string); |
535 EXPECT_TRUE(sdch_manager_->AddSdchDictionary(dictionary, url)); | 542 EXPECT_TRUE(AddDictionary(dictionary, url)); |
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 EXPECT_TRUE(AddDictionary(dictionary, url)); |
562 | 569 |
563 std::string compressed(NewSdchCompressedData(dictionary)); | 570 std::string compressed(NewSdchCompressedData(dictionary)); |
564 | 571 |
565 std::vector<Filter::FilterType> filter_types; | 572 std::vector<Filter::FilterType> filter_types; |
566 filter_types.push_back(Filter::FILTER_TYPE_SDCH); | 573 filter_types.push_back(Filter::FILTER_TYPE_SDCH); |
567 | 574 |
568 filter_context()->SetURL(GURL("javascript://" + kSampleDomain)); | 575 filter_context()->SetURL(GURL("javascript://" + kSampleDomain)); |
569 scoped_ptr<Filter> filter(Filter::Factory(filter_types, *filter_context())); | 576 scoped_ptr<Filter> filter(Filter::Factory(filter_types, *filter_context())); |
570 | 577 |
571 const size_t feed_block_size(100); | 578 const size_t feed_block_size(100); |
572 const size_t output_block_size(100); | 579 const size_t output_block_size(100); |
573 std::string output; | 580 std::string output; |
574 | 581 |
575 EXPECT_FALSE(FilterTestData(compressed, feed_block_size, output_block_size, | 582 EXPECT_FALSE(FilterTestData(compressed, feed_block_size, output_block_size, |
576 filter.get(), &output)); | 583 filter.get(), &output)); |
577 } | 584 } |
578 | 585 |
579 TEST_F(SdchFilterTest, CanStillDecodeHttp) { | 586 TEST_F(SdchFilterTest, CanStillDecodeHttp) { |
580 // Construct a valid SDCH dictionary from a VCDIFF dictionary. | 587 // Construct a valid SDCH dictionary from a VCDIFF dictionary. |
581 const std::string kSampleDomain = "sdchtest.com"; | 588 const std::string kSampleDomain = "sdchtest.com"; |
582 std::string dictionary(NewSdchDictionary(kSampleDomain)); | 589 std::string dictionary(NewSdchDictionary(kSampleDomain)); |
583 | 590 |
584 std::string url_string = "http://" + kSampleDomain; | 591 std::string url_string = "http://" + kSampleDomain; |
585 | 592 |
586 GURL url(url_string); | 593 GURL url(url_string); |
587 EXPECT_TRUE(sdch_manager_->AddSdchDictionary(dictionary, url)); | 594 EXPECT_TRUE(AddDictionary(dictionary, url)); |
588 | 595 |
589 std::string compressed(NewSdchCompressedData(dictionary)); | 596 std::string compressed(NewSdchCompressedData(dictionary)); |
590 | 597 |
591 std::vector<Filter::FilterType> filter_types; | 598 std::vector<Filter::FilterType> filter_types; |
592 filter_types.push_back(Filter::FILTER_TYPE_SDCH); | 599 filter_types.push_back(Filter::FILTER_TYPE_SDCH); |
593 | 600 |
594 filter_context()->SetURL(GURL("http://" + kSampleDomain)); | 601 filter_context()->SetURL(GURL("http://" + kSampleDomain)); |
595 scoped_ptr<Filter> filter(Filter::Factory(filter_types, *filter_context())); | 602 scoped_ptr<Filter> filter(Filter::Factory(filter_types, *filter_context())); |
596 | 603 |
597 const size_t feed_block_size(100); | 604 const size_t feed_block_size(100); |
598 const size_t output_block_size(100); | 605 const size_t output_block_size(100); |
599 std::string output; | 606 std::string output; |
600 | 607 |
601 EXPECT_TRUE(FilterTestData(compressed, feed_block_size, output_block_size, | 608 EXPECT_TRUE(FilterTestData(compressed, feed_block_size, output_block_size, |
602 filter.get(), &output)); | 609 filter.get(), &output)); |
603 } | 610 } |
604 | 611 |
605 TEST_F(SdchFilterTest, CrossDomainDictionaryUse) { | 612 TEST_F(SdchFilterTest, CrossDomainDictionaryUse) { |
606 // Construct a valid SDCH dictionary from a VCDIFF dictionary. | 613 // Construct a valid SDCH dictionary from a VCDIFF dictionary. |
607 const std::string kSampleDomain = "sdchtest.com"; | 614 const std::string kSampleDomain = "sdchtest.com"; |
608 std::string dictionary(NewSdchDictionary(kSampleDomain)); | 615 std::string dictionary(NewSdchDictionary(kSampleDomain)); |
609 | 616 |
610 std::string url_string = "http://" + kSampleDomain; | 617 std::string url_string = "http://" + kSampleDomain; |
611 | 618 |
612 GURL url(url_string); | 619 GURL url(url_string); |
613 EXPECT_TRUE(sdch_manager_->AddSdchDictionary(dictionary, url)); | 620 EXPECT_TRUE(AddDictionary(dictionary, url)); |
614 | 621 |
615 std::string compressed(NewSdchCompressedData(dictionary)); | 622 std::string compressed(NewSdchCompressedData(dictionary)); |
616 | 623 |
617 std::vector<Filter::FilterType> filter_types; | 624 std::vector<Filter::FilterType> filter_types; |
618 filter_types.push_back(Filter::FILTER_TYPE_SDCH); | 625 filter_types.push_back(Filter::FILTER_TYPE_SDCH); |
619 | 626 |
620 // Decode with content arriving from the "wrong" domain. | 627 // Decode with content arriving from the "wrong" domain. |
621 // This tests SdchManager::CanSet(). | 628 // This tests SdchManager::CanSet(). |
622 GURL wrong_domain_url("http://www.wrongdomain.com"); | 629 GURL wrong_domain_url("http://www.wrongdomain.com"); |
623 filter_context()->SetURL(wrong_domain_url); | 630 filter_context()->SetURL(wrong_domain_url); |
(...skipping 18 matching lines...) Expand all Loading... |
642 if (SdchManager::kMaxDictionaryCount <= 1) | 649 if (SdchManager::kMaxDictionaryCount <= 1) |
643 return; | 650 return; |
644 | 651 |
645 // Construct a valid SDCH dictionary from a VCDIFF dictionary. | 652 // Construct a valid SDCH dictionary from a VCDIFF dictionary. |
646 const std::string kSampleDomain = "sdchtest.com"; | 653 const std::string kSampleDomain = "sdchtest.com"; |
647 std::string dictionary(NewSdchDictionary(kSampleDomain)); | 654 std::string dictionary(NewSdchDictionary(kSampleDomain)); |
648 | 655 |
649 std::string url_string = "http://" + kSampleDomain; | 656 std::string url_string = "http://" + kSampleDomain; |
650 | 657 |
651 GURL url(url_string); | 658 GURL url(url_string); |
652 EXPECT_TRUE(sdch_manager_->AddSdchDictionary(dictionary, url)); | 659 EXPECT_TRUE(AddDictionary(dictionary, url)); |
653 | 660 |
654 // Create a dictionary with a path restriction, by prefixing dictionary. | 661 // Create a dictionary with a path restriction, by prefixing dictionary. |
655 const std::string path("/special_path/bin"); | 662 const std::string path("/special_path/bin"); |
656 std::string dictionary_with_path("Path: " + path + "\n"); | 663 std::string dictionary_with_path("Path: " + path + "\n"); |
657 dictionary_with_path.append(dictionary); | 664 dictionary_with_path.append(dictionary); |
658 EXPECT_TRUE(sdch_manager_->AddSdchDictionary(dictionary_with_path, url)); | 665 EXPECT_TRUE(AddDictionary(dictionary_with_path, url)); |
659 | 666 |
660 std::string compressed_for_path(NewSdchCompressedData(dictionary_with_path)); | 667 std::string compressed_for_path(NewSdchCompressedData(dictionary_with_path)); |
661 | 668 |
662 std::vector<Filter::FilterType> filter_types; | 669 std::vector<Filter::FilterType> filter_types; |
663 filter_types.push_back(Filter::FILTER_TYPE_SDCH); | 670 filter_types.push_back(Filter::FILTER_TYPE_SDCH); |
664 | 671 |
665 // Test decode the path data, arriving from a valid path. | 672 // Test decode the path data, arriving from a valid path. |
666 filter_context()->SetURL(GURL(url_string + path)); | 673 filter_context()->SetURL(GURL(url_string + path)); |
667 scoped_ptr<Filter> filter(Filter::Factory(filter_types, *filter_context())); | 674 scoped_ptr<Filter> filter(Filter::Factory(filter_types, *filter_context())); |
668 | 675 |
(...skipping 27 matching lines...) Expand all Loading... |
696 if (SdchManager::kMaxDictionaryCount <= 1) | 703 if (SdchManager::kMaxDictionaryCount <= 1) |
697 return; | 704 return; |
698 | 705 |
699 // Construct a valid SDCH dictionary from a VCDIFF dictionary. | 706 // Construct a valid SDCH dictionary from a VCDIFF dictionary. |
700 const std::string kSampleDomain = "sdchtest.com"; | 707 const std::string kSampleDomain = "sdchtest.com"; |
701 std::string dictionary(NewSdchDictionary(kSampleDomain)); | 708 std::string dictionary(NewSdchDictionary(kSampleDomain)); |
702 | 709 |
703 std::string url_string = "http://" + kSampleDomain; | 710 std::string url_string = "http://" + kSampleDomain; |
704 | 711 |
705 GURL url(url_string); | 712 GURL url(url_string); |
706 EXPECT_TRUE(sdch_manager_->AddSdchDictionary(dictionary, url)); | 713 EXPECT_TRUE(AddDictionary(dictionary, url)); |
707 | |
708 | 714 |
709 // Create a dictionary with a port restriction, by prefixing old dictionary. | 715 // Create a dictionary with a port restriction, by prefixing old dictionary. |
710 const std::string port("502"); | 716 const std::string port("502"); |
711 std::string dictionary_with_port("Port: " + port + "\n"); | 717 std::string dictionary_with_port("Port: " + port + "\n"); |
712 dictionary_with_port.append("Port: 80\n"); // Add default port. | 718 dictionary_with_port.append("Port: 80\n"); // Add default port. |
713 dictionary_with_port.append(dictionary); | 719 dictionary_with_port.append(dictionary); |
714 EXPECT_TRUE(sdch_manager_->AddSdchDictionary(dictionary_with_port, | 720 EXPECT_TRUE( |
715 GURL(url_string + ":" + port))); | 721 AddDictionary(dictionary_with_port, GURL(url_string + ":" + port))); |
716 | 722 |
717 std::string compressed_for_port(NewSdchCompressedData(dictionary_with_port)); | 723 std::string compressed_for_port(NewSdchCompressedData(dictionary_with_port)); |
718 | 724 |
719 std::vector<Filter::FilterType> filter_types; | 725 std::vector<Filter::FilterType> filter_types; |
720 filter_types.push_back(Filter::FILTER_TYPE_SDCH); | 726 filter_types.push_back(Filter::FILTER_TYPE_SDCH); |
721 | 727 |
722 // Test decode the port data, arriving from a valid port. | 728 // Test decode the port data, arriving from a valid port. |
723 filter_context()->SetURL(GURL(url_string + ":" + port)); | 729 filter_context()->SetURL(GURL(url_string + ":" + port)); |
724 scoped_ptr<Filter> filter(Filter::Factory(filter_types, *filter_context())); | 730 scoped_ptr<Filter> filter(Filter::Factory(filter_types, *filter_context())); |
725 | 731 |
(...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 | 832 // 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. | 833 // do the gzip decoding first, and then decode the SDCH content. |
828 TEST_F(SdchFilterTest, FilterChaining) { | 834 TEST_F(SdchFilterTest, FilterChaining) { |
829 // Construct a valid SDCH dictionary from a VCDIFF dictionary. | 835 // Construct a valid SDCH dictionary from a VCDIFF dictionary. |
830 const std::string kSampleDomain = "sdchtest.com"; | 836 const std::string kSampleDomain = "sdchtest.com"; |
831 std::string dictionary(NewSdchDictionary(kSampleDomain)); | 837 std::string dictionary(NewSdchDictionary(kSampleDomain)); |
832 | 838 |
833 std::string url_string = "http://" + kSampleDomain; | 839 std::string url_string = "http://" + kSampleDomain; |
834 | 840 |
835 GURL url(url_string); | 841 GURL url(url_string); |
836 EXPECT_TRUE(sdch_manager_->AddSdchDictionary(dictionary, url)); | 842 EXPECT_TRUE(AddDictionary(dictionary, url)); |
837 | 843 |
838 std::string sdch_compressed(NewSdchCompressedData(dictionary)); | 844 std::string sdch_compressed(NewSdchCompressedData(dictionary)); |
839 | 845 |
840 // Use Gzip to compress the sdch sdch_compressed data. | 846 // Use Gzip to compress the sdch sdch_compressed data. |
841 std::string gzip_compressed_sdch = gzip_compress(sdch_compressed); | 847 std::string gzip_compressed_sdch = gzip_compress(sdch_compressed); |
842 | 848 |
843 // Construct a chained filter. | 849 // Construct a chained filter. |
844 std::vector<Filter::FilterType> filter_types; | 850 std::vector<Filter::FilterType> filter_types; |
845 filter_types.push_back(Filter::FILTER_TYPE_SDCH); | 851 filter_types.push_back(Filter::FILTER_TYPE_SDCH); |
846 filter_types.push_back(Filter::FILTER_TYPE_GZIP); | 852 filter_types.push_back(Filter::FILTER_TYPE_GZIP); |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
908 } | 914 } |
909 | 915 |
910 TEST_F(SdchFilterTest, DefaultGzipIfSdch) { | 916 TEST_F(SdchFilterTest, DefaultGzipIfSdch) { |
911 // Construct a valid SDCH dictionary from a VCDIFF dictionary. | 917 // Construct a valid SDCH dictionary from a VCDIFF dictionary. |
912 const std::string kSampleDomain = "sdchtest.com"; | 918 const std::string kSampleDomain = "sdchtest.com"; |
913 std::string dictionary(NewSdchDictionary(kSampleDomain)); | 919 std::string dictionary(NewSdchDictionary(kSampleDomain)); |
914 | 920 |
915 std::string url_string = "http://" + kSampleDomain; | 921 std::string url_string = "http://" + kSampleDomain; |
916 | 922 |
917 GURL url(url_string); | 923 GURL url(url_string); |
918 EXPECT_TRUE(sdch_manager_->AddSdchDictionary(dictionary, url)); | 924 EXPECT_TRUE(AddDictionary(dictionary, url)); |
919 | 925 |
920 std::string sdch_compressed(NewSdchCompressedData(dictionary)); | 926 std::string sdch_compressed(NewSdchCompressedData(dictionary)); |
921 | 927 |
922 // Use Gzip to compress the sdch sdch_compressed data. | 928 // Use Gzip to compress the sdch sdch_compressed data. |
923 std::string gzip_compressed_sdch = gzip_compress(sdch_compressed); | 929 std::string gzip_compressed_sdch = gzip_compress(sdch_compressed); |
924 | 930 |
925 // Only claim to have sdch content, but really use the gzipped sdch content. | 931 // Only claim to have sdch content, but really use the gzipped sdch content. |
926 // System should automatically add the missing (optional) gzip. | 932 // System should automatically add the missing (optional) gzip. |
927 std::vector<Filter::FilterType> filter_types; | 933 std::vector<Filter::FilterType> filter_types; |
928 filter_types.push_back(Filter::FILTER_TYPE_SDCH); | 934 filter_types.push_back(Filter::FILTER_TYPE_SDCH); |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
964 } | 970 } |
965 | 971 |
966 TEST_F(SdchFilterTest, AcceptGzipSdchIfGzip) { | 972 TEST_F(SdchFilterTest, AcceptGzipSdchIfGzip) { |
967 // Construct a valid SDCH dictionary from a VCDIFF dictionary. | 973 // Construct a valid SDCH dictionary from a VCDIFF dictionary. |
968 const std::string kSampleDomain = "sdchtest.com"; | 974 const std::string kSampleDomain = "sdchtest.com"; |
969 std::string dictionary(NewSdchDictionary(kSampleDomain)); | 975 std::string dictionary(NewSdchDictionary(kSampleDomain)); |
970 | 976 |
971 std::string url_string = "http://" + kSampleDomain; | 977 std::string url_string = "http://" + kSampleDomain; |
972 | 978 |
973 GURL url(url_string); | 979 GURL url(url_string); |
974 EXPECT_TRUE(sdch_manager_->AddSdchDictionary(dictionary, url)); | 980 EXPECT_TRUE(AddDictionary(dictionary, url)); |
975 | 981 |
976 std::string sdch_compressed(NewSdchCompressedData(dictionary)); | 982 std::string sdch_compressed(NewSdchCompressedData(dictionary)); |
977 | 983 |
978 // Use Gzip to compress the sdch sdch_compressed data. | 984 // Use Gzip to compress the sdch sdch_compressed data. |
979 std::string gzip_compressed_sdch = gzip_compress(sdch_compressed); | 985 std::string gzip_compressed_sdch = gzip_compress(sdch_compressed); |
980 | 986 |
981 // Some proxies strip the content encoding statement down to a mere gzip, but | 987 // Some proxies strip the content encoding statement down to a mere gzip, but |
982 // pass through the original content (with full sdch,gzip encoding). | 988 // pass through the original content (with full sdch,gzip encoding). |
983 // Only claim to have gzip content, but really use the gzipped sdch content. | 989 // Only claim to have gzip content, but really use the gzipped sdch content. |
984 // System should automatically add the missing (optional) sdch. | 990 // System should automatically add the missing (optional) sdch. |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1023 } | 1029 } |
1024 | 1030 |
1025 TEST_F(SdchFilterTest, DefaultSdchGzipIfEmpty) { | 1031 TEST_F(SdchFilterTest, DefaultSdchGzipIfEmpty) { |
1026 // Construct a valid SDCH dictionary from a VCDIFF dictionary. | 1032 // Construct a valid SDCH dictionary from a VCDIFF dictionary. |
1027 const std::string kSampleDomain = "sdchtest.com"; | 1033 const std::string kSampleDomain = "sdchtest.com"; |
1028 std::string dictionary(NewSdchDictionary(kSampleDomain)); | 1034 std::string dictionary(NewSdchDictionary(kSampleDomain)); |
1029 | 1035 |
1030 std::string url_string = "http://" + kSampleDomain; | 1036 std::string url_string = "http://" + kSampleDomain; |
1031 | 1037 |
1032 GURL url(url_string); | 1038 GURL url(url_string); |
1033 EXPECT_TRUE(sdch_manager_->AddSdchDictionary(dictionary, url)); | 1039 EXPECT_TRUE(AddDictionary(dictionary, url)); |
1034 | 1040 |
1035 std::string sdch_compressed(NewSdchCompressedData(dictionary)); | 1041 std::string sdch_compressed(NewSdchCompressedData(dictionary)); |
1036 | 1042 |
1037 // Use Gzip to compress the sdch sdch_compressed data. | 1043 // Use Gzip to compress the sdch sdch_compressed data. |
1038 std::string gzip_compressed_sdch = gzip_compress(sdch_compressed); | 1044 std::string gzip_compressed_sdch = gzip_compress(sdch_compressed); |
1039 | 1045 |
1040 // Only claim to have non-encoded content, but really use the gzipped sdch | 1046 // Only claim to have non-encoded content, but really use the gzipped sdch |
1041 // content. | 1047 // content. |
1042 // System should automatically add the missing (optional) sdch,gzip. | 1048 // System should automatically add the missing (optional) sdch,gzip. |
1043 std::vector<Filter::FilterType> filter_types; | 1049 std::vector<Filter::FilterType> filter_types; |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1079 } | 1085 } |
1080 | 1086 |
1081 TEST_F(SdchFilterTest, AcceptGzipGzipSdchIfGzip) { | 1087 TEST_F(SdchFilterTest, AcceptGzipGzipSdchIfGzip) { |
1082 // Construct a valid SDCH dictionary from a VCDIFF dictionary. | 1088 // Construct a valid SDCH dictionary from a VCDIFF dictionary. |
1083 const std::string kSampleDomain = "sdchtest.com"; | 1089 const std::string kSampleDomain = "sdchtest.com"; |
1084 std::string dictionary(NewSdchDictionary(kSampleDomain)); | 1090 std::string dictionary(NewSdchDictionary(kSampleDomain)); |
1085 | 1091 |
1086 std::string url_string = "http://" + kSampleDomain; | 1092 std::string url_string = "http://" + kSampleDomain; |
1087 | 1093 |
1088 GURL url(url_string); | 1094 GURL url(url_string); |
1089 EXPECT_TRUE(sdch_manager_->AddSdchDictionary(dictionary, url)); | 1095 EXPECT_TRUE(AddDictionary(dictionary, url)); |
1090 | 1096 |
1091 std::string sdch_compressed(NewSdchCompressedData(dictionary)); | 1097 std::string sdch_compressed(NewSdchCompressedData(dictionary)); |
1092 | 1098 |
1093 // Vodaphone (UK) Mobile Broadband provides double gzipped sdch with a content | 1099 // Vodaphone (UK) Mobile Broadband provides double gzipped sdch with a content |
1094 // encoding of merely gzip (apparently, only listing the extra level of | 1100 // encoding of merely gzip (apparently, only listing the extra level of |
1095 // wrapper compression they added, but discarding the actual content encoding. | 1101 // wrapper compression they added, but discarding the actual content encoding. |
1096 // Use Gzip to double compress the sdch sdch_compressed data. | 1102 // Use Gzip to double compress the sdch sdch_compressed data. |
1097 std::string double_gzip_compressed_sdch = gzip_compress(gzip_compress( | 1103 std::string double_gzip_compressed_sdch = gzip_compress(gzip_compress( |
1098 sdch_compressed)); | 1104 sdch_compressed)); |
1099 | 1105 |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1133 | 1139 |
1134 feed_block_size = 1; | 1140 feed_block_size = 1; |
1135 output_block_size = 1; | 1141 output_block_size = 1; |
1136 output.clear(); | 1142 output.clear(); |
1137 EXPECT_TRUE(FilterTestData(double_gzip_compressed_sdch, feed_block_size, | 1143 EXPECT_TRUE(FilterTestData(double_gzip_compressed_sdch, feed_block_size, |
1138 output_block_size, filter.get(), &output)); | 1144 output_block_size, filter.get(), &output)); |
1139 EXPECT_EQ(output, expanded_); | 1145 EXPECT_EQ(output, expanded_); |
1140 } | 1146 } |
1141 | 1147 |
1142 } // namespace net | 1148 } // namespace net |
OLD | NEW |