@@ -679,6 +679,7 @@ describe('utils', () => {
679679 . mockResolvedValueOnce ( undefined ) // injectWebviewOverlay
680680 . mockResolvedValueOnce ( undefined ) // executeNativeClick
681681 . mockResolvedValueOnce ( { x : 150 , y : 300 , width : 100 , height : 100 } ) // getMobileWebviewClickAndDimensions
682+ . mockResolvedValueOnce ( { vs : 'visible' , focus : true } ) // visibilityState debug check
682683
683684 const result = await getMobileViewPortPosition ( {
684685 browserInstance : mockBrowserInstance ,
@@ -715,6 +716,7 @@ describe('utils', () => {
715716 width : overlayWidth ,
716717 height : overlayHeight ,
717718 } ) // getMobileWebviewClickAndDimensions (rounded integers from overlay)
719+ . mockResolvedValueOnce ( { vs : 'visible' , focus : true } ) // visibilityState debug check
718720
719721 const result = await getMobileViewPortPosition ( {
720722 browserInstance : mockBrowserInstance ,
@@ -735,16 +737,15 @@ describe('utils', () => {
735737
736738 it ( 'should retry and succeed on Android when overlay returns zeros (Start Surface blocking)' , async ( ) => {
737739 const warnSpy = vi . spyOn ( log , 'warn' ) . mockImplementation ( ( ) => { } )
738- const infoSpy = vi . spyOn ( log , 'info' ) . mockImplementation ( ( ) => { } )
739740
740741 vi . mocked ( mockBrowserInstance . execute )
741742 // --- Attempt 1: overlay returns zeros (Start Surface is blocking) ---
742743 . mockResolvedValueOnce ( undefined ) // loadBase64Html (blob)
743744 . mockResolvedValueOnce ( undefined ) // injectWebviewOverlay
744745 . mockResolvedValueOnce ( undefined ) // executeNativeClick (screen center)
745746 . mockResolvedValueOnce ( { x : 0 , y : 0 , width : 0 , height : 0 } ) // getMobileWebviewClickAndDimensions
746- // --- Dismiss Start Surface: tap tab thumbnail area ---
747- . mockResolvedValueOnce ( undefined ) // executeNativeClick (thumbnail tap )
747+ // --- Dismiss Start Surface: Back button ---
748+ . mockResolvedValueOnce ( undefined ) // mobile: pressKey (Back button )
748749 // --- Attempt 2: overlay returns valid data ---
749750 . mockResolvedValueOnce ( undefined ) // loadBase64Html (blob)
750751 . mockResolvedValueOnce ( undefined ) // injectWebviewOverlay
@@ -761,41 +762,32 @@ describe('utils', () => {
761762 expect ( warnSpy ) . toHaveBeenCalledWith (
762763 expect . stringContaining ( 'overlay did not receive the native click' )
763764 )
764- expect ( infoSpy ) . toHaveBeenCalledWith (
765- expect . stringContaining ( 'Tapping tab thumbnail area' )
766- )
767765 expect ( mockBrowserInstance . url ) . toHaveBeenCalledWith ( 'http://example.com' )
768766 expect ( result . viewport . width ) . toBe ( 100 )
769767 expect ( result . viewport . height ) . toBe ( 100 )
770768
771769 warnSpy . mockRestore ( )
772- infoSpy . mockRestore ( )
773770 } )
774771
775- it ( 'should return initialDeviceRectangles after all retries are exhausted on Android' , async ( ) => {
772+ it ( 'should return initialDeviceRectangles after all retries are exhausted on Android' , { timeout : 15000 } , async ( ) => {
776773 const warnSpy = vi . spyOn ( log , 'warn' ) . mockImplementation ( ( ) => { } )
777- const infoSpy = vi . spyOn ( log , 'info' ) . mockImplementation ( ( ) => { } )
778774 const errorSpy = vi . spyOn ( log , 'error' ) . mockImplementation ( ( ) => { } )
779775
780776 const zeroOverlay = { x : 0 , y : 0 , width : 0 , height : 0 }
781- vi . mocked ( mockBrowserInstance . execute )
782- // --- Attempt 1 ---
783- . mockResolvedValueOnce ( undefined ) // loadBase64Html
784- . mockResolvedValueOnce ( undefined ) // injectWebviewOverlay
785- . mockResolvedValueOnce ( undefined ) // executeNativeClick (center)
786- . mockResolvedValueOnce ( zeroOverlay ) // getMobileWebviewClickAndDimensions
787- . mockResolvedValueOnce ( undefined ) // dismissal tap
788- // --- Attempt 2 ---
789- . mockResolvedValueOnce ( undefined ) // loadBase64Html
790- . mockResolvedValueOnce ( undefined ) // injectWebviewOverlay
791- . mockResolvedValueOnce ( undefined ) // executeNativeClick (center)
792- . mockResolvedValueOnce ( zeroOverlay ) // getMobileWebviewClickAndDimensions
793- . mockResolvedValueOnce ( undefined ) // dismissal tap
794- // --- Attempt 3 (last, no dismissal after) ---
795- . mockResolvedValueOnce ( undefined ) // loadBase64Html
796- . mockResolvedValueOnce ( undefined ) // injectWebviewOverlay
797- . mockResolvedValueOnce ( undefined ) // executeNativeClick (center)
798- . mockResolvedValueOnce ( zeroOverlay ) // getMobileWebviewClickAndDimensions
777+ const attemptMocks = ( ) => [
778+ undefined , // loadBase64Html
779+ undefined , // injectWebviewOverlay
780+ undefined , // executeNativeClick (center)
781+ zeroOverlay , // getMobileWebviewClickAndDimensions
782+ ]
783+ const mocked = vi . mocked ( mockBrowserInstance . execute )
784+ // 5 attempts: attempts 1-4 have Back button dismissal, last attempt has none
785+ for ( let i = 0 ; i < 5 ; i ++ ) {
786+ for ( const val of attemptMocks ( ) ) { mocked . mockResolvedValueOnce ( val ) }
787+ if ( i < 4 ) {
788+ mocked . mockResolvedValueOnce ( undefined ) // mobile: pressKey (Back button)
789+ }
790+ }
799791
800792 const result = await getMobileViewPortPosition ( {
801793 browserInstance : mockBrowserInstance ,
@@ -804,15 +796,14 @@ describe('utils', () => {
804796 isIOS : false ,
805797 } )
806798
807- expect ( warnSpy ) . toHaveBeenCalledTimes ( 3 )
799+ expect ( warnSpy ) . toHaveBeenCalledTimes ( 5 )
808800 expect ( errorSpy ) . toHaveBeenCalledWith (
809- expect . stringContaining ( 'Viewport measurement failed after 3 attempts' )
801+ expect . stringContaining ( 'Viewport measurement failed after 5 attempts' )
810802 )
811803 expect ( mockBrowserInstance . url ) . toHaveBeenCalledWith ( 'http://example.com' )
812804 expect ( result ) . toEqual ( DEVICE_RECTANGLES )
813805
814806 warnSpy . mockRestore ( )
815- infoSpy . mockRestore ( )
816807 errorSpy . mockRestore ( )
817808 } )
818809
@@ -825,6 +816,7 @@ describe('utils', () => {
825816 . mockResolvedValueOnce ( undefined ) // injectWebviewOverlay
826817 . mockResolvedValueOnce ( undefined ) // executeNativeClick (center, 'mobile: tap')
827818 . mockResolvedValueOnce ( { x : 0 , y : 0 , width : 0 , height : 0 } ) // getMobileWebviewClickAndDimensions
819+ . mockResolvedValueOnce ( { vs : 'visible' , focus : true } ) // visibilityState debug check
828820
829821 const result = await getMobileViewPortPosition ( {
830822 browserInstance : mockBrowserInstance ,
0 commit comments