|
1 <!DOCTYPE HTML> |
|
2 <html> |
|
3 <!-- |
|
4 https://bugzilla.mozilla.org/show_bug.cgi?id=462957 |
|
5 --> |
|
6 <head> |
|
7 <title>Test for Bug 462957</title> |
|
8 <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script> |
|
9 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/> |
|
10 <script type="text/javascript" src="manifest.js"></script> |
|
11 </head> |
|
12 <body> |
|
13 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=462957">Mozilla Bug 462957</a> |
|
14 |
|
15 <p id="display"></p> |
|
16 <div id="content" style="display: none"> |
|
17 |
|
18 </div> |
|
19 <pre id="test"> |
|
20 <script type="application/javascript"> |
|
21 |
|
22 // Test for Bug 462957; HTMLMediaElement.buffered. |
|
23 |
|
24 var manager = new MediaTestManager; |
|
25 |
|
26 function testBuffered(e) { |
|
27 var v = e.target; |
|
28 |
|
29 // The whole media should be buffered... |
|
30 var b = v.buffered; |
|
31 is(b.length, 1, v._name + ": Should be buffered in one range"); |
|
32 is(b.start(0), 0, v._name + ": First range start should be media start"); |
|
33 is(b.end(0), v.duration, v._name + ": First range end should be media end"); |
|
34 |
|
35 // Ensure INDEX_SIZE_ERR is thrown when we access outside the range |
|
36 var caught = false; |
|
37 try { |
|
38 b.start(-1); |
|
39 } catch (e) { |
|
40 caught = e.name == "IndexSizeError" && e.code == DOMException.INDEX_SIZE_ERR; |
|
41 } |
|
42 is(caught, true, v._name + ": Should throw INDEX_SIZE_ERR on under start bounds range"); |
|
43 |
|
44 caught = false; |
|
45 try { |
|
46 b.end(-1); |
|
47 } catch (e) { |
|
48 caught = e.name == "IndexSizeError" && e.code == DOMException.INDEX_SIZE_ERR; |
|
49 } |
|
50 is(caught, true, v._name + ": Should throw INDEX_SIZE_ERR on under end bounds range"); |
|
51 |
|
52 caught = false; |
|
53 try { |
|
54 b.start(b.length); |
|
55 } catch (e) { |
|
56 caught = e.name == "IndexSizeError" && e.code == DOMException.INDEX_SIZE_ERR; |
|
57 } |
|
58 is(caught, true, v._name + ": Should throw INDEX_SIZE_ERR on over start bounds range"); |
|
59 |
|
60 caught = false; |
|
61 try { |
|
62 b.end(b.length); |
|
63 } catch (e) { |
|
64 caught = e.name == "IndexSizeError" && e.code == DOMException.INDEX_SIZE_ERR; |
|
65 } |
|
66 is(caught, true, v._name + ": Should throw INDEX_SIZE_ERR on over end bounds range"); |
|
67 |
|
68 manager.finished(v._token); |
|
69 v.src = ""; |
|
70 v.parentNode.removeChild(v); |
|
71 } |
|
72 |
|
73 function fetch(url, fetched_callback) { |
|
74 var xhr = new XMLHttpRequest(); |
|
75 xhr.open("GET", url, true); |
|
76 xhr.responseType = "blob"; |
|
77 |
|
78 var loaded = function (event) { |
|
79 if (xhr.status == 200 || xhr.status == 206) { |
|
80 // Request fulfilled. Note sometimes we get 206... Presumably because either |
|
81 // httpd.js or Necko cached the result. |
|
82 fetched_callback(window.URL.createObjectURL(xhr.response)); |
|
83 } else { |
|
84 ok(false, "Fetch failed headers=" + xhr.getAllResponseHeaders()); |
|
85 } |
|
86 }; |
|
87 |
|
88 xhr.addEventListener("load", loaded, false); |
|
89 xhr.send(); |
|
90 } |
|
91 |
|
92 function startTest(test, token) { |
|
93 // Fetch the media resource using XHR so we can be sure the entire |
|
94 // resource is loaded before we test buffered ranges. This ensures |
|
95 // we have deterministic behaviour. |
|
96 var onfetched = function(uri) { |
|
97 var v = document.createElement('video'); |
|
98 v.preload = "metadata"; |
|
99 v._token = token; |
|
100 v.src = uri; |
|
101 v._name = test.name; |
|
102 v._test = test; |
|
103 v.addEventListener("loadedmetadata", testBuffered, false); |
|
104 document.body.appendChild(v); |
|
105 }; |
|
106 |
|
107 manager.started(token); |
|
108 fetch(test.name, onfetched); |
|
109 } |
|
110 |
|
111 // Note: No need to set media test prefs, since we're using XHR to fetch |
|
112 // media data. |
|
113 SimpleTest.waitForExplicitFinish(); |
|
114 manager.runTests(gSeekTests, startTest); |
|
115 |
|
116 </script> |
|
117 </pre> |
|
118 </body> |
|
119 </html> |