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

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: Added const-ness to PreviewDecider arg 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, 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_;
megjablon 2017/05/22 23:58:57 s/context_/context/
dougarnett 2017/05/23 16:28:45 Done.
1453 net::TestDelegate delegate_;
megjablon 2017/05/22 23:58:57 s/delegate_/delegate
dougarnett 2017/05/23 16:28:45 Done.
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 for Cellular Only flag.
megjablon 2017/05/22 23:58:57 Verify false for Cellular Only flag and WIFI conne
dougarnett 2017/05/23 16:28:45 Done.
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()));
megjablon 2017/05/22 23:58:57 Verify true for Cellular Only flag and 3G connecti
dougarnett 2017/05/23 16:28:45 Done.
1580 config()->SetConnectionTypeForTesting(
1581 net::NetworkChangeNotifier::ConnectionType::CONNECTION_3G);
1582 EXPECT_TRUE(config()->ShouldAcceptServerLoFi(*request.get(),
1583 *previews_decider.get()));
1584
1585 // Verify true for field trial.
1586 {
1587 base::CommandLine::ForCurrentProcess()->InitFromArgv(0, NULL);
1588 base::FieldTrialList field_trial_list(nullptr);
1589 base::FieldTrialList::CreateFieldTrial(params::GetLoFiFieldTrialName(),
1590 "Enabled");
1591 EXPECT_TRUE(config()->ShouldAcceptServerLoFi(*request.get(),
1592 *previews_decider.get()));
1593 }
1594
1595 // Verify false for control field trial.
1596 {
1597 base::CommandLine::ForCurrentProcess()->InitFromArgv(0, NULL);
1598 base::FieldTrialList field_trial_list(nullptr);
1599 base::FieldTrialList::CreateFieldTrial(params::GetLoFiFieldTrialName(),
1600 "Control");
1601 EXPECT_FALSE(config()->ShouldAcceptServerLoFi(*request.get(),
1602 *previews_decider.get()));
1603 }
1604
1605 // Verify PreviewsDecider check.
1606 {
1607 base::CommandLine::ForCurrentProcess()->InitFromArgv(0, NULL);
1608 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII(
1609 switches::kDataReductionProxyLoFi,
1610 switches::kDataReductionProxyLoFiValueAlwaysOn);
1611 base::FieldTrialList field_trial_list(nullptr);
1612 base::FieldTrialList::CreateFieldTrial(
1613 "DataReductionProxyPreviewsBlackListTransition", "Enabled");
1614 EXPECT_FALSE(config()->ShouldAcceptServerLoFi(*request.get(),
1615 *previews_decider.get()));
1616 previews_decider = base::MakeUnique<TestPreviewsDecider>(true);
1617 EXPECT_TRUE(config()->ShouldAcceptServerLoFi(*request.get(),
1618 *previews_decider.get()));
1619 }
1620 }
1621
1622 TEST_F(DataReductionProxyConfigTest, ShouldAcceptLitePages) {
1623 // Turn on proxy-decides-transform feature to satisfy DCHECK.
1624 base::test::ScopedFeatureList scoped_feature_list;
1625 scoped_feature_list.InitAndEnableFeature(
1626 features::kDataReductionProxyDecidesTransform);
1627
1628 net::TestURLRequestContext context_;
1629 net::TestDelegate delegate_;
1630 std::unique_ptr<net::URLRequest> request = context_.CreateRequest(
1631 GURL(), net::IDLE, &delegate_, TRAFFIC_ANNOTATION_FOR_TESTS);
1632 request->SetLoadFlags(request->load_flags() |
1633 net::LOAD_MAIN_FRAME_DEPRECATED);
1634 std::unique_ptr<TestPreviewsDecider> previews_decider =
1635 base::MakeUnique<TestPreviewsDecider>(false);
1636
1637 // Verify false for no flags.
1638 EXPECT_FALSE(
1639 config()->ShouldAcceptLitePages(*request.get(), *previews_decider.get()));
1640
1641 // Verify true for Always-On flag and LitePage flag.
1642 base::CommandLine::ForCurrentProcess()->InitFromArgv(0, NULL);
1643 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII(
1644 switches::kDataReductionProxyLoFi,
1645 switches::kDataReductionProxyLoFiValueAlwaysOn);
1646 EXPECT_FALSE(
1647 config()->ShouldAcceptLitePages(*request.get(), *previews_decider.get()));
1648 base::CommandLine::ForCurrentProcess()->AppendSwitch(
1649 switches::kEnableDataReductionProxyLitePage);
1650 EXPECT_TRUE(
1651 config()->ShouldAcceptLitePages(*request.get(), *previews_decider.get()));
1652
1653 // Verify true for Slow Connection flag and LitePage flag.
1654 base::CommandLine::ForCurrentProcess()->InitFromArgv(0, NULL);
1655 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII(
1656 switches::kDataReductionProxyLoFi,
1657 switches::kDataReductionProxyLoFiValueSlowConnectionsOnly);
1658 EXPECT_FALSE(
1659 config()->ShouldAcceptLitePages(*request.get(), *previews_decider.get()));
1660 base::CommandLine::ForCurrentProcess()->AppendSwitch(
1661 switches::kEnableDataReductionProxyLitePage);
1662 EXPECT_TRUE(
1663 config()->ShouldAcceptLitePages(*request.get(), *previews_decider.get()));
1664
1665 // Verify for Cellular Only flag.
megjablon 2017/05/22 23:58:57 Verify true for Cellular Only flag and 3G connecti
dougarnett 2017/05/23 16:28:45 Done.
1666 base::CommandLine::ForCurrentProcess()->InitFromArgv(0, NULL);
1667 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII(
1668 switches::kDataReductionProxyLoFi,
1669 switches::kDataReductionProxyLoFiValueCellularOnly);
1670 config()->SetConnectionTypeForTesting(
1671 net::NetworkChangeNotifier::ConnectionType::CONNECTION_3G);
1672 EXPECT_FALSE(
1673 config()->ShouldAcceptLitePages(*request.get(), *previews_decider.get()));
1674 base::CommandLine::ForCurrentProcess()->AppendSwitch(
1675 switches::kEnableDataReductionProxyLitePage);
1676 EXPECT_TRUE(
1677 config()->ShouldAcceptLitePages(*request.get(), *previews_decider.get()));
megjablon 2017/05/22 23:58:57 Verify false for Cellular Only flag and WIFI conne
dougarnett 2017/05/23 16:28:45 Done.
1678 config()->SetConnectionTypeForTesting(
1679 net::NetworkChangeNotifier::ConnectionType::CONNECTION_WIFI);
1680 EXPECT_FALSE(
1681 config()->ShouldAcceptLitePages(*request.get(), *previews_decider.get()));
1682
1683 // Verify true for field trial.
1684 {
1685 base::CommandLine::ForCurrentProcess()->InitFromArgv(0, NULL);
1686 base::FieldTrialList field_trial_list(nullptr);
1687 base::FieldTrialList::CreateFieldTrial(params::GetLoFiFieldTrialName(),
1688 "Enabled_Preview");
1689 EXPECT_TRUE(config()->ShouldAcceptLitePages(*request.get(),
1690 *previews_decider.get()));
1691 }
1692
1693 // Verify PreviewsDecider check.
1694 {
1695 base::CommandLine::ForCurrentProcess()->InitFromArgv(0, NULL);
1696 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII(
1697 switches::kDataReductionProxyLoFi,
1698 switches::kDataReductionProxyLoFiValueAlwaysOn);
1699 base::CommandLine::ForCurrentProcess()->AppendSwitch(
1700 switches::kEnableDataReductionProxyLitePage);
1701 base::FieldTrialList field_trial_list(nullptr);
1702 base::FieldTrialList::CreateFieldTrial(
1703 "DataReductionProxyPreviewsBlackListTransition", "Enabled");
1704 EXPECT_FALSE(config()->ShouldAcceptLitePages(*request.get(),
1705 *previews_decider.get()));
1706 previews_decider = base::MakeUnique<TestPreviewsDecider>(true);
1707 EXPECT_TRUE(config()->ShouldAcceptLitePages(*request.get(),
1708 *previews_decider.get()));
1709 }
1710 }
1711
1397 } // namespace data_reduction_proxy 1712 } // namespace data_reduction_proxy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698