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