Flutter macOS Embedder
FlutterInputPluginTestObjc Class Reference
Inheritance diagram for FlutterInputPluginTestObjc:

Instance Methods

(bool) - testEmptyCompositionRange
 
(bool) - testClearClientDuringComposing
 

Detailed Description

Definition at line 52 of file FlutterTextInputPluginTest.mm.

Method Documentation

◆ testClearClientDuringComposing

- (bool) testClearClientDuringComposing

Definition at line 299 of file FlutterTextInputPluginTest.mm.

299  {
300  // Set up FlutterTextInputPlugin.
301  id engineMock = flutter::testing::CreateMockFlutterEngine(@"");
302  id binaryMessengerMock = OCMProtocolMock(@protocol(FlutterBinaryMessenger));
303  OCMStub( // NOLINT(google-objc-avoid-throwing-exception)
304  [engineMock binaryMessenger])
305  .andReturn(binaryMessengerMock);
306  FlutterViewController* viewController = [[FlutterViewController alloc] initWithEngine:engineMock
307  nibName:@""
308  bundle:nil];
309  FlutterTextInputPlugin* plugin =
310  [[FlutterTextInputPlugin alloc] initWithViewController:viewController];
311 
312  // Set input client 1.
313  NSDictionary* setClientConfig = @{
314  @"inputAction" : @"action",
315  @"inputType" : @{@"name" : @"inputName"},
316  };
317  [plugin handleMethodCall:[FlutterMethodCall methodCallWithMethodName:@"TextInput.setClient"
318  arguments:@[ @(1), setClientConfig ]]
319  result:^(id){
320  }];
321 
322  // Set editing state with an active composing range.
323  [plugin handleMethodCall:[FlutterMethodCall methodCallWithMethodName:@"TextInput.setEditingState"
324  arguments:@{
325  @"text" : @"Text",
326  @"selectionBase" : @(0),
327  @"selectionExtent" : @(0),
328  @"composingBase" : @(0),
329  @"composingExtent" : @(1),
330  }]
331  result:^(id){
332  }];
333 
334  // Verify composing range is (0, 1).
335  NSDictionary* editingState = [plugin editingState];
336  EXPECT_EQ([editingState[@"composingBase"] intValue], 0);
337  EXPECT_EQ([editingState[@"composingExtent"] intValue], 1);
338 
339  // Clear input client.
340  [plugin handleMethodCall:[FlutterMethodCall methodCallWithMethodName:@"TextInput.clearClient"
341  arguments:@[]]
342  result:^(id){
343  }];
344 
345  // Verify composing range is collapsed.
346  editingState = [plugin editingState];
347  EXPECT_EQ([editingState[@"composingBase"] intValue], [editingState[@"composingExtent"] intValue]);
348  return true;
349 }

References flutter::testing::CreateMockFlutterEngine(), FlutterTextInputPlugin::editingState, FlutterTextInputPlugin::handleMethodCall:result:, and FlutterMethodCall::methodCallWithMethodName:arguments:.

◆ testEmptyCompositionRange

- (bool) testEmptyCompositionRange

Definition at line 59 of file FlutterTextInputPluginTest.mm.

59  {
60  id engineMock = flutter::testing::CreateMockFlutterEngine(@"");
61  id binaryMessengerMock = OCMProtocolMock(@protocol(FlutterBinaryMessenger));
62  OCMStub( // NOLINT(google-objc-avoid-throwing-exception)
63  [engineMock binaryMessenger])
64  .andReturn(binaryMessengerMock);
65 
66  FlutterViewController* viewController = [[FlutterViewController alloc] initWithEngine:engineMock
67  nibName:@""
68  bundle:nil];
69 
70  FlutterTextInputPlugin* plugin =
71  [[FlutterTextInputPlugin alloc] initWithViewController:viewController];
72 
73  NSDictionary* setClientConfig = @{
74  @"inputAction" : @"action",
75  @"inputType" : @{@"name" : @"inputName"},
76  };
77  [plugin handleMethodCall:[FlutterMethodCall methodCallWithMethodName:@"TextInput.setClient"
78  arguments:@[ @(1), setClientConfig ]]
79  result:^(id){
80  }];
81 
82  FlutterMethodCall* call = [FlutterMethodCall methodCallWithMethodName:@"TextInput.setEditingState"
83  arguments:@{
84  @"text" : @"Text",
85  @"selectionBase" : @(0),
86  @"selectionExtent" : @(0),
87  @"composingBase" : @(-1),
88  @"composingExtent" : @(-1),
89  }];
90 
91  [plugin handleMethodCall:call
92  result:^(id){
93  }];
94 
95  // Verify editing state was set.
96  NSDictionary* editingState = [plugin editingState];
97  EXPECT_STREQ([editingState[@"text"] UTF8String], "Text");
98  EXPECT_STREQ([editingState[@"selectionAffinity"] UTF8String], "TextAffinity.upstream");
99  EXPECT_FALSE([editingState[@"selectionIsDirectional"] boolValue]);
100  EXPECT_EQ([editingState[@"selectionBase"] intValue], 0);
101  EXPECT_EQ([editingState[@"selectionExtent"] intValue], 0);
102  EXPECT_EQ([editingState[@"composingBase"] intValue], -1);
103  EXPECT_EQ([editingState[@"composingExtent"] intValue], -1);
104  return true;
105 }

References flutter::testing::CreateMockFlutterEngine(), FlutterTextInputPlugin::editingState, FlutterTextInputPlugin::handleMethodCall:result:, and FlutterMethodCall::methodCallWithMethodName:arguments:.


The documentation for this class was generated from the following file:
+[FlutterMethodCall methodCallWithMethodName:arguments:]
instancetype methodCallWithMethodName:arguments:(NSString *method,[arguments] id _Nullable arguments)
-[FlutterTextInputPlugin handleMethodCall:result:]
void handleMethodCall:result:(FlutterMethodCall *call,[result] FlutterResult result)
FlutterViewController
Definition: FlutterViewController.h:62
flutter::testing::CreateMockFlutterEngine
id CreateMockFlutterEngine(NSString *pasteboardString)
Definition: FlutterEngineTestUtils.mm:76
-[FlutterTextInputPlugin editingState]
NSDictionary * editingState()
FlutterMethodCall
Definition: FlutterCodecs.h:220
FlutterTextInputPlugin
Definition: FlutterTextInputPlugin.h:24
FlutterBinaryMessenger-p
Definition: FlutterBinaryMessenger.h:49