зеркало из https://github.com/mozilla/pjs.git
Bug 696586 - Part 3: Tests; r=jonas
This commit is contained in:
Родитель
ccfe102961
Коммит
9ed67ddc9b
|
@ -212,13 +212,16 @@ is(xhr.response, null, "Bad JSON should result in null response even 2nd time.")
|
|||
// test response (responseType='blob')
|
||||
var onloadCount = 0;
|
||||
function checkOnloadCount() {
|
||||
if (++onloadCount >= 3) SimpleTest.finish();
|
||||
if (++onloadCount >= 6) SimpleTest.finish();
|
||||
};
|
||||
|
||||
var responseTypes = ['blob', 'moz-blob'];
|
||||
for (var i = 0; i < responseTypes.length; i++) {
|
||||
var t = responseTypes[i];
|
||||
// with a simple text file
|
||||
xhr = new XMLHttpRequest();
|
||||
xhr.open("GET", 'file_XHR_pass2.txt');
|
||||
xhr.responseType = 'blob';
|
||||
xhr.responseType = t;
|
||||
xhr.onloadend = continueTest;
|
||||
xhr.send(null);
|
||||
yield;
|
||||
|
@ -245,7 +248,7 @@ xhr.onreadystatechange = function() {
|
|||
switch (xhr.readyState) {
|
||||
case 2:
|
||||
is(xhr.status, 200, "wrong status");
|
||||
xhr.responseType = 'blob';
|
||||
xhr.responseType = t;
|
||||
break;
|
||||
case 4:
|
||||
b = xhr.response;
|
||||
|
@ -293,9 +296,10 @@ xhr.onreadystatechange = function() {
|
|||
}
|
||||
};
|
||||
xhr.open("GET", 'file_XHR_binary2.bin', true);
|
||||
xhr.responseType = 'blob';
|
||||
xhr.responseType = t;
|
||||
xhr.send(null);
|
||||
})();
|
||||
}
|
||||
|
||||
var client = new XMLHttpRequest();
|
||||
client.onreadystatechange = function() {
|
||||
|
|
|
@ -39,13 +39,21 @@ function updateProgress(e, data, testName) {
|
|||
is(typeof e.target.response, "string", "response should be a string" + test);
|
||||
response = e.target.response;
|
||||
}
|
||||
else if (data.blob) {
|
||||
ok(e.target.response instanceof Blob, "response should be a Blob" + test);
|
||||
response = e.target.response;
|
||||
}
|
||||
else {
|
||||
ok(e.target.response instanceof ArrayBuffer, "response should be a ArrayBuffer" + test);
|
||||
ok(e.target.response instanceof ArrayBuffer, "response should be an ArrayBuffer" + test);
|
||||
response = bufferToString(e.target.response);
|
||||
}
|
||||
is(e.target.response, e.target.response, "reflexivity should hold" + test);
|
||||
|
||||
if (!data.nodata && !data.encoded) {
|
||||
if (!data.chunked) {
|
||||
if (data.blob) {
|
||||
is(e.loaded, response.size, "event.loaded matches response size" + test);
|
||||
}
|
||||
else if (!data.chunked) {
|
||||
is(e.loaded, response.length, "event.loaded matches response size" + test);
|
||||
}
|
||||
else {
|
||||
|
@ -57,7 +65,7 @@ function updateProgress(e, data, testName) {
|
|||
ok(e.loaded - data.receivedBytes <= data.pendingBytes,
|
||||
"event.loaded didn't increase too much" + test);
|
||||
|
||||
if (!data.nodata) {
|
||||
if (!data.nodata && !data.blob) {
|
||||
var newData;
|
||||
ok(startsWith(response, data.receivedResult),
|
||||
"response strictly grew" + test);
|
||||
|
@ -74,7 +82,7 @@ function updateProgress(e, data, testName) {
|
|||
is(e.total, data.total, "total" + test);
|
||||
}
|
||||
|
||||
if (!data.nodata) {
|
||||
if (!data.nodata && !data.blob) {
|
||||
data.pendingResult = data.pendingResult.substr(newData.length);
|
||||
}
|
||||
data.pendingBytes -= e.loaded - data.receivedBytes;
|
||||
|
@ -113,7 +121,8 @@ function runTests() {
|
|||
|
||||
var responseTypes = [{ type: "text", text: true },
|
||||
{ type: "arraybuffer", text: false, nodata: true },
|
||||
{ type: "blob", text: false, nodata: true },
|
||||
{ type: "blob", text: false, nodata: true, blob: true },
|
||||
{ type: "moz-blob", text: false, nodata: false, blob: true },
|
||||
{ type: "document", text: true, nodata: true },
|
||||
{ type: "json", text: true, nodata: true },
|
||||
{ type: "", text: true },
|
||||
|
@ -153,7 +162,7 @@ function runTests() {
|
|||
{ data: utf8encode("a\u867Eb").substr(4), utf16: "b" },
|
||||
{ close: true },
|
||||
];
|
||||
if (responseType.type === "blob") {
|
||||
if (responseType.blob) {
|
||||
tests.push({ file: "file_XHR_binary2.bin", name: "cacheable data", total: 65536 },
|
||||
{ close: true },
|
||||
{ file: "file_XHR_binary2.bin", name: "cached data", total: 65536 },
|
||||
|
@ -177,6 +186,7 @@ function runTests() {
|
|||
nodata: responseType.nodata,
|
||||
chunked: responseType.chunked,
|
||||
text: responseType.text,
|
||||
blob: responseType.blob,
|
||||
file: test.file };
|
||||
|
||||
xhr.onreadystatechange = null;
|
||||
|
@ -235,7 +245,7 @@ function runTests() {
|
|||
is(xhr.response, null, "chunked data has null response for " + testState.name);
|
||||
}
|
||||
|
||||
if (!testState.nodata || responseType.chunked) {
|
||||
if (!testState.nodata && !responseType.blob || responseType.chunked) {
|
||||
// This branch intentionally left blank
|
||||
// Under these conditions we check the response during updateProgress
|
||||
}
|
||||
|
@ -243,7 +253,7 @@ function runTests() {
|
|||
is(bufferToString(xhr.response), testState.pendingResult,
|
||||
"full response for " + testState.name);
|
||||
}
|
||||
else if (responseType.type === "blob") {
|
||||
else if (responseType.blob) {
|
||||
let reader = new FileReader;
|
||||
reader.readAsBinaryString(xhr.response);
|
||||
reader.onloadend = getEvent;
|
||||
|
@ -280,7 +290,7 @@ function runTests() {
|
|||
}
|
||||
}
|
||||
|
||||
if (!testState.nodata) {
|
||||
if (!testState.nodata && !testState.blob) {
|
||||
is(testState.pendingResult, "",
|
||||
"should have consumed the expected result");
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче