summaryrefslogtreecommitdiffstats
path: root/dom/media/tests/mochitest/test_peerConnection_verifyVideoAfterRenegotiation.html
blob: 4aeb5e7ed0b2519b3ad583d48004d90f3a59ab45 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
<!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: "1166832",
    title: "Renegotiation: verify video after renegotiation"
  });

runNetworkTest(() => {
  var test = new PeerConnectionTest();

  var h1 = new CaptureStreamTestHelper2D(50, 50);
  var canvas1 = h1.createAndAppendElement('canvas', 'source_canvas1');
  var stream1;
  var vremote1;

  var h2 = new CaptureStreamTestHelper2D(50, 50);
  var canvas2;
  var stream2;
  var vremote2;

  test.setMediaConstraints([{video: true}], []);
  test.chain.replace("PC_LOCAL_GUM", [
    function DRAW_INITIAL_LOCAL_GREEN(test) {
      h1.drawColor(canvas1, h1.green);
    },
    function PC_LOCAL_CANVAS_CAPTURESTREAM(test) {
      stream1 = canvas1.captureStream(0);
      test.pcLocal.attachLocalStream(stream1);
    }
  ]);

  test.chain.append([
    function FIND_REMOTE_VIDEO() {
      vremote1 = test.pcRemote.remoteMediaElements[0];
      ok(!!vremote1, "Should have remote video element for pcRemote");
    },
    function WAIT_FOR_REMOTE_GREEN() {
      return h1.waitForPixelColor(vremote1, h1.green, 128,
                                 "pcRemote's remote should become green");
    },
    function DRAW_LOCAL_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();
      h1.drawColor(canvas1, h1.red);
    },
    function WAIT_FOR_REMOTE_RED() {
      return h1.waitForPixelColor(vremote1, h1.red, 128,
                                 "pcRemote's remote should become red");
    }
  ]);

  addRenegotiation(test.chain,
    [
      function PC_LOCAL_ADD_SECOND_STREAM(test) {
        canvas2 = h2.createAndAppendElement('canvas', 'source_canvas2');
        h2.drawColor(canvas2, h2.blue);
        stream2 = canvas2.captureStream(0);

        // can't use test.pcLocal.getAllUserMedia([{video: true}]);
        // because it doesn't let us substitute the capture stream
        test.pcLocal.attachLocalStream(stream2);
      }
    ]
  );

  test.chain.append([
    function FIND_REMOTE2_VIDEO() {
      vremote2 = test.pcRemote.remoteMediaElements[1];
      ok(!!vremote2, "Should have remote2 video element for pcRemote");
    },
    function WAIT_FOR_REMOTE2_BLUE() {
      return h2.waitForPixelColor(vremote2, h2.blue, 128,
                                 "pcRemote's remote2 should become blue");
    },
    function DRAW_NEW_LOCAL_GREEN(test) {
      stream1.requestFrame();
      h1.drawColor(canvas1, h1.green);
    },
    function WAIT_FOR_REMOTE1_GREEN() {
      return h1.waitForPixelColor(vremote1, h1.green, 128,
                                 "pcRemote's remote1 should become green");
    }
  ]);

  test.run();
});

</script>
</pre>
</body>
</html>