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

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

Issue 1933653004: Reset the Lo-Fi main frame state when there is a new main frame request (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: check data_reduction_proxy_io_data_ Created 4 years, 7 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/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 <string> 10 #include <string>
11 #include <utility> 11 #include <utility>
12 12
13 #include "base/command_line.h" 13 #include "base/command_line.h"
14 #include "base/macros.h" 14 #include "base/macros.h"
15 #include "base/memory/ptr_util.h" 15 #include "base/memory/ptr_util.h"
16 #include "base/message_loop/message_loop.h" 16 #include "base/message_loop/message_loop.h"
17 #include "base/metrics/field_trial.h" 17 #include "base/metrics/field_trial.h"
18 #include "base/numerics/safe_conversions.h" 18 #include "base/numerics/safe_conversions.h"
19 #include "base/run_loop.h" 19 #include "base/run_loop.h"
20 #include "base/strings/string_number_conversions.h" 20 #include "base/strings/string_number_conversions.h"
21 #include "base/test/histogram_tester.h" 21 #include "base/test/histogram_tester.h"
22 #include "base/test/mock_entropy_provider.h" 22 #include "base/test/mock_entropy_provider.h"
23 #include "base/time/time.h" 23 #include "base/time/time.h"
24 #include "base/values.h" 24 #include "base/values.h"
25 #include "build/build_config.h" 25 #include "build/build_config.h"
26 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_conf ig_test_utils.h" 26 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_conf ig_test_utils.h"
27 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_metr ics.h" 27 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_metr ics.h"
28 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_requ est_options.h" 28 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_requ est_options.h"
29 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_test _utils.h" 29 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_test _utils.h"
30 #include "components/data_reduction_proxy/core/common/data_reduction_proxy_heade rs.h"
30 #include "components/data_reduction_proxy/core/common/data_reduction_proxy_heade rs_test_utils.h" 31 #include "components/data_reduction_proxy/core/common/data_reduction_proxy_heade rs_test_utils.h"
31 #include "components/data_reduction_proxy/core/common/data_reduction_proxy_param s_test_utils.h" 32 #include "components/data_reduction_proxy/core/common/data_reduction_proxy_param s_test_utils.h"
32 #include "components/data_reduction_proxy/core/common/data_reduction_proxy_pref_ names.h" 33 #include "components/data_reduction_proxy/core/common/data_reduction_proxy_pref_ names.h"
33 #include "components/data_reduction_proxy/core/common/data_reduction_proxy_switc hes.h" 34 #include "components/data_reduction_proxy/core/common/data_reduction_proxy_switc hes.h"
34 #include "components/data_reduction_proxy/core/common/lofi_decider.h" 35 #include "components/data_reduction_proxy/core/common/lofi_decider.h"
35 #include "net/base/host_port_pair.h" 36 #include "net/base/host_port_pair.h"
36 #include "net/base/load_flags.h" 37 #include "net/base/load_flags.h"
37 #include "net/base/net_errors.h" 38 #include "net/base/net_errors.h"
38 #include "net/http/http_request_headers.h" 39 #include "net/http/http_request_headers.h"
39 #include "net/http/http_response_headers.h" 40 #include "net/http/http_response_headers.h"
40 #include "net/http/http_util.h" 41 #include "net/http/http_util.h"
41 #include "net/proxy/proxy_config.h" 42 #include "net/proxy/proxy_config.h"
42 #include "net/proxy/proxy_server.h" 43 #include "net/proxy/proxy_server.h"
43 #include "net/socket/socket_test_util.h" 44 #include "net/socket/socket_test_util.h"
44 #include "net/url_request/url_request.h" 45 #include "net/url_request/url_request.h"
45 #include "net/url_request/url_request_test_util.h" 46 #include "net/url_request/url_request_test_util.h"
46 #include "testing/gtest/include/gtest/gtest.h" 47 #include "testing/gtest/include/gtest/gtest.h"
47 48
48 namespace data_reduction_proxy { 49 namespace data_reduction_proxy {
49 namespace { 50 namespace {
50 51
51 using TestNetworkDelegate = net::NetworkDelegateImpl; 52 using TestNetworkDelegate = net::NetworkDelegateImpl;
52 53
53 const char kChromeProxyHeader[] = "chrome-proxy"; 54 const char kOtherProxy[] = "testproxy:17";
54 55
55 #if defined(OS_ANDROID) 56 #if defined(OS_ANDROID)
56 const Client kClient = Client::CHROME_ANDROID; 57 const Client kClient = Client::CHROME_ANDROID;
57 #elif defined(OS_IOS) 58 #elif defined(OS_IOS)
58 const Client kClient = Client::CHROME_IOS; 59 const Client kClient = Client::CHROME_IOS;
59 #elif defined(OS_MACOSX) 60 #elif defined(OS_MACOSX)
60 const Client kClient = Client::CHROME_MAC; 61 const Client kClient = Client::CHROME_MAC;
61 #elif defined(OS_CHROMEOS) 62 #elif defined(OS_CHROMEOS)
62 const Client kClient = Client::CHROME_CHROMEOS; 63 const Client kClient = Client::CHROME_CHROMEOS;
63 #elif defined(OS_LINUX) 64 #elif defined(OS_LINUX)
(...skipping 20 matching lines...) Expand all
84 bool IsUsingLoFiMode(const net::URLRequest& request) const override { 85 bool IsUsingLoFiMode(const net::URLRequest& request) const override {
85 return should_request_lofi_resource_; 86 return should_request_lofi_resource_;
86 } 87 }
87 88
88 void SetIsUsingLoFiMode(bool should_request_lofi_resource) { 89 void SetIsUsingLoFiMode(bool should_request_lofi_resource) {
89 should_request_lofi_resource_ = should_request_lofi_resource; 90 should_request_lofi_resource_ = should_request_lofi_resource;
90 } 91 }
91 92
92 bool MaybeAddLoFiDirectiveToHeaders( 93 bool MaybeAddLoFiDirectiveToHeaders(
93 const net::URLRequest& request, 94 const net::URLRequest& request,
94 net::HttpRequestHeaders* headers, 95 net::HttpRequestHeaders* headers) const override {
95 const net::ProxyServer& proxy_server,
96 DataReductionProxyConfig* config) const override {
97 if (should_request_lofi_resource_) { 96 if (should_request_lofi_resource_) {
98 const char kChromeProxyHeader[] = "Chrome-Proxy";
99 std::string header_value; 97 std::string header_value;
100 98
101 if (headers->HasHeader(kChromeProxyHeader)) { 99 if (headers->HasHeader(chrome_proxy_header())) {
102 headers->GetHeader(kChromeProxyHeader, &header_value); 100 headers->GetHeader(chrome_proxy_header(), &header_value);
103 headers->RemoveHeader(kChromeProxyHeader); 101 headers->RemoveHeader(chrome_proxy_header());
104 header_value += ", "; 102 header_value += ", ";
105 } 103 }
106 104
107 header_value += "q=low"; 105 header_value += "q=low";
108 headers->SetHeader(kChromeProxyHeader, header_value); 106 headers->SetHeader(chrome_proxy_header(), header_value);
109 return true; 107 return true;
110 } 108 }
111 109
112 return false; 110 return false;
113 } 111 }
114 112
115 private: 113 private:
116 bool should_request_lofi_resource_; 114 bool should_request_lofi_resource_;
117 }; 115 };
118 116
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
154 152
155 std::unique_ptr<TestLoFiUIService> lofi_ui_service(new TestLoFiUIService()); 153 std::unique_ptr<TestLoFiUIService> lofi_ui_service(new TestLoFiUIService());
156 lofi_ui_service_ = lofi_ui_service.get(); 154 lofi_ui_service_ = lofi_ui_service.get();
157 test_context_->io_data()->set_lofi_ui_service(std::move(lofi_ui_service)); 155 test_context_->io_data()->set_lofi_ui_service(std::move(lofi_ui_service));
158 156
159 context_.Init(); 157 context_.Init();
160 158
161 test_context_->EnableDataReductionProxyWithSecureProxyCheckSuccess(); 159 test_context_->EnableDataReductionProxyWithSecureProxyCheckSuccess();
162 } 160 }
163 161
164 static void VerifyLoFiHeader(bool expected_lofi_used, 162 static void VerifyHeaders(bool expected_data_reduction_proxy_used,
165 const net::HttpRequestHeaders& headers) { 163 bool expected_lofi_used,
166 EXPECT_TRUE(headers.HasHeader(kChromeProxyHeader)); 164 const net::HttpRequestHeaders& headers) {
165 EXPECT_EQ(expected_data_reduction_proxy_used,
166 headers.HasHeader(chrome_proxy_header()));
167 std::string header_value; 167 std::string header_value;
168 headers.GetHeader(kChromeProxyHeader, &header_value); 168 headers.GetHeader(chrome_proxy_header(), &header_value);
169 EXPECT_EQ(expected_lofi_used, 169 EXPECT_EQ(expected_data_reduction_proxy_used && expected_lofi_used,
170 header_value.find("q=low") != std::string::npos); 170 header_value.find("q=low") != std::string::npos);
171 } 171 }
172 172
173 void VerifyWasLoFiModeActiveOnMainFrame(bool expected_value) { 173 void VerifyWasLoFiModeActiveOnMainFrame(bool expected_value) {
174 test_context_->RunUntilIdle(); 174 test_context_->RunUntilIdle();
175 EXPECT_EQ(expected_value, 175 EXPECT_EQ(expected_value,
176 test_context_->settings()->WasLoFiModeActiveOnMainFrame()); 176 test_context_->settings()->WasLoFiModeActiveOnMainFrame());
177 } 177 }
178 178
179 void VerifyDidNotifyLoFiResponse(bool lofi_response) const { 179 void VerifyDidNotifyLoFiResponse(bool lofi_response) const {
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
231 } 231 }
232 232
233 TestDataReductionProxyParams* params() const { 233 TestDataReductionProxyParams* params() const {
234 return test_context_->config()->test_params(); 234 return test_context_->config()->test_params();
235 } 235 }
236 236
237 TestDataReductionProxyConfig* config() const { 237 TestDataReductionProxyConfig* config() const {
238 return test_context_->config(); 238 return test_context_->config();
239 } 239 }
240 240
241 TestDataReductionProxyIOData* io_data() const {
242 return test_context_->io_data();
243 }
244
241 TestLoFiDecider* lofi_decider() const { return lofi_decider_; } 245 TestLoFiDecider* lofi_decider() const { return lofi_decider_; }
242 246
243 private: 247 private:
244 int64_t GetSessionNetworkStatsInfoInt64(const char* key) const { 248 int64_t GetSessionNetworkStatsInfoInt64(const char* key) const {
245 const DataReductionProxyNetworkDelegate* drp_network_delegate = 249 const DataReductionProxyNetworkDelegate* drp_network_delegate =
246 reinterpret_cast<const DataReductionProxyNetworkDelegate*>( 250 reinterpret_cast<const DataReductionProxyNetworkDelegate*>(
247 context_.network_delegate()); 251 context_.network_delegate());
248 252
249 std::unique_ptr<base::DictionaryValue> session_network_stats_info = 253 std::unique_ptr<base::DictionaryValue> session_network_stats_info =
250 base::DictionaryValue::From(base::WrapUnique( 254 base::DictionaryValue::From(base::WrapUnique(
(...skipping 23 matching lines...) Expand all
274 278
275 net::ProxyInfo data_reduction_proxy_info; 279 net::ProxyInfo data_reduction_proxy_info;
276 std::string data_reduction_proxy; 280 std::string data_reduction_proxy;
277 base::TrimString(params()->DefaultOrigin(), "/", &data_reduction_proxy); 281 base::TrimString(params()->DefaultOrigin(), "/", &data_reduction_proxy);
278 data_reduction_proxy_info.UseNamedProxy(data_reduction_proxy); 282 data_reduction_proxy_info.UseNamedProxy(data_reduction_proxy);
279 283
280 net::HttpRequestHeaders headers; 284 net::HttpRequestHeaders headers;
281 network_delegate()->NotifyBeforeSendProxyHeaders( 285 network_delegate()->NotifyBeforeSendProxyHeaders(
282 fake_request.get(), data_reduction_proxy_info, &headers); 286 fake_request.get(), data_reduction_proxy_info, &headers);
283 287
284 EXPECT_TRUE(headers.HasHeader(kChromeProxyHeader)); 288 EXPECT_TRUE(headers.HasHeader(chrome_proxy_header()));
285 std::string header_value; 289 std::string header_value;
286 headers.GetHeader(kChromeProxyHeader, &header_value); 290 headers.GetHeader(chrome_proxy_header(), &header_value);
287 EXPECT_TRUE(header_value.find("ps=") != std::string::npos); 291 EXPECT_TRUE(header_value.find("ps=") != std::string::npos);
288 EXPECT_TRUE(header_value.find("sid=") != std::string::npos); 292 EXPECT_TRUE(header_value.find("sid=") != std::string::npos);
289 } 293 }
290 294
291 TEST_F(DataReductionProxyNetworkDelegateTest, LoFiTransitions) { 295 TEST_F(DataReductionProxyNetworkDelegateTest, LoFiTransitions) {
292 // Enable Lo-Fi. 296 // Enable Lo-Fi.
293 const struct { 297 const struct {
294 bool lofi_switch_enabled; 298 bool lofi_switch_enabled;
295 bool auto_lofi_enabled; 299 bool auto_lofi_enabled;
300 bool is_data_reduction_proxy;
296 } tests[] = { 301 } tests[] = {
297 { 302 {
298 // Lo-Fi enabled through switch. 303 // Lo-Fi enabled through switch and not using a Data Reduction Proxy.
299 true, false, 304 true, false, false,
300 }, 305 },
301 { 306 {
302 // Lo-Fi enabled through field trial. 307 // Lo-Fi enabled through switch and using a Data Reduction Proxy.
303 false, true, 308 true, false, true,
309 },
310 {
311 // Lo-Fi enabled through field trial and not using a Data Reduction
312 // Proxy.
313 false, true, false,
314 },
315 {
316 // Lo-Fi enabled through field trial and using a Data Reduction Proxy.
317 false, true, true,
304 }, 318 },
305 }; 319 };
306 320
307 for (size_t i = 0; i < arraysize(tests); ++i) { 321 for (size_t i = 0; i < arraysize(tests); ++i) {
308 if (tests[i].lofi_switch_enabled) { 322 if (tests[i].lofi_switch_enabled) {
309 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII( 323 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII(
310 switches::kDataReductionProxyLoFi, 324 switches::kDataReductionProxyLoFi,
311 switches::kDataReductionProxyLoFiValueAlwaysOn); 325 switches::kDataReductionProxyLoFiValueAlwaysOn);
312 } 326 }
313 base::FieldTrialList field_trial_list(nullptr); 327 base::FieldTrialList field_trial_list(nullptr);
314 if (tests[i].auto_lofi_enabled) { 328 if (tests[i].auto_lofi_enabled) {
315 base::FieldTrialList::CreateFieldTrial(params::GetLoFiFieldTrialName(), 329 base::FieldTrialList::CreateFieldTrial(params::GetLoFiFieldTrialName(),
316 "Enabled"); 330 "Enabled");
317 } 331 }
318 config()->SetNetworkProhibitivelySlow(tests[i].auto_lofi_enabled); 332 config()->SetNetworkProhibitivelySlow(tests[i].auto_lofi_enabled);
333 io_data()->SetLoFiModeActiveOnMainFrame(false);
319 334
320 net::ProxyInfo data_reduction_proxy_info; 335 net::ProxyInfo data_reduction_proxy_info;
321 std::string data_reduction_proxy; 336 std::string proxy;
322 base::TrimString(params()->DefaultOrigin(), "/", &data_reduction_proxy); 337 if (tests[i].is_data_reduction_proxy)
323 data_reduction_proxy_info.UseNamedProxy(data_reduction_proxy); 338 base::TrimString(params()->DefaultOrigin(), "/", &proxy);
339 else
340 base::TrimString(kOtherProxy, "/", &proxy);
341 data_reduction_proxy_info.UseNamedProxy(proxy);
324 342
325 { 343 {
326 // Main frame loaded. Lo-Fi should be used. 344 // Main frame loaded. Lo-Fi should be used.
327 net::HttpRequestHeaders headers; 345 net::HttpRequestHeaders headers;
328 346
329 std::unique_ptr<net::URLRequest> fake_request(FetchURLRequest( 347 std::unique_ptr<net::URLRequest> fake_request(FetchURLRequest(
330 GURL("http://www.google.com/"), nullptr, std::string(), 0)); 348 GURL("http://www.google.com/"), nullptr, std::string(), 0));
331 fake_request->SetLoadFlags(net::LOAD_MAIN_FRAME); 349 fake_request->SetLoadFlags(net::LOAD_MAIN_FRAME);
332 lofi_decider()->SetIsUsingLoFiMode( 350 lofi_decider()->SetIsUsingLoFiMode(
333 config()->ShouldEnableLoFiMode(*fake_request.get())); 351 config()->ShouldEnableLoFiMode(*fake_request.get()));
334 network_delegate()->NotifyBeforeSendProxyHeaders( 352 network_delegate()->NotifyBeforeSendProxyHeaders(
335 fake_request.get(), data_reduction_proxy_info, &headers); 353 fake_request.get(), data_reduction_proxy_info, &headers);
336 VerifyLoFiHeader(true, headers); 354 VerifyHeaders(tests[i].is_data_reduction_proxy, true, headers);
337 VerifyWasLoFiModeActiveOnMainFrame(true); 355 VerifyWasLoFiModeActiveOnMainFrame(tests[i].is_data_reduction_proxy);
338 } 356 }
339 357
340 { 358 {
341 // Lo-Fi is already off. Lo-Fi should not be used. 359 // Lo-Fi is already off. Lo-Fi should not be used.
342 net::HttpRequestHeaders headers; 360 net::HttpRequestHeaders headers;
343 std::unique_ptr<net::URLRequest> fake_request(FetchURLRequest( 361 std::unique_ptr<net::URLRequest> fake_request(FetchURLRequest(
344 GURL("http://www.google.com/"), nullptr, std::string(), 0)); 362 GURL("http://www.google.com/"), nullptr, std::string(), 0));
345 lofi_decider()->SetIsUsingLoFiMode(false); 363 lofi_decider()->SetIsUsingLoFiMode(false);
346 network_delegate()->NotifyBeforeSendProxyHeaders( 364 network_delegate()->NotifyBeforeSendProxyHeaders(
347 fake_request.get(), data_reduction_proxy_info, &headers); 365 fake_request.get(), data_reduction_proxy_info, &headers);
348 VerifyLoFiHeader(false, headers); 366 VerifyHeaders(tests[i].is_data_reduction_proxy, false, headers);
349 // Not a mainframe request, WasLoFiModeActiveOnMainFrame should still be 367 // Not a mainframe request, WasLoFiModeActiveOnMainFrame should still be
350 // true. 368 // true if the proxy is a Data Reduction Proxy.
351 VerifyWasLoFiModeActiveOnMainFrame(true); 369 VerifyWasLoFiModeActiveOnMainFrame(tests[i].is_data_reduction_proxy);
352 } 370 }
353 371
354 { 372 {
355 // Lo-Fi is already on. Lo-Fi should be used. 373 // Lo-Fi is already on. Lo-Fi should be used.
356 net::HttpRequestHeaders headers; 374 net::HttpRequestHeaders headers;
357 std::unique_ptr<net::URLRequest> fake_request(FetchURLRequest( 375 std::unique_ptr<net::URLRequest> fake_request(FetchURLRequest(
358 GURL("http://www.google.com/"), nullptr, std::string(), 0)); 376 GURL("http://www.google.com/"), nullptr, std::string(), 0));
359 377
360 lofi_decider()->SetIsUsingLoFiMode(true); 378 lofi_decider()->SetIsUsingLoFiMode(true);
361 network_delegate()->NotifyBeforeSendProxyHeaders( 379 network_delegate()->NotifyBeforeSendProxyHeaders(
362 fake_request.get(), data_reduction_proxy_info, &headers); 380 fake_request.get(), data_reduction_proxy_info, &headers);
363 VerifyLoFiHeader(true, headers); 381 VerifyHeaders(tests[i].is_data_reduction_proxy, true, headers);
364 // Not a mainframe request, WasLoFiModeActiveOnMainFrame should still be 382 // Not a mainframe request, WasLoFiModeActiveOnMainFrame should still be
365 // true. 383 // true if the proxy is a Data Reduction Proxy.
366 VerifyWasLoFiModeActiveOnMainFrame(true); 384 VerifyWasLoFiModeActiveOnMainFrame(tests[i].is_data_reduction_proxy);
367 } 385 }
368 386
369 { 387 {
370 // TODO(megjablon): Can remove the cases below once
371 // WasLoFiModeActiveOnMainFrame is fixed to be per-page.
372 // Main frame request with Lo-Fi off. Lo-Fi should not be used. 388 // Main frame request with Lo-Fi off. Lo-Fi should not be used.
373 // State of Lo-Fi should persist until next page load. 389 // State of Lo-Fi should persist until next page load.
374 net::HttpRequestHeaders headers; 390 net::HttpRequestHeaders headers;
375 std::unique_ptr<net::URLRequest> fake_request(FetchURLRequest( 391 std::unique_ptr<net::URLRequest> fake_request(FetchURLRequest(
376 GURL("http://www.google.com/"), nullptr, std::string(), 0)); 392 GURL("http://www.google.com/"), nullptr, std::string(), 0));
377 fake_request->SetLoadFlags(net::LOAD_MAIN_FRAME); 393 fake_request->SetLoadFlags(net::LOAD_MAIN_FRAME);
378 lofi_decider()->SetIsUsingLoFiMode(false); 394 lofi_decider()->SetIsUsingLoFiMode(false);
379 network_delegate()->NotifyBeforeSendProxyHeaders( 395 network_delegate()->NotifyBeforeSendProxyHeaders(
380 fake_request.get(), data_reduction_proxy_info, &headers); 396 fake_request.get(), data_reduction_proxy_info, &headers);
381 VerifyLoFiHeader(false, headers); 397 VerifyHeaders(tests[i].is_data_reduction_proxy, false, headers);
382 VerifyWasLoFiModeActiveOnMainFrame(false); 398 VerifyWasLoFiModeActiveOnMainFrame(false);
383 } 399 }
384 400
385 { 401 {
386 // Lo-Fi is off. Lo-Fi is still not used. 402 // Lo-Fi is off. Lo-Fi is still not used.
387 net::HttpRequestHeaders headers; 403 net::HttpRequestHeaders headers;
388 std::unique_ptr<net::URLRequest> fake_request(FetchURLRequest( 404 std::unique_ptr<net::URLRequest> fake_request(FetchURLRequest(
389 GURL("http://www.google.com/"), nullptr, std::string(), 0)); 405 GURL("http://www.google.com/"), nullptr, std::string(), 0));
390 lofi_decider()->SetIsUsingLoFiMode(false); 406 lofi_decider()->SetIsUsingLoFiMode(false);
391 network_delegate()->NotifyBeforeSendProxyHeaders( 407 network_delegate()->NotifyBeforeSendProxyHeaders(
392 fake_request.get(), data_reduction_proxy_info, &headers); 408 fake_request.get(), data_reduction_proxy_info, &headers);
393 VerifyLoFiHeader(false, headers); 409 VerifyHeaders(tests[i].is_data_reduction_proxy, false, headers);
394 // Not a mainframe request, WasLoFiModeActiveOnMainFrame should still be 410 // Not a mainframe request, WasLoFiModeActiveOnMainFrame should still be
395 // false. 411 // false.
396 VerifyWasLoFiModeActiveOnMainFrame(false); 412 VerifyWasLoFiModeActiveOnMainFrame(false);
397 } 413 }
398 414
399 { 415 {
400 // Main frame request. Lo-Fi should be used. 416 // Main frame request. Lo-Fi should be used.
401 net::HttpRequestHeaders headers; 417 net::HttpRequestHeaders headers;
402 std::unique_ptr<net::URLRequest> fake_request(FetchURLRequest( 418 std::unique_ptr<net::URLRequest> fake_request(FetchURLRequest(
403 GURL("http://www.google.com/"), nullptr, std::string(), 0)); 419 GURL("http://www.google.com/"), nullptr, std::string(), 0));
404 fake_request->SetLoadFlags(net::LOAD_MAIN_FRAME); 420 fake_request->SetLoadFlags(net::LOAD_MAIN_FRAME);
405 lofi_decider()->SetIsUsingLoFiMode( 421 lofi_decider()->SetIsUsingLoFiMode(
406 config()->ShouldEnableLoFiMode(*fake_request.get())); 422 config()->ShouldEnableLoFiMode(*fake_request.get()));
407 network_delegate()->NotifyBeforeSendProxyHeaders( 423 network_delegate()->NotifyBeforeSendProxyHeaders(
408 fake_request.get(), data_reduction_proxy_info, &headers); 424 fake_request.get(), data_reduction_proxy_info, &headers);
409 VerifyLoFiHeader(true, headers); 425 VerifyHeaders(tests[i].is_data_reduction_proxy, true, headers);
410 VerifyWasLoFiModeActiveOnMainFrame(true); 426 VerifyWasLoFiModeActiveOnMainFrame(tests[i].is_data_reduction_proxy);
411 } 427 }
412 } 428 }
413 } 429 }
414 430
415 TEST_F(DataReductionProxyNetworkDelegateTest, NetHistograms) { 431 TEST_F(DataReductionProxyNetworkDelegateTest, NetHistograms) {
416 const std::string kReceivedValidOCLHistogramName = 432 const std::string kReceivedValidOCLHistogramName =
417 "Net.HttpContentLengthWithValidOCL"; 433 "Net.HttpContentLengthWithValidOCL";
418 const std::string kOriginalValidOCLHistogramName = 434 const std::string kOriginalValidOCLHistogramName =
419 "Net.HttpOriginalContentLengthWithValidOCL"; 435 "Net.HttpOriginalContentLengthWithValidOCL";
420 const std::string kDifferenceValidOCLHistogramName = 436 const std::string kDifferenceValidOCLHistogramName =
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after
571 "PROXY " + 587 "PROXY " +
572 net::ProxyServer::FromURI(params()->DefaultOrigin(), 588 net::ProxyServer::FromURI(params()->DefaultOrigin(),
573 net::ProxyServer::SCHEME_HTTP) 589 net::ProxyServer::SCHEME_HTTP)
574 .host_port_pair() 590 .host_port_pair()
575 .ToString() + 591 .ToString() +
576 "; DIRECT"); 592 "; DIRECT");
577 EXPECT_FALSE(data_reduction_proxy_info.is_empty()); 593 EXPECT_FALSE(data_reduction_proxy_info.is_empty());
578 594
579 network_delegate()->NotifyBeforeSendProxyHeaders( 595 network_delegate()->NotifyBeforeSendProxyHeaders(
580 nullptr, data_reduction_proxy_info, &headers); 596 nullptr, data_reduction_proxy_info, &headers);
581 EXPECT_TRUE(headers.HasHeader(kChromeProxyHeader)); 597 EXPECT_TRUE(headers.HasHeader(chrome_proxy_header()));
582 } 598 }
583 599
584 TEST_F(DataReductionProxyNetworkDelegateTest, OnCompletedInternalLoFi) { 600 TEST_F(DataReductionProxyNetworkDelegateTest, OnCompletedInternalLoFi) {
585 // Enable Lo-Fi. 601 // Enable Lo-Fi.
586 const struct { 602 const struct {
587 bool lofi_response; 603 bool lofi_response;
588 } tests[] = { 604 } tests[] = {
589 {false}, {true}, 605 {false}, {true},
590 }; 606 };
591 607
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
661 FetchURLRequest(GURL("http://www.google.com/"), nullptr, response_headers, 677 FetchURLRequest(GURL("http://www.google.com/"), nullptr, response_headers,
662 140); 678 140);
663 679
664 histogram_tester.ExpectBucketCount(kLoFiTransformationTypeHistogram, PREVIEW, 680 histogram_tester.ExpectBucketCount(kLoFiTransformationTypeHistogram, PREVIEW,
665 1); 681 1);
666 } 682 }
667 683
668 } // namespace 684 } // namespace
669 685
670 } // namespace data_reduction_proxy 686 } // namespace data_reduction_proxy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698