Source code

Revision control

Copy as Markdown

Other Tools

Test Info: Warnings

<?xml version="1.0"?>
<?xml-stylesheet href="chrome://global/skin" type="text/css"?>
<?xml-stylesheet href="chrome://mochikit/content/tests/SimpleTest/test.css" type="text/css"?>
<!--
-->
<window title="Mozilla Bug 884693"
<!-- test results are displayed in the html:body -->
target="_blank">Mozilla Bug 884693</a>
</body>
<!-- test code goes here -->
<script type="application/javascript"><![CDATA[
const INVALID_XML = "InvalidXML";
const XML_WITHOUT_ROOT = "<?xml version='1.0'?>";
function runTest(status, statusText, body, expectedResponse, expectedMessages)
{
return new Promise((resolve, reject) => {
Services.console.reset();
let xhr = new XMLHttpRequest();
xhr.onload = () => {
is(xhr.responseText, expectedResponse, "Correct responseText returned");
let messages = Services.console.getMessageArray() || [];
// broadcastlisteners can happen and cause false alarm.
messages = messages.filter(msg =>
!(msg instanceof Ci.nsIScriptError &&
msg.category.includes("chrome javascript") &&
msg.message.includes("Unknown event")));
if (messages.length) {
info(`Got console messages ${messages}`);
}
is(messages.length, expectedMessages.length, "Got expected message count");
messages = messages.map(m => m.message).join(",");
for(let message of expectedMessages) {
ok(messages.includes(message), "Got expected message: " + message);
}
resolve();
};
xhr.onerror = e => {
reject(e);
};
xhr.open("GET", `${SERVER_URL}?${status}&${statusText}&${body}`);
xhr.send();
});
}
SimpleTest.waitForExplicitFinish();
runTest(201, "Created", "", "", []).
then(() => { return runTest(201, "Created", INVALID_XML, INVALID_XML, []); }).
then(() => { return runTest(202, "Accepted", "", "", []); }).
then(() => { return runTest(202, "Accepted", INVALID_XML, INVALID_XML, []); }).
then(() => { return runTest(204, "No Content", "", "", []); }).
then(() => { return runTest(204, "No Content", INVALID_XML, "", []); }).
then(() => { return runTest(205, "Reset Content", "", "", []); }).
then(() => { return runTest(205, "Reset Content", INVALID_XML, "", []); }).
then(() => { return runTest(304, "Not modified", "", "", []); }).
then(() => { return runTest(304, "Not modified", INVALID_XML, "", []); }).
then(() => { return runTest(200, "OK", "", "", []); }).
then(() => { return runTest(200, "OK", XML_WITHOUT_ROOT, XML_WITHOUT_ROOT, ["no root element found"]); }).
then(() => { return runTest(200, "OK", INVALID_XML, INVALID_XML, ["syntax error"]); }).
then(SimpleTest.finish);
]]></script>
</window>