OLD | NEW |
| (Empty) |
1 if (self.importScripts) { | |
2 importScripts('../../resources/helpers.js'); | |
3 importScripts('testrunner-helpers.js'); | |
4 | |
5 if (get_current_scope() == 'ServiceWorker') | |
6 importScripts('../../../serviceworker/resources/worker-testharness.js'); | |
7 else | |
8 importScripts('../../../resources/testharness.js'); | |
9 } | |
10 | |
11 var tests = [ | |
12 { | |
13 test: async_test('Test empty array in ' + get_current_scope() + ' scope.'), | |
14 fn: function(callback) { | |
15 navigator.permissions.request([]).then(function(result) { | |
16 assert_array_equals(result, []); | |
17 callback(); | |
18 }, function(error) { | |
19 assert_unreached(error); | |
20 callback(); | |
21 }); | |
22 } | |
23 }, { | |
24 test: async_test('Test single permission with update in ' + get_current_scop
e() + ' scope.'), | |
25 fn: function(callback) { | |
26 navigator.permissions.request([{name:'geolocation'}]).then(function(resu
lt) { | |
27 assert_equals(result.length, 1); | |
28 assert_true(result[0] instanceof PermissionStatus); | |
29 assert_equals(result[0].state, 'denied'); | |
30 return setPermission('geolocation', 'granted', location.origin, loca
tion.origin); | |
31 }).then(function() { | |
32 return navigator.permissions.request([{name:'geolocation'}]); | |
33 }).then(function(result) { | |
34 assert_equals(result.length, 1); | |
35 assert_true(result[0] instanceof PermissionStatus); | |
36 assert_equals(result[0].state, 'granted'); | |
37 // Set back to denied to cleanup. | |
38 return setPermission('geolocation', 'denied', location.origin, locat
ion.origin); | |
39 }).then(callback).catch(function(error) { | |
40 assert_unreached(error); | |
41 callback(); | |
42 }); | |
43 } | |
44 }, { | |
45 test: async_test('Test two permissions with update in ' + get_current_scope(
) + ' scope.'), | |
46 fn: function(callback) { | |
47 navigator.permissions.request([{name:'geolocation'}, {name:'notification
s'}]).then(function(result) { | |
48 assert_equals(result.length, 2); | |
49 for (var i = 0; i < result.length; i++) { | |
50 assert_true(result[i] instanceof PermissionStatus); | |
51 assert_equals(result[i].state, 'denied'); | |
52 } | |
53 return setPermission('geolocation', 'granted', location.origin, loca
tion.origin); | |
54 }).then(function() { | |
55 return navigator.permissions.request([{name:'geolocation'}, {name:'n
otifications'}]); | |
56 }).then(function(result) { | |
57 assert_equals(result.length, 2); | |
58 for (var i = 0; i < result.length; i++) | |
59 assert_true(result[i] instanceof PermissionStatus); | |
60 assert_equals(result[0].state, 'granted'); | |
61 assert_equals(result[1].state, 'denied'); | |
62 return setPermission('notifications', 'prompt', location.origin, loc
ation.origin); | |
63 }).then(function() { | |
64 return navigator.permissions.request([{name:'geolocation'}, {name:'n
otifications'}]); | |
65 }).then(function(result) { | |
66 assert_equals(result.length, 2); | |
67 for (var i = 0; i < result.length; i++) | |
68 assert_true(result[i] instanceof PermissionStatus); | |
69 assert_equals(result[0].state, 'granted'); | |
70 assert_equals(result[1].state, 'prompt'); | |
71 // Set back to denied to cleanup. | |
72 return setPermission('geolocation', 'denied', location.origin, locat
ion.origin).then(function() { | |
73 return setPermission('notifications', 'denied', location.origin,
location.origin) | |
74 }) | |
75 }).then(callback) | |
76 .catch(function(error) { | |
77 assert_unreached(error); | |
78 callback(); | |
79 }); | |
80 } | |
81 }, { | |
82 test: async_test('Test two permissions (inverted) with update in ' + get_cur
rent_scope() + ' scope.'), | |
83 fn: function(callback) { | |
84 navigator.permissions.request([{name:'notifications'}, {name:'geolocatio
n'}]).then(function(result) { | |
85 assert_equals(result.length, 2); | |
86 for (var i = 0; i < result.length; i++) { | |
87 assert_true(result[i] instanceof PermissionStatus); | |
88 assert_equals(result[i].state, 'denied'); | |
89 } | |
90 return setPermission('notifications', 'granted', location.origin, lo
cation.origin); | |
91 }).then(function() { | |
92 return navigator.permissions.request([{name:'notifications'}, {name:
'geolocation'}]); | |
93 }).then(function(result) { | |
94 assert_equals(result.length, 2); | |
95 for (var i = 0; i < result.length; i++) | |
96 assert_true(result[i] instanceof PermissionStatus); | |
97 assert_equals(result[0].state, 'granted'); | |
98 assert_equals(result[1].state, 'denied'); | |
99 return setPermission('geolocation', 'prompt', location.origin, locat
ion.origin); | |
100 }).then(function() { | |
101 return navigator.permissions.request([{name:'notifications'}, {name:
'geolocation'}]); | |
102 }).then(function(result) { | |
103 assert_equals(result.length, 2); | |
104 for (var i = 0; i < result.length; i++) | |
105 assert_true(result[i] instanceof PermissionStatus); | |
106 assert_equals(result[0].state, 'granted'); | |
107 assert_equals(result[1].state, 'prompt'); | |
108 // Set back to denied to cleanup. | |
109 return setPermission('geolocation', 'denied', location.origin, locat
ion.origin).then(function() { | |
110 return setPermission('notifications', 'denied', location.origin,
location.origin) | |
111 }) | |
112 }).then(callback).catch(function(error) { | |
113 assert_unreached(error); | |
114 callback(); | |
115 }); | |
116 } | |
117 }, { | |
118 test: async_test('Test duplicate permissions with update in ' + get_current_
scope() + ' scope.'), | |
119 fn: function(callback) { | |
120 navigator.permissions.request([{name:'geolocation'}, {name:'geolocation'
}]).then(function(result) { | |
121 assert_equals(result.length, 2); | |
122 for (var i = 0; i < result.length; i++) { | |
123 assert_true(result[i] instanceof PermissionStatus); | |
124 assert_equals(result[i].state, 'denied'); | |
125 } | |
126 return setPermission('geolocation', 'granted', location.origin, loca
tion.origin); | |
127 }).then(function() { | |
128 return navigator.permissions.request([{name:'geolocation'}, {name:'g
eolocation'}]); | |
129 }).then(function(result) { | |
130 assert_equals(result.length, 2); | |
131 for (var i = 0; i < result.length; i++) { | |
132 assert_true(result[i] instanceof PermissionStatus); | |
133 assert_equals(result[i].state, 'granted'); | |
134 } | |
135 // Set back to denied to cleanup. | |
136 return setPermission('geolocation', 'denied', location.origin, locat
ion.origin); | |
137 }).then(callback).catch(function(error) { | |
138 assert_unreached(error); | |
139 callback(); | |
140 }); | |
141 } | |
142 }]; | |
143 | |
144 function runTest(i) { | |
145 tests[i].test.step(function() { | |
146 tests[i].fn(function() { | |
147 tests[i].test.done(); | |
148 if (i + 1 < tests.length) { | |
149 runTest(i + 1); | |
150 } else { | |
151 done(); | |
152 } | |
153 }); | |
154 }); | |
155 } | |
156 runTest(0); | |
OLD | NEW |