1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 package org.htmlunit.javascript.host.html;
16
17 import org.htmlunit.WebDriverTestCase;
18 import org.htmlunit.junit.BrowserRunner;
19 import org.htmlunit.junit.annotation.Alerts;
20 import org.htmlunit.junit.annotation.HtmlUnitNYI;
21 import org.junit.Test;
22 import org.junit.runner.RunWith;
23
24
25
26
27
28
29
30
31 @RunWith(BrowserRunner.class)
32 public class HTMLMediaElementTest extends WebDriverTestCase {
33
34
35
36
37 @Test
38 @Alerts("")
39 public void canPlayTypeBlank() throws Exception {
40 canPlayType("");
41 }
42
43
44
45
46 @Test
47 @Alerts("maybe")
48 public void canPlayTypeVideoOgg() throws Exception {
49 canPlayType("video/ogg");
50 }
51
52
53
54
55 @Test
56 @Alerts("maybe")
57 public void canPlayTypeVideoMp4() throws Exception {
58 canPlayType("video/mp4");
59 }
60
61
62
63
64 @Test
65 @Alerts("maybe")
66 public void canPlayTypeVideoWebm() throws Exception {
67 canPlayType("video/webm");
68 }
69
70
71
72
73 @Test
74 @Alerts(DEFAULT = "maybe",
75 CHROME = "probably",
76 EDGE = "probably")
77 @HtmlUnitNYI(CHROME = "maybe",
78 EDGE = "maybe")
79 public void canPlayTypeAudioMpeg() throws Exception {
80 canPlayType("audio/mpeg");
81 }
82
83
84
85
86 @Test
87 @Alerts("maybe")
88 public void canPlayTypeAudioMp4() throws Exception {
89 canPlayType("audio/mp4");
90 }
91
92
93
94
95 @Test
96 @Alerts("probably")
97 public void canPlayTypeVideoOggCodecs() throws Exception {
98 canPlayType("video/ogg; codecs=\"theora, vorbis\"");
99 }
100
101
102
103
104 @Test
105 @Alerts("probably")
106 public void canPlayTypeVideoMp4Codecs() throws Exception {
107 canPlayType("video/mp4; codecs=\"avc1.4D401E, mp4a.40.2\"");
108 }
109
110
111
112
113 @Test
114 @Alerts("probably")
115 public void canPlayTypeAudioWebmCodecs() throws Exception {
116 canPlayType("video/webm; codecs=\"vp8.0, vorbis\"");
117 }
118
119
120
121
122 @Test
123 @Alerts("probably")
124 public void canPlayTypeAudioOggCodecs() throws Exception {
125 canPlayType("audio/ogg; codecs=\"vorbis\"");
126 }
127
128
129
130
131 @Test
132 @Alerts("probably")
133 public void canPlayTypeAudioMp4Codecs() throws Exception {
134 canPlayType("audio/mp4; codecs=\"mp4a.40.5\"");
135 }
136
137 private void canPlayType(final String type) throws Exception {
138 final String html = DOCTYPE_HTML
139 + "<html>\n"
140 + "<head>\n"
141 + " <script>\n"
142 + LOG_TITLE_FUNCTION
143 + " </script>\n"
144 + "</head>\n"
145 + "<body>\n"
146 + "<script>\n"
147 + "try {\n"
148 + " var video = document.createElement('video');"
149 + " log(video.canPlayType('" + type + "'));\n"
150 + "} catch(e) { logEx(e); }\n"
151 + "</script>\n"
152 + "</body></html>";
153
154 loadPageVerifyTitle2(html);
155 }
156
157
158
159
160 @Test
161 @Alerts({"[object HTMLAudioElement]", "done"})
162 public void pause() throws Exception {
163 final String html = DOCTYPE_HTML
164 + "<html><head>\n"
165 + "<script>\n"
166 + LOG_TITLE_FUNCTION
167 + " function test() {\n"
168 + " var a = new Audio('1.mp3');\n"
169 + " log(a);\n"
170 + " a.pause();\n"
171 + " log('done');\n"
172 + " }\n"
173 + "</script>\n"
174 + "</head>\n"
175 + "<body onload='test()'>\n"
176 + "</body></html>";
177
178 loadPageVerifyTitle2(html);
179 }
180 }