Bug 1208371 - Simplify track disabling test code. r=jib
authorAndreas Pehrson <pehrsons@gmail.com>
Tue, 05 Jan 2016 10:16:30 +0800
changeset 348466 61a778ea5288324443bbbd738d24dc1f037a0236
parent 348465 7b3edee97b25a728ec147e4db06488a5fe6985ac
child 348467 0c907897958d6e2ede952b13145d8686ef894545
push id14828
push userpehrsons@gmail.com
push dateThu, 07 Apr 2016 12:57:27 +0000
reviewersjib
bugs1208371
milestone48.0a1
Bug 1208371 - Simplify track disabling test code. r=jib MozReview-Commit-ID: 1xMIosdYTW4
dom/media/tests/mochitest/test_peerConnection_trackDisabling.html
--- a/dom/media/tests/mochitest/test_peerConnection_trackDisabling.html
+++ b/dom/media/tests/mochitest/test_peerConnection_trackDisabling.html
@@ -34,33 +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, offsetX*2, offsetY*2)));
       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), offsetX*2, offsetY*2))
+        .then(() => checkVideoDisabled(localVideo))
         .then(() => info("Checking remote video disabled"))
-        .then(() => h.waitForPixel(remoteVideo, offsetX, offsetY,
-                                   px => h.isPixel(px, h.black, 128), offsetX*2, offsetY*2))
+        .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();