зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1171614 - Add a test for data-URI images to test_inspector_getImageData.html, and check that the server is being truthful about resizing. r=jdescottes
Also tidy up the HTML a bit by removing errant <img> close tags MozReview-Commit-ID: 4cmtW1S2BI8 --HG-- extra : transplant_source : %26%E6%FE%BB%FE%2A%CCG%E0%27%3B%3DYK%2BP%E7%9D%C7%C9
This commit is contained in:
Родитель
93ef07dcad
Коммит
86d55a0b62
|
@ -2,9 +2,10 @@
|
|||
<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");
|
||||
|
|
|
@ -47,7 +47,7 @@ addTest(function testLargeImage() {
|
|||
|
||||
imageData.data.string().then(str => {
|
||||
ok(str, "We have an image data string!");
|
||||
runNextTest();
|
||||
testResizing(imageData, str);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@ -68,7 +68,7 @@ addTest(function testLargeCanvas() {
|
|||
|
||||
imageData.data.string().then(str => {
|
||||
ok(str, "We have an image data string!");
|
||||
runNextTest();
|
||||
testResizing(imageData, str);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@ -89,7 +89,28 @@ addTest(function testSmallImage() {
|
|||
|
||||
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);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@ -106,6 +127,20 @@ addTest(function cleanup() {
|
|||
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.
|
||||
*/
|
||||
|
|
Загрузка…
Ссылка в новой задаче