summaryrefslogtreecommitdiff
path: root/packages/CredentialManager/tests
diff options
context:
space:
mode:
author Helen Qin <helenqin@google.com> 2024-01-16 23:55:23 +0000
committer Helen Qin <helenqin@google.com> 2024-02-13 13:20:00 +0000
commit68e23a070ab380067f8c576d83bb083fd4f436c3 (patch)
tree73fc9b7cf4474bbab5649af03be996e66f85be19 /packages/CredentialManager/tests
parent6ebd8d8945a12bbafc4c1f2dd993943f4c31fc29 (diff)
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
Diffstat (limited to 'packages/CredentialManager/tests')
-rw-r--r--packages/CredentialManager/tests/robotests/Android.bp58
-rw-r--r--packages/CredentialManager/tests/robotests/config/robolectric.properties16
-rw-r--r--packages/CredentialManager/tests/robotests/customization/assets/phone/dark_landscape_singleCredentialScreen.pngbin0 -> 79116 bytes
-rw-r--r--packages/CredentialManager/tests/robotests/customization/assets/phone/dark_portrait_singleCredentialScreen.pngbin0 -> 81786 bytes
-rw-r--r--packages/CredentialManager/tests/robotests/customization/assets/phone/light_landscape_singleCredentialScreen.pngbin0 -> 78283 bytes
-rw-r--r--packages/CredentialManager/tests/robotests/customization/assets/phone/light_portrait_singleCredentialScreen.pngbin0 -> 80777 bytes
-rw-r--r--packages/CredentialManager/tests/robotests/customization/assets/tablet/dark_landscape_singleCredentialScreen.pngbin0 -> 53502 bytes
-rw-r--r--packages/CredentialManager/tests/robotests/customization/assets/tablet/dark_portrait_singleCredentialScreen.pngbin0 -> 55450 bytes
-rw-r--r--packages/CredentialManager/tests/robotests/customization/assets/tablet/light_landscape_singleCredentialScreen.pngbin0 -> 53271 bytes
-rw-r--r--packages/CredentialManager/tests/robotests/customization/assets/tablet/light_portrait_singleCredentialScreen.pngbin0 -> 55116 bytes
-rw-r--r--packages/CredentialManager/tests/robotests/robo-manifest.xml36
-rw-r--r--packages/CredentialManager/tests/robotests/screenshot/Android.bp15
-rw-r--r--packages/CredentialManager/tests/robotests/screenshot/AndroidManifest.xml36
-rw-r--r--packages/CredentialManager/tests/robotests/screenshot/customization/res/drawable/provider1.xml26
-rw-r--r--packages/CredentialManager/tests/robotests/screenshot/customization/res/drawable/provider2.xml26
-rw-r--r--packages/CredentialManager/tests/robotests/screenshot/src/com/android/credentialmanager/CredentialManagerGoldenImagePathManager.kt51
-rw-r--r--packages/CredentialManager/tests/robotests/screenshot/src/com/android/credentialmanager/GetCredScreenshotTest.kt119
17 files changed, 383 insertions, 0 deletions
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
--- /dev/null
+++ b/packages/CredentialManager/tests/robotests/customization/assets/phone/dark_landscape_singleCredentialScreen.png
Binary files 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
--- /dev/null
+++ b/packages/CredentialManager/tests/robotests/customization/assets/phone/dark_portrait_singleCredentialScreen.png
Binary files 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
--- /dev/null
+++ b/packages/CredentialManager/tests/robotests/customization/assets/phone/light_landscape_singleCredentialScreen.png
Binary files 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
--- /dev/null
+++ b/packages/CredentialManager/tests/robotests/customization/assets/phone/light_portrait_singleCredentialScreen.png
Binary files 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
--- /dev/null
+++ b/packages/CredentialManager/tests/robotests/customization/assets/tablet/dark_landscape_singleCredentialScreen.png
Binary files 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
--- /dev/null
+++ b/packages/CredentialManager/tests/robotests/customization/assets/tablet/dark_portrait_singleCredentialScreen.png
Binary files 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
--- /dev/null
+++ b/packages/CredentialManager/tests/robotests/customization/assets/tablet/light_landscape_singleCredentialScreen.png
Binary files 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
--- /dev/null
+++ b/packages/CredentialManager/tests/robotests/customization/assets/tablet/light_portrait_singleCredentialScreen.png
Binary files 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 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+ ~ 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.
+ -->
+
+<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.credentialmanager.tests.screenshot">
+ <uses-permission android:name="android.permission.LAUNCH_CREDENTIAL_SELECTOR"/>
+ <uses-permission android:name="android.permission.QUERY_ALL_PACKAGES"/>
+ <uses-permission android:name="android.permission.HIDE_NON_SYSTEM_OVERLAY_WINDOWS"/>
+ <uses-permission android:name="android.permission.ACCESS_INSTANT_APPS" />
+
+ <application>
+ <activity
+ android:name="platform.test.screenshot.ScreenshotActivity"
+ android:exported="true"
+ android:configChanges="orientation|screenSize|screenLayout|smallestScreenSize"
+ android:theme="@style/Theme.PlatformUi.Screenshot">
+ </activity>
+ </application>
+
+</manifest>
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 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+ ~ 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.
+ -->
+
+<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.credentialmanager.tests.screenshot">
+ <uses-permission android:name="android.permission.LAUNCH_CREDENTIAL_SELECTOR"/>
+ <uses-permission android:name="android.permission.QUERY_ALL_PACKAGES"/>
+ <uses-permission android:name="android.permission.HIDE_NON_SYSTEM_OVERLAY_WINDOWS"/>
+ <uses-permission android:name="android.permission.ACCESS_INSTANT_APPS" />
+
+ <application>
+ <activity
+ android:name="platform.test.screenshot.ScreenshotActivity"
+ android:exported="true"
+ android:configChanges="orientation|screenSize|screenLayout|smallestScreenSize"
+ android:theme="@style/Theme.PlatformUi.Screenshot">
+ </activity>
+ </application>
+
+</manifest>
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 @@
+<!--
+ ~ 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.
+ -->
+
+<vector xmlns:android="http://schemas.android.com/apk/res/android"
+ android:width="50dp"
+ android:height="50dp"
+ android:viewportWidth="50"
+ android:viewportHeight="50">
+ <path
+ android:pathData="M32.411,8.729L41,11.95V20H9V11.95L17.592,8.728L15.486,5.115C15.423,4.924 15.417,4.734 15.47,4.544C15.524,4.353 15.635,4.205 15.805,4.099C15.995,3.993 16.202,3.972 16.425,4.036C16.648,4.099 16.812,4.226 16.918,4.417L19.105,8.161L25,5.95L30.897,8.161L33.114,4.417C33.22,4.226 33.384,4.099 33.607,4.036C33.829,3.972 34.036,3.993 34.227,4.099C34.397,4.205 34.519,4.358 34.593,4.559C34.667,4.76 34.652,4.946 34.546,5.115L32.411,8.729ZM9,22V23.85C9,28.917 10.5,33.575 13.5,37.825C16.5,42.075 20.333,44.783 25,45.95C29.667,44.783 33.5,42.075 36.5,37.825C39.5,33.575 41,28.917 41,23.85V22H9ZM19.705,15.698C19.386,16.015 19.015,16.174 18.591,16.174C18.167,16.174 17.795,16.015 17.477,15.698C17.159,15.38 17,15.01 17,14.587C17,14.164 17.159,13.793 17.477,13.476C17.795,13.159 18.167,13 18.591,13C19.015,13 19.386,13.159 19.705,13.476C20.023,13.793 20.182,14.164 20.182,14.587C20.182,15.01 20.023,15.38 19.705,15.698ZM32.432,15.698C32.114,16.015 31.742,16.174 31.318,16.174C30.894,16.174 30.523,16.015 30.205,15.698C29.886,15.38 29.727,15.01 29.727,14.587C29.727,14.164 29.886,13.793 30.205,13.476C30.523,13.159 30.894,13 31.318,13C31.742,13 32.114,13.159 32.432,13.476C32.75,13.793 32.909,14.164 32.909,14.587C32.909,15.01 32.75,15.38 32.432,15.698Z"
+ android:fillColor="#8BC34A"
+ android:fillType="evenOdd"/>
+</vector>
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 @@
+<!--
+ ~ 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.
+ -->
+
+<vector xmlns:android="http://schemas.android.com/apk/res/android"
+ android:width="50dp"
+ android:height="50dp"
+ android:viewportWidth="50"
+ android:viewportHeight="50">
+ <path
+ android:pathData="M32.411,8.729L41,11.95V20H9V11.95L17.592,8.728L15.486,5.115C15.423,4.924 15.417,4.734 15.47,4.544C15.524,4.353 15.635,4.205 15.805,4.099C15.995,3.993 16.202,3.972 16.425,4.036C16.648,4.099 16.812,4.226 16.918,4.417L19.105,8.161L25,5.95L30.897,8.161L33.114,4.417C33.22,4.226 33.384,4.099 33.607,4.036C33.829,3.972 34.036,3.993 34.227,4.099C34.397,4.205 34.519,4.358 34.593,4.559C34.667,4.76 34.652,4.946 34.546,5.115L32.411,8.729ZM9,22V23.85C9,28.917 10.5,33.575 13.5,37.825C16.5,42.075 20.333,44.783 25,45.95C29.667,44.783 33.5,42.075 36.5,37.825C39.5,33.575 41,28.917 41,23.85V22H9ZM19.705,15.698C19.386,16.015 19.015,16.174 18.591,16.174C18.167,16.174 17.795,16.015 17.477,15.698C17.159,15.38 17,15.01 17,14.587C17,14.164 17.159,13.793 17.477,13.476C17.795,13.159 18.167,13 18.591,13C19.015,13 19.386,13.159 19.705,13.476C20.023,13.793 20.182,14.164 20.182,14.587C20.182,15.01 20.023,15.38 19.705,15.698ZM32.432,15.698C32.114,16.015 31.742,16.174 31.318,16.174C30.894,16.174 30.523,16.015 30.205,15.698C29.886,15.38 29.727,15.01 29.727,14.587C29.727,14.164 29.886,13.793 30.205,13.476C30.523,13.159 30.894,13 31.318,13C31.742,13 32.114,13.159 32.432,13.476C32.75,13.793 32.909,14.164 32.909,14.587C32.909,15.01 32.75,15.38 32.432,15.698Z"
+ android:fillColor="#8B034A"
+ android:fillType="evenOdd"/>
+</vector>
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<ProviderInfo> {
+ val context = ApplicationProvider.getApplicationContext<Context>()
+ 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