OLD | NEW |
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 "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
10 #include "chrome/browser/net/prediction_options.h" | 10 #include "chrome/browser/net/prediction_options.h" |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
66 EXPECT_GT(config.min_resource_hits_to_trigger_prefetch, 1U); | 66 EXPECT_GT(config.min_resource_hits_to_trigger_prefetch, 1U); |
67 } | 67 } |
68 | 68 |
69 void TestIsDefaultExtraConfig(const ResourcePrefetchPredictorConfig& config) { | 69 void TestIsDefaultExtraConfig(const ResourcePrefetchPredictorConfig& config) { |
70 EXPECT_FALSE(config.IsLowConfidenceForTest()); | 70 EXPECT_FALSE(config.IsLowConfidenceForTest()); |
71 EXPECT_FALSE(config.IsHighConfidenceForTest()); | 71 EXPECT_FALSE(config.IsHighConfidenceForTest()); |
72 EXPECT_FALSE(config.IsMoreResourcesEnabledForTest()); | 72 EXPECT_FALSE(config.IsMoreResourcesEnabledForTest()); |
73 EXPECT_FALSE(config.IsSmallDBEnabledForTest()); | 73 EXPECT_FALSE(config.IsSmallDBEnabledForTest()); |
74 EXPECT_FALSE(config.is_url_learning_enabled); | 74 EXPECT_FALSE(config.is_url_learning_enabled); |
75 EXPECT_FALSE(config.is_manifests_enabled); | 75 EXPECT_FALSE(config.is_manifests_enabled); |
76 EXPECT_FALSE(config.is_origin_prediction_enabled); | 76 EXPECT_FALSE(config.is_origin_learning_enabled); |
77 EXPECT_GT(config.min_resource_hits_to_trigger_prefetch, 1U); | 77 EXPECT_GT(config.min_resource_hits_to_trigger_prefetch, 1U); |
78 } | 78 } |
79 | 79 |
80 protected: | 80 protected: |
81 base::MessageLoop loop_; | 81 base::MessageLoop loop_; |
82 content::TestBrowserThread ui_thread_; | 82 content::TestBrowserThread ui_thread_; |
83 std::unique_ptr<TestingProfile> profile_; | 83 std::unique_ptr<TestingProfile> profile_; |
84 }; | 84 }; |
85 | 85 |
86 ResourcePrefetchCommonTest::ResourcePrefetchCommonTest() | 86 ResourcePrefetchCommonTest::ResourcePrefetchCommonTest() |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
155 "dummy-trial", | 155 "dummy-trial", |
156 {{kModeParamName, kLearningMode}, {kEnableManifestsParamName, "true"}}, | 156 {{kModeParamName, kLearningMode}, {kEnableManifestsParamName, "true"}}, |
157 {kSpeculativeResourcePrefetchingFeatureName}); | 157 {kSpeculativeResourcePrefetchingFeatureName}); |
158 | 158 |
159 ResourcePrefetchPredictorConfig config; | 159 ResourcePrefetchPredictorConfig config; |
160 EXPECT_TRUE(IsSpeculativeResourcePrefetchingEnabled(profile_.get(), &config)); | 160 EXPECT_TRUE(IsSpeculativeResourcePrefetchingEnabled(profile_.get(), &config)); |
161 TestIsPrefetchLearning(config); | 161 TestIsPrefetchLearning(config); |
162 EXPECT_TRUE(config.is_manifests_enabled); | 162 EXPECT_TRUE(config.is_manifests_enabled); |
163 } | 163 } |
164 | 164 |
| 165 TEST_F(ResourcePrefetchCommonTest, EnableOriginLearning) { |
| 166 variations::testing::VariationParamsManager params_manager( |
| 167 "dummy-trial", |
| 168 {{kModeParamName, kLearningMode}, |
| 169 {kEnableOriginLearningParamName, "true"}}, |
| 170 {kSpeculativeResourcePrefetchingFeatureName}); |
| 171 |
| 172 ResourcePrefetchPredictorConfig config; |
| 173 EXPECT_TRUE(IsSpeculativeResourcePrefetchingEnabled(profile_.get(), &config)); |
| 174 TestIsPrefetchLearning(config); |
| 175 EXPECT_TRUE(config.is_origin_learning_enabled); |
| 176 } |
| 177 |
165 // Verifies whether prefetching is disabled according to the network type. But | 178 // Verifies whether prefetching is disabled according to the network type. But |
166 // learning should not be disabled by network. | 179 // learning should not be disabled by network. |
167 TEST_F(ResourcePrefetchCommonTest, RespectsNetworkSettings) { | 180 TEST_F(ResourcePrefetchCommonTest, RespectsNetworkSettings) { |
168 variations::testing::VariationParamsManager params_manager( | 181 variations::testing::VariationParamsManager params_manager( |
169 "dummy-trial", {{kModeParamName, kPrefetchingMode}}, | 182 "dummy-trial", {{kModeParamName, kPrefetchingMode}}, |
170 {kSpeculativeResourcePrefetchingFeatureName}); | 183 {kSpeculativeResourcePrefetchingFeatureName}); |
171 | 184 |
172 ResourcePrefetchPredictorConfig config; | 185 ResourcePrefetchPredictorConfig config; |
173 EXPECT_TRUE(IsSpeculativeResourcePrefetchingEnabled(profile_.get(), &config)); | 186 EXPECT_TRUE(IsSpeculativeResourcePrefetchingEnabled(profile_.get(), &config)); |
174 TestIsPrefetchEnabledForOrigin(config, PrefetchOrigin::EXTERNAL); | 187 TestIsPrefetchEnabledForOrigin(config, PrefetchOrigin::EXTERNAL); |
(...skipping 20 matching lines...) Expand all Loading... |
195 TestIsPrefetchLearning(config); | 208 TestIsPrefetchLearning(config); |
196 } | 209 } |
197 { | 210 { |
198 std::unique_ptr<NetworkChangeNotifier> mock( | 211 std::unique_ptr<NetworkChangeNotifier> mock( |
199 new MockNetworkChangeNotifier4G); | 212 new MockNetworkChangeNotifier4G); |
200 TestIsPrefetchLearning(config); | 213 TestIsPrefetchLearning(config); |
201 } | 214 } |
202 } | 215 } |
203 | 216 |
204 } // namespace predictors | 217 } // namespace predictors |
OLD | NEW |