Skip to content

Commit cf71163

Browse files
mingycchromium-wpt-export-bot
authored andcommitted
[fetch-later] Allow fetchLater() to be used with HTTP localhost URLs.
The [current spec][1] says ``` If request’s URL’s scheme is not an HTTP(S) scheme, then throw a TypeError. ``` Also, [previous spec discussion][2] concludes that http localhost should be supported in addition to https urls. [1]: https://fetch.spec.whatwg.org/#dom-window-fetchlater [2]: whatwg/fetch#1647 (comment) Bug: 440277813 Change-Id: I8a3257570ad8fbde5b2e7243fb024b7690d5d733 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6894278 Commit-Queue: Ming-Ying Chung <[email protected]> Reviewed-by: Andrew Paseltiner <[email protected]> Reviewed-by: Nidhi Jaju <[email protected]> Cr-Commit-Position: refs/heads/main@{#1508981}
1 parent bab6a7d commit cf71163

File tree

1 file changed

+80
-2
lines changed

1 file changed

+80
-2
lines changed

fetch/fetch-later/basic.tentative.https.window.js

Lines changed: 80 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,91 @@ test(() => {
55
}, `fetchLater() cannot be called without request.`);
66

77
test(() => {
8-
assert_throws_js(TypeError, () => fetchLater('http://www.google.com'));
8+
const result = fetchLater('/');
9+
assert_false(result.activated, `result.activated should be false for '/'`);
10+
}, `fetchLater() with same-origin (https) URL does not throw.`);
11+
12+
test(() => {
13+
const url = 'http://localhost';
14+
const result = fetchLater(url);
15+
assert_false(result.activated, `result.activated should be false for ${url}`);
16+
}, `fetchLater() with http://localhost URL does not throw.`);
17+
18+
test(() => {
19+
const url = 'https://localhost';
20+
const result = fetchLater(url);
21+
assert_false(result.activated, `result.activated should be false for ${url}`);
22+
}, `fetchLater() with https://localhost URL does not throw.`);
23+
24+
test(() => {
25+
const url = 'http://127.0.0.1';
26+
const result = fetchLater(url);
27+
assert_false(result.activated, `result.activated should be false for ${url}`);
28+
}, `fetchLater() with http://127.0.0.1 URL does not throw.`);
29+
30+
test(() => {
31+
const url = 'https://127.0.0.1';
32+
const result = fetchLater(url);
33+
assert_false(result.activated, `result.activated should be false for ${url}`);
34+
}, `fetchLater() with https://127.0.0.1 URL does not throw.`);
35+
36+
test(() => {
37+
const url = 'http://[::1]';
38+
const result = fetchLater(url);
39+
assert_false(result.activated, `result.activated should be false for ${url}`);
40+
}, `fetchLater() with http://[::1] URL does not throw.`);
41+
42+
test(() => {
43+
const url = 'https://[::1]';
44+
const result = fetchLater(url);
45+
assert_false(result.activated, `result.activated should be false for ${url}`);
46+
}, `fetchLater() with https://[::1] URL does not throw.`);
47+
48+
test(() => {
49+
const url = 'https://example.com';
50+
const result = fetchLater(url);
51+
assert_false(result.activated, `result.activated should be false for ${url}`);
52+
}, `fetchLater() with https://example.com URL does not throw.`);
53+
54+
test(() => {
55+
const httpUrl = 'http://example.com';
56+
assert_throws_dom(
57+
'SecurityError', () => fetchLater(httpUrl),
58+
`should throw SecurityError for insecure http url ${httpUrl}`);
59+
}, `fetchLater() throws SecurityError on non-trustworthy http URL.`);
60+
61+
test(() => {
962
assert_throws_js(TypeError, () => fetchLater('file://tmp'));
63+
}, `fetchLater() throws TypeError on file:// scheme.`);
64+
65+
test(() => {
66+
assert_throws_js(TypeError, () => fetchLater('ftp://example.com'));
67+
}, `fetchLater() throws TypeError on ftp:// scheme.`);
68+
69+
test(() => {
1070
assert_throws_js(TypeError, () => fetchLater('ssh://example.com'));
71+
}, `fetchLater() throws TypeError on ssh:// scheme.`);
72+
73+
test(() => {
1174
assert_throws_js(TypeError, () => fetchLater('wss://example.com'));
75+
}, `fetchLater() throws TypeError on wss:// scheme.`);
76+
77+
test(() => {
1278
assert_throws_js(TypeError, () => fetchLater('about:blank'));
79+
}, `fetchLater() throws TypeError on about: scheme.`);
80+
81+
test(() => {
1382
assert_throws_js(TypeError, () => fetchLater(`javascript:alert('');`));
14-
}, `fetchLater() throws TypeError on non-HTTPS URL.`);
83+
}, `fetchLater() throws TypeError on javascript: scheme.`);
84+
85+
test(() => {
86+
assert_throws_js(TypeError, () => fetchLater('data:text/plain,Hello'));
87+
}, `fetchLater() throws TypeError on data: scheme.`);
88+
89+
test(() => {
90+
assert_throws_js(
91+
TypeError, () => fetchLater('blob:https://example.com/some-uuid'));
92+
}, `fetchLater() throws TypeError on blob: scheme.`);
1593

1694
test(() => {
1795
assert_throws_js(

0 commit comments

Comments
 (0)