Finish DrawerTest with click-at-position clicks
Bug: 147427614
Test: ./gradlew ui:ui-material:cC \
-Pandroid.testInstrumentationRunnerArguments.class=\
androidx.ui.material.DrawerTest
Change-Id: I0f63931ca9a3c53eb8be117c72467dfed82a9b88
diff --git a/ui/ui-material/src/androidTest/java/androidx/ui/material/DrawerTest.kt b/ui/ui-material/src/androidTest/java/androidx/ui/material/DrawerTest.kt
index 4f9080f..b6a64ad 100644
--- a/ui/ui-material/src/androidTest/java/androidx/ui/material/DrawerTest.kt
+++ b/ui/ui-material/src/androidTest/java/androidx/ui/material/DrawerTest.kt
@@ -16,6 +16,7 @@
package androidx.ui.material
+import android.os.SystemClock.sleep
import androidx.compose.Model
import androidx.test.filters.MediumTest
import androidx.ui.core.OnPositioned
@@ -24,14 +25,16 @@
import androidx.ui.layout.Container
import androidx.ui.semantics.Semantics
import androidx.ui.test.createComposeRule
-import androidx.ui.test.doClick
+import androidx.ui.test.doGesture
import androidx.ui.test.findByTag
+import androidx.ui.test.globalBounds
+import androidx.ui.test.sendClick
import androidx.ui.unit.PxPosition
import androidx.ui.unit.PxSize
import androidx.ui.unit.dp
+import androidx.ui.unit.px
import androidx.ui.unit.round
import com.google.common.truth.Truth.assertThat
-import org.junit.Ignore
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith
@@ -155,7 +158,6 @@
}
@Test
- @Ignore("(malkov/mount): unignore this when b/136678145 is fixed")
fun modalDrawer_bodyContent_clickable() {
var drawerClicks = 0
var bodyClicks = 0
@@ -179,8 +181,8 @@
}
}
- findByTag("Drawer")
- .doClick()
+ // Click in the middle of the drawer (which is the middle of the body)
+ findByTag("Drawer").doGesture { sendClick() }
composeTestRule.runOnIdleCompose {
assertThat(drawerClicks).isEqualTo(0)
@@ -188,9 +190,14 @@
drawerState.state = DrawerState.Opened
}
+ sleep(100) // TODO(147586311): remove this sleep when opening the drawer triggers a wait
- findByTag("Drawer")
- .doClick()
+ // Click on the left-center pixel of the drawer
+ findByTag("Drawer").doGesture {
+ val left = 1
+ val centerY = globalBounds.height / 2
+ sendClick(PxPosition(left.px, centerY.px))
+ }
composeTestRule.runOnIdleCompose {
assertThat(drawerClicks).isEqualTo(1)
@@ -199,7 +206,6 @@
}
@Test
- @Ignore("(malkov/mount): unignore this when b/136678145 is fixed")
fun bottomDrawer_bodyContent_clickable() {
var drawerClicks = 0
var bodyClicks = 0
@@ -223,25 +229,28 @@
}
}
- findByTag("Drawer")
- .doClick()
+ // Click in the middle of the drawer (which is the middle of the body)
+ findByTag("Drawer").doGesture { sendClick() }
composeTestRule.runOnIdleCompose {
assertThat(drawerClicks).isEqualTo(0)
assertThat(bodyClicks).isEqualTo(1)
}
- // TODO (malkov/pavlis) : uncomment this when custom onClick location will be implemented
-// composeTestRule.runOnUiThread {
-// drawerState.state = DrawerState.Opened
-// }
-// Thread.sleep(100L)
-//
-// findByTag("Drawer")
-// .doClick()
-//
-//
-// Truth.assertThat(drawerClicks).isEqualTo(1)
-// Truth.assertThat(bodyClicks).isEqualTo(1)
+ composeTestRule.runOnUiThread {
+ drawerState.state = DrawerState.Opened
+ }
+ sleep(100) // TODO(147586311): remove this sleep when opening the drawer triggers a wait
+
+ // Click on the bottom-center pixel of the drawer
+ findByTag("Drawer").doGesture {
+ val bounds = globalBounds
+ val centerX = bounds.width / 2
+ val bottom = bounds.height - 1
+ sendClick(PxPosition(centerX.px, bottom.px))
+ }
+
+ assertThat(drawerClicks).isEqualTo(1)
+ assertThat(bodyClicks).isEqualTo(1)
}
}
diff --git a/ui/ui-test/api/0.1.0-dev04.txt b/ui/ui-test/api/0.1.0-dev04.txt
index 0c1757b..c3b9767 100644
--- a/ui/ui-test/api/0.1.0-dev04.txt
+++ b/ui/ui-test/api/0.1.0-dev04.txt
@@ -144,6 +144,7 @@
}
public final class GestureScopeKt {
+ method public static androidx.ui.geometry.Rect getGlobalBounds(androidx.ui.test.GestureScope);
method public static void sendClick(androidx.ui.test.GestureScope, androidx.ui.unit.PxPosition position);
method public static void sendClick(androidx.ui.test.GestureScope);
method public static void sendDoubleClick(androidx.ui.test.GestureScope, androidx.ui.unit.PxPosition position);
@@ -156,6 +157,7 @@
method public static void sendSwipeRight(androidx.ui.test.GestureScope);
method public static void sendSwipeUp(androidx.ui.test.GestureScope);
method public static void sendSwipeWithVelocity(androidx.ui.test.GestureScope, androidx.ui.unit.PxPosition start, androidx.ui.unit.PxPosition end, @FloatRange(from=0.0) float endVelocity, androidx.ui.unit.Duration duration = 200.milliseconds);
+ method public static androidx.ui.unit.PxPosition toGlobalPosition(androidx.ui.test.GestureScope, androidx.ui.unit.PxPosition position);
}
public final class GoldenSemanticsKt {
diff --git a/ui/ui-test/api/current.txt b/ui/ui-test/api/current.txt
index 0c1757b..c3b9767 100644
--- a/ui/ui-test/api/current.txt
+++ b/ui/ui-test/api/current.txt
@@ -144,6 +144,7 @@
}
public final class GestureScopeKt {
+ method public static androidx.ui.geometry.Rect getGlobalBounds(androidx.ui.test.GestureScope);
method public static void sendClick(androidx.ui.test.GestureScope, androidx.ui.unit.PxPosition position);
method public static void sendClick(androidx.ui.test.GestureScope);
method public static void sendDoubleClick(androidx.ui.test.GestureScope, androidx.ui.unit.PxPosition position);
@@ -156,6 +157,7 @@
method public static void sendSwipeRight(androidx.ui.test.GestureScope);
method public static void sendSwipeUp(androidx.ui.test.GestureScope);
method public static void sendSwipeWithVelocity(androidx.ui.test.GestureScope, androidx.ui.unit.PxPosition start, androidx.ui.unit.PxPosition end, @FloatRange(from=0.0) float endVelocity, androidx.ui.unit.Duration duration = 200.milliseconds);
+ method public static androidx.ui.unit.PxPosition toGlobalPosition(androidx.ui.test.GestureScope, androidx.ui.unit.PxPosition position);
}
public final class GoldenSemanticsKt {
diff --git a/ui/ui-test/api/public_plus_experimental_0.1.0-dev04.txt b/ui/ui-test/api/public_plus_experimental_0.1.0-dev04.txt
index 0c1757b..c3b9767 100644
--- a/ui/ui-test/api/public_plus_experimental_0.1.0-dev04.txt
+++ b/ui/ui-test/api/public_plus_experimental_0.1.0-dev04.txt
@@ -144,6 +144,7 @@
}
public final class GestureScopeKt {
+ method public static androidx.ui.geometry.Rect getGlobalBounds(androidx.ui.test.GestureScope);
method public static void sendClick(androidx.ui.test.GestureScope, androidx.ui.unit.PxPosition position);
method public static void sendClick(androidx.ui.test.GestureScope);
method public static void sendDoubleClick(androidx.ui.test.GestureScope, androidx.ui.unit.PxPosition position);
@@ -156,6 +157,7 @@
method public static void sendSwipeRight(androidx.ui.test.GestureScope);
method public static void sendSwipeUp(androidx.ui.test.GestureScope);
method public static void sendSwipeWithVelocity(androidx.ui.test.GestureScope, androidx.ui.unit.PxPosition start, androidx.ui.unit.PxPosition end, @FloatRange(from=0.0) float endVelocity, androidx.ui.unit.Duration duration = 200.milliseconds);
+ method public static androidx.ui.unit.PxPosition toGlobalPosition(androidx.ui.test.GestureScope, androidx.ui.unit.PxPosition position);
}
public final class GoldenSemanticsKt {
diff --git a/ui/ui-test/api/public_plus_experimental_current.txt b/ui/ui-test/api/public_plus_experimental_current.txt
index 0c1757b..c3b9767 100644
--- a/ui/ui-test/api/public_plus_experimental_current.txt
+++ b/ui/ui-test/api/public_plus_experimental_current.txt
@@ -144,6 +144,7 @@
}
public final class GestureScopeKt {
+ method public static androidx.ui.geometry.Rect getGlobalBounds(androidx.ui.test.GestureScope);
method public static void sendClick(androidx.ui.test.GestureScope, androidx.ui.unit.PxPosition position);
method public static void sendClick(androidx.ui.test.GestureScope);
method public static void sendDoubleClick(androidx.ui.test.GestureScope, androidx.ui.unit.PxPosition position);
@@ -156,6 +157,7 @@
method public static void sendSwipeRight(androidx.ui.test.GestureScope);
method public static void sendSwipeUp(androidx.ui.test.GestureScope);
method public static void sendSwipeWithVelocity(androidx.ui.test.GestureScope, androidx.ui.unit.PxPosition start, androidx.ui.unit.PxPosition end, @FloatRange(from=0.0) float endVelocity, androidx.ui.unit.Duration duration = 200.milliseconds);
+ method public static androidx.ui.unit.PxPosition toGlobalPosition(androidx.ui.test.GestureScope, androidx.ui.unit.PxPosition position);
}
public final class GoldenSemanticsKt {
diff --git a/ui/ui-test/api/restricted_0.1.0-dev04.txt b/ui/ui-test/api/restricted_0.1.0-dev04.txt
index 0c1757b..c3b9767 100644
--- a/ui/ui-test/api/restricted_0.1.0-dev04.txt
+++ b/ui/ui-test/api/restricted_0.1.0-dev04.txt
@@ -144,6 +144,7 @@
}
public final class GestureScopeKt {
+ method public static androidx.ui.geometry.Rect getGlobalBounds(androidx.ui.test.GestureScope);
method public static void sendClick(androidx.ui.test.GestureScope, androidx.ui.unit.PxPosition position);
method public static void sendClick(androidx.ui.test.GestureScope);
method public static void sendDoubleClick(androidx.ui.test.GestureScope, androidx.ui.unit.PxPosition position);
@@ -156,6 +157,7 @@
method public static void sendSwipeRight(androidx.ui.test.GestureScope);
method public static void sendSwipeUp(androidx.ui.test.GestureScope);
method public static void sendSwipeWithVelocity(androidx.ui.test.GestureScope, androidx.ui.unit.PxPosition start, androidx.ui.unit.PxPosition end, @FloatRange(from=0.0) float endVelocity, androidx.ui.unit.Duration duration = 200.milliseconds);
+ method public static androidx.ui.unit.PxPosition toGlobalPosition(androidx.ui.test.GestureScope, androidx.ui.unit.PxPosition position);
}
public final class GoldenSemanticsKt {
diff --git a/ui/ui-test/api/restricted_current.txt b/ui/ui-test/api/restricted_current.txt
index 0c1757b..c3b9767 100644
--- a/ui/ui-test/api/restricted_current.txt
+++ b/ui/ui-test/api/restricted_current.txt
@@ -144,6 +144,7 @@
}
public final class GestureScopeKt {
+ method public static androidx.ui.geometry.Rect getGlobalBounds(androidx.ui.test.GestureScope);
method public static void sendClick(androidx.ui.test.GestureScope, androidx.ui.unit.PxPosition position);
method public static void sendClick(androidx.ui.test.GestureScope);
method public static void sendDoubleClick(androidx.ui.test.GestureScope, androidx.ui.unit.PxPosition position);
@@ -156,6 +157,7 @@
method public static void sendSwipeRight(androidx.ui.test.GestureScope);
method public static void sendSwipeUp(androidx.ui.test.GestureScope);
method public static void sendSwipeWithVelocity(androidx.ui.test.GestureScope, androidx.ui.unit.PxPosition start, androidx.ui.unit.PxPosition end, @FloatRange(from=0.0) float endVelocity, androidx.ui.unit.Duration duration = 200.milliseconds);
+ method public static androidx.ui.unit.PxPosition toGlobalPosition(androidx.ui.test.GestureScope, androidx.ui.unit.PxPosition position);
}
public final class GoldenSemanticsKt {
diff --git a/ui/ui-test/src/main/java/androidx/ui/test/GestureScope.kt b/ui/ui-test/src/main/java/androidx/ui/test/GestureScope.kt
index 619f397..2003538 100644
--- a/ui/ui-test/src/main/java/androidx/ui/test/GestureScope.kt
+++ b/ui/ui-test/src/main/java/androidx/ui/test/GestureScope.kt
@@ -65,14 +65,23 @@
*/
private val doubleClickDelay = 145.milliseconds
-private fun GestureScope.getGlobalBounds(): Rect {
- return requireNotNull(semanticsTreeNode.globalRect) {
- "Semantic Node has no child layout to resolve coordinates on"
+/**
+ * Returns the global bounds of the component we're interacting with
+ */
+val GestureScope.globalBounds: Rect
+ get() {
+ return requireNotNull(semanticsTreeNode.globalRect) {
+ "Semantic Node has no child layout to resolve coordinates on"
+ }
}
-}
-private fun GestureScope.toGlobalPosition(position: PxPosition): PxPosition {
- val bounds = getGlobalBounds()
+/**
+ * Transforms the [position] to global coordinates, as defined by [globalBounds]
+ *
+ * @param position A position in local coordinates
+ */
+fun GestureScope.toGlobalPosition(position: PxPosition): PxPosition {
+ val bounds = globalBounds
return position + PxPosition(bounds.left.px, bounds.top.px)
}
@@ -97,7 +106,7 @@
* Throws [AssertionError] when the component doesn't have a bounding rectangle set
*/
fun GestureScope.sendClick() {
- val bounds = getGlobalBounds()
+ val bounds = globalBounds
sendClick(PxPosition(Px(bounds.width / 2), Px(bounds.height / 2)))
}
@@ -122,7 +131,7 @@
* Throws [AssertionError] when the component doesn't have a bounding rectangle set
*/
fun GestureScope.sendLongClick() {
- val bounds = getGlobalBounds()
+ val bounds = globalBounds
sendLongClick(PxPosition(Px(bounds.width / 2), Px(bounds.height / 2)))
}
@@ -150,7 +159,7 @@
* Throws [AssertionError] when the component doesn't have a bounding rectangle set
*/
fun GestureScope.sendDoubleClick() {
- val bounds = getGlobalBounds()
+ val bounds = globalBounds
sendDoubleClick(PxPosition(Px(bounds.width / 2), Px(bounds.height / 2)))
}
@@ -246,7 +255,7 @@
* Throws [AssertionError] when the component doesn't have a bounding rectangle set
*/
fun GestureScope.sendSwipeUp() {
- val bounds = getGlobalBounds()
+ val bounds = globalBounds
val x = bounds.width / 2
val y0 = bounds.height * (1 - edgeFuzzFactor)
val y1 = 0f
@@ -262,7 +271,7 @@
* Throws [AssertionError] when the component doesn't have a bounding rectangle set
*/
fun GestureScope.sendSwipeDown() {
- val bounds = getGlobalBounds()
+ val bounds = globalBounds
val x = bounds.width / 2
val y0 = bounds.height * edgeFuzzFactor
val y1 = bounds.height
@@ -278,7 +287,7 @@
* Throws [AssertionError] when the component doesn't have a bounding rectangle set
*/
fun GestureScope.sendSwipeLeft() {
- val bounds = getGlobalBounds()
+ val bounds = globalBounds
val x0 = bounds.width * (1 - edgeFuzzFactor)
val x1 = 0f
val y = bounds.height / 2
@@ -294,7 +303,7 @@
* Throws [AssertionError] when the component doesn't have a bounding rectangle set
*/
fun GestureScope.sendSwipeRight() {
- val bounds = getGlobalBounds()
+ val bounds = globalBounds
val x0 = bounds.width * edgeFuzzFactor
val x1 = bounds.width
val y = bounds.height / 2