1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
|
<!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.clearUserPref("notification.prompt.testing");
await SpecialPowers.pushPrefEnv({
set: [
// Automatically dismiss the permission request when it appears.
["dom.webnotifications.requireuserinteraction", 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>
|