fix: 首次提交

This commit is contained in:
2024-12-09 11:25:23 +08:00
parent d0c01071e9
commit 2c2109a5f3
4741 changed files with 290641 additions and 0 deletions

View File

@@ -0,0 +1,51 @@
//
// 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.
//
package {
default_applicable_licenses: ["frameworks_base_license"],
}
filegroup {
name: "SpaScreenshotTestRNGFiles",
srcs: [
"src/**/*.java",
"src/**/*.kt",
],
}
android_test {
name: "SpaScreenshotTests",
use_resource_processor: true,
test_suites: ["device-tests"],
asset_dirs: ["assets"],
srcs: ["src/**/*.kt"],
certificate: "platform",
static_libs: [
"SpaLib",
"SpaLibTestUtils",
"androidx.compose.runtime_runtime",
"androidx.test.ext.junit",
"androidx.test.runner",
"mockito-target-minus-junit4",
"platform-parametric-runner-lib",
"platform-screenshot-diff-core",
],
kotlincflags: ["-Xjvm-default=all"],
}

View File

@@ -0,0 +1,32 @@
<?xml version="1.0" encoding="utf-8"?><!--
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.
-->
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.android.settingslib.spa.screenshot">
<uses-sdk android:minSdkVersion="21"/>
<application>
<uses-library android:name="android.test.runner" />
<activity android:name=".DebugActivity" android:exported="true" />
</application>
<instrumentation
android:name="androidx.test.runner.AndroidJUnitRunner"
android:label="Screenshot tests for SpaLib"
android:targetPackage="com.android.settingslib.spa.screenshot">
</instrumentation>
</manifest>

View File

@@ -0,0 +1,36 @@
<!--
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.
-->
<configuration description="Runs 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="SpaScreenshotTests.apk" />
</target_preparer>
<metrics_collector class="com.android.tradefed.device.metric.FilePullerLogCollector">
<option name="directory-keys"
value="/data/user/0/com.android.settingslib.spa.screenshot/files/settings_screenshots" />
<option name="collect-on-run-ended-only" value="true" />
</metrics_collector>
<test class="com.android.tradefed.testtype.AndroidJUnitTest">
<option name="package" value="com.android.settingslib.spa.screenshot" />
<option name="runner" value="androidx.test.runner.AndroidJUnitRunner" />
</test>
</configuration>

Binary file not shown.

After

Width:  |  Height:  |  Size: 24 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 28 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 17 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 23 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 55 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 57 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 75 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 53 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 80 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 59 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 92 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 76 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 20 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 23 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 17 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 41 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 50 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 65 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 52 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 93 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 50 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 82 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 69 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 28 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 30 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 37 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 29 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 62 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 30 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 49 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 42 KiB

View File

@@ -0,0 +1,52 @@
/*
* 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.
*/
plugins {
alias(libs.plugins.android.library)
alias(libs.plugins.kotlin.android)
}
val androidTop: String by extra
android {
namespace = "com.android.settingslib.spa.screenshot"
defaultConfig {
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
}
sourceSets {
sourceSets.getByName("main") {
java.setSrcDirs(
listOf("$androidTop/platform_testing/libraries/screenshot/src/main/java")
)
}
sourceSets.getByName("androidTest") {
kotlin.setSrcDirs(listOf("src"))
res.setSrcDirs(listOf("res"))
manifest.srcFile("AndroidManifest.xml")
}
}
buildFeatures {
compose = true
}
}
dependencies {
androidTestImplementation(project(":spa"))
androidTestImplementation(project(":testutils"))
androidTestImplementation(libs.dexmaker.mockito)
}

View File

