Bug 1089880 (Part 2) - Add tests for HAS_TRANSPARENCY. r=tn
authorSeth Fowler <seth@mozilla.com>
Mon, 17 Nov 2014 11:16:45 -0800
changeset 240456 2af9fb958b4eac603e6fda3570452190a97d80ce
parent 240455 72822bad1819522fd518775ef5adfd9177b6c05c
child 240457 f4eea7e2f94be3d737c844703a9de7f46563aaab
push id4311
push userraliiev@mozilla.com
push dateMon, 12 Jan 2015 19:37:41 +0000
treeherdermozilla-beta@150c9fed433b [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerstn
bugs1089880
milestone36.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1089880 (Part 2) - Add tests for HAS_TRANSPARENCY. r=tn
image/public/imgIScriptedNotificationObserver.idl
image/src/ScriptedNotificationObserver.cpp
image/test/mochitest/chrome.ini
image/test/mochitest/first-frame-padding.gif
image/test/mochitest/ico-bmp-opaque.ico
image/test/mochitest/ico-bmp-transparent.ico
image/test/mochitest/imgutils.js
image/test/mochitest/opaque.bmp
image/test/mochitest/red.gif
image/test/mochitest/test_has_transparency.html
image/test/mochitest/transparent.gif
image/test/mochitest/transparent.png
--- a/image/public/imgIScriptedNotificationObserver.idl
+++ b/image/public/imgIScriptedNotificationObserver.idl
@@ -13,9 +13,10 @@ interface imgIScriptedNotificationObserv
 {
   void sizeAvailable(in imgIRequest aRequest);
   void frameUpdate(in imgIRequest aRequest);
   void frameComplete(in imgIRequest aRequest);
   void loadComplete(in imgIRequest aRequest);
   void decodeComplete(in imgIRequest aRequest);
   void discard(in imgIRequest aRequest);
   void isAnimated(in imgIRequest aRequest);
+  void hasTransparency(in imgIRequest aRequest);
 };
--- a/image/src/ScriptedNotificationObserver.cpp
+++ b/image/src/ScriptedNotificationObserver.cpp
@@ -41,13 +41,15 @@ ScriptedNotificationObserver::Notify(img
   if (aType == imgINotificationObserver::DECODE_COMPLETE)
     return mInner->DecodeComplete(aRequest);
   if (aType == imgINotificationObserver::LOAD_COMPLETE)
     return mInner->LoadComplete(aRequest);
   if (aType == imgINotificationObserver::DISCARD)
     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;
 }
 
 } // namespace image
 } // namespace mozilla
--- a/image/test/mochitest/chrome.ini
+++ b/image/test/mochitest/chrome.ini
@@ -6,35 +6,43 @@ support-files =
   animated1.gif
   animated2.gif
   animation.svg
   animationPolling.js
   bad.jpg
   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]
 [test_animation.html]
 [test_animation2.html]
 [test_background_image_anim.html]
 [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]
 [test_staticClone.html]
 [test_svg_animatedGIF.html]
 [test_svg_filter_animation.html]
 [test_synchronized_animation.html]
 [test_undisplayed_iframe.html]
copy from image/test/reftest/gif/one-color-offset.gif
copy to image/test/mochitest/first-frame-padding.gif
copy from image/test/reftest/ico/ico-bmp-8bpp/ico-size-1x1-8bpp.ico
copy to image/test/mochitest/ico-bmp-opaque.ico
copy from image/test/reftest/ico/ico-bmp-32bpp/ico-transparent-32bpp.ico
copy to image/test/mochitest/ico-bmp-transparent.ico
--- a/image/test/mochitest/imgutils.js
+++ b/image/test/mochitest/imgutils.js
@@ -112,16 +112,17 @@ function getImagePref(pref)
   }
   else
     return null;
 }
 
 // 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) {}
 }
copy from image/test/reftest/bmp/bmp-8bpp/bmp-size-2x2-8bpp.bmp
copy to image/test/mochitest/opaque.bmp
copy from image/test/reftest/gif/red.gif
copy to image/test/mochitest/red.gif
new file mode 100644
--- /dev/null
+++ b/image/test/mochitest/test_has_transparency.html
@@ -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>
copy from image/test/reftest/gif/in-colormap-trans.gif
copy to image/test/mochitest/transparent.gif
copy from image/test/reftest/pngsuite-transparency/tbbn1g04.png
copy to image/test/mochitest/transparent.png