Bug 1166832 - Adding test for canvas capture on multiple streams.
--- a/dom/canvas/test/captureStream_common.js
+++ b/dom/canvas/test/captureStream_common.js
@@ -23,16 +23,17 @@ function CaptureStreamTestHelper(width,
}
CaptureStreamTestHelper.prototype = {
/* Predefined colors for use in the methods below. */
black: { data: [0, 0, 0, 255], name: "black" },
blackTransparent: { data: [0, 0, 0, 0], name: "blackTransparent" },
green: { data: [0, 255, 0, 255], name: "green" },
red: { data: [255, 0, 0, 255], name: "red" },
+ blue: { data: [0, 0, 255, 255], name: "blue"},
grey: { data: [128, 128, 128, 255], name: "grey" },
/* Default element size for createAndAppendElement() */
elemWidth: 100,
elemHeight: 100,
/*
* Perform the drawing operation on each animation frame until stop is called
--- a/dom/media/tests/mochitest/mochitest.ini
+++ b/dom/media/tests/mochitest/mochitest.ini
@@ -107,16 +107,18 @@ skip-if = toolkit == 'gonk' # B2G emulat
[test_peerConnection_bug1042791.html]
skip-if = buildapp == 'b2g' || buildapp == 'mulet' || os == 'android' # bug 1043403 # Bug 1141029 Mulet parity with B2G Desktop for TC
[test_peerConnection_bug1064223.html]
[test_peerConnection_capturedVideo.html]
tags=capturestream
skip-if = toolkit == 'gonk' || buildapp == 'mulet' || android_version == '18' # b2g(Bug 960442, video support for WebRTC is disabled on b2g), android(Bug 1189784, timeouts on 4.3 emulator)
[test_peerConnection_captureStream_canvas_2d.html]
skip-if = toolkit == 'gonk' || buildapp == 'mulet' || (android_version == '18' && debug) # b2g(Bug 960442, video support for WebRTC is disabled on b2g), android(Bug 1189784, timeouts on 4.3 emulator)
+[test_peerConnection_multiple_captureStream_canvas_2d.html]
+skip-if = toolkit == 'gonk' || buildapp == 'mulet' || (android_version == '18' && debug) # b2g(Bug 960442, video support for WebRTC is disabled on b2g), android(Bug 1189784, timeouts on 4.3 emulator)
[test_peerConnection_captureStream_canvas_webgl.html]
skip-if = toolkit == 'gonk' || buildapp == 'mulet' # b2g(Bug 960442, video support for WebRTC is disabled on b2g)
# [test_peerConnection_certificates.html] # bug 1180968
# skip-if = toolkit == 'gonk' || buildapp == 'mulet' # b2g (Bug 1059867)
[test_peerConnection_close.html]
[test_peerConnection_closeDuringIce.html]
[test_peerConnection_errorCallbacks.html]
[test_peerConnection_iceFailure.html]
new file mode 100644
--- /dev/null
+++ b/dom/media/tests/mochitest/test_peerConnection_multiple_captureStream_canvas_2d.html
@@ -0,0 +1,106 @@
+<!DOCTYPE HTML>
+<html>
+<head>
+ <script type="application/javascript" src="pc.js"></script>
+ <script type="application/javascript" src="/tests/dom/canvas/test/captureStream_common.js"></script>
+</head>
+<body>
+<pre id="test">
+<script type="application/javascript">
+createHTML({
+ bug: "1032848",
+ title: "Canvas(2D)::Multiple CaptureStream as video-only input to peerconnection",
+ visible: true
+});
+
+/**
+ * Test to verify using multiple capture streams concurrently.
+ */
+runNetworkTest(() => {
+ var test = new PeerConnectionTest();
+ var h = new CaptureStreamTestHelper2D(50, 50);
+
+ var vremote1;
+ var stream1;
+ var canvas1 = h.createAndAppendElement('canvas', 'source_canvas1');
+
+ var vremote2;
+ var stream2;
+ var canvas2 = h.createAndAppendElement('canvas', 'source_canvas2');
+
+ test.setMediaConstraints([{video: true}, {video: true}], []);
+ test.chain.replace("PC_LOCAL_GUM", [
+ function DRAW_INITIAL_LOCAL1_GREEN(test) {
+ h.drawColor(canvas1, h.green);
+ },
+ function DRAW_INITIAL_LOCAL2_BLUE(test) {
+ h.drawColor(canvas2, h.blue);
+ },
+ function PC_LOCAL_CANVAS_CAPTURESTREAM(test) {
+ 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
+ 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");
+
+ 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");
+ },
+ 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() {
+ // 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);
+ },
+ function WAIT_FOR_REMOTE2_GREEN() {
+ return h.waitForPixelColor(vremote2, h.green, 128,
+ "pcRemote's remote2 should become green");
+ }
+ ]);
+ test.run();
+});
+</script>
+</pre>
+</body>
+</html>