Bug 1096263 - XMLHttpRequest.send({}) should not throw, tests, r=bz

This commit is contained in:
Olli Pettay 2014-11-11 13:41:20 +02:00
Родитель 90482773b2
Коммит 52b9b1f74d
3 изменённых файлов: 106 добавлений и 0 удалений

21
dom/base/test/echo.sjs Normal file
Просмотреть файл

@ -0,0 +1,21 @@
const CC = Components.Constructor;
const BinaryInputStream = CC("@mozilla.org/binaryinputstream;1",
"nsIBinaryInputStream",
"setInputStream");
function handleRequest(request, response)
{
response.setHeader("Content-Type", "text/plain");
if (request.method == "GET") {
response.write(request.queryString);
return;
}
var bodyStream = new BinaryInputStream(request.bodyInputStream);
var body = "";
var bodyAvail;
while ((bodyAvail = bodyStream.available()) > 0)
body += String.fromCharCode.apply(null, bodyStream.readByteArray(bodyAvail));
response.write(body);
}

Просмотреть файл

@ -56,6 +56,7 @@ support-files =
bug819051.sjs
copypaste.js
delayedServerEvents.sjs
echo.sjs
eventsource.resource
eventsource.resource^headers^
eventsource_redirect.resource
@ -739,6 +740,7 @@ skip-if = toolkit == 'android'
[test_xhr_forbidden_headers.html]
[test_xhr_progressevents.html]
skip-if = toolkit == 'android'
[test_xhr_send.html]
[test_xhr_send_readystate.html]
[test_xhr_withCredentials.html]
[test_file_from_blob.html]

Просмотреть файл

@ -0,0 +1,83 @@
<!DOCTYPE HTML>
<html>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=1096263
-->
<head>
<meta charset="utf-8">
<title>Test for Bug 1096263</title>
<script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
<script type="application/javascript">
/** Test for Bug 1096263 **/
SimpleTest.waitForExplicitFinish();
function simpleGetTest() {
var x = new XMLHttpRequest();
x.open("GET", "echo.sjs");
x.onload = function() {
ok(true, "Should have processed GET");
simplePostTest();
}
x.send({});
}
function simplePostTest() {
var x = new XMLHttpRequest();
x.open("POST", "echo.sjs");
x.onload = function() {
ise(x.responseText, "somedata", "Should have processed POST");
undefinedPostTest();
}
x.send({toString: function() { return "somedata"; }});
}
function undefinedPostTest() {
var x = new XMLHttpRequest();
x.open("POST", "echo.sjs");
x.onload = function() {
ise(x.responseText, "undefined", "Should have processed POST");
nullPostTest();
}
x.send({toString: function() { return undefined; }});
}
function nullPostTest() {
var x = new XMLHttpRequest();
x.open("POST", "echo.sjs");
x.onload = function() {
ise(x.responseText, "null", "Should have processed POST");
testExceptionInToString();
}
x.send({toString: function() { return null; }});
}
function testExceptionInToString() {
var x = new XMLHttpRequest();
x.open("GET", "echo.sjs");
x.onload = function() {
ok(false);
SimpleTest.finish();
}
try {
x.send({toString: function() { throw "dummy"; }});
} catch(ex) {
ise(ex, "dummy");
SimpleTest.finish();
}
}
</script>
</head>
<body onload="simpleGetTest()">
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1096263">Mozilla Bug 1096263</a>
<p id="display"></p>
<div id="content">
</div>
<pre id="test">
</pre>
</body>
</html>