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
 
NSResponder * nextResponder
 

Detailed Description

Definition at line 180 of file FlutterKeyboardManagerTest.mm.

Method Documentation

◆ handleChannelMessage:message:binaryReply:

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

Definition at line 373 of file FlutterKeyboardManagerTest.mm.

373  :(NSString*)channel
374  message:(NSData* _Nullable)message
375  binaryReply:(FlutterBinaryReply _Nullable)callback {
376  if (_typeStorage != nil && (_typeStorageMask & kChannelCall) != 0) {
377  [_typeStorage addObject:@(kChannelCall)];
378  }
379  _channelHandler(^(BOOL handled) {
380  NSDictionary* result = @{
381  @"handled" : @(handled),
382  };
383  NSData* encodedKeyEvent = [[FlutterJSONMessageCodec sharedInstance] encode:result];
384  callback(encodedKeyEvent);
385  });
386 }

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 360 of file FlutterKeyboardManagerTest.mm.

360  :(const FlutterKeyEvent&)event
361  callback:(nullable FlutterKeyEventCallback)callback
362  userData:(nullable void*)userData {
363  if (_typeStorage != nil && (_typeStorageMask & kEmbedderCall) != 0) {
364  [_typeStorage addObject:@(kEmbedderCall)];
365  }
366  if (callback != nullptr) {
367  _embedderHandler(&event, ^(BOOL handled) {
368  callback(handled, userData);
369  });
370  }
371 }

References _typeStorage, and _typeStorageMask.

◆ handleTextInputKeyEvent:

- (BOOL) handleTextInputKeyEvent: (NSEvent*)  event

Definition at line 394 of file FlutterKeyboardManagerTest.mm.

394  :(NSEvent*)event {
395  if (_typeStorage != nil && (_typeStorageMask & kTextCall) != 0) {
396  [_typeStorage addObject:@(kTextCall)];
397  }
398  return _textCallback(event);
399 }

References _textCallback, _typeStorage, and _typeStorageMask.

◆ init

- (nonnull instancetype) init

Definition at line 251 of file FlutterKeyboardManagerTest.mm.

251  {
252  self = [super init];
253  if (self == nil) {
254  return nil;
255  }
256 
257  _nextResponder = OCMClassMock([NSResponder class]);
258  [self respondChannelCallsWith:FALSE];
259  [self respondEmbedderCallsWith:FALSE];
260  [self respondTextInputWith:FALSE];
261 
262  _currentLayout = &kUsLayout;
263 
264  _messengerMock = OCMStrictProtocolMock(@protocol(FlutterBinaryMessenger));
265  OCMStub([_messengerMock sendOnChannel:@"flutter/keyevent"
266  message:[OCMArg any]
267  binaryReply:[OCMArg any]])
268  .andCall(self, @selector(handleChannelMessage:message:binaryReply:));
269  OCMStub([_messengerMock setMessageHandlerOnChannel:@"flutter/keyboard"
270  binaryMessageHandler:[OCMArg any]])
271  .andCall(self, @selector(setKeyboardChannelHandler:handler:));
272  OCMStub([_messengerMock sendOnChannel:@"flutter/keyboard" message:[OCMArg any]])
273  .andCall(self, @selector(handleKeyboardChannelMessage:message:));
274  id viewDelegateMock = OCMStrictProtocolMock(@protocol(FlutterKeyboardViewDelegate));
275  OCMStub([viewDelegateMock nextResponder]).andReturn(_nextResponder);
276  OCMStub([viewDelegateMock onTextInputKeyEvent:[OCMArg any]])
277  .andCall(self, @selector(handleTextInputKeyEvent:));
278  OCMStub([viewDelegateMock getBinaryMessenger]).andReturn(_messengerMock);
279  OCMStub([viewDelegateMock sendKeyEvent:FlutterKeyEvent {} callback:nil userData:nil])
280  .ignoringNonObjectArgs()
281  .andCall(self, @selector(handleEmbedderEvent:callback:userData:));
282  OCMStub([viewDelegateMock subscribeToKeyboardLayoutChange:[OCMArg any]])
283  .andCall(self, @selector(onSetKeyboardLayoutNotifier:));
284  OCMStub([viewDelegateMock lookUpLayoutForKeyCode:0 shift:false])
285  .ignoringNonObjectArgs()
286  .andCall(self, @selector(lookUpLayoutForKeyCode:shift:));
287 
288  _manager = [[FlutterKeyboardManager alloc] initWithViewDelegate:viewDelegateMock];
289  return self;
290 }

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

