Revert "Revert "CTS for scrollbar dimensions""
This reverts commit 41a16ca7b6f16ebd7ec83a6b4d2691c1ec0f940d
and fixes the bug in the test that was the reason for the
original revert.
Test: android.view.cts.ViewTest compiles and passes.
Change-Id: Icaddbe95fce9742c7ce678dd2e7f9412cbea74e3
diff --git a/tests/tests/view/res/drawable/scrollbar_no_size.xml b/tests/tests/view/res/drawable/scrollbar_no_size.xml
new file mode 100644
index 0000000..88a59f0
--- /dev/null
+++ b/tests/tests/view/res/drawable/scrollbar_no_size.xml
@@ -0,0 +1,20 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2017 The Android Open Source Project
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+
+<shape xmlns:android="http://schemas.android.com/apk/res/android"
+ android:shape="rectangle">
+ <solid android:color="@android:color/white" />
+</shape>
diff --git a/tests/tests/view/res/drawable/scrollbar_thumb.xml b/tests/tests/view/res/drawable/scrollbar_thumb.xml
new file mode 100644
index 0000000..d7612ac
--- /dev/null
+++ b/tests/tests/view/res/drawable/scrollbar_thumb.xml
@@ -0,0 +1,23 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2017 The Android Open Source Project
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+
+<shape xmlns:android="http://schemas.android.com/apk/res/android"
+ android:shape="rectangle">
+ <solid android:color="@android:color/white" />
+ <size
+ android:width="@dimen/scrollbar_thumb_width"
+ android:height="@dimen/scrollbar_thumb_height"/>
+</shape>
diff --git a/tests/tests/view/res/drawable/scrollbar_track.xml b/tests/tests/view/res/drawable/scrollbar_track.xml
new file mode 100644
index 0000000..a184569
--- /dev/null
+++ b/tests/tests/view/res/drawable/scrollbar_track.xml
@@ -0,0 +1,23 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2017 The Android Open Source Project
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+
+<shape xmlns:android="http://schemas.android.com/apk/res/android"
+ android:shape="rectangle">
+ <solid android:color="@android:color/white" />
+ <size
+ android:width="@dimen/scrollbar_track_width"
+ android:height="@dimen/scrollbar_track_height"/>
+</shape>
diff --git a/tests/tests/view/res/layout/view_layout.xml b/tests/tests/view/res/layout/view_layout.xml
index 920da83..3cfaafa 100644
--- a/tests/tests/view/res/layout/view_layout.xml
+++ b/tests/tests/view/res/layout/view_layout.xml
@@ -46,6 +46,42 @@
android:requiresFadingEdge="horizontal|vertical"
android:fadingEdgeLength="20px"/>
+ <android.view.cts.MockView
+ android:id="@+id/scroll_view_3"
+ android:layout_width="100px"
+ android:layout_height="200px"
+ android:scrollbars="horizontal|vertical"
+ android:scrollbarThumbVertical="@drawable/scrollbar_no_size"
+ android:scrollbarThumbHorizontal="@drawable/scrollbar_no_size"/>
+
+ <android.view.cts.MockView
+ android:id="@+id/scroll_view_4"
+ android:layout_width="100px"
+ android:layout_height="200px"
+ android:scrollbars="horizontal|vertical"
+ android:scrollbarThumbVertical="@drawable/scrollbar_thumb"
+ android:scrollbarThumbHorizontal="@drawable/scrollbar_thumb"/>
+
+ <android.view.cts.MockView
+ android:id="@+id/scroll_view_5"
+ android:layout_width="100px"
+ android:layout_height="200px"
+ android:scrollbars="horizontal|vertical"
+ android:scrollbarThumbVertical="@drawable/scrollbar_thumb"
+ android:scrollbarTrackVertical="@drawable/scrollbar_track"
+ android:scrollbarThumbHorizontal="@drawable/scrollbar_thumb"
+ android:scrollbarTrackHorizontal="@drawable/scrollbar_track"/>
+
+ <android.view.cts.MockView
+ android:id="@+id/scroll_view_6"
+ android:layout_width="100px"
+ android:layout_height="200px"
+ android:scrollbars="horizontal|vertical"
+ android:scrollbarThumbVertical="@drawable/scrollbar_thumb"
+ android:scrollbarTrackVertical="@drawable/scrollbar_no_size"
+ android:scrollbarThumbHorizontal="@drawable/scrollbar_thumb"
+ android:scrollbarTrackHorizontal="@drawable/scrollbar_no_size"/>
+
<View
android:id="@+id/fit_windows"
android:fitsSystemWindows="true"
diff --git a/tests/tests/view/res/values/dimens.xml b/tests/tests/view/res/values/dimens.xml
index 5680de0..5ae23c2 100644
--- a/tests/tests/view/res/values/dimens.xml
+++ b/tests/tests/view/res/values/dimens.xml
@@ -41,4 +41,8 @@
<dimen name="hover_target_margin">4dp</dimen>
<dimen name="hover_target_size">8dp</dimen>
<dimen name="hover_target_size_double">16dp</dimen>
+ <dimen name="scrollbar_thumb_width">11dp</dimen>
+ <dimen name="scrollbar_thumb_height">12dp</dimen>
+ <dimen name="scrollbar_track_width">13dp</dimen>
+ <dimen name="scrollbar_track_height">14dp</dimen>
</resources>
\ No newline at end of file
diff --git a/tests/tests/view/src/android/view/cts/ViewTest.java b/tests/tests/view/src/android/view/cts/ViewTest.java
index 2550915..4eaa413 100644
--- a/tests/tests/view/src/android/view/cts/ViewTest.java
+++ b/tests/tests/view/src/android/view/cts/ViewTest.java
@@ -3661,6 +3661,67 @@
}
@Test
+ public void testScrollbarSize() {
+ final int configScrollbarSize = ViewConfiguration.get(mActivity).getScaledScrollBarSize();
+ final int customScrollbarSize = configScrollbarSize * 2;
+
+ // No explicit scrollbarSize or custom drawables, ViewConfiguration applies.
+ final MockView view = (MockView) mActivity.findViewById(R.id.scroll_view);
+ assertEquals(configScrollbarSize, view.getScrollBarSize());
+ assertEquals(configScrollbarSize, view.getVerticalScrollbarWidth());
+ assertEquals(configScrollbarSize, view.getHorizontalScrollbarHeight());
+
+ // No custom drawables, explicit scrollbarSize takes precedence.
+ final MockView view2 = (MockView) mActivity.findViewById(R.id.scroll_view_2);
+ view2.setScrollBarSize(customScrollbarSize);
+ assertEquals(customScrollbarSize, view2.getScrollBarSize());
+ assertEquals(customScrollbarSize, view2.getVerticalScrollbarWidth());
+ assertEquals(customScrollbarSize, view2.getHorizontalScrollbarHeight());
+
+ // Custom drawables with no intrinsic size, ViewConfiguration applies.
+ final MockView view3 = (MockView) mActivity.findViewById(R.id.scroll_view_3);
+ assertEquals(configScrollbarSize, view3.getVerticalScrollbarWidth());
+ assertEquals(configScrollbarSize, view3.getHorizontalScrollbarHeight());
+ // Explicit scrollbarSize takes precedence.
+ view3.setScrollBarSize(customScrollbarSize);
+ assertEquals(view3.getScrollBarSize(), view3.getVerticalScrollbarWidth());
+ assertEquals(view3.getScrollBarSize(), view3.getHorizontalScrollbarHeight());
+
+ // Custom thumb drawables with intrinsic sizes define the scrollbars' dimensions.
+ final MockView view4 = (MockView) mActivity.findViewById(R.id.scroll_view_4);
+ final Resources res = mActivity.getResources();
+ final int thumbWidth = res.getDimensionPixelSize(R.dimen.scrollbar_thumb_width);
+ final int thumbHeight = res.getDimensionPixelSize(R.dimen.scrollbar_thumb_height);
+ assertEquals(thumbWidth, view4.getVerticalScrollbarWidth());
+ assertEquals(thumbHeight, view4.getHorizontalScrollbarHeight());
+ // Explicit scrollbarSize has no effect.
+ view4.setScrollBarSize(customScrollbarSize);
+ assertEquals(thumbWidth, view4.getVerticalScrollbarWidth());
+ assertEquals(thumbHeight, view4.getHorizontalScrollbarHeight());
+
+ // Custom thumb and track drawables with intrinsic sizes. Track size take precedence.
+ final MockView view5 = (MockView) mActivity.findViewById(R.id.scroll_view_5);
+ final int trackWidth = res.getDimensionPixelSize(R.dimen.scrollbar_track_width);
+ final int trackHeight = res.getDimensionPixelSize(R.dimen.scrollbar_track_height);
+ assertEquals(trackWidth, view5.getVerticalScrollbarWidth());
+ assertEquals(trackHeight, view5.getHorizontalScrollbarHeight());
+ // Explicit scrollbarSize has no effect.
+ view5.setScrollBarSize(customScrollbarSize);
+ assertEquals(trackWidth, view5.getVerticalScrollbarWidth());
+ assertEquals(trackHeight, view5.getHorizontalScrollbarHeight());
+
+ // Custom thumb and track, track with no intrinsic size, ViewConfiguration applies
+ // regardless of the thumb drawable dimensions.
+ final MockView view6 = (MockView) mActivity.findViewById(R.id.scroll_view_6);
+ assertEquals(configScrollbarSize, view6.getVerticalScrollbarWidth());
+ assertEquals(configScrollbarSize, view6.getHorizontalScrollbarHeight());
+ // Explicit scrollbarSize takes precedence.
+ view6.setScrollBarSize(customScrollbarSize);
+ assertEquals(customScrollbarSize, view6.getVerticalScrollbarWidth());
+ assertEquals(customScrollbarSize, view6.getHorizontalScrollbarHeight());
+ }
+
+ @Test
public void testOnStartAndFinishTemporaryDetach() throws Throwable {
final AtomicBoolean exitedDispatchStartTemporaryDetach = new AtomicBoolean(false);
final AtomicBoolean exitedDispatchFinishTemporaryDetach = new AtomicBoolean(false);