Bug 1225202, part 1 - Move some variables earlier in test_fileapi_slice.html. r=baku

imageLoadHandler, testBinaryData, fileData and size are used by all of
the subtests, so move their declarations earlier so they will remain
at the global scope when we start splitting scopes in preparation for
supporting asynchronous file creation.

memFile is only used in one subtest, so move it later.

code earlier that we want at the global scope
also move memFile down, which we don't want at the global scope
This commit is contained in:
Andrew McCreight 2015-11-19 10:24:20 -08:00
parent d728c0a24e
commit 2e2afea623

View File

@ -54,31 +54,6 @@ cx.fill();
cx.closePath();
var fileData =
atob(cx.canvas.toDataURL("image/png").substring("data:text/png;base64,".length + 1));
var memFile = cx.canvas.mozGetAsFile("image/png");
var fileFile = createFileWithData(fileData);
var size = fileData.length;
// This might fail if we dramatically improve the png encoder. If that happens
// please increase the complexity or size of the image generated above to ensure
// that we're testing with files that are large enough.
ok(size > 65536, "test data sufficiently large");
// Test that basic properties work
testSlice(memFile, size, "image/png", fileData, "memFile");
testSlice(fileFile, size, "", fileData, "fileFile");
// Try loading directly from slice into an image
var testBinaryData = "";
for (var i = 0; i < 256; i++) {
testBinaryData += String.fromCharCode(i);
}
while (testBinaryData.length < 20000) {
testBinaryData += testBinaryData;
}
function imageLoadHandler(event) {
var origcanvas = $("canvas");
var testcanvas = $("testcanvas");
@ -100,6 +75,32 @@ function imageLoadHandler(event) {
testHasRun();
}
var fileData =
atob(cx.canvas.toDataURL("image/png").substring("data:text/png;base64,".length + 1));
var size = fileData.length;
var testBinaryData = "";
// This might fail if we dramatically improve the png encoder. If that happens
// please increase the complexity or size of the image generated above to ensure
// that we're testing with files that are large enough.
ok(size > 65536, "test data sufficiently large");
var fileFile = createFileWithData(fileData);
// Test that basic properties work
var memFile = cx.canvas.mozGetAsFile("image/png");
testSlice(memFile, size, "image/png", fileData, "memFile");
testSlice(fileFile, size, "", fileData, "fileFile");
// Try loading directly from slice into an image
for (var i = 0; i < 256; i++) {
testBinaryData += String.fromCharCode(i);
}
while (testBinaryData.length < 20000) {
testBinaryData += testBinaryData;
}
// image in the middle
var imgfile = createFileWithData(testBinaryData + fileData + testBinaryData);
is(imgfile.size, size + testBinaryData.length * 2, "correct file size (middle)");