Bug 1349097 P4 - add a mochitest; r?jwwang draft
authorKaku Kuo <kaku@mozilla.com>
Fri, 24 Mar 2017 17:09:41 +0800
changeset 556588 6484119d76296b8b71e387e135483e00f768ff07
parent 556587 f47c3e7f8ffd8057e180724093e2a8404c953cb9
child 556630 e49a3f098336a19c344f89e4c54be04df0a50dca
push id52588
push userbmo:kaku@mozilla.com
push dateThu, 06 Apr 2017 03:24:43 +0000
reviewersjwwang
bugs1349097
milestone55.0a1
Bug 1349097 P4 - add a mochitest; r?jwwang MozReview-Commit-ID: A71wl09i0eq
dom/media/test/mochitest.ini
dom/media/test/test_background_video_ended_event.html
--- a/dom/media/test/mochitest.ini
+++ b/dom/media/test/mochitest.ini
@@ -1156,11 +1156,14 @@ tags = suspend
 skip-if = toolkit == 'android' # bug 1346705
 tags = suspend
 [test_background_video_tainted_by_drawimage.html]
 skip-if = toolkit == 'android' # bug 1346705
 tags = suspend
 [test_background_video_drawimage_with_suspended_video.html]
 skip-if = toolkit == 'android' # bug 1346705
 tags = suspend
+[test_background_video_ended_event.html]
+skip-if = toolkit == 'android' # bug 1346705
+tags = suspend
 
 [test_temporary_file_blob_video_plays.html]
 skip-if = toolkit == 'android' # android(bug 1232305)
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>Test Background Video Suspends</title>
+<script src="/tests/SimpleTest/SimpleTest.js"></script>
+<script src="manifest.js"></script>
+<script src="background_video.js"></script>
+<link rel="stylesheet" href="/tests/SimpleTest/test.css"/>
+<script type="text/javascript">
+"use strict";
+
+var manager = new MediaTestManager;
+
+startTest({
+  desc: "Test background video doesn't fire the 'ended' event twice.",
+  prefs: [
+    [ "media.test.video-suspend", true ],
+    [ "media.suspend-bkgnd-video.enabled", true ],
+    [ "media.suspend-bkgnd-video.delay-ms", 100 ]
+  ],
+  tests: gDecodeSuspendTests,
+  runTest: (test, token) => {
+    let v = appendVideoToDoc(test.name, token);
+    manager.started(token);
+
+    let count = 0;
+    v.addEventListener("ended", function() {
+      is(++count, 1, `${token} should get only one 'ended' event.`);
+    });
+
+    /*
+     * This test checks that, after a video element had finished its playback,
+     * resuming video decoder doesn't dispatch 2nd ended event.
+     * This issue was found in bug 1349097.
+     */
+    waitUntilPlaying(v)
+      .then(() => testVideoSuspendsWhenHidden(v))
+      .then(() => waitUntilEnded(v))
+      .then(() => testVideoResumesWhenShown(v))
+      .then(() => {
+        // Wait for a while and finish the test. We should get only one 'ended' event.
+        setTimeout(function() {
+          removeNodeAndSource(v);
+          manager.finished(token);
+        }, 3000);
+      });
+  }
+});
+</script>