Skip to content
Snippets Groups Projects
Commit e5627bb0 authored by Treehugger Robot's avatar Treehugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Add framework test for vector-specific fill color A11Y settings." into main

parents 23a95523 ba6858d9
No related branches found
No related tags found
No related merge requests found
......@@ -18,18 +18,21 @@ android_test {
"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",
"cts-wm-util",
......@@ -39,6 +42,7 @@ android_test {
"kotlin-test",
"mockito-target-minus-junit4",
"platform-test-annotations",
"platform-screenshot-diff-core",
"services.core.unboosted",
"servicestests-utils",
"testables",
......
......@@ -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">
......
......@@ -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>
tests/Input/assets/testPointerFillStyle.png

569 B

/*
* 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
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment