gecko/content/base/test/test_XHR.html

66 lines
1.7 KiB
HTML
Raw Normal View History

<!DOCTYPE HTML>
<html>
<head>
<title>Test for XMLHttpRequest</title>
<script type="text/javascript" src="/MochiKit/MochiKit.js"></script>
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
</head>
<body>
<p id="display"></p>
<div id="content" style="display: none">
</div>
<pre id="test">
<script class="testbody" type="text/javascript">
var path = "/tests/content/base/test/";
var passFiles = [['file_XHR_pass1.xml', 'GET'],
['file_XHR_pass2.txt', 'GET'],
['file_XHR_pass3.txt', 'GET'],
];
var failFiles = [['//example.com' + path + 'file_XHR_pass1.xml', 'GET'],
['ftp://localhost' + path + 'file_XHR_pass1.xml', 'GET'],
['file_XHR_fail1.txt', 'GET'],
];
for (i = 0; i < passFiles.length; ++i) {
xhr = new XMLHttpRequest();
xhr.open(passFiles[i][1], passFiles[i][0], false);
xhr.send(null);
is(xhr.status, 200, "wrong status");
if (xhr.responseXML) {
is((new XMLSerializer()).serializeToString(xhr.responseXML.documentElement),
"<res>hello</res>",
"wrong response");
}
else {
is(xhr.responseText, "hello pass\n", "wrong response");
}
}
for (i = 0; i < failFiles.length; ++i) {
xhr = new XMLHttpRequest();
didthrow = false;
try {
xhr.open(failFiles[i][1], failFiles[i][0], false);
xhr.send(null);
}
catch (e) {
didthrow = true;
}
if (!didthrow) {
is(xhr.status, 301, "wrong status");
is(xhr.responseText, "redirect file\n", "wrong response");
}
else {
ok(1, "should have thrown or given incorrect result");
}
}
</script>
</pre>
</body>
</html>