Migrating webrtc tests to latest API
[WebKit-https.git] / LayoutTests / webrtc / video.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="video" autoplay=""></video>
11         <canvas id="canvas" width="640" height="480"></canvas>
12         <script src ="routines.js"></script>
13         <script>
14 video = document.getElementById("video");
15 canvas = document.getElementById("canvas");
16
17 function testImage()
18 {
19     canvas.width = video.videoWidth;
20     canvas.height = video.videoHeight;
21     canvas.getContext('2d').drawImage(video, 0, 0, canvas.width, canvas.height);
22
23     imageData = canvas.getContext('2d').getImageData(10, 325, 250, 1);
24     data = imageData.data;
25
26     var index = 20;
27     assert_true(data[index] < 100);
28     assert_true(data[index + 1] < 100);
29     assert_true(data[index + 2] < 100);
30
31     index = 80;
32     assert_true(data[index] > 200);
33     assert_true(data[index + 1] > 200);
34     assert_true(data[index + 2] > 200);
35
36     index += 80;
37     assert_true(data[index] > 200);
38     assert_true(data[index + 1] > 200);
39     assert_true(data[index + 2] < 100);
40 }
41
42 promise_test((test) => {
43     if (window.testRunner)
44         testRunner.setUserMediaPermission(true);
45
46     return navigator.mediaDevices.getUserMedia({ video: true}).then((stream) => {
47         return new Promise((resolve, reject) => {
48             createConnections((firstConnection) => {
49                 var track = stream.getVideoTracks()[0];
50                 firstConnection.addTrack(stream.getVideoTracks()[0], stream);
51             }, (secondConnection) => {
52                 secondConnection.ontrack = (trackEvent) => {
53                     assert_true(trackEvent.track instanceof MediaStreamTrack);
54                     assert_true(trackEvent.receiver instanceof RTCRtpReceiver);
55                     assert_true(Array.isArray(trackEvent.streams), "Array.isArray() should return true");
56                     assert_true(Object.isFrozen(trackEvent.streams), "Object.isFrozen() should return true");
57                     assert_equals(trackEvent.track.id, stream.getVideoTracks()[0].id);
58                     resolve(trackEvent.streams[0]);
59                 };
60             });
61             setTimeout(() => reject("Test timed out"), 5000);
62         });
63     }).then((stream) => {
64         video.srcObject = stream;
65         return video.play();
66     }).then(() => {
67         testImage();
68     });
69 }, "Basic video exchange");
70         </script>
71     </body>
72 </html>