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

Commit 3ad486a5 authored by David Saff's avatar David Saff
Browse files

Thread guard teardown to prevent crash

Bug: 384537275
Test: ABTD in bug
Flag: TEST_ONLY
Change-Id: I6ce2c56d255ce1c0767fa581af977511b0bd5a58
parent 253d3033
Loading
Loading
Loading
Loading
+8 −4
Original line number Diff line number Diff line
@@ -148,7 +148,7 @@ class TileServiceRequestControllerTestComposeOn : SysuiTestCase() {
    @Test
    fun showAllUsers_set() =
        kosmos.runTest {
            val dialog = runOnMainThreadAndWaitForIdleSync {
            val dialog = createDialog {
                underTest.requestTileAdd(
                    TEST_UID,
                    TEST_COMPONENT,
@@ -158,7 +158,6 @@ class TileServiceRequestControllerTestComposeOn : SysuiTestCase() {
                    Callback(),
                )!!
            }
            onTeardown { dialog.cancel() }

            assertThat(dialog.isShowForAllUsers).isTrue()
        }
@@ -166,7 +165,7 @@ class TileServiceRequestControllerTestComposeOn : SysuiTestCase() {
    @Test
    fun cancelOnTouchOutside_set() =
        kosmos.runTest {
            val dialog = runOnMainThreadAndWaitForIdleSync {
            val dialog = createDialog {
                underTest.requestTileAdd(
                    TEST_UID,
                    TEST_COMPONENT,
@@ -176,11 +175,16 @@ class TileServiceRequestControllerTestComposeOn : SysuiTestCase() {
                    Callback(),
                )!!
            }
            onTeardown { dialog.cancel() }

            assertThat(dialog.isCancelOnTouchOutside).isTrue()
        }

    fun <T : DialogInterface> createDialog(constructor: () -> T): T {
        val dialog = runOnMainThreadAndWaitForIdleSync { constructor() }
        onTeardown { runOnMainThreadAndWaitForIdleSync { dialog.cancel() } }
        return dialog
    }

    @Test
    fun positiveAction_tileAdded() =
        kosmos.runTest {