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

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

Issue 2889993004: New CPAT support in DataReductionProxyConfig guarded by feature flag. (Closed)
Patch Set: Updates new code path to accept LoFi when LitePages enabled (to allow fallback) Created 3 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 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
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
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
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, ShouldEnableLoFiDoesNotFallback) {
1405 // Turn off proxy-decides-transform feature (path for client ECT check).
1406 base::test::ScopedFeatureList scoped_feature_list;
1407 scoped_feature_list.InitAndDisableFeature(
1408 features::kDataReductionProxyDecidesTransform);
1409
1410 // Enable Server Lo-Fi.
1411 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII(
1412 switches::kDataReductionProxyLoFi,
1413 switches::kDataReductionProxyLoFiValueAlwaysOn);
1414
1415 // Also enable LitePages
1416 base::CommandLine::ForCurrentProcess()->AppendSwitch(
1417 switches::kEnableDataReductionProxyLitePage);
1418
1419 net::TestURLRequestContext context;
1420 net::TestDelegate delegate;
1421 std::unique_ptr<net::URLRequest> request = context.CreateRequest(
1422 GURL(), net::IDLE, &delegate, TRAFFIC_ANNOTATION_FOR_TESTS);
1423 request->SetLoadFlags(request->load_flags() |
1424 net::LOAD_MAIN_FRAME_DEPRECATED);
1425 std::unique_ptr<TestPreviewsDecider> previews_decider =
1426 base::MakeUnique<TestPreviewsDecider>(false);
1427
1428 EXPECT_TRUE(
1429 config()->ShouldEnableLitePages(*request.get(), *previews_decider.get()));
1430 EXPECT_FALSE(
1431 config()->ShouldEnableLoFi(*request.get(), *previews_decider.get()));
1432 }
1433
1434 TEST_F(DataReductionProxyConfigTest, ShouldEnableLoFiWithECTCheck) {
1435 // Turn off proxy-decides-transform feature (so will locally check ECT).
1436 base::test::ScopedFeatureList scoped_feature_list;
1437 scoped_feature_list.InitAndDisableFeature(
1438 features::kDataReductionProxyDecidesTransform);
1439
1440 // Enable Server Lo-Fi field trial.
1441 base::FieldTrialList field_trial_list(nullptr);
1442 base::FieldTrialList::CreateFieldTrial(params::GetLoFiFieldTrialName(),
1443 "Enabled");
1444
1445 EXPECT_CALL(*config(), IsNetworkQualityProhibitivelySlow(_))
1446 .WillRepeatedly(testing::Return(true));
1447
1448 net::TestURLRequestContext context;
1449 net::TestDelegate delegate;
1450 std::unique_ptr<net::URLRequest> request = context.CreateRequest(
1451 GURL(), net::IDLE, &delegate, TRAFFIC_ANNOTATION_FOR_TESTS);
1452 request->SetLoadFlags(request->load_flags() |
1453 net::LOAD_MAIN_FRAME_DEPRECATED);
1454 std::unique_ptr<TestPreviewsDecider> previews_decider =
1455 base::MakeUnique<TestPreviewsDecider>(false);
1456
1457 EXPECT_TRUE(
1458 config()->ShouldEnableLoFi(*request.get(), *previews_decider.get()));
1459
1460 // Now verify should not enable with good network connection.
1461 EXPECT_CALL(*config(), IsNetworkQualityProhibitivelySlow(_))
1462 .WillRepeatedly(testing::Return(false));
1463
1464 EXPECT_FALSE(
1465 config()->ShouldEnableLoFi(*request.get(), *previews_decider.get()));
1466 }
1467
1468 TEST_F(DataReductionProxyConfigTest, ShouldEnableLoFiWithoutECTCheck) {
1469 // Turn on proxy-decides-transform feature (so will not locally check ECT).
1470 base::test::ScopedFeatureList scoped_feature_list;
1471 scoped_feature_list.InitAndEnableFeature(
1472 features::kDataReductionProxyDecidesTransform);
1473
1474 // Enable Server Lo-Fi field trial.
1475 base::FieldTrialList field_trial_list(nullptr);
1476 base::FieldTrialList::CreateFieldTrial(params::GetLoFiFieldTrialName(),
1477 "Enabled");
1478
1479 // Expect network quality check is never called.
1480 EXPECT_CALL(*config(), IsNetworkQualityProhibitivelySlow(_)).Times(0);
1481
1482 net::TestURLRequestContext context;
1483 net::TestDelegate delegate;
1484 std::unique_ptr<net::URLRequest> request = context.CreateRequest(
1485 GURL(), net::IDLE, &delegate, TRAFFIC_ANNOTATION_FOR_TESTS);
1486 request->SetLoadFlags(request->load_flags() |
1487 net::LOAD_MAIN_FRAME_DEPRECATED);
1488 std::unique_ptr<TestPreviewsDecider> previews_decider =
1489 base::MakeUnique<TestPreviewsDecider>(false);
1490
1491 EXPECT_TRUE(
1492 config()->ShouldEnableLoFi(*request.get(), *previews_decider.get()));
1493 }
1494
1495 TEST_F(DataReductionProxyConfigTest, ShouldEnableLitePagesWithECTCheck) {
1496 // Turn off proxy-decides-transform feature (so will locally check ECT).
1497 base::test::ScopedFeatureList scoped_feature_list;
1498 scoped_feature_list.InitAndDisableFeature(
1499 features::kDataReductionProxyDecidesTransform);
1500
1501 // Enable Server Lo-Fi field trial.
1502 base::FieldTrialList field_trial_list(nullptr);
1503 base::FieldTrialList::CreateFieldTrial(params::GetLoFiFieldTrialName(),
1504 "Enabled_Preview");
1505
1506 EXPECT_CALL(*config(), IsNetworkQualityProhibitivelySlow(_))
1507 .WillRepeatedly(testing::Return(true));
1508
1509 net::TestURLRequestContext context;
1510 net::TestDelegate delegate;
1511 std::unique_ptr<net::URLRequest> request = context.CreateRequest(
1512 GURL(), net::IDLE, &delegate, TRAFFIC_ANNOTATION_FOR_TESTS);
1513 request->SetLoadFlags(request->load_flags() |
1514 net::LOAD_MAIN_FRAME_DEPRECATED);
1515 std::unique_ptr<TestPreviewsDecider> previews_decider =
1516 base::MakeUnique<TestPreviewsDecider>(false);
1517
1518 EXPECT_TRUE(
1519 config()->ShouldEnableLitePages(*request.get(), *previews_decider.get()));
1520
1521 // Now verify should not enable with good network connection.
1522 EXPECT_CALL(*config(), IsNetworkQualityProhibitivelySlow(_))
1523 .WillRepeatedly(testing::Return(false));
1524
1525 EXPECT_FALSE(
1526 config()->ShouldEnableLitePages(*request.get(), *previews_decider.get()));
1527 }
1528
1529 TEST_F(DataReductionProxyConfigTest, ShouldEnableLitePagesWithoutECTCheck) {
1530 // Turn on proxy-decides-transform feature (so will not locally check ECT).
1531 base::test::ScopedFeatureList scoped_feature_list;
1532 scoped_feature_list.InitAndEnableFeature(
1533 features::kDataReductionProxyDecidesTransform);
1534
1535 // Enable Server Lo-Fi field trial.
1536 base::FieldTrialList field_trial_list(nullptr);
1537 base::FieldTrialList::CreateFieldTrial(params::GetLoFiFieldTrialName(),
1538 "Enabled_Preview");
1539
1540 // Expect network quality check is never called.
1541 EXPECT_CALL(*config(), IsNetworkQualityProhibitivelySlow(_)).Times(0);
1542
1543 net::TestURLRequestContext context_;
1544 net::TestDelegate delegate_;
1545 std::unique_ptr<net::URLRequest> request = context_.CreateRequest(
1546 GURL(), net::IDLE, &delegate_, TRAFFIC_ANNOTATION_FOR_TESTS);
1547 request->SetLoadFlags(request->load_flags() |
1548 net::LOAD_MAIN_FRAME_DEPRECATED);
1549 std::unique_ptr<TestPreviewsDecider> previews_decider =
1550 base::MakeUnique<TestPreviewsDecider>(false);
1551
1552 EXPECT_TRUE(
1553 config()->ShouldEnableLitePages(*request.get(), *previews_decider.get()));
1554 }
1555
1556 TEST_F(DataReductionProxyConfigTest, ShouldAcceptServerLoFi) {
1557 // Turn on proxy-decides-transform feature to satisfy DCHECK.
1558 base::test::ScopedFeatureList scoped_feature_list;
1559 scoped_feature_list.InitAndEnableFeature(
1560 features::kDataReductionProxyDecidesTransform);
1561
1562 net::TestURLRequestContext context_;
1563 net::TestDelegate delegate_;
1564 std::unique_ptr<net::URLRequest> request = context_.CreateRequest(
1565 GURL(), net::IDLE, &delegate_, TRAFFIC_ANNOTATION_FOR_TESTS);
1566 request->SetLoadFlags(request->load_flags() |
1567 net::LOAD_MAIN_FRAME_DEPRECATED);
1568 std::unique_ptr<TestPreviewsDecider> previews_decider =
1569 base::MakeUnique<TestPreviewsDecider>(false);
1570
1571 // Verify false for no flags.
1572 EXPECT_FALSE(config()->ShouldAcceptServerLoFi(*request.get(),
1573 *previews_decider.get()));
1574
1575 // Verify true for Always-On flag.
1576 base::CommandLine::ForCurrentProcess()->InitFromArgv(0, NULL);
1577 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII(
1578 switches::kDataReductionProxyLoFi,
1579 switches::kDataReductionProxyLoFiValueAlwaysOn);
1580 EXPECT_TRUE(config()->ShouldAcceptServerLoFi(*request.get(),
1581 *previews_decider.get()));
1582
1583 // Verify true for Always-On with LitePages enabled too.
1584 base::CommandLine::ForCurrentProcess()->InitFromArgv(0, NULL);
1585 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII(
1586 switches::kDataReductionProxyLoFi,
1587 switches::kDataReductionProxyLoFiValueAlwaysOn);
1588 base::CommandLine::ForCurrentProcess()->AppendSwitch(
1589 switches::kEnableDataReductionProxyLitePage);
1590 EXPECT_TRUE(config()->ShouldAcceptServerLoFi(*request.get(),
1591 *previews_decider.get()));
1592
1593 // Verify true for Slow Connection flag.
1594 base::CommandLine::ForCurrentProcess()->InitFromArgv(0, NULL);
1595 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII(
1596 switches::kDataReductionProxyLoFi,
1597 switches::kDataReductionProxyLoFiValueSlowConnectionsOnly);
1598 EXPECT_TRUE(config()->ShouldAcceptServerLoFi(*request.get(),
1599 *previews_decider.get()));
1600
1601 // Verify false for Cellular Only flag and WIFI connection.
1602 base::CommandLine::ForCurrentProcess()->InitFromArgv(0, NULL);
1603 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII(
1604 switches::kDataReductionProxyLoFi,
1605 switches::kDataReductionProxyLoFiValueCellularOnly);
1606 config()->SetConnectionTypeForTesting(
1607 net::NetworkChangeNotifier::ConnectionType::CONNECTION_WIFI);
1608 EXPECT_FALSE(config()->ShouldAcceptServerLoFi(*request.get(),
1609 *previews_decider.get()));
1610
1611 // Verify true for Cellular Only flag and 3G connection.
1612 config()->SetConnectionTypeForTesting(
1613 net::NetworkChangeNotifier::ConnectionType::CONNECTION_3G);
1614 EXPECT_TRUE(config()->ShouldAcceptServerLoFi(*request.get(),
1615 *previews_decider.get()));
1616
1617 // Verify true for field trial.
1618 {
1619 base::CommandLine::ForCurrentProcess()->InitFromArgv(0, NULL);
1620 base::FieldTrialList field_trial_list(nullptr);
1621 base::FieldTrialList::CreateFieldTrial(params::GetLoFiFieldTrialName(),
1622 "Enabled");
1623 EXPECT_TRUE(config()->ShouldAcceptServerLoFi(*request.get(),
1624 *previews_decider.get()));
1625 }
1626
1627 // Verify false for control field trial.
1628 {
1629 base::CommandLine::ForCurrentProcess()->InitFromArgv(0, NULL);
1630 base::FieldTrialList field_trial_list(nullptr);
1631 base::FieldTrialList::CreateFieldTrial(params::GetLoFiFieldTrialName(),
1632 "Control");
1633 EXPECT_FALSE(config()->ShouldAcceptServerLoFi(*request.get(),
1634 *previews_decider.get()));
1635 }
1636
1637 // Verify PreviewsDecider check.
1638 {
1639 base::CommandLine::ForCurrentProcess()->InitFromArgv(0, NULL);
1640 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII(
1641 switches::kDataReductionProxyLoFi,
1642 switches::kDataReductionProxyLoFiValueAlwaysOn);
1643 base::FieldTrialList field_trial_list(nullptr);
1644 base::FieldTrialList::CreateFieldTrial(
1645 "DataReductionProxyPreviewsBlackListTransition", "Enabled");
1646 EXPECT_FALSE(config()->ShouldAcceptServerLoFi(*request.get(),
1647 *previews_decider.get()));
1648 previews_decider = base::MakeUnique<TestPreviewsDecider>(true);
1649 EXPECT_TRUE(config()->ShouldAcceptServerLoFi(*request.get(),
1650 *previews_decider.get()));
1651 }
1652 }
1653
1654 TEST_F(DataReductionProxyConfigTest, ShouldAcceptLitePages) {
1655 // Turn on proxy-decides-transform feature to satisfy DCHECK.
1656 base::test::ScopedFeatureList scoped_feature_list;
1657 scoped_feature_list.InitAndEnableFeature(
1658 features::kDataReductionProxyDecidesTransform);
1659
1660 net::TestURLRequestContext context_;
1661 net::TestDelegate delegate_;
1662 std::unique_ptr<net::URLRequest> request = context_.CreateRequest(
1663 GURL(), net::IDLE, &delegate_, TRAFFIC_ANNOTATION_FOR_TESTS);
1664 request->SetLoadFlags(request->load_flags() |
1665 net::LOAD_MAIN_FRAME_DEPRECATED);
1666 std::unique_ptr<TestPreviewsDecider> previews_decider =
1667 base::MakeUnique<TestPreviewsDecider>(false);
1668
1669 // Verify false for no flags.
1670 EXPECT_FALSE(
1671 config()->ShouldAcceptLitePages(*request.get(), *previews_decider.get()));
1672
1673 // Verify true for Always-On flag and LitePage flag.
1674 base::CommandLine::ForCurrentProcess()->InitFromArgv(0, NULL);
1675 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII(
1676 switches::kDataReductionProxyLoFi,
1677 switches::kDataReductionProxyLoFiValueAlwaysOn);
1678 EXPECT_FALSE(
1679 config()->ShouldAcceptLitePages(*request.get(), *previews_decider.get()));
1680 base::CommandLine::ForCurrentProcess()->AppendSwitch(
1681 switches::kEnableDataReductionProxyLitePage);
1682 EXPECT_TRUE(
1683 config()->ShouldAcceptLitePages(*request.get(), *previews_decider.get()));
1684
1685 // Verify true for Slow Connection flag and LitePage flag.
1686 base::CommandLine::ForCurrentProcess()->InitFromArgv(0, NULL);
1687 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII(
1688 switches::kDataReductionProxyLoFi,
1689 switches::kDataReductionProxyLoFiValueSlowConnectionsOnly);
1690 EXPECT_FALSE(
1691 config()->ShouldAcceptLitePages(*request.get(), *previews_decider.get()));
1692 base::CommandLine::ForCurrentProcess()->AppendSwitch(
1693 switches::kEnableDataReductionProxyLitePage);
1694 EXPECT_TRUE(
1695 config()->ShouldAcceptLitePages(*request.get(), *previews_decider.get()));
1696
1697 // Verify true for Cellular Only flag and 3G connection.
1698 base::CommandLine::ForCurrentProcess()->InitFromArgv(0, NULL);
1699 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII(
1700 switches::kDataReductionProxyLoFi,
1701 switches::kDataReductionProxyLoFiValueCellularOnly);
1702 config()->SetConnectionTypeForTesting(
1703 net::NetworkChangeNotifier::ConnectionType::CONNECTION_3G);
1704 EXPECT_FALSE(
1705 config()->ShouldAcceptLitePages(*request.get(), *previews_decider.get()));
1706 base::CommandLine::ForCurrentProcess()->AppendSwitch(
1707 switches::kEnableDataReductionProxyLitePage);
1708 EXPECT_TRUE(
1709 config()->ShouldAcceptLitePages(*request.get(), *previews_decider.get()));
1710
1711 // Verify false for Cellular Only flag and WIFI connection.
1712 config()->SetConnectionTypeForTesting(
1713 net::NetworkChangeNotifier::ConnectionType::CONNECTION_WIFI);
1714 EXPECT_FALSE(
1715 config()->ShouldAcceptLitePages(*request.get(), *previews_decider.get()));
1716
1717 // Verify true for field trial.
1718 {
1719 base::CommandLine::ForCurrentProcess()->InitFromArgv(0, NULL);
1720 base::FieldTrialList field_trial_list(nullptr);
1721 base::FieldTrialList::CreateFieldTrial(params::GetLoFiFieldTrialName(),
1722 "Enabled_Preview");
1723 EXPECT_TRUE(config()->ShouldAcceptLitePages(*request.get(),
1724 *previews_decider.get()));
1725 }
1726
1727 // Verify PreviewsDecider check.
1728 {
1729 base::CommandLine::ForCurrentProcess()->InitFromArgv(0, NULL);
1730 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII(
1731 switches::kDataReductionProxyLoFi,
1732 switches::kDataReductionProxyLoFiValueAlwaysOn);
1733 base::CommandLine::ForCurrentProcess()->AppendSwitch(
1734 switches::kEnableDataReductionProxyLitePage);
1735 base::FieldTrialList field_trial_list(nullptr);
1736 base::FieldTrialList::CreateFieldTrial(
1737 "DataReductionProxyPreviewsBlackListTransition", "Enabled");
1738 EXPECT_FALSE(config()->ShouldAcceptLitePages(*request.get(),
1739 *previews_decider.get()));
1740 previews_decider = base::MakeUnique<TestPreviewsDecider>(true);
1741 EXPECT_TRUE(config()->ShouldAcceptLitePages(*request.get(),
1742 *previews_decider.get()));
1743 }
1744 }
1745
1397 } // namespace data_reduction_proxy 1746 } // namespace data_reduction_proxy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698