OLD | NEW |
1 <html><head> | 1 <html><head> |
2 <meta http-equiv="content-type" content="text/html; charset=utf-8"> | 2 <meta http-equiv="content-type" content="text/html; charset=utf-8"> |
3 <script type="text/javascript"> | 3 <script type="text/javascript"> |
4 var defaultActions = { | 4 var defaultActions = { |
5 'keydown': true, | 5 'keydown': true, |
6 'keypress': true, | 6 'keypress': true, |
7 'keyup': true, | 7 'keyup': true, |
8 'textInput': true, | 8 'textInput': true, |
9 }; | 9 }; |
10 var keyEventResult = []; | 10 var keyEventResult = []; |
11 var focusedElement = ""; | 11 var focusedElement = ""; |
12 var lastFocusedElement = ""; | 12 var lastFocusedElement = ""; |
13 var testStarted = false; | 13 var testStarted = false; |
14 var keyEventCount = 0; | 14 var expectedEventCount = 0; |
| 15 var eventCount = 0; |
| 16 var keyDownCount = 0; |
| 17 var keyUpCount = 0; |
15 | 18 |
16 function init() { | 19 function init() { |
17 document.addEventListener("keydown", handleEvent, false); | 20 document.addEventListener("keydown", handleEvent, false); |
18 document.addEventListener("keypress", handleEvent, false); | 21 document.addEventListener("keypress", handleEvent, false); |
19 document.addEventListener("keyup", handleEvent, false); | 22 document.addEventListener("keyup", handleEvent, false); |
20 document.addEventListener("textInput", handleEvent, false); | 23 document.addEventListener("textInput", handleEvent, false); |
21 window.addEventListener("blur", handleWindowBlur, false); | 24 window.addEventListener("blur", handleWindowBlur, false); |
22 } | 25 } |
23 | 26 |
24 function log(text) { | 27 function log(text) { |
25 document.getElementById('log').innerHTML += text + '<br/>'; | 28 document.getElementById('log').innerHTML += text + '<br/>'; |
26 } | 29 } |
27 | 30 |
28 function setDefaultAction(type, value) { | 31 function setDefaultAction(type, value) { |
29 defaultActions[type] = value; | 32 defaultActions[type] = value; |
30 document.getElementById(type).checked = !value; | 33 document.getElementById(type).checked = !value; |
31 return defaultActions[type]; | 34 return defaultActions[type]; |
32 } | 35 } |
33 | 36 |
34 function startTest() { | 37 function startTest(count) { |
35 if (!testStarted) { | 38 if (!testStarted) { |
36 clearResult(); | 39 clearResult(); |
37 testStarted = true; | 40 testStarted = true; |
| 41 expectedEventCount = count; |
38 log("Start test."); | 42 log("Start test."); |
39 return true; | 43 return true; |
40 } | 44 } |
41 return false; | 45 return false; |
42 } | 46 } |
43 | 47 |
44 function finishTest() { | 48 function finishTest() { |
45 testStarted = false; | 49 testStarted = false; |
46 window.domAutomationController.setAutomationId(0); | 50 window.domAutomationController.setAutomationId(0); |
47 window.domAutomationController.send("FINISHED"); | 51 window.domAutomationController.send("FINISHED"); |
(...skipping 17 matching lines...) Expand all Loading... |
65 // corresponding modifier attribute set, while the keyup event does have, | 69 // corresponding modifier attribute set, while the keyup event does have, |
66 // eg. pressing and releasing ctrl may generate a keydown event with | 70 // eg. pressing and releasing ctrl may generate a keydown event with |
67 // ctrlKey=false and a keyup event with ctrlKey=true. | 71 // ctrlKey=false and a keyup event with ctrlKey=true. |
68 // But Windows and Mac have opposite behavior than Linux. | 72 // But Windows and Mac have opposite behavior than Linux. |
69 // To make the C++ testing code simpler, if it's a modifier key event, | 73 // 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. | 74 // then ignores the corresponding modifier attribute by setting it to true. |
71 var keyId = evt.keyIdentifier; | 75 var keyId = evt.keyIdentifier; |
72 result += (evt.keyCode + ' ' + evt.charCode + ' ' + | 76 result += (evt.keyCode + ' ' + evt.charCode + ' ' + |
73 (keyId == 'Control' ? true : evt.ctrlKey) + ' ' + | 77 (keyId == 'Control' ? true : evt.ctrlKey) + ' ' + |
74 (keyId == 'Shift' ? true : evt.shiftKey) + ' ' + | 78 (keyId == 'Shift' ? true : evt.shiftKey) + ' ' + |
75 (keyId == 'Alt' ? true : evt.altKey)); | 79 (keyId == 'Alt' ? true : evt.altKey) + ' ' + |
| 80 (keyId == 'Meta' ? true : evt.metaKey)); |
76 } | 81 } |
77 keyEventResult.push(result); | 82 keyEventResult.push(result); |
78 log(result); | 83 log(result); |
79 | 84 |
80 if (testStarted) { | 85 if (testStarted) { |
| 86 ++eventCount; |
81 if (evt.type == "keydown") { | 87 if (evt.type == "keydown") { |
82 ++keyEventCount; | 88 ++keyDownCount; |
83 } else if (evt.type == "keyup") { | 89 } else if (evt.type == "keyup") { |
84 --keyEventCount; | 90 ++keyUpCount; |
85 if (keyEventCount == 0) | 91 if (keyDownCount == keyUpCount || (eventCount >= expectedEventCount)) |
86 finishTest(); | 92 finishTest(); |
87 } | 93 } |
88 } | 94 } |
89 | 95 |
90 if (!defaultActions[evt.type]) { | 96 if (!defaultActions[evt.type]) { |
91 if (evt.preventDefault) evt.preventDefault(); | 97 if (evt.preventDefault) evt.preventDefault(); |
92 if (evt.stopPropagation) evt.stopPropagation(); | 98 if (evt.stopPropagation) evt.stopPropagation(); |
93 } | 99 } |
94 return defaultActions[evt.type]; | 100 return defaultActions[evt.type]; |
95 } | 101 } |
96 | 102 |
97 function handleWindowBlur() { | 103 function handleWindowBlur() { |
98 if (testStarted) | 104 if (testStarted) |
99 finishTest(); | 105 finishTest(); |
100 } | 106 } |
101 | 107 |
102 function clearResult() { | 108 function clearResult() { |
103 keyEventResult = []; | 109 keyEventResult = []; |
104 testStarted = false; | 110 testStarted = false; |
105 keyEventCount = 0; | 111 expectedEventCount = 0; |
| 112 eventCount = 0; |
| 113 keyDownCount = 0; |
| 114 keyUpCount = 0; |
106 document.getElementById('log').innerHTML = ""; | 115 document.getElementById('log').innerHTML = ""; |
107 return true; | 116 return true; |
108 } | 117 } |
109 | 118 |
110 function setFocusedElement(id) { | 119 function setFocusedElement(id) { |
111 if (id == "" && focusedElement != "") { | 120 if (id == "" && focusedElement != "") { |
112 var elem = document.getElementById(focusedElement); | 121 var elem = document.getElementById(focusedElement); |
113 if (elem) { | 122 if (elem) { |
114 elem.blur(); | 123 elem.blur(); |
115 return true; | 124 return true; |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
150 <input type="checkbox" id="1" accesskey='1' | 159 <input type="checkbox" id="1" accesskey='1' |
151 onfocus="onFocus(this)" onblur="onBlur(this)"/> | 160 onfocus="onFocus(this)" onblur="onBlur(this)"/> |
152 <input type="checkbox" id="2" accesskey='2' | 161 <input type="checkbox" id="2" accesskey='2' |
153 onfocus="onFocus(this)" onblur="onBlur(this)"/> | 162 onfocus="onFocus(this)" onblur="onBlur(this)"/> |
154 <input type="checkbox" id="3" accesskey='3' | 163 <input type="checkbox" id="3" accesskey='3' |
155 onfocus="onFocus(this)" onblur="onBlur(this)"/> | 164 onfocus="onFocus(this)" onblur="onBlur(this)"/> |
156 <input type="checkbox" id="D" accesskey='D' | 165 <input type="checkbox" id="D" accesskey='D' |
157 onfocus="onFocus(this)" onblur="onBlur(this)"/> | 166 onfocus="onFocus(this)" onblur="onBlur(this)"/> |
158 <input type="text" id="A" accesskey="A" | 167 <input type="text" id="A" accesskey="A" |
159 onfocus="onFocus(this)" onblur="onBlur(this)"/> | 168 onfocus="onFocus(this)" onblur="onBlur(this)"/> |
160 <input type="text" id="B" accesskey="B" | 169 <input type="password" id="B" accesskey="B" |
161 onfocus="onFocus(this)" onblur="onBlur(this)"/> | 170 onfocus="onFocus(this)" onblur="onBlur(this)"/> |
162 <button id="clear" accesskey='C' onclick="clearResult()">Clear</button> | 171 <button id="clear" accesskey='C' onclick="clearResult()">Clear</button> |
163 <p id="log"></p> | 172 <p id="log"></p> |
164 </body> | 173 </body> |
165 </html> | 174 </html> |
OLD | NEW |