Fix LazyScrollAccessibilityTests Instead of defining the sizes in dp we will use pixels to not depend on the density and how the rounding works. Fixes: 260010883 Fixes: 260011449 Fixes: 242180919 Test: run all LazyScrollAccessibilityTest`s Change-Id: Id239eb8ee6c42eae6e816c728b70e76dfbec9f5c
diff --git a/compose/foundation/foundation/src/androidAndroidTest/kotlin/androidx/compose/foundation/lazy/grid/LazyScrollAccessibilityTest.kt b/compose/foundation/foundation/src/androidAndroidTest/kotlin/androidx/compose/foundation/lazy/grid/LazyScrollAccessibilityTest.kt index 2293c1a..3371446 100644 --- a/compose/foundation/foundation/src/androidAndroidTest/kotlin/androidx/compose/foundation/lazy/grid/LazyScrollAccessibilityTest.kt +++ b/compose/foundation/foundation/src/androidAndroidTest/kotlin/androidx/compose/foundation/lazy/grid/LazyScrollAccessibilityTest.kt
@@ -32,7 +32,6 @@ import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.graphics.Color -import androidx.compose.ui.platform.LocalDensity import androidx.compose.ui.platform.LocalLayoutDirection import androidx.compose.ui.platform.LocalView import androidx.compose.ui.platform.testTag @@ -41,15 +40,15 @@ import androidx.compose.ui.test.assertIsDisplayed import androidx.compose.ui.test.onNodeWithTag import androidx.compose.ui.test.onNodeWithText +import androidx.compose.ui.unit.Dp import androidx.compose.ui.unit.LayoutDirection -import androidx.compose.ui.unit.dp import androidx.core.view.ViewCompat import androidx.core.view.accessibility.AccessibilityNodeInfoCompat.ACTION_SCROLL_BACKWARD import androidx.core.view.accessibility.AccessibilityNodeInfoCompat.ACTION_SCROLL_FORWARD import androidx.test.filters.MediumTest -import androidx.test.filters.SdkSuppress import com.google.common.truth.IterableSubject import com.google.common.truth.Truth.assertThat +import org.junit.Before import org.junit.Test import org.junit.runner.RunWith import org.junit.runners.Parameterized @@ -100,6 +99,22 @@ .provider as AccessibilityNodeProvider } + private val itemSize = 21 + private var itemSizeDp: Dp = Dp.Unspecified + private val containerSize = 200 + private var containerSizeDp: Dp = Dp.Unspecified + private val contentPadding = 50 + private var contentPaddingDp: Dp = Dp.Unspecified + + @Before + fun before() { + with(rule.density) { + itemSizeDp = itemSize.toDp() + containerSizeDp = containerSize.toDp() + contentPaddingDp = contentPadding.toDp() + } + } + @Test fun scrollForward() { testRelativeDirection(58, ACTION_SCROLL_FORWARD) @@ -148,7 +163,6 @@ ) } - @SdkSuppress(minSdkVersion = 29) // b/260010883 @Test fun verifyScrollActionsAtEnd() { createScrollableContent_StartAtEnd() @@ -277,13 +291,13 @@ private fun createScrollableContent_StartInMiddle() { createScrollableContent { // Start at the middle: - // Content size: 100 items * 21dp per item = 2100dp - // Viewport size: 200dp rect - 50dp padding on both sides = 100dp - // Content outside viewport: 2100dp - 100dp = 2000dp - // -> centered when 1000dp on either side, which is 47 items + 13dp + // Content size: 100 items * 21 per item = 2100 + // Viewport size: 200 rect - 50 padding on both sides = 100 + // Content outside viewport: 2100 - 100 = 2000 + // -> centered when 1000 on either side, which is 47 items + 13 rememberLazyGridState( 47, - with(LocalDensity.current) { 13.dp.roundToPx() } + 13 ) } } @@ -294,19 +308,19 @@ private fun createScrollableContent_StartAtEnd() { createScrollableContent { // Start at the end: - // Content size: 100 items * 21dp per item = 2100dp - // Viewport size: 200dp rect - 50dp padding on both sides = 100dp - // Content outside viewport: 2100dp - 100dp = 2000dp - // -> at the end when offset at 2000dp, which is 95 items + 5dp + // Content size: 100 items * 21 per item = 2100 + // Viewport size: 200 rect - 50 padding on both sides = 100 + // Content outside viewport: 2100 - 100 = 2000 + // -> at the end when offset at 2000, which is 95 items + 5 rememberLazyGridState( 95, - with(LocalDensity.current) { 5.dp.roundToPx() } + 5 ) } } /** - * Creates a grid with a viewport of 100.dp, containing 100 items each 17.dp in size. + * Creates a grid with a viewport of 100 px, containing 100 items each 21 px in size. * The items have a text with their index (ASC), and where the viewport starts is determined * by the given [lambda][rememberLazyGridState]. All properties from [config] are applied. * The viewport has padding around it to make sure scroll distance doesn't include padding. @@ -317,18 +331,18 @@ val state = rememberLazyGridState() - Box(Modifier.requiredSize(200.dp).background(Color.White)) { + Box(Modifier.requiredSize(containerSizeDp).background(Color.White)) { val direction = if (config.rtl) LayoutDirection.Rtl else LayoutDirection.Ltr CompositionLocalProvider(LocalLayoutDirection provides direction) { LazyGrid( cells = 1, modifier = Modifier.testTag(scrollerTag).matchParentSize(), state = state, - contentPadding = PaddingValues(50.dp), + contentPadding = PaddingValues(contentPaddingDp), reverseLayout = config.reversed ) { items(100) { - Box(Modifier.requiredSize(21.dp).background(Color.Yellow)) { + Box(Modifier.requiredSize(itemSizeDp).background(Color.Yellow)) { BasicText("$it", Modifier.align(Alignment.Center)) } }
diff --git a/compose/foundation/foundation/src/androidAndroidTest/kotlin/androidx/compose/foundation/lazy/list/LazyScrollAccessibilityTest.kt b/compose/foundation/foundation/src/androidAndroidTest/kotlin/androidx/compose/foundation/lazy/list/LazyScrollAccessibilityTest.kt index a29edf6..15fd4f6 100644 --- a/compose/foundation/foundation/src/androidAndroidTest/kotlin/androidx/compose/foundation/lazy/list/LazyScrollAccessibilityTest.kt +++ b/compose/foundation/foundation/src/androidAndroidTest/kotlin/androidx/compose/foundation/lazy/list/LazyScrollAccessibilityTest.kt
@@ -38,7 +38,6 @@ import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.graphics.Color -import androidx.compose.ui.platform.LocalDensity import androidx.compose.ui.platform.LocalLayoutDirection import androidx.compose.ui.platform.LocalView import androidx.compose.ui.platform.testTag @@ -48,15 +47,15 @@ import androidx.compose.ui.test.junit4.createAndroidComposeRule import androidx.compose.ui.test.onNodeWithTag import androidx.compose.ui.test.onNodeWithText +import androidx.compose.ui.unit.Dp import androidx.compose.ui.unit.LayoutDirection -import androidx.compose.ui.unit.dp import androidx.core.view.ViewCompat import androidx.core.view.accessibility.AccessibilityNodeInfoCompat.ACTION_SCROLL_BACKWARD import androidx.core.view.accessibility.AccessibilityNodeInfoCompat.ACTION_SCROLL_FORWARD import androidx.test.filters.MediumTest -import androidx.test.filters.SdkSuppress import com.google.common.truth.IterableSubject import com.google.common.truth.Truth.assertThat +import org.junit.Before import org.junit.Rule import org.junit.Test import org.junit.runner.RunWith @@ -107,6 +106,22 @@ .provider as AccessibilityNodeProvider } + private val itemSize = 21 + private var itemSizeDp: Dp = Dp.Unspecified + private val containerSize = 200 + private var containerSizeDp: Dp = Dp.Unspecified + private val contentPadding = 50 + private var contentPaddingDp: Dp = Dp.Unspecified + + @Before + fun before() { + with(rule.density) { + itemSizeDp = itemSize.toDp() + containerSizeDp = containerSize.toDp() + contentPaddingDp = contentPadding.toDp() + } + } + @Test fun scrollForward() { testRelativeDirection(58, ACTION_SCROLL_FORWARD) @@ -155,7 +170,6 @@ ) } - @SdkSuppress(minSdkVersion = 29) // b/260011449 @Test fun verifyScrollActionsAtEnd() { createScrollableContent_StartAtEnd() @@ -284,13 +298,13 @@ private fun createScrollableContent_StartInMiddle() { createScrollableContent { // Start at the middle: - // Content size: 100 items * 21dp per item = 2100dp - // Viewport size: 200dp rect - 50dp padding on both sides = 100dp - // Content outside viewport: 2100dp - 100dp = 2000dp - // -> centered when 1000dp on either side, which is 47 items + 13dp + // Content size: 100 items * 21 per item = 2100 + // Viewport size: 200 rect - 50 padding on both sides = 100 + // Content outside viewport: 2100 - 100 = 2000 + // -> centered when 1000 on either side, which is 47 items + 13 rememberLazyListState( 47, - with(LocalDensity.current) { 13.dp.roundToPx() } + 13 ) } } @@ -301,19 +315,19 @@ private fun createScrollableContent_StartAtEnd() { createScrollableContent { // Start at the end: - // Content size: 100 items * 21dp per item = 2100dp - // Viewport size: 200dp rect - 50dp padding on both sides = 100dp - // Content outside viewport: 2100dp - 100dp = 2000dp - // -> at the end when offset at 2000dp, which is 95 items + 5dp + // Content size: 100 items * 21 per item = 2100 + // Viewport size: 200 rect - 50 padding on both sides = 100 + // Content outside viewport: 2100 - 100 = 2000 + // -> at the end when offset at 2000, which is 95 items + 5 rememberLazyListState( 95, - with(LocalDensity.current) { 5.dp.roundToPx() } + 5 ) } } /** - * Creates a Row/Column with a viewport of 100.dp, containing 100 items each 17.dp in size. + * Creates a Row/Column with a viewport of 100 px, containing 100 items each 21 px in size. * The items have a text with their index (ASC), and where the viewport starts is determined * by the given [lambda][rememberLazyListState]. All properties from [config] are applied. * The viewport has padding around it to make sure scroll distance doesn't include padding. @@ -323,7 +337,7 @@ composeView = LocalView.current val lazyContent: LazyListScope.() -> Unit = { items(100) { - Box(Modifier.requiredSize(21.dp).background(Color.Yellow)) { + Box(Modifier.requiredSize(itemSizeDp).background(Color.Yellow)) { BasicText("$it", Modifier.align(Alignment.Center)) } } @@ -331,14 +345,14 @@ val state = rememberLazyListState() - Box(Modifier.requiredSize(200.dp).background(Color.White)) { + Box(Modifier.requiredSize(containerSizeDp).background(Color.White)) { val direction = if (config.rtl) LayoutDirection.Rtl else LayoutDirection.Ltr CompositionLocalProvider(LocalLayoutDirection provides direction) { if (config.horizontal) { LazyRow( Modifier.testTag(scrollerTag).matchParentSize(), state = state, - contentPadding = PaddingValues(50.dp), + contentPadding = PaddingValues(contentPaddingDp), reverseLayout = config.reversed, verticalAlignment = Alignment.CenterVertically ) { @@ -348,7 +362,7 @@ LazyColumn( Modifier.testTag(scrollerTag).matchParentSize(), state = state, - contentPadding = PaddingValues(50.dp), + contentPadding = PaddingValues(contentPaddingDp), reverseLayout = config.reversed, horizontalAlignment = Alignment.CenterHorizontally ) {
diff --git a/tv/tv-foundation/src/androidTest/java/androidx/tv/foundation/lazy/grid/LazyScrollAccessibilityTest.kt b/tv/tv-foundation/src/androidTest/java/androidx/tv/foundation/lazy/grid/LazyScrollAccessibilityTest.kt index a7bed08..aa11fda 100644 --- a/tv/tv-foundation/src/androidTest/java/androidx/tv/foundation/lazy/grid/LazyScrollAccessibilityTest.kt +++ b/tv/tv-foundation/src/androidTest/java/androidx/tv/foundation/lazy/grid/LazyScrollAccessibilityTest.kt
@@ -32,7 +32,6 @@ import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.graphics.Color -import androidx.compose.ui.platform.LocalDensity import androidx.compose.ui.platform.LocalLayoutDirection import androidx.compose.ui.platform.LocalView import androidx.compose.ui.platform.testTag @@ -41,15 +40,15 @@ import androidx.compose.ui.test.assertIsDisplayed import androidx.compose.ui.test.onNodeWithTag import androidx.compose.ui.test.onNodeWithText +import androidx.compose.ui.unit.Dp import androidx.compose.ui.unit.LayoutDirection -import androidx.compose.ui.unit.dp import androidx.core.view.ViewCompat import androidx.core.view.accessibility.AccessibilityNodeInfoCompat.ACTION_SCROLL_BACKWARD import androidx.core.view.accessibility.AccessibilityNodeInfoCompat.ACTION_SCROLL_FORWARD import androidx.test.filters.MediumTest import com.google.common.truth.IterableSubject import com.google.common.truth.Truth.assertThat -import org.junit.Ignore +import org.junit.Before import org.junit.Test import org.junit.runner.RunWith import org.junit.runners.Parameterized @@ -100,6 +99,22 @@ .provider as AccessibilityNodeProvider } + private val itemSize = 21 + private var itemSizeDp: Dp = Dp.Unspecified + private val containerSize = 200 + private var containerSizeDp: Dp = Dp.Unspecified + private val contentPadding = 50 + private var contentPaddingDp: Dp = Dp.Unspecified + + @Before + fun before() { + with(rule.density) { + itemSizeDp = itemSize.toDp() + containerSizeDp = containerSize.toDp() + contentPaddingDp = contentPadding.toDp() + } + } + @Test fun scrollForward() { testRelativeDirection(58, ACTION_SCROLL_FORWARD) @@ -148,7 +163,6 @@ ) } - @Ignore // b/242180919 @Test fun verifyScrollActionsAtEnd() { createScrollableContent_StartAtEnd() @@ -277,13 +291,13 @@ private fun createScrollableContent_StartInMiddle() { createScrollableContent { // Start at the middle: - // Content size: 100 items * 21dp per item = 2100dp - // Viewport size: 200dp rect - 50dp padding on both sides = 100dp - // Content outside viewport: 2100dp - 100dp = 2000dp - // -> centered when 1000dp on either side, which is 47 items + 13dp + // Content size: 100 items * 21 per item = 2100 + // Viewport size: 200 rect - 50 padding on both sides = 100 + // Content outside viewport: 2100 - 100 = 2000 + // -> centered when 1000 on either side, which is 47 items + 13 rememberTvLazyGridState( 47, - with(LocalDensity.current) { 13.dp.roundToPx() } + 13 ) } } @@ -294,19 +308,19 @@ private fun createScrollableContent_StartAtEnd() { createScrollableContent { // Start at the end: - // Content size: 100 items * 21dp per item = 2100dp - // Viewport size: 200dp rect - 50dp padding on both sides = 100dp - // Content outside viewport: 2100dp - 100dp = 2000dp - // -> at the end when offset at 2000dp, which is 95 items + 5dp + // Content size: 100 items * 21 per item = 2100 + // Viewport size: 200 rect - 50 padding on both sides = 100 + // Content outside viewport: 2100 - 100 = 2000 + // -> at the end when offset at 2000, which is 95 items + 5 rememberTvLazyGridState( 95, - with(LocalDensity.current) { 5.dp.roundToPx() } + 5 ) } } /** - * Creates a grid with a viewport of 100.dp, containing 100 items each 17.dp in size. + * Creates a grid with a viewport of 100 px, containing 100 items each 21 px in size. * The items have a text with their index (ASC), and where the viewport starts is determined * by the given [lambda][rememberTvLazyGridState]. All properties from [config] are applied. * The viewport has padding around it to make sure scroll distance doesn't include padding. @@ -319,18 +333,18 @@ val state = rememberTvLazyGridState() - Box(Modifier.requiredSize(200.dp).background(Color.White)) { + Box(Modifier.requiredSize(containerSizeDp).background(Color.White)) { val direction = if (config.rtl) LayoutDirection.Rtl else LayoutDirection.Ltr CompositionLocalProvider(LocalLayoutDirection provides direction) { LazyGrid( cells = 1, modifier = Modifier.testTag(scrollerTag).matchParentSize(), state = state, - contentPadding = PaddingValues(50.dp), + contentPadding = PaddingValues(contentPaddingDp), reverseLayout = config.reversed ) { items(100) { - Box(Modifier.requiredSize(21.dp).background(Color.Yellow)) { + Box(Modifier.requiredSize(itemSizeDp).background(Color.Yellow)) { BasicText("$it", Modifier.align(Alignment.Center)) } }