Loading packages/SystemUI/TEST_MAPPING +19 −0 Original line number Original line Diff line number Diff line Loading @@ -43,6 +43,9 @@ }, }, { { "exclude-annotation": "androidx.test.filters.FlakyTest" "exclude-annotation": "androidx.test.filters.FlakyTest" }, { "exclude-annotation": "android.platform.test.annotations.Postsubmit" } } ] ] }, }, Loading Loading @@ -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" } ] } ] ] } } packages/SystemUI/screenshot/src/com/android/systemui/testing/screenshot/ViewScreenshotTestRule.kt +17 −10 Original line number Original line Diff line number Diff line Loading @@ -39,14 +39,14 @@ import platform.test.screenshot.getEmulatedDevicePathConfig import platform.test.screenshot.matchers.BitmapMatcher import platform.test.screenshot.matchers.BitmapMatcher /** A rule for View screenshot diff unit tests. */ /** A rule for View screenshot diff unit tests. */ class ViewScreenshotTestRule( open class ViewScreenshotTestRule( emulationSpec: DeviceEmulationSpec, emulationSpec: DeviceEmulationSpec, private val matcher: BitmapMatcher = UnitTestBitmapMatcher, private val matcher: BitmapMatcher = UnitTestBitmapMatcher, assetsPathRelativeToBuildRoot: String assetsPathRelativeToBuildRoot: String ) : TestRule { ) : TestRule { private val colorsRule = MaterialYouColorsRule() private val colorsRule = MaterialYouColorsRule() private val deviceEmulationRule = DeviceEmulationRule(emulationSpec) private val deviceEmulationRule = DeviceEmulationRule(emulationSpec) private val screenshotRule = protected val screenshotRule = ScreenshotTestRule( ScreenshotTestRule( SystemUIGoldenImagePathManager( SystemUIGoldenImagePathManager( getEmulatedDevicePathConfig(emulationSpec), getEmulatedDevicePathConfig(emulationSpec), Loading @@ -64,15 +64,10 @@ class ViewScreenshotTestRule( return delegateRule.apply(base, description) return delegateRule.apply(base, description) } } /** protected fun takeScreenshot( * 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, mode: Mode = Mode.WrapContent, viewProvider: (ComponentActivity) -> View, viewProvider: (ComponentActivity) -> View, ) { ): Bitmap { activityRule.scenario.onActivity { activity -> activityRule.scenario.onActivity { activity -> // Make sure that the activity draws full screen and fits the whole display instead of // Make sure that the activity draws full screen and fits the whole display instead of // the system bars. // the system bars. Loading @@ -99,7 +94,19 @@ class ViewScreenshotTestRule( contentView = content.getChildAt(0) 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( screenshotRule.assertBitmapAgainstGolden( bitmap, bitmap, goldenIdentifier, goldenIdentifier, Loading Loading
packages/SystemUI/TEST_MAPPING +19 −0 Original line number Original line Diff line number Diff line Loading @@ -43,6 +43,9 @@ }, }, { { "exclude-annotation": "androidx.test.filters.FlakyTest" "exclude-annotation": "androidx.test.filters.FlakyTest" }, { "exclude-annotation": "android.platform.test.annotations.Postsubmit" } } ] ] }, }, Loading Loading @@ -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" } ] } ] ] } }
packages/SystemUI/screenshot/src/com/android/systemui/testing/screenshot/ViewScreenshotTestRule.kt +17 −10 Original line number Original line Diff line number Diff line Loading @@ -39,14 +39,14 @@ import platform.test.screenshot.getEmulatedDevicePathConfig import platform.test.screenshot.matchers.BitmapMatcher import platform.test.screenshot.matchers.BitmapMatcher /** A rule for View screenshot diff unit tests. */ /** A rule for View screenshot diff unit tests. */ class ViewScreenshotTestRule( open class ViewScreenshotTestRule( emulationSpec: DeviceEmulationSpec, emulationSpec: DeviceEmulationSpec, private val matcher: BitmapMatcher = UnitTestBitmapMatcher, private val matcher: BitmapMatcher = UnitTestBitmapMatcher, assetsPathRelativeToBuildRoot: String assetsPathRelativeToBuildRoot: String ) : TestRule { ) : TestRule { private val colorsRule = MaterialYouColorsRule() private val colorsRule = MaterialYouColorsRule() private val deviceEmulationRule = DeviceEmulationRule(emulationSpec) private val deviceEmulationRule = DeviceEmulationRule(emulationSpec) private val screenshotRule = protected val screenshotRule = ScreenshotTestRule( ScreenshotTestRule( SystemUIGoldenImagePathManager( SystemUIGoldenImagePathManager( getEmulatedDevicePathConfig(emulationSpec), getEmulatedDevicePathConfig(emulationSpec), Loading @@ -64,15 +64,10 @@ class ViewScreenshotTestRule( return delegateRule.apply(base, description) return delegateRule.apply(base, description) } } /** protected fun takeScreenshot( * 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, mode: Mode = Mode.WrapContent, viewProvider: (ComponentActivity) -> View, viewProvider: (ComponentActivity) -> View, ) { ): Bitmap { activityRule.scenario.onActivity { activity -> activityRule.scenario.onActivity { activity -> // Make sure that the activity draws full screen and fits the whole display instead of // Make sure that the activity draws full screen and fits the whole display instead of // the system bars. // the system bars. Loading @@ -99,7 +94,19 @@ class ViewScreenshotTestRule( contentView = content.getChildAt(0) 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( screenshotRule.assertBitmapAgainstGolden( bitmap, bitmap, goldenIdentifier, goldenIdentifier, Loading