Add new access object callback
[framework/web/webkit-efl.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             testException("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 canplaythrough()
50 {
51     var movie = movieInfo.movies[movieInfo.current];
52
53     consoleWrite("* event handler NOT triggered by a user gesture");
54
55     if (movie.type == 'video') {
56         testExpected("mediaElement.webkitSupportsFullscreen", movie.supportsFS);
57         testExpected("mediaElement.webkitDisplayingFullscreen", false);
58     } else {
59         testExpected("mediaElement.webkitSupportsFullscreen", undefined);
60         testExpected("mediaElement.webkitDisplayingFullscreen", undefined);
61     }
62     
63     // Verify that we get an exception when trying to enter fullscreen since this isn't
64     // called in response to a user gesture.
65     if (movie.type == 'video')
66         testException("mediaElement.webkitEnterFullScreen()", "DOMException.INVALID_STATE_ERR");
67
68     // Click on the button
69     if (window.testRunner)
70         setTimeout(clickEnterFullscreenButton, 10);
71     else
72         openNextMovie();
73 }
74
75 function openNextMovie()
76 {
77     consoleWrite("");
78
79     movieInfo.current++;
80     if (movieInfo.current >= movieInfo.movies.length) {
81         endTest();
82         return;
83     }
84
85     var movie = movieInfo.movies[movieInfo.current];
86     var url = movie.url;
87     var container = document.getElementById('parent');
88
89     // Remove the current media element, if any
90     if (container.firstChild)
91         container.removeChild(container.firstChild);
92
93     var desc = "*** Creating &lt;" + movie.type  + "&gt; element with <em>\"" + url + "\"</em> "
94                 + (!movie.inline ? "not " : "") + "in the document, should " 
95                 + (!movie.supportsFS ? "<b>NOT</b> " : "") + "support fullscreen " + movie.description;
96     consoleWrite(desc);
97
98     // Create a new element, maybe insert it into the DOM
99     mediaElement = document.createElement(movie.type);
100     if (movie.inline)
101         mediaElement = container.appendChild(mediaElement);
102     addEventListeners();
103     mediaElement.setAttribute('controls', 'controls'); 
104     mediaElement.setAttribute('src', url); 
105
106     if (!movie.inline)
107         mediaElement.load();
108 }
109
110 function addEventListeners(elem)
111 {
112     waitForEvent("error");
113     waitForEvent("loadstart");
114     waitForEvent("waiting");
115     waitForEvent("ratechange");
116     waitForEvent("durationchange");
117     waitForEvent("pause");
118     waitForEvent("play");
119     waitForEvent("playing");
120
121     waitForEvent('canplaythrough', canplaythrough);
122
123     waitForEvent('webkitbeginfullscreen', beginfullscreen);
124     waitForEvent('webkitendfullscreen', endfullscreen);
125     waitForEvent('webkitfullscreenchange', fullscreenchange);
126 }
127