Improve debugging ability of some webrtc tests
[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 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                 firstConnection.addTrack(stream.getVideoTracks()[0], stream);
50             }, (secondConnection) => {
51                 resolve(secondConnection.addTransceiver("video").receiver.track);
52             });
53             setTimeout(() => reject("Test timed out"), 5000);
54         });
55     }).then((track) => {
56         video.srcObject = new MediaStream([track]);
57         return waitFor(500);
58     }).then(() => {
59         return video.play();
60     }).then(() => {
61         testImage();
62     });
63 }, "Basic video exchange");
64         </script>
65     </body>
66 </html>