Flutter macOS Embedder
KeyboardTester Class Reference
Inheritance diagram for KeyboardTester:

Instance Methods

(nonnull instancetype) - init
 
(void) - respondEmbedderCallsWith:
 
(void) - recordEmbedderCallsTo:
 
(void) - recordEmbedderEventsTo:returning:
 
(void) - respondChannelCallsWith:
 
(void) - recordChannelCallsTo:
 
(void) - respondTextInputWith:
 
(void) - recordCallTypesTo:forTypes:
 
(id) - lastKeyboardChannelResult
 
(void) - sendKeyboardChannelMessage:
 
(void) - handleEmbedderEvent:callback:userData:
 
(void) - handleChannelMessage:message:binaryReply:
 
(BOOL) - handleTextInputKeyEvent:
 

Properties

FlutterKeyboardManagermanager
 
id< FlutterKeyboardManagerEventContexteventContextMock
 
NSResponder * nextResponder
 

Detailed Description

Definition at line 181 of file FlutterKeyboardManagerTest.mm.

Method Documentation

◆ handleChannelMessage:message:binaryReply:

- (void) handleChannelMessage: (NSString*)  channel
message: (NSData* _Nullable)  message
binaryReply: (FlutterBinaryReply _Nullable)  callback 

Definition at line 382 of file FlutterKeyboardManagerTest.mm.

382  :(NSString*)channel
383  message:(NSData* _Nullable)message
384  binaryReply:(FlutterBinaryReply _Nullable)callback {
385  if (_typeStorage != nil && (_typeStorageMask & kChannelCall) != 0) {
386  [_typeStorage addObject:@(kChannelCall)];
387  }
388  _channelHandler(^(BOOL handled) {
389  NSDictionary* result = @{
390  @"handled" : @(handled),
391  };
392  NSData* encodedKeyEvent = [[FlutterJSONMessageCodec sharedInstance] encode:result];
393  callback(encodedKeyEvent);
394  });
395 }

References _channelHandler, _typeStorage, _typeStorageMask, and <FlutterMessageCodec>::sharedInstance.

◆ handleEmbedderEvent:callback:userData:

- (void) handleEmbedderEvent: (const FlutterKeyEvent&)  event
callback: (nullable FlutterKeyEventCallback)  callback
userData: (nullable void*)  userData 

Definition at line 369 of file FlutterKeyboardManagerTest.mm.

369  :(const FlutterKeyEvent&)event
370  callback:(nullable FlutterKeyEventCallback)callback
371  userData:(nullable void*)userData {
372  if (_typeStorage != nil && (_typeStorageMask & kEmbedderCall) != 0) {
373  [_typeStorage addObject:@(kEmbedderCall)];
374  }
375  if (callback != nullptr) {
376  _embedderHandler(&event, ^(BOOL handled) {
377  callback(handled, userData);
378  });
379  }
380 }

References _typeStorage, and _typeStorageMask.

◆ handleTextInputKeyEvent:

- (BOOL) handleTextInputKeyEvent: (NSEvent*)  event

Definition at line 403 of file FlutterKeyboardManagerTest.mm.

403  :(NSEvent*)event {
404  if (_typeStorage != nil && (_typeStorageMask & kTextCall) != 0) {
405  [_typeStorage addObject:@(kTextCall)];
406  }
407  return _textCallback(event);
408 }

References _textCallback, _typeStorage, and _typeStorageMask.

◆ init

- (nonnull instancetype) init

Definition at line 255 of file FlutterKeyboardManagerTest.mm.

