Adding back screenshot test to Settings.
Test: atest SettingsScreenshotTests Fixes: 307356833 Change-Id: I80b32cd40155d56e38d41d5f6d52e4c5d5ef715c
This commit is contained in:
committed by
Joshua McCloskey
parent
9718ae0aa9
commit
114fabf79d
@@ -24,6 +24,7 @@
|
|||||||
|
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
style="@style/SudContentFrame"
|
style="@style/SudContentFrame"
|
||||||
|
android:id="@+id/enroll_intro_content_view"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:clipChildren="false"
|
android:clipChildren="false"
|
||||||
|
@@ -186,6 +186,9 @@ class FingerprintEnrollIntroV2Fragment() : Fragment(R.layout.fingerprint_v2_enro
|
|||||||
return view
|
return view
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* TODO (b/305269201): This link isn't displaying for screenshot tests.
|
||||||
|
*/
|
||||||
private fun setFooterLink(view: View) {
|
private fun setFooterLink(view: View) {
|
||||||
val footerLink: TextView = view.requireViewById(R.id.footer_learn_more)
|
val footerLink: TextView = view.requireViewById(R.id.footer_learn_more)
|
||||||
footerLink.movementMethod = LinkMovementMethod.getInstance()
|
footerLink.movementMethod = LinkMovementMethod.getInstance()
|
||||||
|
70
tests/screenshot/Android.bp
Normal file
70
tests/screenshot/Android.bp
Normal file
@@ -0,0 +1,70 @@
|
|||||||
|
//
|
||||||
|
// Copyright (C) 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.
|
||||||
|
|
||||||
|
android_app {
|
||||||
|
name: "ScreenshotTestStub",
|
||||||
|
defaults: [
|
||||||
|
"SettingsLibDefaults",
|
||||||
|
],
|
||||||
|
platform_apis: true,
|
||||||
|
certificate: "platform",
|
||||||
|
privileged: true,
|
||||||
|
use_resource_processor: true,
|
||||||
|
|
||||||
|
static_libs: [
|
||||||
|
"Settings-core",
|
||||||
|
"androidx.fragment_fragment-testing",
|
||||||
|
"androidx.fragment_fragment",
|
||||||
|
"androidx.test.runner",
|
||||||
|
"androidx.test.core",
|
||||||
|
],
|
||||||
|
uses_libs: ["org.apache.http.legacy"],
|
||||||
|
|
||||||
|
aaptflags: ["--extra-packages com.android.settings"],
|
||||||
|
manifest: "AndroidManifest.xml",
|
||||||
|
}
|
||||||
|
|
||||||
|
android_test {
|
||||||
|
name: "SettingsScreenshotTests",
|
||||||
|
platform_apis: true,
|
||||||
|
certificate: "platform",
|
||||||
|
test_suites: ["device-tests"],
|
||||||
|
srcs: [
|
||||||
|
"src/**/*.kt",
|
||||||
|
],
|
||||||
|
static_libs: [
|
||||||
|
"androidx.fragment_fragment-testing",
|
||||||
|
"androidx.fragment_fragment",
|
||||||
|
"androidx.test.rules",
|
||||||
|
"androidx.test.ext.junit",
|
||||||
|
"platform-screenshot-diff-core",
|
||||||
|
"Settings-testutils2",
|
||||||
|
"androidx.test.core",
|
||||||
|
"androidx.test.espresso.core",
|
||||||
|
"kotlinx-coroutines-android",
|
||||||
|
"androidx.lifecycle_lifecycle-runtime-testing",
|
||||||
|
"kotlinx_coroutines_test",
|
||||||
|
"Settings-core",
|
||||||
|
"androidx.test.runner",
|
||||||
|
],
|
||||||
|
uses_libs: ["org.apache.http.legacy"],
|
||||||
|
compile_multilib: "both",
|
||||||
|
manifest: "AndroidManifest.xml",
|
||||||
|
test_config: "AndroidTest.xml",
|
||||||
|
use_embedded_native_libs: false,
|
||||||
|
asset_dirs: ["assets"],
|
||||||
|
instrumentation_for: "ScreenshotTestStub",
|
||||||
|
data: [":ScreenshotTestStub"],
|
||||||
|
}
|
47
tests/screenshot/AndroidManifest.xml
Normal file
47
tests/screenshot/AndroidManifest.xml
Normal file
@@ -0,0 +1,47 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<!--
|
||||||
|
Copyright (C) 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"
|
||||||
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
|
package="com.android.settings.tests.screenshot"
|
||||||
|
>
|
||||||
|
|
||||||
|
<application android:debuggable="true">
|
||||||
|
<provider
|
||||||
|
android:name="com.android.settings.slices.SettingsSliceProvider"
|
||||||
|
android:authorities="com.android.settings.tests.screenshot.disabled"
|
||||||
|
android:enabled="false"
|
||||||
|
tools:node="remove"
|
||||||
|
tools:replace="android:authorities" />
|
||||||
|
|
||||||
|
</application>
|
||||||
|
|
||||||
|
<uses-permission android:name="android.permission.PACKAGE_USAGE_STATS" />
|
||||||
|
<uses-permission android:name="android.permission.WRITE_SECURE_SETTINGS" />
|
||||||
|
<uses-permission android:name="android.permission.READ_LOGS" />
|
||||||
|
<uses-permission android:name="android.permission.MOUNT_UNMOUNT_FILESYSTEMS" />
|
||||||
|
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
|
||||||
|
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
|
||||||
|
<uses-permission android:name="android.permission.MANAGE_EXTERNAL_STORAGE" />
|
||||||
|
<uses-permission android:name="android.permission.READ_DEVICE_CONFIG" />
|
||||||
|
|
||||||
|
<instrumentation
|
||||||
|
android:name="androidx.test.runner.AndroidJUnitRunner"
|
||||||
|
android:label="Android Settings Screenshot tests"
|
||||||
|
android:targetPackage="com.android.settings.tests.screenshot" />
|
||||||
|
|
||||||
|
</manifest>
|
36
tests/screenshot/AndroidTest.xml
Normal file
36
tests/screenshot/AndroidTest.xml
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
<!--
|
||||||
|
~ Copyright (C) 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.
|
||||||
|
-->
|
||||||
|
|
||||||
|
<configuration description="Runs settings screendiff tests.">
|
||||||
|
<option name="test-suite-tag" value="apct-instrumentation" />
|
||||||
|
<option name="test-suite-tag" value="apct" />
|
||||||
|
<target_preparer class="com.android.tradefed.targetprep.DeviceSetup">
|
||||||
|
<option name="optimized-property-setting" value="true" />
|
||||||
|
</target_preparer>
|
||||||
|
<target_preparer class="com.android.tradefed.targetprep.suite.SuiteApkInstaller">
|
||||||
|
<option name="cleanup-apks" value="true" />
|
||||||
|
<option name="test-file-name" value="SettingsScreenshotTests.apk" />
|
||||||
|
</target_preparer>
|
||||||
|
<metrics_collector class="com.android.tradefed.device.metric.FilePullerLogCollector">
|
||||||
|
<option name="directory-keys"
|
||||||
|
value="/data/user/0/com.android.settings.tests.screenshot/" />
|
||||||
|
<option name="collect-on-run-ended-only" value="true" />
|
||||||
|
</metrics_collector>
|
||||||
|
<test class="com.android.tradefed.testtype.AndroidJUnitTest">
|
||||||
|
<option name="package" value="com.android.settings.tests.screenshot" />
|
||||||
|
<option name="runner" value="androidx.test.runner.AndroidJUnitRunner" />
|
||||||
|
</test>
|
||||||
|
</configuration>
|
BIN
tests/screenshot/assets/pixel_4a_(5g)/fp_enroll_intro.png
Normal file
BIN
tests/screenshot/assets/pixel_4a_(5g)/fp_enroll_intro.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 210 KiB |
@@ -0,0 +1,147 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.android.settings.tests.screenshot
|
||||||
|
|
||||||
|
import android.content.Context
|
||||||
|
import android.graphics.Bitmap
|
||||||
|
import android.graphics.Canvas
|
||||||
|
import android.graphics.Color
|
||||||
|
import android.os.Bundle
|
||||||
|
import android.view.View
|
||||||
|
import androidx.fragment.app.testing.FragmentScenario
|
||||||
|
import androidx.fragment.app.testing.launchFragmentInContainer
|
||||||
|
import androidx.lifecycle.ViewModel
|
||||||
|
import androidx.lifecycle.ViewModelProvider
|
||||||
|
import androidx.test.core.app.ApplicationProvider
|
||||||
|
import androidx.test.ext.junit.runners.AndroidJUnit4
|
||||||
|
import androidx.test.platform.app.InstrumentationRegistry
|
||||||
|
import com.android.settings.R
|
||||||
|
import com.android.settings.biometrics.fingerprint2.shared.model.Default
|
||||||
|
import com.android.settings.biometrics.fingerprint2.ui.enrollment.fragment.FingerprintEnrollIntroV2Fragment
|
||||||
|
import com.android.settings.biometrics.fingerprint2.ui.enrollment.viewmodel.FingerprintEnrollNavigationViewModel
|
||||||
|
import com.android.settings.biometrics.fingerprint2.ui.enrollment.viewmodel.FingerprintEnrollViewModel
|
||||||
|
import com.android.settings.biometrics.fingerprint2.ui.enrollment.viewmodel.FingerprintGatekeeperViewModel
|
||||||
|
import com.android.settings.biometrics.fingerprint2.ui.enrollment.viewmodel.FingerprintScrollViewModel
|
||||||
|
import com.android.settings.biometrics.fingerprint2.ui.enrollment.viewmodel.GatekeeperInfo
|
||||||
|
import com.android.settings.biometrics.fingerprint2.ui.enrollment.viewmodel.NavState
|
||||||
|
import com.android.settings.biometrics.fingerprint2.ui.enrollment.viewmodel.Start
|
||||||
|
import com.android.settings.testutils2.FakeFingerprintManagerInteractor
|
||||||
|
import kotlinx.coroutines.test.StandardTestDispatcher
|
||||||
|
import org.junit.Before
|
||||||
|
import org.junit.Rule
|
||||||
|
import org.junit.Test
|
||||||
|
import org.junit.runner.RunWith
|
||||||
|
import platform.test.screenshot.GoldenImagePathManager
|
||||||
|
import platform.test.screenshot.ScreenshotTestRule
|
||||||
|
import platform.test.screenshot.matchers.MSSIMMatcher
|
||||||
|
|
||||||
|
@RunWith(AndroidJUnit4::class)
|
||||||
|
class BasicScreenshotTest {
|
||||||
|
@Rule
|
||||||
|
@JvmField
|
||||||
|
var rule: ScreenshotTestRule =
|
||||||
|
ScreenshotTestRule(
|
||||||
|
GoldenImagePathManager(
|
||||||
|
InstrumentationRegistry.getInstrumentation().getContext(),
|
||||||
|
InstrumentationRegistry.getInstrumentation()
|
||||||
|
.getTargetContext()
|
||||||
|
.getFilesDir()
|
||||||
|
.getAbsolutePath() + "/settings_screenshots"
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
private var context: Context = ApplicationProvider.getApplicationContext()
|
||||||
|
private var interactor = FakeFingerprintManagerInteractor()
|
||||||
|
|
||||||
|
private val gatekeeperViewModel =
|
||||||
|
FingerprintGatekeeperViewModel(
|
||||||
|
GatekeeperInfo.GatekeeperPasswordInfo(byteArrayOf(1, 2, 3), 100L),
|
||||||
|
interactor
|
||||||
|
)
|
||||||
|
|
||||||
|
private val backgroundDispatcher = StandardTestDispatcher()
|
||||||
|
private lateinit var fragmentScenario: FragmentScenario<FingerprintEnrollIntroV2Fragment>
|
||||||
|
val navState = NavState(true)
|
||||||
|
|
||||||
|
private val navigationViewModel = FingerprintEnrollNavigationViewModel(
|
||||||
|
backgroundDispatcher,
|
||||||
|
interactor,
|
||||||
|
gatekeeperViewModel,
|
||||||
|
Start.next(navState),
|
||||||
|
navState,
|
||||||
|
Default,
|
||||||
|
)
|
||||||
|
private var fingerprintViewModel = FingerprintEnrollViewModel(
|
||||||
|
interactor, gatekeeperViewModel, navigationViewModel,
|
||||||
|
)
|
||||||
|
private var fingerprintScrollViewModel = FingerprintScrollViewModel()
|
||||||
|
|
||||||
|
@Before
|
||||||
|
fun setup() {
|
||||||
|
val factory =
|
||||||
|
object : ViewModelProvider.Factory {
|
||||||
|
@Suppress("UNCHECKED_CAST")
|
||||||
|
override fun <T : ViewModel> create(
|
||||||
|
modelClass: Class<T>,
|
||||||
|
): T {
|
||||||
|
return when (modelClass) {
|
||||||
|
FingerprintEnrollViewModel::class.java -> fingerprintViewModel
|
||||||
|
FingerprintScrollViewModel::class.java -> fingerprintScrollViewModel
|
||||||
|
FingerprintEnrollNavigationViewModel::class.java -> navigationViewModel
|
||||||
|
FingerprintGatekeeperViewModel::class.java -> gatekeeperViewModel
|
||||||
|
else -> null
|
||||||
|
}
|
||||||
|
as T
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fragmentScenario =
|
||||||
|
launchFragmentInContainer(Bundle(), R.style.SudThemeGlif) {
|
||||||
|
FingerprintEnrollIntroV2Fragment(factory)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Renders a [view] into a [Bitmap]. */
|
||||||
|
private fun viewToBitmap(view: View): Bitmap {
|
||||||
|
val bitmap =
|
||||||
|
Bitmap.createBitmap(
|
||||||
|
view.measuredWidth,
|
||||||
|
view.measuredHeight,
|
||||||
|
Bitmap.Config.ARGB_8888,
|
||||||
|
)
|
||||||
|
val canvas = Canvas(bitmap)
|
||||||
|
view.draw(canvas)
|
||||||
|
return bitmap
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun testEnrollIntro() {
|
||||||
|
fragmentScenario.onFragment { fragment ->
|
||||||
|
val view = fragment.requireView().findViewById<View>(R.id.enroll_intro_content_view)!!
|
||||||
|
view.setBackgroundColor(Color.BLACK)
|
||||||
|
}
|
||||||
|
fragmentScenario.onFragment { fragment ->
|
||||||
|
val view = fragment.requireView().findViewById<View>(R.id.enroll_intro_content_view)!!
|
||||||
|
rule.assertBitmapAgainstGolden(
|
||||||
|
viewToBitmap(view),
|
||||||
|
"fp_enroll_intro",
|
||||||
|
MSSIMMatcher()
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user