[go: nahoru, domu]

Synchronize test in composeTestRule.setContent

ComposeTestRule.setContent already made an effort to be fully drawn
after it returned from the method, but it didn't work and it is now
handled by FirstDrawIdlingResource. All we need to do in setContent
is call waitForIdle().

This also adds waitForIdle() as a global method in Synchronization.

Bug: 154079800
Test: ./gradlew ui:ui-test:cC
Relnote: "No longer need to explicitly call onIdle() after
`ComposeTestRule.setContent {}`."

Change-Id: Iafb2e031362bb3cd179947642299f01f8c720b15
diff --git a/ui/ui-test/src/androidTest/java/androidx/ui/test/FirstDrawTest.kt b/ui/ui-test/src/androidTest/java/androidx/ui/test/FirstDrawTest.kt
index 086fe88..fa112c6 100644
--- a/ui/ui-test/src/androidTest/java/androidx/ui/test/FirstDrawTest.kt
+++ b/ui/ui-test/src/androidTest/java/androidx/ui/test/FirstDrawTest.kt
@@ -55,6 +55,21 @@
     }
 
     /**
+     * Tests that the compose tree has been drawn at least once when [onIdle] finishes.
+     */
+    @Test
+    fun waitsForFirstDraw_withoutOnIdle() {
+        var drawn = false
+        testRule.setContent {
+            Canvas(Modifier.fillMaxSize()) {
+                drawn = true
+            }
+        }
+        // onIdle() shouldn't be necessary
+        assertThat(drawn).isTrue()
+    }
+
+    /**
      * Tests that [onIdle] doesn't timeout when the compose tree is completely off-screen and
      * will hence not be drawn.
      */