diff --git a/mobile/android/geckoview/src/androidTest/java/org/mozilla/geckoview/test/LoginStorageDelegateTest.kt b/mobile/android/geckoview/src/androidTest/java/org/mozilla/geckoview/test/LoginStorageDelegateTest.kt index dc96de5bb5bd..449fa0c13534 100644 --- a/mobile/android/geckoview/src/androidTest/java/org/mozilla/geckoview/test/LoginStorageDelegateTest.kt +++ b/mobile/android/geckoview/src/androidTest/java/org/mozilla/geckoview/test/LoginStorageDelegateTest.kt @@ -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>? { 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() + + 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(savedLogin) + + sessionRule.addExternalDelegateUntilTestEnd( + LoginStorage.Delegate::class, register, unregister, + object : LoginStorage.Delegate { + @AssertCalled + override fun onLoginFetch(domain: String) + : GeckoResult>? { + 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? { + return null + } + }) + + mainSession.loadTestPath(FORMS3_HTML_PATH) + mainSession.waitForPageStop() + mainSession.evaluateJS("document.querySelector('#form1').submit()") + + sessionRule.waitForResult(usedHandled) + } }