summaryrefslogtreecommitdiffstats
path: root/testing/mochitest/tests/browser/browser_document_builder_sjs.js
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 19:33:14 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 19:33:14 +0000
commit36d22d82aa202bb199967e9512281e9a53db42c9 (patch)
tree105e8c98ddea1c1e4784a60a5a6410fa416be2de /testing/mochitest/tests/browser/browser_document_builder_sjs.js
parentInitial commit. (diff)
downloadfirefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.tar.xz
firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.zip
Adding upstream version 115.7.0esr.upstream/115.7.0esr
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'testing/mochitest/tests/browser/browser_document_builder_sjs.js')
-rw-r--r--testing/mochitest/tests/browser/browser_document_builder_sjs.js74
1 files changed, 74 insertions, 0 deletions
diff --git a/testing/mochitest/tests/browser/browser_document_builder_sjs.js b/testing/mochitest/tests/browser/browser_document_builder_sjs.js
new file mode 100644
index 0000000000..4b653a792d
--- /dev/null
+++ b/testing/mochitest/tests/browser/browser_document_builder_sjs.js
@@ -0,0 +1,74 @@
+/* Any copyright is dedicated to the Public Domain.
+ * http://creativecommons.org/publicdomain/zero/1.0/ */
+"use strict";
+
+// Checks that document-builder.sjs works as expected
+add_task(async function assertHtmlParam() {
+ const html = "<main><h1>I'm built different</h1></main>";
+ const delay = 5000;
+
+ const params = new URLSearchParams({
+ delay,
+ html,
+ });
+ params.append("headers", "x-header-1:a");
+ params.append("headers", "x-header-2:b");
+
+ const startTime = performance.now();
+ const request = new Request(
+ `https://example.com/document-builder.sjs?${params}`
+ );
+ info("Do a fetch request to document-builder.sjs");
+ const response = await fetch(request);
+ const duration = performance.now() - startTime;
+
+ is(response.status, 200, "Response is a 200");
+ ok(
+ duration > delay,
+ `The delay parameter works as expected (took ${duration}ms)`
+ );
+
+ const responseText = await response.text();
+ is(responseText, html, "The response has the expected content");
+
+ is(
+ response.headers.get("content-type"),
+ "text/html",
+ "response has the expected content-type"
+ );
+ is(
+ response.headers.get("x-header-1"),
+ "a",
+ "first header was set as expected"
+ );
+ is(
+ response.headers.get("x-header-2"),
+ "b",
+ "second header was set as expected"
+ );
+});
+
+add_task(async function assertFileParam() {
+ const file = `browser/testing/mochitest/tests/browser/dummy.html`;
+ const request = new Request(
+ `https://example.com/document-builder.sjs?file=${file}`
+ );
+
+ info("Do a fetch request to document-builder.sjs with a `file` parameter");
+ const response = await fetch(request);
+ is(response.status, 200, "Response is a 200");
+ is(
+ response.headers.get("content-type"),
+ "text/html",
+ "response has the expected content-type"
+ );
+
+ const responseText = await response.text();
+ const parser = new DOMParser();
+ const doc = parser.parseFromString(responseText, "text/html");
+ is(
+ doc.body.innerHTML.trim(),
+ "This is a dummy page",
+ "The response has the file content"
+ );
+});