OLD | NEW |
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/core/browser/data_reduction_proxy_conf
ig.h" | 5 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_conf
ig.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include <cstdlib> | 10 #include <cstdlib> |
11 #include <map> | 11 #include <map> |
12 #include <memory> | 12 #include <memory> |
13 #include <utility> | 13 #include <utility> |
14 #include <vector> | 14 #include <vector> |
15 | 15 |
16 #include "base/command_line.h" | 16 #include "base/command_line.h" |
17 #include "base/files/file_path.h" | 17 #include "base/files/file_path.h" |
18 #include "base/files/file_util.h" | 18 #include "base/files/file_util.h" |
19 #include "base/macros.h" | 19 #include "base/macros.h" |
20 #include "base/memory/ptr_util.h" | 20 #include "base/memory/ptr_util.h" |
21 #include "base/memory/ref_counted.h" | 21 #include "base/memory/ref_counted.h" |
22 #include "base/message_loop/message_loop.h" | 22 #include "base/message_loop/message_loop.h" |
23 #include "base/metrics/field_trial.h" | 23 #include "base/metrics/field_trial.h" |
24 #include "base/run_loop.h" | 24 #include "base/run_loop.h" |
25 #include "base/strings/safe_sprintf.h" | 25 #include "base/strings/safe_sprintf.h" |
26 #include "base/strings/string_number_conversions.h" | 26 #include "base/strings/string_number_conversions.h" |
27 #include "base/strings/string_util.h" | 27 #include "base/strings/string_util.h" |
28 #include "base/test/histogram_tester.h" | 28 #include "base/test/histogram_tester.h" |
| 29 #include "base/test/scoped_feature_list.h" |
29 #include "base/test/simple_test_tick_clock.h" | 30 #include "base/test/simple_test_tick_clock.h" |
30 #include "base/threading/platform_thread.h" | 31 #include "base/threading/platform_thread.h" |
31 #include "base/time/time.h" | 32 #include "base/time/time.h" |
32 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_conf
ig_test_utils.h" | 33 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_conf
ig_test_utils.h" |
33 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_conf
igurator.h" | 34 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_conf
igurator.h" |
34 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_muta
ble_config_values.h" | 35 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_muta
ble_config_values.h" |
35 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_serv
ice.h" | 36 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_serv
ice.h" |
36 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_test
_utils.h" | 37 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_test
_utils.h" |
37 #include "components/data_reduction_proxy/core/common/data_reduction_proxy_event
_creator.h" | 38 #include "components/data_reduction_proxy/core/common/data_reduction_proxy_event
_creator.h" |
| 39 #include "components/data_reduction_proxy/core/common/data_reduction_proxy_featu
res.h" |
38 #include "components/data_reduction_proxy/core/common/data_reduction_proxy_param
s_test_utils.h" | 40 #include "components/data_reduction_proxy/core/common/data_reduction_proxy_param
s_test_utils.h" |
39 #include "components/data_reduction_proxy/core/common/data_reduction_proxy_serve
r.h" | 41 #include "components/data_reduction_proxy/core/common/data_reduction_proxy_serve
r.h" |
40 #include "components/data_reduction_proxy/core/common/data_reduction_proxy_switc
hes.h" | 42 #include "components/data_reduction_proxy/core/common/data_reduction_proxy_switc
hes.h" |
41 #include "components/data_reduction_proxy/proto/client_config.pb.h" | 43 #include "components/data_reduction_proxy/proto/client_config.pb.h" |
42 #include "components/previews/core/previews_decider.h" | 44 #include "components/previews/core/previews_decider.h" |
43 #include "components/previews/core/previews_experiments.h" | 45 #include "components/previews/core/previews_experiments.h" |
44 #include "components/variations/variations_associated_data.h" | 46 #include "components/variations/variations_associated_data.h" |
45 #include "net/base/load_flags.h" | 47 #include "net/base/load_flags.h" |
46 #include "net/base/net_errors.h" | 48 #include "net/base/net_errors.h" |
47 #include "net/base/network_change_notifier.h" | 49 #include "net/base/network_change_notifier.h" |
(...skipping 962 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1010 // The user is in the enabled field trial group but the network | 1012 // The user is in the enabled field trial group but the network |
1011 // quality is not bad. Lo-Fi should not be used. | 1013 // quality is not bad. Lo-Fi should not be used. |
1012 false, true, "Enabled_Control", false, false, | 1014 false, true, "Enabled_Control", false, false, |
1013 0, // Lo-Fi request header is not used (state change: empty to empty) | 1015 0, // Lo-Fi request header is not used (state change: empty to empty) |
1014 1, false, | 1016 1, false, |
1015 }, | 1017 }, |
1016 }; | 1018 }; |
1017 for (size_t i = 0; i < arraysize(tests); ++i) { | 1019 for (size_t i = 0; i < arraysize(tests); ++i) { |
1018 config()->ResetLoFiStatusForTest(); | 1020 config()->ResetLoFiStatusForTest(); |
1019 | 1021 |
| 1022 // Ensure not using proxy-decides-transform feature. |
| 1023 base::test::ScopedFeatureList scoped_feature_list; |
| 1024 scoped_feature_list.InitAndDisableFeature( |
| 1025 features::kDataReductionProxyDecidesTransform); |
| 1026 |
1020 base::FieldTrialList field_trial_list(nullptr); | 1027 base::FieldTrialList field_trial_list(nullptr); |
1021 if (tests[i].previews_black_list_used) { | 1028 if (tests[i].previews_black_list_used) { |
1022 base::FieldTrialList::CreateFieldTrial( | 1029 base::FieldTrialList::CreateFieldTrial( |
1023 "DataReductionProxyPreviewsBlackListTransition", "Enabled_"); | 1030 "DataReductionProxyPreviewsBlackListTransition", "Enabled_"); |
1024 } else if (tests[i].is_opted_out) { | 1031 } else if (tests[i].is_opted_out) { |
1025 config()->SetLoFiModeOff(); | 1032 config()->SetLoFiModeOff(); |
1026 } | 1033 } |
1027 if (tests[i].lofi_enabled) { | 1034 if (tests[i].lofi_enabled) { |
1028 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII( | 1035 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII( |
1029 switches::kDataReductionProxyLoFi, | 1036 switches::kDataReductionProxyLoFi, |
(...skipping 15 matching lines...) Expand all Loading... |
1045 base::HistogramTester histogram_tester; | 1052 base::HistogramTester histogram_tester; |
1046 net::TestURLRequestContext context_; | 1053 net::TestURLRequestContext context_; |
1047 net::TestDelegate delegate_; | 1054 net::TestDelegate delegate_; |
1048 std::unique_ptr<net::URLRequest> request = context_.CreateRequest( | 1055 std::unique_ptr<net::URLRequest> request = context_.CreateRequest( |
1049 GURL(), net::IDLE, &delegate_, TRAFFIC_ANNOTATION_FOR_TESTS); | 1056 GURL(), net::IDLE, &delegate_, TRAFFIC_ANNOTATION_FOR_TESTS); |
1050 request->SetLoadFlags(request->load_flags() | | 1057 request->SetLoadFlags(request->load_flags() | |
1051 net::LOAD_MAIN_FRAME_DEPRECATED); | 1058 net::LOAD_MAIN_FRAME_DEPRECATED); |
1052 std::unique_ptr<TestPreviewsDecider> previews_decider = | 1059 std::unique_ptr<TestPreviewsDecider> previews_decider = |
1053 base::MakeUnique<TestPreviewsDecider>(!tests[i].is_opted_out); | 1060 base::MakeUnique<TestPreviewsDecider>(!tests[i].is_opted_out); |
1054 bool should_enable_lofi = | 1061 bool should_enable_lofi = |
1055 config()->ShouldEnableLoFi(*request.get(), previews_decider.get()); | 1062 config()->ShouldEnableLoFi(*request.get(), *previews_decider.get()); |
1056 if (tests[i].expect_bucket_count != 0) { | 1063 if (tests[i].expect_bucket_count != 0) { |
1057 histogram_tester.ExpectBucketCount( | 1064 histogram_tester.ExpectBucketCount( |
1058 "DataReductionProxy.AutoLoFiRequestHeaderState.Unknown", | 1065 "DataReductionProxy.AutoLoFiRequestHeaderState.Unknown", |
1059 tests[i].bucket_to_check_for_auto_lofi_uma, | 1066 tests[i].bucket_to_check_for_auto_lofi_uma, |
1060 tests[i].expect_bucket_count); | 1067 tests[i].expect_bucket_count); |
1061 } | 1068 } |
1062 | 1069 |
1063 EXPECT_EQ(tests[i].expect_lofi_header, should_enable_lofi) << i; | 1070 EXPECT_EQ(tests[i].expect_lofi_header, should_enable_lofi) << i; |
1064 } | 1071 } |
1065 } | 1072 } |
(...skipping 321 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1387 | 1394 |
1388 // Sleep to ensure that the delayed task is posted. | 1395 // Sleep to ensure that the delayed task is posted. |
1389 base::PlatformThread::Sleep(base::TimeDelta::FromSeconds(1)); | 1396 base::PlatformThread::Sleep(base::TimeDelta::FromSeconds(1)); |
1390 RunUntilIdle(); | 1397 RunUntilIdle(); |
1391 histogram_tester.ExpectTotalCount( | 1398 histogram_tester.ExpectTotalCount( |
1392 "DataReductionProxy.LoFi.Accuracy.1.Unknown", 1); | 1399 "DataReductionProxy.LoFi.Accuracy.1.Unknown", 1); |
1393 histogram_tester.ExpectBucketCount( | 1400 histogram_tester.ExpectBucketCount( |
1394 "DataReductionProxy.LoFi.Accuracy.1.Unknown", 0, 1); | 1401 "DataReductionProxy.LoFi.Accuracy.1.Unknown", 0, 1); |
1395 } | 1402 } |
1396 | 1403 |
| 1404 TEST_F(DataReductionProxyConfigTest, ShouldEnableLoFiWithECTCheck) { |
| 1405 // Turn off proxy-decides-transform feature (so will locally check ECT). |
| 1406 base::test::ScopedFeatureList scoped_feature_list; |
| 1407 scoped_feature_list.InitAndDisableFeature( |
| 1408 features::kDataReductionProxyDecidesTransform); |
| 1409 |
| 1410 // Enable Server Lo-Fi field trial. |
| 1411 base::FieldTrialList field_trial_list(nullptr); |
| 1412 base::FieldTrialList::CreateFieldTrial(params::GetLoFiFieldTrialName(), |
| 1413 "Enabled"); |
| 1414 |
| 1415 EXPECT_CALL(*config(), IsNetworkQualityProhibitivelySlow(_)) |
| 1416 .WillRepeatedly(testing::Return(true)); |
| 1417 |
| 1418 net::TestURLRequestContext context; |
| 1419 net::TestDelegate delegate; |
| 1420 std::unique_ptr<net::URLRequest> request = context.CreateRequest( |
| 1421 GURL(), net::IDLE, &delegate, TRAFFIC_ANNOTATION_FOR_TESTS); |
| 1422 request->SetLoadFlags(request->load_flags() | |
| 1423 net::LOAD_MAIN_FRAME_DEPRECATED); |
| 1424 std::unique_ptr<TestPreviewsDecider> previews_decider = |
| 1425 base::MakeUnique<TestPreviewsDecider>(false); |
| 1426 |
| 1427 EXPECT_TRUE( |
| 1428 config()->ShouldEnableLoFi(*request.get(), *previews_decider.get())); |
| 1429 |
| 1430 // Now verify should not enable with good network connection. |
| 1431 EXPECT_CALL(*config(), IsNetworkQualityProhibitivelySlow(_)) |
| 1432 .WillRepeatedly(testing::Return(false)); |
| 1433 |
| 1434 EXPECT_FALSE( |
| 1435 config()->ShouldEnableLoFi(*request.get(), *previews_decider.get())); |
| 1436 } |
| 1437 |
| 1438 TEST_F(DataReductionProxyConfigTest, ShouldEnableLoFiWithoutECTCheck) { |
| 1439 // Turn on proxy-decides-transform feature (so will not locally check ECT). |
| 1440 base::test::ScopedFeatureList scoped_feature_list; |
| 1441 scoped_feature_list.InitAndEnableFeature( |
| 1442 features::kDataReductionProxyDecidesTransform); |
| 1443 |
| 1444 // Enable Server Lo-Fi field trial. |
| 1445 base::FieldTrialList field_trial_list(nullptr); |
| 1446 base::FieldTrialList::CreateFieldTrial(params::GetLoFiFieldTrialName(), |
| 1447 "Enabled"); |
| 1448 |
| 1449 // Expect network quality check is never called. |
| 1450 EXPECT_CALL(*config(), IsNetworkQualityProhibitivelySlow(_)).Times(0); |
| 1451 |
| 1452 net::TestURLRequestContext context; |
| 1453 net::TestDelegate delegate; |
| 1454 std::unique_ptr<net::URLRequest> request = context.CreateRequest( |
| 1455 GURL(), net::IDLE, &delegate, TRAFFIC_ANNOTATION_FOR_TESTS); |
| 1456 request->SetLoadFlags(request->load_flags() | |
| 1457 net::LOAD_MAIN_FRAME_DEPRECATED); |
| 1458 std::unique_ptr<TestPreviewsDecider> previews_decider = |
| 1459 base::MakeUnique<TestPreviewsDecider>(false); |
| 1460 |
| 1461 EXPECT_TRUE( |
| 1462 config()->ShouldEnableLoFi(*request.get(), *previews_decider.get())); |
| 1463 } |
| 1464 |
| 1465 TEST_F(DataReductionProxyConfigTest, ShouldEnableLitePagesWithECTCheck) { |
| 1466 // Turn off proxy-decides-transform feature (so will locally check ECT). |
| 1467 base::test::ScopedFeatureList scoped_feature_list; |
| 1468 scoped_feature_list.InitAndDisableFeature( |
| 1469 features::kDataReductionProxyDecidesTransform); |
| 1470 |
| 1471 // Enable Server Lo-Fi field trial. |
| 1472 base::FieldTrialList field_trial_list(nullptr); |
| 1473 base::FieldTrialList::CreateFieldTrial(params::GetLoFiFieldTrialName(), |
| 1474 "Enabled_Preview"); |
| 1475 |
| 1476 EXPECT_CALL(*config(), IsNetworkQualityProhibitivelySlow(_)) |
| 1477 .WillRepeatedly(testing::Return(true)); |
| 1478 |
| 1479 net::TestURLRequestContext context; |
| 1480 net::TestDelegate delegate; |
| 1481 std::unique_ptr<net::URLRequest> request = context.CreateRequest( |
| 1482 GURL(), net::IDLE, &delegate, TRAFFIC_ANNOTATION_FOR_TESTS); |
| 1483 request->SetLoadFlags(request->load_flags() | |
| 1484 net::LOAD_MAIN_FRAME_DEPRECATED); |
| 1485 std::unique_ptr<TestPreviewsDecider> previews_decider = |
| 1486 base::MakeUnique<TestPreviewsDecider>(false); |
| 1487 |
| 1488 EXPECT_TRUE( |
| 1489 config()->ShouldEnableLitePages(*request.get(), *previews_decider.get())); |
| 1490 |
| 1491 // Now verify should not enable with good network connection. |
| 1492 EXPECT_CALL(*config(), IsNetworkQualityProhibitivelySlow(_)) |
| 1493 .WillRepeatedly(testing::Return(false)); |
| 1494 |
| 1495 EXPECT_FALSE( |
| 1496 config()->ShouldEnableLitePages(*request.get(), *previews_decider.get())); |
| 1497 } |
| 1498 |
| 1499 TEST_F(DataReductionProxyConfigTest, ShouldEnableLitePagesWithoutECTCheck) { |
| 1500 // Turn on proxy-decides-transform feature (so will not locally check ECT). |
| 1501 base::test::ScopedFeatureList scoped_feature_list; |
| 1502 scoped_feature_list.InitAndEnableFeature( |
| 1503 features::kDataReductionProxyDecidesTransform); |
| 1504 |
| 1505 // Enable Server Lo-Fi field trial. |
| 1506 base::FieldTrialList field_trial_list(nullptr); |
| 1507 base::FieldTrialList::CreateFieldTrial(params::GetLoFiFieldTrialName(), |
| 1508 "Enabled_Preview"); |
| 1509 |
| 1510 // Expect network quality check is never called. |
| 1511 EXPECT_CALL(*config(), IsNetworkQualityProhibitivelySlow(_)).Times(0); |
| 1512 |
| 1513 net::TestURLRequestContext context_; |
| 1514 net::TestDelegate delegate_; |
| 1515 std::unique_ptr<net::URLRequest> request = context_.CreateRequest( |
| 1516 GURL(), net::IDLE, &delegate_, TRAFFIC_ANNOTATION_FOR_TESTS); |
| 1517 request->SetLoadFlags(request->load_flags() | |
| 1518 net::LOAD_MAIN_FRAME_DEPRECATED); |
| 1519 std::unique_ptr<TestPreviewsDecider> previews_decider = |
| 1520 base::MakeUnique<TestPreviewsDecider>(false); |
| 1521 |
| 1522 EXPECT_TRUE( |
| 1523 config()->ShouldEnableLitePages(*request.get(), *previews_decider.get())); |
| 1524 } |
| 1525 |
| 1526 TEST_F(DataReductionProxyConfigTest, ShouldAcceptServerLoFi) { |
| 1527 // Turn on proxy-decides-transform feature to satisfy DCHECK. |
| 1528 base::test::ScopedFeatureList scoped_feature_list; |
| 1529 scoped_feature_list.InitAndEnableFeature( |
| 1530 features::kDataReductionProxyDecidesTransform); |
| 1531 |
| 1532 net::TestURLRequestContext context_; |
| 1533 net::TestDelegate delegate_; |
| 1534 std::unique_ptr<net::URLRequest> request = context_.CreateRequest( |
| 1535 GURL(), net::IDLE, &delegate_, TRAFFIC_ANNOTATION_FOR_TESTS); |
| 1536 request->SetLoadFlags(request->load_flags() | |
| 1537 net::LOAD_MAIN_FRAME_DEPRECATED); |
| 1538 std::unique_ptr<TestPreviewsDecider> previews_decider = |
| 1539 base::MakeUnique<TestPreviewsDecider>(false); |
| 1540 |
| 1541 // Verify false for no flags. |
| 1542 EXPECT_FALSE(config()->ShouldAcceptServerLoFi(*request.get(), |
| 1543 *previews_decider.get())); |
| 1544 |
| 1545 // Verify true for Always-On flag. |
| 1546 base::CommandLine::ForCurrentProcess()->InitFromArgv(0, NULL); |
| 1547 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII( |
| 1548 switches::kDataReductionProxyLoFi, |
| 1549 switches::kDataReductionProxyLoFiValueAlwaysOn); |
| 1550 EXPECT_TRUE(config()->ShouldAcceptServerLoFi(*request.get(), |
| 1551 *previews_decider.get())); |
| 1552 |
| 1553 // Verify false for Always-On but LitePages enabled too. |
| 1554 base::CommandLine::ForCurrentProcess()->InitFromArgv(0, NULL); |
| 1555 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII( |
| 1556 switches::kDataReductionProxyLoFi, |
| 1557 switches::kDataReductionProxyLoFiValueAlwaysOn); |
| 1558 base::CommandLine::ForCurrentProcess()->AppendSwitch( |
| 1559 switches::kEnableDataReductionProxyLitePage); |
| 1560 EXPECT_FALSE(config()->ShouldAcceptServerLoFi(*request.get(), |
| 1561 *previews_decider.get())); |
| 1562 |
| 1563 // Verify true for Slow Connection flag. |
| 1564 base::CommandLine::ForCurrentProcess()->InitFromArgv(0, NULL); |
| 1565 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII( |
| 1566 switches::kDataReductionProxyLoFi, |
| 1567 switches::kDataReductionProxyLoFiValueSlowConnectionsOnly); |
| 1568 EXPECT_TRUE(config()->ShouldAcceptServerLoFi(*request.get(), |
| 1569 *previews_decider.get())); |
| 1570 |
| 1571 // Verify false for Cellular Only flag and WIFI connection. |
| 1572 base::CommandLine::ForCurrentProcess()->InitFromArgv(0, NULL); |
| 1573 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII( |
| 1574 switches::kDataReductionProxyLoFi, |
| 1575 switches::kDataReductionProxyLoFiValueCellularOnly); |
| 1576 config()->SetConnectionTypeForTesting( |
| 1577 net::NetworkChangeNotifier::ConnectionType::CONNECTION_WIFI); |
| 1578 EXPECT_FALSE(config()->ShouldAcceptServerLoFi(*request.get(), |
| 1579 *previews_decider.get())); |
| 1580 |
| 1581 // Verify true for Cellular Only flag and 3G connection. |
| 1582 config()->SetConnectionTypeForTesting( |
| 1583 net::NetworkChangeNotifier::ConnectionType::CONNECTION_3G); |
| 1584 EXPECT_TRUE(config()->ShouldAcceptServerLoFi(*request.get(), |
| 1585 *previews_decider.get())); |
| 1586 |
| 1587 // Verify true for field trial. |
| 1588 { |
| 1589 base::CommandLine::ForCurrentProcess()->InitFromArgv(0, NULL); |
| 1590 base::FieldTrialList field_trial_list(nullptr); |
| 1591 base::FieldTrialList::CreateFieldTrial(params::GetLoFiFieldTrialName(), |
| 1592 "Enabled"); |
| 1593 EXPECT_TRUE(config()->ShouldAcceptServerLoFi(*request.get(), |
| 1594 *previews_decider.get())); |
| 1595 } |
| 1596 |
| 1597 // Verify false for control field trial. |
| 1598 { |
| 1599 base::CommandLine::ForCurrentProcess()->InitFromArgv(0, NULL); |
| 1600 base::FieldTrialList field_trial_list(nullptr); |
| 1601 base::FieldTrialList::CreateFieldTrial(params::GetLoFiFieldTrialName(), |
| 1602 "Control"); |
| 1603 EXPECT_FALSE(config()->ShouldAcceptServerLoFi(*request.get(), |
| 1604 *previews_decider.get())); |
| 1605 } |
| 1606 |
| 1607 // Verify PreviewsDecider check. |
| 1608 { |
| 1609 base::CommandLine::ForCurrentProcess()->InitFromArgv(0, NULL); |
| 1610 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII( |
| 1611 switches::kDataReductionProxyLoFi, |
| 1612 switches::kDataReductionProxyLoFiValueAlwaysOn); |
| 1613 base::FieldTrialList field_trial_list(nullptr); |
| 1614 base::FieldTrialList::CreateFieldTrial( |
| 1615 "DataReductionProxyPreviewsBlackListTransition", "Enabled"); |
| 1616 EXPECT_FALSE(config()->ShouldAcceptServerLoFi(*request.get(), |
| 1617 *previews_decider.get())); |
| 1618 previews_decider = base::MakeUnique<TestPreviewsDecider>(true); |
| 1619 EXPECT_TRUE(config()->ShouldAcceptServerLoFi(*request.get(), |
| 1620 *previews_decider.get())); |
| 1621 } |
| 1622 } |
| 1623 |
| 1624 TEST_F(DataReductionProxyConfigTest, ShouldAcceptLitePages) { |
| 1625 // Turn on proxy-decides-transform feature to satisfy DCHECK. |
| 1626 base::test::ScopedFeatureList scoped_feature_list; |
| 1627 scoped_feature_list.InitAndEnableFeature( |
| 1628 features::kDataReductionProxyDecidesTransform); |
| 1629 |
| 1630 net::TestURLRequestContext context_; |
| 1631 net::TestDelegate delegate_; |
| 1632 std::unique_ptr<net::URLRequest> request = context_.CreateRequest( |
| 1633 GURL(), net::IDLE, &delegate_, TRAFFIC_ANNOTATION_FOR_TESTS); |
| 1634 request->SetLoadFlags(request->load_flags() | |
| 1635 net::LOAD_MAIN_FRAME_DEPRECATED); |
| 1636 std::unique_ptr<TestPreviewsDecider> previews_decider = |
| 1637 base::MakeUnique<TestPreviewsDecider>(false); |
| 1638 |
| 1639 // Verify false for no flags. |
| 1640 EXPECT_FALSE( |
| 1641 config()->ShouldAcceptLitePages(*request.get(), *previews_decider.get())); |
| 1642 |
| 1643 // Verify true for Always-On flag and LitePage flag. |
| 1644 base::CommandLine::ForCurrentProcess()->InitFromArgv(0, NULL); |
| 1645 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII( |
| 1646 switches::kDataReductionProxyLoFi, |
| 1647 switches::kDataReductionProxyLoFiValueAlwaysOn); |
| 1648 EXPECT_FALSE( |
| 1649 config()->ShouldAcceptLitePages(*request.get(), *previews_decider.get())); |
| 1650 base::CommandLine::ForCurrentProcess()->AppendSwitch( |
| 1651 switches::kEnableDataReductionProxyLitePage); |
| 1652 EXPECT_TRUE( |
| 1653 config()->ShouldAcceptLitePages(*request.get(), *previews_decider.get())); |
| 1654 |
| 1655 // Verify true for Slow Connection flag and LitePage flag. |
| 1656 base::CommandLine::ForCurrentProcess()->InitFromArgv(0, NULL); |
| 1657 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII( |
| 1658 switches::kDataReductionProxyLoFi, |
| 1659 switches::kDataReductionProxyLoFiValueSlowConnectionsOnly); |
| 1660 EXPECT_FALSE( |
| 1661 config()->ShouldAcceptLitePages(*request.get(), *previews_decider.get())); |
| 1662 base::CommandLine::ForCurrentProcess()->AppendSwitch( |
| 1663 switches::kEnableDataReductionProxyLitePage); |
| 1664 EXPECT_TRUE( |
| 1665 config()->ShouldAcceptLitePages(*request.get(), *previews_decider.get())); |
| 1666 |
| 1667 // Verify true for Cellular Only flag and 3G connection. |
| 1668 base::CommandLine::ForCurrentProcess()->InitFromArgv(0, NULL); |
| 1669 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII( |
| 1670 switches::kDataReductionProxyLoFi, |
| 1671 switches::kDataReductionProxyLoFiValueCellularOnly); |
| 1672 config()->SetConnectionTypeForTesting( |
| 1673 net::NetworkChangeNotifier::ConnectionType::CONNECTION_3G); |
| 1674 EXPECT_FALSE( |
| 1675 config()->ShouldAcceptLitePages(*request.get(), *previews_decider.get())); |
| 1676 base::CommandLine::ForCurrentProcess()->AppendSwitch( |
| 1677 switches::kEnableDataReductionProxyLitePage); |
| 1678 EXPECT_TRUE( |
| 1679 config()->ShouldAcceptLitePages(*request.get(), *previews_decider.get())); |
| 1680 |
| 1681 // Verify false for Cellular Only flag and WIFI connection. |
| 1682 config()->SetConnectionTypeForTesting( |
| 1683 net::NetworkChangeNotifier::ConnectionType::CONNECTION_WIFI); |
| 1684 EXPECT_FALSE( |
| 1685 config()->ShouldAcceptLitePages(*request.get(), *previews_decider.get())); |
| 1686 |
| 1687 // Verify true for field trial. |
| 1688 { |
| 1689 base::CommandLine::ForCurrentProcess()->InitFromArgv(0, NULL); |
| 1690 base::FieldTrialList field_trial_list(nullptr); |
| 1691 base::FieldTrialList::CreateFieldTrial(params::GetLoFiFieldTrialName(), |
| 1692 "Enabled_Preview"); |
| 1693 EXPECT_TRUE(config()->ShouldAcceptLitePages(*request.get(), |
| 1694 *previews_decider.get())); |
| 1695 } |
| 1696 |
| 1697 // Verify PreviewsDecider check. |
| 1698 { |
| 1699 base::CommandLine::ForCurrentProcess()->InitFromArgv(0, NULL); |
| 1700 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII( |
| 1701 switches::kDataReductionProxyLoFi, |
| 1702 switches::kDataReductionProxyLoFiValueAlwaysOn); |
| 1703 base::CommandLine::ForCurrentProcess()->AppendSwitch( |
| 1704 switches::kEnableDataReductionProxyLitePage); |
| 1705 base::FieldTrialList field_trial_list(nullptr); |
| 1706 base::FieldTrialList::CreateFieldTrial( |
| 1707 "DataReductionProxyPreviewsBlackListTransition", "Enabled"); |
| 1708 EXPECT_FALSE(config()->ShouldAcceptLitePages(*request.get(), |
| 1709 *previews_decider.get())); |
| 1710 previews_decider = base::MakeUnique<TestPreviewsDecider>(true); |
| 1711 EXPECT_TRUE(config()->ShouldAcceptLitePages(*request.get(), |
| 1712 *previews_decider.get())); |
| 1713 } |
| 1714 } |
| 1715 |
1397 } // namespace data_reduction_proxy | 1716 } // namespace data_reduction_proxy |
OLD | NEW |