Commit 7ef36b85 authored by Shivani Sharma's avatar Shivani Sharma Committed by Commit Bot

[Split Cache] Http cache tests framework to support network isolation key

Populate NetworkIsolationKey in MockHttpRequest so that the tests are
equipped to support partitioned Http cache. Also passes the
generated cache key in various test utility functions instead of simply
the URL.

Bug: 1009621
Change-Id: I5c9577a8bffc9438902bd9c079a703a2dcf6e191
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1830094
Commit-Queue: Shivani Sharma <shivanisha@chromium.org>
Reviewed-by: default avatarJosh Karlin <jkarlin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#708697}
parent 254044d9
......@@ -444,6 +444,7 @@ std::string HttpCache::GetResourceURLFromHttpCacheKey(const std::string& key) {
return key;
}
// static
std::string HttpCache::GenerateCacheKeyForTest(const HttpRequestInfo* request) {
return GenerateCacheKey(request);
}
......@@ -520,6 +521,7 @@ int HttpCache::GetBackendForTransaction(Transaction* transaction) {
return ERR_IO_PENDING;
}
// static
// Generate a key that can be used inside the cache.
std::string HttpCache::GenerateCacheKey(const HttpRequestInfo* request) {
std::string isolation_key;
......@@ -540,7 +542,6 @@ std::string HttpCache::GenerateCacheKey(const HttpRequestInfo* request) {
// concatenate with the network isolation key if we are splitting the cache.
std::string url = isolation_key + HttpUtil::SpecForRequest(request->url);
DCHECK_NE(DISABLE, mode_);
// No valid URL can begin with numerals, so we should not have to worry
// about collisions with normal URLs.
if (request->upload_data_stream &&
......
......@@ -268,7 +268,7 @@ class NET_EXPORT HttpCache : public HttpTransactionFactory {
static std::string GetResourceURLFromHttpCacheKey(const std::string& key);
// Function to generate cache key for testing.
std::string GenerateCacheKeyForTest(const HttpRequestInfo* request);
static std::string GenerateCacheKeyForTest(const HttpRequestInfo* request);
private:
// Types --------------------------------------------------------------------
......@@ -417,7 +417,7 @@ class NET_EXPORT HttpCache : public HttpTransactionFactory {
int GetBackendForTransaction(Transaction* transaction);
// Generates the cache key for this request.
std::string GenerateCacheKey(const HttpRequestInfo*);
static std::string GenerateCacheKey(const HttpRequestInfo*);
// Dooms the entry selected by |key|, if it is currently in the list of active
// entries.
......
This diff is collapsed.
......@@ -20,6 +20,7 @@
#include "net/base/load_flags.h"
#include "net/base/load_timing_info.h"
#include "net/base/net_errors.h"
#include "net/base/network_isolation_key.h"
#include "net/cert/x509_certificate.h"
#include "net/disk_cache/disk_cache.h"
#include "net/http/http_cache.h"
......@@ -174,6 +175,12 @@ MockHttpRequest::MockHttpRequest(const MockTransaction& t) {
method = t.method;
extra_headers.AddHeadersFromString(t.request_headers);
load_flags = t.load_flags;
url::Origin origin = url::Origin::Create(url);
network_isolation_key = NetworkIsolationKey(origin, origin);
}
std::string MockHttpRequest::CacheKey() {
return HttpCache::GenerateCacheKeyForTest(this);
}
//-----------------------------------------------------------------------------
......
......@@ -122,6 +122,7 @@ struct ScopedMockTransaction : MockTransaction {
class MockHttpRequest : public HttpRequestInfo {
public:
explicit MockHttpRequest(const MockTransaction& t);
std::string CacheKey();
};
//-----------------------------------------------------------------------------
......
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