зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1345403 part 5 - Test video suspend canceling; r=jwwang
MozReview-Commit-ID: 99IDqpwuRIf --HG-- extra : rebase_source : 468cb4563d6ed1b5fdb976ecfb68cf9b14b90389 extra : intermediate-source : 67db97814e8acbc68e4dc708d175a3c1013c9257 extra : source : 5f834fb13ceea6b13136c1fbd60d266eee95f3ad
This commit is contained in:
Родитель
b49796fcdf
Коммит
7dff9a64fb
|
@ -34,10 +34,10 @@ function appendVideoToDoc(url, token, width, height) {
|
|||
|
||||
/**
|
||||
* @param {HTMLMediaElement} video Video element under test.
|
||||
* @returns {Promise} Promise that is resolved when video 'playing' event fires and rejected on error.
|
||||
* @returns {Promise} Promise that is resolved when video 'playing' event fires.
|
||||
*/
|
||||
function waitUntilPlaying(video) {
|
||||
var p = once(video, 'playing', () => { ok(true, video.token + " played."); });
|
||||
var p = once(video, 'playing', () => { ok(true, `${video.token} played.`); });
|
||||
Log(video.token, "Start playing");
|
||||
video.play();
|
||||
return p;
|
||||
|
@ -54,7 +54,21 @@ function waitUntilEnded(video) {
|
|||
return Promise.resolve();
|
||||
}
|
||||
|
||||
return once(video, 'ended', () => { ok(true, video.token + " ended"); });
|
||||
return once(video, 'ended', () => { ok(true, `${video.token} ended`); });
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {HTMLMediaElement} video Video element under test.
|
||||
* @returns {Promise} Promise that is resolved when video decode starts
|
||||
* suspend timer.
|
||||
*/
|
||||
function testSuspendTimerStartedWhenHidden(video) {
|
||||
var p = once(video, 'mozstartvideosuspendtimer').then(() => {
|
||||
ok(true, `${video.token} suspend begins`)
|
||||
});
|
||||
Log(video.token, 'Set Hidden');
|
||||
video.setVisible(false);
|
||||
return p;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -63,7 +77,7 @@ function waitUntilEnded(video) {
|
|||
*/
|
||||
function testVideoSuspendsWhenHidden(video) {
|
||||
let p = once(video, 'mozentervideosuspend').then(() => {
|
||||
ok(true, video.token + " suspends");
|
||||
ok(true, `${video.token} suspends`);
|
||||
});
|
||||
Log(video.token, "Set hidden");
|
||||
video.setVisible(false);
|
||||
|
@ -76,7 +90,7 @@ function testVideoSuspendsWhenHidden(video) {
|
|||
*/
|
||||
function testVideoResumesWhenShown(video) {
|
||||
var p = once(video, 'mozexitvideosuspend').then(() => {
|
||||
ok(true, video.token + " resumes");
|
||||
ok(true, `${video.token} resumes`);
|
||||
});
|
||||
Log(video.token, "Set visible");
|
||||
video.setVisible(true);
|
||||
|
@ -89,8 +103,8 @@ function testVideoResumesWhenShown(video) {
|
|||
*/
|
||||
function checkVideoDoesntSuspend(video) {
|
||||
let p = Promise.race([
|
||||
waitUntilEnded(video).then(() => { ok(true, video.token + ' ended before decode was suspended')}),
|
||||
once(video, 'mozentervideosuspend', () => { Promise.reject(new Error(video.token + ' suspended')) })
|
||||
waitUntilEnded(video).then(() => { ok(true, `${video.token} ended before decode was suspended`)}),
|
||||
once(video, 'mozentervideosuspend', () => { Promise.reject(new Error(`${video.token} suspended`)) })
|
||||
]);
|
||||
Log(video.token, "Set hidden.");
|
||||
video.setVisible(false);
|
||||
|
@ -103,7 +117,7 @@ function checkVideoDoesntSuspend(video) {
|
|||
* @returns {Promise} Promise that is resolved once currentTime passes time.
|
||||
*/
|
||||
function waitTil(video, time) {
|
||||
Log(video.token, "Waiting for time to reach " + time + "s");
|
||||
Log(video.token, `Waiting for time to reach ${time}s`);
|
||||
return new Promise(resolve => {
|
||||
video.addEventListener('timeupdate', function timeUpdateEvent() {
|
||||
if (video.currentTime > time) {
|
||||
|
|
|
@ -1128,6 +1128,12 @@ skip-if = android_version == '15' || android_version == '17' # android(bug 12323
|
|||
[test_fragment_play.html]
|
||||
skip-if = android_version == '15' || android_version == '17' # bug 1335520, bug 1209318, android(bug 1232305)
|
||||
|
||||
[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)
|
||||
tags = suspend
|
||||
|
|
|
@ -0,0 +1,69 @@
|
|||
<!DOCTYPE html>
|
||||
<meta charset="utf-8">
|
||||
<title>Test Background Video Suspend Cancels (Element Taint)</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;
|
||||
|
||||
/**
|
||||
* @param {HTMLMediaElement} video Video element under test.
|
||||
* @returns {Promise} Promise that is resolved when video decode resumes.
|
||||
*/
|
||||
function testSuspendTimerCanceledWhenTainted(video) {
|
||||
function ended() {
|
||||
video.removeEventListener("mozcancelvideosuspendtimer", canceled);
|
||||
ok(false, `${video.token} ended before suspend cancels`);
|
||||
this.ended_resolve();
|
||||
}
|
||||
|
||||
function canceled() {
|
||||
video.removeEventListener("ended", ended);
|
||||
ok(true, `${video.token} suspend cancels`);
|
||||
this.canceled_resolve();
|
||||
}
|
||||
|
||||
let p = Promise.race([
|
||||
new Promise((resolve) => {
|
||||
video.ended_resolve = resolve;
|
||||
video.addEventListener('ended', ended, { 'once': true });
|
||||
}),
|
||||
new Promise((resolve) => {
|
||||
video.canceled_resolve = resolve;
|
||||
video.addEventListener('mozcancelvideosuspendtimer', canceled, { 'once': true });
|
||||
})
|
||||
]);
|
||||
|
||||
Log(video.token, "Mark tainted");
|
||||
|
||||
let c = document.createElement('canvas');
|
||||
let g = c.getContext('2d');
|
||||
g.drawImage(video, 0, 0, c.width, c.height);
|
||||
ok(video.hasSuspendTaint(), 'video used with drawImage is tainted.');
|
||||
|
||||
return p;
|
||||
}
|
||||
|
||||
startTest({
|
||||
desc: 'Test Background Video Suspend Cancels (Element Taint)',
|
||||
prefs: [
|
||||
[ "media.test.video-suspend", true ],
|
||||
[ "media.suspend-bkgnd-video.enabled", true ],
|
||||
[ "media.suspend-bkgnd-video.delay-ms", 10000 ]
|
||||
],
|
||||
tests: gDecodeSuspendTests,
|
||||
runTest: (test, token) => {
|
||||
let v = appendVideoToDoc(test.name, token);
|
||||
manager.started(token);
|
||||
|
||||
waitUntilPlaying(v)
|
||||
.then(() => testSuspendTimerStartedWhenHidden(v))
|
||||
.then(() => testSuspendTimerCanceledWhenTainted(v))
|
||||
.then(() => { manager.finished(token); });
|
||||
}
|
||||
});
|
||||
</script>
|
|
@ -0,0 +1,69 @@
|
|||
<!DOCTYPE html>
|
||||
<meta charset="utf-8">
|
||||
<title>Test Background Video Suspend Cancels (Visibility)</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;
|
||||
|
||||
/**
|
||||
* Check that making the element visible before suspend timer delay causes the
|
||||
* the suspend timer to be canceled.
|
||||
* @param {HTMLMediaElement} video Video element under test.
|
||||
* @returns {Promise} Promise that is resolved when video decode resumes.
|
||||
*/
|
||||
function testSuspendTimerCanceledWhenShown(video) {
|
||||
function ended() {
|
||||
video.removeEventListener("mozcancelvideosuspendtimer", canceled);
|
||||
ok(false, `${video.token} ended before suspend cancels`);
|
||||
this.ended_resolve();
|
||||
}
|
||||
|
||||
function canceled() {
|
||||
video.removeEventListener("ended", ended);
|
||||
ok(true, `${video.token} suspend cancels`);
|
||||
this.canceled_resolve();
|
||||
}
|
||||
|
||||
let p = Promise.race([
|
||||
new Promise((resolve) => {
|
||||
video.ended_resolve = resolve;
|
||||
video.addEventListener('ended', ended, { 'once': true });
|
||||
}),
|
||||
new Promise((resolve) => {
|
||||
video.canceled_resolve = resolve;
|
||||
video.addEventListener('mozcancelvideosuspendtimer', canceled, { 'once': true });
|
||||
})
|
||||
]);
|
||||
|
||||
Log(video.token, "Set visible");
|
||||
video.setVisible(true);
|
||||
|
||||
return p;
|
||||
}
|
||||
|
||||
startTest({
|
||||
desc: 'Test Background Video Suspend Cancels (Visibility)',
|
||||
prefs: [
|
||||
[ "media.test.video-suspend", true ],
|
||||
[ "media.suspend-bkgnd-video.enabled", true ],
|
||||
[ "media.suspend-bkgnd-video.delay-ms", 10000 ]
|
||||
],
|
||||
tests: gDecodeSuspendTests,
|
||||
runTest: (test, token) => {
|
||||
let v = appendVideoToDoc(test.name, token);
|
||||
manager.started(token);
|
||||
|
||||
waitUntilPlaying(v)
|
||||
.then(() => testSuspendTimerStartedWhenHidden(v))
|
||||
.then(() => testSuspendTimerCanceledWhenShown(v))
|
||||
.then(() => {
|
||||
ok(true, `${v.token} finished`);
|
||||
manager.finished(token);
|
||||
});
|
||||
}
|
||||
});
|
Загрузка…
Ссылка в новой задаче