Flutter Engine
 
Loading...
Searching...
No Matches
FlutterInputPluginTestObjc Class Reference
Inheritance diagram for FlutterInputPluginTestObjc:

Instance Methods

(bool) - testEmptyCompositionRange
 
(bool) - testClearClientDuringComposing
 

Detailed Description

Definition at line 55 of file FlutterTextInputPluginTest.mm.

Method Documentation

◆ testClearClientDuringComposing

- (bool) testClearClientDuringComposing

Definition at line 70 of file FlutterTextInputPluginTest.mm.

365 {
366 // Set up FlutterTextInputPlugin.
368 id binaryMessengerMock = OCMProtocolMock(@protocol(FlutterBinaryMessenger));
369 OCMStub( // NOLINT(google-objc-avoid-throwing-exception)
370 [engineMock binaryMessenger])
371 .andReturn(binaryMessengerMock);
372 FlutterViewController* viewController = [[FlutterViewController alloc] initWithEngine:engineMock
373 nibName:@""
374 bundle:nil];
376 [[FlutterTextInputPluginTestDelegate alloc] initWithBinaryMessenger:binaryMessengerMock
377 viewController:viewController];
378
379 FlutterTextInputPlugin* plugin = [[FlutterTextInputPlugin alloc] initWithDelegate:delegate];
380
381 // Set input client 1.
382 NSDictionary* setClientConfig = @{
383 @"viewId" : @(kViewId),
384 @"inputAction" : @"action",
385 @"inputType" : @{@"name" : @"inputName"},
386 };
387 [plugin handleMethodCall:[FlutterMethodCall methodCallWithMethodName:@"TextInput.setClient"
388 arguments:@[ @(1), setClientConfig ]]
389 result:^(id){
390 }];
391
392 // Set editing state with an active composing range.
393 [plugin handleMethodCall:[FlutterMethodCall methodCallWithMethodName:@"TextInput.setEditingState"
394 arguments:@{
395 @"text" : @"Text",
396 @"selectionBase" : @(0),
397 @"selectionExtent" : @(0),
398 @"composingBase" : @(0),
399 @"composingExtent" : @(1),
400 }]
401 result:^(id){
402 }];
403
404 // Verify composing range is (0, 1).
405 NSDictionary* editingState = [plugin editingState];
406 EXPECT_EQ([editingState[@"composingBase"] intValue], 0);
407 EXPECT_EQ([editingState[@"composingExtent"] intValue], 1);
408
409 // Clear input client.
410 [plugin handleMethodCall:[FlutterMethodCall methodCallWithMethodName:@"TextInput.clearClient"
411 arguments:@[]]
412 result:^(id){
413 }];
414
415 // Verify composing range is collapsed.
416 editingState = [plugin editingState];
417 EXPECT_EQ([editingState[@"composingBase"] intValue], [editingState[@"composingExtent"] intValue]);
418 return true;
419}
instancetype methodCallWithMethodName:arguments:(NSString *method,[arguments] id _Nullable arguments)
FlutterViewController * viewController
static const FlutterViewIdentifier kViewId
id CreateMockFlutterEngine(NSString *pasteboardString)

References _binaryMessenger, self, and viewController.

◆ testEmptyCompositionRange

- (bool) testEmptyCompositionRange

Definition at line 70 of file FlutterTextInputPluginTest.mm.

109 {
111 id binaryMessengerMock = OCMProtocolMock(@protocol(FlutterBinaryMessenger));
112 OCMStub( // NOLINT(google-objc-avoid-throwing-exception)
113 [engineMock binaryMessenger])
114 .andReturn(binaryMessengerMock);
115
116 FlutterViewController* viewController = [[FlutterViewController alloc] initWithEngine:engineMock
117 nibName:@""
118 bundle:nil];
119
121 [[FlutterTextInputPluginTestDelegate alloc] initWithBinaryMessenger:binaryMessengerMock
122 viewController:viewController];
123
124 FlutterTextInputPlugin* plugin = [[FlutterTextInputPlugin alloc] initWithDelegate:delegate];
125
126 NSDictionary* setClientConfig = @{
127 @"viewId" : @(kViewId),
128 @"inputAction" : @"action",
129 @"inputType" : @{@"name" : @"inputName"},
130 };
131 [plugin handleMethodCall:[FlutterMethodCall methodCallWithMethodName:@"TextInput.setClient"
132 arguments:@[ @(1), setClientConfig ]]
133 result:^(id){
134 }];
135
136 FlutterMethodCall* call = [FlutterMethodCall methodCallWithMethodName:@"TextInput.setEditingState"
137 arguments:@{
138 @"text" : @"Text",
139 @"selectionBase" : @(0),
140 @"selectionExtent" : @(0),
141 @"composingBase" : @(-1),
142 @"composingExtent" : @(-1),
143 }];
144
145 [plugin handleMethodCall:call
146 result:^(id){
147 }];
148
149 // Verify editing state was set.
150 NSDictionary* editingState = [plugin editingState];
151 EXPECT_STREQ([editingState[@"text"] UTF8String], "Text");
152 EXPECT_STREQ([editingState[@"selectionAffinity"] UTF8String], "TextAffinity.upstream");
153 EXPECT_FALSE([editingState[@"selectionIsDirectional"] boolValue]);
154 EXPECT_EQ([editingState[@"selectionBase"] intValue], 0);
155 EXPECT_EQ([editingState[@"selectionExtent"] intValue], 0);
156 EXPECT_EQ([editingState[@"composingBase"] intValue], -1);
157 EXPECT_EQ([editingState[@"composingExtent"] intValue], -1);
158 return true;
159}

The documentation for this class was generated from the following file: