forked from mozilla/gecko-dev
-
Notifications
You must be signed in to change notification settings - Fork 2
/
test_permission_basics.html
109 lines (91 loc) · 3.93 KB
/
test_permission_basics.html
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
<!DOCTYPE html>
<html>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=770731
-->
<head>
<title>Test for Bug {770731} Permissions</title>
<script type="text/javascript" src="/MochiKit/MochiKit.js"></script>
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
</head>
<body>
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=770731">Mozilla Bug 770731</a>
<p id="display"></p>
<div id="content" style="display: none">
</div>
<pre id="test">
<script class="testbody" type="text/javascript">
"use strict";
SimpleTest.waitForExplicitFinish();
var testPrivApp = {
'manifestURL' : 'https://aprivileged.com/manifest.webapp'
};
var testCertApp = {
'manifestURL' : 'https://acertified.com/manifest.webapp'
};
// Any permission explicit for privileged and implicit for certified serves
var testPerm = "contacts-read";
// Any permission explicit for privileged and certified apps
var explicitPerm = "geolocation";
// Simulate that the app requested the permissions
SpecialPowers.pushPermissions([{'type': 'permissions', 'allow': true, 'context': document}, {'type': testPerm, 'allow': true, 'context': testPrivApp}, {'type': testPerm, 'allow': true, 'context': testCertApp}, {'type': explicitPerm, 'allow': true, 'context': testPrivApp}, {'type': explicitPerm, 'allow': true, 'context': testCertApp}], function() {
SpecialPowers.pushPrefEnv({ "set": [["dom.mozPermissionSettings.enabled", true]] }, permissionTest);
});
function permissionTest() {
if (SpecialPowers.isMainProcess()) {
SpecialPowers.Cu.import("resource://gre/modules/PermissionSettings.jsm");
}
var mozPermissions = window.navigator.mozPermissionSettings;
isnot(mozPermissions, null, "mozPermissionSettings is null when not enabled.");
var certAppManifest = testCertApp.manifestURL;
var privAppManifest = testPrivApp.manifestURL;
var originPriv = "https://aprivileged.com";
var originCert = "https://acertified.com";
var originOther = "http://test";
// Trying to make any change to implicit permissions should fail
try {
mozPermissions.set(testPerm, "allow", certAppManifest, originCert, false);
ok(false, "Change implicit permission");
} catch (e) {
ok(true, "Change implicit permission");
}
var result=mozPermissions.get(testPerm, certAppManifest, originCert, false);
is(result, "allow", "same result");
// Removing a permission from the same origin, even an explicit one, should fail
try {
mozPermissions.set(testPerm, "unknown", privAppManifest, originPriv);
ok(false, "Setting a permission to unknown");
} catch (e) {
ok(true, "Setting a permission to unknown");
}
// Removing an explicit permission from a different origin should work
var testRemove = function(aPerm, aManifest, aOrigin, aTestMsg) {
try {
mozPermissions.remove(aPerm, aManifest, aOrigin);
var status = mozPermissions.get(aPerm, aManifest, aOrigin, false);
is(status, "unknown", aTestMsg);
} catch (e) {
ok(false, aTestMsg);
}
}
testRemove(explicitPerm, privAppManifest, originOther,
"Remove explicit permission of privileged app");
testRemove(explicitPerm, certAppManifest, originOther,
"Remove explicit permission of certified app");
mozPermissions.set(testPerm, "allow", privAppManifest, originPriv, false);
result = mozPermissions.get(testPerm, privAppManifest, originPriv, false);
is(result, "allow", "Set to allow");
mozPermissions.set(testPerm, "deny", privAppManifest, originPriv, false);
result = mozPermissions.get(testPerm, privAppManifest, originPriv, false);
is(result, "deny", "Set to deny");
mozPermissions.set(testPerm, "prompt", privAppManifest, originPriv, false);
result = mozPermissions.get(testPerm, privAppManifest, originPriv, false);
is(result, "prompt", "Set to prompt");
SimpleTest.finish();
}
ok(true, "test passed");
</script>
</pre>
</body>
</html>