6 document
.getElementById('log').appendChild(document
.createTextNode(msg
+ '\n'));
9 function description(element
)
11 if (element
.tagName
&& element
.tagName
.match(/input/i)) {
12 return '<input value="' + element
.value
+ '" tabindex="' + element
.tabIndex
+ '">';
14 return element
.toString();
18 function dispatchTabPress(element
, shiftKey
)
20 var event
= document
.createEvent('KeyboardEvents');
21 var tabKeyIdentifier
= 'U+0009';
22 event
.initKeyboardEvent('keydown', true, true, document
.defaultView
, tabKeyIdentifier
, 0, false, false, shiftKey
, false, false);
23 element
.dispatchEvent(event
);
26 var lastFocusedElement
= null;
27 function focusListener(event
)
29 log('<input value="' + event
.target
.value
+ '" tabindex="' + event
.target
.tabIndex
+ '"> focused');
30 lastFocusedElement
= event
.target
;
33 function addEventListenersToInputs(inputs
)
35 for (var i
= 0; i
< inputs
.length
; ++i
) {
36 inputs
[i
].addEventListener('focus', focusListener
, false);
42 if (window
.testRunner
) {
43 testRunner
.dumpAsText();
46 var inputs
= document
.getElementsByTagName('input');
48 // Put focus in the page
52 addEventListenersToInputs(inputs
);
54 log('Tabbing forward....\n');
55 for (var i
= 0; i
< inputs
.length
; ++i
) {
56 if (inputs
[i
].tabIndex
>= 0)
57 dispatchTabPress(document
, false);
60 lastFocusedElement
.blur();
62 log('\nTabbing backward....\n');
63 for (var i
= 0; i
< inputs
.length
; ++i
) {
64 if (inputs
[i
].tabIndex
>= 0)
65 dispatchTabPress(document
, true);
68 log('\nTest finished\n');
72 <body onload=
"test()">
73 <p>This page tests that the
<a href=
"http://www.w3.org/TR/html4/interact/forms.html#h-17.11.1" title=
"HTML4 tabbing order spec">HTML4 tabbing order
</a> is respected properly.
</p>
74 <p>To test, put focus in
"a
". Pressing Tab should focus
"a
" through
"k
" in order, and pressing Shift-Tab should reverse the order.
</p>
76 <input tabindex=
"6" value=
"g"><br>
77 <input tabindex=
"1" value=
"a"><br>
78 <input tabindex=
"-5" value=
"not in tab order (negative tabindex)"><br>
79 <input tabindex=
"1" value=
"b"><br>
80 <input tabindex=
"0" value=
"i"><br>
81 <input tabindex=
"6" value=
"h"><br>
82 <input tabindex=
"1" value=
"c"><br>
83 <input tabindex=
"1" value=
"d"><br>
84 <input tabindex=
"0" value=
"j"><br>
85 <input tabindex=
"-1" value=
"not in tab order (negative tabindex)"><br>
86 <input tabindex=
"0" value=
"k"><br>
87 <input tabindex=
"4" value=
"f"><br>
88 <input tabindex=
"3" value=
"e"><br>