@@ -15,6 +15,7 @@ import { ANDROID_SNAPSHOT_HELPER_FIXTURE_ARTIFACT } from './test-utils/android-s
1515import {
1616 readAndroidFillTargetBeforeMutation ,
1717 verifyAndroidFilledText ,
18+ type FillVerificationClock ,
1819} from '../fill-verification.ts' ;
1920import { resetAndroidSnapshotHelperSessions } from '../snapshot-helper-session-lifecycle.ts' ;
2021import {
@@ -93,43 +94,66 @@ test('verification samples re-read the hierarchy instead of sharing one capture'
9394} ) ;
9495
9596test ( 'a value the app renders late still verifies, as long as it lands before the deadline' , async ( ) => {
96- // Six samples of the hint before the value shows: about 900 ms in, past the retired schedule's
97- // last sample at 500 ms and inside the deadline.
97+ // Six samples of the hint before the value shows: 900 ms in, past the retired schedule's last
98+ // sample at 500 ms and inside the deadline.
9899 const session = createFillHelperSession ( {
99100 textForCapture : ( captureIndex ) => ( captureIndex <= 6 ? 'Key echo' : 'chips' ) ,
100101 } ) ;
102+ const clock = createFakeClock ( ) ;
101103
102104 const verification = await withFillHelperProvider (
103105 session . provider ,
104106 async ( ) =>
105- await verifyAndroidFilledText ( device , 10 , 10 , 'chips' , {
106- helperSessionScope : 'daemon-session' ,
107- } ) ,
107+ await verifyAndroidFilledText (
108+ device ,
109+ 10 ,
110+ 10 ,
111+ 'chips' ,
112+ { helperSessionScope : 'daemon-session' } ,
113+ clock ,
114+ ) ,
108115 ) ;
109116
110117 assert . equal ( verification . ok , true ) ;
111118 assert . equal ( session . captureCount ( ) , 8 , 'six hint samples, then the value held for two' ) ;
119+ assert . equal ( clock . now ( ) , 1050 , 'the value held from the 900 ms sample to the 1050 ms one' ) ;
112120} ) ;
113121
114122test ( 'a value that never lands is a mismatch at the deadline, not before it' , async ( ) => {
115123 const session = createFillHelperSession ( { textForCapture : ( ) => 'Key echo' } ) ;
116- const startedAt = Date . now ( ) ;
124+ const clock = createFakeClock ( ) ;
117125
118126 const verification = await withFillHelperProvider (
119127 session . provider ,
120128 async ( ) =>
121- await verifyAndroidFilledText ( device , 10 , 10 , 'chips' , {
122- helperSessionScope : 'daemon-session' ,
123- } ) ,
129+ await verifyAndroidFilledText (
130+ device ,
131+ 10 ,
132+ 10 ,
133+ 'chips' ,
134+ { helperSessionScope : 'daemon-session' } ,
135+ clock ,
136+ ) ,
124137 ) ;
125138
126139 assert . equal ( verification . ok , false ) ;
127140 assert . equal ( verification . reason , 'text_mismatch' ) ;
128- assert . equal ( verification . actual , 'Key echo' , 'the last sample is the answer' ) ;
129- assert . ok ( Date . now ( ) - startedAt >= 1500 , 'sampling ran to the deadline' ) ;
130- assert . ok ( session . captureCount ( ) >= 4 , 'the deadline admits more samples than the old schedule ' ) ;
141+ assert . equal ( verification . actual , 'Key echo' , 'the sample at the deadline is the answer' ) ;
142+ assert . equal ( clock . now ( ) , 1500 , 'sampling ran to the deadline and not past it ' ) ;
143+ assert . equal ( session . captureCount ( ) , 11 , 'a sample every 150 ms from 0 to 1500 ' ) ;
131144} ) ;
132145
146+ /** A clock the sampler advances by sleeping, so the deadline is reached without waiting it out. */
147+ function createFakeClock ( ) : FillVerificationClock & { now ( ) : number } {
148+ let elapsed = 0 ;
149+ return {
150+ now : ( ) => elapsed ,
151+ sleep : async ( milliseconds ) => {
152+ elapsed += milliseconds ;
153+ } ,
154+ } ;
155+ }
156+
133157test ( 'the pre-action target read shares the daemon-session helper with the samples' , async ( ) => {
134158 const session = createFillHelperSession ( ) ;
135159
0 commit comments