@@ -2119,6 +2119,182 @@ Future<void> testMain() async {
21192119 expect (dormantForms, hasLength (1 ));
21202120 });
21212121
2122+ test ('TextInput.updateConfig preserves active autofill form' , () async {
2123+ final Map <String , dynamic > initialConfig = createFlutterConfig (
2124+ 'text' ,
2125+ autofillHint: 'password' ,
2126+ autofillHintsForFields: < String > ['username' , 'password' ],
2127+ obscureText: true ,
2128+ );
2129+
2130+ final setClient = MethodCall ('TextInput.setClient' , < dynamic > [123 , initialConfig]);
2131+ sendFrameworkMessage (codec.encodeMethodCall (setClient));
2132+
2133+ const setEditingState = MethodCall ('TextInput.setEditingState' , < String , dynamic > {
2134+ 'text' : 'secret' ,
2135+ 'selectionBase' : 6 ,
2136+ 'selectionExtent' : 6 ,
2137+ 'composingBase' : - 1 ,
2138+ 'composingExtent' : - 1 ,
2139+ });
2140+ sendFrameworkMessage (codec.encodeMethodCall (setEditingState));
2141+
2142+ const show = MethodCall ('TextInput.show' );
2143+ sendFrameworkMessage (codec.encodeMethodCall (show));
2144+
2145+ final MethodCall setSizeAndTransform = configureSetSizeAndTransformMethodCall (
2146+ 150 ,
2147+ 50 ,
2148+ Matrix4 .identity ().storage.toList (),
2149+ );
2150+ sendFrameworkMessage (codec.encodeMethodCall (setSizeAndTransform));
2151+
2152+ final DefaultTextEditingStrategy strategy = textEditing! .strategy;
2153+
2154+ expect (strategy.appendedToForm, isTrue);
2155+
2156+ final EngineAutofillForm originalAutofillGroup = strategy.inputConfiguration.autofillGroup! ;
2157+
2158+ final DomHTMLFormElement originalForm = originalAutofillGroup.formElement! ;
2159+
2160+ final DomHTMLElement activeElement = strategy.activeDomElement;
2161+
2162+ expect (originalForm.contains (activeElement), isTrue);
2163+
2164+ // Simulates toggling TextField.obscureText while the autofill-enabled
2165+ // password field remains connected.
2166+ final Map <String , dynamic > updatedConfig = createFlutterConfig (
2167+ 'text' ,
2168+ autofillHint: 'password' ,
2169+ autofillHintsForFields: < String > ['username' , 'password' ],
2170+ );
2171+
2172+ final updateConfig = MethodCall ('TextInput.updateConfig' , updatedConfig);
2173+
2174+ sendFrameworkMessage (codec.encodeMethodCall (updateConfig));
2175+
2176+ final EngineAutofillForm updatedAutofillGroup = strategy.inputConfiguration.autofillGroup! ;
2177+
2178+ // updateConfig must continue using the object that owns the live DOM form.
2179+ expect (identical (updatedAutofillGroup, originalAutofillGroup), isTrue);
2180+
2181+ expect (updatedAutofillGroup.formElement, same (originalForm));
2182+ expect (originalForm.contains (activeElement), isTrue);
2183+
2184+ const clearClient = MethodCall ('TextInput.clearClient' );
2185+ sendFrameworkMessage (codec.encodeMethodCall (clearClient));
2186+
2187+ // The form must go dormant rather than having the focused DOM element
2188+ // removed through the non-autofill path.
2189+ expect (dormantForms, hasLength (1 ));
2190+ expect (dormantForms.values.single.formElement, same (originalForm));
2191+ expect (originalForm.isConnected, isTrue);
2192+ });
2193+
2194+ test ('TextInput.updateConfig preserves active single-field autofill form' , () async {
2195+ final Map <String , dynamic > initialConfig = createFlutterConfig (
2196+ 'text' ,
2197+ autofillHint: 'password' ,
2198+ obscureText: true ,
2199+ );
2200+
2201+ final setClient = MethodCall ('TextInput.setClient' , < dynamic > [123 , initialConfig]);
2202+ sendFrameworkMessage (codec.encodeMethodCall (setClient));
2203+
2204+ const show = MethodCall ('TextInput.show' );
2205+ sendFrameworkMessage (codec.encodeMethodCall (show));
2206+
2207+ final MethodCall setSizeAndTransform = configureSetSizeAndTransformMethodCall (
2208+ 150 ,
2209+ 50 ,
2210+ Matrix4 .identity ().storage.toList (),
2211+ );
2212+ sendFrameworkMessage (codec.encodeMethodCall (setSizeAndTransform));
2213+
2214+ final DefaultTextEditingStrategy strategy = textEditing! .strategy;
2215+
2216+ expect (strategy.appendedToForm, isTrue);
2217+
2218+ final EngineAutofillForm originalAutofillGroup = strategy.inputConfiguration.autofillGroup! ;
2219+ final DomHTMLFormElement originalForm = originalAutofillGroup.formElement! ;
2220+
2221+ final Map <String , dynamic > updatedConfig = createFlutterConfig (
2222+ 'text' ,
2223+ autofillHint: 'password' ,
2224+ );
2225+
2226+ final updateConfig = MethodCall ('TextInput.updateConfig' , updatedConfig);
2227+ sendFrameworkMessage (codec.encodeMethodCall (updateConfig));
2228+
2229+ final EngineAutofillForm updatedAutofillGroup = strategy.inputConfiguration.autofillGroup! ;
2230+ expect (identical (updatedAutofillGroup, originalAutofillGroup), isTrue);
2231+ expect (updatedAutofillGroup.formElement, same (originalForm));
2232+
2233+ const clearClient = MethodCall ('TextInput.clearClient' );
2234+ sendFrameworkMessage (codec.encodeMethodCall (clearClient));
2235+
2236+ expect (dormantForms, hasLength (1 ));
2237+ expect (dormantForms.values.single.formElement, same (originalForm));
2238+ expect (originalForm.isConnected, isTrue);
2239+ });
2240+
2241+ test ('autofill form remains reusable after TextInput.updateConfig' , () async {
2242+ final Map <String , dynamic > config = createFlutterConfig (
2243+ 'text' ,
2244+ autofillHint: 'password' ,
2245+ autofillHintsForFields: < String > ['username' , 'password' ],
2246+ obscureText: true ,
2247+ );
2248+
2249+ sendFrameworkMessage (
2250+ codec.encodeMethodCall (MethodCall ('TextInput.setClient' , < dynamic > [123 , config])),
2251+ );
2252+
2253+ sendFrameworkMessage (codec.encodeMethodCall (const MethodCall ('TextInput.show' )));
2254+
2255+ sendFrameworkMessage (
2256+ codec.encodeMethodCall (
2257+ configureSetSizeAndTransformMethodCall (100 , 40 , Matrix4 .identity ().storage.toList ()),
2258+ ),
2259+ );
2260+
2261+ final DomHTMLFormElement originalForm = textEditing! .strategy.focusedFormElement! ;
2262+
2263+ final Map <String , dynamic > visiblePasswordConfig = createFlutterConfig (
2264+ 'text' ,
2265+ autofillHint: 'password' ,
2266+ autofillHintsForFields: < String > ['username' , 'password' ],
2267+ );
2268+
2269+ sendFrameworkMessage (
2270+ codec.encodeMethodCall (MethodCall ('TextInput.updateConfig' , visiblePasswordConfig)),
2271+ );
2272+
2273+ sendFrameworkMessage (codec.encodeMethodCall (const MethodCall ('TextInput.clearClient' )));
2274+
2275+ expect (dormantForms, hasLength (1 ));
2276+ expect (dormantForms.values.single.formElement, same (originalForm));
2277+
2278+ // Reconnect to the same autofill field.
2279+ sendFrameworkMessage (
2280+ codec.encodeMethodCall (
2281+ MethodCall ('TextInput.setClient' , < dynamic > [124 , visiblePasswordConfig]),
2282+ ),
2283+ );
2284+
2285+ sendFrameworkMessage (codec.encodeMethodCall (const MethodCall ('TextInput.show' )));
2286+
2287+ sendFrameworkMessage (
2288+ codec.encodeMethodCall (
2289+ configureSetSizeAndTransformMethodCall (100 , 40 , Matrix4 .identity ().storage.toList ()),
2290+ ),
2291+ );
2292+
2293+ expect (textEditing! .strategy.focusedFormElement, same (originalForm));
2294+
2295+ expect (originalForm.contains (textEditing! .strategy.activeDomElement), isTrue);
2296+ });
2297+
21222298 test ('No capitalization: setClient, setEditingState, show' , () {
21232299 final Map <String , dynamic > noCapitalizationConfig = createFlutterConfig ('text' );
21242300 final setClient = MethodCall ('TextInput.setClient' , < dynamic > [123 , noCapitalizationConfig]);
0 commit comments