Skip to content

Commit

Permalink
wake lock: Remove WakeLockPermissionDescriptor, use separate permissi…
Browse files Browse the repository at this point in the history
…on names.

This adapts the implementation to some of the breaking spec changes
introduced in w3c/screen-wake-lock#255.

Namely, WakeLockPermissionDescriptor has been removed in favor of using a
regular PermissionDescriptor object with |name| set to "screen-wake-lock".

That spec change also removed system wake locks (and consequently the
additions to the WorkerNavigator interface) altogether, but that will be
done in a separate CL, so for now we also support a PermissionDescriptor
object with |name| set to "system-wake-lock".

Bug: 257511, 1064685
Change-Id: I096f3fae24444da5ca6b1eeb3889a813a9e5f270
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2134228
Reviewed-by: Kentaro Hara <[email protected]>
Reviewed-by: Kent Tamura <[email protected]>
Reviewed-by: Mounir Lamouri <[email protected]>
Reviewed-by: Kinuko Yasuda <[email protected]>
Reviewed-by: Reilly Grant <[email protected]>
Auto-Submit: Raphael Kubo da Costa <[email protected]>
Commit-Queue: Raphael Kubo da Costa <[email protected]>
Cr-Commit-Position: refs/heads/master@{#756753}
  • Loading branch information
Raphael Kubo da Costa authored and chromium-wpt-export-bot committed Apr 6, 2020
1 parent 1bb27f7 commit 7ab34f7
Show file tree
Hide file tree
Showing 9 changed files with 16 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
Promise.resolve().then(async () => {
try {
await test_driver.set_permission(
{ name: 'wake-lock', type: 'screen' }, 'granted', false);
{ name: 'screen-wake-lock' }, 'granted', false);

const wakeLock = await navigator.wakeLock.request("screen");
await wakeLock.release();
Expand Down
2 changes: 1 addition & 1 deletion wake-lock/idlharness-worker.https.window.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

promise_test(async t => {
await test_driver.set_permission(
{ name: 'wake-lock', type: 'system' }, 'granted', false);
{ name: 'system-wake-lock' }, 'granted', false);

await fetch_tests_from_worker(new Worker('resources/idlharness-worker.js'));
}, 'Run idlharness tests in a worker.');
4 changes: 2 additions & 2 deletions wake-lock/idlharness.https.window.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// META: script=/resources/testdriver.js
// META: script=/resources/testdriver-vendor.js

// https://w3c.github.io/wake-lock/
// https://w3c.github.io/screen-wake-lock/

'use strict';

Expand All @@ -19,7 +19,7 @@ idl_test(
});

await test_driver.set_permission(
{ name: 'wake-lock', type: 'screen' }, 'granted', false);
{ name: 'screen-wake-lock' }, 'granted', false);
self.sentinel = await navigator.wakeLock.request('screen');
self.sentinel.release();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

promise_test(async t => {
await test_driver.set_permission(
{ name: 'wake-lock', type: 'screen' }, 'granted', false);
{ name: 'screen-wake-lock' }, 'granted', false);
await navigator.wakeLock.request('screen').then(lock => lock.release());
}, 'Feature-Policy header {"screen-wake-lock" : ["*"]} allows the top-level document.');

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

promise_test(async t => {
await test_driver.set_permission(
{ name: 'wake-lock', type: 'screen' }, 'granted', false);
{ name: 'screen-wake-lock' }, 'granted', false);
await navigator.wakeLock.request('screen').then(lock => lock.release());
}, 'Feature-Policy header screen-wake-lock "self" allows the top-level document.');

Expand Down
4 changes: 2 additions & 2 deletions wake-lock/wakelock-onrelease.https.html
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
<!DOCTYPE html>
<link rel="help" href="https://w3c.github.io/wake-lock/#the-onrelease-attribute">
<link rel="help" href="https://w3c.github.io/screen-wake-lock/#the-onrelease-attribute">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/resources/testdriver.js"></script>
<script src="/resources/testdriver-vendor.js"></script>
<script>
async_test(async t => {
await test_driver.set_permission({name: 'wake-lock', type: 'screen'}, 'granted', false);
await test_driver.set_permission({name: 'screen-wake-lock'}, 'granted', false);

const lock = await navigator.wakeLock.request("screen");
lock.onrelease = t.step_func_done((ev) => {
Expand Down
2 changes: 1 addition & 1 deletion wake-lock/wakelock-request-denied.https.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
'use strict';

promise_test(async t => {
await test_driver.set_permission({name: 'wake-lock', type: 'screen'}, 'denied', false);
await test_driver.set_permission({name: 'screen-wake-lock'}, 'denied', false);
return promise_rejects_dom(t, "NotAllowedError", navigator.wakeLock.request('screen'));
}, 'Denied requests should abort with NotAllowedError');
</script>
Expand Down
2 changes: 1 addition & 1 deletion wake-lock/wakelock-supported-by-feature-policy.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<!DOCTYPE html>
<title>Test that wake-lock is advertised in the feature list</title>
<link rel="help" href="https://w3c.github.io/webappsec-feature-policy/#dom-featurepolicy-features">
<link rel="help" href="https://w3c.github.io/wake-lock/#dfn-wake-lock-feature">
<link rel="help" href="https://w3c.github.io/screen-wake-lock/#dfn-wake-lock-feature">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script>
Expand Down
20 changes: 6 additions & 14 deletions wake-lock/wakelockpermissiondescriptor.https.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,29 +5,21 @@
<script src="/resources/testdriver.js"></script>
<script src="/resources/testdriver-vendor.js"></script>
<script>
promise_test(t => {
return promise_rejects_js(t, TypeError, navigator.permissions.query({ name:'wake-lock' }));
}, "WakeLockPermissionDescriptor's type attribute is required");

promise_test(t => {
return promise_rejects_js(t, TypeError, navigator.permissions.query({ name: 'wake-lock', type: 'foo' }));
}, "WakeLockPermissionDescriptor's type attribute must be a WakeLockType");

promise_test(async t => {
await test_driver.set_permission({name: 'wake-lock', type: 'screen'}, 'denied', false);
await test_driver.set_permission({name: 'screen-wake-lock'}, 'denied', false);

return navigator.permissions.query({name:'wake-lock', type: 'screen'}).then(status => {
return navigator.permissions.query({name:'screen-wake-lock'}).then(status => {
assert_class_string(status, "PermissionStatus");
assert_equals(status.state, "denied");
});
}, "WakeLockPermissionDescriptor with type=screen works");
}, "PermissionDescriptor with name='screen-wake-lock' works");

promise_test(async t => {
await test_driver.set_permission({name: 'wake-lock', type: 'system'}, 'denied', false);
await test_driver.set_permission({name: 'system-wake-lock'}, 'denied', false);

return navigator.permissions.query({ name: 'wake-lock', type: 'system' }).then(status => {
return navigator.permissions.query({ name: 'system-wake-lock' }).then(status => {
assert_class_string(status, "PermissionStatus");
assert_equals(status.state, "denied");
});
}, "WakeLockPermissionDescriptor with type=system works");
}, "PermissionDescriptor with name='system-wake-lock' works");
</script>

0 comments on commit 7ab34f7

Please sign in to comment.