[android] use #onDidBecomeIdle event instead of layer querying during instrumentation tests
This commit is contained in:
committed by
Łukasz Paczos
parent
fbbc83aa0e
commit
ca7d9422b6
@@ -16,19 +16,18 @@ import android.support.test.runner.AndroidJUnit4
|
||||
import android.support.v4.content.ContextCompat
|
||||
import com.mapbox.geojson.Point
|
||||
import com.mapbox.mapboxsdk.camera.CameraUpdateFactory
|
||||
import com.mapbox.mapboxsdk.maps.Style
|
||||
import com.mapbox.mapboxsdk.geometry.LatLng
|
||||
import com.mapbox.mapboxsdk.location.LocationComponentConstants.*
|
||||
import com.mapbox.mapboxsdk.location.modes.CameraMode
|
||||
import com.mapbox.mapboxsdk.location.modes.RenderMode
|
||||
import com.mapbox.mapboxsdk.location.utils.*
|
||||
import com.mapbox.mapboxsdk.location.utils.MapboxTestingUtils.Companion.MAPBOX_HEAVY_STYLE
|
||||
import com.mapbox.mapboxsdk.location.utils.MapboxTestingUtils.Companion.MAP_CONNECTION_DELAY
|
||||
import com.mapbox.mapboxsdk.location.utils.MapboxTestingUtils.Companion.MAP_RENDER_DELAY
|
||||
import com.mapbox.mapboxsdk.location.utils.MapboxTestingUtils.Companion.pushSourceUpdates
|
||||
import com.mapbox.mapboxsdk.maps.MapboxMap
|
||||
import com.mapbox.mapboxsdk.maps.Style
|
||||
import com.mapbox.mapboxsdk.testapp.activity.EspressoTest
|
||||
import com.mapbox.mapboxsdk.testapp.activity.espresso.EspressoTestActivity
|
||||
import com.mapbox.mapboxsdk.testapp.utils.TestingAsyncUtils
|
||||
import com.mapbox.mapboxsdk.utils.ColorUtils
|
||||
import org.hamcrest.CoreMatchers.*
|
||||
import org.junit.*
|
||||
@@ -55,7 +54,7 @@ class LocationComponentTest : EspressoTest() {
|
||||
|
||||
override fun validateTestSetup() {
|
||||
super.validateTestSetup()
|
||||
assertThat(mapboxMap.getStyle(), notNullValue())
|
||||
assertThat(mapboxMap.style, notNullValue())
|
||||
}
|
||||
|
||||
@Before
|
||||
@@ -70,14 +69,14 @@ class LocationComponentTest : EspressoTest() {
|
||||
validateTestSetup()
|
||||
val componentAction = object : LocationComponentAction.OnPerformLocationComponentAction {
|
||||
override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap,
|
||||
uiController: UiController, context: Context) {
|
||||
component.activateLocationComponent(context, mapboxMap.style!!)
|
||||
style: Style, uiController: UiController, context: Context) {
|
||||
component.activateLocationComponent(context, style)
|
||||
component.isLocationComponentEnabled = true
|
||||
|
||||
val locationEngine = component.locationEngine
|
||||
assertThat(locationEngine, notNullValue())
|
||||
|
||||
uiController.loopMainThreadForAtLeast(MAP_CONNECTION_DELAY)
|
||||
TestingAsyncUtils.waitForLayer(uiController, idlingResource.mapView)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -89,10 +88,10 @@ class LocationComponentTest : EspressoTest() {
|
||||
validateTestSetup()
|
||||
val componentAction = object : LocationComponentAction.OnPerformLocationComponentAction {
|
||||
override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap,
|
||||
uiController: UiController, context: Context) {
|
||||
style: Style, uiController: UiController, context: Context) {
|
||||
component.activateLocationComponent(
|
||||
context,
|
||||
mapboxMap.style!!,
|
||||
style,
|
||||
LocationComponentOptions.builder(context)
|
||||
.staleStateTimeout(200)
|
||||
.enableStaleState(false)
|
||||
@@ -107,7 +106,7 @@ class LocationComponentTest : EspressoTest() {
|
||||
assertThat(locationEngine, notNullValue())
|
||||
assertThat(componentOptions, notNullValue())
|
||||
|
||||
uiController.loopMainThreadForAtLeast(MAP_CONNECTION_DELAY)
|
||||
TestingAsyncUtils.waitForLayer(uiController, idlingResource.mapView)
|
||||
assertThat(componentOptions?.accuracyAlpha(), `is`(.5f))
|
||||
assertThat(componentOptions?.accuracyColor(), `is`(Color.BLUE))
|
||||
}
|
||||
@@ -121,10 +120,10 @@ class LocationComponentTest : EspressoTest() {
|
||||
validateTestSetup()
|
||||
val componentAction = object : LocationComponentAction.OnPerformLocationComponentAction {
|
||||
override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap,
|
||||
uiController: UiController, context: Context) {
|
||||
style: Style, uiController: UiController, context: Context) {
|
||||
component.activateLocationComponent(
|
||||
context,
|
||||
mapboxMap.style!!,
|
||||
style,
|
||||
null,
|
||||
LocationComponentOptions.builder(context)
|
||||
.staleStateTimeout(200)
|
||||
@@ -140,7 +139,7 @@ class LocationComponentTest : EspressoTest() {
|
||||
assertThat(locationEngine, nullValue())
|
||||
assertThat(componentOptions, notNullValue())
|
||||
|
||||
uiController.loopMainThreadForAtLeast(MAP_CONNECTION_DELAY)
|
||||
TestingAsyncUtils.waitForLayer(uiController, idlingResource.mapView)
|
||||
assertThat(componentOptions?.accuracyAlpha(), `is`(.5f))
|
||||
assertThat(componentOptions?.accuracyColor(), `is`(Color.BLUE))
|
||||
}
|
||||
@@ -150,24 +149,13 @@ class LocationComponentTest : EspressoTest() {
|
||||
}
|
||||
|
||||
@Test(expected = IllegalStateException::class)
|
||||
fun settingMapStyleImmediatelyBeforeLoadingComponent_doesStillLoadLayersProperly() {
|
||||
fun settingMapStyleImmediatelyBeforeLoadingComponent_throwsInvalidStyle() {
|
||||
validateTestSetup()
|
||||
val componentAction = object : LocationComponentAction.OnPerformLocationComponentAction {
|
||||
override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap,
|
||||
uiController: UiController, context: Context) {
|
||||
|
||||
val style = mapboxMap.style!!
|
||||
style: Style, uiController: UiController, context: Context) {
|
||||
mapboxMap.setStyle(Style.Builder().fromUrl(Style.LIGHT))
|
||||
component.activateLocationComponent(context, style,false)
|
||||
component.isLocationComponentEnabled = true
|
||||
component.forceLocationUpdate(location)
|
||||
mapboxMap.waitForLayer(uiController, location, FOREGROUND_LAYER)
|
||||
|
||||
assertThat(component.renderMode, `is`(equalTo(RenderMode.NORMAL)))
|
||||
assertThat(mapboxMap.isLayerVisible(FOREGROUND_LAYER), `is`(true))
|
||||
assertThat(mapboxMap.isLayerVisible(BACKGROUND_LAYER), `is`(true))
|
||||
assertThat(mapboxMap.isLayerVisible(SHADOW_LAYER), `is`(true))
|
||||
assertThat(mapboxMap.isLayerVisible(BEARING_LAYER), `is`(false))
|
||||
component.activateLocationComponent(context, style, false)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -179,8 +167,8 @@ class LocationComponentTest : EspressoTest() {
|
||||
validateTestSetup()
|
||||
val componentAction = object : LocationComponentAction.OnPerformLocationComponentAction {
|
||||
override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap,
|
||||
uiController: UiController, context: Context) {
|
||||
component.activateLocationComponent(context, mapboxMap.style!!,false)
|
||||
style: Style, uiController: UiController, context: Context) {
|
||||
component.activateLocationComponent(context, style, false)
|
||||
component.isLocationComponentEnabled = true
|
||||
|
||||
// Source should be present but empty
|
||||
@@ -191,7 +179,7 @@ class LocationComponentTest : EspressoTest() {
|
||||
|
||||
// Force the first location update
|
||||
component.forceLocationUpdate(location)
|
||||
mapboxMap.waitForLayer(uiController, location, FOREGROUND_LAYER)
|
||||
TestingAsyncUtils.waitForLayer(uiController, idlingResource.mapView)
|
||||
|
||||
// Check if the puck is visible
|
||||
assertThat(mapboxMap.queryRenderedFeatures(location, FOREGROUND_LAYER).isEmpty(), `is`(false))
|
||||
@@ -209,9 +197,9 @@ class LocationComponentTest : EspressoTest() {
|
||||
validateTestSetup()
|
||||
val componentAction = object : LocationComponentAction.OnPerformLocationComponentAction {
|
||||
override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap,
|
||||
uiController: UiController, context: Context) {
|
||||
style: Style, uiController: UiController, context: Context) {
|
||||
component.activateLocationComponent(context,
|
||||
mapboxMap.style!!,
|
||||
style,
|
||||
null,
|
||||
LocationComponentOptions.builder(context)
|
||||
.staleStateTimeout(200)
|
||||
@@ -220,12 +208,11 @@ class LocationComponentTest : EspressoTest() {
|
||||
component.isLocationComponentEnabled = true
|
||||
|
||||
component.forceLocationUpdate(location)
|
||||
mapboxMap.waitForLayer(uiController, location, FOREGROUND_LAYER)
|
||||
uiController.loopMainThreadForAtLeast(500)
|
||||
TestingAsyncUtils.waitForLayer(uiController, idlingResource.mapView)
|
||||
uiController.loopMainThreadForAtLeast(300) // waiting for stale state
|
||||
|
||||
mapboxMap.waitForSource(uiController, LOCATION_SOURCE)
|
||||
mapboxMap.querySourceFeatures(LOCATION_SOURCE).also {
|
||||
it.forEach {
|
||||
mapboxMap.querySourceFeatures(LOCATION_SOURCE).also { feature ->
|
||||
feature.forEach {
|
||||
assertThat(it.getBooleanProperty(PROPERTY_LOCATION_STALE), `is`(false))
|
||||
}
|
||||
}
|
||||
@@ -240,9 +227,9 @@ class LocationComponentTest : EspressoTest() {
|
||||
validateTestSetup()
|
||||
val componentAction = object : LocationComponentAction.OnPerformLocationComponentAction {
|
||||
override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap,
|
||||
uiController: UiController, context: Context) {
|
||||
style: Style, uiController: UiController, context: Context) {
|
||||
component.activateLocationComponent(context,
|
||||
mapboxMap.style!!,
|
||||
style,
|
||||
null,
|
||||
LocationComponentOptions.builder(context)
|
||||
.foregroundName("custom-foreground-bitmap")
|
||||
@@ -263,11 +250,10 @@ class LocationComponentTest : EspressoTest() {
|
||||
}
|
||||
|
||||
component.forceLocationUpdate(location)
|
||||
mapboxMap.waitForLayer(uiController, location, FOREGROUND_LAYER)
|
||||
assertThat(mapboxMap.queryRenderedFeatures(location, FOREGROUND_LAYER).isEmpty(), `is`(false))
|
||||
|
||||
mapboxMap.waitForSource(uiController, LOCATION_SOURCE)
|
||||
TestingAsyncUtils.waitForLayer(uiController, idlingResource.mapView)
|
||||
val feature = mapboxMap.querySourceFeatures(LOCATION_SOURCE)[0]
|
||||
|
||||
assertThat(mapboxMap.queryRenderedFeatures(location, FOREGROUND_LAYER).isEmpty(), `is`(false))
|
||||
assertThat(feature.getStringProperty(PROPERTY_FOREGROUND_ICON), `is`(equalTo("custom-foreground-bitmap")))
|
||||
assertThat(feature.getStringProperty(PROPERTY_BACKGROUND_ICON), `is`(equalTo("custom-background-bitmap")))
|
||||
assertThat(feature.getStringProperty(PROPERTY_FOREGROUND_STALE_ICON), `is`(equalTo("custom-foreground-stale-bitmap")))
|
||||
@@ -284,9 +270,9 @@ class LocationComponentTest : EspressoTest() {
|
||||
validateTestSetup()
|
||||
val componentAction = object : LocationComponentAction.OnPerformLocationComponentAction {
|
||||
override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap,
|
||||
uiController: UiController, context: Context) {
|
||||
style: Style, uiController: UiController, context: Context) {
|
||||
component.activateLocationComponent(context,
|
||||
mapboxMap.style!!,
|
||||
style,
|
||||
null,
|
||||
LocationComponentOptions.builder(context)
|
||||
.foregroundName("custom-foreground-bitmap")
|
||||
@@ -296,14 +282,14 @@ class LocationComponentTest : EspressoTest() {
|
||||
|
||||
component.renderMode = RenderMode.GPS
|
||||
component.forceLocationUpdate(location)
|
||||
mapboxMap.waitForLayer(uiController, location, FOREGROUND_LAYER)
|
||||
val foregroundDrawable = ContextCompat.getDrawable(context, R.drawable.ic_media_play)
|
||||
foregroundDrawable?.let {
|
||||
mapboxMap.addImageFromDrawable("custom-foreground-bitmap", it)
|
||||
mapboxMap.addImageFromDrawable("custom-gps-bitmap", it)
|
||||
}
|
||||
mapboxMap.waitForLayer(uiController, location, FOREGROUND_LAYER)
|
||||
TestingAsyncUtils.waitForLayer(uiController, idlingResource.mapView)
|
||||
val foregroundId = mapboxMap.querySourceFeatures(LOCATION_SOURCE)[0].getStringProperty(PROPERTY_FOREGROUND_ICON)
|
||||
|
||||
assertThat(foregroundId, `is`(equalTo("custom-gps-bitmap")))
|
||||
}
|
||||
}
|
||||
@@ -316,9 +302,9 @@ class LocationComponentTest : EspressoTest() {
|
||||
validateTestSetup()
|
||||
val componentAction = object : LocationComponentAction.OnPerformLocationComponentAction {
|
||||
override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap,
|
||||
uiController: UiController, context: Context) {
|
||||
style: Style, uiController: UiController, context: Context) {
|
||||
component.activateLocationComponent(context,
|
||||
mapboxMap.style!!,
|
||||
style,
|
||||
null,
|
||||
LocationComponentOptions.builder(context)
|
||||
.foregroundName("custom-foreground-bitmap")
|
||||
@@ -328,20 +314,15 @@ class LocationComponentTest : EspressoTest() {
|
||||
|
||||
component.renderMode = RenderMode.GPS
|
||||
component.forceLocationUpdate(location)
|
||||
mapboxMap.waitForLayer(uiController, location, FOREGROUND_LAYER)
|
||||
TestingAsyncUtils.waitForLayer(uiController, idlingResource.mapView)
|
||||
|
||||
mapboxMap.waitForSource(uiController, LOCATION_SOURCE)
|
||||
val foregroundId = mapboxMap.querySourceFeatures(LOCATION_SOURCE)[0].getStringProperty(PROPERTY_FOREGROUND_ICON)
|
||||
assertThat(foregroundId, `is`(equalTo("custom-gps-bitmap")))
|
||||
|
||||
component.applyStyle(LocationComponentOptions.builder(context).build())
|
||||
TestingAsyncUtils.waitForLayer(uiController, idlingResource.mapView)
|
||||
|
||||
val renderCheck = {
|
||||
mapboxMap.waitForSource(uiController, LOCATION_SOURCE)
|
||||
mapboxMap.querySourceFeatures(LOCATION_SOURCE)[0].getStringProperty(PROPERTY_FOREGROUND_ICON) == FOREGROUND_ICON
|
||||
}
|
||||
waitForRenderResult(uiController, renderCheck, true)
|
||||
assertThat(renderCheck.invoke(), `is`(true))
|
||||
assertEquals(FOREGROUND_ICON, mapboxMap.querySourceFeatures(LOCATION_SOURCE)[0].getStringProperty(PROPERTY_FOREGROUND_ICON))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -353,10 +334,9 @@ class LocationComponentTest : EspressoTest() {
|
||||
validateTestSetup()
|
||||
val componentAction = object : LocationComponentAction.OnPerformLocationComponentAction {
|
||||
override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap,
|
||||
uiController: UiController, context: Context) {
|
||||
|
||||
style: Style, uiController: UiController, context: Context) {
|
||||
component.activateLocationComponent(context,
|
||||
mapboxMap.style!!,
|
||||
style,
|
||||
null,
|
||||
LocationComponentOptions.builder(context)
|
||||
.gpsName("custom-gps-bitmap")
|
||||
@@ -365,20 +345,15 @@ class LocationComponentTest : EspressoTest() {
|
||||
|
||||
component.renderMode = RenderMode.GPS
|
||||
component.forceLocationUpdate(location)
|
||||
mapboxMap.waitForLayer(uiController, location, FOREGROUND_LAYER)
|
||||
TestingAsyncUtils.waitForLayer(uiController, idlingResource.mapView)
|
||||
|
||||
mapboxMap.waitForSource(uiController, LOCATION_SOURCE)
|
||||
val foregroundId = mapboxMap.querySourceFeatures(LOCATION_SOURCE)[0].getStringProperty(PROPERTY_FOREGROUND_ICON)
|
||||
assertThat(foregroundId, `is`(equalTo("custom-gps-bitmap")))
|
||||
|
||||
component.renderMode = RenderMode.NORMAL
|
||||
TestingAsyncUtils.waitForLayer(uiController, idlingResource.mapView)
|
||||
|
||||
val renderCheck = {
|
||||
mapboxMap.waitForSource(uiController, LOCATION_SOURCE)
|
||||
mapboxMap.querySourceFeatures(LOCATION_SOURCE)[0].getStringProperty(PROPERTY_FOREGROUND_ICON) == FOREGROUND_ICON
|
||||
}
|
||||
waitForRenderResult(uiController, renderCheck, true)
|
||||
assertThat(renderCheck.invoke(), `is`(true))
|
||||
assertEquals(FOREGROUND_ICON, mapboxMap.querySourceFeatures(LOCATION_SOURCE)[0].getStringProperty(PROPERTY_FOREGROUND_ICON))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -390,9 +365,9 @@ class LocationComponentTest : EspressoTest() {
|
||||
validateTestSetup()
|
||||
val componentAction = object : LocationComponentAction.OnPerformLocationComponentAction {
|
||||
override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap,
|
||||
uiController: UiController, context: Context) {
|
||||
style: Style, uiController: UiController, context: Context) {
|
||||
component.activateLocationComponent(context,
|
||||
mapboxMap.style!!,
|
||||
style,
|
||||
null,
|
||||
LocationComponentOptions.builder(context)
|
||||
.staleStateTimeout(200)
|
||||
@@ -400,21 +375,15 @@ class LocationComponentTest : EspressoTest() {
|
||||
component.isLocationComponentEnabled = true
|
||||
|
||||
component.forceLocationUpdate(location)
|
||||
mapboxMap.waitForLayer(uiController, location, FOREGROUND_LAYER)
|
||||
TestingAsyncUtils.waitForLayer(uiController, idlingResource.mapView)
|
||||
uiController.loopMainThreadForAtLeast(250) // engaging stale state
|
||||
|
||||
val renderCheck = {
|
||||
mapboxMap.waitForSource(uiController, LOCATION_SOURCE)
|
||||
mapboxMap.querySourceFeatures(LOCATION_SOURCE)[0].getBooleanProperty(PROPERTY_LOCATION_STALE)
|
||||
}
|
||||
waitForRenderResult(uiController, renderCheck, true)
|
||||
assertThat(renderCheck.invoke(), `is`(true))
|
||||
assertThat(mapboxMap.querySourceFeatures(LOCATION_SOURCE)[0].getBooleanProperty(PROPERTY_LOCATION_STALE), `is`(true))
|
||||
|
||||
component.onStop()
|
||||
component.onStart()
|
||||
mapboxMap.waitForLayer(uiController, location, FOREGROUND_LAYER)
|
||||
TestingAsyncUtils.waitForLayer(uiController, idlingResource.mapView)
|
||||
|
||||
mapboxMap.waitForSource(uiController, LOCATION_SOURCE)
|
||||
assertThat(mapboxMap.querySourceFeatures(LOCATION_SOURCE)[0].getBooleanProperty(PROPERTY_LOCATION_STALE), `is`(true))
|
||||
assertThat(mapboxMap.isLayerVisible(ACCURACY_LAYER), `is`(false))
|
||||
}
|
||||
@@ -428,20 +397,18 @@ class LocationComponentTest : EspressoTest() {
|
||||
validateTestSetup()
|
||||
val componentAction = object : LocationComponentAction.OnPerformLocationComponentAction {
|
||||
override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap,
|
||||
uiController: UiController, context: Context) {
|
||||
component.activateLocationComponent(context, mapboxMap.style!!, false)
|
||||
style: Style, uiController: UiController, context: Context) {
|
||||
component.activateLocationComponent(context, style, false)
|
||||
component.isLocationComponentEnabled = true
|
||||
component.forceLocationUpdate(location)
|
||||
mapboxMap.waitForLayer(uiController, location, FOREGROUND_LAYER)
|
||||
TestingAsyncUtils.waitForLayer(uiController, idlingResource.mapView)
|
||||
|
||||
mapboxMap.waitForSource(uiController, LOCATION_SOURCE)
|
||||
assertThat(mapboxMap.querySourceFeatures(LOCATION_SOURCE)[0].getBooleanProperty(PROPERTY_LOCATION_STALE), `is`(false))
|
||||
|
||||
component.onStop()
|
||||
component.onStart()
|
||||
mapboxMap.waitForLayer(uiController, location, FOREGROUND_LAYER)
|
||||
TestingAsyncUtils.waitForLayer(uiController, idlingResource.mapView)
|
||||
|
||||
mapboxMap.waitForSource(uiController, LOCATION_SOURCE)
|
||||
assertThat(mapboxMap.querySourceFeatures(LOCATION_SOURCE)[0].getBooleanProperty(PROPERTY_LOCATION_STALE), `is`(false))
|
||||
assertThat(mapboxMap.isLayerVisible(ACCURACY_LAYER), `is`(true))
|
||||
}
|
||||
@@ -457,9 +424,9 @@ class LocationComponentTest : EspressoTest() {
|
||||
|
||||
val componentAction = object : LocationComponentAction.OnPerformLocationComponentAction {
|
||||
override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap,
|
||||
uiController: UiController, context: Context) {
|
||||
style: Style, uiController: UiController, context: Context) {
|
||||
component.activateLocationComponent(context,
|
||||
mapboxMap.style!!,
|
||||
style,
|
||||
null,
|
||||
LocationComponentOptions.builder(context)
|
||||
.accuracyColor(color)
|
||||
@@ -467,12 +434,10 @@ class LocationComponentTest : EspressoTest() {
|
||||
component.isLocationComponentEnabled = true
|
||||
|
||||
component.forceLocationUpdate(location)
|
||||
mapboxMap.waitForLayer(uiController, location, FOREGROUND_LAYER)
|
||||
TestingAsyncUtils.waitForLayer(uiController, idlingResource.mapView)
|
||||
|
||||
// Check that the source property changes correctly
|
||||
mapboxMap.waitForSource(uiController, LOCATION_SOURCE)
|
||||
mapboxMap.querySourceFeatures(LOCATION_SOURCE).also {
|
||||
it.forEach {
|
||||
mapboxMap.querySourceFeatures(LOCATION_SOURCE).also { feature ->
|
||||
feature.forEach {
|
||||
assertThat(it.getStringProperty(PROPERTY_ACCURACY_COLOR), `is`(equalTo(rgbaColor)))
|
||||
}
|
||||
}
|
||||
@@ -487,15 +452,13 @@ class LocationComponentTest : EspressoTest() {
|
||||
validateTestSetup()
|
||||
val componentAction = object : LocationComponentAction.OnPerformLocationComponentAction {
|
||||
override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap,
|
||||
uiController: UiController, context: Context) {
|
||||
component.activateLocationComponent(context, mapboxMap.style!!,false)
|
||||
style: Style, uiController: UiController, context: Context) {
|
||||
component.activateLocationComponent(context, style, false)
|
||||
component.isLocationComponentEnabled = true
|
||||
component.forceLocationUpdate(location)
|
||||
mapboxMap.waitForLayer(uiController, location, FOREGROUND_LAYER)
|
||||
TestingAsyncUtils.waitForLayer(uiController, idlingResource.mapView)
|
||||
|
||||
mapboxMap.waitForSource(uiController, LOCATION_SOURCE)
|
||||
val point: Point = mapboxMap.querySourceFeatures(LOCATION_SOURCE)[0].geometry() as Point
|
||||
|
||||
assertThat(component.locationEngine, nullValue())
|
||||
assertEquals(point.latitude(), location.latitude, 0.1)
|
||||
assertEquals(point.longitude(), location.longitude, 0.1)
|
||||
@@ -509,18 +472,18 @@ class LocationComponentTest : EspressoTest() {
|
||||
validateTestSetup()
|
||||
val componentAction = object : LocationComponentAction.OnPerformLocationComponentAction {
|
||||
override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap,
|
||||
uiController: UiController, context: Context) {
|
||||
component.activateLocationComponent(context, mapboxMap.style!!,false)
|
||||
style: Style, uiController: UiController, context: Context) {
|
||||
component.activateLocationComponent(context, style, false)
|
||||
component.isLocationComponentEnabled = true
|
||||
component.forceLocationUpdate(location)
|
||||
mapboxMap.waitForLayer(uiController, location, FOREGROUND_LAYER)
|
||||
TestingAsyncUtils.waitForLayer(uiController, idlingResource.mapView)
|
||||
|
||||
val point: Point = mapboxMap.queryRenderedFeatures(location, FOREGROUND_LAYER)[0].geometry() as Point
|
||||
assertEquals(point.latitude(), location.latitude, 0.1)
|
||||
assertEquals(point.longitude(), location.longitude, 0.1)
|
||||
|
||||
component.isLocationComponentEnabled = false
|
||||
mapboxMap.waitForLayer(uiController, location, FOREGROUND_LAYER, true)
|
||||
TestingAsyncUtils.waitForLayer(uiController, idlingResource.mapView)
|
||||
assertThat(mapboxMap.queryRenderedFeatures(location, FOREGROUND_LAYER).isEmpty(), `is`(true))
|
||||
}
|
||||
}
|
||||
@@ -532,17 +495,15 @@ class LocationComponentTest : EspressoTest() {
|
||||
validateTestSetup()
|
||||
val componentAction = object : LocationComponentAction.OnPerformLocationComponentAction {
|
||||
override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap,
|
||||
uiController: UiController, context: Context) {
|
||||
component.activateLocationComponent(context, mapboxMap.style!!, false)
|
||||
style: Style, uiController: UiController, context: Context) {
|
||||
component.activateLocationComponent(context, style, false)
|
||||
component.isLocationComponentEnabled = true
|
||||
component.forceLocationUpdate(location)
|
||||
mapboxMap.waitForLayer(uiController, location, FOREGROUND_LAYER)
|
||||
|
||||
component.isLocationComponentEnabled = false
|
||||
mapboxMap.setStyle(Style.Builder().fromUrl(Style.LIGHT))
|
||||
|
||||
component.isLocationComponentEnabled = true
|
||||
mapboxMap.waitForLayer(uiController, location, FOREGROUND_LAYER)
|
||||
TestingAsyncUtils.waitForLayer(uiController, idlingResource.mapView)
|
||||
|
||||
assertThat(mapboxMap.isLayerVisible(FOREGROUND_LAYER), `is`(true))
|
||||
}
|
||||
}
|
||||
@@ -554,12 +515,12 @@ class LocationComponentTest : EspressoTest() {
|
||||
validateTestSetup()
|
||||
val componentAction = object : LocationComponentAction.OnPerformLocationComponentAction {
|
||||
override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap,
|
||||
uiController: UiController, context: Context) {
|
||||
style: Style, uiController: UiController, context: Context) {
|
||||
assertThat(component.isLocationComponentEnabled, `is`(false))
|
||||
component.onStop()
|
||||
component.onStart()
|
||||
assertThat(component.isLocationComponentEnabled, `is`(false))
|
||||
component.activateLocationComponent(context, mapboxMap.style!!, false)
|
||||
component.activateLocationComponent(context, style, false)
|
||||
component.isLocationComponentEnabled = true
|
||||
assertThat(component.isLocationComponentEnabled, `is`(true))
|
||||
}
|
||||
@@ -572,8 +533,8 @@ class LocationComponentTest : EspressoTest() {
|
||||
validateTestSetup()
|
||||
val componentAction = object : LocationComponentAction.OnPerformLocationComponentAction {
|
||||
override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap,
|
||||
uiController: UiController, context: Context) {
|
||||
component.activateLocationComponent(context, mapboxMap.style!!, false)
|
||||
style: Style, uiController: UiController, context: Context) {
|
||||
component.activateLocationComponent(context, style, false)
|
||||
component.isLocationComponentEnabled = true
|
||||
assertThat(component.isLocationComponentEnabled, `is`(true))
|
||||
component.onStop()
|
||||
@@ -589,8 +550,8 @@ class LocationComponentTest : EspressoTest() {
|
||||
validateTestSetup()
|
||||
val componentAction = object : LocationComponentAction.OnPerformLocationComponentAction {
|
||||
override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap,
|
||||
uiController: UiController, context: Context) {
|
||||
component.activateLocationComponent(context, mapboxMap.style!!, false)
|
||||
style: Style, uiController: UiController, context: Context) {
|
||||
component.activateLocationComponent(context, style, false)
|
||||
component.isLocationComponentEnabled = true
|
||||
component.isLocationComponentEnabled = false
|
||||
assertThat(component.isLocationComponentEnabled, `is`(false))
|
||||
@@ -607,15 +568,15 @@ class LocationComponentTest : EspressoTest() {
|
||||
validateTestSetup()
|
||||
val componentAction = object : LocationComponentAction.OnPerformLocationComponentAction {
|
||||
override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap,
|
||||
uiController: UiController, context: Context) {
|
||||
component.activateLocationComponent(context, mapboxMap.style!!, false)
|
||||
style: Style, uiController: UiController, context: Context) {
|
||||
component.activateLocationComponent(context, style, false)
|
||||
component.isLocationComponentEnabled = true
|
||||
|
||||
component.onStop()
|
||||
component.onStart()
|
||||
|
||||
mapboxMap.setStyle(Style.Builder().fromUrl(Style.DARK))
|
||||
uiController.loopMainThreadForAtLeast(MAP_CONNECTION_DELAY)
|
||||
TestingAsyncUtils.waitForLayer(uiController, idlingResource.mapView)
|
||||
}
|
||||
}
|
||||
executeComponentTest(componentAction)
|
||||
@@ -626,13 +587,13 @@ class LocationComponentTest : EspressoTest() {
|
||||
validateTestSetup()
|
||||
val componentAction = object : LocationComponentAction.OnPerformLocationComponentAction {
|
||||
override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap,
|
||||
uiController: UiController, context: Context) {
|
||||
component.activateLocationComponent(context, mapboxMap.style!!,false)
|
||||
style: Style, uiController: UiController, context: Context) {
|
||||
component.activateLocationComponent(context, style, false)
|
||||
component.isLocationComponentEnabled = true
|
||||
mapboxMap.setStyle(Style.Builder().fromUrl(Style.DARK))
|
||||
component.onStop()
|
||||
component.onStart()
|
||||
uiController.loopMainThreadForAtLeast(MAP_CONNECTION_DELAY)
|
||||
TestingAsyncUtils.waitForLayer(uiController, idlingResource.mapView)
|
||||
}
|
||||
}
|
||||
executeComponentTest(componentAction)
|
||||
@@ -643,14 +604,13 @@ class LocationComponentTest : EspressoTest() {
|
||||
validateTestSetup()
|
||||
val componentAction = object : LocationComponentAction.OnPerformLocationComponentAction {
|
||||
override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap,
|
||||
uiController: UiController, context: Context) {
|
||||
component.activateLocationComponent(context, mapboxMap.style!!,false)
|
||||
style: Style, uiController: UiController, context: Context) {
|
||||
component.activateLocationComponent(context, style, false)
|
||||
component.isLocationComponentEnabled = true
|
||||
component.onStop()
|
||||
component.forceLocationUpdate(location)
|
||||
mapboxMap.waitForLayer(uiController, location, FOREGROUND_LAYER)
|
||||
TestingAsyncUtils.waitForLayer(uiController, idlingResource.mapView)
|
||||
|
||||
mapboxMap.waitForSource(uiController, LOCATION_SOURCE)
|
||||
assertThat(mapboxMap.querySourceFeatures(LOCATION_SOURCE).isEmpty(), `is`(true))
|
||||
}
|
||||
}
|
||||
@@ -662,16 +622,14 @@ class LocationComponentTest : EspressoTest() {
|
||||
validateTestSetup()
|
||||
val componentAction = object : LocationComponentAction.OnPerformLocationComponentAction {
|
||||
override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap,
|
||||
uiController: UiController, context: Context) {
|
||||
component.activateLocationComponent(context, mapboxMap.style!!,false)
|
||||
style: Style, uiController: UiController, context: Context) {
|
||||
component.activateLocationComponent(context, style, false)
|
||||
component.isLocationComponentEnabled = true
|
||||
component.onStop()
|
||||
component.forceLocationUpdate(location)
|
||||
component.onStart()
|
||||
mapboxMap.waitForLayer(uiController, location, FOREGROUND_LAYER)
|
||||
TestingAsyncUtils.waitForLayer(uiController, idlingResource.mapView)
|
||||
|
||||
mapboxMap.waitForSource(uiController, LOCATION_SOURCE)
|
||||
mapboxMap.waitForLayer(uiController, location, FOREGROUND_LAYER)
|
||||
val point: Point = mapboxMap.querySourceFeatures(LOCATION_SOURCE)[0].geometry() as Point
|
||||
assertEquals(point.latitude(), location.latitude, 0.1)
|
||||
assertEquals(point.longitude(), location.longitude, 0.1)
|
||||
@@ -685,21 +643,19 @@ class LocationComponentTest : EspressoTest() {
|
||||
validateTestSetup()
|
||||
val componentAction = object : LocationComponentAction.OnPerformLocationComponentAction {
|
||||
override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap,
|
||||
uiController: UiController, context: Context) {
|
||||
component.activateLocationComponent(context, mapboxMap.style!!,false)
|
||||
style: Style, uiController: UiController, context: Context) {
|
||||
component.activateLocationComponent(context, style, false)
|
||||
component.isLocationComponentEnabled = true
|
||||
component.forceLocationUpdate(location)
|
||||
mapboxMap.setStyle(Style.Builder().fromUrl(Style.LIGHT))
|
||||
component.onStop()
|
||||
uiController.loopMainThreadForAtLeast(MAP_CONNECTION_DELAY)
|
||||
TestingAsyncUtils.waitForLayer(uiController, idlingResource.mapView)
|
||||
component.onStart()
|
||||
mapboxMap.waitForLayer(uiController, location, FOREGROUND_LAYER)
|
||||
TestingAsyncUtils.waitForLayer(uiController, idlingResource.mapView)
|
||||
|
||||
mapboxMap.waitForSource(uiController, LOCATION_SOURCE)
|
||||
val point: Point = mapboxMap.querySourceFeatures(LOCATION_SOURCE)[0].geometry() as Point
|
||||
assertEquals(point.latitude(), location.latitude, 0.1)
|
||||
assertEquals(point.longitude(), location.longitude, 0.1)
|
||||
|
||||
assertThat(mapboxMap.isLayerVisible(FOREGROUND_LAYER), `is`(true))
|
||||
assertThat(mapboxMap.isLayerVisible(BACKGROUND_LAYER), `is`(true))
|
||||
assertThat(mapboxMap.isLayerVisible(SHADOW_LAYER), `is`(true))
|
||||
@@ -715,8 +671,8 @@ class LocationComponentTest : EspressoTest() {
|
||||
validateTestSetup()
|
||||
val componentAction = object : LocationComponentAction.OnPerformLocationComponentAction {
|
||||
override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap,
|
||||
uiController: UiController, context: Context) {
|
||||
component.activateLocationComponent(context, mapboxMap.style!!,false)
|
||||
style: Style, uiController: UiController, context: Context) {
|
||||
component.activateLocationComponent(context, style, false)
|
||||
component.isLocationComponentEnabled = true
|
||||
styleChangeIdlingResource.waitForStyle(mapboxMap, MAPBOX_HEAVY_STYLE)
|
||||
val options = LocationComponentOptions.builder(context)
|
||||
@@ -727,7 +683,7 @@ class LocationComponentTest : EspressoTest() {
|
||||
component.applyStyle(options)
|
||||
}
|
||||
|
||||
uiController.loopMainThreadForAtLeast(MAP_CONNECTION_DELAY)
|
||||
TestingAsyncUtils.waitForLayer(uiController, idlingResource.mapView)
|
||||
}
|
||||
}
|
||||
executeComponentTest(componentAction)
|
||||
@@ -741,8 +697,8 @@ class LocationComponentTest : EspressoTest() {
|
||||
validateTestSetup()
|
||||
val componentAction = object : LocationComponentAction.OnPerformLocationComponentAction {
|
||||
override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap,
|
||||
uiController: UiController, context: Context) {
|
||||
component.activateLocationComponent(context, mapboxMap.style!!,false)
|
||||
style: Style, uiController: UiController, context: Context) {
|
||||
component.activateLocationComponent(context, style, false)
|
||||
component.isLocationComponentEnabled = true
|
||||
styleChangeIdlingResource.waitForStyle(mapboxMap, MAPBOX_HEAVY_STYLE)
|
||||
|
||||
@@ -750,7 +706,7 @@ class LocationComponentTest : EspressoTest() {
|
||||
component.forceLocationUpdate(location)
|
||||
}
|
||||
|
||||
uiController.loopMainThreadForAtLeast(MAP_CONNECTION_DELAY)
|
||||
TestingAsyncUtils.waitForLayer(uiController, idlingResource.mapView)
|
||||
}
|
||||
}
|
||||
executeComponentTest(componentAction)
|
||||
@@ -764,10 +720,10 @@ class LocationComponentTest : EspressoTest() {
|
||||
validateTestSetup()
|
||||
val componentAction = object : LocationComponentAction.OnPerformLocationComponentAction {
|
||||
override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap,
|
||||
uiController: UiController, context: Context) {
|
||||
style: Style, uiController: UiController, context: Context) {
|
||||
styleChangeIdlingResource.waitForStyle(mapboxMap, MAPBOX_HEAVY_STYLE)
|
||||
uiController.loopMainThreadForAtLeast(100)
|
||||
component.activateLocationComponent(context, mapboxMap.style!!,false)
|
||||
TestingAsyncUtils.waitForLayer(uiController, idlingResource.mapView)
|
||||
component.activateLocationComponent(context, mapboxMap.style!!, false)
|
||||
component.isLocationComponentEnabled = true
|
||||
|
||||
val options = LocationComponentOptions.builder(context)
|
||||
@@ -791,24 +747,20 @@ class LocationComponentTest : EspressoTest() {
|
||||
validateTestSetup()
|
||||
val componentAction = object : LocationComponentAction.OnPerformLocationComponentAction {
|
||||
override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap,
|
||||
uiController: UiController, context: Context) {
|
||||
component.activateLocationComponent(context, mapboxMap.style!!, false)
|
||||
style: Style, uiController: UiController, context: Context) {
|
||||
component.activateLocationComponent(context, style, false)
|
||||
component.isLocationComponentEnabled = true
|
||||
component.renderMode = RenderMode.GPS
|
||||
location.bearing = 77f
|
||||
component.forceLocationUpdate(location)
|
||||
uiController.loopMainThreadForAtLeast(MAX_ANIMATION_DURATION_MS + MAP_RENDER_DELAY)
|
||||
assertThat(mapboxMap.style, notNullValue())
|
||||
assertThat(mapboxMap.style?.getSource(LOCATION_SOURCE), notNullValue())
|
||||
mapboxMap.waitForLayer(uiController, location, FOREGROUND_LAYER)
|
||||
mapboxMap.waitForSource(uiController, LOCATION_SOURCE)
|
||||
TestingAsyncUtils.waitForLayer(uiController, idlingResource.mapView)
|
||||
uiController.loopMainThreadForAtLeast(MAX_ANIMATION_DURATION_MS)
|
||||
assertEquals(77f, mapboxMap.querySourceFeatures(LOCATION_SOURCE)[0].getNumberProperty(PROPERTY_GPS_BEARING).toFloat(), 0.1f)
|
||||
|
||||
location.bearing = 92f
|
||||
component.forceLocationUpdate(location)
|
||||
uiController.loopMainThreadForAtLeast(MAX_ANIMATION_DURATION_MS + MAP_RENDER_DELAY) // Waiting for the animation to finish
|
||||
mapboxMap.waitForSource(uiController, LOCATION_SOURCE)
|
||||
mapboxMap.waitForLayer(uiController, location, FOREGROUND_LAYER)
|
||||
TestingAsyncUtils.waitForLayer(uiController, idlingResource.mapView)
|
||||
uiController.loopMainThreadForAtLeast(MAX_ANIMATION_DURATION_MS) // Waiting for the animation to finish
|
||||
assertEquals(92.0f, mapboxMap.querySourceFeatures(LOCATION_SOURCE)[0].getNumberProperty(PROPERTY_GPS_BEARING).toFloat(), 0.1f)
|
||||
}
|
||||
}
|
||||
@@ -820,13 +772,15 @@ class LocationComponentTest : EspressoTest() {
|
||||
fun animators_cameraLatLngBearingCorrect() {
|
||||
val componentAction = object : LocationComponentAction.OnPerformLocationComponentAction {
|
||||
override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap,
|
||||
uiController: UiController, context: Context) {
|
||||
component.activateLocationComponent(context, mapboxMap.style!!, false)
|
||||
style: Style, uiController: UiController, context: Context) {
|
||||
component.activateLocationComponent(context, style, false)
|
||||
component.isLocationComponentEnabled = true
|
||||
component.cameraMode = CameraMode.TRACKING_GPS
|
||||
location.bearing = 77f
|
||||
component.forceLocationUpdate(location)
|
||||
uiController.loopMainThreadForAtLeast(MAX_ANIMATION_DURATION_MS + MAP_RENDER_DELAY)
|
||||
TestingAsyncUtils.waitForLayer(uiController, idlingResource.mapView)
|
||||
uiController.loopMainThreadForAtLeast(MAX_ANIMATION_DURATION_MS)
|
||||
|
||||
assertEquals(77.0, mapboxMap.cameraPosition.bearing, 0.1)
|
||||
assertEquals(location.latitude, mapboxMap.cameraPosition.target.latitude, 0.1)
|
||||
assertEquals(location.longitude, mapboxMap.cameraPosition.target.longitude, 0.1)
|
||||
@@ -835,7 +789,9 @@ class LocationComponentTest : EspressoTest() {
|
||||
location.latitude = 30.0
|
||||
location.longitude = 35.0
|
||||
component.forceLocationUpdate(location)
|
||||
uiController.loopMainThreadForAtLeast(MAX_ANIMATION_DURATION_MS + MAP_RENDER_DELAY) // Waiting for the animation to finish
|
||||
TestingAsyncUtils.waitForLayer(uiController, idlingResource.mapView)
|
||||
uiController.loopMainThreadForAtLeast(MAX_ANIMATION_DURATION_MS) // Waiting for the animation to finish
|
||||
|
||||
assertEquals(92.0, mapboxMap.cameraPosition.bearing, 0.1)
|
||||
assertEquals(location.latitude, mapboxMap.cameraPosition.target.latitude, 0.1)
|
||||
assertEquals(location.longitude, mapboxMap.cameraPosition.target.longitude, 0.1)
|
||||
@@ -849,8 +805,8 @@ class LocationComponentTest : EspressoTest() {
|
||||
fun animators_cameraBearingCorrect() {
|
||||
val componentAction = object : LocationComponentAction.OnPerformLocationComponentAction {
|
||||
override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap,
|
||||
uiController: UiController, context: Context) {
|
||||
component.activateLocationComponent(context, mapboxMap.style!!, false)
|
||||
style: Style, uiController: UiController, context: Context) {
|
||||
component.activateLocationComponent(context, style, false)
|
||||
component.isLocationComponentEnabled = true
|
||||
component.cameraMode = CameraMode.NONE_GPS
|
||||
val latitude = mapboxMap.cameraPosition.target.latitude
|
||||
@@ -858,7 +814,9 @@ class LocationComponentTest : EspressoTest() {
|
||||
|
||||
location.bearing = 77f
|
||||
component.forceLocationUpdate(location)
|
||||
uiController.loopMainThreadForAtLeast(MAX_ANIMATION_DURATION_MS + MAP_RENDER_DELAY)
|
||||
TestingAsyncUtils.waitForLayer(uiController, idlingResource.mapView)
|
||||
uiController.loopMainThreadForAtLeast(MAX_ANIMATION_DURATION_MS)
|
||||
|
||||
assertEquals(77.0, mapboxMap.cameraPosition.bearing, 0.1)
|
||||
assertEquals(latitude, mapboxMap.cameraPosition.target.latitude, 0.1)
|
||||
assertEquals(longitude, mapboxMap.cameraPosition.target.longitude, 0.1)
|
||||
@@ -867,7 +825,9 @@ class LocationComponentTest : EspressoTest() {
|
||||
location.latitude = 30.0
|
||||
location.longitude = 35.0
|
||||
component.forceLocationUpdate(location)
|
||||
uiController.loopMainThreadForAtLeast(MAX_ANIMATION_DURATION_MS + MAP_RENDER_DELAY)
|
||||
TestingAsyncUtils.waitForLayer(uiController, idlingResource.mapView)
|
||||
uiController.loopMainThreadForAtLeast(MAX_ANIMATION_DURATION_MS)
|
||||
|
||||
assertEquals(92.0, mapboxMap.cameraPosition.bearing, 0.1)
|
||||
assertEquals(latitude, mapboxMap.cameraPosition.target.latitude, 0.1)
|
||||
assertEquals(longitude, mapboxMap.cameraPosition.target.longitude, 0.1)
|
||||
@@ -881,8 +841,8 @@ class LocationComponentTest : EspressoTest() {
|
||||
fun animators_cameraNoneCorrect() {
|
||||
val componentAction = object : LocationComponentAction.OnPerformLocationComponentAction {
|
||||
override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap,
|
||||
uiController: UiController, context: Context) {
|
||||
component.activateLocationComponent(context, mapboxMap.style!!, false)
|
||||
style: Style, uiController: UiController, context: Context) {
|
||||
component.activateLocationComponent(context, style, false)
|
||||
component.isLocationComponentEnabled = true
|
||||
component.cameraMode = CameraMode.NONE
|
||||
val latitude = mapboxMap.cameraPosition.target.latitude
|
||||
@@ -891,7 +851,9 @@ class LocationComponentTest : EspressoTest() {
|
||||
|
||||
location.bearing = 77f
|
||||
component.forceLocationUpdate(location)
|
||||
uiController.loopMainThreadForAtLeast(MAX_ANIMATION_DURATION_MS + MAP_RENDER_DELAY)
|
||||
TestingAsyncUtils.waitForLayer(uiController, idlingResource.mapView)
|
||||
uiController.loopMainThreadForAtLeast(MAX_ANIMATION_DURATION_MS)
|
||||
|
||||
assertEquals(bearing, mapboxMap.cameraPosition.bearing, 0.1)
|
||||
assertEquals(latitude, mapboxMap.cameraPosition.target.latitude, 0.1)
|
||||
assertEquals(longitude, mapboxMap.cameraPosition.target.longitude, 0.1)
|
||||
@@ -900,7 +862,9 @@ class LocationComponentTest : EspressoTest() {
|
||||
location.latitude = 30.0
|
||||
location.longitude = 35.0
|
||||
component.forceLocationUpdate(location)
|
||||
uiController.loopMainThreadForAtLeast(MAX_ANIMATION_DURATION_MS + MAP_RENDER_DELAY) // Waiting for the animation to finish
|
||||
TestingAsyncUtils.waitForLayer(uiController, idlingResource.mapView)
|
||||
uiController.loopMainThreadForAtLeast(MAX_ANIMATION_DURATION_MS)
|
||||
|
||||
assertEquals(bearing, mapboxMap.cameraPosition.bearing, 0.1)
|
||||
assertEquals(latitude, mapboxMap.cameraPosition.target.latitude, 0.1)
|
||||
assertEquals(longitude, mapboxMap.cameraPosition.target.longitude, 0.1)
|
||||
@@ -914,13 +878,13 @@ class LocationComponentTest : EspressoTest() {
|
||||
fun animators_focalPointAdjustment() {
|
||||
val componentAction = object : LocationComponentAction.OnPerformLocationComponentAction {
|
||||
override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap,
|
||||
uiController: UiController, context: Context) {
|
||||
component.activateLocationComponent(context, mapboxMap.style!!,false)
|
||||
style: Style, uiController: UiController, context: Context) {
|
||||
component.activateLocationComponent(context, style, false)
|
||||
component.isLocationComponentEnabled = true
|
||||
component.cameraMode = CameraMode.TRACKING
|
||||
component.cameraMode = CameraMode.NONE
|
||||
component.forceLocationUpdate(location)
|
||||
mapboxMap.waitForLayer(uiController, location, FOREGROUND_LAYER)
|
||||
TestingAsyncUtils.waitForLayer(uiController, idlingResource.mapView)
|
||||
|
||||
assertThat(mapboxMap.uiSettings.focalPoint, nullValue())
|
||||
}
|
||||
@@ -933,13 +897,14 @@ class LocationComponentTest : EspressoTest() {
|
||||
fun animators_dontZoomWhileNotTracking() {
|
||||
val componentAction = object : LocationComponentAction.OnPerformLocationComponentAction {
|
||||
override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap,
|
||||
uiController: UiController, context: Context) {
|
||||
component.activateLocationComponent(context, mapboxMap.style!!, false)
|
||||
style: Style, uiController: UiController, context: Context) {
|
||||
component.activateLocationComponent(context, style, false)
|
||||
component.isLocationComponentEnabled = true
|
||||
component.cameraMode = CameraMode.NONE
|
||||
val zoom = mapboxMap.cameraPosition.zoom
|
||||
component.zoomWhileTracking(10.0)
|
||||
uiController.loopMainThreadForAtLeast(DEFAULT_TRACKING_ZOOM_ANIM_DURATION)
|
||||
TestingAsyncUtils.waitForLayer(uiController, idlingResource.mapView)
|
||||
|
||||
assertEquals(zoom, mapboxMap.cameraPosition.zoom, 0.1)
|
||||
}
|
||||
@@ -952,12 +917,13 @@ class LocationComponentTest : EspressoTest() {
|
||||
fun animators_zoomWhileTracking() {
|
||||
val componentAction = object : LocationComponentAction.OnPerformLocationComponentAction {
|
||||
override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap,
|
||||
uiController: UiController, context: Context) {
|
||||
component.activateLocationComponent(context, mapboxMap.style!!, false)
|
||||
style: Style, uiController: UiController, context: Context) {
|
||||
component.activateLocationComponent(context, style, false)
|
||||
component.isLocationComponentEnabled = true
|
||||
component.cameraMode = CameraMode.TRACKING
|
||||
component.zoomWhileTracking(10.0)
|
||||
uiController.loopMainThreadForAtLeast(DEFAULT_TRACKING_ZOOM_ANIM_DURATION)
|
||||
TestingAsyncUtils.waitForLayer(uiController, idlingResource.mapView)
|
||||
|
||||
assertEquals(10.0, mapboxMap.cameraPosition.zoom, 0.1)
|
||||
}
|
||||
@@ -971,14 +937,15 @@ class LocationComponentTest : EspressoTest() {
|
||||
fun animators_zoomWhileTrackingCanceledOnModeChange() {
|
||||
val componentAction = object : LocationComponentAction.OnPerformLocationComponentAction {
|
||||
override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap,
|
||||
uiController: UiController, context: Context) {
|
||||
component.activateLocationComponent(context, mapboxMap.style!!, false)
|
||||
style: Style, uiController: UiController, context: Context) {
|
||||
component.activateLocationComponent(context, style, false)
|
||||
component.isLocationComponentEnabled = true
|
||||
component.cameraMode = CameraMode.TRACKING
|
||||
component.zoomWhileTracking(15.0)
|
||||
uiController.loopMainThreadForAtLeast(DEFAULT_TRACKING_ZOOM_ANIM_DURATION / 2)
|
||||
component.cameraMode = CameraMode.NONE
|
||||
uiController.loopMainThreadForAtLeast(DEFAULT_TRACKING_ZOOM_ANIM_DURATION / 2)
|
||||
TestingAsyncUtils.waitForLayer(uiController, idlingResource.mapView)
|
||||
|
||||
assertEquals(15.0 / 2.0, mapboxMap.cameraPosition.zoom, 3.0)
|
||||
}
|
||||
@@ -991,8 +958,8 @@ class LocationComponentTest : EspressoTest() {
|
||||
fun animators_dontZoomWhileStopped() {
|
||||
val componentAction = object : LocationComponentAction.OnPerformLocationComponentAction {
|
||||
override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap,
|
||||
uiController: UiController, context: Context) {
|
||||
component.activateLocationComponent(context, mapboxMap.style!!,false)
|
||||
style: Style, uiController: UiController, context: Context) {
|
||||
component.activateLocationComponent(context, style, false)
|
||||
component.isLocationComponentEnabled = true
|
||||
|
||||
component.cameraMode = CameraMode.TRACKING
|
||||
@@ -1001,6 +968,7 @@ class LocationComponentTest : EspressoTest() {
|
||||
component.onStop()
|
||||
component.zoomWhileTracking(10.0)
|
||||
uiController.loopMainThreadForAtLeast(DEFAULT_TRACKING_ZOOM_ANIM_DURATION)
|
||||
TestingAsyncUtils.waitForLayer(uiController, idlingResource.mapView)
|
||||
|
||||
assertEquals(zoom, mapboxMap.cameraPosition.zoom, 0.1)
|
||||
}
|
||||
@@ -1014,14 +982,15 @@ class LocationComponentTest : EspressoTest() {
|
||||
fun animators_cancelZoomWhileTracking() {
|
||||
val componentAction = object : LocationComponentAction.OnPerformLocationComponentAction {
|
||||
override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap,
|
||||
uiController: UiController, context: Context) {
|
||||
component.activateLocationComponent(context, mapboxMap.style!!, false)
|
||||
style: Style, uiController: UiController, context: Context) {
|
||||
component.activateLocationComponent(context, style, false)
|
||||
component.isLocationComponentEnabled = true
|
||||
component.cameraMode = CameraMode.TRACKING
|
||||
component.zoomWhileTracking(15.0)
|
||||
uiController.loopMainThreadForAtLeast(DEFAULT_TRACKING_ZOOM_ANIM_DURATION / 2)
|
||||
component.cancelZoomWhileTrackingAnimation()
|
||||
uiController.loopMainThreadForAtLeast(DEFAULT_TRACKING_ZOOM_ANIM_DURATION / 2)
|
||||
TestingAsyncUtils.waitForLayer(uiController, idlingResource.mapView)
|
||||
|
||||
assertEquals(15.0 / 2.0, mapboxMap.cameraPosition.zoom, 3.0)
|
||||
}
|
||||
@@ -1034,13 +1003,14 @@ class LocationComponentTest : EspressoTest() {
|
||||
fun animators_dontTiltWhileNotTracking() {
|
||||
val componentAction = object : LocationComponentAction.OnPerformLocationComponentAction {
|
||||
override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap,
|
||||
uiController: UiController, context: Context) {
|
||||
component.activateLocationComponent(context, mapboxMap.style!!, false)
|
||||
style: Style, uiController: UiController, context: Context) {
|
||||
component.activateLocationComponent(context, style, false)
|
||||
component.isLocationComponentEnabled = true
|
||||
component.cameraMode = CameraMode.NONE
|
||||
val tilt = mapboxMap.cameraPosition.tilt
|
||||
component.tiltWhileTracking(30.0)
|
||||
uiController.loopMainThreadForAtLeast(DEFAULT_TRACKING_TILT_ANIM_DURATION)
|
||||
TestingAsyncUtils.waitForLayer(uiController, idlingResource.mapView)
|
||||
|
||||
assertEquals(tilt, mapboxMap.cameraPosition.tilt, 0.1)
|
||||
}
|
||||
@@ -1053,12 +1023,13 @@ class LocationComponentTest : EspressoTest() {
|
||||
fun animators_tiltWhileTracking() {
|
||||
val componentAction = object : LocationComponentAction.OnPerformLocationComponentAction {
|
||||
override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap,
|
||||
uiController: UiController, context: Context) {
|
||||
component.activateLocationComponent(context, mapboxMap.style!!,false)
|
||||
style: Style, uiController: UiController, context: Context) {
|
||||
component.activateLocationComponent(context, style, false)
|
||||
component.isLocationComponentEnabled = true
|
||||
component.cameraMode = CameraMode.TRACKING
|
||||
component.tiltWhileTracking(30.0)
|
||||
uiController.loopMainThreadForAtLeast(DEFAULT_TRACKING_TILT_ANIM_DURATION)
|
||||
TestingAsyncUtils.waitForLayer(uiController, idlingResource.mapView)
|
||||
|
||||
assertEquals(30.0, mapboxMap.cameraPosition.tilt, 0.1)
|
||||
}
|
||||
@@ -1072,14 +1043,15 @@ class LocationComponentTest : EspressoTest() {
|
||||
fun animators_tiltWhileTrackingCanceledOnModeChange() {
|
||||
val componentAction = object : LocationComponentAction.OnPerformLocationComponentAction {
|
||||
override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap,
|
||||
uiController: UiController, context: Context) {
|
||||
component.activateLocationComponent(context, mapboxMap.style!!,false)
|
||||
style: Style, uiController: UiController, context: Context) {
|
||||
component.activateLocationComponent(context, style, false)
|
||||
component.isLocationComponentEnabled = true
|
||||
component.cameraMode = CameraMode.TRACKING
|
||||
component.tiltWhileTracking(30.0)
|
||||
uiController.loopMainThreadForAtLeast(DEFAULT_TRACKING_TILT_ANIM_DURATION / 2)
|
||||
component.cameraMode = CameraMode.NONE
|
||||
uiController.loopMainThreadForAtLeast(DEFAULT_TRACKING_TILT_ANIM_DURATION / 2)
|
||||
TestingAsyncUtils.waitForLayer(uiController, idlingResource.mapView)
|
||||
|
||||
assertEquals(30.0 / 2.0, mapboxMap.cameraPosition.tilt, 3.0)
|
||||
}
|
||||
@@ -1092,8 +1064,8 @@ class LocationComponentTest : EspressoTest() {
|
||||
fun animators_dontTiltWhileStopped() {
|
||||
val componentAction = object : LocationComponentAction.OnPerformLocationComponentAction {
|
||||
override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap,
|
||||
uiController: UiController, context: Context) {
|
||||
component.activateLocationComponent(context, mapboxMap.style!!, false)
|
||||
style: Style, uiController: UiController, context: Context) {
|
||||
component.activateLocationComponent(context, style, false)
|
||||
component.isLocationComponentEnabled = true
|
||||
component.cameraMode = CameraMode.TRACKING
|
||||
val tilt = mapboxMap.cameraPosition.tilt
|
||||
@@ -1101,6 +1073,7 @@ class LocationComponentTest : EspressoTest() {
|
||||
component.onStop()
|
||||
component.tiltWhileTracking(30.0)
|
||||
uiController.loopMainThreadForAtLeast(DEFAULT_TRACKING_TILT_ANIM_DURATION)
|
||||
TestingAsyncUtils.waitForLayer(uiController, idlingResource.mapView)
|
||||
|
||||
assertEquals(tilt, mapboxMap.cameraPosition.tilt, 0.1)
|
||||
}
|
||||
@@ -1114,8 +1087,8 @@ class LocationComponentTest : EspressoTest() {
|
||||
fun animators_cancelTiltWhileTracking() {
|
||||
val componentAction = object : LocationComponentAction.OnPerformLocationComponentAction {
|
||||
override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap,
|
||||
uiController: UiController, context: Context) {
|
||||
component.activateLocationComponent(context, mapboxMap.style!!,false)
|
||||
style: Style, uiController: UiController, context: Context) {
|
||||
component.activateLocationComponent(context, style, false)
|
||||
component.isLocationComponentEnabled = true
|
||||
component.cameraMode = CameraMode.TRACKING
|
||||
component.tiltWhileTracking(30.0)
|
||||
@@ -1134,8 +1107,8 @@ class LocationComponentTest : EspressoTest() {
|
||||
fun cameraPositionAdjustedToTrackingModeWhenComponentEnabled() {
|
||||
val componentAction = object : LocationComponentAction.OnPerformLocationComponentAction {
|
||||
override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap,
|
||||
uiController: UiController, context: Context) {
|
||||
component.activateLocationComponent(context, mapboxMap.style!!, false)
|
||||
style: Style, uiController: UiController, context: Context) {
|
||||
component.activateLocationComponent(context, style, false)
|
||||
component.isLocationComponentEnabled = true
|
||||
component.cameraMode = CameraMode.TRACKING_GPS
|
||||
component.forceLocationUpdate(location)
|
||||
@@ -1143,7 +1116,8 @@ class LocationComponentTest : EspressoTest() {
|
||||
mapboxMap.moveCamera(CameraUpdateFactory.newLatLng(LatLng(51.0, 17.0)))
|
||||
mapboxMap.moveCamera(CameraUpdateFactory.bearingTo(90.0))
|
||||
component.isLocationComponentEnabled = true
|
||||
uiController.loopMainThreadForAtLeast(MAX_ANIMATION_DURATION_MS + MAP_RENDER_DELAY)
|
||||
TestingAsyncUtils.waitForLayer(uiController, idlingResource.mapView)
|
||||
uiController.loopMainThreadForAtLeast(MAX_ANIMATION_DURATION_MS)
|
||||
|
||||
assertEquals(location.bearing.toDouble(), mapboxMap.cameraPosition.bearing, 0.1)
|
||||
assertEquals(location.latitude, mapboxMap.cameraPosition.target.latitude, 0.1)
|
||||
@@ -1158,8 +1132,8 @@ class LocationComponentTest : EspressoTest() {
|
||||
fun cameraPositionSnappedToTargetIfExceedsThreshold() {
|
||||
val componentAction = object : LocationComponentAction.OnPerformLocationComponentAction {
|
||||
override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap,
|
||||
uiController: UiController, context: Context) {
|
||||
component.activateLocationComponent(context, mapboxMap.style!!, false)
|
||||
style: Style, uiController: UiController, context: Context) {
|
||||
component.activateLocationComponent(context, style, false)
|
||||
component.isLocationComponentEnabled = true
|
||||
component.cameraMode = CameraMode.NONE
|
||||
component.forceLocationUpdate(location)
|
||||
@@ -1184,8 +1158,8 @@ class LocationComponentTest : EspressoTest() {
|
||||
fun compassEngine_onComponentInitializedDefaultIsProvided() {
|
||||
val componentAction = object : LocationComponentAction.OnPerformLocationComponentAction {
|
||||
override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap,
|
||||
uiController: UiController, context: Context) {
|
||||
component.activateLocationComponent(context, mapboxMap.style!!, false)
|
||||
style: Style, uiController: UiController, context: Context) {
|
||||
component.activateLocationComponent(context, style, false)
|
||||
component.isLocationComponentEnabled = true
|
||||
assertTrue(component.compassEngine is LocationComponentCompassEngine)
|
||||
}
|
||||
@@ -1198,8 +1172,8 @@ class LocationComponentTest : EspressoTest() {
|
||||
fun compassEngine_changesWhenNewProvided() {
|
||||
val componentAction = object : LocationComponentAction.OnPerformLocationComponentAction {
|
||||
override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap,
|
||||
uiController: UiController, context: Context) {
|
||||
component.activateLocationComponent(context, mapboxMap.style!!, false)
|
||||
style: Style, uiController: UiController, context: Context) {
|
||||
component.activateLocationComponent(context, style, false)
|
||||
component.isLocationComponentEnabled = true
|
||||
val engine: CompassEngine = object : CompassEngine {
|
||||
override fun addCompassListener(compassListener: CompassListener) {
|
||||
|
||||
@@ -14,18 +14,20 @@ import android.support.test.rule.GrantPermissionRule
|
||||
import android.support.test.rule.GrantPermissionRule.grant
|
||||
import android.support.test.runner.AndroidJUnit4
|
||||
import com.mapbox.mapboxsdk.camera.CameraUpdateFactory
|
||||
import com.mapbox.mapboxsdk.maps.Style
|
||||
import com.mapbox.mapboxsdk.geometry.LatLng
|
||||
import com.mapbox.mapboxsdk.location.LocationComponentConstants.*
|
||||
import com.mapbox.mapboxsdk.location.modes.RenderMode
|
||||
import com.mapbox.mapboxsdk.location.utils.*
|
||||
import com.mapbox.mapboxsdk.location.utils.LocationComponentAction
|
||||
import com.mapbox.mapboxsdk.location.utils.MapboxTestingUtils.Companion.MAPBOX_HEAVY_STYLE
|
||||
import com.mapbox.mapboxsdk.location.utils.MapboxTestingUtils.Companion.MAP_CONNECTION_DELAY
|
||||
import com.mapbox.mapboxsdk.location.utils.MapboxTestingUtils.Companion.MAP_RENDER_DELAY
|
||||
import com.mapbox.mapboxsdk.location.utils.MapboxTestingUtils.Companion.pushSourceUpdates
|
||||
import com.mapbox.mapboxsdk.location.utils.StyleChangeIdlingResource
|
||||
import com.mapbox.mapboxsdk.location.utils.isLayerVisible
|
||||
import com.mapbox.mapboxsdk.location.utils.querySourceFeatures
|
||||
import com.mapbox.mapboxsdk.maps.MapboxMap
|
||||
import com.mapbox.mapboxsdk.maps.Style
|
||||
import com.mapbox.mapboxsdk.style.sources.GeoJsonSource
|
||||
import com.mapbox.mapboxsdk.testapp.activity.EspressoTest
|
||||
import com.mapbox.mapboxsdk.testapp.utils.TestingAsyncUtils
|
||||
import org.hamcrest.CoreMatchers.`is`
|
||||
import org.hamcrest.CoreMatchers.notNullValue
|
||||
import org.hamcrest.Matchers.equalTo
|
||||
@@ -69,12 +71,13 @@ class LocationLayerControllerTest : EspressoTest() {
|
||||
fun renderModeNormal_sourceDoesGetAdded() {
|
||||
val componentAction = object : LocationComponentAction.OnPerformLocationComponentAction {
|
||||
override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap,
|
||||
uiController: UiController, context: Context) {
|
||||
component.activateLocationComponent(context, mapboxMap.style!!,false)
|
||||
style: Style, uiController: UiController, context: Context) {
|
||||
component.activateLocationComponent(context, style, false)
|
||||
component.isLocationComponentEnabled = true
|
||||
component.renderMode = RenderMode.NORMAL
|
||||
uiController.loopMainThreadForAtLeast(MAP_RENDER_DELAY)
|
||||
assertThat(mapboxMap.getStyle()!!.getSource(LOCATION_SOURCE), notNullValue())
|
||||
TestingAsyncUtils.waitForLayer(uiController, idlingResource.mapView)
|
||||
|
||||
assertThat(style.getSource(LOCATION_SOURCE), notNullValue())
|
||||
}
|
||||
}
|
||||
executeComponentTest(componentAction)
|
||||
@@ -88,12 +91,13 @@ class LocationLayerControllerTest : EspressoTest() {
|
||||
fun renderModeNormal_trackingNormalLayersDoGetAdded() {
|
||||
val componentAction = object : LocationComponentAction.OnPerformLocationComponentAction {
|
||||
override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap,
|
||||
uiController: UiController, context: Context) {
|
||||
component.activateLocationComponent(context, mapboxMap.style!!, false)
|
||||
style: Style, uiController: UiController, context: Context) {
|
||||
component.activateLocationComponent(context, style, false)
|
||||
component.isLocationComponentEnabled = true
|
||||
component.renderMode = RenderMode.NORMAL
|
||||
component.forceLocationUpdate(location)
|
||||
mapboxMap.waitForLayer(uiController, location, FOREGROUND_LAYER)
|
||||
TestingAsyncUtils.waitForLayer(uiController, idlingResource.mapView)
|
||||
|
||||
assertThat(mapboxMap.isLayerVisible(FOREGROUND_LAYER), `is`(true))
|
||||
assertThat(mapboxMap.isLayerVisible(BACKGROUND_LAYER), `is`(true))
|
||||
assertThat(mapboxMap.isLayerVisible(SHADOW_LAYER), `is`(true))
|
||||
@@ -108,12 +112,13 @@ class LocationLayerControllerTest : EspressoTest() {
|
||||
fun renderModeCompass_bearingLayersDoGetAdded() {
|
||||
val componentAction = object : LocationComponentAction.OnPerformLocationComponentAction {
|
||||
override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap,
|
||||
uiController: UiController, context: Context) {
|
||||
component.activateLocationComponent(context, mapboxMap.style!!, false)
|
||||
style: Style, uiController: UiController, context: Context) {
|
||||
component.activateLocationComponent(context, style, false)
|
||||
component.isLocationComponentEnabled = true
|
||||
component.renderMode = RenderMode.COMPASS
|
||||
component.forceLocationUpdate(location)
|
||||
mapboxMap.waitForLayer(uiController, location, FOREGROUND_LAYER)
|
||||
TestingAsyncUtils.waitForLayer(uiController, idlingResource.mapView)
|
||||
|
||||
assertThat(mapboxMap.isLayerVisible(FOREGROUND_LAYER), `is`(true))
|
||||
assertThat(mapboxMap.isLayerVisible(BACKGROUND_LAYER), `is`(true))
|
||||
assertThat(mapboxMap.isLayerVisible(SHADOW_LAYER), `is`(true))
|
||||
@@ -128,12 +133,13 @@ class LocationLayerControllerTest : EspressoTest() {
|
||||
fun renderModeGps_navigationLayersDoGetAdded() {
|
||||
val componentAction = object : LocationComponentAction.OnPerformLocationComponentAction {
|
||||
override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap,
|
||||
uiController: UiController, context: Context) {
|
||||
component.activateLocationComponent(context, mapboxMap.style!!, false)
|
||||
style: Style, uiController: UiController, context: Context) {
|
||||
component.activateLocationComponent(context, style, false)
|
||||
component.isLocationComponentEnabled = true
|
||||
component.renderMode = RenderMode.GPS
|
||||
component.forceLocationUpdate(location)
|
||||
mapboxMap.waitForLayer(uiController, location, FOREGROUND_LAYER)
|
||||
TestingAsyncUtils.waitForLayer(uiController, idlingResource.mapView)
|
||||
|
||||
assertThat(mapboxMap.isLayerVisible(FOREGROUND_LAYER), `is`(true))
|
||||
assertThat(mapboxMap.isLayerVisible(BACKGROUND_LAYER), `is`(true))
|
||||
assertThat(mapboxMap.isLayerVisible(SHADOW_LAYER), `is`(false))
|
||||
@@ -148,21 +154,14 @@ class LocationLayerControllerTest : EspressoTest() {
|
||||
fun dontShowPuckWhenRenderModeSetAndComponentDisabled() {
|
||||
val componentAction = object : LocationComponentAction.OnPerformLocationComponentAction {
|
||||
override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap,
|
||||
uiController: UiController, context: Context) {
|
||||
component.activateLocationComponent(context, mapboxMap.style!!, false)
|
||||
style: Style, uiController: UiController, context: Context) {
|
||||
component.activateLocationComponent(context, style, false)
|
||||
component.isLocationComponentEnabled = true
|
||||
component.forceLocationUpdate(location)
|
||||
mapboxMap.waitForLayer(uiController, location, FOREGROUND_LAYER)
|
||||
component.isLocationComponentEnabled = false
|
||||
mapboxMap.waitForLayer(uiController, location, FOREGROUND_LAYER, shouldDisappear = true)
|
||||
TestingAsyncUtils.waitForLayer(uiController, idlingResource.mapView)
|
||||
component.renderMode = RenderMode.GPS
|
||||
|
||||
// waiting for layer to appear or timing out
|
||||
val renderCheck = {
|
||||
mapboxMap.isLayerVisible(FOREGROUND_LAYER)
|
||||
}
|
||||
waitForRenderResult(uiController, renderCheck, true)
|
||||
|
||||
assertThat(mapboxMap.isLayerVisible(FOREGROUND_LAYER), `is`(false))
|
||||
assertThat(mapboxMap.isLayerVisible(BACKGROUND_LAYER), `is`(false))
|
||||
assertThat(mapboxMap.isLayerVisible(SHADOW_LAYER), `is`(false))
|
||||
@@ -177,14 +176,13 @@ class LocationLayerControllerTest : EspressoTest() {
|
||||
fun whenLocationComponentDisabled_doesSetAllLayersToVisibilityNone() {
|
||||
val componentAction = object : LocationComponentAction.OnPerformLocationComponentAction {
|
||||
override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap,
|
||||
uiController: UiController, context: Context) {
|
||||
component.activateLocationComponent(context, mapboxMap.style!!, false)
|
||||
style: Style, uiController: UiController, context: Context) {
|
||||
component.activateLocationComponent(context, style, false)
|
||||
component.isLocationComponentEnabled = true
|
||||
component.renderMode = RenderMode.NORMAL
|
||||
component.forceLocationUpdate(location)
|
||||
mapboxMap.waitForLayer(uiController, location, FOREGROUND_LAYER)
|
||||
component.isLocationComponentEnabled = false
|
||||
mapboxMap.waitForLayer(uiController, location, FOREGROUND_LAYER, shouldDisappear = true)
|
||||
TestingAsyncUtils.waitForLayer(uiController, idlingResource.mapView)
|
||||
|
||||
// Check that all layers visibilities are set to none
|
||||
assertThat(mapboxMap.isLayerVisible(FOREGROUND_LAYER), `is`(false))
|
||||
@@ -201,21 +199,18 @@ class LocationLayerControllerTest : EspressoTest() {
|
||||
fun onMapChange_locationComponentLayersDoGetRedrawn() {
|
||||
val componentAction = object : LocationComponentAction.OnPerformLocationComponentAction {
|
||||
override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap,
|
||||
uiController: UiController, context: Context) {
|
||||
component.activateLocationComponent(context, mapboxMap.style!!, false)
|
||||
style: Style, uiController: UiController, context: Context) {
|
||||
component.activateLocationComponent(context, style, false)
|
||||
component.isLocationComponentEnabled = true
|
||||
component.renderMode = RenderMode.NORMAL
|
||||
component.forceLocationUpdate(location)
|
||||
mapboxMap.waitForLayer(uiController, location, FOREGROUND_LAYER)
|
||||
mapboxMap.setStyle(Style.Builder().fromUrl(Style.LIGHT))
|
||||
uiController.loopMainThreadForAtLeast(MAP_CONNECTION_DELAY)
|
||||
component.forceLocationUpdate(location)
|
||||
mapboxMap.waitForLayer(uiController, location, FOREGROUND_LAYER)
|
||||
styleChangeIdlingResource.waitForStyle(mapboxMap, Style.LIGHT)
|
||||
TestingAsyncUtils.waitForLayer(uiController, idlingResource.mapView)
|
||||
|
||||
assertThat(component.renderMode, `is`(equalTo(RenderMode.NORMAL)))
|
||||
|
||||
// Check that the Source has been re-added to the new map style
|
||||
val source: GeoJsonSource? = mapboxMap.getStyle()!!.getSourceAs(LOCATION_SOURCE)
|
||||
val source: GeoJsonSource? = mapboxMap.style!!.getSourceAs(LOCATION_SOURCE)
|
||||
assertThat(source, notNullValue())
|
||||
|
||||
// Check that all layers visibilities are set to visible
|
||||
@@ -233,24 +228,18 @@ class LocationLayerControllerTest : EspressoTest() {
|
||||
fun whenStyleChanged_continuesUsingStaleIcons() {
|
||||
val componentAction = object : LocationComponentAction.OnPerformLocationComponentAction {
|
||||
override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap,
|
||||
uiController: UiController, context: Context) {
|
||||
component.activateLocationComponent(context, mapboxMap.style!!,false)
|
||||
style: Style, uiController: UiController, context: Context) {
|
||||
component.activateLocationComponent(context, style, false)
|
||||
component.isLocationComponentEnabled = true
|
||||
component.applyStyle(LocationComponentOptions.builder(context).staleStateTimeout(100).build())
|
||||
component.forceLocationUpdate(location)
|
||||
mapboxMap.waitForLayer(uiController, location, FOREGROUND_LAYER)
|
||||
TestingAsyncUtils.waitForLayer(uiController, idlingResource.mapView)
|
||||
uiController.loopMainThreadForAtLeast(150)
|
||||
|
||||
val renderCheck = {
|
||||
mapboxMap.querySourceFeatures(LOCATION_SOURCE)[0].getBooleanProperty(PROPERTY_LOCATION_STALE)
|
||||
}
|
||||
waitForRenderResult(uiController, renderCheck, true)
|
||||
|
||||
assertThat(renderCheck.invoke(), `is`(true))
|
||||
assertThat(mapboxMap.querySourceFeatures(LOCATION_SOURCE)[0].getBooleanProperty(PROPERTY_LOCATION_STALE), `is`(true))
|
||||
|
||||
mapboxMap.setStyle(Style.Builder().fromUrl(Style.LIGHT))
|
||||
uiController.loopMainThreadForAtLeast(MAP_CONNECTION_DELAY)
|
||||
mapboxMap.waitForLayer(uiController, location, FOREGROUND_LAYER)
|
||||
TestingAsyncUtils.waitForLayer(uiController, idlingResource.mapView)
|
||||
|
||||
assertThat(mapboxMap.querySourceFeatures(LOCATION_SOURCE)[0].getBooleanProperty(PROPERTY_LOCATION_STALE), `is`(true))
|
||||
}
|
||||
@@ -262,8 +251,8 @@ class LocationLayerControllerTest : EspressoTest() {
|
||||
fun whenStyleChanged_staleStateChanges() {
|
||||
val componentAction = object : LocationComponentAction.OnPerformLocationComponentAction {
|
||||
override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap,
|
||||
uiController: UiController, context: Context) {
|
||||
component.activateLocationComponent(context, mapboxMap.style!!,false)
|
||||
style: Style, uiController: UiController, context: Context) {
|
||||
component.activateLocationComponent(context, style, false)
|
||||
component.isLocationComponentEnabled = true
|
||||
component.applyStyle(LocationComponentOptions.builder(context).staleStateTimeout(1).build())
|
||||
styleChangeIdlingResource.waitForStyle(mapboxMap, MAPBOX_HEAVY_STYLE)
|
||||
@@ -282,17 +271,17 @@ class LocationLayerControllerTest : EspressoTest() {
|
||||
fun whenStyleChanged_layerVisibilityUpdates() {
|
||||
val componentAction = object : LocationComponentAction.OnPerformLocationComponentAction {
|
||||
override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap,
|
||||
uiController: UiController, context: Context) {
|
||||
style: Style, uiController: UiController, context: Context) {
|
||||
styleChangeIdlingResource.waitForStyle(mapboxMap, MAPBOX_HEAVY_STYLE)
|
||||
uiController.loopMainThreadForAtLeast(100)
|
||||
var show = true
|
||||
component.activateLocationComponent(context, mapboxMap.style!!,false)
|
||||
component.activateLocationComponent(context, mapboxMap.style!!, false)
|
||||
pushSourceUpdates(styleChangeIdlingResource) {
|
||||
component.isLocationComponentEnabled = show
|
||||
show = !show
|
||||
}
|
||||
|
||||
uiController.loopMainThreadForAtLeast(MAP_CONNECTION_DELAY)
|
||||
TestingAsyncUtils.waitForLayer(uiController, idlingResource.mapView)
|
||||
}
|
||||
}
|
||||
executeComponentTest(componentAction)
|
||||
@@ -305,12 +294,12 @@ class LocationLayerControllerTest : EspressoTest() {
|
||||
fun accuracy_visibleWithNewLocation() {
|
||||
val componentAction = object : LocationComponentAction.OnPerformLocationComponentAction {
|
||||
override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap,
|
||||
uiController: UiController, context: Context) {
|
||||
component.activateLocationComponent(context, mapboxMap.style!!,false)
|
||||
style: Style, uiController: UiController, context: Context) {
|
||||
component.activateLocationComponent(context, style, false)
|
||||
component.isLocationComponentEnabled = true
|
||||
mapboxMap.moveCamera(CameraUpdateFactory.newLatLngZoom(LatLng(location), 16.0))
|
||||
component.forceLocationUpdate(location)
|
||||
mapboxMap.waitForLayer(uiController, location, FOREGROUND_LAYER)
|
||||
TestingAsyncUtils.waitForLayer(uiController, idlingResource.mapView)
|
||||
uiController.loopMainThreadForAtLeast(ACCURACY_RADIUS_ANIMATION_DURATION)
|
||||
|
||||
assertEquals(Utils.calculateZoomLevelRadius(mapboxMap, location) /*meters projected to radius on zoom 16*/,
|
||||
@@ -325,31 +314,27 @@ class LocationLayerControllerTest : EspressoTest() {
|
||||
fun accuracy_visibleWhenCameraEased() {
|
||||
val componentAction = object : LocationComponentAction.OnPerformLocationComponentAction {
|
||||
override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap,
|
||||
uiController: UiController, context: Context) {
|
||||
component.activateLocationComponent(context, mapboxMap.style!!, false)
|
||||
style: Style, uiController: UiController, context: Context) {
|
||||
component.activateLocationComponent(context, style, false)
|
||||
component.isLocationComponentEnabled = true
|
||||
component.forceLocationUpdate(location)
|
||||
mapboxMap.waitForLayer(uiController, location, FOREGROUND_LAYER)
|
||||
|
||||
val target = LatLng(location)
|
||||
val zoom = 16.0
|
||||
mapboxMap.easeCamera(CameraUpdateFactory.newLatLngZoom(target, zoom), 300)
|
||||
uiController.loopMainThreadForAtLeast(300)
|
||||
TestingAsyncUtils.waitForLayer(uiController, idlingResource.mapView)
|
||||
|
||||
val cameraCheck = {
|
||||
Math.abs(zoom - mapboxMap.cameraPosition.zoom) < 0.1
|
||||
&& Math.abs(target.latitude - mapboxMap.cameraPosition.target.latitude) < 0.1
|
||||
&& Math.abs(target.longitude - mapboxMap.cameraPosition.target.longitude) < 0.1
|
||||
}
|
||||
waitForRenderResult(uiController, cameraCheck, true)
|
||||
|
||||
assertThat(Math.abs(zoom - mapboxMap.cameraPosition.zoom) < 0.1
|
||||
&& Math.abs(target.latitude - mapboxMap.cameraPosition.target.latitude) < 0.1
|
||||
&& Math.abs(target.longitude - mapboxMap.cameraPosition.target.longitude) < 0.1,
|
||||
`is`(true))
|
||||
|
||||
val expectedRadius = Utils.calculateZoomLevelRadius(mapboxMap, location) /*meters projected to radius on zoom 16*/
|
||||
val renderCheck = {
|
||||
Math.abs(expectedRadius - mapboxMap.querySourceFeatures(LOCATION_SOURCE)[0].getNumberProperty(PROPERTY_ACCURACY_RADIUS).toFloat()) < 0.1
|
||||
}
|
||||
waitForRenderResult(uiController, renderCheck, true)
|
||||
|
||||
assertThat(renderCheck.invoke(), `is`(true))
|
||||
assertThat(
|
||||
Math.abs(expectedRadius - mapboxMap.querySourceFeatures(LOCATION_SOURCE)[0].getNumberProperty(PROPERTY_ACCURACY_RADIUS).toFloat()) < 0.1,
|
||||
`is`(true))
|
||||
}
|
||||
}
|
||||
executeComponentTest(componentAction)
|
||||
@@ -359,30 +344,25 @@ class LocationLayerControllerTest : EspressoTest() {
|
||||
fun accuracy_visibleWhenCameraMoved() {
|
||||
val componentAction = object : LocationComponentAction.OnPerformLocationComponentAction {
|
||||
override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap,
|
||||
uiController: UiController, context: Context) {
|
||||
component.activateLocationComponent(context, mapboxMap.style!!, false)
|
||||
style: Style, uiController: UiController, context: Context) {
|
||||
component.activateLocationComponent(context, style, false)
|
||||
component.isLocationComponentEnabled = true
|
||||
component.forceLocationUpdate(location)
|
||||
mapboxMap.waitForLayer(uiController, location, FOREGROUND_LAYER)
|
||||
|
||||
val target = LatLng(location)
|
||||
val zoom = 16.0
|
||||
mapboxMap.moveCamera(CameraUpdateFactory.newLatLngZoom(target, zoom))
|
||||
TestingAsyncUtils.waitForLayer(uiController, idlingResource.mapView)
|
||||
|
||||
val cameraCheck = {
|
||||
Math.abs(zoom - mapboxMap.cameraPosition.zoom) < 0.1
|
||||
&& Math.abs(target.latitude - mapboxMap.cameraPosition.target.latitude) < 0.1
|
||||
&& Math.abs(target.longitude - mapboxMap.cameraPosition.target.longitude) < 0.1
|
||||
}
|
||||
waitForRenderResult(uiController, cameraCheck, true)
|
||||
assertThat(Math.abs(zoom - mapboxMap.cameraPosition.zoom) < 0.1
|
||||
&& Math.abs(target.latitude - mapboxMap.cameraPosition.target.latitude) < 0.1
|
||||
&& Math.abs(target.longitude - mapboxMap.cameraPosition.target.longitude) < 0.1,
|
||||
`is`(true))
|
||||
|
||||
val expectedRadius = Utils.calculateZoomLevelRadius(mapboxMap, location) /*meters projected to radius on zoom 16*/
|
||||
val renderCheck = {
|
||||
Math.abs(expectedRadius - mapboxMap.querySourceFeatures(LOCATION_SOURCE)[0].getNumberProperty(PROPERTY_ACCURACY_RADIUS).toFloat()) < 0.1
|
||||
}
|
||||
waitForRenderResult(uiController, renderCheck, true)
|
||||
|
||||
assertThat(renderCheck.invoke(), `is`(true))
|
||||
assertThat(
|
||||
Math.abs(expectedRadius - mapboxMap.querySourceFeatures(LOCATION_SOURCE)[0].getNumberProperty(PROPERTY_ACCURACY_RADIUS).toFloat()) < 0.1,
|
||||
`is`(true))
|
||||
}
|
||||
}
|
||||
executeComponentTest(componentAction)
|
||||
@@ -392,12 +372,11 @@ class LocationLayerControllerTest : EspressoTest() {
|
||||
fun applyStyle_layerBelow_restoreLayerVisibility() {
|
||||
val componentAction = object : LocationComponentAction.OnPerformLocationComponentAction {
|
||||
override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap,
|
||||
uiController: UiController, context: Context) {
|
||||
component.activateLocationComponent(context, mapboxMap.style!!,false)
|
||||
style: Style, uiController: UiController, context: Context) {
|
||||
component.activateLocationComponent(context, style, false)
|
||||
component.isLocationComponentEnabled = true
|
||||
component.forceLocationUpdate(location)
|
||||
mapboxMap.waitForLayer(uiController, location, FOREGROUND_LAYER)
|
||||
uiController.loopMainThreadForAtLeast(150)
|
||||
TestingAsyncUtils.waitForLayer(uiController, idlingResource.mapView)
|
||||
|
||||
component.applyStyle(LocationComponentOptions.builder(context).layerBelow("road-label").build())
|
||||
|
||||
|
||||
@@ -7,6 +7,7 @@ import android.support.test.espresso.matcher.ViewMatchers.isDisplayed
|
||||
import android.view.View
|
||||
import com.mapbox.mapboxsdk.maps.MapboxMap
|
||||
import com.mapbox.mapboxsdk.location.LocationComponent
|
||||
import com.mapbox.mapboxsdk.maps.Style
|
||||
import org.hamcrest.Matcher
|
||||
|
||||
class LocationComponentAction(private val mapboxMap: MapboxMap,
|
||||
@@ -24,11 +25,12 @@ class LocationComponentAction(private val mapboxMap: MapboxMap,
|
||||
onPerformLocationComponentAction.onLocationComponentAction(
|
||||
mapboxMap.locationComponent,
|
||||
mapboxMap,
|
||||
mapboxMap.style!!,
|
||||
uiController,
|
||||
view.context)
|
||||
}
|
||||
|
||||
interface OnPerformLocationComponentAction {
|
||||
fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap, uiController: UiController, context: Context)
|
||||
fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap, style: Style, uiController: UiController, context: Context)
|
||||
}
|
||||
}
|
||||
@@ -28,51 +28,9 @@ fun MapboxMap.isLayerVisible(layerId: String): Boolean {
|
||||
return this.style!!.getLayer(layerId)?.visibility?.value?.equals(Property.VISIBLE)!!
|
||||
}
|
||||
|
||||
fun MapboxMap.waitForSource(uiController: UiController, sourceId: String) {
|
||||
var counter = 0
|
||||
val delay = MapboxTestingUtils.MAP_RENDER_DELAY
|
||||
while (this.querySourceFeatures(sourceId).isEmpty() && delay * counter < MapboxTestingUtils.RENDER_TIMEOUT) {
|
||||
uiController.loopMainThreadForAtLeast(delay)
|
||||
counter++
|
||||
}
|
||||
}
|
||||
|
||||
fun MapboxMap.waitForLayer(uiController: UiController, location: Location, layerId: String, shouldDisappear: Boolean = false) {
|
||||
var counter = 0
|
||||
val delay = MapboxTestingUtils.MAP_RENDER_DELAY
|
||||
while (
|
||||
if (shouldDisappear) this.queryRenderedFeatures(location, layerId).isNotEmpty() else (this.style == null || this.queryRenderedFeatures(location, layerId).isEmpty())
|
||||
&& delay * counter < MapboxTestingUtils.RENDER_TIMEOUT) {
|
||||
uiController.loopMainThreadForAtLeast(delay)
|
||||
counter++
|
||||
}
|
||||
}
|
||||
|
||||
fun MapboxMap.waitForStyle(uiController: UiController, mapboxMap: MapboxMap) {
|
||||
var counter = 0
|
||||
val delay = MapboxTestingUtils.MAP_RENDER_DELAY
|
||||
while ((mapboxMap.style == null && !mapboxMap.style?.isFullyLoaded!!) && delay * counter < MapboxTestingUtils.RENDER_TIMEOUT) {
|
||||
uiController.loopMainThreadForAtLeast(delay)
|
||||
counter++
|
||||
}
|
||||
}
|
||||
|
||||
inline fun waitForRenderResult(uiController: UiController, checkFunction: () -> Boolean, expectedResult: Boolean) {
|
||||
var counter = 0
|
||||
val delay = MapboxTestingUtils.MAP_RENDER_DELAY
|
||||
while (checkFunction.invoke() != expectedResult && delay * counter < MapboxTestingUtils.RENDER_TIMEOUT) {
|
||||
uiController.loopMainThreadForAtLeast(delay)
|
||||
counter++
|
||||
}
|
||||
}
|
||||
|
||||
class MapboxTestingUtils {
|
||||
companion object {
|
||||
|
||||
const val MAP_RENDER_DELAY = 250L
|
||||
const val MAP_CONNECTION_DELAY = 1000L
|
||||
const val RENDER_TIMEOUT = 5_500L
|
||||
|
||||
/**
|
||||
* Used to increase style load time for stress testing.
|
||||
*/
|
||||
@@ -14,7 +14,7 @@ import com.mapbox.mapboxsdk.style.sources.CustomGeometrySource;
|
||||
import com.mapbox.mapboxsdk.style.sources.GeoJsonSource;
|
||||
import com.mapbox.mapboxsdk.style.sources.GeometryTileProvider;
|
||||
import com.mapbox.mapboxsdk.testapp.activity.EspressoTest;
|
||||
import com.mapbox.mapboxsdk.testapp.utils.Utils;
|
||||
import com.mapbox.mapboxsdk.testapp.utils.TestingAsyncUtils;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
@@ -148,7 +148,7 @@ public class GeoJsonConversionTest extends EspressoTest {
|
||||
);
|
||||
mapboxMap.getStyle().addLayer(layer);
|
||||
|
||||
Utils.waitForLayer(uiController, mapboxMap, latLng, "layer");
|
||||
TestingAsyncUtils.INSTANCE.waitForLayer(uiController, idlingResource.getMapView());
|
||||
|
||||
assertFalse(mapboxMap.queryRenderedFeatures(mapboxMap.getProjection().toScreenLocation(latLng)).isEmpty());
|
||||
}));
|
||||
|
||||
@@ -17,6 +17,7 @@ import com.mapbox.mapboxsdk.style.types.Formatted;
|
||||
import com.mapbox.mapboxsdk.style.types.FormattedSection;
|
||||
import com.mapbox.mapboxsdk.testapp.R;
|
||||
import com.mapbox.mapboxsdk.testapp.activity.EspressoTest;
|
||||
import com.mapbox.mapboxsdk.testapp.utils.TestingAsyncUtils;
|
||||
import com.mapbox.mapboxsdk.testapp.utils.ResourceUtils;
|
||||
import com.mapbox.mapboxsdk.utils.ColorUtils;
|
||||
|
||||
@@ -53,7 +54,6 @@ import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.fillColor;
|
||||
import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.fillOutlineColor;
|
||||
import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.textField;
|
||||
import static com.mapbox.mapboxsdk.testapp.action.MapboxMapAction.invoke;
|
||||
import static com.mapbox.mapboxsdk.testapp.utils.Utils.waitForLayer;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNull;
|
||||
@@ -290,10 +290,10 @@ public class ExpressionTest extends EspressoTest {
|
||||
formatEntry("test")
|
||||
);
|
||||
layer.setProperties(textField(expression));
|
||||
waitForLayer(uiController, mapboxMap, latLng, "layer");
|
||||
TestingAsyncUtils.INSTANCE.waitForLayer(uiController, idlingResource.getMapView());
|
||||
|
||||
assertFalse(mapboxMap.queryRenderedFeatures(mapboxMap.getProjection().toScreenLocation(latLng), "layer")
|
||||
.isEmpty());
|
||||
|
||||
assertNull(layer.getTextField().getExpression());
|
||||
assertEquals(new Formatted(new FormattedSection("test")), layer.getTextField().getValue());
|
||||
});
|
||||
@@ -313,10 +313,10 @@ public class ExpressionTest extends EspressoTest {
|
||||
formatEntry("test", formatFontScale(1.75))
|
||||
);
|
||||
layer.setProperties(textField(expression));
|
||||
waitForLayer(uiController, mapboxMap, latLng, "layer");
|
||||
TestingAsyncUtils.INSTANCE.waitForLayer(uiController, idlingResource.getMapView());
|
||||
|
||||
assertFalse(mapboxMap.queryRenderedFeatures(mapboxMap.getProjection().toScreenLocation(latLng), "layer")
|
||||
.isEmpty());
|
||||
|
||||
assertNull(layer.getTextField().getExpression());
|
||||
assertEquals(new Formatted(new FormattedSection("test", 1.75)), layer.getTextField().getValue());
|
||||
});
|
||||
@@ -339,11 +339,11 @@ public class ExpressionTest extends EspressoTest {
|
||||
)
|
||||
);
|
||||
layer.setProperties(textField(expression));
|
||||
waitForLayer(uiController, mapboxMap, latLng, "layer");
|
||||
TestingAsyncUtils.INSTANCE.waitForLayer(uiController, idlingResource.getMapView());
|
||||
|
||||
assertFalse(
|
||||
mapboxMap.queryRenderedFeatures(mapboxMap.getProjection().toScreenLocation(latLng), "layer").isEmpty()
|
||||
);
|
||||
|
||||
assertNull(layer.getTextField().getExpression());
|
||||
assertEquals(new Formatted(
|
||||
new FormattedSection("test",
|
||||
@@ -370,11 +370,11 @@ public class ExpressionTest extends EspressoTest {
|
||||
)
|
||||
);
|
||||
layer.setProperties(textField(expression));
|
||||
waitForLayer(uiController, mapboxMap, latLng, "layer");
|
||||
TestingAsyncUtils.INSTANCE.waitForLayer(uiController, idlingResource.getMapView());
|
||||
|
||||
assertFalse(
|
||||
mapboxMap.queryRenderedFeatures(mapboxMap.getProjection().toScreenLocation(latLng), "layer").isEmpty()
|
||||
);
|
||||
|
||||
assertNull(layer.getTextField().getExpression());
|
||||
assertEquals(new Formatted(
|
||||
new FormattedSection("test",
|
||||
@@ -403,11 +403,11 @@ public class ExpressionTest extends EspressoTest {
|
||||
formatEntry("\ntest2", formatFontScale(2))
|
||||
);
|
||||
layer.setProperties(textField(expression));
|
||||
waitForLayer(uiController, mapboxMap, latLng, "layer");
|
||||
TestingAsyncUtils.INSTANCE.waitForLayer(uiController, idlingResource.getMapView());
|
||||
|
||||
assertFalse(
|
||||
mapboxMap.queryRenderedFeatures(mapboxMap.getProjection().toScreenLocation(latLng), "layer").isEmpty()
|
||||
);
|
||||
|
||||
assertNull(layer.getTextField().getExpression());
|
||||
assertEquals(new Formatted(
|
||||
new FormattedSection("test", 1.5,
|
||||
@@ -437,10 +437,10 @@ public class ExpressionTest extends EspressoTest {
|
||||
)
|
||||
);
|
||||
layer.setProperties(textField(expression));
|
||||
waitForLayer(uiController, mapboxMap, latLng, "layer");
|
||||
TestingAsyncUtils.INSTANCE.waitForLayer(uiController, idlingResource.getMapView());
|
||||
|
||||
assertFalse(mapboxMap.queryRenderedFeatures(mapboxMap.getProjection().toScreenLocation(latLng), "layer")
|
||||
.isEmpty());
|
||||
|
||||
assertEquals(expression, layer.getTextField().getExpression());
|
||||
assertNull(layer.getTextField().getValue());
|
||||
});
|
||||
@@ -467,10 +467,10 @@ public class ExpressionTest extends EspressoTest {
|
||||
formatEntry("\ntest2", formatFontScale(2))
|
||||
);
|
||||
layer.setProperties(textField(expression));
|
||||
waitForLayer(uiController, mapboxMap, latLng, "layer");
|
||||
TestingAsyncUtils.INSTANCE.waitForLayer(uiController, idlingResource.getMapView());
|
||||
|
||||
assertFalse(mapboxMap.queryRenderedFeatures(mapboxMap.getProjection().toScreenLocation(latLng), "layer")
|
||||
.isEmpty());
|
||||
|
||||
assertEquals(expression, layer.getTextField().getExpression());
|
||||
assertNull(layer.getTextField().getValue());
|
||||
});
|
||||
@@ -487,10 +487,10 @@ public class ExpressionTest extends EspressoTest {
|
||||
mapboxMap.getStyle().addLayer(layer);
|
||||
|
||||
layer.setProperties(textField("test"));
|
||||
waitForLayer(uiController, mapboxMap, latLng, "layer");
|
||||
TestingAsyncUtils.INSTANCE.waitForLayer(uiController, idlingResource.getMapView());
|
||||
|
||||
assertFalse(mapboxMap.queryRenderedFeatures(mapboxMap.getProjection().toScreenLocation(latLng), "layer")
|
||||
.isEmpty());
|
||||
|
||||
assertNull(layer.getTextField().getExpression());
|
||||
assertEquals(new Formatted(
|
||||
new FormattedSection("test")), layer.getTextField().getValue());
|
||||
@@ -512,10 +512,10 @@ public class ExpressionTest extends EspressoTest {
|
||||
new FormattedSection("\ntest", 0.5, new String[] {"Arial Unicode MS Regular", "DIN Offc Pro Regular"})
|
||||
);
|
||||
layer.setProperties(textField(formatted));
|
||||
waitForLayer(uiController, mapboxMap, latLng, "layer");
|
||||
TestingAsyncUtils.INSTANCE.waitForLayer(uiController, idlingResource.getMapView());
|
||||
|
||||
assertFalse(mapboxMap.queryRenderedFeatures(mapboxMap.getProjection().toScreenLocation(latLng), "layer")
|
||||
.isEmpty());
|
||||
|
||||
assertNull(layer.getTextField().getExpression());
|
||||
assertEquals(formatted, layer.getTextField().getValue());
|
||||
});
|
||||
|
||||
@@ -9,12 +9,13 @@ import com.mapbox.mapboxsdk.testapp.R;
|
||||
|
||||
public abstract class MapboxIdlingResource implements IdlingResource {
|
||||
|
||||
private MapView mapView;
|
||||
private MapboxMap mapboxMap;
|
||||
IdlingResource.ResourceCallback resourceCallback;
|
||||
|
||||
@UiThread
|
||||
void inflateMap(Activity activity) {
|
||||
MapView mapView = activity.findViewById(R.id.mapView);
|
||||
mapView = activity.findViewById(R.id.mapView);
|
||||
if (mapView != null) {
|
||||
mapView.getMapAsync(this::initMap);
|
||||
}
|
||||
@@ -38,4 +39,8 @@ public abstract class MapboxIdlingResource implements IdlingResource {
|
||||
public MapboxMap getMapboxMap() {
|
||||
return mapboxMap;
|
||||
}
|
||||
|
||||
public MapView getMapView() {
|
||||
return mapView;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package com.mapbox.mapboxsdk.testapp.utils
|
||||
|
||||
import android.support.test.espresso.UiController
|
||||
import com.mapbox.mapboxsdk.maps.MapView
|
||||
|
||||
object TestingAsyncUtils {
|
||||
private const val DEFAULT_TIMEOUT = 15_000L
|
||||
|
||||
fun waitForLayer(uiController: UiController, mapView: MapView) {
|
||||
val start = System.nanoTime() / 1E6
|
||||
var isIdle = false
|
||||
mapView.addOnDidBecomeIdleListener { isIdle = true }
|
||||
|
||||
while (!isIdle && System.nanoTime() / 1E6 - start < DEFAULT_TIMEOUT) {
|
||||
uiController.loopMainThreadForAtLeast(100)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,23 +0,0 @@
|
||||
package com.mapbox.mapboxsdk.testapp.utils;
|
||||
|
||||
import android.support.test.espresso.UiController;
|
||||
|
||||
import com.mapbox.mapboxsdk.geometry.LatLng;
|
||||
import com.mapbox.mapboxsdk.maps.MapboxMap;
|
||||
|
||||
import static org.junit.Assert.assertFalse;
|
||||
|
||||
public class Utils {
|
||||
|
||||
private static final long WAIT_TIMEOUT = 5000;
|
||||
private static final long WAIT_DELAY = 150;
|
||||
|
||||
public static void waitForLayer(UiController uiController, MapboxMap mapboxMap, LatLng latLng, String... layerIds) {
|
||||
int i = 0;
|
||||
while (mapboxMap.queryRenderedFeatures(mapboxMap.getProjection().toScreenLocation(latLng), layerIds).isEmpty()) {
|
||||
i++;
|
||||
assertFalse("Waiting for layer timed out", i * WAIT_DELAY > WAIT_TIMEOUT);
|
||||
uiController.loopMainThreadForAtLeast(WAIT_DELAY);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user