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

Side by Side Diff: chrome/browser/predictors/resource_prefetch_common_unittest.cc

Issue 2729563002: predictors: Disable URL-based learning by default. (Closed)
Patch Set: Created 3 years, 9 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 <memory> 5 #include <memory>
6 #include <string> 6 #include <string>
7 7
8 #include "base/command_line.h"
9 #include "base/memory/ptr_util.h" 8 #include "base/memory/ptr_util.h"
10 #include "base/message_loop/message_loop.h" 9 #include "base/message_loop/message_loop.h"
11 #include "chrome/browser/net/prediction_options.h" 10 #include "chrome/browser/net/prediction_options.h"
12 #include "chrome/browser/predictors/resource_prefetch_common.h" 11 #include "chrome/browser/predictors/resource_prefetch_common.h"
13 #include "chrome/browser/predictors/resource_prefetch_predictor.h" 12 #include "chrome/browser/predictors/resource_prefetch_predictor.h"
14 #include "chrome/browser/profiles/profile.h" 13 #include "chrome/browser/profiles/profile.h"
15 #include "chrome/common/pref_names.h" 14 #include "chrome/common/pref_names.h"
16 #include "chrome/test/base/testing_profile.h" 15 #include "chrome/test/base/testing_profile.h"
17 #include "components/prefs/pref_service.h" 16 #include "components/prefs/pref_service.h"
18 #include "components/variations/variations_params_manager.h" 17 #include "components/variations/variations_params_manager.h"
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
85 profile_(new TestingProfile()) { } 84 profile_(new TestingProfile()) { }
86 85
87 TEST_F(ResourcePrefetchCommonTest, IsDisabledByDefault) { 86 TEST_F(ResourcePrefetchCommonTest, IsDisabledByDefault) {
88 ResourcePrefetchPredictorConfig config; 87 ResourcePrefetchPredictorConfig config;
89 EXPECT_FALSE( 88 EXPECT_FALSE(
90 IsSpeculativeResourcePrefetchingEnabled(profile_.get(), &config)); 89 IsSpeculativeResourcePrefetchingEnabled(profile_.get(), &config));
91 90
92 EXPECT_FALSE(config.IsLearningEnabled()); 91 EXPECT_FALSE(config.IsLearningEnabled());
93 EXPECT_FALSE(config.IsPrefetchingEnabledForOrigin(profile_.get(), 92 EXPECT_FALSE(config.IsPrefetchingEnabledForOrigin(profile_.get(),
94 PrefetchOrigin::EXTERNAL)); 93 PrefetchOrigin::EXTERNAL));
95 EXPECT_FALSE(config.IsLearningEnabled()); 94 EXPECT_FALSE(config.IsPrefetchingEnabledForOrigin(
alexilin 2017/03/01 12:57:57 Second check of the same thing. Looks like a bug.
95 profile_.get(), PrefetchOrigin::NAVIGATION));
96 96
97 TestIsDefaultExtraConfig(config); 97 TestIsDefaultExtraConfig(config);
98 } 98 }
99 99
100 TEST_F(ResourcePrefetchCommonTest, EnableLearning) { 100 TEST_F(ResourcePrefetchCommonTest, EnableLearning) {
101 variations::testing::VariationParamsManager params_manager( 101 variations::testing::VariationParamsManager params_manager(
102 "dummy-trial", {{kModeParamName, kLearningMode}}, 102 "dummy-trial", {{kModeParamName, kLearningMode}},
103 {kSpeculativeResourcePrefetchingFeatureName}); 103 {kSpeculativeResourcePrefetchingFeatureName});
104 104
105 ResourcePrefetchPredictorConfig config; 105 ResourcePrefetchPredictorConfig config;
(...skipping 20 matching lines...) Expand all
126 {kSpeculativeResourcePrefetchingFeatureName}); 126 {kSpeculativeResourcePrefetchingFeatureName});
127 127
128 ResourcePrefetchPredictorConfig config; 128 ResourcePrefetchPredictorConfig config;
129 EXPECT_TRUE(IsSpeculativeResourcePrefetchingEnabled(profile_.get(), &config)); 129 EXPECT_TRUE(IsSpeculativeResourcePrefetchingEnabled(profile_.get(), &config));
130 TestIsPrefetchEnabledForOrigin(config, PrefetchOrigin::EXTERNAL); 130 TestIsPrefetchEnabledForOrigin(config, PrefetchOrigin::EXTERNAL);
131 EXPECT_FALSE(config.IsPrefetchingEnabledForOrigin( 131 EXPECT_FALSE(config.IsPrefetchingEnabledForOrigin(
132 profile_.get(), PrefetchOrigin::NAVIGATION)); 132 profile_.get(), PrefetchOrigin::NAVIGATION));
133 TestIsDefaultExtraConfig(config); 133 TestIsDefaultExtraConfig(config);
134 } 134 }
135 135
136 TEST_F(ResourcePrefetchCommonTest, EnableUrlLearning) {
137 variations::testing::VariationParamsManager params_manager(
138 "dummy-trial",
139 {{kModeParamName, kLearningMode}, {kKeyTypeParamName, kUrlKeyType}},
140 {kSpeculativeResourcePrefetchingFeatureName});
141
142 ResourcePrefetchPredictorConfig config;
143 EXPECT_TRUE(IsSpeculativeResourcePrefetchingEnabled(profile_.get(), &config));
144 TestIsPrefetchLearning(config);
145 EXPECT_TRUE(config.IsURLLearningEnabled());
146 EXPECT_FALSE(config.IsHostLearningEnabled());
147 TestIsDefaultExtraConfig(config);
148 }
149
150 TEST_F(ResourcePrefetchCommonTest, EnableHostLearning) {
151 variations::testing::VariationParamsManager params_manager(
152 "dummy-trial",
153 {{kModeParamName, kLearningMode}, {kKeyTypeParamName, kHostKeyType}},
154 {kSpeculativeResourcePrefetchingFeatureName});
155
156 ResourcePrefetchPredictorConfig config;
157 EXPECT_TRUE(IsSpeculativeResourcePrefetchingEnabled(profile_.get(), &config));
158 TestIsPrefetchLearning(config);
159 EXPECT_FALSE(config.IsURLLearningEnabled());
160 EXPECT_TRUE(config.IsHostLearningEnabled());
161 TestIsDefaultExtraConfig(config);
162 }
163
164 TEST_F(ResourcePrefetchCommonTest, EnableBothLearning) {
165 variations::testing::VariationParamsManager params_manager(
166 "dummy-trial",
167 {{kModeParamName, kLearningMode}, {kKeyTypeParamName, kBothKeyType}},
168 {kSpeculativeResourcePrefetchingFeatureName});
169
170 ResourcePrefetchPredictorConfig config;
171 EXPECT_TRUE(IsSpeculativeResourcePrefetchingEnabled(profile_.get(), &config));
172 TestIsPrefetchLearning(config);
173 EXPECT_TRUE(config.IsURLLearningEnabled());
174 EXPECT_TRUE(config.IsHostLearningEnabled());
175 TestIsDefaultExtraConfig(config);
176 }
177
136 // Verifies whether prefetching is disabled according to the network type. But 178 // Verifies whether prefetching is disabled according to the network type. But
137 // learning should not be disabled by network. 179 // learning should not be disabled by network.
138 TEST_F(ResourcePrefetchCommonTest, RespectsNetworkSettings) { 180 TEST_F(ResourcePrefetchCommonTest, RespectsNetworkSettings) {
139 variations::testing::VariationParamsManager params_manager( 181 variations::testing::VariationParamsManager params_manager(
140 "dummy-trial", {{kModeParamName, kPrefetchingMode}}, 182 "dummy-trial", {{kModeParamName, kPrefetchingMode}},
141 {kSpeculativeResourcePrefetchingFeatureName}); 183 {kSpeculativeResourcePrefetchingFeatureName});
142 184
143 ResourcePrefetchPredictorConfig config; 185 ResourcePrefetchPredictorConfig config;
144 EXPECT_TRUE(IsSpeculativeResourcePrefetchingEnabled(profile_.get(), &config)); 186 EXPECT_TRUE(IsSpeculativeResourcePrefetchingEnabled(profile_.get(), &config));
145 TestIsPrefetchEnabledForOrigin(config, PrefetchOrigin::EXTERNAL); 187 TestIsPrefetchEnabledForOrigin(config, PrefetchOrigin::EXTERNAL);
(...skipping 20 matching lines...) Expand all
166 TestIsPrefetchLearning(config); 208 TestIsPrefetchLearning(config);
167 } 209 }
168 { 210 {
169 std::unique_ptr<NetworkChangeNotifier> mock( 211 std::unique_ptr<NetworkChangeNotifier> mock(
170 new MockNetworkChangeNotifier4G); 212 new MockNetworkChangeNotifier4G);
171 TestIsPrefetchLearning(config); 213 TestIsPrefetchLearning(config);
172 } 214 }
173 } 215 }
174 216
175 } // namespace predictors 217 } // namespace predictors
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698