Bug 1208371 - Simplify track disabling test code. r?jib
MozReview-Commit-ID: 1xMIosdYTW4
--- a/dom/media/tests/mochitest/test_peerConnection_trackDisabling.html
+++ b/dom/media/tests/mochitest/test_peerConnection_trackDisabling.html
@@ -34,32 +34,38 @@ runNetworkTest(() => {
var h = new CaptureStreamTestHelper2D();
var localVideo = test.pcLocal.mediaElements[0];
var remoteVideo = test.pcRemote.mediaElements[0];
// We check a pixel somewhere away from the top left corner since
// MediaEngineDefault puts semi-transparent time indicators there.
const offsetX = 50;
const offsetY = 50;
const threshold = 128;
+
+ // We're regarding black as disabled here, and we're setting the alpha
+ // channel of the pixel to 255 to disregard alpha when testing.
+ var checkVideoEnabled = video =>
+ h.waitForPixel(video, offsetX, offsetY,
+ px => (px[3] = 255, h.isPixelNot(px, h.black, threshold)));
+ var checkVideoDisabled = video =>
+ h.waitForPixel(video, offsetX, offsetY,
+ px => (px[3] = 255, h.isPixel(px, h.black, threshold)));
return Promise.resolve()
.then(() => info("Checking local video enabled"))
- .then(() => h.waitForPixel(localVideo, offsetX, offsetY,
- px => h.isPixelNot(px, h.black, 128)))
+ .then(() => checkVideoEnabled(localVideo))
.then(() => info("Checking remote video enabled"))
- .then(() => h.waitForPixel(remoteVideo, offsetX, offsetY,
- px => h.isPixelNot(px, h.black, 128)))
+ .then(() => checkVideoEnabled(remoteVideo))
+ .then(() => info("Disabling original"))
.then(() => test.pcLocal.streams[0].getVideoTracks()[0].enabled = false)
.then(() => info("Checking local video disabled"))
- .then(() => h.waitForPixel(localVideo, offsetX, offsetY,
- px => h.isPixel(px, h.blackTransparent, 128)))
+ .then(() => checkVideoDisabled(localVideo))
.then(() => info("Checking remote video disabled"))
- .then(() => h.waitForPixel(remoteVideo, offsetX, offsetY,
- px => h.isPixel(px, h.black, 128)))
+ .then(() => checkVideoDisabled(remoteVideo))
},
function CHECK_AUDIO() {
var ac = new AudioContext();
var localAnalyser = new AudioStreamAnalyser(ac, test.pcLocal.streams[0]);
var remoteAnalyser = new AudioStreamAnalyser(ac, test.pcRemote.streams[0]);
var checkAudio = (analyser, fun) => {
analyser.enableDebugCanvas();