[Modern Media Controls] Turn media/modern-media-controls/ios-inline-media-controls...
[WebKit-https.git] / LayoutTests / media / media-fullscreen.js
1
2 function buttonClickHandler()
3 {
4     var movie = movieInfo.movies[movieInfo.current];
5
6     consoleWrite("EVENT(mouseup)");
7     
8     consoleWrite("* event handler triggered by user gesture");
9
10     // Try to enter fullscreen in response to a mouse click
11
12     if (movie.supportsFS)
13         run("mediaElement.webkitEnterFullScreen()");
14     else {
15         if (movie.type == 'video')
16             testDOMException("mediaElement.webkitEnterFullScreen()", "DOMException.INVALID_STATE_ERR");
17         openNextMovie();
18     }
19 }
20
21 function clickEnterFullscreenButton()
22 {
23     consoleWrite("* clicking on button");
24     var button = document.getElementById('button');
25     eventSender.mouseMoveTo(button.offsetLeft + 20, button.offsetTop + 7);
26     eventSender.mouseDown();
27     eventSender.mouseUp();
28 }
29
30 function fullscreenchange()
31 {
32     if (document.webkitIsFullScreen)
33         beginfullscreen();
34     else
35         endfullscreen();
36 }
37
38 function beginfullscreen()
39 {
40     testExpected("mediaElement.webkitDisplayingFullscreen", true);
41     run("mediaElement.webkitExitFullScreen()");
42 }
43
44 function endfullscreen()
45 {
46     setTimeout(openNextMovie, 10);
47 }
48
49 function fullscreenerror()
50 {
51     var movie = movieInfo.movies[movieInfo.current];
52     if (movie.inline) {
53         failTest("Unexpected fullscreenerror event");
54     } else {
55         testExpected("mediaElement.webkitDisplayingFullscreen", false);
56         openNextMovie();
57     }
58 }
59
60 function canplaythrough()
61 {
62     var movie = movieInfo.movies[movieInfo.current];
63
64     consoleWrite("* event handler NOT triggered by a user gesture");
65
66     if (movie.type == 'video') {
67         testExpected("mediaElement.webkitSupportsFullscreen", movie.supportsFS);
68         if (mediaElement.webkitSupportsPresentationMode)
69             testExpected("mediaElement.webkitSupportsPresentationMode('fullscreen')", movie.supportsFS);
70         testExpected("mediaElement.webkitDisplayingFullscreen", false);
71     } else {
72         testExpected("mediaElement.webkitSupportsFullscreen", undefined);
73         testExpected("mediaElement.webkitSupportsPresentationMode", undefined);
74         testExpected("mediaElement.webkitDisplayingFullscreen", undefined);
75     }
76     
77     // Verify that we get an exception when trying to enter fullscreen since this isn't
78     // called in response to a user gesture.
79     if (movie.type == 'video')
80         testDOMException("mediaElement.webkitEnterFullScreen()", "DOMException.INVALID_STATE_ERR");
81
82     // Click on the button
83     if (window.testRunner)
84         setTimeout(clickEnterFullscreenButton, 10);
85     else
86         openNextMovie();
87 }
88
89 function openNextMovie()
90 {
91     consoleWrite("");
92
93     movieInfo.current++;
94     if (movieInfo.current >= movieInfo.movies.length) {
95         endTest();
96         return;
97     }
98
99     var movie = movieInfo.movies[movieInfo.current];
100     var url = movie.url;
101     var container = document.getElementById('parent');
102
103     // Remove the current media element, if any
104     if (container.firstChild)
105         container.removeChild(container.firstChild);
106
107     var desc = "*** Creating &lt;" + movie.type  + "&gt; element with <em>\"" + url + "\"</em> "
108                 + (!movie.inline ? "not " : "") + "in the document, should " 
109                 + (!movie.supportsFS ? "<b>NOT</b> " : "") + "support fullscreen " + movie.description;
110     consoleWrite(desc);
111
112     // Create a new element, maybe insert it into the DOM
113     mediaElement = document.createElement(movie.type);
114     if (movie.inline)
115         mediaElement = container.appendChild(mediaElement);
116     addEventListeners();
117     mediaElement.setAttribute('controls', 'controls'); 
118     mediaElement.setAttribute('src', url); 
119
120     if (!movie.inline)
121         mediaElement.load();
122 }
123
124 function addEventListeners(elem)
125 {
126     waitForEvent("error");
127     waitForEvent("loadstart");
128     waitForEvent("waiting");
129     waitForEvent("ratechange");
130     waitForEvent("durationchange");
131     waitForEvent("pause");
132     waitForEvent("play");
133     waitForEvent("playing");
134
135     waitForEvent('canplaythrough', canplaythrough);
136
137     waitForEvent('webkitbeginfullscreen', beginfullscreen);
138     waitForEvent('webkitendfullscreen', endfullscreen);
139     waitForEvent('webkitfullscreenchange', fullscreenchange);
140     waitForEvent('webkitfullscreenerror', fullscreenerror);
141 }
142