OLD | NEW |
(Empty) | |
| 1 <!DOCTYPE html> |
| 2 <!-- |
| 3 The html/js to help testing keyboard events. It |
| 4 - receives keybord events and preventDefault(), |
| 5 - writes the key codes to /html/body/div[@id='container'], |
| 6 - sends the key codes to window.domAutomationController once KeyX is received. |
| 7 --> |
| 8 <html> |
| 9 <head> |
| 10 <title>Fullscreen Keyboard Lock Test</title> |
| 11 <script> |
| 12 let done = false; |
| 13 function getKeyEventReport() { |
| 14 return new Promise((resolve, reject) => { |
| 15 const register = () => { |
| 16 window.setTimeout(() => { |
| 17 if (done) { |
| 18 resolve(); |
| 19 } else { |
| 20 register(); |
| 21 } |
| 22 }, 100); |
| 23 }; |
| 24 register(); |
| 25 }).then(() => { |
| 26 window.domAutomationController.send(container().innerHTML); |
| 27 }); |
| 28 }; |
| 29 |
| 30 function isMacOSFullscreenShortcut(e) { |
| 31 return e.metaKey && |
| 32 e.ctrlKey && |
| 33 !e.altKey && |
| 34 !e.shiftKey && |
| 35 e.code == "KeyF"; |
| 36 } |
| 37 |
| 38 function isF11FullscreenShortcut(e) { |
| 39 return !e.metaKey && |
| 40 !e.ctrlKey && |
| 41 !e.altKey && |
| 42 !e.shiftKey && |
| 43 e.code == "F11"; |
| 44 } |
| 45 |
| 46 function isBrowserFullscreenShortcut(e) { |
| 47 return isMacOSFullscreenShortcut(e) || |
| 48 isF11FullscreenShortcut(e); |
| 49 } |
| 50 |
| 51 function container() { |
| 52 return document.getElementById('container'); |
| 53 } |
| 54 |
| 55 function consumeEvent(type, e) { |
| 56 container().innerHTML += type + ' ' + e.code + '\n'; |
| 57 e.preventDefault(); |
| 58 } |
| 59 |
| 60 function init() { |
| 61 document.addEventListener('keydown', (e) => { |
| 62 // The web content triggers fullscreen on the "S" key down event. |
| 63 if (e.code == 'KeyS') { |
| 64 container().webkitRequestFullscreen(); |
| 65 } else if (isBrowserFullscreenShortcut(e)) { |
| 66 // Web page can consume fullscreen shortcut when the page is in |
| 67 // window mode, but it's not expected in test cases. |
| 68 return; |
| 69 } |
| 70 consumeEvent('keydown', e); |
| 71 }); |
| 72 |
| 73 document.addEventListener('keyup', (e) => { |
| 74 if (isBrowserFullscreenShortcut(e)) { |
| 75 return; |
| 76 } |
| 77 consumeEvent('keyup', e); |
| 78 |
| 79 if (e.code == 'KeyX') { |
| 80 done = true; |
| 81 } |
| 82 }); |
| 83 |
| 84 document.addEventListener('keypress', (e) => { |
| 85 consumeEvent('keypress', e); |
| 86 }); |
| 87 } |
| 88 </script> |
| 89 </head> |
| 90 <body onload='init()'> |
| 91 <div id='container'> |
| 92 </div> |
| 93 </body> |
| 94 </html> |
OLD | NEW |