Bug 1714998 - Rewrite org.mozilla.geckoview.test.TextInputDelegateTest.editorInfo_defaultByInputType. r=geckoview-reviewers,agi

When landing bug 1711626, I reuse /assets/www/forms.html for this issue. But
this causes unexpected issue. Although this HTML has iframe,
`loadTestPath(FORMS_HTML_PATH)` doesn't wait for iframe content, so then,
it seems to cause unexpected form initialization and editorInfo becomes
invalid value.

So I would like to rewrite this test.

InputConnection is updated asynchronously, so we need to check whether it is
created. Then even if it is created, editorInfo may not be ready. So we need
to flush IC's thread task.

Differential Revision: https://phabricator.services.mozilla.com/D118371
This commit is contained in:
Makoto Kato 2021-06-21 21:19:46 +00:00
Родитель c4afcf5b50
Коммит 2bbef07fe0
3 изменённых файлов: 48 добавлений и 4 удалений

Просмотреть файл

@ -0,0 +1,24 @@
<html>
<head>
<meta charset="utf-8">
<title>Forms</title>
<meta name="viewport" content="minimum-scale=1,width=device-width">
</head>
<body>
<form id="form1">
<input type="text" id="user1" value="foo">
<input type="password" id="pass1" value="foo">
<input type="email" id="email1" value="@">
<input type="number" id="number1" value="0">
<input type="tel" id="tel1" value="0">
<input type="submit" value="submit">
</form>
<input type="Text" id="user2" value="foo">
<input type="PassWord" id="pass2" maxlength="8" value="foo">
<input type="button" id="button1" value="foo"/>
<input type="checkbox" id="checkbox1"/>
<input type="search" id="search1">
<input type="url" id="url1">
<input type="hidden" id="hidden1" value="foo"/>
</body>
</html>

Просмотреть файл

@ -41,6 +41,7 @@ open class BaseSessionTest(noErrorCollector: Boolean = false) {
const val FORMS2_HTML_PATH = "/assets/www/forms2.html"
const val FORMS3_HTML_PATH = "/assets/www/forms3.html"
const val FORMS4_HTML_PATH = "/assets/www/forms4.html"
const val FORMS5_HTML_PATH = "/assets/www/forms5.html"
const val FORMS_AUTOCOMPLETE_HTML_PATH = "/assets/www/forms_autocomplete.html"
const val FORMS_ID_VALUE_HTML_PATH = "/assets/www/forms_id_value.html"
const val CC_FORM_HTML_PATH = "/assets/www/cc_form.html"

Просмотреть файл

@ -6,12 +6,15 @@ package org.mozilla.geckoview.test
import android.os.SystemClock
import androidx.test.platform.app.InstrumentationRegistry
import org.mozilla.geckoview.GeckoResult
import org.mozilla.geckoview.GeckoSession
import org.mozilla.geckoview.test.rule.GeckoSessionTestRule.AssertCalled
import org.mozilla.geckoview.test.rule.GeckoSessionTestRule.WithDisplay
import org.mozilla.geckoview.test.util.Callbacks
import androidx.test.filters.MediumTest
import android.os.Handler;
import android.os.Looper;
import android.text.InputType;
import android.view.KeyEvent
import android.view.View
@ -798,15 +801,34 @@ class TextInputDelegateTest : BaseSessionTest() {
assumeThat(sessionRule.env.isWebrender and sessionRule.env.isDebugBuild, equalTo(false))
mainSession.textInput.view = View(InstrumentationRegistry.getInstrumentation().targetContext)
mainSession.loadTestPath(FORMS_HTML_PATH)
mainSession.loadTestPath(FORMS5_HTML_PATH)
mainSession.waitForPageStop()
for (inputType in listOf("#email1", "#pass1", "#search1", "#tel1", "#url1")) {
mainSession.evaluateJS("document.querySelector('$inputType').focus()")
mainSession.waitUntilCalled(GeckoSession.TextInputDelegate::class, "restartInput")
// IC will be updated asynchronously, so spin event loop
processChildEvents()
processParentEvents()
val editorInfo = EditorInfo()
val ic = mainSession.textInput.onCreateInputConnection(editorInfo)!!
assertThat("InputConnection is created correctly", ic, notNullValue())
// Even if we get IC, new EditorInfo isn't updated yet.
// We post and wait for empty job to IC thread to flush all IC's job.
val result = object : GeckoResult<Boolean>() {
init {
val icHandler = mainSession.textInput.getHandler(Handler(Looper.getMainLooper()))
icHandler.post({
complete(true)
})
}
}
sessionRule.waitForResult(result)
mainSession.textInput.onCreateInputConnection(editorInfo)
assertThat("EditorInfo.inputType of $inputType", editorInfo.inputType, equalTo(
when (inputType) {
"#email1" -> InputType.TYPE_CLASS_TEXT or
@ -822,9 +844,6 @@ class TextInputDelegateTest : BaseSessionTest() {
InputType.TYPE_TEXT_VARIATION_URI
else -> 0
}))
mainSession.evaluateJS("document.querySelector('$inputType').blur()")
mainSession.waitUntilCalled(GeckoSession.TextInputDelegate::class, "restartInput")
}
}