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