d6a5f4489a3a6e8fc75b13347aa1269d8967af3b
[WebKit-https.git] / LayoutTests / fast / mediastream / MediaStream-page-muted.html
1 <!DOCTYPE HTML>
2 <html>
3     <head>
4         <script src="../../resources/js-test-pre.js"></script>
5         <script>
6             let mediaStream;
7             let eventCount = 0;
8
9             function muteChanged(ev)
10             {
11                 event = ev;
12                 debug(`EVENT: ${ev.type}`);
13                 shouldBe('event.target.muted', (ev.type == "mute").toString());
14                 debug("");
15
16                 if (++eventCount == 2) {
17                     eventCount = 0;
18
19                     if (ev.type == "unmute") {
20                         finishJSTest();
21                         return;
22                     }
23
24                     if (window.internals) {
25                         debug("<br>*** Unmuting capture devices");
26                         internals.setPageMuted("");
27                     }
28                 }
29             }
30             
31             function testWhenEnabled()
32             {
33                 navigator.mediaDevices
34                     .getUserMedia({audio:{}, video:{}})
35                     .then(stream => {
36                         mediaStream = stream;
37                         shouldBeType("mediaStream", "Object");
38                         shouldBe("mediaStream.getTracks().length", "2");
39
40                         var tracks = mediaStream.getTracks();
41                         for (var i = 0; i < tracks.length; i++) {
42                             tracks[i].onmute = muteChanged;
43                             tracks[i].onunmute = muteChanged;
44                         }
45
46                         if (window.internals) {
47                             debug("<br>*** Muting capture devices");
48                             internals.setPageMuted("capturedevices");
49                         }
50                     })
51                     .catch((err) => {
52                         testFailed(`mediaDevices.getUserMedia() failed with ${err.name}`);
53                         finishJSTest();
54                     });
55             }
56
57             function start()
58             {
59                 debug(`<br>*** Mock capture devices should be enabled by default`);
60                 if (window.testRunner)
61                     testRunner.setUserMediaPermission(true);
62
63                 testWhenEnabled();
64             }
65
66         </script>
67     </head>
68
69     <body onload="start()">
70         <p id="description"></p>
71         <div id="console"></div>
72         <script>
73             description("Test enabling/disabling mock media capture devices");
74             window.jsTestIsAsync = true;
75
76             window.successfullyParsed = true;
77         </script>
78         <script src="../../resources/js-test-post.js"></script>
79     </body>
80 </html>