@@ -0,0 +1,52 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (C) 2021 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="412dp"
android:height="300dp"
android:viewportWidth="412"
android:viewportHeight="300">
<path
android:pathData="M383.9,300H28.1C12.6,300 0,287.4 0,271.9V28.1C0,12.6 12.6,0 28.1,0h355.8C399.4,0 412,12.6 412,28.1v243.8C412,287.4 399.4,300 383.9,300z"
android:fillColor="#FFFFFF"/>
<path
android:pathData="M79.2,179.6h53.6v8.5h-53.6z"
android:fillColor="#1A73E8"/>
<path
android:pathData="M142.5,179.6h30.4v8.5h-30.4z"
android:fillColor="#1A73E8"/>
<path
android:pathData="M79.2,195.5h79.2v8.5h-79.2z"
android:fillColor="#1A73E8"/>
<path
android:pathData="M168.1,195.5h34.1v8.5h-34.1z"
android:fillColor="#1A73E8"/>
<path
android:pathData="M211.9,195.5h34.1v8.5h-34.1z"
android:fillColor="#1A73E8"/>
<path
android:pathData="M182.7,179.6h73.1v8.5h-73.1z"
android:fillColor="#1A73E8"/>
<path
android:pathData="M265.5,179.6h26.8v8.5h-26.8z"
android:fillColor="#1A73E8"/>
<path
android:pathData="M302.1,179.6h26.8v8.5h-26.8z"
android:fillColor="#1A73E8"/>
<path
android:pathData="M142.7,67.9h-11.5c-1.6,0 -2.9,1.3 -2.9,2.9H67.8c-7.9,0 -14.4,6.5 -14.4,14.4v132.4c0,7.9 6.5,14.4 14.4,14.4h276.4c7.9,0 14.4,-6.5 14.4,-14.4V85.2c0,-7.9 -6.5,-14.4 -14.4,-14.4H203.1c0,-1.6 -1.3,-2.9 -2.9,-2.9h-28.8c-1.6,0 -2.9,1.3 -2.9,2.9h-23C145.5,69.2 144.3,67.9 142.7,67.9zM344.2,73.7c6.4,0 11.5,5.2 11.5,11.5v132.4c0,6.3 -5.2,11.5 -11.5,11.5H67.8c-6.4,0 -11.5,-5.2 -11.5,-11.5V85.2c0,-6.3 5.2,-11.5 11.5,-11.5H344.2z"
android:fillColor="#DADCE0"/>
</vector>

View File

@@ -0,0 +1,74 @@
package {
default_applicable_licenses: ["Android-Apache-2.0"],
}
android_library {
name: "SpaRoboRNGTestsAssetsLib",
asset_dirs: ["assets"],
sdk_version: "current",
platform_apis: true,
manifest: "AndroidManifest.xml",
optimize: {
enabled: false,
},
use_resource_processor: true,
resource_dirs: ["res"],
}
android_app {
name: "SpaRoboApp",
srcs: [],
static_libs: [
"androidx.test.espresso.core",
"androidx.appcompat_appcompat",
"flag-junit",
"guava",
"SpaLib",
"SpaLibTestUtils",
"SpaRoboRNGTestsAssetsLib",
"platform-screenshot-diff-core",
"PlatformComposeSceneTransitionLayoutTestsUtils",
],
manifest: "robo-manifest.xml",
aaptflags: [
"--extra-packages",
"com.android.settingslib.spa.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: "SpaRoboRNGTests",
srcs: [
":SpaScreenshotTestRNGFiles",
":flag-junit",
":platform-test-screenshot-rules",
],
// Do not add any new libraries here, they should be added to SpaRoboApp 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: "SpaRoboApp",
}

View File

@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="utf-8"?><!--
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.
-->
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.android.settingslib.spa.screenshot">
<uses-sdk android:minSdkVersion="21"/>
<uses-permission android:name="android.permission.WRITE_SECURE_SETTINGS" />
</manifest>

Binary file not shown.

After

Width:  |  Height:  |  Size: 22 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 28 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 16 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 23 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 54 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 55 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 75 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 56 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 77 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 57 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 88 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 72 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 18 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 23 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 16 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 40 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 48 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 65 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 50 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 90 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 48 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 78 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 65 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 27 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 28 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 37 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 28 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 59 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 29 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 47 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 39 KiB

View File

@@ -0,0 +1,16 @@
# 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
graphicsMode=NATIVE

View File

@@ -0,0 +1,52 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (C) 2021 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="412dp"
android:height="300dp"
android:viewportWidth="412"
android:viewportHeight="300">
<path
android:pathData="M383.9,300H28.1C12.6,300 0,287.4 0,271.9V28.1C0,12.6 12.6,0 28.1,0h355.8C399.4,0 412,12.6 412,28.1v243.8C412,287.4 399.4,300 383.9,300z"
android:fillColor="#FFFFFF"/>
<path
android:pathData="M79.2,179.6h53.6v8.5h-53.6z"
android:fillColor="#1A73E8"/>
<path
android:pathData="M142.5,179.6h30.4v8.5h-30.4z"
android:fillColor="#1A73E8"/>
<path
android:pathData="M79.2,195.5h79.2v8.5h-79.2z"
android:fillColor="#1A73E8"/>
<path
android:pathData="M168.1,195.5h34.1v8.5h-34.1z"
android:fillColor="#1A73E8"/>
<path
android:pathData="M211.9,195.5h34.1v8.5h-34.1z"
android:fillColor="#1A73E8"/>
<path
android:pathData="M182.7,179.6h73.1v8.5h-73.1z"
android:fillColor="#1A73E8"/>
<path
android:pathData="M265.5,179.6h26.8v8.5h-26.8z"
android:fillColor="#1A73E8"/>
<path
android:pathData="M302.1,179.6h26.8v8.5h-26.8z"
android:fillColor="#1A73E8"/>
<path
android:pathData="M142.7,67.9h-11.5c-1.6,0 -2.9,1.3 -2.9,2.9H67.8c-7.9,0 -14.4,6.5 -14.4,14.4v132.4c0,7.9 6.5,14.4 14.4,14.4h276.4c7.9,0 14.4,-6.5 14.4,-14.4V85.2c0,-7.9 -6.5,-14.4 -14.4,-14.4H203.1c0,-1.6 -1.3,-2.9 -2.9,-2.9h-28.8c-1.6,0 -2.9,1.3 -2.9,2.9h-23C145.5,69.2 144.3,67.9 142.7,67.9zM344.2,73.7c6.4,0 11.5,5.2 11.5,11.5v132.4c0,6.3 -5.2,11.5 -11.5,11.5H67.8c-6.4,0 -11.5,-5.2 -11.5,-11.5V85.2c0,-6.3 5.2,-11.5 11.5,-11.5H344.2z"
android:fillColor="#DADCE0"/>
</vector>

View File

@@ -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.settingslib.spa.screenshot"
coreApp="true">
<application>
<activity
android:name="androidx.activity.ComponentActivity"
android:exported="true">
</activity>
</application>
</manifest>

View File

@@ -0,0 +1,66 @@
/*
* 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.settingslib.spa.screenshot.util
import android.graphics.Bitmap
import android.graphics.Canvas
import android.os.Build
import android.view.View
import platform.test.screenshot.matchers.MSSIMMatcher
import platform.test.screenshot.matchers.PixelPerfectMatcher
/** Draw this [View] into a [Bitmap]. */
// TODO(b/195673633): Remove this once Compose screenshot tests use hardware rendering for their
// tests.
fun View.drawIntoBitmap(): Bitmap {
val bitmap =
Bitmap.createBitmap(
measuredWidth,
measuredHeight,
Bitmap.Config.ARGB_8888,
)
val canvas = Canvas(bitmap)
draw(canvas)
return bitmap
}
/**
* The [BitmapMatcher][platform.test.screenshot.matchers.BitmapMatcher] that should be used for
* screenshot *unit* tests.
*/
val UnitTestBitmapMatcher =
if (Build.CPU_ABI == "x86_64") {
// Different CPU architectures can sometimes end up rendering differently, so we can't do
// pixel-perfect matching on different architectures using the same golden. Given that our
// presubmits are run on cf_x86_64_phone, our goldens should be perfectly matched on the
// x86_64 architecture and use the Structural Similarity Index on others.
// TODO(b/237511747): Run our screenshot presubmit tests on arm64 instead so that we can
// do pixel perfect matching both at presubmit time and at development time with actual
// devices.
PixelPerfectMatcher()
} else {
MSSIMMatcher()
}
/**
* The [BitmapMatcher][platform.test.screenshot.matchers.BitmapMatcher] that should be used for
* screenshot *unit* tests.
*
* We use the Structural Similarity Index for integration tests because they usually contain
* additional information and noise that shouldn't break the test.
*/
val IntegrationTestBitmapMatcher = MSSIMMatcher()

View File

@@ -0,0 +1,44 @@
/*
* 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.settingslib.spa.screenshot.util
import androidx.test.platform.app.InstrumentationRegistry
import platform.test.screenshot.GoldenImagePathManager
import platform.test.screenshot.PathConfig
/** A [GoldenImagePathManager] that should be used for all Settings screenshot tests. */
class SettingsGoldenImagePathManager(
pathConfig: PathConfig,
assetsPathRelativeToBuildRoot: String
) :
GoldenImagePathManager(
appContext = InstrumentationRegistry.getInstrumentation().context,
assetsPathRelativeToBuildRoot = assetsPathRelativeToBuildRoot,
deviceLocalPath =
InstrumentationRegistry.getInstrumentation()
.targetContext
.filesDir
.absolutePath
.toString() + "/settings_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 "SettingsGoldenImagePathManager"
}
}

View File

@@ -0,0 +1,111 @@
/*
* 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.settingslib.spa.screenshot.util
import android.os.Build
import androidx.activity.ComponentActivity
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Surface
import androidx.compose.runtime.Composable
import androidx.compose.ui.platform.ViewRootForTest
import androidx.compose.ui.test.junit4.createAndroidComposeRule
import androidx.compose.ui.test.onRoot
import com.android.settingslib.spa.framework.theme.SettingsTheme
import org.junit.rules.RuleChain
import org.junit.rules.TestRule
import org.junit.runner.Description
import org.junit.runners.model.Statement
import platform.test.screenshot.DeviceEmulationRule
import platform.test.screenshot.DeviceEmulationSpec
import platform.test.screenshot.MaterialYouColorsRule
import platform.test.screenshot.ScreenshotTestRule
import platform.test.screenshot.getEmulatedDevicePathConfig
/** A rule for Settings screenshot diff tests. */
class SettingsScreenshotTestRule(
emulationSpec: DeviceEmulationSpec,
assetsPathRelativeToBuildRoot: String
) : TestRule {
private val colorsRule = MaterialYouColorsRule()
private val deviceEmulationRule = DeviceEmulationRule(emulationSpec)
private val screenshotRule =
ScreenshotTestRule(
SettingsGoldenImagePathManager(
getEmulatedDevicePathConfig(emulationSpec),
assetsPathRelativeToBuildRoot
)
)
private val composeRule = createAndroidComposeRule<ComponentActivity>()
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 {
val ruleToApply = if (isRobolectric) roboRule else delegateRule
return ruleToApply.apply(base, description)
}
/**
* Compare [content] with the golden image identified by [goldenIdentifier] in the context of
* [testSpec].
*/
fun screenshotTest(
goldenIdentifier: String,
content: @Composable () -> Unit,
) {
// Make sure that the activity draws full screen and fits the whole display.
val activity = composeRule.activity
activity.mainExecutor.execute { activity.window.setDecorFitsSystemWindows(false) }
// Set the content using the AndroidComposeRule to make sure that the Activity is set up
// correctly.
composeRule.setContent {
SettingsTheme {
Surface(
color = MaterialTheme.colorScheme.background,
) {
content()
}
}
}
composeRule.waitForIdle()
val view = (composeRule.onRoot().fetchSemanticsNode().root as ViewRootForTest).view
screenshotRule.assertBitmapAgainstGolden(view.drawIntoBitmap(), goldenIdentifier, matcher)
}
}
/** Create a [SettingsScreenshotTestRule] for settings screenshot tests. */
fun settingsScreenshotTestRule(
emulationSpec: DeviceEmulationSpec,
): SettingsScreenshotTestRule {
val assetPath = if (Build.FINGERPRINT.contains("robolectric")) {
"frameworks/base/packages/SettingsLib/Spa/screenshot/robotests/assets"
} else {
"frameworks/base/packages/SettingsLib/Spa/screenshot/assets"
}
return SettingsScreenshotTestRule(
emulationSpec,
assetPath
)
}

View File

@@ -0,0 +1,60 @@
/*
* 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.settingslib.spa.screenshot.widget.button
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.automirrored.outlined.Launch
import androidx.compose.material.icons.outlined.Delete
import androidx.compose.material.icons.outlined.WarningAmber
import com.android.settingslib.spa.screenshot.util.settingsScreenshotTestRule
import com.android.settingslib.spa.widget.button.ActionButton
import com.android.settingslib.spa.widget.button.ActionButtons
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.PhoneAndTabletMinimal
/** A screenshot test for ExampleFeature. */
@RunWith(ParameterizedAndroidJunit4::class)
class ActionButtonsScreenshotTest(emulationSpec: DeviceEmulationSpec) {
companion object {
@Parameters(name = "{0}")
@JvmStatic
fun getTestSpecs() = DeviceEmulationSpec.PhoneAndTabletMinimal
}
@get:Rule
val screenshotRule =
settingsScreenshotTestRule(
emulationSpec,
)
@Test
fun test() {
screenshotRule.screenshotTest("actionButtons") {
val actionButtons = listOf(
ActionButton(text = "Open", imageVector = Icons.AutoMirrored.Outlined.Launch) {},
ActionButton(text = "Uninstall", imageVector = Icons.Outlined.Delete) {},
ActionButton(text = "Force stop", imageVector = Icons.Outlined.WarningAmber) {},
)
ActionButtons(actionButtons)
}
}
}

View File

@@ -0,0 +1,81 @@
/*
* 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.settingslib.spa.screenshot.widget.chart
import androidx.compose.material3.MaterialTheme
import com.android.settingslib.spa.screenshot.util.settingsScreenshotTestRule
import com.android.settingslib.spa.widget.chart.BarChart
import com.android.settingslib.spa.widget.chart.BarChartData
import com.android.settingslib.spa.widget.chart.BarChartModel
import com.github.mikephil.charting.formatter.IAxisValueFormatter
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.PhoneAndTabletMinimal
/** A screenshot test for ExampleFeature. */
@RunWith(ParameterizedAndroidJunit4::class)
class BarChartScreenshotTest(emulationSpec: DeviceEmulationSpec) {
companion object {
@Parameters(name = "{0}")
@JvmStatic
fun getTestSpecs() = DeviceEmulationSpec.PhoneAndTabletMinimal
}
@get:Rule
val screenshotRule =
settingsScreenshotTestRule(
emulationSpec,
)
@Test
fun test() {
screenshotRule.screenshotTest("barChart") {
val color = MaterialTheme.colorScheme.surfaceVariant
BarChart(
barChartModel = object : BarChartModel {
override val chartDataList = listOf(
BarChartData(x = 0f, y = listOf(12f)),
BarChartData(x = 1f, y = listOf(5f)),
BarChartData(x = 2f, y = listOf(21f)),
BarChartData(x = 3f, y = listOf(5f)),
BarChartData(x = 4f, y = listOf(10f)),
BarChartData(x = 5f, y = listOf(9f)),
BarChartData(x = 6f, y = listOf(1f)),
)
override val colors = listOf(color)
override val xValueFormatter =
IAxisValueFormatter { value, _ ->
"${WeekDay.entries[value.toInt()]}"
}
override val yValueFormatter =
IAxisValueFormatter { value, _ ->
"${value.toInt()}m"
}
override val yAxisMaxValue = 30f
}
)
}
}
private enum class WeekDay(val num: Int) {
Sun(0), Mon(1), Tue(2), Wed(3), Thu(4), Fri(5), Sat(6),
}
}

View File

@@ -0,0 +1,78 @@
/*
* 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.settingslib.spa.screenshot.widget.chart
import com.android.settingslib.spa.screenshot.util.settingsScreenshotTestRule
import com.android.settingslib.spa.widget.chart.LineChart
import com.android.settingslib.spa.widget.chart.LineChartData
import com.android.settingslib.spa.widget.chart.LineChartModel
import com.github.mikephil.charting.formatter.IAxisValueFormatter
import java.text.NumberFormat
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.PhoneAndTabletMinimal
/** A screenshot test for ExampleFeature. */
@RunWith(ParameterizedAndroidJunit4::class)
class LineChartScreenshotTest(emulationSpec: DeviceEmulationSpec) {
companion object {
@Parameters(name = "{0}")
@JvmStatic
fun getTestSpecs() = DeviceEmulationSpec.PhoneAndTabletMinimal
}
@get:Rule
val screenshotRule =
settingsScreenshotTestRule(
emulationSpec,
)
@Test
fun test() {
screenshotRule.screenshotTest("lineChart") {
LineChart(
lineChartModel = object : LineChartModel {
override val chartDataList = listOf(
LineChartData(x = 0f, y = 0f),
LineChartData(x = 1f, y = 0.1f),
LineChartData(x = 2f, y = 0.2f),
LineChartData(x = 3f, y = 0.6f),
LineChartData(x = 4f, y = 0.9f),
LineChartData(x = 5f, y = 1.0f),
LineChartData(x = 6f, y = 0.8f),
)
override val xValueFormatter =
IAxisValueFormatter { value, _ ->
"${WeekDay.entries[value.toInt()]}"
}
override val yValueFormatter =
IAxisValueFormatter { value, _ ->
NumberFormat.getPercentInstance().format(value)
}
}
)
}
}
private enum class WeekDay(val num: Int) {
Sun(0), Mon(1), Tue(2), Wed(3), Thu(4), Fri(5), Sat(6),
}
}

View File

@@ -0,0 +1,61 @@
/*
* 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.settingslib.spa.screenshot.widget.chart
import com.android.settingslib.spa.screenshot.util.settingsScreenshotTestRule
import com.android.settingslib.spa.widget.chart.PieChart
import com.android.settingslib.spa.widget.chart.PieChartData
import com.android.settingslib.spa.widget.chart.PieChartModel
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.PhoneAndTabletMinimal
/** A screenshot test for ExampleFeature. */
@RunWith(ParameterizedAndroidJunit4::class)
class PieChartScreenshotTest(emulationSpec: DeviceEmulationSpec) {
companion object {
@Parameters(name = "{0}")
@JvmStatic
fun getTestSpecs() = DeviceEmulationSpec.PhoneAndTabletMinimal
}
@get:Rule
val screenshotRule =
settingsScreenshotTestRule(
emulationSpec,
)
@Test
fun test() {
screenshotRule.screenshotTest("pieChart") {
PieChart(
pieChartModel = object : PieChartModel {
override val chartDataList = listOf(
PieChartData(label = "Settings", value = 20f),
PieChartData(label = "Chrome", value = 5f),
PieChartData(label = "Gmail", value = 3f),
)
override val centerText = "Today"
}
)
}
}
}

View File

