Commit bb317b9c authored by zijiehe's avatar zijiehe Committed by Commit Bot

Add BrowserCommandController Interactive Test

BrowserCommandController interactive test ensures the recent changes of browser
shortcuts in fullscreen won't be broken by unexpected changes. It starts a full
screen browser window, sends several key events normally consumed by browser,
and checks whether these events are caught by the web page.

BUG=680809

Review-Url: https://codereview.chromium.org/2922773002
Cr-Commit-Position: refs/heads/master@{#486949}
parent f6a16073
...@@ -448,6 +448,7 @@ if (!is_android) { ...@@ -448,6 +448,7 @@ if (!is_android) {
"../browser/site_per_process_interactive_browsertest.cc", "../browser/site_per_process_interactive_browsertest.cc",
"../browser/ui/autofill/autofill_popup_controller_interactive_uitest.cc", "../browser/ui/autofill/autofill_popup_controller_interactive_uitest.cc",
"../browser/ui/blocked_content/popup_blocker_browsertest.cc", "../browser/ui/blocked_content/popup_blocker_browsertest.cc",
"../browser/ui/browser_command_controller_interactive_browsertest.cc",
"../browser/ui/browser_focus_uitest.cc", "../browser/ui/browser_focus_uitest.cc",
"../browser/ui/cocoa/apps/app_shim_menu_controller_mac_interactive_uitest.mm", "../browser/ui/cocoa/apps/app_shim_menu_controller_mac_interactive_uitest.mm",
"../browser/ui/cocoa/apps/quit_with_apps_controller_mac_interactive_uitest.mm", "../browser/ui/cocoa/apps/quit_with_apps_controller_mac_interactive_uitest.mm",
......
<!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 x_pressed = false;
let report_called = false;
function processResult() {
if (x_pressed && report_called) {
window.domAutomationController.send(container().innerHTML);
}
}
function getKeyEventReport() {
report_called = true;
processResult();
}
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') {
x_pressed = true;
processResult();
}
});
document.addEventListener('keypress', (e) => {
consumeEvent('keypress', e);
});
}
</script>
</head>
<body onload='init()'>
<div id='container'>
</div>
</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