Bug 1775107 [wpt PR 34499] - Add requestPermission() to DeviceOrientationEvent and...
[gecko.git] / testing / web-platform / tests / orientation-event / orientation / requestPermission.https.window.js
blob4a39a238d018d20e5c3f968d6cd5fc68cd0ce8ca
1 // META: script=/resources/testdriver.js
2 // META: script=/resources/testdriver-vendor.js
4 'use strict';
6 // The Device Orientation spec does not fully integrate with the Permissions
7 // spec and does not list the permissions that are expected for
8 // requestPermission() to work. The list below was based on the permissions
9 // listed in https://w3c.github.io/orientation-sensor/#model for the low-level
10 // sensors that power absolute and relative orientation sensors.
11 const permissionDescriptorNames =
12     ['accelerometer', 'gyroscope', 'magnetometer'];
14 promise_test(async (t) => {
15   await Promise.all(permissionDescriptorNames.map(
16       name => test_driver.set_permission({name}, 'granted')));
18   const permission = await DeviceOrientationEvent.requestPermission();
19   assert_equals(permission, 'granted');
20 }, 'requestPermission() returns "granted" for granted permissions without user activation');
22 promise_test(async (t) => {
23   await Promise.all(permissionDescriptorNames.map(
24       name => test_driver.set_permission({name}, 'granted')));
26   return test_driver.bless('enable user activation', async () => {
27     const permission = await DeviceOrientationEvent.requestPermission();
28     assert_equals(permission, 'granted');
29   });
30 }, 'requestPermission() returns "granted" for granted permissions with user activation');
32 promise_test(async (t) => {
33   await Promise.all(permissionDescriptorNames.map(
34       name => test_driver.set_permission({name}, 'denied')));
36   const permission = await DeviceOrientationEvent.requestPermission();
37   assert_equals(permission, 'denied');
38 }, 'requestPermission() returns "denied" for denied permissions without user activation');
40 promise_test(async (t) => {
41   await Promise.all(permissionDescriptorNames.map(
42       name => test_driver.set_permission({name}, 'denied')));
44   return test_driver.bless('enable user activation', async () => {
45     const permission = await DeviceOrientationEvent.requestPermission();
46     assert_equals(permission, 'denied');
47   });
48 }, 'requestPermission() returns "denied" for denied permissions with user activation');