var testData = "blahblahblahblahblahblahblaaaaaaaah. blah."; var extensions = [".txt",".png",".jpg",".gif",".xml", "noext"]; var fileTypes = ["text/plain", "image/png", "image/jpeg", "image/gif", "text/xml", null]; var gen; var testDOMFiles;
function executeTests() {
gen = runTests();
createFiles();
}
// arraybuffer test objects var shortArray = new ArrayBuffer(1); var shortInt8View = new Uint8Array(shortArray);
shortInt8View[0] = 3;
var longArray = new ArrayBuffer(512); var longInt8View = new Uint8Array(longArray);
for (let i = 0; i < longInt8View.length; i++) {
longInt8View[i] = i % 255;
}
// arraybufferview test objects var longArraySlice = longArray.slice(256, 384); var longInt32View1 = new Int32Array(longArraySlice) var longInt32View2 = new Int32Array(longArray, 256, 32) var longInt16View1 = new Uint16Array(longArraySlice) var longInt16View2 = new Uint16Array(longArray, 256, 64) var longInt8View1 = new Int8Array(longArraySlice) var longInt8View2 = new Int8Array(longArray, 256, 128)
for (let i = 0; i < testDOMFiles.length; i++) {
tests.push({ body: testDOMFiles[i],
resBody: testData,
resContentType: fileTypes[i],
resContentLength: testData.length,
});
}
try {
for (var test of tests) {
xhr = new XMLHttpRequest;
xhr.open("POST", "file_XHRSendData.sjs", !!test.resType);
if (test.contentType)
xhr.setRequestHeader("Content-Type", test.contentType);
if (test.resType) {
xhr.responseType = test.resType;
xhr.onloadend = continueTest;
}
xhr.send(test.body);
if (test.resType)
yield undefined;
if (test.resContentLength) {
is(xhr.getResponseHeader("Result-Content-Length"),
String(test.resContentLength), "Wrong Content-Length sent");
}
if (test.resType == "arraybuffer") {
is_identical_arraybuffer(xhr.response, test.resBody);
}
else if (test.body instanceof Document) {
is(xhr.responseText.replace("\r\n", "\n"), test.resBody, "Wrong body");
}
else if (!test.redirect) {
is(xhr.responseText, test.resBody, "Wrong body");
}
else {
// If we're testing redirect, determine whether the body is
// this document by looking for the relevant bug url
is(xhr.responseText.includes("https://bugzilla.mozilla.org/show_bug.cgi?id=464848"), true, "Wrong page for redirect");
}
}
} catch (e) {
}
function is_identical_arraybuffer(ab1, ab2) {
is(ab1.byteLength, ab2.byteLength, "arraybuffer byteLengths not equal"); var u8v1 = new Uint8Array(ab1); var u8v2 = new Uint8Array(ab2);
is(String.fromCharCode.apply(String, u8v1),
String.fromCharCode.apply(String, u8v2), "arraybuffer values not equal");
}
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.