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

Side by Side Diff: components/data_reduction_proxy/content/browser/content_lofi_decider_unittest.cc

Issue 2424263002: Added support for heavy page previews transformations (Closed)
Patch Set: Addressed comments Created 4 years, 2 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 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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/content/browser/content_lofi_decider.h " 5 #include "components/data_reduction_proxy/content/browser/content_lofi_decider.h "
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <memory> 8 #include <memory>
9 #include <string> 9 #include <string>
10 #include <utility> 10 #include <utility>
11 11
12 #include "base/command_line.h" 12 #include "base/command_line.h"
13 #include "base/macros.h" 13 #include "base/macros.h"
14 #include "base/message_loop/message_loop.h" 14 #include "base/message_loop/message_loop.h"
15 #include "base/metrics/field_trial.h" 15 #include "base/metrics/field_trial.h"
16 #include "base/strings/string_util.h" 16 #include "base/strings/string_util.h"
17 #include "base/strings/stringprintf.h"
17 #include "build/build_config.h" 18 #include "build/build_config.h"
18 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_conf ig_test_utils.h" 19 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_conf ig_test_utils.h"
19 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_data .h" 20 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_data .h"
20 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_netw ork_delegate.h" 21 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_netw ork_delegate.h"
21 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_test _utils.h" 22 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_test _utils.h"
22 #include "components/data_reduction_proxy/core/common/data_reduction_proxy_heade rs.h" 23 #include "components/data_reduction_proxy/core/common/data_reduction_proxy_heade rs.h"
23 #include "components/data_reduction_proxy/core/common/data_reduction_proxy_param s.h" 24 #include "components/data_reduction_proxy/core/common/data_reduction_proxy_param s.h"
24 #include "components/data_reduction_proxy/core/common/data_reduction_proxy_param s_test_utils.h" 25 #include "components/data_reduction_proxy/core/common/data_reduction_proxy_param s_test_utils.h"
25 #include "components/data_reduction_proxy/core/common/data_reduction_proxy_switc hes.h" 26 #include "components/data_reduction_proxy/core/common/data_reduction_proxy_switc hes.h"
26 #include "content/public/browser/resource_request_info.h" 27 #include "content/public/browser/resource_request_info.h"
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
160 const net::HttpRequestHeaders& headers) { 161 const net::HttpRequestHeaders& headers) {
161 if (expected_lite_page_used) 162 if (expected_lite_page_used)
162 EXPECT_TRUE(headers.HasHeader(chrome_proxy_accept_transform_header())); 163 EXPECT_TRUE(headers.HasHeader(chrome_proxy_accept_transform_header()));
163 std::string header_value; 164 std::string header_value;
164 headers.GetHeader(chrome_proxy_accept_transform_header(), &header_value); 165 headers.GetHeader(chrome_proxy_accept_transform_header(), &header_value);
165 EXPECT_EQ(expected_lite_page_used, 166 EXPECT_EQ(expected_lite_page_used,
166 header_value.find(lite_page_directive()) != std::string::npos); 167 header_value.find(lite_page_directive()) != std::string::npos);
167 } 168 }
168 169
169 static void VerifyLoFiHeader(bool expected_lofi_used, 170 static void VerifyLoFiHeader(bool expected_lofi_used,
171 bool expected_if_heavy,
170 const net::HttpRequestHeaders& headers) { 172 const net::HttpRequestHeaders& headers) {
171 if (expected_lofi_used) 173 if (expected_lofi_used)
172 EXPECT_TRUE(headers.HasHeader(chrome_proxy_accept_transform_header())); 174 EXPECT_TRUE(headers.HasHeader(chrome_proxy_accept_transform_header()));
173 std::string header_value; 175 std::string header_value;
174 headers.GetHeader(chrome_proxy_accept_transform_header(), &header_value); 176 headers.GetHeader(chrome_proxy_accept_transform_header(), &header_value);
175 EXPECT_EQ(expected_lofi_used, 177 if (expected_if_heavy) {
176 header_value.find(empty_image_directive()) != std::string::npos); 178 std::string empty_image_if_heavy = base::StringPrintf(
179 "%s;%s", empty_image_directive(), if_heavy_qualifier());
180 EXPECT_EQ(expected_lofi_used, empty_image_if_heavy == header_value);
181 } else {
182 EXPECT_EQ(expected_lofi_used, header_value == empty_image_directive());
183 }
177 } 184 }
178 185
179 static void VerifyLoFiPreviewHeader(bool expected_lofi_preview_used, 186 static void VerifyLitePageHeader(bool expected_lofi_preview_used,
180 const net::HttpRequestHeaders& headers) { 187 bool expected_if_heavy,
188 const net::HttpRequestHeaders& headers) {
181 if (expected_lofi_preview_used) 189 if (expected_lofi_preview_used)
182 EXPECT_TRUE(headers.HasHeader(chrome_proxy_accept_transform_header())); 190 EXPECT_TRUE(headers.HasHeader(chrome_proxy_accept_transform_header()));
183 std::string header_value; 191 std::string header_value;
184 headers.GetHeader(chrome_proxy_accept_transform_header(), &header_value); 192 headers.GetHeader(chrome_proxy_accept_transform_header(), &header_value);
185 EXPECT_EQ(expected_lofi_preview_used, 193 if (expected_if_heavy) {
186 header_value.find(lite_page_directive()) != std::string::npos); 194 std::string lite_page_if_heavy = base::StringPrintf(
195 "%s;%s", lite_page_directive(), if_heavy_qualifier());
196 EXPECT_EQ(expected_lofi_preview_used, lite_page_if_heavy == header_value);
197 } else {
198 EXPECT_EQ(expected_lofi_preview_used,
199 header_value == lite_page_directive());
200 }
187 } 201 }
188 202
189 static void VerifyVideoHeader(bool expected_compressed_video_used, 203 static void VerifyVideoHeader(bool expected_compressed_video_used,
190 const net::HttpRequestHeaders& headers) { 204 const net::HttpRequestHeaders& headers) {
191 EXPECT_EQ(expected_compressed_video_used, 205 EXPECT_EQ(expected_compressed_video_used,
192 headers.HasHeader(chrome_proxy_accept_transform_header())); 206 headers.HasHeader(chrome_proxy_accept_transform_header()));
193 std::string header_value; 207 std::string header_value;
194 headers.GetHeader(chrome_proxy_accept_transform_header(), &header_value); 208 headers.GetHeader(chrome_proxy_accept_transform_header(), &header_value);
195 EXPECT_EQ( 209 EXPECT_EQ(
196 expected_compressed_video_used, 210 expected_compressed_video_used,
197 header_value.find(compressed_video_directive()) != std::string::npos); 211 header_value.find(compressed_video_directive()) != std::string::npos);
198 } 212 }
199 213
200 static void VerifyLitePageIgnoreBlacklistHeader( 214 static void VerifyLitePageIgnoreBlacklistHeader(
201 bool expected_lite_page_used, 215 bool expected_blacklist_directive_added,
202 const net::HttpRequestHeaders& headers) { 216 const net::HttpRequestHeaders& headers) {
203 EXPECT_TRUE(headers.HasHeader(chrome_proxy_header())); 217 EXPECT_TRUE(headers.HasHeader(chrome_proxy_header()));
204 std::string header_value; 218 std::string header_value;
205 headers.GetHeader(chrome_proxy_header(), &header_value); 219 headers.GetHeader(chrome_proxy_header(), &header_value);
206 EXPECT_EQ(expected_lite_page_used, 220 EXPECT_EQ(expected_blacklist_directive_added,
207 header_value.find( 221 header_value.find(
208 chrome_proxy_lite_page_ignore_blacklist_directive()) != 222 chrome_proxy_lite_page_ignore_blacklist_directive()) !=
209 std::string::npos); 223 std::string::npos);
210 } 224 }
211 225
212 protected: 226 protected:
213 base::MessageLoopForIO message_loop_; 227 base::MessageLoopForIO message_loop_;
214 net::MockClientSocketFactory mock_socket_factory_; 228 net::MockClientSocketFactory mock_socket_factory_;
215 net::TestURLRequestContext context_; 229 net::TestURLRequestContext context_;
216 net::TestDelegate delegate_; 230 net::TestDelegate delegate_;
(...skipping 19 matching lines...) Expand all
236 CreateRequest(tests[i].is_main_frame, tests[i].is_using_lofi); 250 CreateRequest(tests[i].is_main_frame, tests[i].is_using_lofi);
237 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); 251 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
238 command_line->InitFromArgv(command_line->argv()); 252 command_line->InitFromArgv(command_line->argv());
239 if (tests[i].is_using_lite_page) { 253 if (tests[i].is_using_lite_page) {
240 command_line->AppendSwitch(switches::kEnableDataReductionProxyLitePage); 254 command_line->AppendSwitch(switches::kEnableDataReductionProxyLitePage);
241 } 255 }
242 256
243 // No flags or field trials. The Lo-Fi header should not be added. 257 // No flags or field trials. The Lo-Fi header should not be added.
244 net::HttpRequestHeaders headers; 258 net::HttpRequestHeaders headers;
245 NotifyBeforeSendHeaders(&headers, request.get(), true); 259 NotifyBeforeSendHeaders(&headers, request.get(), true);
246 VerifyLoFiHeader(false, headers); 260 VerifyLoFiHeader(false, false, headers);
247 VerifyLitePageHeader(false, headers); 261 VerifyLitePageHeader(false, false, headers);
248 VerifyLitePageIgnoreBlacklistHeader(false, headers); 262 VerifyLitePageIgnoreBlacklistHeader(false, headers);
249 263
250 // The Lo-Fi flag is "always-on", Lo-Fi is being used, and it's a main frame 264 // The Lo-Fi flag is "always-on", Lo-Fi is being used, and it's a main frame
251 // request. Lo-Fi or lite page header should be added. 265 // request. Lo-Fi or lite page header should be added.
252 command_line->AppendSwitchASCII( 266 command_line->AppendSwitchASCII(
253 switches::kDataReductionProxyLoFi, 267 switches::kDataReductionProxyLoFi,
254 switches::kDataReductionProxyLoFiValueAlwaysOn); 268 switches::kDataReductionProxyLoFiValueAlwaysOn);
255 headers.Clear(); 269 headers.Clear();
256 NotifyBeforeSendHeaders(&headers, request.get(), true); 270 NotifyBeforeSendHeaders(&headers, request.get(), true);
257 VerifyLoFiHeader(tests[i].is_using_lofi && !tests[i].is_using_lite_page && 271 VerifyLoFiHeader(!tests[i].is_using_lite_page && !tests[i].is_main_frame,
258 !tests[i].is_main_frame, 272 !tests[i].is_using_lofi, headers);
259 headers); 273 VerifyLitePageHeader(tests[i].is_using_lite_page && tests[i].is_main_frame,
260 VerifyLitePageHeader(tests[i].is_using_lofi && 274 !tests[i].is_using_lofi, headers);
261 tests[i].is_using_lite_page && 275 VerifyLitePageIgnoreBlacklistHeader(
262 tests[i].is_main_frame, 276 tests[i].is_using_lite_page && tests[i].is_main_frame, headers);
263 headers);
264 VerifyLitePageIgnoreBlacklistHeader(tests[i].is_using_lofi &&
265 tests[i].is_using_lite_page &&
266 tests[i].is_main_frame,
267 headers);
268 DataReductionProxyData* data = DataReductionProxyData::GetData(*request); 277 DataReductionProxyData* data = DataReductionProxyData::GetData(*request);
269 // |lofi_requested| should be set to false when Lo-Fi is enabled using 278 // |lofi_requested| should be set to false when Lo-Fi is enabled using
270 // flags. 279 // flags.
271 EXPECT_FALSE(data->lofi_requested()); 280 EXPECT_FALSE(data->lofi_requested());
272 281
273 // The Lo-Fi flag is "always-on" and Lo-Fi is being used. Lo-Fi header 282 // The Lo-Fi flag is "always-on" and Lo-Fi is being used. Lo-Fi header
274 // should be added. 283 // should be added.
275 AllocateRequestInfoForTesting(request.get(), 284 AllocateRequestInfoForTesting(request.get(),
276 content::RESOURCE_TYPE_SUB_FRAME, 285 content::RESOURCE_TYPE_SUB_FRAME,
277 tests[i].is_using_lofi); 286 tests[i].is_using_lofi);
278 headers.Clear(); 287 headers.Clear();
279 NotifyBeforeSendHeaders(&headers, request.get(), true); 288 NotifyBeforeSendHeaders(&headers, request.get(), true);
280 VerifyLoFiHeader(tests[i].is_using_lofi && !tests[i].is_using_lite_page, 289 VerifyLoFiHeader(!tests[i].is_using_lite_page, !tests[i].is_using_lofi,
281 headers); 290 headers);
282 VerifyLitePageHeader(false, headers); 291 VerifyLitePageHeader(false, false, headers);
283 VerifyLitePageIgnoreBlacklistHeader(false, headers); 292 VerifyLitePageIgnoreBlacklistHeader(false, headers);
284 293
285 // The Lo-Fi flag is "cellular-only" and Lo-Fi is being used. Lo-Fi header 294 // The Lo-Fi flag is "cellular-only" and Lo-Fi is being used. Lo-Fi header
286 // should be added. 295 // should be added.
287 command_line->AppendSwitchASCII( 296 command_line->AppendSwitchASCII(
288 switches::kDataReductionProxyLoFi, 297 switches::kDataReductionProxyLoFi,
289 switches::kDataReductionProxyLoFiValueCellularOnly); 298 switches::kDataReductionProxyLoFiValueCellularOnly);
290 headers.Clear(); 299 headers.Clear();
291 NotifyBeforeSendHeaders(&headers, request.get(), true); 300 NotifyBeforeSendHeaders(&headers, request.get(), true);
292 VerifyLoFiHeader(tests[i].is_using_lofi && !tests[i].is_using_lite_page, 301 VerifyLoFiHeader(!tests[i].is_using_lite_page, !tests[i].is_using_lofi,
293 headers); 302 headers);
294 VerifyLitePageHeader(false, headers); 303 VerifyLitePageHeader(false, false, headers);
295 VerifyLitePageIgnoreBlacklistHeader(false, headers); 304 VerifyLitePageIgnoreBlacklistHeader(false, headers);
296 data = DataReductionProxyData::GetData(*request); 305 data = DataReductionProxyData::GetData(*request);
297 // |lofi_requested| should be set to false when Lo-Fi is enabled using 306 // |lofi_requested| should be set to false when Lo-Fi is enabled using
298 // flags. 307 // flags.
299 EXPECT_FALSE(data->lofi_requested()); 308 EXPECT_FALSE(data->lofi_requested());
300 309
301 // The Lo-Fi flag is "slow-connections-only" and Lo-Fi is being used. Lo-Fi 310 // The Lo-Fi flag is "slow-connections-only" and Lo-Fi is being used. Lo-Fi
302 // header should be added. 311 // header should be added.
303 command_line->AppendSwitchASCII( 312 command_line->AppendSwitchASCII(
304 switches::kDataReductionProxyLoFi, 313 switches::kDataReductionProxyLoFi,
305 switches::kDataReductionProxyLoFiValueSlowConnectionsOnly); 314 switches::kDataReductionProxyLoFiValueSlowConnectionsOnly);
306 headers.Clear(); 315 headers.Clear();
307 NotifyBeforeSendHeaders(&headers, request.get(), true); 316 NotifyBeforeSendHeaders(&headers, request.get(), true);
308 VerifyLoFiHeader(tests[i].is_using_lofi && !tests[i].is_using_lite_page, 317 VerifyLoFiHeader(!tests[i].is_using_lite_page, !tests[i].is_using_lofi,
309 headers); 318 headers);
310 VerifyLitePageHeader(false, headers); 319 VerifyLitePageHeader(false, false, headers);
311 VerifyLitePageIgnoreBlacklistHeader(false, headers); 320 VerifyLitePageIgnoreBlacklistHeader(false, headers);
312 data = DataReductionProxyData::GetData(*request); 321 data = DataReductionProxyData::GetData(*request);
313 // |lofi_requested| should be set to false when Lo-Fi is enabled using 322 // |lofi_requested| should be set to false when Lo-Fi is enabled using
314 // flags. 323 // flags.
315 EXPECT_FALSE(data->lofi_requested()); 324 EXPECT_FALSE(data->lofi_requested());
316 } 325 }
317 } 326 }
318 327
319 TEST_F(ContentLoFiDeciderTest, LoFiEnabledFieldTrial) { 328 TEST_F(ContentLoFiDeciderTest, LoFiEnabledFieldTrial) {
320 base::FieldTrialList field_trial_list(nullptr); 329 base::FieldTrialList field_trial_list(nullptr);
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
368 net::HttpRequestHeaders headers; 377 net::HttpRequestHeaders headers;
369 NotifyBeforeSendHeaders(&headers, request.get(), true); 378 NotifyBeforeSendHeaders(&headers, request.get(), true);
370 bool is_lofi_resource_type = 379 bool is_lofi_resource_type =
371 !(tests[i].resource_type == content::RESOURCE_TYPE_MAIN_FRAME || 380 !(tests[i].resource_type == content::RESOURCE_TYPE_MAIN_FRAME ||
372 tests[i].resource_type == content::RESOURCE_TYPE_STYLESHEET || 381 tests[i].resource_type == content::RESOURCE_TYPE_STYLESHEET ||
373 tests[i].resource_type == content::RESOURCE_TYPE_SCRIPT || 382 tests[i].resource_type == content::RESOURCE_TYPE_SCRIPT ||
374 tests[i].resource_type == content::RESOURCE_TYPE_FONT_RESOURCE || 383 tests[i].resource_type == content::RESOURCE_TYPE_FONT_RESOURCE ||
375 tests[i].resource_type == content::RESOURCE_TYPE_MEDIA || 384 tests[i].resource_type == content::RESOURCE_TYPE_MEDIA ||
376 tests[i].resource_type == content::RESOURCE_TYPE_CSP_REPORT); 385 tests[i].resource_type == content::RESOURCE_TYPE_CSP_REPORT);
377 386
378 VerifyLoFiHeader(tests[i].is_using_lofi && is_lofi_resource_type, headers); 387 VerifyLoFiHeader(is_lofi_resource_type, !tests[i].is_using_lofi, headers);
379 VerifyLoFiPreviewHeader(false, headers); 388 VerifyLitePageHeader(false, false, headers);
380 VerifyLitePageIgnoreBlacklistHeader(false, headers); 389 VerifyLitePageIgnoreBlacklistHeader(false, headers);
381 DataReductionProxyData* data = DataReductionProxyData::GetData(*request); 390 DataReductionProxyData* data = DataReductionProxyData::GetData(*request);
382 EXPECT_EQ(tests[i].is_using_lofi, data->lofi_requested()) << i; 391 EXPECT_EQ(tests[i].is_using_lofi, data->lofi_requested()) << i;
383 } 392 }
384 } 393 }
385 394
386 TEST_F(ContentLoFiDeciderTest, LoFiControlFieldTrial) { 395 TEST_F(ContentLoFiDeciderTest, LoFiControlFieldTrial) {
387 base::FieldTrialList field_trial_list(nullptr); 396 base::FieldTrialList field_trial_list(nullptr);
388 base::FieldTrialList::CreateFieldTrial(params::GetLoFiFieldTrialName(), 397 base::FieldTrialList::CreateFieldTrial(params::GetLoFiFieldTrialName(),
389 "Control"); 398 "Control");
390 // Enable Lo-Fi. 399 // Enable Lo-Fi.
391 const struct { 400 const struct {
392 bool is_using_lofi; 401 bool is_using_lofi;
393 bool is_main_frame; 402 bool is_main_frame;
394 } tests[] = {{false, false}, {false, true}, {true, false}, {true, true}}; 403 } tests[] = {{false, false}, {false, true}, {true, false}, {true, true}};
395 404
396 for (size_t i = 0; i < arraysize(tests); ++i) { 405 for (size_t i = 0; i < arraysize(tests); ++i) {
397 std::unique_ptr<net::URLRequest> request = 406 std::unique_ptr<net::URLRequest> request =
398 CreateRequest(tests[i].is_main_frame, tests[i].is_using_lofi); 407 CreateRequest(tests[i].is_main_frame, tests[i].is_using_lofi);
399 net::HttpRequestHeaders headers; 408 net::HttpRequestHeaders headers;
400 NotifyBeforeSendHeaders(&headers, request.get(), true); 409 NotifyBeforeSendHeaders(&headers, request.get(), true);
401 VerifyLoFiHeader(false, headers); 410 VerifyLoFiHeader(false, false, headers);
402 VerifyLitePageHeader(false, headers); 411 VerifyLitePageHeader(false, false, headers);
403 VerifyLitePageIgnoreBlacklistHeader(false, headers); 412 VerifyLitePageIgnoreBlacklistHeader(false, headers);
404 DataReductionProxyData* data = DataReductionProxyData::GetData(*request); 413 DataReductionProxyData* data = DataReductionProxyData::GetData(*request);
405 EXPECT_EQ(tests[i].is_using_lofi, data->lofi_requested()) << i; 414 EXPECT_EQ(tests[i].is_using_lofi, data->lofi_requested()) << i;
406 } 415 }
407 } 416 }
408 417
409 TEST_F(ContentLoFiDeciderTest, LitePageFieldTrial) { 418 TEST_F(ContentLoFiDeciderTest, LitePageFieldTrial) {
410 base::FieldTrialList field_trial_list(nullptr); 419 base::FieldTrialList field_trial_list(nullptr);
411 base::FieldTrialList::CreateFieldTrial(params::GetLoFiFieldTrialName(), 420 base::FieldTrialList::CreateFieldTrial(params::GetLoFiFieldTrialName(),
412 "Enabled_Preview"); 421 "Enabled_Preview");
413 // Enable Lo-Fi. 422 // Enable Lo-Fi.
414 const struct { 423 const struct {
415 bool is_using_lofi; 424 bool is_using_lofi;
416 bool is_main_frame; 425 bool is_main_frame;
417 } tests[] = { 426 } tests[] = {
418 {false, false}, {true, false}, {false, true}, {true, true}, 427 {false, false}, {true, false}, {false, true}, {true, true},
419 }; 428 };
420 429
421 for (size_t i = 0; i < arraysize(tests); ++i) { 430 for (size_t i = 0; i < arraysize(tests); ++i) {
422 std::unique_ptr<net::URLRequest> request = 431 std::unique_ptr<net::URLRequest> request =
423 CreateRequest(tests[i].is_main_frame, tests[i].is_using_lofi); 432 CreateRequest(tests[i].is_main_frame, tests[i].is_using_lofi);
424 net::HttpRequestHeaders headers; 433 net::HttpRequestHeaders headers;
425 NotifyBeforeSendHeaders(&headers, request.get(), true); 434 NotifyBeforeSendHeaders(&headers, request.get(), true);
426 VerifyLoFiHeader(false, headers); 435 VerifyLoFiHeader(false, false, headers);
427 VerifyLitePageHeader(tests[i].is_using_lofi && tests[i].is_main_frame, 436 VerifyLitePageHeader(tests[i].is_main_frame, !tests[i].is_using_lofi,
428 headers); 437 headers);
429 VerifyLitePageIgnoreBlacklistHeader(false, headers); 438 VerifyLitePageIgnoreBlacklistHeader(false, headers);
430 DataReductionProxyData* data = DataReductionProxyData::GetData(*request); 439 DataReductionProxyData* data = DataReductionProxyData::GetData(*request);
431 EXPECT_EQ(tests[i].is_using_lofi, data->lofi_requested()) << i; 440 EXPECT_EQ(tests[i].is_using_lofi, data->lofi_requested()) << i;
432 } 441 }
433 } 442 }
434 443
435 TEST_F(ContentLoFiDeciderTest, AutoLoFi) { 444 TEST_F(ContentLoFiDeciderTest, AutoLoFi) {
436 const struct { 445 const struct {
437 bool auto_lofi_enabled_group; 446 bool auto_lofi_enabled_group;
438 bool auto_lofi_control_group; 447 bool auto_lofi_control_group;
439 bool network_prohibitively_slow; 448 bool network_prohibitively_slow;
440 bool is_main_frame; 449 bool is_main_frame;
441 } tests[] = { 450 } tests[] = {
442 {false, false, false, false}, 451 {false, false, false, false},
443 {false, false, true, false}, 452 {false, false, true, false},
444 {true, false, false, false}, 453 {true, false, false, false},
445 {true, false, true, false}, 454 {true, false, true, false},
446 {true, false, true, true}, 455 {true, false, true, true},
447 {false, true, false, false}, 456 {false, true, false, false},
448 {false, true, true, false}, 457 {false, true, true, false},
449 // Repeat this test data to simulate user moving out of Lo-Fi control 458 // Repeat this test data to simulate user moving out of Lo-Fi control
450 // experiment. 459 // experiment.
451 {false, true, false, false}, 460 {false, true, false, false},
452 }; 461 };
453 462
454 for (size_t i = 0; i < arraysize(tests); ++i) { 463 for (size_t i = 0; i < arraysize(tests); ++i) {
455 test_context_->config()->ResetLoFiStatusForTest(); 464 test_context_->config()->ResetLoFiStatusForTest();
456 const bool expect_lofi_header = tests[i].auto_lofi_enabled_group && 465 const bool expect_lofi_header = tests[i].auto_lofi_enabled_group &&
457 tests[i].network_prohibitively_slow &&
458 !tests[i].is_main_frame; 466 !tests[i].is_main_frame;
459 467
460 base::FieldTrialList field_trial_list(nullptr); 468 base::FieldTrialList field_trial_list(nullptr);
461 if (tests[i].auto_lofi_enabled_group) { 469 if (tests[i].auto_lofi_enabled_group) {
462 base::FieldTrialList::CreateFieldTrial(params::GetLoFiFieldTrialName(), 470 base::FieldTrialList::CreateFieldTrial(params::GetLoFiFieldTrialName(),
463 "Enabled"); 471 "Enabled");
464 } 472 }
465 473
466 if (tests[i].auto_lofi_control_group) { 474 if (tests[i].auto_lofi_control_group) {
467 base::FieldTrialList::CreateFieldTrial(params::GetLoFiFieldTrialName(), 475 base::FieldTrialList::CreateFieldTrial(params::GetLoFiFieldTrialName(),
468 "Control"); 476 "Control");
469 } 477 }
470 478
471 test_context_->config()->SetNetworkProhibitivelySlow( 479 test_context_->config()->SetNetworkProhibitivelySlow(
472 tests[i].network_prohibitively_slow); 480 tests[i].network_prohibitively_slow);
473 481
474 std::unique_ptr<net::URLRequest> request = CreateRequest( 482 std::unique_ptr<net::URLRequest> request = CreateRequest(
475 tests[i].is_main_frame, tests[i].network_prohibitively_slow); 483 tests[i].is_main_frame, tests[i].network_prohibitively_slow);
476 net::HttpRequestHeaders headers; 484 net::HttpRequestHeaders headers;
477 NotifyBeforeSendHeaders(&headers, request.get(), true); 485 NotifyBeforeSendHeaders(&headers, request.get(), true);
478 486
479 VerifyLoFiHeader(expect_lofi_header, headers); 487 VerifyLoFiHeader(expect_lofi_header, !tests[i].network_prohibitively_slow,
488 headers);
480 } 489 }
481 } 490 }
482 491
483 TEST_F(ContentLoFiDeciderTest, SlowConnectionsFlag) { 492 TEST_F(ContentLoFiDeciderTest, SlowConnectionsFlag) {
484 const struct { 493 const struct {
485 bool slow_connections_flag_enabled; 494 bool slow_connections_flag_enabled;
486 bool network_prohibitively_slow; 495 bool network_prohibitively_slow;
487 bool auto_lofi_enabled_group; 496 bool auto_lofi_enabled_group;
488 bool is_main_frame; 497 bool is_main_frame;
489 } tests[] = { 498 } tests[] = {
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
522 } 531 }
523 532
524 test_context_->config()->SetNetworkProhibitivelySlow( 533 test_context_->config()->SetNetworkProhibitivelySlow(
525 tests[i].network_prohibitively_slow); 534 tests[i].network_prohibitively_slow);
526 535
527 std::unique_ptr<net::URLRequest> request = CreateRequest( 536 std::unique_ptr<net::URLRequest> request = CreateRequest(
528 tests[i].is_main_frame, tests[i].network_prohibitively_slow); 537 tests[i].is_main_frame, tests[i].network_prohibitively_slow);
529 net::HttpRequestHeaders headers; 538 net::HttpRequestHeaders headers;
530 NotifyBeforeSendHeaders(&headers, request.get(), true); 539 NotifyBeforeSendHeaders(&headers, request.get(), true);
531 540
532 VerifyLoFiHeader(expect_lofi_header, headers); 541 VerifyLoFiHeader(expect_lofi_header, false, headers);
533 } 542 }
534 } 543 }
535 544
536 TEST_F(ContentLoFiDeciderTest, ProxyIsNotDataReductionProxy) { 545 TEST_F(ContentLoFiDeciderTest, ProxyIsNotDataReductionProxy) {
537 base::FieldTrialList field_trial_list(nullptr); 546 base::FieldTrialList field_trial_list(nullptr);
538 base::FieldTrialList::CreateFieldTrial(params::GetLoFiFieldTrialName(), 547 base::FieldTrialList::CreateFieldTrial(params::GetLoFiFieldTrialName(),
539 "Enabled"); 548 "Enabled");
540 // Enable Lo-Fi. 549 // Enable Lo-Fi.
541 const struct { 550 const struct {
542 bool is_using_lofi; 551 bool is_using_lofi;
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
672 EXPECT_EQ("exp=ignore_preview_blacklist", header_value); 681 EXPECT_EQ("exp=ignore_preview_blacklist", header_value);
673 682
674 headers.SetHeader(chrome_proxy_header(), "Foo"); 683 headers.SetHeader(chrome_proxy_header(), "Foo");
675 lofi_decider->MaybeSetIgnorePreviewsBlacklistDirective(&headers); 684 lofi_decider->MaybeSetIgnorePreviewsBlacklistDirective(&headers);
676 EXPECT_TRUE(headers.HasHeader(chrome_proxy_header())); 685 EXPECT_TRUE(headers.HasHeader(chrome_proxy_header()));
677 headers.GetHeader(chrome_proxy_header(), &header_value); 686 headers.GetHeader(chrome_proxy_header(), &header_value);
678 EXPECT_EQ("Foo, exp=ignore_preview_blacklist", header_value); 687 EXPECT_EQ("Foo, exp=ignore_preview_blacklist", header_value);
679 } 688 }
680 689
681 } // namespace data_reduction_roxy 690 } // namespace data_reduction_roxy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698