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

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

Issue 2777823002: Bypass DRP if a redirect cycle is detected (Closed)
Patch Set: ps Created 3 years, 9 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
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/core/common/data_reduction_proxy_heade rs.h" 5 #include "components/data_reduction_proxy/core/common/data_reduction_proxy_heade rs.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <memory> 10 #include <memory>
11 #include <vector> 11 #include <vector>
12 12
13 #include "base/macros.h" 13 #include "base/macros.h"
14 #include "base/metrics/field_trial.h" 14 #include "base/metrics/field_trial.h"
15 #include "components/data_reduction_proxy/core/common/data_reduction_proxy_event _creator.h" 15 #include "components/data_reduction_proxy/core/common/data_reduction_proxy_event _creator.h"
16 #include "components/data_reduction_proxy/core/common/data_reduction_proxy_event _storage_delegate_test_utils.h" 16 #include "components/data_reduction_proxy/core/common/data_reduction_proxy_event _storage_delegate_test_utils.h"
17 #include "components/data_reduction_proxy/core/common/data_reduction_proxy_heade rs_test_utils.h" 17 #include "components/data_reduction_proxy/core/common/data_reduction_proxy_heade rs_test_utils.h"
18 #include "net/http/http_response_headers.h" 18 #include "net/http/http_response_headers.h"
19 #include "net/proxy/proxy_service.h" 19 #include "net/proxy/proxy_service.h"
20 #include "testing/gtest/include/gtest/gtest.h" 20 #include "testing/gtest/include/gtest/gtest.h"
21 #include "url/gurl.h"
21 22
22 namespace data_reduction_proxy { 23 namespace data_reduction_proxy {
23 24
24 class DataReductionProxyHeadersTest : public testing::Test { 25 class DataReductionProxyHeadersTest : public testing::Test {
25 protected: 26 protected:
26 void SetUp() override { 27 void SetUp() override {
27 storage_delegate_.reset(new TestDataReductionProxyEventStorageDelegate()); 28 storage_delegate_.reset(new TestDataReductionProxyEventStorageDelegate());
28 event_creator_.reset( 29 event_creator_.reset(
29 new DataReductionProxyEventCreator(storage_delegate_.get())); 30 new DataReductionProxyEventCreator(storage_delegate_.get()));
30 } 31 }
(...skipping 730 matching lines...) Expand 10 before | Expand all | Expand 10 after
761 scoped_refptr<net::HttpResponseHeaders> parsed( 762 scoped_refptr<net::HttpResponseHeaders> parsed(
762 new net::HttpResponseHeaders(headers)); 763 new net::HttpResponseHeaders(headers));
763 DataReductionProxyInfo chrome_proxy_info; 764 DataReductionProxyInfo chrome_proxy_info;
764 765
765 base::FieldTrialList trial_list(nullptr); 766 base::FieldTrialList trial_list(nullptr);
766 base::FieldTrialList::CreateFieldTrial( 767 base::FieldTrialList::CreateFieldTrial(
767 "DataReductionProxyServerExperiments", 768 "DataReductionProxyServerExperiments",
768 tests[i].in_tamper_detection_experiment ? "TamperDetection_Enabled" 769 tests[i].in_tamper_detection_experiment ? "TamperDetection_Enabled"
769 : "TamperDetection_Disabled"); 770 : "TamperDetection_Disabled");
770 771
771 EXPECT_EQ(tests[i].expected_result, GetDataReductionProxyBypassType( 772 EXPECT_EQ(tests[i].expected_result,
772 parsed.get(), &chrome_proxy_info)); 773 GetDataReductionProxyBypassType(std::vector<GURL>(), *parsed,
774 &chrome_proxy_info));
773 } 775 }
774 } 776 }
775 777
778 TEST_F(DataReductionProxyHeadersTest,
779 GetDataReductionProxyBypassEventTypeURLRedirectCycle) {
780 const struct {
781 const char* headers;
782 std::vector<GURL> url_chain;
783 DataReductionProxyBypassType expected_result;
784 } tests[] = {
785 {
786 "HTTP/1.1 200 OK\n"
787 "Via: 1.1 Chrome-Compression-Proxy\n",
788 std::vector<GURL>{GURL("http://google.com/1"),
789 GURL("http://google.com/2"),
790 GURL("http://google.com/1")},
791 BYPASS_EVENT_TYPE_URL_REDIRECT_CYCLE,
792 },
793 {
794 "HTTP/1.1 200 OK\n"
795 "Via: 1.1 Chrome-Compression-Proxy\n",
796 std::vector<GURL>{
797 GURL("http://google.com/1"), GURL("http://google.com/2"),
798 GURL("http://google.com/1"), GURL("http://google.com/2")},
799 BYPASS_EVENT_TYPE_URL_REDIRECT_CYCLE,
800 },
801 {
802 "HTTP/1.1 200 OK\n"
803 "Via: 1.1 Chrome-Compression-Proxy\n",
804 std::vector<GURL>{GURL("http://google.com/1")}, BYPASS_EVENT_TYPE_MAX,
805 },
806 {
807 "HTTP/1.1 200 OK\n"
808 "Via: 1.1 Chrome-Compression-Proxy\n",
809 std::vector<GURL>{GURL("http://google.com/1"),
810 GURL("http://google.com/2")},
811 BYPASS_EVENT_TYPE_MAX,
812 },
813 {
814 "HTTP/1.1 200 OK\n"
815 "Via: 1.1 Chrome-Compression-Proxy\n",
816 std::vector<GURL>{GURL("http://google.com/1"),
817 GURL("http://google.com/2"),
818 GURL("http://google.com/3")},
819 BYPASS_EVENT_TYPE_MAX,
820 },
821 {
822 "HTTP/1.1 200 OK\n"
823 "Via: 1.1 Chrome-Compression-Proxy\n",
824 std::vector<GURL>{
825 GURL("http://google.com/1"), GURL("http://google.com/2"),
826 GURL("http://google.com/3"), GURL("http://google.com/1")},
827 BYPASS_EVENT_TYPE_URL_REDIRECT_CYCLE,
828 },
829 {
830 "HTTP/1.1 200 OK\n"
831 "Via: 1.1 Chrome-Compression-Proxy\n",
832 std::vector<GURL>(), BYPASS_EVENT_TYPE_MAX,
833 }};
834
835 for (const auto& test : tests) {
836 std::string headers(test.headers);
837 HeadersToRaw(&headers);
838 scoped_refptr<net::HttpResponseHeaders> parsed(
839 new net::HttpResponseHeaders(headers));
840 DataReductionProxyInfo chrome_proxy_info;
841
842 EXPECT_EQ(test.expected_result,
843 GetDataReductionProxyBypassType(test.url_chain, *parsed,
844 &chrome_proxy_info));
845 }
846 }
847
776 TEST_F(DataReductionProxyHeadersTest, 848 TEST_F(DataReductionProxyHeadersTest,
777 GetDataReductionProxyActionFingerprintChromeProxy) { 849 GetDataReductionProxyActionFingerprintChromeProxy) {
778 const struct { 850 const struct {
779 std::string label; 851 std::string label;
780 const char* headers; 852 const char* headers;
781 bool expected_fingerprint_exist; 853 bool expected_fingerprint_exist;
782 std::string expected_fingerprint; 854 std::string expected_fingerprint;
783 } tests[] = { 855 } tests[] = {
784 { "fingerprint doesn't exist", 856 { "fingerprint doesn't exist",
785 "HTTP/1.1 200 OK\n" 857 "HTTP/1.1 200 OK\n"
(...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after
1010 std::string output_values_string; 1082 std::string output_values_string;
1011 for (size_t j = 0; j < output_values.size(); ++j) 1083 for (size_t j = 0; j < output_values.size(); ++j)
1012 output_values_string += output_values[j] + ","; 1084 output_values_string += output_values[j] + ",";
1013 1085
1014 EXPECT_EQ(test[i].expected_output_values_string, output_values_string) 1086 EXPECT_EQ(test[i].expected_output_values_string, output_values_string)
1015 << test[i].label; 1087 << test[i].label;
1016 } 1088 }
1017 } 1089 }
1018 1090
1019 } // namespace data_reduction_proxy 1091 } // namespace data_reduction_proxy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698