[Modern Media Controls] Turn media/modern-media-controls/ios-inline-media-controls...
[WebKit-https.git] / LayoutTests / media / video-play-audio-require-user-gesture.html
1 <!-- webkit-test-runner [ enableModernMediaControls=false ] -->
2 <html>
3     <head>
4         <title>Test that video play, pause and enterfullscreen does not work unless a user gesture is involved in playing a video</title>
5         <script src=media-controls.js></script>
6         <script src=media-file.js></script>
7         <script src=video-test.js></script>
8         <script>
9             var userGestureInitiated = 0;
10             if (window.internals) 
11                 window.internals.settings.setAudioPlaybackRequiresUserGesture(true);
12
13             function playing()
14             {
15                 if (userGestureInitiated == 0) {
16                     failTest("Should not play without user gesture.");
17                 } else {
18                     run("video.pause()");
19                 }
20             }
21
22             function pause()
23             {
24                 testExpected("video.paused", true);
25                 // Now video.webkitEnterFullScreen() should no longer throw any exception.
26                 // However, the video element may not always enter fullscreen. For example,
27                 // chromium uses fullscreen API which still requires user gesture
28                 try {
29                     run("video.webkitEnterFullScreen()");
30                 } catch(ex) {
31                     failTest("video.webkitEnterFullScreen() still requires user gesture.");
32                 }
33                 endTest();
34             }
35
36             function canplaythrough()
37             {
38                 consoleWrite("");
39                 consoleWrite("* No user gesture initiated");
40                 run("handlePromise(video.play())");
41                 testDOMException("video.webkitEnterFullScreen()", "DOMException.INVALID_STATE_ERR");
42                 testExpected("video.paused", true);
43                 consoleWrite("");
44
45                 consoleWrite("* User gesture initiated");
46                 userGestureInitiated = 1;
47                 try {
48                     clickPlayButton(video);
49                 } catch (exception) {
50                     failTest(exception.description);
51                     return;
52                 }
53             }
54
55             function start()
56             {
57                  findMediaElement();
58                  waitForEvent('canplaythrough', canplaythrough);
59                  waitForEvent('playing', playing);
60                  waitForEvent('pause', pause);
61                  video.src = findMediaFile("video", "content/test");
62             }
63         </script>
64     </head>
65
66     <body onload="start()">
67     <p>Test that video play(), pause() and webkitEnterFullScreen() should not work unless a user clicked on the play button.</p>
68     <video controls></video>
69     </body>
70 </html>