Skip to content

Commit 891678d

Browse files
device-orientation-permisson-ui: Don't emit "granted" event until permissions are actually granted. (#5079)
* Change order of catch and then branches * Clarify comments
1 parent aedc9f5 commit 891678d

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

‎src/components/scene/device-orientation-permission-ui.js‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,17 +52,17 @@ module.exports.Component = registerComponent('device-orientation-permission-ui',
5252
this.onDeviceMotionDialogAllowClicked = bind(this.onDeviceMotionDialogAllowClicked, this);
5353
this.onDeviceMotionDialogDenyClicked = bind(this.onDeviceMotionDialogDenyClicked, this);
5454
// Show dialog only if permission has not yet been granted.
55-
DeviceOrientationEvent.requestPermission().catch(function () {
55+
DeviceOrientationEvent.requestPermission().then(function () {
56+
self.el.emit('deviceorientationpermissiongranted');
57+
self.permissionGranted = true;
58+
}).catch(function () {
5659
self.devicePermissionDialogEl = createPermissionDialog(
5760
self.data.denyButtonText,
5861
self.data.allowButtonText,
5962
self.data.deviceMotionMessage,
6063
self.onDeviceMotionDialogAllowClicked,
6164
self.onDeviceMotionDialogDenyClicked);
6265
self.el.appendChild(self.devicePermissionDialogEl);
63-
}).then(function () {
64-
self.el.emit('deviceorientationpermissiongranted');
65-
self.permissionGranted = true;
6666
});
6767
},
6868

‎tests/components/scene/device-motion-permission-ui.test.js‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,15 @@ suite('device-orientation-permission-ui', function () {
1111
window.DeviceOrientationEvent = {
1212
requestPermission: function () { return Promise.reject(); }
1313
};
14-
el.addEventListener('loaded', function () { done(); });
14+
el.addEventListener('deviceorientationpermissiongranted', function () {
15+
assert.fail('Received permissiongranted too soon.');
16+
});
17+
el.addEventListener('deviceorientationpermissionrejected', function () {
18+
assert.fail('Received permissionrejected too soon.');
19+
});
20+
el.addEventListener('loaded', function () {
21+
done();
22+
});
1523
});
1624

1725
test('appends permission dialog', function (done) {

0 commit comments

Comments
 (0)