diff options
author | Matt A. Tobin <mattatobin@localhost.localdomain> | 2018-02-02 04:16:08 -0500 |
---|---|---|
committer | Matt A. Tobin <mattatobin@localhost.localdomain> | 2018-02-02 04:16:08 -0500 |
commit | 5f8de423f190bbb79a62f804151bc24824fa32d8 (patch) | |
tree | 10027f336435511475e392454359edea8e25895d /testing/web-platform/tests/fetch/api/basic | |
parent | 49ee0794b5d912db1f95dce6eb52d781dc210db5 (diff) | |
download | UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.gz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.lz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.xz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.zip |
Add m-esr52 at 52.6.0
Diffstat (limited to 'testing/web-platform/tests/fetch/api/basic')
46 files changed, 1097 insertions, 0 deletions
diff --git a/testing/web-platform/tests/fetch/api/basic/accept-header-worker.html b/testing/web-platform/tests/fetch/api/basic/accept-header-worker.html new file mode 100644 index 000000000..4d5b32205 --- /dev/null +++ b/testing/web-platform/tests/fetch/api/basic/accept-header-worker.html @@ -0,0 +1,16 @@ +<!doctype html> +<html> + <head> + <meta charset="utf-8"> + <title>Fetch in worker: accept header</title> + <meta name="help" href="https://fetch.spec.whatwg.org/#fetching"> + <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> + fetch_tests_from_worker(new Worker("accept-header.js")); + </script> + </body> +</html>
\ No newline at end of file diff --git a/testing/web-platform/tests/fetch/api/basic/accept-header.html b/testing/web-platform/tests/fetch/api/basic/accept-header.html new file mode 100644 index 000000000..cd9550fb2 --- /dev/null +++ b/testing/web-platform/tests/fetch/api/basic/accept-header.html @@ -0,0 +1,15 @@ +<!doctype html> +<html> + <head> + <meta charset="utf-8"> + <title>Fetch: accept header</title> + <meta name="help" href="https://fetch.spec.whatwg.org/#fetching"> + <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 src="accept-header.js"></script> + </body> +</html>
\ No newline at end of file diff --git a/testing/web-platform/tests/fetch/api/basic/accept-header.js b/testing/web-platform/tests/fetch/api/basic/accept-header.js new file mode 100644 index 000000000..3cf9ba3b0 --- /dev/null +++ b/testing/web-platform/tests/fetch/api/basic/accept-header.js @@ -0,0 +1,38 @@ +if (this.document === undefined) { + importScripts("/resources/testharness.js"); + importScripts("../resources/utils.js"); +} + +promise_test(function() { + return fetch(RESOURCES_DIR + "inspect-headers.py?headers=Accept").then(function(response) { + assert_equals(response.status, 200, "HTTP status is 200"); + assert_equals(response.type , "basic", "Response's type is basic"); + assert_equals(response.headers.get("x-request-accept"), "*/*", "Request has accept header with value '*/*'"); + }); +}, "Request through fetch should have 'accept' header with value '*/*'"); + +promise_test(function() { + return fetch(RESOURCES_DIR + "inspect-headers.py?headers=Accept", {"headers": [["Accept", "custom/*"]]}).then(function(response) { + assert_equals(response.status, 200, "HTTP status is 200"); + assert_equals(response.type , "basic", "Response's type is basic"); + assert_equals(response.headers.get("x-request-accept"), "custom/*", "Request has accept header with value 'custom/*'"); + }); +}, "Request through fetch should have 'accept' header with value 'custom/*'"); + +promise_test(function() { + return fetch(RESOURCES_DIR + "inspect-headers.py?headers=Accept-Language").then(function(response) { + assert_equals(response.status, 200, "HTTP status is 200"); + assert_equals(response.type , "basic", "Response's type is basic"); + assert_true(response.headers.has("x-request-accept-language")); + }); +}, "Request through fetch should have a 'accept-language' header"); + +promise_test(function() { + return fetch(RESOURCES_DIR + "inspect-headers.py?headers=Accept-Language", {"headers": [["Accept-Language", "bzh"]]}).then(function(response) { + assert_equals(response.status, 200, "HTTP status is 200"); + assert_equals(response.type , "basic", "Response's type is basic"); + assert_equals(response.headers.get("x-request-accept-language"), "bzh", "Request has accept header with value 'bzh'"); + }); +}, "Request through fetch should have 'accept-language' header with value 'bzh'"); + +done(); diff --git a/testing/web-platform/tests/fetch/api/basic/integrity-sharedworker.html b/testing/web-platform/tests/fetch/api/basic/integrity-sharedworker.html new file mode 100644 index 000000000..fa90a60ce --- /dev/null +++ b/testing/web-platform/tests/fetch/api/basic/integrity-sharedworker.html @@ -0,0 +1,15 @@ +<!doctype html> +<html> + <head> + <meta charset="utf-8"> + <title>Fetch in sharedworker: integrity handling</title> + <meta name="help" href="https://fetch.spec.whatwg.org/#main-fetch"> + <script src="/resources/testharness.js"></script> + <script src="/resources/testharnessreport.js"></script> + </head> + <body> + <script> + fetch_tests_from_worker(new SharedWorker("integrity.js?pipe=sub")); + </script> + </body> +</html> diff --git a/testing/web-platform/tests/fetch/api/basic/integrity-worker.html b/testing/web-platform/tests/fetch/api/basic/integrity-worker.html new file mode 100644 index 000000000..9240bc632 --- /dev/null +++ b/testing/web-platform/tests/fetch/api/basic/integrity-worker.html @@ -0,0 +1,16 @@ +<!doctype html> +<html> + <head> + <meta charset="utf-8"> + <title>Fetch in worker: integrity handling</title> + <meta name="author" title="Canon Research France" href="https://www.crf.canon.fr"> + <meta name="help" href="https://fetch.spec.whatwg.org/#main-fetch"> + <script src="/resources/testharness.js"></script> + <script src="/resources/testharnessreport.js"></script> + </head> + <body> + <script> + fetch_tests_from_worker(new Worker("integrity.js?pipe=sub")); + </script> + </body> +</html>
\ No newline at end of file diff --git a/testing/web-platform/tests/fetch/api/basic/integrity.html b/testing/web-platform/tests/fetch/api/basic/integrity.html new file mode 100644 index 000000000..150c9b71d --- /dev/null +++ b/testing/web-platform/tests/fetch/api/basic/integrity.html @@ -0,0 +1,15 @@ +<!doctype html> +<html> + <head> + <meta charset="utf-8"> + <title>Fetch: integrity handling</title> + <meta name="author" title="Canon Research France" href="https://www.crf.canon.fr"> + <meta name="help" href="https://fetch.spec.whatwg.org/#main-fetch"> + <script src="/resources/testharness.js"></script> + <script src="/resources/testharnessreport.js"></script> + </head> + <body> + <script src="../resources/utils.js"></script> + <script src="integrity.js?pipe=sub"></script> + </body> +</html>
\ No newline at end of file diff --git a/testing/web-platform/tests/fetch/api/basic/integrity.js b/testing/web-platform/tests/fetch/api/basic/integrity.js new file mode 100644 index 000000000..a436dabe4 --- /dev/null +++ b/testing/web-platform/tests/fetch/api/basic/integrity.js @@ -0,0 +1,45 @@ +if (this.document === undefined) { + importScripts("/resources/testharness.js"); + importScripts("../resources/utils.js"); +} + +function integrity(desc, url, integrity, shouldPass) { + if (shouldPass) { + promise_test(function(test) { + return fetch(url, {'integrity': integrity}).then(function(resp) { + assert_equals(resp.status, 200, "Response's status is 200"); + }); + }, desc); + } else { + promise_test(function(test) { + return promise_rejects(test, new TypeError(), fetch(url, {'integrity': integrity})); + }, desc); + } +} + +var topSha256 = "sha256-KHIDZcXnR2oBHk9DrAA+5fFiR6JjudYjqoXtMR1zvzk="; +var topSha384 = "sha384-MgZYnnAzPM/MjhqfOIMfQK5qcFvGZsGLzx4Phd7/A8fHTqqLqXqKo8cNzY3xEPTL"; +var topSha512 = "sha512-D6yns0qxG0E7+TwkevZ4Jt5t7Iy3ugmAajG/dlf6Pado1JqTyneKXICDiqFIkLMRExgtvg8PlxbKTkYfRejSOg=="; +var invalidSha256 = "sha256-dKUcPOn/AlUjWIwcHeHNqYXPlvyGiq+2dWOdFcE+24I="; +var invalidSha512 = "sha512-oUceBRNxPxnY60g/VtPCj2syT4wo4EZh2CgYdWy9veW8+OsReTXoh7dizMGZafvx9+QhMS39L/gIkxnPIn41Zg=="; + +var url = "../resources/top.txt"; +var corsUrl = "http://{{host}}:{{ports[http][1]}}" + dirname(location.pathname) + RESOURCES_DIR + "top.txt"; +/* Enable CORS*/ +corsUrl += "?pipe=header(Access-Control-Allow-Origin,*)"; + +integrity("Empty string integrity", url, "", true); +integrity("SHA-256 integrity", url, topSha256, true); +integrity("SHA-384 integrity", url, topSha384, true); +integrity("SHA-512 integrity", url, topSha512, true); +integrity("Invalid integrity", url, invalidSha256, false); +integrity("Multiple integrities: valid stronger than invalid", url, invalidSha256 + " " + topSha384, true); +integrity("Multiple integrities: invalid stronger than valid", url, invalidSha512 + " " + topSha384, false); +integrity("Multiple integrities: invalid as strong as valid", url, invalidSha512 + " " + topSha512, true); +integrity("Multiple integrities: both are valid", url, topSha384 + " " + topSha512, true); +integrity("Multiple integrities: both are invalid", url, invalidSha256 + " " + invalidSha512, false); +integrity("CORS empty integrity", corsUrl, "", true); +integrity("CORS SHA-512 integrity", corsUrl, topSha512, true); +integrity("CORS invalid integrity", corsUrl, invalidSha512, false); + +done(); diff --git a/testing/web-platform/tests/fetch/api/basic/mode-no-cors-worker.html b/testing/web-platform/tests/fetch/api/basic/mode-no-cors-worker.html new file mode 100644 index 000000000..87376a130 --- /dev/null +++ b/testing/web-platform/tests/fetch/api/basic/mode-no-cors-worker.html @@ -0,0 +1,17 @@ +<!doctype html> +<html> + <head> + <meta charset="utf-8"> + <title>Fetch in worker: no-cors mode and opaque filtering</title> + <meta name="help" href="https://fetch.spec.whatwg.org/#main-fetch"> + <meta name="help" href="https://fetch.spec.whatwg.org/#concept-filtered-response-opaque"> + <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> + fetch_tests_from_worker(new Worker("mode-no-cors.js?pipe=sub")); + </script> + </body> +</html>
\ No newline at end of file diff --git a/testing/web-platform/tests/fetch/api/basic/mode-no-cors.html b/testing/web-platform/tests/fetch/api/basic/mode-no-cors.html new file mode 100644 index 000000000..7aee37909 --- /dev/null +++ b/testing/web-platform/tests/fetch/api/basic/mode-no-cors.html @@ -0,0 +1,16 @@ +<!doctype html> +<html> + <head> + <meta charset="utf-8"> + <title>Fetch: no-cors mode and opaque filtering</title> + <meta name="help" href="https://fetch.spec.whatwg.org/#main-fetch"> + <meta name="help" href="https://fetch.spec.whatwg.org/#concept-filtered-response-opaque"> + <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 src="mode-no-cors.js?pipe=sub"></script> + </body> +</html>
\ No newline at end of file diff --git a/testing/web-platform/tests/fetch/api/basic/mode-no-cors.js b/testing/web-platform/tests/fetch/api/basic/mode-no-cors.js new file mode 100644 index 000000000..53e849051 --- /dev/null +++ b/testing/web-platform/tests/fetch/api/basic/mode-no-cors.js @@ -0,0 +1,31 @@ +if (this.document === undefined) { + importScripts("/resources/testharness.js"); + importScripts("../resources/utils.js"); +} + +function fetchNoCors(url, isOpaqueFiltered) { + var urlQuery = "?pipe=header(x-is-filtered,value)" + promise_test(function(test) { + if (isOpaqueFiltered) + return fetch(url + urlQuery, {"mode": "no-cors"}).then(function(resp) { + assert_equals(resp.status, 0, "Opaque filter: status is 0"); + assert_equals(resp.statusText, "", "Opaque filter: statusText is \"\""); + assert_equals(resp.type , "opaque", "Opaque filter: response's type is opaque"); + assert_equals(resp.headers.get("x-is-filtered"), null, "Header x-is-filtered is filtered"); + }); + else + return fetch(url + urlQuery, {"mode": "no-cors"}).then(function(resp) { + assert_equals(resp.status, 200, "HTTP status is 200"); + assert_equals(resp.type , "basic", "Response's type is basic"); + assert_equals(resp.headers.get("x-is-filtered"), "value", "Header x-is-filtered is not filtered"); + }); + }, "Fetch "+ url + " with no-cors mode"); +} + +fetchNoCors(RESOURCES_DIR + "top.txt", false); +fetchNoCors("http://{{host}}:{{ports[http][0]}}/fetch/api/resources/top.txt", false); +fetchNoCors("https://{{host}}:{{ports[https][0]}}/fetch/api/resources/top.txt", true); +fetchNoCors("http://{{host}}:{{ports[http][1]}}/fetch/api/resources/top.txt", true); + +done(); + diff --git a/testing/web-platform/tests/fetch/api/basic/mode-same-origin-worker.html b/testing/web-platform/tests/fetch/api/basic/mode-same-origin-worker.html new file mode 100644 index 000000000..cc39af3cb --- /dev/null +++ b/testing/web-platform/tests/fetch/api/basic/mode-same-origin-worker.html @@ -0,0 +1,17 @@ +<!doctype html> +<html> + <head> + <meta charset="utf-8"> + <title>Fetch in worker: same-origin mode</title> + <meta name="help" href="https://fetch.spec.whatwg.org/#main-fetch"> + <meta name="help" href="https://fetch.spec.whatwg.org/#basic-fetch"> + <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> + fetch_tests_from_worker(new Worker("mode-same-origin.js")); + </script> + </body> +</html> diff --git a/testing/web-platform/tests/fetch/api/basic/mode-same-origin.html b/testing/web-platform/tests/fetch/api/basic/mode-same-origin.html new file mode 100644 index 000000000..550053f30 --- /dev/null +++ b/testing/web-platform/tests/fetch/api/basic/mode-same-origin.html @@ -0,0 +1,17 @@ +<!doctype html> +<html> + <head> + <meta charset="utf-8"> + <title>Fetch: same-origin mode</title> + <meta name="help" href="https://fetch.spec.whatwg.org/#main-fetch"> + <meta name="help" href="https://fetch.spec.whatwg.org/#basic-fetch"> + <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 src="/common/get-host-info.sub.js"></script> + <script src="mode-same-origin.js"></script> + </body> +</html> diff --git a/testing/web-platform/tests/fetch/api/basic/mode-same-origin.js b/testing/web-platform/tests/fetch/api/basic/mode-same-origin.js new file mode 100644 index 000000000..6418b22f5 --- /dev/null +++ b/testing/web-platform/tests/fetch/api/basic/mode-same-origin.js @@ -0,0 +1,34 @@ +if (this.document === undefined) { + importScripts("/resources/testharness.js"); + importScripts("../resources/utils.js"); + importScripts("/common/get-host-info.sub.js") +} + +function fetchSameOrigin(url, shouldPass) { + promise_test(function(test) { + if (shouldPass) + return fetch(url , {"mode": "same-origin"}).then(function(resp) { + assert_equals(resp.status, 200, "HTTP status is 200"); + assert_equals(resp.type, "basic", "response type is basic"); + }); + else + return promise_rejects(test, new TypeError, fetch(url, {mode: "same-origin"})); + }, "Fetch "+ url + " with same-origin mode"); +} + +var host_info = get_host_info(); + +fetchSameOrigin(RESOURCES_DIR + "top.txt", true); +fetchSameOrigin(host_info.HTTP_ORIGIN + "/fetch/api/resources/top.txt", true); +fetchSameOrigin(host_info.HTTPS_ORIGIN + "/fetch/api/resources/top.txt", false); +fetchSameOrigin(host_info.HTTP_REMOTE_ORIGIN + "/fetch/api/resources/top.txt", false); + +var redirPath = dirname(location.pathname) + RESOURCES_DIR + "redirect.py?location="; + +fetchSameOrigin(redirPath + RESOURCES_DIR + "top.txt", true); +fetchSameOrigin(redirPath + host_info.HTTP_ORIGIN + "/fetch/api/resources/top.txt", true); +fetchSameOrigin(redirPath + host_info.HTTPS_ORIGIN + "/fetch/api/resources/top.txt", false); +fetchSameOrigin(redirPath + host_info.HTTP_REMOTE_ORIGIN + "/fetch/api/resources/top.txt", false); + +done(); + diff --git a/testing/web-platform/tests/fetch/api/basic/referrer-worker.html b/testing/web-platform/tests/fetch/api/basic/referrer-worker.html new file mode 100644 index 000000000..4b397de43 --- /dev/null +++ b/testing/web-platform/tests/fetch/api/basic/referrer-worker.html @@ -0,0 +1,17 @@ +<!doctype html> +<html> + <head> + <meta charset="utf-8"> + <title>Fetch in worker: same-origin mode</title> + <meta name="help" href="https://fetch.spec.whatwg.org/#main-fetch"> + <meta name="help" href="https://fetch.spec.whatwg.org/#basic-fetch"> + <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> + fetch_tests_from_worker(new Worker("referrer.js")); + </script> + </body> +</html> diff --git a/testing/web-platform/tests/fetch/api/basic/referrer.html b/testing/web-platform/tests/fetch/api/basic/referrer.html new file mode 100644 index 000000000..1af3f75ba --- /dev/null +++ b/testing/web-platform/tests/fetch/api/basic/referrer.html @@ -0,0 +1,17 @@ +<!doctype html> +<html> + <head> + <meta charset="utf-8"> + <title>Fetch: same-origin mode</title> + <meta name="help" href="https://fetch.spec.whatwg.org/#main-fetch"> + <meta name="help" href="https://fetch.spec.whatwg.org/#basic-fetch"> + <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 src="/common/get-host-info.sub.js"></script> + <script src="referrer.js"></script> + </body> +</html> diff --git a/testing/web-platform/tests/fetch/api/basic/referrer.js b/testing/web-platform/tests/fetch/api/basic/referrer.js new file mode 100644 index 000000000..84cf980c7 --- /dev/null +++ b/testing/web-platform/tests/fetch/api/basic/referrer.js @@ -0,0 +1,35 @@ +if (this.document === undefined) { + importScripts("/resources/testharness.js"); + importScripts("../resources/utils.js"); + importScripts("/common/get-host-info.sub.js") +} + +function runTest(url, init, expectedReferrer, title) { + promise_test(function(test) { + url += (url.indexOf('?') !== -1 ? '&' : '?') + "headers=referer&cors"; + + return fetch(url , init).then(function(resp) { + assert_equals(resp.status, 200, "HTTP status is 200"); + assert_equals(resp.headers.get("x-request-referer"), expectedReferrer, "Request's referrer is correct"); + }); + }, title); +} + +var fetchedUrl = RESOURCES_DIR + "inspect-headers.py"; +var corsFetchedUrl = get_host_info().HTTP_REMOTE_ORIGIN + dirname(location.pathname) + RESOURCES_DIR + "inspect-headers.py"; +var redirectUrl = RESOURCES_DIR + "redirect.py?location=" ; +var corsRedirectUrl = get_host_info().HTTP_REMOTE_ORIGIN + dirname(location.pathname) + RESOURCES_DIR + "redirect.py?location="; + +runTest(fetchedUrl, { referrerPolicy: "origin-when-cross-origin"}, location.toString(), "origin-when-cross-origin policy on a same-origin URL"); +runTest(corsFetchedUrl, { referrerPolicy: "origin-when-cross-origin"}, get_host_info().HTTP_ORIGIN + "/", "origin-when-cross-origin policy on a cross-origin URL"); +runTest(redirectUrl + corsFetchedUrl, { referrerPolicy: "origin-when-cross-origin"}, get_host_info().HTTP_ORIGIN + "/", "origin-when-cross-origin policy on a cross-origin URL after same-origin redirection"); +runTest(corsRedirectUrl + fetchedUrl, { referrerPolicy: "origin-when-cross-origin"}, get_host_info().HTTP_ORIGIN + "/", "origin-when-cross-origin policy on a same-origin URL after cross-origin redirection"); + + +var referrerUrlWithCredentials = get_host_info().HTTP_ORIGIN.replace("http://", "http://username:password@"); +runTest(fetchedUrl, {referrer: referrerUrlWithCredentials}, get_host_info().HTTP_ORIGIN + "/", "Referrer with credentials should be stripped"); +var referrerUrlWithFragmentIdentifier = get_host_info().HTTP_ORIGIN + "#fragmentIdentifier"; +runTest(fetchedUrl, {referrer: referrerUrlWithFragmentIdentifier}, get_host_info().HTTP_ORIGIN + "/", "Referrer with fragment ID should be stripped"); + +done(); + diff --git a/testing/web-platform/tests/fetch/api/basic/request-forbidden-headers-worker.html b/testing/web-platform/tests/fetch/api/basic/request-forbidden-headers-worker.html new file mode 100644 index 000000000..12e87f9e4 --- /dev/null +++ b/testing/web-platform/tests/fetch/api/basic/request-forbidden-headers-worker.html @@ -0,0 +1,17 @@ +<!doctype html> +<html> + <head> + <meta charset="utf-8"> + <title>Fetch in worker: forbidden request header management</title> + <meta name="author" title="Canon Research France" href="https://www.crf.canon.fr"> + <meta name="help" href="https://fetch.spec.whatwg.org/#forbidden-header-name"> + <meta name="help" href="https://fetch.spec.whatwg.org/#main-fetch"> + <script src="/resources/testharness.js"></script> + <script src="/resources/testharnessreport.js"></script> + </head> + <body> + <script> + fetch_tests_from_worker(new Worker("request-forbidden-headers.js")); + </script> + </body> +</html>
\ No newline at end of file diff --git a/testing/web-platform/tests/fetch/api/basic/request-forbidden-headers.html b/testing/web-platform/tests/fetch/api/basic/request-forbidden-headers.html new file mode 100644 index 000000000..56ce2a65b --- /dev/null +++ b/testing/web-platform/tests/fetch/api/basic/request-forbidden-headers.html @@ -0,0 +1,16 @@ +<!doctype html> +<html> + <head> + <meta charset="utf-8"> + <title>Fetch: forbidden request header management</title> + <meta name="author" title="Canon Research France" href="https://www.crf.canon.fr"> + <meta name="help" href="https://fetch.spec.whatwg.org/#forbidden-header-name"> + <meta name="help" href="https://fetch.spec.whatwg.org/#main-fetch"> + <script src="/resources/testharness.js"></script> + <script src="/resources/testharnessreport.js"></script> + </head> + <body> + <script src="../resources/utils.js"></script> + <script src="request-forbidden-headers.js"></script> + </body> +</html>
\ No newline at end of file diff --git a/testing/web-platform/tests/fetch/api/basic/request-forbidden-headers.js b/testing/web-platform/tests/fetch/api/basic/request-forbidden-headers.js new file mode 100644 index 000000000..72a8392a5 --- /dev/null +++ b/testing/web-platform/tests/fetch/api/basic/request-forbidden-headers.js @@ -0,0 +1,48 @@ +if (this.document === undefined) { + importScripts("/resources/testharness.js"); + importScripts("../resources/utils.js"); +} + +function requestForbiddenHeaders(desc, forbiddenHeaders) { + var url = RESOURCES_DIR + "inspect-headers.py"; + var requestInit = {"headers": forbiddenHeaders} + var urlParameters = "?headers=" + Object.keys(forbiddenHeaders).join("|"); + + promise_test(function(test){ + return fetch(url + urlParameters, requestInit).then(function(resp) { + assert_equals(resp.status, 200, "HTTP status is 200"); + assert_equals(resp.type , "basic", "Response's type is basic"); + for (var header in forbiddenHeaders) + assert_not_equals(resp.headers.get("x-request-" + header), forbiddenHeaders[header], header + " does not have the value we defined"); + }); + }, desc); +} + +requestForbiddenHeaders("Accept-Charset is a forbidden request header", {"Accept-Charset": "utf-8"}); +requestForbiddenHeaders("Accept-Encoding is a forbidden request header", {"Accept-Encoding": ""}); + +requestForbiddenHeaders("Access-Control-Request-Headers is a forbidden request header", {"Access-Control-Request-Headers": ""}); +requestForbiddenHeaders("Access-Control-Request-Method is a forbidden request header", {"Access-Control-Request-Method": ""}); +requestForbiddenHeaders("Connection is a forbidden request header", {"Connection": "close"}); +requestForbiddenHeaders("Content-Length is a forbidden request header", {"Content-Length": "42"}); +requestForbiddenHeaders("Cookie is a forbidden request header", {"Cookie": "cookie=none"}); +requestForbiddenHeaders("Cookie2 is a forbidden request header", {"Cookie2": "cookie2=none"}); +requestForbiddenHeaders("Date is a forbidden request header", {"Date": "Wed, 04 May 1988 22:22:22 GMT"}); +requestForbiddenHeaders("DNT is a forbidden request header", {"DNT": "4"}); +requestForbiddenHeaders("Expect is a forbidden request header", {"Expect": "100-continue"}); +requestForbiddenHeaders("Host is a forbidden request header", {"Host": "http://wrong-host.com"}); +requestForbiddenHeaders("Keep-Alive is a forbidden request header", {"Keep-Alive": "timeout=15"}); +requestForbiddenHeaders("Origin is a forbidden request header", {"Origin": "http://wrong-origin.com"}); +requestForbiddenHeaders("Referer is a forbidden request header", {"Referer": "http://wrong-referer.com"}); +requestForbiddenHeaders("TE is a forbidden request header", {"TE": "trailers"}); +requestForbiddenHeaders("Trailer is a forbidden request header", {"Trailer": "Accept"}); +requestForbiddenHeaders("Transfer-Encoding is a forbidden request header", {"Transfer-Encoding": "chunked"}); +requestForbiddenHeaders("Upgrade is a forbidden request header", {"Upgrade": "HTTP/2.0"}); +requestForbiddenHeaders("Via is a forbidden request header", {"Via": "1.1 nowhere.com"}); +requestForbiddenHeaders("Proxy- is a forbidden request header", {"Proxy-": "value"}); +requestForbiddenHeaders("Proxy-Test is a forbidden request header", {"Proxy-Test": "value"}); +requestForbiddenHeaders("Sec- is a forbidden request header", {"Sec-": "value"}); +requestForbiddenHeaders("Sec-Test is a forbidden request header", {"Sec-Test": "value"}); + +done(); + diff --git a/testing/web-platform/tests/fetch/api/basic/request-head-worker.html b/testing/web-platform/tests/fetch/api/basic/request-head-worker.html new file mode 100644 index 000000000..3be7c99ad --- /dev/null +++ b/testing/web-platform/tests/fetch/api/basic/request-head-worker.html @@ -0,0 +1,14 @@ +<!doctype html> +<html> + <head> + <meta charset="utf-8"> + <title>Fetch in worker: HEAD method</title> + <script src="/resources/testharness.js"></script> + <script src="/resources/testharnessreport.js"></script> + </head> + <body> + <script> + fetch_tests_from_worker(new Worker("request-head.js")); + </script> + </body> +</html> diff --git a/testing/web-platform/tests/fetch/api/basic/request-head.html b/testing/web-platform/tests/fetch/api/basic/request-head.html new file mode 100644 index 000000000..a9d8bef1f --- /dev/null +++ b/testing/web-platform/tests/fetch/api/basic/request-head.html @@ -0,0 +1,12 @@ +<!doctype html> +<html> + <head> + <meta charset="utf-8"> + <title>Fetch: HEAD method</title> + <script src="/resources/testharness.js"></script> + <script src="/resources/testharnessreport.js"></script> + </head> + <body> + <script src="request-head.js"></script> + </body> +</html> diff --git a/testing/web-platform/tests/fetch/api/basic/request-head.js b/testing/web-platform/tests/fetch/api/basic/request-head.js new file mode 100644 index 000000000..f0d6b74f8 --- /dev/null +++ b/testing/web-platform/tests/fetch/api/basic/request-head.js @@ -0,0 +1,10 @@ +if (this.document === undefined) { + importScripts("/resources/testharness.js"); +} + +promise_test(function(test) { + var requestInit = {"method": "HEAD", "body": "test"}; + return promise_rejects(test, new TypeError(), fetch(".", requestInit)); +}, "Fetch with HEAD with body"); + +done(); diff --git a/testing/web-platform/tests/fetch/api/basic/request-headers-worker.html b/testing/web-platform/tests/fetch/api/basic/request-headers-worker.html new file mode 100644 index 000000000..85b4c4c70 --- /dev/null +++ b/testing/web-platform/tests/fetch/api/basic/request-headers-worker.html @@ -0,0 +1,16 @@ +<!doctype html> +<html> + <head> + <meta charset="utf-8"> + <title>Fetch in worker: User agent add headers to request</title> + <meta name="author" title="Canon Research France" href="https://www.crf.canon.fr"> + <meta name="help" href="https://fetch.spec.whatwg.org/#http-network-or-cache-fetch"> + <script src="/resources/testharness.js"></script> + <script src="/resources/testharnessreport.js"></script> + </head> + <body> + <script> + fetch_tests_from_worker(new Worker("request-headers.js")); + </script> + </body> +</html>
\ No newline at end of file diff --git a/testing/web-platform/tests/fetch/api/basic/request-headers.html b/testing/web-platform/tests/fetch/api/basic/request-headers.html new file mode 100644 index 000000000..5236d29b1 --- /dev/null +++ b/testing/web-platform/tests/fetch/api/basic/request-headers.html @@ -0,0 +1,15 @@ +<!doctype html> +<html> + <head> + <meta charset="utf-8"> + <title>Fetch: User agent add headers to request</title> + <meta name="author" title="Canon Research France" href="https://www.crf.canon.fr"> + <meta name="help" href="https://fetch.spec.whatwg.org/#http-network-or-cache-fetch"> + <script src="/resources/testharness.js"></script> + <script src="/resources/testharnessreport.js"></script> + </head> + <body> + <script src="../resources/utils.js"></script> + <script src="request-headers.js"></script> + </body> +</html>
\ No newline at end of file diff --git a/testing/web-platform/tests/fetch/api/basic/request-headers.js b/testing/web-platform/tests/fetch/api/basic/request-headers.js new file mode 100644 index 000000000..4c78ff0dc --- /dev/null +++ b/testing/web-platform/tests/fetch/api/basic/request-headers.js @@ -0,0 +1,63 @@ +if (this.document === undefined) { + importScripts("/resources/testharness.js"); + importScripts("../resources/utils.js"); +} + +function checkContentType(contentType, body) +{ + if (self.FormData && body instanceof self.FormData) { + assert_true(contentType.startsWith("multipart/form-data;boundary="), "Request should have header content-type starting with multipart/form-data;boundary=, but got " + contentType); + return; + } + + var expectedContentType = "text/plain;charset=UTF-8"; + if(body === null || body instanceof ArrayBuffer || body.buffer instanceof ArrayBuffer) + expectedContentType = null; + else if (body instanceof Blob) + expectedContentType = body.type ? body.type : null; + + assert_equals(contentType , expectedContentType, "Request should have header content-type: " + expectedContentType); +} + +function requestHeaders(desc, url, method, body, expectedOrigin, expectedContentLength) { + var urlParameters = "?headers=origin|user-agent|accept-charset|content-length|content-type"; + var requestInit = {"method": method} + promise_test(function(test){ + if (typeof body === "function") + body = body(); + if (body) + requestInit["body"] = body; + return fetch(url + urlParameters, requestInit).then(function(resp) { + assert_equals(resp.status, 200, "HTTP status is 200"); + assert_equals(resp.type , "basic", "Response's type is basic"); + assert_true(resp.headers.has("x-request-user-agent"), "Request has header user-agent"); + assert_false(resp.headers.has("accept-charset"), "Request has header accept-charset"); + assert_equals(resp.headers.get("x-request-origin") , expectedOrigin, "Request should have header origin: " + expectedOrigin); + if (expectedContentLength !== undefined) + assert_equals(resp.headers.get("x-request-content-length") , expectedContentLength, "Request should have header content-length: " + expectedContentLength); + checkContentType(resp.headers.get("x-request-content-type"), body); + }); + }, desc); +} + +var url = RESOURCES_DIR + "inspect-headers.py" + +requestHeaders("Fetch with GET", url, "GET", null, location.origin, null); +requestHeaders("Fetch with HEAD", url, "HEAD", null, location.origin, null); +requestHeaders("Fetch with PUT without body", url, "POST", null, location.origin, "0"); +requestHeaders("Fetch with PUT with body", url, "PUT", "Request's body", location.origin, "14"); +requestHeaders("Fetch with POST without body", url, "POST", null, location.origin, "0"); +requestHeaders("Fetch with POST with text body", url, "POST", "Request's body", location.origin, "14"); +requestHeaders("Fetch with POST with FormData body", url, "POST", function() { return new FormData(); }, location.origin); +requestHeaders("Fetch with POST with Blob body", url, "POST", new Blob(["Test"]), location.origin, "4"); +requestHeaders("Fetch with POST with ArrayBuffer body", url, "POST", new ArrayBuffer(4), location.origin, "4"); +requestHeaders("Fetch with POST with Uint8Array body", url, "POST", new Uint8Array(4), location.origin, "4"); +requestHeaders("Fetch with POST with Int8Array body", url, "POST", new Int8Array(4), location.origin, "4"); +requestHeaders("Fetch with POST with Float32Array body", url, "POST", new Float32Array(1), location.origin, "4"); +requestHeaders("Fetch with POST with Float64Array body", url, "POST", new Float64Array(1), location.origin, "8"); +requestHeaders("Fetch with POST with DataView body", url, "POST", new DataView(new ArrayBuffer(8), 0, 4), location.origin, "4"); +requestHeaders("Fetch with POST with Blob body with mime type", url, "POST", new Blob(["Test"], { type: "text/maybe" }), location.origin, "4"); +requestHeaders("Fetch with Chicken", url, "Chicken", null, location.origin, null); +requestHeaders("Fetch with Chicken with body", url, "Chicken", "Request's body", location.origin, "14"); + +done(); diff --git a/testing/web-platform/tests/fetch/api/basic/request-referrer.html b/testing/web-platform/tests/fetch/api/basic/request-referrer.html new file mode 100644 index 000000000..dd895617b --- /dev/null +++ b/testing/web-platform/tests/fetch/api/basic/request-referrer.html @@ -0,0 +1,13 @@ +<!doctype html> +<html> + <head> + <meta charset="utf-8"> + <title>Fetch: fetch() respects Request referrer value</title> + <script src="/resources/testharness.js"></script> + <script src="/resources/testharnessreport.js"></script> + </head> + <body> + <script src="../resources/utils.js"></script> + <script src="request-referrer.js"></script> + </body> +</html> diff --git a/testing/web-platform/tests/fetch/api/basic/request-referrer.js b/testing/web-platform/tests/fetch/api/basic/request-referrer.js new file mode 100644 index 000000000..cc5cc8e01 --- /dev/null +++ b/testing/web-platform/tests/fetch/api/basic/request-referrer.js @@ -0,0 +1,28 @@ +if (this.document === undefined) { + importScripts("/resources/testharness.js"); + importScripts("../resources/utils.js"); +} + +function testReferrer(referrer, expected) { + promise_test(function(test) { + var url = RESOURCES_DIR + "inspect-headers.py?headers=referer" + var req = new Request(url, { referrer: referrer }); + return fetch(req).then(function(resp) { + var actual = resp.headers.get("x-request-referer"); + if (expected) { + assert_equals(actual, expected, "request's referer should be: " + expected); + return; + } + if (actual) { + assert_equals(actual, "", "request's referer should be empty"); + } + }); + }); +} + +testReferrer("about:client", window.location.href); + +var fooURL = new URL("./foo", window.location).href; +testReferrer(fooURL, fooURL); + +done(); diff --git a/testing/web-platform/tests/fetch/api/basic/response-url-worker.html b/testing/web-platform/tests/fetch/api/basic/response-url-worker.html new file mode 100644 index 000000000..03374e0f6 --- /dev/null +++ b/testing/web-platform/tests/fetch/api/basic/response-url-worker.html @@ -0,0 +1,15 @@ +<!doctype html> +<html> + <head> + <meta charset="utf-8"> + <title>Fetch in worker: response url getter</title> + <meta name="help" href="https://fetch.spec.whatwg.org/#response-class"> + <script src="/resources/testharness.js"></script> + <script src="/resources/testharnessreport.js"></script> + </head> + <body> + <script> + fetch_tests_from_worker(new Worker("response-url.js?pipe=sub")); + </script> + </body> +</html> diff --git a/testing/web-platform/tests/fetch/api/basic/response-url.html b/testing/web-platform/tests/fetch/api/basic/response-url.html new file mode 100644 index 000000000..dfe9d96c7 --- /dev/null +++ b/testing/web-platform/tests/fetch/api/basic/response-url.html @@ -0,0 +1,13 @@ +<!doctype html> +<html> + <head> + <meta charset="utf-8"> + <title>Fetch: response url getter</title> + <meta name="help" href="https://fetch.spec.whatwg.org/#response-class"> + <script src="/resources/testharness.js"></script> + <script src="/resources/testharnessreport.js"></script> + </head> + <body> + <script src="response-url.js?pipe=sub"></script> + </body> +</html> diff --git a/testing/web-platform/tests/fetch/api/basic/response-url.js b/testing/web-platform/tests/fetch/api/basic/response-url.js new file mode 100644 index 000000000..91b553aae --- /dev/null +++ b/testing/web-platform/tests/fetch/api/basic/response-url.js @@ -0,0 +1,21 @@ +if (this.document === undefined) { + importScripts("/resources/testharness.js"); +} + +function checkResponseURL(fetchedURL, expectedURL) +{ + promise_test(function() { + return fetch(fetchedURL).then(function(response) { + assert_equals(response.url, expectedURL); + }); + }, "Testing response url getter with " +fetchedURL); +} + +var baseURL = "http://{{host}}:{{ports[http][0]}}"; +checkResponseURL(baseURL + "/ada", baseURL + "/ada"); +checkResponseURL(baseURL + "/#", baseURL + "/"); +checkResponseURL(baseURL + "/#ada", baseURL + "/"); +checkResponseURL(baseURL + "#ada", baseURL + "/"); + +done(); + diff --git a/testing/web-platform/tests/fetch/api/basic/scheme-about-worker.html b/testing/web-platform/tests/fetch/api/basic/scheme-about-worker.html new file mode 100644 index 000000000..9c9d9a038 --- /dev/null +++ b/testing/web-platform/tests/fetch/api/basic/scheme-about-worker.html @@ -0,0 +1,17 @@ +<!doctype html> +<html> + <head> + <meta charset="utf-8"> + <title>Fetch in worker: about scheme</title> + <meta name="help" href="https://fetch.spec.whatwg.org/#main-fetch"> + <meta name="help" href="https://fetch.spec.whatwg.org/#basic-fetch"> + <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> + fetch_tests_from_worker(new Worker("scheme-about.js")); + </script> + </body> +</html>
\ No newline at end of file diff --git a/testing/web-platform/tests/fetch/api/basic/scheme-about.html b/testing/web-platform/tests/fetch/api/basic/scheme-about.html new file mode 100644 index 000000000..8b6df2468 --- /dev/null +++ b/testing/web-platform/tests/fetch/api/basic/scheme-about.html @@ -0,0 +1,16 @@ +<!doctype html> +<html> + <head> + <meta charset="utf-8"> + <title>Fetch: about scheme</title> + <meta name="help" href="https://fetch.spec.whatwg.org/#main-fetch"> + <meta name="help" href="https://fetch.spec.whatwg.org/#basic-fetch"> + <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 src="scheme-about.js"></script> + </body> +</html>
\ No newline at end of file diff --git a/testing/web-platform/tests/fetch/api/basic/scheme-about.js b/testing/web-platform/tests/fetch/api/basic/scheme-about.js new file mode 100644 index 000000000..ddf711bf0 --- /dev/null +++ b/testing/web-platform/tests/fetch/api/basic/scheme-about.js @@ -0,0 +1,39 @@ +if (this.document === undefined) { + importScripts("/resources/testharness.js"); + importScripts("../resources/utils.js"); +} + +function checkFetchResponse(url, method, desc) { + if (!desc) { + var cut = (url.length >= 40) ? "[...]" : ""; + cut += " (" + method + ")" + desc = "Fetching " + url.substring(0, 40) + cut + " is OK" + } + promise_test(function(test) { + return fetch(url, { method: method }).then(function(resp) { + assert_equals(resp.status, 200, "HTTP status is 200"); + assert_equals(resp.type, "basic", "response type is basic"); + assert_equals(resp.headers.get("Content-Type"), "text/html;charset=utf-8", "Content-Type is " + resp.headers.get("Content-Type")); + return resp.text(); + }) + }, desc); +} + +checkFetchResponse("about:blank", "GET"); +checkFetchResponse("about:blank", "PUT"); +checkFetchResponse("about:blank", "POST"); + +function checkKoUrl(url, desc) { + if (!desc) + desc = "Fetching " + url.substring(0, 45) + " is KO" + promise_test(function(test) { + var promise = fetch(url); + return promise_rejects(test, new TypeError(), promise); + }, desc); +} + +checkKoUrl("about:invalid.com"); +checkKoUrl("about:config"); +checkKoUrl("about:unicorn"); + +done(); diff --git a/testing/web-platform/tests/fetch/api/basic/scheme-blob-worker.html b/testing/web-platform/tests/fetch/api/basic/scheme-blob-worker.html new file mode 100644 index 000000000..961ecbd52 --- /dev/null +++ b/testing/web-platform/tests/fetch/api/basic/scheme-blob-worker.html @@ -0,0 +1,17 @@ +<!doctype html> +<html> + <head> + <meta charset="utf-8"> + <title>Fetch in worker: blob scheme</title> + <meta name="help" href="https://fetch.spec.whatwg.org/#main-fetch"> + <meta name="help" href="https://fetch.spec.whatwg.org/#basic-fetch"> + <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> + fetch_tests_from_worker(new Worker("scheme-blob.js?pipe=sub")); + </script> + </body> +</html>
\ No newline at end of file diff --git a/testing/web-platform/tests/fetch/api/basic/scheme-blob.html b/testing/web-platform/tests/fetch/api/basic/scheme-blob.html new file mode 100644 index 000000000..7787c3710 --- /dev/null +++ b/testing/web-platform/tests/fetch/api/basic/scheme-blob.html @@ -0,0 +1,16 @@ +<!doctype html> +<html> + <head> + <meta charset="utf-8"> + <title>Fetch: blob scheme</title> + <meta name="help" href="https://fetch.spec.whatwg.org/#main-fetch"> + <meta name="help" href="https://fetch.spec.whatwg.org/#basic-fetch"> + <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 src="scheme-blob.js?pipe=sub"></script> + </body> +</html>
\ No newline at end of file diff --git a/testing/web-platform/tests/fetch/api/basic/scheme-blob.js b/testing/web-platform/tests/fetch/api/basic/scheme-blob.js new file mode 100644 index 000000000..9bf73a693 --- /dev/null +++ b/testing/web-platform/tests/fetch/api/basic/scheme-blob.js @@ -0,0 +1,48 @@ +if (this.document === undefined) { + importScripts("/resources/testharness.js"); + importScripts("../resources/utils.js"); +} + +function checkFetchResponse(url, data, mime, size, desc) { + promise_test(function(test) { + size = size.toString(); + return fetch(url).then(function(resp) { + assert_equals(resp.status, 200, "HTTP status is 200"); + assert_equals(resp.type, "basic", "response type is basic"); + assert_equals(resp.headers.get("Content-Type"), mime, "Content-Type is " + resp.headers.get("Content-Type")); + assert_equals(resp.headers.get("Content-Length"), size, "Content-Length is " + resp.headers.get("Content-Length")); + return resp.text(); + }).then(function(bodyAsText) { + assert_equals(bodyAsText, data, "Response's body is " + data); + }); + }, desc); +} + +var blob = new Blob(["Blob's data"], { "type" : "text/plain" }); +checkFetchResponse(URL.createObjectURL(blob), "Blob's data", "text/plain", blob.size, + "Fetching [GET] URL.createObjectURL(blob) is OK"); + +function checkKoUrl(url, method, desc) { + promise_test(function(test) { + var promise = fetch(url, {"method": method}); + return promise_rejects(test, new TypeError(), promise); + }, desc); +} + +var blob2 = new Blob(["Blob's data"], { "type" : "text/plain" }); +checkKoUrl("blob:http://{{domains[www]}}:{{ports[http][0]}}/", "GET", + "Fetching [GET] blob:http://{{domains[www]}}:{{ports[http][0]}}/ is KO"); + +var invalidRequestMethods = [ + "POST", + "OPTIONS", + "HEAD", + "PUT", + "DELETE", + "INVALID", +]; +invalidRequestMethods.forEach(function(method) { + checkKoUrl(URL.createObjectURL(blob2), method, "Fetching [" + method + "] URL.createObjectURL(blob) is KO"); +}); + +done(); diff --git a/testing/web-platform/tests/fetch/api/basic/scheme-data-worker.html b/testing/web-platform/tests/fetch/api/basic/scheme-data-worker.html new file mode 100644 index 000000000..42fc3f4a9 --- /dev/null +++ b/testing/web-platform/tests/fetch/api/basic/scheme-data-worker.html @@ -0,0 +1,17 @@ +<!doctype html> +<html> + <head> + <meta charset="utf-8"> + <title>Fetch in worker: data scheme</title> + <meta name="help" href="https://fetch.spec.whatwg.org/#main-fetch"> + <meta name="help" href="https://fetch.spec.whatwg.org/#basic-fetch"> + <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> + fetch_tests_from_worker(new Worker("scheme-data.js")); + </script> + </body> +</html>
\ No newline at end of file diff --git a/testing/web-platform/tests/fetch/api/basic/scheme-data.html b/testing/web-platform/tests/fetch/api/basic/scheme-data.html new file mode 100644 index 000000000..0b41991c9 --- /dev/null +++ b/testing/web-platform/tests/fetch/api/basic/scheme-data.html @@ -0,0 +1,16 @@ +<!doctype html> +<html> + <head> + <meta charset="utf-8"> + <title>Fetch: data scheme</title> + <meta name="help" href="https://fetch.spec.whatwg.org/#main-fetch"> + <meta name="help" href="https://fetch.spec.whatwg.org/#basic-fetch"> + <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 src="scheme-data.js"></script> + </body> +</html>
\ No newline at end of file diff --git a/testing/web-platform/tests/fetch/api/basic/scheme-data.js b/testing/web-platform/tests/fetch/api/basic/scheme-data.js new file mode 100644 index 000000000..61efd2b2d --- /dev/null +++ b/testing/web-platform/tests/fetch/api/basic/scheme-data.js @@ -0,0 +1,48 @@ +if (this.document === undefined) { + importScripts("/resources/testharness.js"); + importScripts("../resources/utils.js"); +} + +<<<<<<< b45946c54935c6113fefb5199b3fe0e4bf087777 +function checkFetchResponse(url, data, mime, fetchMode, method) { + var cut = (url.length >= 40) ? "[...]" : ""; + desc = "Fetching " + (method ? "[" + method + "] " : "") + url.substring(0, 40) + cut + " is OK"; + var init = {"method": method || "GET"}; + if (fetchMode) { + init.mode = fetchMode; + desc += " (" + fetchMode + ")"; + } + promise_test(function(test) { + return fetch(url, init).then(function(resp) { + assert_equals(resp.status, 200, "HTTP status is 200"); + assert_equals(resp.statusText, "OK", "HTTP statusText is OK"); + assert_equals(resp.type, "basic", "response type is basic"); + assert_equals(resp.headers.get("Content-Type"), mime, "Content-Type is " + resp.headers.get("Content-Type")); + return resp.text(); + }).then(function(body) { + assert_equals(body, data, "Response's body is correct"); + }); + }, desc); +} + +checkFetchResponse("data:,response%27s%20body", "response's body", "text/plain;charset=US-ASCII"); +checkFetchResponse("data:,response%27s%20body", "response's body", "text/plain;charset=US-ASCII", "same-origin"); +checkFetchResponse("data:,response%27s%20body", "response's body", "text/plain;charset=US-ASCII", "cors"); +checkFetchResponse("data:text/plain;base64,cmVzcG9uc2UncyBib2R5", "response's body", "text/plain"); +checkFetchResponse("data:image/png;base64,cmVzcG9uc2UncyBib2R5", + "response's body", + "image/png"); +checkFetchResponse("data:,response%27s%20body", "response's body", "text/plain;charset=US-ASCII", null, "POST"); +checkFetchResponse("data:,response%27s%20body", "response's body", "text/plain;charset=US-ASCII", null, "HEAD"); + +function checkKoUrl(url, method, desc) { + var cut = (url.length >= 40) ? "[...]" : ""; + desc = "Fetching [" + method + "] " + url.substring(0, 45) + cut + " is KO" + promise_test(function(test) { + return promise_rejects(test, new TypeError(), fetch(url, {"method": method})); + }, desc); +} + +checkKoUrl("data:notAdataUrl.com", "GET"); + +done(); diff --git a/testing/web-platform/tests/fetch/api/basic/scheme-others-worker.html b/testing/web-platform/tests/fetch/api/basic/scheme-others-worker.html new file mode 100644 index 000000000..397d9257b --- /dev/null +++ b/testing/web-platform/tests/fetch/api/basic/scheme-others-worker.html @@ -0,0 +1,17 @@ +<!doctype html> +<html> + <head> + <meta charset="utf-8"> + <title>Fetch in worker: urls with unsupported schemes</title> + <meta name="help" href="https://fetch.spec.whatwg.org/#main-fetch"> + <meta name="help" href="https://fetch.spec.whatwg.org/#basic-fetch"> + <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> + fetch_tests_from_worker(new Worker("scheme-others.js?pipe=sub")); + </script> + </body> +</html>
\ No newline at end of file diff --git a/testing/web-platform/tests/fetch/api/basic/scheme-others.html b/testing/web-platform/tests/fetch/api/basic/scheme-others.html new file mode 100644 index 000000000..dd37143b0 --- /dev/null +++ b/testing/web-platform/tests/fetch/api/basic/scheme-others.html @@ -0,0 +1,16 @@ +<!doctype html> +<html> + <head> + <meta charset="utf-8"> + <title>Fetch: urls with unsupported schemes</title> + <meta name="help" href="https://fetch.spec.whatwg.org/#main-fetch"> + <meta name="help" href="https://fetch.spec.whatwg.org/#basic-fetch"> + <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 src="scheme-others.js?pipe=sub"></script> + </body> +</html>
\ No newline at end of file diff --git a/testing/web-platform/tests/fetch/api/basic/scheme-others.js b/testing/web-platform/tests/fetch/api/basic/scheme-others.js new file mode 100644 index 000000000..ce02ec134 --- /dev/null +++ b/testing/web-platform/tests/fetch/api/basic/scheme-others.js @@ -0,0 +1,33 @@ +if (this.document === undefined) { + importScripts("/resources/testharness.js"); + importScripts("../resources/utils.js"); +} + +function checkKoUrl(url, desc) { + if (!desc) + desc = "Fetching " + url.substring(0, 45) + " is KO" + promise_test(function(test) { + var promise = fetch(url); + return promise_rejects(test, new TypeError(), promise); + }, desc); +} + +var urlWithoutScheme = "://{{host}}:{{ports[http][0]}}/"; +checkKoUrl("aaa" + urlWithoutScheme); +checkKoUrl("cap" + urlWithoutScheme); +checkKoUrl("cid" + urlWithoutScheme); +checkKoUrl("dav" + urlWithoutScheme); +checkKoUrl("dict" + urlWithoutScheme); +checkKoUrl("dns" + urlWithoutScheme); +checkKoUrl("geo" + urlWithoutScheme); +checkKoUrl("im" + urlWithoutScheme); +checkKoUrl("imap" + urlWithoutScheme); +checkKoUrl("ipp" + urlWithoutScheme); +checkKoUrl("ldap" + urlWithoutScheme); +checkKoUrl("mailto" + urlWithoutScheme); +checkKoUrl("nfs" + urlWithoutScheme); +checkKoUrl("pop" + urlWithoutScheme); +checkKoUrl("rtsp" + urlWithoutScheme); +checkKoUrl("snmp" + urlWithoutScheme); + +done(); diff --git a/testing/web-platform/tests/fetch/api/basic/stream-response-worker.html b/testing/web-platform/tests/fetch/api/basic/stream-response-worker.html new file mode 100644 index 000000000..0be1c0d13 --- /dev/null +++ b/testing/web-platform/tests/fetch/api/basic/stream-response-worker.html @@ -0,0 +1,17 @@ +<!doctype html> +<html> + <head> + <meta charset="utf-8"> + <title>Fetch in worker: retrieve response's body progressively</title> + <meta name="help" href="https://fetch.spec.whatwg.org/#main-fetch"> + <meta name="help" href="https://fetch.spec.whatwg.org/#http-fetch"> + <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> + fetch_tests_from_worker(new Worker("stream-response.js")); + </script> + </body> +</html>
\ No newline at end of file diff --git a/testing/web-platform/tests/fetch/api/basic/stream-response.html b/testing/web-platform/tests/fetch/api/basic/stream-response.html new file mode 100644 index 000000000..eb6b1415a --- /dev/null +++ b/testing/web-platform/tests/fetch/api/basic/stream-response.html @@ -0,0 +1,16 @@ +<!doctype html> +<html> + <head> + <meta charset="utf-8"> + <title>Fetch: retrieve response's body progressively</title> + <meta name="help" href="https://fetch.spec.whatwg.org/#main-fetch"> + <meta name="help" href="https://fetch.spec.whatwg.org/#http-fetch"> + <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 src="stream-response.js"></script> + </body> +</html>
\ No newline at end of file diff --git a/testing/web-platform/tests/fetch/api/basic/stream-response.js b/testing/web-platform/tests/fetch/api/basic/stream-response.js new file mode 100644 index 000000000..322b16455 --- /dev/null +++ b/testing/web-platform/tests/fetch/api/basic/stream-response.js @@ -0,0 +1,33 @@ +if (this.document === undefined) { + importScripts("/resources/testharness.js"); + importScripts("../resources/utils.js"); +} + +function streamBody(reader, test, count) { + return reader.read().then(function(data) { + if (!data.done && count < 2) { + count += 1; + return streamBody(reader, test, count); + } else { + test.step(function() { + assert_true(count >= 2, "Retrieve body progressively"); + }); + } + }); +} + +//simulate streaming: +//count is large enough to let the UA deliver the body before it is completely retrieved +promise_test(function(test) { + return fetch(RESOURCES_DIR + "trickle.py?ms=30&count=100").then(function(resp) { + var count = 0; + if (resp.body) + return streamBody(resp.body.getReader(), test, count); + else + test.step(function() { + assert_unreached( "Body does not exist in response"); + }); + }); +}, "Stream response's body"); + +done(); diff --git a/testing/web-platform/tests/fetch/api/basic/text-utf8.html b/testing/web-platform/tests/fetch/api/basic/text-utf8.html new file mode 100644 index 000000000..7499a474a --- /dev/null +++ b/testing/web-platform/tests/fetch/api/basic/text-utf8.html @@ -0,0 +1,69 @@ +<!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> + +function testTextDecoding(body, expectedText, urlParameter, title) +{ + var arrayBuffer = stringToArray(body); + + promise_test(function(test) { + var request = new Request("", {method: "POST", body: arrayBuffer}); + return request.text().then(function(value) { + assert_equals(value, expectedText, "Request.text() should decode data as UTF-8"); + }); + }, title + " with Request.text()"); + + promise_test(function(test) { + var response = new Response(arrayBuffer); + return response.text().then(function(value) { + assert_equals(value, expectedText, "Response.text() should decode data as UTF-8"); + }); + }, title + " with Response.text()"); + + promise_test(function(test) { + return fetch("../resources/status.py?code=200&type=text%2Fplain%3Bcharset%3DUTF-8&content=" + urlParameter).then(function(response) { + return response.text().then(function(value) { + assert_equals(value, expectedText, "Fetched Response.text() should decode data as UTF-8"); + }); + }); + }, title + " with fetched data (UTF-8 charset)"); + + promise_test(function(test) { + return fetch("../resources/status.py?code=200&type=text%2Fplain%3Bcharset%3DUTF-16&content=" + urlParameter).then(function(response) { + return response.text().then(function(value) { + assert_equals(value, expectedText, "Fetched Response.text() should decode data as UTF-8"); + }); + }); + }, title + " with fetched data (UTF-16 charset)"); +} + +var utf8WithBOM = "\xef\xbb\xbf\xe4\xb8\x89\xe6\x9d\x91\xe3\x81\x8b\xe3\x81\xaa\xe5\xad\x90"; +var utf8WithBOMAsURLParameter = "%EF%BB%BF%E4%B8%89%E6%9D%91%E3%81%8B%E3%81%AA%E5%AD%90"; +var utf8WithoutBOM = "\xe4\xb8\x89\xe6\x9d\x91\xe3\x81\x8b\xe3\x81\xaa\xe5\xad\x90"; +var utf8WithoutBOMAsURLParameter = "%E4%B8%89%E6%9D%91%E3%81%8B%E3%81%AA%E5%AD%90"; +var utf8Decoded = "三村かな子"; +testTextDecoding(utf8WithBOM, utf8Decoded, utf8WithBOMAsURLParameter, "UTF-8 with BOM"); +testTextDecoding(utf8WithoutBOM, utf8Decoded, utf8WithoutBOMAsURLParameter, "UTF-8 without BOM"); + +var utf16BEWithBOM = "\xfe\xff\x4e\x09\x67\x51\x30\x4b\x30\x6a\x5b\x50"; +var utf16BEWithBOMAsURLParameter = "%fe%ff%4e%09%67%51%30%4b%30%6a%5b%50"; +var utf16BEWithBOMDecodedAsUTF8 = "��N\tgQ0K0j[P"; +testTextDecoding(utf16BEWithBOM, utf16BEWithBOMDecodedAsUTF8, utf16BEWithBOMAsURLParameter, "UTF-16BE with BOM decoded as UTF-8"); + +var utf16LEWithBOM = "\xff\xfe\x09\x4e\x51\x67\x4b\x30\x6a\x30\x50\x5b"; +var utf16LEWithBOMAsURLParameter = "%ff%fe%09%4e%51%67%4b%30%6a%30%50%5b"; +var utf16LEWithBOMDecodedAsUTF8 = "��\tNQgK0j0P["; +testTextDecoding(utf16LEWithBOM, utf16LEWithBOMDecodedAsUTF8, utf16LEWithBOMAsURLParameter, "UTF-16LE with BOM decoded as UTF-8"); + +var utf16WithoutBOM = "\xe6\x00\xf8\x00\xe5\x00\x0a\x00\xc6\x30\xb9\x30\xc8\x30\x0a\x00"; +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> |