Make mDNS ICE Candidate an experimental flag again
[WebKit-https.git] / LayoutTests / webrtc / video-interruption.html
1 <!doctype html>
2 <html>
3     <head>
4         <meta charset="utf-8">
5         <title>Testing basic video exchange from offerer to receiver</title>
6         <script src="../resources/testharness.js"></script>
7         <script src="../resources/testharnessreport.js"></script>
8     </head>
9     <body>
10         <video id="video1" autoplay=""></video>
11         <video id="video2" autoplay=""></video>
12         <canvas id="canvas" width="640" height="480"></canvas>
13         <script src ="routines.js"></script>
14         <script>
15 video = document.getElementById("video");
16 canvas = document.getElementById("canvas");
17
18 function testImage(video)
19 {
20     canvas.width = video.videoWidth;
21     canvas.height = video.videoHeight;
22     canvas.getContext('2d').drawImage(video, 0, 0, canvas.width, canvas.height);
23
24     imageData = canvas.getContext('2d').getImageData(10, 325, 250, 1);
25     data = imageData.data;
26
27     var index = 20;
28     assert_true(data[index] < 100);
29     assert_true(data[index + 1] < 100);
30     assert_true(data[index + 2] < 100);
31
32     index = 80;
33     assert_true(data[index] > 200);
34     assert_true(data[index + 1] > 200);
35     assert_true(data[index + 2] > 200);
36
37     index += 80;
38     assert_true(data[index] > 200);
39     assert_true(data[index + 1] > 200);
40     assert_true(data[index + 2] < 100);
41 }
42
43 promise_test((test) => {
44     if (window.testRunner)
45         testRunner.setUserMediaPermission(true);
46
47     var stream;
48     return navigator.mediaDevices.getUserMedia({video: {advanced: [{width:{min:640}}, {height:{min:480} } ]}}).then((stream) => {
49         return new Promise((resolve, reject) => {
50             createConnections((firstConnection) => {
51                 var track = stream.getVideoTracks()[0];
52                 firstConnection.addTrack(stream.getVideoTracks()[0], stream);
53             }, (secondConnection) => {
54                 secondConnection.ontrack = (trackEvent) => {
55                     assert_true(trackEvent.track instanceof MediaStreamTrack);
56                     assert_true(trackEvent.receiver instanceof RTCRtpReceiver);
57                     assert_true(Array.isArray(trackEvent.streams), "Array.isArray() should return true");
58                     assert_true(Object.isFrozen(trackEvent.streams), "Object.isFrozen() should return true");
59                     assert_equals(trackEvent.track.id, stream.getVideoTracks()[0].id);
60                     assert_equals(trackEvent.track, trackEvent.streams[0].getVideoTracks()[0]);
61                     resolve(trackEvent.streams[0]);
62                 };
63             });
64             setTimeout(() => reject("Test timed out"), 5000);
65         });
66     }).then((s) => {
67         stream = s;
68         video1.srcObject = stream;
69         return video1.play();
70     }).then(() => {
71         testImage(video1);
72     }).then(() => {
73         internals.beginMediaSessionInterruption('EnteringBackground');
74     }).then(() => {
75         internals.endMediaSessionInterruption('');
76     }).then(() => {
77         video2.srcObject = stream;
78         return video2.play();
79     }).then(() => {
80         testImage(video2);
81     });
82 }, "Basic video exchange with media session interruption");
83         </script>
84     </body>
85 </html>