14 #import <OCMock/OCMock.h>
15 #import "flutter/testing/testing.h"
18 #include "flutter/common/constants.h"
21 - (void)setPlatformNode:(
flutter::FlutterTextPlatformNode*)node;
26 @property(nonatomic, nullable, copy) NSString* lastUpdatedString;
27 @property(nonatomic) NSRange lastUpdatedSelection;
33 - (void)updateString:(NSString*)string withSelection:(NSRange)selection {
34 _lastUpdatedString = string;
35 _lastUpdatedSelection = selection;
53 self.view = [[NSView alloc] initWithFrame:NSZeroRect];
54 _flutterViewMock = OCMClassMock([
FlutterView class]);
58 return _flutterViewMock;
69 return [OCMArg checkWithBlock:^BOOL(NSData* message) {
115 if (viewIdentifier ==
kViewId) {
117 }
else if (viewIdentifier == flutter::kFlutterImplicitViewId) {
132 [engineMock binaryMessenger])
133 .andReturn(binaryMessengerMock);
141 viewController:viewController];
145 NSDictionary* setClientConfig = @{
147 @"inputAction" :
@"action",
148 @"inputType" : @{
@"name" :
@"inputName"},
158 @"selectionBase" : @(0),
159 @"selectionExtent" : @(0),
160 @"composingBase" : @(-1),
161 @"composingExtent" : @(-1),
170 EXPECT_STREQ([editingState[
@"text"] UTF8String],
"Text");
171 EXPECT_STREQ([editingState[
@"selectionAffinity"] UTF8String],
"TextAffinity.upstream");
172 EXPECT_FALSE([editingState[
@"selectionIsDirectional"] boolValue]);
173 EXPECT_EQ([editingState[
@"selectionBase"] intValue], 0);
174 EXPECT_EQ([editingState[
@"selectionExtent"] intValue], 0);
175 EXPECT_EQ([editingState[
@"composingBase"] intValue], -1);
176 EXPECT_EQ([editingState[
@"composingExtent"] intValue], -1);
180 - (bool)testSetMarkedTextWithSelectionChange {
184 [engineMock binaryMessenger])
185 .andReturn(binaryMessengerMock);
193 viewController:viewController];
197 NSDictionary* setClientConfig = @{
199 @"inputAction" :
@"action",
200 @"inputType" : @{
@"name" :
@"inputName"},
210 @"selectionBase" : @(4),
211 @"selectionExtent" : @(4),
212 @"composingBase" : @(-1),
213 @"composingExtent" : @(-1),
219 [plugin setMarkedText:@"marked"
220 selectedRange:NSMakeRange(1, 0)
221 replacementRange:NSMakeRange(NSNotFound, 0)];
223 NSDictionary* expectedState = @{
224 @"selectionBase" : @(5),
225 @"selectionExtent" : @(5),
226 @"selectionAffinity" :
@"TextAffinity.upstream",
227 @"selectionIsDirectional" : @(NO),
228 @"composingBase" : @(4),
229 @"composingExtent" : @(10),
230 @"text" :
@"Textmarked",
239 [binaryMessengerMock sendOnChannel:
@"flutter/textinput"
244 [binaryMessengerMock sendOnChannel:
@"flutter/textinput"
252 - (bool)testSetMarkedTextWithReplacementRange {
256 [engineMock binaryMessenger])
257 .andReturn(binaryMessengerMock);
265 viewController:viewController];
269 NSDictionary* setClientConfig = @{
271 @"inputAction" :
@"action",
272 @"inputType" : @{
@"name" :
@"inputName"},
282 @"selectionBase" : @(3),
283 @"selectionExtent" : @(3),
284 @"composingBase" : @(-1),
285 @"composingExtent" : @(-1),
291 [plugin setMarkedText:@"marked"
292 selectedRange:NSMakeRange(1, 0)
293 replacementRange:NSMakeRange(1, 2)];
295 NSDictionary* expectedState = @{
296 @"selectionBase" : @(2),
297 @"selectionExtent" : @(2),
298 @"selectionAffinity" :
@"TextAffinity.upstream",
299 @"selectionIsDirectional" : @(NO),
300 @"composingBase" : @(1),
301 @"composingExtent" : @(7),
302 @"text" :
@"1marked4",
311 [binaryMessengerMock sendOnChannel:
@"flutter/textinput"
316 [binaryMessengerMock sendOnChannel:
@"flutter/textinput"
324 - (bool)testSetMarkedTextWithSelectedRangeNotFound {
328 [engineMock binaryMessenger])
329 .andReturn(binaryMessengerMock);
337 viewController:viewController];
341 NSDictionary* setClientConfig = @{
343 @"inputAction" :
@"action",
344 @"inputType" : @{
@"name" :
@"inputName"},
354 @"selectionBase" : @(4),
355 @"selectionExtent" : @(4),
356 @"composingBase" : @(-1),
357 @"composingExtent" : @(-1),
363 [plugin setMarkedText:@"marked"
364 selectedRange:NSMakeRange(1, 0)
365 replacementRange:NSMakeRange(NSNotFound, 0)];
371 [plugin setMarkedText:@""
372 selectedRange:NSMakeRange(NSNotFound, 0)
373 replacementRange:NSMakeRange(NSNotFound, 0)];
374 [plugin setMarkedText:@"n"
375 selectedRange:NSMakeRange(NSNotFound, 0)
376 replacementRange:NSMakeRange(NSNotFound, 0)];
380 EXPECT_STREQ([editingState[
@"text"] UTF8String],
"Textn");
381 EXPECT_EQ([editingState[
@"selectionBase"] intValue], 5);
382 EXPECT_EQ([editingState[
@"selectionExtent"] intValue], 5);
383 EXPECT_EQ([editingState[
@"composingBase"] intValue], 4);
384 EXPECT_EQ([editingState[
@"composingExtent"] intValue], 5);
388 - (bool)testSetMarkedTextWithOutOfBoundsRanges {
392 [engineMock binaryMessenger])
393 .andReturn(binaryMessengerMock);
401 viewController:viewController];
405 NSDictionary* setClientConfig = @{
407 @"inputAction" :
@"action",
408 @"inputType" : @{
@"name" :
@"inputName"},
418 @"selectionBase" : @(3),
419 @"selectionExtent" : @(3),
420 @"composingBase" : @(-1),
421 @"composingExtent" : @(-1),
430 [plugin setMarkedText:@"marked"
431 selectedRange:NSMakeRange(100, 20)
432 replacementRange:NSMakeRange(10, 2)];
435 EXPECT_STREQ([editingState[
@"text"] UTF8String],
"1234marked");
436 EXPECT_EQ([editingState[
@"selectionBase"] intValue], 10);
437 EXPECT_EQ([editingState[
@"selectionExtent"] intValue], 10);
438 EXPECT_EQ([editingState[
@"composingBase"] intValue], 4);
439 EXPECT_EQ([editingState[
@"composingExtent"] intValue], 10);
443 - (bool)testSetEditingStateWithOutOfBoundsSelection {
447 [engineMock binaryMessenger])
448 .andReturn(binaryMessengerMock);
456 viewController:viewController];
460 NSDictionary* setClientConfig = @{
462 @"inputAction" :
@"action",
463 @"inputType" : @{
@"name" :
@"inputName"},
478 @"selectionBase" : @(4),
479 @"selectionExtent" : @(4),
480 @"composingBase" : @(-1),
481 @"composingExtent" : @(-1),
488 EXPECT_STREQ([editingState[
@"text"] UTF8String],
"Te");
489 EXPECT_EQ([editingState[
@"selectionBase"] intValue], 2);
490 EXPECT_EQ([editingState[
@"selectionExtent"] intValue], 2);
492 [plugin setMarkedText:@"m" selectedRange:NSMakeRange(1, 0)];
495 EXPECT_STREQ([editingState[
@"text"] UTF8String],
"Tem");
496 EXPECT_EQ([editingState[
@"selectionBase"] intValue], 3);
497 EXPECT_EQ([editingState[
@"selectionExtent"] intValue], 3);
498 EXPECT_EQ([editingState[
@"composingBase"] intValue], 2);
499 EXPECT_EQ([editingState[
@"composingExtent"] intValue], 3);
503 - (bool)testComposingRegionRemovedByFramework {
507 [engineMock binaryMessenger])
508 .andReturn(binaryMessengerMock);
516 viewController:viewController];
520 NSDictionary* setClientConfig = @{
522 @"inputAction" :
@"action",
523 @"inputType" : @{
@"name" :
@"inputName"},
533 @"selectionBase" : @(4),
534 @"selectionExtent" : @(4),
535 @"composingBase" : @(2),
536 @"composingExtent" : @(4),
546 @"selectionBase" : @(2),
547 @"selectionExtent" : @(2),
548 @"composingBase" : @(-1),
549 @"composingExtent" : @(-1),
557 EXPECT_STREQ([editingState[
@"text"] UTF8String],
"Te");
558 EXPECT_STREQ([editingState[
@"selectionAffinity"] UTF8String],
"TextAffinity.upstream");
559 EXPECT_FALSE([editingState[
@"selectionIsDirectional"] boolValue]);
560 EXPECT_EQ([editingState[
@"selectionBase"] intValue], 2);
561 EXPECT_EQ([editingState[
@"selectionExtent"] intValue], 2);
562 EXPECT_EQ([editingState[
@"composingBase"] intValue], -1);
563 EXPECT_EQ([editingState[
@"composingExtent"] intValue], -1);
572 [engineMock binaryMessenger])
573 .andReturn(binaryMessengerMock);
579 viewController:viewController];
584 NSDictionary* setClientConfig = @{
586 @"inputAction" :
@"action",
587 @"inputType" : @{
@"name" :
@"inputName"},
598 @"selectionBase" : @(0),
599 @"selectionExtent" : @(0),
600 @"composingBase" : @(0),
601 @"composingExtent" : @(1),
608 EXPECT_EQ([editingState[
@"composingBase"] intValue], 0);
609 EXPECT_EQ([editingState[
@"composingExtent"] intValue], 1);
619 EXPECT_EQ([editingState[
@"composingBase"] intValue], [editingState[
@"composingExtent"] intValue]);
623 - (bool)testAutocompleteDisabledWhenAutofillNotSet {
628 [engineMock binaryMessenger])
629 .andReturn(binaryMessengerMock);
635 viewController:viewController];
640 NSDictionary* setClientConfig = @{
642 @"inputAction" :
@"action",
643 @"inputType" : @{
@"name" :
@"inputName"},
651 EXPECT_FALSE([plugin isAutomaticTextCompletionEnabled]);
655 - (bool)testAutocompleteEnabledWhenAutofillSet {
660 [engineMock binaryMessenger])
661 .andReturn(binaryMessengerMock);
667 viewController:viewController];
672 NSDictionary* setClientConfig = @{
674 @"inputAction" :
@"action",
675 @"inputType" : @{
@"name" :
@"inputName"},
677 @"uniqueIdentifier" :
@"field1",
678 @"hints" : @[ @"name" ],
679 @"editingValue" : @{
@"text" :
@""},
688 EXPECT_TRUE([plugin isAutomaticTextCompletionEnabled]);
691 if (@available(macOS 11.0, *)) {
692 EXPECT_EQ([plugin contentType], nil);
697 - (bool)testAutocompleteEnabledWhenAutofillSetNoHint {
702 [engineMock binaryMessenger])
703 .andReturn(binaryMessengerMock);
709 viewController:viewController];
714 NSDictionary* setClientConfig = @{
716 @"inputAction" :
@"action",
717 @"inputType" : @{
@"name" :
@"inputName"},
719 @"uniqueIdentifier" :
@"field1",
721 @"editingValue" : @{
@"text" :
@""},
730 EXPECT_TRUE([plugin isAutomaticTextCompletionEnabled]);
734 - (bool)testAutocompleteDisabledWhenObscureTextSet {
739 [engineMock binaryMessenger])
740 .andReturn(binaryMessengerMock);
746 viewController:viewController];
751 NSDictionary* setClientConfig = @{
753 @"inputAction" :
@"action",
754 @"inputType" : @{
@"name" :
@"inputName"},
755 @"obscureText" : @YES,
757 @"uniqueIdentifier" :
@"field1",
758 @"editingValue" : @{
@"text" :
@""},
767 EXPECT_FALSE([plugin isAutomaticTextCompletionEnabled]);
771 - (bool)testAutocompleteDisabledWhenPasswordAutofillSet {
776 [engineMock binaryMessenger])
777 .andReturn(binaryMessengerMock);
783 viewController:viewController];
788 NSDictionary* setClientConfig = @{
790 @"inputAction" :
@"action",
791 @"inputType" : @{
@"name" :
@"inputName"},
793 @"uniqueIdentifier" :
@"field1",
794 @"hints" : @[ @"password" ],
795 @"editingValue" : @{
@"text" :
@""},
804 EXPECT_FALSE([plugin isAutomaticTextCompletionEnabled]);
807 if (@available(macOS 11.0, *)) {
808 EXPECT_EQ([plugin contentType], NSTextContentTypePassword);
813 - (bool)testAutocompleteDisabledWhenAutofillGroupIncludesPassword {
818 [engineMock binaryMessenger])
819 .andReturn(binaryMessengerMock);
825 viewController:viewController];
830 NSDictionary* setClientConfig = @{
832 @"inputAction" :
@"action",
833 @"inputType" : @{
@"name" :
@"inputName"},
836 @"inputAction" : @"action",
837 @"inputType" : @{@"name" : @"inputName"},
839 @"uniqueIdentifier" : @"field1",
840 @"hints" : @[ @"password" ],
841 @"editingValue" : @{@"text" : @""},
845 @"inputAction" : @"action",
846 @"inputType" : @{@"name" : @"inputName"},
848 @"uniqueIdentifier" : @"field2",
849 @"hints" : @[ @"name" ],
850 @"editingValue" : @{@"text" : @""},
861 EXPECT_FALSE([plugin isAutomaticTextCompletionEnabled]);
865 - (bool)testContentTypeWhenAutofillTypeIsUsername {
870 [engineMock binaryMessenger])
871 .andReturn(binaryMessengerMock);
877 viewController:viewController];
882 NSDictionary* setClientConfig = @{
884 @"inputAction" :
@"action",
885 @"inputType" : @{
@"name" :
@"inputName"},
887 @"uniqueIdentifier" :
@"field1",
888 @"hints" : @[ @"name" ],
889 @"editingValue" : @{
@"text" :
@""},
898 EXPECT_FALSE([plugin isAutomaticTextCompletionEnabled]);
901 if (@available(macOS 11.0, *)) {
902 EXPECT_EQ([plugin contentType], NSTextContentTypeUsername);
907 - (bool)testContentTypeWhenAutofillTypeIsOneTimeCode {
912 [engineMock binaryMessenger])
913 .andReturn(binaryMessengerMock);
919 viewController:viewController];
924 NSDictionary* setClientConfig = @{
926 @"inputAction" :
@"action",
927 @"inputType" : @{
@"name" :
@"inputName"},
929 @"uniqueIdentifier" :
@"field1",
930 @"hints" : @[ @"oneTimeCode" ],
931 @"editingValue" : @{
@"text" :
@""},
940 EXPECT_FALSE([plugin isAutomaticTextCompletionEnabled]);
943 if (@available(macOS 11.0, *)) {
944 EXPECT_EQ([plugin contentType], NSTextContentTypeOneTimeCode);
949 - (bool)testFirstRectForCharacterRange {
953 [engineMock binaryMessenger])
954 .andReturn(binaryMessengerMock);
957 [controllerMock loadView];
958 id viewMock = controllerMock.flutterView;
961 .andReturn(NSMakeRect(0, 0, 200, 200));
963 id windowMock = OCMClassMock([NSWindow
class]);
966 .andReturn(windowMock);
969 [viewMock convertRect:NSMakeRect(28, 10, 2, 19) toView:nil])
970 .andReturn(NSMakeRect(28, 10, 2, 19));
973 [windowMock convertRectToScreen:NSMakeRect(28, 10, 2, 19)])
974 .andReturn(NSMakeRect(38, 20, 2, 19));
978 viewController:controllerMock];
982 NSDictionary* setClientConfig = @{
995 @(1.0), @(0.0), @(0.0), @(0.0), @(0.0), @(1.0), @(0.0), @(0.0), @(0.0),
996 @(0.0), @(1.0), @(0.0), @(20.0), @(10.0), @(0.0), @(1.0)
1007 @"height" : @(19.0),
1020 [windowMock convertRectToScreen:NSMakeRect(28, 10, 2, 19)]);
1025 return NSEqualRects(rect, NSMakeRect(38, 20, 2, 19));
1028 - (bool)testFirstRectForCharacterRangeAtInfinity {
1032 [engineMock binaryMessenger])
1033 .andReturn(binaryMessengerMock);
1036 [controllerMock loadView];
1037 id viewMock = controllerMock.flutterView;
1040 .andReturn(NSMakeRect(0, 0, 200, 200));
1042 id windowMock = OCMClassMock([NSWindow
class]);
1045 .andReturn(windowMock);
1049 viewController:controllerMock];
1053 NSDictionary* setClientConfig = @{
1064 @"height" : @(20.0),
1067 @(1.0), @(0.0), @(0.0), @(0.0), @(0.0), @(1.0), @(0.0), @(0.0), @(0.0),
1068 @(0.0), @(1.0), @(0.0), @(20.0), @(10.0), @(0.0), @(0.0)
1070 @"width" : @(400.0),
1079 @"height" : @(19.0),
1090 return NSEqualRects(rect, CGRectZero);
1093 - (bool)testFirstRectForCharacterRangeWithEsotericAffineTransform {
1097 [engineMock binaryMessenger])
1098 .andReturn(binaryMessengerMock);
1101 [controllerMock loadView];
1102 id viewMock = controllerMock.flutterView;
1105 .andReturn(NSMakeRect(0, 0, 200, 200));
1107 id windowMock = OCMClassMock([NSWindow
class]);
1110 .andReturn(windowMock);
1113 [viewMock convertRect:NSMakeRect(-18, 6, 3, 3) toView:nil])
1114 .andReturn(NSMakeRect(-18, 6, 3, 3));
1117 [windowMock convertRectToScreen:NSMakeRect(-18, 6, 3, 3)])
1118 .andReturn(NSMakeRect(-18, 6, 3, 3));
1122 viewController:controllerMock];
1126 NSDictionary* setClientConfig = @{
1137 @"height" : @(20.0),
1142 @(0.0), @(3.0), @(0.0), @(0.0), @(-3.0), @(0.0), @(0.0), @(0.0), @(0.0),
1143 @(0.0), @(3.0), @(0.0), @(-6.0), @(3.0), @(9.0), @(1.0)
1145 @"width" : @(400.0),
1168 [windowMock convertRectToScreen:NSMakeRect(-18, 6, 3, 3)]);
1173 return NSEqualRects(rect, NSMakeRect(-18, 6, 3, 3));
1176 - (bool)testSetEditingStateWithTextEditingDelta {
1180 [engineMock binaryMessenger])
1181 .andReturn(binaryMessengerMock);
1189 viewController:viewController];
1193 NSDictionary* setClientConfig = @{
1195 @"inputAction" :
@"action",
1196 @"enableDeltaModel" :
@"true",
1197 @"inputType" : @{
@"name" :
@"inputName"},
1207 @"selectionBase" : @(0),
1208 @"selectionExtent" : @(0),
1209 @"composingBase" : @(-1),
1210 @"composingExtent" : @(-1),
1219 EXPECT_STREQ([editingState[
@"text"] UTF8String],
"Text");
1220 EXPECT_STREQ([editingState[
@"selectionAffinity"] UTF8String],
"TextAffinity.upstream");
1221 EXPECT_FALSE([editingState[
@"selectionIsDirectional"] boolValue]);
1222 EXPECT_EQ([editingState[
@"selectionBase"] intValue], 0);
1223 EXPECT_EQ([editingState[
@"selectionExtent"] intValue], 0);
1224 EXPECT_EQ([editingState[
@"composingBase"] intValue], -1);
1225 EXPECT_EQ([editingState[
@"composingExtent"] intValue], -1);
1229 - (bool)testOperationsThatTriggerDelta {
1233 [engineMock binaryMessenger])
1234 .andReturn(binaryMessengerMock);
1242 viewController:viewController];
1246 NSDictionary* setClientConfig = @{
1248 @"inputAction" :
@"action",
1249 @"enableDeltaModel" :
@"true",
1250 @"inputType" : @{
@"name" :
@"inputName"},
1256 [plugin insertText:@"text to insert"];
1258 NSDictionary* deltaToFramework = @{
1260 @"deltaText" :
@"text to insert",
1261 @"deltaStart" : @(0),
1263 @"selectionBase" : @(14),
1264 @"selectionExtent" : @(14),
1265 @"selectionAffinity" :
@"TextAffinity.upstream",
1266 @"selectionIsDirectional" : @(
false),
1267 @"composingBase" : @(-1),
1268 @"composingExtent" : @(-1),
1270 NSDictionary* expectedState = @{
1271 @"deltas" : @[ deltaToFramework ],
1281 [binaryMessengerMock sendOnChannel:
@"flutter/textinput"
1287 [plugin setMarkedText:@"marked text" selectedRange:NSMakeRange(0, 1)];
1289 deltaToFramework = @{
1290 @"oldText" :
@"text to insert",
1291 @"deltaText" :
@"marked text",
1292 @"deltaStart" : @(14),
1293 @"deltaEnd" : @(14),
1294 @"selectionBase" : @(14),
1295 @"selectionExtent" : @(15),
1296 @"selectionAffinity" :
@"TextAffinity.upstream",
1297 @"selectionIsDirectional" : @(
false),
1298 @"composingBase" : @(14),
1299 @"composingExtent" : @(25),
1302 @"deltas" : @[ deltaToFramework ],
1312 [binaryMessengerMock sendOnChannel:
@"flutter/textinput"
1318 [plugin unmarkText];
1320 deltaToFramework = @{
1321 @"oldText" :
@"text to insertmarked text",
1323 @"deltaStart" : @(-1),
1324 @"deltaEnd" : @(-1),
1325 @"selectionBase" : @(25),
1326 @"selectionExtent" : @(25),
1327 @"selectionAffinity" :
@"TextAffinity.upstream",
1328 @"selectionIsDirectional" : @(false),
1329 @"composingBase" : @(-1),
1330 @"composingExtent" : @(-1),
1333 @"deltas" : @[ deltaToFramework ],
1343 [binaryMessengerMock sendOnChannel:
@"flutter/textinput"
1351 - (bool)testComposingWithDelta {
1355 [engineMock binaryMessenger])
1356 .andReturn(binaryMessengerMock);
1364 viewController:viewController];
1368 NSDictionary* setClientConfig = @{
1370 @"inputAction" :
@"action",
1371 @"enableDeltaModel" :
@"true",
1372 @"inputType" : @{
@"name" :
@"inputName"},
1378 [plugin setMarkedText:@"m" selectedRange:NSMakeRange(0, 1)];
1380 NSDictionary* deltaToFramework = @{
1382 @"deltaText" :
@"m",
1383 @"deltaStart" : @(0),
1385 @"selectionBase" : @(0),
1386 @"selectionExtent" : @(1),
1387 @"selectionAffinity" :
@"TextAffinity.upstream",
1388 @"selectionIsDirectional" : @(
false),
1389 @"composingBase" : @(0),
1390 @"composingExtent" : @(1),
1392 NSDictionary* expectedState = @{
1393 @"deltas" : @[ deltaToFramework ],
1403 [binaryMessengerMock sendOnChannel:
@"flutter/textinput"
1409 [plugin setMarkedText:@"ma" selectedRange:NSMakeRange(0, 1)];
1411 deltaToFramework = @{
1413 @"deltaText" :
@"ma",
1414 @"deltaStart" : @(0),
1416 @"selectionBase" : @(0),
1417 @"selectionExtent" : @(1),
1418 @"selectionAffinity" :
@"TextAffinity.upstream",
1419 @"selectionIsDirectional" : @(
false),
1420 @"composingBase" : @(0),
1421 @"composingExtent" : @(2),
1424 @"deltas" : @[ deltaToFramework ],
1434 [binaryMessengerMock sendOnChannel:
@"flutter/textinput"
1440 [plugin setMarkedText:@"mar" selectedRange:NSMakeRange(0, 1)];
1442 deltaToFramework = @{
1444 @"deltaText" :
@"mar",
1445 @"deltaStart" : @(0),
1447 @"selectionBase" : @(0),
1448 @"selectionExtent" : @(1),
1449 @"selectionAffinity" :
@"TextAffinity.upstream",
1450 @"selectionIsDirectional" : @(
false),
1451 @"composingBase" : @(0),
1452 @"composingExtent" : @(3),
1455 @"deltas" : @[ deltaToFramework ],
1465 [binaryMessengerMock sendOnChannel:
@"flutter/textinput"
1471 [plugin setMarkedText:@"mark" selectedRange:NSMakeRange(0, 1)];
1473 deltaToFramework = @{
1474 @"oldText" :
@"mar",
1475 @"deltaText" :
@"mark",
1476 @"deltaStart" : @(0),
1478 @"selectionBase" : @(0),
1479 @"selectionExtent" : @(1),
1480 @"selectionAffinity" :
@"TextAffinity.upstream",
1481 @"selectionIsDirectional" : @(
false),
1482 @"composingBase" : @(0),
1483 @"composingExtent" : @(4),
1486 @"deltas" : @[ deltaToFramework ],
1496 [binaryMessengerMock sendOnChannel:
@"flutter/textinput"
1502 [plugin setMarkedText:@"marke" selectedRange:NSMakeRange(0, 1)];
1504 deltaToFramework = @{
1505 @"oldText" :
@"mark",
1506 @"deltaText" :
@"marke",
1507 @"deltaStart" : @(0),
1509 @"selectionBase" : @(0),
1510 @"selectionExtent" : @(1),
1511 @"selectionAffinity" :
@"TextAffinity.upstream",
1512 @"selectionIsDirectional" : @(
false),
1513 @"composingBase" : @(0),
1514 @"composingExtent" : @(5),
1517 @"deltas" : @[ deltaToFramework ],
1527 [binaryMessengerMock sendOnChannel:
@"flutter/textinput"
1533 [plugin setMarkedText:@"marked" selectedRange:NSMakeRange(0, 1)];
1535 deltaToFramework = @{
1536 @"oldText" :
@"marke",
1537 @"deltaText" :
@"marked",
1538 @"deltaStart" : @(0),
1540 @"selectionBase" : @(0),
1541 @"selectionExtent" : @(1),
1542 @"selectionAffinity" :
@"TextAffinity.upstream",
1543 @"selectionIsDirectional" : @(
false),
1544 @"composingBase" : @(0),
1545 @"composingExtent" : @(6),
1548 @"deltas" : @[ deltaToFramework ],
1558 [binaryMessengerMock sendOnChannel:
@"flutter/textinput"
1564 [plugin unmarkText];
1566 deltaToFramework = @{
1567 @"oldText" :
@"marked",
1569 @"deltaStart" : @(-1),
1570 @"deltaEnd" : @(-1),
1571 @"selectionBase" : @(6),
1572 @"selectionExtent" : @(6),
1573 @"selectionAffinity" :
@"TextAffinity.upstream",
1574 @"selectionIsDirectional" : @(false),
1575 @"composingBase" : @(-1),
1576 @"composingExtent" : @(-1),
1579 @"deltas" : @[ deltaToFramework ],
1589 [binaryMessengerMock sendOnChannel:
@"flutter/textinput"
1597 - (bool)testComposingWithDeltasWhenSelectionIsActive {
1601 [engineMock binaryMessenger])
1602 .andReturn(binaryMessengerMock);
1610 viewController:viewController];
1614 NSDictionary* setClientConfig = @{
1616 @"inputAction" :
@"action",
1617 @"enableDeltaModel" :
@"true",
1618 @"inputType" : @{
@"name" :
@"inputName"},
1628 @"selectionBase" : @(0),
1629 @"selectionExtent" : @(4),
1630 @"composingBase" : @(-1),
1631 @"composingExtent" : @(-1),
1637 [plugin setMarkedText:@"~"
1638 selectedRange:NSMakeRange(1, 0)
1639 replacementRange:NSMakeRange(NSNotFound, 0)];
1641 NSDictionary* deltaToFramework = @{
1642 @"oldText" :
@"Text",
1643 @"deltaText" :
@"~",
1644 @"deltaStart" : @(0),
1646 @"selectionBase" : @(1),
1647 @"selectionExtent" : @(1),
1648 @"selectionAffinity" :
@"TextAffinity.upstream",
1649 @"selectionIsDirectional" : @(
false),
1650 @"composingBase" : @(0),
1651 @"composingExtent" : @(1),
1653 NSDictionary* expectedState = @{
1654 @"deltas" : @[ deltaToFramework ],
1664 [binaryMessengerMock sendOnChannel:
@"flutter/textinput"
1672 - (bool)testPerformKeyEquivalent {
1674 __block NSEvent* eventBeingDispatchedByKeyboardManager = nil;
1676 OCMStub([viewControllerMock isDispatchingKeyEvent:[OCMArg any]])
1677 .andDo(^(NSInvocation* invocation) {
1679 [invocation getArgument:(void*)&event atIndex:2];
1680 BOOL result =
event == eventBeingDispatchedByKeyboardManager;
1681 [invocation setReturnValue:&result];
1684 NSEvent*
event = [NSEvent keyEventWithType:NSEventTypeKeyDown
1685 location:NSZeroPoint
1691 charactersIgnoringModifiers:@""
1697 viewController:viewControllerMock];
1701 NSDictionary* setClientConfig = @{
1709 OCMExpect([viewControllerMock keyDown:event]);
1712 if (![plugin performKeyEquivalent:event]) {
1718 [viewControllerMock keyDown:event]);
1725 eventBeingDispatchedByKeyboardManager = event;
1727 OCMReject([viewControllerMock keyDown:event]);
1731 if ([plugin performKeyEquivalent:event]) {
1741 - (bool)handleArrowKeyWhenImePopoverIsActive {
1745 [engineMock binaryMessenger])
1746 .andReturn(binaryMessengerMock);
1747 OCMStub([[engineMock ignoringNonObjectArgs] sendKeyEvent:FlutterKeyEvent {}
1751 NSTextInputContext* textInputContext = OCMClassMock([NSTextInputContext
class]);
1752 OCMStub([textInputContext handleEvent:[OCMArg any]]).andReturn(YES);
1760 viewController:viewController];
1766 NSDictionary* setClientConfig = @{
1768 @"inputAction" :
@"action",
1769 @"enableDeltaModel" :
@"true",
1770 @"inputType" : @{
@"name" :
@"inputName"},
1783 [plugin setMarkedText:@"m"
1784 selectedRange:NSMakeRange(0, 1)
1785 replacementRange:NSMakeRange(NSNotFound, 0)];
1788 NSEvent*
event = [NSEvent keyEventWithType:NSEventTypeKeyDown
1789 location:NSZeroPoint
1790 modifierFlags:0xa00100
1794 characters:@"\uF702"
1795 charactersIgnoringModifiers:@"\uF702"
1800 [plugin performKeyEquivalent:event];
1802 if ([plugin handleKeyEvent:event] !=
true) {
1807 event = [NSEvent keyEventWithType:NSEventTypeKeyDown
1808 location:NSZeroPoint
1809 modifierFlags:0x40101
1813 characters:@"\uF702"
1814 charactersIgnoringModifiers:@"\uF702"
1819 [plugin performKeyEquivalent:event];
1821 if ([plugin handleKeyEvent:event] !=
false) {
1828 - (bool)unhandledKeyEquivalent {
1832 [engineMock binaryMessenger])
1833 .andReturn(binaryMessengerMock);
1841 viewController:viewController];
1845 NSDictionary* setClientConfig = @{
1847 @"inputAction" :
@"action",
1848 @"enableDeltaModel" :
@"true",
1849 @"inputType" : @{
@"name" :
@"inputName"},
1862 NSEvent*
event = [NSEvent keyEventWithType:NSEventTypeKeyDown
1863 location:NSZeroPoint
1864 modifierFlags:0x40101
1869 charactersIgnoringModifiers:@"h"
1874 [plugin performKeyEquivalent:event];
1878 if ([plugin handleKeyEvent:event] !=
true) {
1883 event = [NSEvent keyEventWithType:NSEventTypeKeyDown
1884 location:NSZeroPoint
1885 modifierFlags:0x100108
1890 charactersIgnoringModifiers:@"w"
1895 [plugin performKeyEquivalent:event];
1899 if ([plugin handleKeyEvent:event] !=
false) {
1906 - (bool)testInsertNewLine {
1910 [engineMock binaryMessenger])
1911 .andReturn(binaryMessengerMock);
1912 OCMStub([[engineMock ignoringNonObjectArgs] sendKeyEvent:FlutterKeyEvent {}
1922 viewController:viewController];
1926 NSDictionary* setClientConfig = @{
1928 @"inputType" : @{
@"name" :
@"TextInputType.multiline"},
1929 @"inputAction" :
@"TextInputAction.newline",
1939 @"selectionBase" : @(4),
1940 @"selectionExtent" : @(4),
1941 @"composingBase" : @(-1),
1942 @"composingExtent" : @(-1),
1951 EXPECT_STREQ([editingState[
@"text"] UTF8String],
"Text");
1952 EXPECT_STREQ([editingState[
@"selectionAffinity"] UTF8String],
"TextAffinity.upstream");
1953 EXPECT_FALSE([editingState[
@"selectionIsDirectional"] boolValue]);
1954 EXPECT_EQ([editingState[
@"selectionBase"] intValue], 4);
1955 EXPECT_EQ([editingState[
@"selectionExtent"] intValue], 4);
1956 EXPECT_EQ([editingState[
@"composingBase"] intValue], -1);
1957 EXPECT_EQ([editingState[
@"composingExtent"] intValue], -1);
1959 [plugin doCommandBySelector:@selector(insertNewline:)];
1963 EXPECT_STREQ([editingState[
@"text"] UTF8String],
"Text\n");
1964 EXPECT_STREQ([editingState[
@"selectionAffinity"] UTF8String],
"TextAffinity.upstream");
1965 EXPECT_FALSE([editingState[
@"selectionIsDirectional"] boolValue]);
1966 EXPECT_EQ([editingState[
@"selectionBase"] intValue], 5);
1967 EXPECT_EQ([editingState[
@"selectionExtent"] intValue], 5);
1968 EXPECT_EQ([editingState[
@"composingBase"] intValue], -1);
1969 EXPECT_EQ([editingState[
@"composingExtent"] intValue], -1);
1974 - (bool)testSendActionDoNotInsertNewLine {
1978 [engineMock binaryMessenger])
1979 .andReturn(binaryMessengerMock);
1980 OCMStub([[engineMock ignoringNonObjectArgs] sendKeyEvent:FlutterKeyEvent {}
1990 viewController:viewController];
1994 NSDictionary* setClientConfig = @{
1996 @"inputType" : @{
@"name" :
@"TextInputType.multiline"},
1997 @"inputAction" :
@"TextInputAction.send",
2007 @"selectionBase" : @(4),
2008 @"selectionExtent" : @(4),
2009 @"composingBase" : @(-1),
2010 @"composingExtent" : @(-1),
2013 NSDictionary* expectedState = @{
2014 @"selectionBase" : @(4),
2015 @"selectionExtent" : @(4),
2016 @"selectionAffinity" :
@"TextAffinity.upstream",
2017 @"selectionIsDirectional" : @(NO),
2018 @"composingBase" : @(-1),
2019 @"composingExtent" : @(-1),
2029 [binaryMessengerMock sendOnChannel:
@"flutter/textinput"
2036 [plugin doCommandBySelector:@selector(insertNewline:)];
2041 arguments:@[ @(1), @"TextInputAction.send" ]]];
2046 [binaryMessengerMock sendOnChannel:
@"flutter/textinput"
2052 NSDictionary* updatedState = @{
2053 @"selectionBase" : @(5),
2054 @"selectionExtent" : @(5),
2055 @"selectionAffinity" :
@"TextAffinity.upstream",
2056 @"selectionIsDirectional" : @(NO),
2057 @"composingBase" : @(-1),
2058 @"composingExtent" : @(-1),
2059 @"text" :
@"Text\n",
2070 [binaryMessengerMock sendOnChannel:
@"flutter/textinput"
2080 - (bool)testLocalTextAndSelectionUpdateAfterDelta {
2084 [engineMock binaryMessenger])
2085 .andReturn(binaryMessengerMock);
2093 viewController:viewController];
2097 NSDictionary* setClientConfig = @{
2099 @"inputAction" :
@"action",
2100 @"enableDeltaModel" :
@"true",
2101 @"inputType" : @{
@"name" :
@"inputName"},
2107 [plugin insertText:@"text to insert"];
2109 NSDictionary* deltaToFramework = @{
2111 @"deltaText" :
@"text to insert",
2112 @"deltaStart" : @(0),
2114 @"selectionBase" : @(14),
2115 @"selectionExtent" : @(14),
2116 @"selectionAffinity" :
@"TextAffinity.upstream",
2117 @"selectionIsDirectional" : @(
false),
2118 @"composingBase" : @(-1),
2119 @"composingExtent" : @(-1),
2121 NSDictionary* expectedState = @{
2122 @"deltas" : @[ deltaToFramework ],
2132 [binaryMessengerMock sendOnChannel:
@"flutter/textinput"
2138 bool localTextAndSelectionUpdated = [plugin.string isEqualToString:@"text to insert"] &&
2139 NSEqualRanges(plugin.selectedRange, NSMakeRange(14, 0));
2141 return localTextAndSelectionUpdated;
2144 - (bool)testSelectorsAreForwardedToFramework {
2148 [engineMock binaryMessenger])
2149 .andReturn(binaryMessengerMock);
2157 viewController:viewController];
2161 NSDictionary* setClientConfig = @{
2163 @"inputAction" :
@"action",
2164 @"enableDeltaModel" :
@"true",
2165 @"inputType" : @{
@"name" :
@"inputName"},
2174 NSString* runLoopMode =
@"FlutterTestRunLoopMode";
2178 [plugin doCommandBySelector:@selector(moveUp:)];
2179 [plugin doCommandBySelector:@selector(moveRightAndModifySelection:)];
2181 __block
bool done =
false;
2182 CFRunLoopPerformBlock(CFRunLoopGetMain(), (__bridge CFStringRef)runLoopMode, ^{
2188 CFRunLoopRunInMode((__bridge CFStringRef)runLoopMode, 0,
true);
2195 @(1), @[ @"moveUp:", @"moveRightAndModifySelection:" ]
2200 [binaryMessengerMock sendOnChannel:
@"flutter/textinput"
2209 - (bool)testSelectorsNotForwardedToFrameworkIfNoClient {
2213 [engineMock binaryMessenger])
2214 .andReturn(binaryMessengerMock);
2216 OCMReject([binaryMessengerMock sendOnChannel:
@"flutter/textinput" message:[OCMArg any]]);
2223 viewController:viewController];
2229 NSString* runLoopMode =
@"FlutterTestRunLoopMode";
2233 [plugin doCommandBySelector:@selector(moveUp:)];
2234 [plugin doCommandBySelector:@selector(moveRightAndModifySelection:)];
2236 __block
bool done =
false;
2237 CFRunLoopPerformBlock(CFRunLoopGetMain(), (__bridge CFStringRef)runLoopMode, ^{
2242 CFRunLoopRunInMode((__bridge CFStringRef)runLoopMode, 0,
true);
2248 - (bool)testInsertTextWithCollapsedSelectionInsideComposing {
2251 OCMStub([engineMock binaryMessenger]).andReturn(binaryMessengerMock);
2258 viewController:viewController];
2261 NSDictionary* setClientConfig = @{
2263 @"inputAction" :
@"action",
2264 @"inputType" : @{
@"name" :
@"text"},
2273 @"text" : @"ä »Šæ —¥ã �¯å ®¶ã �«å ¸°ã ‚Šã �¾ã �™",
2274 @"selectionBase" : @(0),
2275 @"selectionExtent" : @(3),
2276 @"composingBase" : @(0),
2277 @"composingExtent" : @(9),
2283 [plugin insertText:@"ä »Šæ —¥ã �¯å ®¶ã �«å ¸°ã ‚Šã �¾ã �™" replacementRange:NSMakeRange(NSNotFound, 0)];
2286 EXPECT_STREQ([editingState[
@"text"] UTF8String],
"今日�家�帰り��");
2287 EXPECT_EQ([editingState[
@"selectionBase"] intValue], 9);
2288 EXPECT_EQ([editingState[
@"selectionExtent"] intValue], 9);
2300 NSString* fixtures = @(testing::GetFixturesPath());
2302 initWithAssetsPath:fixtures
2303 ICUDataPath:[fixtures stringByAppendingString:@"/icudtl.dat"]];
2304 return [[
FlutterEngine alloc] initWithName:@"test" project:project allowHeadlessExecution:true];
2308 TEST(FlutterTextInputPluginTest, TestEmptyCompositionRange) {
2312 TEST(FlutterTextInputPluginTest, TestSetMarkedTextWithSelectionChange) {
2316 TEST(FlutterTextInputPluginTest, TestSetMarkedTextWithReplacementRange) {
2320 TEST(FlutterTextInputPluginTest, TestSetMarkedTextWithSelectedRangeNotFound) {
2324 TEST(FlutterTextInputPluginTest, TestSetMarkedTextWithOutOfBoundsRanges) {
2328 TEST(FlutterTextInputPluginTest, TestSetEditingStateWithOutOfBoundsSelection) {
2332 TEST(FlutterTextInputPluginTest, TestComposingRegionRemovedByFramework) {
2336 TEST(FlutterTextInputPluginTest, TestClearClientDuringComposing) {
2340 TEST(FlutterTextInputPluginTest, TestAutocompleteDisabledWhenAutofillNotSet) {
2344 TEST(FlutterTextInputPluginTest, TestAutocompleteEnabledWhenAutofillSet) {
2348 TEST(FlutterTextInputPluginTest, TestAutocompleteEnabledWhenAutofillSetNoHint) {
2352 TEST(FlutterTextInputPluginTest, TestAutocompleteDisabledWhenObscureTextSet) {
2356 TEST(FlutterTextInputPluginTest, TestAutocompleteDisabledWhenPasswordAutofillSet) {
2360 TEST(FlutterTextInputPluginTest, TestAutocompleteDisabledWhenAutofillGroupIncludesPassword) {
2362 testAutocompleteDisabledWhenAutofillGroupIncludesPassword]);
2365 TEST(FlutterTextInputPluginTest, TestFirstRectForCharacterRange) {
2369 TEST(FlutterTextInputPluginTest, TestFirstRectForCharacterRangeAtInfinity) {
2373 TEST(FlutterTextInputPluginTest, TestFirstRectForCharacterRangeWithEsotericAffineTransform) {
2375 testFirstRectForCharacterRangeWithEsotericAffineTransform]);
2378 TEST(FlutterTextInputPluginTest, TestSetEditingStateWithTextEditingDelta) {
2382 TEST(FlutterTextInputPluginTest, TestOperationsThatTriggerDelta) {
2386 TEST(FlutterTextInputPluginTest, TestComposingWithDelta) {
2390 TEST(FlutterTextInputPluginTest, TestComposingWithDeltasWhenSelectionIsActive) {
2394 TEST(FlutterTextInputPluginTest, TestLocalTextAndSelectionUpdateAfterDelta) {
2398 TEST(FlutterTextInputPluginTest, TestPerformKeyEquivalent) {
2402 TEST(FlutterTextInputPluginTest, HandleArrowKeyWhenImePopoverIsActive) {
2406 TEST(FlutterTextInputPluginTest, UnhandledKeyEquivalent) {
2410 TEST(FlutterTextInputPluginTest, TestSelectorsAreForwardedToFramework) {
2414 TEST(FlutterTextInputPluginTest, TestSelectorsNotForwardedToFrameworkIfNoClient) {
2418 TEST(FlutterTextInputPluginTest, TestInsertNewLine) {
2422 TEST(FlutterTextInputPluginTest, TestSendActionDoNotInsertNewLine) {
2426 TEST(FlutterTextInputPluginTest, TestAttributedSubstringOutOfRange) {
2430 [engineMock binaryMessenger])
2431 .andReturn(binaryMessengerMock);
2439 viewController:viewController];
2443 NSDictionary* setClientConfig = @{
2445 @"inputAction" :
@"action",
2446 @"enableDeltaModel" :
@"true",
2447 @"inputType" : @{
@"name" :
@"inputName"},
2457 @"selectionBase" : @(0),
2458 @"selectionExtent" : @(0),
2459 @"composingBase" : @(-1),
2460 @"composingExtent" : @(-1),
2468 NSAttributedString* text = [plugin attributedSubstringForProposedRange:NSMakeRange(1, 10)
2470 EXPECT_TRUE([text.string isEqualToString:
@"ext"]);
2471 EXPECT_EQ(out.location, 1u);
2472 EXPECT_EQ(out.length, 3u);
2474 text = [plugin attributedSubstringForProposedRange:NSMakeRange(4, 10) actualRange:&out];
2475 EXPECT_EQ(text, nil);
2478 TEST(FlutterTextInputPluginTest, CanWorkWithFlutterTextField) {
2483 [viewController loadView];
2485 NSWindow* window = [[NSWindow alloc] initWithContentRect:NSMakeRect(0, 0, 800, 600)
2486 styleMask:NSBorderlessWindowMask
2487 backing:NSBackingStoreBuffered
2489 window.contentView = viewController.view;
2491 engine.semanticsEnabled = YES;
2493 auto bridge = viewController.accessibilityBridge.lock();
2496 ui::AXNode ax_node(&tree,
nullptr, 0, 0);
2497 ui::AXNodeData node_data;
2498 node_data.SetValue(
"initial text");
2499 ax_node.SetData(node_data);
2500 delegate.
Init(viewController.accessibilityBridge, &ax_node);
2506 fieldEditor:engine.textInputPlugin];
2507 [viewController.view addSubview:mockTextField];
2510 NSDictionary* setClientConfig = @{
2511 @"viewId" : @(flutter::kFlutterImplicitViewId),
2512 @"inputAction" :
@"action",
2513 @"inputType" : @{
@"name" :
@"inputName"},
2520 [engine.textInputPlugin handleMethodCall:methodCall result:result];
2522 NSDictionary* arguments = @{
2523 @"text" :
@"new text",
2524 @"selectionBase" : @(1),
2525 @"selectionExtent" : @(2),
2526 @"composingBase" : @(-1),
2527 @"composingExtent" : @(-1),
2531 [engine.textInputPlugin handleMethodCall:methodCall result:result];
2537 [mockTextField setPlatformNode:nil];
2541 [[NSRunLoop currentRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:0.1]];
2544 TEST(FlutterTextInputPluginTest, CanNotBecomeResponderIfNoViewController) {
2549 [viewController loadView];
2551 NSWindow* window = [[NSWindow alloc] initWithContentRect:NSMakeRect(0, 0, 800, 600)
2552 styleMask:NSBorderlessWindowMask
2553 backing:NSBackingStoreBuffered
2555 window.contentView = viewController.view;
2557 engine.semanticsEnabled = YES;
2559 auto bridge = viewController.accessibilityBridge.lock();
2562 ui::AXNode ax_node(&tree,
nullptr, 0, 0);
2563 ui::AXNodeData node_data;
2564 node_data.SetValue(
"initial text");
2565 ax_node.SetData(node_data);
2566 delegate.
Init(viewController.accessibilityBridge, &ax_node);
2570 EXPECT_EQ([textField becomeFirstResponder], YES);
2572 [engine setViewController:nil];
2575 EXPECT_EQ([textField becomeFirstResponder], NO);
2578 TEST(FlutterTextInputPluginTest, IsAddedAndRemovedFromViewHierarchy) {
2583 [viewController loadView];
2585 NSWindow* window = [[NSWindow alloc] initWithContentRect:NSMakeRect(0, 0, 800, 600)
2586 styleMask:NSBorderlessWindowMask
2587 backing:NSBackingStoreBuffered
2589 window.contentView = viewController.view;
2591 ASSERT_EQ(engine.textInputPlugin.superview, nil);
2592 ASSERT_FALSE(window.firstResponder == engine.textInputPlugin);
2594 NSDictionary* setClientConfig = @{
2595 @"viewId" : @(flutter::kFlutterImplicitViewId),
2597 [engine.textInputPlugin
2603 [engine.textInputPlugin
2608 ASSERT_EQ(engine.textInputPlugin.superview, viewController.view);
2609 ASSERT_TRUE(window.firstResponder == engine.textInputPlugin);
2611 [engine.textInputPlugin
2616 ASSERT_EQ(engine.textInputPlugin.superview, nil);
2617 ASSERT_FALSE(window.firstResponder == engine.textInputPlugin);
2620 TEST(FlutterTextInputPluginTest, FirstResponderIsCorrect) {
2625 [viewController loadView];
2627 NSWindow* window = [[NSWindow alloc] initWithContentRect:NSMakeRect(0, 0, 800, 600)
2628 styleMask:NSBorderlessWindowMask
2629 backing:NSBackingStoreBuffered
2631 window.contentView = viewController.view;
2633 ASSERT_TRUE(viewController.flutterView.acceptsFirstResponder);
2635 [window makeFirstResponder:viewController.flutterView];
2637 NSDictionary* setClientConfig = @{
2638 @"viewId" : @(flutter::kFlutterImplicitViewId),
2640 [engine.textInputPlugin
2646 [engine.textInputPlugin
2651 ASSERT_TRUE(window.firstResponder == engine.textInputPlugin);
2653 ASSERT_FALSE(viewController.flutterView.acceptsFirstResponder);
2655 [engine.textInputPlugin
2660 ASSERT_TRUE(viewController.flutterView.acceptsFirstResponder);
2661 ASSERT_TRUE(window.firstResponder == viewController.flutterView);
2664 TEST(FlutterTextInputPluginTest, HasZeroSizeAndClipsToBounds) {
2668 [engineMock binaryMessenger])
2669 .andReturn(binaryMessengerMock);
2677 viewController:viewController];
2681 ASSERT_TRUE(NSIsEmptyRect(plugin.frame));
2682 ASSERT_TRUE(plugin.clipsToBounds);
2685 TEST(FlutterTextInputPluginTest, WorksWithoutViewId) {
2689 [engineMock binaryMessenger])
2690 .andReturn(binaryMessengerMock);
2698 implicitViewController:viewController];
2702 NSDictionary* setClientConfig = @{
2713 TEST(FlutterTextInputPluginTest, InsertTextWithCollapsedSelectionInsideComposing) {
2718 TEST(FlutterTextInputPluginTest, InsertTextHandlesNSAttributedString) {
2722 [engineMock binaryMessenger])
2723 .andReturn(binaryMessengerMock);
2731 viewController:viewController];
2735 NSDictionary* setClientConfig = @{
2737 @"inputAction" :
@"action",
2738 @"inputType" : @{
@"name" :
@"inputName"},
2746 NSAttributedString* attributedString =
2747 [[NSAttributedString alloc] initWithString:@"attributed text"];
2748 [plugin insertText:attributedString replacementRange:NSMakeRange(NSNotFound, 0)];
2751 EXPECT_STREQ([editingState[
@"text"] UTF8String],
"attributed text");
2752 EXPECT_EQ([editingState[
@"selectionBase"] intValue], 15);
2753 EXPECT_EQ([editingState[
@"selectionExtent"] intValue], 15);
2756 TEST(FlutterTextInputPluginTest, InsertTextWithReversedReplacementRange) {
2760 [engineMock binaryMessenger])
2761 .andReturn(binaryMessengerMock);
2769 viewController:viewController];
2773 NSDictionary* setClientConfig = @{
2775 @"inputAction" :
@"action",
2776 @"inputType" : @{
@"name" :
@"inputName"},
2786 @"selectionBase" : @(5),
2787 @"selectionExtent" : @(5),
2788 @"composingBase" : @(-1),
2789 @"composingExtent" : @(-1),
2797 [plugin insertText:@"X" replacementRange:NSMakeRange(4, static_cast<NSUInteger>(-2))];
2800 EXPECT_STREQ([editingState[
@"text"] UTF8String],
"12X5");
2801 EXPECT_EQ([editingState[
@"selectionBase"] intValue], 3);
2802 EXPECT_EQ([editingState[
@"selectionExtent"] intValue], 3);
2805 TEST(FlutterTextInputPluginTest, InsertTextHandlesEmptyAttributedString) {
2809 [engineMock binaryMessenger])
2810 .andReturn(binaryMessengerMock);
2818 viewController:viewController];
2822 NSDictionary* setClientConfig = @{
2824 @"inputAction" :
@"action",
2825 @"inputType" : @{
@"name" :
@"inputName"},
2833 NSAttributedString* emptyAttributedString = [[NSAttributedString alloc] initWithString:@""];
2834 [plugin insertText:emptyAttributedString replacementRange:NSMakeRange(NSNotFound, 0)];
2837 EXPECT_STREQ([editingState[
@"text"] UTF8String],
"");
2838 EXPECT_EQ([editingState[
@"selectionBase"] intValue], 0);
2839 EXPECT_EQ([editingState[
@"selectionExtent"] intValue], 0);
2842 TEST(FlutterTextInputPluginTest, WillUseParentControllerIfCanNotBecomeKey) {
2846 [engineMock binaryMessenger])
2847 .andReturn(binaryMessengerMock);
2849 [engineMock enableMultiView];
2850 [engineMock runWithEntrypoint:nil];
2867 NSWindow* rootWindow = [[NSWindow alloc] initWithContentRect:NSZeroRect
2868 styleMask:NSWindowStyleMaskTitled
2869 backing:NSBackingStoreBuffered
2871 rootWindow.contentViewController = rootViewController;
2873 NSWindow* popupWindow1 = [[NSWindow alloc] initWithContentRect:NSZeroRect
2874 styleMask:NSWindowStyleMaskBorderless
2875 backing:NSBackingStoreBuffered
2877 popupWindow1.contentViewController = popupController1;
2878 [rootWindow addChildWindow:popupWindow1 ordered:NSWindowAbove];
2880 NSWindow* popupWindow2 = [[NSWindow alloc] initWithContentRect:NSZeroRect
2881 styleMask:NSWindowStyleMaskBorderless
2882 backing:NSBackingStoreBuffered
2884 popupWindow2.contentViewController = popupController2;
2885 [popupWindow1 addChildWindow:popupWindow2 ordered:NSWindowAbove];
2890 viewController:popupController2];
2894 NSDictionary* setClientConfig = @{
2896 @"inputAction" :
@"action",
2897 @"inputType" : @{
@"name" :
@"inputName"},
void(^ FlutterResult)(id _Nullable result)
FlutterBinaryMessengerRelay * _binaryMessenger
static const FlutterViewIdentifier kViewId
static id JSONMessageWithContentOf(NSData *expected)
int64_t FlutterViewIdentifier
The ax platform node for a text field.
gfx::NativeViewAccessible GetNativeViewAccessible() override
instancetype methodCallWithMethodName:arguments:(NSString *method,[arguments] id _Nullable arguments)
NSRange lastUpdatedSelection
NSString * lastUpdatedString
NSString * customRunLoopMode
NSTextInputContext * textInputContext
FlutterViewController * currentViewController
NSRect firstRectForCharacterRange:actualRange:(NSRange range,[actualRange] NSRangePointer actualRange)
void handleMethodCall:result:(FlutterMethodCall *call,[result] FlutterResult result)
NSDictionary * editingState()
FlutterViewController * _implicitViewController
id< FlutterBinaryMessenger > _binaryMessenger
FlutterViewController * _viewController
id CreateMockFlutterEngine(NSString *pasteboardString)
TEST(FlutterTextInputPluginTest, WillUseParentControllerIfCanNotBecomeKey)
instancetype sharedInstance()
id< FlutterBinaryMessenger > binaryMessenger