Add framework test for vector-specific fill color A11Y settings.
Bug: 305193969
Test: PointerIconTest
Flag: com.android.systemui.enable_vector_cursor_a11y_settings
Change-Id: Ia34f925a4452ad8c410d57b29d431d8afa6b8aa8
diff --git a/tests/Input/Android.bp b/tests/Input/Android.bp
index c0cbdc3..47d85a3 100644
--- a/tests/Input/Android.bp
+++ b/tests/Input/Android.bp
@@ -18,18 +18,21 @@
"src/**/*.java",
"src/**/*.kt",
],
+ asset_dirs: ["assets"],
kotlincflags: [
"-Werror",
],
platform_apis: true,
certificate: "platform",
static_libs: [
+ "android.view.flags-aconfig-java",
"androidx.test.core",
"androidx.test.ext.junit",
"androidx.test.ext.truth",
"androidx.test.rules",
"androidx.test.runner",
"androidx.test.uiautomator_uiautomator",
+ "collector-device-lib",
"compatibility-device-util-axt",
"cts-input-lib",
"flag-junit",
@@ -38,6 +41,7 @@
"kotlin-test",
"mockito-target-minus-junit4",
"platform-test-annotations",
+ "platform-screenshot-diff-core",
"services.core.unboosted",
"servicestests-utils",
"testables",
diff --git a/tests/Input/AndroidManifest.xml b/tests/Input/AndroidManifest.xml
index 3b723dd..a05d08c 100644
--- a/tests/Input/AndroidManifest.xml
+++ b/tests/Input/AndroidManifest.xml
@@ -22,6 +22,8 @@
<uses-permission android:name="android.permission.MONITOR_INPUT"/>
<uses-permission android:name="android.permission.READ_DEVICE_CONFIG"/>
<uses-permission android:name="android.permission.WRITE_SECURE_SETTINGS"/>
+ <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
+ <uses-permission android:name="android.permission.MANAGE_EXTERNAL_STORAGE"/>
<application android:label="InputTest" android:debuggable="true">
diff --git a/tests/Input/AndroidTest.xml b/tests/Input/AndroidTest.xml
index f602c512..8db3705 100644
--- a/tests/Input/AndroidTest.xml
+++ b/tests/Input/AndroidTest.xml
@@ -28,4 +28,10 @@
<!-- Take screenshot upon test failure -->
<option name="screenshot-on-failure" value="true" />
</object>
+ <metrics_collector class="com.android.tradefed.device.metric.FilePullerLogCollector">
+ <option name="pull-pattern-keys" value="input_.*" />
+ <!-- Pull files created by tests, like the output of screenshot tests -->
+ <option name="directory-keys" value="/storage/emulated/0/InputTests" />
+ <option name="collect-on-run-ended-only" value="false" />
+ </metrics_collector>
</configuration>
diff --git a/tests/Input/assets/testPointerFillStyle.png b/tests/Input/assets/testPointerFillStyle.png
new file mode 100644
index 0000000..b2354f8
--- /dev/null
+++ b/tests/Input/assets/testPointerFillStyle.png
Binary files differ
diff --git a/tests/Input/src/com/android/test/input/PointerIconLoadingTest.kt b/tests/Input/src/com/android/test/input/PointerIconLoadingTest.kt
new file mode 100644
index 0000000..dac4253
--- /dev/null
+++ b/tests/Input/src/com/android/test/input/PointerIconLoadingTest.kt
@@ -0,0 +1,114 @@
+/*
+ * Copyright 2024 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.
+ */
+
+package com.android.test.input
+
+import android.content.Context
+import android.content.res.Configuration
+import android.content.res.Resources
+import android.os.Environment
+import android.view.ContextThemeWrapper
+import android.view.PointerIcon
+import android.view.flags.Flags.enableVectorCursorA11ySettings
+import android.view.flags.Flags.enableVectorCursors
+import androidx.test.ext.junit.runners.AndroidJUnit4
+import androidx.test.filters.SmallTest
+import androidx.test.platform.app.InstrumentationRegistry
+import org.junit.Assume.assumeTrue
+import org.junit.Before
+import org.junit.Rule
+import org.junit.Test
+import org.junit.rules.TestName
+import org.junit.runner.RunWith
+import platform.test.screenshot.GoldenPathManager
+import platform.test.screenshot.PathConfig
+import platform.test.screenshot.ScreenshotTestRule
+import platform.test.screenshot.assertAgainstGolden
+import platform.test.screenshot.matchers.BitmapMatcher
+import platform.test.screenshot.matchers.PixelPerfectMatcher
+
+/**
+ * Unit tests for PointerIcon.
+ *
+ * Run with:
+ * atest InputTests:com.android.test.input.PointerIconLoadingTest
+ */
+@SmallTest
+@RunWith(AndroidJUnit4::class)
+class PointerIconLoadingTest {
+ private lateinit var context: Context
+ private lateinit var exactScreenshotMatcher: BitmapMatcher
+
+ @get:Rule
+ val testName = TestName()
+
+ @get:Rule
+ val screenshotRule = ScreenshotTestRule(GoldenPathManager(
+ InstrumentationRegistry.getInstrumentation().getContext(),
+ ASSETS_PATH,
+ TEST_OUTPUT_PATH,
+ PathConfig()
+ ), disableIconPool = false)
+
+ @Before
+ fun setUp() {
+ context = InstrumentationRegistry.getInstrumentation().targetContext
+ val config =
+ Configuration(context.resources.configuration).apply {
+ densityDpi = DENSITY_DPI
+ screenWidthDp = SCREEN_WIDTH_DP
+ screenHeightDp = SCREEN_HEIGHT_DP
+ smallestScreenWidthDp = SCREEN_WIDTH_DP
+ }
+ context = context.createConfigurationContext(config)
+
+ exactScreenshotMatcher = PixelPerfectMatcher()
+ }
+
+ @Test
+ fun testPointerFillStyle() {
+ assumeTrue(enableVectorCursors())
+ assumeTrue(enableVectorCursorA11ySettings())
+
+ val theme: Resources.Theme = context.getResources().newTheme()
+ theme.setTo(context.getTheme())
+ theme.applyStyle(
+ PointerIcon.vectorFillStyleToResource(PointerIcon.POINTER_ICON_VECTOR_STYLE_FILL_GREEN),
+ /* force= */ true)
+
+ val pointerIcon =
+ PointerIcon.getLoadedSystemIcon(
+ ContextThemeWrapper(context, theme),
+ PointerIcon.TYPE_ARROW,
+ /* useLargeIcons= */ false)
+
+ pointerIcon.getBitmap().assertAgainstGolden(
+ screenshotRule,
+ testName.methodName,
+ exactScreenshotMatcher
+ )
+ }
+
+ companion object {
+ const val DENSITY_DPI = 160
+ const val SCREEN_WIDTH_DP = 480
+ const val SCREEN_HEIGHT_DP = 800
+ const val ASSETS_PATH = "tests/input/assets"
+ val TEST_OUTPUT_PATH = Environment.getExternalStorageDirectory().absolutePath +
+ "/InputTests/" +
+ PointerIconLoadingTest::class.java.simpleName
+ }
+}