2010-10-13 23:25:33 +00:00
|
|
|
<!DOCTYPE HTML>
|
|
|
|
<html>
|
|
|
|
<head>
|
|
|
|
<!--
|
|
|
|
https://bugzilla.mozilla.org/show_bug.cgi?id=575946
|
|
|
|
-->
|
|
|
|
<title>Test for Bug 575946</title>
|
|
|
|
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
|
2011-05-20 17:18:45 +00:00
|
|
|
<script type="text/javascript" src="fileutils.js"></script>
|
2010-10-13 23:25:33 +00:00
|
|
|
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
|
|
|
|
</head>
|
|
|
|
|
|
|
|
<body>
|
|
|
|
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=575946">Mozilla Bug 575946</a>
|
|
|
|
<p id="display">
|
2012-01-23 01:08:17 +00:00
|
|
|
<canvas id=canvas width=1100 height=1100 hidden moz-opaque></canvas>
|
|
|
|
<canvas id=testcanvas hidden moz-opaque></canvas>
|
2010-10-13 23:25:33 +00:00
|
|
|
<input id="fileList" type="file"></input>
|
|
|
|
</p>
|
|
|
|
<div id="content" style="display: none">
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<pre id="test">
|
|
|
|
<script class="testbody" type="text/javascript">
|
2013-03-13 16:40:55 +00:00
|
|
|
const isOSXMtnLion = navigator.userAgent.indexOf("Mac OS X 10.8") != -1;
|
|
|
|
|
|
|
|
if (isOSXMtnLion) {
|
|
|
|
todo(false, "Mountain Lion doesn't like this test (bug 788999)");
|
|
|
|
} else {
|
2010-10-13 23:25:33 +00:00
|
|
|
var fileNum = 1;
|
|
|
|
SimpleTest.waitForExplicitFinish();
|
|
|
|
|
|
|
|
// Create files containing data we'll test with. We'll want long
|
|
|
|
// strings to ensure they span multiple buffers while loading
|
|
|
|
|
|
|
|
// Create a decent-sized image
|
|
|
|
cx = $("canvas").getContext('2d');
|
|
|
|
var s = cx.canvas.width;
|
|
|
|
var grad = cx.createLinearGradient(0, 0, s-1, s-1);
|
|
|
|
for (i = 0; i < 0.95; i += .1) {
|
|
|
|
grad.addColorStop(i, "white");
|
|
|
|
grad.addColorStop(i + .05, "black");
|
|
|
|
}
|
|
|
|
grad.addColorStop(1, "white");
|
|
|
|
cx.fillStyle = grad;
|
|
|
|
cx.fillRect(0, 0, s-1, s-1);
|
|
|
|
cx.fillStyle = "rgba(200, 0, 0, 0.9)";
|
|
|
|
cx.fillRect(.1 * s, .1 * s, .7 * s, .7 * s);
|
|
|
|
cx.strokeStyle = "rgba(0, 0, 130, 0.5)";
|
|
|
|
cx.lineWidth = .14 * s;
|
|
|
|
cx.beginPath();
|
|
|
|
cx.arc(.6 * s, .6 * s, .3 * s, 0, Math.PI*2, true);
|
|
|
|
cx.stroke();
|
|
|
|
cx.closePath();
|
|
|
|
cx.fillStyle = "rgb(0, 255, 0)";
|
|
|
|
cx.beginPath();
|
|
|
|
cx.arc(.1 * s, .8 * s, .1 * s, 0, Math.PI*2, true);
|
|
|
|
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
|
2011-05-20 17:18:45 +00:00
|
|
|
testSlice(memFile, size, "image/png", fileData, "memFile");
|
|
|
|
testSlice(fileFile, size, "", fileData, "fileFile");
|
2010-10-13 23:25:33 +00:00
|
|
|
|
|
|
|
|
|
|
|
// 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");
|
|
|
|
var image = event.target;
|
|
|
|
is(image.naturalWidth, origcanvas.width, "width correct");
|
|
|
|
is(image.naturalHeight, origcanvas.height, "height correct");
|
|
|
|
|
|
|
|
testcanvas.width = origcanvas.width;
|
|
|
|
testcanvas.height = origcanvas.height;
|
|
|
|
testcanvas.getContext("2d").drawImage(image, 0, 0);
|
2011-01-05 11:35:55 +00:00
|
|
|
// Do not use |is(testcanvas.toDataURL("image/png"), origcanvas.toDataURL("image/png"), "...");| that results in a _very_ long line.
|
|
|
|
var origDataURL = origcanvas.toDataURL("image/png");
|
|
|
|
var testDataURL = testcanvas.toDataURL("image/png");
|
|
|
|
is(testDataURL.length, origDataURL.length,
|
|
|
|
"Length of correct image data");
|
|
|
|
ok(testDataURL == origDataURL,
|
|
|
|
"Content of correct image data");
|
2010-10-13 23:25:33 +00:00
|
|
|
|
|
|
|
testHasRun();
|
|
|
|
}
|
|
|
|
|
|
|
|
// image in the middle
|
|
|
|
var imgfile = createFileWithData(testBinaryData + fileData + testBinaryData);
|
2011-01-05 11:35:55 +00:00
|
|
|
is(imgfile.size, size + testBinaryData.length * 2, "correct file size (middle)");
|
2010-10-13 23:25:33 +00:00
|
|
|
var img = new Image;
|
2012-02-16 10:22:25 +00:00
|
|
|
img.src = URL.createObjectURL(imgfile.slice(testBinaryData.length, testBinaryData.length + size));
|
2010-10-13 23:25:33 +00:00
|
|
|
img.onload = imageLoadHandler;
|
|
|
|
expectedTestCount++;
|
|
|
|
|
|
|
|
// image at start
|
|
|
|
var imgfile = createFileWithData(fileData + testBinaryData);
|
2011-01-05 11:35:55 +00:00
|
|
|
is(imgfile.size, size + testBinaryData.length, "correct file size (start)");
|
2010-10-13 23:25:33 +00:00
|
|
|
var img = new Image;
|
2012-02-16 10:22:25 +00:00
|
|
|
img.src = URL.createObjectURL(imgfile.slice(0, size));
|
2010-10-13 23:25:33 +00:00
|
|
|
img.onload = imageLoadHandler;
|
|
|
|
expectedTestCount++;
|
|
|
|
|
|
|
|
// image at end
|
|
|
|
var imgfile = createFileWithData(testBinaryData + fileData);
|
2011-01-05 11:35:55 +00:00
|
|
|
is(imgfile.size, size + testBinaryData.length, "correct file size (end)");
|
2010-10-13 23:25:33 +00:00
|
|
|
var img = new Image;
|
2012-02-16 10:22:25 +00:00
|
|
|
img.src = URL.createObjectURL(imgfile.slice(testBinaryData.length, testBinaryData.length + size));
|
2010-10-13 23:25:33 +00:00
|
|
|
img.onload = imageLoadHandler;
|
|
|
|
expectedTestCount++;
|
|
|
|
|
|
|
|
// image past end
|
|
|
|
var imgfile = createFileWithData(testBinaryData + fileData);
|
2011-01-05 11:35:55 +00:00
|
|
|
is(imgfile.size, size + testBinaryData.length, "correct file size (past end)");
|
2010-10-13 23:25:33 +00:00
|
|
|
var img = new Image;
|
2012-02-16 10:22:25 +00:00
|
|
|
img.src = URL.createObjectURL(imgfile.slice(testBinaryData.length, testBinaryData.length + size + 1000));
|
2010-10-13 23:25:33 +00:00
|
|
|
img.onload = imageLoadHandler;
|
|
|
|
expectedTestCount++;
|
2013-03-13 16:40:55 +00:00
|
|
|
}
|
2010-10-13 23:25:33 +00:00
|
|
|
</script>
|
|
|
|
</pre>
|
|
|
|
</body> </html>
|