@@ -58,6 +58,23 @@ function fixture(beforeDispatch?: NativeEventDispatch): TestDriverFixture {
5858}
5959
6060describe ( 'testdriver keyboard backend integration' , ( ) => {
61+ it ( 'focuses the target once and follows focus changes between Tab key events' , async ( ) => {
62+ const { document, first, third, events, driver } = fixture ( ) ;
63+ let focusCount = 0 ;
64+ first . addEventListener ( 'focus' , ( ) => focusCount ++ ) ;
65+
66+ await driver . send_keys ( first , '\uE004\uE004' ) ;
67+
68+ expect ( focusCount ) . toBe ( 1 ) ;
69+ expect ( document . activeElement ) . toBe ( third ) ;
70+ expect ( events ) . toEqual ( [
71+ [ 'keydown' , 'Tab' , 'first' , false ] ,
72+ [ 'keyup' , 'Tab' , 'second' , false ] ,
73+ [ 'keydown' , 'Tab' , 'second' , false ] ,
74+ [ 'keyup' , 'Tab' , 'third' , false ] ,
75+ ] ) ;
76+ } ) ;
77+
6178 it ( 'dispatches to the active element when a focus handler redirects the target' , async ( ) => {
6279 const { document, first, second, events, driver } = fixture ( ) ;
6380 first . addEventListener ( 'focus' , ( ) => second . focus ( ) ) ;
@@ -71,6 +88,19 @@ describe('testdriver keyboard backend integration', () => {
7188 ] ) ;
7289 } ) ;
7390
91+ it ( 'continues from the focused control when the target is the body' , async ( ) => {
92+ const { document, second, third, events, driver } = fixture ( ) ;
93+ second . focus ( ) ;
94+
95+ await driver . send_keys ( document . body , '\uE004' ) ;
96+
97+ expect ( document . activeElement ) . toBe ( third ) ;
98+ expect ( events ) . toEqual ( [
99+ [ 'keydown' , 'Tab' , 'second' , false ] ,
100+ [ 'keyup' , 'Tab' , 'third' , false ] ,
101+ ] ) ;
102+ } ) ;
103+
74104 it ( 'holds automatic Shift across uppercase and punctuation, then releases it for lowercase' , async ( ) => {
75105 const { first, events, driver } = fixture ( ) ;
76106
@@ -88,6 +118,28 @@ describe('testdriver keyboard backend integration', () => {
88118 ] ) ;
89119 } ) ;
90120
121+ it ( 'handles Shift+Tab and releases modifiers at NULL and completion' , async ( ) => {
122+ const { document, second, third, events, driver } = fixture ( ) ;
123+
124+ await driver . send_keys ( second , '\uE008\uE004\uE000\uE004\uE008' ) ;
125+ expect ( document . activeElement ) . toBe ( second ) ;
126+ await driver . send_keys ( second , '\uE004' ) ;
127+
128+ expect ( document . activeElement ) . toBe ( third ) ;
129+ expect ( events ) . toEqual ( [
130+ [ 'keydown' , 'Shift' , 'second' , true ] ,
131+ [ 'keydown' , 'Tab' , 'second' , true ] ,
132+ [ 'keyup' , 'Tab' , 'first' , true ] ,
133+ [ 'keyup' , 'Shift' , 'first' , false ] ,
134+ [ 'keydown' , 'Tab' , 'first' , false ] ,
135+ [ 'keyup' , 'Tab' , 'second' , false ] ,
136+ [ 'keydown' , 'Shift' , 'second' , true ] ,
137+ [ 'keyup' , 'Shift' , 'second' , false ] ,
138+ [ 'keydown' , 'Tab' , 'second' , false ] ,
139+ [ 'keyup' , 'Tab' , 'third' , false ] ,
140+ ] ) ;
141+ } ) ;
142+
91143 it ( 'releases Shift before Control at NULL even when Control was pressed first' , async ( ) => {
92144 const { first, events, driver } = fixture ( ) ;
93145
@@ -101,6 +153,19 @@ describe('testdriver keyboard backend integration', () => {
101153 ] ) ;
102154 } ) ;
103155
156+ it ( 'honors cancellation of Tab navigation' , async ( ) => {
157+ const { document, first, events, driver } = fixture ( ) ;
158+ first . addEventListener ( 'keydown' , ( event ) => event . preventDefault ( ) ) ;
159+
160+ await driver . send_keys ( first , '\uE004' ) ;
161+
162+ expect ( document . activeElement ) . toBe ( first ) ;
163+ expect ( events ) . toEqual ( [
164+ [ 'keydown' , 'Tab' , 'first' , false ] ,
165+ [ 'keyup' , 'Tab' , 'first' , false ] ,
166+ ] ) ;
167+ } ) ;
168+
104169 it ( 'queues send_keys after concurrent Actions including their pauses' , async ( ) => {
105170 const { first, second, events, driver } = fixture ( ) ;
106171 first . focus ( ) ;
0 commit comments