--- a/devtools/server/tests/mochitest/inspector_getImageData.html
+++ b/devtools/server/tests/mochitest/inspector_getImageData.html
@@ -1,15 +1,16 @@
<html>
<head>
<body>
<img class="custom">
- <img class="big-horizontal" src="large-image.jpg" style="width:500px;" />
+ <img class="big-horizontal" src="large-image.jpg" style="width:500px;">
<canvas class="big-vertical" style="width:500px;"></canvas>
- <img class="small" src="small-image.gif"></img>
+ <img class="small" src="small-image.gif">
+ <img class="data" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABwAAAAcCAYAAAByDd+UAAAAJklEQVRIie3NMREAAAgAoe9fWls4eAzMVM0xoVAoFAqFQqFQ+C9chp4NHvu+4Q4AAAAASUVORK5CYII=">
<script>
window.onload = () => {
var canvas = document.querySelector("canvas"), ctx = canvas.getContext("2d");
canvas.width = 1000;
canvas.height = 2000;
ctx.fillStyle = "red";
ctx.fillRect(0, 0, 1000, 2000);
--- a/devtools/server/tests/mochitest/test_inspector_getImageData.html
+++ b/devtools/server/tests/mochitest/test_inspector_getImageData.html
@@ -42,17 +42,17 @@ addTest(function testLargeImage() {
ok(imageData.data, "Image data actor was sent back");
ok(imageData.size, "Image size info was sent back too");
is(imageData.size.naturalWidth, 5333, "Natural width of the image correct");
is(imageData.size.naturalHeight, 3000, "Natural width of the image correct");
ok(imageData.size.resized, "Image was resized");
imageData.data.string().then(str => {
ok(str, "We have an image data string!");
- runNextTest();
+ testResizing(imageData, str);
});
});
});
});
addTest(function testLargeCanvas() {
// Select the canvas node from the test page
gWalker.querySelector(gWalker.rootNode, ".big-vertical").then(canvas => {
@@ -63,17 +63,17 @@ addTest(function testLargeCanvas() {
ok(imageData.data, "Image data actor was sent back");
ok(imageData.size, "Image size info was sent back too");
is(imageData.size.naturalWidth, 1000, "Natural width of the image correct");
is(imageData.size.naturalHeight, 2000, "Natural width of the image correct");
ok(imageData.size.resized, "Image was resized");
imageData.data.string().then(str => {
ok(str, "We have an image data string!");
- runNextTest();
+ testResizing(imageData, str);
});
});
});
});
addTest(function testSmallImage() {
// Select the small image node from the test page
gWalker.querySelector(gWalker.rootNode, ".small").then(img => {
@@ -84,17 +84,38 @@ addTest(function testSmallImage() {
ok(imageData.data, "Image data actor was sent back");
ok(imageData.size, "Image size info was sent back too");
is(imageData.size.naturalWidth, 245, "Natural width of the image correct");
is(imageData.size.naturalHeight, 240, "Natural width of the image correct");
ok(!imageData.size.resized, "Image was NOT resized");
imageData.data.string().then(str => {
ok(str, "We have an image data string!");
- runNextTest();
+ testResizing(imageData, str);
+ });
+ });
+ });
+});
+
+addTest(function testDataImage() {
+ // Select the data image node from the test page
+ gWalker.querySelector(gWalker.rootNode, ".data").then(img => {
+ ok(img, "Image node found in the test page");
+ ok(img.getImageData, "Image node has the getImageData function");
+
+ img.getImageData(14).then(imageData => {
+ ok(imageData.data, "Image data actor was sent back");
+ ok(imageData.size, "Image size info was sent back too");
+ is(imageData.size.naturalWidth, 28, "Natural width of the image correct");
+ is(imageData.size.naturalHeight, 28, "Natural width of the image correct");
+ ok(imageData.size.resized, "Image was resized");
+
+ imageData.data.string().then(str => {
+ ok(str, "We have an image data string!");
+ testResizing(imageData, str);
});
});
});
});
addTest(function testNonImgOrCanvasElements() {
gWalker.querySelector(gWalker.rootNode, "body").then(body => {
ensureRejects(body.getImageData(), "Invalid element").then(runNextTest);
@@ -102,16 +123,30 @@ addTest(function testNonImgOrCanvasEleme
});
addTest(function cleanup() {
delete gWalker;
runNextTest();
});
/**
+ * Checks if the server told the truth about resizing the image
+ */
+function testResizing(imageData, str) {
+ let img = document.createElement("img");
+ img.addEventListener("load", () => {
+ let resized = !(img.naturalWidth == imageData.size.naturalWidth &&
+ img.naturalHeight == imageData.size.naturalHeight);
+ is(imageData.size.resized, resized, "Server told the truth about resizing");
+ runNextTest();
+ }, false);
+ img.src = str;
+}
+
+/**
* Asserts that the given promise rejects.
*/
function ensureRejects(promise, desc) {
return promise.then(() => {
ok(false, desc + ": promise resolved unexpectedly.");
}, () => {
ok(true, desc + ": promise rejected as expected.");
});