Index: chrome/test/data/fullscreen_keyboardlock.html |
diff --git a/chrome/test/data/fullscreen_keyboardlock.html b/chrome/test/data/fullscreen_keyboardlock.html |
new file mode 100644 |
index 0000000000000000000000000000000000000000..6afe3091e4d3f2c217cd9585b92751d3fd128aff |
--- /dev/null |
+++ b/chrome/test/data/fullscreen_keyboardlock.html |
@@ -0,0 +1,105 @@ |
+<!DOCTYPE html> |
+<!-- |
+ The html/js to help testing keyboard events. It |
+ - receives keybord events and preventDefault(), |
+ - writes the key codes to /html/body/div[@id='container'], |
+ - sends the key codes to window.domAutomationController once KeyX is received. |
+--> |
+<html> |
+ <head> |
+ <title>Fullscreen Keyboard Lock Test</title> |
+ <script> |
+ let done = false; |
+ function getKeyEventReport() { |
+ return new Promise((resolve, reject) => { |
+ const register = () => { |
+ window.setTimeout(() => { |
Paweł Hajdan Jr.
2017/07/11 11:59:57
What's the purpose of this delay? Looks like a pol
Hzj_jie
2017/07/11 17:47:26
The key events are sent to renderer process throug
Hzj_jie
2017/07/12 02:41:06
But yes, this logic is over-complex, I have update
|
+ if (done) { |
+ resolve(); |
+ } else { |
+ register(); |
+ } |
+ }, 100); |
+ }; |
+ register(); |
+ }).then(() => { |
+ window.domAutomationController.send(container().innerHTML); |
+ }); |
+ }; |
+ |
+ function isMacOSFullscreenShortcut(e) { |
+ return e.metaKey && |
+ e.ctrlKey && |
+ !e.altKey && |
+ !e.shiftKey && |
+ e.code == "KeyF"; |
+ } |
+ |
+ function isF11FullscreenShortcut(e) { |
+ return !e.metaKey && |
+ !e.ctrlKey && |
+ !e.altKey && |
+ !e.shiftKey && |
+ e.code == "F11"; |
+ } |
+ |
+ function isBrowserFullscreenShortcut(e) { |
+ return isMacOSFullscreenShortcut(e) || |
+ isF11FullscreenShortcut(e); |
+ } |
+ |
+ function container() { |
+ return document.getElementById('container'); |
+ } |
+ |
+ function consumeEvent(type, e) { |
+ if (type == 'keydown' && |
+ !e.code.startsWith("Control") && |
+ !e.code.startsWith("Shift") && |
+ !e.code.startsWith("Alt") && |
+ !e.code.startsWith("Meta")) { |
+ container().innerHTML += |
+ e.code + |
+ ' ctrl:' + e.getModifierState('Control') + |
+ ' shift:' + e.getModifierState('Shift') + |
+ ' alt:' + e.getModifierState('Alt') + |
+ ' meta:' + e.getModifierState('Meta') + '\n'; |
+ } |
+ e.preventDefault(); |
+ } |
+ |
+ function init() { |
+ document.addEventListener('keydown', (e) => { |
+ // The web content triggers fullscreen on the "S" key down event. |
+ if (e.code == 'KeyS') { |
+ container().webkitRequestFullscreen(); |
+ } else if (isBrowserFullscreenShortcut(e)) { |
+ // Web page can consume fullscreen shortcut when the page is in |
+ // window mode, but it's not expected in test cases. |
+ return; |
+ } |
+ consumeEvent('keydown', e); |
+ }); |
+ |
+ document.addEventListener('keyup', (e) => { |
+ if (isBrowserFullscreenShortcut(e)) { |
+ return; |
+ } |
+ consumeEvent('keyup', e); |
+ |
+ if (e.code == 'KeyX') { |
+ done = true; |
+ } |
+ }); |
+ |
+ document.addEventListener('keypress', (e) => { |
+ consumeEvent('keypress', e); |
+ }); |
+ } |
+ </script> |
+ </head> |
+ <body onload='init()'> |
+ <div id='container'> |
+ </div> |
+ </body> |
+</html> |