mirror of
https://github.com/flutter/flutter.git
synced 2026-02-20 02:29:02 +08:00
[iOS TextInputPlugin] fix autofill assert (flutter/engine#26711)
This commit is contained in:
parent
e933c9ab3e
commit
d2b8e10379
@ -1371,8 +1371,11 @@ static FlutterAutofillType autofillTypeOf(NSDictionary* configuration) {
|
||||
_autofillContext = [[NSMutableDictionary alloc] init];
|
||||
_inputHider = [[FlutterTextInputViewAccessibilityHider alloc] init];
|
||||
// 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 decommission];
|
||||
}
|
||||
|
||||
return self;
|
||||
@ -1383,6 +1386,9 @@ static FlutterAutofillType autofillTypeOf(NSDictionary* configuration) {
|
||||
_activeView.textInputDelegate = nil;
|
||||
[_activeView release];
|
||||
[_inputHider release];
|
||||
for (FlutterTextInputView* autofillView in _autofillContext.allValues) {
|
||||
autofillView.textInputDelegate = nil;
|
||||
}
|
||||
[_autofillContext release];
|
||||
[super dealloc];
|
||||
}
|
||||
@ -1477,13 +1483,12 @@ static FlutterAutofillType autofillTypeOf(NSDictionary* configuration) {
|
||||
[self removeEnableFlutterTextInputViewAccessibilityTimer];
|
||||
_activeView.accessibilityEnabled = NO;
|
||||
[_activeView resignFirstResponder];
|
||||
[_activeView decommission];
|
||||
[_activeView removeFromSuperview];
|
||||
[_inputHider removeFromSuperview];
|
||||
}
|
||||
|
||||
- (void)triggerAutofillSave:(BOOL)saveEntries {
|
||||
[self hideTextInput];
|
||||
[_activeView resignFirstResponder];
|
||||
|
||||
if (saveEntries) {
|
||||
// Make all the input fields in the autofill context visible,
|
||||
|
||||
@ -80,6 +80,9 @@ FLUTTER_ASSERT_ARC
|
||||
}
|
||||
|
||||
- (void)tearDown {
|
||||
for (FlutterTextInputView* autofillView in textInputPlugin.autofillContext.allValues) {
|
||||
autofillView.textInputDelegate = nil;
|
||||
}
|
||||
[textInputPlugin.autofillContext removeAllObjects];
|
||||
[textInputPlugin cleanUpViewHierarchy:YES clearText:YES delayRemoval:NO];
|
||||
[[[[textInputPlugin textInputView] superview] subviews]
|
||||
@ -896,6 +899,38 @@ FLUTTER_ASSERT_ARC
|
||||
[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
|
||||
|
||||
- (void)testUITextInputAccessibilityNotHiddenWhenShowed {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user