Commit f7701912 authored by Robert Ogden's avatar Robert Ogden Committed by Commit Bot

HTTPS Previews: Add cmd line flag to ignore opt hints blacklist

This is needed for ChromeDriver testing. See bug.

Bug: 908491
Change-Id: Ifaf1505757badc0b9c39b2a98e48a733a26564d7
Reviewed-on: https://chromium-review.googlesource.com/c/1351097Reviewed-by: default avatarDoug Arnett <dougarnett@chromium.org>
Commit-Queue: Robert Ogden <robertogden@chromium.org>
Cr-Commit-Position: refs/heads/master@{#611738}
parent 2a562aeb
......@@ -7,6 +7,7 @@
#include <array>
#include <string>
#include "base/command_line.h"
#include "base/files/file.h"
#include "base/files/file_util.h"
#include "base/metrics/field_trial_params.h"
......@@ -18,6 +19,7 @@
#include "components/optimization_guide/url_pattern_with_wildcards.h"
#include "components/previews/core/bloom_filter.h"
#include "components/previews/core/previews_features.h"
#include "components/previews/core/previews_switches.h"
#include "url/gurl.h"
namespace previews {
......@@ -615,6 +617,11 @@ 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 (lite_page_redirect_blacklist_)
return lite_page_redirect_blacklist_->ContainsHostSuffix(url);
}
......
......@@ -4,12 +4,14 @@
#include "components/previews/content/previews_hints.h"
#include "base/command_line.h"
#include "base/files/scoped_temp_dir.h"
#include "base/test/metrics/histogram_tester.h"
#include "base/test/scoped_feature_list.h"
#include "components/optimization_guide/optimization_guide_service_observer.h"
#include "components/optimization_guide/proto/hints.pb.h"
#include "components/previews/core/previews_features.h"
#include "components/previews/core/previews_switches.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "url/gurl.h"
......@@ -178,6 +180,22 @@ TEST_F(PreviewsHintsTest, IsBlacklisted) {
PreviewsType::LITE_PAGE_REDIRECT));
}
TEST_F(PreviewsHintsTest, IgnoreLitePageRedirectBlacklist) {
std::unique_ptr<PreviewsHints> previews_hints =
PreviewsHints::CreateForTesting(
std::make_unique<TestHostFilter>("black.com"));
base::CommandLine::ForCurrentProcess()->AppendSwitch(
switches::kIgnoreLitePageRedirectOptimizationBlacklist);
EXPECT_FALSE(previews_hints->IsBlacklisted(GURL("https://black.com/path"),
PreviewsType::LOFI));
EXPECT_FALSE(previews_hints->IsBlacklisted(GURL("https://black.com/path"),
PreviewsType::LITE_PAGE_REDIRECT));
EXPECT_FALSE(previews_hints->IsBlacklisted(GURL("https://nonblack.com"),
PreviewsType::LITE_PAGE_REDIRECT));
}
TEST_F(PreviewsHintsTest, IsBlacklistedFromConfig) {
base::test::ScopedFeatureList scoped_list;
scoped_list.InitAndEnableFeature(features::kLitePageServerPreviews);
......
......@@ -13,5 +13,9 @@ const char kIgnorePreviewsBlacklist[] = "ignore-previews-blacklist";
// Override the Lite Page Preview Host.
const char kLitePageServerPreviewHost[] = "litepage-server-previews-host";
// Ignore the optimization hints blacklist for Lite Page Redirect previews.
const char kIgnoreLitePageRedirectOptimizationBlacklist[] =
"ignore-litepage-redirect-optimization-blacklist";
} // namespace switches
} // namespace previews
......@@ -10,6 +10,7 @@ namespace switches {
extern const char kIgnorePreviewsBlacklist[];
extern const char kLitePageServerPreviewHost[];
extern const char kIgnoreLitePageRedirectOptimizationBlacklist[];
} // namespace switches
} // namespace previews
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment