diff options
| author | 2023-03-10 20:29:21 +0000 | |
|---|---|---|
| committer | 2023-03-10 20:29:21 +0000 | |
| commit | 6ffd6e9f46b124c80820ebbf55cca3432f35a7ae (patch) | |
| tree | 3b4e5d8ed0ebcc192eda4e8deae7c7790447b2e7 | |
| parent | 654056be779d9c5bff936adefebcc7ffa981e04e (diff) | |
| parent | e861ada26ed9137c777da98d84af238dadbd16db (diff) | |
[DO NOT MERGE] Refactor ViewScreenshotTestRule slightly to make it a bit extensible am: e861ada26e
Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/21931979
Change-Id: Ie9050ed2b82d16ed3ccedd15a87a44cb233a58b0
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
| -rw-r--r-- | packages/SystemUI/TEST_MAPPING | 19 | ||||
| -rw-r--r-- | packages/SystemUI/screenshot/src/com/android/systemui/testing/screenshot/ViewScreenshotTestRule.kt | 27 |
2 files changed, 36 insertions, 10 deletions
diff --git a/packages/SystemUI/TEST_MAPPING b/packages/SystemUI/TEST_MAPPING index 60bfdb2ee379..6474e6a867ac 100644 --- a/packages/SystemUI/TEST_MAPPING +++ b/packages/SystemUI/TEST_MAPPING @@ -43,6 +43,9 @@ }, { "exclude-annotation": "androidx.test.filters.FlakyTest" + }, + { + "exclude-annotation": "android.platform.test.annotations.Postsubmit" } ] }, @@ -160,5 +163,21 @@ } ] } + ], + "postsubmit": [ + { + "name": "SystemUIGoogleScreenshotTests", + "options": [ + { + "exclude-annotation": "org.junit.Ignore" + }, + { + "exclude-annotation": "androidx.test.filters.FlakyTest" + }, + { + "include-annotation": "android.platform.test.annotations.Postsubmit" + } + ] + } ] } diff --git a/packages/SystemUI/screenshot/src/com/android/systemui/testing/screenshot/ViewScreenshotTestRule.kt b/packages/SystemUI/screenshot/src/com/android/systemui/testing/screenshot/ViewScreenshotTestRule.kt index 738b37c9eea4..2d47356f2ce1 100644 --- a/packages/SystemUI/screenshot/src/com/android/systemui/testing/screenshot/ViewScreenshotTestRule.kt +++ b/packages/SystemUI/screenshot/src/com/android/systemui/testing/screenshot/ViewScreenshotTestRule.kt @@ -39,14 +39,14 @@ import platform.test.screenshot.getEmulatedDevicePathConfig import platform.test.screenshot.matchers.BitmapMatcher /** A rule for View screenshot diff unit tests. */ -class ViewScreenshotTestRule( +open class ViewScreenshotTestRule( emulationSpec: DeviceEmulationSpec, private val matcher: BitmapMatcher = UnitTestBitmapMatcher, assetsPathRelativeToBuildRoot: String ) : TestRule { private val colorsRule = MaterialYouColorsRule() private val deviceEmulationRule = DeviceEmulationRule(emulationSpec) - private val screenshotRule = + protected val screenshotRule = ScreenshotTestRule( SystemUIGoldenImagePathManager( getEmulatedDevicePathConfig(emulationSpec), @@ -64,15 +64,10 @@ class ViewScreenshotTestRule( return delegateRule.apply(base, description) } - /** - * Compare the content of the view provided by [viewProvider] with the golden image identified - * by [goldenIdentifier] in the context of [emulationSpec]. - */ - fun screenshotTest( - goldenIdentifier: String, + protected fun takeScreenshot( mode: Mode = Mode.WrapContent, viewProvider: (ComponentActivity) -> View, - ) { + ): Bitmap { activityRule.scenario.onActivity { activity -> // Make sure that the activity draws full screen and fits the whole display instead of // the system bars. @@ -99,7 +94,19 @@ class ViewScreenshotTestRule( contentView = content.getChildAt(0) } - val bitmap = contentView?.toBitmap() ?: error("contentView is null") + return contentView?.toBitmap() ?: error("contentView is null") + } + + /** + * Compare the content of the view provided by [viewProvider] with the golden image identified + * by [goldenIdentifier] in the context of [emulationSpec]. + */ + fun screenshotTest( + goldenIdentifier: String, + mode: Mode = Mode.WrapContent, + viewProvider: (ComponentActivity) -> View, + ) { + val bitmap = takeScreenshot(mode, viewProvider) screenshotRule.assertBitmapAgainstGolden( bitmap, goldenIdentifier, |