Commit 53ddd03f authored by Alex Turner's avatar Alex Turner Committed by Commit Bot

Use explicit third-party domains in PrefetchBrowserTests

PrefetchBrowserTest.CrossOriginWithPreload is currently failing when
split cache and UseRegistrableDomainInNetworkIsolationKey are enabled.
The cause is the cross_origin_server_'s URLs only differing from the
embedded_test_server's in the port used, resulting in an identical
scheme and eTLD+1.

We thus explicitly specify third-party domains that differ in eTLD+1,
also changing other tests for consistency. We also disable HTTPS to
avoid SSL certificate errors from mismatched host names.

Bug: 1035499
Change-Id: Ibb6b566814743343a93e6538cecd1f5771486810
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2001140
Commit-Queue: Alex Turner <alexmt@chromium.org>
Reviewed-by: default avatarShivani Sharma <shivanisha@chromium.org>
Reviewed-by: default avatarCharlie Harrison <csharrison@chromium.org>
Reviewed-by: default avatarTsuyoshi Horo <horo@chromium.org>
Cr-Commit-Position: refs/heads/master@{#731999}
parent e02bdc5b
...@@ -18,6 +18,7 @@ ...@@ -18,6 +18,7 @@
#include "content/public/test/content_browser_test_utils.h" #include "content/public/test/content_browser_test_utils.h"
#include "content/shell/browser/shell.h" #include "content/shell/browser/shell.h"
#include "net/base/features.h" #include "net/base/features.h"
#include "net/dns/mock_host_resolver.h"
#include "services/network/public/cpp/features.h" #include "services/network/public/cpp/features.h"
#include "third_party/blink/public/common/features.h" #include "third_party/blink/public/common/features.h"
...@@ -28,12 +29,16 @@ class PrefetchBrowserTest ...@@ -28,12 +29,16 @@ class PrefetchBrowserTest
public testing::WithParamInterface<std::tuple<bool, bool>> { public testing::WithParamInterface<std::tuple<bool, bool>> {
public: public:
PrefetchBrowserTest() PrefetchBrowserTest()
: cross_origin_server_(std::make_unique<net::EmbeddedTestServer>( : cross_origin_server_(std::make_unique<net::EmbeddedTestServer>()),
net::EmbeddedTestServer::TYPE_HTTPS)),
signed_exchange_enabled_(std::get<0>(GetParam())), signed_exchange_enabled_(std::get<0>(GetParam())),
split_cache_enabled_(std::get<1>(GetParam())) {} split_cache_enabled_(std::get<1>(GetParam())) {}
~PrefetchBrowserTest() = default; ~PrefetchBrowserTest() = default;
void SetUpOnMainThread() override {
PrefetchBrowserTestBase::SetUpOnMainThread();
host_resolver()->AddRule("*", "127.0.0.1");
}
void SetUp() override { void SetUp() override {
std::vector<base::Feature> enable_features; std::vector<base::Feature> enable_features;
std::vector<base::Feature> disabled_features; std::vector<base::Feature> disabled_features;
...@@ -76,8 +81,7 @@ class PrefetchBrowserTestPrivacyChanges ...@@ -76,8 +81,7 @@ class PrefetchBrowserTestPrivacyChanges
public: public:
PrefetchBrowserTestPrivacyChanges() PrefetchBrowserTestPrivacyChanges()
: privacy_changes_enabled_(GetParam()), : privacy_changes_enabled_(GetParam()),
cross_origin_server_(std::make_unique<net::EmbeddedTestServer>( cross_origin_server_(std::make_unique<net::EmbeddedTestServer>()) {}
net::EmbeddedTestServer::TYPE_HTTPS)) {}
~PrefetchBrowserTestPrivacyChanges() override = default; ~PrefetchBrowserTestPrivacyChanges() override = default;
void SetUp() override { void SetUp() override {
...@@ -167,7 +171,7 @@ IN_PROC_BROWSER_TEST_P(PrefetchBrowserTest, ...@@ -167,7 +171,7 @@ IN_PROC_BROWSER_TEST_P(PrefetchBrowserTest,
ASSERT_TRUE(cross_origin_server_->Start()); ASSERT_TRUE(cross_origin_server_->Start());
const GURL cross_origin_target_url = const GURL cross_origin_target_url =
cross_origin_server_->GetURL(target_path); cross_origin_server_->GetURL("3p.example", target_path);
RegisterResponse( RegisterResponse(
prefetch_path, prefetch_path,
ResponseEntry(base::StringPrintf( ResponseEntry(base::StringPrintf(
...@@ -219,9 +223,10 @@ IN_PROC_BROWSER_TEST_P(PrefetchBrowserTest, ...@@ -219,9 +223,10 @@ IN_PROC_BROWSER_TEST_P(PrefetchBrowserTest,
RegisterRequestHandler(cross_origin_server_.get()); RegisterRequestHandler(cross_origin_server_.get());
ASSERT_TRUE(cross_origin_server_->Start()); ASSERT_TRUE(cross_origin_server_->Start());
const GURL cross_origin_host_url = cross_origin_server_->GetURL(host_path); const GURL cross_origin_host_url =
cross_origin_server_->GetURL("3p.example", host_path);
const GURL cross_origin_iframe_url = const GURL cross_origin_iframe_url =
cross_origin_server_->GetURL(iframe_path); cross_origin_server_->GetURL("3p.example", iframe_path);
RegisterResponse( RegisterResponse(
prefetch_path, prefetch_path,
ResponseEntry(base::StringPrintf( ResponseEntry(base::StringPrintf(
...@@ -277,9 +282,10 @@ IN_PROC_BROWSER_TEST_P(PrefetchBrowserTest, CrossOriginSubresourceNotReused) { ...@@ -277,9 +282,10 @@ IN_PROC_BROWSER_TEST_P(PrefetchBrowserTest, CrossOriginSubresourceNotReused) {
RegisterRequestHandler(cross_origin_server_.get()); RegisterRequestHandler(cross_origin_server_.get());
ASSERT_TRUE(cross_origin_server_->Start()); ASSERT_TRUE(cross_origin_server_->Start());
const GURL cross_origin_host_url = cross_origin_server_->GetURL(host_path); const GURL cross_origin_host_url =
cross_origin_server_->GetURL("3p.example", host_path);
const GURL cross_origin_subresource_url = const GURL cross_origin_subresource_url =
cross_origin_server_->GetURL(subresource_path); cross_origin_server_->GetURL("3p.example", subresource_path);
RegisterResponse(prefetch_path, RegisterResponse(prefetch_path,
ResponseEntry(base::StringPrintf( ResponseEntry(base::StringPrintf(
"<body><link rel='prefetch' href='%s'></body>", "<body><link rel='prefetch' href='%s'></body>",
...@@ -324,7 +330,7 @@ IN_PROC_BROWSER_TEST_P(PrefetchBrowserTest, ...@@ -324,7 +330,7 @@ IN_PROC_BROWSER_TEST_P(PrefetchBrowserTest,
ASSERT_TRUE(cross_origin_server_->Start()); ASSERT_TRUE(cross_origin_server_->Start());
const GURL cross_origin_subresource_url = const GURL cross_origin_subresource_url =
cross_origin_server_->GetURL(subresource_path); cross_origin_server_->GetURL("3p.example", subresource_path);
RegisterResponse(prefetch_path, RegisterResponse(prefetch_path,
ResponseEntry(base::StringPrintf( ResponseEntry(base::StringPrintf(
"<body><link rel='prefetch' href='%s'></body>", "<body><link rel='prefetch' href='%s'></body>",
...@@ -383,7 +389,7 @@ IN_PROC_BROWSER_TEST_P(PrefetchBrowserTest, ...@@ -383,7 +389,7 @@ IN_PROC_BROWSER_TEST_P(PrefetchBrowserTest,
ASSERT_TRUE(cross_origin_server_->Start()); ASSERT_TRUE(cross_origin_server_->Start());
const GURL cross_origin_subresource_url = const GURL cross_origin_subresource_url =
cross_origin_server_->GetURL(subresource_path); cross_origin_server_->GetURL("3p.example", subresource_path);
RegisterResponse(prefetch_path, RegisterResponse(prefetch_path,
ResponseEntry(base::StringPrintf( ResponseEntry(base::StringPrintf(
"<body><link rel='prefetch' href='%s'></body>", "<body><link rel='prefetch' href='%s'></body>",
...@@ -614,7 +620,8 @@ IN_PROC_BROWSER_TEST_P(PrefetchBrowserTest, CrossOriginWithPreload) { ...@@ -614,7 +620,8 @@ IN_PROC_BROWSER_TEST_P(PrefetchBrowserTest, CrossOriginWithPreload) {
ASSERT_TRUE(cross_origin_server_->Start()); ASSERT_TRUE(cross_origin_server_->Start());
const GURL cross_origin_target_url = const GURL cross_origin_target_url =
cross_origin_server_->GetURL(target_path); cross_origin_server_->GetURL("3p.example", target_path);
const char* prefetch_path = "/prefetch.html"; const char* prefetch_path = "/prefetch.html";
RegisterResponse(prefetch_path, RegisterResponse(prefetch_path,
ResponseEntry(base::StringPrintf( ResponseEntry(base::StringPrintf(
...@@ -634,7 +641,8 @@ IN_PROC_BROWSER_TEST_P(PrefetchBrowserTest, CrossOriginWithPreload) { ...@@ -634,7 +641,8 @@ IN_PROC_BROWSER_TEST_P(PrefetchBrowserTest, CrossOriginWithPreload) {
EXPECT_EQ(1, preload_request_counter->GetRequestCount()); EXPECT_EQ(1, preload_request_counter->GetRequestCount());
EXPECT_EQ(split_cache_enabled_ ? 2 : 1, GetPrefetchURLLoaderCallCount()); EXPECT_EQ(split_cache_enabled_ ? 2 : 1, GetPrefetchURLLoaderCallCount());
GURL cross_origin_preload_url = cross_origin_server_->GetURL(preload_path); GURL cross_origin_preload_url =
cross_origin_server_->GetURL("3p.example", preload_path);
WaitUntilLoaded(cross_origin_preload_url); WaitUntilLoaded(cross_origin_preload_url);
// When SplitCache is enabled and the prefetch resource and its headers are // When SplitCache is enabled and the prefetch resource and its headers are
...@@ -658,8 +666,7 @@ IN_PROC_BROWSER_TEST_P(PrefetchBrowserTest, CrossOriginWithPreload) { ...@@ -658,8 +666,7 @@ IN_PROC_BROWSER_TEST_P(PrefetchBrowserTest, CrossOriginWithPreload) {
cross_origin_preload_url.spec().c_str())}, cross_origin_preload_url.spec().c_str())},
{"access-control-allow-origin", "*"}})); {"access-control-allow-origin", "*"}}));
std::unique_ptr<net::EmbeddedTestServer> other_cross_origin_server = std::unique_ptr<net::EmbeddedTestServer> other_cross_origin_server =
std::make_unique<net::EmbeddedTestServer>( std::make_unique<net::EmbeddedTestServer>();
net::EmbeddedTestServer::TYPE_HTTPS);
RegisterRequestHandler(other_cross_origin_server.get()); RegisterRequestHandler(other_cross_origin_server.get());
ASSERT_TRUE(other_cross_origin_server->Start()); ASSERT_TRUE(other_cross_origin_server->Start());
...@@ -667,8 +674,9 @@ IN_PROC_BROWSER_TEST_P(PrefetchBrowserTest, CrossOriginWithPreload) { ...@@ -667,8 +674,9 @@ IN_PROC_BROWSER_TEST_P(PrefetchBrowserTest, CrossOriginWithPreload) {
// Navigate to a page on the above-created server. A request for the same // Navigate to a page on the above-created server. A request for the same
// preload header fetched earlier must not be reusable, and must hit the // preload header fetched earlier must not be reusable, and must hit the
// network. // network.
EXPECT_TRUE(NavigateToURL(shell(), other_cross_origin_server->GetURL( EXPECT_TRUE(NavigateToURL(
reuse_preload_attempt_path))); shell(), other_cross_origin_server->GetURL(
"other3p.example", reuse_preload_attempt_path)));
preload_waiter_second_request.Run(); preload_waiter_second_request.Run();
EXPECT_EQ(2, preload_request_counter_second_request->GetRequestCount()); EXPECT_EQ(2, preload_request_counter_second_request->GetRequestCount());
...@@ -782,9 +790,10 @@ IN_PROC_BROWSER_TEST_P(PrefetchBrowserTest, ...@@ -782,9 +790,10 @@ IN_PROC_BROWSER_TEST_P(PrefetchBrowserTest,
RegisterRequestHandler(cross_origin_server_.get()); RegisterRequestHandler(cross_origin_server_.get());
ASSERT_TRUE(cross_origin_server_->Start()); ASSERT_TRUE(cross_origin_server_->Start());
const GURL target_sxg_url = cross_origin_server_->GetURL(target_sxg_path); const GURL target_sxg_url =
cross_origin_server_->GetURL("3p.example", target_sxg_path);
const GURL preload_url_in_sxg = const GURL preload_url_in_sxg =
cross_origin_server_->GetURL(preload_path_in_sxg); cross_origin_server_->GetURL("3p.example", preload_path_in_sxg);
RegisterResponse( RegisterResponse(
prefetch_path, prefetch_path,
...@@ -797,7 +806,8 @@ IN_PROC_BROWSER_TEST_P(PrefetchBrowserTest, ...@@ -797,7 +806,8 @@ IN_PROC_BROWSER_TEST_P(PrefetchBrowserTest,
MockSignedExchangeHandlerFactory factory({MockSignedExchangeHandlerParams( MockSignedExchangeHandlerFactory factory({MockSignedExchangeHandlerParams(
target_sxg_url, SignedExchangeLoadResult::kSuccess, net::OK, target_sxg_url, SignedExchangeLoadResult::kSuccess, net::OK,
GURL(cross_origin_server_->GetURL(target_path)), "text/html", GURL(cross_origin_server_->GetURL("3p.example", target_path)),
"text/html",
{base::StringPrintf("Link: <%s>;rel=\"preload\";as=\"script\"", {base::StringPrintf("Link: <%s>;rel=\"preload\";as=\"script\"",
preload_url_in_sxg.spec().c_str())}, preload_url_in_sxg.spec().c_str())},
net::SHA256HashValue({{0x00}}))}); net::SHA256HashValue({{0x00}}))});
......
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