diff options
Diffstat (limited to 'chromium/components/previews')
4 files changed, 49 insertions, 31 deletions
diff --git a/chromium/components/previews/content/previews_hints.cc b/chromium/components/previews/content/previews_hints.cc index 5a8011f46ab..c6b31fd2494 100644 --- a/chromium/components/previews/content/previews_hints.cc +++ b/chromium/components/previews/content/previews_hints.cc @@ -6,7 +6,6 @@ #include <unordered_set> -#include "base/command_line.h" #include "base/files/file.h" #include "base/files/file_util.h" #include "base/metrics/histogram_functions.h" @@ -463,14 +462,13 @@ bool PreviewsHints::IsBlacklisted(const GURL& url, PreviewsType type) const { // Check large scale blacklists received from the server. // (At some point, we may have blacklisting to check in HintCache as well.) if (type == PreviewsType::LITE_PAGE_REDIRECT) { - if (base::CommandLine::ForCurrentProcess()->HasSwitch( - switches::kIgnoreLitePageRedirectOptimizationBlacklist)) { - return false; + // If no bloom filter blacklist is provided by the component update, assume + // a server error and return true. + if (!lite_page_redirect_blacklist_) { + return true; } - if (lite_page_redirect_blacklist_) { - return lite_page_redirect_blacklist_->ContainsHostSuffix(url); - } + return lite_page_redirect_blacklist_->ContainsHostSuffix(url); } return false; diff --git a/chromium/components/previews/content/previews_hints_unittest.cc b/chromium/components/previews/content/previews_hints_unittest.cc index 474cf0159c9..9fa246bedb0 100644 --- a/chromium/components/previews/content/previews_hints_unittest.cc +++ b/chromium/components/previews/content/previews_hints_unittest.cc @@ -259,32 +259,27 @@ TEST_F(PreviewsHintsTest, LogHintCacheMatch) { 5 /* EFFECTIVE_CONNECTION_TYPE_4G */, 1); } -TEST_F(PreviewsHintsTest, IsBlacklisted) { +TEST_F(PreviewsHintsTest, IsBlacklistedReturnsTrueIfNoBloomFilter) { base::test::ScopedFeatureList scoped_list; scoped_list.InitAndEnableFeature(features::kLitePageServerPreviews); - BloomFilter blacklist_bloom_filter(kBlackBlacklistBloomFilterNumHashFunctions, - kBlackBlacklistBloomFilterNumBits); - PopulateBlackBlacklistBloomFilter(&blacklist_bloom_filter); - optimization_guide::proto::Configuration config; - AddBlacklistBloomFilterToConfig(blacklist_bloom_filter, - kBlackBlacklistBloomFilterNumHashFunctions, - kBlackBlacklistBloomFilterNumBits, &config); ParseConfig(config); - EXPECT_TRUE(HasLitePageRedirectBlacklist()); + EXPECT_FALSE(HasLitePageRedirectBlacklist()); + EXPECT_FALSE(previews_hints()->IsBlacklisted(GURL("https://black.com/path"), PreviewsType::LOFI)); + EXPECT_TRUE(previews_hints()->IsBlacklisted( GURL("https://black.com/path"), PreviewsType::LITE_PAGE_REDIRECT)); EXPECT_TRUE(previews_hints()->IsBlacklisted( GURL("https://joe.black.com/path"), PreviewsType::LITE_PAGE_REDIRECT)); - EXPECT_FALSE(previews_hints()->IsBlacklisted( + EXPECT_TRUE(previews_hints()->IsBlacklisted( GURL("https://nonblack.com"), PreviewsType::LITE_PAGE_REDIRECT)); } -TEST_F(PreviewsHintsTest, IgnoreLitePageRedirectBlacklist) { +TEST_F(PreviewsHintsTest, IsBlacklisted) { base::test::ScopedFeatureList scoped_list; scoped_list.InitAndEnableFeature(features::kLitePageServerPreviews); @@ -298,14 +293,12 @@ TEST_F(PreviewsHintsTest, IgnoreLitePageRedirectBlacklist) { kBlackBlacklistBloomFilterNumBits, &config); ParseConfig(config); - base::CommandLine::ForCurrentProcess()->AppendSwitch( - switches::kIgnoreLitePageRedirectOptimizationBlacklist); - + EXPECT_TRUE(HasLitePageRedirectBlacklist()); EXPECT_FALSE(previews_hints()->IsBlacklisted(GURL("https://black.com/path"), PreviewsType::LOFI)); - EXPECT_FALSE(previews_hints()->IsBlacklisted( + EXPECT_TRUE(previews_hints()->IsBlacklisted( GURL("https://black.com/path"), PreviewsType::LITE_PAGE_REDIRECT)); - EXPECT_FALSE(previews_hints()->IsBlacklisted( + EXPECT_TRUE(previews_hints()->IsBlacklisted( GURL("https://joe.black.com/path"), PreviewsType::LITE_PAGE_REDIRECT)); EXPECT_FALSE(previews_hints()->IsBlacklisted( GURL("https://nonblack.com"), PreviewsType::LITE_PAGE_REDIRECT)); @@ -337,7 +330,7 @@ TEST_F(PreviewsHintsTest, ParseConfigWithInsufficientConfigDetails) { "Previews.OptimizationFilterStatus.LitePageRedirect", 2 /* FAILED_SERVER_BLACKLIST_BAD_CONFIG */, 1); - EXPECT_FALSE(previews_hints()->IsBlacklisted( + EXPECT_TRUE(previews_hints()->IsBlacklisted( GURL("https://black.com/path"), PreviewsType::LITE_PAGE_REDIRECT)); } @@ -369,7 +362,7 @@ TEST_F(PreviewsHintsTest, ParseConfigWithTooLargeBlacklist) { "Previews.OptimizationFilterStatus.LitePageRedirect", 3 /* FAILED_SERVER_BLACKLIST_TOO_BIG */, 1); - EXPECT_FALSE(previews_hints()->IsBlacklisted( + EXPECT_TRUE(previews_hints()->IsBlacklisted( GURL("https://black.com/path"), PreviewsType::LITE_PAGE_REDIRECT)); } diff --git a/chromium/components/previews/content/previews_optimization_guide.cc b/chromium/components/previews/content/previews_optimization_guide.cc index cc16e22fdc5..4c1f93733c6 100644 --- a/chromium/components/previews/content/previews_optimization_guide.cc +++ b/chromium/components/previews/content/previews_optimization_guide.cc @@ -129,11 +129,22 @@ bool PreviewsOptimizationGuide::IsWhitelisted( bool PreviewsOptimizationGuide::IsBlacklisted(const GURL& url, PreviewsType type) const { DCHECK(ui_task_runner_->BelongsToCurrentThread()); - if (!hints_) { - return false; + + if (type == PreviewsType::LITE_PAGE_REDIRECT) { + if (base::CommandLine::ForCurrentProcess()->HasSwitch( + switches::kIgnoreLitePageRedirectOptimizationBlacklist)) { + return false; + } + + if (!hints_) + return true; + + return hints_->IsBlacklisted(url, PreviewsType::LITE_PAGE_REDIRECT); } - return hints_->IsBlacklisted(url, type); + // This function is only used by lite page redirect. + NOTREACHED(); + return false; } void PreviewsOptimizationGuide::OnLoadedHint( diff --git a/chromium/components/previews/content/previews_optimization_guide_unittest.cc b/chromium/components/previews/content/previews_optimization_guide_unittest.cc index dfba646da12..aca9b7cd247 100644 --- a/chromium/components/previews/content/previews_optimization_guide_unittest.cc +++ b/chromium/components/previews/content/previews_optimization_guide_unittest.cc @@ -1514,7 +1514,7 @@ TEST_F(PreviewsOptimizationGuideTest, IsBlacklisted) { base::test::ScopedFeatureList scoped_list; scoped_list.InitAndEnableFeature(features::kLitePageServerPreviews); - EXPECT_FALSE( + EXPECT_TRUE( guide()->IsBlacklisted(GURL("https://m.blacklisteddomain.com/path"), PreviewsType::LITE_PAGE_REDIRECT)); @@ -1523,7 +1523,7 @@ TEST_F(PreviewsOptimizationGuideTest, IsBlacklisted) { EXPECT_TRUE( guide()->IsBlacklisted(GURL("https://m.blacklisteddomain.com/path"), PreviewsType::LITE_PAGE_REDIRECT)); - EXPECT_FALSE(guide()->IsBlacklisted( + EXPECT_DCHECK_DEATH(guide()->IsBlacklisted( GURL("https://m.blacklisteddomain.com/path"), PreviewsType::NOSCRIPT)); EXPECT_TRUE(guide()->IsBlacklisted( @@ -1534,6 +1534,22 @@ TEST_F(PreviewsOptimizationGuideTest, IsBlacklisted) { PreviewsType::LITE_PAGE_REDIRECT)); } +TEST_F(PreviewsOptimizationGuideTest, LitePageRedirectSkipIsBlacklistedCheck) { + base::test::ScopedFeatureList scoped_list; + scoped_list.InitAndEnableFeature(features::kLitePageServerPreviews); + InitializeWithLitePageRedirectBlacklist(); + + EXPECT_TRUE( + guide()->IsBlacklisted(GURL("https://m.blacklisteddomain.com/path"), + PreviewsType::LITE_PAGE_REDIRECT)); + base::CommandLine::ForCurrentProcess()->AppendSwitch( + switches::kIgnoreLitePageRedirectOptimizationBlacklist); + + EXPECT_FALSE( + guide()->IsBlacklisted(GURL("https://m.blacklisteddomain.com/path"), + PreviewsType::LITE_PAGE_REDIRECT)); +} + TEST_F(PreviewsOptimizationGuideTest, IsBlacklistedWithLitePageServerPreviewsDisabled) { base::test::ScopedFeatureList scoped_list; @@ -1541,7 +1557,7 @@ TEST_F(PreviewsOptimizationGuideTest, InitializeWithLitePageRedirectBlacklist(); - EXPECT_FALSE( + EXPECT_TRUE( guide()->IsBlacklisted(GURL("https://m.blacklisteddomain.com/path"), PreviewsType::LITE_PAGE_REDIRECT)); } |