Update device orientation & motion permission native SPI as per latest proposal
[WebKit-https.git] / LayoutTests / webrtc / connection-state.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         <script src ="routines.js"></script>
11         <script>
12 promise_test((test) => {
13     if (window.testRunner)
14         testRunner.setUserMediaPermission(true);
15
16     var firstConnection, secondConnection;
17     var localConnectionStates = ["new"];
18     var remoteConnectionStates = ["new"];
19     var localIceConnectionStates = ["new"];
20     var remoteIceConnectionStates = ["new"];
21     var localGatheringStates = ["new"];
22     var remoteGatheringStates = ["new"];
23     return navigator.mediaDevices.getUserMedia({ video: true}).then((stream) => {
24         return new Promise((resolve, reject) => {
25             createConnections((connection) => {
26                 firstConnection = connection;
27                 firstConnection.addTrack(stream.getVideoTracks()[0], stream);
28                 assert_equals(firstConnection.connectionState, "new");
29                 firstConnection.onconnectionstatechange = () => {
30                     localConnectionStates.push(firstConnection.connectionState);
31                 }
32                 firstConnection.onicegatheringstatechange = () => {
33                     localGatheringStates.push(firstConnection.iceGatheringState);
34                 }
35                 firstConnection.oniceconnectionstatechange = () => {
36                     localIceConnectionStates.push(firstConnection.iceConnectionState);
37                 }
38             }, (connection) => {
39                 secondConnection = connection;
40                 assert_equals(secondConnection.connectionState, "new");
41                 secondConnection.onconnectionstatechange = () => {
42                     remoteConnectionStates.push(secondConnection.connectionState);
43                 }
44                 secondConnection.onicegatheringstatechange = () => {
45                     remoteGatheringStates.push(secondConnection.iceGatheringState);
46                 }
47                 secondConnection.oniceconnectionstatechange = () => {
48                     remoteIceConnectionStates.push(secondConnection.iceConnectionState);
49                 }
50                 secondConnection.ontrack = (trackEvent) => {
51                     resolve(trackEvent.streams[0]);
52                 };
53             });
54             setTimeout(() => reject("Test timed out"), 5000);
55         });
56     }).then((stream) => {
57         return waitFor(500);
58     }).then(() => {
59         assert_array_equals(localConnectionStates, ["new", "connecting", "connected"]);
60         assert_array_equals(remoteConnectionStates, ["new", "connecting", "connected"]);
61         assert_array_equals(localGatheringStates, ["new", "gathering", "complete"]);
62         assert_array_equals(remoteGatheringStates, ["new", "gathering", "complete"]);
63         assert_array_equals(localIceConnectionStates, ["new", "checking", "connected", "completed"]);
64         assert_array_equals(remoteIceConnectionStates, ["new", "checking", "connected"]);
65     });
66 }, "Checking various connection state for video exchange");
67
68 promise_test((test) => {
69     return new Promise((resolve, reject) => {
70         var pc = new RTCPeerConnection();
71         pc.onconnectionstatechange = () => {
72             assert_unreached();
73         };
74         pc.close();
75         setTimeout(resolve, 200);
76     })
77 }, "Checking connection state event when closing peer connetion");
78         </script>
79     </body>
80 </html>