◆ lastKeyboardChannelResult

- (id) lastKeyboardChannelResult

◆ recordCallTypesTo:forTypes:

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

Definition at line 341 of file FlutterKeyboardManagerTest.mm.

341  :(nonnull NSMutableArray<NSNumber*>*)typeStorage
342  forTypes:(uint32_t)typeMask {
343  _typeStorage = typeStorage;
344  _typeStorageMask = typeMask;
345 }

References _typeStorage, and _typeStorageMask.

Referenced by FlutterKeyboardManagerUnittestsObjC::racingConditionBetweenKeyAndText.

◆ recordChannelCallsTo:

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

Definition at line 329 of file FlutterKeyboardManagerTest.mm.

329  :(nonnull NSMutableArray<FlutterAsyncKeyCallback>*)storage {
331  [storage addObject:callback];
332  };
333 }

References _channelHandler.

Referenced by FlutterKeyboardManagerUnittestsObjC::doublePrimaryResponder.

◆ recordEmbedderCallsTo:

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

Definition at line 302 of file FlutterKeyboardManagerTest.mm.

302  :(nonnull NSMutableArray<FlutterAsyncKeyCallback>*)storage {
303  _embedderHandler = ^(const FlutterKeyEvent* event, FlutterAsyncKeyCallback callback) {
304  [storage addObject:callback];
305  };
306 }

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 308 of file FlutterKeyboardManagerTest.mm.

308  :(nonnull std::vector<FlutterKeyEvent>*)storage
309  returning:(bool)handled {
310  _embedderHandler = ^(const FlutterKeyEvent* event, FlutterAsyncKeyCallback callback) {
311  FlutterKeyEvent newEvent = *event;
312  if (event->character != nullptr) {
313  size_t charLen = strlen(event->character);
314  char* newCharacter = new char[charLen + 1];
315  strlcpy(newCharacter, event->character, charLen + 1);
316  newEvent.character = newCharacter;
317  }
318  storage->push_back(newEvent);
319  callback(handled);
320  };
321 }

Referenced by FlutterKeyboardManagerUnittestsObjC::correctLogicalKeyForLayouts.

◆ respondChannelCallsWith:

◆ respondEmbedderCallsWith:

- (void) respondEmbedderCallsWith: (BOOL)  response

◆ respondTextInputWith:

◆ sendKeyboardChannelMessage:

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

Definition at line 347 of file FlutterKeyboardManagerTest.mm.

347  :(NSData* _Nullable)message {
348  [_messengerMock sendOnChannel:@"flutter/keyboard" message:message];
349 }

Referenced by FlutterKeyboardManagerUnittestsObjC::keyboardChannelGetPressedState.

Property Documentation

◆ manager

- (FlutterKeyboardManager*) manager
readnonatomicstrong

Definition at line 219 of file FlutterKeyboardManagerTest.mm.

◆ nextResponder


The documentation for this class was generated from the following file:
FlutterKeyboardViewDelegate-p
Definition: FlutterKeyboardViewDelegate.h:39
_channelHandler
AsyncKeyCallbackHandler _channelHandler
Definition: FlutterKeyboardManagerTest.mm:235
KeyboardTester::nextResponder
NSResponder * nextResponder
Definition: FlutterKeyboardManagerTest.mm:220
FlutterAsyncKeyCallback
void(^ FlutterAsyncKeyCallback)(BOOL handled)
Definition: FlutterKeyPrimaryResponder.h:7
_typeStorageMask
uint32_t _typeStorageMask
Definition: FlutterKeyboardManagerTest.mm:241
_messengerMock
NSObject< FlutterBinaryMessenger > * _messengerMock
Definition: FlutterKeyboardManagerTest.mm:247
_keyboardChannelResult
id _keyboardChannelResult
Definition: FlutterKeyboardManagerTest.mm:246
FlutterKeyboardManager
Definition: FlutterKeyboardManager.h:24
_textCallback
TextInputCallback _textCallback
Definition: FlutterKeyboardManagerTest.mm:238
FlutterBinaryMessenger-p
Definition: FlutterBinaryMessenger.h:48
_typeStorage
NSMutableArray< NSNumber * > * _typeStorage
Definition: FlutterKeyboardManagerTest.mm:240
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:244