test_bug884693.xhtml (3275B)
1 <?xml version="1.0"?> 2 <?xml-stylesheet href="chrome://global/skin" type="text/css"?> 3 <?xml-stylesheet href="chrome://mochikit/content/tests/SimpleTest/test.css" type="text/css"?> 4 <!-- 5 https://bugzilla.mozilla.org/show_bug.cgi?id=884693 6 --> 7 <window title="Mozilla Bug 884693" 8 xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"> 9 <script src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"/> 10 11 <!-- test results are displayed in the html:body --> 12 <body xmlns="http://www.w3.org/1999/xhtml"> 13 <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=884693" 14 target="_blank">Mozilla Bug 884693</a> 15 </body> 16 17 <!-- test code goes here --> 18 <script type="application/javascript"><![CDATA[ 19 20 const SERVER_URL = "http://mochi.test:8888/tests/dom/base/test/chrome/bug884693.sjs"; 21 const INVALID_XML = "InvalidXML"; 22 const XML_WITHOUT_ROOT = "<?xml version='1.0'?>"; 23 24 function runTest(status, statusText, body, expectedResponse, expectedMessages) 25 { 26 return new Promise((resolve, reject) => { 27 Services.console.reset(); 28 29 let xhr = new XMLHttpRequest(); 30 31 xhr.onload = () => { 32 is(xhr.responseText, expectedResponse, "Correct responseText returned"); 33 34 let messages = Services.console.getMessageArray() || []; 35 // broadcastlisteners can happen and cause false alarm. 36 messages = messages.filter(msg => 37 !(msg instanceof Ci.nsIScriptError && 38 msg.category.includes("chrome javascript") && 39 msg.message.includes("Unknown event"))); 40 41 if (messages.length) { 42 info(`Got console messages ${messages}`); 43 } 44 is(messages.length, expectedMessages.length, "Got expected message count"); 45 messages = messages.map(m => m.message).join(","); 46 for(let message of expectedMessages) { 47 ok(messages.includes(message), "Got expected message: " + message); 48 } 49 50 resolve(); 51 }; 52 53 xhr.onerror = e => { 54 reject(e); 55 }; 56 57 xhr.open("GET", `${SERVER_URL}?${status}&${statusText}&${body}`); 58 xhr.send(); 59 }); 60 } 61 62 SimpleTest.waitForExplicitFinish(); 63 runTest(201, "Created", "", "", []). 64 then(() => { return runTest(201, "Created", INVALID_XML, INVALID_XML, []); }). 65 then(() => { return runTest(202, "Accepted", "", "", []); }). 66 then(() => { return runTest(202, "Accepted", INVALID_XML, INVALID_XML, []); }). 67 then(() => { return runTest(204, "No Content", "", "", []); }). 68 then(() => { return runTest(204, "No Content", INVALID_XML, "", []); }). 69 then(() => { return runTest(205, "Reset Content", "", "", []); }). 70 then(() => { return runTest(205, "Reset Content", INVALID_XML, "", []); }). 71 then(() => { return runTest(304, "Not modified", "", "", []); }). 72 then(() => { return runTest(304, "Not modified", INVALID_XML, "", []); }). 73 then(() => { return runTest(200, "OK", "", "", []); }). 74 then(() => { return runTest(200, "OK", XML_WITHOUT_ROOT, XML_WITHOUT_ROOT, ["no root element found"]); }). 75 then(() => { return runTest(200, "OK", INVALID_XML, INVALID_XML, ["syntax error"]); }). 76 then(SimpleTest.finish); 77 78 ]]></script> 79 </window>