|
16 | 16 |
|
17 | 17 | const float kFloatCompareEpsilon = 0.001;
|
18 | 18 |
|
| 19 | +@interface TextInputSemanticsObject (Test) |
| 20 | +- (UIView<UITextInput>*)textInputSurrogate; |
| 21 | +@end |
| 22 | + |
19 | 23 | @interface SemanticsObjectTest : XCTestCase
|
20 | 24 | @end
|
21 | 25 |
|
@@ -1069,4 +1073,89 @@ - (void)testTextInputSemanticsObject {
|
1069 | 1073 | XCTAssertEqual([object accessibilityTraits], UIAccessibilityTraitNone);
|
1070 | 1074 | }
|
1071 | 1075 |
|
| 1076 | +- (void)testTextInputSemanticsObject_canPerformAction { |
| 1077 | + fml::WeakPtrFactory<flutter::AccessibilityBridgeIos> factory( |
| 1078 | + new flutter::testing::MockAccessibilityBridge()); |
| 1079 | + fml::WeakPtr<flutter::AccessibilityBridgeIos> bridge = factory.GetWeakPtr(); |
| 1080 | + |
| 1081 | + flutter::SemanticsNode node; |
| 1082 | + node.label = "foo"; |
| 1083 | + node.flags = static_cast<int32_t>(flutter::SemanticsFlags::kIsTextField) | |
| 1084 | + static_cast<int32_t>(flutter::SemanticsFlags::kIsReadOnly); |
| 1085 | + TextInputSemanticsObject* object = [[TextInputSemanticsObject alloc] initWithBridge:bridge uid:0]; |
| 1086 | + [object setSemanticsNode:&node]; |
| 1087 | + [object accessibilityBridgeDidFinishUpdate]; |
| 1088 | + |
| 1089 | + id textInputSurrogate = OCMClassMock([UIResponder class]); |
| 1090 | + id partialSemanticsObject = OCMPartialMock(object); |
| 1091 | + OCMStub([partialSemanticsObject textInputSurrogate]).andReturn(textInputSurrogate); |
| 1092 | + |
| 1093 | + OCMExpect([textInputSurrogate canPerformAction:[OCMArg anySelector] withSender:OCMOCK_ANY]) |
| 1094 | + .andReturn(YES); |
| 1095 | + XCTAssertTrue([partialSemanticsObject canPerformAction:@selector(copy:) withSender:nil]); |
| 1096 | + |
| 1097 | + OCMExpect([textInputSurrogate canPerformAction:[OCMArg anySelector] withSender:OCMOCK_ANY]) |
| 1098 | + .andReturn(NO); |
| 1099 | + XCTAssertFalse([partialSemanticsObject canPerformAction:@selector(copy:) withSender:nil]); |
| 1100 | +} |
| 1101 | + |
| 1102 | +- (void)testTextInputSemanticsObject_editActions { |
| 1103 | + fml::WeakPtrFactory<flutter::AccessibilityBridgeIos> factory( |
| 1104 | + new flutter::testing::MockAccessibilityBridge()); |
| 1105 | + fml::WeakPtr<flutter::AccessibilityBridgeIos> bridge = factory.GetWeakPtr(); |
| 1106 | + |
| 1107 | + flutter::SemanticsNode node; |
| 1108 | + node.label = "foo"; |
| 1109 | + node.flags = static_cast<int32_t>(flutter::SemanticsFlags::kIsTextField) | |
| 1110 | + static_cast<int32_t>(flutter::SemanticsFlags::kIsReadOnly); |
| 1111 | + TextInputSemanticsObject* object = [[TextInputSemanticsObject alloc] initWithBridge:bridge uid:0]; |
| 1112 | + [object setSemanticsNode:&node]; |
| 1113 | + [object accessibilityBridgeDidFinishUpdate]; |
| 1114 | + |
| 1115 | + id textInputSurrogate = OCMClassMock([UIResponder class]); |
| 1116 | + id partialSemanticsObject = OCMPartialMock(object); |
| 1117 | + OCMStub([partialSemanticsObject textInputSurrogate]).andReturn(textInputSurrogate); |
| 1118 | + |
| 1119 | + XCTestExpectation* copyExpectation = |
| 1120 | + [self expectationWithDescription:@"Surrogate's copy method is called."]; |
| 1121 | + XCTestExpectation* cutExpectation = |
| 1122 | + [self expectationWithDescription:@"Surrogate's cut method is called."]; |
| 1123 | + XCTestExpectation* pasteExpectation = |
| 1124 | + [self expectationWithDescription:@"Surrogate's paste method is called."]; |
| 1125 | + XCTestExpectation* selectExpectation = |
| 1126 | + [self expectationWithDescription:@"Surrogate's select method is called."]; |
| 1127 | + XCTestExpectation* selectAllExpectation = |
| 1128 | + [self expectationWithDescription:@"Surrogate's selectAll method is called."]; |
| 1129 | + XCTestExpectation* deleteExpectation = |
| 1130 | + [self expectationWithDescription:@"Surrogate's delete method is called."]; |
| 1131 | + |
| 1132 | + OCMStub([textInputSurrogate copy:OCMOCK_ANY]).andDo(^(NSInvocation* invocation) { |
| 1133 | + [copyExpectation fulfill]; |
| 1134 | + }); |
| 1135 | + OCMStub([textInputSurrogate cut:OCMOCK_ANY]).andDo(^(NSInvocation* invocation) { |
| 1136 | + [cutExpectation fulfill]; |
| 1137 | + }); |
| 1138 | + OCMStub([textInputSurrogate paste:OCMOCK_ANY]).andDo(^(NSInvocation* invocation) { |
| 1139 | + [pasteExpectation fulfill]; |
| 1140 | + }); |
| 1141 | + OCMStub([textInputSurrogate select:OCMOCK_ANY]).andDo(^(NSInvocation* invocation) { |
| 1142 | + [selectExpectation fulfill]; |
| 1143 | + }); |
| 1144 | + OCMStub([textInputSurrogate selectAll:OCMOCK_ANY]).andDo(^(NSInvocation* invocation) { |
| 1145 | + [selectAllExpectation fulfill]; |
| 1146 | + }); |
| 1147 | + OCMStub([textInputSurrogate delete:OCMOCK_ANY]).andDo(^(NSInvocation* invocation) { |
| 1148 | + [deleteExpectation fulfill]; |
| 1149 | + }); |
| 1150 | + |
| 1151 | + [partialSemanticsObject copy:nil]; |
| 1152 | + [partialSemanticsObject cut:nil]; |
| 1153 | + [partialSemanticsObject paste:nil]; |
| 1154 | + [partialSemanticsObject select:nil]; |
| 1155 | + [partialSemanticsObject selectAll:nil]; |
| 1156 | + [partialSemanticsObject delete:nil]; |
| 1157 | + |
| 1158 | + [self waitForExpectationsWithTimeout:1 handler:nil]; |
| 1159 | +} |
| 1160 | + |
1072 | 1161 | @end
|
0 commit comments