mirror of
https://github.com/servo/servo.git
synced 2025-08-08 06:55:31 +01:00
Update web-platform-tests to revision f8941337b646b67942d912db9ce83cd612d2bd60
This commit is contained in:
parent
b15995fcab
commit
6a818ffecf
431 changed files with 14440 additions and 5715 deletions
|
@ -0,0 +1,47 @@
|
|||
// META: title=Request signals & the cache API
|
||||
// META: global=window,worker
|
||||
|
||||
promise_test(async () => {
|
||||
await caches.delete('test');
|
||||
const controller = new AbortController();
|
||||
const signal = controller.signal;
|
||||
const request = new Request('../resources/data.json', { signal });
|
||||
|
||||
const cache = await caches.open('test');
|
||||
await cache.put(request, new Response(''));
|
||||
|
||||
const requests = await cache.keys();
|
||||
|
||||
assert_equals(requests.length, 1, 'Ensuring cleanup worked');
|
||||
|
||||
const [cachedRequest] = requests;
|
||||
|
||||
controller.abort();
|
||||
|
||||
assert_false(cachedRequest.signal.aborted, "Request from cache shouldn't be aborted");
|
||||
|
||||
const data = await fetch(cachedRequest).then(r => r.json());
|
||||
assert_equals(data.key, 'value', 'Fetch fully completes');
|
||||
}, "Signals are not stored in the cache API");
|
||||
|
||||
promise_test(async () => {
|
||||
await caches.delete('test');
|
||||
const controller = new AbortController();
|
||||
const signal = controller.signal;
|
||||
const request = new Request('../resources/data.json', { signal });
|
||||
controller.abort();
|
||||
|
||||
const cache = await caches.open('test');
|
||||
await cache.put(request, new Response(''));
|
||||
|
||||
const requests = await cache.keys();
|
||||
|
||||
assert_equals(requests.length, 1, 'Ensuring cleanup worked');
|
||||
|
||||
const [cachedRequest] = requests;
|
||||
|
||||
assert_false(cachedRequest.signal.aborted, "Request from cache shouldn't be aborted");
|
||||
|
||||
const data = await fetch(cachedRequest).then(r => r.json());
|
||||
assert_equals(data.key, 'value', 'Fetch fully completes');
|
||||
}, "Signals are not stored in the cache API, even if they're already aborted");
|
|
@ -1,57 +0,0 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>Request signals & the cache API</title>
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
<script>
|
||||
promise_test(async () => {
|
||||
await caches.delete('test');
|
||||
const controller = new AbortController();
|
||||
const signal = controller.signal;
|
||||
const request = new Request('../resources/data.json', { signal });
|
||||
|
||||
const cache = await caches.open('test');
|
||||
await cache.put(request, new Response(''));
|
||||
|
||||
const requests = await cache.keys();
|
||||
|
||||
assert_equals(requests.length, 1, 'Ensuring cleanup worked');
|
||||
|
||||
const [cachedRequest] = requests;
|
||||
|
||||
controller.abort();
|
||||
|
||||
assert_false(cachedRequest.signal.aborted, "Request from cache shouldn't be aborted");
|
||||
|
||||
const data = await fetch(cachedRequest).then(r => r.json());
|
||||
assert_equals(data.key, 'value', 'Fetch fully completes');
|
||||
}, "Signals are not stored in the cache API");
|
||||
|
||||
promise_test(async () => {
|
||||
await caches.delete('test');
|
||||
const controller = new AbortController();
|
||||
const signal = controller.signal;
|
||||
const request = new Request('../resources/data.json', { signal });
|
||||
controller.abort();
|
||||
|
||||
const cache = await caches.open('test');
|
||||
await cache.put(request, new Response(''));
|
||||
|
||||
const requests = await cache.keys();
|
||||
|
||||
assert_equals(requests.length, 1, 'Ensuring cleanup worked');
|
||||
|
||||
const [cachedRequest] = requests;
|
||||
|
||||
assert_false(cachedRequest.signal.aborted, "Request from cache shouldn't be aborted");
|
||||
|
||||
const data = await fetch(cachedRequest).then(r => r.json());
|
||||
assert_equals(data.key, 'value', 'Fetch fully completes');
|
||||
}, "Signals are not stored in the cache API, even if they're already aborted");
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
|
@ -1,3 +1,4 @@
|
|||
// META: global=window,worker
|
||||
// META: script=../resources/utils.js
|
||||
|
||||
promise_test(function() {
|
||||
|
|
|
@ -0,0 +1,38 @@
|
|||
// META: title=Request ETag
|
||||
// META: global=window,worker
|
||||
// META: script=/common/utils.js
|
||||
|
||||
promise_test(function() {
|
||||
var cacheBuster = token(); // ensures first request is uncached
|
||||
var url = "../resources/cache.py?v=" + cacheBuster;
|
||||
var etag;
|
||||
|
||||
// make the first request
|
||||
return fetch(url).then(function(response) {
|
||||
// ensure we're getting the regular, uncached response
|
||||
assert_equals(response.status, 200);
|
||||
assert_equals(response.headers.get("X-HTTP-STATUS"), null)
|
||||
|
||||
return response.text(); // consuming the body, just to be safe
|
||||
}).then(function(body) {
|
||||
// make a second request
|
||||
return fetch(url);
|
||||
}).then(function(response) {
|
||||
// while the server responds with 304 if our browser sent the correct
|
||||
// If-None-Match request header, at the JavaScript level this surfaces
|
||||
// as 200
|
||||
assert_equals(response.status, 200);
|
||||
assert_equals(response.headers.get("X-HTTP-STATUS"), "304")
|
||||
|
||||
etag = response.headers.get("ETag")
|
||||
|
||||
return response.text(); // consuming the body, just to be safe
|
||||
}).then(function(body) {
|
||||
// make a third request, explicitly setting If-None-Match request header
|
||||
var headers = { "If-None-Match": etag }
|
||||
return fetch(url, { headers: headers })
|
||||
}).then(function(response) {
|
||||
// 304 now surfaces thanks to the explicit If-None-Match request header
|
||||
assert_equals(response.status, 304);
|
||||
});
|
||||
}, "Testing conditional GET with ETags");
|
|
@ -1,51 +0,0 @@
|
|||
<!doctype html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>Request ETag</title>
|
||||
<meta name="help" href="https://fetch.spec.whatwg.org/#request">
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
<script src="/common/utils.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
<script>
|
||||
promise_test(function() {
|
||||
var cacheBuster = token(); // ensures first request is uncached
|
||||
var url = "../resources/cache.py?v=" + cacheBuster;
|
||||
var etag;
|
||||
|
||||
// make the first request
|
||||
return fetch(url).then(function(response) {
|
||||
// ensure we're getting the regular, uncached response
|
||||
assert_equals(response.status, 200);
|
||||
assert_equals(response.headers.get("X-HTTP-STATUS"), null)
|
||||
|
||||
return response.text(); // consuming the body, just to be safe
|
||||
}).then(function(body) {
|
||||
// make a second request
|
||||
return fetch(url);
|
||||
}).then(function(response) {
|
||||
// while the server responds with 304 if our browser sent the correct
|
||||
// If-None-Match request header, at the JavaScript level this surfaces
|
||||
// as 200
|
||||
assert_equals(response.status, 200);
|
||||
assert_equals(response.headers.get("X-HTTP-STATUS"), "304")
|
||||
|
||||
etag = response.headers.get("ETag")
|
||||
|
||||
return response.text(); // consuming the body, just to be safe
|
||||
}).then(function(body) {
|
||||
// make a third request, explicitly setting If-None-Match request header
|
||||
var headers = { "If-None-Match": etag }
|
||||
return fetch(url, { headers: headers })
|
||||
}).then(function(response) {
|
||||
// 304 now surfaces thanks to the explicit If-None-Match request header
|
||||
assert_equals(response.status, 304);
|
||||
});
|
||||
}, "Testing conditional GET with ETags");
|
||||
|
||||
done();
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
|
@ -1,15 +1,8 @@
|
|||
<!doctype html>
|
||||
<html>
|
||||
<head>
|
||||
<title>Fetch: network timeout after receiving the HTTP response headers</title>
|
||||
<meta name="timeout" content="long">
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
<script src="../resources/utils.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
<div id="log"></div>
|
||||
<script>
|
||||
// META: title=Fetch: network timeout after receiving the HTTP response headers
|
||||
// META: global=window,worker
|
||||
// META: timeout=long
|
||||
// META: script=../resources/utils.js
|
||||
|
||||
function checkReader(test, reader, promiseToTest)
|
||||
{
|
||||
return reader.read().then((value) => {
|
||||
|
@ -29,7 +22,3 @@ promise_test((test) => {
|
|||
return checkReader(test, response.body.getReader(), reader => reader.closed);
|
||||
});
|
||||
}, "Response reader closed promise should reject after a network error happening after resolving fetch promise");
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
|
|
@ -1,3 +1,5 @@
|
|||
// META: global=window,worker
|
||||
|
||||
test(() => {
|
||||
assert_false("getAll" in new Headers());
|
||||
assert_false("getAll" in Headers.prototype);
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
// META: global=window,worker
|
||||
// META: script=../resources/utils.js
|
||||
|
||||
function requestForbiddenHeaders(desc, forbiddenHeaders) {
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
// META: global=window,worker
|
||||
|
||||
promise_test(function(test) {
|
||||
var requestInit = {"method": "HEAD", "body": "test"};
|
||||
return promise_rejects_js(test, TypeError, fetch(".", requestInit));
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
// META: global=window,worker
|
||||
|
||||
promise_test(() => {
|
||||
return fetch("/xhr/resources/echo-headers.py", {headers: [["THIS-is-A-test", 1], ["THIS-IS-A-TEST", 2]] }).then(res => res.text()).then(body => {
|
||||
assert_regexp_match(body, /THIS-is-A-test: 1, 2/)
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
// META: global=window,worker
|
||||
|
||||
// This tests characters that are not
|
||||
// https://infra.spec.whatwg.org/#ascii-code-point
|
||||
// but are still
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
// META: global=window,worker
|
||||
// META: script=../resources/utils.js
|
||||
|
||||
function checkContentType(contentType, body)
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
// META: global=window,worker
|
||||
// META: script=../resources/utils.js
|
||||
|
||||
function testReferrer(referrer, expected, desc) {
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
// META: global=window,worker
|
||||
// META: script=../resources/utils.js
|
||||
|
||||
function testUpload(desc, url, method, createBody, expectedBody) {
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
// META: global=window,worker
|
||||
// META: script=../resources/utils.js
|
||||
|
||||
function checkNetworkError(url, method) {
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
// META: global=window,worker
|
||||
// META: script=../resources/utils.js
|
||||
|
||||
function checkFetchResponse(url, data, mime, fetchMode, method) {
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
// META: global=window,worker
|
||||
// META: script=../resources/utils.js
|
||||
|
||||
function checkKoUrl(url, desc) {
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
// META: global=window,worker
|
||||
// META: script=../resources/utils.js
|
||||
|
||||
function streamBody(reader, test, count) {
|
||||
|
|
|
@ -1,12 +1,6 @@
|
|||
<!doctype html>
|
||||
<meta charset=utf-8>
|
||||
<title>Fetch: Request and Response text() should decode as UTF-8</title>
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
<link rel="help" href="https://fetch.spec.whatwg.org/#body-mixin" />
|
||||
|
||||
<script src="../resources/utils.js"></script>
|
||||
<script>
|
||||
// META: title=Fetch: Request and Response text() should decode as UTF-8
|
||||
// META: global=window,worker
|
||||
// META: script=../resources/utils.js
|
||||
|
||||
function testTextDecoding(body, expectedText, urlParameter, title)
|
||||
{
|
||||
|
@ -78,5 +72,3 @@ var utf16WithoutBOM = "\xe6\x00\xf8\x00\xe5\x00\x0a\x00\xc6\x30\xb9\x30\xc8\x30\
|
|||
var utf16WithoutBOMAsURLParameter = "%E6%00%F8%00%E5%00%0A%00%C6%30%B9%30%C8%30%0A%00";
|
||||
var utf16WithoutBOMDecoded = "\ufffd\u0000\ufffd\u0000\ufffd\u0000\u000a\u0000\ufffd\u0030\ufffd\u0030\ufffd\u0030\u000a\u0000";
|
||||
testTextDecoding(utf16WithoutBOM, utf16WithoutBOMDecoded, utf16WithoutBOMAsURLParameter, "UTF-16 without BOM decoded as UTF-8");
|
||||
|
||||
</script>
|
|
@ -1,3 +1,4 @@
|
|||
// META: global=window,worker
|
||||
// META: script=../resources/utils.js
|
||||
|
||||
function corsMultipleOrigins(originList) {
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
// META: global=window,worker
|
||||
// META: script=/common/utils.js
|
||||
// META: script=../resources/utils.js
|
||||
// META: script=/common/get-host-info.sub.js
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
// META: global=window,worker
|
||||
// META: script=../resources/utils.js
|
||||
|
||||
function basicAuth(desc, user, pass, mode, status) {
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
// META: global=window,worker
|
||||
// META: script=../resources/utils.js
|
||||
|
||||
function cookies(desc, credentials1, credentials2 ,cookies) {
|
||||
|
|
|
@ -1,11 +1,7 @@
|
|||
<!doctype html>
|
||||
<meta charset=utf8>
|
||||
<meta name=timeout content=long>
|
||||
<title>Header value normalizing test</title>
|
||||
<script src=/resources/testharness.js></script>
|
||||
<script src=/resources/testharnessreport.js></script>
|
||||
<div id=log></div>
|
||||
<script>
|
||||
// META: title=Header value normalizing test
|
||||
// META: global=window,worker
|
||||
// META: timeout=long
|
||||
|
||||
for(let i = 0; i < 0x21; i++) {
|
||||
let fail = false,
|
||||
strip = false
|
||||
|
@ -32,26 +28,29 @@ for(let i = 0; i < 0x21; i++) {
|
|||
val3 = val + "x",
|
||||
expectedVal3 = expectedVal + "x"
|
||||
|
||||
async_test((t) => {
|
||||
let xhr = new XMLHttpRequest()
|
||||
xhr.open("POST", url)
|
||||
if(fail) {
|
||||
assert_throws_dom("SyntaxError", () => xhr.setRequestHeader("val1", val1))
|
||||
assert_throws_dom("SyntaxError", () => xhr.setRequestHeader("val2", val2))
|
||||
assert_throws_dom("SyntaxError", () => xhr.setRequestHeader("val3", val3))
|
||||
t.done()
|
||||
} else {
|
||||
xhr.setRequestHeader("val1", val1)
|
||||
xhr.setRequestHeader("val2", val2)
|
||||
xhr.setRequestHeader("val3", val3)
|
||||
xhr.onload = t.step_func_done(() => {
|
||||
assert_equals(xhr.getResponseHeader("x-request-val1"), expectedVal1)
|
||||
assert_equals(xhr.getResponseHeader("x-request-val2"), expectedVal2)
|
||||
assert_equals(xhr.getResponseHeader("x-request-val3"), expectedVal3)
|
||||
})
|
||||
xhr.send()
|
||||
}
|
||||
}, "XMLHttpRequest with value " + encodeURI(val))
|
||||
// XMLHttpRequest is not available in service workers
|
||||
if (!self.GLOBAL.isWorker()) {
|
||||
async_test((t) => {
|
||||
let xhr = new XMLHttpRequest()
|
||||
xhr.open("POST", url)
|
||||
if(fail) {
|
||||
assert_throws_dom("SyntaxError", () => xhr.setRequestHeader("val1", val1))
|
||||
assert_throws_dom("SyntaxError", () => xhr.setRequestHeader("val2", val2))
|
||||
assert_throws_dom("SyntaxError", () => xhr.setRequestHeader("val3", val3))
|
||||
t.done()
|
||||
} else {
|
||||
xhr.setRequestHeader("val1", val1)
|
||||
xhr.setRequestHeader("val2", val2)
|
||||
xhr.setRequestHeader("val3", val3)
|
||||
xhr.onload = t.step_func_done(() => {
|
||||
assert_equals(xhr.getResponseHeader("x-request-val1"), expectedVal1)
|
||||
assert_equals(xhr.getResponseHeader("x-request-val2"), expectedVal2)
|
||||
assert_equals(xhr.getResponseHeader("x-request-val3"), expectedVal3)
|
||||
})
|
||||
xhr.send()
|
||||
}
|
||||
}, "XMLHttpRequest with value " + encodeURI(val))
|
||||
}
|
||||
|
||||
promise_test((t) => {
|
||||
if(fail) {
|
||||
|
@ -69,4 +68,3 @@ for(let i = 0; i < 0x21; i++) {
|
|||
}
|
||||
}, "fetch() with value " + encodeURI(val))
|
||||
}
|
||||
</script>
|
|
@ -1,19 +1,19 @@
|
|||
<!doctype html>
|
||||
<meta charset=utf8>
|
||||
<meta name=timeout content=long>
|
||||
<title>Header value test</title>
|
||||
<script src=/resources/testharness.js></script>
|
||||
<script src=/resources/testharnessreport.js></script>
|
||||
<div id=log></div>
|
||||
<script>
|
||||
// META: title=Header value test
|
||||
// META: global=window,worker
|
||||
// META: timeout=long
|
||||
|
||||
// Invalid values
|
||||
[0, 0x0A, 0x0D].forEach(val => {
|
||||
val = "x" + String.fromCharCode(val) + "x"
|
||||
test(() => {
|
||||
let xhr = new XMLHttpRequest()
|
||||
xhr.open("POST", "/")
|
||||
assert_throws_dom("SyntaxError", () => xhr.setRequestHeader("value-test", val))
|
||||
}, "XMLHttpRequest with value " + encodeURI(val) + " needs to throw")
|
||||
|
||||
// XMLHttpRequest is not available in service workers
|
||||
if (!self.GLOBAL.isWorker()) {
|
||||
test(() => {
|
||||
let xhr = new XMLHttpRequest()
|
||||
xhr.open("POST", "/")
|
||||
assert_throws_dom("SyntaxError", () => xhr.setRequestHeader("value-test", val))
|
||||
}, "XMLHttpRequest with value " + encodeURI(val) + " needs to throw")
|
||||
}
|
||||
|
||||
promise_test(t => promise_rejects_js(t, TypeError, fetch("/", { headers: {"value-test": val} })), "fetch() with value " + encodeURI(val) + " needs to throw")
|
||||
})
|
||||
|
@ -31,19 +31,22 @@ headerValues.forEach((_, i) => {
|
|||
url += "val" + i + "|"
|
||||
})
|
||||
|
||||
async_test((t) => {
|
||||
let xhr = new XMLHttpRequest()
|
||||
xhr.open("POST", url)
|
||||
headerValues.forEach((val, i) => {
|
||||
xhr.setRequestHeader("val" + i, val)
|
||||
})
|
||||
xhr.onload = t.step_func_done(() => {
|
||||
// XMLHttpRequest is not available in service workers
|
||||
if (!self.GLOBAL.isWorker()) {
|
||||
async_test((t) => {
|
||||
let xhr = new XMLHttpRequest()
|
||||
xhr.open("POST", url)
|
||||
headerValues.forEach((val, i) => {
|
||||
assert_equals(xhr.getResponseHeader("x-request-val" + i), val)
|
||||
xhr.setRequestHeader("val" + i, val)
|
||||
})
|
||||
})
|
||||
xhr.send()
|
||||
}, "XMLHttpRequest with all valid values")
|
||||
xhr.onload = t.step_func_done(() => {
|
||||
headerValues.forEach((val, i) => {
|
||||
assert_equals(xhr.getResponseHeader("x-request-val" + i), val)
|
||||
})
|
||||
})
|
||||
xhr.send()
|
||||
}, "XMLHttpRequest with all valid values")
|
||||
}
|
||||
|
||||
promise_test((t) => {
|
||||
const headers = new Headers
|
||||
|
@ -56,4 +59,3 @@ promise_test((t) => {
|
|||
})
|
||||
})
|
||||
}, "fetch() with all valid values")
|
||||
</script>
|
|
@ -0,0 +1,218 @@
|
|||
// META: title=Headers structure
|
||||
// META: global=window,worker
|
||||
|
||||
test(function() {
|
||||
new Headers();
|
||||
}, "Create headers from no parameter");
|
||||
|
||||
test(function() {
|
||||
new Headers(undefined);
|
||||
}, "Create headers from undefined parameter");
|
||||
|
||||
test(function() {
|
||||
new Headers({});
|
||||
}, "Create headers from empty object");
|
||||
|
||||
var parameters = [null, 1];
|
||||
parameters.forEach(function(parameter) {
|
||||
test(function() {
|
||||
assert_throws_js(TypeError, function() { new Headers(parameter) });
|
||||
}, "Create headers with " + parameter + " should throw");
|
||||
});
|
||||
|
||||
var headerDict = {"name1": "value1",
|
||||
"name2": "value2",
|
||||
"name3": "value3",
|
||||
"name4": null,
|
||||
"name5": undefined,
|
||||
"name6": 1,
|
||||
"Content-Type": "value4"
|
||||
};
|
||||
|
||||
var headerSeq = [];
|
||||
for (var name in headerDict)
|
||||
headerSeq.push([name, headerDict[name]]);
|
||||
|
||||
test(function() {
|
||||
var headers = new Headers(headerSeq);
|
||||
for (name in headerDict) {
|
||||
assert_equals(headers.get(name), String(headerDict[name]),
|
||||
"name: " + name + " has value: " + headerDict[name]);
|
||||
}
|
||||
assert_equals(headers.get("length"), null, "init should be treated as a sequence, not as a dictionary");
|
||||
}, "Create headers with sequence");
|
||||
|
||||
test(function() {
|
||||
var headers = new Headers(headerDict);
|
||||
for (name in headerDict) {
|
||||
assert_equals(headers.get(name), String(headerDict[name]),
|
||||
"name: " + name + " has value: " + headerDict[name]);
|
||||
}
|
||||
}, "Create headers with record");
|
||||
|
||||
test(function() {
|
||||
var headers = new Headers(headerDict);
|
||||
var headers2 = new Headers(headers);
|
||||
for (name in headerDict) {
|
||||
assert_equals(headers2.get(name), String(headerDict[name]),
|
||||
"name: " + name + " has value: " + headerDict[name]);
|
||||
}
|
||||
}, "Create headers with existing headers");
|
||||
|
||||
test(function() {
|
||||
var headers = new Headers()
|
||||
headers[Symbol.iterator] = function *() {
|
||||
yield ["test", "test"]
|
||||
}
|
||||
var headers2 = new Headers(headers)
|
||||
assert_equals(headers2.get("test"), "test")
|
||||
}, "Create headers with existing headers with custom iterator");
|
||||
|
||||
test(function() {
|
||||
var headers = new Headers();
|
||||
for (name in headerDict) {
|
||||
headers.append(name, headerDict[name]);
|
||||
assert_equals(headers.get(name), String(headerDict[name]),
|
||||
"name: " + name + " has value: " + headerDict[name]);
|
||||
}
|
||||
}, "Check append method");
|
||||
|
||||
test(function() {
|
||||
var headers = new Headers();
|
||||
for (name in headerDict) {
|
||||
headers.set(name, headerDict[name]);
|
||||
assert_equals(headers.get(name), String(headerDict[name]),
|
||||
"name: " + name + " has value: " + headerDict[name]);
|
||||
}
|
||||
}, "Check set method");
|
||||
|
||||
test(function() {
|
||||
var headers = new Headers(headerDict);
|
||||
for (name in headerDict)
|
||||
assert_true(headers.has(name),"headers has name " + name);
|
||||
|
||||
assert_false(headers.has("nameNotInHeaders"),"headers do not have header: nameNotInHeaders");
|
||||
}, "Check has method");
|
||||
|
||||
test(function() {
|
||||
var headers = new Headers(headerDict);
|
||||
for (name in headerDict) {
|
||||
assert_true(headers.has(name),"headers have a header: " + name);
|
||||
headers.delete(name)
|
||||
assert_true(!headers.has(name),"headers do not have anymore a header: " + name);
|
||||
}
|
||||
}, "Check delete method");
|
||||
|
||||
test(function() {
|
||||
var headers = new Headers(headerDict);
|
||||
for (name in headerDict)
|
||||
assert_equals(headers.get(name), String(headerDict[name]),
|
||||
"name: " + name + " has value: " + headerDict[name]);
|
||||
|
||||
assert_equals(headers.get("nameNotInHeaders"), null, "header: nameNotInHeaders has no value");
|
||||
}, "Check get method");
|
||||
|
||||
var headerEntriesDict = {"name1": "value1",
|
||||
"Name2": "value2",
|
||||
"name": "value3",
|
||||
"content-Type": "value4",
|
||||
"Content-Typ": "value5",
|
||||
"Content-Types": "value6"
|
||||
};
|
||||
var sortedHeaderDict = {};
|
||||
var headerValues = [];
|
||||
var sortedHeaderKeys = Object.keys(headerEntriesDict).map(function(value) {
|
||||
sortedHeaderDict[value.toLowerCase()] = headerEntriesDict[value];
|
||||
headerValues.push(headerEntriesDict[value]);
|
||||
return value.toLowerCase();
|
||||
}).sort();
|
||||
|
||||
var iteratorPrototype = Object.getPrototypeOf(Object.getPrototypeOf([][Symbol.iterator]()));
|
||||
function checkIteratorProperties(iterator) {
|
||||
var prototype = Object.getPrototypeOf(iterator);
|
||||
assert_equals(Object.getPrototypeOf(prototype), iteratorPrototype);
|
||||
|
||||
var descriptor = Object.getOwnPropertyDescriptor(prototype, "next");
|
||||
assert_true(descriptor.configurable, "configurable");
|
||||
assert_true(descriptor.enumerable, "enumerable");
|
||||
assert_true(descriptor.writable, "writable");
|
||||
}
|
||||
|
||||
test(function() {
|
||||
var headers = new Headers(headerEntriesDict);
|
||||
var actual = headers.keys();
|
||||
checkIteratorProperties(actual);
|
||||
|
||||
sortedHeaderKeys.forEach(function(key) {
|
||||
entry = actual.next();
|
||||
assert_false(entry.done);
|
||||
assert_equals(entry.value, key);
|
||||
});
|
||||
assert_true(actual.next().done);
|
||||
assert_true(actual.next().done);
|
||||
|
||||
for (key of headers.keys())
|
||||
assert_true(sortedHeaderKeys.indexOf(key) != -1);
|
||||
}, "Check keys method");
|
||||
|
||||
test(function() {
|
||||
var headers = new Headers(headerEntriesDict);
|
||||
var actual = headers.values();
|
||||
checkIteratorProperties(actual);
|
||||
|
||||
sortedHeaderKeys.forEach(function(key) {
|
||||
entry = actual.next();
|
||||
assert_false(entry.done);
|
||||
assert_equals(entry.value, sortedHeaderDict[key]);
|
||||
});
|
||||
assert_true(actual.next().done);
|
||||
assert_true(actual.next().done);
|
||||
|
||||
for (value of headers.values())
|
||||
assert_true(headerValues.indexOf(value) != -1);
|
||||
}, "Check values method");
|
||||
|
||||
test(function() {
|
||||
var headers = new Headers(headerEntriesDict);
|
||||
var actual = headers.entries();
|
||||
checkIteratorProperties(actual);
|
||||
|
||||
sortedHeaderKeys.forEach(function(key) {
|
||||
entry = actual.next();
|
||||
assert_false(entry.done);
|
||||
assert_equals(entry.value[0], key);
|
||||
assert_equals(entry.value[1], sortedHeaderDict[key]);
|
||||
});
|
||||
assert_true(actual.next().done);
|
||||
assert_true(actual.next().done);
|
||||
|
||||
for (entry of headers.entries())
|
||||
assert_equals(entry[1], sortedHeaderDict[entry[0]]);
|
||||
}, "Check entries method");
|
||||
|
||||
test(function() {
|
||||
var headers = new Headers(headerEntriesDict);
|
||||
var actual = headers[Symbol.iterator]();
|
||||
|
||||
sortedHeaderKeys.forEach(function(key) {
|
||||
entry = actual.next();
|
||||
assert_false(entry.done);
|
||||
assert_equals(entry.value[0], key);
|
||||
assert_equals(entry.value[1], sortedHeaderDict[key]);
|
||||
});
|
||||
assert_true(actual.next().done);
|
||||
assert_true(actual.next().done);
|
||||
}, "Check Symbol.iterator method");
|
||||
|
||||
test(function() {
|
||||
var headers = new Headers(headerEntriesDict);
|
||||
var reference = sortedHeaderKeys[Symbol.iterator]();
|
||||
headers.forEach(function(value, key, container) {
|
||||
assert_equals(headers, container);
|
||||
entry = reference.next();
|
||||
assert_false(entry.done);
|
||||
assert_equals(key, entry.value);
|
||||
assert_equals(value, sortedHeaderDict[entry.value]);
|
||||
});
|
||||
assert_true(reference.next().done);
|
||||
}, "Check forEach method");
|
|
@ -1,230 +0,0 @@
|
|||
<!doctype html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>Headers structure</title>
|
||||
<meta name="help" href="https://fetch.spec.whatwg.org/#headers">
|
||||
<meta name="author" title="Canon Research France" href="https://www.crf.canon.fr">
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
<script>
|
||||
test(function() {
|
||||
new Headers();
|
||||
}, "Create headers from no parameter");
|
||||
|
||||
test(function() {
|
||||
new Headers(undefined);
|
||||
}, "Create headers from undefined parameter");
|
||||
|
||||
test(function() {
|
||||
new Headers({});
|
||||
}, "Create headers from empty object");
|
||||
|
||||
var parameters = [null, 1];
|
||||
parameters.forEach(function(parameter) {
|
||||
test(function() {
|
||||
assert_throws_js(TypeError, function() { new Headers(parameter) });
|
||||
}, "Create headers with " + parameter + " should throw");
|
||||
});
|
||||
|
||||
var headerDict = {"name1": "value1",
|
||||
"name2": "value2",
|
||||
"name3": "value3",
|
||||
"name4": null,
|
||||
"name5": undefined,
|
||||
"name6": 1,
|
||||
"Content-Type": "value4"
|
||||
};
|
||||
|
||||
var headerSeq = [];
|
||||
for (var name in headerDict)
|
||||
headerSeq.push([name, headerDict[name]]);
|
||||
|
||||
test(function() {
|
||||
var headers = new Headers(headerSeq);
|
||||
for (name in headerDict) {
|
||||
assert_equals(headers.get(name), String(headerDict[name]),
|
||||
"name: " + name + " has value: " + headerDict[name]);
|
||||
}
|
||||
assert_equals(headers.get("length"), null, "init should be treated as a sequence, not as a dictionary");
|
||||
}, "Create headers with sequence");
|
||||
|
||||
test(function() {
|
||||
var headers = new Headers(headerDict);
|
||||
for (name in headerDict) {
|
||||
assert_equals(headers.get(name), String(headerDict[name]),
|
||||
"name: " + name + " has value: " + headerDict[name]);
|
||||
}
|
||||
}, "Create headers with record");
|
||||
|
||||
test(function() {
|
||||
var headers = new Headers(headerDict);
|
||||
var headers2 = new Headers(headers);
|
||||
for (name in headerDict) {
|
||||
assert_equals(headers2.get(name), String(headerDict[name]),
|
||||
"name: " + name + " has value: " + headerDict[name]);
|
||||
}
|
||||
}, "Create headers with existing headers");
|
||||
|
||||
test(function() {
|
||||
var headers = new Headers()
|
||||
headers[Symbol.iterator] = function *() {
|
||||
yield ["test", "test"]
|
||||
}
|
||||
var headers2 = new Headers(headers)
|
||||
assert_equals(headers2.get("test"), "test")
|
||||
}, "Create headers with existing headers with custom iterator");
|
||||
|
||||
test(function() {
|
||||
var headers = new Headers();
|
||||
for (name in headerDict) {
|
||||
headers.append(name, headerDict[name]);
|
||||
assert_equals(headers.get(name), String(headerDict[name]),
|
||||
"name: " + name + " has value: " + headerDict[name]);
|
||||
}
|
||||
}, "Check append method");
|
||||
|
||||
test(function() {
|
||||
var headers = new Headers();
|
||||
for (name in headerDict) {
|
||||
headers.set(name, headerDict[name]);
|
||||
assert_equals(headers.get(name), String(headerDict[name]),
|
||||
"name: " + name + " has value: " + headerDict[name]);
|
||||
}
|
||||
}, "Check set method");
|
||||
|
||||
test(function() {
|
||||
var headers = new Headers(headerDict);
|
||||
for (name in headerDict)
|
||||
assert_true(headers.has(name),"headers has name " + name);
|
||||
|
||||
assert_false(headers.has("nameNotInHeaders"),"headers do not have header: nameNotInHeaders");
|
||||
}, "Check has method");
|
||||
|
||||
test(function() {
|
||||
var headers = new Headers(headerDict);
|
||||
for (name in headerDict) {
|
||||
assert_true(headers.has(name),"headers have a header: " + name);
|
||||
headers.delete(name)
|
||||
assert_true(!headers.has(name),"headers do not have anymore a header: " + name);
|
||||
}
|
||||
}, "Check delete method");
|
||||
|
||||
test(function() {
|
||||
var headers = new Headers(headerDict);
|
||||
for (name in headerDict)
|
||||
assert_equals(headers.get(name), String(headerDict[name]),
|
||||
"name: " + name + " has value: " + headerDict[name]);
|
||||
|
||||
assert_equals(headers.get("nameNotInHeaders"), null, "header: nameNotInHeaders has no value");
|
||||
}, "Check get method");
|
||||
|
||||
var headerEntriesDict = {"name1": "value1",
|
||||
"Name2": "value2",
|
||||
"name": "value3",
|
||||
"content-Type": "value4",
|
||||
"Content-Typ": "value5",
|
||||
"Content-Types": "value6"
|
||||
};
|
||||
var sortedHeaderDict = {};
|
||||
var headerValues = [];
|
||||
var sortedHeaderKeys = Object.keys(headerEntriesDict).map(function(value) {
|
||||
sortedHeaderDict[value.toLowerCase()] = headerEntriesDict[value];
|
||||
headerValues.push(headerEntriesDict[value]);
|
||||
return value.toLowerCase();
|
||||
}).sort();
|
||||
|
||||
var iteratorPrototype = Object.getPrototypeOf(Object.getPrototypeOf([][Symbol.iterator]()));
|
||||
function checkIteratorProperties(iterator) {
|
||||
var prototype = Object.getPrototypeOf(iterator);
|
||||
assert_equals(Object.getPrototypeOf(prototype), iteratorPrototype);
|
||||
|
||||
var descriptor = Object.getOwnPropertyDescriptor(prototype, "next");
|
||||
assert_true(descriptor.configurable, "configurable");
|
||||
assert_true(descriptor.enumerable, "enumerable");
|
||||
assert_true(descriptor.writable, "writable");
|
||||
}
|
||||
|
||||
test(function() {
|
||||
var headers = new Headers(headerEntriesDict);
|
||||
var actual = headers.keys();
|
||||
checkIteratorProperties(actual);
|
||||
|
||||
sortedHeaderKeys.forEach(function(key) {
|
||||
entry = actual.next();
|
||||
assert_false(entry.done);
|
||||
assert_equals(entry.value, key);
|
||||
});
|
||||
assert_true(actual.next().done);
|
||||
assert_true(actual.next().done);
|
||||
|
||||
for (key of headers.keys())
|
||||
assert_true(sortedHeaderKeys.indexOf(key) != -1);
|
||||
}, "Check keys method");
|
||||
|
||||
test(function() {
|
||||
var headers = new Headers(headerEntriesDict);
|
||||
var actual = headers.values();
|
||||
checkIteratorProperties(actual);
|
||||
|
||||
sortedHeaderKeys.forEach(function(key) {
|
||||
entry = actual.next();
|
||||
assert_false(entry.done);
|
||||
assert_equals(entry.value, sortedHeaderDict[key]);
|
||||
});
|
||||
assert_true(actual.next().done);
|
||||
assert_true(actual.next().done);
|
||||
|
||||
for (value of headers.values())
|
||||
assert_true(headerValues.indexOf(value) != -1);
|
||||
}, "Check values method");
|
||||
|
||||
test(function() {
|
||||
var headers = new Headers(headerEntriesDict);
|
||||
var actual = headers.entries();
|
||||
checkIteratorProperties(actual);
|
||||
|
||||
sortedHeaderKeys.forEach(function(key) {
|
||||
entry = actual.next();
|
||||
assert_false(entry.done);
|
||||
assert_equals(entry.value[0], key);
|
||||
assert_equals(entry.value[1], sortedHeaderDict[key]);
|
||||
});
|
||||
assert_true(actual.next().done);
|
||||
assert_true(actual.next().done);
|
||||
|
||||
for (entry of headers.entries())
|
||||
assert_equals(entry[1], sortedHeaderDict[entry[0]]);
|
||||
}, "Check entries method");
|
||||
|
||||
test(function() {
|
||||
var headers = new Headers(headerEntriesDict);
|
||||
var actual = headers[Symbol.iterator]();
|
||||
|
||||
sortedHeaderKeys.forEach(function(key) {
|
||||
entry = actual.next();
|
||||
assert_false(entry.done);
|
||||
assert_equals(entry.value[0], key);
|
||||
assert_equals(entry.value[1], sortedHeaderDict[key]);
|
||||
});
|
||||
assert_true(actual.next().done);
|
||||
assert_true(actual.next().done);
|
||||
}, "Check Symbol.iterator method");
|
||||
|
||||
test(function() {
|
||||
var headers = new Headers(headerEntriesDict);
|
||||
var reference = sortedHeaderKeys[Symbol.iterator]();
|
||||
headers.forEach(function(value, key, container) {
|
||||
assert_equals(headers, container);
|
||||
entry = reference.next();
|
||||
assert_false(entry.done);
|
||||
assert_equals(key, entry.value);
|
||||
assert_equals(value, sortedHeaderDict[entry.value]);
|
||||
});
|
||||
assert_true(reference.next().done);
|
||||
}, "Check forEach method");
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,52 @@
|
|||
// META: title=Headers case management
|
||||
// META: global=window,worker
|
||||
|
||||
var headerDictCase = {"UPPERCASE": "value1",
|
||||
"lowercase": "value2",
|
||||
"mixedCase": "value3",
|
||||
"Content-TYPE": "value4"
|
||||
};
|
||||
|
||||
function checkHeadersCase(originalName, headersToCheck, expectedDict) {
|
||||
var lowCaseName = originalName.toLowerCase();
|
||||
var upCaseName = originalName.toUpperCase();
|
||||
var expectedValue = expectedDict[originalName];
|
||||
assert_equals(headersToCheck.get(originalName), expectedValue,
|
||||
"name: " + originalName + " has value: " + expectedValue);
|
||||
assert_equals(headersToCheck.get(lowCaseName), expectedValue,
|
||||
"name: " + lowCaseName + " has value: " + expectedValue);
|
||||
assert_equals(headersToCheck.get(upCaseName), expectedValue,
|
||||
"name: " + upCaseName + " has value: " + expectedValue);
|
||||
}
|
||||
|
||||
test(function() {
|
||||
var headers = new Headers(headerDictCase);
|
||||
for (name in headerDictCase)
|
||||
checkHeadersCase(name, headers, headerDictCase)
|
||||
}, "Create headers, names use characters with different case");
|
||||
|
||||
test(function() {
|
||||
var headers = new Headers();
|
||||
for (name in headerDictCase) {
|
||||
headers.append(name, headerDictCase[name]);
|
||||
checkHeadersCase(name, headers, headerDictCase);
|
||||
}
|
||||
}, "Check append method, names use characters with different case");
|
||||
|
||||
test(function() {
|
||||
var headers = new Headers();
|
||||
for (name in headerDictCase) {
|
||||
headers.set(name, headerDictCase[name]);
|
||||
checkHeadersCase(name, headers, headerDictCase);
|
||||
}
|
||||
}, "Check set method, names use characters with different case");
|
||||
|
||||
test(function() {
|
||||
var headers = new Headers();
|
||||
for (name in headerDictCase)
|
||||
headers.set(name, headerDictCase[name]);
|
||||
for (name in headerDictCase)
|
||||
headers.delete(name.toLowerCase());
|
||||
for (name in headerDictCase)
|
||||
assert_false(headers.has(name), "header " + name + " should have been deleted");
|
||||
}, "Check delete method, names use characters with different case");
|
|
@ -1,64 +0,0 @@
|
|||
<!doctype html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>Headers case management</title>
|
||||
<meta name="help" href="https://fetch.spec.whatwg.org/#concept-header-list-append">
|
||||
<meta name="author" title="Canon Research France" href="https://www.crf.canon.fr">
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
<script>
|
||||
var headerDictCase = {"UPPERCASE": "value1",
|
||||
"lowercase": "value2",
|
||||
"mixedCase": "value3",
|
||||
"Content-TYPE": "value4"
|
||||
};
|
||||
|
||||
function checkHeadersCase(originalName, headersToCheck, expectedDict) {
|
||||
var lowCaseName = originalName.toLowerCase();
|
||||
var upCaseName = originalName.toUpperCase();
|
||||
var expectedValue = expectedDict[originalName];
|
||||
assert_equals(headersToCheck.get(originalName), expectedValue,
|
||||
"name: " + originalName + " has value: " + expectedValue);
|
||||
assert_equals(headersToCheck.get(lowCaseName), expectedValue,
|
||||
"name: " + lowCaseName + " has value: " + expectedValue);
|
||||
assert_equals(headersToCheck.get(upCaseName), expectedValue,
|
||||
"name: " + upCaseName + " has value: " + expectedValue);
|
||||
}
|
||||
|
||||
test(function() {
|
||||
var headers = new Headers(headerDictCase);
|
||||
for (name in headerDictCase)
|
||||
checkHeadersCase(name, headers, headerDictCase)
|
||||
}, "Create headers, names use characters with different case");
|
||||
|
||||
test(function() {
|
||||
var headers = new Headers();
|
||||
for (name in headerDictCase) {
|
||||
headers.append(name, headerDictCase[name]);
|
||||
checkHeadersCase(name, headers, headerDictCase);
|
||||
}
|
||||
}, "Check append method, names use characters with different case");
|
||||
|
||||
test(function() {
|
||||
var headers = new Headers();
|
||||
for (name in headerDictCase) {
|
||||
headers.set(name, headerDictCase[name]);
|
||||
checkHeadersCase(name, headers, headerDictCase);
|
||||
}
|
||||
}, "Check set method, names use characters with different case");
|
||||
|
||||
test(function() {
|
||||
var headers = new Headers();
|
||||
for (name in headerDictCase)
|
||||
headers.set(name, headerDictCase[name]);
|
||||
for (name in headerDictCase)
|
||||
headers.delete(name.toLowerCase());
|
||||
for (name in headerDictCase)
|
||||
assert_false(headers.has(name), "header " + name + " should have been deleted");
|
||||
}, "Check delete method, names use characters with different case");
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,64 @@
|
|||
// META: title=Headers have combined (and sorted) values
|
||||
// META: global=window,worker
|
||||
|
||||
var headerSeqCombine = [["single", "singleValue"],
|
||||
["double", "doubleValue1"],
|
||||
["double", "doubleValue2"],
|
||||
["triple", "tripleValue1"],
|
||||
["triple", "tripleValue2"],
|
||||
["triple", "tripleValue3"]
|
||||
];
|
||||
var expectedDict = {"single": "singleValue",
|
||||
"double": "doubleValue1, doubleValue2",
|
||||
"triple": "tripleValue1, tripleValue2, tripleValue3"
|
||||
};
|
||||
|
||||
test(function() {
|
||||
var headers = new Headers(headerSeqCombine);
|
||||
for (name in expectedDict)
|
||||
assert_equals(headers.get(name), expectedDict[name]);
|
||||
}, "Create headers using same name for different values");
|
||||
|
||||
test(function() {
|
||||
var headers = new Headers(headerSeqCombine);
|
||||
for (name in expectedDict) {
|
||||
assert_true(headers.has(name), "name: " + name + " has value(s)");
|
||||
headers.delete(name);
|
||||
assert_false(headers.has(name), "name: " + name + " has no value(s) anymore");
|
||||
}
|
||||
}, "Check delete and has methods when using same name for different values");
|
||||
|
||||
test(function() {
|
||||
var headers = new Headers(headerSeqCombine);
|
||||
for (name in expectedDict) {
|
||||
headers.set(name,"newSingleValue");
|
||||
assert_equals(headers.get(name), "newSingleValue", "name: " + name + " has value: newSingleValue");
|
||||
}
|
||||
}, "Check set methods when called with already used name");
|
||||
|
||||
test(function() {
|
||||
var headers = new Headers(headerSeqCombine);
|
||||
for (name in expectedDict) {
|
||||
var value = headers.get(name);
|
||||
headers.append(name,"newSingleValue");
|
||||
assert_equals(headers.get(name), (value + ", " + "newSingleValue"));
|
||||
}
|
||||
}, "Check append methods when called with already used name");
|
||||
|
||||
test(() => {
|
||||
const headers = new Headers([["1", "a"],["1", "b"]]);
|
||||
for(let header of headers) {
|
||||
assert_array_equals(header, ["1", "a, b"]);
|
||||
}
|
||||
}, "Iterate combined values");
|
||||
|
||||
test(() => {
|
||||
const headers = new Headers([["2", "a"], ["1", "b"], ["2", "b"]]),
|
||||
expected = [["1", "b"], ["2", "a, b"]];
|
||||
let i = 0;
|
||||
for(let header of headers) {
|
||||
assert_array_equals(header, expected[i]);
|
||||
i++;
|
||||
}
|
||||
assert_equals(i, 2);
|
||||
}, "Iterate combined values in sorted order")
|
|
@ -1,76 +0,0 @@
|
|||
<!doctype html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>Headers have combined (and sorted) values</title>
|
||||
<meta name="help" href="https://fetch.spec.whatwg.org/#headers">
|
||||
<meta name="author" title="Canon Research France" href="https://www.crf.canon.fr">
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
<script>
|
||||
var headerSeqCombine = [["single", "singleValue"],
|
||||
["double", "doubleValue1"],
|
||||
["double", "doubleValue2"],
|
||||
["triple", "tripleValue1"],
|
||||
["triple", "tripleValue2"],
|
||||
["triple", "tripleValue3"]
|
||||
];
|
||||
var expectedDict = {"single": "singleValue",
|
||||
"double": "doubleValue1, doubleValue2",
|
||||
"triple": "tripleValue1, tripleValue2, tripleValue3"
|
||||
};
|
||||
|
||||
test(function() {
|
||||
var headers = new Headers(headerSeqCombine);
|
||||
for (name in expectedDict)
|
||||
assert_equals(headers.get(name), expectedDict[name]);
|
||||
}, "Create headers using same name for different values");
|
||||
|
||||
test(function() {
|
||||
var headers = new Headers(headerSeqCombine);
|
||||
for (name in expectedDict) {
|
||||
assert_true(headers.has(name), "name: " + name + " has value(s)");
|
||||
headers.delete(name);
|
||||
assert_false(headers.has(name), "name: " + name + " has no value(s) anymore");
|
||||
}
|
||||
}, "Check delete and has methods when using same name for different values");
|
||||
|
||||
test(function() {
|
||||
var headers = new Headers(headerSeqCombine);
|
||||
for (name in expectedDict) {
|
||||
headers.set(name,"newSingleValue");
|
||||
assert_equals(headers.get(name), "newSingleValue", "name: " + name + " has value: newSingleValue");
|
||||
}
|
||||
}, "Check set methods when called with already used name");
|
||||
|
||||
test(function() {
|
||||
var headers = new Headers(headerSeqCombine);
|
||||
for (name in expectedDict) {
|
||||
var value = headers.get(name);
|
||||
headers.append(name,"newSingleValue");
|
||||
assert_equals(headers.get(name), (value + ", " + "newSingleValue"));
|
||||
}
|
||||
}, "Check append methods when called with already used name");
|
||||
|
||||
test(() => {
|
||||
const headers = new Headers([["1", "a"],["1", "b"]]);
|
||||
for(let header of headers) {
|
||||
assert_array_equals(header, ["1", "a, b"]);
|
||||
}
|
||||
}, "Iterate combined values");
|
||||
|
||||
test(() => {
|
||||
const headers = new Headers([["2", "a"], ["1", "b"], ["2", "b"]]),
|
||||
expected = [["1", "b"], ["2", "a, b"]];
|
||||
let i = 0;
|
||||
for(let header of headers) {
|
||||
assert_array_equals(header, expected[i]);
|
||||
i++;
|
||||
}
|
||||
assert_equals(i, 2);
|
||||
}, "Iterate combined values in sorted order")
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,94 @@
|
|||
// META: title=Headers errors
|
||||
// META: global=window,worker
|
||||
|
||||
test(function() {
|
||||
assert_throws_js(TypeError, function() { new Headers([["name"]]); });
|
||||
}, "Create headers giving an array having one string as init argument");
|
||||
|
||||
test(function() {
|
||||
assert_throws_js(TypeError, function() { new Headers([["invalid", "invalidValue1", "invalidValue2"]]); });
|
||||
}, "Create headers giving an array having three strings as init argument");
|
||||
|
||||
test(function() {
|
||||
assert_throws_js(TypeError, function() { new Headers([["invalidĀ", "Value1"]]); });
|
||||
}, "Create headers giving bad header name as init argument");
|
||||
|
||||
test(function() {
|
||||
assert_throws_js(TypeError, function() { new Headers([["name", "invalidValueĀ"]]); });
|
||||
}, "Create headers giving bad header value as init argument");
|
||||
|
||||
var badNames = ["invalidĀ", {}];
|
||||
var badValues = ["invalidĀ"];
|
||||
|
||||
badNames.forEach(function(name) {
|
||||
test(function() {
|
||||
var headers = new Headers();
|
||||
assert_throws_js(TypeError, function() { headers.get(name); });
|
||||
}, "Check headers get with an invalid name " + name);
|
||||
});
|
||||
|
||||
badNames.forEach(function(name) {
|
||||
test(function() {
|
||||
var headers = new Headers();
|
||||
assert_throws_js(TypeError, function() { headers.delete(name); });
|
||||
}, "Check headers delete with an invalid name " + name);
|
||||
});
|
||||
|
||||
badNames.forEach(function(name) {
|
||||
test(function() {
|
||||
var headers = new Headers();
|
||||
assert_throws_js(TypeError, function() { headers.has(name); });
|
||||
}, "Check headers has with an invalid name " + name);
|
||||
});
|
||||
|
||||
badNames.forEach(function(name) {
|
||||
test(function() {
|
||||
var headers = new Headers();
|
||||
assert_throws_js(TypeError, function() { headers.set(name, "Value1"); });
|
||||
}, "Check headers set with an invalid name " + name);
|
||||
});
|
||||
|
||||
badValues.forEach(function(value) {
|
||||
test(function() {
|
||||
var headers = new Headers();
|
||||
assert_throws_js(TypeError, function() { headers.set("name", value); });
|
||||
}, "Check headers set with an invalid value " + value);
|
||||
});
|
||||
|
||||
badNames.forEach(function(name) {
|
||||
test(function() {
|
||||
var headers = new Headers();
|
||||
assert_throws_js(TypeError, function() { headers.append("invalidĀ", "Value1"); });
|
||||
}, "Check headers append with an invalid name " + name);
|
||||
});
|
||||
|
||||
badValues.forEach(function(value) {
|
||||
test(function() {
|
||||
var headers = new Headers();
|
||||
assert_throws_js(TypeError, function() { headers.append("name", value); });
|
||||
}, "Check headers append with an invalid value " + value);
|
||||
});
|
||||
|
||||
test(function() {
|
||||
var headers = new Headers([["name", "value"]]);
|
||||
assert_throws_js(TypeError, function() { headers.forEach(); });
|
||||
assert_throws_js(TypeError, function() { headers.forEach(undefined); });
|
||||
assert_throws_js(TypeError, function() { headers.forEach(1); });
|
||||
}, "Headers forEach throws if argument is not callable");
|
||||
|
||||
test(function() {
|
||||
var headers = new Headers([["name1", "value1"], ["name2", "value2"], ["name3", "value3"]]);
|
||||
var counter = 0;
|
||||
try {
|
||||
headers.forEach(function(value, name) {
|
||||
counter++;
|
||||
if (name == "name2")
|
||||
throw "error";
|
||||
});
|
||||
} catch (e) {
|
||||
assert_equals(counter, 2);
|
||||
assert_equals(e, "error");
|
||||
return;
|
||||
}
|
||||
assert_unreached();
|
||||
}, "Headers forEach loop should stop if callback is throwing exception");
|
|
@ -1,107 +0,0 @@
|
|||
<!doctype html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>Headers errors</title>
|
||||
<meta name="help" href="https://fetch.spec.whatwg.org/#headers">
|
||||
<meta name="author" title="Canon Research France" href="https://www.crf.canon.fr">
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
<script>
|
||||
|
||||
test(function() {
|
||||
assert_throws_js(TypeError, function() { new Headers([["name"]]); });
|
||||
}, "Create headers giving an array having one string as init argument");
|
||||
|
||||
test(function() {
|
||||
assert_throws_js(TypeError, function() { new Headers([["invalid", "invalidValue1", "invalidValue2"]]); });
|
||||
}, "Create headers giving an array having three strings as init argument");
|
||||
|
||||
test(function() {
|
||||
assert_throws_js(TypeError, function() { new Headers([["invalidĀ", "Value1"]]); });
|
||||
}, "Create headers giving bad header name as init argument");
|
||||
|
||||
test(function() {
|
||||
assert_throws_js(TypeError, function() { new Headers([["name", "invalidValueĀ"]]); });
|
||||
}, "Create headers giving bad header value as init argument");
|
||||
|
||||
var badNames = ["invalidĀ", {}];
|
||||
var badValues = ["invalidĀ"];
|
||||
|
||||
badNames.forEach(function(name) {
|
||||
test(function() {
|
||||
var headers = new Headers();
|
||||
assert_throws_js(TypeError, function() { headers.get(name); });
|
||||
}, "Check headers get with an invalid name " + name);
|
||||
});
|
||||
|
||||
badNames.forEach(function(name) {
|
||||
test(function() {
|
||||
var headers = new Headers();
|
||||
assert_throws_js(TypeError, function() { headers.delete(name); });
|
||||
}, "Check headers delete with an invalid name " + name);
|
||||
});
|
||||
|
||||
badNames.forEach(function(name) {
|
||||
test(function() {
|
||||
var headers = new Headers();
|
||||
assert_throws_js(TypeError, function() { headers.has(name); });
|
||||
}, "Check headers has with an invalid name " + name);
|
||||
});
|
||||
|
||||
badNames.forEach(function(name) {
|
||||
test(function() {
|
||||
var headers = new Headers();
|
||||
assert_throws_js(TypeError, function() { headers.set(name, "Value1"); });
|
||||
}, "Check headers set with an invalid name " + name);
|
||||
});
|
||||
|
||||
badValues.forEach(function(value) {
|
||||
test(function() {
|
||||
var headers = new Headers();
|
||||
assert_throws_js(TypeError, function() { headers.set("name", value); });
|
||||
}, "Check headers set with an invalid value " + value);
|
||||
});
|
||||
|
||||
badNames.forEach(function(name) {
|
||||
test(function() {
|
||||
var headers = new Headers();
|
||||
assert_throws_js(TypeError, function() { headers.append("invalidĀ", "Value1"); });
|
||||
}, "Check headers append with an invalid name " + name);
|
||||
});
|
||||
|
||||
badValues.forEach(function(value) {
|
||||
test(function() {
|
||||
var headers = new Headers();
|
||||
assert_throws_js(TypeError, function() { headers.append("name", value); });
|
||||
}, "Check headers append with an invalid value " + value);
|
||||
});
|
||||
|
||||
test(function() {
|
||||
var headers = new Headers([["name", "value"]]);
|
||||
assert_throws_js(TypeError, function() { headers.forEach(); });
|
||||
assert_throws_js(TypeError, function() { headers.forEach(undefined); });
|
||||
assert_throws_js(TypeError, function() { headers.forEach(1); });
|
||||
}, "Headers forEach throws if argument is not callable");
|
||||
|
||||
test(function() {
|
||||
var headers = new Headers([["name1", "value1"], ["name2", "value2"], ["name3", "value3"]]);
|
||||
var counter = 0;
|
||||
try {
|
||||
headers.forEach(function(value, name) {
|
||||
counter++;
|
||||
if (name == "name2")
|
||||
throw "error";
|
||||
});
|
||||
} catch (e) {
|
||||
assert_equals(counter, 2);
|
||||
assert_equals(e, "error");
|
||||
return;
|
||||
}
|
||||
assert_unreached();
|
||||
}, "Headers forEach loop should stop if callback is throwing exception");
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
|
@ -1,3 +1,5 @@
|
|||
// META: global=window,worker
|
||||
|
||||
promise_test(() => fetch("../cors/resources/not-cors-safelisted.json").then(res => res.json().then(runTests)), "Loading data…");
|
||||
|
||||
const longValue = "s".repeat(127);
|
|
@ -0,0 +1,35 @@
|
|||
// META: title=Headers normalize values
|
||||
// META: global=window,worker
|
||||
|
||||
var headerDictWS = {"name1": " space ",
|
||||
"name2": "\ttab\t",
|
||||
"name3": " spaceAndTab\t",
|
||||
"name4": "\r\n newLine", //obs-fold cases
|
||||
"name5": "newLine\r\n ",
|
||||
"name6": "\r\n\tnewLine",
|
||||
};
|
||||
|
||||
test(function() {
|
||||
var headers = new Headers(headerDictWS);
|
||||
for (name in headerDictWS)
|
||||
assert_equals(headers.get(name), headerDictWS[name].trim(),
|
||||
"name: " + name + " has normalized value: " + headerDictWS[name].trim());
|
||||
}, "Create headers with not normalized values");
|
||||
|
||||
test(function() {
|
||||
var headers = new Headers();
|
||||
for (name in headerDictWS) {
|
||||
headers.append(name, headerDictWS[name]);
|
||||
assert_equals(headers.get(name), headerDictWS[name].trim(),
|
||||
"name: " + name + " has value: " + headerDictWS[name].trim());
|
||||
}
|
||||
}, "Check append method with not normalized values");
|
||||
|
||||
test(function() {
|
||||
var headers = new Headers();
|
||||
for (name in headerDictWS) {
|
||||
headers.set(name, headerDictWS[name]);
|
||||
assert_equals(headers.get(name), headerDictWS[name].trim(),
|
||||
"name: " + name + " has value: " + headerDictWS[name].trim());
|
||||
}
|
||||
}, "Check set method with not normalized values");
|
|
@ -1,47 +0,0 @@
|
|||
<!doctype html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>Headers normalize values</title>
|
||||
<meta name="help" href="https://fetch.spec.whatwg.org/#concept-header-value-normalize">
|
||||
<meta name="author" title="Canon Research France" href="https://www.crf.canon.fr">
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
<script>
|
||||
var headerDictWS = {"name1": " space ",
|
||||
"name2": "\ttab\t",
|
||||
"name3": " spaceAndTab\t",
|
||||
"name4": "\r\n newLine", //obs-fold cases
|
||||
"name5": "newLine\r\n ",
|
||||
"name6": "\r\n\tnewLine",
|
||||
};
|
||||
|
||||
test(function() {
|
||||
var headers = new Headers(headerDictWS);
|
||||
for (name in headerDictWS)
|
||||
assert_equals(headers.get(name), headerDictWS[name].trim(),
|
||||
"name: " + name + " has normalized value: " + headerDictWS[name].trim());
|
||||
}, "Create headers with not normalized values");
|
||||
|
||||
test(function() {
|
||||
var headers = new Headers();
|
||||
for (name in headerDictWS) {
|
||||
headers.append(name, headerDictWS[name]);
|
||||
assert_equals(headers.get(name), headerDictWS[name].trim(),
|
||||
"name: " + name + " has value: " + headerDictWS[name].trim());
|
||||
}
|
||||
}, "Check append method with not normalized values");
|
||||
|
||||
test(function() {
|
||||
var headers = new Headers();
|
||||
for (name in headerDictWS) {
|
||||
headers.set(name, headerDictWS[name]);
|
||||
assert_equals(headers.get(name), headerDictWS[name].trim(),
|
||||
"name: " + name + " has value: " + headerDictWS[name].trim());
|
||||
}
|
||||
}, "Check set method with not normalized values");
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
|
@ -1,9 +1,5 @@
|
|||
<!doctype html>
|
||||
<meta charset=utf-8>
|
||||
<title></title>
|
||||
<script src=/resources/testharness.js></script>
|
||||
<script src=/resources/testharnessreport.js></script>
|
||||
<script>
|
||||
// META: global=window,worker
|
||||
|
||||
var log = [];
|
||||
function clearLog() {
|
||||
log = [];
|
||||
|
@ -357,4 +353,3 @@ test(function() {
|
|||
assert_true(h.has("c"));
|
||||
assert_equals(h.get("c"), "d");
|
||||
}, "Operation with non-enumerable Symbol keys");
|
||||
</script>
|
|
@ -0,0 +1,18 @@
|
|||
// META: title=Headers basic
|
||||
// META: global=window,worker
|
||||
|
||||
var headers = new Headers();
|
||||
var methods = ["append",
|
||||
"delete",
|
||||
"get",
|
||||
"has",
|
||||
"set",
|
||||
//Headers is iterable
|
||||
"entries",
|
||||
"keys",
|
||||
"values"
|
||||
];
|
||||
for (var idx in methods)
|
||||
test(function() {
|
||||
assert_true(methods[idx] in headers, "headers has " + methods[idx] + " method");
|
||||
}, "Headers has " + methods[idx] + " method");
|
|
@ -1,31 +0,0 @@
|
|||
<!doctype html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>Headers basic</title>
|
||||
<meta name="help" href="https://fetch.spec.whatwg.org/#headers">
|
||||
<meta name="help" href="https://heycam.github.io/webidl/#idl-iterable">
|
||||
<meta name="author" title="Canon Research France" href="https://www.crf.canon.fr">
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
<script>
|
||||
var headers = new Headers();
|
||||
var methods = ["append",
|
||||
"delete",
|
||||
"get",
|
||||
"has",
|
||||
"set",
|
||||
//Headers is iterable
|
||||
"entries",
|
||||
"keys",
|
||||
"values"
|
||||
];
|
||||
for (var idx in methods)
|
||||
test(function() {
|
||||
assert_true(methods[idx] in headers, "headers has " + methods[idx] + " method");
|
||||
}, "Headers has " + methods[idx] + " method");
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
|
@ -1,3 +1,4 @@
|
|||
// META: global=window,worker
|
||||
// META: script=/common/get-host-info.sub.js
|
||||
|
||||
const BASE = location.href;
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
// META: global=window,worker
|
||||
// META: script=../resources/utils.js
|
||||
// META: script=/common/utils.js
|
||||
// META: timeout=long
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
// META: global=window,worker
|
||||
// META: script=../resources/utils.js
|
||||
|
||||
// Tests receiving a redirect response with a Location header with an empty
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
// META: global=window,worker
|
||||
// META: script=../resources/utils.js
|
||||
|
||||
// See https://github.com/whatwg/fetch/issues/883 for the behavior covered by
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
// META: global=window,worker
|
||||
// META: script=../resources/utils.js
|
||||
|
||||
function redirectLocation(desc, redirectUrl, redirectLocation, redirectStatus, redirectMode, shouldPass) {
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
// META: global=window,worker
|
||||
// META: script=../resources/utils.js
|
||||
|
||||
// Creates a promise_test that fetches a URL that returns a redirect response.
|
||||
|
|
|
@ -0,0 +1,19 @@
|
|||
// META: title=Fetch: handling different schemes in redirects
|
||||
// META: global=window,worker
|
||||
// META: script=/common/get-host-info.sub.js
|
||||
|
||||
// All non-HTTP(S) schemes cannot survive redirects
|
||||
var url = "../resources/redirect.py?location=";
|
||||
var tests = [
|
||||
url + "mailto:a@a.com",
|
||||
url + "data:,HI",
|
||||
url + "facetime:a@a.org",
|
||||
url + "about:blank",
|
||||
url + "about:unicorn",
|
||||
url + "blob:djfksfjs"
|
||||
];
|
||||
tests.forEach(function(url) {
|
||||
promise_test(function(test) {
|
||||
return promise_rejects_js(test, TypeError, fetch(url))
|
||||
})
|
||||
})
|
|
@ -1,23 +0,0 @@
|
|||
<!doctype html>
|
||||
<meta charset="utf-8">
|
||||
<title>Fetch: handling different schemes in redirects</title>
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
<div id=log></div>
|
||||
<script>
|
||||
// All non-HTTP(S) schemes cannot survive redirects
|
||||
var url = "../resources/redirect.py?location=";
|
||||
var tests = [
|
||||
url + "mailto:a@a.com",
|
||||
url + "data:,HI",
|
||||
url + "facetime:a@a.org",
|
||||
url + "about:blank",
|
||||
url + "about:unicorn",
|
||||
url + "blob:djfksfjs"
|
||||
];
|
||||
tests.forEach(function(url) {
|
||||
promise_test(function(test) {
|
||||
return promise_rejects_js(test, TypeError, fetch(url))
|
||||
})
|
||||
})
|
||||
</script>
|
|
@ -1,3 +1,4 @@
|
|||
// META: global=window,worker
|
||||
// META: script=/common/get-host-info.sub.js
|
||||
|
||||
var dataURL = "data:text/plain;base64,cmVzcG9uc2UncyBib2R5";
|
||||
|
|
|
@ -0,0 +1,79 @@
|
|||
// META: global=window,worker
|
||||
|
||||
// list of bad ports according to
|
||||
// https://fetch.spec.whatwg.org/#port-blocking
|
||||
var BLOCKED_PORTS_LIST = [
|
||||
1, // tcpmux
|
||||
7, // echo
|
||||
9, // discard
|
||||
11, // systat
|
||||
13, // daytime
|
||||
15, // netstat
|
||||
17, // qotd
|
||||
19, // chargen
|
||||
20, // ftp-data
|
||||
21, // ftp
|
||||
22, // ssh
|
||||
23, // telnet
|
||||
25, // smtp
|
||||
37, // time
|
||||
42, // name
|
||||
43, // nicname
|
||||
53, // domain
|
||||
77, // priv-rjs
|
||||
79, // finger
|
||||
87, // ttylink
|
||||
95, // supdup
|
||||
101, // hostriame
|
||||
102, // iso-tsap
|
||||
103, // gppitnp
|
||||
104, // acr-nema
|
||||
109, // pop2
|
||||
110, // pop3
|
||||
111, // sunrpc
|
||||
113, // auth
|
||||
115, // sftp
|
||||
117, // uucp-path
|
||||
119, // nntp
|
||||
123, // ntp
|
||||
135, // loc-srv / epmap
|
||||
139, // netbios
|
||||
143, // imap2
|
||||
179, // bgp
|
||||
389, // ldap
|
||||
427, // afp (alternate)
|
||||
465, // smtp (alternate)
|
||||
512, // print / exec
|
||||
513, // login
|
||||
514, // shell
|
||||
515, // printer
|
||||
526, // tempo
|
||||
530, // courier
|
||||
531, // chat
|
||||
532, // netnews
|
||||
540, // uucp
|
||||
548, // afp
|
||||
556, // remotefs
|
||||
563, // nntp+ssl
|
||||
587, // smtp (outgoing)
|
||||
601, // syslog-conn
|
||||
636, // ldap+ssl
|
||||
993, // ldap+ssl
|
||||
995, // pop3+ssl
|
||||
2049, // nfs
|
||||
3659, // apple-sasl
|
||||
4045, // lockd
|
||||
6000, // x11
|
||||
6665, // irc (alternate)
|
||||
6666, // irc (alternate)
|
||||
6667, // irc (default)
|
||||
6668, // irc (alternate)
|
||||
6669, // irc (alternate)
|
||||
6697, // irc+tls
|
||||
];
|
||||
|
||||
BLOCKED_PORTS_LIST.map(function(a){
|
||||
promise_test(function(t){
|
||||
return promise_rejects_js(t, TypeError, fetch("http://example.com:" + a))
|
||||
}, 'Request on bad port ' + a + ' should throw TypeError.');
|
||||
});
|
|
@ -1,85 +0,0 @@
|
|||
<!doctype html>
|
||||
<meta charset="utf-8">
|
||||
<title></title>
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
<script>
|
||||
|
||||
// list of bad ports according to
|
||||
// https://fetch.spec.whatwg.org/#port-blocking
|
||||
var BLOCKED_PORTS_LIST = [
|
||||
1, // tcpmux
|
||||
7, // echo
|
||||
9, // discard
|
||||
11, // systat
|
||||
13, // daytime
|
||||
15, // netstat
|
||||
17, // qotd
|
||||
19, // chargen
|
||||
20, // ftp-data
|
||||
21, // ftp
|
||||
22, // ssh
|
||||
23, // telnet
|
||||
25, // smtp
|
||||
37, // time
|
||||
42, // name
|
||||
43, // nicname
|
||||
53, // domain
|
||||
77, // priv-rjs
|
||||
79, // finger
|
||||
87, // ttylink
|
||||
95, // supdup
|
||||
101, // hostriame
|
||||
102, // iso-tsap
|
||||
103, // gppitnp
|
||||
104, // acr-nema
|
||||
109, // pop2
|
||||
110, // pop3
|
||||
111, // sunrpc
|
||||
113, // auth
|
||||
115, // sftp
|
||||
117, // uucp-path
|
||||
119, // nntp
|
||||
123, // ntp
|
||||
135, // loc-srv / epmap
|
||||
139, // netbios
|
||||
143, // imap2
|
||||
179, // bgp
|
||||
389, // ldap
|
||||
427, // afp (alternate)
|
||||
465, // smtp (alternate)
|
||||
512, // print / exec
|
||||
513, // login
|
||||
514, // shell
|
||||
515, // printer
|
||||
526, // tempo
|
||||
530, // courier
|
||||
531, // chat
|
||||
532, // netnews
|
||||
540, // uucp
|
||||
548, // afp
|
||||
556, // remotefs
|
||||
563, // nntp+ssl
|
||||
587, // smtp (outgoing)
|
||||
601, // syslog-conn
|
||||
636, // ldap+ssl
|
||||
993, // ldap+ssl
|
||||
995, // pop3+ssl
|
||||
2049, // nfs
|
||||
3659, // apple-sasl
|
||||
4045, // lockd
|
||||
6000, // x11
|
||||
6665, // irc (alternate)
|
||||
6666, // irc (alternate)
|
||||
6667, // irc (default)
|
||||
6668, // irc (alternate)
|
||||
6669, // irc (alternate)
|
||||
6697, // irc+tls
|
||||
];
|
||||
|
||||
BLOCKED_PORTS_LIST.map(function(a){
|
||||
promise_test(function(t){
|
||||
return promise_rejects_js(t, TypeError, fetch("http://example.com:" + a))
|
||||
}, 'Request on bad port ' + a + ' should throw TypeError.');
|
||||
});
|
||||
</script>
|
|
@ -0,0 +1,170 @@
|
|||
// META: global=window,worker
|
||||
// META: title=Request cache - default with conditional requests
|
||||
// META: timeout=long
|
||||
// META: script=/common/utils.js
|
||||
// META: script=/common/get-host-info.sub.js
|
||||
// META: script=request-cache.js
|
||||
|
||||
var tests = [
|
||||
{
|
||||
name: 'RequestCache "default" mode with an If-Modified-Since header (following a request without additional headers) is treated similarly to "no-store"',
|
||||
state: "stale",
|
||||
request_cache: ["default", "default"],
|
||||
request_headers: [{}, {"If-Modified-Since": now.toGMTString()}],
|
||||
expected_validation_headers: [false, false],
|
||||
expected_no_cache_headers: [false, true],
|
||||
},
|
||||
{
|
||||
name: 'RequestCache "default" mode with an If-Modified-Since header (following a request without additional headers) is treated similarly to "no-store"',
|
||||
state: "fresh",
|
||||
request_cache: ["default", "default"],
|
||||
request_headers: [{}, {"If-Modified-Since": now.toGMTString()}],
|
||||
expected_validation_headers: [false, false],
|
||||
expected_no_cache_headers: [false, true],
|
||||
},
|
||||
{
|
||||
name: 'RequestCache "default" mode with an If-Modified-Since header is treated similarly to "no-store"',
|
||||
state: "stale",
|
||||
request_cache: ["default", "default"],
|
||||
request_headers: [{"If-Modified-Since": now.toGMTString()}, {}],
|
||||
expected_validation_headers: [false, false],
|
||||
expected_no_cache_headers: [true, false],
|
||||
},
|
||||
{
|
||||
name: 'RequestCache "default" mode with an If-Modified-Since header is treated similarly to "no-store"',
|
||||
state: "fresh",
|
||||
request_cache: ["default", "default"],
|
||||
request_headers: [{"If-Modified-Since": now.toGMTString()}, {}],
|
||||
expected_validation_headers: [false, false],
|
||||
expected_no_cache_headers: [true, false],
|
||||
},
|
||||
{
|
||||
name: 'RequestCache "default" mode with an If-None-Match header (following a request without additional headers) is treated similarly to "no-store"',
|
||||
state: "stale",
|
||||
request_cache: ["default", "default"],
|
||||
request_headers: [{}, {"If-None-Match": '"foo"'}],
|
||||
expected_validation_headers: [false, false],
|
||||
expected_no_cache_headers: [false, true],
|
||||
},
|
||||
{
|
||||
name: 'RequestCache "default" mode with an If-None-Match header (following a request without additional headers) is treated similarly to "no-store"',
|
||||
state: "fresh",
|
||||
request_cache: ["default", "default"],
|
||||
request_headers: [{}, {"If-None-Match": '"foo"'}],
|
||||
expected_validation_headers: [false, false],
|
||||
expected_no_cache_headers: [false, true],
|
||||
},
|
||||
{
|
||||
name: 'RequestCache "default" mode with an If-None-Match header is treated similarly to "no-store"',
|
||||
state: "stale",
|
||||
request_cache: ["default", "default"],
|
||||
request_headers: [{"If-None-Match": '"foo"'}, {}],
|
||||
expected_validation_headers: [false, false],
|
||||
expected_no_cache_headers: [true, false],
|
||||
},
|
||||
{
|
||||
name: 'RequestCache "default" mode with an If-None-Match header is treated similarly to "no-store"',
|
||||
state: "fresh",
|
||||
request_cache: ["default", "default"],
|
||||
request_headers: [{"If-None-Match": '"foo"'}, {}],
|
||||
expected_validation_headers: [false, false],
|
||||
expected_no_cache_headers: [true, false],
|
||||
},
|
||||
{
|
||||
name: 'RequestCache "default" mode with an If-Unmodified-Since header (following a request without additional headers) is treated similarly to "no-store"',
|
||||
state: "stale",
|
||||
request_cache: ["default", "default"],
|
||||
request_headers: [{}, {"If-Unmodified-Since": now.toGMTString()}],
|
||||
expected_validation_headers: [false, false],
|
||||
expected_no_cache_headers: [false, true],
|
||||
},
|
||||
{
|
||||
name: 'RequestCache "default" mode with an If-Unmodified-Since header (following a request without additional headers) is treated similarly to "no-store"',
|
||||
state: "fresh",
|
||||
request_cache: ["default", "default"],
|
||||
request_headers: [{}, {"If-Unmodified-Since": now.toGMTString()}],
|
||||
expected_validation_headers: [false, false],
|
||||
expected_no_cache_headers: [false, true],
|
||||
},
|
||||
{
|
||||
name: 'RequestCache "default" mode with an If-Unmodified-Since header is treated similarly to "no-store"',
|
||||
state: "stale",
|
||||
request_cache: ["default", "default"],
|
||||
request_headers: [{"If-Unmodified-Since": now.toGMTString()}, {}],
|
||||
expected_validation_headers: [false, false],
|
||||
expected_no_cache_headers: [true, false],
|
||||
},
|
||||
{
|
||||
name: 'RequestCache "default" mode with an If-Unmodified-Since header is treated similarly to "no-store"',
|
||||
state: "fresh",
|
||||
request_cache: ["default", "default"],
|
||||
request_headers: [{"If-Unmodified-Since": now.toGMTString()}, {}],
|
||||
expected_validation_headers: [false, false],
|
||||
expected_no_cache_headers: [true, false],
|
||||
},
|
||||
{
|
||||
name: 'RequestCache "default" mode with an If-Match header (following a request without additional headers) is treated similarly to "no-store"',
|
||||
state: "stale",
|
||||
request_cache: ["default", "default"],
|
||||
request_headers: [{}, {"If-Match": '"foo"'}],
|
||||
expected_validation_headers: [false, false],
|
||||
expected_no_cache_headers: [false, true],
|
||||
},
|
||||
{
|
||||
name: 'RequestCache "default" mode with an If-Match header (following a request without additional headers) is treated similarly to "no-store"',
|
||||
state: "fresh",
|
||||
request_cache: ["default", "default"],
|
||||
request_headers: [{}, {"If-Match": '"foo"'}],
|
||||
expected_validation_headers: [false, false],
|
||||
expected_no_cache_headers: [false, true],
|
||||
},
|
||||
{
|
||||
name: 'RequestCache "default" mode with an If-Match header is treated similarly to "no-store"',
|
||||
state: "stale",
|
||||
request_cache: ["default", "default"],
|
||||
request_headers: [{"If-Match": '"foo"'}, {}],
|
||||
expected_validation_headers: [false, false],
|
||||
expected_no_cache_headers: [true, false],
|
||||
},
|
||||
{
|
||||
name: 'RequestCache "default" mode with an If-Match header is treated similarly to "no-store"',
|
||||
state: "fresh",
|
||||
request_cache: ["default", "default"],
|
||||
request_headers: [{"If-Match": '"foo"'}, {}],
|
||||
expected_validation_headers: [false, false],
|
||||
expected_no_cache_headers: [true, false],
|
||||
},
|
||||
{
|
||||
name: 'RequestCache "default" mode with an If-Range header (following a request without additional headers) is treated similarly to "no-store"',
|
||||
state: "stale",
|
||||
request_cache: ["default", "default"],
|
||||
request_headers: [{}, {"If-Range": '"foo"'}],
|
||||
expected_validation_headers: [false, false],
|
||||
expected_no_cache_headers: [false, true],
|
||||
},
|
||||
{
|
||||
name: 'RequestCache "default" mode with an If-Range header (following a request without additional headers) is treated similarly to "no-store"',
|
||||
state: "fresh",
|
||||
request_cache: ["default", "default"],
|
||||
request_headers: [{}, {"If-Range": '"foo"'}],
|
||||
expected_validation_headers: [false, false],
|
||||
expected_no_cache_headers: [false, true],
|
||||
},
|
||||
{
|
||||
name: 'RequestCache "default" mode with an If-Range header is treated similarly to "no-store"',
|
||||
state: "stale",
|
||||
request_cache: ["default", "default"],
|
||||
request_headers: [{"If-Range": '"foo"'}, {}],
|
||||
expected_validation_headers: [false, false],
|
||||
expected_no_cache_headers: [true, false],
|
||||
},
|
||||
{
|
||||
name: 'RequestCache "default" mode with an If-Range header is treated similarly to "no-store"',
|
||||
state: "fresh",
|
||||
request_cache: ["default", "default"],
|
||||
request_headers: [{"If-Range": '"foo"'}, {}],
|
||||
expected_validation_headers: [false, false],
|
||||
expected_no_cache_headers: [true, false],
|
||||
},
|
||||
];
|
||||
run_tests(tests);
|
|
@ -1,181 +0,0 @@
|
|||
<!doctype html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>Request cache - default with conditional requests</title>
|
||||
<meta name="timeout" content="long">
|
||||
<meta name="help" href="https://fetch.spec.whatwg.org/#request">
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
<script src="/common/utils.js"></script>
|
||||
<script src="/common/get-host-info.sub.js"></script>
|
||||
<script src="request-cache.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
<script>
|
||||
var tests = [
|
||||
{
|
||||
name: 'RequestCache "default" mode with an If-Modified-Since header (following a request without additional headers) is treated similarly to "no-store"',
|
||||
state: "stale",
|
||||
request_cache: ["default", "default"],
|
||||
request_headers: [{}, {"If-Modified-Since": now.toGMTString()}],
|
||||
expected_validation_headers: [false, false],
|
||||
expected_no_cache_headers: [false, true],
|
||||
},
|
||||
{
|
||||
name: 'RequestCache "default" mode with an If-Modified-Since header (following a request without additional headers) is treated similarly to "no-store"',
|
||||
state: "fresh",
|
||||
request_cache: ["default", "default"],
|
||||
request_headers: [{}, {"If-Modified-Since": now.toGMTString()}],
|
||||
expected_validation_headers: [false, false],
|
||||
expected_no_cache_headers: [false, true],
|
||||
},
|
||||
{
|
||||
name: 'RequestCache "default" mode with an If-Modified-Since header is treated similarly to "no-store"',
|
||||
state: "stale",
|
||||
request_cache: ["default", "default"],
|
||||
request_headers: [{"If-Modified-Since": now.toGMTString()}, {}],
|
||||
expected_validation_headers: [false, false],
|
||||
expected_no_cache_headers: [true, false],
|
||||
},
|
||||
{
|
||||
name: 'RequestCache "default" mode with an If-Modified-Since header is treated similarly to "no-store"',
|
||||
state: "fresh",
|
||||
request_cache: ["default", "default"],
|
||||
request_headers: [{"If-Modified-Since": now.toGMTString()}, {}],
|
||||
expected_validation_headers: [false, false],
|
||||
expected_no_cache_headers: [true, false],
|
||||
},
|
||||
{
|
||||
name: 'RequestCache "default" mode with an If-None-Match header (following a request without additional headers) is treated similarly to "no-store"',
|
||||
state: "stale",
|
||||
request_cache: ["default", "default"],
|
||||
request_headers: [{}, {"If-None-Match": '"foo"'}],
|
||||
expected_validation_headers: [false, false],
|
||||
expected_no_cache_headers: [false, true],
|
||||
},
|
||||
{
|
||||
name: 'RequestCache "default" mode with an If-None-Match header (following a request without additional headers) is treated similarly to "no-store"',
|
||||
state: "fresh",
|
||||
request_cache: ["default", "default"],
|
||||
request_headers: [{}, {"If-None-Match": '"foo"'}],
|
||||
expected_validation_headers: [false, false],
|
||||
expected_no_cache_headers: [false, true],
|
||||
},
|
||||
{
|
||||
name: 'RequestCache "default" mode with an If-None-Match header is treated similarly to "no-store"',
|
||||
state: "stale",
|
||||
request_cache: ["default", "default"],
|
||||
request_headers: [{"If-None-Match": '"foo"'}, {}],
|
||||
expected_validation_headers: [false, false],
|
||||
expected_no_cache_headers: [true, false],
|
||||
},
|
||||
{
|
||||
name: 'RequestCache "default" mode with an If-None-Match header is treated similarly to "no-store"',
|
||||
state: "fresh",
|
||||
request_cache: ["default", "default"],
|
||||
request_headers: [{"If-None-Match": '"foo"'}, {}],
|
||||
expected_validation_headers: [false, false],
|
||||
expected_no_cache_headers: [true, false],
|
||||
},
|
||||
{
|
||||
name: 'RequestCache "default" mode with an If-Unmodified-Since header (following a request without additional headers) is treated similarly to "no-store"',
|
||||
state: "stale",
|
||||
request_cache: ["default", "default"],
|
||||
request_headers: [{}, {"If-Unmodified-Since": now.toGMTString()}],
|
||||
expected_validation_headers: [false, false],
|
||||
expected_no_cache_headers: [false, true],
|
||||
},
|
||||
{
|
||||
name: 'RequestCache "default" mode with an If-Unmodified-Since header (following a request without additional headers) is treated similarly to "no-store"',
|
||||
state: "fresh",
|
||||
request_cache: ["default", "default"],
|
||||
request_headers: [{}, {"If-Unmodified-Since": now.toGMTString()}],
|
||||
expected_validation_headers: [false, false],
|
||||
expected_no_cache_headers: [false, true],
|
||||
},
|
||||
{
|
||||
name: 'RequestCache "default" mode with an If-Unmodified-Since header is treated similarly to "no-store"',
|
||||
state: "stale",
|
||||
request_cache: ["default", "default"],
|
||||
request_headers: [{"If-Unmodified-Since": now.toGMTString()}, {}],
|
||||
expected_validation_headers: [false, false],
|
||||
expected_no_cache_headers: [true, false],
|
||||
},
|
||||
{
|
||||
name: 'RequestCache "default" mode with an If-Unmodified-Since header is treated similarly to "no-store"',
|
||||
state: "fresh",
|
||||
request_cache: ["default", "default"],
|
||||
request_headers: [{"If-Unmodified-Since": now.toGMTString()}, {}],
|
||||
expected_validation_headers: [false, false],
|
||||
expected_no_cache_headers: [true, false],
|
||||
},
|
||||
{
|
||||
name: 'RequestCache "default" mode with an If-Match header (following a request without additional headers) is treated similarly to "no-store"',
|
||||
state: "stale",
|
||||
request_cache: ["default", "default"],
|
||||
request_headers: [{}, {"If-Match": '"foo"'}],
|
||||
expected_validation_headers: [false, false],
|
||||
expected_no_cache_headers: [false, true],
|
||||
},
|
||||
{
|
||||
name: 'RequestCache "default" mode with an If-Match header (following a request without additional headers) is treated similarly to "no-store"',
|
||||
state: "fresh",
|
||||
request_cache: ["default", "default"],
|
||||
request_headers: [{}, {"If-Match": '"foo"'}],
|
||||
expected_validation_headers: [false, false],
|
||||
expected_no_cache_headers: [false, true],
|
||||
},
|
||||
{
|
||||
name: 'RequestCache "default" mode with an If-Match header is treated similarly to "no-store"',
|
||||
state: "stale",
|
||||
request_cache: ["default", "default"],
|
||||
request_headers: [{"If-Match": '"foo"'}, {}],
|
||||
expected_validation_headers: [false, false],
|
||||
expected_no_cache_headers: [true, false],
|
||||
},
|
||||
{
|
||||
name: 'RequestCache "default" mode with an If-Match header is treated similarly to "no-store"',
|
||||
state: "fresh",
|
||||
request_cache: ["default", "default"],
|
||||
request_headers: [{"If-Match": '"foo"'}, {}],
|
||||
expected_validation_headers: [false, false],
|
||||
expected_no_cache_headers: [true, false],
|
||||
},
|
||||
{
|
||||
name: 'RequestCache "default" mode with an If-Range header (following a request without additional headers) is treated similarly to "no-store"',
|
||||
state: "stale",
|
||||
request_cache: ["default", "default"],
|
||||
request_headers: [{}, {"If-Range": '"foo"'}],
|
||||
expected_validation_headers: [false, false],
|
||||
expected_no_cache_headers: [false, true],
|
||||
},
|
||||
{
|
||||
name: 'RequestCache "default" mode with an If-Range header (following a request without additional headers) is treated similarly to "no-store"',
|
||||
state: "fresh",
|
||||
request_cache: ["default", "default"],
|
||||
request_headers: [{}, {"If-Range": '"foo"'}],
|
||||
expected_validation_headers: [false, false],
|
||||
expected_no_cache_headers: [false, true],
|
||||
},
|
||||
{
|
||||
name: 'RequestCache "default" mode with an If-Range header is treated similarly to "no-store"',
|
||||
state: "stale",
|
||||
request_cache: ["default", "default"],
|
||||
request_headers: [{"If-Range": '"foo"'}, {}],
|
||||
expected_validation_headers: [false, false],
|
||||
expected_no_cache_headers: [true, false],
|
||||
},
|
||||
{
|
||||
name: 'RequestCache "default" mode with an If-Range header is treated similarly to "no-store"',
|
||||
state: "fresh",
|
||||
request_cache: ["default", "default"],
|
||||
request_headers: [{"If-Range": '"foo"'}, {}],
|
||||
expected_validation_headers: [false, false],
|
||||
expected_no_cache_headers: [true, false],
|
||||
},
|
||||
];
|
||||
run_tests(tests);
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,39 @@
|
|||
// META: global=window,worker
|
||||
// META: title=Request cache - default
|
||||
// META: script=/common/utils.js
|
||||
// META: script=/common/get-host-info.sub.js
|
||||
// META: script=request-cache.js
|
||||
|
||||
var tests = [
|
||||
{
|
||||
name: 'RequestCache "default" mode checks the cache for previously cached content and goes to the network for stale responses',
|
||||
state: "stale",
|
||||
request_cache: ["default", "default"],
|
||||
expected_validation_headers: [false, true],
|
||||
expected_no_cache_headers: [false, false],
|
||||
},
|
||||
{
|
||||
name: 'RequestCache "default" mode checks the cache for previously cached content and avoids going to the network if a fresh response exists',
|
||||
state: "fresh",
|
||||
request_cache: ["default", "default"],
|
||||
expected_validation_headers: [false],
|
||||
expected_no_cache_headers: [false],
|
||||
},
|
||||
{
|
||||
name: 'Responses with the "Cache-Control: no-store" header are not stored in the cache',
|
||||
state: "stale",
|
||||
cache_control: "no-store",
|
||||
request_cache: ["default", "default"],
|
||||
expected_validation_headers: [false, false],
|
||||
expected_no_cache_headers: [false, false],
|
||||
},
|
||||
{
|
||||
name: 'Responses with the "Cache-Control: no-store" header are not stored in the cache',
|
||||
state: "fresh",
|
||||
cache_control: "no-store",
|
||||
request_cache: ["default", "default"],
|
||||
expected_validation_headers: [false, false],
|
||||
expected_no_cache_headers: [false, false],
|
||||
},
|
||||
];
|
||||
run_tests(tests);
|
|
@ -1,50 +0,0 @@
|
|||
<!doctype html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>Request cache - default</title>
|
||||
<meta name="help" href="https://fetch.spec.whatwg.org/#request">
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
<script src="/common/utils.js"></script>
|
||||
<script src="/common/get-host-info.sub.js"></script>
|
||||
<script src="request-cache.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
<script>
|
||||
var tests = [
|
||||
{
|
||||
name: 'RequestCache "default" mode checks the cache for previously cached content and goes to the network for stale responses',
|
||||
state: "stale",
|
||||
request_cache: ["default", "default"],
|
||||
expected_validation_headers: [false, true],
|
||||
expected_no_cache_headers: [false, false],
|
||||
},
|
||||
{
|
||||
name: 'RequestCache "default" mode checks the cache for previously cached content and avoids going to the network if a fresh response exists',
|
||||
state: "fresh",
|
||||
request_cache: ["default", "default"],
|
||||
expected_validation_headers: [false],
|
||||
expected_no_cache_headers: [false],
|
||||
},
|
||||
{
|
||||
name: 'Responses with the "Cache-Control: no-store" header are not stored in the cache',
|
||||
state: "stale",
|
||||
cache_control: "no-store",
|
||||
request_cache: ["default", "default"],
|
||||
expected_validation_headers: [false, false],
|
||||
expected_no_cache_headers: [false, false],
|
||||
},
|
||||
{
|
||||
name: 'Responses with the "Cache-Control: no-store" header are not stored in the cache',
|
||||
state: "fresh",
|
||||
cache_control: "no-store",
|
||||
request_cache: ["default", "default"],
|
||||
expected_validation_headers: [false, false],
|
||||
expected_no_cache_headers: [false, false],
|
||||
},
|
||||
];
|
||||
run_tests(tests);
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,67 @@
|
|||
// META: global=window,worker
|
||||
// META: title=Request cache - force-cache
|
||||
// META: script=/common/utils.js
|
||||
// META: script=/common/get-host-info.sub.js
|
||||
// META: script=request-cache.js
|
||||
|
||||
var tests = [
|
||||
{
|
||||
name: 'RequestCache "force-cache" mode checks the cache for previously cached content and avoid revalidation for stale responses',
|
||||
state: "stale",
|
||||
request_cache: ["default", "force-cache"],
|
||||
expected_validation_headers: [false],
|
||||
expected_no_cache_headers: [false],
|
||||
},
|
||||
{
|
||||
name: 'RequestCache "force-cache" mode checks the cache for previously cached content and avoid revalidation for fresh responses',
|
||||
state: "fresh",
|
||||
request_cache: ["default", "force-cache"],
|
||||
expected_validation_headers: [false],
|
||||
expected_no_cache_headers: [false],
|
||||
},
|
||||
{
|
||||
name: 'RequestCache "force-cache" mode checks the cache for previously cached content and goes to the network if a cached response is not found',
|
||||
state: "stale",
|
||||
request_cache: ["force-cache"],
|
||||
expected_validation_headers: [false],
|
||||
expected_no_cache_headers: [false],
|
||||
},
|
||||
{
|
||||
name: 'RequestCache "force-cache" mode checks the cache for previously cached content and goes to the network if a cached response is not found',
|
||||
state: "fresh",
|
||||
request_cache: ["force-cache"],
|
||||
expected_validation_headers: [false],
|
||||
expected_no_cache_headers: [false],
|
||||
},
|
||||
{
|
||||
name: 'RequestCache "force-cache" mode checks the cache for previously cached content and goes to the network if a cached response would vary',
|
||||
state: "stale",
|
||||
vary: "*",
|
||||
request_cache: ["default", "force-cache"],
|
||||
expected_validation_headers: [false, true],
|
||||
expected_no_cache_headers: [false, false],
|
||||
},
|
||||
{
|
||||
name: 'RequestCache "force-cache" mode checks the cache for previously cached content and goes to the network if a cached response would vary',
|
||||
state: "fresh",
|
||||
vary: "*",
|
||||
request_cache: ["default", "force-cache"],
|
||||
expected_validation_headers: [false, true],
|
||||
expected_no_cache_headers: [false, false],
|
||||
},
|
||||
{
|
||||
name: 'RequestCache "force-cache" stores the response in the cache if it goes to the network',
|
||||
state: "stale",
|
||||
request_cache: ["force-cache", "default"],
|
||||
expected_validation_headers: [false, true],
|
||||
expected_no_cache_headers: [false, false],
|
||||
},
|
||||
{
|
||||
name: 'RequestCache "force-cache" stores the response in the cache if it goes to the network',
|
||||
state: "fresh",
|
||||
request_cache: ["force-cache", "default"],
|
||||
expected_validation_headers: [false],
|
||||
expected_no_cache_headers: [false],
|
||||
},
|
||||
];
|
||||
run_tests(tests);
|
|
@ -1,78 +0,0 @@
|
|||
<!doctype html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>Request cache - force-cache</title>
|
||||
<meta name="help" href="https://fetch.spec.whatwg.org/#request">
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
<script src="/common/utils.js"></script>
|
||||
<script src="/common/get-host-info.sub.js"></script>
|
||||
<script src="request-cache.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
<script>
|
||||
var tests = [
|
||||
{
|
||||
name: 'RequestCache "force-cache" mode checks the cache for previously cached content and avoid revalidation for stale responses',
|
||||
state: "stale",
|
||||
request_cache: ["default", "force-cache"],
|
||||
expected_validation_headers: [false],
|
||||
expected_no_cache_headers: [false],
|
||||
},
|
||||
{
|
||||
name: 'RequestCache "force-cache" mode checks the cache for previously cached content and avoid revalidation for fresh responses',
|
||||
state: "fresh",
|
||||
request_cache: ["default", "force-cache"],
|
||||
expected_validation_headers: [false],
|
||||
expected_no_cache_headers: [false],
|
||||
},
|
||||
{
|
||||
name: 'RequestCache "force-cache" mode checks the cache for previously cached content and goes to the network if a cached response is not found',
|
||||
state: "stale",
|
||||
request_cache: ["force-cache"],
|
||||
expected_validation_headers: [false],
|
||||
expected_no_cache_headers: [false],
|
||||
},
|
||||
{
|
||||
name: 'RequestCache "force-cache" mode checks the cache for previously cached content and goes to the network if a cached response is not found',
|
||||
state: "fresh",
|
||||
request_cache: ["force-cache"],
|
||||
expected_validation_headers: [false],
|
||||
expected_no_cache_headers: [false],
|
||||
},
|
||||
{
|
||||
name: 'RequestCache "force-cache" mode checks the cache for previously cached content and goes to the network if a cached response would vary',
|
||||
state: "stale",
|
||||
vary: "*",
|
||||
request_cache: ["default", "force-cache"],
|
||||
expected_validation_headers: [false, true],
|
||||
expected_no_cache_headers: [false, false],
|
||||
},
|
||||
{
|
||||
name: 'RequestCache "force-cache" mode checks the cache for previously cached content and goes to the network if a cached response would vary',
|
||||
state: "fresh",
|
||||
vary: "*",
|
||||
request_cache: ["default", "force-cache"],
|
||||
expected_validation_headers: [false, true],
|
||||
expected_no_cache_headers: [false, false],
|
||||
},
|
||||
{
|
||||
name: 'RequestCache "force-cache" stores the response in the cache if it goes to the network',
|
||||
state: "stale",
|
||||
request_cache: ["force-cache", "default"],
|
||||
expected_validation_headers: [false, true],
|
||||
expected_no_cache_headers: [false, false],
|
||||
},
|
||||
{
|
||||
name: 'RequestCache "force-cache" stores the response in the cache if it goes to the network',
|
||||
state: "fresh",
|
||||
request_cache: ["force-cache", "default"],
|
||||
expected_validation_headers: [false],
|
||||
expected_no_cache_headers: [false],
|
||||
},
|
||||
];
|
||||
run_tests(tests);
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,25 @@
|
|||
// META: global=window,worker
|
||||
// META: title=Request cache : no-cache
|
||||
// META: script=/common/utils.js
|
||||
// META: script=/common/get-host-info.sub.js
|
||||
// META: script=request-cache.js
|
||||
|
||||
var tests = [
|
||||
{
|
||||
name: 'RequestCache "no-cache" mode revalidates stale responses found in the cache',
|
||||
state: "stale",
|
||||
request_cache: ["default", "no-cache"],
|
||||
expected_validation_headers: [false, true],
|
||||
expected_no_cache_headers: [false, false],
|
||||
expected_max_age_headers: [false, true],
|
||||
},
|
||||
{
|
||||
name: 'RequestCache "no-cache" mode revalidates fresh responses found in the cache',
|
||||
state: "fresh",
|
||||
request_cache: ["default", "no-cache"],
|
||||
expected_validation_headers: [false, true],
|
||||
expected_no_cache_headers: [false, false],
|
||||
expected_max_age_headers: [false, true],
|
||||
},
|
||||
];
|
||||
run_tests(tests);
|
|
@ -1,36 +0,0 @@
|
|||
<!doctype html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>Request cache : no-cache</title>
|
||||
<meta name="help" href="https://fetch.spec.whatwg.org/#request">
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
<script src="/common/utils.js"></script>
|
||||
<script src="/common/get-host-info.sub.js"></script>
|
||||
<script src="request-cache.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
<script>
|
||||
var tests = [
|
||||
{
|
||||
name: 'RequestCache "no-cache" mode revalidates stale responses found in the cache',
|
||||
state: "stale",
|
||||
request_cache: ["default", "no-cache"],
|
||||
expected_validation_headers: [false, true],
|
||||
expected_no_cache_headers: [false, false],
|
||||
expected_max_age_headers: [false, true],
|
||||
},
|
||||
{
|
||||
name: 'RequestCache "no-cache" mode revalidates fresh responses found in the cache',
|
||||
state: "fresh",
|
||||
request_cache: ["default", "no-cache"],
|
||||
expected_validation_headers: [false, true],
|
||||
expected_no_cache_headers: [false, false],
|
||||
expected_max_age_headers: [false, true],
|
||||
},
|
||||
];
|
||||
run_tests(tests);
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,37 @@
|
|||
// META: global=window,worker
|
||||
// META: title=Request cache - no store
|
||||
// META: script=/common/utils.js
|
||||
// META: script=/common/get-host-info.sub.js
|
||||
// META: script=request-cache.js
|
||||
|
||||
var tests = [
|
||||
{
|
||||
name: 'RequestCache "no-store" mode does not check the cache for previously cached content and goes to the network regardless',
|
||||
state: "stale",
|
||||
request_cache: ["default", "no-store"],
|
||||
expected_validation_headers: [false, false],
|
||||
expected_no_cache_headers: [false, true],
|
||||
},
|
||||
{
|
||||
name: 'RequestCache "no-store" mode does not check the cache for previously cached content and goes to the network regardless',
|
||||
state: "fresh",
|
||||
request_cache: ["default", "no-store"],
|
||||
expected_validation_headers: [false, false],
|
||||
expected_no_cache_headers: [false, true],
|
||||
},
|
||||
{
|
||||
name: 'RequestCache "no-store" mode does not store the response in the cache',
|
||||
state: "stale",
|
||||
request_cache: ["no-store", "default"],
|
||||
expected_validation_headers: [false, false],
|
||||
expected_no_cache_headers: [true, false],
|
||||
},
|
||||
{
|
||||
name: 'RequestCache "no-store" mode does not store the response in the cache',
|
||||
state: "fresh",
|
||||
request_cache: ["no-store", "default"],
|
||||
expected_validation_headers: [false, false],
|
||||
expected_no_cache_headers: [true, false],
|
||||
},
|
||||
];
|
||||
run_tests(tests);
|
|
@ -1,48 +0,0 @@
|
|||
<!doctype html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>Request cache - no store</title>
|
||||
<meta name="help" href="https://fetch.spec.whatwg.org/#request">
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
<script src="/common/utils.js"></script>
|
||||
<script src="/common/get-host-info.sub.js"></script>
|
||||
<script src="request-cache.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
<script>
|
||||
var tests = [
|
||||
{
|
||||
name: 'RequestCache "no-store" mode does not check the cache for previously cached content and goes to the network regardless',
|
||||
state: "stale",
|
||||
request_cache: ["default", "no-store"],
|
||||
expected_validation_headers: [false, false],
|
||||
expected_no_cache_headers: [false, true],
|
||||
},
|
||||
{
|
||||
name: 'RequestCache "no-store" mode does not check the cache for previously cached content and goes to the network regardless',
|
||||
state: "fresh",
|
||||
request_cache: ["default", "no-store"],
|
||||
expected_validation_headers: [false, false],
|
||||
expected_no_cache_headers: [false, true],
|
||||
},
|
||||
{
|
||||
name: 'RequestCache "no-store" mode does not store the response in the cache',
|
||||
state: "stale",
|
||||
request_cache: ["no-store", "default"],
|
||||
expected_validation_headers: [false, false],
|
||||
expected_no_cache_headers: [true, false],
|
||||
},
|
||||
{
|
||||
name: 'RequestCache "no-store" mode does not store the response in the cache',
|
||||
state: "fresh",
|
||||
request_cache: ["no-store", "default"],
|
||||
expected_validation_headers: [false, false],
|
||||
expected_no_cache_headers: [true, false],
|
||||
},
|
||||
];
|
||||
run_tests(tests);
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,66 @@
|
|||
// META: global=window,dedicatedworker,sharedworker
|
||||
// META: title=Request cache - only-if-cached
|
||||
// META: script=/common/utils.js
|
||||
// META: script=/common/get-host-info.sub.js
|
||||
// META: script=request-cache.js
|
||||
|
||||
// FIXME: avoid mixed content requests to enable service worker global
|
||||
var tests = [
|
||||
{
|
||||
name: 'RequestCache "only-if-cached" mode checks the cache for previously cached content and avoids revalidation for stale responses',
|
||||
state: "stale",
|
||||
request_cache: ["default", "only-if-cached"],
|
||||
expected_validation_headers: [false],
|
||||
expected_no_cache_headers: [false]
|
||||
},
|
||||
{
|
||||
name: 'RequestCache "only-if-cached" mode checks the cache for previously cached content and avoids revalidation for fresh responses',
|
||||
state: "fresh",
|
||||
request_cache: ["default", "only-if-cached"],
|
||||
expected_validation_headers: [false],
|
||||
expected_no_cache_headers: [false]
|
||||
},
|
||||
{
|
||||
name: 'RequestCache "only-if-cached" mode checks the cache for previously cached content and does not go to the network if a cached response is not found',
|
||||
state: "fresh",
|
||||
request_cache: ["only-if-cached"],
|
||||
response: ["error"],
|
||||
expected_validation_headers: [],
|
||||
expected_no_cache_headers: []
|
||||
},
|
||||
{
|
||||
name: 'RequestCache "only-if-cached" (with "same-origin") uses cached same-origin redirects to same-origin content',
|
||||
state: "fresh",
|
||||
request_cache: ["default", "only-if-cached"],
|
||||
redirect: "same-origin",
|
||||
expected_validation_headers: [false, false],
|
||||
expected_no_cache_headers: [false, false],
|
||||
},
|
||||
{
|
||||
name: 'RequestCache "only-if-cached" (with "same-origin") uses cached same-origin redirects to same-origin content',
|
||||
state: "stale",
|
||||
request_cache: ["default", "only-if-cached"],
|
||||
redirect: "same-origin",
|
||||
expected_validation_headers: [false, false],
|
||||
expected_no_cache_headers: [false, false],
|
||||
},
|
||||
{
|
||||
name: 'RequestCache "only-if-cached" (with "same-origin") does not follow redirects across origins and rejects',
|
||||
state: "fresh",
|
||||
request_cache: ["default", "only-if-cached"],
|
||||
redirect: "cross-origin",
|
||||
response: [null, "error"],
|
||||
expected_validation_headers: [false, false],
|
||||
expected_no_cache_headers: [false, false],
|
||||
},
|
||||
{
|
||||
name: 'RequestCache "only-if-cached" (with "same-origin") does not follow redirects across origins and rejects',
|
||||
state: "stale",
|
||||
request_cache: ["default", "only-if-cached"],
|
||||
redirect: "cross-origin",
|
||||
response: [null, "error"],
|
||||
expected_validation_headers: [false, false],
|
||||
expected_no_cache_headers: [false, false],
|
||||
},
|
||||
];
|
||||
run_tests(tests);
|
|
@ -1,76 +0,0 @@
|
|||
<!doctype html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>Request cache - only-if-cached</title>
|
||||
<meta name="help" href="https://fetch.spec.whatwg.org/#request">
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
<script src="/common/utils.js"></script>
|
||||
<script src="/common/get-host-info.sub.js"></script>
|
||||
<script src="request-cache.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
<script>
|
||||
var tests = [
|
||||
{
|
||||
name: 'RequestCache "only-if-cached" mode checks the cache for previously cached content and avoids revalidation for stale responses',
|
||||
state: "stale",
|
||||
request_cache: ["default", "only-if-cached"],
|
||||
expected_validation_headers: [false],
|
||||
expected_no_cache_headers: [false]
|
||||
},
|
||||
{
|
||||
name: 'RequestCache "only-if-cached" mode checks the cache for previously cached content and avoids revalidation for fresh responses',
|
||||
state: "fresh",
|
||||
request_cache: ["default", "only-if-cached"],
|
||||
expected_validation_headers: [false],
|
||||
expected_no_cache_headers: [false]
|
||||
},
|
||||
{
|
||||
name: 'RequestCache "only-if-cached" mode checks the cache for previously cached content and does not go to the network if a cached response is not found',
|
||||
state: "fresh",
|
||||
request_cache: ["only-if-cached"],
|
||||
response: ["error"],
|
||||
expected_validation_headers: [],
|
||||
expected_no_cache_headers: []
|
||||
},
|
||||
{
|
||||
name: 'RequestCache "only-if-cached" (with "same-origin") uses cached same-origin redirects to same-origin content',
|
||||
state: "fresh",
|
||||
request_cache: ["default", "only-if-cached"],
|
||||
redirect: "same-origin",
|
||||
expected_validation_headers: [false, false],
|
||||
expected_no_cache_headers: [false, false],
|
||||
},
|
||||
{
|
||||
name: 'RequestCache "only-if-cached" (with "same-origin") uses cached same-origin redirects to same-origin content',
|
||||
state: "stale",
|
||||
request_cache: ["default", "only-if-cached"],
|
||||
redirect: "same-origin",
|
||||
expected_validation_headers: [false, false],
|
||||
expected_no_cache_headers: [false, false],
|
||||
},
|
||||
{
|
||||
name: 'RequestCache "only-if-cached" (with "same-origin") does not follow redirects across origins and rejects',
|
||||
state: "fresh",
|
||||
request_cache: ["default", "only-if-cached"],
|
||||
redirect: "cross-origin",
|
||||
response: [null, "error"],
|
||||
expected_validation_headers: [false, false],
|
||||
expected_no_cache_headers: [false, false],
|
||||
},
|
||||
{
|
||||
name: 'RequestCache "only-if-cached" (with "same-origin") does not follow redirects across origins and rejects',
|
||||
state: "stale",
|
||||
request_cache: ["default", "only-if-cached"],
|
||||
redirect: "cross-origin",
|
||||
response: [null, "error"],
|
||||
expected_validation_headers: [false, false],
|
||||
expected_no_cache_headers: [false, false],
|
||||
},
|
||||
];
|
||||
run_tests(tests);
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,51 @@
|
|||
// META: global=window,worker
|
||||
// META: title=Request cache - reload
|
||||
// META: script=/common/utils.js
|
||||
// META: script=/common/get-host-info.sub.js
|
||||
// META: script=request-cache.js
|
||||
|
||||
var tests = [
|
||||
{
|
||||
name: 'RequestCache "reload" mode does not check the cache for previously cached content and goes to the network regardless',
|
||||
state: "stale",
|
||||
request_cache: ["default", "reload"],
|
||||
expected_validation_headers: [false, false],
|
||||
expected_no_cache_headers: [false, true],
|
||||
},
|
||||
{
|
||||
name: 'RequestCache "reload" mode does not check the cache for previously cached content and goes to the network regardless',
|
||||
state: "fresh",
|
||||
request_cache: ["default", "reload"],
|
||||
expected_validation_headers: [false, false],
|
||||
expected_no_cache_headers: [false, true],
|
||||
},
|
||||
{
|
||||
name: 'RequestCache "reload" mode does store the response in the cache',
|
||||
state: "stale",
|
||||
request_cache: ["reload", "default"],
|
||||
expected_validation_headers: [false, true],
|
||||
expected_no_cache_headers: [true, false],
|
||||
},
|
||||
{
|
||||
name: 'RequestCache "reload" mode does store the response in the cache',
|
||||
state: "fresh",
|
||||
request_cache: ["reload", "default"],
|
||||
expected_validation_headers: [false],
|
||||
expected_no_cache_headers: [true],
|
||||
},
|
||||
{
|
||||
name: 'RequestCache "reload" mode does store the response in the cache even if a previous response is already stored',
|
||||
state: "stale",
|
||||
request_cache: ["default", "reload", "default"],
|
||||
expected_validation_headers: [false, false, true],
|
||||
expected_no_cache_headers: [false, true, false],
|
||||
},
|
||||
{
|
||||
name: 'RequestCache "reload" mode does store the response in the cache even if a previous response is already stored',
|
||||
state: "fresh",
|
||||
request_cache: ["default", "reload", "default"],
|
||||
expected_validation_headers: [false, false],
|
||||
expected_no_cache_headers: [false, true],
|
||||
},
|
||||
];
|
||||
run_tests(tests);
|
|
@ -1,62 +0,0 @@
|
|||
<!doctype html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>Request cache - reload</title>
|
||||
<meta name="help" href="https://fetch.spec.whatwg.org/#request">
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
<script src="/common/utils.js"></script>
|
||||
<script src="/common/get-host-info.sub.js"></script>
|
||||
<script src="request-cache.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
<script>
|
||||
var tests = [
|
||||
{
|
||||
name: 'RequestCache "reload" mode does not check the cache for previously cached content and goes to the network regardless',
|
||||
state: "stale",
|
||||
request_cache: ["default", "reload"],
|
||||
expected_validation_headers: [false, false],
|
||||
expected_no_cache_headers: [false, true],
|
||||
},
|
||||
{
|
||||
name: 'RequestCache "reload" mode does not check the cache for previously cached content and goes to the network regardless',
|
||||
state: "fresh",
|
||||
request_cache: ["default", "reload"],
|
||||
expected_validation_headers: [false, false],
|
||||
expected_no_cache_headers: [false, true],
|
||||
},
|
||||
{
|
||||
name: 'RequestCache "reload" mode does store the response in the cache',
|
||||
state: "stale",
|
||||
request_cache: ["reload", "default"],
|
||||
expected_validation_headers: [false, true],
|
||||
expected_no_cache_headers: [true, false],
|
||||
},
|
||||
{
|
||||
name: 'RequestCache "reload" mode does store the response in the cache',
|
||||
state: "fresh",
|
||||
request_cache: ["reload", "default"],
|
||||
expected_validation_headers: [false],
|
||||
expected_no_cache_headers: [true],
|
||||
},
|
||||
{
|
||||
name: 'RequestCache "reload" mode does store the response in the cache even if a previous response is already stored',
|
||||
state: "stale",
|
||||
request_cache: ["default", "reload", "default"],
|
||||
expected_validation_headers: [false, false, true],
|
||||
expected_no_cache_headers: [false, true, false],
|
||||
},
|
||||
{
|
||||
name: 'RequestCache "reload" mode does store the response in the cache even if a previous response is already stored',
|
||||
state: "fresh",
|
||||
request_cache: ["default", "reload", "default"],
|
||||
expected_validation_headers: [false, false],
|
||||
expected_no_cache_headers: [false, true],
|
||||
},
|
||||
];
|
||||
run_tests(tests);
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,101 @@
|
|||
// META: global=window,worker
|
||||
// META: title=Request consume empty bodies
|
||||
|
||||
function checkBodyText(test, request) {
|
||||
return request.text().then(function(bodyAsText) {
|
||||
assert_equals(bodyAsText, "", "Resolved value should be empty");
|
||||
assert_false(request.bodyUsed);
|
||||
});
|
||||
}
|
||||
|
||||
function checkBodyBlob(test, request) {
|
||||
return request.blob().then(function(bodyAsBlob) {
|
||||
var promise = new Promise(function(resolve, reject) {
|
||||
var reader = new FileReader();
|
||||
reader.onload = function(evt) {
|
||||
resolve(reader.result)
|
||||
};
|
||||
reader.onerror = function() {
|
||||
reject("Blob's reader failed");
|
||||
};
|
||||
reader.readAsText(bodyAsBlob);
|
||||
});
|
||||
return promise.then(function(body) {
|
||||
assert_equals(body, "", "Resolved value should be empty");
|
||||
assert_false(request.bodyUsed);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function checkBodyArrayBuffer(test, request) {
|
||||
return request.arrayBuffer().then(function(bodyAsArrayBuffer) {
|
||||
assert_equals(bodyAsArrayBuffer.byteLength, 0, "Resolved value should be empty");
|
||||
assert_false(request.bodyUsed);
|
||||
});
|
||||
}
|
||||
|
||||
function checkBodyJSON(test, request) {
|
||||
return request.json().then(
|
||||
function(bodyAsJSON) {
|
||||
assert_unreached("JSON parsing should fail");
|
||||
},
|
||||
function() {
|
||||
assert_false(request.bodyUsed);
|
||||
});
|
||||
}
|
||||
|
||||
function checkBodyFormData(test, request) {
|
||||
return request.formData().then(function(bodyAsFormData) {
|
||||
assert_true(bodyAsFormData instanceof FormData, "Should receive a FormData");
|
||||
assert_false(request.bodyUsed);
|
||||
});
|
||||
}
|
||||
|
||||
function checkBodyFormDataError(test, request) {
|
||||
return promise_rejects_js(test, TypeError, request.formData()).then(function() {
|
||||
assert_false(request.bodyUsed);
|
||||
});
|
||||
}
|
||||
|
||||
function checkRequestWithNoBody(bodyType, checkFunction, headers = []) {
|
||||
promise_test(function(test) {
|
||||
var request = new Request("", {"method": "POST", "headers": headers});
|
||||
assert_false(request.bodyUsed);
|
||||
return checkFunction(test, request);
|
||||
}, "Consume request's body as " + bodyType);
|
||||
}
|
||||
|
||||
checkRequestWithNoBody("text", checkBodyText);
|
||||
checkRequestWithNoBody("blob", checkBodyBlob);
|
||||
checkRequestWithNoBody("arrayBuffer", checkBodyArrayBuffer);
|
||||
checkRequestWithNoBody("json (error case)", checkBodyJSON);
|
||||
checkRequestWithNoBody("formData with correct multipart type (error case)", checkBodyFormDataError, [["Content-Type", 'multipart/form-data; boundary="boundary"']]);
|
||||
checkRequestWithNoBody("formData with correct urlencoded type", checkBodyFormData, [["Content-Type", "application/x-www-form-urlencoded;charset=UTF-8"]]);
|
||||
checkRequestWithNoBody("formData without correct type (error case)", checkBodyFormDataError);
|
||||
|
||||
function checkRequestWithEmptyBody(bodyType, body, asText) {
|
||||
promise_test(function(test) {
|
||||
var request = new Request("", {"method": "POST", "body": body});
|
||||
assert_false(request.bodyUsed, "bodyUsed is false at init");
|
||||
if (asText) {
|
||||
return request.text().then(function(bodyAsString) {
|
||||
assert_equals(bodyAsString.length, 0, "Resolved value should be empty");
|
||||
assert_true(request.bodyUsed, "bodyUsed is true after being consumed");
|
||||
});
|
||||
}
|
||||
return request.arrayBuffer().then(function(bodyAsArrayBuffer) {
|
||||
assert_equals(bodyAsArrayBuffer.byteLength, 0, "Resolved value should be empty");
|
||||
assert_true(request.bodyUsed, "bodyUsed is true after being consumed");
|
||||
});
|
||||
}, "Consume empty " + bodyType + " request body as " + (asText ? "text" : "arrayBuffer"));
|
||||
}
|
||||
|
||||
// FIXME: Add BufferSource, FormData and URLSearchParams.
|
||||
checkRequestWithEmptyBody("blob", new Blob([], { "type" : "text/plain" }), false);
|
||||
checkRequestWithEmptyBody("text", "", false);
|
||||
checkRequestWithEmptyBody("blob", new Blob([], { "type" : "text/plain" }), true);
|
||||
checkRequestWithEmptyBody("text", "", true);
|
||||
checkRequestWithEmptyBody("URLSearchParams", new URLSearchParams(""), true);
|
||||
// FIXME: This test assumes that the empty string be returned but it is not clear whether that is right. See https://github.com/web-platform-tests/wpt/pull/3950.
|
||||
checkRequestWithEmptyBody("FormData", new FormData(), true);
|
||||
checkRequestWithEmptyBody("ArrayBuffer", new ArrayBuffer(), true);
|
|
@ -1,114 +0,0 @@
|
|||
<!doctype html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>Request consume empty bodies</title>
|
||||
<meta name="help" href="https://fetch.spec.whatwg.org/#request">
|
||||
<meta name="help" href="https://fetch.spec.whatwg.org/#body-mixin">
|
||||
<meta name="author" title="Canon Research France" href="https://www.crf.canon.fr">
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
<script>
|
||||
function checkBodyText(test, request) {
|
||||
return request.text().then(function(bodyAsText) {
|
||||
assert_equals(bodyAsText, "", "Resolved value should be empty");
|
||||
assert_false(request.bodyUsed);
|
||||
});
|
||||
}
|
||||
|
||||
function checkBodyBlob(test, request) {
|
||||
return request.blob().then(function(bodyAsBlob) {
|
||||
var promise = new Promise(function(resolve, reject) {
|
||||
var reader = new FileReader();
|
||||
reader.onload = function(evt) {
|
||||
resolve(reader.result)
|
||||
};
|
||||
reader.onerror = function() {
|
||||
reject("Blob's reader failed");
|
||||
};
|
||||
reader.readAsText(bodyAsBlob);
|
||||
});
|
||||
return promise.then(function(body) {
|
||||
assert_equals(body, "", "Resolved value should be empty");
|
||||
assert_false(request.bodyUsed);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function checkBodyArrayBuffer(test, request) {
|
||||
return request.arrayBuffer().then(function(bodyAsArrayBuffer) {
|
||||
assert_equals(bodyAsArrayBuffer.byteLength, 0, "Resolved value should be empty");
|
||||
assert_false(request.bodyUsed);
|
||||
});
|
||||
}
|
||||
|
||||
function checkBodyJSON(test, request) {
|
||||
return request.json().then(
|
||||
function(bodyAsJSON) {
|
||||
assert_unreached("JSON parsing should fail");
|
||||
},
|
||||
function() {
|
||||
assert_false(request.bodyUsed);
|
||||
});
|
||||
}
|
||||
|
||||
function checkBodyFormData(test, request) {
|
||||
return request.formData().then(function(bodyAsFormData) {
|
||||
assert_true(bodyAsFormData instanceof FormData, "Should receive a FormData");
|
||||
assert_false(request.bodyUsed);
|
||||
});
|
||||
}
|
||||
|
||||
function checkBodyFormDataError(test, request) {
|
||||
return promise_rejects_js(test, TypeError, request.formData()).then(function() {
|
||||
assert_false(request.bodyUsed);
|
||||
});
|
||||
}
|
||||
|
||||
function checkRequestWithNoBody(bodyType, checkFunction, headers = []) {
|
||||
promise_test(function(test) {
|
||||
var request = new Request("", {"method": "POST", "headers": headers});
|
||||
assert_false(request.bodyUsed);
|
||||
return checkFunction(test, request);
|
||||
}, "Consume request's body as " + bodyType);
|
||||
}
|
||||
|
||||
checkRequestWithNoBody("text", checkBodyText);
|
||||
checkRequestWithNoBody("blob", checkBodyBlob);
|
||||
checkRequestWithNoBody("arrayBuffer", checkBodyArrayBuffer);
|
||||
checkRequestWithNoBody("json (error case)", checkBodyJSON);
|
||||
checkRequestWithNoBody("formData with correct multipart type (error case)", checkBodyFormDataError, [["Content-Type", 'multipart/form-data; boundary="boundary"']]);
|
||||
checkRequestWithNoBody("formData with correct urlencoded type", checkBodyFormData, [["Content-Type", "application/x-www-form-urlencoded;charset=UTF-8"]]);
|
||||
checkRequestWithNoBody("formData without correct type (error case)", checkBodyFormDataError);
|
||||
|
||||
function checkRequestWithEmptyBody(bodyType, body, asText) {
|
||||
promise_test(function(test) {
|
||||
var request = new Request("", {"method": "POST", "body": body});
|
||||
assert_false(request.bodyUsed, "bodyUsed is false at init");
|
||||
if (asText) {
|
||||
return request.text().then(function(bodyAsString) {
|
||||
assert_equals(bodyAsString.length, 0, "Resolved value should be empty");
|
||||
assert_true(request.bodyUsed, "bodyUsed is true after being consumed");
|
||||
});
|
||||
}
|
||||
return request.arrayBuffer().then(function(bodyAsArrayBuffer) {
|
||||
assert_equals(bodyAsArrayBuffer.byteLength, 0, "Resolved value should be empty");
|
||||
assert_true(request.bodyUsed, "bodyUsed is true after being consumed");
|
||||
});
|
||||
}, "Consume empty " + bodyType + " request body as " + (asText ? "text" : "arrayBuffer"));
|
||||
}
|
||||
|
||||
// FIXME: Add BufferSource, FormData and URLSearchParams.
|
||||
checkRequestWithEmptyBody("blob", new Blob([], { "type" : "text/plain" }), false);
|
||||
checkRequestWithEmptyBody("text", "", false);
|
||||
checkRequestWithEmptyBody("blob", new Blob([], { "type" : "text/plain" }), true);
|
||||
checkRequestWithEmptyBody("text", "", true);
|
||||
checkRequestWithEmptyBody("URLSearchParams", new URLSearchParams(""), true);
|
||||
// FIXME: This test assumes that the empty string be returned but it is not clear whether that is right. See https://github.com/web-platform-tests/wpt/pull/3950.
|
||||
checkRequestWithEmptyBody("FormData", new FormData(), true);
|
||||
checkRequestWithEmptyBody("ArrayBuffer", new ArrayBuffer(), true);
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,145 @@
|
|||
// META: global=window,worker
|
||||
// META: title=Request consume
|
||||
// META: script=../resources/utils.js
|
||||
|
||||
function checkBodyText(request, expectedBody) {
|
||||
return request.text().then(function(bodyAsText) {
|
||||
assert_equals(bodyAsText, expectedBody, "Retrieve and verify request's body");
|
||||
assert_true(request.bodyUsed, "body as text: bodyUsed turned true");
|
||||
});
|
||||
}
|
||||
|
||||
function checkBodyBlob(request, expectedBody, checkContentType) {
|
||||
return request.blob().then(function(bodyAsBlob) {
|
||||
if (checkContentType)
|
||||
assert_equals(bodyAsBlob.type, "text/plain", "Blob body type should be computed from the request Content-Type");
|
||||
|
||||
var promise = new Promise(function (resolve, reject) {
|
||||
var reader = new FileReader();
|
||||
reader.onload = function(evt) {
|
||||
resolve(reader.result)
|
||||
};
|
||||
reader.onerror = function() {
|
||||
reject("Blob's reader failed");
|
||||
};
|
||||
reader.readAsText(bodyAsBlob);
|
||||
});
|
||||
return promise.then(function(body) {
|
||||
assert_equals(body, expectedBody, "Retrieve and verify request's body");
|
||||
assert_true(request.bodyUsed, "body as blob: bodyUsed turned true");
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function checkBodyArrayBuffer(request, expectedBody) {
|
||||
return request.arrayBuffer().then(function(bodyAsArrayBuffer) {
|
||||
validateBufferFromString(bodyAsArrayBuffer, expectedBody, "Retrieve and verify request's body");
|
||||
assert_true(request.bodyUsed, "body as arrayBuffer: bodyUsed turned true");
|
||||
});
|
||||
}
|
||||
|
||||
function checkBodyJSON(request, expectedBody) {
|
||||
return request.json().then(function(bodyAsJSON) {
|
||||
var strBody = JSON.stringify(bodyAsJSON)
|
||||
assert_equals(strBody, expectedBody, "Retrieve and verify request's body");
|
||||
assert_true(request.bodyUsed, "body as json: bodyUsed turned true");
|
||||
});
|
||||
}
|
||||
|
||||
function checkBodyFormData(request, expectedBody) {
|
||||
return request.formData().then(function(bodyAsFormData) {
|
||||
assert_true(bodyAsFormData instanceof FormData, "Should receive a FormData");
|
||||
assert_true(request.bodyUsed, "body as formData: bodyUsed turned true");
|
||||
});
|
||||
}
|
||||
|
||||
function checkRequestBody(body, expected, bodyType) {
|
||||
promise_test(function(test) {
|
||||
var request = new Request("", {"method": "POST", "body": body, "headers": [["Content-Type", "text/PLAIN"]] });
|
||||
assert_false(request.bodyUsed, "bodyUsed is false at init");
|
||||
return checkBodyText(request, expected);
|
||||
}, "Consume " + bodyType + " request's body as text");
|
||||
promise_test(function(test) {
|
||||
var request = new Request("", {"method": "POST", "body": body });
|
||||
assert_false(request.bodyUsed, "bodyUsed is false at init");
|
||||
return checkBodyBlob(request, expected);
|
||||
}, "Consume " + bodyType + " request's body as blob");
|
||||
promise_test(function(test) {
|
||||
var request = new Request("", {"method": "POST", "body": body });
|
||||
assert_false(request.bodyUsed, "bodyUsed is false at init");
|
||||
return checkBodyArrayBuffer(request, expected);
|
||||
}, "Consume " + bodyType + " request's body as arrayBuffer");
|
||||
promise_test(function(test) {
|
||||
var request = new Request("", {"method": "POST", "body": body });
|
||||
assert_false(request.bodyUsed, "bodyUsed is false at init");
|
||||
return checkBodyJSON(request, expected);
|
||||
}, "Consume " + bodyType + " request's body as JSON");
|
||||
}
|
||||
|
||||
var textData = JSON.stringify("This is response's body");
|
||||
var blob = new Blob([textData], { "type" : "text/plain" });
|
||||
|
||||
checkRequestBody(textData, textData, "String");
|
||||
|
||||
var string = "\"123456\"";
|
||||
function getArrayBuffer() {
|
||||
var arrayBuffer = new ArrayBuffer(8);
|
||||
var int8Array = new Int8Array(arrayBuffer);
|
||||
for (var cptr = 0; cptr < 8; cptr++)
|
||||
int8Array[cptr] = string.charCodeAt(cptr);
|
||||
return arrayBuffer;
|
||||
}
|
||||
|
||||
function getArrayBufferWithZeros() {
|
||||
var arrayBuffer = new ArrayBuffer(10);
|
||||
var int8Array = new Int8Array(arrayBuffer);
|
||||
for (var cptr = 0; cptr < 8; cptr++)
|
||||
int8Array[cptr + 1] = string.charCodeAt(cptr);
|
||||
return arrayBuffer;
|
||||
}
|
||||
|
||||
checkRequestBody(getArrayBuffer(), string, "ArrayBuffer");
|
||||
checkRequestBody(new Uint8Array(getArrayBuffer()), string, "Uint8Array");
|
||||
checkRequestBody(new Int8Array(getArrayBufferWithZeros(), 1, 8), string, "Int8Array");
|
||||
checkRequestBody(new Float32Array(getArrayBuffer()), string, "Float32Array");
|
||||
checkRequestBody(new DataView(getArrayBufferWithZeros(), 1, 8), string, "DataView");
|
||||
|
||||
promise_test(function(test) {
|
||||
var formData = new FormData();
|
||||
formData.append("name", "value")
|
||||
var request = new Request("", {"method": "POST", "body": formData });
|
||||
assert_false(request.bodyUsed, "bodyUsed is false at init");
|
||||
return checkBodyFormData(request, formData);
|
||||
}, "Consume FormData request's body as FormData");
|
||||
|
||||
function checkBlobResponseBody(blobBody, blobData, bodyType, checkFunction) {
|
||||
promise_test(function(test) {
|
||||
var response = new Response(blobBody);
|
||||
assert_false(response.bodyUsed, "bodyUsed is false at init");
|
||||
return checkFunction(response, blobData);
|
||||
}, "Consume blob response's body as " + bodyType);
|
||||
}
|
||||
|
||||
checkBlobResponseBody(blob, textData, "blob", checkBodyBlob);
|
||||
checkBlobResponseBody(blob, textData, "text", checkBodyText);
|
||||
checkBlobResponseBody(blob, textData, "json", checkBodyJSON);
|
||||
checkBlobResponseBody(blob, textData, "arrayBuffer", checkBodyArrayBuffer);
|
||||
checkBlobResponseBody(new Blob([""]), "", "blob (empty blob as input)", checkBodyBlob);
|
||||
|
||||
var goodJSONValues = ["null", "1", "true", "\"string\""];
|
||||
goodJSONValues.forEach(function(value) {
|
||||
promise_test(function(test) {
|
||||
var request = new Request("", {"method": "POST", "body": value});
|
||||
return request.json().then(function(v) {
|
||||
assert_equals(v, JSON.parse(value));
|
||||
});
|
||||
}, "Consume JSON from text: '" + JSON.stringify(value) + "'");
|
||||
});
|
||||
|
||||
var badJSONValues = ["undefined", "{", "a", "["];
|
||||
badJSONValues.forEach(function(value) {
|
||||
promise_test(function(test) {
|
||||
var request = new Request("", {"method": "POST", "body": value});
|
||||
return promise_rejects_js(test, SyntaxError, request.json());
|
||||
}, "Trying to consume bad JSON text as JSON: '" + value + "'");
|
||||
});
|
|
@ -1,158 +0,0 @@
|
|||
<!doctype html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>Request consume</title>
|
||||
<meta name="help" href="https://fetch.spec.whatwg.org/#request">
|
||||
<meta name="help" href="https://fetch.spec.whatwg.org/#body-mixin">
|
||||
<meta name="author" title="Canon Research France" href="https://www.crf.canon.fr">
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
<script src="../resources/utils.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
<script>
|
||||
function checkBodyText(request, expectedBody) {
|
||||
return request.text().then(function(bodyAsText) {
|
||||
assert_equals(bodyAsText, expectedBody, "Retrieve and verify request's body");
|
||||
assert_true(request.bodyUsed, "body as text: bodyUsed turned true");
|
||||
});
|
||||
}
|
||||
|
||||
function checkBodyBlob(request, expectedBody, checkContentType) {
|
||||
return request.blob().then(function(bodyAsBlob) {
|
||||
if (checkContentType)
|
||||
assert_equals(bodyAsBlob.type, "text/plain", "Blob body type should be computed from the request Content-Type");
|
||||
|
||||
var promise = new Promise(function (resolve, reject) {
|
||||
var reader = new FileReader();
|
||||
reader.onload = function(evt) {
|
||||
resolve(reader.result)
|
||||
};
|
||||
reader.onerror = function() {
|
||||
reject("Blob's reader failed");
|
||||
};
|
||||
reader.readAsText(bodyAsBlob);
|
||||
});
|
||||
return promise.then(function(body) {
|
||||
assert_equals(body, expectedBody, "Retrieve and verify request's body");
|
||||
assert_true(request.bodyUsed, "body as blob: bodyUsed turned true");
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function checkBodyArrayBuffer(request, expectedBody) {
|
||||
return request.arrayBuffer().then(function(bodyAsArrayBuffer) {
|
||||
validateBufferFromString(bodyAsArrayBuffer, expectedBody, "Retrieve and verify request's body");
|
||||
assert_true(request.bodyUsed, "body as arrayBuffer: bodyUsed turned true");
|
||||
});
|
||||
}
|
||||
|
||||
function checkBodyJSON(request, expectedBody) {
|
||||
return request.json().then(function(bodyAsJSON) {
|
||||
var strBody = JSON.stringify(bodyAsJSON)
|
||||
assert_equals(strBody, expectedBody, "Retrieve and verify request's body");
|
||||
assert_true(request.bodyUsed, "body as json: bodyUsed turned true");
|
||||
});
|
||||
}
|
||||
|
||||
function checkBodyFormData(request, expectedBody) {
|
||||
return request.formData().then(function(bodyAsFormData) {
|
||||
assert_true(bodyAsFormData instanceof FormData, "Should receive a FormData");
|
||||
assert_true(request.bodyUsed, "body as formData: bodyUsed turned true");
|
||||
});
|
||||
}
|
||||
|
||||
function checkRequestBody(body, expected, bodyType) {
|
||||
promise_test(function(test) {
|
||||
var request = new Request("", {"method": "POST", "body": body, "headers": [["Content-Type", "text/PLAIN"]] });
|
||||
assert_false(request.bodyUsed, "bodyUsed is false at init");
|
||||
return checkBodyText(request, expected);
|
||||
}, "Consume " + bodyType + " request's body as text");
|
||||
promise_test(function(test) {
|
||||
var request = new Request("", {"method": "POST", "body": body });
|
||||
assert_false(request.bodyUsed, "bodyUsed is false at init");
|
||||
return checkBodyBlob(request, expected);
|
||||
}, "Consume " + bodyType + " request's body as blob");
|
||||
promise_test(function(test) {
|
||||
var request = new Request("", {"method": "POST", "body": body });
|
||||
assert_false(request.bodyUsed, "bodyUsed is false at init");
|
||||
return checkBodyArrayBuffer(request, expected);
|
||||
}, "Consume " + bodyType + " request's body as arrayBuffer");
|
||||
promise_test(function(test) {
|
||||
var request = new Request("", {"method": "POST", "body": body });
|
||||
assert_false(request.bodyUsed, "bodyUsed is false at init");
|
||||
return checkBodyJSON(request, expected);
|
||||
}, "Consume " + bodyType + " request's body as JSON");
|
||||
}
|
||||
|
||||
var textData = JSON.stringify("This is response's body");
|
||||
var blob = new Blob([textData], { "type" : "text/plain" });
|
||||
|
||||
checkRequestBody(textData, textData, "String");
|
||||
|
||||
var string = "\"123456\"";
|
||||
function getArrayBuffer() {
|
||||
var arrayBuffer = new ArrayBuffer(8);
|
||||
var int8Array = new Int8Array(arrayBuffer);
|
||||
for (var cptr = 0; cptr < 8; cptr++)
|
||||
int8Array[cptr] = string.charCodeAt(cptr);
|
||||
return arrayBuffer;
|
||||
}
|
||||
|
||||
function getArrayBufferWithZeros() {
|
||||
var arrayBuffer = new ArrayBuffer(10);
|
||||
var int8Array = new Int8Array(arrayBuffer);
|
||||
for (var cptr = 0; cptr < 8; cptr++)
|
||||
int8Array[cptr + 1] = string.charCodeAt(cptr);
|
||||
return arrayBuffer;
|
||||
}
|
||||
|
||||
checkRequestBody(getArrayBuffer(), string, "ArrayBuffer");
|
||||
checkRequestBody(new Uint8Array(getArrayBuffer()), string, "Uint8Array");
|
||||
checkRequestBody(new Int8Array(getArrayBufferWithZeros(), 1, 8), string, "Int8Array");
|
||||
checkRequestBody(new Float32Array(getArrayBuffer()), string, "Float32Array");
|
||||
checkRequestBody(new DataView(getArrayBufferWithZeros(), 1, 8), string, "DataView");
|
||||
|
||||
promise_test(function(test) {
|
||||
var formData = new FormData();
|
||||
formData.append("name", "value")
|
||||
var request = new Request("", {"method": "POST", "body": formData });
|
||||
assert_false(request.bodyUsed, "bodyUsed is false at init");
|
||||
return checkBodyFormData(request, formData);
|
||||
}, "Consume FormData request's body as FormData");
|
||||
|
||||
function checkBlobResponseBody(blobBody, blobData, bodyType, checkFunction) {
|
||||
promise_test(function(test) {
|
||||
var response = new Response(blobBody);
|
||||
assert_false(response.bodyUsed, "bodyUsed is false at init");
|
||||
return checkFunction(response, blobData);
|
||||
}, "Consume blob response's body as " + bodyType);
|
||||
}
|
||||
|
||||
checkBlobResponseBody(blob, textData, "blob", checkBodyBlob);
|
||||
checkBlobResponseBody(blob, textData, "text", checkBodyText);
|
||||
checkBlobResponseBody(blob, textData, "json", checkBodyJSON);
|
||||
checkBlobResponseBody(blob, textData, "arrayBuffer", checkBodyArrayBuffer);
|
||||
checkBlobResponseBody(new Blob([""]), "", "blob (empty blob as input)", checkBodyBlob);
|
||||
|
||||
var goodJSONValues = ["null", "1", "true", "\"string\""];
|
||||
goodJSONValues.forEach(function(value) {
|
||||
promise_test(function(test) {
|
||||
var request = new Request("", {"method": "POST", "body": value});
|
||||
return request.json().then(function(v) {
|
||||
assert_equals(v, JSON.parse(value));
|
||||
});
|
||||
}, "Consume JSON from text: '" + JSON.stringify(value) + "'");
|
||||
});
|
||||
|
||||
var badJSONValues = ["undefined", "{", "a", "["];
|
||||
badJSONValues.forEach(function(value) {
|
||||
promise_test(function(test) {
|
||||
var request = new Request("", {"method": "POST", "body": value});
|
||||
return promise_rejects_js(test, SyntaxError, request.json());
|
||||
}, "Trying to consume bad JSON text as JSON: '" + value + "'");
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,109 @@
|
|||
// META: global=window,worker
|
||||
// META: title=Request disturbed
|
||||
// META: script=../resources/utils.js
|
||||
|
||||
var initValuesDict = {"method" : "POST",
|
||||
"body" : "Request's body"
|
||||
};
|
||||
|
||||
var noBodyConsumed = new Request("");
|
||||
var bodyConsumed = new Request("", initValuesDict);
|
||||
|
||||
test(() => {
|
||||
assert_equals(noBodyConsumed.body, null, "body's default value is null");
|
||||
assert_false(noBodyConsumed.bodyUsed , "bodyUsed is false when request is not disturbed");
|
||||
assert_not_equals(bodyConsumed.body, null, "non-null body");
|
||||
assert_true(bodyConsumed.body instanceof ReadableStream, "non-null body type");
|
||||
assert_false(noBodyConsumed.bodyUsed, "bodyUsed is false when request is not disturbed");
|
||||
}, "Request's body: initial state");
|
||||
|
||||
noBodyConsumed.blob();
|
||||
bodyConsumed.blob();
|
||||
|
||||
test(function() {
|
||||
assert_false(noBodyConsumed.bodyUsed , "bodyUsed is false when request is not disturbed");
|
||||
try {
|
||||
noBodyConsumed.clone();
|
||||
} catch (e) {
|
||||
assert_unreached("Can use request not disturbed for creating or cloning request");
|
||||
}
|
||||
}, "Request without body cannot be disturbed");
|
||||
|
||||
test(function() {
|
||||
assert_true(bodyConsumed.bodyUsed , "bodyUsed is true when request is disturbed");
|
||||
assert_throws_js(TypeError, function() { bodyConsumed.clone(); });
|
||||
}, "Check cloning a disturbed request");
|
||||
|
||||
test(function() {
|
||||
assert_true(bodyConsumed.bodyUsed , "bodyUsed is true when request is disturbed");
|
||||
assert_throws_js(TypeError, function() { new Request(bodyConsumed); });
|
||||
}, "Check creating a new request from a disturbed request");
|
||||
|
||||
promise_test(function() {
|
||||
assert_true(bodyConsumed.bodyUsed , "bodyUsed is true when request is disturbed");
|
||||
const originalBody = bodyConsumed.body;
|
||||
const bodyReplaced = new Request(bodyConsumed, { body: "Replaced body" });
|
||||
assert_not_equals(bodyReplaced.body, originalBody, "new request's body is new");
|
||||
assert_false(bodyReplaced.bodyUsed, "bodyUsed is false when request is not disturbed");
|
||||
return bodyReplaced.text().then(text => {
|
||||
assert_equals(text, "Replaced body");
|
||||
});
|
||||
}, "Check creating a new request with a new body from a disturbed request");
|
||||
|
||||
promise_test(function() {
|
||||
var bodyRequest = new Request("", initValuesDict);
|
||||
const originalBody = bodyRequest.body;
|
||||
assert_false(bodyRequest.bodyUsed , "bodyUsed is false when request is not disturbed");
|
||||
var requestFromRequest = new Request(bodyRequest);
|
||||
assert_true(bodyRequest.bodyUsed , "bodyUsed is true when request is disturbed");
|
||||
assert_equals(bodyRequest.body, originalBody, "body should not change");
|
||||
assert_not_equals(originalBody, undefined, "body should not be undefined");
|
||||
assert_not_equals(originalBody, null, "body should not be null");
|
||||
assert_not_equals(requestFromRequest.body, originalBody, "new request's body is new");
|
||||
return requestFromRequest.text().then(text => {
|
||||
assert_equals(text, "Request's body");
|
||||
});
|
||||
}, "Input request used for creating new request became disturbed");
|
||||
|
||||
promise_test(() => {
|
||||
const bodyRequest = new Request("", initValuesDict);
|
||||
const originalBody = bodyRequest.body;
|
||||
assert_false(bodyRequest.bodyUsed , "bodyUsed is false when request is not disturbed");
|
||||
const requestFromRequest = new Request(bodyRequest, { body : "init body" });
|
||||
assert_true(bodyRequest.bodyUsed , "bodyUsed is true when request is disturbed");
|
||||
assert_equals(bodyRequest.body, originalBody, "body should not change");
|
||||
assert_not_equals(originalBody, undefined, "body should not be undefined");
|
||||
assert_not_equals(originalBody, null, "body should not be null");
|
||||
assert_not_equals(requestFromRequest.body, originalBody, "new request's body is new");
|
||||
|
||||
return requestFromRequest.text().then(text => {
|
||||
assert_equals(text, "init body");
|
||||
});
|
||||
}, "Input request used for creating new request became disturbed even if body is not used");
|
||||
|
||||
promise_test(function(test) {
|
||||
assert_true(bodyConsumed.bodyUsed , "bodyUsed is true when request is disturbed");
|
||||
return promise_rejects_js(test, TypeError, bodyConsumed.blob());
|
||||
}, "Check consuming a disturbed request");
|
||||
|
||||
test(function() {
|
||||
var req = new Request(URL, {method: 'POST', body: 'hello'});
|
||||
assert_false(req.bodyUsed,
|
||||
'Request should not be flagged as used if it has not been ' +
|
||||
'consumed.');
|
||||
assert_throws_js(TypeError,
|
||||
function() { new Request(req, {method: 'GET'}); },
|
||||
'A get request may not have body.');
|
||||
|
||||
assert_false(req.bodyUsed, 'After the GET case');
|
||||
|
||||
assert_throws_js(TypeError,
|
||||
function() { new Request(req, {method: 'CONNECT'}); },
|
||||
'Request() with a forbidden method must throw.');
|
||||
|
||||
assert_false(req.bodyUsed, 'After the forbidden method case');
|
||||
|
||||
var req2 = new Request(req);
|
||||
assert_true(req.bodyUsed,
|
||||
'Request should be flagged as used if it has been consumed.');
|
||||
}, 'Request construction failure should not set "bodyUsed"');
|
|
@ -1,121 +0,0 @@
|
|||
<!doctype html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>Request disturbed</title>
|
||||
<meta name="help" href="https://fetch.spec.whatwg.org/#request">
|
||||
<meta name="help" href="https://fetch.spec.whatwg.org/#body-mixin">
|
||||
<meta name="author" title="Canon Research France" href="https://www.crf.canon.fr">
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
<script>
|
||||
var initValuesDict = {"method" : "POST",
|
||||
"body" : "Request's body"
|
||||
};
|
||||
|
||||
var noBodyConsumed = new Request("");
|
||||
var bodyConsumed = new Request("", initValuesDict);
|
||||
|
||||
test(() => {
|
||||
assert_equals(noBodyConsumed.body, null, "body's default value is null");
|
||||
assert_false(noBodyConsumed.bodyUsed , "bodyUsed is false when request is not disturbed");
|
||||
assert_not_equals(bodyConsumed.body, null, "non-null body");
|
||||
assert_true(bodyConsumed.body instanceof ReadableStream, "non-null body type");
|
||||
assert_false(noBodyConsumed.bodyUsed, "bodyUsed is false when request is not disturbed");
|
||||
}, "Request's body: initial state");
|
||||
|
||||
noBodyConsumed.blob();
|
||||
bodyConsumed.blob();
|
||||
|
||||
test(function() {
|
||||
assert_false(noBodyConsumed.bodyUsed , "bodyUsed is false when request is not disturbed");
|
||||
try {
|
||||
noBodyConsumed.clone();
|
||||
} catch (e) {
|
||||
assert_unreached("Can use request not disturbed for creating or cloning request");
|
||||
}
|
||||
}, "Request without body cannot be disturbed");
|
||||
|
||||
test(function() {
|
||||
assert_true(bodyConsumed.bodyUsed , "bodyUsed is true when request is disturbed");
|
||||
assert_throws_js(TypeError, function() { bodyConsumed.clone(); });
|
||||
}, "Check cloning a disturbed request");
|
||||
|
||||
test(function() {
|
||||
assert_true(bodyConsumed.bodyUsed , "bodyUsed is true when request is disturbed");
|
||||
assert_throws_js(TypeError, function() { new Request(bodyConsumed); });
|
||||
}, "Check creating a new request from a disturbed request");
|
||||
|
||||
promise_test(function() {
|
||||
assert_true(bodyConsumed.bodyUsed , "bodyUsed is true when request is disturbed");
|
||||
const originalBody = bodyConsumed.body;
|
||||
const bodyReplaced = new Request(bodyConsumed, { body: "Replaced body" });
|
||||
assert_not_equals(bodyReplaced.body, originalBody, "new request's body is new");
|
||||
assert_false(bodyReplaced.bodyUsed, "bodyUsed is false when request is not disturbed");
|
||||
return bodyReplaced.text().then(text => {
|
||||
assert_equals(text, "Replaced body");
|
||||
});
|
||||
}, "Check creating a new request with a new body from a disturbed request");
|
||||
|
||||
promise_test(function() {
|
||||
var bodyRequest = new Request("", initValuesDict);
|
||||
const originalBody = bodyRequest.body;
|
||||
assert_false(bodyRequest.bodyUsed , "bodyUsed is false when request is not disturbed");
|
||||
var requestFromRequest = new Request(bodyRequest);
|
||||
assert_true(bodyRequest.bodyUsed , "bodyUsed is true when request is disturbed");
|
||||
assert_equals(bodyRequest.body, originalBody, "body should not change");
|
||||
assert_not_equals(originalBody, undefined, "body should not be undefined");
|
||||
assert_not_equals(originalBody, null, "body should not be null");
|
||||
assert_not_equals(requestFromRequest.body, originalBody, "new request's body is new");
|
||||
return requestFromRequest.text().then(text => {
|
||||
assert_equals(text, "Request's body");
|
||||
});
|
||||
}, "Input request used for creating new request became disturbed");
|
||||
|
||||
promise_test(() => {
|
||||
const bodyRequest = new Request("", initValuesDict);
|
||||
const originalBody = bodyRequest.body;
|
||||
assert_false(bodyRequest.bodyUsed , "bodyUsed is false when request is not disturbed");
|
||||
const requestFromRequest = new Request(bodyRequest, { body : "init body" });
|
||||
assert_true(bodyRequest.bodyUsed , "bodyUsed is true when request is disturbed");
|
||||
assert_equals(bodyRequest.body, originalBody, "body should not change");
|
||||
assert_not_equals(originalBody, undefined, "body should not be undefined");
|
||||
assert_not_equals(originalBody, null, "body should not be null");
|
||||
assert_not_equals(requestFromRequest.body, originalBody, "new request's body is new");
|
||||
|
||||
return requestFromRequest.text().then(text => {
|
||||
assert_equals(text, "init body");
|
||||
});
|
||||
}, "Input request used for creating new request became disturbed even if body is not used");
|
||||
|
||||
promise_test(function(test) {
|
||||
assert_true(bodyConsumed.bodyUsed , "bodyUsed is true when request is disturbed");
|
||||
return promise_rejects_js(test, TypeError, bodyConsumed.blob());
|
||||
}, "Check consuming a disturbed request");
|
||||
|
||||
test(function() {
|
||||
var req = new Request(URL, {method: 'POST', body: 'hello'});
|
||||
assert_false(req.bodyUsed,
|
||||
'Request should not be flagged as used if it has not been ' +
|
||||
'consumed.');
|
||||
assert_throws_js(TypeError,
|
||||
function() { new Request(req, {method: 'GET'}); },
|
||||
'A get request may not have body.');
|
||||
|
||||
assert_false(req.bodyUsed, 'After the GET case');
|
||||
|
||||
assert_throws_js(TypeError,
|
||||
function() { new Request(req, {method: 'CONNECT'}); },
|
||||
'Request() with a forbidden method must throw.');
|
||||
|
||||
assert_false(req.bodyUsed, 'After the forbidden method case');
|
||||
|
||||
var req2 = new Request(req);
|
||||
assert_true(req.bodyUsed,
|
||||
'Request should be flagged as used if it has been consumed.');
|
||||
}, 'Request construction failure should not set "bodyUsed"');
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,48 @@
|
|||
// META: global=window,worker
|
||||
// META: title=Request error
|
||||
// META: script=request-error.js
|
||||
|
||||
// badRequestArgTests is from response-error.js
|
||||
for (const { args, testName } of badRequestArgTests) {
|
||||
test(() => {
|
||||
assert_throws_js(
|
||||
TypeError,
|
||||
() => new Request(...args),
|
||||
"Expect TypeError exception"
|
||||
);
|
||||
}, testName);
|
||||
}
|
||||
|
||||
test(function() {
|
||||
var initialHeaders = new Headers([["Content-Type", "potato"]]);
|
||||
var initialRequest = new Request("", {"headers" : initialHeaders});
|
||||
var request = new Request(initialRequest);
|
||||
assert_equals(request.headers.get("Content-Type"), "potato");
|
||||
}, "Request should get its content-type from the init request");
|
||||
|
||||
test(function() {
|
||||
var initialHeaders = new Headers([["Content-Type", "potato"]]);
|
||||
var initialRequest = new Request("", {"headers" : initialHeaders});
|
||||
var headers = new Headers([]);
|
||||
var request = new Request(initialRequest, {"headers" : headers});
|
||||
assert_false(request.headers.has("Content-Type"));
|
||||
}, "Request should not get its content-type from the init request if init headers are provided");
|
||||
|
||||
test(function() {
|
||||
var initialHeaders = new Headers([["Content-Type-Extra", "potato"]]);
|
||||
var initialRequest = new Request("", {"headers" : initialHeaders, "body" : "this is my plate", "method" : "POST"});
|
||||
var request = new Request(initialRequest);
|
||||
assert_equals(request.headers.get("Content-Type"), "text/plain;charset=UTF-8");
|
||||
}, "Request should get its content-type from the body if none is provided");
|
||||
|
||||
test(function() {
|
||||
var initialHeaders = new Headers([["Content-Type", "potato"]]);
|
||||
var initialRequest = new Request("", {"headers" : initialHeaders, "body" : "this is my plate", "method" : "POST"});
|
||||
var request = new Request(initialRequest);
|
||||
assert_equals(request.headers.get("Content-Type"), "potato");
|
||||
}, "Request should get its content-type from init headers if one is provided");
|
||||
|
||||
test(function() {
|
||||
var options = {"cache": "only-if-cached", "mode": "same-origin"};
|
||||
new Request("test", options);
|
||||
}, "Request with cache mode: only-if-cached and fetch mode: same-origin");
|
|
@ -1,61 +0,0 @@
|
|||
<!doctype html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>Request error</title>
|
||||
<meta name="help" href="https://fetch.spec.whatwg.org/#request">
|
||||
<meta name="help" href="https://fetch.spec.whatwg.org/#body-mixin">
|
||||
<meta name="author" title="Canon Research France" href="https://www.crf.canon.fr">
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
<script src="request-error.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
<script>
|
||||
// badRequestArgTests is from response-error.js
|
||||
for (const { args, testName } of badRequestArgTests) {
|
||||
test(() => {
|
||||
assert_throws_js(
|
||||
TypeError,
|
||||
() => new Request(...args),
|
||||
"Expect TypeError exception"
|
||||
);
|
||||
}, testName);
|
||||
}
|
||||
|
||||
test(function() {
|
||||
var initialHeaders = new Headers([["Content-Type", "potato"]]);
|
||||
var initialRequest = new Request("", {"headers" : initialHeaders});
|
||||
var request = new Request(initialRequest);
|
||||
assert_equals(request.headers.get("Content-Type"), "potato");
|
||||
}, "Request should get its content-type from the init request");
|
||||
|
||||
test(function() {
|
||||
var initialHeaders = new Headers([["Content-Type", "potato"]]);
|
||||
var initialRequest = new Request("", {"headers" : initialHeaders});
|
||||
var headers = new Headers([]);
|
||||
var request = new Request(initialRequest, {"headers" : headers});
|
||||
assert_false(request.headers.has("Content-Type"));
|
||||
}, "Request should not get its content-type from the init request if init headers are provided");
|
||||
|
||||
test(function() {
|
||||
var initialHeaders = new Headers([["Content-Type-Extra", "potato"]]);
|
||||
var initialRequest = new Request("", {"headers" : initialHeaders, "body" : "this is my plate", "method" : "POST"});
|
||||
var request = new Request(initialRequest);
|
||||
assert_equals(request.headers.get("Content-Type"), "text/plain;charset=UTF-8");
|
||||
}, "Request should get its content-type from the body if none is provided");
|
||||
|
||||
test(function() {
|
||||
var initialHeaders = new Headers([["Content-Type", "potato"]]);
|
||||
var initialRequest = new Request("", {"headers" : initialHeaders, "body" : "this is my plate", "method" : "POST"});
|
||||
var request = new Request(initialRequest);
|
||||
assert_equals(request.headers.get("Content-Type"), "potato");
|
||||
}, "Request should get its content-type from init headers if one is provided");
|
||||
|
||||
test(function() {
|
||||
var options = {"cache": "only-if-cached", "mode": "same-origin"};
|
||||
new Request("test", options);
|
||||
}, "Request with cache mode: only-if-cached and fetch mode: same-origin");
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,173 @@
|
|||
// META: global=window,worker
|
||||
// META: title=Request Headers
|
||||
|
||||
var validRequestHeaders = [
|
||||
["Content-Type", "OK"],
|
||||
["Potato", "OK"],
|
||||
["proxy", "OK"],
|
||||
["proxya", "OK"],
|
||||
["sec", "OK"],
|
||||
["secb", "OK"],
|
||||
];
|
||||
var invalidRequestHeaders = [
|
||||
["Accept-Charset", "KO"],
|
||||
["accept-charset", "KO"],
|
||||
["ACCEPT-ENCODING", "KO"],
|
||||
["Accept-Encoding", "KO"],
|
||||
["Access-Control-Request-Headers", "KO"],
|
||||
["Access-Control-Request-Method", "KO"],
|
||||
["Connection", "KO"],
|
||||
["Content-Length", "KO"],
|
||||
["Cookie", "KO"],
|
||||
["Cookie2", "KO"],
|
||||
["Date", "KO"],
|
||||
["DNT", "KO"],
|
||||
["Expect", "KO"],
|
||||
["Host", "KO"],
|
||||
["Keep-Alive", "KO"],
|
||||
["Origin", "KO"],
|
||||
["Referer", "KO"],
|
||||
["TE", "KO"],
|
||||
["Trailer", "KO"],
|
||||
["Transfer-Encoding", "KO"],
|
||||
["Upgrade", "KO"],
|
||||
["Via", "KO"],
|
||||
["Proxy-", "KO"],
|
||||
["proxy-a", "KO"],
|
||||
["Sec-", "KO"],
|
||||
["sec-b", "KO"],
|
||||
];
|
||||
|
||||
var validRequestNoCorsHeaders = [
|
||||
["Accept", "OK"],
|
||||
["Accept-Language", "OK"],
|
||||
["content-language", "OK"],
|
||||
["content-type", "application/x-www-form-urlencoded"],
|
||||
["content-type", "application/x-www-form-urlencoded;charset=UTF-8"],
|
||||
["content-type", "multipart/form-data"],
|
||||
["content-type", "multipart/form-data;charset=UTF-8"],
|
||||
["content-TYPE", "text/plain"],
|
||||
["CONTENT-type", "text/plain;charset=UTF-8"],
|
||||
];
|
||||
var invalidRequestNoCorsHeaders = [
|
||||
["Content-Type", "KO"],
|
||||
["Potato", "KO"],
|
||||
["proxy", "KO"],
|
||||
["proxya", "KO"],
|
||||
["sec", "KO"],
|
||||
["secb", "KO"],
|
||||
];
|
||||
|
||||
validRequestHeaders.forEach(function(header) {
|
||||
test(function() {
|
||||
var request = new Request("");
|
||||
request.headers.set(header[0], header[1]);
|
||||
assert_equals(request.headers.get(header[0]), header[1]);
|
||||
}, "Adding valid request header \"" + header[0] + ": " + header[1] + "\"");
|
||||
});
|
||||
invalidRequestHeaders.forEach(function(header) {
|
||||
test(function() {
|
||||
var request = new Request("");
|
||||
request.headers.set(header[0], header[1]);
|
||||
assert_equals(request.headers.get(header[0]), null);
|
||||
}, "Adding invalid request header \"" + header[0] + ": " + header[1] + "\"");
|
||||
});
|
||||
|
||||
validRequestNoCorsHeaders.forEach(function(header) {
|
||||
test(function() {
|
||||
var requestNoCors = new Request("", {"mode": "no-cors"});
|
||||
requestNoCors.headers.set(header[0], header[1]);
|
||||
assert_equals(requestNoCors.headers.get(header[0]), header[1]);
|
||||
}, "Adding valid no-cors request header \"" + header[0] + ": " + header[1] + "\"");
|
||||
});
|
||||
invalidRequestNoCorsHeaders.forEach(function(header) {
|
||||
test(function() {
|
||||
var requestNoCors = new Request("", {"mode": "no-cors"});
|
||||
requestNoCors.headers.set(header[0], header[1]);
|
||||
assert_equals(requestNoCors.headers.get(header[0]), null);
|
||||
}, "Adding invalid no-cors request header \"" + header[0] + ": " + header[1] + "\"");
|
||||
});
|
||||
|
||||
test(function() {
|
||||
var headers = new Headers([["Cookie2", "potato"]]);
|
||||
var request = new Request("", {"headers": headers});
|
||||
assert_equals(request.headers.get("Cookie2"), null);
|
||||
}, "Check that request constructor is filtering headers provided as init parameter");
|
||||
|
||||
test(function() {
|
||||
var headers = new Headers([["Content-Type", "potato"]]);
|
||||
var request = new Request("", {"headers": headers, "mode": "no-cors"});
|
||||
assert_equals(request.headers.get("Content-Type"), null);
|
||||
}, "Check that no-cors request constructor is filtering headers provided as init parameter");
|
||||
|
||||
test(function() {
|
||||
var headers = new Headers([["Content-Type", "potato"]]);
|
||||
var initialRequest = new Request("", {"headers": headers});
|
||||
var request = new Request(initialRequest, {"mode": "no-cors"});
|
||||
assert_equals(request.headers.get("Content-Type"), null);
|
||||
}, "Check that no-cors request constructor is filtering headers provided as part of request parameter");
|
||||
|
||||
test(function() {
|
||||
var initialHeaders = new Headers([["Content-Type", "potato"]]);
|
||||
var initialRequest = new Request("", {"headers" : initialHeaders});
|
||||
var request = new Request(initialRequest);
|
||||
assert_equals(request.headers.get("Content-Type"), "potato");
|
||||
}, "Request should get its content-type from the init request");
|
||||
|
||||
test(function() {
|
||||
var initialHeaders = new Headers([["Content-Type", "potato"]]);
|
||||
var initialRequest = new Request("", {"headers" : initialHeaders});
|
||||
var headers = new Headers([]);
|
||||
var request = new Request(initialRequest, {"headers" : headers});
|
||||
assert_false(request.headers.has("Content-Type"));
|
||||
}, "Request should not get its content-type from the init request if init headers are provided");
|
||||
|
||||
test(function() {
|
||||
var initialHeaders = new Headers([["Content-Type-Extra", "potato"]]);
|
||||
var initialRequest = new Request("", {"headers" : initialHeaders, "body" : "this is my plate", "method" : "POST"});
|
||||
var request = new Request(initialRequest);
|
||||
assert_equals(request.headers.get("Content-Type"), "text/plain;charset=UTF-8");
|
||||
}, "Request should get its content-type from the body if none is provided");
|
||||
|
||||
test(function() {
|
||||
var initialHeaders = new Headers([["Content-Type", "potato"]]);
|
||||
var initialRequest = new Request("", {"headers" : initialHeaders, "body" : "this is my plate", "method" : "POST"});
|
||||
var request = new Request(initialRequest);
|
||||
assert_equals(request.headers.get("Content-Type"), "potato");
|
||||
}, "Request should get its content-type from init headers if one is provided");
|
||||
|
||||
test(function() {
|
||||
var array = [["hello", "worldAHH"]];
|
||||
var object = {"hello": 'worldOOH'};
|
||||
var headers = new Headers(array);
|
||||
|
||||
assert_equals(headers.get("hello"), "worldAHH");
|
||||
|
||||
var request1 = new Request("", {"headers": headers});
|
||||
var request2 = new Request("", {"headers": array});
|
||||
var request3 = new Request("", {"headers": object});
|
||||
|
||||
assert_equals(request1.headers.get("hello"), "worldAHH");
|
||||
assert_equals(request2.headers.get("hello"), "worldAHH");
|
||||
assert_equals(request3.headers.get("hello"), "worldOOH");
|
||||
}, "Testing request header creations with various objects");
|
||||
|
||||
promise_test(function(test) {
|
||||
var request = new Request("", {"headers" : [["Content-Type", ""]], "body" : "this is my plate", "method" : "POST"});
|
||||
return request.blob().then(function(blob) {
|
||||
assert_equals(blob.type, "", "Blob type should be the empty string");
|
||||
});
|
||||
}, "Testing empty Request Content-Type header");
|
||||
|
||||
test(function() {
|
||||
const request1 = new Request("");
|
||||
assert_equals(request1.headers, request1.headers);
|
||||
|
||||
const request2 = new Request("", {"headers": {"X-Foo": "bar"}});
|
||||
assert_equals(request2.headers, request2.headers);
|
||||
const headers = request2.headers;
|
||||
request2.headers.set("X-Foo", "quux");
|
||||
assert_equals(headers, request2.headers);
|
||||
headers.set("X-Other-Header", "baz");
|
||||
assert_equals(headers, request2.headers);
|
||||
}, "Test that Request.headers has the [SameObject] extended attribute");
|
|
@ -1,186 +0,0 @@
|
|||
<!doctype html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>Request Headers</title>
|
||||
<meta name="help" href="https://fetch.spec.whatwg.org/#request">
|
||||
<meta name="author" title="Canon Research France" href="https://www.crf.canon.fr">
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
<script>
|
||||
var validRequestHeaders = [
|
||||
["Content-Type", "OK"],
|
||||
["Potato", "OK"],
|
||||
["proxy", "OK"],
|
||||
["proxya", "OK"],
|
||||
["sec", "OK"],
|
||||
["secb", "OK"],
|
||||
];
|
||||
var invalidRequestHeaders = [
|
||||
["Accept-Charset", "KO"],
|
||||
["accept-charset", "KO"],
|
||||
["ACCEPT-ENCODING", "KO"],
|
||||
["Accept-Encoding", "KO"],
|
||||
["Access-Control-Request-Headers", "KO"],
|
||||
["Access-Control-Request-Method", "KO"],
|
||||
["Connection", "KO"],
|
||||
["Content-Length", "KO"],
|
||||
["Cookie", "KO"],
|
||||
["Cookie2", "KO"],
|
||||
["Date", "KO"],
|
||||
["DNT", "KO"],
|
||||
["Expect", "KO"],
|
||||
["Host", "KO"],
|
||||
["Keep-Alive", "KO"],
|
||||
["Origin", "KO"],
|
||||
["Referer", "KO"],
|
||||
["TE", "KO"],
|
||||
["Trailer", "KO"],
|
||||
["Transfer-Encoding", "KO"],
|
||||
["Upgrade", "KO"],
|
||||
["Via", "KO"],
|
||||
["Proxy-", "KO"],
|
||||
["proxy-a", "KO"],
|
||||
["Sec-", "KO"],
|
||||
["sec-b", "KO"],
|
||||
];
|
||||
|
||||
var validRequestNoCorsHeaders = [
|
||||
["Accept", "OK"],
|
||||
["Accept-Language", "OK"],
|
||||
["content-language", "OK"],
|
||||
["content-type", "application/x-www-form-urlencoded"],
|
||||
["content-type", "application/x-www-form-urlencoded;charset=UTF-8"],
|
||||
["content-type", "multipart/form-data"],
|
||||
["content-type", "multipart/form-data;charset=UTF-8"],
|
||||
["content-TYPE", "text/plain"],
|
||||
["CONTENT-type", "text/plain;charset=UTF-8"],
|
||||
];
|
||||
var invalidRequestNoCorsHeaders = [
|
||||
["Content-Type", "KO"],
|
||||
["Potato", "KO"],
|
||||
["proxy", "KO"],
|
||||
["proxya", "KO"],
|
||||
["sec", "KO"],
|
||||
["secb", "KO"],
|
||||
];
|
||||
|
||||
validRequestHeaders.forEach(function(header) {
|
||||
test(function() {
|
||||
var request = new Request("");
|
||||
request.headers.set(header[0], header[1]);
|
||||
assert_equals(request.headers.get(header[0]), header[1]);
|
||||
}, "Adding valid request header \"" + header[0] + ": " + header[1] + "\"");
|
||||
});
|
||||
invalidRequestHeaders.forEach(function(header) {
|
||||
test(function() {
|
||||
var request = new Request("");
|
||||
request.headers.set(header[0], header[1]);
|
||||
assert_equals(request.headers.get(header[0]), null);
|
||||
}, "Adding invalid request header \"" + header[0] + ": " + header[1] + "\"");
|
||||
});
|
||||
|
||||
validRequestNoCorsHeaders.forEach(function(header) {
|
||||
test(function() {
|
||||
var requestNoCors = new Request("", {"mode": "no-cors"});
|
||||
requestNoCors.headers.set(header[0], header[1]);
|
||||
assert_equals(requestNoCors.headers.get(header[0]), header[1]);
|
||||
}, "Adding valid no-cors request header \"" + header[0] + ": " + header[1] + "\"");
|
||||
});
|
||||
invalidRequestNoCorsHeaders.forEach(function(header) {
|
||||
test(function() {
|
||||
var requestNoCors = new Request("", {"mode": "no-cors"});
|
||||
requestNoCors.headers.set(header[0], header[1]);
|
||||
assert_equals(requestNoCors.headers.get(header[0]), null);
|
||||
}, "Adding invalid no-cors request header \"" + header[0] + ": " + header[1] + "\"");
|
||||
});
|
||||
|
||||
test(function() {
|
||||
var headers = new Headers([["Cookie2", "potato"]]);
|
||||
var request = new Request("", {"headers": headers});
|
||||
assert_equals(request.headers.get("Cookie2"), null);
|
||||
}, "Check that request constructor is filtering headers provided as init parameter");
|
||||
|
||||
test(function() {
|
||||
var headers = new Headers([["Content-Type", "potato"]]);
|
||||
var request = new Request("", {"headers": headers, "mode": "no-cors"});
|
||||
assert_equals(request.headers.get("Content-Type"), null);
|
||||
}, "Check that no-cors request constructor is filtering headers provided as init parameter");
|
||||
|
||||
test(function() {
|
||||
var headers = new Headers([["Content-Type", "potato"]]);
|
||||
var initialRequest = new Request("", {"headers": headers});
|
||||
var request = new Request(initialRequest, {"mode": "no-cors"});
|
||||
assert_equals(request.headers.get("Content-Type"), null);
|
||||
}, "Check that no-cors request constructor is filtering headers provided as part of request parameter");
|
||||
|
||||
test(function() {
|
||||
var initialHeaders = new Headers([["Content-Type", "potato"]]);
|
||||
var initialRequest = new Request("", {"headers" : initialHeaders});
|
||||
var request = new Request(initialRequest);
|
||||
assert_equals(request.headers.get("Content-Type"), "potato");
|
||||
}, "Request should get its content-type from the init request");
|
||||
|
||||
test(function() {
|
||||
var initialHeaders = new Headers([["Content-Type", "potato"]]);
|
||||
var initialRequest = new Request("", {"headers" : initialHeaders});
|
||||
var headers = new Headers([]);
|
||||
var request = new Request(initialRequest, {"headers" : headers});
|
||||
assert_false(request.headers.has("Content-Type"));
|
||||
}, "Request should not get its content-type from the init request if init headers are provided");
|
||||
|
||||
test(function() {
|
||||
var initialHeaders = new Headers([["Content-Type-Extra", "potato"]]);
|
||||
var initialRequest = new Request("", {"headers" : initialHeaders, "body" : "this is my plate", "method" : "POST"});
|
||||
var request = new Request(initialRequest);
|
||||
assert_equals(request.headers.get("Content-Type"), "text/plain;charset=UTF-8");
|
||||
}, "Request should get its content-type from the body if none is provided");
|
||||
|
||||
test(function() {
|
||||
var initialHeaders = new Headers([["Content-Type", "potato"]]);
|
||||
var initialRequest = new Request("", {"headers" : initialHeaders, "body" : "this is my plate", "method" : "POST"});
|
||||
var request = new Request(initialRequest);
|
||||
assert_equals(request.headers.get("Content-Type"), "potato");
|
||||
}, "Request should get its content-type from init headers if one is provided");
|
||||
|
||||
test(function() {
|
||||
var array = [["hello", "worldAHH"]];
|
||||
var object = {"hello": 'worldOOH'};
|
||||
var headers = new Headers(array);
|
||||
|
||||
assert_equals(headers.get("hello"), "worldAHH");
|
||||
|
||||
var request1 = new Request("", {"headers": headers});
|
||||
var request2 = new Request("", {"headers": array});
|
||||
var request3 = new Request("", {"headers": object});
|
||||
|
||||
assert_equals(request1.headers.get("hello"), "worldAHH");
|
||||
assert_equals(request2.headers.get("hello"), "worldAHH");
|
||||
assert_equals(request3.headers.get("hello"), "worldOOH");
|
||||
}, "Testing request header creations with various objects");
|
||||
|
||||
promise_test(function(test) {
|
||||
var request = new Request("", {"headers" : [["Content-Type", ""]], "body" : "this is my plate", "method" : "POST"});
|
||||
return request.blob().then(function(blob) {
|
||||
assert_equals(blob.type, "", "Blob type should be the empty string");
|
||||
});
|
||||
}, "Testing empty Request Content-Type header");
|
||||
|
||||
test(function() {
|
||||
const request1 = new Request("");
|
||||
assert_equals(request1.headers, request1.headers);
|
||||
|
||||
const request2 = new Request("", {"headers": {"X-Foo": "bar"}});
|
||||
assert_equals(request2.headers, request2.headers);
|
||||
const headers = request2.headers;
|
||||
request2.headers.set("X-Foo", "quux");
|
||||
assert_equals(headers, request2.headers);
|
||||
headers.set("X-Other-Header", "baz");
|
||||
assert_equals(headers, request2.headers);
|
||||
}, "Test that Request.headers has the [SameObject] extended attribute");
|
||||
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,60 @@
|
|||
// META: global=window,worker
|
||||
// META: title=Request init: headers and body
|
||||
|
||||
test(function() {
|
||||
var headerDict = {"name1": "value1",
|
||||
"name2": "value2",
|
||||
"name3": "value3"
|
||||
};
|
||||
var headers = new Headers(headerDict);
|
||||
var request = new Request("", { "headers" : headers })
|
||||
for (var name in headerDict) {
|
||||
assert_equals(request.headers.get(name), headerDict[name],
|
||||
"request's headers has " + name + " : " + headerDict[name]);
|
||||
}
|
||||
}, "Initialize Request with headers values");
|
||||
|
||||
function makeRequestInit(body, method) {
|
||||
return {"method": method, "body": body};
|
||||
}
|
||||
|
||||
function checkRequestInit(body, bodyType, expectedTextBody) {
|
||||
promise_test(function(test) {
|
||||
var request = new Request("", makeRequestInit(body, "POST"));
|
||||
if (body) {
|
||||
assert_throws_js(TypeError, function() { new Request("", makeRequestInit(body, "GET")); });
|
||||
assert_throws_js(TypeError, function() { new Request("", makeRequestInit(body, "HEAD")); });
|
||||
} else {
|
||||
new Request("", makeRequestInit(body, "GET")); // should not throw
|
||||
}
|
||||
var reqHeaders = request.headers;
|
||||
var mime = reqHeaders.get("Content-Type");
|
||||
assert_true(!body || (mime && mime.search(bodyType) > -1), "Content-Type header should be \"" + bodyType + "\", not \"" + mime + "\"");
|
||||
return request.text().then(function(bodyAsText) {
|
||||
//not equals: cannot guess formData exact value
|
||||
assert_true( bodyAsText.search(expectedTextBody) > -1, "Retrieve and verify request body");
|
||||
});
|
||||
}, `Initialize Request's body with "${body}", ${bodyType}`);
|
||||
}
|
||||
|
||||
var blob = new Blob(["This is a blob"], {type: "application/octet-binary"});
|
||||
var formaData = new FormData();
|
||||
formaData.append("name", "value");
|
||||
var usvString = "This is a USVString"
|
||||
|
||||
checkRequestInit(undefined, undefined, "");
|
||||
checkRequestInit(null, null, "");
|
||||
checkRequestInit(blob, "application/octet-binary", "This is a blob");
|
||||
checkRequestInit(formaData, "multipart/form-data", "name=\"name\"\r\n\r\nvalue");
|
||||
checkRequestInit(usvString, "text/plain;charset=UTF-8", "This is a USVString");
|
||||
checkRequestInit({toString: () => "hi!"}, "text/plain;charset=UTF-8", "hi!");
|
||||
|
||||
// Ensure test does not time out in case of missing URLSearchParams support.
|
||||
if (self.URLSearchParams) {
|
||||
var urlSearchParams = new URLSearchParams("name=value");
|
||||
checkRequestInit(urlSearchParams, "application/x-www-form-urlencoded;charset=UTF-8", "name=value");
|
||||
} else {
|
||||
promise_test(function(test) {
|
||||
return Promise.reject("URLSearchParams not supported");
|
||||
}, "Initialize Request's body with application/x-www-form-urlencoded;charset=UTF-8");
|
||||
}
|
|
@ -1,72 +0,0 @@
|
|||
<!doctype html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>Request init: headers and body</title>
|
||||
<meta name="help" href="https://fetch.spec.whatwg.org/#request">
|
||||
<meta name="author" title="Canon Research France" href="https://www.crf.canon.fr">
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
<script>
|
||||
test(function() {
|
||||
var headerDict = {"name1": "value1",
|
||||
"name2": "value2",
|
||||
"name3": "value3"
|
||||
};
|
||||
var headers = new Headers(headerDict);
|
||||
var request = new Request("", { "headers" : headers })
|
||||
for (var name in headerDict) {
|
||||
assert_equals(request.headers.get(name), headerDict[name],
|
||||
"request's headers has " + name + " : " + headerDict[name]);
|
||||
}
|
||||
}, "Initialize Request with headers values");
|
||||
|
||||
function makeRequestInit(body, method) {
|
||||
return {"method": method, "body": body};
|
||||
}
|
||||
|
||||
function checkRequestInit(body, bodyType, expectedTextBody) {
|
||||
promise_test(function(test) {
|
||||
var request = new Request("", makeRequestInit(body, "POST"));
|
||||
if (body) {
|
||||
assert_throws_js(TypeError, function() { new Request("", makeRequestInit(body, "GET")); });
|
||||
assert_throws_js(TypeError, function() { new Request("", makeRequestInit(body, "HEAD")); });
|
||||
} else {
|
||||
new Request("", makeRequestInit(body, "GET")); // should not throw
|
||||
}
|
||||
var reqHeaders = request.headers;
|
||||
var mime = reqHeaders.get("Content-Type");
|
||||
assert_true(!body || (mime && mime.search(bodyType) > -1), "Content-Type header should be \"" + bodyType + "\", not \"" + mime + "\"");
|
||||
return request.text().then(function(bodyAsText) {
|
||||
//not equals: cannot guess formData exact value
|
||||
assert_true( bodyAsText.search(expectedTextBody) > -1, "Retrieve and verify request body");
|
||||
});
|
||||
}, `Initialize Request's body with "${body}", ${bodyType}`);
|
||||
}
|
||||
|
||||
var blob = new Blob(["This is a blob"], {type: "application/octet-binary"});
|
||||
var formaData = new FormData();
|
||||
formaData.append("name", "value");
|
||||
var usvString = "This is a USVString"
|
||||
|
||||
checkRequestInit(undefined, undefined, "");
|
||||
checkRequestInit(null, null, "");
|
||||
checkRequestInit(blob, "application/octet-binary", "This is a blob");
|
||||
checkRequestInit(formaData, "multipart/form-data", "name=\"name\"\r\n\r\nvalue");
|
||||
checkRequestInit(usvString, "text/plain;charset=UTF-8", "This is a USVString");
|
||||
checkRequestInit({toString: () => "hi!"}, "text/plain;charset=UTF-8", "hi!");
|
||||
|
||||
// Ensure test does not time out in case of missing URLSearchParams support.
|
||||
if (window.URLSearchParams) {
|
||||
var urlSearchParams = new URLSearchParams("name=value");
|
||||
checkRequestInit(urlSearchParams, "application/x-www-form-urlencoded;charset=UTF-8", "name=value");
|
||||
} else {
|
||||
promise_test(function(test) {
|
||||
return Promise.reject("URLSearchParams not supported");
|
||||
}, "Initialize Request's body with application/x-www-form-urlencoded;charset=UTF-8");
|
||||
}
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
|
@ -1,16 +1,8 @@
|
|||
<!doctype html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>Request keepalive</title>
|
||||
<meta name="help" href="https://fetch.spec.whatwg.org/#request">
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
<script src="/common/utils.js"></script>
|
||||
<script src="/common/get-host-info.sub.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
<script>
|
||||
// META: global=window,worker
|
||||
// META: title=Request keepalive
|
||||
// META: script=/common/utils.js
|
||||
// META: script=/common/get-host-info.sub.js
|
||||
|
||||
test(() => {
|
||||
assert_false(new Request('/').keepalive, 'default');
|
||||
assert_true(new Request('/', {keepalive: true}).keepalive, 'true');
|
||||
|
@ -23,6 +15,3 @@ test(() => {
|
|||
const init = {method: 'POST', keepalive: true, body: new ReadableStream()};
|
||||
assert_throws_js(TypeError, () => {new Request('/', init)});
|
||||
}, 'keepalive flag with stream body');
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,128 @@
|
|||
// META: global=window,worker
|
||||
// META: title=Request structure
|
||||
|
||||
var request = new Request("");
|
||||
var methods = ["clone",
|
||||
//Request implements Body
|
||||
"arrayBuffer",
|
||||
"blob",
|
||||
"formData",
|
||||
"json",
|
||||
"text"
|
||||
];
|
||||
var attributes = ["method",
|
||||
"url",
|
||||
"headers",
|
||||
"destination",
|
||||
"referrer",
|
||||
"referrerPolicy",
|
||||
"mode",
|
||||
"credentials",
|
||||
"cache",
|
||||
"redirect",
|
||||
"integrity",
|
||||
"isReloadNavigation",
|
||||
"isHistoryNavigation",
|
||||
//Request implements Body
|
||||
"bodyUsed"
|
||||
];
|
||||
|
||||
function IsreadOnly(request, attributeToCheck) {
|
||||
var defaultValue = undefined;
|
||||
var newValue = undefined;
|
||||
switch (attributeToCheck) {
|
||||
case "method":
|
||||
defaultValue = "GET";
|
||||
newValue = "POST";
|
||||
break;
|
||||
|
||||
case "url":
|
||||
//default value is base url
|
||||
//i.e http://example.com/fetch/api/request-structure.html
|
||||
newValue = "http://url.test";
|
||||
break;
|
||||
|
||||
case "headers":
|
||||
request.headers = new Headers ({"name":"value"});
|
||||
assert_false(request.headers.has("name"), "Headers attribute is read only");
|
||||
return;
|
||||
break;
|
||||
|
||||
case "destination":
|
||||
defaultValue = "";
|
||||
newValue = "worker";
|
||||
break;
|
||||
|
||||
case "referrer":
|
||||
defaultValue = "about:client";
|
||||
newValue = "http://url.test";
|
||||
break;
|
||||
|
||||
case "referrerPolicy":
|
||||
defaultValue = "";
|
||||
newValue = "unsafe-url";
|
||||
break;
|
||||
|
||||
case "mode":
|
||||
defaultValue = "cors";
|
||||
newValue = "navigate";
|
||||
break;
|
||||
|
||||
case "credentials":
|
||||
defaultValue = "same-origin";
|
||||
newValue = "cors";
|
||||
break;
|
||||
|
||||
case "cache":
|
||||
defaultValue = "default";
|
||||
newValue = "reload";
|
||||
break;
|
||||
|
||||
case "redirect":
|
||||
defaultValue = "follow";
|
||||
newValue = "manual";
|
||||
break;
|
||||
|
||||
case "integrity":
|
||||
newValue = "CannotWriteIntegrity";
|
||||
break;
|
||||
|
||||
case "bodyUsed":
|
||||
defaultValue = false;
|
||||
newValue = true;
|
||||
break;
|
||||
|
||||
case "isReloadNavigation":
|
||||
defaultValue = false;
|
||||
newValue = true;
|
||||
break;
|
||||
|
||||
case "isHistoryNavigation":
|
||||
defaultValue = false;
|
||||
newValue = true;
|
||||
break;
|
||||
|
||||
default:
|
||||
return;
|
||||
}
|
||||
|
||||
request[attributeToCheck] = newValue;
|
||||
if (defaultValue === undefined)
|
||||
assert_not_equals(request[attributeToCheck], newValue, "Attribute " + attributeToCheck + " is read only");
|
||||
else
|
||||
assert_equals(request[attributeToCheck], defaultValue,
|
||||
"Attribute " + attributeToCheck + " is read only. Default value is " + defaultValue);
|
||||
}
|
||||
|
||||
for (var idx in methods) {
|
||||
test(function() {
|
||||
assert_true(methods[idx] in request, "request has " + methods[idx] + " method");
|
||||
}, "Request has " + methods[idx] + " method");
|
||||
}
|
||||
|
||||
for (var idx in attributes) {
|
||||
test(function() {
|
||||
assert_true(attributes[idx] in request, "request has " + attributes[idx] + " attribute");
|
||||
IsreadOnly(request, attributes[idx]);
|
||||
}, "Check " + attributes[idx] + " attribute");
|
||||
}
|
|
@ -1,140 +0,0 @@
|
|||
<!doctype html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>Request structure</title>
|
||||
<meta name="help" href="https://fetch.spec.whatwg.org/#request">
|
||||
<meta name="author" title="Canon Research France" href="https://www.crf.canon.fr">
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
<script>
|
||||
var request = new Request("");
|
||||
var methods = ["clone",
|
||||
//Request implements Body
|
||||
"arrayBuffer",
|
||||
"blob",
|
||||
"formData",
|
||||
"json",
|
||||
"text"
|
||||
];
|
||||
var attributes = ["method",
|
||||
"url",
|
||||
"headers",
|
||||
"destination",
|
||||
"referrer",
|
||||
"referrerPolicy",
|
||||
"mode",
|
||||
"credentials",
|
||||
"cache",
|
||||
"redirect",
|
||||
"integrity",
|
||||
"isReloadNavigation",
|
||||
"isHistoryNavigation",
|
||||
//Request implements Body
|
||||
"bodyUsed"
|
||||
];
|
||||
|
||||
function IsreadOnly(request, attributeToCheck) {
|
||||
var defaultValue = undefined;
|
||||
var newValue = undefined;
|
||||
switch (attributeToCheck) {
|
||||
case "method":
|
||||
defaultValue = "GET";
|
||||
newValue = "POST";
|
||||
break;
|
||||
|
||||
case "url":
|
||||
//default value is base url
|
||||
//i.e http://example.com/fetch/api/request-structure.html
|
||||
newValue = "http://url.test";
|
||||
break;
|
||||
|
||||
case "headers":
|
||||
request.headers = new Headers ({"name":"value"});
|
||||
assert_false(request.headers.has("name"), "Headers attribute is read only");
|
||||
return;
|
||||
break;
|
||||
|
||||
case "destination":
|
||||
defaultValue = "";
|
||||
newValue = "worker";
|
||||
break;
|
||||
|
||||
case "referrer":
|
||||
defaultValue = "about:client";
|
||||
newValue = "http://url.test";
|
||||
break;
|
||||
|
||||
case "referrerPolicy":
|
||||
defaultValue = "";
|
||||
newValue = "unsafe-url";
|
||||
break;
|
||||
|
||||
case "mode":
|
||||
defaultValue = "cors";
|
||||
newValue = "navigate";
|
||||
break;
|
||||
|
||||
case "credentials":
|
||||
defaultValue = "same-origin";
|
||||
newValue = "cors";
|
||||
break;
|
||||
|
||||
case "cache":
|
||||
defaultValue = "default";
|
||||
newValue = "reload";
|
||||
break;
|
||||
|
||||
case "redirect":
|
||||
defaultValue = "follow";
|
||||
newValue = "manual";
|
||||
break;
|
||||
|
||||
case "integrity":
|
||||
newValue = "CannotWriteIntegrity";
|
||||
break;
|
||||
|
||||
case "bodyUsed":
|
||||
defaultValue = false;
|
||||
newValue = true;
|
||||
break;
|
||||
|
||||
case "isReloadNavigation":
|
||||
defaultValue = false;
|
||||
newValue = true;
|
||||
break;
|
||||
|
||||
case "isHistoryNavigation":
|
||||
defaultValue = false;
|
||||
newValue = true;
|
||||
break;
|
||||
|
||||
default:
|
||||
return;
|
||||
}
|
||||
|
||||
request[attributeToCheck] = newValue;
|
||||
if (defaultValue === undefined)
|
||||
assert_not_equals(request[attributeToCheck], newValue, "Attribute " + attributeToCheck + " is read only");
|
||||
else
|
||||
assert_equals(request[attributeToCheck], defaultValue,
|
||||
"Attribute " + attributeToCheck + " is read only. Default value is " + defaultValue);
|
||||
}
|
||||
|
||||
for (var idx in methods) {
|
||||
test(function() {
|
||||
assert_true(methods[idx] in request, "request has " + methods[idx] + " method");
|
||||
}, "Request has " + methods[idx] + " method");
|
||||
}
|
||||
|
||||
for (var idx in attributes) {
|
||||
test(function() {
|
||||
assert_true(attributes[idx] in request, "request has " + attributes[idx] + " attribute");
|
||||
IsreadOnly(request, attributes[idx]);
|
||||
}, "Check " + attributes[idx] + " attribute");
|
||||
}
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
|
@ -1,17 +1,7 @@
|
|||
<!doctype html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>Response consume blob and http bodies</title>
|
||||
<meta name="help" href="https://fetch.spec.whatwg.org/#response">
|
||||
<meta name="help" href="https://fetch.spec.whatwg.org/#body-mixin">
|
||||
<meta name="author" title="Canon Research France" href="https://www.crf.canon.fr">
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
<script src="../resources/utils.js"></script>
|
||||
<script>
|
||||
// META: global=window,worker
|
||||
// META: title=Response consume blob and http bodies
|
||||
// META: script=../resources/utils.js
|
||||
|
||||
promise_test(function(test) {
|
||||
return new Response(new Blob([], { "type" : "text/plain" })).body.cancel();
|
||||
}, "Cancelling a starting blob Response stream");
|
||||
|
@ -65,6 +55,3 @@ promise_test(function() {
|
|||
return readAll(reader).then(() => reader.cancel());
|
||||
});
|
||||
}, "Cancelling a closed Response stream");
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,124 @@
|
|||
// META: global=window,worker
|
||||
// META: title=Response clone
|
||||
// META: script=../resources/utils.js
|
||||
|
||||
var defaultValues = { "type" : "default",
|
||||
"url" : "",
|
||||
"ok" : true,
|
||||
"status" : 200,
|
||||
"statusText" : ""
|
||||
};
|
||||
|
||||
var response = new Response();
|
||||
var clonedResponse = response.clone();
|
||||
test(function() {
|
||||
for (var attributeName in defaultValues) {
|
||||
var expectedValue = defaultValues[attributeName];
|
||||
assert_equals(clonedResponse[attributeName], expectedValue,
|
||||
"Expect default response." + attributeName + " is " + expectedValue);
|
||||
}
|
||||
}, "Check Response's clone with default values, without body");
|
||||
|
||||
var body = "This is response body";
|
||||
var headersInit = { "name" : "value" };
|
||||
var responseInit = { "status" : 200,
|
||||
"statusText" : "GOOD",
|
||||
"headers" : headersInit
|
||||
};
|
||||
var response = new Response(body, responseInit);
|
||||
var clonedResponse = response.clone();
|
||||
test(function() {
|
||||
assert_equals(clonedResponse.status, responseInit["status"],
|
||||
"Expect response.status is " + responseInit["status"]);
|
||||
assert_equals(clonedResponse.statusText, responseInit["statusText"],
|
||||
"Expect response.statusText is " + responseInit["statusText"]);
|
||||
assert_equals(clonedResponse.headers.get("name"), "value",
|
||||
"Expect response.headers has name:value header");
|
||||
}, "Check Response's clone has the expected attribute values");
|
||||
|
||||
promise_test(function(test) {
|
||||
return validateStreamFromString(response.body.getReader(), body);
|
||||
}, "Check orginal response's body after cloning");
|
||||
|
||||
promise_test(function(test) {
|
||||
return validateStreamFromString(clonedResponse.body.getReader(), body);
|
||||
}, "Check cloned response's body");
|
||||
|
||||
promise_test(function(test) {
|
||||
var disturbedResponse = new Response("data");
|
||||
return disturbedResponse.text().then(function() {
|
||||
assert_true(disturbedResponse.bodyUsed, "response is disturbed");
|
||||
assert_throws_js(TypeError, function() { disturbedResponse.clone(); },
|
||||
"Expect TypeError exception");
|
||||
});
|
||||
}, "Cannot clone a disturbed response");
|
||||
|
||||
promise_test(function(t) {
|
||||
var clone;
|
||||
var result;
|
||||
var response;
|
||||
return fetch('../resources/trickle.py?count=2&delay=100').then(function(res) {
|
||||
clone = res.clone();
|
||||
response = res;
|
||||
return clone.text();
|
||||
}).then(function(r) {
|
||||
assert_equals(r.length, 26);
|
||||
result = r;
|
||||
return response.text();
|
||||
}).then(function(r) {
|
||||
assert_equals(r, result, "cloned responses should provide the same data");
|
||||
});
|
||||
}, 'Cloned responses should provide the same data');
|
||||
|
||||
promise_test(function(t) {
|
||||
var clone;
|
||||
return fetch('../resources/trickle.py?count=2&delay=100').then(function(res) {
|
||||
clone = res.clone();
|
||||
res.body.cancel();
|
||||
assert_true(res.bodyUsed);
|
||||
assert_false(clone.bodyUsed);
|
||||
return clone.arrayBuffer();
|
||||
}).then(function(r) {
|
||||
assert_equals(r.byteLength, 26);
|
||||
assert_true(clone.bodyUsed);
|
||||
});
|
||||
}, 'Cancelling stream should not affect cloned one');
|
||||
|
||||
function testReadableStreamClone(initialBuffer, bufferType)
|
||||
{
|
||||
promise_test(function(test) {
|
||||
var response = new Response(new ReadableStream({start : function(controller) {
|
||||
controller.enqueue(initialBuffer);
|
||||
controller.close();
|
||||
}}));
|
||||
|
||||
var clone = response.clone();
|
||||
var stream1 = response.body;
|
||||
var stream2 = clone.body;
|
||||
|
||||
var buffer;
|
||||
return stream1.getReader().read().then(function(data) {
|
||||
assert_false(data.done);
|
||||
assert_equals(data.value, initialBuffer, "Buffer of being-cloned response stream is the same as the original buffer");
|
||||
return stream2.getReader().read();
|
||||
}).then(function(data) {
|
||||
assert_false(data.done);
|
||||
assert_array_equals(data.value, initialBuffer, "Cloned buffer chunks have the same content");
|
||||
assert_equals(Object.getPrototypeOf(data.value), Object.getPrototypeOf(initialBuffer), "Cloned buffers have the same type");
|
||||
assert_not_equals(data.value, initialBuffer, "Buffer of cloned response stream is a clone of the original buffer");
|
||||
});
|
||||
}, "Check response clone use structureClone for teed ReadableStreams (" + bufferType + "chunk)");
|
||||
}
|
||||
|
||||
var arrayBuffer = new ArrayBuffer(16);
|
||||
testReadableStreamClone(new Int8Array(arrayBuffer, 1), "Int8Array");
|
||||
testReadableStreamClone(new Int16Array(arrayBuffer, 2, 2), "Int16Array");
|
||||
testReadableStreamClone(new Int32Array(arrayBuffer), "Int32Array");
|
||||
testReadableStreamClone(arrayBuffer, "ArrayBuffer");
|
||||
testReadableStreamClone(new Uint8Array(arrayBuffer), "Uint8Array");
|
||||
testReadableStreamClone(new Uint8ClampedArray(arrayBuffer), "Uint8ClampedArray");
|
||||
testReadableStreamClone(new Uint16Array(arrayBuffer, 2), "Uint16Array");
|
||||
testReadableStreamClone(new Uint32Array(arrayBuffer), "Uint32Array");
|
||||
testReadableStreamClone(new Float32Array(arrayBuffer), "Float32Array");
|
||||
testReadableStreamClone(new Float64Array(arrayBuffer), "Float64Array");
|
||||
testReadableStreamClone(new DataView(arrayBuffer, 2, 8), "DataView");
|
|
@ -1,137 +0,0 @@
|
|||
<!doctype html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>Response clone</title>
|
||||
<meta name="timeout" content="long">
|
||||
<meta name="help" href="https://fetch.spec.whatwg.org/#response">
|
||||
<meta name="author" title="Canon Research France" href="https://www.crf.canon.fr">
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
<script src="../resources/utils.js"></script>
|
||||
<script>
|
||||
var defaultValues = { "type" : "default",
|
||||
"url" : "",
|
||||
"ok" : true,
|
||||
"status" : 200,
|
||||
"statusText" : ""
|
||||
};
|
||||
|
||||
var response = new Response();
|
||||
var clonedResponse = response.clone();
|
||||
test(function() {
|
||||
for (var attributeName in defaultValues) {
|
||||
var expectedValue = defaultValues[attributeName];
|
||||
assert_equals(clonedResponse[attributeName], expectedValue,
|
||||
"Expect default response." + attributeName + " is " + expectedValue);
|
||||
}
|
||||
}, "Check Response's clone with default values, without body");
|
||||
|
||||
var body = "This is response body";
|
||||
var headersInit = { "name" : "value" };
|
||||
var responseInit = { "status" : 200,
|
||||
"statusText" : "GOOD",
|
||||
"headers" : headersInit
|
||||
};
|
||||
var response = new Response(body, responseInit);
|
||||
var clonedResponse = response.clone();
|
||||
test(function() {
|
||||
assert_equals(clonedResponse.status, responseInit["status"],
|
||||
"Expect response.status is " + responseInit["status"]);
|
||||
assert_equals(clonedResponse.statusText, responseInit["statusText"],
|
||||
"Expect response.statusText is " + responseInit["statusText"]);
|
||||
assert_equals(clonedResponse.headers.get("name"), "value",
|
||||
"Expect response.headers has name:value header");
|
||||
}, "Check Response's clone has the expected attribute values");
|
||||
|
||||
promise_test(function(test) {
|
||||
return validateStreamFromString(response.body.getReader(), body);
|
||||
}, "Check orginal response's body after cloning");
|
||||
|
||||
promise_test(function(test) {
|
||||
return validateStreamFromString(clonedResponse.body.getReader(), body);
|
||||
}, "Check cloned response's body");
|
||||
|
||||
promise_test(function(test) {
|
||||
var disturbedResponse = new Response("data");
|
||||
return disturbedResponse.text().then(function() {
|
||||
assert_true(disturbedResponse.bodyUsed, "response is disturbed");
|
||||
assert_throws_js(TypeError, function() { disturbedResponse.clone(); },
|
||||
"Expect TypeError exception");
|
||||
});
|
||||
}, "Cannot clone a disturbed response");
|
||||
|
||||
promise_test(function(t) {
|
||||
var clone;
|
||||
var result;
|
||||
var response;
|
||||
return fetch('../resources/trickle.py?count=2&delay=100').then(function(res) {
|
||||
clone = res.clone();
|
||||
response = res;
|
||||
return clone.text();
|
||||
}).then(function(r) {
|
||||
assert_equals(r.length, 26);
|
||||
result = r;
|
||||
return response.text();
|
||||
}).then(function(r) {
|
||||
assert_equals(r, result, "cloned responses should provide the same data");
|
||||
});
|
||||
}, 'Cloned responses should provide the same data');
|
||||
|
||||
promise_test(function(t) {
|
||||
var clone;
|
||||
return fetch('../resources/trickle.py?count=2&delay=100').then(function(res) {
|
||||
clone = res.clone();
|
||||
res.body.cancel();
|
||||
assert_true(res.bodyUsed);
|
||||
assert_false(clone.bodyUsed);
|
||||
return clone.arrayBuffer();
|
||||
}).then(function(r) {
|
||||
assert_equals(r.byteLength, 26);
|
||||
assert_true(clone.bodyUsed);
|
||||
});
|
||||
}, 'Cancelling stream should not affect cloned one');
|
||||
|
||||
function testReadableStreamClone(initialBuffer, bufferType)
|
||||
{
|
||||
promise_test(function(test) {
|
||||
var response = new Response(new ReadableStream({start : function(controller) {
|
||||
controller.enqueue(initialBuffer);
|
||||
controller.close();
|
||||
}}));
|
||||
|
||||
var clone = response.clone();
|
||||
var stream1 = response.body;
|
||||
var stream2 = clone.body;
|
||||
|
||||
var buffer;
|
||||
return stream1.getReader().read().then(function(data) {
|
||||
assert_false(data.done);
|
||||
assert_equals(data.value, initialBuffer, "Buffer of being-cloned response stream is the same as the original buffer");
|
||||
return stream2.getReader().read();
|
||||
}).then(function(data) {
|
||||
assert_false(data.done);
|
||||
assert_array_equals(data.value, initialBuffer, "Cloned buffer chunks have the same content");
|
||||
assert_equals(Object.getPrototypeOf(data.value), Object.getPrototypeOf(initialBuffer), "Cloned buffers have the same type");
|
||||
assert_not_equals(data.value, initialBuffer, "Buffer of cloned response stream is a clone of the original buffer");
|
||||
});
|
||||
}, "Check response clone use structureClone for teed ReadableStreams (" + bufferType + "chunk)");
|
||||
}
|
||||
|
||||
var arrayBuffer = new ArrayBuffer(16);
|
||||
testReadableStreamClone(new Int8Array(arrayBuffer, 1), "Int8Array");
|
||||
testReadableStreamClone(new Int16Array(arrayBuffer, 2, 2), "Int16Array");
|
||||
testReadableStreamClone(new Int32Array(arrayBuffer), "Int32Array");
|
||||
testReadableStreamClone(arrayBuffer, "ArrayBuffer");
|
||||
testReadableStreamClone(new Uint8Array(arrayBuffer), "Uint8Array");
|
||||
testReadableStreamClone(new Uint8ClampedArray(arrayBuffer), "Uint8ClampedArray");
|
||||
testReadableStreamClone(new Uint16Array(arrayBuffer, 2), "Uint16Array");
|
||||
testReadableStreamClone(new Uint32Array(arrayBuffer), "Uint32Array");
|
||||
testReadableStreamClone(new Float32Array(arrayBuffer), "Float32Array");
|
||||
testReadableStreamClone(new Float64Array(arrayBuffer), "Float64Array");
|
||||
testReadableStreamClone(new DataView(arrayBuffer, 2, 8), "DataView");
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,99 @@
|
|||
// META: global=window,worker
|
||||
// META: title=Response consume empty bodies
|
||||
|
||||
function checkBodyText(test, response) {
|
||||
return response.text().then(function(bodyAsText) {
|
||||
assert_equals(bodyAsText, "", "Resolved value should be empty");
|
||||
assert_false(response.bodyUsed);
|
||||
});
|
||||
}
|
||||
|
||||
function checkBodyBlob(test, response) {
|
||||
return response.blob().then(function(bodyAsBlob) {
|
||||
var promise = new Promise(function(resolve, reject) {
|
||||
var reader = new FileReader();
|
||||
reader.onload = function(evt) {
|
||||
resolve(reader.result)
|
||||
};
|
||||
reader.onerror = function() {
|
||||
reject("Blob's reader failed");
|
||||
};
|
||||
reader.readAsText(bodyAsBlob);
|
||||
});
|
||||
return promise.then(function(body) {
|
||||
assert_equals(body, "", "Resolved value should be empty");
|
||||
assert_false(response.bodyUsed);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function checkBodyArrayBuffer(test, response) {
|
||||
return response.arrayBuffer().then(function(bodyAsArrayBuffer) {
|
||||
assert_equals(bodyAsArrayBuffer.byteLength, 0, "Resolved value should be empty");
|
||||
assert_false(response.bodyUsed);
|
||||
});
|
||||
}
|
||||
|
||||
function checkBodyJSON(test, response) {
|
||||
return response.json().then(
|
||||
function(bodyAsJSON) {
|
||||
assert_unreached("JSON parsing should fail");
|
||||
},
|
||||
function() {
|
||||
assert_false(response.bodyUsed);
|
||||
});
|
||||
}
|
||||
|
||||
function checkBodyFormData(test, response) {
|
||||
return response.formData().then(function(bodyAsFormData) {
|
||||
assert_true(bodyAsFormData instanceof FormData, "Should receive a FormData");
|
||||
assert_false(response.bodyUsed);
|
||||
});
|
||||
}
|
||||
|
||||
function checkBodyFormDataError(test, response) {
|
||||
return promise_rejects_js(test, TypeError, response.formData()).then(function() {
|
||||
assert_false(response.bodyUsed);
|
||||
});
|
||||
}
|
||||
|
||||
function checkResponseWithNoBody(bodyType, checkFunction, headers = []) {
|
||||
promise_test(function(test) {
|
||||
var response = new Response(undefined, { "headers": headers });
|
||||
assert_false(response.bodyUsed);
|
||||
return checkFunction(test, response);
|
||||
}, "Consume response's body as " + bodyType);
|
||||
}
|
||||
|
||||
checkResponseWithNoBody("text", checkBodyText);
|
||||
checkResponseWithNoBody("blob", checkBodyBlob);
|
||||
checkResponseWithNoBody("arrayBuffer", checkBodyArrayBuffer);
|
||||
checkResponseWithNoBody("json (error case)", checkBodyJSON);
|
||||
checkResponseWithNoBody("formData with correct multipart type (error case)", checkBodyFormDataError, [["Content-Type", 'multipart/form-data; boundary="boundary"']]);
|
||||
checkResponseWithNoBody("formData with correct urlencoded type", checkBodyFormData, [["Content-Type", "application/x-www-form-urlencoded;charset=UTF-8"]]);
|
||||
checkResponseWithNoBody("formData without correct type (error case)", checkBodyFormDataError);
|
||||
|
||||
function checkResponseWithEmptyBody(bodyType, body, asText) {
|
||||
promise_test(function(test) {
|
||||
var response = new Response(body);
|
||||
assert_false(response.bodyUsed, "bodyUsed is false at init");
|
||||
if (asText) {
|
||||
return response.text().then(function(bodyAsString) {
|
||||
assert_equals(bodyAsString.length, 0, "Resolved value should be empty");
|
||||
assert_true(response.bodyUsed, "bodyUsed is true after being consumed");
|
||||
});
|
||||
}
|
||||
return response.arrayBuffer().then(function(bodyAsArrayBuffer) {
|
||||
assert_equals(bodyAsArrayBuffer.byteLength, 0, "Resolved value should be empty");
|
||||
assert_true(response.bodyUsed, "bodyUsed is true after being consumed");
|
||||
});
|
||||
}, "Consume empty " + bodyType + " response body as " + (asText ? "text" : "arrayBuffer"));
|
||||
}
|
||||
|
||||
checkResponseWithEmptyBody("blob", new Blob([], { "type" : "text/plain" }), false);
|
||||
checkResponseWithEmptyBody("text", "", false);
|
||||
checkResponseWithEmptyBody("blob", new Blob([], { "type" : "text/plain" }), true);
|
||||
checkResponseWithEmptyBody("text", "", true);
|
||||
checkResponseWithEmptyBody("URLSearchParams", new URLSearchParams(""), true);
|
||||
checkResponseWithEmptyBody("FormData", new FormData(), true);
|
||||
checkResponseWithEmptyBody("ArrayBuffer", new ArrayBuffer(), true);
|
|
@ -1,112 +0,0 @@
|
|||
<!doctype html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>Response consume empty bodies</title>
|
||||
<meta name="help" href="https://fetch.spec.whatwg.org/#response">
|
||||
<meta name="help" href="https://fetch.spec.whatwg.org/#body-mixin">
|
||||
<meta name="author" title="Canon Research France" href="https://www.crf.canon.fr">
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
<script>
|
||||
function checkBodyText(test, response) {
|
||||
return response.text().then(function(bodyAsText) {
|
||||
assert_equals(bodyAsText, "", "Resolved value should be empty");
|
||||
assert_false(response.bodyUsed);
|
||||
});
|
||||
}
|
||||
|
||||
function checkBodyBlob(test, response) {
|
||||
return response.blob().then(function(bodyAsBlob) {
|
||||
var promise = new Promise(function(resolve, reject) {
|
||||
var reader = new FileReader();
|
||||
reader.onload = function(evt) {
|
||||
resolve(reader.result)
|
||||
};
|
||||
reader.onerror = function() {
|
||||
reject("Blob's reader failed");
|
||||
};
|
||||
reader.readAsText(bodyAsBlob);
|
||||
});
|
||||
return promise.then(function(body) {
|
||||
assert_equals(body, "", "Resolved value should be empty");
|
||||
assert_false(response.bodyUsed);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function checkBodyArrayBuffer(test, response) {
|
||||
return response.arrayBuffer().then(function(bodyAsArrayBuffer) {
|
||||
assert_equals(bodyAsArrayBuffer.byteLength, 0, "Resolved value should be empty");
|
||||
assert_false(response.bodyUsed);
|
||||
});
|
||||
}
|
||||
|
||||
function checkBodyJSON(test, response) {
|
||||
return response.json().then(
|
||||
function(bodyAsJSON) {
|
||||
assert_unreached("JSON parsing should fail");
|
||||
},
|
||||
function() {
|
||||
assert_false(response.bodyUsed);
|
||||
});
|
||||
}
|
||||
|
||||
function checkBodyFormData(test, response) {
|
||||
return response.formData().then(function(bodyAsFormData) {
|
||||
assert_true(bodyAsFormData instanceof FormData, "Should receive a FormData");
|
||||
assert_false(response.bodyUsed);
|
||||
});
|
||||
}
|
||||
|
||||
function checkBodyFormDataError(test, response) {
|
||||
return promise_rejects_js(test, TypeError, response.formData()).then(function() {
|
||||
assert_false(response.bodyUsed);
|
||||
});
|
||||
}
|
||||
|
||||
function checkResponseWithNoBody(bodyType, checkFunction, headers = []) {
|
||||
promise_test(function(test) {
|
||||
var response = new Response(undefined, { "headers": headers });
|
||||
assert_false(response.bodyUsed);
|
||||
return checkFunction(test, response);
|
||||
}, "Consume response's body as " + bodyType);
|
||||
}
|
||||
|
||||
checkResponseWithNoBody("text", checkBodyText);
|
||||
checkResponseWithNoBody("blob", checkBodyBlob);
|
||||
checkResponseWithNoBody("arrayBuffer", checkBodyArrayBuffer);
|
||||
checkResponseWithNoBody("json (error case)", checkBodyJSON);
|
||||
checkResponseWithNoBody("formData with correct multipart type (error case)", checkBodyFormDataError, [["Content-Type", 'multipart/form-data; boundary="boundary"']]);
|
||||
checkResponseWithNoBody("formData with correct urlencoded type", checkBodyFormData, [["Content-Type", "application/x-www-form-urlencoded;charset=UTF-8"]]);
|
||||
checkResponseWithNoBody("formData without correct type (error case)", checkBodyFormDataError);
|
||||
|
||||
function checkResponseWithEmptyBody(bodyType, body, asText) {
|
||||
promise_test(function(test) {
|
||||
var response = new Response(body);
|
||||
assert_false(response.bodyUsed, "bodyUsed is false at init");
|
||||
if (asText) {
|
||||
return response.text().then(function(bodyAsString) {
|
||||
assert_equals(bodyAsString.length, 0, "Resolved value should be empty");
|
||||
assert_true(response.bodyUsed, "bodyUsed is true after being consumed");
|
||||
});
|
||||
}
|
||||
return response.arrayBuffer().then(function(bodyAsArrayBuffer) {
|
||||
assert_equals(bodyAsArrayBuffer.byteLength, 0, "Resolved value should be empty");
|
||||
assert_true(response.bodyUsed, "bodyUsed is true after being consumed");
|
||||
});
|
||||
}, "Consume empty " + bodyType + " response body as " + (asText ? "text" : "arrayBuffer"));
|
||||
}
|
||||
|
||||
checkResponseWithEmptyBody("blob", new Blob([], { "type" : "text/plain" }), false);
|
||||
checkResponseWithEmptyBody("text", "", false);
|
||||
checkResponseWithEmptyBody("blob", new Blob([], { "type" : "text/plain" }), true);
|
||||
checkResponseWithEmptyBody("text", "", true);
|
||||
checkResponseWithEmptyBody("URLSearchParams", new URLSearchParams(""), true);
|
||||
checkResponseWithEmptyBody("FormData", new FormData(), true);
|
||||
checkResponseWithEmptyBody("ArrayBuffer", new ArrayBuffer(), true);
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
|
@ -1,17 +1,6 @@
|
|||
<!doctype html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>Response consume</title>
|
||||
<meta name="help" href="https://fetch.spec.whatwg.org/#response">
|
||||
<meta name="help" href="https://fetch.spec.whatwg.org/#body-mixin">
|
||||
<meta name="author" title="Canon Research France" href="https://www.crf.canon.fr">
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
<script src="../resources/utils.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
<script>
|
||||
// META: global=window,worker
|
||||
// META: title=Response consume
|
||||
// META: script=../resources/utils.js
|
||||
|
||||
promise_test(function(test) {
|
||||
var body = "";
|
||||
|
@ -68,7 +57,3 @@ test(function() {
|
|||
test(function() {
|
||||
assert_equals(Response.redirect("/").body, null);
|
||||
}, "Getting a redirect Response stream");
|
||||
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,59 @@
|
|||
// META: global=window,worker
|
||||
// META: title=Response Receives Propagated Error from ReadableStream
|
||||
|
||||
function newStreamWithStartError() {
|
||||
var err = new Error("Start error");
|
||||
return [new ReadableStream({
|
||||
start(controller) {
|
||||
controller.error(err);
|
||||
}
|
||||
}),
|
||||
err]
|
||||
}
|
||||
|
||||
function newStreamWithPullError() {
|
||||
var err = new Error("Pull error");
|
||||
return [new ReadableStream({
|
||||
pull(controller) {
|
||||
controller.error(err);
|
||||
}
|
||||
}),
|
||||
err]
|
||||
}
|
||||
|
||||
function runRequestPromiseTest([stream, err], responseReaderMethod, testDescription) {
|
||||
promise_test(test => {
|
||||
return promise_rejects_exactly(
|
||||
test,
|
||||
err,
|
||||
new Response(stream)[responseReaderMethod](),
|
||||
'CustomTestError should propagate'
|
||||
)
|
||||
}, testDescription)
|
||||
}
|
||||
|
||||
|
||||
promise_test(test => {
|
||||
var [stream, err] = newStreamWithStartError();
|
||||
return promise_rejects_exactly(test, err, stream.getReader().read(), 'CustomTestError should propagate')
|
||||
}, "ReadableStreamDefaultReader Promise receives ReadableStream start() Error")
|
||||
|
||||
promise_test(test => {
|
||||
var [stream, err] = newStreamWithPullError();
|
||||
return promise_rejects_exactly(test, err, stream.getReader().read(), 'CustomTestError should propagate')
|
||||
}, "ReadableStreamDefaultReader Promise receives ReadableStream pull() Error")
|
||||
|
||||
|
||||
// test start() errors for all Body reader methods
|
||||
runRequestPromiseTest(newStreamWithStartError(), 'arrayBuffer', 'ReadableStream start() Error propagates to Response.arrayBuffer() Promise');
|
||||
runRequestPromiseTest(newStreamWithStartError(), 'blob', 'ReadableStream start() Error propagates to Response.blob() Promise');
|
||||
runRequestPromiseTest(newStreamWithStartError(), 'formData', 'ReadableStream start() Error propagates to Response.formData() Promise');
|
||||
runRequestPromiseTest(newStreamWithStartError(), 'json', 'ReadableStream start() Error propagates to Response.json() Promise');
|
||||
runRequestPromiseTest(newStreamWithStartError(), 'text', 'ReadableStream start() Error propagates to Response.text() Promise');
|
||||
|
||||
// test pull() errors for all Body reader methods
|
||||
runRequestPromiseTest(newStreamWithPullError(), 'arrayBuffer', 'ReadableStream pull() Error propagates to Response.arrayBuffer() Promise');
|
||||
runRequestPromiseTest(newStreamWithPullError(), 'blob', 'ReadableStream pull() Error propagates to Response.blob() Promise');
|
||||
runRequestPromiseTest(newStreamWithPullError(), 'formData', 'ReadableStream pull() Error propagates to Response.formData() Promise');
|
||||
runRequestPromiseTest(newStreamWithPullError(), 'json', 'ReadableStream pull() Error propagates to Response.json() Promise');
|
||||
runRequestPromiseTest(newStreamWithPullError(), 'text', 'ReadableStream pull() Error propagates to Response.text() Promise');
|
|
@ -1,69 +0,0 @@
|
|||
<!doctype html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>Response Receives Propagated Error from ReadableStream</title>
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
<script>
|
||||
function newStreamWithStartError() {
|
||||
var err = new Error("Start error");
|
||||
return [new ReadableStream({
|
||||
start(controller) {
|
||||
controller.error(err);
|
||||
}
|
||||
}),
|
||||
err]
|
||||
}
|
||||
|
||||
function newStreamWithPullError() {
|
||||
var err = new Error("Pull error");
|
||||
return [new ReadableStream({
|
||||
pull(controller) {
|
||||
controller.error(err);
|
||||
}
|
||||
}),
|
||||
err]
|
||||
}
|
||||
|
||||
function runRequestPromiseTest([stream, err], responseReaderMethod, testDescription) {
|
||||
promise_test(test => {
|
||||
return promise_rejects_exactly(
|
||||
test,
|
||||
err,
|
||||
new Response(stream)[responseReaderMethod](),
|
||||
'CustomTestError should propagate'
|
||||
)
|
||||
}, testDescription)
|
||||
}
|
||||
|
||||
|
||||
promise_test(test => {
|
||||
var [stream, err] = newStreamWithStartError();
|
||||
return promise_rejects_exactly(test, err, stream.getReader().read(), 'CustomTestError should propagate')
|
||||
}, "ReadableStreamDefaultReader Promise receives ReadableStream start() Error")
|
||||
|
||||
promise_test(test => {
|
||||
var [stream, err] = newStreamWithPullError();
|
||||
return promise_rejects_exactly(test, err, stream.getReader().read(), 'CustomTestError should propagate')
|
||||
}, "ReadableStreamDefaultReader Promise receives ReadableStream pull() Error")
|
||||
|
||||
|
||||
// test start() errors for all Body reader methods
|
||||
runRequestPromiseTest(newStreamWithStartError(), 'arrayBuffer', 'ReadableStream start() Error propagates to Response.arrayBuffer() Promise');
|
||||
runRequestPromiseTest(newStreamWithStartError(), 'blob', 'ReadableStream start() Error propagates to Response.blob() Promise');
|
||||
runRequestPromiseTest(newStreamWithStartError(), 'formData', 'ReadableStream start() Error propagates to Response.formData() Promise');
|
||||
runRequestPromiseTest(newStreamWithStartError(), 'json', 'ReadableStream start() Error propagates to Response.json() Promise');
|
||||
runRequestPromiseTest(newStreamWithStartError(), 'text', 'ReadableStream start() Error propagates to Response.text() Promise');
|
||||
|
||||
// test pull() errors for all Body reader methods
|
||||
runRequestPromiseTest(newStreamWithPullError(), 'arrayBuffer', 'ReadableStream pull() Error propagates to Response.arrayBuffer() Promise');
|
||||
runRequestPromiseTest(newStreamWithPullError(), 'blob', 'ReadableStream pull() Error propagates to Response.blob() Promise');
|
||||
runRequestPromiseTest(newStreamWithPullError(), 'formData', 'ReadableStream pull() Error propagates to Response.formData() Promise');
|
||||
runRequestPromiseTest(newStreamWithPullError(), 'json', 'ReadableStream pull() Error propagates to Response.json() Promise');
|
||||
runRequestPromiseTest(newStreamWithPullError(), 'text', 'ReadableStream pull() Error propagates to Response.text() Promise');
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,27 @@
|
|||
// META: global=window,worker
|
||||
// META: title=Response error
|
||||
|
||||
var invalidStatus = [0, 100, 199, 600, 1000];
|
||||
invalidStatus.forEach(function(status) {
|
||||
test(function() {
|
||||
assert_throws_js(RangeError, function() { new Response("", { "status" : status }); },
|
||||
"Expect RangeError exception when status is " + status);
|
||||
},"Throws RangeError when responseInit's status is " + status);
|
||||
});
|
||||
|
||||
var invalidStatusText = ["\n", "Ā"];
|
||||
invalidStatusText.forEach(function(statusText) {
|
||||
test(function() {
|
||||
assert_throws_js(TypeError, function() { new Response("", { "statusText" : statusText }); },
|
||||
"Expect TypeError exception " + statusText);
|
||||
},"Throws TypeError when responseInit's statusText is " + statusText);
|
||||
});
|
||||
|
||||
var nullBodyStatus = [204, 205, 304];
|
||||
nullBodyStatus.forEach(function(status) {
|
||||
test(function() {
|
||||
assert_throws_js(TypeError,
|
||||
function() { new Response("body", {"status" : status }); },
|
||||
"Expect TypeError exception ");
|
||||
},"Throws TypeError when building a response with body and a body status of " + status);
|
||||
});
|
|
@ -1,39 +0,0 @@
|
|||
<!doctype html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>Response error</title>
|
||||
<meta name="help" href="https://fetch.spec.whatwg.org/#response">
|
||||
<meta name="author" title="Canon Research France" href="https://www.crf.canon.fr">
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
<script>
|
||||
var invalidStatus = [0, 100, 199, 600, 1000];
|
||||
invalidStatus.forEach(function(status) {
|
||||
test(function() {
|
||||
assert_throws_js(RangeError, function() { new Response("", { "status" : status }); },
|
||||
"Expect RangeError exception when status is " + status);
|
||||
},"Throws RangeError when responseInit's status is " + status);
|
||||
});
|
||||
|
||||
var invalidStatusText = ["\n", "Ā"];
|
||||
invalidStatusText.forEach(function(statusText) {
|
||||
test(function() {
|
||||
assert_throws_js(TypeError, function() { new Response("", { "statusText" : statusText }); },
|
||||
"Expect TypeError exception " + statusText);
|
||||
},"Throws TypeError when responseInit's statusText is " + statusText);
|
||||
});
|
||||
|
||||
var nullBodyStatus = [204, 205, 304];
|
||||
nullBodyStatus.forEach(function(status) {
|
||||
test(function() {
|
||||
assert_throws_js(TypeError,
|
||||
function() { new Response("body", {"status" : status }); },
|
||||
"Expect TypeError exception ");
|
||||
},"Throws TypeError when building a response with body and a body status of " + status);
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,64 @@
|
|||
// META: global=window,worker
|
||||
// META: title=Response init: simple cases
|
||||
|
||||
var defaultValues = { "type" : "default",
|
||||
"url" : "",
|
||||
"ok" : true,
|
||||
"status" : 200,
|
||||
"statusText" : "",
|
||||
"body" : null
|
||||
};
|
||||
|
||||
var statusCodes = { "givenValues" : [200, 300, 400, 500, 599],
|
||||
"expectedValues" : [200, 300, 400, 500, 599]
|
||||
};
|
||||
var statusTexts = { "givenValues" : ["", "OK", "with space", String.fromCharCode(0x80)],
|
||||
"expectedValues" : ["", "OK", "with space", String.fromCharCode(0x80)]
|
||||
};
|
||||
var initValuesDict = { "status" : statusCodes,
|
||||
"statusText" : statusTexts
|
||||
};
|
||||
|
||||
function isOkStatus(status) {
|
||||
return 200 <= status && 299 >= status;
|
||||
}
|
||||
|
||||
var response = new Response();
|
||||
for (var attributeName in defaultValues) {
|
||||
test(function() {
|
||||
var expectedValue = defaultValues[attributeName];
|
||||
assert_equals(response[attributeName], expectedValue,
|
||||
"Expect default response." + attributeName + " is " + expectedValue);
|
||||
}, "Check default value for " + attributeName + " attribute");
|
||||
}
|
||||
|
||||
for (var attributeName in initValuesDict) {
|
||||
test(function() {
|
||||
var valuesToTest = initValuesDict[attributeName];
|
||||
for (var valueIdx in valuesToTest["givenValues"]) {
|
||||
var givenValue = valuesToTest["givenValues"][valueIdx];
|
||||
var expectedValue = valuesToTest["expectedValues"][valueIdx];
|
||||
var responseInit = {};
|
||||
responseInit[attributeName] = givenValue;
|
||||
var response = new Response("", responseInit);
|
||||
assert_equals(response[attributeName], expectedValue,
|
||||
"Expect response." + attributeName + " is " + expectedValue +
|
||||
" when initialized with " + givenValue);
|
||||
assert_equals(response.ok, isOkStatus(response.status),
|
||||
"Expect response.ok is " + isOkStatus(response.status));
|
||||
}
|
||||
}, "Check " + attributeName + " init values and associated getter");
|
||||
}
|
||||
|
||||
test(function() {
|
||||
const response1 = new Response("");
|
||||
assert_equals(response1.headers, response1.headers);
|
||||
|
||||
const response2 = new Response("", {"headers": {"X-Foo": "bar"}});
|
||||
assert_equals(response2.headers, response2.headers);
|
||||
const headers = response2.headers;
|
||||
response2.headers.set("X-Foo", "quux");
|
||||
assert_equals(headers, response2.headers);
|
||||
headers.set("X-Other-Header", "baz");
|
||||
assert_equals(headers, response2.headers);
|
||||
}, "Test that Response.headers has the [SameObject] extended attribute");
|
|
@ -1,77 +0,0 @@
|
|||
<!doctype html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>Response init: simple cases</title>
|
||||
<meta name="help" href="https://fetch.spec.whatwg.org/#response">
|
||||
<meta name="help" href="https://fetch.spec.whatwg.org/#concept-response">
|
||||
<meta name="author" title="Canon Research France" href="https://www.crf.canon.fr">
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
<script>
|
||||
var defaultValues = { "type" : "default",
|
||||
"url" : "",
|
||||
"ok" : true,
|
||||
"status" : 200,
|
||||
"statusText" : "",
|
||||
"body" : null
|
||||
};
|
||||
|
||||
var statusCodes = { "givenValues" : [200, 300, 400, 500, 599],
|
||||
"expectedValues" : [200, 300, 400, 500, 599]
|
||||
};
|
||||
var statusTexts = { "givenValues" : ["", "OK", "with space", String.fromCharCode(0x80)],
|
||||
"expectedValues" : ["", "OK", "with space", String.fromCharCode(0x80)]
|
||||
};
|
||||
var initValuesDict = { "status" : statusCodes,
|
||||
"statusText" : statusTexts
|
||||
};
|
||||
|
||||
function isOkStatus(status) {
|
||||
return 200 <= status && 299 >= status;
|
||||
}
|
||||
|
||||
var response = new Response();
|
||||
for (var attributeName in defaultValues) {
|
||||
test(function() {
|
||||
var expectedValue = defaultValues[attributeName];
|
||||
assert_equals(response[attributeName], expectedValue,
|
||||
"Expect default response." + attributeName + " is " + expectedValue);
|
||||
}, "Check default value for " + attributeName + " attribute");
|
||||
}
|
||||
|
||||
for (var attributeName in initValuesDict) {
|
||||
test(function() {
|
||||
var valuesToTest = initValuesDict[attributeName];
|
||||
for (var valueIdx in valuesToTest["givenValues"]) {
|
||||
var givenValue = valuesToTest["givenValues"][valueIdx];
|
||||
var expectedValue = valuesToTest["expectedValues"][valueIdx];
|
||||
var responseInit = {};
|
||||
responseInit[attributeName] = givenValue;
|
||||
var response = new Response("", responseInit);
|
||||
assert_equals(response[attributeName], expectedValue,
|
||||
"Expect response." + attributeName + " is " + expectedValue +
|
||||
" when initialized with " + givenValue);
|
||||
assert_equals(response.ok, isOkStatus(response.status),
|
||||
"Expect response.ok is " + isOkStatus(response.status));
|
||||
}
|
||||
}, "Check " + attributeName + " init values and associated getter");
|
||||
}
|
||||
|
||||
test(function() {
|
||||
const response1 = new Response("");
|
||||
assert_equals(response1.headers, response1.headers);
|
||||
|
||||
const response2 = new Response("", {"headers": {"X-Foo": "bar"}});
|
||||
assert_equals(response2.headers, response2.headers);
|
||||
const headers = response2.headers;
|
||||
response2.headers.set("X-Foo", "quux");
|
||||
assert_equals(headers, response2.headers);
|
||||
headers.set("X-Other-Header", "baz");
|
||||
assert_equals(headers, response2.headers);
|
||||
}, "Test that Response.headers has the [SameObject] extended attribute");
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,61 @@
|
|||
// META: global=window,worker
|
||||
// META: title=Response init: body and headers
|
||||
// META: script=../resources/utils.js
|
||||
|
||||
test(function() {
|
||||
var headerDict = {"name1": "value1",
|
||||
"name2": "value2",
|
||||
"name3": "value3"
|
||||
};
|
||||
var headers = new Headers(headerDict);
|
||||
var response = new Response("", { "headers" : headers })
|
||||
for (var name in headerDict) {
|
||||
assert_equals(response.headers.get(name), headerDict[name],
|
||||
"response's headers has " + name + " : " + headerDict[name]);
|
||||
}
|
||||
}, "Initialize Response with headers values");
|
||||
|
||||
function checkResponseInit(body, bodyType, expectedTextBody) {
|
||||
promise_test(function(test) {
|
||||
var response = new Response(body);
|
||||
var resHeaders = response.headers;
|
||||
var mime = resHeaders.get("Content-Type");
|
||||
assert_true(mime && mime.search(bodyType) > -1, "Content-Type header should be \"" + bodyType + "\" ");
|
||||
return response.text().then(function(bodyAsText) {
|
||||
//not equals: cannot guess formData exact value
|
||||
assert_true(bodyAsText.search(expectedTextBody) > -1, "Retrieve and verify response body");
|
||||
});
|
||||
}, "Initialize Response's body with " + bodyType);
|
||||
}
|
||||
|
||||
var blob = new Blob(["This is a blob"], {type: "application/octet-binary"});
|
||||
var formaData = new FormData();
|
||||
formaData.append("name", "value");
|
||||
var urlSearchParams = "URLSearchParams are not supported";
|
||||
//avoid test timeout if not implemented
|
||||
if (self.URLSearchParams)
|
||||
urlSearchParams = new URLSearchParams("name=value");
|
||||
var usvString = "This is a USVString"
|
||||
|
||||
checkResponseInit(blob, "application/octet-binary", "This is a blob");
|
||||
checkResponseInit(formaData, "multipart/form-data", "name=\"name\"\r\n\r\nvalue");
|
||||
checkResponseInit(urlSearchParams, "application/x-www-form-urlencoded;charset=UTF-8", "name=value");
|
||||
checkResponseInit(usvString, "text/plain;charset=UTF-8", "This is a USVString");
|
||||
|
||||
promise_test(function(test) {
|
||||
var body = "This is response body";
|
||||
var response = new Response(body);
|
||||
return validateStreamFromString(response.body.getReader(), body);
|
||||
}, "Read Response's body as readableStream");
|
||||
|
||||
promise_test(function(test) {
|
||||
var response = new Response("This is my fork", {"headers" : [["Content-Type", ""]]});
|
||||
return response.blob().then(function(blob) {
|
||||
assert_equals(blob.type, "", "Blob type should be the empty string");
|
||||
});
|
||||
}, "Testing empty Response Content-Type header");
|
||||
|
||||
test(function() {
|
||||
var response = new Response(null, {status: 204});
|
||||
assert_equals(response.body, null);
|
||||
}, "Testing null Response body");
|
|
@ -1,75 +0,0 @@
|
|||
<!doctype html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>Response init: body and headers</title>
|
||||
<meta name="help" href="https://fetch.spec.whatwg.org/#response">
|
||||
<meta name="help" href="https://fetch.spec.whatwg.org/#concept-response">
|
||||
<meta name="author" title="Canon Research France" href="https://www.crf.canon.fr">
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
<script src="../resources/utils.js"></script>
|
||||
<script>
|
||||
test(function() {
|
||||
var headerDict = {"name1": "value1",
|
||||
"name2": "value2",
|
||||
"name3": "value3"
|
||||
};
|
||||
var headers = new Headers(headerDict);
|
||||
var response = new Response("", { "headers" : headers })
|
||||
for (var name in headerDict) {
|
||||
assert_equals(response.headers.get(name), headerDict[name],
|
||||
"response's headers has " + name + " : " + headerDict[name]);
|
||||
}
|
||||
}, "Initialize Response with headers values");
|
||||
|
||||
function checkResponseInit(body, bodyType, expectedTextBody) {
|
||||
promise_test(function(test) {
|
||||
var response = new Response(body);
|
||||
var resHeaders = response.headers;
|
||||
var mime = resHeaders.get("Content-Type");
|
||||
assert_true(mime && mime.search(bodyType) > -1, "Content-Type header should be \"" + bodyType + "\" ");
|
||||
return response.text().then(function(bodyAsText) {
|
||||
//not equals: cannot guess formData exact value
|
||||
assert_true(bodyAsText.search(expectedTextBody) > -1, "Retrieve and verify response body");
|
||||
});
|
||||
}, "Initialize Response's body with " + bodyType);
|
||||
}
|
||||
|
||||
var blob = new Blob(["This is a blob"], {type: "application/octet-binary"});
|
||||
var formaData = new FormData();
|
||||
formaData.append("name", "value");
|
||||
var urlSearchParams = "URLSearchParams are not supported";
|
||||
//avoid test timeout if not implemented
|
||||
if (window.URLSearchParams)
|
||||
urlSearchParams = new URLSearchParams("name=value");
|
||||
var usvString = "This is a USVString"
|
||||
|
||||
checkResponseInit(blob, "application/octet-binary", "This is a blob");
|
||||
checkResponseInit(formaData, "multipart/form-data", "name=\"name\"\r\n\r\nvalue");
|
||||
checkResponseInit(urlSearchParams, "application/x-www-form-urlencoded;charset=UTF-8", "name=value");
|
||||
checkResponseInit(usvString, "text/plain;charset=UTF-8", "This is a USVString");
|
||||
|
||||
promise_test(function(test) {
|
||||
var body = "This is response body";
|
||||
var response = new Response(body);
|
||||
return validateStreamFromString(response.body.getReader(), body);
|
||||
}, "Read Response's body as readableStream");
|
||||
|
||||
promise_test(function(test) {
|
||||
var response = new Response("This is my fork", {"headers" : [["Content-Type", ""]]});
|
||||
return response.blob().then(function(blob) {
|
||||
assert_equals(blob.type, "", "Blob type should be the empty string");
|
||||
});
|
||||
}, "Testing empty Response Content-Type header");
|
||||
|
||||
test(function() {
|
||||
var response = new Response(null, {status: 204});
|
||||
assert_equals(response.body, null);
|
||||
}, "Testing null Response body");
|
||||
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,22 @@
|
|||
// META: global=window,worker
|
||||
// META: title=Response: error static method
|
||||
|
||||
test(function() {
|
||||
var responseError = Response.error();
|
||||
assert_equals(responseError.type, "error", "Network error response's type is error");
|
||||
assert_equals(responseError.status, 0, "Network error response's status is 0");
|
||||
assert_equals(responseError.statusText, "", "Network error response's statusText is empty");
|
||||
assert_equals(responseError.body, null, "Network error response's body is null");
|
||||
|
||||
assert_true(responseError.headers.entries().next().done, "Headers should be empty");
|
||||
}, "Check response returned by static method error()");
|
||||
|
||||
test(function() {
|
||||
const headers = Response.error().headers;
|
||||
|
||||
// Avoid false positives if expected API is not available
|
||||
assert_true(!!headers);
|
||||
assert_equals(typeof headers.append, 'function');
|
||||
|
||||
assert_throws_js(TypeError, function () { headers.append('name', 'value'); });
|
||||
}, "the 'guard' of the Headers instance should be immutable");
|
|
@ -1,35 +0,0 @@
|
|||
<!doctype html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>Response: error static method</title>
|
||||
<meta name="help" href="https://fetch.spec.whatwg.org/#response">
|
||||
<meta name="help" href="https://fetch.spec.whatwg.org/#concept-network-error">
|
||||
<meta name="author" title="Canon Research France" href="https://www.crf.canon.fr">
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
<script>
|
||||
test(function() {
|
||||
var responseError = Response.error();
|
||||
assert_equals(responseError.type, "error", "Network error response's type is error");
|
||||
assert_equals(responseError.status, 0, "Network error response's status is 0");
|
||||
assert_equals(responseError.statusText, "", "Network error response's statusText is empty");
|
||||
assert_equals(responseError.body, null, "Network error response's body is null");
|
||||
|
||||
assert_true(responseError.headers.entries().next().done, "Headers should be empty");
|
||||
}, "Check response returned by static method error()");
|
||||
|
||||
test(function() {
|
||||
const headers = Response.error().headers;
|
||||
|
||||
// Avoid false positives if expected API is not available
|
||||
assert_true(!!headers);
|
||||
assert_equals(typeof headers.append, 'function');
|
||||
|
||||
assert_throws_js(TypeError, function () { headers.append('name', 'value'); });
|
||||
}, "the 'guard' of the Headers instance should be immutable");
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,40 @@
|
|||
// META: global=window,worker
|
||||
// META: title=Response: redirect static method
|
||||
|
||||
var url = "http://test.url:1234/";
|
||||
test(function() {
|
||||
redirectResponse = Response.redirect(url);
|
||||
assert_equals(redirectResponse.type, "default");
|
||||
assert_false(redirectResponse.redirected);
|
||||
assert_false(redirectResponse.ok);
|
||||
assert_equals(redirectResponse.status, 302, "Default redirect status is 302");
|
||||
assert_equals(redirectResponse.headers.get("Location"), url,
|
||||
"redirected response has Location header with the correct url");
|
||||
assert_equals(redirectResponse.statusText, "");
|
||||
}, "Check default redirect response");
|
||||
|
||||
[301, 302, 303, 307, 308].forEach(function(status) {
|
||||
test(function() {
|
||||
redirectResponse = Response.redirect(url, status);
|
||||
assert_equals(redirectResponse.type, "default");
|
||||
assert_false(redirectResponse.redirected);
|
||||
assert_false(redirectResponse.ok);
|
||||
assert_equals(redirectResponse.status, status, "Redirect status is " + status);
|
||||
assert_equals(redirectResponse.headers.get("Location"), url);
|
||||
assert_equals(redirectResponse.statusText, "");
|
||||
}, "Check response returned by static method redirect(), status = " + status);
|
||||
});
|
||||
|
||||
test(function() {
|
||||
var invalidUrl = "http://:This is not an url";
|
||||
assert_throws_js(TypeError, function() { Response.redirect(invalidUrl); },
|
||||
"Expect TypeError exception");
|
||||
}, "Check error returned when giving invalid url to redirect()");
|
||||
|
||||
var invalidRedirectStatus = [200, 309, 400, 500];
|
||||
invalidRedirectStatus.forEach(function(invalidStatus) {
|
||||
test(function() {
|
||||
assert_throws_js(RangeError, function() { Response.redirect(url, invalidStatus); },
|
||||
"Expect RangeError exception");
|
||||
}, "Check error returned when giving invalid status to redirect(), status = " + invalidStatus);
|
||||
});
|
|
@ -1,53 +0,0 @@
|
|||
<!doctype html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>Response: redirect static method</title>
|
||||
<meta name="help" href="https://fetch.spec.whatwg.org/#response">
|
||||
<meta name="help" href="https://fetch.spec.whatwg.org/#redirect-status">
|
||||
<meta name="author" title="Canon Research France" href="https://www.crf.canon.fr">
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
<script>
|
||||
var url = "http://test.url:1234/";
|
||||
test(function() {
|
||||
redirectResponse = Response.redirect(url);
|
||||
assert_equals(redirectResponse.type, "default");
|
||||
assert_false(redirectResponse.redirected);
|
||||
assert_false(redirectResponse.ok);
|
||||
assert_equals(redirectResponse.status, 302, "Default redirect status is 302");
|
||||
assert_equals(redirectResponse.headers.get("Location"), url,
|
||||
"redirected response has Location header with the correct url");
|
||||
assert_equals(redirectResponse.statusText, "");
|
||||
}, "Check default redirect response");
|
||||
|
||||
[301, 302, 303, 307, 308].forEach(function(status) {
|
||||
test(function() {
|
||||
redirectResponse = Response.redirect(url, status);
|
||||
assert_equals(redirectResponse.type, "default");
|
||||
assert_false(redirectResponse.redirected);
|
||||
assert_false(redirectResponse.ok);
|
||||
assert_equals(redirectResponse.status, status, "Redirect status is " + status);
|
||||
assert_equals(redirectResponse.headers.get("Location"), url);
|
||||
assert_equals(redirectResponse.statusText, "");
|
||||
}, "Check response returned by static method redirect(), status = " + status);
|
||||
});
|
||||
|
||||
test(function() {
|
||||
var invalidUrl = "http://:This is not an url";
|
||||
assert_throws_js(TypeError, function() { Response.redirect(invalidUrl); },
|
||||
"Expect TypeError exception");
|
||||
}, "Check error returned when giving invalid url to redirect()");
|
||||
|
||||
var invalidRedirectStatus = [200, 309, 400, 500];
|
||||
invalidRedirectStatus.forEach(function(invalidStatus) {
|
||||
test(function() {
|
||||
assert_throws_js(RangeError, function() { Response.redirect(url, invalidStatus); },
|
||||
"Expect RangeError exception");
|
||||
}, "Check error returned when giving invalid status to redirect(), status = " + invalidStatus);
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
|
@ -1,16 +1,5 @@
|
|||
<!doctype html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>Consuming Response body after getting a ReadableStream</title>
|
||||
<meta name="help" href="https://fetch.spec.whatwg.org/#response">
|
||||
<meta name="help" href="https://fetch.spec.whatwg.org/#body-mixin">
|
||||
<meta name="author" title="Canon Research France" href="https://www.crf.canon.fr">
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
<script>
|
||||
// META: global=window,worker
|
||||
// META: title=Consuming Response body after getting a ReadableStream
|
||||
|
||||
function createResponseWithReadableStream(callback) {
|
||||
return fetch("../resources/data.json").then(function(response) {
|
||||
|
@ -51,7 +40,3 @@ promise_test(function() {
|
|||
});
|
||||
});
|
||||
}, "Getting arrayBuffer after getting the Response body - not disturbed, not locked");
|
||||
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
|
@ -1,16 +1,5 @@
|
|||
<!doctype html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>Consuming Response body after getting a ReadableStream</title>
|
||||
<meta name="help" href="https://fetch.spec.whatwg.org/#response">
|
||||
<meta name="help" href="https://fetch.spec.whatwg.org/#body-mixin">
|
||||
<meta name="author" title="Canon Research France" href="https://www.crf.canon.fr">
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
<script>
|
||||
// META: global=window,worker
|
||||
// META: title=Consuming Response body after getting a ReadableStream
|
||||
|
||||
function createResponseWithLockedReadableStream(callback) {
|
||||
return fetch("../resources/data.json").then(function(response) {
|
||||
|
@ -42,7 +31,3 @@ promise_test(function(test) {
|
|||
return promise_rejects_js(test, TypeError, response.arrayBuffer());
|
||||
});
|
||||
}, "Getting arrayBuffer after getting a locked Response body");
|
||||
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
|
@ -1,16 +1,5 @@
|
|||
<!doctype html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>Consuming Response body after getting a ReadableStream</title>
|
||||
<meta name="help" href="https://fetch.spec.whatwg.org/#response">
|
||||
<meta name="help" href="https://fetch.spec.whatwg.org/#body-mixin">
|
||||
<meta name="author" title="Canon Research France" href="https://www.crf.canon.fr">
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
<script>
|
||||
// META: global=window,worker
|
||||
// META: title=Consuming Response body after getting a ReadableStream
|
||||
|
||||
function createResponseWithDisturbedReadableStream(callback) {
|
||||
return fetch("../resources/data.json").then(function(response) {
|
||||
|
@ -43,7 +32,3 @@ promise_test(function(test) {
|
|||
return promise_rejects_js(test, TypeError, response.arrayBuffer());
|
||||
});
|
||||
}, "Getting arrayBuffer after reading the Response body");
|
||||
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Add a link
Reference in a new issue