Merge "Add dialog test util to ViewScreenshotTestRule" into tm-qpr-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
a891b17715
@@ -1,6 +1,7 @@
|
|||||||
package com.android.systemui.testing.screenshot
|
package com.android.systemui.testing.screenshot
|
||||||
|
|
||||||
import android.app.Activity
|
import android.app.Activity
|
||||||
|
import android.app.Dialog
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
import android.view.ViewGroup.LayoutParams
|
import android.view.ViewGroup.LayoutParams
|
||||||
@@ -23,20 +24,20 @@ class ViewScreenshotTestRule(testSpec: ScreenshotTestSpec) : TestRule {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Compare the content of [view] with the golden image identified by [goldenIdentifier] in the
|
* Compare the content of the view provided by [viewProvider] with the golden image identified
|
||||||
* context of [testSpec].
|
* by [goldenIdentifier] in the context of [testSpec].
|
||||||
*/
|
*/
|
||||||
fun screenshotTest(
|
fun screenshotTest(
|
||||||
goldenIdentifier: String,
|
goldenIdentifier: String,
|
||||||
layoutParams: LayoutParams =
|
layoutParams: LayoutParams =
|
||||||
LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT),
|
LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT),
|
||||||
view: (Activity) -> View,
|
viewProvider: (Activity) -> View,
|
||||||
) {
|
) {
|
||||||
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.
|
||||||
activity.window.setDecorFitsSystemWindows(false)
|
activity.window.setDecorFitsSystemWindows(false)
|
||||||
activity.setContentView(view(activity), layoutParams)
|
activity.setContentView(viewProvider(activity), layoutParams)
|
||||||
}
|
}
|
||||||
|
|
||||||
// We call onActivity again because it will make sure that our Activity is done measuring,
|
// We call onActivity again because it will make sure that our Activity is done measuring,
|
||||||
@@ -48,4 +49,32 @@ class ViewScreenshotTestRule(testSpec: ScreenshotTestSpec) : TestRule {
|
|||||||
screenshotRule.screenshotTest(goldenIdentifier, content.getChildAt(0))
|
screenshotRule.screenshotTest(goldenIdentifier, content.getChildAt(0))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Compare the content of the dialog provided by [dialogProvider] with the golden image
|
||||||
|
* identified by [goldenIdentifier] in the context of [testSpec].
|
||||||
|
*/
|
||||||
|
fun dialogScreenshotTest(
|
||||||
|
goldenIdentifier: String,
|
||||||
|
dialogProvider: (Activity) -> Dialog,
|
||||||
|
) {
|
||||||
|
var dialog: Dialog? = null
|
||||||
|
activityRule.scenario.onActivity { activity ->
|
||||||
|
// Make sure that the dialog draws full screen and fits the whole display instead of the
|
||||||
|
// system bars.
|
||||||
|
dialog =
|
||||||
|
dialogProvider(activity).apply {
|
||||||
|
window.setDecorFitsSystemWindows(false)
|
||||||
|
show()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// We call onActivity again because it will make sure that our Dialog is done measuring,
|
||||||
|
// laying out and drawing its content (that we set in the previous onActivity lambda).
|
||||||
|
activityRule.scenario.onActivity {
|
||||||
|
// Check that the content is what we expected.
|
||||||
|
val dialog = dialog ?: error("dialog is null")
|
||||||
|
screenshotRule.screenshotTest(goldenIdentifier, dialog.window.decorView)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user