255  {
256  self = [super init];
257  if (self == nil) {
258  return nil;
259  }
260 
261  _nextResponder = OCMClassMock([NSResponder class]);
262  [self respondChannelCallsWith:FALSE];
263  [self respondEmbedderCallsWith:FALSE];
264  [self respondTextInputWith:FALSE];
265 
266  _currentLayout = &kUsLayout;
267 
268  _messengerMock = OCMStrictProtocolMock(@protocol(FlutterBinaryMessenger));
269  OCMStub([_messengerMock sendOnChannel:@"flutter/keyevent"
270  message:[OCMArg any]
271  binaryReply:[OCMArg any]])
272  .andCall(self, @selector(handleChannelMessage:message:binaryReply:));
273  OCMStub([_messengerMock setMessageHandlerOnChannel:@"flutter/keyboard"
274  binaryMessageHandler:[OCMArg any]])
275  .andCall(self, @selector(setKeyboardChannelHandler:handler:));
276  OCMStub([_messengerMock sendOnChannel:@"flutter/keyboard" message:[OCMArg any]])
277  .andCall(self, @selector(handleKeyboardChannelMessage:message:));
278  id managerDelegateMock = OCMStrictProtocolMock(@protocol(FlutterKeyboardManagerDelegate));
279  OCMStub([managerDelegateMock binaryMessenger]).andReturn(_messengerMock);
280  OCMStub([managerDelegateMock sendKeyEvent:*(const FlutterKeyEvent*)[OCMArg anyPointer]
281  callback:nil
282  userData:nil])
283  .ignoringNonObjectArgs()
284  .andCall(self, @selector(handleEmbedderEvent:callback:userData:));
285 
286  _eventContextMock = OCMStrictProtocolMock(@protocol(FlutterKeyboardManagerEventContext));
287  OCMStub([_eventContextMock nextResponder]).andReturn(_nextResponder);
288  OCMStub([_eventContextMock onTextInputKeyEvent:[OCMArg any]])
289  .andCall(self, @selector(handleTextInputKeyEvent:));
290 
291  id keyboardLayoutMock = OCMStrictClassMock([FlutterKeyboardLayout class]);
292  OCMStub([keyboardLayoutMock lookUpLayoutForKeyCode:0 shift:false])
293  .ignoringNonObjectArgs()
294  .andCall(self, @selector(lookUpLayoutForKeyCode:shift:));
295  OCMStub([keyboardLayoutMock setDelegate:[OCMArg any]])
296  .andCall(self, @selector(onSetKeyboardLayoutDelegate:));
297 
298  _manager = [[FlutterKeyboardManager alloc] initWithDelegate:managerDelegateMock
299  keyboardLayout:keyboardLayoutMock];
300  return self;
301 }

References _currentLayout, _eventContextMock, _messengerMock, respondChannelCallsWith:, respondEmbedderCallsWith:, and respondTextInputWith:.

◆ lastKeyboardChannelResult

- (id) lastKeyboardChannelResult

◆ recordCallTypesTo:forTypes:

- (void) recordCallTypesTo: (nonnull NSMutableArray<NSNumber*>*)  typeStorage
forTypes: (uint32_t)  typeMask 

Definition at line 352 of file FlutterKeyboardManagerTest.mm.

352  :(nonnull NSMutableArray<NSNumber*>*)typeStorage
353  forTypes:(uint32_t)typeMask {
354  _typeStorage = typeStorage;
355  _typeStorageMask = typeMask;
356 }

References _typeStorage, and _typeStorageMask.

Referenced by FlutterKeyboardManagerUnittestsObjC::racingConditionBetweenKeyAndText.

◆ recordChannelCallsTo:

- (void) recordChannelCallsTo: (nonnull NSMutableArray<FlutterAsyncKeyCallback>*)  storage

Definition at line 340 of file FlutterKeyboardManagerTest.mm.

340  :(nonnull NSMutableArray<FlutterAsyncKeyCallback>*)storage {
342  [storage addObject:callback];
343  };
344 }

References _channelHandler.

Referenced by FlutterKeyboardManagerUnittestsObjC::doublePrimaryResponder.

◆ recordEmbedderCallsTo:

- (void) recordEmbedderCallsTo: (nonnull NSMutableArray<FlutterAsyncKeyCallback>*)  storage

Definition at line 313 of file FlutterKeyboardManagerTest.mm.

313  :(nonnull NSMutableArray<FlutterAsyncKeyCallback>*)storage {
314  _embedderHandler = ^(const FlutterKeyEvent* event, FlutterAsyncKeyCallback callback) {
315  [storage addObject:callback];
316  };
317 }

Referenced by FlutterKeyboardManagerUnittestsObjC::doublePrimaryResponder, FlutterKeyboardManagerUnittestsObjC::racingConditionBetweenKeyAndText, FlutterKeyboardManagerUnittestsObjC::singlePrimaryResponder, and FlutterKeyboardManagerUnittestsObjC::textInputPlugin.

