We should pause silent WebAudio rendering in background tabs
[WebKit-https.git] / LayoutTests / webaudio / silent-audio-interrupted-in-background.html
1 <!DOCTYPE html>
2 <html>
3 <body>
4 <script src="../resources/js-test-pre.js"></script>
5 <script>
6 description("Tests that silent WebAudio rendering gets interrupted in hidden pages.");
7 jsTestIsAsync = true;
8
9 document.onvisibilitychange = function() {
10     if (document.hidden) {
11         shouldBecomeEqual("context.state", "'interrupted'", showPage);
12     } else {
13         shouldBecomeEqual("context.state", "'running'", finishJSTest);
14     }
15 }
16
17 function showPage()
18 {
19     debug("* Setting page visibility to visible");
20     if (window.testRunner)
21         testRunner.setPageVisibility("visible");
22 }
23
24 function hidePage()
25 {
26     debug("* Setting page visibility to hidden");
27     if (window.testRunner)
28         testRunner.setPageVisibility("hidden");
29 }
30
31 onload = function() {
32     context = new (window.AudioContext || window.webkitAudioContext)();
33
34     audioElement = document.createElement("audio");
35     audioElement.loop = true;
36     audioElement.muted = true;
37     audioElement.src = "../media/content/test.wav";
38     source = context.createMediaElementSource(audioElement);
39
40     var gainNode = context.createGain();
41     source.connect(gainNode);
42     gainNode.connect(context.destination);
43     gainNode.gain.value = 0; // Mute.
44
45     shouldBecomeEqual("context.state", "'running'", hidePage);
46 }
47 </script>
48 <script src="../resources/js-test-post.js"></script>
49 </body>
50 </html>