Make captureCanvas-webrtc.html more robust
[WebKit-https.git] / LayoutTests / webrtc / video-autoplay.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         <script src=../media/media-file.js></script>
9         <script src=../media/video-test.js></script>
10     </head>
11     <body>
12         <video id="video" autoplay></video>
13         <script src ="routines.js"></script>
14         <script>
15 video = document.getElementById("video");
16
17 if (window.internals)
18     internals.setMediaElementRestrictions(video, "RequireUserGestureForVideoRateChange");
19 if (window.testRunner)
20     testRunner.setUserMediaPermission(true);
21
22 promise_test((test) => {
23     findMediaElement();
24     video.src = findMediaFile("video", "content/test");
25     return video.play().then(() => assert_unreached(), (e) => { assert_equals(e.name, 'NotAllowedError')});
26 }, "Ensuring autoplay does not work on regular video elements")
27
28 promise_test((test) => {
29     return navigator.mediaDevices.getUserMedia({audio: true, video: true}).then((stream) => {
30         findMediaElement();
31         video.src = findMediaFile("video", "content/test");
32         return video.play().then(() => assert_unreached(), (e) => { assert_equals(e.name, 'NotAllowedError')});
33     });
34 }, "Ensuring autoplay does not work on regular video elements when getUserMedia is on");
35
36 promise_test((test) => {
37     return navigator.mediaDevices.getUserMedia({audio: true, video: true}).then((stream) => {
38         video.srcObject = stream;
39         return waitFor(10);
40     }).then(() => {
41         return video.play();
42     });
43 }, "Local media stream autoplay");
44
45 promise_test((test) => {
46     return navigator.mediaDevices.getUserMedia({audio: true, video: true}).then((stream) => {
47         return new Promise((resolve, reject) => {
48             createConnections((firstConnection) => {
49                 firstConnection.addTrack(stream.getVideoTracks()[0], stream);
50                 firstConnection.addTrack(stream.getAudioTracks()[0], stream);
51             }, (secondConnection) => {
52                 var count = 0;
53                 secondConnection.ontrack = (trackEvent) => {
54                     if (++count == 2)
55                         resolve(trackEvent.streams[0]);
56                 };
57             });
58             setTimeout(() => reject("Test timed out"), 5000);
59         });
60     }).then((stream) => {
61         video.srcObject = stream;
62         return video.play();
63     });
64 }, "Remote media stream autoplay");
65
66         </script>
67     </body>
68 </html>