Make mDNS ICE Candidate an experimental flag again
[WebKit-https.git] / LayoutTests / webrtc / audio-muted-stats.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 function getOutboundRTPStats(connection)
13 {
14     return connection.getStats().then((report) => {
15         var stats;
16         report.forEach((statItem) => {
17             if (statItem.type === "outbound-rtp") {
18                 stats = statItem;
19             }
20         });
21         return stats;
22     });
23 }
24
25 function checkOutboundBytesSentIncreased(firstConnection, statsFirstConnection, count)
26 {
27     return getOutboundRTPStats(firstConnection).then((stats) => {
28        if (stats.bytesSent > statsFirstConnection.bytesSent)
29             return;
30         if (++count === 50)
31             return Promise.reject("checking outbound stats bytes sent increasing timed out");
32         return waitFor(50).then(() => {
33             return checkOutboundBytesSentIncreased(firstConnection, statsFirstConnection, count)
34         });
35     });
36 }
37
38 var track, firstConnection;
39 promise_test((test) => {
40     if (window.testRunner)
41         testRunner.setUserMediaPermission(true);
42
43     return navigator.mediaDevices.getUserMedia({ audio: true}).then((stream) => {
44         track = stream.getAudioTracks()[0];
45         return new Promise((resolve, reject) => {
46             createConnections((connection) => {
47                 firstConnection = connection;
48                 firstConnection.addTrack(track, stream);
49             }, (connection) => {
50                 connection.ontrack = resolve;
51             });
52             setTimeout(() => reject("Test timed out"), 5000);
53         });
54     }).then(() => {
55         return getOutboundRTPStats(firstConnection);
56     }).then((stats) => {
57         statsFirstConnection = stats;
58         return checkOutboundBytesSentIncreased(firstConnection, statsFirstConnection, 0);
59     }).then(() => {
60         track.enabled = false;
61         // Let's wait a little bit so that audio is disabled.
62         return waitFor(100);
63     }).then((stats) => {
64         return getOutboundRTPStats(firstConnection);
65     }).then((stats) => {
66         statsFirstConnection = stats;
67         return checkOutboundBytesSentIncreased(firstConnection, statsFirstConnection, 0);
68     });
69 }, "Audio silent data being sent in case track is muted");
70         </script>
71     </body>
72 </html>