2010-08-05 00:40:35 -07:00
|
|
|
<!DOCTYPE HTML>
|
|
|
|
<html>
|
|
|
|
<!--
|
|
|
|
https://bugzilla.mozilla.org/show_bug.cgi?id=462957
|
|
|
|
-->
|
|
|
|
<head>
|
|
|
|
<title>Test for Bug 462957</title>
|
|
|
|
<script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
|
|
|
|
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
|
|
|
|
<script type="text/javascript" src="manifest.js"></script>
|
|
|
|
</head>
|
|
|
|
<body>
|
|
|
|
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=462957">Mozilla Bug 462957</a>
|
|
|
|
|
|
|
|
<p id="display"></p>
|
|
|
|
<div id="content" style="display: none">
|
|
|
|
|
|
|
|
</div>
|
|
|
|
<pre id="test">
|
|
|
|
<script type="application/javascript">
|
|
|
|
|
|
|
|
// Test for Bug 462957; HTMLMediaElement.buffered.
|
|
|
|
|
2010-08-26 19:11:46 -07:00
|
|
|
var manager = new MediaTestManager;
|
2010-08-05 00:40:35 -07:00
|
|
|
|
2014-02-25 16:36:54 -08:00
|
|
|
function testBuffered(e) {
|
2010-08-05 00:40:35 -07:00
|
|
|
var v = e.target;
|
|
|
|
|
|
|
|
// The whole media should be buffered...
|
|
|
|
var b = v.buffered;
|
|
|
|
is(b.length, 1, v._name + ": Should be buffered in one range");
|
|
|
|
is(b.start(0), 0, v._name + ": First range start should be media start");
|
2014-12-01 14:59:45 -08:00
|
|
|
ok(Math.abs(b.end(0) - v.duration) < 0.1, v._name + ": First range end should be media end");
|
2010-08-05 00:40:35 -07:00
|
|
|
|
|
|
|
// Ensure INDEX_SIZE_ERR is thrown when we access outside the range
|
|
|
|
var caught = false;
|
|
|
|
try {
|
|
|
|
b.start(-1);
|
|
|
|
} catch (e) {
|
2012-04-26 09:42:26 -07:00
|
|
|
caught = e.name == "IndexSizeError" && e.code == DOMException.INDEX_SIZE_ERR;
|
2010-08-05 00:40:35 -07:00
|
|
|
}
|
2011-07-11 20:39:37 -07:00
|
|
|
is(caught, true, v._name + ": Should throw INDEX_SIZE_ERR on under start bounds range");
|
2010-08-05 00:40:35 -07:00
|
|
|
|
|
|
|
caught = false;
|
|
|
|
try {
|
|
|
|
b.end(-1);
|
|
|
|
} catch (e) {
|
2012-04-26 09:42:26 -07:00
|
|
|
caught = e.name == "IndexSizeError" && e.code == DOMException.INDEX_SIZE_ERR;
|
2010-08-05 00:40:35 -07:00
|
|
|
}
|
2011-07-11 20:39:37 -07:00
|
|
|
is(caught, true, v._name + ": Should throw INDEX_SIZE_ERR on under end bounds range");
|
2010-08-05 00:40:35 -07:00
|
|
|
|
|
|
|
caught = false;
|
|
|
|
try {
|
|
|
|
b.start(b.length);
|
|
|
|
} catch (e) {
|
2012-04-26 09:42:26 -07:00
|
|
|
caught = e.name == "IndexSizeError" && e.code == DOMException.INDEX_SIZE_ERR;
|
2010-08-05 00:40:35 -07:00
|
|
|
}
|
2011-07-11 20:39:37 -07:00
|
|
|
is(caught, true, v._name + ": Should throw INDEX_SIZE_ERR on over start bounds range");
|
2010-08-05 00:40:35 -07:00
|
|
|
|
|
|
|
caught = false;
|
|
|
|
try {
|
|
|
|
b.end(b.length);
|
|
|
|
} catch (e) {
|
2012-04-26 09:42:26 -07:00
|
|
|
caught = e.name == "IndexSizeError" && e.code == DOMException.INDEX_SIZE_ERR;
|
2010-08-05 00:40:35 -07:00
|
|
|
}
|
2011-07-11 20:39:37 -07:00
|
|
|
is(caught, true, v._name + ": Should throw INDEX_SIZE_ERR on over end bounds range");
|
|
|
|
|
2014-09-14 14:34:00 -07:00
|
|
|
removeNodeAndSource(v);
|
|
|
|
manager.finished(v._token);
|
2014-02-25 16:36:54 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
function fetch(url, fetched_callback) {
|
|
|
|
var xhr = new XMLHttpRequest();
|
|
|
|
xhr.open("GET", url, true);
|
|
|
|
xhr.responseType = "blob";
|
|
|
|
|
|
|
|
var loaded = function (event) {
|
|
|
|
if (xhr.status == 200 || xhr.status == 206) {
|
|
|
|
// Request fulfilled. Note sometimes we get 206... Presumably because either
|
|
|
|
// httpd.js or Necko cached the result.
|
|
|
|
fetched_callback(window.URL.createObjectURL(xhr.response));
|
|
|
|
} else {
|
|
|
|
ok(false, "Fetch failed headers=" + xhr.getAllResponseHeaders());
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
xhr.addEventListener("load", loaded, false);
|
|
|
|
xhr.send();
|
2010-08-05 00:40:35 -07:00
|
|
|
}
|
|
|
|
|
2010-08-26 19:11:46 -07:00
|
|
|
function startTest(test, token) {
|
2014-02-25 16:36:54 -08:00
|
|
|
// Fetch the media resource using XHR so we can be sure the entire
|
|
|
|
// resource is loaded before we test buffered ranges. This ensures
|
|
|
|
// we have deterministic behaviour.
|
|
|
|
var onfetched = function(uri) {
|
|
|
|
var v = document.createElement('video');
|
|
|
|
v.preload = "metadata";
|
|
|
|
v._token = token;
|
|
|
|
v.src = uri;
|
|
|
|
v._name = test.name;
|
|
|
|
v._test = test;
|
|
|
|
v.addEventListener("loadedmetadata", testBuffered, false);
|
|
|
|
document.body.appendChild(v);
|
|
|
|
};
|
2010-08-26 19:11:46 -07:00
|
|
|
|
2014-02-25 16:36:54 -08:00
|
|
|
manager.started(token);
|
|
|
|
fetch(test.name, onfetched);
|
2010-08-05 00:40:35 -07:00
|
|
|
}
|
|
|
|
|
2014-02-25 16:36:54 -08:00
|
|
|
// Note: No need to set media test prefs, since we're using XHR to fetch
|
|
|
|
// media data.
|
2013-06-14 15:13:44 -07:00
|
|
|
SimpleTest.waitForExplicitFinish();
|
2014-02-25 16:36:54 -08:00
|
|
|
manager.runTests(gSeekTests, startTest);
|
|
|
|
|
2010-08-05 00:40:35 -07:00
|
|
|
</script>
|
|
|
|
</pre>
|
|
|
|
</body>
|
|
|
|
</html>
|