Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Instance Methods | List of all members
FlutterChannelKeyResponderTest Class Reference
Inheritance diagram for FlutterChannelKeyResponderTest:

Instance Methods

(FlutterUIPressProxy *testKeyDownEvent) - API_AVAILABLE
 
(FlutterUIPressProxy *testKeyUpEvent) - API_AVAILABLE
 
(void) - setUp [implementation]
 
() - ios [implementation]
 
() - ios [implementation]
 
() - ios [implementation]
 

Detailed Description

Definition at line 22 of file FlutterChannelKeyResponderTest.mm.

Method Documentation

◆ API_AVAILABLE [1/2]

- (FlutterUIPressProxy *testKeyDownEvent) API_AVAILABLE (ios(13.4)) 

◆ API_AVAILABLE [2/2]

- (FlutterUIPressProxy *testKeyUpEvent) API_AVAILABLE (ios(13.4)) 

◆ ios [1/3]

- ios
implementation

Definition at line 24 of file FlutterChannelKeyResponderTest.mm.

39 {
40 _testKeyDownEvent = nil;
41 _testKeyUpEvent = nil;
42}

◆ ios [2/3]

- ios
implementation

Definition at line 24 of file FlutterChannelKeyResponderTest.mm.

44 {
45 __block NSMutableArray<id>* messages = [[NSMutableArray<id> alloc] init];
46 __block BOOL next_response = TRUE;
47 __block NSMutableArray<NSNumber*>* responses = [[NSMutableArray<NSNumber*> alloc] init];
48
49 id mockKeyEventChannel = OCMStrictClassMock([FlutterBasicMessageChannel class]);
50 OCMStub([mockKeyEventChannel sendMessage:[OCMArg any] reply:[OCMArg any]])
51 .andDo((^(NSInvocation* invocation) {
52 [invocation retainArguments];
53 NSDictionary* message;
54 [invocation getArgument:&message atIndex:2];
55 [messages addObject:message];
56
58 [invocation getArgument:&callback atIndex:3];
59 NSDictionary* keyMessage = @{
60 @"handled" : @(next_response),
61 };
62 callback(keyMessage);
63 }));
64
65 // Key down
67 [[FlutterChannelKeyResponder alloc] initWithChannel:mockKeyEventChannel];
68 [responder handlePress:_testKeyDownEvent
69 callback:^(BOOL handled) {
70 [responses addObject:@(handled)];
71 }];
72
73 XCTAssertEqual([messages count], 1u);
74 XCTAssertStrEqual([messages lastObject][@"keymap"], @"ios");
75 XCTAssertStrEqual([messages lastObject][@"type"], @"keydown");
76 XCTAssertEqual([[messages lastObject][@"keyCode"] intValue], UIKeyboardHIDUsageKeyboardA);
77 XCTAssertEqual([[messages lastObject][@"modifiers"] intValue], 0x0);
78 XCTAssertStrEqual([messages lastObject][@"characters"], @"a");
79 XCTAssertStrEqual([messages lastObject][@"charactersIgnoringModifiers"], @"a");
80
81 XCTAssertEqual([responses count], 1u);
82 XCTAssertEqual([[responses lastObject] boolValue], TRUE);
83
84 [messages removeAllObjects];
85 [responses removeAllObjects];
86
87 // Key up
88 next_response = FALSE;
89 [responder handlePress:_testKeyUpEvent
90 callback:^(BOOL handled) {
91 [responses addObject:@(handled)];
92 }];
93
94 XCTAssertEqual([messages count], 1u);
95 XCTAssertStrEqual([messages lastObject][@"keymap"], @"ios");
96 XCTAssertStrEqual([messages lastObject][@"type"], @"keyup");
97 XCTAssertEqual([[messages lastObject][@"keyCode"] intValue], UIKeyboardHIDUsageKeyboardA);
98 XCTAssertEqual([[messages lastObject][@"modifiers"] intValue], 0x0);
99
100 XCTAssertEqual([responses count], 1u);
101 XCTAssertEqual([[responses lastObject] boolValue], FALSE);
102
103 [messages removeAllObjects];
104 [responses removeAllObjects];
105}
NS_ASSUME_NONNULL_BEGIN typedef void(^ FlutterReply)(id _Nullable reply)
int count
FlKeyEvent uint64_t FlKeyResponderAsyncCallback callback
void handlePress:callback:(nonnull FlutterUIPressProxy *press, [callback] ios(13.4) API_AVAILABLE)
#define XCTAssertStrEqual(value, expected)
Win32Message message
return FALSE
SIT bool any(const Vec< 1, T > &x)
Definition SkVx.h:530
int BOOL

