⋯ 185 lines Show the 185 lines above this hunk @@ -186,21 +186,35 @@ class NativeMapTest { 186 186 assertEquals ( 3 , features ( map ) . size ) 187 187 } 188 188 189 - val location = main { 190 - val screen = map . projection . toScreenLocation ( LatLng ( 47.0 , 11.0 ) ) 191 - val origin = IntArray ( 2 ) . also { host . getLocationOnScreen ( it ) } 192 - ( screen . x . toInt ( ) + origin [ 0 ] ) to ( screen . y . toInt ( ) + origin [ 1 ] ) 189 + 190 + 191 + 192 + val deadline = SystemClock . uptimeMillis ( ) + 45 _000 193 + var location : Pair < Int , Int > ? = null 194 + var lastPixel = Color . TRANSPARENT 195 + while ( SystemClock . uptimeMillis ( ) < deadline & & location = = null ) { 196 + val candidate = main { 197 + val screen = map . projection . toScreenLocation ( LatLng ( 47.0 , 11.0 ) ) 198 + val origin = IntArray ( 2 ) . also { host . getLocationOnScreen ( it ) } 199 + ( screen . x . toInt ( ) + origin [ 0 ] ) to ( screen . y . toInt ( ) + origin [ 1 ] ) 200 + } 201 + val image = instrumentation . uiAutomation . takeScreenshot ( ) ? : throw AssertionError ( "Native screenshot unavailable" ) 202 + try { 203 + lastPixel = image . getPixel ( candidate . first , candidate . second ) 204 + if ( kotlin . math . abs ( Color . red ( lastPixel ) - 40 ) < = 8 & & 205 + kotlin . math . abs ( Color . green ( lastPixel ) - 120 ) < = 8 & & 206 + kotlin . math . abs ( Color . blue ( lastPixel ) - 200 ) < = 8 ) location = candidate 207 + } finally { image . recycle ( ) } 208 + if ( location = = null ) SystemClock . sleep ( 100 ) 193 209 } 194 - val image = instrumentation . uiAutomation . takeScreenshot ( ) ? : throw AssertionError ( "Native screenshot unavailable" ) 195 - try { 196 - val pixel = image . getPixel ( location . first , location . second ) 197 - assertEquals ( 40 .0 , Color . red ( pixel ) . toDouble ( ) , 8.0 ) 198 - assertEquals ( 120.0 , Color . green ( pixel ) . toDouble ( ) , 8.0 ) 199 - assertEquals ( 200.0 , Color . blue ( pixel ) . toDouble ( ) , 8.0 ) 200 - } finally { image . recycle ( ) } 210 + if ( location = = null ) evidence ( "map-mutated-pin-not-visible" ) 211 + assertEquals ( "The compositor must show the new pin red channel" , 40.0 , Color . red ( lastPixel ) . toDouble ( ) , 8.0 ) 212 + assertEquals ( "The compositor must show the new pin green channel" , 120.0 , Color . green ( lastPixel ) . toDouble ( ) , 8.0 ) 213 + assertEquals ( "The compositor must show the new pin blue channel" , 200 .0 , Color . blue ( lastPixel ) . toDouble ( ) , 8.0 ) 214 + val tap = location ? : throw AssertionError ( "The updated native pin was never visible" ) 201 215 val downAt = SystemClock . uptimeMillis ( ) 202 216 for ( action in listOf ( android . view . MotionEvent . ACTION_DOWN , android . view . MotionEvent . ACTION_UP ) ) { 203 - val touch = android . view . MotionEvent . obtain ( downAt , SystemClock . uptimeMillis ( ) , action , location . first . toFloat ( ) , location . second . toFloat ( ) , 0 ) 217 + val touch = android . view . MotionEvent . obtain ( downAt , SystemClock . uptimeMillis ( ) , action , tap . first . toFloat ( ) , tap . second . toFloat ( ) , 0 ) 204 218 try { assertTrue ( instrumentation . uiAutomation . injectInputEvent ( touch , true ) ) } finally { touch . recycle ( ) } 205 219 } 206 220 awaitState ( "Tapping the actual native pin must dispatch its stable marker ID" ) { pressed . get ( ) = = "start" }