[Modern Media Controls] Turn media/modern-media-controls/ios-inline-media-controls...
[WebKit-https.git] / LayoutTests / media / restricted-audio-playback-with-multiple-settimeouts.html
1 <!DOCTYPE html>
2 <html>
3 <head>
4     <title>restricted-audio-playback-with-document-gesture</title>
5     <script src=media-file.js></script>
6     <script src=video-test.js></script>
7
8     <script>
9     function runTest()
10     {
11         next();
12     }
13
14     function next() {
15         if (!tests.length) {
16             endTest()
17             return;
18         }
19
20         mediaElement = document.createElement('audio');
21         if (window.internals)
22             internals.setMediaElementRestrictions(mediaElement, "RequireUserGestureForAudioRateChange");
23
24         var nextTest = tests.shift();
25         consoleWrite('');
26         run("mediaElement.src = findMediaFile('audio', 'content/test')");
27         waitForEvent('canplaythrough', event => { runWithKeyDown(nextTest) });
28     }
29
30     var tests = [
31         function() {
32             consoleWrite('Test > 1s in single step');
33             consoleWrite('setTimeout 1, 1.1s');
34             setTimeout(() => {
35                 run("shouldReject(mediaElement.play()).then(next, next)");
36             }, 1100);
37         },
38
39
40         function() {
41             consoleWrite('Test > 1s in multiple steps');
42             consoleWrite('setTimeout 1, 0.6s');
43             setTimeout(() => {
44                 consoleWrite('setTimeout 1, 0.6s');
45                 setTimeout(() => {
46                     run("shouldReject(mediaElement.play()).then(next, next)");
47                 }, 600);
48             }, 600);
49         },
50
51         function() {
52             consoleWrite('Test < 1s total.')
53             consoleWrite('setTimeout 1, 0.1s');
54             setTimeout(() => {
55                 consoleWrite('setTimeout 2, 0.1s');
56                 setTimeout(() => {
57                     consoleWrite('setTimeout 3, 0.1s');
58                     setTimeout(() => {
59                         consoleWrite('setTimeout 4, 0.1s');
60                         setTimeout(() => {
61                             consoleWrite('setTimeout 5, 0.1s');
62                             setTimeout(() => {
63                                 run("shouldResolve(mediaElement.play()).then(next, next)");
64                             }, 100);
65                         }, 100);
66                     }, 100);
67                 }, 100);
68             }, 100);
69         },
70     ];
71     </script>
72 </head>
73
74 <body onload="runTest()">
75     <p>Test that, when RequireUserGestureForAudioRateChange is set along with MediaUserGestureInheritsForDocument, 
76     nested setTimeout() calls of less than 1s will not block play() from succeeding.</p>
77 </body>
78 </html>
79