summaryrefslogtreecommitdiffstats
path: root/dom/media/webrtc/tests/mochitests/test_peerConnection_verifyVideoAfterRenegotiation.html
blob: 8d4155ddff29af4eb24bf20ba795b46db701feb5 (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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
<!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(async () => {
  // [TODO] re-enable HW decoder after bug 1526207 is fixed.
  if (navigator.userAgent.includes("Android")) {
    await pushPrefs(["media.navigator.mediadatadecoder_vpx_enabled", false],
                    ["media.webrtc.hw.h264.enabled", false]);
  }

  const test = new PeerConnectionTest();

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

  const h2 = new CaptureStreamTestHelper2D(50, 50);
  let canvas2;
  let stream2;
  let 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);
      let i = 0;
      return setInterval(function() {
        try {
          info("draw " + i ? "green" : "red");
          h1.drawColor(canvas1, i ? h1.green : h1.red);
          i = 1 - i;
          stream1.requestFrame();
          if (stream2 != null) {
            h2.drawColor(canvas2, i ? h2.green : h2.blue);
            stream2.requestFrame();
          }
        } catch (e) {
          // ignore; stream might have shut down, and we don't bother clearing
          // the setInterval.
        }
      }, 500);
    }
  ]);

  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.pixelMustBecome(vremote1, h1.green, {
        threshold: 128,
        infoString: "pcRemote's remote should become green",
      });
    },
    function WAIT_FOR_REMOTE_RED() {
      return h1.pixelMustBecome(vremote1, h1.red, {
        threshold: 128,
        infoString: "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.getAllUserMediaAndAddStreams([{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.pixelMustBecome(vremote2, h2.blue, {
        threshold: 128,
        infoString: "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.pixelMustBecome(vremote1, h1.green, {
        threshold: 128,
        infoString: "pcRemote's remote1 should become green",
      });
    }
  ]);

  await test.run();
});

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