Skip to content

Commit

Permalink
Allow range requests to pass through a service worker
Browse files Browse the repository at this point in the history
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
  • Loading branch information
naarcini authored and chromium-wpt-export-bot committed Aug 20, 2020
1 parent dea7038 commit 31453dc
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 2 deletions.
4 changes: 2 additions & 2 deletions fetch/range/sw.https.window.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,11 @@ promise_test(async t => {

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

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

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

Expand Down
18 changes: 18 additions & 0 deletions service-workers/cache-storage/script-tests/cache-add.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
if (self.importScripts) {
importScripts('/resources/testharness.js');
importScripts('/common/get-host-info.sub.js');
importScripts('../resources/test-helpers.js');
}

const { REMOTE_HOST } = get_host_info();

cache_test(function(cache, test) {
return promise_rejects_js(
test,
Expand Down Expand Up @@ -104,6 +107,21 @@ cache_test(function(cache, test) {
'Cache.addAll should reject with TypeError if any request fails');
}, 'Cache.addAll with 206 response');

cache_test(function(cache, test) {
var urls = ['../resources/fetch-status.py?status=206',
'../resources/fetch-status.py?status=200'];
var requests = urls.map(function(url) {
var cross_origin_url = new URL(url, location.href);
cross_origin_url.hostname = REMOTE_HOST;
return new Request(cross_origin_url.href, { mode: 'no-cors' });
});
return promise_rejects_js(
test,
TypeError,
cache.addAll(requests),
'Cache.addAll should reject with TypeError if any request fails');
}, 'Cache.addAll with opaque-filtered 206 response');

cache_test(function(cache, test) {
return promise_rejects_js(
test,
Expand Down
19 changes: 19 additions & 0 deletions service-workers/cache-storage/script-tests/cache-put.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
if (self.importScripts) {
importScripts('/resources/testharness.js');
importScripts('/common/get-host-info.sub.js');
importScripts('../resources/test-helpers.js');
}

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

cache_test(function(cache) {
var request = new Request(test_url);
Expand Down Expand Up @@ -129,6 +131,23 @@ cache_test(function(cache, test) {
});
}, 'Cache.put with HTTP 206 response');

cache_test(function(cache, test) {
var test_url = new URL('../resources/fetch-status.py?status=206', location.href);
test_url.hostname = REMOTE_HOST;
var request = new Request(test_url.href, { mode: 'no-cors' });
var response;
return fetch(request)
.then(function(fetch_result) {
assert_equals(fetch_result.type, 'opaque',
'Test framework error: The response type should be opaque.');
assert_equals(fetch_result.status, 0,
'Test framework error: The status code should be 0 for an ' +
' opaque-filtered response. This is actually HTTP 206.');
response = fetch_result.clone();
return promise_rejects_js(test, TypeError, cache.put(request, fetch_result));
});
}, 'Cache.put with opaque-filtered HTTP 206 response');

cache_test(function(cache) {
var test_url = new URL('../resources/fetch-status.py?status=500', location.href).href;
var request = new Request(test_url);
Expand Down
1 change: 1 addition & 0 deletions service-workers/cache-storage/window/cache-add.https.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@
<meta name="timeout" content="long">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/common/get-host-info.sub.js"></script>
<script src="../resources/test-helpers.js"></script>
<script src="../script-tests/cache-add.js"></script>
1 change: 1 addition & 0 deletions service-workers/cache-storage/window/cache-put.https.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
<meta name="timeout" content="long">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/common/get-host-info.sub.js"></script>
<script src="../resources/test-helpers.js"></script>
<script src="../script-tests/cache-put.js"></script>
<script>
Expand Down

0 comments on commit 31453dc

Please sign in to comment.