Bug 1497682 - Part 3. Add junit test. r=droeh

Summary:
Add autofill hint test if using Android 8+.

Depends on D12881

Reviewers: droeh

Reviewed By: droeh

Bug #: 1497682

Differential Revision: https://phabricator.services.mozilla.com/D12882

--HG--
extra : rebase_source : c4458b62d48434fe9d19f8ded04f2bc2666647ff
extra : histedit_source : 5ff01309b49965ff008e431059368ca0f05d56e6
This commit is contained in:
Makoto Kato 2018-12-18 18:05:36 +09:00
parent e305b5ca33
commit 631a33d252
3 changed files with 88 additions and 0 deletions

View File

@ -0,0 +1,19 @@
<html>
<head><title>Forms2</title></head>
<body>
<form>
<input type="text" id="firstname">
<input type="text" id="lastname">
<input type="text" id="user1" value="foo">
<input type="password" id="pass1" value="foo">
</form>
<iframe id="iframe"></iframe>
<script>
addEventListener("load", function(e) {
if (window.parent === window) {
document.getElementById("iframe").contentWindow.location.href = window.location.href;
}
});
</script>
</body>
</html>

View File

@ -29,6 +29,7 @@ open class BaseSessionTest(noErrorCollector: Boolean = false) {
const val CONTENT_CRASH_URL = "about:crashcontent"
const val DOWNLOAD_HTML_PATH = "/assets/www/download.html"
const val FORMS_HTML_PATH = "/assets/www/forms.html"
const val FORMS2_HTML_PATH = "/assets/www/forms2.html"
const val HELLO_HTML_PATH = "/assets/www/hello.html"
const val HELLO2_HTML_PATH = "/assets/www/hello2.html"
const val INPUTS_PATH = "/assets/www/inputs.html"

View File

@ -335,6 +335,9 @@ class ContentDelegateTest : BaseSessionTest() {
InputType.TYPE_TEXT_VARIATION_WEB_EMAIL_ADDRESS ->
arrayOf(View.AUTOFILL_HINT_EMAIL_ADDRESS)
InputType.TYPE_CLASS_PHONE -> arrayOf(View.AUTOFILL_HINT_PHONE)
InputType.TYPE_CLASS_TEXT or
InputType.TYPE_TEXT_VARIATION_WEB_EDIT_TEXT ->
arrayOf(View.AUTOFILL_HINT_USERNAME)
else -> null
}))
@ -455,6 +458,71 @@ class ContentDelegateTest : BaseSessionTest() {
countAutoFillNodes({ it.isFocused }), equalTo(0))
}
@WithDevToolsAPI
@Test fun autofill_userpass() {
if (Build.VERSION.SDK_INT < 26) {
return
}
mainSession.loadTestPath(FORMS2_HTML_PATH)
// Wait for the auto-fill nodes to populate.
sessionRule.waitUntilCalled(object : Callbacks.TextInputDelegate {
@AssertCalled(count = 2)
override fun notifyAutoFill(session: GeckoSession, notification: Int, virtualId: Int) {
}
})
mainSession.evaluateJS("$('#pass1').focus()")
sessionRule.waitUntilCalled(object : Callbacks.TextInputDelegate {
@AssertCalled(count = 1)
override fun notifyAutoFill(session: GeckoSession, notification: Int, virtualId: Int) {
}
})
val rootNode = ViewNode.newInstance()
val rootStructure = ViewNodeBuilder.newInstance(AssistStructure(), rootNode,
/* async */ false) as ViewStructure
// Perform auto-fill and return number of auto-fills performed.
fun checkAutoFillChild(child: AssistStructure.ViewNode): Int {
var sum = 0
// Seal the node info instance so we can perform actions on it.
if (child.childCount > 0) {
for (i in 0 until child.childCount) {
sum += checkAutoFillChild(child.getChildAt(i))
}
}
if (child === rootNode) {
return sum
}
assertThat("ID should be valid", child.id, not(equalTo(View.NO_ID)))
if (EditText::class.java.name == child.className) {
val htmlInfo = child.htmlInfo
assertThat("Should have HTML tag", htmlInfo.tag, equalTo("input"))
if (child.autofillHints == null) {
return sum
}
child.autofillHints.forEach {
when (it) {
View.AUTOFILL_HINT_USERNAME, View.AUTOFILL_HINT_PASSWORD -> {
sum++
}
}
}
}
return sum
}
mainSession.textInput.onProvideAutofillVirtualStructure(rootStructure, 0)
// form and iframe have each 2 hints.
assertThat("autofill hint count",
checkAutoFillChild(rootNode), equalTo(4))
}
private fun goFullscreen() {
sessionRule.setPrefsUntilTestEnd(mapOf("full-screen-api.allow-trusted-requests-only" to false))
mainSession.loadTestPath(FULLSCREEN_PATH)