mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-25 05:41:12 +00:00
Bug 1589754 - Fix permissions.query in top-level document r=tnguyen
Differential Revision: https://phabricator.services.mozilla.com/D50067 --HG-- extra : moz-landing-system : lando
This commit is contained in:
parent
ee9273766f
commit
1884e2a75a
@ -11,6 +11,8 @@ skip-if = toolkit == 'android' && !is_fennec # Bug 1531097
|
||||
[test_notification_crossorigin_iframe.html]
|
||||
# This test needs to be run on HTTP (not HTTPS).
|
||||
[test_notification_insecure_context.html]
|
||||
[test_notification_permissions.html]
|
||||
scheme = https
|
||||
[test_notification_storage.html]
|
||||
[test_bug931307.html]
|
||||
[test_notification_tag.html]
|
||||
|
@ -0,0 +1,67 @@
|
||||
<!DOCTYPE HTML>
|
||||
<html>
|
||||
<!--
|
||||
Tests that the Notification.requestPermission and navigator.permissions.query
|
||||
return values are consistent with the stored permission.
|
||||
https://bugzilla.mozilla.org/show_bug.cgi?id=1589754
|
||||
-->
|
||||
<head>
|
||||
<title>Notification permissions and permissions API</title>
|
||||
<script src="/tests/SimpleTest/SimpleTest.js"></script>
|
||||
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css">
|
||||
</head>
|
||||
<body>
|
||||
<p id="display"></p>
|
||||
<div id="content" style="display: none">
|
||||
</div>
|
||||
<pre id="test">
|
||||
<script class="testbody">
|
||||
|
||||
add_task(async function test_notifications_permission() {
|
||||
await SpecialPowers.pushPrefEnv({
|
||||
set: [
|
||||
// Set pref to exercise relevant code path for regression test.
|
||||
["permissions.delegation.enable", true],
|
||||
],
|
||||
});
|
||||
|
||||
async function testPermissionInWindow(win) {
|
||||
async function checkPermission(perm, expectedResult, expectedPermission) {
|
||||
await SpecialPowers.pushPermissions([
|
||||
{
|
||||
type: "desktop-notification",
|
||||
allow: SpecialPowers.Ci.nsIPermissionManager[perm],
|
||||
context: document,
|
||||
},
|
||||
]);
|
||||
is(
|
||||
await win.Notification.requestPermission(),
|
||||
expectedResult,
|
||||
`expected requestPermission() result for permission ${perm}`
|
||||
);
|
||||
|
||||
let result =
|
||||
await win.navigator.permissions.query({ name: "notifications" });
|
||||
is(
|
||||
result.state,
|
||||
expectedPermission,
|
||||
`expected permissions API result for permission ${perm}`
|
||||
);
|
||||
}
|
||||
|
||||
await checkPermission("UNKNOWN_ACTION", "default", "prompt");
|
||||
await checkPermission("ALLOW_ACTION", "granted", "granted");
|
||||
await checkPermission("DENY_ACTION", "denied", "denied");
|
||||
await checkPermission("PROMPT_ACTION", "default", "prompt");
|
||||
}
|
||||
|
||||
var win = window.open("blank.html");
|
||||
await new Promise(resolve => { win.onload = resolve; });
|
||||
await testPermissionInWindow(win);
|
||||
win.close();
|
||||
});
|
||||
|
||||
</script>
|
||||
</pre>
|
||||
</body>
|
||||
</html>
|
@ -82,7 +82,8 @@ nsresult PermissionDelegateHandler::GetPermissionForPermissionsAPI(
|
||||
return permMgr->TestPermissionFromPrincipal(principal, aType, aPermission);
|
||||
}
|
||||
|
||||
if (info->mPolicy == DelegatePolicy::eDelegateUseIframeOrigin) {
|
||||
if (mDocument->GetWindow()->IsTopLevelWindow() ||
|
||||
info->mPolicy == DelegatePolicy::eDelegateUseIframeOrigin) {
|
||||
return permMgr->TestPermissionFromPrincipal(principal, aType, aPermission);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user