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

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

Issue 2802843003: Update CPAT protocol to send lite-page transform acceptance with ect
Patch Set: Merge with testLitePageBTF 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>
(...skipping 792 matching lines...) Expand 10 before | Expand all | Expand 10 after
803 EXPECT_EQ(test.expected_result, 803 EXPECT_EQ(test.expected_result,
804 config->IsDataReductionProxy(test.proxy_server.proxy_server(), 804 config->IsDataReductionProxy(test.proxy_server.proxy_server(),
805 &proxy_type_info)); 805 &proxy_type_info));
806 EXPECT_EQ(proxy_type_info.proxy_servers, 806 EXPECT_EQ(proxy_type_info.proxy_servers,
807 DataReductionProxyServer::ConvertToNetProxyServers( 807 DataReductionProxyServer::ConvertToNetProxyServers(
808 test.expected_proxies)); 808 test.expected_proxies));
809 EXPECT_EQ(test.expected_proxy_index, proxy_type_info.proxy_index); 809 EXPECT_EQ(test.expected_proxy_index, proxy_type_info.proxy_index);
810 } 810 }
811 } 811 }
812 812
813 TEST_F(DataReductionProxyConfigTest, LoFiOn) { 813 TEST_F(DataReductionProxyConfigTest, ShouldEnableLoFi) {
bengr 2017/05/01 16:53:14 Would you mind breaking each one of these cases ou
814 const struct { 814 const struct {
815 bool lofi_switch_enabled; 815 const char* lofi_switch;
816 const std::string lofi_field_trial_group_name; 816 const std::string lofi_field_trial_group_name;
817 bool network_prohibitively_slow; 817 bool has_cellular_connection;
818 bool expect_lofi_header; 818 bool has_slow_connection;
819 int bucket_to_check_for_auto_lofi_uma; 819 bool supports_fallback;
820 int expect_bucket_count; 820 bool expect_enabled;
821 } tests[] = { 821 } tests[] = {
822 { 822 {
823 // The Lo-Fi switch is off and the user is not in the enabled field 823 // No Lo-Fi switch is set and the user is not in an enabled field
824 // trial group. Lo-Fi should not be used. 824 // trial group. Lo-Fi should not be used.
825 false, std::string(), false, false, 0, 825 nullptr, std::string(), true, true, true, false,
bengr 2017/05/01 16:53:14 #include <string>
826 0, // not in enabled field trial, UMA is not recorded
827 }, 826 },
828 { 827 {
829 // The Lo-Fi switch is off and the user is not in enabled field trial 828 // Lo-Fi is disabled through command line switch is off and the user
bengr 2017/05/01 16:53:14 I can't parse. Do you mean "switch being off?"
830 // group and the network quality is bad. Lo-Fi should not be used. 829 // is also in an enabled field trial group. Lo-Fi should not be used.
831 false, std::string(), true, false, 0, 830 switches::kDataReductionProxyLoFiValueDisabled, "Enabled", false,
832 0, // not in enabled field trial, UMA is not recorded 831 true, true, false,
833 }, 832 },
834 { 833 {
835 // Lo-Fi is enabled through command line switch. LoFi should be used. 834 // Lo-Fi is enabled through command line switch. LoFi should be used.
836 true, std::string(), false, true, 0, 835 switches::kDataReductionProxyLoFiValueAlwaysOn, std::string(), false,
837 0, // not in enabled field trial, UMA is not recorded 836 false, false, true,
838 }, 837 },
839 { 838 {
840 // The user is in the enabled field trial group but the network 839 // Lo-Fi on cellular through command line switch with cellular
841 // quality is not bad. Lo-Fi should not be used. 840 // connection. LoFi should be used.
842 false, "Enabled", false, false, 841 switches::kDataReductionProxyLoFiValueCellularOnly, std::string(),
843 0, // Lo-Fi request header is not used (state change: empty to empty) 842 true /* cell connection */, false, false, true,
844 1,
845 }, 843 },
846 { 844 {
847 // The user is in the enabled field trial group but the network 845 // Lo-Fi on cellular through command line switch without cellular
848 // quality is not bad. Lo-Fi should not be used. 846 // connection. LoFi should not be used.
849 false, "Enabled_Control", false, false, 847 switches::kDataReductionProxyLoFiValueCellularOnly, std::string(),
850 0, // Lo-Fi request header is not used (state change: empty to empty) 848 false /* cell connection */, true, true, false,
851 1,
852 }, 849 },
853 { 850 {
854 // The user is in the enabled field trial group and the network 851 // Experimental field trial group enabled. Lo-Fi should be used.
855 // quality is bad. Lo-Fi should be used. 852 nullptr, "Enabled", false, true /* slow connection */, false, true,
856 false, "Enabled", true, true,
857 1, // Lo-Fi request header is now used (state change: empty to low)
858 1,
859 }, 853 },
860 { 854 {
861 // The user is in the enabled field trial group and the network 855 // Experimental field trial group enabled but not slow connection.
862 // quality is bad. Lo-Fi should be used. 856 nullptr, "Enabled", false, false /* slow connection */, false, false,
863 false, "Enabled_Control", true, true,
864 3, // Lo-Fi request header is now used (state change: low to low)
865 1,
866 }, 857 },
867 { 858 {
868 // The user is in the enabled field trial group and the network 859 // Control field trial group enabled. Lo-Fi should not be used.
869 // quality is bad. Lo-Fi should be used again. 860 nullptr, "Control", false, true, false, false,
870 false, "Enabled", true, true,
871 3, // Lo-Fi request header is now used (state change: low to low)
872 1,
873 }, 861 },
874 { 862 {
875 // The user is in the enabled field trial group and the network 863 // Lo-Fi is enabled through command line switch for slow connections
876 // quality is bad. Lo-Fi should be used again. 864 // only. LoFi should be used for slow connection.
877 false, "Enabled_Control", true, true, 865 switches::kDataReductionProxyLoFiValueSlowConnectionsOnly,
878 3, // Lo-Fi request header is now used (state change: low to low) 866 std::string(), false, true /* slow connection */, false, true,
879 1,
880 }, 867 },
881 { 868 {
882 // The user is in the enabled field trial group but the network 869 // Lo-Fi is enabled through command line switch for slow connections
883 // quality is not bad. Lo-Fi should not be used. 870 // only. LoFi should be not used for non-slow connection.
884 false, "Enabled", false, false, 871 switches::kDataReductionProxyLoFiValueSlowConnectionsOnly,
885 2, // Lo-Fi request header is not used (state change: low to empty) 872 std::string(), false, false /* slow connection */, false, false,
886 1,
887 }, 873 },
888 { 874 {
889 // The user is in the enabled field trial group but the network 875 // LitePage fallback support enables Lo-Fi. LoFi should be used
bengr 2017/05/01 16:53:14 Is it Lo-Fi or LoFi?
890 // quality is not bad. Lo-Fi should not be used. 876 // for slow connection.
891 false, "Enabled_Control", false, false, 877 nullptr, "Enabled_Preview" /* kLitePage */, true,
892 0, // Lo-Fi request header is not used (state change: empty to empty) 878 true /* slow connection */, true, true,
893 1, 879 },
880 {
881 // LitePage fallback support enables Lo-Fi. LoFi should be not used
882 // for non-slow connection.
883 nullptr, "Enabled_Preview" /* kLitePage */, true,
884 false /* slow connection */, true, false,
894 }, 885 },
895 }; 886 };
896 for (size_t i = 0; i < arraysize(tests); ++i) { 887 for (size_t i = 0; i < arraysize(tests); ++i) {
888 base::CommandLine::ForCurrentProcess()->InitFromArgv(0, NULL);
897 config()->ResetLoFiStatusForTest(); 889 config()->ResetLoFiStatusForTest();
898 if (tests[i].lofi_switch_enabled) { 890 if (tests[i].lofi_switch) {
899 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII( 891 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII(
900 switches::kDataReductionProxyLoFi, 892 switches::kDataReductionProxyLoFi, tests[i].lofi_switch);
901 switches::kDataReductionProxyLoFiValueAlwaysOn);
902 } else { 893 } else {
903 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII( 894 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII(
904 switches::kDataReductionProxyLoFi, std::string()); 895 switches::kDataReductionProxyLoFi, std::string());
905 } 896 }
906 897
898 config()->SetConnectionTypeForTesting(
899 tests[i].has_cellular_connection
900 ? net::NetworkChangeNotifier::ConnectionType::CONNECTION_2G
901 : net::NetworkChangeNotifier::ConnectionType::CONNECTION_WIFI);
902
907 base::FieldTrialList field_trial_list(nullptr); 903 base::FieldTrialList field_trial_list(nullptr);
908 if (!tests[i].lofi_field_trial_group_name.empty()) { 904 if (!tests[i].lofi_field_trial_group_name.empty()) {
909 base::FieldTrialList::CreateFieldTrial( 905 base::FieldTrialList::CreateFieldTrial(
910 params::GetLoFiFieldTrialName(), 906 params::GetLoFiFieldTrialName(),
911 tests[i].lofi_field_trial_group_name); 907 tests[i].lofi_field_trial_group_name);
912 } 908 }
913 909
914 EXPECT_CALL(*config(), IsNetworkQualityProhibitivelySlow(_)) 910 config()->SetNetworkProhibitivelySlow(tests[i].has_slow_connection);
915 .WillRepeatedly(testing::Return(tests[i].network_prohibitively_slow));
916 911
917 base::HistogramTester histogram_tester; 912 if (tests[i].supports_fallback) {
913 base::FieldTrialList::CreateFieldTrial(
914 params::GetLitePageFallbackFieldTrialName(), "Enabled");
915 }
916
918 net::TestURLRequestContext context_; 917 net::TestURLRequestContext context_;
919 net::TestDelegate delegate_; 918 net::TestDelegate delegate_;
920 std::unique_ptr<net::URLRequest> request = context_.CreateRequest( 919 std::unique_ptr<net::URLRequest> request = context_.CreateRequest(
921 GURL(), net::IDLE, &delegate_, TRAFFIC_ANNOTATION_FOR_TESTS); 920 GURL(), net::IDLE, &delegate_, TRAFFIC_ANNOTATION_FOR_TESTS);
922 request->SetLoadFlags(request->load_flags() | 921 request->SetLoadFlags(request->load_flags() |
923 net::LOAD_MAIN_FRAME_DEPRECATED); 922 net::LOAD_MAIN_FRAME_DEPRECATED);
923
924 bool should_enable_lofi = config()->ShouldEnableLoFi(*request.get()); 924 bool should_enable_lofi = config()->ShouldEnableLoFi(*request.get());
925 if (tests[i].expect_bucket_count != 0) {
926 histogram_tester.ExpectBucketCount(
927 "DataReductionProxy.AutoLoFiRequestHeaderState.Unknown",
928 tests[i].bucket_to_check_for_auto_lofi_uma,
929 tests[i].expect_bucket_count);
930 }
931 925
932 EXPECT_EQ(tests[i].expect_lofi_header, should_enable_lofi) << i; 926 EXPECT_EQ(tests[i].expect_enabled, should_enable_lofi) << i;
933 } 927 }
934 } 928 }
935 929
936 TEST_F(DataReductionProxyConfigTest, AutoLoFiParams) { 930 TEST_F(DataReductionProxyConfigTest, ShouldEnableLitePages) {
bengr 2017/05/01 16:53:14 Likewise, please break out into separate tests.
937 DataReductionProxyConfig config(task_runner(), nullptr, nullptr,
938 configurator(), event_creator());
939 variations::testing::ClearAllVariationParams();
940 std::map<std::string, std::string> variation_params;
941 std::map<std::string, std::string> variation_params_flag;
942
943 variation_params["effective_connection_type"] = "Slow2G";
944 variation_params_flag["effective_connection_type"] = "2G";
945
946 variation_params["hysteresis_period_seconds"] = "360";
947 variation_params_flag["hysteresis_period_seconds"] = "361";
948
949 variation_params["spurious_field"] = "480";
950 variation_params_flag["spurious_field"] = "481";
951
952 ASSERT_TRUE(variations::AssociateVariationParams(
953 params::GetLoFiFieldTrialName(), "Enabled", variation_params));
954
955 ASSERT_TRUE(variations::AssociateVariationParams(
956 params::GetLoFiFlagFieldTrialName(), "Enabled", variation_params_flag));
957
958 base::FieldTrialList field_trial_list(nullptr);
959 base::FieldTrialList::CreateFieldTrial(params::GetLoFiFieldTrialName(),
960 "Enabled");
961 base::FieldTrialList::CreateFieldTrial(params::GetLoFiFlagFieldTrialName(),
962 "Enabled");
963
964 scoped_refptr<net::URLRequestContextGetter> request_context_getter =
965 new net::TestURLRequestContextGetter(task_runner());
966 config.InitializeOnIOThread(request_context_getter.get(),
967 request_context_getter.get());
968
969 const struct { 931 const struct {
970 bool lofi_flag_group; 932 bool lite_page_switch;
971 933 const char* lofi_switch;
934 const std::string lite_page_field_trial_group_name;
935 bool has_cellular_connection;
936 bool expect_enabled;
972 } tests[] = { 937 } tests[] = {
973 { 938 {
974 false, 939 // No Lo-Fi switch is set and the user is not in an enabled field
940 // trial group. Lo-Fi should not be used.
941 true, nullptr, std::string(), false, false,
975 }, 942 },
976 { 943 {
977 true, 944 // Lo-Fi is disabled through command line switch is off and the user
945 // is also in an enabled field trial group. Lo-Fi should not be used.
946 false, switches::kDataReductionProxyLoFiValueDisabled, "Enabled",
947 false, false,
948 },
949 {
950 // Lo-Fi is enabled through command line switch. LoFi should be used.
951 true, switches::kDataReductionProxyLoFiValueAlwaysOn, std::string(),
952 false, true,
953 },
954 {
955 // Lite Pages enabled with Lo-Fi enabled for cellular with cellular
956 // connection. LoFi should be used.
957 true, switches::kDataReductionProxyLoFiValueCellularOnly,
958 std::string(), true, true,
959 },
960 {
961 // Lite Pages not enabled with Lo-Fi enabled for cellular with
962 // cellular connection. LoFi should not be used.
963 false, switches::kDataReductionProxyLoFiValueCellularOnly,
964 std::string(), true, false,
965 },
966 {
967 // Lite Pages enabled with Lo-Fi enabled for cellular but no
968 // cellular connection. LoFi should not be used.
969 true, switches::kDataReductionProxyLoFiValueCellularOnly,
970 std::string(), false, false,
971 },
972 {
973 // Experimental field trial group enabled for lite page. Lo-Fi should
974 // be used.
975 false, nullptr, "Enabled_Preview" /* kLitePage */, false, true,
976 },
977 {
978 // Control field trial group enabled. Lo-Fi should not be used.
979 false, nullptr, "Control" /* kControl */, false, false,
980 },
981 {
982 // Lo-Fi is enabled through command line switch. LoFi
983 // should be used.
984 true, switches::kDataReductionProxyLoFiValueSlowConnectionsOnly,
985 std::string(), false, true,
978 }, 986 },
979 }; 987 };
980
981 for (size_t i = 0; i < arraysize(tests); ++i) { 988 for (size_t i = 0; i < arraysize(tests); ++i) {
982 net::EffectiveConnectionType expected_effective_connection_type = 989 base::CommandLine::ForCurrentProcess()->InitFromArgv(0, NULL);
bengr 2017/05/01 16:53:14 You can put all of this stuff into a test helper.
983 net::EFFECTIVE_CONNECTION_TYPE_SLOW_2G; 990 config()->ResetLoFiStatusForTest();
984 int expected_hysteresis_sec = 360; 991 if (tests[i].lofi_switch) {
985
986 if (tests[i].lofi_flag_group) {
987 // LoFi flag field trial has higher priority than LoFi field trial.
988 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII( 992 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII(
989 switches::kDataReductionProxyLoFi, 993 switches::kDataReductionProxyLoFi, tests[i].lofi_switch);
990 switches::kDataReductionProxyLoFiValueSlowConnectionsOnly); 994 } else {
991 expected_effective_connection_type = net::EFFECTIVE_CONNECTION_TYPE_2G; 995 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII(
992 expected_hysteresis_sec = 361; 996 switches::kDataReductionProxyLoFi, std::string());
993 } 997 }
994 998
995 config.PopulateAutoLoFiParams(); 999 if (tests[i].lite_page_switch) {
1000 base::CommandLine::ForCurrentProcess()->AppendSwitch(
1001 switches::kEnableDataReductionProxyLitePage);
1002 }
996 1003
997 EXPECT_EQ(expected_effective_connection_type, 1004 config()->SetConnectionTypeForTesting(
998 config.lofi_effective_connection_type_threshold_); 1005 tests[i].has_cellular_connection
999 EXPECT_EQ(base::TimeDelta::FromSeconds(expected_hysteresis_sec), 1006 ? net::NetworkChangeNotifier::ConnectionType::CONNECTION_2G
1000 config.auto_lofi_hysteresis_); 1007 : net::NetworkChangeNotifier::ConnectionType::CONNECTION_WIFI);
1001 1008
1002 net::TestNetworkQualityEstimator test_network_quality_estimator; 1009 base::FieldTrialList field_trial_list(nullptr);
1010 if (!tests[i].lite_page_field_trial_group_name.empty()) {
1011 base::FieldTrialList::CreateFieldTrial(
1012 params::GetLoFiFieldTrialName(),
1013 tests[i].lite_page_field_trial_group_name);
1014 }
1003 1015
1004 // Network is slow. 1016 net::TestURLRequestContext context_;
1005 test_network_quality_estimator.set_effective_connection_type( 1017 net::TestDelegate delegate_;
1006 expected_effective_connection_type); 1018 std::unique_ptr<net::URLRequest> request =
1007 EXPECT_TRUE(config.IsNetworkQualityProhibitivelySlow( 1019 context_.CreateRequest(GURL(), net::IDLE, &delegate_);
1008 &test_network_quality_estimator)); 1020 request->SetLoadFlags(request->load_flags() |
1021 net::LOAD_MAIN_FRAME_DEPRECATED);
1022 bool should_enable_lite_page =
1023 config()->ShouldEnableLitePages(*request.get());
1009 1024
1010 // Network quality improved. However, network should still be marked as slow 1025 EXPECT_EQ(tests[i].expect_enabled, should_enable_lite_page) << i;
1011 // because of hysteresis.
1012 test_network_quality_estimator.set_effective_connection_type(
1013 net::EFFECTIVE_CONNECTION_TYPE_4G);
1014 EXPECT_TRUE(config.IsNetworkQualityProhibitivelySlow(
1015 &test_network_quality_estimator));
1016
1017 // Change the last update time to be older than the hysteresis duration.
1018 // Checking network quality afterwards should show that network is no longer
1019 // slow.
1020 config.network_quality_last_checked_ =
1021 base::TimeTicks::Now() -
1022 base::TimeDelta::FromSeconds(expected_hysteresis_sec + 1);
1023 EXPECT_FALSE(config.IsNetworkQualityProhibitivelySlow(
1024 &test_network_quality_estimator));
1025
1026 // Changing the network quality has no effect because of hysteresis.
1027 test_network_quality_estimator.set_effective_connection_type(
1028 expected_effective_connection_type);
1029 EXPECT_FALSE(config.IsNetworkQualityProhibitivelySlow(
1030 &test_network_quality_estimator));
1031
1032 // Change in connection type changes the network quality despite hysteresis.
1033 EXPECT_FALSE(config.connection_type_changed_);
1034 net::NetworkChangeNotifier::NotifyObserversOfConnectionTypeChangeForTests(
1035 net::NetworkChangeNotifier::CONNECTION_WIFI);
1036 RunUntilIdle();
1037
1038 EXPECT_TRUE(config.connection_type_changed_);
1039 EXPECT_TRUE(config.IsNetworkQualityProhibitivelySlow(
1040 &test_network_quality_estimator));
1041 } 1026 }
1042 } 1027 }
1043 1028
1044 // Tests that default parameters for Lo-Fi are used when the parameters from
1045 // field trial are missing.
1046 TEST_F(DataReductionProxyConfigTest, AutoLoFiMissingParams) {
1047 DataReductionProxyConfig config(task_runner(), nullptr, nullptr,
1048 configurator(), event_creator());
1049 variations::testing::ClearAllVariationParams();
1050 std::map<std::string, std::string> variation_params;
1051 variation_params["spurious_field"] = "480";
1052
1053 ASSERT_TRUE(variations::AssociateVariationParams(
1054 params::GetLoFiFieldTrialName(), "Enabled", variation_params));
1055
1056 base::FieldTrialList field_trial_list(nullptr);
1057 base::FieldTrialList::CreateFieldTrial(params::GetLoFiFieldTrialName(),
1058 "Enabled");
1059
1060 config.PopulateAutoLoFiParams();
1061
1062 EXPECT_EQ(net::EFFECTIVE_CONNECTION_TYPE_SLOW_2G,
1063 config.lofi_effective_connection_type_threshold_);
1064 EXPECT_EQ(base::TimeDelta::FromSeconds(60), config.auto_lofi_hysteresis_);
1065 }
1066
1067 TEST_F(DataReductionProxyConfigTest, AutoLoFiParamsSlowConnectionsFlag) {
1068 DataReductionProxyConfig config(task_runner(), nullptr, nullptr,
1069 configurator(), event_creator());
1070 variations::testing::ClearAllVariationParams();
1071
1072 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII(
1073 switches::kDataReductionProxyLoFi,
1074 switches::kDataReductionProxyLoFiValueSlowConnectionsOnly);
1075 scoped_refptr<net::URLRequestContextGetter> request_context_getter =
1076 new net::TestURLRequestContextGetter(task_runner());
1077 config.InitializeOnIOThread(request_context_getter.get(),
1078 request_context_getter.get());
1079
1080 config.PopulateAutoLoFiParams();
1081
1082 net::EffectiveConnectionType expected_effective_connection_type =
1083 net::EffectiveConnectionType::EFFECTIVE_CONNECTION_TYPE_SLOW_2G;
1084 int hysteresis_sec = 60;
1085 EXPECT_EQ(expected_effective_connection_type,
1086 config.lofi_effective_connection_type_threshold_);
1087 EXPECT_EQ(base::TimeDelta::FromSeconds(hysteresis_sec),
1088 config.auto_lofi_hysteresis_);
1089
1090 net::TestNetworkQualityEstimator test_network_quality_estimator;
1091
1092 // Network is slow.
1093 test_network_quality_estimator.set_effective_connection_type(
1094 net::EFFECTIVE_CONNECTION_TYPE_SLOW_2G);
1095 EXPECT_TRUE(config.IsNetworkQualityProhibitivelySlow(
1096 &test_network_quality_estimator));
1097
1098 // Network quality improved. However, network should still be marked as slow
1099 // because of hysteresis.
1100 test_network_quality_estimator.set_effective_connection_type(
1101 net::EFFECTIVE_CONNECTION_TYPE_2G);
1102 EXPECT_TRUE(config.IsNetworkQualityProhibitivelySlow(
1103 &test_network_quality_estimator));
1104
1105 // Change the last update time to be older than the hysteresis duration.
1106 // Checking network quality afterwards should show that network is no longer
1107 // slow.
1108 config.network_quality_last_checked_ =
1109 base::TimeTicks::Now() - base::TimeDelta::FromSeconds(hysteresis_sec + 1);
1110 EXPECT_FALSE(config.IsNetworkQualityProhibitivelySlow(
1111 &test_network_quality_estimator));
1112
1113 // Changing the network quality has no effect because of hysteresis.
1114 test_network_quality_estimator.set_effective_connection_type(
1115 net::EFFECTIVE_CONNECTION_TYPE_SLOW_2G);
1116 EXPECT_FALSE(config.IsNetworkQualityProhibitivelySlow(
1117 &test_network_quality_estimator));
1118
1119 // Change in connection type changes the network quality despite hysteresis.
1120 EXPECT_FALSE(config.connection_type_changed_);
1121 net::NetworkChangeNotifier::NotifyObserversOfConnectionTypeChangeForTests(
1122 net::NetworkChangeNotifier::CONNECTION_WIFI);
1123 RunUntilIdle();
1124
1125 EXPECT_TRUE(config.connection_type_changed_);
1126 EXPECT_TRUE(config.IsNetworkQualityProhibitivelySlow(
1127 &test_network_quality_estimator));
1128 }
1129
1130 // Tests if metrics for Lo-Fi accuracy are recorded properly.
1131 TEST_F(DataReductionProxyConfigTest, LoFiAccuracy) {
1132 std::unique_ptr<base::SimpleTestTickClock> tick_clock(
1133 new base::SimpleTestTickClock());
1134
1135 std::vector<base::TimeDelta> lofi_accuracy_recording_intervals;
1136 lofi_accuracy_recording_intervals.push_back(base::TimeDelta::FromSeconds(0));
1137
1138 TestDataReductionProxyConfig config(
1139 0, TestDataReductionProxyParams::HAS_EVERYTHING, task_runner(), nullptr,
1140 configurator(), event_creator());
1141 config.SetLofiAccuracyRecordingIntervals(lofi_accuracy_recording_intervals);
1142 config.SetTickClock(tick_clock.get());
1143
1144 variations::testing::ClearAllVariationParams();
1145 std::map<std::string, std::string> variation_params;
1146
1147 int expected_hysteresis_sec = 360;
1148
1149 variation_params["effective_connection_type"] = "Slow2G";
1150 variation_params["hysteresis_period_seconds"] =
1151 base::IntToString(expected_hysteresis_sec);
1152
1153 const struct {
1154 std::string description;
1155 std::string field_trial_group;
1156 net::EffectiveConnectionType effective_connection_type;
1157 net::EffectiveConnectionType recent_effective_connection_type;
1158 bool expect_network_quality_slow;
1159 uint32_t bucket_to_check;
1160 uint32_t expected_bucket_count;
1161 } tests[] = {
1162 {"Predicted slow, actually slow, Enabled group", "Enabled",
1163 net::EFFECTIVE_CONNECTION_TYPE_SLOW_2G,
1164 net::EFFECTIVE_CONNECTION_TYPE_SLOW_2G, true, 0, 1},
1165 {"Predicted slow, actually slow, Enabled_NoControl group",
1166 "Enabled_NoControl", net::EFFECTIVE_CONNECTION_TYPE_SLOW_2G,
1167 net::EFFECTIVE_CONNECTION_TYPE_SLOW_2G, true, 0, 1},
1168 {"Predicted slow, actually slow, Control group", "Control",
1169 net::EFFECTIVE_CONNECTION_TYPE_SLOW_2G,
1170 net::EFFECTIVE_CONNECTION_TYPE_SLOW_2G, true, 0, 1},
1171 {"Predicted slow, actually not slow", "Enabled",
1172 net::EFFECTIVE_CONNECTION_TYPE_SLOW_2G,
1173 net::EFFECTIVE_CONNECTION_TYPE_2G, true, 1, 1},
1174 {"Predicted not slow, actually slow", "Enabled",
1175 net::EFFECTIVE_CONNECTION_TYPE_2G,
1176 net::EFFECTIVE_CONNECTION_TYPE_SLOW_2G, false, 2, 1},
1177 {"Predicted not slow, actually not slow", "Enabled",
1178 net::EFFECTIVE_CONNECTION_TYPE_2G, net::EFFECTIVE_CONNECTION_TYPE_2G,
1179 false, 3, 1},
1180 };
1181
1182 for (const auto& test : tests) {
1183 base::FieldTrialList field_trial_list(nullptr);
1184 variations::testing::ClearAllVariationIDs();
1185 variations::testing::ClearAllVariationParams();
1186 ASSERT_TRUE(variations::AssociateVariationParams(
1187 params::GetLoFiFieldTrialName(), test.field_trial_group,
1188 variation_params))
1189 << test.description;
1190
1191 ASSERT_NE(nullptr,
1192 base::FieldTrialList::CreateFieldTrial(
1193 params::GetLoFiFieldTrialName(), test.field_trial_group))
1194 << test.description;
1195 config.PopulateAutoLoFiParams();
1196
1197 net::TestNetworkQualityEstimator test_network_quality_estimator;
1198
1199 base::HistogramTester histogram_tester;
1200 test_network_quality_estimator.set_effective_connection_type(
1201 test.effective_connection_type);
1202 test_network_quality_estimator.set_recent_effective_connection_type(
1203 test.recent_effective_connection_type);
1204 ASSERT_EQ(test.expect_network_quality_slow,
1205 config.IsNetworkQualityProhibitivelySlow(
1206 &test_network_quality_estimator))
1207 << test.description;
1208 RunUntilIdle();
1209 histogram_tester.ExpectTotalCount(
1210 "DataReductionProxy.LoFi.Accuracy.0.Unknown", 1);
1211 histogram_tester.ExpectBucketCount(
1212 "DataReductionProxy.LoFi.Accuracy.0.Unknown", test.bucket_to_check,
1213 test.expected_bucket_count);
1214 }
1215 }
1216
1217 // Tests if metrics for Lo-Fi accuracy are recorded properly at the specified
1218 // interval.
1219 TEST_F(DataReductionProxyConfigTest, LoFiAccuracyNonZeroDelay) {
1220 std::unique_ptr<base::SimpleTestTickClock> tick_clock(
1221 new base::SimpleTestTickClock());
1222
1223 std::vector<base::TimeDelta> lofi_accuracy_recording_intervals;
1224 lofi_accuracy_recording_intervals.push_back(base::TimeDelta::FromSeconds(1));
1225
1226 TestDataReductionProxyConfig config(
1227 0, TestDataReductionProxyParams::HAS_EVERYTHING, task_runner(), nullptr,
1228 configurator(), event_creator());
1229 config.SetLofiAccuracyRecordingIntervals(lofi_accuracy_recording_intervals);
1230 config.SetTickClock(tick_clock.get());
1231
1232 variations::testing::ClearAllVariationParams();
1233 std::map<std::string, std::string> variation_params;
1234
1235 variation_params["effective_connection_type"] = "Slow2G";
1236
1237 ASSERT_TRUE(variations::AssociateVariationParams(
1238 params::GetLoFiFieldTrialName(), "Enabled", variation_params));
1239
1240 base::FieldTrialList field_trial_list(nullptr);
1241 base::FieldTrialList::CreateFieldTrial(params::GetLoFiFieldTrialName(),
1242 "Enabled");
1243 config.PopulateAutoLoFiParams();
1244
1245 net::TestNetworkQualityEstimator test_network_quality_estimator;
1246
1247 base::HistogramTester histogram_tester;
1248 // Network was predicted to be slow and actually was slow.
1249 test_network_quality_estimator.set_effective_connection_type(
1250 net::EFFECTIVE_CONNECTION_TYPE_SLOW_2G);
1251 test_network_quality_estimator.set_recent_effective_connection_type(
1252 net::EFFECTIVE_CONNECTION_TYPE_SLOW_2G);
1253 ASSERT_TRUE(config.IsNetworkQualityProhibitivelySlow(
1254 &test_network_quality_estimator));
1255 tick_clock->Advance(base::TimeDelta::FromSeconds(1));
1256
1257 // Sleep to ensure that the delayed task is posted.
1258 base::PlatformThread::Sleep(base::TimeDelta::FromSeconds(1));
1259 RunUntilIdle();
1260 histogram_tester.ExpectTotalCount(
1261 "DataReductionProxy.LoFi.Accuracy.1.Unknown", 1);
1262 histogram_tester.ExpectBucketCount(
1263 "DataReductionProxy.LoFi.Accuracy.1.Unknown", 0, 1);
1264 }
1265
1266 } // namespace data_reduction_proxy 1029 } // namespace data_reduction_proxy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698