Make captureCanvas-webrtc.html more robust
[WebKit-https.git] / LayoutTests / webrtc / audio-muted-stats2.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 checkOutboundBytesSentNotIncreasing(firstConnection, statsFirstConnection, count)
26 {
27     return getOutboundRTPStats(firstConnection).then((stats) => {
28        if (stats.bytesSent > statsFirstConnection.bytesSent)
29             return Promise.reject("outbound stats bytes sent increasing");
30         if (++count === 10)
31             return;
32         return waitFor(50).then(() => {
33             return checkOutboundBytesSentNotIncreasing(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         track.enabled = false;
46         return new Promise((resolve, reject) => {
47             createConnections((connection) => {
48                 firstConnection = connection;
49                 firstConnection.addTrack(track, stream);
50             }, (connection) => {
51                 connection.ontrack = resolve;
52             });
53             setTimeout(() => reject("Test timed out"), 5000);
54         });
55     }).then(() => {
56         return getOutboundRTPStats(firstConnection);
57     }).then((stats) => {
58         statsFirstConnection = stats;
59         return checkOutboundBytesSentNotIncreasing(firstConnection, statsFirstConnection, 0);
60     });
61 }, "Audio silent data not being sent in case track is muted from the start");
62         </script>
63     </body>
64 </html>