[iOS TextInputPlugin] fix autofill assert (flutter/engine#26711)
This commit is contained in:
@@ -1371,8 +1371,11 @@ static FlutterAutofillType autofillTypeOf(NSDictionary* configuration) {
|
|||||||
_autofillContext = [[NSMutableDictionary alloc] init];
|
_autofillContext = [[NSMutableDictionary alloc] init];
|
||||||
_inputHider = [[FlutterTextInputViewAccessibilityHider alloc] init];
|
_inputHider = [[FlutterTextInputViewAccessibilityHider alloc] init];
|
||||||
// Initialize activeView with a dummy view to keep tests
|
// Initialize activeView with a dummy view to keep tests
|
||||||
// passing.
|
// passing. This dummy view needs to be replace once the
|
||||||
|
// framework initializes an input connection, and thus
|
||||||
|
// should never have access to the textInputDelegate.
|
||||||
_activeView = [[FlutterTextInputView alloc] init];
|
_activeView = [[FlutterTextInputView alloc] init];
|
||||||
|
[_activeView decommission];
|
||||||
}
|
}
|
||||||
|
|
||||||
return self;
|
return self;
|
||||||
@@ -1383,6 +1386,9 @@ static FlutterAutofillType autofillTypeOf(NSDictionary* configuration) {
|
|||||||
_activeView.textInputDelegate = nil;
|
_activeView.textInputDelegate = nil;
|
||||||
[_activeView release];
|
[_activeView release];
|
||||||
[_inputHider release];
|
[_inputHider release];
|
||||||
|
for (FlutterTextInputView* autofillView in _autofillContext.allValues) {
|
||||||
|
autofillView.textInputDelegate = nil;
|
||||||
|
}
|
||||||
[_autofillContext release];
|
[_autofillContext release];
|
||||||
[super dealloc];
|
[super dealloc];
|
||||||
}
|
}
|
||||||
@@ -1477,13 +1483,12 @@ static FlutterAutofillType autofillTypeOf(NSDictionary* configuration) {
|
|||||||
[self removeEnableFlutterTextInputViewAccessibilityTimer];
|
[self removeEnableFlutterTextInputViewAccessibilityTimer];
|
||||||
_activeView.accessibilityEnabled = NO;
|
_activeView.accessibilityEnabled = NO;
|
||||||
[_activeView resignFirstResponder];
|
[_activeView resignFirstResponder];
|
||||||
[_activeView decommission];
|
|
||||||
[_activeView removeFromSuperview];
|
[_activeView removeFromSuperview];
|
||||||
[_inputHider removeFromSuperview];
|
[_inputHider removeFromSuperview];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)triggerAutofillSave:(BOOL)saveEntries {
|
- (void)triggerAutofillSave:(BOOL)saveEntries {
|
||||||
[self hideTextInput];
|
[_activeView resignFirstResponder];
|
||||||
|
|
||||||
if (saveEntries) {
|
if (saveEntries) {
|
||||||
// Make all the input fields in the autofill context visible,
|
// Make all the input fields in the autofill context visible,
|
||||||
|
|||||||
@@ -80,6 +80,9 @@ FLUTTER_ASSERT_ARC
|
|||||||
}
|
}
|
||||||
|
|
||||||
- (void)tearDown {
|
- (void)tearDown {
|
||||||
|
for (FlutterTextInputView* autofillView in textInputPlugin.autofillContext.allValues) {
|
||||||
|
autofillView.textInputDelegate = nil;
|
||||||
|
}
|
||||||
[textInputPlugin.autofillContext removeAllObjects];
|
[textInputPlugin.autofillContext removeAllObjects];
|
||||||
[textInputPlugin cleanUpViewHierarchy:YES clearText:YES delayRemoval:NO];
|
[textInputPlugin cleanUpViewHierarchy:YES clearText:YES delayRemoval:NO];
|
||||||
[[[[textInputPlugin textInputView] superview] subviews]
|
[[[[textInputPlugin textInputView] superview] subviews]
|
||||||
@@ -896,6 +899,38 @@ FLUTTER_ASSERT_ARC
|
|||||||
[self commitAutofillContextAndVerify];
|
[self commitAutofillContextAndVerify];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (void)testDecommissionedViewAreNotReusedByAutofill {
|
||||||
|
// Regression test for https://github.com/flutter/flutter/issues/84407.
|
||||||
|
NSMutableDictionary* configuration = self.mutableTemplateCopy;
|
||||||
|
[configuration setValue:@{
|
||||||
|
@"uniqueIdentifier" : @"field1",
|
||||||
|
@"hints" : @[ UITextContentTypePassword ],
|
||||||
|
@"editingValue" : @{@"text" : @""}
|
||||||
|
}
|
||||||
|
forKey:@"autofill"];
|
||||||
|
[configuration setValue:@[ [configuration copy] ] forKey:@"fields"];
|
||||||
|
|
||||||
|
[self setClientId:123 configuration:configuration];
|
||||||
|
|
||||||
|
[self setTextInputHide];
|
||||||
|
UIView* previousActiveView = textInputPlugin.activeView;
|
||||||
|
|
||||||
|
[self setClientId:124 configuration:configuration];
|
||||||
|
|
||||||
|
// Make sure the autofillable view is reused.
|
||||||
|
XCTAssertEqual(previousActiveView, textInputPlugin.activeView);
|
||||||
|
XCTAssertNotNil(previousActiveView);
|
||||||
|
// Does not crash.
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)testInitialActiveViewCantAccessTextInputDelegate {
|
||||||
|
textInputPlugin.activeView.textInputDelegate = engine;
|
||||||
|
// Before the framework sends the first text input configuration,
|
||||||
|
// the dummy "activeView" we use should never have access to
|
||||||
|
// its textInputDelegate.
|
||||||
|
XCTAssertNil(textInputPlugin.activeView.textInputDelegate);
|
||||||
|
}
|
||||||
|
|
||||||
#pragma mark - Accessibility - Tests
|
#pragma mark - Accessibility - Tests
|
||||||
|
|
||||||
- (void)testUITextInputAccessibilityNotHiddenWhenShowed {
|
- (void)testUITextInputAccessibilityNotHiddenWhenShowed {
|
||||||
|
|||||||
Reference in New Issue
Block a user