Skip to content

Commit 31453dc

Browse files
naarcinichromium-wpt-export-bot
authored andcommitted
Allow range requests to pass through a service worker
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
1 parent dea7038 commit 31453dc

File tree

5 files changed

+41
-2
lines changed

5 files changed

+41
-2
lines changed

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

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,

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);

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>

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)