Bug 1420488 - part2 : add test. r=jwwang

MozReview-Commit-ID: 1clhH9B2mIf

--HG--
extra : rebase_source : 03da182dfdcba08919a7b0f77adc697ded6b50a6
This commit is contained in:
Alastor Wu 2017-11-28 17:44:24 +08:00
Родитель 258e1d56df
Коммит 3a5eed9bdd
4 изменённых файлов: 62 добавлений и 0 удалений

Просмотреть файл

@ -19,6 +19,7 @@ support-files =
file_redirect_to.html
file_silentAudioTrack.html
file_webAudio.html
gizmo.mp4
head.js
image.jpg
image_page.html
@ -30,6 +31,7 @@ support-files =
tags = audiochannel
[browser_audioCompeting_onlyForActiveAgent.js]
tags = audiochannel
[browser_autoplay_policy_play_twice.js]
[browser_autoscroll_disabled.js]
[browser_block_autoplay_media.js]
tags = audiochannel

Просмотреть файл

@ -0,0 +1,48 @@
const FILE = "https://example.com/browser/toolkit/content/tests/browser/gizmo.mp4";
function setup_test_preference(enableUserGesture) {
let state = enableUserGesture ? "enable" : "disable";
info(`- set pref : ${state} user gesture -`);
return SpecialPowers.pushPrefEnv({"set": [
["media.autoplay.enabled", false],
["media.autoplay.enabled.user-gestures-needed", enableUserGesture]
]});
}
async function allow_play_for_played_video() {
info("- open new tab -");
let tab = await BrowserTestUtils.openNewForegroundTab(window.gBrowser,
"about:blank");
info("- create video -");
let document = tab.linkedBrowser.contentDocument;
let video = document.createElement("video");
video.src = FILE;
video.controls = true;
document.body.appendChild(video);
info("- simulate user-click to start video -");
let waitForPlayEvent = once(video, "play");
await BrowserTestUtils.synthesizeMouseAtCenter(video, {button: 0},
tab.linkedBrowser);
info("- video starts playing -");
await waitForPlayEvent;
info("- call video play() again -");
try {
await video.play();
ok(true, "success to resolve play promise");
} catch (e) {
ok(false, "promise should not be rejected");
}
info("- remove tab -");
await BrowserTestUtils.removeTab(tab);
}
add_task(async function start_test() {
await setup_test_preference(true);
await allow_play_for_played_video();
await setup_test_preference(false);
await allow_play_for_played_video();
});

Двоичные данные
toolkit/content/tests/browser/gizmo.mp4 Normal file

Двоичный файл не отображается.

Просмотреть файл

@ -212,3 +212,15 @@ class DateTimeTestHelper {
this.panel = null;
}
}
/**
* Used to listen events if you just need it once
*/
function once(target, name) {
var p = new Promise(function(resolve, reject) {
target.addEventListener(name, function() {
resolve();
}, {once: true});
});
return p;
}