Bug 1610353 - [3.0] Add Login Storage onLoginUsed test. r=geckoview-reviewers,snorp
authorEugen Sawin <esawin@mozilla.com>
Thu, 23 Jan 2020 20:03:57 +0000
changeset 511530 282778a58d0b3b676d77a56235259514e074d959
parent 511529 1152d253beb2046e3d829899d79ce5f00f9dfe64
child 511531 d0a06daef257a64e1c761035784e623106d5cbb4
push id37049
push userrmaries@mozilla.com
push dateFri, 24 Jan 2020 03:50:24 +0000
treeherdermozilla-central@e05793f68994 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersgeckoview-reviewers, snorp
bugs1610353
milestone74.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 1610353 - [3.0] Add Login Storage onLoginUsed test. r=geckoview-reviewers,snorp Differential Revision: https://phabricator.services.mozilla.com/D60442
mobile/android/geckoview/src/androidTest/java/org/mozilla/geckoview/test/LoginStorageDelegateTest.kt
--- 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
@@ -14,33 +14,34 @@ import org.junit.Test
 import org.junit.runner.RunWith
 
 import org.mozilla.geckoview.GeckoResult
 import org.mozilla.geckoview.GeckoSession
 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
 
 
 @RunWith(AndroidJUnit4::class)
 @MediumTest
 class LoginStorageDelegateTest : BaseSessionTest() {
 
     @Test
     fun fetchLogins() {
         sessionRule.setPrefsUntilTestEnd(mapOf(
                 // Enable login management since it's disabled in automation.
                 "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
         }
         val unregister = { _: LoginStorage.Delegate ->
             runtime.loginStorageDelegate = null
         }
 
         val fetchHandled = GeckoResult<Void>()
@@ -48,34 +49,34 @@ class LoginStorageDelegateTest : BaseSes
         sessionRule.addExternalDelegateDuringNextWait(
                 LoginStorage.Delegate::class, register, unregister,
                 object : LoginStorage.Delegate {
             @AssertCalled(count = 1)
             override fun onLoginFetch(domain: String)
                     : GeckoResult<Array<LoginEntry>>? {
                 assertThat("Domain should match", domain, equalTo("localhost"))
 
-                fetchHandled.complete(null);
+                fetchHandled.complete(null)
                 return null
             }
         })
 
         mainSession.loadTestPath(FORMS3_HTML_PATH)
         sessionRule.waitForResult(fetchHandled)
     }
 
     @Test
     fun loginSaveDismiss() {
         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 runtime = sessionRule.runtime
         val register = { delegate: LoginStorage.Delegate ->
             runtime.loginStorageDelegate = delegate
         }
         val unregister = { _: LoginStorage.Delegate ->
             runtime.loginStorageDelegate = null
         }
 
         sessionRule.addExternalDelegateDuringNextWait(
@@ -139,17 +140,17 @@ class LoginStorageDelegateTest : BaseSes
     @Test
     fun loginSaveAccept() {
         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 runtime = sessionRule.runtime
         val register = { delegate: LoginStorage.Delegate ->
             runtime.loginStorageDelegate = delegate
         }
         val unregister = { _: LoginStorage.Delegate ->
             runtime.loginStorageDelegate = null
         }
 
         mainSession.loadTestPath(FORMS3_HTML_PATH)
@@ -219,17 +220,17 @@ class LoginStorageDelegateTest : BaseSes
     @Test
     fun loginSaveModifyAccept() {
         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 runtime = sessionRule.runtime
         val register = { delegate: LoginStorage.Delegate ->
             runtime.loginStorageDelegate = delegate
         }
         val unregister = { _: LoginStorage.Delegate ->
             runtime.loginStorageDelegate = null
         }
 
         mainSession.loadTestPath(FORMS3_HTML_PATH)
@@ -307,17 +308,17 @@ class LoginStorageDelegateTest : BaseSes
     @Test
     fun loginUpdateAccept() {
         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 runtime = sessionRule.runtime
         val register = { delegate: LoginStorage.Delegate ->
             runtime.loginStorageDelegate = delegate
         }
         val unregister = { _: LoginStorage.Delegate ->
             runtime.loginStorageDelegate = null
         }
 
         val saveHandled = GeckoResult<Void>()
@@ -418,9 +419,94 @@ class LoginStorageDelegateTest : BaseSes
         val session2 = sessionRule.createOpenSession()
         session2.loadTestPath(FORMS3_HTML_PATH)
         session2.waitForPageStop()
         session2.evaluateJS("document.querySelector('#pass1').value = '$pass2'")
         session2.evaluateJS("document.querySelector('#form1').submit()")
 
         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)
+    }
 }