mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-02-04 04:58:00 +00:00
Bug 1591579 - Test for XHR on sharedWorkers, r=smaug
Differential Revision: https://phabricator.services.mozilla.com/D50951 --HG-- extra : moz-landing-system : lando
This commit is contained in:
parent
6c4f3e3599
commit
07aed8049d
@ -113,3 +113,5 @@ skip-if = toolkit == "android" && debug && !is_fennec
|
||||
skip-if = (os == "win" && processor == "aarch64") #bug 1535784
|
||||
[test_worker_xhr_doubleSend.html]
|
||||
support-files = xhr_worker_doubleSend.js
|
||||
[test_sharedworker_xhr.html]
|
||||
support-files = xhr_sharedworker.js
|
||||
|
23
dom/xhr/tests/test_sharedworker_xhr.html
Normal file
23
dom/xhr/tests/test_sharedworker_xhr.html
Normal file
@ -0,0 +1,23 @@
|
||||
<!DOCTYPE HTML>
|
||||
<html>
|
||||
<head>
|
||||
<title>Test for SharedWorker Threads XHR</title>
|
||||
<script src="/tests/SimpleTest/SimpleTest.js"></script>
|
||||
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
|
||||
</head>
|
||||
<body>
|
||||
<script class="testbody" type="text/javascript">
|
||||
|
||||
var worker = new SharedWorker("xhr_sharedworker.js");
|
||||
|
||||
worker.port.onmessage = function(event) {
|
||||
is(event.data, "done", "Got correct result");
|
||||
SimpleTest.finish();
|
||||
}
|
||||
worker.port.postMessage("worker_testXHR.txt");
|
||||
|
||||
SimpleTest.waitForExplicitFinish();
|
||||
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
105
dom/xhr/tests/xhr_sharedworker.js
Normal file
105
dom/xhr/tests/xhr_sharedworker.js
Normal file
@ -0,0 +1,105 @@
|
||||
/**
|
||||
* Any copyright is dedicated to the Public Domain.
|
||||
* http://creativecommons.org/publicdomain/zero/1.0/
|
||||
*/
|
||||
|
||||
/* eslint-env worker */
|
||||
onconnect = e => {
|
||||
e.ports[0].onmessage = 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 (ex) {
|
||||
exception = ex;
|
||||
}
|
||||
|
||||
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");
|
||||
}
|
||||
|
||||
e.ports[0].postMessage("done");
|
||||
};
|
||||
};
|
Loading…
x
Reference in New Issue
Block a user