Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(528)

Unified Diff: chrome/test/data/keyevents_test.html

Issue 268035: Implements tests for testing browser's overall key events handling behavior.... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 11 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/chrome.gyp ('k') | chrome/test/interactive_ui/interactive_ui_tests.gypi » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/test/data/keyevents_test.html
===================================================================
--- chrome/test/data/keyevents_test.html (revision 0)
+++ chrome/test/data/keyevents_test.html (revision 0)
@@ -0,0 +1,165 @@
+<html><head>
+<meta http-equiv="content-type" content="text/html; charset=utf-8">
+<script type="text/javascript">
+var defaultActions = {
+ 'keydown': true,
+ 'keypress': true,
+ 'keyup': true,
+ 'textInput': true,
+};
+var keyEventResult = [];
+var focusedElement = "";
+var lastFocusedElement = "";
+var testStarted = false;
+var keyEventCount = 0;
+
+function init() {
+ document.addEventListener("keydown", handleEvent, false);
+ document.addEventListener("keypress", handleEvent, false);
+ document.addEventListener("keyup", handleEvent, false);
+ document.addEventListener("textInput", handleEvent, false);
+ window.addEventListener("blur", handleWindowBlur, false);
+}
+
+function log(text) {
+ document.getElementById('log').innerHTML += text + '<br/>';
+}
+
+function setDefaultAction(type, value) {
+ defaultActions[type] = value;
+ document.getElementById(type).checked = !value;
+ return defaultActions[type];
+}
+
+function startTest() {
+ if (!testStarted) {
+ clearResult();
+ testStarted = true;
+ log("Start test.");
+ return true;
+ }
+ return false;
+}
+
+function finishTest() {
+ testStarted = false;
+ window.domAutomationController.setAutomationId(0);
+ window.domAutomationController.send("FINISHED");
+ log("Finish test.");
+}
+
+function handleEvent(e) {
+ var prefixes = {
+ 'keydown': 'D',
+ 'keypress': 'P',
+ 'keyup': 'U',
+ 'textInput': 'T',
+ };
+
+ var evt = e || window.event;
+ var result = prefixes[evt.type] + ' ';
+ if (evt.type == 'textInput') {
+ result += evt.data;
+ } else {
+ // On Linux, the keydown event of a modifier key doesn't have the
+ // corresponding modifier attribute set, while the keyup event does have,
+ // eg. pressing and releasing ctrl may generate a keydown event with
+ // ctrlKey=false and a keyup event with ctrlKey=true.
+ // But Windows and Mac have opposite behavior than Linux.
+ // To make the C++ testing code simpler, if it's a modifier key event,
+ // then ignores the corresponding modifier attribute by setting it to true.
+ var keyId = evt.keyIdentifier;
+ result += (evt.keyCode + ' ' + evt.charCode + ' ' +
+ (keyId == 'Control' ? true : evt.ctrlKey) + ' ' +
+ (keyId == 'Shift' ? true : evt.shiftKey) + ' ' +
+ (keyId == 'Alt' ? true : evt.altKey));
+ }
+ keyEventResult.push(result);
+ log(result);
+
+ if (testStarted) {
+ if (evt.type == "keydown") {
+ ++keyEventCount;
+ } else if (evt.type == "keyup") {
+ --keyEventCount;
+ if (keyEventCount == 0)
+ finishTest();
+ }
+ }
+
+ if (!defaultActions[evt.type]) {
+ if (evt.preventDefault) evt.preventDefault();
+ if (evt.stopPropagation) evt.stopPropagation();
+ }
+ return defaultActions[evt.type];
+}
+
+function handleWindowBlur() {
+ if (testStarted)
+ finishTest();
+}
+
+function clearResult() {
+ keyEventResult = [];
+ testStarted = false;
+ keyEventCount = 0;
+ document.getElementById('log').innerHTML = "";
+ return true;
+}
+
+function setFocusedElement(id) {
+ if (id == "" && focusedElement != "") {
+ var elem = document.getElementById(focusedElement);
+ if (elem) {
+ elem.blur();
+ return true;
+ }
+ } else {
+ var elem = document.getElementById(id);
+ if (elem) {
+ elem.focus();
+ return true;
+ }
+ }
+ return false;
+}
+
+function onFocus(element) {
+ focusedElement = element.id;
+ log("Focus: " + focusedElement);
+}
+
+function onBlur(element) {
+ focusedElement = "";
+ lastFocusedElement = element.id;
+ log("Blur: " + element.id);
+}
+
+function onClick(element) {
+ if (defaultActions[element.id] != undefined)
+ defaultActions[element.id] = !element.checked;
+}
+</script>
+</head>
+<body onload="init()">
+ <input type="checkbox" id="keydown" onclick="onClick(this)">keydown</input>
+ <input type="checkbox" id="keypress" onclick="onClick(this)">keypress</input>
+ <input type="checkbox" id="keyup" onclick="onClick(this)">keyup</input>
+ <input type="checkbox" id="textInput" onclick="onClick(this)">textInput</input>
+ <br/>
+ <input type="checkbox" id="1" accesskey='1'
+ onfocus="onFocus(this)" onblur="onBlur(this)"/>
+ <input type="checkbox" id="2" accesskey='2'
+ onfocus="onFocus(this)" onblur="onBlur(this)"/>
+ <input type="checkbox" id="3" accesskey='3'
+ onfocus="onFocus(this)" onblur="onBlur(this)"/>
+ <input type="checkbox" id="D" accesskey='D'
+ onfocus="onFocus(this)" onblur="onBlur(this)"/>
+ <input type="text" id="A" accesskey="A"
+ onfocus="onFocus(this)" onblur="onBlur(this)"/>
+ <input type="text" id="B" accesskey="B"
+ onfocus="onFocus(this)" onblur="onBlur(this)"/>
+ <button id="clear" accesskey='C' onclick="clearResult()">Clear</button>
+ <p id="log"></p>
+</body>
+</html>
Property changes on: chrome/test/data/keyevents_test.html
___________________________________________________________________
Added: svn:eol-style
+ LF
« no previous file with comments | « chrome/chrome.gyp ('k') | chrome/test/interactive_ui/interactive_ui_tests.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698