[iOS] don't get out of sync when interrupt/resume calls are not balanced
[WebKit-https.git] / LayoutTests / media / video-interruption-with-resume-allowing-play.html
1 <html>
2     <head>
3         <script src=media-file.js></script>
4         <script src=video-test.js></script>
5         <script>
6             var state = 0;
7             var resumeCount = 0;
8
9             function checkState()
10             {
11                 switch (state) {
12                 case "playing":
13                     testExpected("video.paused", false);
14                     state = "interrupted";
15                     run("internals.beginMediaSessionInterruption()");;
16                     setTimeout(checkState, 100);
17                     consoleWrite("");
18                     break;
19
20                 case "interrupted":
21                     consoleWrite("100ms timer fired...");
22                     testExpected("video.paused", true);
23                     state = "resuming";
24                     run("internals.endMediaSessionInterruption('MayResumePlaying')");
25                     consoleWrite("");
26                     break;
27
28                 case "resuming":
29                     testExpected("video.paused", false);
30                     consoleWrite("");
31                     if (++resumeCount == 2)
32                         endTest();
33                     state = "playing";
34                     setTimeout(checkState, 100);
35                     break;
36                 }
37             }
38
39             function canplaythrough()
40             {
41                 state = "playing";
42                 run("video.play()");
43                 consoleWrite("");
44             }
45
46             function start()
47             {
48                 if (!window.internals) {
49                     failTest('This test requires window.internals.');
50                     return;
51                 }
52
53                 findMediaElement();
54                 waitForEvent('canplaythrough', canplaythrough);
55                 waitForEvent('playing', checkState);
56                 video.src = findMediaFile("video", "content/test");
57             }
58         </script>
59     </head>
60
61     <body onload="start()">
62         <video controls ></video>
63         <p>Test that play() during interruption does nothing, ending interruption allows playback to resume.</p>
64     </body>
65 </html>