summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/fetch/data-urls
diff options
context:
space:
mode:
Diffstat (limited to 'testing/web-platform/tests/fetch/data-urls')
-rw-r--r--testing/web-platform/tests/fetch/data-urls/README.md11
-rw-r--r--testing/web-platform/tests/fetch/data-urls/base64.any.js18
-rw-r--r--testing/web-platform/tests/fetch/data-urls/navigate.window.js75
-rw-r--r--testing/web-platform/tests/fetch/data-urls/processing.any.js22
-rw-r--r--testing/web-platform/tests/fetch/data-urls/resources/base64.json82
-rw-r--r--testing/web-platform/tests/fetch/data-urls/resources/data-urls.json214
6 files changed, 422 insertions, 0 deletions
diff --git a/testing/web-platform/tests/fetch/data-urls/README.md b/testing/web-platform/tests/fetch/data-urls/README.md
new file mode 100644
index 0000000000..1ce5b18b53
--- /dev/null
+++ b/testing/web-platform/tests/fetch/data-urls/README.md
@@ -0,0 +1,11 @@
+## data: URLs
+
+`resources/data-urls.json` contains `data:` URL tests. The tests are encoded as a JSON array. Each value in the array is an array of two or three values. The first value describes the input, the second value describes the expected MIME type, null if the input is expected to fail somehow, or the empty string if the expected value is `text/plain;charset=US-ASCII`. The third value, if present, describes the expected body as an array of integers representing bytes.
+
+These tests are used for `data:` URLs in this directory (see `processing.any.js`).
+
+## Forgiving-base64 decode
+
+`resources/base64.json` contains [forgiving-base64 decode](https://infra.spec.whatwg.org/#forgiving-base64-decode) tests. The tests are encoded as a JSON array. Each value in the array is an array of two values. The first value describes the input, the second value describes the output as an array of integers representing bytes or null if the input cannot be decoded.
+
+These tests are used for `data:` URLs in this directory (see `base64.any.js`) and `window.atob()` in `../../html/webappapis/atob/base64.html`.
diff --git a/testing/web-platform/tests/fetch/data-urls/base64.any.js b/testing/web-platform/tests/fetch/data-urls/base64.any.js
new file mode 100644
index 0000000000..83f34db177
--- /dev/null
+++ b/testing/web-platform/tests/fetch/data-urls/base64.any.js
@@ -0,0 +1,18 @@
+// META: global=window,worker
+
+promise_test(() => fetch("resources/base64.json").then(res => res.json()).then(runBase64Tests), "Setup.");
+function runBase64Tests(tests) {
+ for(let i = 0; i < tests.length; i++) {
+ const input = tests[i][0],
+ output = tests[i][1],
+ dataURL = "data:;base64," + input;
+ promise_test(t => {
+ if(output === null) {
+ return promise_rejects_js(t, TypeError, fetch(dataURL));
+ }
+ return fetch(dataURL).then(res => res.arrayBuffer()).then(body => {
+ assert_array_equals(new Uint8Array(body), output);
+ });
+ }, "data: URL base64 handling: " + format_value(input));
+ }
+}
diff --git a/testing/web-platform/tests/fetch/data-urls/navigate.window.js b/testing/web-platform/tests/fetch/data-urls/navigate.window.js
new file mode 100644
index 0000000000..b532a00683
--- /dev/null
+++ b/testing/web-platform/tests/fetch/data-urls/navigate.window.js
@@ -0,0 +1,75 @@
+// META: timeout=long
+//
+// Test some edge cases around navigation to data: URLs to ensure they use the same code path
+
+[
+ {
+ input: "data:text/html,<script>parent.postMessage(1, '*')</script>",
+ result: 1,
+ name: "Nothing fancy",
+ },
+ {
+ input: "data:text/html;base64,PHNjcmlwdD5wYXJlbnQucG9zdE1lc3NhZ2UoMiwgJyonKTwvc2NyaXB0Pg==",
+ result: 2,
+ name: "base64",
+ },
+ {
+ input: "data:text/html;base64,PHNjcmlwdD5wYXJlbnQucG9zdE1lc3NhZ2UoNCwgJyonKTwvc2NyaXB0Pr+/",
+ result: 4,
+ name: "base64 with code points that differ from base64url"
+ },
+ {
+ input: "data:text/html;base64,PHNjcml%09%20%20%0A%0C%0DwdD5wYXJlbnQucG9zdE1lc3NhZ2UoNiwgJyonKTwvc2NyaXB0Pg==",
+ result: 6,
+ name: "ASCII whitespace in the input is removed"
+ }
+].forEach(({ input, result, name }) => {
+ // Use promise_test so they go sequentially
+ promise_test(async t => {
+ const event = await new Promise((resolve, reject) => {
+ self.addEventListener("message", t.step_func(resolve), { once: true });
+ const frame = document.body.appendChild(document.createElement("iframe"));
+ t.add_cleanup(() => frame.remove());
+
+ // The assumption is that postMessage() is quicker
+ t.step_timeout(reject, 500);
+ frame.src = input;
+ });
+ assert_equals(event.data, result);
+ }, name);
+});
+
+// Failure cases
+[
+ {
+ input: "data:text/html;base64,PHNjcmlwdD5wYXJlbnQucG9zdE1lc3NhZ2UoMywgJyonKTwvc2NyaXB0Pg=",
+ name: "base64 with incorrect padding",
+ },
+ {
+ input: "data:text/html;base64,PHNjcmlwdD5wYXJlbnQucG9zdE1lc3NhZ2UoNSwgJyonKTwvc2NyaXB0Pr-_",
+ name: "base64url is not supported"
+ },
+ {
+ input: "data:text/html;base64,%0BPHNjcmlwdD5wYXJlbnQucG9zdE1lc3NhZ2UoNywgJyonKTwvc2NyaXB0Pg==",
+ name: "Vertical tab in the input leads to an error"
+ }
+].forEach(({ input, name }) => {
+ // Continue to use promise_test so they go sequentially
+ promise_test(async t => {
+ const event = await new Promise((resolve, reject) => {
+ self.addEventListener("message", t.step_func(reject), { once: true });
+ const frame = document.body.appendChild(document.createElement("iframe"));
+ t.add_cleanup(() => frame.remove());
+
+ // The assumption is that postMessage() is quicker
+ t.step_timeout(resolve, 500);
+ frame.src = input;
+ });
+ }, name);
+});
+
+// I found some of the interesting code point cases above through brute force:
+//
+// for (i = 0; i < 256; i++) {
+// w(btoa("<script>parent.postMessage(5, '*')<\/script>" + String.fromCodePoint(i) + String.fromCodePoint(i)));
+// }
diff --git a/testing/web-platform/tests/fetch/data-urls/processing.any.js b/testing/web-platform/tests/fetch/data-urls/processing.any.js
new file mode 100644
index 0000000000..cec97bd6be
--- /dev/null
+++ b/testing/web-platform/tests/fetch/data-urls/processing.any.js
@@ -0,0 +1,22 @@
+// META: global=window,worker
+
+promise_test(() => fetch("resources/data-urls.json").then(res => res.json()).then(runDataURLTests), "Setup.");
+function runDataURLTests(tests) {
+ for(let i = 0; i < tests.length; i++) {
+ const input = tests[i][0],
+ expectedMimeType = tests[i][1],
+ expectedBody = expectedMimeType !== null ? tests[i][2] : null;
+ promise_test(t => {
+ if(expectedMimeType === null) {
+ return promise_rejects_js(t, TypeError, fetch(input));
+ } else {
+ return fetch(input).then(res => {
+ return res.arrayBuffer().then(body => {
+ assert_array_equals(new Uint8Array(body), expectedBody);
+ assert_equals(res.headers.get("content-type"), expectedMimeType); // We could assert this earlier, but this fails often
+ });
+ });
+ }
+ }, format_value(input));
+ }
+}
diff --git a/testing/web-platform/tests/fetch/data-urls/resources/base64.json b/testing/web-platform/tests/fetch/data-urls/resources/base64.json
new file mode 100644
index 0000000000..01f981a650
--- /dev/null
+++ b/testing/web-platform/tests/fetch/data-urls/resources/base64.json
@@ -0,0 +1,82 @@
+[
+ ["", []],
+ ["abcd", [105, 183, 29]],
+ [" abcd", [105, 183, 29]],
+ ["abcd ", [105, 183, 29]],
+ [" abcd===", null],
+ ["abcd=== ", null],
+ ["abcd ===", null],
+ ["a", null],
+ ["ab", [105]],
+ ["abc", [105, 183]],
+ ["abcde", null],
+ ["𐀀", null],
+ ["=", null],
+ ["==", null],
+ ["===", null],
+ ["====", null],
+ ["=====", null],
+ ["a=", null],
+ ["a==", null],
+ ["a===", null],
+ ["a====", null],
+ ["a=====", null],
+ ["ab=", null],
+ ["ab==", [105]],
+ ["ab===", null],
+ ["ab====", null],
+ ["ab=====", null],
+ ["abc=", [105, 183]],
+ ["abc==", null],
+ ["abc===", null],
+ ["abc====", null],
+ ["abc=====", null],
+ ["abcd=", null],
+ ["abcd==", null],
+ ["abcd===", null],
+ ["abcd====", null],
+ ["abcd=====", null],
+ ["abcde=", null],
+ ["abcde==", null],
+ ["abcde===", null],
+ ["abcde====", null],
+ ["abcde=====", null],
+ ["=a", null],
+ ["=a=", null],
+ ["a=b", null],
+ ["a=b=", null],
+ ["ab=c", null],
+ ["ab=c=", null],
+ ["abc=d", null],
+ ["abc=d=", null],
+ ["ab\u000Bcd", null],
+ ["ab\u3000cd", null],
+ ["ab\u3001cd", null],
+ ["ab\tcd", [105, 183, 29]],
+ ["ab\ncd", [105, 183, 29]],
+ ["ab\fcd", [105, 183, 29]],
+ ["ab\rcd", [105, 183, 29]],
+ ["ab cd", [105, 183, 29]],
+ ["ab\u00a0cd", null],
+ ["ab\t\n\f\r cd", [105, 183, 29]],
+ [" \t\n\f\r ab\t\n\f\r cd\t\n\f\r ", [105, 183, 29]],
+ ["ab\t\n\f\r =\t\n\f\r =\t\n\f\r ", [105]],
+ ["A", null],
+ ["/A", [252]],
+ ["//A", [255, 240]],
+ ["///A", [255, 255, 192]],
+ ["////A", null],
+ ["/", null],
+ ["A/", [3]],
+ ["AA/", [0, 15]],
+ ["AAAA/", null],
+ ["AAA/", [0, 0, 63]],
+ ["\u0000nonsense", null],
+ ["abcd\u0000nonsense", null],
+ ["YQ", [97]],
+ ["YR", [97]],
+ ["~~", null],
+ ["..", null],
+ ["--", null],
+ ["__", null]
+]
diff --git a/testing/web-platform/tests/fetch/data-urls/resources/data-urls.json b/testing/web-platform/tests/fetch/data-urls/resources/data-urls.json
new file mode 100644
index 0000000000..f318d1f3e5
--- /dev/null
+++ b/testing/web-platform/tests/fetch/data-urls/resources/data-urls.json
@@ -0,0 +1,214 @@
+[
+ ["data://test/,X",
+ "text/plain;charset=US-ASCII",
+ [88]],
+ ["data://test:test/,X",
+ null],
+ ["data:,X",
+ "text/plain;charset=US-ASCII",
+ [88]],
+ ["data:",
+ null],
+ ["data:text/html",
+ null],
+ ["data:text/html ;charset=x ",
+ null],
+ ["data:,",
+ "text/plain;charset=US-ASCII",
+ []],
+ ["data:,X#X",
+ "text/plain;charset=US-ASCII",
+ [88]],
+ ["data:,%FF",
+ "text/plain;charset=US-ASCII",
+ [255]],
+ ["data:text/plain,X",
+ "text/plain",
+ [88]],
+ ["data:text/plain ,X",
+ "text/plain",
+ [88]],
+ ["data:text/plain%20,X",
+ "text/plain%20",
+ [88]],
+ ["data:text/plain\f,X",
+ "text/plain%0c",
+ [88]],
+ ["data:text/plain%0C,X",
+ "text/plain%0c",
+ [88]],
+ ["data:text/plain;,X",
+ "text/plain",
+ [88]],
+ ["data:;x=x;charset=x,X",
+ "text/plain;x=x;charset=x",
+ [88]],
+ ["data:;x=x,X",
+ "text/plain;x=x",
+ [88]],
+ ["data:text/plain;charset=windows-1252,%C2%B1",
+ "text/plain;charset=windows-1252",
+ [194, 177]],
+ ["data:text/plain;Charset=UTF-8,%C2%B1",
+ "text/plain;charset=UTF-8",
+ [194, 177]],
+ ["data:text/plain;charset=windows-1252,áñçə💩",
+ "text/plain;charset=windows-1252",
+ [195, 161, 195, 177, 195, 167, 201, 153, 240, 159, 146, 169]],
+ ["data:text/plain;charset=UTF-8,áñçə💩",
+ "text/plain;charset=UTF-8",
+ [195, 161, 195, 177, 195, 167, 201, 153, 240, 159, 146, 169]],
+ ["data:image/gif,%C2%B1",
+ "image/gif",
+ [194, 177]],
+ ["data:IMAGE/gif,%C2%B1",
+ "image/gif",
+ [194, 177]],
+ ["data:IMAGE/gif;hi=x,%C2%B1",
+ "image/gif;hi=x",
+ [194, 177]],
+ ["data:IMAGE/gif;CHARSET=x,%C2%B1",
+ "image/gif;charset=x",
+ [194, 177]],
+ ["data: ,%FF",
+ "text/plain;charset=US-ASCII",
+ [255]],
+ ["data:%20,%FF",
+ "text/plain;charset=US-ASCII",
+ [255]],
+ ["data:\f,%FF",
+ "text/plain;charset=US-ASCII",
+ [255]],
+ ["data:%1F,%FF",
+ "text/plain;charset=US-ASCII",
+ [255]],
+ ["data:\u0000,%FF",
+ "text/plain;charset=US-ASCII",
+ [255]],
+ ["data:%00,%FF",
+ "text/plain;charset=US-ASCII",
+ [255]],
+ ["data:text/html ,X",
+ "text/html",
+ [88]],
+ ["data:text / html,X",
+ "text/plain;charset=US-ASCII",
+ [88]],
+ ["data:†,X",
+ "text/plain;charset=US-ASCII",
+ [88]],
+ ["data:†/†,X",
+ "%e2%80%a0/%e2%80%a0",
+ [88]],
+ ["data:X,X",
+ "text/plain;charset=US-ASCII",
+ [88]],
+ ["data:image/png,X X",
+ "image/png",
+ [88, 32, 88]],
+ ["data:application/javascript,X X",
+ "application/javascript",
+ [88, 32, 88]],
+ ["data:application/xml,X X",
+ "application/xml",
+ [88, 32, 88]],
+ ["data:text/javascript,X X",
+ "text/javascript",
+ [88, 32, 88]],
+ ["data:text/plain,X X",
+ "text/plain",
+ [88, 32, 88]],
+ ["data:unknown/unknown,X X",
+ "unknown/unknown",
+ [88, 32, 88]],
+ ["data:text/plain;a=\",\",X",
+ "text/plain;a=\"\"",
+ [34, 44, 88]],
+ ["data:text/plain;a=%2C,X",
+ "text/plain;a=%2C",
+ [88]],
+ ["data:;base64;base64,WA",
+ "text/plain",
+ [88]],
+ ["data:x/x;base64;base64,WA",
+ "x/x",
+ [88]],
+ ["data:x/x;base64;charset=x,WA",
+ "x/x;charset=x",
+ [87, 65]],
+ ["data:x/x;base64;charset=x;base64,WA",
+ "x/x;charset=x",
+ [88]],
+ ["data:x/x;base64;base64x,WA",
+ "x/x",
+ [87, 65]],
+ ["data:;base64,W%20A",
+ "text/plain;charset=US-ASCII",
+ [88]],
+ ["data:;base64,W%0CA",
+ "text/plain;charset=US-ASCII",
+ [88]],
+ ["data:x;base64x,WA",
+ "text/plain;charset=US-ASCII",
+ [87, 65]],
+ ["data:x;base64;x,WA",
+ "text/plain;charset=US-ASCII",
+ [87, 65]],
+ ["data:x;base64=x,WA",
+ "text/plain;charset=US-ASCII",
+ [87, 65]],
+ ["data:; base64,WA",
+ "text/plain;charset=US-ASCII",
+ [88]],
+ ["data:; base64,WA",
+ "text/plain;charset=US-ASCII",
+ [88]],
+ ["data: ;charset=x ; base64,WA",
+ "text/plain;charset=x",
+ [88]],
+ ["data:;base64;,WA",
+ "text/plain",
+ [87, 65]],
+ ["data:;base64 ,WA",
+ "text/plain;charset=US-ASCII",
+ [88]],
+ ["data:;base64 ,WA",
+ "text/plain;charset=US-ASCII",
+ [88]],
+ ["data:;base 64,WA",
+ "text/plain",
+ [87, 65]],
+ ["data:;BASe64,WA",
+ "text/plain;charset=US-ASCII",
+ [88]],
+ ["data:;%62ase64,WA",
+ "text/plain",
+ [87, 65]],
+ ["data:%3Bbase64,WA",
+ "text/plain;charset=US-ASCII",
+ [87, 65]],
+ ["data:;charset=x,X",
+ "text/plain;charset=x",
+ [88]],
+ ["data:; charset=x,X",
+ "text/plain;charset=x",
+ [88]],
+ ["data:;charset =x,X",
+ "text/plain",
+ [88]],
+ ["data:;charset= x,X",
+ "text/plain;charset=\" x\"",
+ [88]],
+ ["data:;charset=,X",
+ "text/plain",
+ [88]],
+ ["data:;charset,X",
+ "text/plain",
+ [88]],
+ ["data:;charset=\"x\",X",
+ "text/plain;charset=x",
+ [88]],
+ ["data:;CHARSET=\"X\",X",
+ "text/plain;charset=X",
+ [88]]
+]