Skip to content

Commit

Permalink
device_orientation: Add requestPermission() to Device{Orientation,Mot…
Browse files Browse the repository at this point in the history
…ion}Event

STILL WIP, BLOCKED ON https://crbug.com/952824

Implement w3c/deviceorientation#68, which has added
a static requestPermission() method to both DeviceOrientationEvent as well
as DeviceMotionEvent. Scripts wishing to listen to these events (as well as
deviceorientationabsolute) must first request permission from users by
calling those methods; until then, any event listeners are registered but
never triggered.

Permission granted via requestPermission() is checked for after other
existing checks (if the requires feature policy checks fail, for example, we
still do not register the event handler at all).

Implementing this requires changing how sensors permissions work in the
browser: so far, users could choose between always allowing and always
blocking sensor access. It is now possible to choose "Ask" as an option, in
which case a modal prompt asks the user for access (dismissing the prompt or
choosing "Block" both mean "Block" to the new web API). In any case, we keep
"Allow" as the default option for backwards compatibility. Specifically:
* In the desktop UI, it is possible to choose between "Allow", "Ask" and
  "Block" for sensors in chrome://settings/content/siteDetails and between
  "Allow" and "Ask" in chrome://settings/content/sensors.
* On Android, it is currrently not possible to have per-site sensor
  settings; on the global site settings, we now have a tri-state choice
  between "Allow", "Ask" and "Block".

Bug: 947112
Change-Id: I0e34b48fd21d56d6ac35ad55f69f992065a4bc62
  • Loading branch information
rakuco authored and chromium-wpt-export-bot committed Apr 18, 2019
1 parent 0a4f439 commit 4abd2d0
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 53 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,27 @@
</head>
<body>
<p>If an implementation can never provide absolute orientation information, the event should be fired with the alpha, beta and gamma attributes set to null.</p>
<button onclick="prepareAndRun(this)">Start tests</button>
<div id="log"></div>
<script>
var t = async_test("deviceorientationabsolute event fires");
var run = false;
window.addEventListener("deviceorientationabsolute", function(e) {
if (!run) {
run = true;
t.step(function () {
function prepareAndRun(button) {
button.disabled = true;

async_test(async t => {
const permission = await DeviceOrientationEvent.requestPermission();
t.step(() => {
assert_equals(permission, 'granted', 'You must grant permission to run this test.');
});

window.addEventListener("deviceorientationabsolute", t.step_func_done((e) => {
assert_equals(e.type, "deviceorientationabsolute", "type is set to \"deviceorientationabsolute\"");
assert_equals(e.alpha, null, "alpha is set to null");
assert_equals(e.beta, null, "beta is set to null");
assert_equals(e.gamma, null, "gamma is set to null");
assert_true(e.absolute, "absolute is set to true");
});
t.done();
}
}, false);
}), false);
}, 'deviceorientationabsolute event fires');
}
</script>
</body>
</html>
35 changes: 35 additions & 0 deletions orientation-event/ondeviceorientationabsolute-manual.https.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<!DOCTYPE html>
<html>
<head>
<title>User agents must also provide an event handler IDL attribute named ondeviceorientationabsolute on the window object</title>
<meta name=viewport content="width=device-width, maximum-scale=1.0">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
</head>
<body>
<p>Rotate the device to run the tests.</p>
<button onclick="prepareAndRun(this)">Start tests</button>
<div id="log"></div>
<script>
function prepareAndRun(button) {
button.disabled = true;

async_test(async t => {
const permission = await DeviceOrientationEvent.requestPermission();
t.step(() => {
assert_equals(permission, 'granted', 'You must grant permission to run this test.');
});

window.ondeviceorientationabsolute = t.step_func_done((e) => {
assert_equals(e.type, "deviceorientationabsolute",
"Provide an event handler IDL attribute named ondeviceorientationabsolute");
assert_true(e instanceof DeviceOrientationEvent,
"The type of this event handler must be 'DeviceOrientationEvent");
assert_true(e.absolute, "The absolute property must be set to true.");
});
}, 'ondeviceorientationabsolute event handler works');
}
</script>
</body>
</html>

43 changes: 0 additions & 43 deletions orientation-event/ondeviceorientationabsolute.https.html

This file was deleted.

0 comments on commit 4abd2d0

Please sign in to comment.