Bug 1089880 (Part 2) - Add tests for HAS_TRANSPARENCY. r=tn

--HG--
rename : image/test/reftest/gif/one-color-offset.gif => image/test/mochitest/first-frame-padding.gif
rename : image/test/reftest/ico/ico-bmp-8bpp/ico-size-1x1-8bpp.ico => image/test/mochitest/ico-bmp-opaque.ico
rename : image/test/reftest/ico/ico-bmp-32bpp/ico-transparent-32bpp.ico => image/test/mochitest/ico-bmp-transparent.ico
rename : image/test/reftest/bmp/bmp-8bpp/bmp-size-2x2-8bpp.bmp => image/test/mochitest/opaque.bmp
rename : image/test/reftest/gif/red.gif => image/test/mochitest/red.gif
rename : image/test/reftest/gif/in-colormap-trans.gif => image/test/mochitest/transparent.gif
rename : image/test/reftest/pngsuite-transparency/tbbn1g04.png => image/test/mochitest/transparent.png
This commit is contained in:
Seth Fowler 2014-11-17 11:16:45 -08:00
Родитель 5376541aef
Коммит 73039c2713
12 изменённых файлов: 172 добавлений и 7 удалений

Просмотреть файл

@ -18,4 +18,5 @@ interface imgIScriptedNotificationObserver : nsISupports
void decodeComplete(in imgIRequest aRequest);
void discard(in imgIRequest aRequest);
void isAnimated(in imgIRequest aRequest);
void hasTransparency(in imgIRequest aRequest);
};

Просмотреть файл

@ -46,6 +46,8 @@ ScriptedNotificationObserver::Notify(imgIRequest* aRequest,
return mInner->Discard(aRequest);
if (aType == imgINotificationObserver::IS_ANIMATED)
return mInner->IsAnimated(aRequest);
if (aType == imgINotificationObserver::HAS_TRANSPARENCY)
return mInner->HasTransparency(aRequest);
return NS_OK;
}

Просмотреть файл

@ -11,16 +11,23 @@ support-files =
damon.jpg
filter-final.svg
filter.svg
first-frame-padding.gif
ico-bmp-opaque.ico
ico-bmp-transparent.ico
iframe.html
imgutils.js
invalid.jpg
lime-anim-100x100-2.svg
lime-anim-100x100.svg
lime100x100.svg
opaque.bmp
purple.gif
red.gif
red.png
ref-iframe.html
rillybad.jpg
transparent.gif
transparent.png
[test_animSVGImage.html]
[test_animSVGImage2.html]
@ -30,6 +37,7 @@ support-files =
[test_bullet_animation.html]
[test_changeOfSource.html]
[test_changeOfSource2.html]
[test_has_transparency.html]
[test_net_failedtoprocess.html]
[test_removal_ondecode.html]
[test_removal_onload.html]

Двоичные данные
image/test/mochitest/first-frame-padding.gif Normal file

Двоичный файл не отображается.

После

Ширина:  |  Высота:  |  Размер: 49 B

Двоичные данные
image/test/mochitest/ico-bmp-opaque.ico Normal file

Двоичный файл не отображается.

После

Ширина:  |  Высота:  |  Размер: 1.1 KiB

Двоичные данные
image/test/mochitest/ico-bmp-transparent.ico Normal file

Двоичный файл не отображается.

После

Ширина:  |  Высота:  |  Размер: 4.2 KiB

Просмотреть файл

@ -117,11 +117,12 @@ function getImagePref(pref)
// JS implementation of imgIScriptedNotificationObserver with stubs for all of its methods.
function ImageDecoderObserverStub()
{
this.sizeAvailable = function sizeAvailable(aRequest) {}
this.frameComplete = function frameComplete(aRequest) {}
this.decodeComplete = function decodeComplete(aRequest) {}
this.loadComplete = function loadComplete(aRequest) {}
this.frameUpdate = function frameUpdate(aRequest) {}
this.discard = function discard(aRequest) {}
this.isAnimated = function isAnimated(aRequest) {}
this.sizeAvailable = function sizeAvailable(aRequest) {}
this.frameComplete = function frameComplete(aRequest) {}
this.decodeComplete = function decodeComplete(aRequest) {}
this.loadComplete = function loadComplete(aRequest) {}
this.frameUpdate = function frameUpdate(aRequest) {}
this.discard = function discard(aRequest) {}
this.isAnimated = function isAnimated(aRequest) {}
this.hasTransparency = function hasTransparency(aRequest) {}
}

Двоичные данные
image/test/mochitest/opaque.bmp Normal file

Двоичный файл не отображается.

После

Ширина:  |  Высота:  |  Размер: 1.1 KiB

