-
Notifications
You must be signed in to change notification settings - Fork 139
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Port] Do no create new activities in re-use tests (#2600) (#2602)
- Loading branch information
Showing
13 changed files
with
167 additions
and
295 deletions.
There are no files selected for viewing
35 changes: 0 additions & 35 deletions
35
app/src/androidTest/java/com/mapbox/maps/testapp/integration/BaseIntegrationTest.kt
This file was deleted.
Oops, something went wrong.
77 changes: 77 additions & 0 deletions
77
app/src/androidTest/java/com/mapbox/maps/testapp/integration/BaseReuseIntegrationTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
...rc/androidTest/java/com/mapbox/maps/testapp/integration/surface/MapViewSurfaceModeTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
54 changes: 54 additions & 0 deletions
54
...ava/com/mapbox/maps/testapp/integration/surface/MapViewSurfaceModeWithRecyclerViewTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
} |
43 changes: 0 additions & 43 deletions
43
app/src/androidTest/java/com/mapbox/maps/testapp/integration/surface/SurfaceReopenTest.kt
This file was deleted.
Oops, something went wrong.
12 changes: 12 additions & 0 deletions
12
app/src/androidTest/java/com/mapbox/maps/testapp/integration/surface/SurfaceTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
32 changes: 0 additions & 32 deletions
32
...Test/java/com/mapbox/maps/testapp/integration/surface/SurfaceViewOrientationChangeTest.kt
This file was deleted.
Oops, something went wrong.
37 changes: 0 additions & 37 deletions
37
...src/androidTest/java/com/mapbox/maps/testapp/integration/surface/SurfaceViewReopenTest.kt
This file was deleted.
Oops, something went wrong.
45 changes: 0 additions & 45 deletions
45
app/src/androidTest/java/com/mapbox/maps/testapp/integration/surface/SurfaceViewReuseTest.kt
This file was deleted.
Oops, something went wrong.
9 changes: 9 additions & 0 deletions
9
...rc/androidTest/java/com/mapbox/maps/testapp/integration/texture/MapViewTextureModeTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
Oops, something went wrong.