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
--- 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 &&