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

Side by Side Diff: components/data_reduction_proxy/core/browser/data_reduction_proxy_network_delegate_unittest.cc

Issue 2771413004: DRP: Add check that ECT header is present when CPAT header is present. (Closed)
Patch Set: megjablon comments Created 3 years, 8 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/core/browser/data_reduction_proxy_network_delegate.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/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
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 // Call network delegate methods to ensure that appropriate chrome proxy
637 // headers get added/removed.
638 network_delegate()->NotifyBeforeStartTransaction(
639 fake_request.get(),
640 base::Bind(&DataReductionProxyNetworkDelegateTest::DelegateStageDone,
641 base::Unretained(this)),
642 &headers);
636 network_delegate()->NotifyBeforeSendHeaders(fake_request.get(), 643 network_delegate()->NotifyBeforeSendHeaders(fake_request.get(),
637 data_reduction_proxy_info, 644 data_reduction_proxy_info,
638 proxy_retry_info, &headers); 645 proxy_retry_info, &headers);
639 646
640 EXPECT_TRUE(headers.HasHeader(chrome_proxy_header())); 647 EXPECT_TRUE(headers.HasHeader(chrome_proxy_header()));
641 std::string header_value; 648 std::string header_value;
642 headers.GetHeader(chrome_proxy_header(), &header_value); 649 headers.GetHeader(chrome_proxy_header(), &header_value);
643 EXPECT_TRUE(header_value.find("ps=") != std::string::npos); 650 EXPECT_TRUE(header_value.find("ps=") != std::string::npos);
644 EXPECT_TRUE(header_value.find("sid=") != std::string::npos); 651 EXPECT_TRUE(header_value.find("sid=") != std::string::npos);
645 } 652 }
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after
836 843
837 test_network_quality_estimator()->set_effective_connection_type( 844 test_network_quality_estimator()->set_effective_connection_type(
838 net::EFFECTIVE_CONNECTION_TYPE_OFFLINE); 845 net::EFFECTIVE_CONNECTION_TYPE_OFFLINE);
839 846
840 std::unique_ptr<net::URLRequest> request = context()->CreateRequest( 847 std::unique_ptr<net::URLRequest> request = context()->CreateRequest(
841 GURL(kTestURL), net::RequestPriority::IDLE, nullptr); 848 GURL(kTestURL), net::RequestPriority::IDLE, nullptr);
842 request->SetLoadFlags(test.main_frame ? net::LOAD_MAIN_FRAME_DEPRECATED 849 request->SetLoadFlags(test.main_frame ? net::LOAD_MAIN_FRAME_DEPRECATED
843 : 0); 850 : 0);
844 lofi_decider()->SetIsUsingLoFi(test.lofi_on); 851 lofi_decider()->SetIsUsingLoFi(test.lofi_on);
845 io_data()->request_options()->SetSecureSession("fake-session"); 852 io_data()->request_options()->SetSecureSession("fake-session");
853
854 // Call network delegate methods to ensure that appropriate chrome proxy
855 // headers get added/removed.
856 network_delegate()->NotifyBeforeStartTransaction(
857 request.get(),
858 base::Bind(&DataReductionProxyNetworkDelegateTest::DelegateStageDone,
859 base::Unretained(this)),
860 &headers);
846 network_delegate()->NotifyBeforeSendHeaders( 861 network_delegate()->NotifyBeforeSendHeaders(
847 request.get(), data_reduction_proxy_info, proxy_retry_info, &headers); 862 request.get(), data_reduction_proxy_info, proxy_retry_info, &headers);
848 DataReductionProxyData* data = 863 DataReductionProxyData* data =
849 DataReductionProxyData::GetData(*request.get()); 864 DataReductionProxyData::GetData(*request.get());
850 if (!test.used_data_reduction_proxy) { 865 if (!test.used_data_reduction_proxy) {
851 EXPECT_FALSE(data); 866 EXPECT_FALSE(data);
852 } else { 867 } else {
853 EXPECT_TRUE(data); 868 EXPECT_TRUE(data);
854 EXPECT_EQ(test.main_frame ? net::EFFECTIVE_CONNECTION_TYPE_OFFLINE 869 EXPECT_EQ(test.main_frame ? net::EFFECTIVE_CONNECTION_TYPE_OFFLINE
855 : net::EFFECTIVE_CONNECTION_TYPE_UNKNOWN, 870 : net::EFFECTIVE_CONNECTION_TYPE_UNKNOWN,
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
911 } 926 }
912 927
913 TEST_F(DataReductionProxyNetworkDelegateTest, RedirectRequestDataCleared) { 928 TEST_F(DataReductionProxyNetworkDelegateTest, RedirectRequestDataCleared) {
914 Init(false, false); 929 Init(false, false);
915 net::ProxyInfo data_reduction_proxy_info; 930 net::ProxyInfo data_reduction_proxy_info;
916 std::string data_reduction_proxy; 931 std::string data_reduction_proxy;
917 base::TrimString(params()->DefaultOrigin(), "/", &data_reduction_proxy); 932 base::TrimString(params()->DefaultOrigin(), "/", &data_reduction_proxy);
918 data_reduction_proxy_info.UseNamedProxy(data_reduction_proxy); 933 data_reduction_proxy_info.UseNamedProxy(data_reduction_proxy);
919 934
920 // Main frame loaded. Lo-Fi should be used. 935 // Main frame loaded. Lo-Fi should be used.
921 net::HttpRequestHeaders headers; 936 net::HttpRequestHeaders headers_original;
922 net::ProxyRetryInfoMap proxy_retry_info; 937 net::ProxyRetryInfoMap proxy_retry_info;
923 938
924 test_network_quality_estimator()->set_effective_connection_type( 939 test_network_quality_estimator()->set_effective_connection_type(
925 net::EFFECTIVE_CONNECTION_TYPE_OFFLINE); 940 net::EFFECTIVE_CONNECTION_TYPE_OFFLINE);
926 941
927 std::unique_ptr<net::URLRequest> request = context()->CreateRequest( 942 std::unique_ptr<net::URLRequest> request = context()->CreateRequest(
928 GURL(kTestURL), net::RequestPriority::IDLE, nullptr); 943 GURL(kTestURL), net::RequestPriority::IDLE, nullptr);
929 request->SetLoadFlags(net::LOAD_MAIN_FRAME_DEPRECATED); 944 request->SetLoadFlags(net::LOAD_MAIN_FRAME_DEPRECATED);
930 lofi_decider()->SetIsUsingLoFi(true); 945 lofi_decider()->SetIsUsingLoFi(true);
931 io_data()->request_options()->SetSecureSession("fake-session"); 946 io_data()->request_options()->SetSecureSession("fake-session");
947
948 // Call network delegate methods to ensure that appropriate chrome proxy
949 // headers get added/removed.
950 network_delegate()->NotifyBeforeStartTransaction(
951 request.get(),
952 base::Bind(&DataReductionProxyNetworkDelegateTest::DelegateStageDone,
953 base::Unretained(this)),
954 &headers_original);
932 network_delegate()->NotifyBeforeSendHeaders( 955 network_delegate()->NotifyBeforeSendHeaders(
933 request.get(), data_reduction_proxy_info, proxy_retry_info, &headers); 956 request.get(), data_reduction_proxy_info, proxy_retry_info,
957 &headers_original);
934 DataReductionProxyData* data = 958 DataReductionProxyData* data =
935 DataReductionProxyData::GetData(*request.get()); 959 DataReductionProxyData::GetData(*request.get());
936 960
937 EXPECT_TRUE(data); 961 EXPECT_TRUE(data);
938 EXPECT_EQ(net::EFFECTIVE_CONNECTION_TYPE_OFFLINE, 962 EXPECT_EQ(net::EFFECTIVE_CONNECTION_TYPE_OFFLINE,
939 data->effective_connection_type()); 963 data->effective_connection_type());
940 EXPECT_TRUE(data->used_data_reduction_proxy()); 964 EXPECT_TRUE(data->used_data_reduction_proxy());
941 EXPECT_EQ(GURL(kTestURL), data->request_url()); 965 EXPECT_EQ(GURL(kTestURL), data->request_url());
942 EXPECT_EQ("fake-session", data->session_key()); 966 EXPECT_EQ("fake-session", data->session_key());
943 EXPECT_TRUE(data->lofi_requested()); 967 EXPECT_TRUE(data->lofi_requested());
944 968
945 data_reduction_proxy_info.UseNamedProxy("port.of.other.proxy"); 969 data_reduction_proxy_info.UseNamedProxy("port.of.other.proxy");
946 970
947 // Simulate a redirect even though the same URL is used. Should clear 971 // Simulate a redirect even though the same URL is used. Should clear
948 // DataReductionProxyData. 972 // DataReductionProxyData.
949 network_delegate()->NotifyBeforeRedirect(request.get(), GURL(kTestURL)); 973 network_delegate()->NotifyBeforeRedirect(request.get(), GURL(kTestURL));
950 data = DataReductionProxyData::GetData(*request.get()); 974 data = DataReductionProxyData::GetData(*request.get());
951 EXPECT_FALSE(data); 975 EXPECT_FALSE(data);
952 976
953 // Call NotifyBeforeSendHeaders again with different proxy info to check that 977 // Call NotifyBeforeSendHeaders again with different proxy info to check that
954 // new data isn't added. 978 // new data isn't added. Use a new set of headers since the redirected HTTP
979 // jobs do not reuse headers from the previous jobs. Also, call network
980 // delegate methods to ensure that appropriate chrome proxy headers get
981 // added/removed.
982 net::HttpRequestHeaders headers_redirect;
983 network_delegate()->NotifyBeforeStartTransaction(
984 request.get(),
985 base::Bind(&DataReductionProxyNetworkDelegateTest::DelegateStageDone,
986 base::Unretained(this)),
987 &headers_redirect);
955 network_delegate()->NotifyBeforeSendHeaders( 988 network_delegate()->NotifyBeforeSendHeaders(
956 request.get(), data_reduction_proxy_info, proxy_retry_info, &headers); 989 request.get(), data_reduction_proxy_info, proxy_retry_info,
990 &headers_redirect);
957 data = DataReductionProxyData::GetData(*request.get()); 991 data = DataReductionProxyData::GetData(*request.get());
958 EXPECT_FALSE(data); 992 EXPECT_FALSE(data);
959 } 993 }
960 994
961 TEST_F(DataReductionProxyNetworkDelegateTest, NetHistograms) { 995 TEST_F(DataReductionProxyNetworkDelegateTest, NetHistograms) {
962 Init(false, false); 996 Init(false, false);
963 const std::string kReceivedValidOCLHistogramName = 997 const std::string kReceivedValidOCLHistogramName =
964 "Net.HttpContentLengthWithValidOCL"; 998 "Net.HttpContentLengthWithValidOCL";
965 const std::string kOriginalValidOCLHistogramName = 999 const std::string kOriginalValidOCLHistogramName =
966 "Net.HttpOriginalContentLengthWithValidOCL"; 1000 "Net.HttpOriginalContentLengthWithValidOCL";
(...skipping 364 matching lines...) Expand 10 before | Expand all | Expand 10 after
1331 FetchURLRequestAndVerifyECTHeader(effective_connection_types[0], true, true); 1365 FetchURLRequestAndVerifyECTHeader(effective_connection_types[0], true, true);
1332 1366
1333 // When the ECT is set to a different value, the response should still be 1367 // When the ECT is set to a different value, the response should still be
1334 // served from the cache. 1368 // served from the cache.
1335 FetchURLRequestAndVerifyECTHeader(effective_connection_types[1], true, true); 1369 FetchURLRequestAndVerifyECTHeader(effective_connection_types[1], true, true);
1336 } 1370 }
1337 1371
1338 } // namespace 1372 } // namespace
1339 1373
1340 } // namespace data_reduction_proxy 1374 } // namespace data_reduction_proxy
OLDNEW
« no previous file with comments | « components/data_reduction_proxy/core/browser/data_reduction_proxy_network_delegate.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698