summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorŁukasz Paczos <lukas.paczos@gmail.com>2018-09-06 12:43:11 +0200
committerŁukasz Paczos <lukasz.paczos@mapbox.com>2018-09-12 13:59:11 +0200
commitd4a2123bec4289848a4a0634d2727e2d4c77f180 (patch)
tree638990865072c21a479f90a9dcd7f4fbd1e40382
parent8cd86fe1b40c45ac634cce4bb8f989e663ef6ea2 (diff)
downloadqtlocation-mapboxgl-d4a2123bec4289848a4a0634d2727e2d4c77f180.tar.gz
[android] location saved state tests, default location engine deactivation test
-rw-r--r--platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/location/LocationComponent.java2
-rw-r--r--platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/location/LocationComponentTest.kt106
2 files changed, 100 insertions, 8 deletions
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/location/LocationComponent.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/location/LocationComponent.java
index 42c40634f9..c6b868f3da 100644
--- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/location/LocationComponent.java
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/location/LocationComponent.java
@@ -262,7 +262,7 @@ public final class LocationComponent {
*
* @return true if the plugin is enabled, false otherwise
*/
- public boolean isLocationLayerEnabled() {
+ public boolean isLocationComponentEnabled() {
return isEnabled;
}
diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/location/LocationComponentTest.kt b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/location/LocationComponentTest.kt
index 1d7c0c404b..6541abb748 100644
--- a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/location/LocationComponentTest.kt
+++ b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/location/LocationComponentTest.kt
@@ -6,6 +6,7 @@ import android.content.Context
import android.graphics.Color
import android.graphics.RectF
import android.location.Location
+import android.os.Bundle
import android.support.test.espresso.Espresso.onView
import android.support.test.espresso.IdlingRegistry
import android.support.test.espresso.UiController
@@ -491,12 +492,12 @@ class LocationComponentTest : BaseActivityTest() {
val componentAction = object : LocationComponentAction.OnPerformLocationComponentAction {
override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap,
uiController: UiController, context: Context) {
- assertThat(component.isLocationLayerEnabled, `is`(false))
+ assertThat(component.isLocationComponentEnabled, `is`(false))
component.onStop()
component.onStart()
- assertThat(component.isLocationLayerEnabled, `is`(false))
+ assertThat(component.isLocationComponentEnabled, `is`(false))
component.activateLocationComponent(context, false)
- assertThat(component.isLocationLayerEnabled, `is`(true))
+ assertThat(component.isLocationComponentEnabled, `is`(true))
}
}
executeComponentTest(componentAction)
@@ -508,10 +509,10 @@ class LocationComponentTest : BaseActivityTest() {
override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap,
uiController: UiController, context: Context) {
component.activateLocationComponent(context, false)
- assertThat(component.isLocationLayerEnabled, `is`(true))
+ assertThat(component.isLocationComponentEnabled, `is`(true))
component.onStop()
component.onStart()
- assertThat(component.isLocationLayerEnabled, `is`(true))
+ assertThat(component.isLocationComponentEnabled, `is`(true))
}
}
executeComponentTest(componentAction)
@@ -524,10 +525,10 @@ class LocationComponentTest : BaseActivityTest() {
uiController: UiController, context: Context) {
component.activateLocationComponent(context, false)
component.deactivateLocationComponent()
- assertThat(component.isLocationLayerEnabled, `is`(false))
+ assertThat(component.isLocationComponentEnabled, `is`(false))
component.onStop()
component.onStart()
- assertThat(component.isLocationLayerEnabled, `is`(false))
+ assertThat(component.isLocationComponentEnabled, `is`(false))
}
}
executeComponentTest(componentAction)
@@ -1092,6 +1093,97 @@ class LocationComponentTest : BaseActivityTest() {
executeComponentTest(componentAction)
}
+ @Test
+ fun savedState_bundleCreationDeactivated() {
+ val componentAction = object : LocationComponentAction.OnPerformLocationComponentAction {
+ override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap,
+ uiController: UiController, context: Context) {
+ val bundle = Bundle()
+ component.onSaveInstanceState(bundle)
+ assertThat(bundle.getBoolean(STATE_LOCATION_ENABLED), `is`(component.isLocationComponentEnabled))
+ assertThat(bundle.getParcelable(STATE_LOCATION_OPTIONS), `is`(equalTo(component.locationComponentOptions)))
+ assertThat(bundle.getInt(STATE_LOCATION_RENDER_MODE), `is`(equalTo(component.renderMode)))
+ assertThat(bundle.getInt(STATE_LOCATION_CAMERA_MODE), `is`(equalTo(component.cameraMode)))
+ assertThat(bundle.getParcelable(STATE_LOCATION_LAST_LOCATION), `is`(equalTo(component.lastKnownLocation)))
+ }
+ }
+
+ executeComponentTest(componentAction)
+ }
+
+ @Test
+ fun savedState_bundleCreationActivated() {
+ val componentAction = object : LocationComponentAction.OnPerformLocationComponentAction {
+ override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap,
+ uiController: UiController, context: Context) {
+ val options = LocationComponentOptions.builder(context)
+ .accuracyColor(Color.RED)
+ .build()
+ component.activateLocationComponent(null, options)
+ component.cameraMode = CameraMode.TRACKING
+ component.renderMode = RenderMode.GPS
+ component.forceLocationUpdate(location)
+ mapboxMap.waitForLayer(uiController, location, FOREGROUND_LAYER)
+
+ val bundle = Bundle()
+ component.onSaveInstanceState(bundle)
+ assertThat(bundle.getBoolean(STATE_LOCATION_ENABLED), `is`(component.isLocationComponentEnabled))
+ assertThat(bundle.getParcelable(STATE_LOCATION_OPTIONS), `is`(equalTo(component.locationComponentOptions)))
+ assertThat(bundle.getInt(STATE_LOCATION_RENDER_MODE), `is`(component.renderMode))
+ assertThat(bundle.getInt(STATE_LOCATION_CAMERA_MODE), `is`(component.cameraMode))
+ assertThat(bundle.getParcelable(STATE_LOCATION_LAST_LOCATION), `is`(equalTo(component.lastKnownLocation)))
+ }
+ }
+
+ executeComponentTest(componentAction)
+ }
+
+ @Test
+ fun savedState_componentRecreated() {
+ val componentAction = object : LocationComponentAction.OnPerformLocationComponentAction {
+ override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap,
+ uiController: UiController, context: Context) {
+ val options = LocationComponentOptions.builder(context)
+ .accuracyColor(Color.RED)
+ .build()
+
+ val bundle = Bundle()
+ bundle.putBoolean(STATE_LOCATION_ENABLED, true)
+ bundle.putParcelable(STATE_LOCATION_OPTIONS, options)
+ bundle.putInt(STATE_LOCATION_RENDER_MODE, RenderMode.GPS)
+ bundle.putInt(STATE_LOCATION_CAMERA_MODE, CameraMode.TRACKING)
+ bundle.putParcelable(STATE_LOCATION_LAST_LOCATION, location)
+
+ component.onRestoreInstanceState(bundle)
+ assertThat(component.isLocationComponentEnabled, `is`(true))
+ assertThat(component.locationComponentOptions, `is`(equalTo(options)))
+ assertThat(component.renderMode, `is`(RenderMode.GPS))
+ assertThat(component.cameraMode, `is`(CameraMode.TRACKING))
+ assertThat(component.lastKnownLocation, `is`(equalTo(location)))
+ }
+ }
+
+ executeComponentTest(componentAction)
+ }
+
+ @Test
+ fun defaultLocationEngine_deactivatedWhenDestroyed() {
+ val componentAction = object : LocationComponentAction.OnPerformLocationComponentAction {
+ override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap,
+ uiController: UiController, context: Context) {
+ component.activateLocationComponent(context)
+ uiController.loopMainThreadForAtLeast(MAP_CONNECTION_DELAY)
+ assertThat(component.locationEngine?.isConnected, `is`(true))
+
+ component.onStop()
+ component.onDestroy()
+ assertThat(component.locationEngine?.isConnected, `is`(false))
+ }
+ }
+
+ executeComponentTest(componentAction)
+ }
+
@After
override fun afterTest() {
super.afterTest()