diff options
| -rw-r--r-- | packages/SystemUI/tests/utils/src/com/android/systemui/SysuiTestCaseExt.kt | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/packages/SystemUI/tests/utils/src/com/android/systemui/SysuiTestCaseExt.kt b/packages/SystemUI/tests/utils/src/com/android/systemui/SysuiTestCaseExt.kt index 46259a6964cd..d3dccb021ff8 100644 --- a/packages/SystemUI/tests/utils/src/com/android/systemui/SysuiTestCaseExt.kt +++ b/packages/SystemUI/tests/utils/src/com/android/systemui/SysuiTestCaseExt.kt @@ -20,3 +20,11 @@ import com.android.systemui.kosmos.Kosmos import com.android.systemui.kosmos.testCase fun SysuiTestCase.testKosmos(): Kosmos = Kosmos().apply { testCase = this@testKosmos } + +/** Run [f] on the main thread and return its result once completed. */ +fun <T : Any> SysuiTestCase.runOnMainThreadAndWaitForIdleSync(f: () -> T): T { + lateinit var result: T + context.mainExecutor.execute { result = f() } + waitForIdleSync() + return result +} |