-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9d3fe62
commit 759d685
Showing
2 changed files
with
74 additions
and
56 deletions.
There are no files selected for viewing
56 changes: 0 additions & 56 deletions
56
orion-viewer/src/androidTest/kotlin/universe/constellation/orion/viewer/test/RotationTest.kt
This file was deleted.
Oops, something went wrong.
74 changes: 74 additions & 0 deletions
74
.../src/androidTest/kotlin/universe/constellation/orion/viewer/test/espresso/RotationTest.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,74 @@ | ||
package universe.constellation.orion.viewer.test.espresso | ||
|
||
import android.content.pm.ActivityInfo | ||
import androidx.test.filters.SdkSuppress | ||
import org.junit.After | ||
import org.junit.Assert | ||
import org.junit.Assert.assertFalse | ||
import org.junit.Assert.assertTrue | ||
import org.junit.Test | ||
import universe.constellation.orion.viewer.test.framework.BookDescription | ||
import universe.constellation.orion.viewer.view.OrionDrawScene | ||
|
||
class RotationTest : BaseEspressoTest(BookDescription.SICP) { | ||
|
||
@Test | ||
@SdkSuppress(minSdkVersion = 21) | ||
fun testScreenRotationAndViewSize() { | ||
assertTrue(device.isNaturalOrientation) | ||
|
||
val width = device.displayWidth | ||
val height = device.displayHeight | ||
assertTrue(width != 0) | ||
assertTrue(height != 0) | ||
val originSize = getViewSize() | ||
|
||
var orientation: Int = Int.MIN_VALUE | ||
activityScenarioRule.scenario.onActivity { | ||
orientation = it.resources!!.configuration.orientation | ||
it.controller!!.changeOrinatation(if (orientation == ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE) "PORTRAIT" else "LANDSCAPE") | ||
} | ||
device.waitForIdle() | ||
assertFalse(device.isNaturalOrientation) | ||
getViewSize() | ||
|
||
var newOrientation: Int = Int.MAX_VALUE | ||
activityScenarioRule.scenario.onActivity { | ||
newOrientation = it.resources!!.configuration.orientation | ||
} | ||
val rotatedSize = getViewSize() | ||
|
||
Assert.assertNotEquals("Orientation not changed: $orientation", orientation, newOrientation) | ||
val width2 = device.displayWidth | ||
val height2 = device.displayHeight | ||
assertTrue("w1: $width, w2: $width2, original orientation: $orientation", width != width2) | ||
assertTrue("h1: $height, h2: $$height2, original orientation: $orientation", height != height2) | ||
|
||
assertTrue("origin: $originSize, rotated: $rotatedSize, original orientation: $orientation", originSize != rotatedSize) | ||
|
||
activityScenarioRule.scenario.onActivity { | ||
it.controller!!.changeOrinatation("PORTRAIT") | ||
} | ||
device.waitForIdle() | ||
assertTrue(device.isNaturalOrientation) | ||
} | ||
|
||
private fun getViewSize(): Pair<Int, Int> { | ||
lateinit var view: OrionDrawScene | ||
activityScenarioRule.scenario.onActivity { | ||
view = it.view | ||
} | ||
|
||
val width = view.sceneWidth | ||
val height = view.sceneHeight | ||
|
||
assertTrue(width != 0) | ||
assertTrue(height != 0) | ||
return width to height | ||
} | ||
|
||
@After | ||
fun afterTest() { | ||
device.setOrientationNatural() | ||
} | ||
} |