Bug 1349097. P1 - add a test case.
MozReview-Commit-ID: BDAlPb0z2AB
--- a/dom/media/test/mochitest.ini
+++ b/dom/media/test/mochitest.ini
@@ -1123,16 +1123,19 @@ tags = webvtt
skip-if = toolkit == 'android' # android(bug 1232305)
[test_can_play_type_wave.html]
skip-if = android_version == '15' || android_version == '17' # android(bug 1232305)
[test_fragment_noplay.html]
skip-if = android_version == '15' || android_version == '17' # android(bug 1232305)
[test_fragment_play.html]
skip-if = android_version == '15' || android_version == '17' # bug 1335520, bug 1209318, android(bug 1232305)
+[test_background_video_ended_event.html]
+skip-if = toolkit == 'android' # bug 1346705
+tags = suspend
[test_background_video_cancel_suspend_taint.html]
skip-if = toolkit == 'android' # bug 1346705
tags = suspend
[test_background_video_cancel_suspend_visible.html]
skip-if = toolkit == 'android' # bug 1346705
tags = suspend
[test_background_video_no_suspend_disabled.html]
skip-if = toolkit == 'android' # android(bug 1304480)
new file mode 100644
--- /dev/null
+++ b/dom/media/test/test_background_video_ended_event.html
@@ -0,0 +1,48 @@
+<!DOCTYPE html>
+<meta charset="utf-8">
+<title>The 'ended' event should be fired only once for a background video</title>
+<script src="/tests/SimpleTest/SimpleTest.js"></script>
+<script src="manifest.js"></script>
+<link rel="stylesheet" href="/tests/SimpleTest/test.css"/>
+<script type="text/javascript">
+"use strict";
+
+var prefs = [
+ [ "media.test.video-suspend", true ],
+ [ "media.suspend-bkgnd-video.enabled", true ],
+ [ "media.suspend-bkgnd-video.delay-ms", 1 ]
+];
+gTestPrefs = gTestPrefs.concat(prefs);
+
+var manager = new MediaTestManager;
+
+function startTest(test, token) {
+ manager.started(token);
+ let v = document.createElement('video');
+ v.token = token;
+ document.body.appendChild(v);
+ v.src = test.name;
+
+ once(v, "loadedmetadata", function() {
+ v.play();
+ v.setVisible(false);
+ });
+ once(v, "ended", function() {
+ v.setVisible(true);
+ });
+ once(v, "mozexitvideosuspend", function() {
+ info(`${token} video-decode is resumed.`);
+ // Wait for a while and finish the test. We should get only one 'ended' event.
+ setTimeout(function() {
+ manager.finished(token);
+ }, 3000);
+ });
+
+ let count = 0;
+ v.addEventListener("ended", function() {
+ is(++count, 1, `${token} got ${count} ended events.`);
+ });
+}
+
+manager.runTests(gDecodeSuspendTests, startTest);
+</script>