◆ ios [3/3]

- ios
implementation

Definition at line 24 of file FlutterChannelKeyResponderTest.mm.

107 {
108 __block NSMutableArray<id>* messages = [[NSMutableArray<id> alloc] init];
109 __block NSMutableArray<NSNumber*>* responses = [[NSMutableArray<NSNumber*> alloc] init];
110
111 id mockKeyEventChannel = OCMStrictClassMock([FlutterBasicMessageChannel class]);
112 OCMStub([mockKeyEventChannel sendMessage:[OCMArg any] reply:[OCMArg any]])
113 .andDo((^(NSInvocation* invocation) {
114 [invocation retainArguments];
115 NSDictionary* message;
116 [invocation getArgument:&message atIndex:2];
117 [messages addObject:message];
118
120 [invocation getArgument:&callback atIndex:3];
121 callback(nullptr);
122 }));
123
124 FlutterChannelKeyResponder* responder =
125 [[FlutterChannelKeyResponder alloc] initWithChannel:mockKeyEventChannel];
126 [responder handlePress:_testKeyDownEvent
127 callback:^(BOOL handled) {
128 [responses addObject:@(handled)];
129 }];
130
131 XCTAssertEqual([messages count], 1u);
132 XCTAssertStrEqual([messages lastObject][@"keymap"], @"ios");
133 XCTAssertStrEqual([messages lastObject][@"type"], @"keydown");
134 XCTAssertEqual([[messages lastObject][@"keyCode"] intValue], UIKeyboardHIDUsageKeyboardA);
135 XCTAssertEqual([[messages lastObject][@"modifiers"] intValue], 0x0);
136 XCTAssertStrEqual([messages lastObject][@"characters"], @"a");
137 XCTAssertStrEqual([messages lastObject][@"charactersIgnoringModifiers"], @"a");
138
139 XCTAssertEqual([responses count], 1u);
140 XCTAssertEqual([[responses lastObject] boolValue], TRUE);
141}

◆ setUp

- (void) setUp
implementation

Definition at line 24 of file FlutterChannelKeyResponderTest.mm.

29 {
30 // All of these tests were designed to run on iOS 13.4 or later.
31 if (@available(iOS 13.4, *)) {
32 } else {
33 XCTSkip(@"Required API not present for test.");
34 }
35 _testKeyDownEvent = keyDownEvent(UIKeyboardHIDUsageKeyboardA, 0x0, 0.0f, "a", "a");
36 _testKeyUpEvent = keyUpEvent(UIKeyboardHIDUsageKeyboardA, 0x0, 0.0f);
37}
FlutterUIPressProxy * keyUpEvent(UIKeyboardHIDUsage keyCode, UIKeyModifierFlags modifierFlags=0x0, NSTimeInterval timestamp=0.0f, const char *characters="", const char *charactersIgnoringModifiers="") API_AVAILABLE(ios(13.4))
FlutterUIPressProxy * keyDownEvent(UIKeyboardHIDUsage keyCode, UIKeyModifierFlags modifierFlags=0x0, NSTimeInterval timestamp=0.0f, const char *characters="", const char *charactersIgnoringModifiers="") API_AVAILABLE(ios(13.4))

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