summaryrefslogtreecommitdiffstats
path: root/dom/xhr/tests/xhr2_worker.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 /dom/xhr/tests/xhr2_worker.js
parentInitial commit. (diff)
downloadfirefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.tar.xz
firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.zip
Adding upstream version 115.7.0esr.upstream/115.7.0esrupstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'dom/xhr/tests/xhr2_worker.js')
-rw-r--r--dom/xhr/tests/xhr2_worker.js102
1 files changed, 102 insertions, 0 deletions
diff --git a/dom/xhr/tests/xhr2_worker.js b/dom/xhr/tests/xhr2_worker.js
new file mode 100644
index 0000000000..f9bfc88ed9
--- /dev/null
+++ b/dom/xhr/tests/xhr2_worker.js
@@ -0,0 +1,102 @@
+/**
+ * Any copyright is dedicated to the Public Domain.
+ * http://creativecommons.org/publicdomain/zero/1.0/
+ */
+/* eslint-env worker */
+onmessage = function (event) {
+ const url = event.data;
+
+ var xhr = new XMLHttpRequest();
+ xhr.open("GET", url, false);
+ xhr.send();
+
+ const refText = xhr.responseText;
+
+ function getResponse(type) {
+ xhr = new XMLHttpRequest();
+ xhr.open("GET", url, false);
+ if (type !== undefined) {
+ xhr.responseType = type;
+ }
+ xhr.send();
+ return xhr.response;
+ }
+
+ if (getResponse() != refText) {
+ throw new Error("unset responseType failed");
+ }
+
+ if (getResponse("") != refText) {
+ throw new Error("'' responseType failed");
+ }
+
+ if (getResponse("text") != refText) {
+ throw new Error("'text' responseType failed");
+ }
+
+ var array = new Uint8Array(getResponse("arraybuffer"));
+ if (String.fromCharCode.apply(String, array) != refText) {
+ throw new Error("'arraybuffer' responseType failed");
+ }
+
+ var blob = getResponse("blob");
+ if (new FileReaderSync().readAsText(blob) != refText) {
+ throw new Error("'blob' responseType failed");
+ }
+
+ // Make sure that we get invalid state exceptions when getting the wrong
+ // property.
+
+ function testResponseTextException(type) {
+ xhr = new XMLHttpRequest();
+ xhr.open("GET", url, false);
+ xhr.responseType = type;
+ xhr.send();
+
+ var exception;
+
+ try {
+ xhr.responseText;
+ } catch (e) {
+ exception = e;
+ }
+
+ if (!exception) {
+ throw new Error(
+ "Failed to throw when getting responseText on '" + type + "' type"
+ );
+ }
+
+ if (exception.name != "InvalidStateError") {
+ throw new Error(
+ "Unexpected error when getting responseText on '" + type + "' type"
+ );
+ }
+
+ if (exception.code != DOMException.INVALID_STATE_ERR) {
+ throw new Error(
+ "Unexpected error code when getting responseText on '" + type + "' type"
+ );
+ }
+ }
+
+ testResponseTextException("arraybuffer");
+ testResponseTextException("blob");
+
+ // Make sure "document" works, but returns text.
+ xhr = new XMLHttpRequest();
+
+ if (xhr.responseType != "") {
+ throw new Error("Default value for responseType is wrong!");
+ }
+
+ xhr.open("GET", url, false);
+ xhr.responseType = "document";
+ xhr.send();
+
+ if (xhr.responseText != refText) {
+ throw new Error("'document' type not working correctly");
+ }
+
+ postMessage("done");
+};