Bug 1610353 - [3.0] Add Login Storage onLoginUsed test. r=geckoview-reviewers,snorp

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

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Eugen Sawin 2020-01-23 20:03:57 +00:00
Родитель 7f3a6f5a5f
Коммит 78b6ddecbf
1 изменённых файлов: 92 добавлений и 6 удалений

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

@ -19,6 +19,7 @@ import org.mozilla.geckoview.GeckoSession.PromptDelegate
import org.mozilla.geckoview.GeckoSession.PromptDelegate.LoginStoragePrompt
import org.mozilla.geckoview.LoginStorage
import org.mozilla.geckoview.LoginStorage.LoginEntry
import org.mozilla.geckoview.test.rule.GeckoSessionTestRule
import org.mozilla.geckoview.test.rule.GeckoSessionTestRule.AssertCalled
import org.mozilla.geckoview.test.rule.GeckoSessionTestRule.WithDisplay
import org.mozilla.geckoview.test.util.Callbacks
@ -35,7 +36,7 @@ class LoginStorageDelegateTest : BaseSessionTest() {
"signon.rememberSignons" to true,
"signon.autofillForms.http" to true))
val runtime = sessionRule.runtime;
val runtime = sessionRule.runtime
val register = { delegate: LoginStorage.Delegate ->
runtime.loginStorageDelegate = delegate
}
@ -53,7 +54,7 @@ class LoginStorageDelegateTest : BaseSessionTest() {
: GeckoResult<Array<LoginEntry>>? {
assertThat("Domain should match", domain, equalTo("localhost"))
fetchHandled.complete(null);
fetchHandled.complete(null)
return null
}
})
@ -70,7 +71,7 @@ class LoginStorageDelegateTest : BaseSessionTest() {
"signon.autofillForms.http" to true,
"signon.userInputRequiredToCapture.enabled" to false))
val runtime = sessionRule.runtime;
val runtime = sessionRule.runtime
val register = { delegate: LoginStorage.Delegate ->
runtime.loginStorageDelegate = delegate
}
@ -144,7 +145,7 @@ class LoginStorageDelegateTest : BaseSessionTest() {
"signon.autofillForms.http" to true,
"signon.userInputRequiredToCapture.enabled" to false))
val runtime = sessionRule.runtime;
val runtime = sessionRule.runtime
val register = { delegate: LoginStorage.Delegate ->
runtime.loginStorageDelegate = delegate
}
@ -224,7 +225,7 @@ class LoginStorageDelegateTest : BaseSessionTest() {
"signon.autofillForms.http" to true,
"signon.userInputRequiredToCapture.enabled" to false))
val runtime = sessionRule.runtime;
val runtime = sessionRule.runtime
val register = { delegate: LoginStorage.Delegate ->
runtime.loginStorageDelegate = delegate
}
@ -312,7 +313,7 @@ class LoginStorageDelegateTest : BaseSessionTest() {
"signon.autofillForms.http" to true,
"signon.userInputRequiredToCapture.enabled" to false))
val runtime = sessionRule.runtime;
val runtime = sessionRule.runtime
val register = { delegate: LoginStorage.Delegate ->
runtime.loginStorageDelegate = delegate
}
@ -423,4 +424,89 @@ class LoginStorageDelegateTest : BaseSessionTest() {
sessionRule.waitForResult(saveHandled2)
}
@Test
fun loginUsed() {
sessionRule.setPrefsUntilTestEnd(mapOf(
// Enable login management since it's disabled in automation.
"signon.rememberSignons" to true,
"signon.autofillForms.http" to true,
"signon.userInputRequiredToCapture.enabled" to false))
val runtime = sessionRule.runtime
val register = { delegate: LoginStorage.Delegate ->
runtime.loginStorageDelegate = delegate
}
val unregister = { _: LoginStorage.Delegate ->
runtime.loginStorageDelegate = null
}
val usedHandled = GeckoResult<Void>()
val user1 = "user1x"
val pass1 = "pass1x"
val guid = "test-guid"
val origin = GeckoSessionTestRule.TEST_ENDPOINT
val savedLogin = LoginEntry.Builder()
.guid(guid)
.origin(origin)
.formActionOrigin(origin)
.username(user1)
.password(pass1)
.build()
val savedLogins = mutableListOf<LoginEntry>(savedLogin)
sessionRule.addExternalDelegateUntilTestEnd(
LoginStorage.Delegate::class, register, unregister,
object : LoginStorage.Delegate {
@AssertCalled
override fun onLoginFetch(domain: String)
: GeckoResult<Array<LoginEntry>>? {
assertThat("Domain should match", domain, equalTo("localhost"))
return GeckoResult.fromValue(savedLogins.toTypedArray())
}
@AssertCalled(count = 1)
override fun onLoginUsed(login: LoginEntry, usedFields: Int) {
assertThat(
"Used fields should match",
usedFields,
equalTo(LoginStorage.UsedField.PASSWORD))
assertThat(
"Username should match",
login.username,
equalTo(user1))
assertThat(
"Password should match",
login.password,
equalTo(pass1))
assertThat(
"GUID should match",
login.guid,
equalTo(guid))
usedHandled.complete(null)
}
})
sessionRule.delegateUntilTestEnd(object : Callbacks.PromptDelegate {
@AssertCalled(false)
override fun onLoginStoragePrompt(
session: GeckoSession,
prompt: LoginStoragePrompt)
: GeckoResult<PromptDelegate.PromptResponse>? {
return null
}
})
mainSession.loadTestPath(FORMS3_HTML_PATH)
mainSession.waitForPageStop()
mainSession.evaluateJS("document.querySelector('#form1').submit()")
sessionRule.waitForResult(usedHandled)
}
}