Backed out changeset ddccd40117a0 (bug 1853271) for causing bug 1854769. CLOSED TREE
[gecko.git] / dom / media / test / test_background_video_cancel_suspend_visible.html
blob73aaa4783e185d0fd2ac951976b64db0a65a6953
1 <!DOCTYPE html>
2 <meta charset="utf-8">
3 <title>Test Background Video Suspend Cancels (Visibility)</title>
4 <script src="/tests/SimpleTest/SimpleTest.js"></script>
5 <script src="manifest.js"></script>
6 <script src="background_video.js"></script>
7 <link rel="stylesheet" href="/tests/SimpleTest/test.css"/>
8 <script type="text/javascript">
9 "use strict";
11 var manager = new MediaTestManager;
13 /**
14 * Check that making the element visible before suspend timer delay causes the
15 * the suspend timer to be canceled.
16 * @param {HTMLMediaElement} video Video element under test.
17 * @returns {Promise} Promise that is resolved when video decode resumes.
19 function testSuspendTimerCanceledWhenShown(video) {
20 function ended() {
21 video.removeEventListener("mozcancelvideosuspendtimer", canceled);
22 ok(false, `${video.token} ended before suspend cancels`);
23 this.ended_resolve();
26 function canceled() {
27 video.removeEventListener("ended", ended);
28 ok(true, `${video.token} suspend cancels`);
29 this.canceled_resolve();
32 let p = Promise.race([
33 new Promise((resolve) => {
34 video.ended_resolve = resolve;
35 video.addEventListener('ended', ended, { 'once': true });
36 }),
37 new Promise((resolve) => {
38 video.canceled_resolve = resolve;
39 video.addEventListener('mozcancelvideosuspendtimer', canceled, { 'once': true });
41 ]);
43 Log(video.token, "Set visible");
44 video.setVisible(true);
46 return p;
49 startTest({
50 desc: 'Test Background Video Suspend Cancels (Visibility)',
51 prefs: [
52 [ "media.test.video-suspend", true ],
53 [ "media.suspend-background-video.enabled", true ],
54 [ "media.suspend-background-video.delay-ms", 10000 ]
56 tests: gDecodeSuspendTests,
57 runTest: (test, token) => {
58 let v = appendVideoToDoc(test.name, token);
59 manager.started(token);
61 waitUntilPlaying(v)
62 .then(() => testSuspendTimerStartedWhenHidden(v))
63 .then(() => testSuspendTimerCanceledWhenShown(v))
64 .then(() => {
65 ok(true, `${v.token} finished`);
66 manager.finished(token);
67 });
69 });