Bug 1493766 - part3 : modify test. r=smaug

Differential Revision: https://phabricator.services.mozilla.com/D7017

--HG--
extra : moz-landing-system : lando
This commit is contained in:
alwu 2018-11-14 01:32:26 +00:00
Родитель dab4434860
Коммит c084141553
3 изменённых файлов: 86 добавлений и 0 удалений

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

@ -4388,6 +4388,22 @@ nsDOMWindowUtils::NotifyTemporaryAutoplayPermissionChanged(int32_t aState,
return NS_OK;
}
NS_IMETHODIMP
nsDOMWindowUtils::IsAutoplayTemporarilyAllowed(bool* aResult)
{
*aResult = false;
nsCOMPtr<nsPIDOMWindowOuter> window = do_QueryReferent(mWindow);
NS_ENSURE_STATE(window);
nsCOMPtr<nsPIDOMWindowOuter> topWindow = window->GetScriptableTop();
if (!topWindow) {
return NS_OK;
}
*aResult = topWindow->HasTemporaryAutoplayPermission();
return NS_OK;
}
NS_INTERFACE_MAP_BEGIN(nsTranslationNodeList)
NS_INTERFACE_MAP_ENTRY(nsISupports)
NS_INTERFACE_MAP_ENTRY(nsITranslationNodeList)

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

@ -1960,6 +1960,12 @@ interface nsIDOMWindowUtils : nsISupports {
void notifyTemporaryAutoplayPermissionChanged(in long aState,
in AString aPrePath);
/**
* Used to check whether the window temporarily allows autoplay for current
* domain.
*/
bool isAutoplayTemporarilyAllowed();
// These consts are only for testing purposes.
const long DEFAULT_MOUSE_POINTER_ID = 0;
const long DEFAULT_PEN_POINTER_ID = 1;

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

@ -92,6 +92,7 @@ async function testAutoplayUnknownPermission(args) {
ok(promptShowing(), "Should now be showing permission prompt");
// Click the appropriate doorhanger button.
PopupNotifications.panel.firstElementChild.checkbox.checked = args.checkbox;
if (args.button == "allow") {
info("Clicking allow button");
PopupNotifications.panel.firstElementChild.button.click();
@ -104,6 +105,37 @@ async function testAutoplayUnknownPermission(args) {
// Check that the video started playing.
await checkVideoDidPlay(browser, args);
const isTemporaryPermission = !args.checkbox;
if (isTemporaryPermission) {
info("- check temporary permission -");
const isAllowed = (args.button === "allow");
let permission = SitePermissions.get(browser.currentURI, "autoplay-media", browser);
is(permission.state == SitePermissions.ALLOW, isAllowed,
"should get autoplay permission.");
ok(permission.scope == SitePermissions.SCOPE_TEMPORARY,
"the permission is temporary permission.");
await ContentTask.spawn(browser, isAllowed,
isAllowed => {
is(content.windowUtils.isAutoplayTemporarilyAllowed(), isAllowed,
"window should have" + (isAllowed ? " " : " not ") +
"granted temporary autoplay permission.");
});
info("- remove temporary permission -");
const permissionChanged = BrowserTestUtils.waitForEvent(browser, "PermissionStateChange");
SitePermissions.remove(browser.currentURI, "autoplay-media", browser);
await permissionChanged;
permission = SitePermissions.get(browser.currentURI, "autoplay-media", browser);
ok(permission.state == SitePermissions.UNKNOWN, "temporary permission has been reset.");
await ContentTask.spawn(browser, null,
() => {
ok(!content.windowUtils.isAutoplayTemporarilyAllowed(),
"window should reset temporary autoplay permission as well.");
});
}
// Reset permission.
SitePermissions.remove(browser.currentURI, "autoplay-media");
info("- Finished '" + args.name + "' -");
@ -119,24 +151,56 @@ add_task(async () => {
button: "allow",
shouldPlay: true,
mode: "autoplay attribute",
checkbox: true,
});
await testAutoplayUnknownPermission({
name: "Unknown permission click allow call play",
button: "allow",
shouldPlay: true,
mode: "call play",
checkbox: true,
});
await testAutoplayUnknownPermission({
name: "Unknown permission click allow autoplay attribute and no check check-box",
button: "allow",
shouldPlay: true,
mode: "autoplay attribute",
checkbox: false,
});
await testAutoplayUnknownPermission({
name: "Unknown permission click allow call play and no check check-box",
button: "allow",
shouldPlay: true,
mode: "call play",
checkbox: false,
});
await testAutoplayUnknownPermission({
name: "Unknown permission click block autoplay attribute",
button: "block",
shouldPlay: false,
mode: "autoplay attribute",
checkbox: true,
});
await testAutoplayUnknownPermission({
name: "Unknown permission click block call play",
button: "block",
shouldPlay: false,
mode: "call play",
checkbox: true,
});
await testAutoplayUnknownPermission({
name: "Unknown permission click block autoplay attribute and no check check-box",
button: "block",
shouldPlay: false,
mode: "autoplay attribute",
checkbox: false,
});
await testAutoplayUnknownPermission({
name: "Unknown permission click block call play and no check check-box",
button: "block",
shouldPlay: false,
mode: "call play",
checkbox: false,
});
});