Skip to content

Commit

Permalink
Move KeyboardLock API methods to a 'keyboard' object
Browse files Browse the repository at this point in the history
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:
https://w3c.github.io/keyboard-lock/#API

Old calling pattern:
Navigator.keyboardLock();
Navigator.leyboardUnlock();

New calling pattern:
Navigator.keyboard.lock();
Navigator.keyboard.unlock();

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.

BUG=680809

Change-Id: I234b2ab12d5ecd44c894ed5103863fd96fd548d4
  • Loading branch information
Joe Downing authored and chromium-wpt-export-bot committed Mar 20, 2018
1 parent 6e1b5f4 commit 47b2598
Show file tree
Hide file tree
Showing 7 changed files with 53 additions and 52 deletions.
8 changes: 8 additions & 0 deletions interfaces/keyboard-apis.idl
@@ -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();
};
34 changes: 34 additions & 0 deletions keyboard-apis/idlharness.https.html
@@ -0,0 +1,34 @@
<!doctype html>
<html>
<head>
<title>Keyboard IDL tests</title>
<link rel="help" href="https://w3c.github.io/keyboard-lock/"/>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/resources/WebIDLParser.js"></script>
<script src="/resources/idlharness.js"></script>
<script>
'use strict';

function doTest(idls) {
var idl_array = new IdlArray();
idl_array.add_untested_idls('interface Navigator {};');
for (let idl of idls) {
idl_array.add_idls(idl);
}
idl_array.add_objects({
Navigator: ['navigator'],
Keyboard: ['navigator.keyboard'],
});
idl_array.test();
};

function fetchText(url) {
return fetch(url).then((response) => response.text());
}

promise_test(() => {
return Promise.all(["/interfaces/keyboard-apis.idl"].map(fetchText))
.then(doTest);
}, "Test driver");
</script>
Expand Up @@ -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');

</script>
Expand Up @@ -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');

</script>
Expand Up @@ -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');

</script>
Expand Up @@ -5,8 +5,8 @@
'use strict';

test(() => {
assert_equals(navigator.keyboardUnlock(),
assert_equals(navigator.keyboard.unlock(),
undefined);
}, 'Keyboard Lock keyboardUnlock');
}, '[Keyboard Lock] keyboard.unlock');

</script>
41 changes: 0 additions & 41 deletions keyboard-lock/idlharness.https.html

This file was deleted.

0 comments on commit 47b2598

Please sign in to comment.