Attempt to fix flaky cursorNotBlinking_whenWindowLostFocus in BTF

Also made sure this and focusedTextField_resumeBlinking_whenWindowRegainsFocus tests are the same in BTF and BTF2

Test: cursorNotBlinking_whenWindowLostFocus in BTF/BTF2
Test: focusedTextField_resumeBlinking_whenWindowRegainsFocus in BTF/BTF2
Bug: 306038723

Change-Id: I8ba27f506b75a8ab9d1bd674dbdec566a4038fa6
diff --git a/compose/foundation/foundation/src/androidInstrumentedTest/kotlin/androidx/compose/foundation/text2/TextFieldCursorTest.kt b/compose/foundation/foundation/src/androidInstrumentedTest/kotlin/androidx/compose/foundation/text2/TextFieldCursorTest.kt
index 16f3650..85c4f9a 100644
--- a/compose/foundation/foundation/src/androidInstrumentedTest/kotlin/androidx/compose/foundation/text2/TextFieldCursorTest.kt
+++ b/compose/foundation/foundation/src/androidInstrumentedTest/kotlin/androidx/compose/foundation/text2/TextFieldCursorTest.kt
@@ -733,6 +733,14 @@
             }
         }
 
+        focusAndWait()
+
+        // cursor visible first 500ms
+        rule.mainClock.advanceTimeBy(100)
+        rule.onNode(hasSetTextAction())
+            .captureToImage()
+            .assertContainsColor(cursorColor)
+
         // window loses focus
         focusWindow.value = false
         rule.waitForIdle()
@@ -776,12 +784,11 @@
 
         // check that text field cursor disappeared even within visible 500ms
         rule.mainClock.advanceTimeBy(100)
-
         rule.onNode(hasSetTextAction())
             .captureToImage()
             .assertDoesNotContainColor(cursorColor)
 
-        // window regains focus
+        // window regains focus within 500ms
         focusWindow.value = true
         rule.waitForIdle()
 
diff --git a/compose/foundation/foundation/src/androidInstrumentedTest/kotlin/androidx/compose/foundation/textfield/TextFieldCursorTest.kt b/compose/foundation/foundation/src/androidInstrumentedTest/kotlin/androidx/compose/foundation/textfield/TextFieldCursorTest.kt
index 249f1a4..38a96aa 100644
--- a/compose/foundation/foundation/src/androidInstrumentedTest/kotlin/androidx/compose/foundation/textfield/TextFieldCursorTest.kt
+++ b/compose/foundation/foundation/src/androidInstrumentedTest/kotlin/androidx/compose/foundation/textfield/TextFieldCursorTest.kt
@@ -28,6 +28,8 @@
 import androidx.compose.runtime.mutableStateOf
 import androidx.compose.runtime.remember
 import androidx.compose.runtime.setValue
+import androidx.compose.testutils.assertContainsColor
+import androidx.compose.testutils.assertDoesNotContainColor
 import androidx.compose.testutils.assertPixelColor
 import androidx.compose.testutils.assertPixels
 import androidx.compose.testutils.assertShape
@@ -600,11 +602,9 @@
 
         // cursor visible first 500ms
         rule.mainClock.advanceTimeBy(100)
-        with(rule.density) {
-            rule.onNode(hasSetTextAction())
-                .captureToImage()
-                .assertCursor(2.dp, this, cursorRect)
-        }
+        rule.onNode(hasSetTextAction())
+            .captureToImage()
+            .assertContainsColor(cursorColor)
 
         // window loses focus
         focusWindow.value = false
@@ -614,13 +614,7 @@
         rule.mainClock.advanceTimeBy(100)
         rule.onNode(hasSetTextAction())
             .captureToImage()
-            .assertShape(
-                density = rule.density,
-                shape = RectangleShape,
-                shapeColor = Color.White,
-                backgroundColor = Color.White,
-                shapeOverlapPixelCount = 0.0f
-            )
+            .assertDoesNotContainColor(cursorColor)
     }
 
     @Test
@@ -656,24 +650,17 @@
         rule.mainClock.advanceTimeBy(100)
         rule.onNode(hasSetTextAction())
             .captureToImage()
-            .assertShape(
-                density = rule.density,
-                shape = RectangleShape,
-                shapeColor = Color.White,
-                backgroundColor = Color.White,
-                shapeOverlapPixelCount = 0.0f
-            )
+            .assertDoesNotContainColor(cursorColor)
 
         // window regains focus within 500ms
         focusWindow.value = true
         rule.waitForIdle()
 
         rule.mainClock.advanceTimeBy(100)
-        with(rule.density) {
-            rule.onNode(hasSetTextAction())
-                .captureToImage()
-                .assertCursor(2.dp, this, cursorRect)
-        }
+        rule.onNode(hasSetTextAction())
+            .captureToImage()
+            .assertContainsColor(cursorColor)
+            .assertCursor(2.dp, rule.density, cursorRect)
     }
 
     private fun focusAndWait() {