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

Side by Side Diff: components/data_reduction_proxy/common/data_reduction_proxy_headers_unittest.cc

Issue 501413003: Remove implicit conversions from scoped_refptr to T* in components/data_reduction_proxy/ (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 3 months 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
« no previous file with comments | « components/data_reduction_proxy/browser/data_reduction_proxy_tamper_detection_unittest.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "components/data_reduction_proxy/common/data_reduction_proxy_headers.h" 5 #include "components/data_reduction_proxy/common/data_reduction_proxy_headers.h"
6 6
7 #include <vector> 7 #include <vector>
8 8
9 #include "net/http/http_response_headers.h" 9 #include "net/http/http_response_headers.h"
10 #include "net/proxy/proxy_service.h" 10 #include "net/proxy/proxy_service.h"
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
105 }, 105 },
106 }; 106 };
107 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) { 107 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) {
108 std::string headers(tests[i].headers); 108 std::string headers(tests[i].headers);
109 HeadersToRaw(&headers); 109 HeadersToRaw(&headers);
110 scoped_refptr<net::HttpResponseHeaders> parsed( 110 scoped_refptr<net::HttpResponseHeaders> parsed(
111 new net::HttpResponseHeaders(headers)); 111 new net::HttpResponseHeaders(headers));
112 112
113 std::string action_value; 113 std::string action_value;
114 bool has_action_key = GetDataReductionProxyActionValue( 114 bool has_action_key = GetDataReductionProxyActionValue(
115 parsed, tests[i].action_key, &action_value); 115 parsed.get(), tests[i].action_key, &action_value);
116 EXPECT_EQ(tests[i].expected_result, has_action_key); 116 EXPECT_EQ(tests[i].expected_result, has_action_key);
117 if (has_action_key) { 117 if (has_action_key) {
118 EXPECT_EQ(tests[i].expected_action_value, action_value); 118 EXPECT_EQ(tests[i].expected_action_value, action_value);
119 } 119 }
120 } 120 }
121 } 121 }
122 122
123 TEST_F(DataReductionProxyHeadersTest, GetProxyBypassInfo) { 123 TEST_F(DataReductionProxyHeadersTest, GetProxyBypassInfo) {
124 const struct { 124 const struct {
125 const char* headers; 125 const char* headers;
(...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after
354 false, 354 false,
355 }, 355 },
356 }; 356 };
357 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) { 357 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) {
358 std::string headers(tests[i].headers); 358 std::string headers(tests[i].headers);
359 HeadersToRaw(&headers); 359 HeadersToRaw(&headers);
360 scoped_refptr<net::HttpResponseHeaders> parsed( 360 scoped_refptr<net::HttpResponseHeaders> parsed(
361 new net::HttpResponseHeaders(headers)); 361 new net::HttpResponseHeaders(headers));
362 362
363 DataReductionProxyInfo data_reduction_proxy_info; 363 DataReductionProxyInfo data_reduction_proxy_info;
364 EXPECT_EQ(tests[i].expected_result, 364 EXPECT_EQ(
365 ParseHeadersAndSetProxyInfo(parsed, &data_reduction_proxy_info)); 365 tests[i].expected_result,
366 ParseHeadersAndSetProxyInfo(parsed.get(), &data_reduction_proxy_info));
366 EXPECT_EQ(tests[i].expected_retry_delay, 367 EXPECT_EQ(tests[i].expected_retry_delay,
367 data_reduction_proxy_info.bypass_duration.InSeconds()); 368 data_reduction_proxy_info.bypass_duration.InSeconds());
368 EXPECT_EQ(tests[i].expected_bypass_all, 369 EXPECT_EQ(tests[i].expected_bypass_all,
369 data_reduction_proxy_info.bypass_all); 370 data_reduction_proxy_info.bypass_all);
370 EXPECT_EQ(tests[i].expected_mark_proxies_as_bad, 371 EXPECT_EQ(tests[i].expected_mark_proxies_as_bad,
371 data_reduction_proxy_info.mark_proxies_as_bad); 372 data_reduction_proxy_info.mark_proxies_as_bad);
372 } 373 }
373 } 374 }
374 375
375 TEST_F(DataReductionProxyHeadersTest, ParseHeadersAndSetProxyInfo) { 376 TEST_F(DataReductionProxyHeadersTest, ParseHeadersAndSetProxyInfo) {
376 std::string headers = 377 std::string headers =
377 "HTTP/1.1 200 OK\n" 378 "HTTP/1.1 200 OK\n"
378 "connection: keep-alive\n" 379 "connection: keep-alive\n"
379 "Chrome-Proxy: bypass=0\n" 380 "Chrome-Proxy: bypass=0\n"
380 "Content-Length: 999\n"; 381 "Content-Length: 999\n";
381 HeadersToRaw(&headers); 382 HeadersToRaw(&headers);
382 scoped_refptr<net::HttpResponseHeaders> parsed( 383 scoped_refptr<net::HttpResponseHeaders> parsed(
383 new net::HttpResponseHeaders(headers)); 384 new net::HttpResponseHeaders(headers));
384 385
385 DataReductionProxyInfo data_reduction_proxy_info; 386 DataReductionProxyInfo data_reduction_proxy_info;
386 EXPECT_TRUE(ParseHeadersAndSetProxyInfo(parsed, &data_reduction_proxy_info)); 387 EXPECT_TRUE(
388 ParseHeadersAndSetProxyInfo(parsed.get(), &data_reduction_proxy_info));
387 EXPECT_LE(60, data_reduction_proxy_info.bypass_duration.InSeconds()); 389 EXPECT_LE(60, data_reduction_proxy_info.bypass_duration.InSeconds());
388 EXPECT_GE(5 * 60, data_reduction_proxy_info.bypass_duration.InSeconds()); 390 EXPECT_GE(5 * 60, data_reduction_proxy_info.bypass_duration.InSeconds());
389 EXPECT_FALSE(data_reduction_proxy_info.bypass_all); 391 EXPECT_FALSE(data_reduction_proxy_info.bypass_all);
390 } 392 }
391 393
392 TEST_F(DataReductionProxyHeadersTest, HasDataReductionProxyViaHeader) { 394 TEST_F(DataReductionProxyHeadersTest, HasDataReductionProxyViaHeader) {
393 const struct { 395 const struct {
394 const char* headers; 396 const char* headers;
395 bool expected_result; 397 bool expected_result;
396 bool expected_has_intermediary; 398 bool expected_has_intermediary;
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
506 }; 508 };
507 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) { 509 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) {
508 std::string headers(tests[i].headers); 510 std::string headers(tests[i].headers);
509 HeadersToRaw(&headers); 511 HeadersToRaw(&headers);
510 scoped_refptr<net::HttpResponseHeaders> parsed( 512 scoped_refptr<net::HttpResponseHeaders> parsed(
511 new net::HttpResponseHeaders(headers)); 513 new net::HttpResponseHeaders(headers));
512 514
513 bool has_chrome_proxy_via_header, has_intermediary; 515 bool has_chrome_proxy_via_header, has_intermediary;
514 if (tests[i].ignore_intermediary) { 516 if (tests[i].ignore_intermediary) {
515 has_chrome_proxy_via_header = 517 has_chrome_proxy_via_header =
516 HasDataReductionProxyViaHeader(parsed, NULL); 518 HasDataReductionProxyViaHeader(parsed.get(), NULL);
517 } 519 }
518 else { 520 else {
519 has_chrome_proxy_via_header = 521 has_chrome_proxy_via_header =
520 HasDataReductionProxyViaHeader(parsed, &has_intermediary); 522 HasDataReductionProxyViaHeader(parsed.get(), &has_intermediary);
521 } 523 }
522 EXPECT_EQ(tests[i].expected_result, has_chrome_proxy_via_header); 524 EXPECT_EQ(tests[i].expected_result, has_chrome_proxy_via_header);
523 if (has_chrome_proxy_via_header && !tests[i].ignore_intermediary) { 525 if (has_chrome_proxy_via_header && !tests[i].ignore_intermediary) {
524 EXPECT_EQ(tests[i].expected_has_intermediary, has_intermediary); 526 EXPECT_EQ(tests[i].expected_has_intermediary, has_intermediary);
525 } 527 }
526 } 528 }
527 } 529 }
528 530
529 TEST_F(DataReductionProxyHeadersTest, GetDataReductionProxyBypassEventType) { 531 TEST_F(DataReductionProxyHeadersTest, GetDataReductionProxyBypassEventType) {
530 const struct { 532 const struct {
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
626 "Via: 1.1 Chrome-Compression-Proxy\n", 628 "Via: 1.1 Chrome-Compression-Proxy\n",
627 BYPASS_EVENT_TYPE_MAX, 629 BYPASS_EVENT_TYPE_MAX,
628 } 630 }
629 }; 631 };
630 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) { 632 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) {
631 std::string headers(tests[i].headers); 633 std::string headers(tests[i].headers);
632 HeadersToRaw(&headers); 634 HeadersToRaw(&headers);
633 scoped_refptr<net::HttpResponseHeaders> parsed( 635 scoped_refptr<net::HttpResponseHeaders> parsed(
634 new net::HttpResponseHeaders(headers)); 636 new net::HttpResponseHeaders(headers));
635 DataReductionProxyInfo chrome_proxy_info; 637 DataReductionProxyInfo chrome_proxy_info;
636 EXPECT_EQ(tests[i].expected_result, 638 EXPECT_EQ(
637 GetDataReductionProxyBypassType(parsed, &chrome_proxy_info)); 639 tests[i].expected_result,
640 GetDataReductionProxyBypassType(parsed.get(), &chrome_proxy_info));
638 } 641 }
639 } 642 }
640 643
641 TEST_F(DataReductionProxyHeadersTest, 644 TEST_F(DataReductionProxyHeadersTest,
642 GetDataReductionProxyActionFingerprintChromeProxy) { 645 GetDataReductionProxyActionFingerprintChromeProxy) {
643 const struct { 646 const struct {
644 std::string label; 647 std::string label;
645 const char* headers; 648 const char* headers;
646 bool expected_fingerprint_exist; 649 bool expected_fingerprint_exist;
647 std::string expected_fingerprint; 650 std::string expected_fingerprint;
(...skipping 18 matching lines...) Expand all
666 }, 669 },
667 }; 670 };
668 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) { 671 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) {
669 std::string headers(tests[i].headers); 672 std::string headers(tests[i].headers);
670 HeadersToRaw(&headers); 673 HeadersToRaw(&headers);
671 scoped_refptr<net::HttpResponseHeaders> parsed( 674 scoped_refptr<net::HttpResponseHeaders> parsed(
672 new net::HttpResponseHeaders(headers)); 675 new net::HttpResponseHeaders(headers));
673 676
674 std::string fingerprint; 677 std::string fingerprint;
675 bool fingerprint_exist = GetDataReductionProxyActionFingerprintChromeProxy( 678 bool fingerprint_exist = GetDataReductionProxyActionFingerprintChromeProxy(
676 parsed, &fingerprint); 679 parsed.get(), &fingerprint);
677 EXPECT_EQ(tests[i].expected_fingerprint_exist, fingerprint_exist) 680 EXPECT_EQ(tests[i].expected_fingerprint_exist, fingerprint_exist)
678 << tests[i].label; 681 << tests[i].label;
679 682
680 if (fingerprint_exist) 683 if (fingerprint_exist)
681 EXPECT_EQ(tests[i].expected_fingerprint, fingerprint) << tests[i].label; 684 EXPECT_EQ(tests[i].expected_fingerprint, fingerprint) << tests[i].label;
682 } 685 }
683 } 686 }
684 687
685 TEST_F(DataReductionProxyHeadersTest, 688 TEST_F(DataReductionProxyHeadersTest,
686 GetDataReductionProxyActionFingerprintVia) { 689 GetDataReductionProxyActionFingerprintVia) {
(...skipping 23 matching lines...) Expand all
710 }, 713 },
711 }; 714 };
712 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) { 715 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) {
713 std::string headers(tests[i].headers); 716 std::string headers(tests[i].headers);
714 HeadersToRaw(&headers); 717 HeadersToRaw(&headers);
715 scoped_refptr<net::HttpResponseHeaders> parsed( 718 scoped_refptr<net::HttpResponseHeaders> parsed(
716 new net::HttpResponseHeaders(headers)); 719 new net::HttpResponseHeaders(headers));
717 720
718 std::string fingerprint; 721 std::string fingerprint;
719 bool fingerprint_exist = 722 bool fingerprint_exist =
720 GetDataReductionProxyActionFingerprintVia(parsed, &fingerprint); 723 GetDataReductionProxyActionFingerprintVia(parsed.get(), &fingerprint);
721 EXPECT_EQ(tests[i].expected_fingerprint_exist, fingerprint_exist) 724 EXPECT_EQ(tests[i].expected_fingerprint_exist, fingerprint_exist)
722 << tests[i].label; 725 << tests[i].label;
723 726
724 if (fingerprint_exist) 727 if (fingerprint_exist)
725 EXPECT_EQ(tests[i].expected_fingerprint, fingerprint) << tests[i].label; 728 EXPECT_EQ(tests[i].expected_fingerprint, fingerprint) << tests[i].label;
726 } 729 }
727 } 730 }
728 731
729 TEST_F(DataReductionProxyHeadersTest, 732 TEST_F(DataReductionProxyHeadersTest,
730 GetDataReductionProxyActionFingerprintOtherHeaders) { 733 GetDataReductionProxyActionFingerprintOtherHeaders) {
(...skipping 22 matching lines...) Expand all
753 "foh1", 756 "foh1",
754 }, 757 },
755 }; 758 };
756 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) { 759 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) {
757 std::string headers(tests[i].headers); 760 std::string headers(tests[i].headers);
758 HeadersToRaw(&headers); 761 HeadersToRaw(&headers);
759 scoped_refptr<net::HttpResponseHeaders> parsed( 762 scoped_refptr<net::HttpResponseHeaders> parsed(
760 new net::HttpResponseHeaders(headers)); 763 new net::HttpResponseHeaders(headers));
761 764
762 std::string fingerprint; 765 std::string fingerprint;
763 bool fingerprint_exist = 766 bool fingerprint_exist = GetDataReductionProxyActionFingerprintOtherHeaders(
764 GetDataReductionProxyActionFingerprintOtherHeaders( 767 parsed.get(), &fingerprint);
765 parsed, &fingerprint);
766 EXPECT_EQ(tests[i].expected_fingerprint_exist, fingerprint_exist) 768 EXPECT_EQ(tests[i].expected_fingerprint_exist, fingerprint_exist)
767 << tests[i].label; 769 << tests[i].label;
768 770
769 if (fingerprint_exist) 771 if (fingerprint_exist)
770 EXPECT_EQ(tests[i].expected_fingerprint, fingerprint) << tests[i].label; 772 EXPECT_EQ(tests[i].expected_fingerprint, fingerprint) << tests[i].label;
771 } 773 }
772 } 774 }
773 775
774 TEST_F(DataReductionProxyHeadersTest, 776 TEST_F(DataReductionProxyHeadersTest,
775 GetDataReductionProxyActionFingerprintContentLength) { 777 GetDataReductionProxyActionFingerprintContentLength) {
(...skipping 23 matching lines...) Expand all
799 }, 801 },
800 }; 802 };
801 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) { 803 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) {
802 std::string headers(tests[i].headers); 804 std::string headers(tests[i].headers);
803 HeadersToRaw(&headers); 805 HeadersToRaw(&headers);
804 scoped_refptr<net::HttpResponseHeaders> parsed( 806 scoped_refptr<net::HttpResponseHeaders> parsed(
805 new net::HttpResponseHeaders(headers)); 807 new net::HttpResponseHeaders(headers));
806 808
807 std::string fingerprint; 809 std::string fingerprint;
808 bool fingerprint_exist = 810 bool fingerprint_exist =
809 GetDataReductionProxyActionFingerprintContentLength( 811 GetDataReductionProxyActionFingerprintContentLength(parsed.get(),
810 parsed, &fingerprint); 812 &fingerprint);
811 EXPECT_EQ(tests[i].expected_fingerprint_exist, fingerprint_exist) 813 EXPECT_EQ(tests[i].expected_fingerprint_exist, fingerprint_exist)
812 << tests[i].label; 814 << tests[i].label;
813 815
814 if (fingerprint_exist) 816 if (fingerprint_exist)
815 EXPECT_EQ(tests[i].expected_fingerprint, fingerprint) << tests[i].label; 817 EXPECT_EQ(tests[i].expected_fingerprint, fingerprint) << tests[i].label;
816 } 818 }
817 } 819 }
818 820
819 TEST_F(DataReductionProxyHeadersTest, 821 TEST_F(DataReductionProxyHeadersTest,
820 GetDataReductionProxyHeaderWithFingerprintRemoved) { 822 GetDataReductionProxyHeaderWithFingerprintRemoved) {
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
863 }, 865 },
864 }; 866 };
865 867
866 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(test); ++i) { 868 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(test); ++i) {
867 std::string headers(test[i].headers); 869 std::string headers(test[i].headers);
868 HeadersToRaw(&headers); 870 HeadersToRaw(&headers);
869 scoped_refptr<net::HttpResponseHeaders> parsed( 871 scoped_refptr<net::HttpResponseHeaders> parsed(
870 new net::HttpResponseHeaders(headers)); 872 new net::HttpResponseHeaders(headers));
871 873
872 std::vector<std::string> output_values; 874 std::vector<std::string> output_values;
873 GetDataReductionProxyHeaderWithFingerprintRemoved(parsed, &output_values); 875 GetDataReductionProxyHeaderWithFingerprintRemoved(parsed.get(),
876 &output_values);
874 877
875 std::string output_values_string; 878 std::string output_values_string;
876 for (size_t j = 0; j < output_values.size(); ++j) 879 for (size_t j = 0; j < output_values.size(); ++j)
877 output_values_string += output_values[j] + ","; 880 output_values_string += output_values[j] + ",";
878 881
879 EXPECT_EQ(test[i].expected_output_values_string, output_values_string) 882 EXPECT_EQ(test[i].expected_output_values_string, output_values_string)
880 << test[i].label; 883 << test[i].label;
881 } 884 }
882 } 885 }
883 886
884 } // namespace data_reduction_proxy 887 } // namespace data_reduction_proxy
OLDNEW
« no previous file with comments | « components/data_reduction_proxy/browser/data_reduction_proxy_tamper_detection_unittest.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698