From 68e23a070ab380067f8c576d83bb083fd4f436c3 Mon Sep 17 00:00:00 2001 From: Helen Qin Date: Tue, 16 Jan 2024 23:55:23 +0000 Subject: CredentialManager screenshot test setup To start, set up the screenshot test with a single get-credential flow entry screen. Bug: 319448897 Test: atest CredentialManagerScreenshotTest Change-Id: I5cbe6ca07747f2052a9395f80eaaddb6baf118be --- .../CredentialManager/tests/robotests/Android.bp | 58 ++++++++++ .../tests/robotests/config/robolectric.properties | 16 +++ .../dark_landscape_singleCredentialScreen.png | Bin 0 -> 79116 bytes .../phone/dark_portrait_singleCredentialScreen.png | Bin 0 -> 81786 bytes .../light_landscape_singleCredentialScreen.png | Bin 0 -> 78283 bytes .../light_portrait_singleCredentialScreen.png | Bin 0 -> 80777 bytes .../dark_landscape_singleCredentialScreen.png | Bin 0 -> 53502 bytes .../dark_portrait_singleCredentialScreen.png | Bin 0 -> 55450 bytes .../light_landscape_singleCredentialScreen.png | Bin 0 -> 53271 bytes .../light_portrait_singleCredentialScreen.png | Bin 0 -> 55116 bytes .../tests/robotests/robo-manifest.xml | 36 +++++++ .../tests/robotests/screenshot/Android.bp | 15 +++ .../tests/robotests/screenshot/AndroidManifest.xml | 36 +++++++ .../customization/res/drawable/provider1.xml | 26 +++++ .../customization/res/drawable/provider2.xml | 26 +++++ .../CredentialManagerGoldenImagePathManager.kt | 51 +++++++++ .../credentialmanager/GetCredScreenshotTest.kt | 119 +++++++++++++++++++++ 17 files changed, 383 insertions(+) create mode 100644 packages/CredentialManager/tests/robotests/Android.bp create mode 100644 packages/CredentialManager/tests/robotests/config/robolectric.properties create mode 100644 packages/CredentialManager/tests/robotests/customization/assets/phone/dark_landscape_singleCredentialScreen.png create mode 100644 packages/CredentialManager/tests/robotests/customization/assets/phone/dark_portrait_singleCredentialScreen.png create mode 100644 packages/CredentialManager/tests/robotests/customization/assets/phone/light_landscape_singleCredentialScreen.png create mode 100644 packages/CredentialManager/tests/robotests/customization/assets/phone/light_portrait_singleCredentialScreen.png create mode 100644 packages/CredentialManager/tests/robotests/customization/assets/tablet/dark_landscape_singleCredentialScreen.png create mode 100644 packages/CredentialManager/tests/robotests/customization/assets/tablet/dark_portrait_singleCredentialScreen.png create mode 100644 packages/CredentialManager/tests/robotests/customization/assets/tablet/light_landscape_singleCredentialScreen.png create mode 100644 packages/CredentialManager/tests/robotests/customization/assets/tablet/light_portrait_singleCredentialScreen.png create mode 100644 packages/CredentialManager/tests/robotests/robo-manifest.xml create mode 100644 packages/CredentialManager/tests/robotests/screenshot/Android.bp create mode 100644 packages/CredentialManager/tests/robotests/screenshot/AndroidManifest.xml create mode 100644 packages/CredentialManager/tests/robotests/screenshot/customization/res/drawable/provider1.xml create mode 100644 packages/CredentialManager/tests/robotests/screenshot/customization/res/drawable/provider2.xml create mode 100644 packages/CredentialManager/tests/robotests/screenshot/src/com/android/credentialmanager/CredentialManagerGoldenImagePathManager.kt create mode 100644 packages/CredentialManager/tests/robotests/screenshot/src/com/android/credentialmanager/GetCredScreenshotTest.kt (limited to 'packages/CredentialManager/tests') diff --git a/packages/CredentialManager/tests/robotests/Android.bp b/packages/CredentialManager/tests/robotests/Android.bp new file mode 100644 index 000000000000..baebfeb399f2 --- /dev/null +++ b/packages/CredentialManager/tests/robotests/Android.bp @@ -0,0 +1,58 @@ +package { + // See: http://go/android-license-faq + // A large-scale-change added 'default_applicable_licenses' to import + // all of the 'license_kinds' from "frameworks_base_license" + // to get the below license kinds: + // SPDX-license-identifier-Apache-2.0 + default_applicable_licenses: ["frameworks_base_license"], +} + +android_app { + name: "CredentialManagerRobo", + srcs: [], + static_libs: [ + "SystemUI-core", + "CredentialManager-handheld", + "ScreenshotComposeUtilsLib", + "androidx.test.espresso.core", + "androidx.compose.material3_material3", + "platform-screenshot-diff-core", + ], + manifest: "robo-manifest.xml", + dont_merge_manifests: true, + platform_apis: true, + system_ext_specific: true, + certificate: "platform", + privileged: true, + kotlincflags: ["-Xjvm-default=all"], + asset_dirs: ["customization/assets"], + resource_dirs: ["screenshot/customization/res"], + use_resource_processor: true, +} + +// This is a RNG (Robolectric native graphics) test target. +android_robolectric_test { + name: "CredentialManagerScreenshotTest", + srcs: [ + ":CredentialManagerScreenshotTestFiles", + ], + + // Do not add any libraries here, instead add them to the ScreenshotTestStub + 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: "CredentialManagerRobo", +} diff --git a/packages/CredentialManager/tests/robotests/config/robolectric.properties b/packages/CredentialManager/tests/robotests/config/robolectric.properties new file mode 100644 index 000000000000..83065ac1a93f --- /dev/null +++ b/packages/CredentialManager/tests/robotests/config/robolectric.properties @@ -0,0 +1,16 @@ +# Copyright (C) 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. +# +sdk=NEWEST_SDK +graphicsMode=NATIVE diff --git a/packages/CredentialManager/tests/robotests/customization/assets/phone/dark_landscape_singleCredentialScreen.png b/packages/CredentialManager/tests/robotests/customization/assets/phone/dark_landscape_singleCredentialScreen.png new file mode 100644 index 000000000000..975ce9f07595 Binary files /dev/null and b/packages/CredentialManager/tests/robotests/customization/assets/phone/dark_landscape_singleCredentialScreen.png differ diff --git a/packages/CredentialManager/tests/robotests/customization/assets/phone/dark_portrait_singleCredentialScreen.png b/packages/CredentialManager/tests/robotests/customization/assets/phone/dark_portrait_singleCredentialScreen.png new file mode 100644 index 000000000000..4b8e8a067fa7 Binary files /dev/null and b/packages/CredentialManager/tests/robotests/customization/assets/phone/dark_portrait_singleCredentialScreen.png differ diff --git a/packages/CredentialManager/tests/robotests/customization/assets/phone/light_landscape_singleCredentialScreen.png b/packages/CredentialManager/tests/robotests/customization/assets/phone/light_landscape_singleCredentialScreen.png new file mode 100644 index 000000000000..cd98581d890a Binary files /dev/null and b/packages/CredentialManager/tests/robotests/customization/assets/phone/light_landscape_singleCredentialScreen.png differ diff --git a/packages/CredentialManager/tests/robotests/customization/assets/phone/light_portrait_singleCredentialScreen.png b/packages/CredentialManager/tests/robotests/customization/assets/phone/light_portrait_singleCredentialScreen.png new file mode 100644 index 000000000000..643b5cea005b Binary files /dev/null and b/packages/CredentialManager/tests/robotests/customization/assets/phone/light_portrait_singleCredentialScreen.png differ diff --git a/packages/CredentialManager/tests/robotests/customization/assets/tablet/dark_landscape_singleCredentialScreen.png b/packages/CredentialManager/tests/robotests/customization/assets/tablet/dark_landscape_singleCredentialScreen.png new file mode 100644 index 000000000000..7b05f26abc5c Binary files /dev/null and b/packages/CredentialManager/tests/robotests/customization/assets/tablet/dark_landscape_singleCredentialScreen.png differ diff --git a/packages/CredentialManager/tests/robotests/customization/assets/tablet/dark_portrait_singleCredentialScreen.png b/packages/CredentialManager/tests/robotests/customization/assets/tablet/dark_portrait_singleCredentialScreen.png new file mode 100644 index 000000000000..d575d289f008 Binary files /dev/null and b/packages/CredentialManager/tests/robotests/customization/assets/tablet/dark_portrait_singleCredentialScreen.png differ diff --git a/packages/CredentialManager/tests/robotests/customization/assets/tablet/light_landscape_singleCredentialScreen.png b/packages/CredentialManager/tests/robotests/customization/assets/tablet/light_landscape_singleCredentialScreen.png new file mode 100644 index 000000000000..fb0da8c915b7 Binary files /dev/null and b/packages/CredentialManager/tests/robotests/customization/assets/tablet/light_landscape_singleCredentialScreen.png differ diff --git a/packages/CredentialManager/tests/robotests/customization/assets/tablet/light_portrait_singleCredentialScreen.png b/packages/CredentialManager/tests/robotests/customization/assets/tablet/light_portrait_singleCredentialScreen.png new file mode 100644 index 000000000000..136e52be885f Binary files /dev/null and b/packages/CredentialManager/tests/robotests/customization/assets/tablet/light_portrait_singleCredentialScreen.png differ diff --git a/packages/CredentialManager/tests/robotests/robo-manifest.xml b/packages/CredentialManager/tests/robotests/robo-manifest.xml new file mode 100644 index 000000000000..12c02508d9ec --- /dev/null +++ b/packages/CredentialManager/tests/robotests/robo-manifest.xml @@ -0,0 +1,36 @@ + + + + + + + + + + + + + + + diff --git a/packages/CredentialManager/tests/robotests/screenshot/Android.bp b/packages/CredentialManager/tests/robotests/screenshot/Android.bp new file mode 100644 index 000000000000..666ced4fa687 --- /dev/null +++ b/packages/CredentialManager/tests/robotests/screenshot/Android.bp @@ -0,0 +1,15 @@ +package { + // See: http://go/android-license-faq + // A large-scale-change added 'default_applicable_licenses' to import + // all of the 'license_kinds' from "frameworks_base_license" + // to get the below license kinds: + // SPDX-license-identifier-Apache-2.0 + default_applicable_licenses: ["frameworks_base_license"], +} + +filegroup { + name: "CredentialManagerScreenshotTestFiles", + srcs: [ + "src/**/*.kt", + ], +} diff --git a/packages/CredentialManager/tests/robotests/screenshot/AndroidManifest.xml b/packages/CredentialManager/tests/robotests/screenshot/AndroidManifest.xml new file mode 100644 index 000000000000..12c02508d9ec --- /dev/null +++ b/packages/CredentialManager/tests/robotests/screenshot/AndroidManifest.xml @@ -0,0 +1,36 @@ + + + + + + + + + + + + + + + diff --git a/packages/CredentialManager/tests/robotests/screenshot/customization/res/drawable/provider1.xml b/packages/CredentialManager/tests/robotests/screenshot/customization/res/drawable/provider1.xml new file mode 100644 index 000000000000..a1e1b41cc1a3 --- /dev/null +++ b/packages/CredentialManager/tests/robotests/screenshot/customization/res/drawable/provider1.xml @@ -0,0 +1,26 @@ + + + + + diff --git a/packages/CredentialManager/tests/robotests/screenshot/customization/res/drawable/provider2.xml b/packages/CredentialManager/tests/robotests/screenshot/customization/res/drawable/provider2.xml new file mode 100644 index 000000000000..cdcf83f1096e --- /dev/null +++ b/packages/CredentialManager/tests/robotests/screenshot/customization/res/drawable/provider2.xml @@ -0,0 +1,26 @@ + + + + + diff --git a/packages/CredentialManager/tests/robotests/screenshot/src/com/android/credentialmanager/CredentialManagerGoldenImagePathManager.kt b/packages/CredentialManager/tests/robotests/screenshot/src/com/android/credentialmanager/CredentialManagerGoldenImagePathManager.kt new file mode 100644 index 000000000000..6aef24d846a9 --- /dev/null +++ b/packages/CredentialManager/tests/robotests/screenshot/src/com/android/credentialmanager/CredentialManagerGoldenImagePathManager.kt @@ -0,0 +1,51 @@ +/* + * Copyright (C) 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.credentialmanager + +import android.os.Build +import androidx.test.platform.app.InstrumentationRegistry +import platform.test.screenshot.GoldenImagePathManager +import platform.test.screenshot.PathConfig + +/** The assets path to be used by all CredentialManager screenshot tests. */ +private const val ASSETS_PREFIX = "frameworks/base/packages/CredentialManager" +private const val ASSETS_PATH = "${ASSETS_PREFIX}/tests/robotests/screenshot/customization/assets" +private const val ASSETS_PATH_ROBO = + "${ASSETS_PREFIX}/tests/robotests/customization/assets" + +private val isRobolectric = Build.FINGERPRINT.contains("robolectric") + +class CredentialManagerGoldenImagePathManager( + pathConfig: PathConfig, + assetsPathRelativeToBuildRoot: String = if (isRobolectric) ASSETS_PATH_ROBO else ASSETS_PATH +) : GoldenImagePathManager( + appContext = InstrumentationRegistry.getInstrumentation().context, + assetsPathRelativeToBuildRoot = assetsPathRelativeToBuildRoot, + deviceLocalPath = + InstrumentationRegistry.getInstrumentation() + .targetContext + .filesDir + .absolutePath + .toString() + "/credman_screenshots", + pathConfig = pathConfig, +) { + override fun toString(): String { + // This string is appended to all actual/expected screenshots on the device, so make sure + // it is a static value. + return "CredentialManagerGoldenImagePathManager" + } +} \ No newline at end of file diff --git a/packages/CredentialManager/tests/robotests/screenshot/src/com/android/credentialmanager/GetCredScreenshotTest.kt b/packages/CredentialManager/tests/robotests/screenshot/src/com/android/credentialmanager/GetCredScreenshotTest.kt new file mode 100644 index 000000000000..a0e1fed0ac96 --- /dev/null +++ b/packages/CredentialManager/tests/robotests/screenshot/src/com/android/credentialmanager/GetCredScreenshotTest.kt @@ -0,0 +1,119 @@ +/* + * Copyright (C) 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.credentialmanager + +import android.content.Context +import com.android.credentialmanager.getflow.RequestDisplayInfo +import com.android.credentialmanager.model.CredentialType +import com.android.credentialmanager.model.get.ProviderInfo +import com.android.credentialmanager.model.get.CredentialEntryInfo +import platform.test.screenshot.getEmulatedDevicePathConfig +import platform.test.screenshot.utils.compose.ComposeScreenshotTestRule +import com.android.credentialmanager.getflow.toProviderDisplayInfo +import com.android.credentialmanager.getflow.toActiveEntry +import org.junit.Rule +import org.junit.Test +import org.junit.runner.RunWith +import platform.test.runner.parameterized.ParameterizedAndroidJunit4 +import platform.test.runner.parameterized.Parameters +import platform.test.screenshot.DeviceEmulationSpec +import platform.test.screenshot.PhoneAndTabletFull +import androidx.test.core.app.ApplicationProvider +import com.android.credentialmanager.common.ui.ModalBottomSheet +import com.android.credentialmanager.getflow.PrimarySelectionCard +import com.android.credentialmanager.tests.screenshot.R + +/** A screenshot test for our Get-Credential flows. */ +@RunWith(ParameterizedAndroidJunit4::class) +class GetCredScreenshotTest(emulationSpec: DeviceEmulationSpec) { + companion object { + @Parameters(name = "{0}") + @JvmStatic + fun getTestSpecs() = DeviceEmulationSpec.PhoneAndTabletFull + + val REQUEST_DISPLAY_INFO = RequestDisplayInfo( + appName = "Test App", + preferImmediatelyAvailableCredentials = false, + preferIdentityDocUi = false, + preferTopBrandingContent = null, + ) + } + + @get:Rule + val screenshotRule = ComposeScreenshotTestRule( + emulationSpec, + CredentialManagerGoldenImagePathManager(getEmulatedDevicePathConfig(emulationSpec)) + ) + + @Test + fun singleCredentialScreen() { + val providerInfoList = buildProviderInfoList() + val providerDisplayInfo = toProviderDisplayInfo(providerInfoList) + val activeEntry = toActiveEntry(providerDisplayInfo) + screenshotRule.screenshotTest("singleCredentialScreen") { + ModalBottomSheet( + sheetContent = { + PrimarySelectionCard( + requestDisplayInfo = REQUEST_DISPLAY_INFO, + providerDisplayInfo = providerDisplayInfo, + providerInfoList = providerInfoList, + activeEntry = activeEntry, + onEntrySelected = {}, + onConfirm = {}, + onMoreOptionSelected = {}, + onLog = {}, + ) + }, + isInitialRender = true, + onDismiss = {}, + onInitialRenderComplete = {}, + isAutoSelectFlow = false, + ) + } + } + + private fun buildProviderInfoList(): List { + val context = ApplicationProvider.getApplicationContext() + val provider1 = ProviderInfo( + id = "1", + icon = context.getDrawable(R.drawable.provider1)!!, + displayName = "Password Manager 1", + credentialEntryList = listOf( + CredentialEntryInfo( + providerId = "1", + entryKey = "key1", + entrySubkey = "subkey1", + pendingIntent = null, + fillInIntent = null, + credentialType = CredentialType.PASSWORD, + credentialTypeDisplayName = "Passkey", + providerDisplayName = "Password Manager 1", + userName = "username", + displayName = "Display Name", + icon = null, + shouldTintIcon = true, + lastUsedTimeMillis = null, + isAutoSelectable = false + ) + ), + authenticationEntryList = emptyList(), + remoteEntry = null, + actionEntryList = emptyList(), + ) + return listOf(provider1) + } +} \ No newline at end of file -- cgit v1.2.3-59-g8ed1b