⋯ 72 lines Show the 72 lines above this hunk @@ -73,6 +73,31 @@ class NativeMapTest { 73 73 image . recycle ( ) 74 74 } 75 75 76 + private fun awaitBasemapPixels ( host : CraftNativeMapView , label : String ) { 77 + val deadline = SystemClock . uptimeMillis ( ) + 45 _000 78 + do { 79 + val bounds = main { 80 + val origin = IntArray ( 2 ) . also { host . getLocationOnScreen ( it ) } 81 + intArrayOf ( origin [ 0 ] , origin [ 1 ] , host . width , host . height ) 82 + } 83 + val image = instrumentation . uiAutomation . takeScreenshot ( ) ? : throw AssertionError ( "Native screenshot unavailable" ) 84 + val visible = try { 85 + 86 + 87 + var painted = 0 88 + for ( row in 1. . 8 ) for ( column in 1. . 8 ) { 89 + val pixel = image . getPixel ( bounds [ 0 ] + bounds [ 2 ] * column / 9 , bounds [ 1 ] + bounds [ 3 ] * row / 9 ) 90 + if ( Color . red ( pixel ) + Color . green ( pixel ) + Color . blue ( pixel ) > 60 ) painted + + 91 + } 92 + painted > = 58 93 + } finally { image . recycle ( ) } 94 + if ( visible ) return 95 + SystemClock . sleep ( 100 ) 96 + } while ( SystemClock . uptimeMillis ( ) < deadline ) 97 + evidence ( "$label-basemap-not-visible" ) 98 + fail ( "$label did not paint native basemap tiles across the viewport" ) 99 + } 100 + 76 101 private fun withMap ( block : ( MainActivity , CraftNativeMapView , MapView , MapLibreMap , AtomicInteger ) - > Unit ) { 77 102 val activity = instrumentation . startActivitySync ( Intent ( instrumentation . targetContext , MainActivity : : class . java ) 78 103 . addFlags ( Intent . FLAG_ACTIVITY_NEW_TASK or Intent . FLAG_ACTIVITY_CLEAR_TASK ) ) as MainActivity ⋯ 25 lines Show the 25 lines above this hunk @@ -104,10 +129,13 @@ class NativeMapTest { 104 129 } 105 130 106 131 @ Test 107 - fun keyFreeBasemapsKeepTheRecordedRouteAndDirectionSignsVisible ( ) = withMap { _ , host , _ , map , loaded - > 132 + fun keyFreeBasemapsKeepTheRecordedRouteAndDirectionSignsVisible ( ) = withMap { _ , host , widget , map , loaded - > 108 133 for ( type in listOf ( "outdoors" , "standard" , "satellite" , "hybrid" ) ) { 109 134 val before = loaded . get ( ) 135 + val rendered = AtomicInteger ( ) 136 + val listener = MapView . OnDidFinishRenderingFrameListener { fully , _ , _ - > if ( fully ) rendered . incrementAndGet ( ) } 110 137 main { 138 + widget . addOnDidFinishRenderingFrameListener ( listener ) 111 139 val options = props ( ) . put ( "mapType" , if ( type = = "outdoors" ) "standard" else type ) 112 140 if ( type = = "outdoors" ) options . put ( "tileOverlay" , JSONObject ( ) 113 141 . put ( "urlTemplate" , "https://server.arcgisonline.com/ArcGIS/rest/services/World_Topo_Map/MapServer/tile/{z}/{y}/{x}" ) ⋯ 1 line Show the 1 line above this hunk @@ -115,9 +143,11 @@ class NativeMapTest { 115 143 host . configure ( options , overlays ( ) ) { } 116 144 } 117 145 awaitState ( "$type did not finish loading its real native basemap" ) { 118 - loaded . get ( ) > before & & features ( map ) . size = = 3 & & 146 + loaded . get ( ) > before & & rendered . get ( ) > 0 & & features ( map ) . size = = 3 & & 119 147 map . queryRenderedFeatures ( map . projection . toScreenLocation ( LatLng ( 47.005 , 11.005 ) ) , "craft-map-directions" ) . isNotEmpty ( ) 120 148 } 149 + awaitBasemapPixels ( host , type ) 150 + main { widget . removeOnDidFinishRenderingFrameListener ( listener ) } 121 151 main { 122 152 val start = features ( map ) . first { it . getStringProperty ( "craftOverlayId" ) = = "start" } . geometry ( ) as Point 123 153 assertEquals ( 47.0 , start . latitude ( ) , 0.000001 ) ⋯ 21 lines Show the 21 lines above this hunk @@ -145,6 +175,7 @@ class NativeMapTest { 145 175 kotlin . math . abs ( map . cameraPosition . bearing - 90 ) < 1 & & kotlin . math . abs ( map . cameraPosition . tilt - 30 ) < 1 & & 146 176 map . queryRenderedFeatures ( map . projection . toScreenLocation ( LatLng ( 47.0 , 11.0 ) ) , "craft-map-markers" ) . any { it . getStringProperty ( "color" ) = = "rgba(40,120,200,1.0)" } 147 177 } 178 + awaitBasemapPixels ( host , "mutated-map" ) 148 179 main { 149 180 assertSame ( "Overlay updates must not reload the native basemap" , style , map . style ) 150 181 assertTrue ( map . uiSettings . isTiltGesturesEnabled )