Commit 3aa4d66b authored by Yifan Luo's avatar Yifan Luo Committed by Commit Bot

[Fetch Metadata] Fix `sec-fetch-dest` for favicon.

Bug: 1053540
Change-Id: Ie6e009915c90669719bbdecb803a5d1065be1836
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2082381
Commit-Queue: Yifan Luo <lyf@chromium.org>
Reviewed-by: default avatarScott Violet <sky@chromium.org>
Reviewed-by: default avatarMike West <mkwst@chromium.org>
Cr-Commit-Position: refs/heads/master@{#750942}
parent 5de8f538
......@@ -69,10 +69,15 @@ class TestURLLoaderInterceptor {
bypass_cache_urls_.clear();
}
network::mojom::RequestDestination destination(const GURL& url) {
return destinations_[url];
}
private:
bool InterceptURLRequest(
content::URLLoaderInterceptor::RequestParams* params) {
intercepted_urls_.insert(params->url_request.url);
destinations_[params->url_request.url] = params->url_request.destination;
if (params->url_request.load_flags & net::LOAD_BYPASS_CACHE)
bypass_cache_urls_.insert(params->url_request.url);
return false;
......@@ -81,6 +86,7 @@ class TestURLLoaderInterceptor {
std::set<GURL> intercepted_urls_;
std::set<GURL> bypass_cache_urls_;
content::URLLoaderInterceptor interceptor_;
std::map<GURL, network::mojom::RequestDestination> destinations_;
DISALLOW_COPY_AND_ASSIGN(TestURLLoaderInterceptor);
};
......@@ -278,6 +284,8 @@ IN_PROC_BROWSER_TEST_F(ContentFaviconDriverTest, ReloadBypassingCache) {
waiter.Wait();
}
ASSERT_TRUE(url_loader_interceptor.was_loaded(icon_url));
ASSERT_EQ(network::mojom::RequestDestination::kImage,
url_loader_interceptor.destination(icon_url));
EXPECT_FALSE(url_loader_interceptor.did_bypass_cache(icon_url));
url_loader_interceptor.Reset();
......@@ -293,6 +301,8 @@ IN_PROC_BROWSER_TEST_F(ContentFaviconDriverTest, ReloadBypassingCache) {
waiter.Wait();
}
EXPECT_FALSE(url_loader_interceptor.did_bypass_cache(icon_url));
ASSERT_EQ(network::mojom::RequestDestination::kImage,
url_loader_interceptor.destination(icon_url));
url_loader_interceptor.Reset();
// A reload ignoring the cache should refetch the favicon from the website.
......@@ -302,6 +312,8 @@ IN_PROC_BROWSER_TEST_F(ContentFaviconDriverTest, ReloadBypassingCache) {
waiter.Wait();
}
ASSERT_TRUE(url_loader_interceptor.was_loaded(icon_url));
ASSERT_EQ(network::mojom::RequestDestination::kImage,
url_loader_interceptor.destination(icon_url));
EXPECT_TRUE(url_loader_interceptor.did_bypass_cache(icon_url));
}
......@@ -426,6 +438,8 @@ IN_PROC_BROWSER_TEST_F(ContentFaviconDriverTest, LoadIconFromWebManifest) {
#if defined(OS_ANDROID)
EXPECT_TRUE(url_loader_interceptor.was_loaded(icon_url));
ASSERT_EQ(network::mojom::RequestDestination::kImage,
url_loader_interceptor.destination(icon_url));
EXPECT_NE(nullptr,
GetFaviconForPageURL(url, favicon_base::IconType::kWebManifestIcon)
.bitmap_data);
......@@ -776,6 +790,8 @@ IN_PROC_BROWSER_TEST_F(ContentFaviconDriverTestWithAutoupgradesDisabled,
waiter.Wait();
EXPECT_TRUE(url_interceptor.was_loaded(favicon_url));
ASSERT_EQ(network::mojom::RequestDestination::kImage,
url_interceptor.destination(favicon_url));
}
IN_PROC_BROWSER_TEST_F(ContentFaviconDriverTest, SVGFavicon) {
......
......@@ -45,7 +45,9 @@ SubresourceRedirectURLLoaderThrottle::MaybeCreateThrottle(
request.GetRequestDestination() ==
network::mojom::RequestDestination::kImage &&
request.Url().ProtocolIs(url::kHttpsScheme) &&
blink::WebNetworkStateNotifier::SaveDataEnabled()) {
blink::WebNetworkStateNotifier::SaveDataEnabled() &&
request.GetRequestContext() !=
blink::mojom::RequestContextType::FAVICON) {
return base::WrapUnique<SubresourceRedirectURLLoaderThrottle>(
new SubresourceRedirectURLLoaderThrottle(
render_frame_id, request.GetPreviewsState() &
......
include_rules = [
"+services/network/public/cpp/request_destination.h",
"+skia/ext/image_operations.h",
"+ui/gfx/geometry/size.h",
]
......@@ -209,6 +209,7 @@ void MultiResolutionImageResourceFetcher::Start(
request_.SetSiteForCookies(frame->GetDocument()->SiteForCookies());
request_.SetMode(request_mode);
request_.SetCredentialsMode(credentials_mode);
request_.SetRequestDestination(network::mojom::RequestDestination::kImage);
client_ = std::make_unique<ClientImpl>(std::move(callback));
......
......@@ -48,6 +48,10 @@ crbug.com/1048761 external/wpt/infrastructure/server/http2-context.sub.h2.any.sh
crbug.com/1048761 external/wpt/infrastructure/server/http2-context.sub.h2.any.worker.html [ Skip ]
crbug.com/1048761 external/wpt/infrastructure/server/wpt-server-http.sub.html [ Skip ]
# Favicon is not supported by run_web_tests.
external/wpt/fetch/metadata/favicon.https.sub.html [ Skip ]
virtual/omt-worker-fetch/external/wpt/fetch/metadata/favicon.https.sub.html [ Skip ]
crbug.com/807686 crbug.com/24182 jquery/manipulation.html [ Timeout Pass ]
# The following tests need to remove the assumption that user activation isvirtual/text-antialias/firstline/capitalize-transform.html
......
<!DOCTYPE html>
<html>
<link rel="author" href="mtrzos@google.com" title="Maciek Trzos">
<script src=/resources/testharness.js></script>
<script src=/resources/testharnessreport.js></script>
<script src=/fetch/metadata/resources/helper.js></script>
<script src=/common/utils.js></script>
<body></body>
<script>
promise_test(t => {
return new Promise((resolve, reject) => {
let nonce = token();
let key = "image" + nonce;
let e = document.createElement('link');
e.rel = "icon";
e.type = "image/png";
e.href = "https://{{host}}:{{ports[https][0]}}/fetch/metadata/resources/record-header.py?file=" + key;
document.head.appendChild(e);
t.step_timeout(_=> {
let expected = {"site":"same-origin", "user":"", "mode": "no-cors", "dest": "image"};
validate_expectations(key, expected, "Same-Origin favicon")
.then(_ => resolve())
.catch(e => reject(e));
}, 1000);
})
}, "Same-Origin favicon");
promise_test(t => {
return new Promise((resolve, reject) => {
let nonce = token();
let key = "image" + nonce;
let e = document.createElement('link');
e.rel = "icon";
e.type = "image/png";
e.href = "https://{{hosts[][www]}}:{{ports[https][0]}}/fetch/metadata/resources/record-header.py?file=" + key;
document.head.appendChild(e);
t.step_timeout(_=> {
let expected = {"site":"same-site", "user":"", "mode": "no-cors", "dest": "image"};
validate_expectations(key, expected, "Same-Site favicon")
.then(_ => resolve())
.catch(e => reject(e));
}, 1000);
})
}, "Same-Site favicon");
promise_test(t => {
return new Promise((resolve, reject) => {
let nonce = token();
let key = "image" + nonce;
let e = document.createElement('link');
e.rel = "icon";
e.type = "image/png";
e.href = "https://{{hosts[alt][www]}}:{{ports[https][0]}}/fetch/metadata/resources/record-header.py?file=" + key;
document.head.appendChild(e);
t.step_timeout(_=> {
let expected = {"site":"cross-site", "user":"", "mode": "no-cors", "dest": "image"};
validate_expectations(key, expected, "Cross-Site favicon")
.then(_ => resolve())
.catch(e => reject(e));
}, 1000);
})
}, "Cross-Site favicon");
</script>
</html>
\ No newline at end of file
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