Bug 1166832 - Address review, using a promise to avoid a rendering race. draft
authorMichael Froman <mfroman@mozilla.com>
Wed, 13 Jan 2016 20:53:33 -0600
changeset 321548 2e15b57fcc6593fcc5bf273320cdbfa6387c979e
parent 321547 7175c404ba5ab08ffa23a272a3b7c0a8dbe1bcd9
child 321549 b4b2dd4e82ae86bfe40eeaafc522b0edecb73737
push id9416
push usermfroman@nostrum.com
push dateThu, 14 Jan 2016 03:00:43 +0000
bugs1166832
milestone46.0a1
Bug 1166832 - Address review, using a promise to avoid a rendering race.
dom/media/tests/mochitest/test_peerConnection_multiple_captureStream_canvas_2d.html
--- a/dom/media/tests/mochitest/test_peerConnection_multiple_captureStream_canvas_2d.html
+++ b/dom/media/tests/mochitest/test_peerConnection_multiple_captureStream_canvas_2d.html
@@ -40,67 +40,61 @@ runNetworkTest(() => {
       stream1 = canvas1.captureStream(0); // fps = 0 to capture single frame
       test.pcLocal.attachMedia(stream1, 'video', 'local');
       stream2 = canvas2.captureStream(0); // fps = 0 to capture single frame
       test.pcLocal.attachMedia(stream2, 'video', 'local');
     }
   ]);
 
   test.chain.append([
-    function FIND_REMOTE_VIDEO() {
-      // we don't know which remote video is created first, so we don't know
-      // which corresponds to the original local video (meaning we don't know
-      // which color is expected in which remote
+    function CHECK_REMOTE_VIDEO() {
       var testremote = document.getElementById('pcRemote_remote3_video');
       ok(!testremote, "Should not have remote3 video element for pcRemote");
-      testremote = document.getElementById('pcRemote_remote1_video');
-      ok(testremote, "Should have remote1 video element for pcRemote");
+      vremote1 = document.getElementById('pcRemote_remote1_video');
+      vremote2 = document.getElementById('pcRemote_remote2_video');
 
-      if (h.isPixel(h.getPixel(testremote), h.green, 128)) {
-        info("testremote has green");
-        vremote1 = testremote;
-        vremote2 = document.getElementById('pcRemote_remote2_video');;
-      } else if (h.isPixel(h.getPixel(testremote), h.blue, 128)) {
-        info("testremote has blue");
-        vremote2 = testremote;
-        vremote1 = document.getElementById('pcRemote_remote2_video');
-      }
-
-      ok(vremote1, "Should have remote1 video element for pcRemote");
-      ok(vremote2, "Should have remote2 video element for pcRemote");
-    },
-    function WAIT_FOR_REMOTE1_GREEN() {
-      return h.waitForPixelColor(vremote1, h.green, 128,
-                                 "pcRemote's remote1 should become green");
-    },
-    function WAIT_FOR_REMOTE2_BLUE() {
-      return h.waitForPixelColor(vremote2, h.blue, 128,
-                                 "pcRemote's remote2 should become green");
+      // since we don't know which remote video is created first, we don't know
+      // which should be blue or green, but this will make sure that one is
+      // green and one is blue
+      return Promise.race([
+               Promise.all([
+                 h.waitForPixelColor(vremote1, h.green, 128,
+                                     "pcRemote's remote1 should become green"),
+                 h.waitForPixelColor(vremote2, h.blue, 128,
+                                     "pcRemote's remote2 should become blue")
+               ]),
+               Promise.all([
+                 h.waitForPixelColor(vremote2, h.green, 128,
+                                     "pcRemote's remote2 should become green"),
+                 h.waitForPixelColor(vremote1, h.blue, 128,
+                                     "pcRemote's remote1 should become blue")
+               ])
+             ])
     },
     function DRAW_LOCAL1_RED() {
       // After requesting a frame it will be captured at the time of next render.
       // Next render will happen at next stable state, at the earliest,
       // i.e., this order of `requestFrame(); draw();` should work.
       stream1.requestFrame();
       h.drawColor(canvas1, h.red);
     },
     function WAIT_FOR_REMOTE1_RED() {
       return h.waitForPixelColor(vremote1, h.red, 128,
                                  "pcRemote's remote1 should become red");
     },
-    function DRAW_LOCAL2_GREEN() {
+    function DRAW_LOCAL2_RED() {
       // After requesting a frame it will be captured at the time of next render.
       // Next render will happen at next stable state, at the earliest,
       // i.e., this order of `requestFrame(); draw();` should work.
       stream2.requestFrame();
-      h.drawColor(canvas2, h.green);
+      h.drawColor(canvas2, h.red);
     },
-    function WAIT_FOR_REMOTE2_GREEN() {
-      return h.waitForPixelColor(vremote2, h.green, 128,
-                                 "pcRemote's remote2 should become green");
+    function WAIT_FOR_REMOTE2_RED() {
+      return h.waitForPixelColor(vremote2, h.red, 128,
+                                 "pcRemote's remote2 should become red");
     }
   ]);
   test.run();
 });
 </script>
 </pre>
 </body>
 </html>