From 313756b084c11f7b5b594ad81a9e9f5dfdbd09bb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Paczos?= Date: Thu, 6 Sep 2018 12:43:11 +0200 Subject: [android] location saved state tests, default location engine deactivation test --- .../mapboxsdk/location/LocationComponent.java | 2 +- .../mapboxsdk/location/LocationComponentTest.kt | 106 +++++++++++++++++++-- 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() -- cgit v1.2.1