@@ -29,6 +29,15 @@ + (void)respondFalseForSendEvent:(const FlutterKeyEvent&)event
29
29
30
30
namespace {
31
31
32
+ // Returns an engine configured for the test fixture resource configuration.
33
+ FlutterEngine* CreateTestEngine () {
34
+ NSString * fixtures = @(testing::GetFixturesPath ());
35
+ FlutterDartProject* project = [[FlutterDartProject alloc ]
36
+ initWithAssetsPath: fixtures
37
+ ICUDataPath: [fixtures stringByAppendingString: @" /icudtl.dat" ]];
38
+ return [[FlutterEngine alloc ] initWithName: @" test" project: project allowHeadlessExecution: true ];
39
+ }
40
+
32
41
NSResponder * mockResponder () {
33
42
NSResponder * mock = OCMStrictClassMock ([NSResponder class ]);
34
43
OCMStub ([mock keyDown: [OCMArg any ]]).andDo (nil );
@@ -98,6 +107,39 @@ + (void)respondFalseForSendEvent:(const FlutterKeyEvent&)event
98
107
EXPECT_EQ (accessibilityChildren[0 ], viewControllerMock.flutterView );
99
108
}
100
109
110
+ TEST (FlutterViewController,
111
+ MakesFlutterViewFirstResponderWhenAccessibilityIsTurnedOffAndTextInputPluginIsFirstResponder) {
112
+ FlutterEngine* engine = CreateTestEngine ();
113
+ NSString * fixtures = @(testing::GetFixturesPath ());
114
+ FlutterDartProject* project = [[FlutterDartProject alloc ]
115
+ initWithAssetsPath: fixtures
116
+ ICUDataPath: [fixtures stringByAppendingString: @" /icudtl.dat" ]];
117
+ FlutterViewController* viewController = [[FlutterViewController alloc ] initWithProject: project];
118
+ [viewController loadView ];
119
+ [engine setViewController: viewController];
120
+ // Creates a NSWindow so that sub view can be first responder.
121
+ NSWindow * window = [[NSWindow alloc ] initWithContentRect: NSMakeRect (0 , 0 , 800 , 600 )
122
+ styleMask: NSBorderlessWindowMask
123
+ backing: NSBackingStoreBuffered
124
+ defer: NO ];
125
+ window.contentView = viewController.view ;
126
+ // Attaches FlutterTextInputPlugin to the view;
127
+ [viewController.view addSubview: viewController.textInputPlugin];
128
+ // Makes sure the textInputPlugin can be the first responder.
129
+ EXPECT_TRUE ([window makeFirstResponder: viewController.textInputPlugin]);
130
+ EXPECT_EQ ([window firstResponder ], viewController.textInputPlugin );
131
+ // Sends a notification to turn off the accessibility.
132
+ NSDictionary * userInfo = @{
133
+ @" AXEnhancedUserInterface" : @(NO ),
134
+ };
135
+ NSNotification * accessibilityOff = [NSNotification notificationWithName: @" "
136
+ object: nil
137
+ userInfo: userInfo];
138
+ [viewController onAccessibilityStatusChanged: accessibilityOff];
139
+ // FlutterView becomes the first responder.
140
+ EXPECT_EQ ([window firstResponder ], viewController.flutterView );
141
+ }
142
+
101
143
TEST (FlutterViewControllerTest, TestKeyEventsAreSentToFramework) {
102
144
ASSERT_TRUE ([[FlutterViewControllerTestObjC alloc ] testKeyEventsAreSentToFramework ]);
103
145
}
0 commit comments