@@ -43,17 +43,22 @@ beforeEach(() => {
4343 resetAndroidTestImeActivationCacheForTests ( ) ;
4444} ) ;
4545
46- test ( 'close-time restore puts the previous IME back and clears record and marker ' , async ( ) => {
46+ test . each ( [ false , true ] ) ( 'close restores the previous IME with displaced=%s ' , async ( displaced ) => {
4747 const host = bindAndroidAdbHostStub ( ) ;
4848 await host . imeRecoveryMarkers . write ( STATE_DIR , DEVICE . id ) ;
4949 setAndroidTestImeActiveForTests ( DEVICE , true ) ;
5050 const state = stuckDeviceState ( ) ;
51+ if ( displaced ) {
52+ state . settings . set ( 'default_input_method' , 'com.android.inputmethod.latin/.LatinIME' ) ;
53+ state . settings . set ( 'agent_device_ime_helper_rebind_displaced' , '1' ) ;
54+ }
5155
5256 const result = await restoreWith ( state ) ;
5357
5458 expect ( result ) . toMatchObject ( { restored : true , reason : 'ok' } ) ;
5559 expect ( state . settings . get ( 'default_input_method' ) ) . toBe ( 'com.samsung/.Keyboard' ) ;
5660 expect ( state . settings . has ( 'agent_device_ime_helper_previous_ime' ) ) . toBe ( false ) ;
61+ expect ( state . settings . has ( 'agent_device_ime_helper_rebind_displaced' ) ) . toBe ( false ) ;
5762 expect ( [ ...( host . markerStore . get ( STATE_DIR ) ?? [ ] ) ] ) . toEqual ( [ ] ) ;
5863} ) ;
5964
@@ -97,26 +102,13 @@ test('a failed restore keeps the record and the marker for a later retry', async
97102 expect ( [ ...( host . markerStore . get ( STATE_DIR ) ?? [ ] ) ] ) . toEqual ( [ DEVICE . id ] ) ;
98103} ) ;
99104
100- test ( "close-time restore undoes a rebind's fallback IME, but not the user's own switch" , async ( ) => {
101- const host = bindAndroidAdbHostStub ( ) ;
102- await host . imeRecoveryMarkers . write ( STATE_DIR , DEVICE . id ) ;
103- setAndroidTestImeActiveForTests ( DEVICE , true ) ;
104- const displaced = stuckDeviceState ( ) ;
105- displaced . settings . set ( 'default_input_method' , 'com.android.inputmethod.latin/.LatinIME' ) ;
106- displaced . settings . set ( 'agent_device_ime_helper_rebind_displaced' , '1' ) ;
107-
108- expect ( await restoreWith ( displaced ) ) . toMatchObject ( { restored : true , reason : 'ok' } ) ;
109- expect ( displaced . settings . get ( 'default_input_method' ) ) . toBe ( 'com.samsung/.Keyboard' ) ;
110- expect ( displaced . settings . has ( 'agent_device_ime_helper_previous_ime' ) ) . toBe ( false ) ;
111- expect ( displaced . settings . has ( 'agent_device_ime_helper_rebind_displaced' ) ) . toBe ( false ) ;
112- expect ( [ ...( host . markerStore . get ( STATE_DIR ) ?? [ ] ) ] ) . toEqual ( [ ] ) ;
113-
105+ test ( 'close leaves the user-selected keyboard alone' , async ( ) => {
106+ bindAndroidAdbHostStub ( ) ;
114107 setAndroidTestImeActiveForTests ( DEVICE , true ) ;
115- const switched = stuckDeviceState ( ) ;
116- switched . settings . set ( 'default_input_method' , 'com.android.inputmethod.latin/.LatinIME' ) ;
117-
118- expect ( await restoreWith ( switched ) ) . toMatchObject ( { reason : 'helper-not-active' } ) ;
119- expect ( switched . settings . get ( 'default_input_method' ) ) . toBe (
108+ const state = stuckDeviceState ( ) ;
109+ state . settings . set ( 'default_input_method' , 'com.android.inputmethod.latin/.LatinIME' ) ;
110+ expect ( await restoreWith ( state ) ) . toMatchObject ( { reason : 'helper-not-active' } ) ;
111+ expect ( state . settings . get ( 'default_input_method' ) ) . toBe (
120112 'com.android.inputmethod.latin/.LatinIME' ,
121113 ) ;
122114} ) ;
@@ -147,10 +139,14 @@ test('startup recovery never scans devices without a pending marker, and retains
147139 expect ( [ ...( host . markerStore . get ( STATE_DIR ) ?? [ ] ) ] ) . toEqual ( [ DEVICE . id ] ) ;
148140} ) ;
149141
150- test ( 'startup recovery restores a stuck orphan through the scoped transport and clears its marker ' , async ( ) => {
142+ test . each ( [ false , true ] ) ( 'startup recovers a stuck orphan with displaced=%s ' , async ( displaced ) => {
151143 const host = bindAndroidAdbHostStub ( ) ;
152144 await host . imeRecoveryMarkers . write ( STATE_DIR , DEVICE . id ) ;
153145 const state = stuckDeviceState ( ) ;
146+ if ( displaced ) {
147+ state . settings . set ( 'default_input_method' , 'com.android.inputmethod.latin/.LatinIME' ) ;
148+ state . settings . set ( 'agent_device_ime_helper_rebind_displaced' , '1' ) ;
149+ }
154150
155151 await withAndroidAdbProvider (
156152 { exec : fakeImeDeviceAdb ( state ) } ,
@@ -163,32 +159,11 @@ test('startup recovery restores a stuck orphan through the scoped transport and
163159 ) ;
164160
165161 expect ( state . settings . get ( 'default_input_method' ) ) . toBe ( 'com.samsung/.Keyboard' ) ;
162+ expect ( state . settings . has ( 'agent_device_ime_helper_rebind_displaced' ) ) . toBe ( false ) ;
163+ expect ( state . settings . has ( 'agent_device_ime_helper_previous_ime' ) ) . toBe ( false ) ;
166164 expect ( [ ...( host . markerStore . get ( STATE_DIR ) ?? [ ] ) ] ) . toEqual ( [ ] ) ;
167165 expect ( host . diagnostics ) . toContainEqual ( {
168166 phase : 'android_test_ime_orphan_restored' ,
169167 level : 'warn' ,
170168 } ) ;
171169} ) ;
172-
173- test ( "startup recovery undoes a crashed daemon's unconfirmed rebind" , async ( ) => {
174- const host = bindAndroidAdbHostStub ( ) ;
175- await host . imeRecoveryMarkers . write ( STATE_DIR , DEVICE . id ) ;
176- const state = stuckDeviceState ( ) ;
177- state . settings . set ( 'default_input_method' , 'com.android.inputmethod.latin/.LatinIME' ) ;
178- state . settings . set ( 'agent_device_ime_helper_rebind_displaced' , '1' ) ;
179-
180- await withAndroidAdbProvider (
181- { exec : fakeImeDeviceAdb ( state ) } ,
182- { serial : DEVICE . id } ,
183- async ( ) =>
184- await restoreOrphanedAndroidTestImeOnDaemonStartup ( {
185- stateDir : STATE_DIR ,
186- listSerials : async ( ) => [ DEVICE . id ] ,
187- } ) ,
188- ) ;
189-
190- expect ( state . settings . get ( 'default_input_method' ) ) . toBe ( 'com.samsung/.Keyboard' ) ;
191- expect ( state . settings . has ( 'agent_device_ime_helper_rebind_displaced' ) ) . toBe ( false ) ;
192- expect ( state . settings . has ( 'agent_device_ime_helper_previous_ime' ) ) . toBe ( false ) ;
193- expect ( [ ...( host . markerStore . get ( STATE_DIR ) ?? [ ] ) ] ) . toEqual ( [ ] ) ;
194- } ) ;
0 commit comments