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

Commit 6d609fd1 authored by Fabián Kozynski's avatar Fabián Kozynski
Browse files

Make sure that views process posted messages

Adds a latch to make sure that messages put in the view handler are
processed before continuing the test.

Test: atest ControlsFavoritingActivityTest
Fixes: 276857737
Change-Id: Ie182f7f308ac17e0d78059bade908f78f6aded01
parent 02c4e4e0
Loading
Loading
Loading
Loading
+14 −2
Original line number Diff line number Diff line
@@ -60,6 +60,12 @@ class ControlsFavoritingActivityTest : SysuiTestCase() {
            }
        val TEST_STRUCTURE: CharSequence = "TestStructure"
        val TEST_APP: CharSequence = "TestApp"

        private fun View.waitForPost() {
            val latch = CountDownLatch(1)
            post(latch::countDown)
            latch.await()
        }
    }

    @Main private val executor: Executor = MoreExecutors.directExecutor()
@@ -140,7 +146,10 @@ class ControlsFavoritingActivityTest : SysuiTestCase() {
            val rearrangeButton = requireViewById<Button>(R.id.rearrange)
            assertThat(rearrangeButton.visibility).isEqualTo(View.VISIBLE)
            assertThat(rearrangeButton.isEnabled).isFalse()
            assertThat(requireViewById<Button>(R.id.other_apps).visibility).isEqualTo(View.GONE)

            val otherAppsButton = requireViewById<Button>(R.id.other_apps)
            otherAppsButton.waitForPost()
            assertThat(otherAppsButton.visibility).isEqualTo(View.GONE)
        }
    }

@@ -160,7 +169,10 @@ class ControlsFavoritingActivityTest : SysuiTestCase() {
            val rearrangeButton = requireViewById<Button>(R.id.rearrange)
            assertThat(rearrangeButton.visibility).isEqualTo(View.GONE)
            assertThat(rearrangeButton.isEnabled).isFalse()
            assertThat(requireViewById<Button>(R.id.other_apps).visibility).isEqualTo(View.VISIBLE)

            val otherAppsButton = requireViewById<Button>(R.id.other_apps)
            otherAppsButton.waitForPost()
            assertThat(otherAppsButton.visibility).isEqualTo(View.VISIBLE)
        }
    }