Bug 1577005 - [2.4] Add autofill commit tests. r=snorp
authorEugen Sawin <esawin@me73.com>
Fri, 15 Nov 2019 15:48:52 +0000
changeset 502190 56bf24c7a31a61e9c339661963d0d7c8eab098bc
parent 502189 741f4a9a2f642a96907b6a56a9dfc2936f7dea75
child 502191 a69b9ff498cd1774ac76af6071e2022a3ea742e5
push id114172
push userdluca@mozilla.com
push dateTue, 19 Nov 2019 11:31:10 +0000
treeherdermozilla-inbound@b5c5ba07d3db [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssnorp
bugs1577005
milestone72.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 1577005 - [2.4] Add autofill commit tests. r=snorp Differential Revision: https://phabricator.services.mozilla.com/D51186
mobile/android/geckoview/src/androidTest/assets/www/forms.html
mobile/android/geckoview/src/androidTest/java/org/mozilla/geckoview/test/AutofillDelegateTest.kt
--- a/mobile/android/geckoview/src/androidTest/assets/www/forms.html
+++ b/mobile/android/geckoview/src/androidTest/assets/www/forms.html
@@ -1,20 +1,21 @@
 <html>
     <head>
         <title>Forms</title>
         <meta name="viewport" content="minimum-scale=1,width=device-width">
     </head>
     <body>
-        <form>
+        <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="hidden" id="hidden1" value="foo"/>
 
         <iframe id="iframe"></iframe>
--- a/mobile/android/geckoview/src/androidTest/java/org/mozilla/geckoview/test/AutofillDelegateTest.kt
+++ b/mobile/android/geckoview/src/androidTest/java/org/mozilla/geckoview/test/AutofillDelegateTest.kt
@@ -25,16 +25,78 @@ import org.mozilla.geckoview.test.rule.G
 import org.mozilla.geckoview.test.rule.GeckoSessionTestRule.WithDisplay
 import org.mozilla.geckoview.test.util.Callbacks
 
 
 @RunWith(AndroidJUnit4::class)
 @MediumTest
 class AutofillDelegateTest : BaseSessionTest() {
 
+    @Test fun autofillCommit() {
+        sessionRule.setPrefsUntilTestEnd(mapOf("signon.rememberSignons" to true))
+
+        mainSession.loadTestPath(FORMS_HTML_PATH)
+        // Wait for the auto-fill nodes to populate.
+        sessionRule.waitUntilCalled(object : Callbacks.AutofillDelegate {
+            // For the root document and the iframe document, each has a form group and
+            // a group for inputs outside of forms, so the total count is 4.
+            @AssertCalled(count = 4)
+            override fun onAutofill(session: GeckoSession,
+                                    notification: Int,
+                                    node: Autofill.Node?) {
+                assertThat("Should be starting auto-fill",
+                           notification,
+                           equalTo(forEachCall(
+                              Autofill.Notify.SESSION_STARTED,
+                              Autofill.Notify.NODE_ADDED)))
+            }
+        })
+
+        // Assign node values.
+        mainSession.evaluateJS("document.querySelector('#user1').value = 'user1x'")
+        mainSession.evaluateJS("document.querySelector('#pass1').value = 'pass1x'")
+        mainSession.evaluateJS("document.querySelector('#email1').value = 'e@mail.com'")
+        mainSession.evaluateJS("document.querySelector('#number1').value = '1'")
+
+        // Submit the session.
+        mainSession.evaluateJS("document.querySelector('#form1').submit()")
+
+        sessionRule.waitUntilCalled(object : Callbacks.AutofillDelegate {
+            @AssertCalled(count = 5)
+            override fun onAutofill(session: GeckoSession,
+                                    notification: Int,
+                                    node: Autofill.Node?) {
+                val info = sessionRule.currentCall
+
+                if (info.counter < 5) {
+                    assertThat("Should be an update notification",
+                               notification,
+                               equalTo(Autofill.Notify.NODE_UPDATED))
+                } else {
+                    assertThat("Should be a commit notification",
+                               notification,
+                               equalTo(Autofill.Notify.SESSION_COMMITTED))
+
+                    assertThat("Values should match",
+                               countAutofillNodes({ it.value == "user1x" }),
+                               equalTo(1))
+                    assertThat("Values should match",
+                               countAutofillNodes({ it.value == "pass1x" }),
+                               equalTo(1))
+                    assertThat("Values should match",
+                               countAutofillNodes({ it.value == "e@mail.com" }),
+                               equalTo(1))
+                    assertThat("Values should match",
+                               countAutofillNodes({ it.value == "1" }),
+                               equalTo(1))
+                }
+            }
+        })
+    }
+
     @Test fun autofill() {
         // Test parts of the Oreo auto-fill API; there is another autofill test in
         // SessionAccessibility for a11y auto-fill support.
         mainSession.loadTestPath(FORMS_HTML_PATH)
         // Wait for the auto-fill nodes to populate.
         sessionRule.waitUntilCalled(object : Callbacks.AutofillDelegate {
             // For the root document and the iframe document, each has a form group and
             // a group for inputs outside of forms, so the total count is 4.