Commit bca6d608 authored by Tarun Bansal's avatar Tarun Bansal Committed by Commit Bot

Add browser tests for late arrival of loading hints

Add regression test for the case where the loading hints arrive
late in Blink. A new HTML file is added that loads resources
using link-rel preload. The existing browsertest fails in
that case.

Bug: 891328
Change-Id: Id100da5b7c16c357132dcbf875d1d2048968c7c1
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1663355
Commit-Queue: Tarun Bansal <tbansal@chromium.org>
Reviewed-by: default avatarDoug Arnett <dougarnett@chromium.org>
Cr-Commit-Position: refs/heads/master@{#670149}
parent 1b1948aa
......@@ -93,6 +93,9 @@ class ResourceLoadingNoFeaturesBrowserTest : public InProcessBrowserTest {
https_url_ = https_server_->GetURL("/resource_loading_hints.html");
ASSERT_TRUE(https_url_.SchemeIs(url::kHttpsScheme));
https_url_preload_ =
https_server_->GetURL("/resource_loading_hints_preload.html");
https_second_url_ =
https_server_->GetURL("/resource_loading_hints_second.html");
ASSERT_TRUE(https_second_url_.SchemeIs(url::kHttpsScheme));
......@@ -251,7 +254,8 @@ class ResourceLoadingNoFeaturesBrowserTest : public InProcessBrowserTest {
LoadHintsForUrl(hint_setup_url);
}
const GURL& https_url() const { return https_url_; }
virtual const GURL& https_url() const { return https_url_; }
const GURL& https_url_preload() const { return https_url_preload_; }
const GURL& https_second_url() const { return https_second_url_; }
const GURL& https_no_transform_url() const { return https_no_transform_url_; }
const GURL& https_hint_setup_url() const { return https_hint_setup_url_; }
......@@ -337,6 +341,7 @@ class ResourceLoadingNoFeaturesBrowserTest : public InProcessBrowserTest {
std::unique_ptr<net::EmbeddedTestServer> https_server_;
std::unique_ptr<net::EmbeddedTestServer> http_server_;
GURL https_url_;
GURL https_url_preload_;
GURL https_second_url_;
GURL https_no_transform_url_;
GURL https_hint_setup_url_;
......@@ -356,8 +361,11 @@ class ResourceLoadingNoFeaturesBrowserTest : public InProcessBrowserTest {
};
// This test class enables ResourceLoadingHints with OptimizationHints.
// Parameter is true if the test should be run with a webpage that preloads
// resources in the HTML head using link-rel preload.
class ResourceLoadingHintsBrowserTest
: public ResourceLoadingNoFeaturesBrowserTest {
: public ::testing::WithParamInterface<bool>,
public ResourceLoadingNoFeaturesBrowserTest {
public:
ResourceLoadingHintsBrowserTest() = default;
......@@ -376,10 +384,22 @@ class ResourceLoadingHintsBrowserTest
ResourceLoadingNoFeaturesBrowserTest::SetUp();
}
const GURL& https_url() const override {
if (GetParam())
return ResourceLoadingNoFeaturesBrowserTest::https_url_preload();
return ResourceLoadingNoFeaturesBrowserTest::https_url();
}
private:
DISALLOW_COPY_AND_ASSIGN(ResourceLoadingHintsBrowserTest);
};
// Parameter is true if the test should be run with a webpage that preloads
// resources in the HTML head using link-rel preload.
INSTANTIATE_TEST_SUITE_P(,
ResourceLoadingHintsBrowserTest,
::testing::Values(false, true));
// Previews InfoBar (which these tests triggers) does not work on Mac.
// See https://crbug.com/782322 for details. Also occasional flakes on win7
// (https://crbug.com/789542).
......@@ -389,9 +409,14 @@ class ResourceLoadingHintsBrowserTest
#define DISABLE_ON_WIN_MAC_CHROMESOS(x) x
#endif
IN_PROC_BROWSER_TEST_F(
IN_PROC_BROWSER_TEST_P(
ResourceLoadingHintsBrowserTest,
DISABLE_ON_WIN_MAC_CHROMESOS(ResourceLoadingHintsHttpsWhitelisted)) {
// TODO(https://crbug.com/891328): The test does not pass when resources are
// loaded using link-rel preload.
if (GetParam())
return;
GURL url = https_url();
// Whitelist resource loading hints for https_hint_setup_url()'s' host.
......@@ -451,7 +476,7 @@ IN_PROC_BROWSER_TEST_F(
// Sets only the experimental hints, but does not enable the matching
// experiment. Verifies that the hints are not used, and the resource loading is
// not blocked.
IN_PROC_BROWSER_TEST_F(
IN_PROC_BROWSER_TEST_P(
ResourceLoadingHintsBrowserTest,
DISABLE_ON_WIN_MAC_CHROMESOS(ExperimentalHints_ExperimentIsNotEnabled)) {
GURL url = https_url();
......@@ -479,9 +504,14 @@ IN_PROC_BROWSER_TEST_F(
// Sets only the experimental hints, and enables the matching experiment.
// Verifies that the hints are used, and the resource loading is blocked.
IN_PROC_BROWSER_TEST_F(
IN_PROC_BROWSER_TEST_P(
ResourceLoadingHintsBrowserTest,
DISABLE_ON_WIN_MAC_CHROMESOS(ExperimentalHints_ExperimentIsEnabled)) {
// TODO(https://crbug.com/891328): The test does not pass when resources are
// loaded using link-rel preload.
if (GetParam())
return;
base::test::ScopedFeatureList scoped_list;
scoped_list.InitAndEnableFeatureWithParameters(
previews::features::kOptimizationHintsExperiments,
......@@ -522,9 +552,13 @@ IN_PROC_BROWSER_TEST_F(
// Sets both the experimental and default hints, and enables the matching
// experiment. Verifies that the hints are used, and the resource loading is
// blocked.
IN_PROC_BROWSER_TEST_F(
IN_PROC_BROWSER_TEST_P(
ResourceLoadingHintsBrowserTest,
DISABLE_ON_WIN_MAC_CHROMESOS(MixExperimentalHints_ExperimentIsEnabled)) {
// TODO(https://crbug.com/891328): The test does not pass when resources are
// loaded using link-rel preload.
if (GetParam())
return;
base::test::ScopedFeatureList scoped_list;
scoped_list.InitAndEnableFeatureWithParameters(
previews::features::kOptimizationHintsExperiments,
......@@ -566,7 +600,7 @@ IN_PROC_BROWSER_TEST_F(
// Sets the default hints with a non-wildcard page pattern. Loads a webpage from
// an origin for which the hints are present, but the page pattern does not
// match. Verifies that the hints are not used on that webpage.
IN_PROC_BROWSER_TEST_F(
IN_PROC_BROWSER_TEST_P(
ResourceLoadingHintsBrowserTest,
DISABLE_ON_WIN_MAC_CHROMESOS(MatchingOrigin_NonMatchingPagePattern)) {
const GURL url = https_url();
......@@ -604,9 +638,13 @@ IN_PROC_BROWSER_TEST_F(
// webpage from a host for which the hints are present (page pattern matches).
// Next, loads a webpage from the same host but the webpage's URL does not match
// the page patterns. Verifies that the hints are not used on that webpage.
IN_PROC_BROWSER_TEST_F(
IN_PROC_BROWSER_TEST_P(
ResourceLoadingHintsBrowserTest,
DISABLE_ON_WIN_MAC_CHROMESOS(SameOriginDifferentPattern)) {
// TODO(https://crbug.com/891328): The test does not pass when resources are
// loaded using link-rel preload.
if (GetParam())
return;
// Whitelist resource loading hints for https_url()'s' host and pattern.
SetDefaultOnlyResourceLoadingHintsWithPagePattern(https_url(),
https_url().path());
......@@ -667,9 +705,13 @@ IN_PROC_BROWSER_TEST_F(
// Sets both the experimental and default hints, but does not enable the
// matching experiment. Verifies that the hints from the experiment are not
// used.
IN_PROC_BROWSER_TEST_F(
IN_PROC_BROWSER_TEST_P(
ResourceLoadingHintsBrowserTest,
DISABLE_ON_WIN_MAC_CHROMESOS(MixExperimentalHints_ExperimentIsNotEnabled)) {
// TODO(https://crbug.com/891328): The test does not pass when resources are
// loaded using link-rel preload.
if (GetParam())
return;
base::test::ScopedFeatureList scoped_list;
scoped_list.InitAndEnableFeatureWithParameters(
previews::features::kOptimizationHintsExperiments,
......@@ -702,10 +744,14 @@ IN_PROC_BROWSER_TEST_F(
EXPECT_TRUE(resource_loading_hint_intervention_header_seen());
}
IN_PROC_BROWSER_TEST_F(
IN_PROC_BROWSER_TEST_P(
ResourceLoadingHintsBrowserTest,
DISABLE_ON_WIN_MAC_CHROMESOS(
ResourceLoadingHintsHttpsWhitelistedRedirectToHttps)) {
// TODO(https://crbug.com/891328): The test does not pass when resources are
// loaded using link-rel preload.
if (GetParam())
return;
GURL url = redirect_url();
// Whitelist resource loading hints for https_hint_setup_url()'s' host.
......@@ -738,7 +784,7 @@ IN_PROC_BROWSER_TEST_F(
EXPECT_TRUE(resource_loading_hint_intervention_header_seen());
}
IN_PROC_BROWSER_TEST_F(
IN_PROC_BROWSER_TEST_P(
ResourceLoadingHintsBrowserTest,
DISABLE_ON_WIN_MAC_CHROMESOS(ResourceLoadingHintsHttpsNotWhitelisted)) {
GURL url = https_url();
......@@ -766,7 +812,7 @@ IN_PROC_BROWSER_TEST_F(
EXPECT_FALSE(resource_loading_hint_intervention_header_seen());
}
IN_PROC_BROWSER_TEST_F(ResourceLoadingHintsBrowserTest,
IN_PROC_BROWSER_TEST_P(ResourceLoadingHintsBrowserTest,
DISABLE_ON_WIN_MAC_CHROMESOS(ResourceLoadingHintsHttp)) {
GURL url = http_url();
......@@ -792,7 +838,7 @@ IN_PROC_BROWSER_TEST_F(ResourceLoadingHintsBrowserTest,
EXPECT_FALSE(resource_loading_hint_intervention_header_seen());
}
IN_PROC_BROWSER_TEST_F(ResourceLoadingHintsBrowserTest,
IN_PROC_BROWSER_TEST_P(ResourceLoadingHintsBrowserTest,
DISABLE_ON_WIN_MAC_CHROMESOS(
ResourceLoadingHintsHttpsWhitelistedNoTransform)) {
GURL url = https_no_transform_url();
......@@ -819,7 +865,7 @@ IN_PROC_BROWSER_TEST_F(ResourceLoadingHintsBrowserTest,
EXPECT_FALSE(resource_loading_hint_intervention_header_seen());
}
IN_PROC_BROWSER_TEST_F(
IN_PROC_BROWSER_TEST_P(
ResourceLoadingHintsBrowserTest,
DISABLE_ON_WIN_MAC_CHROMESOS(
ResourceLoadingHintsHttpsWhitelistedButShouldNotApplyBecauseCoinFlipHoldback)) {
......
<html>
<head>
<link rel="stylesheet" href="foo.jpg" as="style">
<link rel="stylesheet" href="bar.jpg" as="style">
</head>
<body>
<p>Test page for Resource Loading Hints.</p>
</body>
</html>
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