summaryrefslogtreecommitdiffstats
path: root/test/wpt/tests/fetch/content-length
diff options
context:
space:
mode:
Diffstat (limited to 'test/wpt/tests/fetch/content-length')
-rw-r--r--test/wpt/tests/fetch/content-length/api-and-duplicate-headers.any.js23
-rw-r--r--test/wpt/tests/fetch/content-length/content-length.html14
-rw-r--r--test/wpt/tests/fetch/content-length/content-length.html.headers1
-rw-r--r--test/wpt/tests/fetch/content-length/parsing.window.js18
-rw-r--r--test/wpt/tests/fetch/content-length/resources/content-length.py10
-rw-r--r--test/wpt/tests/fetch/content-length/resources/content-lengths.json142
-rw-r--r--test/wpt/tests/fetch/content-length/resources/identical-duplicates.asis9
-rw-r--r--test/wpt/tests/fetch/content-length/too-long.window.js4
8 files changed, 221 insertions, 0 deletions
diff --git a/test/wpt/tests/fetch/content-length/api-and-duplicate-headers.any.js b/test/wpt/tests/fetch/content-length/api-and-duplicate-headers.any.js
new file mode 100644
index 0000000..8015289
--- /dev/null
+++ b/test/wpt/tests/fetch/content-length/api-and-duplicate-headers.any.js
@@ -0,0 +1,23 @@
+promise_test(async t => {
+ const response = await fetch("resources/identical-duplicates.asis");
+ assert_equals(response.statusText, "BLAH");
+ assert_equals(response.headers.get("test"), "x, x");
+ assert_equals(response.headers.get("content-type"), "text/plain, text/plain");
+ assert_equals(response.headers.get("content-length"), "6, 6");
+ const text = await response.text();
+ assert_equals(text, "Test.\n");
+}, "fetch() and duplicate Content-Length/Content-Type headers");
+
+async_test(t => {
+ const xhr = new XMLHttpRequest();
+ xhr.open("GET", "resources/identical-duplicates.asis");
+ xhr.send();
+ xhr.onload = t.step_func_done(() => {
+ assert_equals(xhr.statusText, "BLAH");
+ assert_equals(xhr.getResponseHeader("test"), "x, x");
+ assert_equals(xhr.getResponseHeader("content-type"), "text/plain, text/plain");
+ assert_equals(xhr.getResponseHeader("content-length"), "6, 6");
+ assert_equals(xhr.getAllResponseHeaders(), "content-length: 6, 6\r\ncontent-type: text/plain, text/plain\r\ntest: x, x\r\n");
+ assert_equals(xhr.responseText, "Test.\n");
+ });
+}, "XMLHttpRequest and duplicate Content-Length/Content-Type headers");
diff --git a/test/wpt/tests/fetch/content-length/content-length.html b/test/wpt/tests/fetch/content-length/content-length.html
new file mode 100644
index 0000000..cda9b5b
--- /dev/null
+++ b/test/wpt/tests/fetch/content-length/content-length.html
@@ -0,0 +1,14 @@
+<!DOCTYPE html>
+<!-- CAUTION: if updating this test also update the expected content-length in the .headers file -->
+<title>Content-Length Test</title>
+<script src="/resources/testharness.js"></script>
+<script src="/resources/testharnessreport.js"></script>
+<script>
+setup({ single_test: true });
+onload = function() {
+ assert_equals(document.body.textContent, "PASS");
+ done();
+}
+</script>
+<body>PASS
+but FAIL if this is in the body. \ No newline at end of file
diff --git a/test/wpt/tests/fetch/content-length/content-length.html.headers b/test/wpt/tests/fetch/content-length/content-length.html.headers
new file mode 100644
index 0000000..25389b7
--- /dev/null
+++ b/test/wpt/tests/fetch/content-length/content-length.html.headers
@@ -0,0 +1 @@
+Content-Length: 403
diff --git a/test/wpt/tests/fetch/content-length/parsing.window.js b/test/wpt/tests/fetch/content-length/parsing.window.js
new file mode 100644
index 0000000..5028ad9
--- /dev/null
+++ b/test/wpt/tests/fetch/content-length/parsing.window.js
@@ -0,0 +1,18 @@
+promise_test(() => {
+ return fetch("resources/content-lengths.json").then(res => res.json()).then(runTests);
+}, "Loading JSONā€¦");
+
+function runTests(testUnits) {
+ testUnits.forEach(({ input, output }) => {
+ promise_test(t => {
+ const result = fetch(`resources/content-length.py?length=${encodeURIComponent(input)}`);
+ if (output === null) {
+ return promise_rejects_js(t, TypeError, result);
+ } else {
+ return result.then(res => res.text()).then(text => {
+ assert_equals(text.length, output);
+ });
+ }
+ }, `Input: ${format_value(input)}. Expected: ${output === null ? "network error" : output}.`);
+ });
+}
diff --git a/test/wpt/tests/fetch/content-length/resources/content-length.py b/test/wpt/tests/fetch/content-length/resources/content-length.py
new file mode 100644
index 0000000..92cfade
--- /dev/null
+++ b/test/wpt/tests/fetch/content-length/resources/content-length.py
@@ -0,0 +1,10 @@
+def main(request, response):
+ response.add_required_headers = False
+ output = b"HTTP/1.1 200 OK\r\n"
+ output += b"Content-Type: text/plain;charset=UTF-8\r\n"
+ output += b"Connection: close\r\n"
+ output += request.GET.first(b"length") + b"\r\n"
+ output += b"\r\n"
+ output += b"Fact: this is really forty-two bytes long."
+ response.writer.write(output)
+ response.close_connection = True
diff --git a/test/wpt/tests/fetch/content-length/resources/content-lengths.json b/test/wpt/tests/fetch/content-length/resources/content-lengths.json
new file mode 100644
index 0000000..ac6f1a2
--- /dev/null
+++ b/test/wpt/tests/fetch/content-length/resources/content-lengths.json
@@ -0,0 +1,142 @@
+[
+ {
+ "input": "Content-Length: 42",
+ "output": 42
+ },
+ {
+ "input": "Content-Length: 42,42",
+ "output": 42
+ },
+ {
+ "input": "Content-Length: 42\r\nContent-Length: 42",
+ "output": 42
+ },
+ {
+ "input": "Content-Length: 42\r\nContent-Length: 42,42",
+ "output": 42
+ },
+ {
+ "input": "Content-Length: 30",
+ "output": 30
+ },
+ {
+ "input": "Content-Length: 30,30",
+ "output": 30
+ },
+ {
+ "input": "Content-Length: 30\r\nContent-Length: 30",
+ "output": 30
+ },
+ {
+ "input": "Content-Length: 30\r\nContent-Length: 30,30",
+ "output": 30
+ },
+ {
+ "input": "Content-Length: 30,30\r\nContent-Length: 30,30",
+ "output": 30
+ },
+ {
+ "input": "Content-Length: 30,30, 30 \r\nContent-Length: 30 ",
+ "output": 30
+ },
+ {
+ "input": "Content-Length: 30,42\r\nContent-Length: 30",
+ "output": null
+ },
+ {
+ "input": "Content-Length: 30,42\r\nContent-Length: 30,42",
+ "output": null
+ },
+ {
+ "input": "Content-Length: 42,30",
+ "output": null
+ },
+ {
+ "input": "Content-Length: 30,42",
+ "output": null
+ },
+ {
+ "input": "Content-Length: 42\r\nContent-Length: 30",
+ "output": null
+ },
+ {
+ "input": "Content-Length: 30\r\nContent-Length: 42",
+ "output": null
+ },
+ {
+ "input": "Content-Length: 30,",
+ "output": null
+ },
+ {
+ "input": "Content-Length: ,30",
+ "output": null
+ },
+ {
+ "input": "Content-Length: 30\r\nContent-Length: \t",
+ "output": null
+ },
+ {
+ "input": "Content-Length: \r\nContent-Length: 30",
+ "output": null
+ },
+ {
+ "input": "Content-Length: aaaah\r\nContent-Length: nah",
+ "output": null
+ },
+ {
+ "input": "Content-Length: aaaah, nah",
+ "output": null
+ },
+ {
+ "input": "Content-Length: aaaah\r\nContent-Length: aaaah",
+ "output": 42
+ },
+ {
+ "input": "Content-Length: aaaah, aaaah",
+ "output": 42
+ },
+ {
+ "input": "Content-Length: aaaah",
+ "output": 42
+ },
+ {
+ "input": "Content-Length: 42s",
+ "output": 42
+ },
+ {
+ "input": "Content-Length: 30s",
+ "output": 42
+ },
+ {
+ "input": "Content-Length: -1",
+ "output": 42
+ },
+ {
+ "input": "Content-Length: 0x20",
+ "output": 42
+ },
+ {
+ "input": "Content-Length: 030",
+ "output": 30
+ },
+ {
+ "input": "Content-Length: 030\r\nContent-Length: 30",
+ "output": null
+ },
+ {
+ "input": "Content-Length: 030, 30",
+ "output": null
+ },
+ {
+ "input": "Content-Length: \"30\"",
+ "output": 42
+ },
+ {
+ "input": "Content-Length:30\r\nContent-Length:,\r\nContent-Length:30",
+ "output": null
+ },
+ {
+ "input": "Content-Length: ",
+ "output": 42
+ }
+]
diff --git a/test/wpt/tests/fetch/content-length/resources/identical-duplicates.asis b/test/wpt/tests/fetch/content-length/resources/identical-duplicates.asis
new file mode 100644
index 0000000..f38c9a4
--- /dev/null
+++ b/test/wpt/tests/fetch/content-length/resources/identical-duplicates.asis
@@ -0,0 +1,9 @@
+HTTP/1.1 200 BLAH
+Test: x
+Test: x
+Content-Type: text/plain
+Content-Type: text/plain
+Content-Length: 6
+Content-Length: 6
+
+Test.
diff --git a/test/wpt/tests/fetch/content-length/too-long.window.js b/test/wpt/tests/fetch/content-length/too-long.window.js
new file mode 100644
index 0000000..f8cefaa
--- /dev/null
+++ b/test/wpt/tests/fetch/content-length/too-long.window.js
@@ -0,0 +1,4 @@
+promise_test(async t => {
+ const result = await fetch(`resources/content-length.py?length=${encodeURIComponent("Content-Length: 50")}`);
+ await promise_rejects_js(t, TypeError, result.text());
+}, "Content-Length header value of network response exceeds response body");