Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit db6ed76f authored by Jordan Demeulenaere's avatar Jordan Demeulenaere
Browse files

Add SysuiTestCase.runOnMainThreadAndWaitForIdleSync()

This CL introduces a runOnMainThreadAndWaitForIdleSync() utility to
easily post work in the main thread and wait for its completion in a
test. This should make it easier to work with code that has to run on
the main thread, like dialogs.

Bug: 346519570
Test: None, this is a test utility
Flag: EXEMPT test utility
Change-Id: I93790fb9a729d273b3806db9637d9a9af94d966f
parent 158f837e
Loading
Loading
Loading
Loading
+8 −0
Original line number Diff line number Diff line
@@ -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
}