gecko-dev/testing/web-platform/tests/FileAPI/url/url-with-fetch.any.js
Boris Zbarsky cc23d02e38 Bug 1613239 [wpt PR 21582] - Replace some "promise_rejects(t, new FooError, stuff)" calls with pro…, a=testonly
Automatic update from web-platform-tests
Replace some "promise_rejects(t, new FooError, stuff)" calls with promise_rejects_js.

This diff was generated by running:

  find . -type f -print0 | xargs -0 perl -pi -e 'BEGIN { $/ = undef; } s/promise_rejects\(([ \n]*[a-zA-Z_]+[ \n]*,[ \n]*)(?:new )?([A-Z][A-Za-z]*Error) *(?:\(\))? *(, *.)/promise_rejects_js(\1\2\3/gs'

(which allows the optional "new" before "FooError" and an optional "()" after
it) and then:

1) Manually editing css/cssom-view/MediaQueryList-addListener-handleEvent.html
to make it get TypeError from the right global.

2) Manually editing fetch/api/response/response-error-from-stream.html to use
promise_rejects_exactly instead of the thing it was doing with a
CustomTestError.

3) Manually editing html/cross-origin-embedder-policy/require-corp.https.html
to use TypeError from the right global in the window.open case.

4) Manually editing
service-workers/service-worker/controller-with-no-fetch-event-handler.https.html
to use TypeError from the right global in the subframe case.

5) Manually editing
service-workers/service-worker/fetch-response-taint.https.html to use TypeError
from the right frame.

6) Manually editing
service-workers/service-worker/redirected-response.https.html to get the
TypeError from the right subframe in various places.

--

wpt-commits: ab733fd9f53eefdc034a2b96d08f080b355b6b10
wpt-pr: 21582
2020-02-14 19:08:35 +00:00

53 lines
1.7 KiB
JavaScript

// META: script=resources/fetch-tests.js
function fetch_should_succeed(test, request) {
return fetch(request).then(response => response.text());
}
function fetch_should_fail(test, url, method = 'GET') {
return promise_rejects_js(test, TypeError, fetch(url, {method: method}));
}
fetch_tests('fetch', fetch_should_succeed, fetch_should_fail);
promise_test(t => {
const blob_contents = 'test blob contents';
const blob_type = 'image/png';
const blob = new Blob([blob_contents], {type: blob_type});
const url = URL.createObjectURL(blob);
return fetch(url).then(response => {
assert_equals(response.headers.get('Content-Type'), blob_type);
});
}, 'fetch should return Content-Type from Blob');
promise_test(t => {
const blob_contents = 'test blob contents';
const blob = new Blob([blob_contents]);
const url = URL.createObjectURL(blob);
const request = new Request(url);
// Revoke the object URL. Request should take a reference to the blob as
// soon as it receives it in open(), so the request succeeds even though we
// revoke the URL before calling fetch().
URL.revokeObjectURL(url);
return fetch_should_succeed(t, request).then(text => {
assert_equals(text, blob_contents);
});
}, 'Revoke blob URL after creating Request, will fetch');
promise_test(function(t) {
const blob_contents = 'test blob contents';
const blob = new Blob([blob_contents]);
const url = URL.createObjectURL(blob);
const result = fetch_should_succeed(t, url).then(text => {
assert_equals(text, blob_contents);
});
// Revoke the object URL. fetch should have already resolved the blob URL.
URL.revokeObjectURL(url);
return result;
}, 'Revoke blob URL after calling fetch, fetch should succeed');