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 return setPermission('geolocation', 'denied', location.origin, locat ion.origin); | |
mlamouri (slow - plz ping)
2015/09/24 11:12:42
nit: add a comment saying "// Cleanup."
Lalit Maganti
2015/09/24 11:24:35
Done.
| |
38 }).then(callback).catch(function(error) { | |
39 assert_unreached(error); | |
40 callback(); | |
41 }); | |
42 } | |
43 }, { | |
44 test: async_test('Test two permissions with update in ' + get_current_scope( ) + ' scope.'), | |
45 fn: function(callback) { | |
46 navigator.permissions.request([{name:'geolocation'}, {name:'notification s'}]).then(function(result) { | |
47 assert_equals(result.length, 2); | |
48 for (var i = 0; i < result.length; i++) { | |
49 assert_true(result[i] instanceof PermissionStatus); | |
50 assert_equals(result[i].state, 'denied'); | |
51 } | |
52 return setPermission('geolocation', 'granted', location.origin, loca tion.origin); | |
53 }).then(function() { | |
54 return setPermission('notifications', 'prompt', location.origin, loc ation.origin); | |
mlamouri (slow - plz ping)
2015/09/24 11:12:42
could you check the intermediary state here? (ie.
Lalit Maganti
2015/09/24 11:24:35
Done.
| |
55 }).then(function() { | |
56 return navigator.permissions.request([{name:'geolocation'}, {name:'n otifications'}]); | |
57 }).then(function(result) { | |
58 assert_equals(result.length, 2); | |
59 for (var i = 0; i < result.length; i++) | |
60 assert_true(result[i] instanceof PermissionStatus); | |
61 assert_equals(result[0].state, 'granted'); | |
62 assert_equals(result[1].state, 'prompt'); | |
63 return setPermission('geolocation', 'denied', location.origin, locat ion.origin); | |
mlamouri (slow - plz ping)
2015/09/24 11:12:42
ditto
Lalit Maganti
2015/09/24 11:24:35
Done.
| |
64 }).then(function() { | |
65 return setPermission('notifications', 'denied', location.origin, loc ation.origin); | |
mlamouri (slow - plz ping)
2015/09/24 11:12:42
Actually, could you do above:
return Promise.all
Lalit Maganti
2015/09/24 11:24:35
Done.
Lalit Maganti
2015/09/24 12:43:39
Realised that Promise.all does not work with the w
| |
66 }).then(callback).catch(function(error) { | |
67 assert_unreached(error); | |
68 callback(); | |
69 }); | |
70 } | |
71 }, { | |
72 test: async_test('Test two permissions (inverted) with update in ' + get_cur rent_scope() + ' scope.'), | |
73 fn: function(callback) { | |
74 navigator.permissions.request([{name:'notifications'}, {name:'geolocatio n'}]).then(function(result) { | |
75 assert_equals(result.length, 2); | |
76 for (var i = 0; i < result.length; i++) { | |
77 assert_true(result[i] instanceof PermissionStatus); | |
78 assert_equals(result[i].state, 'denied'); | |
79 } | |
80 return setPermission('notifications', 'granted', location.origin, lo cation.origin); | |
81 }).then(function() { | |
82 return setPermission('geolocation', 'prompt', location.origin, locat ion.origin); | |
mlamouri (slow - plz ping)
2015/09/24 11:12:42
could you check the intermediary state here? (ie.
Lalit Maganti
2015/09/24 11:24:35
Done.
| |
83 }).then(function() { | |
84 return navigator.permissions.request([{name:'notifications'}, {name: 'geolocation'}]); | |
85 }).then(function(result) { | |
86 assert_equals(result.length, 2); | |
87 for (var i = 0; i < result.length; i++) | |
88 assert_true(result[i] instanceof PermissionStatus); | |
89 assert_equals(result[0].state, 'granted'); | |
90 assert_equals(result[1].state, 'prompt'); | |
91 return setPermission('notifications', 'denied', location.origin, loc ation.origin); | |
92 }).then(function() { | |
93 return setPermission('geolocation', 'denied', location.origin, locat ion.origin); | |
94 }).then(callback).catch(function(error) { | |
95 assert_unreached(error); | |
96 callback(); | |
97 }); | |
98 } | |
99 }, { | |
100 test: async_test('Test duplicate permissions with update in ' + get_current_ scope() + ' scope.'), | |
101 fn: function(callback) { | |
102 navigator.permissions.request([{name:'geolocation'}, {name:'geolocation' }]).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[i].state, 'denied'); | |
107 } | |
108 return setPermission('geolocation', 'granted', location.origin, loca tion.origin); | |
109 }).then(function() { | |
110 return navigator.permissions.request([{name:'geolocation'}, {name:'g eolocation'}]); | |
111 }).then(function(result) { | |
112 assert_equals(result.length, 2); | |
113 for (var i = 0; i < result.length; i++) { | |
114 assert_true(result[i] instanceof PermissionStatus); | |
115 assert_equals(result[i].state, 'granted'); | |
116 } | |
117 return setPermission('geolocation', 'denied', location.origin, locat ion.origin); | |
118 }).then(callback).catch(function(error) { | |
119 assert_unreached(error); | |
120 callback(); | |
121 }); | |
122 } | |
123 }]; | |
124 | |
125 function runTest(i) { | |
126 tests[i].test.step(function() { | |
127 tests[i].fn(function() { | |
128 tests[i].test.done(); | |
129 if (i + 1 < tests.length) { | |
130 runTest(i + 1); | |
131 } else { | |
132 done(); | |
133 } | |
134 }); | |
135 }); | |
136 } | |
137 runTest(0); | |
OLD | NEW |