Bug 1208371 - Clear output canvas on each drawImage(). r?jib draft
authorAndreas Pehrson <pehrsons@gmail.com>
Tue, 05 Jan 2016 10:16:32 +0800
changeset 342165 9a334eadae40baa2d5f69ba4b60f455500c7d380
parent 342164 517b9deed7065d9318278799c1135b4a3dc1eff8
child 342166 f558878e2449672141fec69b0ce58464a986998f
push id13352
push userpehrsons@gmail.com
push dateFri, 18 Mar 2016 13:49:47 +0000
reviewersjib
bugs1208371
milestone47.0a1
Bug 1208371 - Clear output canvas on each drawImage(). r?jib Otherwise we'd risk reading old pixels in case we draw something transparent. MozReview-Commit-ID: LjNXE4Rmrmt
dom/canvas/test/captureStream_common.js
--- a/dom/canvas/test/captureStream_common.js
+++ b/dom/canvas/test/captureStream_common.js
@@ -57,16 +57,20 @@ CaptureStreamTestHelper.prototype = {
 
   /*
    * Returns the pixel at (|offsetX|, |offsetY|) (from top left corner) of
    * |video| as an array of the pixel's color channels: [R,G,B,A].
    */
   getPixel: function (video, offsetX, offsetY) {
     offsetX = offsetX || 0; // Set to 0 if not passed in.
     offsetY = offsetY || 0; // Set to 0 if not passed in.
+
+    // Avoids old values in case of a transparent image.
+    CaptureStreamTestHelper2D.prototype.clear.call(this, this.cout);
+
     var ctxout = this.cout.getContext('2d');
     ctxout.drawImage(video, 0, 0);
     return ctxout.getImageData(offsetX, offsetY, 1, 1).data;
   },
 
   /*
    * Returns true if px lies within the per-channel |threshold| of the
    * referenced color for all channels. px is on the form of an array of color
@@ -92,17 +96,16 @@ CaptureStreamTestHelper.prototype = {
 
   /*
    * Returns a promise that resolves when the provided function |test|
    * returns true.
    */
   waitForPixel: function (video, offsetX, offsetY, test, timeout) {
     return new Promise(resolve => {
       const startTime = video.currentTime;
-      CaptureStreamTestHelper2D.prototype.clear.call(this, this.cout);
       var ontimeupdate = () => {
         var pixelMatch = false;
         try {
           pixelMatch = test(this.getPixel(video, offsetX, offsetY));
         } catch (NS_ERROR_NOT_AVAILABLE) {
           info("Waiting for pixel but no video available");
         }
         if (!pixelMatch &&