2008-01-31 00:16:54 -08:00
|
|
|
<!DOCTYPE HTML>
|
|
|
|
<html>
|
|
|
|
<head>
|
2008-03-25 19:46:08 -07:00
|
|
|
<title>Test for XMLHttpRequest</title>
|
2008-01-31 00:16:54 -08:00
|
|
|
<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">
|
|
|
|
|
2008-03-25 19:46:08 -07:00
|
|
|
var path = "/tests/content/base/test/";
|
2008-01-31 00:16:54 -08:00
|
|
|
|
2008-03-25 19:46:08 -07:00
|
|
|
var passFiles = [['file_XHR_pass1.xml', 'GET'],
|
|
|
|
['file_XHR_pass2.txt', 'GET'],
|
|
|
|
['file_XHR_pass3.txt', 'GET'],
|
2008-01-31 00:16:54 -08:00
|
|
|
];
|
|
|
|
|
2008-03-25 19:46:08 -07:00
|
|
|
var failFiles = [['//example.com' + path + 'file_XHR_pass1.xml', 'GET'],
|
|
|
|
['ftp://localhost' + path + 'file_XHR_pass1.xml', 'GET'],
|
|
|
|
['file_XHR_fail1.txt', 'GET'],
|
2008-01-31 00:16:54 -08:00
|
|
|
];
|
|
|
|
|
|
|
|
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();
|
2008-03-25 19:46:08 -07:00
|
|
|
didthrow = false;
|
2008-01-31 00:16:54 -08:00
|
|
|
try {
|
|
|
|
xhr.open(failFiles[i][1], failFiles[i][0], false);
|
|
|
|
xhr.send(null);
|
|
|
|
}
|
|
|
|
catch (e) {
|
2008-03-25 19:46:08 -07:00
|
|
|
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");
|
2008-01-31 00:16:54 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
</script>
|
|
|
|
</pre>
|
|
|
|
</body>
|
|
|
|
</html>
|