Update device orientation & motion permission native SPI as per latest proposal
[WebKit-https.git] / LayoutTests / webrtc / video-with-receiver.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 if (window.testRunner)
18     testRunner.setWebRTCUnifiedPlanEnabled(false);
19
20 function testImage()
21 {
22     canvas.width = video.videoWidth;
23     canvas.height = video.videoHeight;
24     canvas.getContext('2d').drawImage(video, 0, 0, canvas.width, canvas.height);
25
26     imageData = canvas.getContext('2d').getImageData(10, 325, 250, 1);
27     data = imageData.data;
28
29     var index = 20;
30     assert_true(data[index] < 100);
31     assert_true(data[index + 1] < 100);
32     assert_true(data[index + 2] < 100);
33
34     index = 80;
35     assert_true(data[index] > 200);
36     assert_true(data[index + 1] > 200);
37     assert_true(data[index + 2] > 200);
38
39     index += 80;
40     assert_true(data[index] > 200);
41     assert_true(data[index + 1] > 200);
42     assert_true(data[index + 2] < 100);
43 }
44
45 promise_test((test) => {
46     if (window.testRunner)
47         testRunner.setUserMediaPermission(true);
48
49     return navigator.mediaDevices.getUserMedia({ video: true}).then((stream) => {
50         return new Promise((resolve, reject) => {
51             createConnections((firstConnection) => {
52                 firstConnection.addTrack(stream.getVideoTracks()[0], stream);
53             }, (secondConnection) => {
54                 resolve(secondConnection.addTransceiver("video").receiver.track);
55             });
56             setTimeout(() => reject("Test timed out"), 5000);
57         });
58     }).then((track) => {
59         video.srcObject = new MediaStream([track]);
60         return waitFor(500);
61     }).then(() => {
62         return video.play();
63     }).then(() => {
64         testImage();
65     });
66 }, "Basic video exchange");
67         </script>
68     </body>
69 </html>