summaryrefslogtreecommitdiff
path: root/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/plugins/utils
diff options
context:
space:
mode:
Diffstat (limited to 'platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/plugins/utils')
-rw-r--r--platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/plugins/utils/GenericPluginAction.kt48
-rw-r--r--platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/plugins/utils/LocationLayerPluginAction.kt40
-rw-r--r--platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/plugins/utils/MapboxTestingUtils.kt30
-rw-r--r--platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/plugins/utils/PluginGenerationUtil.kt51
-rw-r--r--platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/plugins/utils/TestLifecycleOwner.kt19
5 files changed, 68 insertions, 120 deletions
diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/plugins/utils/GenericPluginAction.kt b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/plugins/utils/GenericPluginAction.kt
deleted file mode 100644
index 210f7b4758..0000000000
--- a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/plugins/utils/GenericPluginAction.kt
+++ /dev/null
@@ -1,48 +0,0 @@
-package com.mapbox.mapboxsdk.plugins.utils
-
-import android.content.Context
-import android.support.test.espresso.UiController
-import android.support.test.espresso.ViewAction
-import android.support.test.espresso.matcher.ViewMatchers.isDisplayed
-import android.view.View
-import com.mapbox.mapboxsdk.maps.MapView
-import com.mapbox.mapboxsdk.maps.MapboxMap
-import com.mapbox.mapboxsdk.plugins.utils.PluginGenerationUtil.Companion.MAP_RENDER_DELAY
-import org.hamcrest.Matcher
-
-class GenericPluginAction<T>(private val mapView: MapView, private val mapboxMap: MapboxMap, private val pluginProvider: PluginProvider<T>,
- private val onPerformGenericPluginAction: OnPerformGenericPluginAction<T>) : ViewAction {
-
- override fun getConstraints(): Matcher<View> {
- return isDisplayed()
- }
-
- override fun getDescription(): String {
- return javaClass.simpleName
- }
-
- override fun perform(uiController: UiController, view: View) {
- val plugin = pluginProvider.providePlugin(mapView, mapboxMap, view.context)
-
- // ensuring that the asynchronous renderer has time to render data we want to test
- uiController.loopMainThreadForAtLeast(MAP_RENDER_DELAY)
- while (!pluginProvider.isPluginDataReady(plugin, mapboxMap)) {
- uiController.loopMainThreadForAtLeast(MAP_RENDER_DELAY)
- }
-
- onPerformGenericPluginAction.onGenericPluginAction(
- plugin,
- mapboxMap,
- uiController,
- view.context)
- }
-
- interface OnPerformGenericPluginAction<in T> {
- fun onGenericPluginAction(plugin: T, mapboxMap: MapboxMap, uiController: UiController, context: Context)
- }
-
- interface PluginProvider<T> {
- fun providePlugin(mapView: MapView, mapboxMap: MapboxMap, context: Context): T
- fun isPluginDataReady(plugin: T, mapboxMap: MapboxMap): Boolean
- }
-} \ No newline at end of file
diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/plugins/utils/LocationLayerPluginAction.kt b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/plugins/utils/LocationLayerPluginAction.kt
new file mode 100644
index 0000000000..af2c9adf35
--- /dev/null
+++ b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/plugins/utils/LocationLayerPluginAction.kt
@@ -0,0 +1,40 @@
+package com.mapbox.mapboxsdk.plugins.utils
+
+import android.content.Context
+import android.support.test.espresso.UiController
+import android.support.test.espresso.ViewAction
+import android.support.test.espresso.matcher.ViewMatchers.isDisplayed
+import android.view.View
+import com.mapbox.mapboxsdk.maps.MapboxMap
+import com.mapbox.mapboxsdk.plugins.locationlayer.LocationLayerPlugin
+import org.hamcrest.Matcher
+
+class LocationLayerPluginAction(private val mapboxMap: MapboxMap,
+ private val onPerformLocationLayerPluginAction: OnPerformLocationLayerPluginAction) : ViewAction {
+
+ override fun getConstraints(): Matcher<View> {
+ return isDisplayed()
+ }
+
+ override fun getDescription(): String {
+ return javaClass.simpleName
+ }
+
+ override fun perform(uiController: UiController, view: View) {
+ val plugin = mapboxMap.locationLayerPlugin
+
+ while (mapboxMap.getSource("mapbox-location-source") == null) {
+ uiController.loopMainThreadForAtLeast(MapboxTestingUtils.MAP_RENDER_DELAY)
+ }
+
+ onPerformLocationLayerPluginAction.onLocationLayerPluginAction(
+ plugin,
+ mapboxMap,
+ uiController,
+ view.context)
+ }
+
+ interface OnPerformLocationLayerPluginAction {
+ fun onLocationLayerPluginAction(plugin: LocationLayerPlugin, mapboxMap: MapboxMap, uiController: UiController, context: Context)
+ }
+} \ No newline at end of file
diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/plugins/utils/MapboxTestingUtils.kt b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/plugins/utils/MapboxTestingUtils.kt
index b65cb3278b..b77ab127d9 100644
--- a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/plugins/utils/MapboxTestingUtils.kt
+++ b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/plugins/utils/MapboxTestingUtils.kt
@@ -7,6 +7,7 @@ import android.graphics.drawable.Drawable
import android.location.Location
import android.os.Handler
import android.os.Looper
+import android.support.test.espresso.UiController
import com.mapbox.geojson.Feature
import com.mapbox.mapboxsdk.geometry.LatLng
import com.mapbox.mapboxsdk.maps.MapboxMap
@@ -14,7 +15,7 @@ import com.mapbox.mapboxsdk.style.layers.Property
import com.mapbox.mapboxsdk.style.sources.GeoJsonSource
fun MapboxMap.querySourceFeatures(sourceId: String): List<Feature> {
- return this.getSourceAs<GeoJsonSource>(sourceId)?.querySourceFeatures(null) as List<Feature>
+ return this.getSourceAs<GeoJsonSource>(sourceId)?.querySourceFeatures(null) ?: emptyList()
}
fun MapboxMap.queryRenderedFeatures(location: Location, layerId: String): List<Feature> {
@@ -27,9 +28,34 @@ fun MapboxMap.isLayerVisible(layerId: String): Boolean {
return this.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.queryRenderedFeatures(location, layerId).isEmpty()
+ && 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 = 3_000L
+
/**
* Used to increase style load time for stress testing.
*/
@@ -71,7 +97,7 @@ fun MapboxMap.addImageFromDrawable(string: String, drawable: Drawable) {
private fun getBitmapFromDrawable(drawable: Drawable): Bitmap {
if (drawable is BitmapDrawable) return drawable.bitmap
val bitmap = Bitmap.createBitmap(drawable.intrinsicWidth,
- drawable.intrinsicHeight, Bitmap.Config.ARGB_8888)
+ drawable.intrinsicHeight, Bitmap.Config.ARGB_8888)
val canvas = Canvas(bitmap)
drawable.setBounds(0, 0, canvas.width, canvas.height)
drawable.draw(canvas)
diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/plugins/utils/PluginGenerationUtil.kt b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/plugins/utils/PluginGenerationUtil.kt
deleted file mode 100644
index 9049a28298..0000000000
--- a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/plugins/utils/PluginGenerationUtil.kt
+++ /dev/null
@@ -1,51 +0,0 @@
-package com.mapbox.mapboxsdk.plugins.utils
-
-import android.content.Context
-import android.support.v7.app.AppCompatActivity
-import com.mapbox.android.core.location.LocationEngine
-import com.mapbox.mapboxsdk.maps.MapView
-import com.mapbox.mapboxsdk.maps.MapboxMap
-import com.mapbox.mapboxsdk.plugins.locationlayer.LocationLayerOptions
-import com.mapbox.mapboxsdk.plugins.locationlayer.LocationLayerPlugin
-
-class PluginGenerationUtil {
- companion object {
- fun getLocationLayerPluginProvider(activity: AppCompatActivity,
- useDefaultEngine: Boolean = false,
- engine: LocationEngine? = null,
- options: LocationLayerOptions? = null,
- registerLifecycleObserver: Boolean = true)
- : GenericPluginAction.PluginProvider<LocationLayerPlugin> {
- return object : GenericPluginAction.PluginProvider<LocationLayerPlugin> {
- override fun providePlugin(mapView: MapView, mapboxMap: MapboxMap, context: Context): LocationLayerPlugin {
- val plugin = if (useDefaultEngine) {
- if (options != null) {
- LocationLayerPlugin(mapView, mapboxMap, options)
- } else {
- LocationLayerPlugin(mapView, mapboxMap)
- }
- } else {
- if (options != null) {
- LocationLayerPlugin(mapView, mapboxMap, engine, options)
- } else {
- LocationLayerPlugin(mapView, mapboxMap, engine)
- }
- }
-
- if (registerLifecycleObserver) {
- activity.lifecycle.addObserver(plugin)
- }
-
- return plugin
- }
-
- override fun isPluginDataReady(plugin: LocationLayerPlugin, mapboxMap: MapboxMap): Boolean {
- return mapboxMap.getSource("mapbox-location-source") != null
- }
- }
- }
-
- const val MAP_RENDER_DELAY = 250L
- const val MAP_CONNECTION_DELAY = 1000L
- }
-} \ No newline at end of file
diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/plugins/utils/TestLifecycleOwner.kt b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/plugins/utils/TestLifecycleOwner.kt
deleted file mode 100644
index ccb8da17a7..0000000000
--- a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/plugins/utils/TestLifecycleOwner.kt
+++ /dev/null
@@ -1,19 +0,0 @@
-package com.mapbox.mapboxsdk.plugins.utils
-
-import android.arch.lifecycle.Lifecycle
-import android.arch.lifecycle.LifecycleOwner
-import android.arch.lifecycle.LifecycleRegistry
-
-class TestLifecycleOwner : LifecycleOwner {
- private val lifecycleRegistry = LifecycleRegistry(this)
-
- override fun getLifecycle() = lifecycleRegistry
-
- fun markState(state: Lifecycle.State) {
- lifecycleRegistry.markState(state)
- }
-
- fun handleLifecycleEvent(event: Lifecycle.Event) {
- lifecycleRegistry.handleLifecycleEvent(event)
- }
-} \ No newline at end of file