Commit 3efb6399 authored by Robert Ogden's avatar Robert Ogden Committed by Commit Bot

HTTPS Previews: Allow the DRP experiment to override Finch-provided one

This allows easier manual testing using chrome://flags

Bug: 934376
Change-Id: Ic9bb78c8c8db20b5a8e6f0f8f5ce26d6897d7e52
Reviewed-on: https://chromium-review.googlesource.com/c/1483390Reviewed-by: default avatarRyan Sturm <ryansturm@chromium.org>
Commit-Queue: Robert Ogden <robertogden@chromium.org>
Cr-Commit-Position: refs/heads/master@{#634841}
parent ff70c6a1
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
#include "base/bind.h" #include "base/bind.h"
#include "base/callback.h" #include "base/callback.h"
#include "base/command_line.h"
#include "base/memory/weak_ptr.h" #include "base/memory/weak_ptr.h"
#include "base/metrics/histogram_macros.h" #include "base/metrics/histogram_macros.h"
#include "base/optional.h" #include "base/optional.h"
...@@ -36,6 +37,7 @@ ...@@ -36,6 +37,7 @@
#include "components/content_settings/core/common/cookie_settings_base.h" #include "components/content_settings/core/common/cookie_settings_base.h"
#include "components/data_reduction_proxy/core/browser/data_reduction_proxy_request_options.h" #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_request_options.h"
#include "components/data_reduction_proxy/core/common/data_reduction_proxy_headers.h" #include "components/data_reduction_proxy/core/common/data_reduction_proxy_headers.h"
#include "components/data_reduction_proxy/core/common/data_reduction_proxy_switches.h"
#include "components/previews/core/previews_experiments.h" #include "components/previews/core/previews_experiments.h"
#include "components/previews/core/previews_lite_page_redirect.h" #include "components/previews/core/previews_lite_page_redirect.h"
#include "content/public/browser/browser_context.h" #include "content/public/browser/browser_context.h"
...@@ -320,6 +322,14 @@ GURL PreviewsLitePageNavigationThrottle::GetPreviewsURLForURL( ...@@ -320,6 +322,14 @@ GURL PreviewsLitePageNavigationThrottle::GetPreviewsURLForURL(
DCHECK(original_url.is_valid()); DCHECK(original_url.is_valid());
std::string experiment_id = std::string experiment_id =
previews::params::LitePageRedirectPreviewExperiment(); previews::params::LitePageRedirectPreviewExperiment();
// Allow the command line to override any variations-provided experiment.
std::string cmd_line_experiment =
base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII(
data_reduction_proxy::switches::kDataReductionProxyExperiment);
if (!cmd_line_experiment.empty())
experiment_id = cmd_line_experiment;
std::string experiment_query; std::string experiment_query;
if (!experiment_id.empty()) { if (!experiment_id.empty()) {
experiment_query = experiment_query =
......
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
#include <memory> #include <memory>
#include "base/command_line.h"
#include "base/memory/ptr_util.h" #include "base/memory/ptr_util.h"
#include "base/metrics/field_trial.h" #include "base/metrics/field_trial.h"
#include "base/metrics/field_trial_params.h" #include "base/metrics/field_trial_params.h"
...@@ -13,6 +14,7 @@ ...@@ -13,6 +14,7 @@
#include "base/test/scoped_task_environment.h" #include "base/test/scoped_task_environment.h"
#include "chrome/browser/previews/previews_lite_page_decider.h" #include "chrome/browser/previews/previews_lite_page_decider.h"
#include "chrome/test/base/chrome_render_view_host_test_harness.h" #include "chrome/test/base/chrome_render_view_host_test_harness.h"
#include "components/data_reduction_proxy/core/common/data_reduction_proxy_switches.h"
#include "components/previews/core/previews_features.h" #include "components/previews/core/previews_features.h"
#include "content/public/browser/navigation_handle.h" #include "content/public/browser/navigation_handle.h"
#include "net/http/http_util.h" #include "net/http/http_util.h"
...@@ -24,7 +26,8 @@ TEST(PreviewsLitePageNavigationThrottleTest, TestGetPreviewsURL) { ...@@ -24,7 +26,8 @@ TEST(PreviewsLitePageNavigationThrottleTest, TestGetPreviewsURL) {
std::string previews_host; std::string previews_host;
std::string original_url; std::string original_url;
std::string expected_previews_url; std::string expected_previews_url;
std::string experiment; std::string experiment_variation;
std::string experiment_cmd_line;
}; };
const TestCase kTestCases[]{ const TestCase kTestCases[]{
// Use https://play.golang.org/p/HUM2HxmUTOW to compute // Use https://play.golang.org/p/HUM2HxmUTOW to compute
...@@ -36,6 +39,7 @@ TEST(PreviewsLitePageNavigationThrottleTest, TestGetPreviewsURL) { ...@@ -36,6 +39,7 @@ TEST(PreviewsLitePageNavigationThrottleTest, TestGetPreviewsURL) {
"previews.host.com/p?u=" "previews.host.com/p?u="
"https%3A%2F%2Foriginal.host.com%2Fpath%2Fpath%2Fpath%3Fquery%3Dyes", "https%3A%2F%2Foriginal.host.com%2Fpath%2Fpath%2Fpath%3Fquery%3Dyes",
"", "",
"",
}, },
{ {
"https://previews.host.com", "https://previews.host.com",
...@@ -52,6 +56,7 @@ TEST(PreviewsLitePageNavigationThrottleTest, TestGetPreviewsURL) { ...@@ -52,6 +56,7 @@ TEST(PreviewsLitePageNavigationThrottleTest, TestGetPreviewsURL) {
"previews.host.com/p?u=https%3A%2F%2Foriginal.host.com%3A1443" "previews.host.com/p?u=https%3A%2F%2Foriginal.host.com%3A1443"
"%2Fpath%2Fpath%2Fpath%3Fquery%3Dyes", "%2Fpath%2Fpath%2Fpath%3Fquery%3Dyes",
"", "",
"",
}, },
{ {
"https://previews.host.com:1443", "https://previews.host.com:1443",
...@@ -60,6 +65,7 @@ TEST(PreviewsLitePageNavigationThrottleTest, TestGetPreviewsURL) { ...@@ -60,6 +65,7 @@ TEST(PreviewsLitePageNavigationThrottleTest, TestGetPreviewsURL) {
"previews.host.com:1443/p?u=" "previews.host.com:1443/p?u="
"http%3A%2F%2Foriginal.host.com%2Fpath%2Fpath%2Fpath%3Fquery%3Dyes", "http%3A%2F%2Foriginal.host.com%2Fpath%2Fpath%2Fpath%3Fquery%3Dyes",
"", "",
"",
}, },
{ {
"https://previews.host.com:1443", "https://previews.host.com:1443",
...@@ -68,6 +74,7 @@ TEST(PreviewsLitePageNavigationThrottleTest, TestGetPreviewsURL) { ...@@ -68,6 +74,7 @@ TEST(PreviewsLitePageNavigationThrottleTest, TestGetPreviewsURL) {
"previews.host.com:1443/p?u=https%3A%2F%2Foriginal.host.com%3A1443" "previews.host.com:1443/p?u=https%3A%2F%2Foriginal.host.com%3A1443"
"%2Fpath%2Fpath%2Fpath%3Fquery%3Dyes", "%2Fpath%2Fpath%2Fpath%3Fquery%3Dyes",
"", "",
"",
}, },
{ {
"https://previews.host.com", "https://previews.host.com",
...@@ -77,6 +84,7 @@ TEST(PreviewsLitePageNavigationThrottleTest, TestGetPreviewsURL) { ...@@ -77,6 +84,7 @@ TEST(PreviewsLitePageNavigationThrottleTest, TestGetPreviewsURL) {
"https%3A%2F%2Foriginal.host.com%2Fpath%2Fpath%2Fpath%3Fquery%3Dyes" "https%3A%2F%2Foriginal.host.com%2Fpath%2Fpath%2Fpath%3Fquery%3Dyes"
"#fragment", "#fragment",
"", "",
"",
}, },
{ {
"https://previews.host.com", "https://previews.host.com",
...@@ -84,8 +92,21 @@ TEST(PreviewsLitePageNavigationThrottleTest, TestGetPreviewsURL) { ...@@ -84,8 +92,21 @@ TEST(PreviewsLitePageNavigationThrottleTest, TestGetPreviewsURL) {
"https://shta44dh4bi7rc6fnpjnkrtytwlabygjhk53v2trlot2wddylwua." "https://shta44dh4bi7rc6fnpjnkrtytwlabygjhk53v2trlot2wddylwua."
"previews.host.com/p?u=" "previews.host.com/p?u="
"https%3A%2F%2Foriginal.host.com%2Fpath%2Fpath%2Fpath%3Fquery%3Dyes" "https%3A%2F%2Foriginal.host.com%2Fpath%2Fpath%2Fpath%3Fquery%3Dyes"
"&x=enable_HTCPCP", "&x=variation_experiment",
"enable_HTCPCP", "variation_experiment",
"",
},
{
// Ensure that the command line experiment takes precedence over the
// one provided by variations.
"https://previews.host.com",
"https://original.host.com/path/path/path?query=yes",
"https://shta44dh4bi7rc6fnpjnkrtytwlabygjhk53v2trlot2wddylwua."
"previews.host.com/p?u="
"https%3A%2F%2Foriginal.host.com%2Fpath%2Fpath%2Fpath%3Fquery%3Dyes"
"&x=cmdline_experiment",
"variation_experiment",
"cmdline_experiment",
}, },
{ {
"https://previews.host.com", "https://previews.host.com",
...@@ -93,15 +114,20 @@ TEST(PreviewsLitePageNavigationThrottleTest, TestGetPreviewsURL) { ...@@ -93,15 +114,20 @@ TEST(PreviewsLitePageNavigationThrottleTest, TestGetPreviewsURL) {
"https://2ikmbopbfxagkb7uer2vgfxmbzu2vw4qq3d3ixe3h2hfhgcabvua." "https://2ikmbopbfxagkb7uer2vgfxmbzu2vw4qq3d3ixe3h2hfhgcabvua."
"previews.host.com/p?u=https%3A%2F%2F%5B%3A%3A1%5D%3A12345%2F", "previews.host.com/p?u=https%3A%2F%2F%5B%3A%3A1%5D%3A12345%2F",
"", "",
"",
}, },
}; };
for (const TestCase& test_case : kTestCases) { for (const TestCase& test_case : kTestCases) {
base::CommandLine::ForCurrentProcess()->AppendSwitchASCII(
data_reduction_proxy::switches::kDataReductionProxyExperiment,
test_case.experiment_cmd_line);
base::test::ScopedFeatureList scoped_feature_list; base::test::ScopedFeatureList scoped_feature_list;
scoped_feature_list.InitAndEnableFeatureWithParameters( scoped_feature_list.InitAndEnableFeatureWithParameters(
previews::features::kLitePageServerPreviews, previews::features::kLitePageServerPreviews,
{{"previews_host", test_case.previews_host}, {{"previews_host", test_case.previews_host},
{"lite_page_preview_experiment", test_case.experiment}}); {"lite_page_preview_experiment", test_case.experiment_variation}});
EXPECT_EQ(PreviewsLitePageNavigationThrottle::GetPreviewsURLForURL( EXPECT_EQ(PreviewsLitePageNavigationThrottle::GetPreviewsURLForURL(
GURL(test_case.original_url)), GURL(test_case.original_url)),
......
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