Skip to content

Commit b9495b8

Browse files
committed
Make JS compose window lifecycle tests robustly handle window focus
1 parent 76232e6 commit b9495b8

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

compose/ui/ui/src/webTest/kotlin/androidx/compose/ui/window/ComposeWindowLifecycleTest.kt

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,13 @@ class ComposeWindowLifecycleTest : OnCanvasTests {
5454

5555
assertEquals(Lifecycle.State.CREATED, eventsChannel.receive().targetState)
5656
assertEquals(Lifecycle.State.STARTED, eventsChannel.receive().targetState)
57-
assertEquals(Lifecycle.State.RESUMED, eventsChannel.receive().targetState)
5857

59-
// Dispatch artificial events that would be sent when the window loses and regains focus.
58+
// Dispatch artificial events that would be sent when the window gains and loses focus.
59+
// Starting with a focus event before checking for the initial RESUMED makes this test
60+
// robust in the face of both an actually-focused window and a non-focused window. Then,
61+
// a blur + focus cycle simulates losing focus and regaining it.
62+
window.dispatchEvent(Event("focus"))
63+
assertEquals(Lifecycle.State.RESUMED, eventsChannel.receive().targetState)
6064
window.dispatchEvent(Event("blur"))
6165
assertEquals(Lifecycle.State.STARTED, eventsChannel.receive().targetState)
6266
window.dispatchEvent(Event("focus"))

0 commit comments

Comments
 (0)