Bug 1208371 - Simplify track disabling test code. r?jib draft
authorAndreas Pehrson <pehrsons@gmail.com>
Tue, 05 Jan 2016 10:16:30 +0800
changeset 342148 b0c78c1bc07d80c73e30896c25e8ed3b624f3aee
parent 342147 4b5d7c4f875af6691046a85de13c6c193322d0a9
child 342149 17484eec167498d28b6a12f3ab347b9260f02774
push id13352
push userpehrsons@gmail.com
push dateFri, 18 Mar 2016 13:49:47 +0000
reviewersjib
bugs1208371
milestone47.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,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();