Skip to content

Commit e4556cd

Browse files
Bug 1659563 [wpt PR 25053] - Allow range requests to pass through a service worker, a=testonly
Automatic update from web-platform-tests Allow range requests to pass through a service worker (#25053) This change implements the following edits to the Fetch spec: whatwg/fetch#560 whatwg/fetch#1076 Existing web tests cover the new functionality. Bug: 847428 Change-Id: Ie63704769e99d4b8d26d8903edf4cc4e3466c124 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2339761 Commit-Queue: Nicolas Arciniega <[email protected]> Reviewed-by: Kinuko Yasuda <[email protected]> Reviewed-by: Matt Falkenhagen <[email protected]> Reviewed-by: Ben Kelly <[email protected]> Reviewed-by: Yutaka Hirano <[email protected]> Reviewed-by: Makoto Shimazu <[email protected]> Cr-Commit-Position: refs/heads/master@{#800663} Co-authored-by: Nicolas Arciniega <[email protected]> -- wpt-commits: 868ca3586f9dda74b2bb3b6f6dfb67a13e359090 wpt-pr: 25053
1 parent 3a484ff commit e4556cd

File tree

5 files changed

+41
-2
lines changed

5 files changed

+41
-2
lines changed

testing/web-platform/tests/fetch/range/sw.https.window.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -86,11 +86,11 @@ promise_test(async t => {
8686

8787
// Fetching should reject
8888
const fetchPromise = w.fetch('?action=use-stored-ranged-response', { mode: 'no-cors' });
89-
promise_rejects_js(t, TypeError, fetchPromise);
89+
await promise_rejects_js(t, w.TypeError, fetchPromise);
9090

9191
// Script loading should error too
9292
const loadScriptPromise = loadScript('?action=use-stored-ranged-response', { doc: w.document });
93-
promise_rejects_js(t, Error, loadScriptPromise);
93+
await promise_rejects_js(t, Error, loadScriptPromise);
9494

9595
await loadScriptPromise.catch(() => {});
9696

testing/web-platform/tests/service-workers/cache-storage/script-tests/cache-add.js

+18
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
if (self.importScripts) {
22
importScripts('/resources/testharness.js');
3+
importScripts('/common/get-host-info.sub.js');
34
importScripts('../resources/test-helpers.js');
45
}
56

7+
const { REMOTE_HOST } = get_host_info();
8+
69
cache_test(function(cache, test) {
710
return promise_rejects_js(
811
test,
@@ -104,6 +107,21 @@ cache_test(function(cache, test) {
104107
'Cache.addAll should reject with TypeError if any request fails');
105108
}, 'Cache.addAll with 206 response');
106109

110+
cache_test(function(cache, test) {
111+
var urls = ['../resources/fetch-status.py?status=206',
112+
'../resources/fetch-status.py?status=200'];
113+
var requests = urls.map(function(url) {
114+
var cross_origin_url = new URL(url, location.href);
115+
cross_origin_url.hostname = REMOTE_HOST;
116+
return new Request(cross_origin_url.href, { mode: 'no-cors' });
117+
});
118+
return promise_rejects_js(
119+
test,
120+
TypeError,
121+
cache.addAll(requests),
122+
'Cache.addAll should reject with TypeError if any request fails');
123+
}, 'Cache.addAll with opaque-filtered 206 response');
124+
107125
cache_test(function(cache, test) {
108126
return promise_rejects_js(
109127
test,

testing/web-platform/tests/service-workers/cache-storage/script-tests/cache-put.js

+19
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
if (self.importScripts) {
22
importScripts('/resources/testharness.js');
3+
importScripts('/common/get-host-info.sub.js');
34
importScripts('../resources/test-helpers.js');
45
}
56

67
var test_url = 'https://example.com/foo';
78
var test_body = 'Hello world!';
9+
const { REMOTE_HOST } = get_host_info();
810

911
cache_test(function(cache) {
1012
var request = new Request(test_url);
@@ -129,6 +131,23 @@ cache_test(function(cache, test) {
129131
});
130132
}, 'Cache.put with HTTP 206 response');
131133

134+
cache_test(function(cache, test) {
135+
var test_url = new URL('../resources/fetch-status.py?status=206', location.href);
136+
test_url.hostname = REMOTE_HOST;
137+
var request = new Request(test_url.href, { mode: 'no-cors' });
138+
var response;
139+
return fetch(request)
140+
.then(function(fetch_result) {
141+
assert_equals(fetch_result.type, 'opaque',
142+
'Test framework error: The response type should be opaque.');
143+
assert_equals(fetch_result.status, 0,
144+
'Test framework error: The status code should be 0 for an ' +
145+
' opaque-filtered response. This is actually HTTP 206.');
146+
response = fetch_result.clone();
147+
return promise_rejects_js(test, TypeError, cache.put(request, fetch_result));
148+
});
149+
}, 'Cache.put with opaque-filtered HTTP 206 response');
150+
132151
cache_test(function(cache) {
133152
var test_url = new URL('../resources/fetch-status.py?status=500', location.href).href;
134153
var request = new Request(test_url);

testing/web-platform/tests/service-workers/cache-storage/window/cache-add.https.html

+1
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,6 @@
44
<meta name="timeout" content="long">
55
<script src="/resources/testharness.js"></script>
66
<script src="/resources/testharnessreport.js"></script>
7+
<script src="/common/get-host-info.sub.js"></script>
78
<script src="../resources/test-helpers.js"></script>
89
<script src="../script-tests/cache-add.js"></script>

testing/web-platform/tests/service-workers/cache-storage/window/cache-put.https.html

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
<meta name="timeout" content="long">
55
<script src="/resources/testharness.js"></script>
66
<script src="/resources/testharnessreport.js"></script>
7+
<script src="/common/get-host-info.sub.js"></script>
78
<script src="../resources/test-helpers.js"></script>
89
<script src="../script-tests/cache-put.js"></script>
910
<script>

0 commit comments

Comments
 (0)