Commit 88d3efa0 authored by Reilly Grant's avatar Reilly Grant Committed by Commit Bot

[wake-lock] Split runtime feature flags for screen and system wake locks

This change adds two new Blink runtime feature flags, ScreenWakeLock and
SystemWakeLock. These can be used to control support for the "screen"
and "system" WakeLockType enum values. These checks need to be
implemented by hand in wake_lock.cc since the bindings generator does
not support adding the [RuntimeEnabled] attribute to an enum value.

A webexposed test has been added to check that only the desired wake
lock types are exposed.

Bug: 257511
Change-Id: If9e94eb39bfd98d91c08da89340ff541f471abb3
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2081618
Commit-Queue: Kent Tamura <tkent@chromium.org>
Reviewed-by: default avatarRaphael Kubo da Costa <raphael.kubo.da.costa@intel.com>
Reviewed-by: default avatarKent Tamura <tkent@chromium.org>
Auto-Submit: Reilly Grant <reillyg@chromium.org>
Cr-Commit-Position: refs/heads/master@{#746546}
parent cd82364e
......@@ -62,7 +62,8 @@ class WakeLockBrowserTest : public InProcessBrowserTest {
};
void WakeLockBrowserTest::SetUpCommandLine(base::CommandLine* command_line) {
command_line->AppendSwitchASCII(switches::kEnableBlinkFeatures, "WakeLock");
command_line->AppendSwitchASCII(switches::kEnableBlinkFeatures,
"ScreenWakeLock,SystemWakeLock");
}
void WakeLockBrowserTest::NavigateToSimplePage() {
......
......@@ -54,6 +54,20 @@ ScriptPromise WakeLock::request(ScriptState* script_state,
auto* context = ExecutionContext::From(script_state);
DCHECK(context->IsDocument() || context->IsDedicatedWorkerGlobalScope());
if (type == "screen" && !RuntimeEnabledFeatures::ScreenWakeLockEnabled()) {
exception_state.ThrowTypeError(
"The provided value 'screen' is not a valid enum value of type "
"WakeLockType.");
return ScriptPromise();
}
if (type == "system" && !RuntimeEnabledFeatures::SystemWakeLockEnabled()) {
exception_state.ThrowTypeError(
"The provided value 'system' is not a valid enum value of type "
"WakeLockType.");
return ScriptPromise();
}
// 2.1. If document is not allowed to use the policy-controlled feature named
// "wake-lock", reject promise with a "NotAllowedError" DOMException and
// return promise.
......
......@@ -1508,6 +1508,10 @@
name: "ScreenEnumeration",
status: "experimental",
},
{
name: "ScreenWakeLock",
status: "experimental",
},
// WebSpeech API with both speech recognition and synthesis functionality
// is not fully enabled on all platforms.
{
......@@ -1644,6 +1648,10 @@
name: "SurfaceEmbeddingFeatures",
status: "stable",
},
{
name: "SystemWakeLock",
status: "experimental",
},
{
name: "TextDetector",
status: "experimental",
......@@ -1763,8 +1771,7 @@
},
{
name: "WakeLock",
origin_trial_feature_name: "WakeLock",
status: "experimental",
implied_by: ['ScreenWakeLock', 'SystemWakeLock'],
},
{
name: "WebAnimationsAPI",
......
This is a testharness.js-based test.
FAIL Screen wake locks available. promise_test: Unhandled rejection with value: object "TypeError: Failed to execute 'setPermission' on 'Internals': Wake Lock is not enabled."
FAIL System wake locks available. promise_test: Unhandled rejection with value: object "TypeError: Failed to execute 'setPermission' on 'Internals': Wake Lock is not enabled."
Harness: the test ran to completion.
<!DOCTYPE html>
<html>
<body>
<script src="../resources/testharness.js"></script>
<script src="../resources/testharnessreport.js"></script>
<script>
'use strict';
promise_test(async t => {
await internals.setPermission({name: 'wake-lock', type: 'screen'}, 'granted',
location.origin, location.origin);
const lock = await navigator.wakeLock.request('screen');
await lock.release();
}, "Screen wake locks available.");
promise_test(async t => {
await internals.setPermission({name: 'wake-lock', type: 'system'}, 'granted',
location.origin, location.origin);
const lock = await navigator.wakeLock.request('system');
await lock.release();
}, "System wake locks available.");
</script>
</body>
</html>
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