for (i = 0; i < passFiles.length; ++i) { // Function to give our hacked is() a scope
(function (oldIs) { function is(actual, expected, message) {
oldIs(actual, expected, message + " for " + passFiles[i][0]);
}
xhr = new XMLHttpRequest();
is(xhr.getResponseHeader("Content-Type"), null, "should be null");
is(xhr.getAllResponseHeaders(), "", "should be empty string");
is(xhr.responseType, "", "wrong initial responseType");
xhr.open(passFiles[i][1], passFiles[i][0], false);
xhr.send(null);
is(xhr.status, passFiles[i][2], "wrong status");
// over HTTP2, no status text is received for network requests (but // data/blob URLs default to "200 OK" responses)
let expectedStatusText = passFiles[i][3]; if (
expectHttp2Results &&
!passFiles[i][0].startsWith("data:") &&
!passFiles[i][0].startsWith("blob:")
) {
expectedStatusText = "";
}
is(xhr.statusText, expectedStatusText, "wrong statusText");
// test response (responseType='arraybuffer') function arraybuffer_equals_to(ab, s) {
is(ab.byteLength, s.length, "wrong arraybuffer byteLength");
var u8v = new Uint8Array(ab);
is(String.fromCharCode.apply(String, u8v), s, "wrong values");
}
// with a simple text file
xhr = new XMLHttpRequest();
xhr.open("GET", "file_XHR_pass2.txt");
xhr.responseType = "arraybuffer";
xhr.onloadend = continueTest;
xhr.send(null);
yield undefined;
is(xhr.status, 200, "wrong status");
checkResponseTextAccessThrows(xhr);
checkResponseXMLAccessThrows(xhr); var ab = xhr.response;
ok(ab != null, "should have a non-null arraybuffer");
arraybuffer_equals_to(ab, "hello pass\n");
// test reusing the same XHR (Bug 680816)
xhr.open("GET", "file_XHR_binary1.bin");
xhr.responseType = "arraybuffer";
xhr.onloadend = continueTest;
xhr.send(null);
yield undefined;
is(xhr.status, 200, "wrong status"); var ab2 = xhr.response;
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");
// with a binary file
xhr = new XMLHttpRequest();
xhr.open("GET", "file_XHR_binary1.bin");
xhr.responseType = "arraybuffer";
xhr.onloadend = continueTest;
xhr.send(null);
yield undefined;
is(xhr.status, 200, "wrong status");
checkResponseTextAccessThrows(xhr);
checkResponseXMLAccessThrows(xhr);
ab = xhr.response;
ok(ab != null, "should have a non-null arraybuffer");
arraybuffer_equals_to(ab, "\xaa\xee\0\x03\xff\xff\xff\xff\xbb\xbb\xbb\xbb");
is(xhr.response, xhr.response, "returns the same ArrayBuffer");
// test response (responseType='json') var xhr = new XMLHttpRequest();
xhr.open("POST", "responseIdentical.sjs");
xhr.responseType = "json"; var jsonObjStr = JSON.stringify({ title: "aBook", author: "john" });
xhr.onloadend = continueTest;
xhr.send(jsonObjStr);
yield undefined;
is(xhr.status, 200, "wrong status");
checkResponseTextAccessThrows(xhr);
checkResponseXMLAccessThrows(xhr);
is(JSON.stringify(xhr.response), jsonObjStr, "correct result");
is(xhr.response, xhr.response, "returning the same object on each access");
// with invalid json
xhr = new XMLHttpRequest();
xhr.open("POST", "responseIdentical.sjs");
xhr.responseType = "json";
xhr.onloadend = continueTest;
xhr.send("{");
yield undefined;
is(xhr.status, 200, "wrong status");
checkResponseTextAccessThrows(xhr);
checkResponseXMLAccessThrows(xhr);
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."
);
// 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"); if (expectHttp2Results) {
is(xhr.statusText, "", "should be '' when over HTTP2");
} else {
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);
xhr.onreadystatechange = continueTest; while (xhr.readyState != 4) {
checkXHRStatus();
yield undefined;
}
checkXHRStatus();
// test response (responseType='blob') // with a simple text file
xhr = new XMLHttpRequest();
xhr.open("GET", "file_XHR_pass2.txt");
xhr.responseType = "blob";
xhr.onloadend = continueTest;
xhr.send(null);
yield undefined;
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");
var fr = new FileReader();
fr.onload = continueTest;
fr.readAsBinaryString(b);
yield undefined;
is(fr.result, "hello pass\n", "wrong values");
// with a binary file
xhr = new XMLHttpRequest();
xhr.open("GET", "file_XHR_binary1.bin", true);
xhr.send(null);
xhr.onreadystatechange = continueTest; while (xhr.readyState != 2) {
yield undefined;
}
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;
yield undefined;
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 = "blob";
xhr.send(null);
xhr.onreadystatechange = continueTest;
while (xhr.readyState != 4) {
yield undefined;
}
xhr.onreadystatechange = null;
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();
yield undefined;
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);
var client = new XMLHttpRequest();
client.open("GET", "file_XHR_pass1.xml", true);
client.send();
client.onreadystatechange = function () { 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 + "]");
}
}
};
client.abort();
SimpleTest.finish();
} /* runTests */
Messung V0.5
¤ Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.0.54Bemerkung:
(vorverarbeitet)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.