Bug 1507997 - Use compositionupdate event to wait for composition text r=geckoview-reviewers,snorp
authorMakoto Kato <m_kato@ga2.so-net.ne.jp>
Mon, 17 Jun 2019 05:23:17 +0000
changeset 479125 bd82743a3e4e570eec6f014d8c5455c080614614
parent 479124 fb974fbba61b24c69f412c051112c41e5f1a1d7d
child 479126 a107e0c09120150c2733f1d40200fb43066c8e7a
push id36170
push usercbrindusan@mozilla.com
push dateWed, 19 Jun 2019 03:56:45 +0000
treeherdermozilla-central@5f0f37756053 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersgeckoview-reviewers, snorp
bugs1507997
milestone69.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1507997 - Use compositionupdate event to wait for composition text r=geckoview-reviewers,snorp A lot of failures occurs in `org.mozilla.geckoview.test.TextInputDelegateTest.inputConnection` when getting composition string. This tests doesn't wait for `compositionupdate`, so we should listen this event to wait for updating composition string. Differential Revision: https://phabricator.services.mozilla.com/D34812
mobile/android/geckoview/src/androidTest/java/org/mozilla/geckoview/test/TextInputDelegateTest.kt
--- a/mobile/android/geckoview/src/androidTest/java/org/mozilla/geckoview/test/TextInputDelegateTest.kt
+++ b/mobile/android/geckoview/src/androidTest/java/org/mozilla/geckoview/test/TextInputDelegateTest.kt
@@ -78,16 +78,26 @@ class TextInputDelegateTest : BaseSessio
     private fun processParentEvents() {
         sessionRule.waitForChromeJS("")
     }
 
     private fun processChildEvents() {
         mainSession.waitForJS("new Promise(r => window.setTimeout(r))")
     }
 
+    private fun setComposingText(ic: InputConnection, text: CharSequence, newCursorPosition: Int) {
+        val promise = mainSession.evaluateJS(
+                when (id) {
+                    "#designmode" -> "new Promise(r => $('$id').contentDocument.addEventListener('compositionupdate', r, { once: true }))"
+                    else -> "new Promise(r => $('$id').addEventListener('compositionupdate', r, { once: true }))"
+                })
+        ic.setComposingText(text, newCursorPosition)
+        promise.asJSPromise().value
+    }
+
     private fun pressKey(keyCode: Int) {
         // Create a Promise to listen to the key event, and wait on it below.
         val promise = mainSession.evaluateJS(
                 "new Promise(r => window.addEventListener('keyup', r, { once: true }))")
         val time = SystemClock.uptimeMillis()
         val keyEvent = KeyEvent(time, time, KeyEvent.ACTION_DOWN, keyCode, 0)
         mainSession.textInput.onKeyDown(keyCode, keyEvent)
         mainSession.textInput.onKeyUp(keyCode, KeyEvent.changeAction(keyEvent, KeyEvent.ACTION_UP))
@@ -344,40 +354,40 @@ class TextInputDelegateTest : BaseSessio
         assertTextAndSelectionAt("Can delete text before/after", ic,
                                  "foofoo", 3)
         ic.deleteSurroundingText(0, 10)
         assertTextAndSelectionAt("Can delete text after", ic, "foo", 3)
         ic.deleteSurroundingText(0, 0)
         assertTextAndSelectionAt("Can delete empty text", ic, "foo", 3)
 
         // Test setComposingText
-        ic.setComposingText("foo", 1)
+        setComposingText(ic, "foo", 1)
         assertTextAndSelectionAt("Can start composition", ic, "foofoo", 6)
-        ic.setComposingText("", 1)
+        setComposingText(ic, "", 1)
         assertTextAndSelectionAt("Can set empty composition", ic, "foo", 3)
-        ic.setComposingText("bar", 1)
+        setComposingText(ic, "bar", 1)
         assertTextAndSelectionAt("Can update composition", ic, "foobar", 6)
 
         // Test finishComposingText
         ic.finishComposingText()
         assertTextAndSelectionAt("Can finish composition", ic, "foobar", 6)
 
         // Test setComposingRegion
         ic.setComposingRegion(0, 3)
         assertTextAndSelectionAt("Can set composing region", ic, "foobar", 6)
 
-        ic.setComposingText("far", 1)
+        setComposingText(ic, "far", 1)
         assertTextAndSelectionAt("Can set composing region text", ic,
                                  "farbar", 3)
 
         ic.setComposingRegion(1, 4)
         assertTextAndSelectionAt("Can set existing composing region", ic,
                                  "farbar", 3)
 
-        ic.setComposingText("rab", 3)
+        setComposingText(ic, "rab", 3)
         assertTextAndSelectionAt("Can set new composing region text", ic,
                                  "frabar", 6, /* checkGecko */ false)
 
         // Test getTextBeforeCursor
         assertThat("Can retrieve text before cursor",
                    "bar", equalTo(ic.getTextBeforeCursor(3, 0)))
 
         // Test getTextAfterCursor
@@ -407,27 +417,30 @@ class TextInputDelegateTest : BaseSessio
         ic.sendKeyEvent(tKey)
         ic.sendKeyEvent(KeyEvent.changeAction(tKey, KeyEvent.ACTION_UP))
         assertTextAndSelectionAt("Can type using event", ic, "frabat", 6)
 
         ic.deleteSurroundingText(6, 0)
         assertTextAndSelectionAt("Can clear text", ic, "", 0)
 
         // Bug 1133802, duplication when setting the same composing text more than once.
-        ic.setComposingText("foo", 1)
+        setComposingText(ic, "foo", 1)
         assertTextAndSelectionAt("Can set the composing text", ic, "foo", 3)
+        // Setting same text doesn't fire compositionupdate
         ic.setComposingText("foo", 1)
         assertTextAndSelectionAt("Can set the same composing text", ic,
                                  "foo", 3)
-        ic.setComposingText("bar", 1)
+        setComposingText(ic, "bar", 1)
         assertTextAndSelectionAt("Can set different composing text", ic,
                                  "bar", 3)
+        // Setting same text doesn't fire compositionupdate
         ic.setComposingText("bar", 1)
         assertTextAndSelectionAt("Can set the same composing text", ic,
                                  "bar", 3)
+        // Setting same text doesn't fire compositionupdate
         ic.setComposingText("bar", 1)
         assertTextAndSelectionAt("Can set the same composing text again", ic,
                                  "bar", 3)
         ic.finishComposingText()
         assertTextAndSelectionAt("Can finish composing text", ic, "bar", 3)
 
         ic.deleteSurroundingText(3, 0)
         assertTextAndSelectionAt("Can clear text", ic, "", 0)
@@ -461,20 +474,20 @@ class TextInputDelegateTest : BaseSessio
         assertTextAndSelectionAt("Cannot forward delete with shift+backspace", ic,
                                  "oo", 0)
 
         ic.deleteSurroundingText(0, 2)
         assertTextAndSelectionAt("Can clear text", ic, "", 0)
 
         // Bug 1490391 - Committing then setting composition can result in duplicates.
         ic.commitText("far", 1)
-        ic.setComposingText("bar", 1)
+        setComposingText(ic, "bar", 1)
         assertTextAndSelectionAt("Can commit then set composition", ic,
                                  "farbar", 6)
-        ic.setComposingText("baz", 1)
+        setComposingText(ic, "baz", 1)
         assertTextAndSelectionAt("Composition still exists after setting", ic,
                                  "farbaz", 6)
 
         ic.finishComposingText()
         ic.deleteSurroundingText(6, 0)
         assertTextAndSelectionAt("Can clear text", ic, "", 0)
     }
 }