Commit 573ceb81 authored by Raphael Kubo da Costa's avatar Raphael Kubo da Costa Committed by Commit Bot

Make WakeLockPermissionDescriptor's type attribute required.

Implements https://github.com/w3c/wake-lock/pull/244.

The permission algorithms in the spec already assume it is, and so does our
implementation.

While here, make sure to catch the exception caught when converting JS to a
WakeLockPermissionDescriptor, as we will throw a TypeError when |type| is
not present or is invalid.

Bug: 257511
Change-Id: Ib20001d48296ea4af70368fa494b0d712348da6b
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1864659
Auto-Submit: Raphael Kubo da Costa <raphael.kubo.da.costa@intel.com>
Reviewed-by: default avatarMounir Lamouri <mlamouri@chromium.org>
Reviewed-by: default avatarReilly Grant <reillyg@chromium.org>
Commit-Queue: Raphael Kubo da Costa <raphael.kubo.da.costa@intel.com>
Cr-Commit-Position: refs/heads/master@{#707018}
parent fb95964d
...@@ -158,6 +158,8 @@ PermissionDescriptorPtr ParsePermission(ScriptState* script_state, ...@@ -158,6 +158,8 @@ PermissionDescriptorPtr ParsePermission(ScriptState* script_state,
NativeValueTraits<WakeLockPermissionDescriptor>::NativeValue( NativeValueTraits<WakeLockPermissionDescriptor>::NativeValue(
script_state->GetIsolate(), raw_permission.V8Value(), script_state->GetIsolate(), raw_permission.V8Value(),
exception_state); exception_state);
if (exception_state.HadException())
return nullptr;
const String& type = wake_lock_permission->type(); const String& type = wake_lock_permission->type();
if (type == "screen") { if (type == "screen") {
return CreateWakeLockPermissionDescriptor( return CreateWakeLockPermissionDescriptor(
......
...@@ -4,5 +4,5 @@ ...@@ -4,5 +4,5 @@
// https://w3c.github.io/wake-lock/#the-wakelockpermissiondescriptor-dictionary // https://w3c.github.io/wake-lock/#the-wakelockpermissiondescriptor-dictionary
dictionary WakeLockPermissionDescriptor : PermissionDescriptor { dictionary WakeLockPermissionDescriptor : PermissionDescriptor {
WakeLockType type; required WakeLockType type;
}; };
<!DOCTYPE html>
<link rel="help" href="https://w3c.github.io/wake-lock/#the-wakelockpermissiondescriptor-dictionary">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script>
// Checking for the permission status requires testdriver.js support for permissions.
// See https://github.com/web-platform-tests/wpt/issues/5671.
promise_test(t => {
return promise_rejects(t, new TypeError(), navigator.permissions.query({ name:'wake-lock' }));
}, "WakeLockPermissionDescriptor's type attribute is required");
promise_test(t => {
return promise_rejects(t, new TypeError(), navigator.permissions.query({ name: 'wake-lock', type: 'foo' }));
}, "WakeLockPermissionDescriptor's type attribute must be a WakeLockType");
</script>
\ No newline at end of file
<!DOCTYPE html>
<link rel="help" href="https://w3c.github.io/wake-lock/#the-wakelockpermissiondescriptor-dictionary">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script>
// TODO(https://crbug.com/1015327): Move this to WPT once we can change
// permissions via testdriver.js.
promise_test(t => {
return navigator.permissions.query({name:'wake-lock', type: 'screen'}).then(status => {
assert_class_string(status, "PermissionStatus");
assert_equals(status.state, "denied");
});
}, "WakeLockPermissionDescriptor with type=screen works");
promise_test(t => {
return navigator.permissions.query({ name: 'wake-lock', type: 'system' }).then(status => {
assert_class_string(status, "PermissionStatus");
assert_equals(status.state, "denied");
});
}, "WakeLockPermissionDescriptor with type=system works");
</script>
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment