summaryrefslogtreecommitdiffstats
path: root/dom/media/mediasource/test/test_PlayEventsAutoPlaying.html
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 17:32:43 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 17:32:43 +0000
commit6bf0a5cb5034a7e684dcc3500e841785237ce2dd (patch)
treea68f146d7fa01f0134297619fbe7e33db084e0aa /dom/media/mediasource/test/test_PlayEventsAutoPlaying.html
parentInitial commit. (diff)
downloadthunderbird-upstream.tar.xz
thunderbird-upstream.zip
Adding upstream version 1:115.7.0.upstream/1%115.7.0upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'dom/media/mediasource/test/test_PlayEventsAutoPlaying.html')
-rw-r--r--dom/media/mediasource/test/test_PlayEventsAutoPlaying.html58
1 files changed, 58 insertions, 0 deletions
diff --git a/dom/media/mediasource/test/test_PlayEventsAutoPlaying.html b/dom/media/mediasource/test/test_PlayEventsAutoPlaying.html
new file mode 100644
index 0000000000..3e395c799d
--- /dev/null
+++ b/dom/media/mediasource/test/test_PlayEventsAutoPlaying.html
@@ -0,0 +1,58 @@
+<!DOCTYPE HTML>
+<html>
+<head>
+ <title>MSE: basic functionality</title>
+ <script src="/tests/SimpleTest/SimpleTest.js"></script>
+ <script type="text/javascript" src="mediasource.js"></script>
+ <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
+</head>
+<body>
+<pre id="test">
+<script class="testbody" type="text/javascript">
+
+SimpleTest.waitForExplicitFinish();
+
+// This test checks that readyState is properly set and the appropriate events are being fired accordingly:
+// 1. Ensure that play/playing aren't fired before any media data been added.
+// 2. Load 1.6s of data and ensure that canplay, play and playing events are fired.
+
+runWithMSE(async (ms, el) => {
+ el.controls = true;
+ el.autoplay = true;
+ const eventCounts = { play: 0, playing: 0 };
+ await once(ms, "sourceopen");
+ logEvents(el);
+ ok(true, "Receive a sourceopen event");
+
+ const forbiddenEvents = e => {
+ ok(el.readyState >= el.HAVE_FUTURE_DATA, "Must not have received event too early");
+ is(eventCounts[e.type], 0, "event should have only be fired once");
+ eventCounts[e.type]++;
+ };
+ el.addEventListener("play", forbiddenEvents);
+ el.addEventListener("playing", forbiddenEvents);
+
+ const videosb = ms.addSourceBuffer("video/mp4");
+ el.addEventListener("error", e => {
+ ok(false, `should not fire ${e.type} event`);
+ SimpleTest.finish();
+ });
+ is(el.readyState, el.HAVE_NOTHING, "readyState is HAVE_NOTHING");
+ let p = once(el, "loadedmetadata");
+ await fetchAndLoad(videosb, "bipbop/bipbop_video", ["init"], ".mp4");
+ await p;
+ ok(true, "got loadedmetadata event");
+ // We're only adding 1.6s worth of data, not enough for readyState to change to HAVE_ENOUGH_DATA
+ // So we end the media source so that all the playable data is available.
+ p = Promise.all(["loadeddata", "canplay", "play", "playing", "ended"].map(e => once(el, e)));
+ await fetchAndLoad(videosb, "bipbop/bipbop_video", range(1, 3), ".m4s");
+ ms.endOfStream();
+ await p;
+ ok(true, "got all required event");
+ SimpleTest.finish();
+});
+
+</script>
+</pre>
+</body>
+</html>