diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 01:47:29 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 01:47:29 +0000 |
commit | 0ebf5bdf043a27fd3dfb7f92e0cb63d88954c44d (patch) | |
tree | a31f07c9bcca9d56ce61e9a1ffd30ef350d513aa /dom/media/test/test_buffered.html | |
parent | Initial commit. (diff) | |
download | firefox-esr-upstream/115.8.0esr.tar.xz firefox-esr-upstream/115.8.0esr.zip |
Adding upstream version 115.8.0esr.upstream/115.8.0esr
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r-- | dom/media/test/test_buffered.html | 117 |
1 files changed, 117 insertions, 0 deletions
diff --git a/dom/media/test/test_buffered.html b/dom/media/test/test_buffered.html new file mode 100644 index 0000000000..86d8eec28a --- /dev/null +++ b/dom/media/test/test_buffered.html @@ -0,0 +1,117 @@ +<!DOCTYPE HTML> +<html> +<!-- +https://bugzilla.mozilla.org/show_bug.cgi?id=462957 +--> +<head> + <title>Test for Bug 462957</title> + <script 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. + +var manager = new MediaTestManager; + +function testBuffered(e) { + 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"); + ok(Math.abs(b.end(0) - v.duration) < 0.1, v._name + ": First range end should be media end"); + + // Ensure INDEX_SIZE_ERR is thrown when we access outside the range + var caught = false; + try { + b.start(-1); + } catch (ex) { + caught = ex.name == "IndexSizeError" && ex.code == DOMException.INDEX_SIZE_ERR; + } + is(caught, true, v._name + ": Should throw INDEX_SIZE_ERR on under start bounds range"); + + caught = false; + try { + b.end(-1); + } catch (ex) { + caught = ex.name == "IndexSizeError" && ex.code == DOMException.INDEX_SIZE_ERR; + } + is(caught, true, v._name + ": Should throw INDEX_SIZE_ERR on under end bounds range"); + + caught = false; + try { + b.start(b.length); + } catch (ex) { + caught = ex.name == "IndexSizeError" && ex.code == DOMException.INDEX_SIZE_ERR; + } + is(caught, true, v._name + ": Should throw INDEX_SIZE_ERR on over start bounds range"); + + caught = false; + try { + b.end(b.length); + } catch (ex) { + caught = ex.name == "IndexSizeError" && ex.code == DOMException.INDEX_SIZE_ERR; + } + is(caught, true, v._name + ": Should throw INDEX_SIZE_ERR on over end bounds range"); + + removeNodeAndSource(v); + manager.finished(v._token); +} + +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) { + ok(true, `${url}: Fetch succeeded, status=${xhr.status}`); + // 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, `${url}: Fetch failed, headers=${xhr.getAllResponseHeaders()}`); + } + }; + + xhr.addEventListener("load", loaded); + xhr.send(); +} + +function startTest(test, token) { + // 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._token = token; + v.src = uri; + v._name = test.name; + v._test = test; + v.addEventListener("loadeddata", testBuffered, {once: true}); + document.body.appendChild(v); + }; + + manager.started(token); + fetch(test.name, onfetched); +} + +// Note: No need to set media test prefs, since we're using XHR to fetch +// media data. +manager.runTests(gSeekTests, startTest); + +</script> +</pre> +</body> +</html> |