From e4556cdb2ac3cf2482eb5f5cda4bda4bc2aee94c Mon Sep 17 00:00:00 2001 From: Blink WPT Bot Date: Wed, 26 Aug 2020 08:55:37 +0000 Subject: [PATCH] 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: https://github.com/whatwg/fetch/pull/560 https://github.com/whatwg/fetch/pull/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 Reviewed-by: Kinuko Yasuda Reviewed-by: Matt Falkenhagen Reviewed-by: Ben Kelly Reviewed-by: Yutaka Hirano Reviewed-by: Makoto Shimazu Cr-Commit-Position: refs/heads/master@{#800663} Co-authored-by: Nicolas Arciniega -- wpt-commits: 868ca3586f9dda74b2bb3b6f6dfb67a13e359090 wpt-pr: 25053 --- .../tests/fetch/range/sw.https.window.js | 4 ++-- .../cache-storage/script-tests/cache-add.js | 18 ++++++++++++++++++ .../cache-storage/script-tests/cache-put.js | 19 +++++++++++++++++++ .../cache-storage/window/cache-add.https.html | 1 + .../cache-storage/window/cache-put.https.html | 1 + 5 files changed, 41 insertions(+), 2 deletions(-) diff --git a/testing/web-platform/tests/fetch/range/sw.https.window.js b/testing/web-platform/tests/fetch/range/sw.https.window.js index 625e513a8133a..76f80e9416c61 100644 --- a/testing/web-platform/tests/fetch/range/sw.https.window.js +++ b/testing/web-platform/tests/fetch/range/sw.https.window.js @@ -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(() => {}); diff --git a/testing/web-platform/tests/service-workers/cache-storage/script-tests/cache-add.js b/testing/web-platform/tests/service-workers/cache-storage/script-tests/cache-add.js index f1617109cfa13..62b44c7880168 100644 --- a/testing/web-platform/tests/service-workers/cache-storage/script-tests/cache-add.js +++ b/testing/web-platform/tests/service-workers/cache-storage/script-tests/cache-add.js @@ -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, @@ -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, diff --git a/testing/web-platform/tests/service-workers/cache-storage/script-tests/cache-put.js b/testing/web-platform/tests/service-workers/cache-storage/script-tests/cache-put.js index 44ba565d86ca0..b45910a3b8ba0 100644 --- a/testing/web-platform/tests/service-workers/cache-storage/script-tests/cache-put.js +++ b/testing/web-platform/tests/service-workers/cache-storage/script-tests/cache-put.js @@ -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); @@ -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); diff --git a/testing/web-platform/tests/service-workers/cache-storage/window/cache-add.https.html b/testing/web-platform/tests/service-workers/cache-storage/window/cache-add.https.html index 8dfb786cf3567..b5a64c6c369b5 100644 --- a/testing/web-platform/tests/service-workers/cache-storage/window/cache-add.https.html +++ b/testing/web-platform/tests/service-workers/cache-storage/window/cache-add.https.html @@ -4,5 +4,6 @@ + diff --git a/testing/web-platform/tests/service-workers/cache-storage/window/cache-put.https.html b/testing/web-platform/tests/service-workers/cache-storage/window/cache-put.https.html index 1ee14bdd124ee..9641c34705186 100644 --- a/testing/web-platform/tests/service-workers/cache-storage/window/cache-put.https.html +++ b/testing/web-platform/tests/service-workers/cache-storage/window/cache-put.https.html @@ -4,6 +4,7 @@ +