123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169 |
- <!DOCTYPE HTML>
- <html>
- <!--
- https://bugzilla.mozilla.org/show_bug.cgi?id=1089880
- -->
- <head>
- <title>Test for Bug 1089880</title>
- <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
- <script type="application/javascript" src="/tests/SimpleTest/WindowSnapshot.js"></script>
- <script type="application/javascript" src="imgutils.js"></script>
- <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=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.requestFlakyTimeout("Early failure timeout");
- SimpleTest.waitForExplicitFinish();
- const FAILURE_TIMEOUT = 120000; // Fail early after 120 seconds (2 minutes)
- const Cc = SpecialPowers.Cc;
- const Ci = SpecialPowers.Ci;
- const gContent = document.getElementById("content");
- var gCanvas;
- var gCanvasCtx;
- 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 are never transparent.
- yield ["damon.jpg", false];
- // Most BMPs are not transparent. (The TestMetadata GTest, which will
- // eventually replace this test totally, has coverage for the kinds that can be
- // transparent.)
- yield ["opaque.bmp", false];
- // ICO files which contain BMPs have an additional type of transparency - the
- // AND mask - that warrants separate testing. (Although, after bug 1201796,
- // all ICOs are considered transparent.)
- yield ["ico-bmp-opaque.ico", true];
- 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);
- // Force decoding of the image.
- SimpleTest.executeSoon(function() {
- gCanvasCtx.drawImage(gImg, 0, 0);
- });
- }
- function failTest() {
- ok(false, "timing out after " + FAILURE_TIMEOUT + "ms. " +
- "currently displaying " + gImg.src);
- cleanUpAndFinish();
- }
- function cleanUpAndFinish() {
- if (gIsTestFinished) {
- return;
- }
- gIsTestFinished = true;
- let imgLoadingContent = SpecialPowers.wrap(gImg).QueryInterface(Ci.nsIImageLoadingContent);
- imgLoadingContent.removeObserver(gMyDecoderObserver);
- SimpleTest.finish();
- }
- function main() {
- gFiles = testFiles();
- gCanvas = document.createElement('canvas');
- gCanvasCtx = gCanvas.getContext('2d');
- 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(SpecialPowers.wrapCallbackObject(observer));
- let imgLoadingContent = SpecialPowers.wrap(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.
- clearAllImageCaches();
- // 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>
|