summaryrefslogtreecommitdiffstats
path: root/dom/xhr/tests/xhr_worker.js
diff options
context:
space:
mode:
authorMatt A. Tobin <mattatobin@localhost.localdomain>2018-02-02 04:16:08 -0500
committerMatt A. Tobin <mattatobin@localhost.localdomain>2018-02-02 04:16:08 -0500
commit5f8de423f190bbb79a62f804151bc24824fa32d8 (patch)
tree10027f336435511475e392454359edea8e25895d /dom/xhr/tests/xhr_worker.js
parent49ee0794b5d912db1f95dce6eb52d781dc210db5 (diff)
downloadUXP-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 'dom/xhr/tests/xhr_worker.js')
-rw-r--r--dom/xhr/tests/xhr_worker.js84
1 files changed, 84 insertions, 0 deletions
diff --git a/dom/xhr/tests/xhr_worker.js b/dom/xhr/tests/xhr_worker.js
new file mode 100644
index 000000000..178c391b6
--- /dev/null
+++ b/dom/xhr/tests/xhr_worker.js
@@ -0,0 +1,84 @@
+/**
+ * Any copyright is dedicated to the Public Domain.
+ * http://creativecommons.org/publicdomain/zero/1.0/
+ */
+var xhr = new XMLHttpRequest();
+
+function onload(event) {
+ if (event.target != xhr) {
+ throw "onload event.target != xhr";
+ }
+
+ if (event.target.status != 200) {
+ var message = { type: "error",
+ error: event.target.status };
+ postMessage(message);
+ }
+
+ var message = { type: "load",
+ data: xhr.responseText };
+ postMessage(message);
+}
+
+xhr.onload = onload;
+xhr.addEventListener("load", onload, false);
+xhr.removeEventListener("load", onload, false);
+if (!xhr.onload) {
+ var message = { type: "error",
+ error: "Lost message listener!" };
+ postMessage(message);
+}
+
+xhr.onerror = function(event) {
+ if (event.target != xhr) {
+ throw "onerror event.target != xhr";
+ }
+ var message = { type: "error",
+ error: event.target.status };
+ postMessage(message);
+};
+xhr.onerror = xhr.onerror;
+if (!xhr.onerror || xhr.onerror != xhr.onerror) {
+ throw "onerror wasn't set properly";
+}
+
+function onprogress(event) {
+ if (event.target != xhr) {
+ throw "onprogress event.target != xhr";
+ }
+ var message = { type: "progress",
+ current: event.loaded,
+ total: event.total };
+ postMessage(message);
+}
+xhr.addEventListener("progress", onprogress, false);
+
+xhr.addEventListener("foopety", function(event) {}, false);
+xhr.removeEventListener("doopety", function(event) {}, false);
+
+xhr.onloadend = function(event) {
+ var message = { type: "loadend" };
+ postMessage(message);
+}
+
+var upload = xhr.upload;
+upload.onprogress = function(event) { };
+upload.addEventListener("foo", function(event) { }, false);
+upload.removeEventListener("foo", function(event) { }, false);
+upload.addEventListener("load", function(event) { }, false);
+upload.removeEventListener("foo", function(event) { }, false);
+upload.onload = function(event) {
+ var message = { type: "upload.load" };
+ postMessage(message);
+}
+
+onmessage = function(event) {
+ if (xhr.DONE != 4 || XMLHttpRequest.DONE != 4) {
+ throw "xhr constants not correct!";
+ }
+ if (xhr.readystate > xhr.UNSENT) {
+ throw "XHR already running!";
+ }
+ xhr.open("POST", event.data);
+ xhr.send("Data to send");
+}