Skip to content
Browse files

Move KeyboardLock API methods to a 'keyboard' object

This change moves the KeyboardLock API methods to a 'keyboard'
namespace on the Navigator object.  We are doing this work now as
there has been a request for additional keyboard functionality that
would also be placed on the new keyboard object and we wanted to
move the KeyboardLock methods there for consistency before we launch.

KeyboardLock API Spec is here:

Old calling pattern:

New calling pattern:

Note: The main logic in the KeyboardLock.cpp class and tests is the
same as it was, however the file changed enough that git does not
recognize it as a file move.


Change-Id: I234b2ab12d5ecd44c894ed5103863fd96fd548d4
Reviewed-by: Philip Jägenstedt <>
Reviewed-by: Gary Kacmarcik <>
Reviewed-by: Daniel Cheng <>
Commit-Queue: Daniel Cheng <>
Cr-Commit-Position: refs/heads/master@{#544996}
  • Loading branch information...
Joe Downing authored and chromium-wpt-export-bot committed Mar 22, 2018
1 parent 1a8c195 commit 5ffa5051c36c670be1a38000de442b002920ac12
@@ -0,0 +1,8 @@
partial interface Navigator {
[SecureContext, SameObject] readonly attribute Keyboard keyboard;

[SecureContext, Exposed=Window] interface Keyboard {
Promise<void> lock(optional sequence<DOMString> keyCodes = []);
void unlock();
@@ -1,41 +1,34 @@
<!doctype html>
<title>Keyboard Lock IDL tests</title>
<link rel="help" href=""/>
<title>Keyboard IDL tests</title>
<link rel="help" href=""/>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/resources/WebIDLParser.js"></script>
<script src="/resources/idlharness.js"></script>
<pre id="untested_idl" style="display: none">
interface Navigator {
The reason of the failure of keyboardLock test looks like a code defect in
idlharness.js. media-capabilities/idlharness.html is also impacted by this
issue. See, which
includes a potential fix.
TODO(joedow): Submit the fix.
<pre id="idl" style="display: none">
partial interface Navigator {
[SecureContext] Promise<void> keyboardLock(optional sequence<DOMString> keyCodes = []);
[SecureContext] void keyboardUnlock();
var idl_array = new IdlArray();
Navigator: ["navigator"]
'use strict';
function doTest(idls) {
var idl_array = new IdlArray();
idl_array.add_untested_idls('interface Navigator {};');
for (let idl of idls) {
Navigator: ['navigator'],
Keyboard: ['navigator.keyboard'],
function fetchText(url) {
return fetch(url).then((response) => response.text());
promise_test(() => {
return Promise.all(["/interfaces/keyboard-lock.idl"].map(fetchText))
}, "Test driver");
<div id="log"></div>
@@ -5,11 +5,11 @@
'use strict';
promise_test((t) => {
const p1 = navigator.keyboardLock(['a', 'b']);
const p2 = navigator.keyboardLock(['c', 'd']);
const p1 = navigator.keyboard.lock(['a', 'b']);
const p2 = navigator.keyboard.lock(['c', 'd']);
return promise_rejects(t, null, p2,
'keyboardLock() should only be ' +
'keyboard.lock() should only be ' +
'executed if another request has finished.');
}, 'Keyboard Lock keyboardLock twice in parallel');
}, '[Keyboard Lock] keyboard.lock twice in parallel');
@@ -5,10 +5,10 @@
'use strict';
promise_test(() => {
return navigator.keyboardLock(['a', 'b'])
return navigator.keyboard.lock(['a', 'b'])
.then(() => {
return navigator.keyboardLock(['c', 'd']);
return navigator.keyboard.lock(['c', 'd']);
}, 'Keyboard Lock keyboardLock twice sequentially');
}, '[Keyboard Lock] keyboard.lock called twice sequentially');
@@ -5,9 +5,9 @@
'use strict';
promise_test(() => {
const p = navigator.keyboardLock(['a', 'b']);
const p = navigator.keyboard.lock(['a', 'b']);
assert_true(p instanceof Promise);
return p;
}, 'Keyboard Lock keyboardLock');
}, '[Keyboard Lock] keyboard.lock');
@@ -5,8 +5,8 @@
'use strict';
test(() => {
}, 'Keyboard Lock keyboardUnlock');
}, '[Keyboard Lock] keyboard.unlock');

0 comments on commit 5ffa505

Please sign in to comment.
You can’t perform that action at this time.