Двоичные данные
image/test/mochitest/red.gif Normal file

Двоичный файл не отображается.

После

Ширина:  |  Высота:  |  Размер: 43 B

Просмотреть файл

@ -0,0 +1,153 @@
<!DOCTYPE HTML>
<html>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=1089880
-->
<head>
<title>Test for Bug 1089880</title>
<script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
<script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/WindowSnapshot.js"></script>
<script type="application/javascript" src="imgutils.js"></script>
<link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css" />
</head>
<body>
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1089880">Mozilla Bug 1089880</a>
<p id="display"></p>
<div id="content">
</div>
<pre id="test">
<script type="application/javascript;version=1.8">
/** Test for Bug 1089880 **/
SimpleTest.waitForExplicitFinish();
const FAILURE_TIMEOUT = 120000; // Fail early after 120 seconds (2 minutes)
const Cc = Components.classes;
const Ci = Components.interfaces;
const gContent = document.getElementById("content");
var gImg;
var gMyDecoderObserver;
var gIsTestFinished = false;
var gFiles;
var gCurrentFileIsTransparent = false;
var gHasTransparencyWasCalled = false;
function testFiles() {
// [A, B] where 'A' is the image and 'B' is whether it's transparent.
// PNGs and GIFs may be transparent or not.
yield ["red.png", false];
yield ["transparent.png", true];
yield ["red.gif", false];
yield ["transparent.gif", true];
// GIFs with padding on the first frame are always transparent.
yield ["first-frame-padding.gif", true];
// JPEGs and BMPs are never transparent.
yield ["damon.jpg", false];
yield ["opaque.bmp", false];
// ICO files which contain BMPs have an additional type of transparency - the
// AND mask - that warrants separate testing.
yield ["ico-bmp-opaque.ico", false];
yield ["ico-bmp-transparent.ico", true];
// SVGs are always transparent.
yield ["lime100x100.svg", true];
}
function loadNext() {
var currentFile = "";
try {
gHasTransparencyWasCalled = false;
[currentFile, gCurrentFileIsTransparent] = gFiles.next();
gImg.setAttribute("src", currentFile);
} catch (e) {
// We ran out of test files.
cleanUpAndFinish();
}
}
function onHasTransparency(aRequest) {
gHasTransparencyWasCalled = true;
}
function onDecodeComplete(aRequest) {
if (!gCurrentFileIsTransparent) {
ok(!gHasTransparencyWasCalled,
"onHasTransparency was not called for non-transparent file " + gImg.src);
} else {
ok(gHasTransparencyWasCalled,
"onHasTransparency was called for transparent file " + gImg.src);
}
loadNext();
}
function onError() {
if (gIsTestFinished) {
return;
}
ok(false, "Should successfully load " + gImg.src);
loadNext();
}
function onLoad() {
if (gIsTestFinished) {
return;
}
ok(true, "Should successfully load " + gImg.src);
}
function failTest() {
ok(false, "timing out after " + FAILURE_TIMEOUT + "ms. " +
"currently displaying " + gImg.src);
cleanUpAndFinish();
}
function cleanUpAndFinish() {
if (gIsTestFinished) {
return;
}
gIsTestFinished = true;
let imgLoadingContent = gImg.QueryInterface(Ci.nsIImageLoadingContent);
imgLoadingContent.removeObserver(gMyDecoderObserver);
SimpleTest.finish();
}
function main() {
gFiles = testFiles();
gImg = new Image();
gImg.onload = onLoad;
gImg.onerror = onError;
// Create, customize & attach decoder observer.
observer = new ImageDecoderObserverStub();
observer.hasTransparency = onHasTransparency;
observer.decodeComplete = onDecodeComplete;
gMyDecoderObserver =
Cc["@mozilla.org/image/tools;1"].getService(Ci.imgITools)
.createScriptedObserver(observer);
let imgLoadingContent = gImg.QueryInterface(Ci.nsIImageLoadingContent);
imgLoadingContent.addObserver(gMyDecoderObserver);
// We want to test the cold loading behavior, so clear cache in case an
// earlier test got our image in there already.
clearImageCache();
// Load the first image.
loadNext();
// In case something goes wrong, fail earlier than mochitest timeout,
// and with more information.
setTimeout(failTest, FAILURE_TIMEOUT);
}
window.onload = main;
</script>
</pre>
</body>
</html>

Двоичные данные
image/test/mochitest/transparent.gif Normal file

Двоичный файл не отображается.

После

Ширина:  |  Высота:  |  Размер: 355 B

Двоичные данные
image/test/mochitest/transparent.png Normal file

Двоичный файл не отображается.

После

Ширина:  |  Высота:  |  Размер: 419 B