@@ -0,0 +1,56 @@
/*
* 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.settingslib.spa.screenshot.widget.illustration
import com.android.settingslib.spa.screenshot.R
import com.android.settingslib.spa.screenshot.util.settingsScreenshotTestRule
import com.android.settingslib.spa.widget.illustration.Illustration
import com.android.settingslib.spa.widget.illustration.IllustrationModel
import com.android.settingslib.spa.widget.illustration.ResourceType
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.PhoneAndTabletMinimal
/** A screenshot test for ExampleFeature. */
@RunWith(ParameterizedAndroidJunit4::class)
class ImageIllustrationScreenshotTest(emulationSpec: DeviceEmulationSpec) {
companion object {
@Parameters(name = "{0}")
@JvmStatic
fun getTestSpecs() = DeviceEmulationSpec.PhoneAndTabletMinimal
}
@get:Rule
val screenshotRule =
settingsScreenshotTestRule(
emulationSpec,
)
@Test
fun test() {
screenshotRule.screenshotTest("imageIllustration") {
Illustration(object : IllustrationModel {
override val resId = R.drawable.accessibility_captioning_banner
override val resourceType = ResourceType.IMAGE
})
}
}
}

View File

@@ -0,0 +1,66 @@
/*
* 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.settingslib.spa.screenshot.widget.preference
import androidx.compose.foundation.layout.Column
import com.android.settingslib.spa.screenshot.util.settingsScreenshotTestRule
import com.android.settingslib.spa.widget.preference.MainSwitchPreference
import com.android.settingslib.spa.widget.preference.SwitchPreferenceModel
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.PhoneAndTabletMinimal
/** A screenshot test for ExampleFeature. */
@RunWith(ParameterizedAndroidJunit4::class)
class MainSwitchPreferenceScreenshotTest(emulationSpec: DeviceEmulationSpec) {
companion object {
@Parameters(name = "{0}")
@JvmStatic
fun getTestSpecs() = DeviceEmulationSpec.PhoneAndTabletMinimal
}
@get:Rule
val screenshotRule =
settingsScreenshotTestRule(
emulationSpec,
)
@Test
fun test() {
screenshotRule.screenshotTest("mainSwitchPreference") {
Column {
MainSwitchPreference(
object : SwitchPreferenceModel {
override val title = "MainSwitchPreference"
override val checked = { false }
override val onCheckedChange = null
})
MainSwitchPreference(object : SwitchPreferenceModel {
override val title = "Not changeable"
override val changeable = { false }
override val checked = { true }
override val onCheckedChange = null
})
}
}
}
}

View File

@@ -0,0 +1,92 @@
/*
* 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.settingslib.spa.screenshot.widget.preference
import androidx.compose.foundation.layout.Column
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.outlined.Autorenew
import androidx.compose.material.icons.outlined.DisabledByDefault
import androidx.compose.runtime.Composable
import com.android.settingslib.spa.screenshot.util.settingsScreenshotTestRule
import com.android.settingslib.spa.widget.preference.Preference
import com.android.settingslib.spa.widget.preference.PreferenceModel
import com.android.settingslib.spa.widget.ui.SettingsIcon
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.PhoneAndTabletMinimal
/** A screenshot test for ExampleFeature. */
@RunWith(ParameterizedAndroidJunit4::class)
class PreferenceScreenshotTest(emulationSpec: DeviceEmulationSpec) {
companion object {
@Parameters(name = "{0}")
@JvmStatic
fun getTestSpecs() = DeviceEmulationSpec.PhoneAndTabletMinimal
private const val TITLE = "Title"
private const val SUMMARY = "Summary"
private const val LONG_SUMMARY =
"Long long long long long long long long long long long long long long long summary"
}
@get:Rule
val screenshotRule =
settingsScreenshotTestRule(
emulationSpec,
)
@Test
fun test() {
screenshotRule.screenshotTest("preference") {
Column {
Preference(object : PreferenceModel {
override val title = TITLE
})
Preference(object : PreferenceModel {
override val title = TITLE
override val summary = { SUMMARY }
})
Preference(object : PreferenceModel {
override val title = TITLE
override val summary = { LONG_SUMMARY }
})
Preference(object : PreferenceModel {
override val title = TITLE
override val summary = { SUMMARY }
override val enabled = { false }
override val icon = @Composable {
SettingsIcon(imageVector = Icons.Outlined.DisabledByDefault)
}
})
Preference(object : PreferenceModel {
override val title = TITLE
override val summary = { SUMMARY }
override val icon = @Composable {
SettingsIcon(imageVector = Icons.Outlined.Autorenew)
}
})
}
}
}
}

