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

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

Issue 2729563002: predictors: Disable URL-based learning by default. (Closed)
Patch Set: Fix missed initialization. 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 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
64 profile_.get(), PrefetchOrigin::EXTERNAL)); 63 profile_.get(), PrefetchOrigin::EXTERNAL));
65 EXPECT_FALSE(config.IsPrefetchingEnabledForOrigin( 64 EXPECT_FALSE(config.IsPrefetchingEnabledForOrigin(
66 profile_.get(), PrefetchOrigin::NAVIGATION)); 65 profile_.get(), PrefetchOrigin::NAVIGATION));
67 } 66 }
68 67
69 void TestIsDefaultExtraConfig(const ResourcePrefetchPredictorConfig& config) { 68 void TestIsDefaultExtraConfig(const ResourcePrefetchPredictorConfig& config) {
70 EXPECT_FALSE(config.IsLowConfidenceForTest()); 69 EXPECT_FALSE(config.IsLowConfidenceForTest());
71 EXPECT_FALSE(config.IsHighConfidenceForTest()); 70 EXPECT_FALSE(config.IsHighConfidenceForTest());
72 EXPECT_FALSE(config.IsMoreResourcesEnabledForTest()); 71 EXPECT_FALSE(config.IsMoreResourcesEnabledForTest());
73 EXPECT_FALSE(config.IsSmallDBEnabledForTest()); 72 EXPECT_FALSE(config.IsSmallDBEnabledForTest());
73 EXPECT_FALSE(config.is_url_learning_enabled);
74 } 74 }
75 75
76 protected: 76 protected:
77 base::MessageLoop loop_; 77 base::MessageLoop loop_;
78 content::TestBrowserThread ui_thread_; 78 content::TestBrowserThread ui_thread_;
79 std::unique_ptr<TestingProfile> profile_; 79 std::unique_ptr<TestingProfile> profile_;
80 }; 80 };
81 81
82 ResourcePrefetchCommonTest::ResourcePrefetchCommonTest() 82 ResourcePrefetchCommonTest::ResourcePrefetchCommonTest()
83 : loop_(base::MessageLoop::TYPE_DEFAULT), 83 : loop_(base::MessageLoop::TYPE_DEFAULT),
84 ui_thread_(content::BrowserThread::UI, &loop_), 84 ui_thread_(content::BrowserThread::UI, &loop_),
85 profile_(new TestingProfile()) { } 85 profile_(new TestingProfile()) { }
86 86
87 TEST_F(ResourcePrefetchCommonTest, IsDisabledByDefault) { 87 TEST_F(ResourcePrefetchCommonTest, IsDisabledByDefault) {
88 ResourcePrefetchPredictorConfig config; 88 ResourcePrefetchPredictorConfig config;
89 EXPECT_FALSE( 89 EXPECT_FALSE(
90 IsSpeculativeResourcePrefetchingEnabled(profile_.get(), &config)); 90 IsSpeculativeResourcePrefetchingEnabled(profile_.get(), &config));
91 91
92 EXPECT_FALSE(config.IsLearningEnabled()); 92 EXPECT_FALSE(config.IsLearningEnabled());
93 EXPECT_FALSE(config.IsPrefetchingEnabledForOrigin(profile_.get(), 93 EXPECT_FALSE(config.IsPrefetchingEnabledForOrigin(profile_.get(),
94 PrefetchOrigin::EXTERNAL)); 94 PrefetchOrigin::EXTERNAL));
95 EXPECT_FALSE(config.IsLearningEnabled()); 95 EXPECT_FALSE(config.IsPrefetchingEnabledForOrigin(
96 profile_.get(), PrefetchOrigin::NAVIGATION));
96 97
97 TestIsDefaultExtraConfig(config); 98 TestIsDefaultExtraConfig(config);
98 } 99 }
99 100
100 TEST_F(ResourcePrefetchCommonTest, EnableLearning) { 101 TEST_F(ResourcePrefetchCommonTest, EnableLearning) {
101 variations::testing::VariationParamsManager params_manager( 102 variations::testing::VariationParamsManager params_manager(
102 "dummy-trial", {{kModeParamName, kLearningMode}}, 103 "dummy-trial", {{kModeParamName, kLearningMode}},
103 {kSpeculativeResourcePrefetchingFeatureName}); 104 {kSpeculativeResourcePrefetchingFeatureName});
104 105
105 ResourcePrefetchPredictorConfig config; 106 ResourcePrefetchPredictorConfig config;
(...skipping 20 matching lines...) Expand all
126 {kSpeculativeResourcePrefetchingFeatureName}); 127 {kSpeculativeResourcePrefetchingFeatureName});
127 128
128 ResourcePrefetchPredictorConfig config; 129 ResourcePrefetchPredictorConfig config;
129 EXPECT_TRUE(IsSpeculativeResourcePrefetchingEnabled(profile_.get(), &config)); 130 EXPECT_TRUE(IsSpeculativeResourcePrefetchingEnabled(profile_.get(), &config));
130 TestIsPrefetchEnabledForOrigin(config, PrefetchOrigin::EXTERNAL); 131 TestIsPrefetchEnabledForOrigin(config, PrefetchOrigin::EXTERNAL);
131 EXPECT_FALSE(config.IsPrefetchingEnabledForOrigin( 132 EXPECT_FALSE(config.IsPrefetchingEnabledForOrigin(
132 profile_.get(), PrefetchOrigin::NAVIGATION)); 133 profile_.get(), PrefetchOrigin::NAVIGATION));
133 TestIsDefaultExtraConfig(config); 134 TestIsDefaultExtraConfig(config);
134 } 135 }
135 136
137 TEST_F(ResourcePrefetchCommonTest, EnableUrlLearning) {
138 variations::testing::VariationParamsManager params_manager(
139 "dummy-trial",
140 {{kModeParamName, kLearningMode}, {kEnableUrlLearningParamName, "true"}},
141 {kSpeculativeResourcePrefetchingFeatureName});
142
143 ResourcePrefetchPredictorConfig config;
144 EXPECT_TRUE(IsSpeculativeResourcePrefetchingEnabled(profile_.get(), &config));
145 TestIsPrefetchLearning(config);
146 EXPECT_TRUE(config.is_url_learning_enabled);
147 }
148
136 // Verifies whether prefetching is disabled according to the network type. But 149 // Verifies whether prefetching is disabled according to the network type. But
137 // learning should not be disabled by network. 150 // learning should not be disabled by network.
138 TEST_F(ResourcePrefetchCommonTest, RespectsNetworkSettings) { 151 TEST_F(ResourcePrefetchCommonTest, RespectsNetworkSettings) {
139 variations::testing::VariationParamsManager params_manager( 152 variations::testing::VariationParamsManager params_manager(
140 "dummy-trial", {{kModeParamName, kPrefetchingMode}}, 153 "dummy-trial", {{kModeParamName, kPrefetchingMode}},
141 {kSpeculativeResourcePrefetchingFeatureName}); 154 {kSpeculativeResourcePrefetchingFeatureName});
142 155
143 ResourcePrefetchPredictorConfig config; 156 ResourcePrefetchPredictorConfig config;
144 EXPECT_TRUE(IsSpeculativeResourcePrefetchingEnabled(profile_.get(), &config)); 157 EXPECT_TRUE(IsSpeculativeResourcePrefetchingEnabled(profile_.get(), &config));
145 TestIsPrefetchEnabledForOrigin(config, PrefetchOrigin::EXTERNAL); 158 TestIsPrefetchEnabledForOrigin(config, PrefetchOrigin::EXTERNAL);
(...skipping 20 matching lines...) Expand all
166 TestIsPrefetchLearning(config); 179 TestIsPrefetchLearning(config);
167 } 180 }
168 { 181 {
169 std::unique_ptr<NetworkChangeNotifier> mock( 182 std::unique_ptr<NetworkChangeNotifier> mock(
170 new MockNetworkChangeNotifier4G); 183 new MockNetworkChangeNotifier4G);
171 TestIsPrefetchLearning(config); 184 TestIsPrefetchLearning(config);
172 } 185 }
173 } 186 }
174 187
175 } // namespace predictors 188 } // namespace predictors
OLDNEW
« no previous file with comments | « chrome/browser/predictors/resource_prefetch_common.cc ('k') | chrome/browser/predictors/resource_prefetch_predictor.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698