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 }) |
| 40 .then(callback) |
| 41 .catch(function(error) { |
| 42 assert_unreached(error); |
| 43 callback(); |
| 44 }); |
| 45 } |
| 46 }, { |
| 47 test: async_test('Test two permissions with update in ' + get_current_scope(
) + ' scope.'), |
| 48 fn: function(callback) { |
| 49 navigator.permissions.request([{name:'geolocation'}, {name:'notification
s'}]).then(function(result) { |
| 50 assert_equals(result.length, 2); |
| 51 for (var i = 0; i < result.length; i++) { |
| 52 assert_true(result[i] instanceof PermissionStatus); |
| 53 assert_equals(result[i].state, 'denied'); |
| 54 } |
| 55 return setPermission('geolocation', 'granted', location.origin, loca
tion.origin); |
| 56 }).then(function() { |
| 57 return navigator.permissions.request([{name:'geolocation'}, {name:'n
otifications'}]); |
| 58 }).then(function(result) { |
| 59 assert_equals(result.length, 2); |
| 60 for (var i = 0; i < result.length; i++) |
| 61 assert_true(result[i] instanceof PermissionStatus); |
| 62 assert_equals(result[0].state, 'granted'); |
| 63 assert_equals(result[1].state, 'denied'); |
| 64 return setPermission('notifications', 'prompt', location.origin, loc
ation.origin); |
| 65 }).then(function() { |
| 66 return navigator.permissions.request([{name:'geolocation'}, {name:'n
otifications'}]); |
| 67 }).then(function(result) { |
| 68 assert_equals(result.length, 2); |
| 69 for (var i = 0; i < result.length; i++) |
| 70 assert_true(result[i] instanceof PermissionStatus); |
| 71 assert_equals(result[0].state, 'granted'); |
| 72 assert_equals(result[1].state, 'prompt'); |
| 73 // Set back to denied to cleanup. |
| 74 return setPermission('geolocation', 'denied', location.origin, locat
ion.origin); |
| 75 }).then(function() { |
| 76 return setPermission('notifications', 'denied', location.origin, loc
ation.origin); |
| 77 }) |
| 78 .then(callback) |
| 79 .catch(function(error) { |
| 80 assert_unreached(error); |
| 81 callback(); |
| 82 }); |
| 83 } |
| 84 }, { |
| 85 test: async_test('Test two permissions (inverted) with update in ' + get_cur
rent_scope() + ' scope.'), |
| 86 fn: function(callback) { |
| 87 navigator.permissions.request([{name:'notifications'}, {name:'geolocatio
n'}]).then(function(result) { |
| 88 assert_equals(result.length, 2); |
| 89 for (var i = 0; i < result.length; i++) { |
| 90 assert_true(result[i] instanceof PermissionStatus); |
| 91 assert_equals(result[i].state, 'denied'); |
| 92 } |
| 93 return setPermission('notifications', 'granted', location.origin, lo
cation.origin); |
| 94 }).then(function() { |
| 95 return navigator.permissions.request([{name:'notifications'}, {name:
'geolocation'}]); |
| 96 }).then(function(result) { |
| 97 assert_equals(result.length, 2); |
| 98 for (var i = 0; i < result.length; i++) |
| 99 assert_true(result[i] instanceof PermissionStatus); |
| 100 assert_equals(result[0].state, 'granted'); |
| 101 assert_equals(result[1].state, 'denied'); |
| 102 return setPermission('geolocation', 'prompt', location.origin, locat
ion.origin); |
| 103 }).then(function() { |
| 104 return navigator.permissions.request([{name:'notifications'}, {name:
'geolocation'}]); |
| 105 }).then(function(result) { |
| 106 assert_equals(result.length, 2); |
| 107 for (var i = 0; i < result.length; i++) |
| 108 assert_true(result[i] instanceof PermissionStatus); |
| 109 assert_equals(result[0].state, 'granted'); |
| 110 assert_equals(result[1].state, 'prompt'); |
| 111 // Set back to denied to cleanup. |
| 112 return setPermission('geolocation', 'denied', location.origin, locat
ion.origin); |
| 113 }).then(function() { |
| 114 return setPermission('notifications', 'denied', location.origin, loc
ation.origin); |
| 115 }) |
| 116 .then(callback) |
| 117 .catch(function(error) { |
| 118 assert_unreached(error); |
| 119 callback(); |
| 120 }); |
| 121 } |
| 122 }, { |
| 123 test: async_test('Test duplicate permissions with update in ' + get_current_
scope() + ' scope.'), |
| 124 fn: function(callback) { |
| 125 navigator.permissions.request([{name:'geolocation'}, {name:'geolocation'
}]).then(function(result) { |
| 126 assert_equals(result.length, 2); |
| 127 for (var i = 0; i < result.length; i++) { |
| 128 assert_true(result[i] instanceof PermissionStatus); |
| 129 assert_equals(result[i].state, 'denied'); |
| 130 } |
| 131 return setPermission('geolocation', 'granted', location.origin, loca
tion.origin); |
| 132 }).then(function() { |
| 133 return navigator.permissions.request([{name:'geolocation'}, {name:'g
eolocation'}]); |
| 134 }).then(function(result) { |
| 135 assert_equals(result.length, 2); |
| 136 for (var i = 0; i < result.length; i++) { |
| 137 assert_true(result[i] instanceof PermissionStatus); |
| 138 assert_equals(result[i].state, 'granted'); |
| 139 } |
| 140 // Set back to denied to cleanup. |
| 141 return setPermission('geolocation', 'denied', location.origin, locat
ion.origin); |
| 142 }) |
| 143 .then(callback) |
| 144 .catch(function(error) { |
| 145 assert_unreached(error); |
| 146 callback(); |
| 147 }); |
| 148 } |
| 149 }, { |
| 150 test: async_test('Test duplicate permissions (2) with update in ' + get_curr
ent_scope() + ' scope.'), |
| 151 fn: function(callback) { |
| 152 navigator.permissions.request([{name:'geolocation'}, {name:'geolocation'
}, {name:'notifications'}, {name:'notifications'}]).then(function(result) { |
| 153 assert_equals(result.length, 4); |
| 154 for (var i = 0; i < result.length; i++) { |
| 155 assert_true(result[i] instanceof PermissionStatus); |
| 156 assert_equals(result[i].state, 'denied'); |
| 157 } |
| 158 return setPermission('geolocation', 'granted', location.origin, loca
tion.origin); |
| 159 }).then(function() { |
| 160 return navigator.permissions.request([{name:'geolocation'}, {name:'g
eolocation'}, {name:'notifications'}, {name:'notifications'}]); |
| 161 }).then(function(result) { |
| 162 assert_equals(result.length, 4); |
| 163 for (var i = 0; i < 2; i++) { |
| 164 assert_true(result[i] instanceof PermissionStatus); |
| 165 assert_equals(result[i].state, 'granted'); |
| 166 } |
| 167 for (var i = 2; i < 4; i++) { |
| 168 assert_true(result[i] instanceof PermissionStatus); |
| 169 assert_equals(result[i].state, 'denied'); |
| 170 } |
| 171 // Set back to denied to cleanup. |
| 172 return setPermission('geolocation', 'denied', location.origin, locat
ion.origin); |
| 173 }) |
| 174 .then(callback) |
| 175 .catch(function(error) { |
| 176 assert_unreached(error); |
| 177 callback(); |
| 178 }); |
| 179 } |
| 180 }, { |
| 181 test: async_test('Test duplicate permissions (3) with update in ' + get_curr
ent_scope() + ' scope.'), |
| 182 fn: function(callback) { |
| 183 navigator.permissions.request([{name:'geolocation'}, {name:'notification
s'}, {name:'geolocation'}, {name:'notifications'}]).then(function(result) { |
| 184 assert_equals(result.length, 4); |
| 185 for (var i = 0; i < result.length; i++) { |
| 186 assert_true(result[i] instanceof PermissionStatus); |
| 187 assert_equals(result[i].state, 'denied'); |
| 188 } |
| 189 return setPermission('geolocation', 'granted', location.origin, loca
tion.origin); |
| 190 }).then(function() { |
| 191 return navigator.permissions.request([{name:'geolocation'}, {name:'n
otifications'}, {name:'geolocation'}, {name:'notifications'}]); |
| 192 }).then(function(result) { |
| 193 assert_equals(result.length, 4); |
| 194 for (var i = 0; i < result.length; i++) { |
| 195 assert_true(result[i] instanceof PermissionStatus); |
| 196 } |
| 197 assert_equals(result[0].state, 'granted'); |
| 198 assert_equals(result[1].state, 'denied'); |
| 199 assert_equals(result[2].state, 'granted'); |
| 200 assert_equals(result[3].state, 'denied'); |
| 201 return setPermission('notifications', 'granted', location.origin, lo
cation.origin); |
| 202 }).then(function() { |
| 203 return navigator.permissions.request([{name:'geolocation'}, {name:'n
otifications'}, {name:'geolocation'}, {name:'notifications'}]); |
| 204 }).then(function(result) { |
| 205 assert_equals(result.length, 4); |
| 206 for (var i = 0; i < result.length; i++) { |
| 207 assert_true(result[i] instanceof PermissionStatus); |
| 208 assert_equals(result[i].state, 'granted'); |
| 209 } |
| 210 // Set back to denied to cleanup. |
| 211 return setPermission('geolocation', 'denied', location.origin, locat
ion.origin); |
| 212 }).then(function() { |
| 213 return setPermission('notifications', 'denied', location.origin, loc
ation.origin); |
| 214 }) |
| 215 .then(callback) |
| 216 .catch(function(error) { |
| 217 assert_unreached(error); |
| 218 callback(); |
| 219 }); |
| 220 } |
| 221 }]; |
| 222 |
| 223 function runTest(i) { |
| 224 tests[i].test.step(function() { |
| 225 tests[i].fn(function() { |
| 226 tests[i].test.done(); |
| 227 if (i + 1 < tests.length) { |
| 228 runTest(i + 1); |
| 229 } else { |
| 230 done(); |
| 231 } |
| 232 }); |
| 233 }); |
| 234 } |
| 235 runTest(0); |
OLD | NEW |