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

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

Issue 2847183002: predictors: Introduce GlowplugPredictor. (Closed)
Patch Set: GlowplugPredictor -> LoadingPredictor 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 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/memory/ptr_util.h" 8 #include "base/memory/ptr_util.h"
9 #include "chrome/browser/net/prediction_options.h" 9 #include "chrome/browser/net/prediction_options.h"
10 #include "chrome/browser/predictors/resource_prefetch_common.h" 10 #include "chrome/browser/predictors/resource_prefetch_common.h"
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
42 namespace predictors { 42 namespace predictors {
43 43
44 class ResourcePrefetchCommonTest : public testing::Test { 44 class ResourcePrefetchCommonTest : public testing::Test {
45 public: 45 public:
46 ResourcePrefetchCommonTest(); 46 ResourcePrefetchCommonTest();
47 47
48 void SetPreference(NetworkPredictionOptions value) { 48 void SetPreference(NetworkPredictionOptions value) {
49 profile_->GetPrefs()->SetInteger(prefs::kNetworkPredictionOptions, value); 49 profile_->GetPrefs()->SetInteger(prefs::kNetworkPredictionOptions, value);
50 } 50 }
51 51
52 void TestIsPrefetchEnabledForOrigin( 52 void TestIsPrefetchEnabledForOrigin(const LoadingPredictorConfig& config,
53 const ResourcePrefetchPredictorConfig& config, 53 HintOrigin origin) {
54 PrefetchOrigin origin) {
55 EXPECT_TRUE(config.IsLearningEnabled()); 54 EXPECT_TRUE(config.IsLearningEnabled());
56 EXPECT_TRUE(config.IsPrefetchingEnabledForOrigin(profile_.get(), origin)); 55 EXPECT_TRUE(config.IsPrefetchingEnabledForOrigin(profile_.get(), origin));
57 } 56 }
58 57
59 void TestIsPrefetchLearning(const ResourcePrefetchPredictorConfig& config) { 58 void TestIsPrefetchLearning(const LoadingPredictorConfig& config) {
60 EXPECT_TRUE(config.IsLearningEnabled()); 59 EXPECT_TRUE(config.IsLearningEnabled());
61 EXPECT_FALSE(config.IsPrefetchingEnabledForOrigin( 60 EXPECT_FALSE(config.IsPrefetchingEnabledForOrigin(profile_.get(),
62 profile_.get(), PrefetchOrigin::EXTERNAL)); 61 HintOrigin::EXTERNAL));
63 EXPECT_FALSE(config.IsPrefetchingEnabledForOrigin( 62 EXPECT_FALSE(config.IsPrefetchingEnabledForOrigin(profile_.get(),
64 profile_.get(), PrefetchOrigin::NAVIGATION)); 63 HintOrigin::NAVIGATION));
65 EXPECT_GT(config.min_resource_hits_to_trigger_prefetch, 1U); 64 EXPECT_GT(config.min_resource_hits_to_trigger_prefetch, 1U);
66 } 65 }
67 66
68 void TestIsDefaultExtraConfig(const ResourcePrefetchPredictorConfig& config) { 67 void TestIsDefaultExtraConfig(const LoadingPredictorConfig& config) {
69 EXPECT_FALSE(config.IsLowConfidenceForTest()); 68 EXPECT_FALSE(config.IsLowConfidenceForTest());
70 EXPECT_FALSE(config.IsHighConfidenceForTest()); 69 EXPECT_FALSE(config.IsHighConfidenceForTest());
71 EXPECT_FALSE(config.IsMoreResourcesEnabledForTest()); 70 EXPECT_FALSE(config.IsMoreResourcesEnabledForTest());
72 EXPECT_FALSE(config.IsSmallDBEnabledForTest()); 71 EXPECT_FALSE(config.IsSmallDBEnabledForTest());
73 EXPECT_FALSE(config.is_url_learning_enabled); 72 EXPECT_FALSE(config.is_url_learning_enabled);
74 EXPECT_FALSE(config.is_manifests_enabled); 73 EXPECT_FALSE(config.is_manifests_enabled);
75 EXPECT_FALSE(config.is_origin_learning_enabled); 74 EXPECT_FALSE(config.is_origin_learning_enabled);
76 EXPECT_GT(config.min_resource_hits_to_trigger_prefetch, 1U); 75 EXPECT_GT(config.min_resource_hits_to_trigger_prefetch, 1U);
77 } 76 }
78 77
79 protected: 78 protected:
80 content::TestBrowserThreadBundle test_browser_thread_bundle_; 79 content::TestBrowserThreadBundle test_browser_thread_bundle_;
81 std::unique_ptr<TestingProfile> profile_; 80 std::unique_ptr<TestingProfile> profile_;
82 }; 81 };
83 82
84 ResourcePrefetchCommonTest::ResourcePrefetchCommonTest() 83 ResourcePrefetchCommonTest::ResourcePrefetchCommonTest()
85 : profile_(new TestingProfile()) {} 84 : profile_(new TestingProfile()) {}
86 85
87 TEST_F(ResourcePrefetchCommonTest, IsDisabledByDefault) { 86 TEST_F(ResourcePrefetchCommonTest, IsDisabledByDefault) {
88 ResourcePrefetchPredictorConfig config; 87 LoadingPredictorConfig 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 HintOrigin::EXTERNAL));
95 EXPECT_FALSE(config.IsPrefetchingEnabledForOrigin( 94 EXPECT_FALSE(config.IsPrefetchingEnabledForOrigin(profile_.get(),
96 profile_.get(), PrefetchOrigin::NAVIGATION)); 95 HintOrigin::NAVIGATION));
97 96
98 TestIsDefaultExtraConfig(config); 97 TestIsDefaultExtraConfig(config);
99 } 98 }
100 99
101 TEST_F(ResourcePrefetchCommonTest, EnableLearning) { 100 TEST_F(ResourcePrefetchCommonTest, EnableLearning) {
102 variations::testing::VariationParamsManager params_manager( 101 variations::testing::VariationParamsManager params_manager(
103 "dummy-trial", {{kModeParamName, kLearningMode}}, 102 "dummy-trial", {{kModeParamName, kLearningMode}},
104 {kSpeculativeResourcePrefetchingFeatureName}); 103 {kSpeculativeResourcePrefetchingFeatureName});
105 104
106 ResourcePrefetchPredictorConfig config; 105 LoadingPredictorConfig config;
107 EXPECT_TRUE(IsSpeculativeResourcePrefetchingEnabled(profile_.get(), &config)); 106 EXPECT_TRUE(IsSpeculativeResourcePrefetchingEnabled(profile_.get(), &config));
108 TestIsPrefetchLearning(config); 107 TestIsPrefetchLearning(config);
109 TestIsDefaultExtraConfig(config); 108 TestIsDefaultExtraConfig(config);
110 } 109 }
111 110
112 TEST_F(ResourcePrefetchCommonTest, EnablePrefetch) { 111 TEST_F(ResourcePrefetchCommonTest, EnablePrefetch) {
113 variations::testing::VariationParamsManager params_manager( 112 variations::testing::VariationParamsManager params_manager(
114 "dummy-trial", {{kModeParamName, kPrefetchingMode}}, 113 "dummy-trial", {{kModeParamName, kPrefetchingMode}},
115 {kSpeculativeResourcePrefetchingFeatureName}); 114 {kSpeculativeResourcePrefetchingFeatureName});
116 115
117 ResourcePrefetchPredictorConfig config; 116 LoadingPredictorConfig config;
118 EXPECT_TRUE(IsSpeculativeResourcePrefetchingEnabled(profile_.get(), &config)); 117 EXPECT_TRUE(IsSpeculativeResourcePrefetchingEnabled(profile_.get(), &config));
119 TestIsPrefetchEnabledForOrigin(config, PrefetchOrigin::EXTERNAL); 118 TestIsPrefetchEnabledForOrigin(config, HintOrigin::EXTERNAL);
120 TestIsPrefetchEnabledForOrigin(config, PrefetchOrigin::NAVIGATION); 119 TestIsPrefetchEnabledForOrigin(config, HintOrigin::NAVIGATION);
121 TestIsDefaultExtraConfig(config); 120 TestIsDefaultExtraConfig(config);
122 } 121 }
123 122
124 TEST_F(ResourcePrefetchCommonTest, EnablePrefetchExternalOnly) { 123 TEST_F(ResourcePrefetchCommonTest, EnablePrefetchExternalOnly) {
125 variations::testing::VariationParamsManager params_manager( 124 variations::testing::VariationParamsManager params_manager(
126 "dummy-trial", {{kModeParamName, kExternalPrefetchingMode}}, 125 "dummy-trial", {{kModeParamName, kExternalPrefetchingMode}},
127 {kSpeculativeResourcePrefetchingFeatureName}); 126 {kSpeculativeResourcePrefetchingFeatureName});
128 127
129 ResourcePrefetchPredictorConfig config; 128 LoadingPredictorConfig config;
130 EXPECT_TRUE(IsSpeculativeResourcePrefetchingEnabled(profile_.get(), &config)); 129 EXPECT_TRUE(IsSpeculativeResourcePrefetchingEnabled(profile_.get(), &config));
131 TestIsPrefetchEnabledForOrigin(config, PrefetchOrigin::EXTERNAL); 130 TestIsPrefetchEnabledForOrigin(config, HintOrigin::EXTERNAL);
132 EXPECT_FALSE(config.IsPrefetchingEnabledForOrigin( 131 EXPECT_FALSE(config.IsPrefetchingEnabledForOrigin(profile_.get(),
133 profile_.get(), PrefetchOrigin::NAVIGATION)); 132 HintOrigin::NAVIGATION));
134 TestIsDefaultExtraConfig(config); 133 TestIsDefaultExtraConfig(config);
135 } 134 }
136 135
137 TEST_F(ResourcePrefetchCommonTest, EnableUrlLearning) { 136 TEST_F(ResourcePrefetchCommonTest, EnableUrlLearning) {
138 variations::testing::VariationParamsManager params_manager( 137 variations::testing::VariationParamsManager params_manager(
139 "dummy-trial", 138 "dummy-trial",
140 {{kModeParamName, kLearningMode}, {kEnableUrlLearningParamName, "true"}}, 139 {{kModeParamName, kLearningMode}, {kEnableUrlLearningParamName, "true"}},
141 {kSpeculativeResourcePrefetchingFeatureName}); 140 {kSpeculativeResourcePrefetchingFeatureName});
142 141
143 ResourcePrefetchPredictorConfig config; 142 LoadingPredictorConfig config;
144 EXPECT_TRUE(IsSpeculativeResourcePrefetchingEnabled(profile_.get(), &config)); 143 EXPECT_TRUE(IsSpeculativeResourcePrefetchingEnabled(profile_.get(), &config));
145 TestIsPrefetchLearning(config); 144 TestIsPrefetchLearning(config);
146 EXPECT_TRUE(config.is_url_learning_enabled); 145 EXPECT_TRUE(config.is_url_learning_enabled);
147 } 146 }
148 147
149 TEST_F(ResourcePrefetchCommonTest, EnableManifests) { 148 TEST_F(ResourcePrefetchCommonTest, EnableManifests) {
150 variations::testing::VariationParamsManager params_manager( 149 variations::testing::VariationParamsManager params_manager(
151 "dummy-trial", 150 "dummy-trial",
152 {{kModeParamName, kLearningMode}, {kEnableManifestsParamName, "true"}}, 151 {{kModeParamName, kLearningMode}, {kEnableManifestsParamName, "true"}},
153 {kSpeculativeResourcePrefetchingFeatureName}); 152 {kSpeculativeResourcePrefetchingFeatureName});
154 153
155 ResourcePrefetchPredictorConfig config; 154 LoadingPredictorConfig config;
156 EXPECT_TRUE(IsSpeculativeResourcePrefetchingEnabled(profile_.get(), &config)); 155 EXPECT_TRUE(IsSpeculativeResourcePrefetchingEnabled(profile_.get(), &config));
157 TestIsPrefetchLearning(config); 156 TestIsPrefetchLearning(config);
158 EXPECT_TRUE(config.is_manifests_enabled); 157 EXPECT_TRUE(config.is_manifests_enabled);
159 } 158 }
160 159
161 TEST_F(ResourcePrefetchCommonTest, EnableOriginLearning) { 160 TEST_F(ResourcePrefetchCommonTest, EnableOriginLearning) {
162 variations::testing::VariationParamsManager params_manager( 161 variations::testing::VariationParamsManager params_manager(
163 "dummy-trial", 162 "dummy-trial",
164 {{kModeParamName, kLearningMode}, 163 {{kModeParamName, kLearningMode},
165 {kEnableOriginLearningParamName, "true"}}, 164 {kEnableOriginLearningParamName, "true"}},
166 {kSpeculativeResourcePrefetchingFeatureName}); 165 {kSpeculativeResourcePrefetchingFeatureName});
167 166
168 ResourcePrefetchPredictorConfig config; 167 LoadingPredictorConfig config;
169 EXPECT_TRUE(IsSpeculativeResourcePrefetchingEnabled(profile_.get(), &config)); 168 EXPECT_TRUE(IsSpeculativeResourcePrefetchingEnabled(profile_.get(), &config));
170 TestIsPrefetchLearning(config); 169 TestIsPrefetchLearning(config);
171 EXPECT_TRUE(config.is_origin_learning_enabled); 170 EXPECT_TRUE(config.is_origin_learning_enabled);
172 } 171 }
173 172
174 // Verifies whether prefetching is disabled according to the network type. But 173 // Verifies whether prefetching is disabled according to the network type. But
175 // learning should not be disabled by network. 174 // learning should not be disabled by network.
176 TEST_F(ResourcePrefetchCommonTest, RespectsNetworkSettings) { 175 TEST_F(ResourcePrefetchCommonTest, RespectsNetworkSettings) {
177 variations::testing::VariationParamsManager params_manager( 176 variations::testing::VariationParamsManager params_manager(
178 "dummy-trial", {{kModeParamName, kPrefetchingMode}}, 177 "dummy-trial", {{kModeParamName, kPrefetchingMode}},
179 {kSpeculativeResourcePrefetchingFeatureName}); 178 {kSpeculativeResourcePrefetchingFeatureName});
180 179
181 ResourcePrefetchPredictorConfig config; 180 LoadingPredictorConfig config;
182 EXPECT_TRUE(IsSpeculativeResourcePrefetchingEnabled(profile_.get(), &config)); 181 EXPECT_TRUE(IsSpeculativeResourcePrefetchingEnabled(profile_.get(), &config));
183 TestIsPrefetchEnabledForOrigin(config, PrefetchOrigin::EXTERNAL); 182 TestIsPrefetchEnabledForOrigin(config, HintOrigin::EXTERNAL);
184 TestIsDefaultExtraConfig(config); 183 TestIsDefaultExtraConfig(config);
185 184
186 // Set preference to WIFI_ONLY: prefetch when not on cellular. 185 // Set preference to WIFI_ONLY: prefetch when not on cellular.
187 SetPreference(NetworkPredictionOptions::NETWORK_PREDICTION_WIFI_ONLY); 186 SetPreference(NetworkPredictionOptions::NETWORK_PREDICTION_WIFI_ONLY);
188 { 187 {
189 std::unique_ptr<NetworkChangeNotifier> mock( 188 std::unique_ptr<NetworkChangeNotifier> mock(
190 new MockNetworkChangeNotifierWIFI); 189 new MockNetworkChangeNotifierWIFI);
191 TestIsPrefetchEnabledForOrigin(config, PrefetchOrigin::EXTERNAL); 190 TestIsPrefetchEnabledForOrigin(config, HintOrigin::EXTERNAL);
192 } 191 }
193 { 192 {
194 std::unique_ptr<NetworkChangeNotifier> mock( 193 std::unique_ptr<NetworkChangeNotifier> mock(
195 new MockNetworkChangeNotifier4G); 194 new MockNetworkChangeNotifier4G);
196 TestIsPrefetchLearning(config); 195 TestIsPrefetchLearning(config);
197 } 196 }
198 197
199 // Set preference to NEVER: never prefetch. 198 // Set preference to NEVER: never prefetch.
200 SetPreference(NetworkPredictionOptions::NETWORK_PREDICTION_NEVER); 199 SetPreference(NetworkPredictionOptions::NETWORK_PREDICTION_NEVER);
201 { 200 {
202 std::unique_ptr<NetworkChangeNotifier> mock( 201 std::unique_ptr<NetworkChangeNotifier> mock(
203 new MockNetworkChangeNotifierWIFI); 202 new MockNetworkChangeNotifierWIFI);
204 TestIsPrefetchLearning(config); 203 TestIsPrefetchLearning(config);
205 } 204 }
206 { 205 {
207 std::unique_ptr<NetworkChangeNotifier> mock( 206 std::unique_ptr<NetworkChangeNotifier> mock(
208 new MockNetworkChangeNotifier4G); 207 new MockNetworkChangeNotifier4G);
209 TestIsPrefetchLearning(config); 208 TestIsPrefetchLearning(config);
210 } 209 }
211 } 210 }
212 211
213 } // namespace predictors 212 } // namespace predictors
OLDNEW
« no previous file with comments | « chrome/browser/predictors/resource_prefetch_common.cc ('k') | chrome/browser/predictors/resource_prefetch_predictor.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698