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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/chrome.gyp ('k') | chrome/test/interactive_ui/interactive_ui_tests.gypi » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Property Changes:
Added: svn:eol-style
+ LF
OLDNEW
(Empty)
1 <html><head>
2 <meta http-equiv="content-type" content="text/html; charset=utf-8">
3 <script type="text/javascript">
4 var defaultActions = {
5 'keydown': true,
6 'keypress': true,
7 'keyup': true,
8 'textInput': true,
9 };
10 var keyEventResult = [];
11 var focusedElement = "";
12 var lastFocusedElement = "";
13 var testStarted = false;
14 var keyEventCount = 0;
15
16 function init() {
17 document.addEventListener("keydown", handleEvent, false);
18 document.addEventListener("keypress", handleEvent, false);
19 document.addEventListener("keyup", handleEvent, false);
20 document.addEventListener("textInput", handleEvent, false);
21 window.addEventListener("blur", handleWindowBlur, false);
22 }
23
24 function log(text) {
25 document.getElementById('log').innerHTML += text + '<br/>';
26 }
27
28 function setDefaultAction(type, value) {
29 defaultActions[type] = value;
30 document.getElementById(type).checked = !value;
31 return defaultActions[type];
32 }
33
34 function startTest() {
35 if (!testStarted) {
36 clearResult();
37 testStarted = true;
38 log("Start test.");
39 return true;
40 }
41 return false;
42 }
43
44 function finishTest() {
45 testStarted = false;
46 window.domAutomationController.setAutomationId(0);
47 window.domAutomationController.send("FINISHED");
48 log("Finish test.");
49 }
50
51 function handleEvent(e) {
52 var prefixes = {
53 'keydown': 'D',
54 'keypress': 'P',
55 'keyup': 'U',
56 'textInput': 'T',
57 };
58
59 var evt = e || window.event;
60 var result = prefixes[evt.type] + ' ';
61 if (evt.type == 'textInput') {
62 result += evt.data;
63 } else {
64 // On Linux, the keydown event of a modifier key doesn't have the
65 // corresponding modifier attribute set, while the keyup event does have,
66 // eg. pressing and releasing ctrl may generate a keydown event with
67 // ctrlKey=false and a keyup event with ctrlKey=true.
68 // But Windows and Mac have opposite behavior than Linux.
69 // To make the C++ testing code simpler, if it's a modifier key event,
70 // then ignores the corresponding modifier attribute by setting it to true.
71 var keyId = evt.keyIdentifier;
72 result += (evt.keyCode + ' ' + evt.charCode + ' ' +
73 (keyId == 'Control' ? true : evt.ctrlKey) + ' ' +
74 (keyId == 'Shift' ? true : evt.shiftKey) + ' ' +
75 (keyId == 'Alt' ? true : evt.altKey));
76 }
77 keyEventResult.push(result);
78 log(result);
79
80 if (testStarted) {
81 if (evt.type == "keydown") {
82 ++keyEventCount;
83 } else if (evt.type == "keyup") {
84 --keyEventCount;
85 if (keyEventCount == 0)
86 finishTest();
87 }
88 }
89
90 if (!defaultActions[evt.type]) {
91 if (evt.preventDefault) evt.preventDefault();
92 if (evt.stopPropagation) evt.stopPropagation();
93 }
94 return defaultActions[evt.type];
95 }
96
97 function handleWindowBlur() {
98 if (testStarted)
99 finishTest();
100 }
101
102 function clearResult() {
103 keyEventResult = [];
104 testStarted = false;
105 keyEventCount = 0;
106 document.getElementById('log').innerHTML = "";
107 return true;
108 }
109
110 function setFocusedElement(id) {
111 if (id == "" && focusedElement != "") {
112 var elem = document.getElementById(focusedElement);
113 if (elem) {
114 elem.blur();
115 return true;
116 }
117 } else {
118 var elem = document.getElementById(id);
119 if (elem) {
120 elem.focus();
121 return true;
122 }
123 }
124 return false;
125 }
126
127 function onFocus(element) {
128 focusedElement = element.id;
129 log("Focus: " + focusedElement);
130 }
131
132 function onBlur(element) {
133 focusedElement = "";
134 lastFocusedElement = element.id;
135 log("Blur: " + element.id);
136 }
137
138 function onClick(element) {
139 if (defaultActions[element.id] != undefined)
140 defaultActions[element.id] = !element.checked;
141 }
142 </script>
143 </head>
144 <body onload="init()">
145 <input type="checkbox" id="keydown" onclick="onClick(this)">keydown</input>
146 <input type="checkbox" id="keypress" onclick="onClick(this)">keypress</input>
147 <input type="checkbox" id="keyup" onclick="onClick(this)">keyup</input>
148 <input type="checkbox" id="textInput" onclick="onClick(this)">textInput</input >
149 <br/>
150 <input type="checkbox" id="1" accesskey='1'
151 onfocus="onFocus(this)" onblur="onBlur(this)"/>
152 <input type="checkbox" id="2" accesskey='2'
153 onfocus="onFocus(this)" onblur="onBlur(this)"/>
154 <input type="checkbox" id="3" accesskey='3'
155 onfocus="onFocus(this)" onblur="onBlur(this)"/>
156 <input type="checkbox" id="D" accesskey='D'
157 onfocus="onFocus(this)" onblur="onBlur(this)"/>
158 <input type="text" id="A" accesskey="A"
159 onfocus="onFocus(this)" onblur="onBlur(this)"/>
160 <input type="text" id="B" accesskey="B"
161 onfocus="onFocus(this)" onblur="onBlur(this)"/>
162 <button id="clear" accesskey='C' onclick="clearResult()">Clear</button>
163 <p id="log"></p>
164 </body>
165 </html>
OLDNEW
« 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