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

Unified Diff: chrome/browser/predictors/resource_prefetch_common_unittest.cc

Issue 2538743002: predictors: Add a origin for prefetch requests, remove the URL/host settings. (Closed)
Patch Set: Created 4 years, 1 month 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/predictors/resource_prefetch_common_unittest.cc
diff --git a/chrome/browser/predictors/resource_prefetch_common_unittest.cc b/chrome/browser/predictors/resource_prefetch_common_unittest.cc
index 714518f5a01a3cc62a8fd9200d86a15acaba6ec4..5f9849bb47aa3181ba814194b8b808480d11cdde 100644
--- a/chrome/browser/predictors/resource_prefetch_common_unittest.cc
+++ b/chrome/browser/predictors/resource_prefetch_common_unittest.cc
@@ -56,22 +56,19 @@ class ResourcePrefetchCommonTest : public testing::Test {
switches::kSpeculativeResourcePrefetching, value);
}
- void TestIsPrefetchEnabled(const ResourcePrefetchPredictorConfig& config) {
+ void TestIsPrefetchEnabledForOrigin(
+ const ResourcePrefetchPredictorConfig& config,
+ ResourcePrefetchPredictorConfig::Origin origin) {
EXPECT_TRUE(config.IsLearningEnabled());
- EXPECT_TRUE(config.IsPrefetchingEnabled(profile_.get()));
- EXPECT_TRUE(config.IsURLLearningEnabled());
- EXPECT_TRUE(config.IsHostLearningEnabled());
- EXPECT_TRUE(config.IsURLPrefetchingEnabled(profile_.get()));
- EXPECT_TRUE(config.IsHostPrefetchingEnabled(profile_.get()));
+ EXPECT_TRUE(config.IsPrefetchingEnabled(profile_.get(), origin));
}
void TestIsPrefetchLearning(const ResourcePrefetchPredictorConfig& config) {
EXPECT_TRUE(config.IsLearningEnabled());
- EXPECT_FALSE(config.IsPrefetchingEnabled(profile_.get()));
- EXPECT_TRUE(config.IsURLLearningEnabled());
- EXPECT_TRUE(config.IsHostLearningEnabled());
- EXPECT_FALSE(config.IsURLPrefetchingEnabled(profile_.get()));
- EXPECT_FALSE(config.IsHostPrefetchingEnabled(profile_.get()));
+ EXPECT_FALSE(config.IsPrefetchingEnabled(
+ profile_.get(), ResourcePrefetchPredictorConfig::ORIGIN_EXTERNAL));
+ EXPECT_FALSE(config.IsPrefetchingEnabled(
+ profile_.get(), ResourcePrefetchPredictorConfig::ORIGIN_NAVIGATION));
}
void TestIsDefaultExtraConfig(const ResourcePrefetchPredictorConfig& config) {
@@ -98,11 +95,9 @@ TEST_F(ResourcePrefetchCommonTest, IsDisabledByDefault) {
IsSpeculativeResourcePrefetchingEnabled(profile_.get(), &config));
EXPECT_FALSE(config.IsLearningEnabled());
- EXPECT_FALSE(config.IsPrefetchingEnabled(profile_.get()));
- EXPECT_FALSE(config.IsURLLearningEnabled());
- EXPECT_FALSE(config.IsHostLearningEnabled());
- EXPECT_FALSE(config.IsURLPrefetchingEnabled(profile_.get()));
- EXPECT_FALSE(config.IsHostPrefetchingEnabled(profile_.get()));
+ EXPECT_FALSE(config.IsPrefetchingEnabled(
+ profile_.get(), ResourcePrefetchPredictorConfig::ORIGIN_EXTERNAL));
+ EXPECT_FALSE(config.IsLearningEnabled());
TestIsDefaultExtraConfig(config);
}
@@ -119,7 +114,21 @@ TEST_F(ResourcePrefetchCommonTest, EnablePrefetch) {
SetCommandLineValue("enabled");
ResourcePrefetchPredictorConfig config;
EXPECT_TRUE(IsSpeculativeResourcePrefetchingEnabled(profile_.get(), &config));
- TestIsPrefetchEnabled(config);
+ TestIsPrefetchEnabledForOrigin(
+ config, ResourcePrefetchPredictorConfig::ORIGIN_EXTERNAL);
+ TestIsPrefetchEnabledForOrigin(
+ config, ResourcePrefetchPredictorConfig::ORIGIN_NAVIGATION);
+ TestIsDefaultExtraConfig(config);
+}
+
+TEST_F(ResourcePrefetchCommonTest, EnablePrefetchExternalOnly) {
+ SetCommandLineValue("enabled-external");
+ ResourcePrefetchPredictorConfig config;
+ EXPECT_TRUE(IsSpeculativeResourcePrefetchingEnabled(profile_.get(), &config));
+ TestIsPrefetchEnabledForOrigin(
+ config, ResourcePrefetchPredictorConfig::ORIGIN_EXTERNAL);
+ EXPECT_FALSE(config.IsPrefetchingEnabled(
+ profile_.get(), ResourcePrefetchPredictorConfig::ORIGIN_NAVIGATION));
TestIsDefaultExtraConfig(config);
}
@@ -129,7 +138,8 @@ TEST_F(ResourcePrefetchCommonTest, RespectsNetworkSettings) {
SetCommandLineValue("enabled");
ResourcePrefetchPredictorConfig config;
EXPECT_TRUE(IsSpeculativeResourcePrefetchingEnabled(profile_.get(), &config));
- TestIsPrefetchEnabled(config);
+ TestIsPrefetchEnabledForOrigin(
+ config, ResourcePrefetchPredictorConfig::ORIGIN_EXTERNAL);
TestIsDefaultExtraConfig(config);
// Set preference to WIFI_ONLY: prefetch when not on cellular.
@@ -137,7 +147,8 @@ TEST_F(ResourcePrefetchCommonTest, RespectsNetworkSettings) {
{
std::unique_ptr<NetworkChangeNotifier> mock(
new MockNetworkChangeNotifierWIFI);
- TestIsPrefetchEnabled(config);
+ TestIsPrefetchEnabledForOrigin(
+ config, ResourcePrefetchPredictorConfig::ORIGIN_EXTERNAL);
}
{
std::unique_ptr<NetworkChangeNotifier> mock(

Powered by Google App Engine
This is Rietveld 408576698