Commit 774e88c5 authored by Alex Turner's avatar Alex Turner Committed by Commit Bot

Ensure valid NIK is present in GenerateCacheKey if split cache enabled

Adapts NetworkContextTest.NotifyExternalCacheHit to enforce its
assumption that the split cache is not enabled. Adds a DCHECK to
GenerateCacheKey, ensuring that the NetworkIsolationKey (NIK) is present
if the split cache is enabled (its absence had caused the test to fail).
This DCHECK is hit by many tests when the split cache is enabled. We fix
the URLLoaderTest.* and SimpleURLLoaderTest.* tests. Other tests will be
fixed in future CLs.

Bug: 1009595
Change-Id: Icf24ad810be6b8adbb179837020ac3520505dfb5
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1837235Reviewed-by: default avatarShivani Sharma <shivanisha@chromium.org>
Reviewed-by: default avatarEric Orth <ericorth@chromium.org>
Commit-Queue: Alex Turner <alexmt@chromium.org>
Cr-Commit-Position: refs/heads/master@{#705336}
parent be56b813
......@@ -530,6 +530,7 @@ std::string HttpCache::GenerateCacheKey(const HttpRequestInfo* request) {
// double-keyed (and makes it an invalid url so that it doesn't get
// confused with a single-keyed entry). Separate the origin and url
// with invalid whitespace character |kDoubleKeySeparator|.
DCHECK(request->network_isolation_key.IsFullyPopulated());
isolation_key = base::StrCat({kDoubleKeyPrefix,
request->network_isolation_key.ToString(),
kDoubleKeySeparator});
......
......@@ -600,6 +600,9 @@ class SimpleURLLoaderTestBase {
mojom::URLLoaderFactoryParams::New();
params->process_id = mojom::kBrowserProcessId;
params->is_corb_enabled = false;
url::Origin origin = url::Origin::Create(test_server_.base_url());
params->network_isolation_key = net::NetworkIsolationKey(origin, origin);
params->is_trusted = true;
network_context_->CreateURLLoaderFactory(
mojo::MakeRequest(&url_loader_factory_), std::move(params));
......@@ -673,6 +676,11 @@ class SimpleURLLoaderTest
resource_request->url = url;
resource_request->method = method;
resource_request->enable_upload_progress = true;
resource_request->trusted_params =
network::ResourceRequest::TrustedParams();
url::Origin request_origin = url::Origin::Create(url);
resource_request->trusted_params->network_isolation_key =
net::NetworkIsolationKey(request_origin, request_origin);
return std::make_unique<SimpleLoaderTestHelper>(std::move(resource_request),
GetParam());
}
......
......@@ -119,9 +119,12 @@ static ResourceRequest CreateResourceRequest(const char* method,
request.method = std::string(method);
request.url = url;
request.site_for_cookies = url; // bypass third-party cookie blocking
request.request_initiator =
url::Origin::Create(url); // ensure initiator is set
url::Origin origin = url::Origin::Create(url);
request.request_initiator = origin; // ensure initiator is set
request.is_main_frame = true;
request.trusted_params = network::ResourceRequest::TrustedParams();
request.trusted_params->network_isolation_key =
net::NetworkIsolationKey(origin, origin);
return request;
}
......@@ -468,6 +471,9 @@ class URLLoaderTest : public testing::Test {
static mojom::URLLoaderFactoryParams params;
params.process_id = mojom::kBrowserProcessId;
params.is_corb_enabled = false;
url::Origin origin = url::Origin::Create(url);
params.network_isolation_key = net::NetworkIsolationKey(origin, origin);
params.is_trusted = true;
url_loader = std::make_unique<URLLoader>(
context(), nullptr /* network_service_client */,
network_context_client.get(),
......
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