Skip to content

Commit

Permalink
[Port] Do no create new activities in re-use tests (#2600) (#2602)
Browse files Browse the repository at this point in the history
  • Loading branch information
jush authored Jul 4, 2024
1 parent dc5c978 commit 21e8ac9
Show file tree
Hide file tree
Showing 13 changed files with 167 additions and 295 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
package com.mapbox.maps.testapp.integration

import android.app.Activity
import android.view.KeyEvent
import androidx.test.ext.junit.rules.ActivityScenarioRule
import androidx.test.filters.LargeTest
import androidx.test.platform.app.InstrumentationRegistry
import androidx.test.uiautomator.UiDevice
import org.junit.Rule
import org.junit.Test

abstract class BaseReuseIntegrationTest(activityClass: Class<out Activity>) {
protected val device: UiDevice by lazy { UiDevice.getInstance(InstrumentationRegistry.getInstrumentation()) }
private val testRepeatCount = 5

@get:Rule
var activityRule = ActivityScenarioRule(activityClass)

@Test
@LargeTest
fun reopenActivityWithHomeButton() {
repeat(testRepeatCount) {
device.waitForIdle()
device.pressHome()
device.waitForIdle()
// double click restores last opened application
device.pressKeyCode(KeyEvent.KEYCODE_APP_SWITCH)
device.waitForIdle()
device.pressKeyCode(KeyEvent.KEYCODE_APP_SWITCH)
// some time to set things up
Thread.sleep(1_000L)
}
}

@Test
@LargeTest
fun reopenActivityWithPowerButton() {
repeat(testRepeatCount) {
device.waitForIdle()
device.sleep()
Thread.sleep(2_000)
device.waitForIdle()
device.wakeUp()
Thread.sleep(2_000)
}
}

@Test
@LargeTest
fun rotateActivity() {
device.waitForIdle()
device.setOrientationLeft()
Thread.sleep(1_000)
device.waitForIdle()
device.setOrientationNatural()
Thread.sleep(1_000)
device.waitForIdle()
device.setOrientationRight()
Thread.sleep(1_000)
device.waitForIdle()
device.setOrientationNatural()
Thread.sleep(1_000)
device.waitForIdle()
device.setOrientationLeft()
Thread.sleep(1_000)
device.waitForIdle()
device.setOrientationNatural()
Thread.sleep(1_000)
device.waitForIdle()
device.setOrientationRight()
Thread.sleep(1_000)
device.waitForIdle()
device.setOrientationNatural()
Thread.sleep(1_000)
device.waitForIdle()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.mapbox.maps.testapp.integration.surface

import androidx.test.ext.junit.runners.AndroidJUnit4
import com.mapbox.maps.testapp.examples.SimpleMapActivity
import com.mapbox.maps.testapp.integration.BaseReuseIntegrationTest
import org.junit.runner.RunWith

@RunWith(AndroidJUnit4::class)
class MapViewSurfaceModeTest : BaseReuseIntegrationTest(SimpleMapActivity::class.java)
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package com.mapbox.maps.testapp.integration.surface

import androidx.recyclerview.widget.RecyclerView
import androidx.test.espresso.Espresso.onView
import androidx.test.espresso.ViewAssertion
import androidx.test.espresso.assertion.ViewAssertions.doesNotExist
import androidx.test.espresso.assertion.ViewAssertions.matches
import androidx.test.espresso.matcher.ViewMatchers.isDisplayed
import androidx.test.espresso.matcher.ViewMatchers.withClassName
import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.filters.LargeTest
import androidx.test.uiautomator.By
import androidx.test.uiautomator.Direction
import androidx.test.uiautomator.UiObject2
import com.mapbox.maps.testapp.examples.SurfaceRecyclerViewActivity
import com.mapbox.maps.testapp.integration.BaseReuseIntegrationTest
import org.hamcrest.core.Is
import org.junit.Test
import org.junit.runner.RunWith

/**
* Regression test that validates if a SurfaceView surface in a recycler view can be recreated
* without crashing.
*/
@RunWith(AndroidJUnit4::class)
class MapViewSurfaceModeWithRecyclerViewTest : BaseReuseIntegrationTest(SurfaceRecyclerViewActivity::class.java) {

@Test
@LargeTest
fun scrollSurfaceRecyclerView() {
// wait extra seconds to make sure recycler view is indeed added to hierarchy
Thread.sleep(2_000)
device.waitForIdle()
val recyclerObject = By.clazz(RecyclerView::class.java)
val recyclerView: UiObject2 = device.findObject(recyclerObject)
repeat(2) {
onMapView(matches(isDisplayed()))
recyclerView.scroll(Direction.DOWN, 100.0f)
device.waitForIdle()
onMapView(doesNotExist())
recyclerView.scroll(Direction.UP, 100.0f)
device.waitForIdle()
// Repeat up. Sometimes it didn't scroll all the way to first row
recyclerView.scroll(Direction.UP, 100.0f)
device.waitForIdle()
onMapView(matches(isDisplayed()))
}
}

private fun onMapView(matches: ViewAssertion?) {
onView(withClassName(Is.`is`("com.mapbox.maps.MapView")))
.check(matches)
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.mapbox.maps.testapp.integration.surface

import androidx.test.ext.junit.runners.AndroidJUnit4
import com.mapbox.maps.testapp.examples.SurfaceActivity
import com.mapbox.maps.testapp.integration.BaseReuseIntegrationTest
import org.junit.runner.RunWith

/**
* Regression test that validates reopening an Activity with a surface using ContextMode.SHARED
*/
@RunWith(AndroidJUnit4::class)
class SurfaceTest : BaseReuseIntegrationTest(SurfaceActivity::class.java)

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.mapbox.maps.testapp.integration.texture

import androidx.test.ext.junit.runners.AndroidJUnit4
import com.mapbox.maps.testapp.examples.TextureViewActivity
import com.mapbox.maps.testapp.integration.BaseReuseIntegrationTest
import org.junit.runner.RunWith

@RunWith(AndroidJUnit4::class)
class MapViewTextureModeTest : BaseReuseIntegrationTest(TextureViewActivity::class.java)
Loading

0 comments on commit 21e8ac9

Please sign in to comment.