@@ -152,3 +152,45 @@ test.describe('request.headers can be passed in form of a Headers object', () =>
152152 expect ( uap . ua ) . toBe ( 'myBrowser/1.0' ) ;
153153 } ) ;
154154} ) ;
155+
156+ test . describe ( 'Chaining withFeatureCheck() & withClientHints() in client-side development' , ( ) => {
157+
158+ test ( 'Chain' , async ( { page, browserName } ) => {
159+ await page . addInitScript ( ( browserName ) => {
160+ Object . defineProperty ( navigator , 'userAgent' , {
161+ value : 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/16.0 Safari/605.1.15'
162+ } ) ;
163+ Object . defineProperty ( navigator , 'standalone' , {
164+ value : true
165+ } ) ;
166+ Object . defineProperty ( navigator , 'maxTouchPoints' , {
167+ value : 3
168+ } ) ;
169+ if ( browserName == 'chromium' ) {
170+ Object . defineProperty ( navigator , 'userAgentData' , {
171+ value : {
172+ brands : [ ] ,
173+ platform : '' ,
174+ mobile : false ,
175+ getHighEntropyValues : ( ) => {
176+ return Promise . resolve ( {
177+ formFactors : 'VR'
178+ } ) ;
179+ }
180+ }
181+ } ) ;
182+ }
183+ } , browserName ) ;
184+ await page . goto ( localHtml ) ;
185+ // @ts -ignore
186+ const fc2ch = await page . evaluate ( async ( ) => await UAParser ( ) . withFeatureCheck ( ) . then ( res => res . withClientHints ( ) ) ) ;
187+ const ch2fc = await page . evaluate ( async ( ) => await UAParser ( ) . withClientHints ( ) . then ( res => res . withFeatureCheck ( ) ) ) ;
188+ if ( browserName == 'chromium' ) {
189+ expect ( fc2ch ) . toHaveProperty ( 'device.type' , 'xr' ) ; // overwrite by client hints
190+ expect ( ch2fc ) . toHaveProperty ( 'device.type' , 'tablet' ) ; // overwrite by feature check
191+ } else {
192+ expect ( fc2ch ) . toHaveProperty ( 'device.type' , 'tablet' ) ; // no client hints found
193+ expect ( ch2fc ) . toHaveProperty ( 'device.type' , 'tablet' ) ;
194+ }
195+ } ) ;
196+ } ) ;
0 commit comments