diff options
author | tobrun <tobrun.van.nuland@gmail.com> | 2019-03-15 13:40:28 +0100 |
---|---|---|
committer | Tobrun <tobrun@mapbox.com> | 2019-03-22 18:39:29 +0100 |
commit | 76df7d9cee6968e7e620f2f915254084f82d94ec (patch) | |
tree | 90375299226055c6061b052a8738836dfe054287 /platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java | |
parent | 5ea450b14bb84950f80bda3eeb9873fdbd736fc7 (diff) | |
download | qtlocation-mapboxgl-76df7d9cee6968e7e620f2f915254084f82d94ec.tar.gz |
[android] - add integration test suite
Diffstat (limited to 'platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java')
11 files changed, 300 insertions, 183 deletions
diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/integration/BaseIntegrationTest.kt b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/integration/BaseIntegrationTest.kt new file mode 100644 index 0000000000..4d39b55a25 --- /dev/null +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/integration/BaseIntegrationTest.kt @@ -0,0 +1,60 @@ +package com.mapbox.mapboxsdk.integration + +import android.content.Intent +import android.support.test.InstrumentationRegistry +import android.support.test.uiautomator.* +import org.hamcrest.CoreMatchers +import org.hamcrest.MatcherAssert +import org.junit.Before + +const val LAUNCH_TIMEOUT = 2500L +private const val TEST_APP_PACKAGE = "com.mapbox.mapboxsdk.testapp" + +abstract class BaseIntegrationTest { + + protected lateinit var device: UiDevice + + @Before + open fun beforeTest() { + // Initialize UiDevice instance + device = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation()) + + // Start from the home screen + device.pressHome() + + // Wait for launcher + val launcherPackage: String = device.launcherPackageName + MatcherAssert.assertThat(launcherPackage, CoreMatchers.notNullValue()) + device.wait(Until.hasObject(By.pkg(launcherPackage).depth(0)), LAUNCH_TIMEOUT) + + // Launch the app + val context = InstrumentationRegistry.getInstrumentation().context + val intent = context.packageManager.getLaunchIntentForPackage(TEST_APP_PACKAGE).apply { + // Clear out any previous instances + addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK) + } + context.startActivity(intent) + + // Wait for the app to appear + device.wait( + Until.hasObject(By.pkg(TEST_APP_PACKAGE).depth(0)), + LAUNCH_TIMEOUT + ) + } + + fun openFeature(featureName: String) { + scrollRecyclerViewTo(featureName) + device.findObject(UiSelector().text(featureName)).clickAndWaitForNewWindow() + device.waitForIdle(LAUNCH_TIMEOUT) + } + + fun scrollRecyclerViewTo(recycleItem: String) { + val appView = UiScrollable(UiSelector().scrollable(true)) + appView.scrollIntoView(UiSelector().text(recycleItem)) + } + + fun pressHomeReturnWithRecentApps(){ + device.pressRecentApps() + device.findObject(UiSelector().text(InstrumentationRegistry.getTargetContext().getString(InstrumentationRegistry.getTargetContext().applicationInfo.labelRes))).click() + } +}
\ No newline at end of file diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/integration/FragmentBackStackTest.kt b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/integration/FragmentBackStackTest.kt new file mode 100644 index 0000000000..f46ec153c3 --- /dev/null +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/integration/FragmentBackStackTest.kt @@ -0,0 +1,59 @@ +package com.mapbox.mapboxsdk.integration + +import android.support.test.filters.LargeTest +import android.support.test.runner.AndroidJUnit4 +import android.support.test.uiautomator.UiSelector +import org.junit.Before +import org.junit.Test +import org.junit.runner.RunWith + +/** + * Regression test that validates MapFragment integration on the backstack + */ +@RunWith(AndroidJUnit4::class) +class FragmentBackStackTest : BaseIntegrationTest() { + + @Before + override fun beforeTest() { + super.beforeTest() + openFeature("Backstack Map Fragment") + } + + @Test + @LargeTest + fun backPressedOnBackStack() { + device.waitForIdle() + clickReplaceFragmentButton() + device.waitForIdle() + backPressBackStack() + } + + @Test + @LargeTest + fun backPressedOnBackStackResumed(){ + device.waitForIdle() + clickReplaceFragmentButton() + device.waitForIdle() + pressHomeReturnWithRecentApps() + device.waitForIdle() + backPressBackStack() + } + + @Test + @LargeTest + fun finishOnBackStack() { + device.waitForIdle() + clickReplaceFragmentButton() + device.waitForIdle() + device.findObject(UiSelector().description("Navigate up")).click() + } + + private fun clickReplaceFragmentButton(){ + device.findObject(UiSelector().text("REPLACE WITH EMPTY FRAGMENT")).click() + } + + private fun backPressBackStack(){ + device.pressBack() // pops fragment, showing map + device.pressBack() // finish activity + } +}
\ No newline at end of file diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/integration/GLSurfaceViewReopenTest.kt b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/integration/GLSurfaceViewReopenTest.kt new file mode 100644 index 0000000000..07fea012eb --- /dev/null +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/integration/GLSurfaceViewReopenTest.kt @@ -0,0 +1,27 @@ +package com.mapbox.mapboxsdk.integration + +import android.support.test.filters.LargeTest +import android.support.test.runner.AndroidJUnit4 +import org.junit.Before +import org.junit.Test +import org.junit.runner.RunWith + +/** + * Regression test that validates reopening an Activity with a GLSurfaceView + */ +@RunWith(AndroidJUnit4::class) +class GLSurfaceViewReopenTest : BaseIntegrationTest() { + + @Before + override fun beforeTest() { + super.beforeTest() + openFeature("Simple Map") + } + + @Test + @LargeTest + fun reopenSimpleMapActivity() { + pressHomeReturnWithRecentApps() + device.waitForIdle() + } +}
\ No newline at end of file diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/integration/GLSurfaceViewReuseTest.kt b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/integration/GLSurfaceViewReuseTest.kt new file mode 100644 index 0000000000..95f05566c3 --- /dev/null +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/integration/GLSurfaceViewReuseTest.kt @@ -0,0 +1,30 @@ +package com.mapbox.mapboxsdk.integration + +import android.support.test.filters.LargeTest +import android.support.test.runner.AndroidJUnit4 +import org.junit.Before +import org.junit.Test +import org.junit.runner.RunWith + +/** + * Regression test that validates if a GLSurfaceView surface can be recreated without crashing. + */ +@RunWith(AndroidJUnit4::class) +class GLSurfaceViewReuseTest : BaseIntegrationTest() { + + @Before + override fun beforeTest() { + super.beforeTest() + openFeature("RecyclerView GLSurfaceView") + } + + @Test + @LargeTest + fun scrollRecylerView() { + device.waitForIdle() + scrollRecyclerViewTo("Twenty-one") + device.waitForIdle() + scrollRecyclerViewTo("One") + device.waitForIdle() + } +}
\ No newline at end of file diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/integration/OrientationChangeTest.kt b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/integration/OrientationChangeTest.kt new file mode 100644 index 0000000000..b79303a1a8 --- /dev/null +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/integration/OrientationChangeTest.kt @@ -0,0 +1,29 @@ +package com.mapbox.mapboxsdk.integration + +import android.support.test.filters.LargeTest +import android.support.test.runner.AndroidJUnit4 +import org.junit.Before +import org.junit.Test +import org.junit.runner.RunWith + +@RunWith(AndroidJUnit4::class) +class OrientationChangeTest : BaseIntegrationTest() { + + @Before + override fun beforeTest() { + super.beforeTest() + openFeature("Simple Map") + } + + @Test + @LargeTest + fun rotateSimpleMap() { + device.setOrientationLeft() + device.waitForIdle() + device.setOrientationNatural() + device.waitForIdle() + device.setOrientationRight() + device.waitForIdle() + device.setOrientationNatural() + } +}
\ No newline at end of file diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/integration/TextureViewReopenTest.kt b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/integration/TextureViewReopenTest.kt new file mode 100644 index 0000000000..3de8ece8c3 --- /dev/null +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/integration/TextureViewReopenTest.kt @@ -0,0 +1,29 @@ +package com.mapbox.mapboxsdk.integration + +import android.support.test.filters.LargeTest +import android.support.test.runner.AndroidJUnit4 +import org.junit.Before +import org.junit.Test +import org.junit.runner.RunWith +import java.lang.Thread.sleep + +/** + * Regression test that validates reopening an Activity with a TextureView + */ +@RunWith(AndroidJUnit4::class) +class TextureViewReopenTest : BaseIntegrationTest() { + + @Before + override fun beforeTest() { + super.beforeTest() + openFeature("TextureView debug") + } + + @Test + @LargeTest + fun reopenTextureViewDebugActivity() { + pressHomeReturnWithRecentApps() + device.waitForIdle() + sleep(LAUNCH_TIMEOUT) + } +}
\ No newline at end of file diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/integration/TextureViewReuseTest.kt b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/integration/TextureViewReuseTest.kt new file mode 100644 index 0000000000..6053e696d6 --- /dev/null +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/integration/TextureViewReuseTest.kt @@ -0,0 +1,29 @@ +package com.mapbox.mapboxsdk.integration + +import android.support.test.filters.LargeTest +import android.support.test.runner.AndroidJUnit4 +import org.junit.Before +import org.junit.Test +import org.junit.runner.RunWith + +/** + * Regression test that validates if a GLSurfaceView surface can be recreated without crashing. + */ +@RunWith(AndroidJUnit4::class) +class TextureViewReuseTest : BaseIntegrationTest() { + + @Before + override fun beforeTest() { + super.beforeTest() + openFeature("RecyclerView TextureView") + } + + @Test + @LargeTest + fun scrollRecylerView() { + scrollRecyclerViewTo("Twenty-one") + device.waitForIdle() + scrollRecyclerViewTo("One") + device.waitForIdle() + } +}
\ No newline at end of file diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/integration/ViewPagerScrollTest.kt b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/integration/ViewPagerScrollTest.kt new file mode 100644 index 0000000000..9f4b7591b6 --- /dev/null +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/integration/ViewPagerScrollTest.kt @@ -0,0 +1,37 @@ +package com.mapbox.mapboxsdk.integration + +import android.support.test.filters.LargeTest +import android.support.test.runner.AndroidJUnit4 +import android.support.test.uiautomator.UiSelector +import org.junit.Before +import org.junit.Test +import org.junit.runner.RunWith + +/** + * Regression test that validates MapFragment integration with a ViewPager + */ +@RunWith(AndroidJUnit4::class) +class ViewPagerScrollTest : BaseIntegrationTest() { + + @Before + override fun beforeTest() { + super.beforeTest() + openFeature("ViewPager") + } + + @Test + @LargeTest + fun scrollViewPager() { + for (i in 1..5) { + clickTab(i) + } + + for (i in 4 downTo 0) { + clickTab(i) + } + } + + private fun clickTab(index: Int) { + device.findObject(UiSelector().text("Page $index")).click() + } +}
\ No newline at end of file diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/maps/GLSurfaceViewReopenTest.kt b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/maps/GLSurfaceViewReopenTest.kt deleted file mode 100644 index 708b633db4..0000000000 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/maps/GLSurfaceViewReopenTest.kt +++ /dev/null @@ -1,72 +0,0 @@ -package com.mapbox.mapboxsdk.maps - -import android.content.Intent -import android.support.test.InstrumentationRegistry -import android.support.test.InstrumentationRegistry.getTargetContext -import android.support.test.filters.SdkSuppress -import android.support.test.runner.AndroidJUnit4 -import android.support.test.uiautomator.By -import android.support.test.uiautomator.UiDevice -import android.support.test.uiautomator.UiSelector -import android.support.test.uiautomator.Until -import org.hamcrest.CoreMatchers.notNullValue -import org.hamcrest.MatcherAssert.assertThat -import org.junit.Before -import org.junit.Test -import org.junit.runner.RunWith - -private const val BASIC_SAMPLE_PACKAGE = "com.mapbox.mapboxsdk.testapp" -private const val LAUNCH_TIMEOUT = 5000L - -@RunWith(AndroidJUnit4::class) -@SdkSuppress(minSdkVersion = 18) -class GLSurfaceViewReopenTest { - - private lateinit var device: UiDevice - - @Before - fun startSimpleMapActivityFromHomeScreen() { - // Initialize UiDevice instance - device = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation()) - - // Start from the home screen - device.pressHome() - - // Wait for launcher - val launcherPackage: String = device.launcherPackageName - assertThat(launcherPackage, notNullValue()) - device.wait(Until.hasObject(By.pkg(launcherPackage).depth(0)), LAUNCH_TIMEOUT) - - // Launch the app - val context = InstrumentationRegistry.getInstrumentation().context - val intent = context.packageManager.getLaunchIntentForPackage(BASIC_SAMPLE_PACKAGE).apply { - // Clear out any previous instances - addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK) - } - context.startActivity(intent) - - // Wait for the app to appear - device.wait( - Until.hasObject(By.pkg(BASIC_SAMPLE_PACKAGE).depth(0)), - LAUNCH_TIMEOUT - ) - - // open SimpleMapActivity - device.findObject(UiSelector().text("Simple Map")).clickAndWaitForNewWindow() - - // wait for idle - device.waitForIdle(LAUNCH_TIMEOUT) - } - - @Test - fun reopenSimpleMapActivity() { - // press recent apps button to pause the app - device.pressRecentApps() - - // return to app - device.findObject(UiSelector().text(getTargetContext().getString(getTargetContext().applicationInfo.labelRes))).click() - - // wait for idle - device.waitForIdle(LAUNCH_TIMEOUT) - } -}
\ No newline at end of file diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/maps/OrientationTest.java b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/maps/OrientationTest.java deleted file mode 100644 index 536f452493..0000000000 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/maps/OrientationTest.java +++ /dev/null @@ -1,41 +0,0 @@ -package com.mapbox.mapboxsdk.maps; - -import com.mapbox.mapboxsdk.testapp.action.OrientationAction; -import com.mapbox.mapboxsdk.testapp.action.WaitAction; -import com.mapbox.mapboxsdk.testapp.activity.BaseTest; -import com.mapbox.mapboxsdk.testapp.activity.camera.CameraAnimationTypeActivity; -import org.junit.Test; - -import static com.mapbox.mapboxsdk.testapp.action.OrientationAction.orientationLandscape; -import static com.mapbox.mapboxsdk.testapp.action.OrientationAction.orientationLandscapeReverse; -import static com.mapbox.mapboxsdk.testapp.action.OrientationAction.orientationPortrait; -import static com.mapbox.mapboxsdk.testapp.action.OrientationAction.orientationPortraitReverse; - -public class OrientationTest extends BaseTest { - - @Test - public void testChangeDeviceOrientation() { - OrientationAction.invoke(orientationLandscape()); - WaitAction.invoke(2200); - OrientationAction.invoke(orientationPortrait()); - WaitAction.invoke(2500); - OrientationAction.invoke(orientationLandscapeReverse()); - WaitAction.invoke(500); - OrientationAction.invoke(orientationPortraitReverse()); - WaitAction.invoke(1250); - OrientationAction.invoke(orientationLandscape()); - WaitAction.invoke(750); - OrientationAction.invoke(orientationPortrait()); - WaitAction.invoke(950); - OrientationAction.invoke(orientationLandscapeReverse()); - OrientationAction.invoke(orientationPortraitReverse()); - OrientationAction.invoke(orientationLandscape()); - OrientationAction.invoke(orientationPortrait()); - } - - @Override - protected Class getActivityClass() { - return CameraAnimationTypeActivity.class; - } - -} diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/maps/TextureViewReopenTest.kt b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/maps/TextureViewReopenTest.kt deleted file mode 100644 index 490f279b29..0000000000 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/maps/TextureViewReopenTest.kt +++ /dev/null @@ -1,70 +0,0 @@ -package com.mapbox.mapboxsdk.maps - -import android.content.Intent -import android.support.test.InstrumentationRegistry -import android.support.test.filters.SdkSuppress -import android.support.test.runner.AndroidJUnit4 -import android.support.test.uiautomator.* -import org.hamcrest.CoreMatchers.notNullValue -import org.hamcrest.MatcherAssert.assertThat -import org.junit.Before -import org.junit.Test -import org.junit.runner.RunWith - -private const val BASIC_SAMPLE_PACKAGE = "com.mapbox.mapboxsdk.testapp" -private const val LAUNCH_TIMEOUT = 5000L - -@RunWith(AndroidJUnit4::class) -@SdkSuppress(minSdkVersion = 18) -class TextureViewReopenTest { - - private lateinit var device: UiDevice - - @Before - fun startSimpleMapActivityFromHomeScreen() { - // Initialize UiDevice instance - device = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation()) - - // Start from the home screen - device.pressHome() - - // Wait for launcher - val launcherPackage: String = device.launcherPackageName - assertThat(launcherPackage, notNullValue()) - device.wait(Until.hasObject(By.pkg(launcherPackage).depth(0)), LAUNCH_TIMEOUT) - - // Launch the app - val context = InstrumentationRegistry.getInstrumentation().context - val intent = context.packageManager.getLaunchIntentForPackage(BASIC_SAMPLE_PACKAGE).apply { - // Clear out any previous instances - addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK) - } - context.startActivity(intent) - - // Wait for the app to appear - device.wait( - Until.hasObject(By.pkg(BASIC_SAMPLE_PACKAGE).depth(0)), - LAUNCH_TIMEOUT - ) - - // open TextureView debug activity - val appView = UiScrollable(UiSelector().scrollable(true)) - appView.scrollIntoView(UiSelector().text("TextureView debug")) - device.findObject(UiSelector().text("TextureView debug")).clickAndWaitForNewWindow() - - // wait for idle - device.waitForIdle(LAUNCH_TIMEOUT) - } - - @Test - fun reopenTextureViewDebugActivity() { - // press recent apps button - device.pressRecentApps() - - // return to app - device.findObject(UiSelector().text(InstrumentationRegistry.getTargetContext().getString(InstrumentationRegistry.getTargetContext().applicationInfo.labelRes))).click() - - // wait for idle - device.waitForIdle(LAUNCH_TIMEOUT) - } -}
\ No newline at end of file |