Bug 756844 - Change test strategy for screenshot API. r=jlebar
authorDale Harvey <dale@arandomurl.com>
Wed, 30 May 2012 22:15:12 -0400
changeset 95312 963ebb01fcba5062b0da0f7e02a500cde252e82a
parent 95311 81398d7402986bc0be6a94a4635bba062a017274
child 95331 7edd4b899696ddf12a2a14aa56269501aa7e5f65
push id10061
push userjlebar@mozilla.com
push dateThu, 31 May 2012 02:15:47 +0000
treeherdermozilla-inbound@963ebb01fcba [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjlebar
bugs756844
milestone15.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 756844 - Change test strategy for screenshot API. r=jlebar We originally made assumptions about the state of the painted window after the mozafterpainted event, now we simple wait until we receive a screenshot we are happy with (with max retries)
dom/tests/mochitest/browser-frame/test_browserFrame9.html
--- a/dom/tests/mochitest/browser-frame/test_browserFrame9.html
+++ b/dom/tests/mochitest/browser-frame/test_browserFrame9.html
@@ -17,67 +17,75 @@ https://bugzilla.mozilla.org/show_bug.cg
 -->
 
 <script type="application/javascript;version=1.7">
 
 "use strict";
 
 SimpleTest.waitForExplicitFinish();
 
-var iframeScript = function() {
-  const Ci = Components.interfaces;
-  function painted() {
-    sendAsyncMessage('test:mozpainted');
-  }
-  var utils = content.QueryInterface(Ci.nsIInterfaceRequestor)
-    .getInterface(Ci.nsIDOMWindowUtils);
-  if (!utils.isMozAfterPaintPending) {
-    sendAsyncMessage('test:mozpainted');
-  } else {
-    content.addEventListener("MozAfterPaint", painted, false);
-  }
-}
-
 function runTest() {
 
   browserFrameHelpers.setEnabledPref(true);
   browserFrameHelpers.addToWhitelist();
 
   var iframe1 = document.createElement('iframe');
   iframe1.mozbrowser = true;
   document.body.appendChild(iframe1);
+  iframe1.src = 'data:text/html,<html>' +
+    '<body style="background:green">hello</body></html>';
 
   var screenshots = [];
   var numLoaded = 0;
 
-  function screenshotLoaded(e) {
-    screenshots.push(e.target.result);
+  function screenshotTaken(screenshot) {
+    screenshots.push(screenshot);
     if (screenshots.length === 1) {
+      ok(true, 'Got initial non blank screenshot');
       iframe1.src = 'data:text/html,<html>' +
         '<body style="background:blue">hello</body></html>';
+      waitForScreenshot(function(screenshot) {
+        return screenshot !== screenshots[0];
+      });
     }
     else if (screenshots.length === 2) {
-      ok(screenshots[0] !== screenshots[1], 'Screenshots differ');
+      ok(true, 'Got updated screenshot after source page changed');
       SimpleTest.finish();
     }
   }
 
-  function recvMozPainted() {
+  // We continually take screenshots until we get one that we are
+  // happy with
+  function waitForScreenshot(filter) {
+
+    function screenshotLoaded(e) {
+      if (filter(e.target.result)) {
+        screenshotTaken(e.target.result);
+        return;
+      }
+      if (--attempts === 0) {
+        ok(false, 'Timed out waiting for correct screenshot');
+        SimpleTest.finish();
+      } else {
+        content.document.defaultView.setTimeout(function() {
+          iframe1.getScreenshot().onsuccess = screenshotLoaded;
+        }, 200);
+      }
+    }
+
+    var attempts = 10;
     iframe1.getScreenshot().onsuccess = screenshotLoaded;
   }
 
   function iframeLoadedHandler() {
     numLoaded++;
-    if (numLoaded === 1) {
-      iframe1.src = 'data:text/html,<html>' +
-        '<body style="background:green">hello</body></html>';
-    } else if (numLoaded === 2 || numLoaded === 3) {
-      var mm = SpecialPowers.getBrowserFrameMessageManager(iframe1);
-      mm.addMessageListener('test:mozpainted', recvMozPainted);
-      mm.loadFrameScript('data:,(' + iframeScript.toString() + ')();', false);
+    if (numLoaded === 2) {
+      waitForScreenshot(function(screenshot) {
+        return screenshot !== 'data:,';
+      });
     }
   }
 
   iframe1.addEventListener('mozbrowserloadend', iframeLoadedHandler);
 }
 
 addEventListener('load', function() { SimpleTest.executeSoon(runTest); });