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 "components/data_reduction_proxy/core/browser/data_reduction_proxy_netw ork_delegate.h" | 5 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_netw ork_delegate.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include <map> | 10 #include <map> |
(...skipping 615 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
626 std::unique_ptr<net::URLRequest> fake_request( | 626 std::unique_ptr<net::URLRequest> fake_request( |
627 FetchURLRequest(GURL(kTestURL), nullptr, std::string(), 0)); | 627 FetchURLRequest(GURL(kTestURL), nullptr, std::string(), 0)); |
628 | 628 |
629 net::ProxyInfo data_reduction_proxy_info; | 629 net::ProxyInfo data_reduction_proxy_info; |
630 net::ProxyRetryInfoMap proxy_retry_info; | 630 net::ProxyRetryInfoMap proxy_retry_info; |
631 std::string data_reduction_proxy; | 631 std::string data_reduction_proxy; |
632 base::TrimString(params()->DefaultOrigin(), "/", &data_reduction_proxy); | 632 base::TrimString(params()->DefaultOrigin(), "/", &data_reduction_proxy); |
633 data_reduction_proxy_info.UseNamedProxy(data_reduction_proxy); | 633 data_reduction_proxy_info.UseNamedProxy(data_reduction_proxy); |
634 | 634 |
635 net::HttpRequestHeaders headers; | 635 net::HttpRequestHeaders headers; |
636 network_delegate()->NotifyBeforeStartTransaction( | |
megjablon
2017/03/29 22:20:01
Why are these NotifyBeforeStartTransaction calls n
tbansal1
2017/03/29 22:37:54
Done. ECT/CPAT headers are added in NotifyBeforeSt
| |
637 fake_request.get(), | |
638 base::Bind(&DataReductionProxyNetworkDelegateTest::DelegateStageDone, | |
639 base::Unretained(this)), | |
640 &headers); | |
636 network_delegate()->NotifyBeforeSendHeaders(fake_request.get(), | 641 network_delegate()->NotifyBeforeSendHeaders(fake_request.get(), |
637 data_reduction_proxy_info, | 642 data_reduction_proxy_info, |
638 proxy_retry_info, &headers); | 643 proxy_retry_info, &headers); |
639 | 644 |
640 EXPECT_TRUE(headers.HasHeader(chrome_proxy_header())); | 645 EXPECT_TRUE(headers.HasHeader(chrome_proxy_header())); |
641 std::string header_value; | 646 std::string header_value; |
642 headers.GetHeader(chrome_proxy_header(), &header_value); | 647 headers.GetHeader(chrome_proxy_header(), &header_value); |
643 EXPECT_TRUE(header_value.find("ps=") != std::string::npos); | 648 EXPECT_TRUE(header_value.find("ps=") != std::string::npos); |
644 EXPECT_TRUE(header_value.find("sid=") != std::string::npos); | 649 EXPECT_TRUE(header_value.find("sid=") != std::string::npos); |
645 } | 650 } |
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
836 | 841 |
837 test_network_quality_estimator()->set_effective_connection_type( | 842 test_network_quality_estimator()->set_effective_connection_type( |
838 net::EFFECTIVE_CONNECTION_TYPE_OFFLINE); | 843 net::EFFECTIVE_CONNECTION_TYPE_OFFLINE); |
839 | 844 |
840 std::unique_ptr<net::URLRequest> request = context()->CreateRequest( | 845 std::unique_ptr<net::URLRequest> request = context()->CreateRequest( |
841 GURL(kTestURL), net::RequestPriority::IDLE, nullptr); | 846 GURL(kTestURL), net::RequestPriority::IDLE, nullptr); |
842 request->SetLoadFlags(test.main_frame ? net::LOAD_MAIN_FRAME_DEPRECATED | 847 request->SetLoadFlags(test.main_frame ? net::LOAD_MAIN_FRAME_DEPRECATED |
843 : 0); | 848 : 0); |
844 lofi_decider()->SetIsUsingLoFi(test.lofi_on); | 849 lofi_decider()->SetIsUsingLoFi(test.lofi_on); |
845 io_data()->request_options()->SetSecureSession("fake-session"); | 850 io_data()->request_options()->SetSecureSession("fake-session"); |
851 network_delegate()->NotifyBeforeStartTransaction( | |
852 request.get(), | |
853 base::Bind(&DataReductionProxyNetworkDelegateTest::DelegateStageDone, | |
854 base::Unretained(this)), | |
855 &headers); | |
846 network_delegate()->NotifyBeforeSendHeaders( | 856 network_delegate()->NotifyBeforeSendHeaders( |
847 request.get(), data_reduction_proxy_info, proxy_retry_info, &headers); | 857 request.get(), data_reduction_proxy_info, proxy_retry_info, &headers); |
848 DataReductionProxyData* data = | 858 DataReductionProxyData* data = |
849 DataReductionProxyData::GetData(*request.get()); | 859 DataReductionProxyData::GetData(*request.get()); |
850 if (!test.used_data_reduction_proxy) { | 860 if (!test.used_data_reduction_proxy) { |
851 EXPECT_FALSE(data); | 861 EXPECT_FALSE(data); |
852 } else { | 862 } else { |
853 EXPECT_TRUE(data); | 863 EXPECT_TRUE(data); |
854 EXPECT_EQ(test.main_frame ? net::EFFECTIVE_CONNECTION_TYPE_OFFLINE | 864 EXPECT_EQ(test.main_frame ? net::EFFECTIVE_CONNECTION_TYPE_OFFLINE |
855 : net::EFFECTIVE_CONNECTION_TYPE_UNKNOWN, | 865 : net::EFFECTIVE_CONNECTION_TYPE_UNKNOWN, |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
911 } | 921 } |
912 | 922 |
913 TEST_F(DataReductionProxyNetworkDelegateTest, RedirectRequestDataCleared) { | 923 TEST_F(DataReductionProxyNetworkDelegateTest, RedirectRequestDataCleared) { |
914 Init(false, false); | 924 Init(false, false); |
915 net::ProxyInfo data_reduction_proxy_info; | 925 net::ProxyInfo data_reduction_proxy_info; |
916 std::string data_reduction_proxy; | 926 std::string data_reduction_proxy; |
917 base::TrimString(params()->DefaultOrigin(), "/", &data_reduction_proxy); | 927 base::TrimString(params()->DefaultOrigin(), "/", &data_reduction_proxy); |
918 data_reduction_proxy_info.UseNamedProxy(data_reduction_proxy); | 928 data_reduction_proxy_info.UseNamedProxy(data_reduction_proxy); |
919 | 929 |
920 // Main frame loaded. Lo-Fi should be used. | 930 // Main frame loaded. Lo-Fi should be used. |
921 net::HttpRequestHeaders headers; | 931 net::HttpRequestHeaders headers_original; |
922 net::ProxyRetryInfoMap proxy_retry_info; | 932 net::ProxyRetryInfoMap proxy_retry_info; |
923 | 933 |
924 test_network_quality_estimator()->set_effective_connection_type( | 934 test_network_quality_estimator()->set_effective_connection_type( |
925 net::EFFECTIVE_CONNECTION_TYPE_OFFLINE); | 935 net::EFFECTIVE_CONNECTION_TYPE_OFFLINE); |
926 | 936 |
927 std::unique_ptr<net::URLRequest> request = context()->CreateRequest( | 937 std::unique_ptr<net::URLRequest> request = context()->CreateRequest( |
928 GURL(kTestURL), net::RequestPriority::IDLE, nullptr); | 938 GURL(kTestURL), net::RequestPriority::IDLE, nullptr); |
929 request->SetLoadFlags(net::LOAD_MAIN_FRAME_DEPRECATED); | 939 request->SetLoadFlags(net::LOAD_MAIN_FRAME_DEPRECATED); |
930 lofi_decider()->SetIsUsingLoFi(true); | 940 lofi_decider()->SetIsUsingLoFi(true); |
931 io_data()->request_options()->SetSecureSession("fake-session"); | 941 io_data()->request_options()->SetSecureSession("fake-session"); |
942 network_delegate()->NotifyBeforeStartTransaction( | |
943 request.get(), | |
944 base::Bind(&DataReductionProxyNetworkDelegateTest::DelegateStageDone, | |
945 base::Unretained(this)), | |
946 &headers_original); | |
932 network_delegate()->NotifyBeforeSendHeaders( | 947 network_delegate()->NotifyBeforeSendHeaders( |
933 request.get(), data_reduction_proxy_info, proxy_retry_info, &headers); | 948 request.get(), data_reduction_proxy_info, proxy_retry_info, |
949 &headers_original); | |
934 DataReductionProxyData* data = | 950 DataReductionProxyData* data = |
935 DataReductionProxyData::GetData(*request.get()); | 951 DataReductionProxyData::GetData(*request.get()); |
936 | 952 |
937 EXPECT_TRUE(data); | 953 EXPECT_TRUE(data); |
938 EXPECT_EQ(net::EFFECTIVE_CONNECTION_TYPE_OFFLINE, | 954 EXPECT_EQ(net::EFFECTIVE_CONNECTION_TYPE_OFFLINE, |
939 data->effective_connection_type()); | 955 data->effective_connection_type()); |
940 EXPECT_TRUE(data->used_data_reduction_proxy()); | 956 EXPECT_TRUE(data->used_data_reduction_proxy()); |
941 EXPECT_EQ(GURL(kTestURL), data->request_url()); | 957 EXPECT_EQ(GURL(kTestURL), data->request_url()); |
942 EXPECT_EQ("fake-session", data->session_key()); | 958 EXPECT_EQ("fake-session", data->session_key()); |
943 EXPECT_TRUE(data->lofi_requested()); | 959 EXPECT_TRUE(data->lofi_requested()); |
944 | 960 |
945 data_reduction_proxy_info.UseNamedProxy("port.of.other.proxy"); | 961 data_reduction_proxy_info.UseNamedProxy("port.of.other.proxy"); |
946 | 962 |
947 // Simulate a redirect even though the same URL is used. Should clear | 963 // Simulate a redirect even though the same URL is used. Should clear |
948 // DataReductionProxyData. | 964 // DataReductionProxyData. |
949 network_delegate()->NotifyBeforeRedirect(request.get(), GURL(kTestURL)); | 965 network_delegate()->NotifyBeforeRedirect(request.get(), GURL(kTestURL)); |
950 data = DataReductionProxyData::GetData(*request.get()); | 966 data = DataReductionProxyData::GetData(*request.get()); |
951 EXPECT_FALSE(data); | 967 EXPECT_FALSE(data); |
952 | 968 |
953 // Call NotifyBeforeSendHeaders again with different proxy info to check that | 969 // Call NotifyBeforeSendHeaders again with different proxy info to check that |
954 // new data isn't added. | 970 // new data isn't added. |
971 net::HttpRequestHeaders headers_redirect; | |
972 network_delegate()->NotifyBeforeStartTransaction( | |
973 request.get(), | |
974 base::Bind(&DataReductionProxyNetworkDelegateTest::DelegateStageDone, | |
975 base::Unretained(this)), | |
976 &headers_redirect); | |
955 network_delegate()->NotifyBeforeSendHeaders( | 977 network_delegate()->NotifyBeforeSendHeaders( |
956 request.get(), data_reduction_proxy_info, proxy_retry_info, &headers); | 978 request.get(), data_reduction_proxy_info, proxy_retry_info, |
979 &headers_redirect); | |
957 data = DataReductionProxyData::GetData(*request.get()); | 980 data = DataReductionProxyData::GetData(*request.get()); |
958 EXPECT_FALSE(data); | 981 EXPECT_FALSE(data); |
959 } | 982 } |
960 | 983 |
961 TEST_F(DataReductionProxyNetworkDelegateTest, NetHistograms) { | 984 TEST_F(DataReductionProxyNetworkDelegateTest, NetHistograms) { |
962 Init(false, false); | 985 Init(false, false); |
963 const std::string kReceivedValidOCLHistogramName = | 986 const std::string kReceivedValidOCLHistogramName = |
964 "Net.HttpContentLengthWithValidOCL"; | 987 "Net.HttpContentLengthWithValidOCL"; |
965 const std::string kOriginalValidOCLHistogramName = | 988 const std::string kOriginalValidOCLHistogramName = |
966 "Net.HttpOriginalContentLengthWithValidOCL"; | 989 "Net.HttpOriginalContentLengthWithValidOCL"; |
(...skipping 364 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1331 FetchURLRequestAndVerifyECTHeader(effective_connection_types[0], true, true); | 1354 FetchURLRequestAndVerifyECTHeader(effective_connection_types[0], true, true); |
1332 | 1355 |
1333 // When the ECT is set to a different value, the response should still be | 1356 // When the ECT is set to a different value, the response should still be |
1334 // served from the cache. | 1357 // served from the cache. |
1335 FetchURLRequestAndVerifyECTHeader(effective_connection_types[1], true, true); | 1358 FetchURLRequestAndVerifyECTHeader(effective_connection_types[1], true, true); |
1336 } | 1359 } |
1337 | 1360 |
1338 } // namespace | 1361 } // namespace |
1339 | 1362 |
1340 } // namespace data_reduction_proxy | 1363 } // namespace data_reduction_proxy |
OLD | NEW |