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

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

Issue 2073233002: Do not trigger Lo-Fi on main frame requests (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixed comment Created 4 years, 6 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/content/browser/content_lofi_decider.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 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>
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after
169 std::unique_ptr<DataReductionProxyTestContext> test_context_; 169 std::unique_ptr<DataReductionProxyTestContext> test_context_;
170 std::unique_ptr<DataReductionProxyNetworkDelegate> 170 std::unique_ptr<DataReductionProxyNetworkDelegate>
171 data_reduction_proxy_network_delegate_; 171 data_reduction_proxy_network_delegate_;
172 }; 172 };
173 173
174 TEST_F(ContentLoFiDeciderTest, LoFiFlags) { 174 TEST_F(ContentLoFiDeciderTest, LoFiFlags) {
175 // Enable Lo-Fi. 175 // Enable Lo-Fi.
176 const struct { 176 const struct {
177 bool is_using_lofi; 177 bool is_using_lofi;
178 bool is_using_previews; 178 bool is_using_previews;
179 bool is_main_frame;
179 } tests[] = { 180 } tests[] = {
180 {false, false}, {true, false}, {false, true}, {true, true}, 181 {false, false, false}, {false, false, true}, {true, false, true},
182 {true, false, false}, {false, true, false}, {false, true, true},
183 {true, true, true}, {true, true, false},
181 }; 184 };
182 185
183 for (size_t i = 0; i < arraysize(tests); ++i) { 186 for (size_t i = 0; i < arraysize(tests); ++i) {
184 std::unique_ptr<net::URLRequest> request = 187 std::unique_ptr<net::URLRequest> request =
185 CreateRequest(tests[i].is_using_lofi); 188 CreateRequest(tests[i].is_using_lofi);
186 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); 189 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
187 command_line->InitFromArgv(command_line->argv()); 190 command_line->InitFromArgv(command_line->argv());
188 if (tests[i].is_using_previews) { 191 if (tests[i].is_using_previews) {
189 command_line->AppendSwitch( 192 command_line->AppendSwitch(
190 switches::kEnableDataReductionProxyLoFiPreview); 193 switches::kEnableDataReductionProxyLoFiPreview);
191 } 194 }
192 195
193 // No flags or field trials. The Lo-Fi header should not be added. 196 // No flags or field trials. The Lo-Fi header should not be added.
194 net::HttpRequestHeaders headers; 197 net::HttpRequestHeaders headers;
195 NotifyBeforeSendHeaders(&headers, request.get(), true); 198 NotifyBeforeSendHeaders(&headers, request.get(), true);
196 VerifyLoFiHeader(false, headers); 199 VerifyLoFiHeader(false, headers);
197 VerifyLoFiPreviewHeader(false, headers); 200 VerifyLoFiPreviewHeader(false, headers);
198 VerifyLoFiIgnorePreviewBlacklistHeader(false, headers); 201 VerifyLoFiIgnorePreviewBlacklistHeader(false, headers);
199 202
200 // The Lo-Fi flag is "always-on", Lo-Fi is being used, and it's a main frame 203 // The Lo-Fi flag is "always-on", Lo-Fi is being used, and it's a main frame
201 // request. Lo-Fi preview header should be added. 204 // request. Lo-Fi preview header should be added.
202 command_line->AppendSwitchASCII( 205 command_line->AppendSwitchASCII(
203 switches::kDataReductionProxyLoFi, 206 switches::kDataReductionProxyLoFi,
204 switches::kDataReductionProxyLoFiValueAlwaysOn); 207 switches::kDataReductionProxyLoFiValueAlwaysOn);
205 request->SetLoadFlags(request->load_flags() | net::LOAD_MAIN_FRAME); 208 if (tests[i].is_main_frame)
209 request->SetLoadFlags(request->load_flags() | net::LOAD_MAIN_FRAME);
206 headers.Clear(); 210 headers.Clear();
207 NotifyBeforeSendHeaders(&headers, request.get(), true); 211 NotifyBeforeSendHeaders(&headers, request.get(), true);
208 VerifyLoFiHeader(tests[i].is_using_lofi && !tests[i].is_using_previews, 212 VerifyLoFiHeader(tests[i].is_using_lofi && !tests[i].is_using_previews &&
213 !tests[i].is_main_frame,
209 headers); 214 headers);
210 VerifyLoFiPreviewHeader( 215 VerifyLoFiPreviewHeader(tests[i].is_using_lofi &&
211 tests[i].is_using_lofi && tests[i].is_using_previews, headers); 216 tests[i].is_using_previews &&
212 VerifyLoFiIgnorePreviewBlacklistHeader( 217 tests[i].is_main_frame,
213 tests[i].is_using_lofi && tests[i].is_using_previews, headers); 218 headers);
219 VerifyLoFiIgnorePreviewBlacklistHeader(tests[i].is_using_lofi &&
220 tests[i].is_using_previews &&
221 tests[i].is_main_frame,
222 headers);
214 223
215 // The Lo-Fi flag is "always-on" and Lo-Fi is being used. Lo-Fi header 224 // The Lo-Fi flag is "always-on" and Lo-Fi is being used. Lo-Fi header
216 // should be added. 225 // should be added.
217 request->SetLoadFlags(0); 226 request->SetLoadFlags(0);
218 headers.Clear(); 227 headers.Clear();
219 NotifyBeforeSendHeaders(&headers, request.get(), true); 228 NotifyBeforeSendHeaders(&headers, request.get(), true);
220 VerifyLoFiHeader(tests[i].is_using_lofi && !tests[i].is_using_previews, 229 VerifyLoFiHeader(tests[i].is_using_lofi && !tests[i].is_using_previews,
221 headers); 230 headers);
222 VerifyLoFiPreviewHeader(false, headers); 231 VerifyLoFiPreviewHeader(false, headers);
223 VerifyLoFiIgnorePreviewBlacklistHeader(false, headers); 232 VerifyLoFiIgnorePreviewBlacklistHeader(false, headers);
(...skipping 24 matching lines...) Expand all
248 } 257 }
249 } 258 }
250 259
251 TEST_F(ContentLoFiDeciderTest, LoFiEnabledFieldTrial) { 260 TEST_F(ContentLoFiDeciderTest, LoFiEnabledFieldTrial) {
252 base::FieldTrialList field_trial_list(nullptr); 261 base::FieldTrialList field_trial_list(nullptr);
253 base::FieldTrialList::CreateFieldTrial(params::GetLoFiFieldTrialName(), 262 base::FieldTrialList::CreateFieldTrial(params::GetLoFiFieldTrialName(),
254 "Enabled"); 263 "Enabled");
255 // Enable Lo-Fi. 264 // Enable Lo-Fi.
256 const struct { 265 const struct {
257 bool is_using_lofi; 266 bool is_using_lofi;
258 } tests[] = { 267 bool is_main_frame;
259 {false}, {true}, 268 } tests[] = {{false, false}, {false, true}, {true, false}, {true, true}};
260 };
261 269
262 for (size_t i = 0; i < arraysize(tests); ++i) { 270 for (size_t i = 0; i < arraysize(tests); ++i) {
263 std::unique_ptr<net::URLRequest> request = 271 std::unique_ptr<net::URLRequest> request =
264 CreateRequest(tests[i].is_using_lofi); 272 CreateRequest(tests[i].is_using_lofi);
273 if (tests[i].is_main_frame)
274 request->SetLoadFlags(request->load_flags() | net::LOAD_MAIN_FRAME);
265 net::HttpRequestHeaders headers; 275 net::HttpRequestHeaders headers;
266 NotifyBeforeSendHeaders(&headers, request.get(), true); 276 NotifyBeforeSendHeaders(&headers, request.get(), true);
267 VerifyLoFiHeader(tests[i].is_using_lofi, headers); 277 VerifyLoFiHeader(tests[i].is_using_lofi && !tests[i].is_main_frame,
278 headers);
268 VerifyLoFiPreviewHeader(false, headers); 279 VerifyLoFiPreviewHeader(false, headers);
269 VerifyLoFiIgnorePreviewBlacklistHeader(false, headers); 280 VerifyLoFiIgnorePreviewBlacklistHeader(false, headers);
270 } 281 }
271 } 282 }
272 283
273 TEST_F(ContentLoFiDeciderTest, LoFiControlFieldTrial) { 284 TEST_F(ContentLoFiDeciderTest, LoFiControlFieldTrial) {
274 base::FieldTrialList field_trial_list(nullptr); 285 base::FieldTrialList field_trial_list(nullptr);
275 base::FieldTrialList::CreateFieldTrial(params::GetLoFiFieldTrialName(), 286 base::FieldTrialList::CreateFieldTrial(params::GetLoFiFieldTrialName(),
276 "Control"); 287 "Control");
277 // Enable Lo-Fi. 288 // Enable Lo-Fi.
278 const struct { 289 const struct {
279 bool is_using_lofi; 290 bool is_using_lofi;
280 } tests[] = { 291 bool is_main_frame;
281 {false}, {true}, 292 } tests[] = {{false, false}, {false, true}, {true, false}, {true, true}};
282 };
283 293
284 for (size_t i = 0; i < arraysize(tests); ++i) { 294 for (size_t i = 0; i < arraysize(tests); ++i) {
285 std::unique_ptr<net::URLRequest> request = 295 std::unique_ptr<net::URLRequest> request =
286 CreateRequest(tests[i].is_using_lofi); 296 CreateRequest(tests[i].is_using_lofi);
297 if (tests[i].is_main_frame)
298 request->SetLoadFlags(request->load_flags() | net::LOAD_MAIN_FRAME);
287 net::HttpRequestHeaders headers; 299 net::HttpRequestHeaders headers;
288 NotifyBeforeSendHeaders(&headers, request.get(), true); 300 NotifyBeforeSendHeaders(&headers, request.get(), true);
289 VerifyLoFiHeader(false, headers); 301 VerifyLoFiHeader(false, headers);
290 VerifyLoFiPreviewHeader(false, headers); 302 VerifyLoFiPreviewHeader(false, headers);
291 VerifyLoFiIgnorePreviewBlacklistHeader(false, headers); 303 VerifyLoFiIgnorePreviewBlacklistHeader(false, headers);
292 } 304 }
293 } 305 }
294 306
295 TEST_F(ContentLoFiDeciderTest, LoFiPreviewFieldTrial) { 307 TEST_F(ContentLoFiDeciderTest, LoFiPreviewFieldTrial) {
296 base::FieldTrialList field_trial_list(nullptr); 308 base::FieldTrialList field_trial_list(nullptr);
(...skipping 19 matching lines...) Expand all
316 headers); 328 headers);
317 VerifyLoFiIgnorePreviewBlacklistHeader(false, headers); 329 VerifyLoFiIgnorePreviewBlacklistHeader(false, headers);
318 } 330 }
319 } 331 }
320 332
321 TEST_F(ContentLoFiDeciderTest, AutoLoFi) { 333 TEST_F(ContentLoFiDeciderTest, AutoLoFi) {
322 const struct { 334 const struct {
323 bool auto_lofi_enabled_group; 335 bool auto_lofi_enabled_group;
324 bool auto_lofi_control_group; 336 bool auto_lofi_control_group;
325 bool network_prohibitively_slow; 337 bool network_prohibitively_slow;
338 bool is_main_frame;
326 } tests[] = { 339 } tests[] = {
327 {false, false, false}, 340 {false, false, false, false},
328 {false, false, true}, 341 {false, false, true, false},
329 {true, false, false}, 342 {true, false, false, false},
330 {true, false, true}, 343 {true, false, true, false},
331 {false, true, false}, 344 {true, false, true, true},
332 {false, true, true}, 345 {false, true, false, false},
346 {false, true, true, false},
333 // Repeat this test data to simulate user moving out of Lo-Fi control 347 // Repeat this test data to simulate user moving out of Lo-Fi control
334 // experiment. 348 // experiment.
335 {false, true, false}, 349 {false, true, false, false},
336 }; 350 };
337 351
338 for (size_t i = 0; i < arraysize(tests); ++i) { 352 for (size_t i = 0; i < arraysize(tests); ++i) {
339 test_context_->config()->ResetLoFiStatusForTest(); 353 test_context_->config()->ResetLoFiStatusForTest();
340 // Lo-Fi header is expected only if session is part of Lo-Fi enabled field 354 const bool expect_lofi_header = tests[i].auto_lofi_enabled_group &&
341 // trial and network is prohibitively slow. 355 tests[i].network_prohibitively_slow &&
342 bool expect_lofi_header = 356 !tests[i].is_main_frame;
343 tests[i].auto_lofi_enabled_group && tests[i].network_prohibitively_slow;
344 357
345 base::FieldTrialList field_trial_list(nullptr); 358 base::FieldTrialList field_trial_list(nullptr);
346 if (tests[i].auto_lofi_enabled_group) { 359 if (tests[i].auto_lofi_enabled_group) {
347 base::FieldTrialList::CreateFieldTrial(params::GetLoFiFieldTrialName(), 360 base::FieldTrialList::CreateFieldTrial(params::GetLoFiFieldTrialName(),
348 "Enabled"); 361 "Enabled");
349 } 362 }
350 363
351 if (tests[i].auto_lofi_control_group) { 364 if (tests[i].auto_lofi_control_group) {
352 base::FieldTrialList::CreateFieldTrial(params::GetLoFiFieldTrialName(), 365 base::FieldTrialList::CreateFieldTrial(params::GetLoFiFieldTrialName(),
353 "Control"); 366 "Control");
354 } 367 }
355 368
356 test_context_->config()->SetNetworkProhibitivelySlow( 369 test_context_->config()->SetNetworkProhibitivelySlow(
357 tests[i].network_prohibitively_slow); 370 tests[i].network_prohibitively_slow);
358 371
359 std::unique_ptr<net::URLRequest> request = 372 std::unique_ptr<net::URLRequest> request =
360 CreateRequest(tests[i].network_prohibitively_slow); 373 CreateRequest(tests[i].network_prohibitively_slow);
374 if (tests[i].is_main_frame)
375 request->SetLoadFlags(request->load_flags() | net::LOAD_MAIN_FRAME);
361 net::HttpRequestHeaders headers; 376 net::HttpRequestHeaders headers;
362 NotifyBeforeSendHeaders(&headers, request.get(), true); 377 NotifyBeforeSendHeaders(&headers, request.get(), true);
363 378
364 VerifyLoFiHeader(expect_lofi_header, headers); 379 VerifyLoFiHeader(expect_lofi_header, headers);
365 } 380 }
366 } 381 }
367 382
368 TEST_F(ContentLoFiDeciderTest, SlowConnectionsFlag) { 383 TEST_F(ContentLoFiDeciderTest, SlowConnectionsFlag) {
369 const struct { 384 const struct {
370 bool slow_connections_flag_enabled; 385 bool slow_connections_flag_enabled;
371 bool network_prohibitively_slow; 386 bool network_prohibitively_slow;
372 bool auto_lofi_enabled_group; 387 bool auto_lofi_enabled_group;
373 388 bool is_main_frame;
374 } tests[] = { 389 } tests[] = {
375 {false, false, false}, {false, true, false}, {true, false, false}, 390 {false, false, false, false}, {false, true, false, false},
376 {true, true, false}, {false, false, true}, {false, true, true}, 391 {true, false, false, false}, {true, true, false, false},
377 {true, false, true}, {true, true, true}, 392 {true, true, false, true}, {false, false, true, false},
393 {false, false, true, true}, {false, true, true, false},
394 {true, false, true, false}, {true, true, true, false},
378 }; 395 };
379 396
380 for (size_t i = 0; i < arraysize(tests); ++i) { 397 for (size_t i = 0; i < arraysize(tests); ++i) {
381 test_context_->config()->ResetLoFiStatusForTest(); 398 test_context_->config()->ResetLoFiStatusForTest();
382 // For the purpose of this test, Lo-Fi header is expected only if LoFi Slow 399 // For the purpose of this test, Lo-Fi header is expected only if LoFi Slow
383 // Connection Flag is enabled or session is part of Lo-Fi enabled field 400 // Connection Flag is enabled or session is part of Lo-Fi enabled field
384 // trial. For both cases, an additional condition is that network must be 401 // trial. For both cases, an additional condition is that network must be
385 // prohibitively slow. 402 // prohibitively slow.
386 bool expect_lofi_header = (tests[i].slow_connections_flag_enabled && 403 const bool expect_lofi_header = ((tests[i].slow_connections_flag_enabled &&
387 tests[i].network_prohibitively_slow) || 404 tests[i].network_prohibitively_slow) ||
388 (!tests[i].slow_connections_flag_enabled && 405 (!tests[i].slow_connections_flag_enabled &&
389 tests[i].auto_lofi_enabled_group && 406 tests[i].auto_lofi_enabled_group &&
390 tests[i].network_prohibitively_slow); 407 tests[i].network_prohibitively_slow)) &&
408 !tests[i].is_main_frame;
391 409
392 std::string expected_header; 410 std::string expected_header;
393 411
394 if (tests[i].slow_connections_flag_enabled) { 412 if (tests[i].slow_connections_flag_enabled) {
395 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII( 413 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII(
396 switches::kDataReductionProxyLoFi, 414 switches::kDataReductionProxyLoFi,
397 switches::kDataReductionProxyLoFiValueSlowConnectionsOnly); 415 switches::kDataReductionProxyLoFiValueSlowConnectionsOnly);
398 } 416 }
399 417
400 base::FieldTrialList field_trial_list(nullptr); 418 base::FieldTrialList field_trial_list(nullptr);
401 if (tests[i].auto_lofi_enabled_group) { 419 if (tests[i].auto_lofi_enabled_group) {
402 base::FieldTrialList::CreateFieldTrial(params::GetLoFiFieldTrialName(), 420 base::FieldTrialList::CreateFieldTrial(params::GetLoFiFieldTrialName(),
403 "Enabled"); 421 "Enabled");
404 } 422 }
405 423
406 test_context_->config()->SetNetworkProhibitivelySlow( 424 test_context_->config()->SetNetworkProhibitivelySlow(
407 tests[i].network_prohibitively_slow); 425 tests[i].network_prohibitively_slow);
408 426
409 std::unique_ptr<net::URLRequest> request = 427 std::unique_ptr<net::URLRequest> request =
410 CreateRequest(tests[i].network_prohibitively_slow); 428 CreateRequest(tests[i].network_prohibitively_slow);
429 if (tests[i].is_main_frame)
430 request->SetLoadFlags(request->load_flags() | net::LOAD_MAIN_FRAME);
411 net::HttpRequestHeaders headers; 431 net::HttpRequestHeaders headers;
412 NotifyBeforeSendHeaders(&headers, request.get(), true); 432 NotifyBeforeSendHeaders(&headers, request.get(), true);
413 433
414 VerifyLoFiHeader(expect_lofi_header, headers); 434 VerifyLoFiHeader(expect_lofi_header, headers);
415 } 435 }
416 } 436 }
417 437
418 TEST_F(ContentLoFiDeciderTest, ProxyIsNotDataReductionProxy) { 438 TEST_F(ContentLoFiDeciderTest, ProxyIsNotDataReductionProxy) {
419 base::FieldTrialList field_trial_list(nullptr); 439 base::FieldTrialList field_trial_list(nullptr);
420 base::FieldTrialList::CreateFieldTrial(params::GetLoFiFieldTrialName(), 440 base::FieldTrialList::CreateFieldTrial(params::GetLoFiFieldTrialName(),
(...skipping 11 matching lines...) Expand all
432 net::HttpRequestHeaders headers; 452 net::HttpRequestHeaders headers;
433 NotifyBeforeSendHeaders(&headers, request.get(), false); 453 NotifyBeforeSendHeaders(&headers, request.get(), false);
434 std::string header_value; 454 std::string header_value;
435 headers.GetHeader(chrome_proxy_header(), &header_value); 455 headers.GetHeader(chrome_proxy_header(), &header_value);
436 EXPECT_EQ(std::string::npos, 456 EXPECT_EQ(std::string::npos,
437 header_value.find(chrome_proxy_lo_fi_directive())); 457 header_value.find(chrome_proxy_lo_fi_directive()));
438 } 458 }
439 } 459 }
440 460
441 } // namespace data_reduction_roxy 461 } // namespace data_reduction_roxy
OLDNEW
« no previous file with comments | « components/data_reduction_proxy/content/browser/content_lofi_decider.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698