◆ recordEmbedderEventsTo:returning:

- (void) recordEmbedderEventsTo: (nonnull std::vector<FlutterKeyEvent>*)  storage
returning: (bool)  handled 

Definition at line 319 of file FlutterKeyboardManagerTest.mm.

319  :(nonnull std::vector<FlutterKeyEvent>*)storage
320  returning:(bool)handled {
321  _embedderHandler = ^(const FlutterKeyEvent* event, FlutterAsyncKeyCallback callback) {
322  FlutterKeyEvent newEvent = *event;
323  if (event->character != nullptr) {
324  size_t charLen = strlen(event->character);
325  char* newCharacter = new char[charLen + 1];
326  strlcpy(newCharacter, event->character, charLen + 1);
327  newEvent.character = newCharacter;
328  }
329  storage->push_back(newEvent);
330  callback(handled);
331  };
332 }

Referenced by FlutterKeyboardManagerUnittestsObjC::correctLogicalKeyForLayouts.

◆ respondChannelCallsWith:

◆ respondEmbedderCallsWith:

- (void) respondEmbedderCallsWith: (BOOL)  response

◆ respondTextInputWith:

◆ sendKeyboardChannelMessage:

- (void) sendKeyboardChannelMessage: (NSData* _Nullable)  message

Definition at line 358 of file FlutterKeyboardManagerTest.mm.

358  :(NSData* _Nullable)message {
359  [_messengerMock sendOnChannel:@"flutter/keyboard" message:message];
360 }

Referenced by FlutterKeyboardManagerUnittestsObjC::keyboardChannelGetPressedState.

Property Documentation

◆ eventContextMock

- (id<FlutterKeyboardManagerEventContext>) eventContextMock
readnonatomicstrong

Definition at line 221 of file FlutterKeyboardManagerTest.mm.

◆ manager

- (FlutterKeyboardManager*) manager
readnonatomicstrong

Definition at line 220 of file FlutterKeyboardManagerTest.mm.

◆ nextResponder


The documentation for this class was generated from the following file:
FlutterKeyboardManagerEventContext-p
Definition: FlutterKeyboardManager.h:40
FlutterKeyboardManagerDelegate-p
Definition: FlutterKeyboardManager.h:13
_channelHandler
AsyncKeyCallbackHandler _channelHandler
Definition: FlutterKeyboardManagerTest.mm:237
KeyboardTester::nextResponder
NSResponder * nextResponder
Definition: FlutterKeyboardManagerTest.mm:222
FlutterAsyncKeyCallback
void(^ FlutterAsyncKeyCallback)(BOOL handled)
Definition: FlutterKeyPrimaryResponder.h:10
_typeStorageMask
uint32_t _typeStorageMask
Definition: FlutterKeyboardManagerTest.mm:243
_messengerMock
NSObject< FlutterBinaryMessenger > * _messengerMock
Definition: FlutterKeyboardManagerTest.mm:249
_keyboardChannelResult
id _keyboardChannelResult
Definition: FlutterKeyboardManagerTest.mm:248
FlutterKeyboardLayout
Definition: FlutterKeyboardLayout.h:50
FlutterKeyboardManager
Definition: FlutterKeyboardManager.h:78
_textCallback
TextInputCallback _textCallback
Definition: FlutterKeyboardManagerTest.mm:240
FlutterBinaryMessenger-p
Definition: FlutterBinaryMessenger.h:49
_typeStorage
NSMutableArray< NSNumber * > * _typeStorage
Definition: FlutterKeyboardManagerTest.mm:242
_eventContextMock
NSObject< FlutterKeyboardManagerEventContext > * _eventContextMock
Definition: FlutterKeyboardManagerTest.mm:252
FlutterBinaryReply
NS_ASSUME_NONNULL_BEGIN typedef void(^ FlutterBinaryReply)(NSData *_Nullable reply)
+[FlutterMessageCodec-p sharedInstance]
instancetype sharedInstance()
FlutterJSONMessageCodec
Definition: FlutterCodecs.h:81
_currentLayout
const MockLayoutData * _currentLayout
Definition: FlutterKeyboardManagerTest.mm:246