4 <title>Media test: media selection
</title>
5 <script type=
"text/javascript" src=
"/MochiKit/MochiKit.js"></script>
6 <script type=
"text/javascript" src=
"/tests/SimpleTest/SimpleTest.js"></script>
7 <link rel=
"stylesheet" type=
"text/css" href=
"/tests/SimpleTest/test.css" />
11 <script class=
"testbody" type=
"text/javascript">
12 SimpleTest.waitForExplicitFinish();
14 function maketest(expect_load, attach_media, name, type, check_metadata) {
15 return function (testNum) {
16 var e = document.createElement('video');
19 // this could be loadedmetadata, but needs bug
466410 fixed
20 e.addEventListener('loadeddata', function () {
21 ok(e.readyState
>= HTMLMediaElement.HAVE_METADATA,
22 'test ' + testNum + ' networkState ' + e.networkState + ' expected
>= ' + e.LOADED_METADATA);
23 is(e.currentSrc.substring(e.currentSrc.length - name.length), name, 'test ' + testNum);
25 e.parentNode.removeChild(e);
30 attach_media(e, name, type);
33 ok(e.networkState
>= HTMLMediaElement.NETWORK_LOADING,
34 'test ' + testNum + ' networkState ' + e.networkState + ' expected
>= ' + e.LOADING);
36 ok(e.networkState == HTMLMediaElement.NETWORK_EMPTY,
37 'test ' + testNum + ' networkState ' + e.networkState + ' expected ' + e.EMPTY);
38 is(e.currentSrc, '', 'test ' + testNum);
39 e.parentNode.removeChild(e);
45 function set_src(element, name, type) {
47 document.body.appendChild(element);
50 function add_source(element, name, type) {
51 do_add_source(element, name, type);
52 document.body.appendChild(element);
55 function do_add_source(element, name, type) {
56 var source = document.createElement('source');
61 element.appendChild(source);
64 function add_sources_last(element, name, type) {
65 do_add_source(element, name, 'unsupported/type');
66 do_add_source(element, name, type);
67 document.body.appendChild(element);
70 function add_sources_first(element, name, type) {
71 do_add_source(element, name, type);
72 do_add_source(element, name, 'unsupported/type');
73 document.body.appendChild(element);
76 function late_add_sources_last(element, name, type) {
77 document.body.appendChild(element);
78 do_add_source(element, name, 'unsupported/type');
79 do_add_source(element, name, type);
82 function late_add_sources_first(element, name, type) {
83 document.body.appendChild(element);
84 do_add_source(element, name, type);
85 do_add_source(element, name, 'unsupported/type');
88 function check_ogg(e) {
89 ok(e.videoWidth ==
320 && e.videoHeight ==
240,
"video should be 320x240");
92 function check_wav(e) {
93 ok(e.duration
> 0.9 && e.duration <
1.1,
"duration should be around 1.0");
98 maketest(true, set_src, '
320x240.ogg', null, check_ogg),
99 maketest(true, add_source, '
320x240.ogg', null, check_ogg),
100 maketest(true, add_source, '
320x240.ogg', 'application/ogg', check_ogg),
101 maketest(true, add_sources_last, '
320x240.ogg', null, check_ogg),
102 maketest(true, add_sources_first, '
320x240.ogg', 'application/ogg', check_ogg),
103 maketest(true, set_src, 'r11025_u8_c1.wav', null, check_wav),
104 maketest(true, add_source, 'r11025_u8_c1.wav', null, check_wav),
105 maketest(true, add_source, 'r11025_u8_c1.wav', 'audio/x-wav', check_wav),
106 maketest(true, add_sources_last, 'r11025_u8_c1.wav', null, check_wav),
107 maketest(true, add_sources_first, 'r11025_u8_c1.wav', 'audio/x-wav', check_wav),
109 // type hint matches a decoder, actual type matches different decoder
110 maketest(true, add_source, '
320x240.ogg', 'audio/x-wav', check_ogg),
111 maketest(true, add_source, 'r11025_u8_c1.wav', 'application/ogg', check_wav),
113 // should not start loading, type excludes it from media candiate list
114 maketest(false, add_source, '
320x240.ogg', 'bogus/type', null),
115 maketest(false, add_source, 'r11025_u8_c1.wav', 'bogus/type', null),
116 maketest(false, add_source, 'unknown.raw', 'bogus/type', null),
118 // should start loading, then fire error, needs bug
462455 fixed
119 // maketest(true, add_source, 'unknown.raw', 'application/ogg', null),
120 // maketest(true, add_source, 'unknown.raw', 'audio/x-wav', null),
122 // element doesn't notice source children attached later, needs bug
462455 fixed
123 // maketest(true, late_add_sources_last, '
320x240.ogg', null,
0.2,
0.4),
124 // maketest(true, late_add_sources_first, '
320x240.ogg', 'application/ogg',
0.2,
0.4),
125 // maketest(true, late_add_sources_last, 'r11025_u8_c1.wav', null,
0.2,
0.4),
126 // maketest(true, late_add_sources_first, 'r11025_u8_c1.wav', 'audio/x-wav',
0.2,
0.4),
131 function runNextTest() {
132 setTimeout(function () {
133 dump('subtest ' + nextTest + '\n');
134 subTests[nextTest](nextTest);
139 addLoadEvent(runNextTest);