2 <meta http-equiv=
"content-type" content=
"text/html; charset=utf-8">
3 <script type=
"text/javascript">
10 var keyEventResult
= [];
11 var focusedElement
= "";
12 var lastFocusedElement
= "";
13 var testStarted
= false;
14 var expectedEventCount
= 0;
20 document
.addEventListener("keydown", handleEvent
, false);
21 document
.addEventListener("keypress", handleEvent
, false);
22 document
.addEventListener("keyup", handleEvent
, false);
23 document
.addEventListener("textInput", handleEvent
, false);
24 window
.addEventListener("blur", handleWindowBlur
, false);
28 document
.getElementById('log').innerHTML
+= text
+ '<br/>';
31 function setDefaultAction(type
, value
) {
32 defaultActions
[type
] = value
;
33 document
.getElementById(type
).checked
= !value
;
34 return defaultActions
[type
];
37 function startTest(count
) {
41 expectedEventCount
= count
;
48 function finishTest() {
50 window
.domAutomationController
.setAutomationId(0);
51 window
.domAutomationController
.send("FINISHED");
55 function handleEvent(e
) {
63 var evt
= e
|| window
.event
;
64 var result
= prefixes
[evt
.type
] + ' ';
65 if (evt
.type
== 'textInput') {
68 // On Linux, the keydown event of a modifier key doesn't have the
69 // corresponding modifier attribute set, while the keyup event does have,
70 // eg. pressing and releasing ctrl may generate a keydown event with
71 // ctrlKey=false and a keyup event with ctrlKey=true.
72 // But Windows and Mac have opposite behavior than Linux.
73 // To make the C++ testing code simpler, if it's a modifier key event,
74 // then ignores the corresponding modifier attribute by setting it to true.
75 var keyId
= evt
.keyIdentifier
;
76 result
+= (evt
.keyCode
+ ' ' + evt
.charCode
+ ' ' +
77 (keyId
== 'Control' ? true : evt
.ctrlKey
) + ' ' +
78 (keyId
== 'Shift' ? true : evt
.shiftKey
) + ' ' +
79 (keyId
== 'Alt' ? true : evt
.altKey
) + ' ' +
80 (keyId
== 'Meta' ? true : evt
.metaKey
));
82 keyEventResult
.push(result
);
87 if (evt
.type
== "keydown") {
89 } else if (evt
.type
== "keyup") {
91 if (keyDownCount
== keyUpCount
|| (eventCount
>= expectedEventCount
))
96 if (!defaultActions
[evt
.type
]) {
97 if (evt
.preventDefault
) evt
.preventDefault();
98 if (evt
.stopPropagation
) evt
.stopPropagation();
100 return defaultActions
[evt
.type
];
103 function handleWindowBlur() {
108 function clearResult() {
111 expectedEventCount
= 0;
115 document
.getElementById('log').innerHTML
= "";
119 function setFocusedElement(id
) {
120 if (id
== "" && focusedElement
!= "") {
121 var elem
= document
.getElementById(focusedElement
);
127 var elem
= document
.getElementById(id
);
136 function onFocus(element
) {
137 focusedElement
= element
.id
;
138 log("Focus: " + focusedElement
);
141 function onBlur(element
) {
143 lastFocusedElement
= element
.id
;
144 log("Blur: " + element
.id
);
147 function onClick(element
) {
148 if (defaultActions
[element
.id
] != undefined)
149 defaultActions
[element
.id
] = !element
.checked
;
153 <body onload=
"init()">
154 <input type=
"checkbox" id=
"keydown" onclick=
"onClick(this)">keydown
</input>
155 <input type=
"checkbox" id=
"keypress" onclick=
"onClick(this)">keypress
</input>
156 <input type=
"checkbox" id=
"keyup" onclick=
"onClick(this)">keyup
</input>
157 <input type=
"checkbox" id=
"textInput" onclick=
"onClick(this)">textInput
</input>
159 <input type=
"checkbox" id=
"1" accesskey='
1'
160 onfocus=
"onFocus(this)" onblur=
"onBlur(this)"/>
161 <input type=
"checkbox" id=
"2" accesskey='
2'
162 onfocus=
"onFocus(this)" onblur=
"onBlur(this)"/>
163 <input type=
"checkbox" id=
"3" accesskey='
3'
164 onfocus=
"onFocus(this)" onblur=
"onBlur(this)"/>
165 <input type=
"checkbox" id=
"D" accesskey='D'
166 onfocus=
"onFocus(this)" onblur=
"onBlur(this)"/>
167 <input type=
"text" id=
"A" accesskey=
"A"
168 onfocus=
"onFocus(this)" onblur=
"onBlur(this)"/>
169 <input type=
"password" id=
"B" accesskey=
"B"
170 onfocus=
"onFocus(this)" onblur=
"onBlur(this)"/>
171 <button id=
"clear" accesskey='C'
onclick=
"clearResult()">Clear
</button>