View File

@@ -0,0 +1,90 @@
/*
* 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.settingslib.spa.screenshot.widget.preference
import androidx.compose.foundation.layout.Column
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.outlined.Delete
import androidx.compose.material.icons.outlined.SystemUpdate
import androidx.compose.runtime.Composable
import com.android.settingslib.spa.screenshot.util.settingsScreenshotTestRule
import com.android.settingslib.spa.widget.preference.ProgressBarPreference
import com.android.settingslib.spa.widget.preference.ProgressBarPreferenceModel
import com.android.settingslib.spa.widget.preference.ProgressBarWithDataPreference
import com.android.settingslib.spa.widget.ui.CircularProgressBar
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.PhoneAndTabletMinimal
/** A screenshot test for ExampleFeature. */
@RunWith(ParameterizedAndroidJunit4::class)
class ProgressBarPreferenceScreenshotTest(emulationSpec: DeviceEmulationSpec) {
companion object {
@Parameters(name = "{0}")
@JvmStatic
fun getTestSpecs() = DeviceEmulationSpec.PhoneAndTabletMinimal
}
@get:Rule
val screenshotRule =
settingsScreenshotTestRule(
emulationSpec,
)
@Test
fun test() {
screenshotRule.screenshotTest("progressBar") {
Column {
LargeProgressBar()
SimpleProgressBar()
ProgressBarWithData()
CircularProgressBar(progress = 0.8f, radius = 160f)
}
}
}
}
@Composable
private fun LargeProgressBar() {
ProgressBarPreference(object : ProgressBarPreferenceModel {
override val title = "Large Progress Bar"
override val progress = 0.2f
override val height = 20f
})
}
@Composable
private fun SimpleProgressBar() {
ProgressBarPreference(object : ProgressBarPreferenceModel {
override val title = "Simple Progress Bar"
override val progress = 0.2f
override val icon = Icons.Outlined.SystemUpdate
})
}
@Composable
private fun ProgressBarWithData() {
ProgressBarWithDataPreference(model = object : ProgressBarPreferenceModel {
override val title = "Progress Bar with Data"
override val progress = 0.2f
override val icon = Icons.Outlined.Delete
}, data = "25G")
}

View File

@@ -0,0 +1,75 @@
/*
* 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.settingslib.spa.screenshot.widget.preference
import androidx.compose.foundation.layout.Column
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.outlined.AccessAlarm
import com.android.settingslib.spa.screenshot.util.settingsScreenshotTestRule
import com.android.settingslib.spa.widget.preference.SliderPreference
import com.android.settingslib.spa.widget.preference.SliderPreferenceModel
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.PhoneAndTabletMinimal
/** A screenshot test for ExampleFeature. */
@RunWith(ParameterizedAndroidJunit4::class)
class SliderPreferenceScreenshotTest(emulationSpec: DeviceEmulationSpec) {
companion object {
@Parameters(name = "{0}")
@JvmStatic
fun getTestSpecs() = DeviceEmulationSpec.PhoneAndTabletMinimal
}
@get:Rule
val screenshotRule =
settingsScreenshotTestRule(
emulationSpec,
)
@Test
fun test() {
screenshotRule.screenshotTest("slider") {
Column {
SliderPreference(object : SliderPreferenceModel {
override val title = "Simple Slider"
override val initValue = 40
})
SliderPreference(object : SliderPreferenceModel {
override val title = "Slider with icon"
override val initValue = 30
override val onValueChangeFinished = {
println("onValueChangeFinished")
}
override val icon = Icons.Outlined.AccessAlarm
})
SliderPreference(object : SliderPreferenceModel {
override val title = "Slider with steps"
override val initValue = 2
override val valueRange = 1..5
override val showSteps = true
})
}
}
}
}

Some files were not shown because too many files have changed in this diff Show More