diff options
author | 2023-11-11 04:50:55 +0000 | |
---|---|---|
committer | 2023-11-21 13:24:18 +0000 | |
commit | 425f2b2f09f0ec41110157878db83ea0f987fa52 (patch) | |
tree | b7ef7014a4dce54bd1f5a7bfa4c5c99aeb1a9aa0 | |
parent | 65db10304f062741ded71ebbe9402bf6fce946d5 (diff) |
Convert keyboard ISO test to bivalent test.
Bug: 311436322
Test: atest -c InputRoboRNGTests
Change-Id: I4b0d838ff5dc9c24ed781de7499cf1e550357575
-rw-r--r-- | tests/InputScreenshotTest/Android.bp | 16 | ||||
-rw-r--r-- | tests/InputScreenshotTest/robotests/Android.bp | 71 | ||||
-rw-r--r-- | tests/InputScreenshotTest/robotests/AndroidManifest.xml | 21 | ||||
-rw-r--r-- | tests/InputScreenshotTest/robotests/assets/phone/light_landscape_layout-preview.png | bin | 0 -> 70150 bytes | |||
-rw-r--r-- | tests/InputScreenshotTest/robotests/assets/phone/light_portrait_layout-preview.png | bin | 0 -> 66888 bytes | |||
-rw-r--r-- | tests/InputScreenshotTest/robotests/assets/tablet/dark_portrait_layout-preview.png | bin | 0 -> 39003 bytes | |||
-rw-r--r-- | tests/InputScreenshotTest/robotests/config/robolectric.properties | 15 | ||||
-rw-r--r-- | tests/InputScreenshotTest/robotests/robo-manifest.xml | 15 | ||||
-rw-r--r-- | tests/InputScreenshotTest/src/android/input/screenshot/InputScreenshotTestRule.kt | 13 | ||||
-rw-r--r-- | tests/InputScreenshotTest/src/android/input/screenshot/KeyboardLayoutPreviewIsoScreenshotTest.kt | 9 | ||||
-rw-r--r-- | tests/InputScreenshotTest/src/android/input/screenshot/package-info.java | 4 |
11 files changed, 155 insertions, 9 deletions
diff --git a/tests/InputScreenshotTest/Android.bp b/tests/InputScreenshotTest/Android.bp index 15aaa463cce7..83ced2c2258f 100644 --- a/tests/InputScreenshotTest/Android.bp +++ b/tests/InputScreenshotTest/Android.bp @@ -7,12 +7,27 @@ package { default_applicable_licenses: ["frameworks_base_license"], } +filegroup { + name: "InputScreenshotTestRNGFiles", + srcs: [ + "src/**/*.java", + "src/**/*.kt", + ], + exclude_srcs: [ + "src/android/input/screenshot/KeyboardLayoutPreviewAnsiScreenshotTest.kt", + "src/android/input/screenshot/KeyboardLayoutPreviewJisScreenshotTest.kt", + ], +} + android_test { name: "InputScreenshotTests", srcs: [ "src/**/*.java", "src/**/*.kt", ], + exclude_srcs: [ + "src/android/input/screenshot/package-info.java", + ], platform_apis: true, certificate: "platform", static_libs: [ @@ -43,6 +58,7 @@ android_test { "hamcrest-library", "kotlin-test", "flag-junit", + "platform-parametric-runner-lib", "platform-test-annotations", "services.core.unboosted", "testables", diff --git a/tests/InputScreenshotTest/robotests/Android.bp b/tests/InputScreenshotTest/robotests/Android.bp new file mode 100644 index 000000000000..912f4b8069b4 --- /dev/null +++ b/tests/InputScreenshotTest/robotests/Android.bp @@ -0,0 +1,71 @@ +package { + default_applicable_licenses: ["Android-Apache-2.0"], +} + +android_library { + name: "InputRoboRNGTestsAssetsLib", + asset_dirs: ["assets"], + sdk_version: "current", + platform_apis: true, + manifest: "AndroidManifest.xml", + optimize: { + enabled: false, + }, + use_resource_processor: true, +} + +android_app { + name: "InputRoboApp", + srcs: [], + static_libs: [ + "androidx.test.espresso.core", + "androidx.appcompat_appcompat", + "flag-junit", + "guava", + "InputRoboRNGTestsAssetsLib", + "platform-screenshot-diff-core", + "PlatformComposeSceneTransitionLayoutTestsUtils", + ], + manifest: "robo-manifest.xml", + aaptflags: [ + "--extra-packages", + "com.android.input.screenshot", + ], + dont_merge_manifests: true, + platform_apis: true, + system_ext_specific: true, + certificate: "platform", + privileged: true, + resource_dirs: [], + kotlincflags: ["-Xjvm-default=all"], + + plugins: ["dagger2-compiler"], + use_resource_processor: true, +} + +android_robolectric_test { + name: "InputRoboRNGTests", + srcs: [ + ":InputScreenshotTestRNGFiles", + ":flag-junit", + ":platform-test-screenshot-rules", + ], + // Do not add any new libraries here, they should be added to SystemUIGoogleRobo above. + static_libs: [ + "androidx.compose.runtime_runtime", + "androidx.test.uiautomator_uiautomator", + "androidx.test.ext.junit", + "inline-mockito-robolectric-prebuilt", + "platform-parametric-runner-lib", + "uiautomator-helpers", + ], + libs: [ + "android.test.runner", + "android.test.base", + "android.test.mock", + "truth", + ], + upstream: true, + java_resource_dirs: ["config"], + instrumentation_for: "InputRoboApp", +} diff --git a/tests/InputScreenshotTest/robotests/AndroidManifest.xml b/tests/InputScreenshotTest/robotests/AndroidManifest.xml new file mode 100644 index 000000000000..56893113288d --- /dev/null +++ b/tests/InputScreenshotTest/robotests/AndroidManifest.xml @@ -0,0 +1,21 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- Copyright 2023 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. +--> + +<manifest xmlns:android="http://schemas.android.com/apk/res/android" + package="com.android.input.screenshot"> + <uses-sdk android:minSdkVersion="21"/> + <uses-permission android:name="android.permission.WRITE_SECURE_SETTINGS" /> +</manifest> diff --git a/tests/InputScreenshotTest/robotests/assets/phone/light_landscape_layout-preview.png b/tests/InputScreenshotTest/robotests/assets/phone/light_landscape_layout-preview.png Binary files differnew file mode 100644 index 000000000000..baf204a6cfb3 --- /dev/null +++ b/tests/InputScreenshotTest/robotests/assets/phone/light_landscape_layout-preview.png diff --git a/tests/InputScreenshotTest/robotests/assets/phone/light_portrait_layout-preview.png b/tests/InputScreenshotTest/robotests/assets/phone/light_portrait_layout-preview.png Binary files differnew file mode 100644 index 000000000000..deb3ceeca7fb --- /dev/null +++ b/tests/InputScreenshotTest/robotests/assets/phone/light_portrait_layout-preview.png diff --git a/tests/InputScreenshotTest/robotests/assets/tablet/dark_portrait_layout-preview.png b/tests/InputScreenshotTest/robotests/assets/tablet/dark_portrait_layout-preview.png Binary files differnew file mode 100644 index 000000000000..34e25f73d953 --- /dev/null +++ b/tests/InputScreenshotTest/robotests/assets/tablet/dark_portrait_layout-preview.png diff --git a/tests/InputScreenshotTest/robotests/config/robolectric.properties b/tests/InputScreenshotTest/robotests/config/robolectric.properties new file mode 100644 index 000000000000..83d7549551ce --- /dev/null +++ b/tests/InputScreenshotTest/robotests/config/robolectric.properties @@ -0,0 +1,15 @@ +# Copyright (C) 2022 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. +# +sdk=NEWEST_SDK
\ No newline at end of file diff --git a/tests/InputScreenshotTest/robotests/robo-manifest.xml b/tests/InputScreenshotTest/robotests/robo-manifest.xml new file mode 100644 index 000000000000..e86f58ef0e55 --- /dev/null +++ b/tests/InputScreenshotTest/robotests/robo-manifest.xml @@ -0,0 +1,15 @@ +<?xml version="1.0" encoding="utf-8"?> + +<!--- Include all the namespaces we will ever need anywhere, because this is the source the manifest merger uses for namespaces --> +<manifest xmlns:android="http://schemas.android.com/apk/res/android" + xmlns:androidprv="http://schemas.android.com/apk/prv/res/android" + xmlns:tools="http://schemas.android.com/tools" + package="com.android.input.screenshot" + coreApp="true"> + <application> + <activity + android:name="androidx.activity.ComponentActivity" + android:exported="true"> + </activity> + </application> +</manifest> diff --git a/tests/InputScreenshotTest/src/android/input/screenshot/InputScreenshotTestRule.kt b/tests/InputScreenshotTest/src/android/input/screenshot/InputScreenshotTestRule.kt index c2c3d5530a00..75dab41d3609 100644 --- a/tests/InputScreenshotTest/src/android/input/screenshot/InputScreenshotTestRule.kt +++ b/tests/InputScreenshotTest/src/android/input/screenshot/InputScreenshotTestRule.kt @@ -18,6 +18,7 @@ package com.android.input.screenshot import android.content.Context import android.graphics.Bitmap +import android.os.Build import androidx.activity.ComponentActivity import androidx.compose.foundation.Image import androidx.compose.ui.platform.ViewRootForTest @@ -49,15 +50,17 @@ class InputScreenshotTestRule( ) ) private val composeRule = createAndroidComposeRule<ComponentActivity>() - private val delegateRule = - RuleChain.outerRule(colorsRule) - .around(deviceEmulationRule) + private val roboRule = + RuleChain.outerRule(deviceEmulationRule) .around(screenshotRule) .around(composeRule) + private val delegateRule = RuleChain.outerRule(colorsRule).around(roboRule) private val matcher = UnitTestBitmapMatcher + private val isRobolectric = if (Build.FINGERPRINT.contains("robolectric")) true else false override fun apply(base: Statement, description: Description): Statement { - return delegateRule.apply(base, description) + val ruleToApply = if (isRobolectric) roboRule else delegateRule + return ruleToApply.apply(base, description) } /** @@ -84,4 +87,4 @@ class InputScreenshotTestRule( val view = (composeRule.onRoot().fetchSemanticsNode().root as ViewRootForTest).view screenshotRule.assertBitmapAgainstGolden(view.drawIntoBitmap(), goldenIdentifier, matcher) } -}
\ No newline at end of file +} diff --git a/tests/InputScreenshotTest/src/android/input/screenshot/KeyboardLayoutPreviewIsoScreenshotTest.kt b/tests/InputScreenshotTest/src/android/input/screenshot/KeyboardLayoutPreviewIsoScreenshotTest.kt index 8ae6dfd8b63b..ab7bb4eda899 100644 --- a/tests/InputScreenshotTest/src/android/input/screenshot/KeyboardLayoutPreviewIsoScreenshotTest.kt +++ b/tests/InputScreenshotTest/src/android/input/screenshot/KeyboardLayoutPreviewIsoScreenshotTest.kt @@ -26,14 +26,15 @@ import org.junit.Rule import org.junit.Test import org.junit.rules.RuleChain import org.junit.runner.RunWith -import org.junit.runners.Parameterized +import platform.test.runner.parameterized.ParameterizedAndroidJunit4 +import platform.test.runner.parameterized.Parameters import platform.test.screenshot.DeviceEmulationSpec /** A screenshot test for Keyboard layout preview for Iso physical layout. */ -@RunWith(Parameterized::class) +@RunWith(ParameterizedAndroidJunit4::class) class KeyboardLayoutPreviewIsoScreenshotTest(emulationSpec: DeviceEmulationSpec) { companion object { - @Parameterized.Parameters(name = "{0}") + @Parameters(name = "{0}") @JvmStatic fun getTestSpecs() = DeviceEmulationSpec.PhoneAndTabletMinimal } @@ -55,4 +56,4 @@ class KeyboardLayoutPreviewIsoScreenshotTest(emulationSpec: DeviceEmulationSpec) } } -}
\ No newline at end of file +} diff --git a/tests/InputScreenshotTest/src/android/input/screenshot/package-info.java b/tests/InputScreenshotTest/src/android/input/screenshot/package-info.java new file mode 100644 index 000000000000..4b5a56d3bd1d --- /dev/null +++ b/tests/InputScreenshotTest/src/android/input/screenshot/package-info.java @@ -0,0 +1,4 @@ +@GraphicsMode(GraphicsMode.Mode.NATIVE) +package com.android.input.screenshot; + +import org.robolectric.annotation.GraphicsMode; |