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>
|
2012-02-04 05:11:09 -08:00
|
|
|
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
|
2008-01-31 00:16:54 -08:00
|
|
|
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
|
|
|
|
</head>
|
2011-12-08 05:55:20 -08:00
|
|
|
<body onload="gen.next();">
|
2008-01-31 00:16:54 -08:00
|
|
|
<p id="display"></p>
|
|
|
|
<div id="content" style="display: none">
|
2012-02-04 05:11:09 -08:00
|
|
|
|
2008-01-31 00:16:54 -08:00
|
|
|
</div>
|
|
|
|
<pre id="test">
|
2011-12-08 05:55:20 -08:00
|
|
|
<script class="testbody" type="application/javascript;version=1.7">
|
2012-02-04 05:11:09 -08:00
|
|
|
"use strict";
|
2011-05-10 16:18:55 -07:00
|
|
|
SimpleTest.waitForExplicitFinish();
|
2008-01-31 00:16:54 -08:00
|
|
|
|
2011-12-08 05:55:20 -08:00
|
|
|
var gen = runTests();
|
|
|
|
function continueTest() { gen.next(); }
|
|
|
|
|
|
|
|
function runTests() {
|
|
|
|
|
2014-10-25 10:25:22 -07:00
|
|
|
var path = "/tests/dom/base/test/";
|
2008-01-31 00:16:54 -08:00
|
|
|
|
2014-09-04 12:26:58 -07:00
|
|
|
var passFiles = [['file_XHR_pass1.xml', 'GET', 200, 'OK', 'text/xml'],
|
|
|
|
['file_XHR_pass2.txt', 'GET', 200, 'OK', 'text/plain'],
|
|
|
|
['file_XHR_pass3.txt', 'GET', 200, 'OK', 'text/plain'],
|
|
|
|
['data:text/xml,%3Cres%3Ehello%3C/res%3E%0A', 'GET', 200, 'OK', 'text/xml'],
|
|
|
|
['data:text/plain,hello%20pass%0A', 'GET', 200, 'OK', 'text/plain'],
|
|
|
|
['data:,foo', 'GET', 200, 'OK', 'text/plain;charset=US-ASCII', 'foo'],
|
|
|
|
['data:text/plain;base64,Zm9v', 'GET', 200, 'OK', 'text/plain', 'foo'],
|
|
|
|
['data:text/plain,foo#bar', 'GET', 200, 'OK', 'text/plain', 'foo'],
|
|
|
|
['data:text/plain,foo%23bar', 'GET', 200, 'OK', 'text/plain', 'foo#bar'],
|
2008-01-31 00:16:54 -08:00
|
|
|
];
|
|
|
|
|
2014-09-04 12:26:58 -07:00
|
|
|
var blob = new Blob(["foo"], { type: "text/plain" });
|
|
|
|
var blobURL = URL.createObjectURL(blob);
|
|
|
|
|
|
|
|
passFiles.push([blobURL, 'GET', 200, 'OK', 'text/plain', 'foo']);
|
|
|
|
|
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) {
|
2014-09-04 12:26:58 -07:00
|
|
|
// Function to give our hacked is() a scope
|
|
|
|
(function(oldIs) {
|
|
|
|
function is(actual, expected, message) {
|
|
|
|
oldIs(actual, expected, message + " for " + passFiles[i][0]);
|
|
|
|
}
|
2008-01-31 00:16:54 -08:00
|
|
|
xhr = new XMLHttpRequest();
|
2012-02-19 03:58:24 -08:00
|
|
|
is(xhr.getResponseHeader("Content-Type"), null, "should be null");
|
|
|
|
is(xhr.getAllResponseHeaders(), "", "should be empty string");
|
2011-05-18 22:11:51 -07:00
|
|
|
is(xhr.responseType, "", "wrong initial responseType");
|
2008-01-31 00:16:54 -08:00
|
|
|
xhr.open(passFiles[i][1], passFiles[i][0], false);
|
|
|
|
xhr.send(null);
|
2012-01-11 01:47:46 -08:00
|
|
|
is(xhr.status, passFiles[i][2], "wrong status");
|
2014-09-04 12:26:58 -07:00
|
|
|
is(xhr.statusText, passFiles[i][3], "wrong statusText");
|
|
|
|
is(xhr.getResponseHeader("Content-Type"), passFiles[i][4], "wrong content type");
|
2012-02-19 03:58:24 -08:00
|
|
|
var headers = xhr.getAllResponseHeaders();
|
2012-07-26 08:55:23 -07:00
|
|
|
ok(/(?:^|\n)Content-Type:\s*([^\r\n]*)\r\n/i.test(headers) &&
|
2014-09-04 12:26:58 -07:00
|
|
|
RegExp.$1 === passFiles[i][4], "wrong response headers");
|
2008-01-31 00:16:54 -08:00
|
|
|
if (xhr.responseXML) {
|
|
|
|
is((new XMLSerializer()).serializeToString(xhr.responseXML.documentElement),
|
2014-09-04 12:26:58 -07:00
|
|
|
passFiles[i][5] || "<res>hello</res>", "wrong responseXML");
|
|
|
|
is(xhr.response, passFiles[i][5] || "<res>hello</res>\n", "wrong response");
|
2008-01-31 00:16:54 -08:00
|
|
|
}
|
|
|
|
else {
|
2014-09-04 12:26:58 -07:00
|
|
|
is(xhr.responseText, passFiles[i][5] || "hello pass\n", "wrong responseText");
|
|
|
|
is(xhr.response, passFiles[i][5] || "hello pass\n", "wrong response");
|
2008-01-31 00:16:54 -08:00
|
|
|
}
|
2014-09-04 12:26:58 -07:00
|
|
|
})(is);
|
2008-01-31 00:16:54 -08:00
|
|
|
}
|
|
|
|
|
2014-09-04 12:26:58 -07:00
|
|
|
URL.revokeObjectURL(blobURL);
|
|
|
|
|
2008-01-31 00:16:54 -08:00
|
|
|
for (i = 0; i < failFiles.length; ++i) {
|
|
|
|
xhr = new XMLHttpRequest();
|
2012-02-04 05:11:09 -08:00
|
|
|
var 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
|
|
|
}
|
|
|
|
}
|
2010-08-14 10:52:19 -07:00
|
|
|
|
2011-05-10 16:18:55 -07:00
|
|
|
function checkResponseTextAccessThrows(xhr) {
|
|
|
|
var didthrow = false;
|
|
|
|
try { xhr.responseText } catch (e) { didthrow = true; }
|
|
|
|
ok(didthrow, "should have thrown when accessing responseText");
|
|
|
|
}
|
|
|
|
function checkResponseXMLAccessThrows(xhr) {
|
|
|
|
var didthrow = false;
|
|
|
|
try { xhr.responseXML } catch (e) { didthrow = true; }
|
|
|
|
ok(didthrow, "should have thrown when accessing responseXML");
|
|
|
|
}
|
2015-01-13 00:51:09 -08:00
|
|
|
function checkSetResponseType(xhr, type) {
|
|
|
|
var didthrow = false;
|
|
|
|
try { xhr.responseType = type; } catch (e) { didthrow = true; }
|
2015-05-12 16:52:01 -07:00
|
|
|
is(xhr.responseType, type, "responseType should be " + type);
|
2015-01-13 00:51:09 -08:00
|
|
|
ok(!didthrow, "should not have thrown when setting responseType");
|
|
|
|
}
|
2011-09-23 18:57:36 -07:00
|
|
|
function checkSetResponseTypeThrows(xhr, type) {
|
2011-05-10 16:18:55 -07:00
|
|
|
var didthrow = false;
|
2011-09-23 18:57:36 -07:00
|
|
|
try { xhr.responseType = type; } catch (e) { didthrow = true; }
|
|
|
|
ok(didthrow, "should have thrown when setting responseType");
|
2011-05-10 16:18:55 -07:00
|
|
|
}
|
2011-12-08 05:55:20 -08:00
|
|
|
function checkOpenThrows(xhr, method, url, async) {
|
|
|
|
var didthrow = false;
|
|
|
|
try { xhr.open(method, url, async); } catch (e) { didthrow = true; }
|
|
|
|
ok(didthrow, "should have thrown when open is called");
|
|
|
|
}
|
2011-05-10 16:18:55 -07:00
|
|
|
|
2015-01-13 00:51:09 -08:00
|
|
|
// test if setting responseType before calling open() works
|
|
|
|
xhr = new XMLHttpRequest();
|
|
|
|
checkSetResponseType(xhr, "");
|
|
|
|
checkSetResponseType(xhr, "text");
|
|
|
|
checkSetResponseType(xhr, "document");
|
|
|
|
checkSetResponseType(xhr, "arraybuffer");
|
|
|
|
checkSetResponseType(xhr, "blob");
|
|
|
|
checkSetResponseType(xhr, "json");
|
|
|
|
checkSetResponseType(xhr, "moz-chunked-text");
|
|
|
|
checkSetResponseType(xhr, "moz-chunked-arraybuffer");
|
|
|
|
checkOpenThrows(xhr, "GET", "file_XHR_pass2.txt", false);
|
|
|
|
|
2011-12-08 05:55:20 -08:00
|
|
|
// test response (sync, responseType is not changeable)
|
2011-05-10 16:18:55 -07:00
|
|
|
xhr = new XMLHttpRequest();
|
2011-12-08 05:55:20 -08:00
|
|
|
xhr.open("GET", 'file_XHR_pass2.txt', false);
|
|
|
|
checkSetResponseTypeThrows(xhr, "");
|
|
|
|
checkSetResponseTypeThrows(xhr, "text");
|
2011-09-23 18:57:36 -07:00
|
|
|
checkSetResponseTypeThrows(xhr, "document");
|
2011-12-08 05:55:20 -08:00
|
|
|
checkSetResponseTypeThrows(xhr, "arraybuffer");
|
|
|
|
checkSetResponseTypeThrows(xhr, "blob");
|
2011-12-08 05:56:14 -08:00
|
|
|
checkSetResponseTypeThrows(xhr, "json");
|
2011-09-23 18:57:36 -07:00
|
|
|
checkSetResponseTypeThrows(xhr, "moz-chunked-text");
|
|
|
|
checkSetResponseTypeThrows(xhr, "moz-chunked-arraybuffer");
|
2011-12-08 05:55:20 -08:00
|
|
|
xhr.send(null);
|
|
|
|
checkSetResponseTypeThrows(xhr, "document");
|
|
|
|
is(xhr.status, 200, "wrong status");
|
|
|
|
is(xhr.response, "hello pass\n", "wrong response");
|
|
|
|
|
|
|
|
// test response (responseType='document')
|
|
|
|
xhr = new XMLHttpRequest();
|
|
|
|
xhr.open("GET", 'file_XHR_pass1.xml');
|
2011-05-18 22:11:51 -07:00
|
|
|
xhr.responseType = 'document';
|
2011-12-08 05:55:20 -08:00
|
|
|
xhr.onloadend = continueTest;
|
2011-05-10 16:18:55 -07:00
|
|
|
xhr.send(null);
|
2013-07-10 14:52:14 -07:00
|
|
|
yield undefined;
|
2011-09-23 18:57:36 -07:00
|
|
|
checkSetResponseTypeThrows(xhr, "document");
|
2011-05-10 16:18:55 -07:00
|
|
|
is(xhr.status, 200, "wrong status");
|
|
|
|
checkResponseTextAccessThrows(xhr);
|
2011-05-18 22:11:51 -07:00
|
|
|
is((new XMLSerializer()).serializeToString(xhr.response.documentElement),
|
2011-05-10 16:18:55 -07:00
|
|
|
"<res>hello</res>",
|
|
|
|
"wrong response");
|
|
|
|
|
|
|
|
// test response (responseType='text')
|
|
|
|
xhr = new XMLHttpRequest();
|
2011-12-08 05:55:20 -08:00
|
|
|
xhr.open("GET", 'file_XHR_pass2.txt');
|
2011-05-18 22:11:51 -07:00
|
|
|
xhr.responseType = 'text';
|
2011-12-08 05:55:20 -08:00
|
|
|
xhr.onloadend = continueTest;
|
2011-05-10 16:18:55 -07:00
|
|
|
xhr.send(null);
|
2013-07-10 14:52:14 -07:00
|
|
|
yield undefined;
|
2011-05-10 16:18:55 -07:00
|
|
|
is(xhr.status, 200, "wrong status");
|
|
|
|
checkResponseXMLAccessThrows(xhr);
|
2011-05-18 22:11:51 -07:00
|
|
|
is(xhr.response, "hello pass\n", "wrong response");
|
2011-05-10 16:18:55 -07:00
|
|
|
|
|
|
|
// test response (responseType='arraybuffer')
|
|
|
|
function arraybuffer_equals_to(ab, s) {
|
|
|
|
is(ab.byteLength, s.length, "wrong arraybuffer byteLength");
|
|
|
|
|
2012-02-04 05:11:09 -08:00
|
|
|
var u8v = new Uint8Array(ab);
|
2011-05-10 16:18:55 -07:00
|
|
|
is(String.fromCharCode.apply(String, u8v), s, "wrong values");
|
|
|
|
}
|
2010-08-14 10:52:19 -07:00
|
|
|
|
|
|
|
// with a simple text file
|
|
|
|
xhr = new XMLHttpRequest();
|
2011-12-08 05:55:20 -08:00
|
|
|
xhr.open("GET", 'file_XHR_pass2.txt');
|
2011-05-18 22:11:51 -07:00
|
|
|
xhr.responseType = 'arraybuffer';
|
2011-12-08 05:55:20 -08:00
|
|
|
xhr.onloadend = continueTest;
|
2010-08-14 10:52:19 -07:00
|
|
|
xhr.send(null);
|
2013-07-10 14:52:14 -07:00
|
|
|
yield undefined;
|
2010-08-14 10:52:19 -07:00
|
|
|
is(xhr.status, 200, "wrong status");
|
2011-05-10 16:18:55 -07:00
|
|
|
checkResponseTextAccessThrows(xhr);
|
|
|
|
checkResponseXMLAccessThrows(xhr);
|
2012-02-04 05:11:09 -08:00
|
|
|
var ab = xhr.response;
|
2010-08-14 10:52:19 -07:00
|
|
|
ok(ab != null, "should have a non-null arraybuffer");
|
2011-05-10 16:18:55 -07:00
|
|
|
arraybuffer_equals_to(ab, "hello pass\n");
|
2010-08-14 10:52:19 -07:00
|
|
|
|
2011-08-24 09:33:31 -07:00
|
|
|
// test reusing the same XHR (Bug 680816)
|
2011-12-08 05:55:20 -08:00
|
|
|
xhr.open("GET", 'file_XHR_binary1.bin');
|
2011-08-24 09:33:31 -07:00
|
|
|
xhr.responseType = 'arraybuffer';
|
2011-12-08 05:55:20 -08:00
|
|
|
xhr.onloadend = continueTest;
|
2011-08-24 09:33:31 -07:00
|
|
|
xhr.send(null);
|
2013-07-10 14:52:14 -07:00
|
|
|
yield undefined;
|
2011-08-24 09:33:31 -07:00
|
|
|
is(xhr.status, 200, "wrong status");
|
2012-02-04 05:11:09 -08:00
|
|
|
var ab2 = xhr.response;
|
2011-08-24 09:33:31 -07:00
|
|
|
ok(ab2 != null, "should have a non-null arraybuffer");
|
|
|
|
ok(ab2 != ab, "arraybuffer on XHR reuse should be distinct");
|
|
|
|
arraybuffer_equals_to(ab, "hello pass\n");
|
|
|
|
arraybuffer_equals_to(ab2, "\xaa\xee\0\x03\xff\xff\xff\xff\xbb\xbb\xbb\xbb");
|
|
|
|
|
2010-08-14 10:52:19 -07:00
|
|
|
// with a binary file
|
|
|
|
xhr = new XMLHttpRequest();
|
2011-12-08 05:55:20 -08:00
|
|
|
xhr.open("GET", 'file_XHR_binary1.bin');
|
2011-05-18 22:11:51 -07:00
|
|
|
xhr.responseType = 'arraybuffer';
|
2011-12-08 05:55:20 -08:00
|
|
|
xhr.onloadend = continueTest;
|
|
|
|
xhr.send(null);
|
2013-07-10 14:52:14 -07:00
|
|
|
yield undefined;
|
2010-08-14 10:52:19 -07:00
|
|
|
is(xhr.status, 200, "wrong status");
|
2011-05-10 16:18:55 -07:00
|
|
|
checkResponseTextAccessThrows(xhr);
|
|
|
|
checkResponseXMLAccessThrows(xhr);
|
2011-05-18 22:11:51 -07:00
|
|
|
ab = xhr.response;
|
2010-08-14 10:52:19 -07:00
|
|
|
ok(ab != null, "should have a non-null arraybuffer");
|
2011-05-10 16:18:55 -07:00
|
|
|
arraybuffer_equals_to(ab, "\xaa\xee\0\x03\xff\xff\xff\xff\xbb\xbb\xbb\xbb");
|
2011-09-23 18:57:36 -07:00
|
|
|
is(xhr.response, xhr.response, "returns the same ArrayBuffer");
|
2011-05-10 16:18:55 -07:00
|
|
|
|
2011-12-08 05:56:14 -08:00
|
|
|
// test response (responseType='json')
|
2011-09-23 18:57:36 -07:00
|
|
|
var xhr = new XMLHttpRequest();
|
2011-12-08 05:55:20 -08:00
|
|
|
xhr.open("POST", 'responseIdentical.sjs');
|
2011-12-08 05:56:14 -08:00
|
|
|
xhr.responseType = 'json';
|
2012-02-04 05:11:09 -08:00
|
|
|
var jsonObjStr = JSON.stringify({title: "aBook", author: "john"});
|
2011-12-08 05:55:20 -08:00
|
|
|
xhr.onloadend = continueTest;
|
2011-09-23 18:57:36 -07:00
|
|
|
xhr.send(jsonObjStr);
|
2013-07-10 14:52:14 -07:00
|
|
|
yield undefined;
|
2011-05-23 18:09:28 -07:00
|
|
|
is(xhr.status, 200, "wrong status");
|
|
|
|
checkResponseTextAccessThrows(xhr);
|
|
|
|
checkResponseXMLAccessThrows(xhr);
|
2011-09-23 18:57:36 -07:00
|
|
|
is(JSON.stringify(xhr.response), jsonObjStr, "correct result");
|
|
|
|
is(xhr.response, xhr.response, "returning the same object on each access");
|
|
|
|
|
|
|
|
// with invalid json
|
|
|
|
var xhr = new XMLHttpRequest();
|
2011-12-08 05:55:20 -08:00
|
|
|
xhr.open("POST", 'responseIdentical.sjs');
|
2011-12-08 05:56:14 -08:00
|
|
|
xhr.responseType = 'json';
|
2011-12-08 05:55:20 -08:00
|
|
|
xhr.onloadend = continueTest;
|
2011-09-23 18:57:36 -07:00
|
|
|
xhr.send("{");
|
2013-07-10 14:52:14 -07:00
|
|
|
yield undefined;
|
2011-09-23 18:57:36 -07:00
|
|
|
is(xhr.status, 200, "wrong status");
|
|
|
|
checkResponseTextAccessThrows(xhr);
|
|
|
|
checkResponseXMLAccessThrows(xhr);
|
2011-12-08 05:56:14 -08:00
|
|
|
is(xhr.response, null, "Bad JSON should result in null response.");
|
|
|
|
is(xhr.response, null, "Bad JSON should result in null response even 2nd time.");
|
2011-05-23 18:09:28 -07:00
|
|
|
|
2012-03-26 01:40:09 -07:00
|
|
|
// Test status/statusText in all readyStates
|
|
|
|
xhr = new XMLHttpRequest();
|
|
|
|
function checkXHRStatus() {
|
|
|
|
if (xhr.readyState == xhr.UNSENT || xhr.readyState == xhr.OPENED) {
|
|
|
|
is(xhr.status, 0, "should be 0 before getting data");
|
|
|
|
is(xhr.statusText, "", "should be empty before getting data");
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
is(xhr.status, 200, "should be 200 when we have data");
|
|
|
|
is(xhr.statusText, "OK", "should be OK when we have data");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
checkXHRStatus();
|
|
|
|
xhr.open("GET", 'file_XHR_binary1.bin');
|
|
|
|
checkXHRStatus();
|
|
|
|
xhr.responseType = 'arraybuffer';
|
|
|
|
xhr.send(null);
|
2012-08-30 20:45:16 -07:00
|
|
|
xhr.onreadystatechange = continueTest;
|
2012-03-26 01:40:09 -07:00
|
|
|
while (xhr.readyState != 4) {
|
|
|
|
checkXHRStatus();
|
2013-07-10 14:52:14 -07:00
|
|
|
yield undefined;
|
2012-03-26 01:40:09 -07:00
|
|
|
}
|
|
|
|
checkXHRStatus();
|
2011-05-10 16:18:55 -07:00
|
|
|
|
2012-03-26 01:40:09 -07:00
|
|
|
// test response (responseType='blob')
|
2012-01-30 02:34:15 -08:00
|
|
|
var responseTypes = ['blob', 'moz-blob'];
|
|
|
|
for (var i = 0; i < responseTypes.length; i++) {
|
2012-02-04 05:11:09 -08:00
|
|
|
var t = responseTypes[i];
|
|
|
|
// with a simple text file
|
|
|
|
xhr = new XMLHttpRequest();
|
|
|
|
xhr.open("GET", 'file_XHR_pass2.txt');
|
|
|
|
xhr.responseType = t;
|
|
|
|
xhr.onloadend = continueTest;
|
|
|
|
xhr.send(null);
|
2013-07-10 14:52:14 -07:00
|
|
|
yield undefined;
|
2012-02-04 05:11:09 -08:00
|
|
|
is(xhr.status, 200, "wrong status");
|
|
|
|
checkResponseTextAccessThrows(xhr);
|
|
|
|
checkResponseXMLAccessThrows(xhr);
|
|
|
|
var b = xhr.response;
|
|
|
|
ok(b, "should have a non-null blob");
|
|
|
|
ok(b instanceof Blob, "should be a Blob");
|
|
|
|
ok(!(b instanceof File), "should not be a File");
|
|
|
|
is(b.size, "hello pass\n".length, "wrong blob size");
|
2011-05-10 16:18:55 -07:00
|
|
|
|
2012-03-26 01:40:09 -07:00
|
|
|
var fr = new FileReader();
|
|
|
|
fr.onload = continueTest;
|
|
|
|
fr.readAsBinaryString(b);
|
2013-07-10 14:52:14 -07:00
|
|
|
yield undefined;
|
2012-03-26 01:40:09 -07:00
|
|
|
ok(fr.result, "hello pass\n", "wrong values");
|
2011-09-27 01:40:36 -07:00
|
|
|
|
2012-02-04 05:11:09 -08:00
|
|
|
// with a binary file
|
2012-03-26 01:40:09 -07:00
|
|
|
xhr = new XMLHttpRequest();
|
|
|
|
xhr.open("GET", 'file_XHR_binary1.bin', true);
|
|
|
|
xhr.send(null);
|
2012-08-30 20:45:16 -07:00
|
|
|
xhr.onreadystatechange = continueTest;
|
2012-03-26 01:40:09 -07:00
|
|
|
while(xhr.readyState != 2)
|
2013-07-10 14:52:14 -07:00
|
|
|
yield undefined;
|
2012-03-26 01:40:09 -07:00
|
|
|
|
|
|
|
is(xhr.status, 200, "wrong status");
|
|
|
|
xhr.responseType = t;
|
|
|
|
|
|
|
|
while(xhr.readyState != 4)
|
2013-07-10 14:52:14 -07:00
|
|
|
yield undefined;
|
2012-03-26 01:40:09 -07:00
|
|
|
|
|
|
|
xhr.onreadystatechange = null;
|
|
|
|
|
|
|
|
b = xhr.response;
|
|
|
|
ok(b != null, "should have a non-null blob");
|
|
|
|
is(b.size, 12, "wrong blob size");
|
|
|
|
|
|
|
|
fr = new FileReader();
|
|
|
|
fr.readAsBinaryString(b);
|
|
|
|
xhr = null; // kill the XHR object
|
|
|
|
b = null;
|
|
|
|
SpecialPowers.gc();
|
|
|
|
fr.onload = continueTest;
|
2013-07-10 14:52:14 -07:00
|
|
|
yield undefined;
|
2012-03-26 01:40:09 -07:00
|
|
|
is(fr.result, "\xaa\xee\0\x03\xff\xff\xff\xff\xbb\xbb\xbb\xbb", "wrong values");
|
|
|
|
|
|
|
|
// with a larger binary file
|
|
|
|
xhr = new XMLHttpRequest();
|
|
|
|
xhr.open("GET", 'file_XHR_binary2.bin', true);
|
|
|
|
xhr.responseType = t;
|
|
|
|
xhr.send(null);
|
2012-08-30 20:45:16 -07:00
|
|
|
xhr.onreadystatechange = continueTest;
|
2012-03-26 01:40:09 -07:00
|
|
|
|
|
|
|
while (xhr.readyState != 4)
|
2013-07-10 14:52:14 -07:00
|
|
|
yield undefined;
|
2012-03-26 01:40:09 -07:00
|
|
|
|
|
|
|
xhr.onreadystatechange = null;
|
|
|
|
|
|
|
|
var b = xhr.response;
|
|
|
|
ok(b != null, "should have a non-null blob");
|
|
|
|
is(b.size, 65536, "wrong blob size");
|
|
|
|
|
|
|
|
fr = new FileReader();
|
|
|
|
fr.readAsArrayBuffer(b);
|
|
|
|
fr.onload = continueTest;
|
|
|
|
xhr = null; // kill the XHR object
|
|
|
|
b = null;
|
|
|
|
SpecialPowers.gc();
|
2013-07-10 14:52:14 -07:00
|
|
|
yield undefined;
|
2012-03-26 01:40:09 -07:00
|
|
|
|
|
|
|
var u8 = new Uint8Array(fr.result);
|
|
|
|
for (var i = 0; i < 65536; i++) {
|
|
|
|
if (u8[i] !== (i & 255)) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
is(i, 65536, "wrong value at offset " + i);
|
2012-01-30 02:34:15 -08:00
|
|
|
}
|
2010-08-14 10:52:19 -07:00
|
|
|
|
2010-11-11 13:39:14 -08:00
|
|
|
var client = new XMLHttpRequest();
|
2012-08-30 20:45:16 -07:00
|
|
|
client.open("GET", "file_XHR_pass1.xml", true);
|
|
|
|
client.send();
|
2010-11-11 13:39:14 -08:00
|
|
|
client.onreadystatechange = function() {
|
2012-02-04 05:11:09 -08:00
|
|
|
if(client.readyState == 4) {
|
|
|
|
try {
|
|
|
|
is(client.responseXML, null, "responseXML should be null.");
|
|
|
|
is(client.responseText, "", "responseText should be empty string.");
|
|
|
|
is(client.response, "", "response should be empty string.");
|
|
|
|
is(client.status, 0, "status should be 0.");
|
|
|
|
is(client.statusText, "", "statusText should be empty string.");
|
|
|
|
is(client.getAllResponseHeaders(), "",
|
|
|
|
"getAllResponseHeaders() should return empty string.");
|
|
|
|
} catch(ex) {
|
|
|
|
ok(false, "Shouldn't throw! [" + ex + "]");
|
2010-11-11 13:39:14 -08:00
|
|
|
}
|
|
|
|
}
|
2012-02-04 05:11:09 -08:00
|
|
|
}
|
2010-11-11 13:39:14 -08:00
|
|
|
client.abort();
|
|
|
|
|
2012-03-26 01:40:09 -07:00
|
|
|
SimpleTest.finish();
|
2013-07-10 14:52:14 -07:00
|
|
|
yield undefined;
|
2012-03-26 01:40:09 -07:00
|
|
|
|
2011-12-08 05:55:20 -08:00
|
|
|
} /* runTests */
|
2008-01-31 00:16:54 -08:00
|
|
|
</script>
|
|
|
|
</pre>
|
|
|
|
</body>
|
|
|
|
</html>
|