fune/toolkit/content/tests/browser/browser_autoplay_policy_play_twice.js
Dale Harvey c9e5e7c554 Bug 1470082 - Change autoplay checkbox to combobox. r=cpearce,flod,johannh
MozReview-Commit-ID: E71TxvgfJlJ

--HG--
extra : rebase_source : 30ca63df77e48a44de4d3e90182440c3937ed32f
2018-06-29 14:14:33 +01:00

47 lines
1.6 KiB
JavaScript

const VIDEO_PAGE = "https://example.com/browser/toolkit/content/tests/browser/file_video.html";
function setup_test_preference(enableUserGesture) {
let state = enableUserGesture ? "enable" : "disable";
info(`- set pref : ${state} user gesture -`);
return SpecialPowers.pushPrefEnv({"set": [
["media.autoplay.default", SpecialPowers.Ci.nsIAutoplay.BLOCKED],
["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");
tab.linkedBrowser.loadURI(VIDEO_PAGE);
await BrowserTestUtils.browserLoaded(tab.linkedBrowser);
info("- simulate user-click to start video -");
await BrowserTestUtils.synthesizeMouseAtCenter("#v", {button: 0},
tab.linkedBrowser);
async function play_video_again() {
let video = content.document.getElementById("v");
ok(!video.paused, "video is playing");
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");
}
}
await ContentTask.spawn(tab.linkedBrowser, null, play_video_again);
info("- remove tab -");
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();
});