| Flutter macOS Embedder |

Classes | Typedefs | Functions
flutter::testing Namespace Reference

## Classes
class | FlutterEngineTest
class | MockFlutterEngineTest
class | FlutterMenuPluginTest

## Typedefs
using | FlutterChannelKeyResponderTest = AutoreleasePoolTest
using | FlutterEmbedderExternalTextureTest = AutoreleasePoolTest
using | FlutterViewControllerTest = AutoreleasePoolTest
using | FlutterViewControllerMockEngineTest = MockFlutterEngineTest

## Functions
| TEST_F (AccessibilityBridgeMacWindowTest, SendsAccessibilityCreateNotificationFlutterViewWindow)
| TEST_F (AccessibilityBridgeMacWindowTest, NonZeroRootNodeId)
| TEST_F (AccessibilityBridgeMacTest, DoesNotSendAccessibilityCreateNotificationWhenHeadless)
| TEST_F (AccessibilityBridgeMacTest, DoesNotSendAccessibilityCreateNotificationWhenNoWindow)
| TEST (FlutterAppDelegateTest, DoesNotCallDelegatesWithoutHandler)
| TEST (FlutterAppDelegateTest, ReceivesOpenURLs)
| TEST (FlutterAppDelegateTest, OperURLsStopsAfterHandled)
| TEST (FlutterAppLifecycleDelegateTest, RespondsToWillFinishLaunching)
| TEST (FlutterAppLifecycleDelegateTest, RespondsToDidFinishLaunching)
| TEST (FlutterAppLifecycleDelegateTest, RespondsToWillBecomeActive)
| TEST (FlutterAppLifecycleDelegateTest, RespondsToDidBecomeActive)
| TEST (FlutterAppLifecycleDelegateTest, RespondsToWillResignActive)
| TEST (FlutterAppLifecycleDelegateTest, RespondsToDidResignActive)
| TEST (FlutterAppLifecycleDelegateTest, RespondsToWillTerminate)
| TEST (FlutterAppLifecycleDelegateTest, RespondsToWillHide)
| TEST (FlutterAppLifecycleDelegateTest, RespondsToWillUnhide)
| TEST (FlutterAppLifecycleDelegateTest, RespondsToDidHide)
| TEST (FlutterAppLifecycleDelegateTest, RespondsToDidUnhide)
| TEST (FlutterAppLifecycleDelegateTest, RespondsToDidChangeScreenParameters)
| TEST (FlutterAppLifecycleDelegateTest, RespondsToDidChangeOcclusionState)
| TEST (FlutterAppLifecycleDelegateTest, ReleasesDelegateOnDealloc)
| TEST_F (FlutterChannelKeyResponderTest, BasicKeyEvent)
| TEST_F (FlutterChannelKeyResponderTest, EmptyResponseIsTakenAsHandled)
| TEST_F (FlutterChannelKeyResponderTest, FollowsLayoutMap)
| TEST_F (FlutterEmbedderExternalTextureTest, TestTextureResolution)
| TEST_F (FlutterEmbedderExternalTextureTest, TestPopulateExternalTexture)
| TEST_F (FlutterEmbedderExternalTextureTest, TestPopulateExternalTextureYUVA)
| TEST_F (FlutterEmbedderExternalTextureTest, TestPopulateExternalTextureYUVA2)
| TEST_F (FlutterEmbedderExternalTextureTest, TestPopulateUnsupportedExternalTexture)
| TEST_F (FlutterEmbedderExternalTextureTest, TestTextureResolutionImpeller)
| TEST_F (FlutterEmbedderExternalTextureTest, TestPopulateExternalTextureImpeller)
| TEST_F (FlutterEmbedderExternalTextureTest, TestPopulateExternalTextureYUVAImpeller)
| TEST_F (FlutterEmbedderExternalTextureTest, TestPopulateExternalTextureYUVA2Impeller)
| TEST_F (FlutterEmbedderExternalTextureTest, TestPopulateUnsupportedExternalTextureImpeller)
| TEST (FlutterEmbedderKeyResponderUnittests, BasicKeyEvent)
| TEST (FlutterEmbedderKeyResponderUnittests, NonAsciiCharacters)
| TEST (FlutterEmbedderKeyResponderUnittests, MultipleCharacters)
| TEST (FlutterEmbedderKeyResponderUnittests, SynthesizeForDuplicateDownEvent)
| TEST (FlutterEmbedderKeyResponderUnittests, IgnoreDuplicateUpEvent)
| TEST (FlutterEmbedderKeyResponderUnittests, ConvertAbruptRepeatEventsToDown)
| TEST (FlutterEmbedderKeyResponderUnittests, ToggleModifiersDuringKeyTap)
| TEST (FlutterEmbedderKeyResponderUnittests, SpecialModiferFlags)
| TEST (FlutterEmbedderKeyResponderUnittests, IdentifyLeftAndRightModifiers)
| TEST (FlutterEmbedderKeyResponderUnittests, SynthesizeMissedModifierEvents)
| TEST (FlutterEmbedderKeyResponderUnittests, SynthesizeMissedModifierEventsInNormalEvents)
| TEST (FlutterEmbedderKeyResponderUnittests, ConvertCapsLockEvents)
| TEST (FlutterEmbedderKeyResponderUnittests, SynchronizeCapsLockStateOnCapsLock)
| TEST (FlutterEmbedderKeyResponderUnittests, SynchronizeCapsLockStateOnNormalKey)
| TEST_F (FlutterEngineTest, CanLaunch)
| TEST_F (FlutterEngineTest, HasNonNullExecutableName)
| TEST_F (FlutterEngineTest, Switches)
| TEST_F (FlutterEngineTest, MessengerSend)
| TEST_F (FlutterEngineTest, CanLogToStdout)
| TEST_F (FlutterEngineTest, DISABLED_BackgroundIsBlack)
| TEST_F (FlutterEngineTest, DISABLED_CanOverrideBackgroundColor)
| TEST_F (FlutterEngineTest, CanToggleAccessibility)
| TEST_F (FlutterEngineTest, CanToggleAccessibilityWhenHeadless)
| TEST_F (FlutterEngineTest, ProducesAccessibilityTreeWhenAddingViews)
| TEST_F (FlutterEngineTest, NativeCallbacks)
| TEST_F (FlutterEngineTest, Compositor)
| TEST_F (FlutterEngineTest, CompositorIgnoresUnknownView)
| TEST_F (FlutterEngineTest, DartEntrypointArguments)
| TEST_F (FlutterEngineTest, FlutterBinaryMessengerDoesNotRetainEngine)
| TEST_F (FlutterEngineTest, FlutterTextureRegistryDoesNotReturnEngine)
| TEST_F (FlutterEngineTest, PublishedValueNilForUnknownPlugin)
| TEST_F (FlutterEngineTest, PublishedValueNSNullIfNoPublishedValue)
| TEST_F (FlutterEngineTest, PublishedValueReturnsLastPublished)
| TEST_F (FlutterEngineTest, MessengerCleanupConnectionWorks)
| TEST_F (FlutterEngineTest, HasStringsWhenPasteboardEmpty)
| TEST_F (FlutterEngineTest, HasStringsWhenPasteboardFull)
| TEST_F (FlutterEngineTest, ResponseAfterEngineDied)
| TEST_F (FlutterEngineTest, ResponseFromBackgroundThread)
| TEST_F (FlutterEngineTest, CanGetEngineForId)
| TEST_F (FlutterEngineTest, ResizeSynchronizerNotBlockingRasterThreadAfterShutdown)
| TEST_F (FlutterEngineTest, ManageControllersIfInitiatedByController)
| TEST_F (FlutterEngineTest, ManageControllersIfInitiatedByEngine)
| TEST_F (FlutterEngineTest, RemovingViewDisposesCompositorResources)
| TEST_F (FlutterEngineTest, HandlesTerminationRequest)
| TEST_F (FlutterEngineTest, IgnoresTerminationRequestIfNotFlutterAppDelegate)
| TEST_F (FlutterEngineTest, HandleAccessibilityEvent)
| TEST_F (FlutterEngineTest, HandleLifecycleStates) API_AVAILABLE(macos(10.9))
| TEST_F (FlutterEngineTest, ForwardsPluginDelegateRegistration)
| TEST_F (FlutterEngineTest, UnregistersPluginsOnEngineDestruction)
| TEST_F (FlutterEngineTest, RunWithEntrypointUpdatesDisplayConfig)
| TEST_F (FlutterEngineTest, NotificationsUpdateDisplays)
| TEST_F (FlutterEngineTest, DisplaySizeIsInPhysicalPixel)
| TEST_F (FlutterEngineTest, ReportsHourFormat)
id | CreateMockFlutterEngine (NSString *pasteboardString)
| TEST (FlutterKeyboardManagerUnittests, SinglePrimaryResponder)
| TEST (FlutterKeyboardManagerUnittests, DoublePrimaryResponder)
| TEST (FlutterKeyboardManagerUnittests, SingleFinalResponder)
| TEST (FlutterKeyboardManagerUnittests, EmptyNextResponder)
| TEST (FlutterKeyboardManagerUnittests, GetPressedState)
| TEST (FlutterKeyboardManagerUnittests, KeyboardChannelGetPressedState)
| TEST (FlutterKeyboardManagerUnittests, RacingConditionBetweenKeyAndText)
| TEST (FlutterKeyboardManagerUnittests, CorrectLogicalKeyForLayouts)
| TEST (FlutterKeyboardManagerUnittests, ShouldNotHoldStrongReferenceToDelegate)
| TEST_F (FlutterMenuPluginTest, TestSetMenu)
| TEST (FlutterPlatformNodeDelegateMac, Basics)
| TEST (FlutterPlatformNodeDelegateMac, SelectableTextHasCorrectSemantics)
| TEST (FlutterPlatformNodeDelegateMac, SelectableTextWithoutSelectionReturnZeroRange)
| TEST (FlutterPlatformNodeDelegateMac, CanPerformAction)
| TEST (FlutterPlatformNodeDelegateMac, TextFieldUsesFlutterTextField)
| TEST (FlutterPlatformNodeDelegateMac, ChangingFlagsUpdatesNativeViewAccessible)
| TEST (FlutterPlatformViewController, TestCreatePlatformViewNoMatchingViewType)
| TEST (FlutterPlatformViewController, TestRegisterPlatformViewFactoryAndCreate)
| TEST (FlutterPlatformViewController, TestCreateAndDispose)
| TEST (FlutterPlatformViewController, TestReset)
| TEST (FlutterPlatformViewController, TestDisposeOnMissingViewId)
| TEST (FlutterPlatformViewController, TestAcceptGesture)
| TEST (FlutterPlatformViewController, TestAcceptGestureOnMissingViewId)
| TEST (FlutterPlatformViewController, TestRejectGesture)
| TEST (FlutterPlatformViewController, TestRejectGestureOnMissingViewId)
static FlutterSurfaceManager * | CreateSurfaceManager (TestView *testView)
static FlutterSurfacePresentInfo * | CreatePresentInfo (FlutterSurface *surface, CGPoint offset=CGPointZero, size_t index=0, const std::vector< FlutterRect > &paintRegion={})
| TEST (FlutterSurfaceManager, MetalTextureSizeMatchesSurfaceSize)
| TEST (FlutterSurfaceManager, TestSurfaceLookupFromTexture)
| TEST (FlutterSurfaceManager, BackBufferCacheDoesNotLeak)
| TEST (FlutterSurfaceManager, SurfacesAreRecycled)
| TEST (FlutterSurfaceManager, BackingStoreCacheSurfaceStuckInUse)
bool | operator== (const CGRect &lhs, const CGRect &rhs)
| TEST (FlutterSurfaceManager, LayerManagement)
| TEST (FlutterTextInputPluginTest, TestEmptyCompositionRange)
| TEST (FlutterTextInputPluginTest, TestSetMarkedTextWithSelectionChange)
| TEST (FlutterTextInputPluginTest, TestSetMarkedTextWithReplacementRange)
| TEST (FlutterTextInputPluginTest, TestComposingRegionRemovedByFramework)
| TEST (FlutterTextInputPluginTest, TestClearClientDuringComposing)
| TEST (FlutterTextInputPluginTest, TestAutocompleteDisabledWhenAutofillNotSet)
| TEST (FlutterTextInputPluginTest, TestAutocompleteEnabledWhenAutofillSet)
| TEST (FlutterTextInputPluginTest, TestAutocompleteEnabledWhenAutofillSetNoHint)
| TEST (FlutterTextInputPluginTest, TestAutocompleteDisabledWhenObscureTextSet)
| TEST (FlutterTextInputPluginTest, TestAutocompleteDisabledWhenPasswordAutofillSet)
| TEST (FlutterTextInputPluginTest, TestAutocompleteDisabledWhenAutofillGroupIncludesPassword)
| TEST (FlutterTextInputPluginTest, TestFirstRectForCharacterRange)
| TEST (FlutterTextInputPluginTest, TestFirstRectForCharacterRangeAtInfinity)
| TEST (FlutterTextInputPluginTest, TestFirstRectForCharacterRangeWithEsotericAffineTransform)
| TEST (FlutterTextInputPluginTest, TestSetEditingStateWithTextEditingDelta)
| TEST (FlutterTextInputPluginTest, TestOperationsThatTriggerDelta)
| TEST (FlutterTextInputPluginTest, TestComposingWithDelta)
| TEST (FlutterTextInputPluginTest, TestComposingWithDeltasWhenSelectionIsActive)
| TEST (FlutterTextInputPluginTest, TestLocalTextAndSelectionUpdateAfterDelta)
| TEST (FlutterTextInputPluginTest, TestPerformKeyEquivalent)
| TEST (FlutterTextInputPluginTest, HandleArrowKeyWhenImePopoverIsActive)
| TEST (FlutterTextInputPluginTest, UnhandledKeyEquivalent)
| TEST (FlutterTextInputPluginTest, TestSelectorsAreForwardedToFramework)
| TEST (FlutterTextInputPluginTest, TestSelectorsNotForwardedToFrameworkIfNoClient)
| TEST (FlutterTextInputPluginTest, TestInsertNewLine)
| TEST (FlutterTextInputPluginTest, TestSendActionDoNotInsertNewLine)
| TEST (FlutterTextInputPluginTest, TestAttributedSubstringOutOfRange)
| TEST (FlutterTextInputPluginTest, CanWorkWithFlutterTextField)
| TEST (FlutterTextInputPluginTest, CanNotBecomeResponderIfNoViewController)
| TEST (FlutterTextInputPluginTest, IsAddedAndRemovedFromViewHierarchy)
| TEST (FlutterTextInputPluginTest, FirstResponderIsCorrect)
| TEST (FlutterTextInputPluginTest, HasZeroSizeAndClipsToBounds)
| TEST (FlutterTextInputSemanticsObjectTest, DoesInitialize)
| TEST_F (FlutterViewControllerTest, HasViewThatHidesOtherViewsInAccessibility)
| TEST_F (FlutterViewControllerTest, FlutterViewAcceptsFirstMouse)
| TEST_F (FlutterViewControllerTest, ReparentsPluginWhenAccessibilityDisabled)
| TEST_F (FlutterViewControllerTest, CanSetMouseTrackingModeBeforeViewLoaded)
| TEST_F (FlutterViewControllerMockEngineTest, TestKeyEventsAreSentToFramework)
| TEST_F (FlutterViewControllerMockEngineTest, TestKeyEventsArePropagatedIfNotHandled)
| TEST_F (FlutterViewControllerMockEngineTest, TestKeyEventsAreNotPropagatedIfHandled)
| TEST_F (FlutterViewControllerMockEngineTest, TestCtrlTabKeyEventIsPropagated)
| TEST_F (FlutterViewControllerMockEngineTest, TestKeyEquivalentIsPassedToTextInputPlugin)
| TEST_F (FlutterViewControllerMockEngineTest, TestFlagsChangedEventsArePropagatedIfNotHandled)
| TEST_F (FlutterViewControllerMockEngineTest, TestKeyboardIsRestartedOnEngineRestart)
| TEST_F (FlutterViewControllerMockEngineTest, TestTrackpadGesturesAreSentToFramework)
| TEST_F (FlutterViewControllerMockEngineTest, TestmouseAndGestureEventsAreHandledSeparately)
| TEST_F (FlutterViewControllerMockEngineTest, TestMouseDownUpEventsSentToNextResponder)
| TEST_F (FlutterViewControllerMockEngineTest, TestModifierKeysAreSynthesizedOnMouseMove)
| TEST_F (FlutterViewControllerMockEngineTest, testViewWillAppearCalledMultipleTimes)
| TEST_F (FlutterViewControllerMockEngineTest, testFlutterViewIsConfigured)
| TEST_F (FlutterViewControllerTest, testLookupKeyAssets)
| TEST_F (FlutterViewControllerTest, testLookupKeyAssetsWithPackage)
| TEST_F (FlutterViewControllerTest, testViewControllerIsReleased)
id | CreateMockViewController ()
| TEST (FlutterViewEngineProviderUnittests, GetViewReturnsTheCorrectView)
| TEST (KeyMappingTest, HasExpectedValues)
FlutterSemanticsNode2 | CreateSemanticsNode (int32_t id, const char *label, const std::vector< int32_t > *children=nullptr)
| TEST (AccessibilityBridgeTest, BasicTest)
| TEST (AccessibilityBridgeTest, AccessibilityRootId)
| TEST (AccessibilityBridgeTest, AddOrder)
| TEST (AccessibilityBridgeTest, CanFireChildrenChangedCorrectly)
| TEST (AccessibilityBridgeTest, CanHandleSelectionChangeCorrectly)
| TEST (AccessibilityBridgeTest, DoesNotAssignEditableRootToSelectableText)
| TEST (AccessibilityBridgeTest, SwitchHasSwitchRole)
| TEST (AccessibilityBridgeTest, SliderHasSliderRole)
| TEST (AccessibilityBridgeTest, CanSetCheckboxChecked)
| TEST (AccessibilityBridgeTest, CanReparentNode)
| TEST (AccessibilityBridgeTest, CanReparentMultipleNodes)
| TEST (AccessibilityBridgeTest, CanReparentNodeWithChild)
| TEST (AccessibilityBridgeTest, AXTreeManagerTest)
| TEST (AccessibilityBridgeTest, LineBreakingObjectTest)
| TEST (FlutterPlatformNodeDelegateTest, NodeDelegateHasUniqueId)
| TEST (FlutterPlatformNodeDelegateTest, canPerfomActions)
| TEST (FlutterPlatformNodeDelegateTest, canGetAXNode)
| TEST (FlutterPlatformNodeDelegateTest, canCalculateBoundsCorrectly)
| TEST (FlutterPlatformNodeDelegateTest, canCalculateOffScreenBoundsCorrectly)
| TEST (FlutterPlatformNodeDelegateTest, canUseOwnerBridge)
| TEST (FlutterPlatformNodeDelegateTest, selfIsLowestPlatformAncestor)
| TEST (FlutterPlatformNodeDelegateTest, canGetFromNodeID)

## Typedef Documentation

## ◆ FlutterChannelKeyResponderTest

using flutter::testing::FlutterChannelKeyResponderTest = typedef AutoreleasePoolTest

Definition at line 73 of file FlutterChannelKeyResponderTest.mm.

## ◆ FlutterEmbedderExternalTextureTest

using flutter::testing::FlutterEmbedderExternalTextureTest = typedef AutoreleasePoolTest

Definition at line 94 of file FlutterEmbedderExternalTextureTest.mm.

## ◆ FlutterViewControllerMockEngineTest

using flutter::testing::FlutterViewControllerMockEngineTest = typedef MockFlutterEngineTest

Definition at line 185 of file FlutterViewControllerTest.mm.

## ◆ FlutterViewControllerTest

using flutter::testing::FlutterViewControllerTest = typedef AutoreleasePoolTest

Definition at line 184 of file FlutterViewControllerTest.mm.

## Function Documentation

## ◆ CreateMockFlutterEngine()

id flutter::testing::CreateMockFlutterEngine | ( | NSString * | pasteboardString | ) |

Definition at line 76 of file FlutterEngineTestUtils.mm.

76 {
77 NSString* fixtures = @(testing::GetFixturesPath());
78 FlutterDartProject* project = [[FlutterDartProject alloc]
79 initWithAssetsPath:fixtures
80 ICUDataPath:[fixtures stringByAppendingString:@"/icudtl.dat"]];
81 FlutterEngine* engine = [[FlutterEngine alloc] initWithName:@"test"
82 project:project
83 allowHeadlessExecution:true];
84
85 FakePasteboard* pasteboardMock = [[FakePasteboard alloc] init];
86 [pasteboardMock setString:pasteboardString forType:NSPasteboardTypeString];
87 engine.pasteboard = pasteboardMock;
88 id engineMock = OCMPartialMock(engine);
89 return engineMock;
90 }
FlutterDartProject
Definition: FlutterDartProject.mm:24
FakePasteboard
Definition: FlutterEngineTestUtils.mm:18
FlutterEngine
Definition: FlutterEngine.h:32

References FlutterPasteboard::setString:forType:.

Referenced by flutter::testing::MockFlutterEngineTest::SetUp(), TEST(), and TEST_F().

## ◆ CreateMockViewController()

id flutter::testing::CreateMockViewController | ( |  | ) |

Definition at line 9 of file FlutterViewControllerTestUtils.mm.

9 {
10 {
11 NSString* fixtures = @(testing::GetFixturesPath());
12 FlutterDartProject* project = [[FlutterDartProject alloc]
13 initWithAssetsPath:fixtures
14 ICUDataPath:[fixtures stringByAppendingString:@"/icudtl.dat"]];
15 FlutterViewController* viewController = [[FlutterViewController alloc] initWithProject:project];
16 id viewControllerMock = OCMPartialMock(viewController);
17 return viewControllerMock;
18 }
19 }
FlutterViewController
Definition: FlutterViewController.h:73

Referenced by TEST_F().

## ◆ CreatePresentInfo()

static FlutterSurfacePresentInfo* flutter::testing::CreatePresentInfo | ( | FlutterSurface * | surface,
|  | CGPoint | offset = `CGPointZero`,
|  | size_t | index = `0`,
|  | const std::vector< FlutterRect > & | paintRegion = `{}`
| ) |  |
| static

Definition at line 53 of file FlutterSurfaceManagerTest.mm.

57 {}) {
58 FlutterSurfacePresentInfo* res = [[FlutterSurfacePresentInfo alloc] init];
59 res.surface = surface;
60 res.offset = offset;
61 res.zIndex = index;
62 res.paintRegion = paintRegion;
63 return res;
64 }
FlutterSurfacePresentInfo
Definition: FlutterSurfaceManager.h:19
FlutterSurfacePresentInfo::surface
FlutterSurface * surface
Definition: FlutterSurfaceManager.h:20
FlutterSurfacePresentInfo::paintRegion
std::vector< FlutterRect > paintRegion
Definition: FlutterSurfaceManager.h:23
FlutterSurfacePresentInfo::offset
CGPoint offset
Definition: FlutterSurfaceManager.h:21
FlutterSurfacePresentInfo::zIndex
size_t zIndex
Definition: FlutterSurfaceManager.h:22

## ◆ CreateSemanticsNode()

FlutterSemanticsNode2 flutter::testing::CreateSemanticsNode | ( | int32_t | id,
|  | const char * | label,
|  | const std::vector< int32_t > * | children = `nullptr`
| ) |  |

Definition at line 18 of file accessibility_bridge_unittests.cc.

21 {
22 return {
23 .id = id,
24 .flags = static_cast<FlutterSemanticsFlag>(0),
25 .actions = static_cast<FlutterSemanticsAction>(0),
26 .text_selection_base = -1,
27 .text_selection_extent = -1,
28 .label = label,
29 .hint = "",
30 .value = "",
31 .increased_value = "",
32 .decreased_value = "",
33 .child_count = children ? children->size() : 0,
34 .children_in_traversal_order = children ? children->data() : nullptr,
35 .custom_accessibility_actions_count = 0,
36 .tooltip = "",
37 };
38 }

Referenced by TEST().

## ◆ CreateSurfaceManager()

static FlutterSurfaceManager* flutter::testing::CreateSurfaceManager | ( | TestView * | testView | ) |
| static

Definition at line 43 of file FlutterSurfaceManagerTest.mm.

43 {
44 id<MTLDevice> device = MTLCreateSystemDefaultDevice();
45 id<MTLCommandQueue> commandQueue = [device newCommandQueue];
46 CALayer* layer = reinterpret_cast<CALayer*>(testView.layer);
47 return [[FlutterSurfaceManager alloc] initWithDevice:device
48 commandQueue:commandQueue
49 layer:layer
50 delegate:testView];
51 }
FlutterSurfaceManager
Definition: FlutterSurfaceManager.h:47

Referenced by TEST().

## ◆ operator==()

bool flutter::testing::operator== | ( | const CGRect & | lhs,
|  | const CGRect & | rhs
| ) |  |
| inline

Definition at line 200 of file FlutterSurfaceManagerTest.mm.

200 {
201 return CGRectEqualToRect(lhs, rhs);
202 }

## ◆ TEST() [1/118]

flutter::testing::TEST | ( | AccessibilityBridgeTest | ,
|  | AccessibilityRootId |
| ) |  |

Definition at line 72 of file accessibility_bridge_unittests.cc.

72 {
73 std::shared_ptr<TestAccessibilityBridge> bridge =
74 std::make_shared<TestAccessibilityBridge>();
75
76 std::vector<int32_t> children{456, 789};
77 FlutterSemanticsNode2 root = CreateSemanticsNode(123, "root", &children);
78 FlutterSemanticsNode2 child1 = CreateSemanticsNode(456, "child 1");
79 FlutterSemanticsNode2 child2 = CreateSemanticsNode(789, "child 2");
80
81 bridge->AddFlutterSemanticsNodeUpdate(root);
82 bridge->AddFlutterSemanticsNodeUpdate(child1);
83 bridge->AddFlutterSemanticsNodeUpdate(child2);
84 bridge->CommitUpdates();
85
86 auto root_node = bridge->GetFlutterPlatformNodeDelegateFromID(123).lock();
87 auto child1_node = bridge->GetFlutterPlatformNodeDelegateFromID(456).lock();
88 auto child2_node = bridge->GetFlutterPlatformNodeDelegateFromID(789).lock();
89 auto fake_delegate = bridge->GetFlutterPlatformNodeDelegateFromID(0).lock();
90
91 EXPECT_EQ(bridge->GetRootAsAXNode()->id(), 123);
92 EXPECT_EQ(bridge->RootDelegate()->GetName(), "root");
93
94 EXPECT_EQ(root_node->GetChildCount(), 2);
95 EXPECT_EQ(root_node->GetData().child_ids[0], 456);
96 EXPECT_EQ(root_node->GetData().child_ids[1], 789);
97 EXPECT_EQ(root_node->GetName(), "root");
98
99 EXPECT_EQ(child1_node->GetChildCount(), 0);
100 EXPECT_EQ(child1_node->GetName(), "child 1");
101
102 EXPECT_EQ(child2_node->GetChildCount(), 0);
103 EXPECT_EQ(child2_node->GetName(), "child 2");
104
105 ASSERT_FALSE(fake_delegate);
106 }
flutter::testing::CreateSemanticsNode
FlutterSemanticsNode2 CreateSemanticsNode(int32_t id, const char *label, const std::vector< int32_t > *children=nullptr)
Definition: accessibility_bridge_unittests.cc:18

References CreateSemanticsNode().

## ◆ TEST() [2/118]

flutter::testing::TEST | ( | AccessibilityBridgeTest | ,
|  | AddOrder |
| ) |  |

Definition at line 109 of file accessibility_bridge_unittests.cc.

109 {
110 std::shared_ptr<TestAccessibilityBridge> bridge =
111 std::make_shared<TestAccessibilityBridge>();
112
113 std::vector<int32_t> root_children{34, 56};
114 std::vector<int32_t> child2_children{78};
115 std::vector<int32_t> child3_children{90};
116 FlutterSemanticsNode2 root = CreateSemanticsNode(12, "root", &root_children);
117 FlutterSemanticsNode2 child1 = CreateSemanticsNode(34, "child 1");
118 FlutterSemanticsNode2 child2 =
119 CreateSemanticsNode(56, "child 2", &child2_children);
120 FlutterSemanticsNode2 child3 =
121 CreateSemanticsNode(78, "child 3", &child3_children);
122 FlutterSemanticsNode2 child4 = CreateSemanticsNode(90, "child 4");
123
124 bridge->AddFlutterSemanticsNodeUpdate(child3);
125 bridge->AddFlutterSemanticsNodeUpdate(child2);
126 bridge->AddFlutterSemanticsNodeUpdate(root);
127 bridge->AddFlutterSemanticsNodeUpdate(child1);
128 bridge->AddFlutterSemanticsNodeUpdate(child4);
129 bridge->CommitUpdates();
130
131 auto root_node = bridge->GetFlutterPlatformNodeDelegateFromID(12).lock();
132 auto child1_node = bridge->GetFlutterPlatformNodeDelegateFromID(34).lock();
133 auto child2_node = bridge->GetFlutterPlatformNodeDelegateFromID(56).lock();
134 auto child3_node = bridge->GetFlutterPlatformNodeDelegateFromID(78).lock();
135 auto child4_node = bridge->GetFlutterPlatformNodeDelegateFromID(90).lock();
136
137 EXPECT_EQ(bridge->GetRootAsAXNode()->id(), 12);
138 EXPECT_EQ(bridge->RootDelegate()->GetName(), "root");
139
140 EXPECT_EQ(root_node->GetChildCount(), 2);
141 EXPECT_EQ(root_node->GetData().child_ids[0], 34);
142 EXPECT_EQ(root_node->GetData().child_ids[1], 56);
143 EXPECT_EQ(root_node->GetName(), "root");
144
145 EXPECT_EQ(child1_node->GetChildCount(), 0);
146 EXPECT_EQ(child1_node->GetName(), "child 1");
147
148 EXPECT_EQ(child2_node->GetChildCount(), 1);
149 EXPECT_EQ(child2_node->GetData().child_ids[0], 78);
150 EXPECT_EQ(child2_node->GetName(), "child 2");
151
152 EXPECT_EQ(child3_node->GetChildCount(), 1);
153 EXPECT_EQ(child3_node->GetData().child_ids[0], 90);
154 EXPECT_EQ(child3_node->GetName(), "child 3");
155
156 EXPECT_EQ(child4_node->GetChildCount(), 0);
157 EXPECT_EQ(child4_node->GetName(), "child 4");
158 }

References CreateSemanticsNode().

## ◆ TEST() [3/118]

flutter::testing::TEST | ( | AccessibilityBridgeTest | ,
|  | AXTreeManagerTest |
| ) |  |

Definition at line 546 of file accessibility_bridge_unittests.cc.

546 {
547 std::shared_ptr<TestAccessibilityBridge> bridge =
548 std::make_shared<TestAccessibilityBridge>();
549
550 ui::AXTreeID tree_id = bridge->GetTreeID();
551 ui::AXTreeManager* manager =
552 ui::AXTreeManagerMap::GetInstance().GetManager(tree_id);
553 ASSERT_EQ(manager, static_cast<ui::AXTreeManager*>(bridge.get()));
554 }

## ◆ TEST() [4/118]

flutter::testing::TEST | ( | AccessibilityBridgeTest | ,
|  | BasicTest |
| ) |  |

Definition at line 40 of file accessibility_bridge_unittests.cc.

40 {
41 std::shared_ptr<TestAccessibilityBridge> bridge =
42 std::make_shared<TestAccessibilityBridge>();
43
44 std::vector<int32_t> children{1, 2};
45 FlutterSemanticsNode2 root = CreateSemanticsNode(0, "root", &children);
46 FlutterSemanticsNode2 child1 = CreateSemanticsNode(1, "child 1");
47 FlutterSemanticsNode2 child2 = CreateSemanticsNode(2, "child 2");
48
49 bridge->AddFlutterSemanticsNodeUpdate(root);
50 bridge->AddFlutterSemanticsNodeUpdate(child1);
51 bridge->AddFlutterSemanticsNodeUpdate(child2);
52 bridge->CommitUpdates();
53
54 auto root_node = bridge->GetFlutterPlatformNodeDelegateFromID(0).lock();
55 auto child1_node = bridge->GetFlutterPlatformNodeDelegateFromID(1).lock();
56 auto child2_node = bridge->GetFlutterPlatformNodeDelegateFromID(2).lock();
57 EXPECT_EQ(root_node->GetChildCount(), 2);
58 EXPECT_EQ(root_node->GetData().child_ids[0], 1);
59 EXPECT_EQ(root_node->GetData().child_ids[1], 2);
60 EXPECT_EQ(root_node->GetName(), "root");
61
62 EXPECT_EQ(child1_node->GetChildCount(), 0);
63 EXPECT_EQ(child1_node->GetName(), "child 1");
64
65 EXPECT_EQ(child2_node->GetChildCount(), 0);
66 EXPECT_EQ(child2_node->GetName(), "child 2");
67 }

References CreateSemanticsNode().

## ◆ TEST() [5/118]

flutter::testing::TEST | ( | AccessibilityBridgeTest | ,
|  | CanFireChildrenChangedCorrectly |
| ) |  |

Definition at line 160 of file accessibility_bridge_unittests.cc.

160 {
161 std::shared_ptr<TestAccessibilityBridge> bridge =
162 std::make_shared<TestAccessibilityBridge>();
163
164 std::vector<int32_t> children{1};
165 FlutterSemanticsNode2 root = CreateSemanticsNode(0, "root", &children);
166 FlutterSemanticsNode2 child1 = CreateSemanticsNode(1, "child 1");
167
168 bridge->AddFlutterSemanticsNodeUpdate(root);
169 bridge->AddFlutterSemanticsNodeUpdate(child1);
170
171 bridge->CommitUpdates();
172
173 auto root_node = bridge->GetFlutterPlatformNodeDelegateFromID(0).lock();
174 auto child1_node = bridge->GetFlutterPlatformNodeDelegateFromID(1).lock();
175 EXPECT_EQ(root_node->GetChildCount(), 1);
176 EXPECT_EQ(root_node->GetData().child_ids[0], 1);
177 EXPECT_EQ(root_node->GetName(), "root");
178
179 EXPECT_EQ(child1_node->GetChildCount(), 0);
180 EXPECT_EQ(child1_node->GetName(), "child 1");
181 bridge->accessibility_events.clear();
182
183 // Add a child to root.
184 root.child_count = 2;
185 int32_t new_children[] = {1, 2};
186 root.children_in_traversal_order = new_children;
187
188 FlutterSemanticsNode2 child2 = CreateSemanticsNode(2, "child 2");
189
190 bridge->AddFlutterSemanticsNodeUpdate(root);
191 bridge->AddFlutterSemanticsNodeUpdate(child2);
192 bridge->CommitUpdates();
193
194 root_node = bridge->GetFlutterPlatformNodeDelegateFromID(0).lock();
195
196 EXPECT_EQ(root_node->GetChildCount(), 2);
197 EXPECT_EQ(root_node->GetData().child_ids[0], 1);
198 EXPECT_EQ(root_node->GetData().child_ids[1], 2);
199 EXPECT_EQ(bridge->accessibility_events.size(), size_t{2});
200 std::set<ui::AXEventGenerator::Event> actual_event{
201 bridge->accessibility_events.begin(), bridge->accessibility_events.end()};
202 EXPECT_THAT(actual_event,
203 Contains(ui::AXEventGenerator::Event::CHILDREN_CHANGED));
204 EXPECT_THAT(actual_event,
205 Contains(ui::AXEventGenerator::Event::SUBTREE_CREATED));
206 }

References CreateSemanticsNode().

## ◆ TEST() [6/118]

flutter::testing::TEST | ( | AccessibilityBridgeTest | ,
|  | CanHandleSelectionChangeCorrectly |
| ) |  |

Definition at line 208 of file accessibility_bridge_unittests.cc.

208 {
209 std::shared_ptr<TestAccessibilityBridge> bridge =
210 std::make_shared<TestAccessibilityBridge>();
211 FlutterSemanticsNode2 root = CreateSemanticsNode(0, "root");
212 root.flags = static_cast<FlutterSemanticsFlag>(
213 FlutterSemanticsFlag::kFlutterSemanticsFlagIsTextField |
214 FlutterSemanticsFlag::kFlutterSemanticsFlagIsFocused);
215 bridge->AddFlutterSemanticsNodeUpdate(root);
216 bridge->CommitUpdates();
217
218 const ui::AXTreeData& tree = bridge->GetAXTreeData();
219 EXPECT_EQ(tree.sel_anchor_object_id, ui::AXNode::kInvalidAXID);
220 bridge->accessibility_events.clear();
221
222 // Update the selection.
223 root.text_selection_base = 0;
224 root.text_selection_extent = 5;
225 bridge->AddFlutterSemanticsNodeUpdate(root);
226
227 bridge->CommitUpdates();
228
229 EXPECT_EQ(tree.sel_anchor_object_id, 0);
230 EXPECT_EQ(tree.sel_anchor_offset, 0);
231 EXPECT_EQ(tree.sel_focus_object_id, 0);
232 EXPECT_EQ(tree.sel_focus_offset, 5);
233 ASSERT_EQ(bridge->accessibility_events.size(), size_t{2});
234 EXPECT_EQ(bridge->accessibility_events[0],
235 ui::AXEventGenerator::Event::DOCUMENT_SELECTION_CHANGED);
236 EXPECT_EQ(bridge->accessibility_events[1],
237 ui::AXEventGenerator::Event::OTHER_ATTRIBUTE_CHANGED);
238 }

References CreateSemanticsNode().

## ◆ TEST() [7/118]

flutter::testing::TEST | ( | AccessibilityBridgeTest | ,
|  | CanReparentMultipleNodes |
| ) |  |

Definition at line 372 of file accessibility_bridge_unittests.cc.

372 {
373 std::shared_ptr<TestAccessibilityBridge> bridge =
374 std::make_shared<TestAccessibilityBridge>();
375
376 int32_t root_id = 0;
377 int32_t intermediary1_id = 1;
378 int32_t intermediary2_id = 2;
379 int32_t leaf1_id = 3;
380 int32_t leaf2_id = 4;
381 int32_t leaf3_id = 5;
382
383 std::vector<int32_t> root_children{intermediary1_id, intermediary2_id};
384 std::vector<int32_t> intermediary1_children{leaf1_id};
385 std::vector<int32_t> intermediary2_children{leaf2_id, leaf3_id};
386 FlutterSemanticsNode2 root =
387 CreateSemanticsNode(root_id, "root", &root_children);
388 FlutterSemanticsNode2 intermediary1 = CreateSemanticsNode(
389 intermediary1_id, "intermediary 1", &intermediary1_children);
390 FlutterSemanticsNode2 intermediary2 = CreateSemanticsNode(
391 intermediary2_id, "intermediary 2", &intermediary2_children);
392 FlutterSemanticsNode2 leaf1 = CreateSemanticsNode(leaf1_id, "leaf 1");
393 FlutterSemanticsNode2 leaf2 = CreateSemanticsNode(leaf2_id, "leaf 2");
394 FlutterSemanticsNode2 leaf3 = CreateSemanticsNode(leaf3_id, "leaf 3");
395
396 bridge->AddFlutterSemanticsNodeUpdate(root);
397 bridge->AddFlutterSemanticsNodeUpdate(intermediary1);
398 bridge->AddFlutterSemanticsNodeUpdate(intermediary2);
399 bridge->AddFlutterSemanticsNodeUpdate(leaf1);
400 bridge->AddFlutterSemanticsNodeUpdate(leaf2);
401 bridge->AddFlutterSemanticsNodeUpdate(leaf3);
402 bridge->CommitUpdates();
403 bridge->accessibility_events.clear();
404
405 // Swap intermediary 1's and intermediary2's children.
406 int32_t new_intermediary1_children[] = {leaf2_id, leaf3_id};
407 intermediary1.child_count = 2;
408 intermediary1.children_in_traversal_order = new_intermediary1_children;
409
410 int32_t new_intermediary2_children[] = {leaf1_id};
411 intermediary2.child_count = 1;
412 intermediary2.children_in_traversal_order = new_intermediary2_children;
413
414 bridge->AddFlutterSemanticsNodeUpdate(intermediary1);
415 bridge->AddFlutterSemanticsNodeUpdate(intermediary2);
416 bridge->AddFlutterSemanticsNodeUpdate(leaf1);
417 bridge->AddFlutterSemanticsNodeUpdate(leaf2);
418 bridge->AddFlutterSemanticsNodeUpdate(leaf3);
419 bridge->CommitUpdates();
420
421 auto root_node = bridge->GetFlutterPlatformNodeDelegateFromID(root_id).lock();
422 auto intermediary1_node =
423 bridge->GetFlutterPlatformNodeDelegateFromID(intermediary1_id).lock();
424 auto intermediary2_node =
425 bridge->GetFlutterPlatformNodeDelegateFromID(intermediary2_id).lock();
426 auto leaf1_node =
427 bridge->GetFlutterPlatformNodeDelegateFromID(leaf1_id).lock();
428 auto leaf2_node =
429 bridge->GetFlutterPlatformNodeDelegateFromID(leaf2_id).lock();
430 auto leaf3_node =
431 bridge->GetFlutterPlatformNodeDelegateFromID(leaf3_id).lock();
432
433 EXPECT_EQ(root_node->GetChildCount(), 2);
434 EXPECT_EQ(root_node->GetData().child_ids[0], intermediary1_id);
435 EXPECT_EQ(root_node->GetData().child_ids[1], intermediary2_id);
436 EXPECT_EQ(root_node->GetName(), "root");
437
438 EXPECT_EQ(intermediary1_node->GetChildCount(), 2);
439 EXPECT_EQ(intermediary1_node->GetData().child_ids[0], leaf2_id);
440 EXPECT_EQ(intermediary1_node->GetData().child_ids[1], leaf3_id);
441 EXPECT_EQ(intermediary1_node->GetName(), "intermediary 1");
442
443 EXPECT_EQ(intermediary2_node->GetChildCount(), 1);
444 EXPECT_EQ(intermediary2_node->GetData().child_ids[0], leaf1_id);
445 EXPECT_EQ(intermediary2_node->GetName(), "intermediary 2");
446
447 EXPECT_EQ(leaf1_node->GetChildCount(), 0);
448 EXPECT_EQ(leaf1_node->GetName(), "leaf 1");
449
450 EXPECT_EQ(leaf2_node->GetChildCount(), 0);
451 EXPECT_EQ(leaf2_node->GetName(), "leaf 2");
452
453 EXPECT_EQ(leaf3_node->GetChildCount(), 0);
454 EXPECT_EQ(leaf3_node->GetName(), "leaf 3");
455
456 // Intermediary 1 and intermediary 2 have new children.
457 // Leaf 1, 2, and 3 are all moved.
458 ASSERT_EQ(bridge->accessibility_events.size(), size_t{5});
459 EXPECT_THAT(bridge->accessibility_events,
460 Contains(ui::AXEventGenerator::Event::CHILDREN_CHANGED).Times(2));
461 EXPECT_THAT(bridge->accessibility_events,
462 Contains(ui::AXEventGenerator::Event::SUBTREE_CREATED).Times(3));
463 }

References CreateSemanticsNode().

## ◆ TEST() [8/118]

flutter::testing::TEST | ( | AccessibilityBridgeTest | ,
|  | CanReparentNode |
| ) |  |

Definition at line 309 of file accessibility_bridge_unittests.cc.

309 {
310 std::shared_ptr<TestAccessibilityBridge> bridge =
311 std::make_shared<TestAccessibilityBridge>();
312
313 std::vector<int32_t> root_children{1};
314 std::vector<int32_t> child1_children{2};
315 FlutterSemanticsNode2 root = CreateSemanticsNode(0, "root", &root_children);
316 FlutterSemanticsNode2 child1 =
317 CreateSemanticsNode(1, "child 1", &child1_children);
318 FlutterSemanticsNode2 child2 = CreateSemanticsNode(2, "child 2");
319
320 bridge->AddFlutterSemanticsNodeUpdate(root);
321 bridge->AddFlutterSemanticsNodeUpdate(child1);
322 bridge->AddFlutterSemanticsNodeUpdate(child2);
323 bridge->CommitUpdates();
324 bridge->accessibility_events.clear();
325
326 // Reparent child2 from child1 to the root.
327 child1.child_count = 0;
328 child1.children_in_traversal_order = nullptr;
329
330 int32_t new_root_children[] = {1, 2};
331 root.child_count = 2;
332 root.children_in_traversal_order = new_root_children;
333
334 bridge->AddFlutterSemanticsNodeUpdate(root);
335 bridge->AddFlutterSemanticsNodeUpdate(child1);
336 bridge->AddFlutterSemanticsNodeUpdate(child2);
337 bridge->CommitUpdates();
338
339 auto root_node = bridge->GetFlutterPlatformNodeDelegateFromID(0).lock();
340 auto child1_node = bridge->GetFlutterPlatformNodeDelegateFromID(1).lock();
341 auto child2_node = bridge->GetFlutterPlatformNodeDelegateFromID(2).lock();
342
343 EXPECT_EQ(root_node->GetChildCount(), 2);
344 EXPECT_EQ(root_node->GetData().child_ids[0], 1);
345 EXPECT_EQ(root_node->GetData().child_ids[1], 2);
346 EXPECT_EQ(root_node->GetName(), "root");
347
348 EXPECT_EQ(child1_node->GetChildCount(), 0);
349 EXPECT_EQ(child1_node->GetName(), "child 1");
350
351 EXPECT_EQ(child2_node->GetChildCount(), 0);
352 EXPECT_EQ(child2_node->GetName(), "child 2");
353
354 ASSERT_EQ(bridge->accessibility_events.size(), size_t{5});
355
356 // Child2 is moved from child1 to root.
357 EXPECT_THAT(bridge->accessibility_events,
358 Contains(ui::AXEventGenerator::Event::CHILDREN_CHANGED).Times(2));
359 EXPECT_THAT(bridge->accessibility_events,
360 Contains(ui::AXEventGenerator::Event::SUBTREE_CREATED).Times(1));
361
362 // Child1 is no longer a parent. It loses its group role and disables its
363 // 'clip children' attribute.
364 EXPECT_THAT(
365 bridge->accessibility_events,
366 Contains(ui::AXEventGenerator::Event::OTHER_ATTRIBUTE_CHANGED).Times(1));
367 EXPECT_THAT(bridge->accessibility_events,
368 Contains(ui::AXEventGenerator::Event::ROLE_CHANGED).Times(1));
369 }

References CreateSemanticsNode().

## ◆ TEST() [9/118]

flutter::testing::TEST | ( | AccessibilityBridgeTest | ,
|  | CanReparentNodeWithChild |
| ) |  |

Definition at line 466 of file accessibility_bridge_unittests.cc.

466 {
467 std::shared_ptr<TestAccessibilityBridge> bridge =
468 std::make_shared<TestAccessibilityBridge>();
469
470 int32_t root_id = 0;
471 int32_t intermediary1_id = 1;
472 int32_t intermediary2_id = 2;
473 int32_t leaf1_id = 3;
474
475 std::vector<int32_t> root_children{intermediary1_id, intermediary2_id};
476 std::vector<int32_t> intermediary1_children{leaf1_id};
477 FlutterSemanticsNode2 root =
478 CreateSemanticsNode(root_id, "root", &root_children);
479 FlutterSemanticsNode2 intermediary1 = CreateSemanticsNode(
480 intermediary1_id, "intermediary 1", &intermediary1_children);
481 FlutterSemanticsNode2 intermediary2 =
482 CreateSemanticsNode(intermediary2_id, "intermediary 2");
483 FlutterSemanticsNode2 leaf1 = CreateSemanticsNode(leaf1_id, "leaf 1");
484
485 bridge->AddFlutterSemanticsNodeUpdate(root);
486 bridge->AddFlutterSemanticsNodeUpdate(intermediary1);
487 bridge->AddFlutterSemanticsNodeUpdate(intermediary2);
488 bridge->AddFlutterSemanticsNodeUpdate(leaf1);
489 bridge->CommitUpdates();
490 bridge->accessibility_events.clear();
491
492 // Move intermediary1 from root to intermediary 2.
493 int32_t new_root_children[] = {intermediary2_id};
494 root.child_count = 1;
495 root.children_in_traversal_order = new_root_children;
496
497 int32_t new_intermediary2_children[] = {intermediary1_id};
498 intermediary2.child_count = 1;
499 intermediary2.children_in_traversal_order = new_intermediary2_children;
500
501 bridge->AddFlutterSemanticsNodeUpdate(root);
502 bridge->AddFlutterSemanticsNodeUpdate(intermediary1);
503 bridge->AddFlutterSemanticsNodeUpdate(intermediary2);
504 bridge->AddFlutterSemanticsNodeUpdate(leaf1);
505 bridge->CommitUpdates();
506
507 auto root_node = bridge->GetFlutterPlatformNodeDelegateFromID(root_id).lock();
508 auto intermediary1_node =
509 bridge->GetFlutterPlatformNodeDelegateFromID(intermediary1_id).lock();
510 auto intermediary2_node =
511 bridge->GetFlutterPlatformNodeDelegateFromID(intermediary2_id).lock();
512 auto leaf1_node =
513 bridge->GetFlutterPlatformNodeDelegateFromID(leaf1_id).lock();
514
515 EXPECT_EQ(root_node->GetChildCount(), 1);
516 EXPECT_EQ(root_node->GetData().child_ids[0], intermediary2_id);
517 EXPECT_EQ(root_node->GetName(), "root");
518
519 EXPECT_EQ(intermediary2_node->GetChildCount(), 1);
520 EXPECT_EQ(intermediary2_node->GetData().child_ids[0], intermediary1_id);
521 EXPECT_EQ(intermediary2_node->GetName(), "intermediary 2");
522
523 EXPECT_EQ(intermediary1_node->GetChildCount(), 1);
524 EXPECT_EQ(intermediary1_node->GetData().child_ids[0], leaf1_id);
525 EXPECT_EQ(intermediary1_node->GetName(), "intermediary 1");
526
527 EXPECT_EQ(leaf1_node->GetChildCount(), 0);
528 EXPECT_EQ(leaf1_node->GetName(), "leaf 1");
529
530 ASSERT_EQ(bridge->accessibility_events.size(), size_t{5});
531
532 EXPECT_THAT(bridge->accessibility_events,
533 Contains(ui::AXEventGenerator::Event::CHILDREN_CHANGED).Times(2));
534 EXPECT_THAT(bridge->accessibility_events,
535 Contains(ui::AXEventGenerator::Event::SUBTREE_CREATED).Times(1));
536
537 // Intermediary 2 becomes a parent node. It updates to group role and enables
538 // its 'clip children' attribute.
539 EXPECT_THAT(
540 bridge->accessibility_events,
541 Contains(ui::AXEventGenerator::Event::OTHER_ATTRIBUTE_CHANGED).Times(1));
542 EXPECT_THAT(bridge->accessibility_events,
543 Contains(ui::AXEventGenerator::Event::ROLE_CHANGED).Times(1));
544 }

References CreateSemanticsNode().

## ◆ TEST() [10/118]

flutter::testing::TEST | ( | AccessibilityBridgeTest | ,
|  | CanSetCheckboxChecked |
| ) |  |

Definition at line 292 of file accessibility_bridge_unittests.cc.

292 {
293 std::shared_ptr<TestAccessibilityBridge> bridge =
294 std::make_shared<TestAccessibilityBridge>();
295 FlutterSemanticsNode2 root = CreateSemanticsNode(0, "root");
296 root.flags = static_cast<FlutterSemanticsFlag>(
297 FlutterSemanticsFlag::kFlutterSemanticsFlagHasCheckedState |
298 FlutterSemanticsFlag::kFlutterSemanticsFlagIsChecked);
299 bridge->AddFlutterSemanticsNodeUpdate(root);
300 bridge->CommitUpdates();
301
302 auto root_node = bridge->GetFlutterPlatformNodeDelegateFromID(0).lock();
303 EXPECT_EQ(root_node->GetData().role, ax::mojom::Role::kCheckBox);
304 EXPECT_EQ(root_node->GetData().GetCheckedState(),
305 ax::mojom::CheckedState::kTrue);
306 }

References CreateSemanticsNode().

## ◆ TEST() [11/118]

flutter::testing::TEST | ( | AccessibilityBridgeTest | ,
|  | DoesNotAssignEditableRootToSelectableText |
| ) |  |

Definition at line 240 of file accessibility_bridge_unittests.cc.

240 {
241 std::shared_ptr<TestAccessibilityBridge> bridge =
242 std::make_shared<TestAccessibilityBridge>();
243 FlutterSemanticsNode2 root = CreateSemanticsNode(0, "root");
244 root.flags = static_cast<FlutterSemanticsFlag>(
245 FlutterSemanticsFlag::kFlutterSemanticsFlagIsTextField |
246 FlutterSemanticsFlag::kFlutterSemanticsFlagIsReadOnly);
247 bridge->AddFlutterSemanticsNodeUpdate(root);
248 bridge->CommitUpdates();
249
250 auto root_node = bridge->GetFlutterPlatformNodeDelegateFromID(0).lock();
251
252 EXPECT_FALSE(root_node->GetData().GetBoolAttribute(
253 ax::mojom::BoolAttribute::kEditableRoot));
254 }

References CreateSemanticsNode().

## ◆ TEST() [12/118]

flutter::testing::TEST | ( | AccessibilityBridgeTest | ,
|  | LineBreakingObjectTest |
| ) |  |

Definition at line 556 of file accessibility_bridge_unittests.cc.

556 {
557 std::shared_ptr<TestAccessibilityBridge> bridge =
558 std::make_shared<TestAccessibilityBridge>();
559
560 const int32_t root_id = 0;
561
562 FlutterSemanticsNode2 root = CreateSemanticsNode(root_id, "root", {});
563
564 bridge->AddFlutterSemanticsNodeUpdate(root);
565 bridge->CommitUpdates();
566
567 auto root_node = bridge->GetFlutterPlatformNodeDelegateFromID(root_id).lock();
568 auto root_data = root_node->GetData();
569 EXPECT_TRUE(root_data.HasBoolAttribute(
570 ax::mojom::BoolAttribute::kIsLineBreakingObject));
571 EXPECT_TRUE(root_data.GetBoolAttribute(
572 ax::mojom::BoolAttribute::kIsLineBreakingObject));
573 }

References CreateSemanticsNode().

## ◆ TEST() [13/118]

flutter::testing::TEST | ( | AccessibilityBridgeTest | ,
|  | SliderHasSliderRole |
| ) |  |

Definition at line 271 of file accessibility_bridge_unittests.cc.

271 {
272 std::shared_ptr<TestAccessibilityBridge> bridge =
273 std::make_shared<TestAccessibilityBridge>();
274 FlutterSemanticsNode2 root = CreateSemanticsNode(0, "root");
275 root.flags = static_cast<FlutterSemanticsFlag>(
276 FlutterSemanticsFlag::kFlutterSemanticsFlagIsSlider |
277 FlutterSemanticsFlag::kFlutterSemanticsFlagHasEnabledState |
278 FlutterSemanticsFlag::kFlutterSemanticsFlagIsEnabled |
279 FlutterSemanticsFlag::kFlutterSemanticsFlagIsFocusable);
280 bridge->AddFlutterSemanticsNodeUpdate(root);
281 bridge->CommitUpdates();
282
283 auto root_node = bridge->GetFlutterPlatformNodeDelegateFromID(0).lock();
284 EXPECT_EQ(root_node->GetData().role, ax::mojom::Role::kSlider);
285 }

References CreateSemanticsNode().

## ◆ TEST() [14/118]

flutter::testing::TEST | ( | AccessibilityBridgeTest | ,
|  | SwitchHasSwitchRole |
| ) |  |

Definition at line 256 of file accessibility_bridge_unittests.cc.

256 {
257 std::shared_ptr<TestAccessibilityBridge> bridge =
258 std::make_shared<TestAccessibilityBridge>();
259 FlutterSemanticsNode2 root = CreateSemanticsNode(0, "root");
260 root.flags = static_cast<FlutterSemanticsFlag>(
261 FlutterSemanticsFlag::kFlutterSemanticsFlagHasToggledState |
262 FlutterSemanticsFlag::kFlutterSemanticsFlagHasEnabledState |
263 FlutterSemanticsFlag::kFlutterSemanticsFlagIsEnabled);
264 bridge->AddFlutterSemanticsNodeUpdate(root);
265 bridge->CommitUpdates();
266
267 auto root_node = bridge->GetFlutterPlatformNodeDelegateFromID(0).lock();
268 EXPECT_EQ(root_node->GetData().role, ax::mojom::Role::kSwitch);
269 }

References CreateSemanticsNode().

## ◆ TEST() [15/118]

flutter::testing::TEST | ( | FlutterAppDelegateTest | ,
|  | DoesNotCallDelegatesWithoutHandler |
| ) |  |

Definition at line 32 of file FlutterAppDelegateTest.mm.

32 {
33 FlutterAppDelegate* appDelegate = [[FlutterAppDelegate alloc] init];
34 AppDelegateNoopFlutterAppLifecycleDelegate* noopDelegate =
35 [[AppDelegateNoopFlutterAppLifecycleDelegate alloc] init];
36 [appDelegate addApplicationLifecycleDelegate:noopDelegate];
37
38 [appDelegate application:NSApplication.sharedApplication openURLs:@[]];
39 // No EXPECT, since the test is that the call doesn't throw due to calling without checking that
40 // the method is implemented.
41 }
AppDelegateNoopFlutterAppLifecycleDelegate
Definition: FlutterAppDelegateTest.mm:10
FlutterAppDelegate
Definition: FlutterAppDelegate.h:54
-[FlutterAppLifecycleProvider-p addApplicationLifecycleDelegate:]
void addApplicationLifecycleDelegate:(nonnull NSObject< FlutterAppLifecycleDelegate > *delegate)

References <FlutterAppLifecycleProvider>::addApplicationLifecycleDelegate:.

## ◆ TEST() [16/118]

flutter::testing::TEST | ( | FlutterAppDelegateTest | ,
|  | OperURLsStopsAfterHandled |
| ) |  |

Definition at line 57 of file FlutterAppDelegateTest.mm.

57 {
58 FlutterAppDelegate* appDelegate = [[FlutterAppDelegate alloc] init];
59 AppDelegateTestFlutterAppLifecycleDelegate* firstDelegate =
60 [[AppDelegateTestFlutterAppLifecycleDelegate alloc] init];
61 AppDelegateTestFlutterAppLifecycleDelegate* secondDelegate =
62 [[AppDelegateTestFlutterAppLifecycleDelegate alloc] init];
63 [appDelegate addApplicationLifecycleDelegate:firstDelegate];
64 [appDelegate addApplicationLifecycleDelegate:secondDelegate];
65
66 NSURL* URL = [NSURL URLWithString:@"https://flutter.dev"];
67 EXPECT_NE(URL, nil);
68 NSArray<NSURL*>* URLs = @[ URL ];
69 [appDelegate application:NSApplication.sharedApplication openURLs:URLs];
70
71 EXPECT_EQ([firstDelegate receivedURLs], URLs);
72 EXPECT_EQ([secondDelegate receivedURLs], nil);
73 }
AppDelegateTestFlutterAppLifecycleDelegate
Definition: FlutterAppDelegateTest.mm:17

References <FlutterAppLifecycleProvider>::addApplicationLifecycleDelegate:, and AppDelegateNoopFlutterAppLifecycleDelegate::receivedURLs.

## ◆ TEST() [17/118]

flutter::testing::TEST | ( | FlutterAppDelegateTest | ,
|  | ReceivesOpenURLs |
| ) |  |

Definition at line 43 of file FlutterAppDelegateTest.mm.

43 {
44 FlutterAppDelegate* appDelegate = [[FlutterAppDelegate alloc] init];
45 AppDelegateTestFlutterAppLifecycleDelegate* delegate =
46 [[AppDelegateTestFlutterAppLifecycleDelegate alloc] init];
47 [appDelegate addApplicationLifecycleDelegate:delegate];
48
49 NSURL* URL = [NSURL URLWithString:@"https://flutter.dev"];
50 EXPECT_NE(URL, nil);
51 NSArray<NSURL*>* URLs = @[ URL ];
52 [appDelegate application:NSApplication.sharedApplication openURLs:URLs];
53
54 EXPECT_EQ([delegate receivedURLs], URLs);
55 }

References <FlutterAppLifecycleProvider>::addApplicationLifecycleDelegate:, and AppDelegateNoopFlutterAppLifecycleDelegate::receivedURLs.

## ◆ TEST() [18/118]

flutter::testing::TEST | ( | FlutterAppLifecycleDelegateTest | ,
|  | ReleasesDelegateOnDealloc |
| ) |  |

Definition at line 223 of file FlutterAppLifecycleDelegateTest.mm.

223 {
224 __weak FlutterAppLifecycleRegistrar* weakRegistrar;
225 __weak TestFlutterAppLifecycleDelegate* weakDelegate;
226 @autoreleasepool {
227 FlutterAppLifecycleRegistrar* registrar = [[FlutterAppLifecycleRegistrar alloc] init];
228 weakRegistrar = registrar;
229 TestFlutterAppLifecycleDelegate* delegate = [[TestFlutterAppLifecycleDelegate alloc] init];
230 weakDelegate = delegate;
231 [registrar addDelegate:delegate];
232 }
233 EXPECT_EQ(weakRegistrar, nil);
234 EXPECT_EQ(weakDelegate, nil);
235 }
FlutterAppLifecycleRegistrar
Definition: FlutterAppLifecycleDelegate.h:126
-[FlutterAppLifecycleRegistrar addDelegate:]
void addDelegate:(NSObject< FlutterAppLifecycleDelegate > *delegate)
Definition: FlutterAppLifecycleDelegate.mm:58
TestFlutterAppLifecycleDelegate
Definition: FlutterAppLifecycleDelegateTest.mm:10

References FlutterAppLifecycleRegistrar::addDelegate:.

## ◆ TEST() [19/118]

flutter::testing::TEST | ( | FlutterAppLifecycleDelegateTest | ,
|  | RespondsToDidBecomeActive |
| ) |  |

Definition at line 109 of file FlutterAppLifecycleDelegateTest.mm.

109 {
110 FlutterAppLifecycleRegistrar* registrar = [[FlutterAppLifecycleRegistrar alloc] init];
111 TestFlutterAppLifecycleDelegate* delegate = [[TestFlutterAppLifecycleDelegate alloc] init];
112 [registrar addDelegate:delegate];
113
114 NSNotification* didBecomeActive =
115 [NSNotification notificationWithName:NSApplicationDidBecomeActiveNotification object:nil];
116 [registrar handleDidBecomeActive:didBecomeActive];
117 EXPECT_EQ([delegate lastNotification], didBecomeActive);
118 }
-[FlutterAppLifecycleDelegate-p handleDidBecomeActive:]
void handleDidBecomeActive:(NSNotification *notification)

References FlutterAppLifecycleRegistrar::addDelegate:, <FlutterAppLifecycleDelegate>::handleDidBecomeActive:, and TestFlutterAppLifecycleDelegate::lastNotification.

## ◆ TEST() [20/118]

flutter::testing::TEST | ( | FlutterAppLifecycleDelegateTest | ,
|  | RespondsToDidChangeOcclusionState |
| ) |  |

Definition at line 209 of file FlutterAppLifecycleDelegateTest.mm.

209 {
210 FlutterAppLifecycleRegistrar* registrar = [[FlutterAppLifecycleRegistrar alloc] init];
211 TestFlutterAppLifecycleDelegate* delegate = [[TestFlutterAppLifecycleDelegate alloc] init];
212 [registrar addDelegate:delegate];
213
214 NSNotification* didChangeOcclusionState =
215 [NSNotification notificationWithName:NSApplicationDidChangeOcclusionStateNotification
216 object:nil];
217 if ([registrar respondsToSelector:@selector(handleDidChangeOcclusionState:)]) {
218 [registrar handleDidChangeOcclusionState:didChangeOcclusionState];
219 EXPECT_EQ([delegate lastNotification], didChangeOcclusionState);
220 }
221 }
-[FlutterAppLifecycleDelegate-p handleDidChangeOcclusionState:]
void handleDidChangeOcclusionState:(NSNotification *notification)

References FlutterAppLifecycleRegistrar::addDelegate:, <FlutterAppLifecycleDelegate>::handleDidChangeOcclusionState:, and TestFlutterAppLifecycleDelegate::lastNotification.

## ◆ TEST() [21/118]

flutter::testing::TEST | ( | FlutterAppLifecycleDelegateTest | ,
|  | RespondsToDidChangeScreenParameters |
| ) |  |

Definition at line 197 of file FlutterAppLifecycleDelegateTest.mm.

197 {
198 FlutterAppLifecycleRegistrar* registrar = [[FlutterAppLifecycleRegistrar alloc] init];
199 TestFlutterAppLifecycleDelegate* delegate = [[TestFlutterAppLifecycleDelegate alloc] init];
200 [registrar addDelegate:delegate];
201
202 NSNotification* didChangeScreenParameters =
203 [NSNotification notificationWithName:NSApplicationDidChangeScreenParametersNotification
204 object:nil];
205 [registrar handleDidChangeScreenParameters:didChangeScreenParameters];
206 EXPECT_EQ([delegate lastNotification], didChangeScreenParameters);
207 }
-[FlutterAppLifecycleDelegate-p handleDidChangeScreenParameters:]
void handleDidChangeScreenParameters:(NSNotification *notification)

References FlutterAppLifecycleRegistrar::addDelegate:, <FlutterAppLifecycleDelegate>::handleDidChangeScreenParameters:, and TestFlutterAppLifecycleDelegate::lastNotification.

## ◆ TEST() [22/118]

flutter::testing::TEST | ( | FlutterAppLifecycleDelegateTest | ,
|  | RespondsToDidFinishLaunching |
| ) |  |

Definition at line 87 of file FlutterAppLifecycleDelegateTest.mm.

87 {
88 FlutterAppLifecycleRegistrar* registrar = [[FlutterAppLifecycleRegistrar alloc] init];
89 TestFlutterAppLifecycleDelegate* delegate = [[TestFlutterAppLifecycleDelegate alloc] init];
90 [registrar addDelegate:delegate];
91
92 NSNotification* didFinishLaunching =
93 [NSNotification notificationWithName:NSApplicationDidFinishLaunchingNotification object:nil];
94 [registrar handleDidFinishLaunching:didFinishLaunching];
95 EXPECT_EQ([delegate lastNotification], didFinishLaunching);
96 }
-[FlutterAppLifecycleDelegate-p handleDidFinishLaunching:]
void handleDidFinishLaunching:(NSNotification *notification)

References FlutterAppLifecycleRegistrar::addDelegate:, <FlutterAppLifecycleDelegate>::handleDidFinishLaunching:, and TestFlutterAppLifecycleDelegate::lastNotification.

## ◆ TEST() [23/118]

flutter::testing::TEST | ( | FlutterAppLifecycleDelegateTest | ,
|  | RespondsToDidHide |
| ) |  |

Definition at line 175 of file FlutterAppLifecycleDelegateTest.mm.

175 {
176 FlutterAppLifecycleRegistrar* registrar = [[FlutterAppLifecycleRegistrar alloc] init];
177 TestFlutterAppLifecycleDelegate* delegate = [[TestFlutterAppLifecycleDelegate alloc] init];
178 [registrar addDelegate:delegate];
179
180 NSNotification* didHide = [NSNotification notificationWithName:NSApplicationDidHideNotification
181 object:nil];
182 [registrar handleDidHide:didHide];
183 EXPECT_EQ([delegate lastNotification], didHide);
184 }
-[FlutterAppLifecycleDelegate-p handleDidHide:]
void handleDidHide:(NSNotification *notification)

References FlutterAppLifecycleRegistrar::addDelegate:, <FlutterAppLifecycleDelegate>::handleDidHide:, and TestFlutterAppLifecycleDelegate::lastNotification.

## ◆ TEST() [24/118]

flutter::testing::TEST | ( | FlutterAppLifecycleDelegateTest | ,
|  | RespondsToDidResignActive |
| ) |  |

Definition at line 131 of file FlutterAppLifecycleDelegateTest.mm.

131 {
132 FlutterAppLifecycleRegistrar* registrar = [[FlutterAppLifecycleRegistrar alloc] init];
133 TestFlutterAppLifecycleDelegate* delegate = [[TestFlutterAppLifecycleDelegate alloc] init];
134 [registrar addDelegate:delegate];
135
136 NSNotification* didResignActive =
137 [NSNotification notificationWithName:NSApplicationDidResignActiveNotification object:nil];
138 [registrar handleDidResignActive:didResignActive];
139 EXPECT_EQ([delegate lastNotification], didResignActive);
140 }
-[FlutterAppLifecycleDelegate-p handleDidResignActive:]
void handleDidResignActive:(NSNotification *notification)

References FlutterAppLifecycleRegistrar::addDelegate:, <FlutterAppLifecycleDelegate>::handleDidResignActive:, and TestFlutterAppLifecycleDelegate::lastNotification.

## ◆ TEST() [25/118]

flutter::testing::TEST | ( | FlutterAppLifecycleDelegateTest | ,
|  | RespondsToDidUnhide |
| ) |  |

Definition at line 186 of file FlutterAppLifecycleDelegateTest.mm.

186 {
187 FlutterAppLifecycleRegistrar* registrar = [[FlutterAppLifecycleRegistrar alloc] init];
188 TestFlutterAppLifecycleDelegate* delegate = [[TestFlutterAppLifecycleDelegate alloc] init];
189 [registrar addDelegate:delegate];
190
191 NSNotification* didUnhide =
192 [NSNotification notificationWithName:NSApplicationDidUnhideNotification object:nil];
193 [registrar handleDidUnhide:didUnhide];
194 EXPECT_EQ([delegate lastNotification], didUnhide);
195 }
-[FlutterAppLifecycleDelegate-p handleDidUnhide:]
void handleDidUnhide:(NSNotification *notification)

References FlutterAppLifecycleRegistrar::addDelegate:, <FlutterAppLifecycleDelegate>::handleDidUnhide:, and TestFlutterAppLifecycleDelegate::lastNotification.

## ◆ TEST() [26/118]

flutter::testing::TEST | ( | FlutterAppLifecycleDelegateTest | ,
|  | RespondsToWillBecomeActive |
| ) |  |

Definition at line 98 of file FlutterAppLifecycleDelegateTest.mm.

98 {
99 FlutterAppLifecycleRegistrar* registrar = [[FlutterAppLifecycleRegistrar alloc] init];
100 TestFlutterAppLifecycleDelegate* delegate = [[TestFlutterAppLifecycleDelegate alloc] init];
101 [registrar addDelegate:delegate];
102
103 NSNotification* willBecomeActive =
104 [NSNotification notificationWithName:NSApplicationWillBecomeActiveNotification object:nil];
105 [registrar handleWillBecomeActive:willBecomeActive];
106 EXPECT_EQ([delegate lastNotification], willBecomeActive);
107 }
-[FlutterAppLifecycleDelegate-p handleWillBecomeActive:]
void handleWillBecomeActive:(NSNotification *notification)

References FlutterAppLifecycleRegistrar::addDelegate:, <FlutterAppLifecycleDelegate>::handleWillBecomeActive:, and TestFlutterAppLifecycleDelegate::lastNotification.

## ◆ TEST() [27/118]

flutter::testing::TEST | ( | FlutterAppLifecycleDelegateTest | ,
|  | RespondsToWillFinishLaunching |
| ) |  |

Definition at line 76 of file FlutterAppLifecycleDelegateTest.mm.

76 {
77 FlutterAppLifecycleRegistrar* registrar = [[FlutterAppLifecycleRegistrar alloc] init];
78 TestFlutterAppLifecycleDelegate* delegate = [[TestFlutterAppLifecycleDelegate alloc] init];
79 [registrar addDelegate:delegate];
80
81 NSNotification* willFinishLaunching =
82 [NSNotification notificationWithName:NSApplicationWillFinishLaunchingNotification object:nil];
83 [registrar handleWillFinishLaunching:willFinishLaunching];
84 EXPECT_EQ([delegate lastNotification], willFinishLaunching);
85 }
-[FlutterAppLifecycleDelegate-p handleWillFinishLaunching:]
void handleWillFinishLaunching:(NSNotification *notification)

References FlutterAppLifecycleRegistrar::addDelegate:, <FlutterAppLifecycleDelegate>::handleWillFinishLaunching:, and TestFlutterAppLifecycleDelegate::lastNotification.

## ◆ TEST() [28/118]

flutter::testing::TEST | ( | FlutterAppLifecycleDelegateTest | ,
|  | RespondsToWillHide |
| ) |  |

Definition at line 153 of file FlutterAppLifecycleDelegateTest.mm.

153 {
154 FlutterAppLifecycleRegistrar* registrar = [[FlutterAppLifecycleRegistrar alloc] init];
155 TestFlutterAppLifecycleDelegate* delegate = [[TestFlutterAppLifecycleDelegate alloc] init];
156 [registrar addDelegate:delegate];
157
158 NSNotification* willHide = [NSNotification notificationWithName:NSApplicationWillHideNotification
159 object:nil];
160 [registrar handleWillHide:willHide];
161 EXPECT_EQ([delegate lastNotification], willHide);
162 }
-[FlutterAppLifecycleDelegate-p handleWillHide:]
void handleWillHide:(NSNotification *notification)

References FlutterAppLifecycleRegistrar::addDelegate:, <FlutterAppLifecycleDelegate>::handleWillHide:, and TestFlutterAppLifecycleDelegate::lastNotification.

## ◆ TEST() [29/118]

flutter::testing::TEST | ( | FlutterAppLifecycleDelegateTest | ,
|  | RespondsToWillResignActive |
| ) |  |

Definition at line 120 of file FlutterAppLifecycleDelegateTest.mm.

120 {
121 FlutterAppLifecycleRegistrar* registrar = [[FlutterAppLifecycleRegistrar alloc] init];
122 TestFlutterAppLifecycleDelegate* delegate = [[TestFlutterAppLifecycleDelegate alloc] init];
123 [registrar addDelegate:delegate];
124
125 NSNotification* willResignActive =
126 [NSNotification notificationWithName:NSApplicationWillResignActiveNotification object:nil];
127 [registrar handleWillResignActive:willResignActive];
128 EXPECT_EQ([delegate lastNotification], willResignActive);
129 }
-[FlutterAppLifecycleDelegate-p handleWillResignActive:]
void handleWillResignActive:(NSNotification *notification)

References FlutterAppLifecycleRegistrar::addDelegate:, <FlutterAppLifecycleDelegate>::handleWillResignActive:, and TestFlutterAppLifecycleDelegate::lastNotification.

## ◆ TEST() [30/118]

flutter::testing::TEST | ( | FlutterAppLifecycleDelegateTest | ,
|  | RespondsToWillTerminate |
| ) |  |

Definition at line 142 of file FlutterAppLifecycleDelegateTest.mm.

142 {
143 FlutterAppLifecycleRegistrar* registrar = [[FlutterAppLifecycleRegistrar alloc] init];
144 TestFlutterAppLifecycleDelegate* delegate = [[TestFlutterAppLifecycleDelegate alloc] init];
145 [registrar addDelegate:delegate];
146
147 NSNotification* applicationWillTerminate =
148 [NSNotification notificationWithName:NSApplicationWillTerminateNotification object:nil];
149 [registrar handleWillTerminate:applicationWillTerminate];
150 EXPECT_EQ([delegate lastNotification], applicationWillTerminate);
151 }
-[FlutterAppLifecycleDelegate-p handleWillTerminate:]
void handleWillTerminate:(NSNotification *notification)

References FlutterAppLifecycleRegistrar::addDelegate:, <FlutterAppLifecycleDelegate>::handleWillTerminate:, and TestFlutterAppLifecycleDelegate::lastNotification.

## ◆ TEST() [31/118]

flutter::testing::TEST | ( | FlutterAppLifecycleDelegateTest | ,
|  | RespondsToWillUnhide |
| ) |  |

Definition at line 164 of file FlutterAppLifecycleDelegateTest.mm.

164 {
165 FlutterAppLifecycleRegistrar* registrar = [[FlutterAppLifecycleRegistrar alloc] init];
166 TestFlutterAppLifecycleDelegate* delegate = [[TestFlutterAppLifecycleDelegate alloc] init];
167 [registrar addDelegate:delegate];
168
169 NSNotification* willUnhide =
170 [NSNotification notificationWithName:NSApplicationWillUnhideNotification object:nil];
171 [registrar handleWillUnhide:willUnhide];
172 EXPECT_EQ([delegate lastNotification], willUnhide);
173 }
-[FlutterAppLifecycleDelegate-p handleWillUnhide:]
void handleWillUnhide:(NSNotification *notification)

References FlutterAppLifecycleRegistrar::addDelegate:, <FlutterAppLifecycleDelegate>::handleWillUnhide:, and TestFlutterAppLifecycleDelegate::lastNotification.

## ◆ TEST() [32/118]

flutter::testing::TEST | ( | FlutterEmbedderKeyResponderUnittests | ,
|  | BasicKeyEvent |
| ) |  |

Definition at line 118 of file FlutterEmbedderKeyResponderTest.mm.

118 {
119 __block NSMutableArray<TestKeyEvent*>* events = [[NSMutableArray<TestKeyEvent*> alloc] init];
120 __block BOOL last_handled = TRUE;
121 FlutterKeyEvent* event;
122
123 FlutterEmbedderKeyResponder* responder = [[FlutterEmbedderKeyResponder alloc]
124 initWithSendEvent:^(const FlutterKeyEvent& event, _Nullable FlutterKeyEventCallback callback,
125 void* _Nullable user_data) {
126 [events addObject:[[TestKeyEvent alloc] initWithEvent:&event
127 callback:callback
128 userData:user_data]];
129 }];
130
131 last_handled = FALSE;
132 [responder handleEvent:keyEvent(NSEventTypeKeyDown, 123.0f, 0x100, @"a", @"a", FALSE, 0)
133 callback:^(BOOL handled) {
134 last_handled = handled;
135 }];
136
137 EXPECT_EQ([events count], 1u);
138 event = [events lastObject].data;
139 ASSERT_NE(event, nullptr);
140 EXPECT_EQ(event->type, kFlutterKeyEventTypeDown);
141 EXPECT_EQ(event->timestamp, 123000000.0f);
142 EXPECT_EQ(event->physical, kPhysicalKeyA);
143 EXPECT_EQ(event->logical, kLogicalKeyA);
144 EXPECT_STREQ(event->character, "a");
145 EXPECT_EQ(event->synthesized, false);
146
147 EXPECT_EQ(last_handled, FALSE);
148 EXPECT_TRUE([[events lastObject] hasCallback]);
149 [[events lastObject] respond:TRUE];
150 EXPECT_EQ(last_handled, TRUE);
151
152 [events removeAllObjects];
153
154 last_handled = FALSE;
155 [responder handleEvent:keyEvent(NSEventTypeKeyDown, 0x100, @"a", @"a", TRUE, kKeyCodeKeyA)
156 callback:^(BOOL handled) {
157 last_handled = handled;
158 }];
159
160 EXPECT_EQ([events count], 1u);
161 event = [events lastObject].data;
162 ASSERT_NE(event, nullptr);
163 EXPECT_EQ(event->type, kFlutterKeyEventTypeRepeat);
164 EXPECT_EQ(event->physical, kPhysicalKeyA);
165 EXPECT_EQ(event->logical, kLogicalKeyA);
166 EXPECT_STREQ(event->character, "a");
167 EXPECT_EQ(event->synthesized, false);
168
169 EXPECT_EQ(last_handled, FALSE);
170 EXPECT_TRUE([[events lastObject] hasCallback]);
171 [[events lastObject] respond:TRUE];
172 EXPECT_EQ(last_handled, TRUE);
173
174 [events removeAllObjects];
175
176 last_handled = TRUE;
177 [responder handleEvent:keyEvent(NSEventTypeKeyUp, 124.0f, 0x100, @"a", @"a", FALSE, kKeyCodeKeyA)
178 callback:^(BOOL handled) {
179 last_handled = handled;
180 }];
181
182 EXPECT_EQ([events count], 1u);
183 event = [events lastObject].data;
184 ASSERT_NE(event, nullptr);
185 EXPECT_EQ(event->type, kFlutterKeyEventTypeUp);
186 EXPECT_EQ(event->timestamp, 124000000.0f);
187 EXPECT_EQ(event->physical, kPhysicalKeyA);
188 EXPECT_EQ(event->logical, kLogicalKeyA);
189 EXPECT_EQ(event->character, nullptr);
190 EXPECT_EQ(event->synthesized, false);
191
192 EXPECT_EQ(last_handled, TRUE);
193 EXPECT_TRUE([[events lastObject] hasCallback]);
194 [[events lastObject] respond:FALSE]; // Check if responding FALSE works
195 EXPECT_EQ(last_handled, FALSE);
196
197 [events removeAllObjects];
198 }
FlutterEmbedderKeyResponder
Definition: FlutterEmbedderKeyResponder.h:23
TestKeyEvent
Definition: FlutterEmbedderKeyResponderTest.mm:14
-[FlutterKeyPrimaryResponder-p handleEvent:callback:]
void handleEvent:callback:(nonnull NSEvent *event,[callback] nonnull FlutterAsyncKeyCallback callback)

References <FlutterKeyPrimaryResponder>::handleEvent:callback:, and TestKeyEvent::hasCallback.

## ◆ TEST() [33/118]

flutter::testing::TEST | ( | FlutterEmbedderKeyResponderUnittests | ,
|  | ConvertAbruptRepeatEventsToDown |
| ) |  |

Definition at line 410 of file FlutterEmbedderKeyResponderTest.mm.

410 {
411 __block NSMutableArray<TestKeyEvent*>* events = [[NSMutableArray<TestKeyEvent*> alloc] init];
412 __block BOOL last_handled = TRUE;
413 FlutterKeyEvent* event;
414
415 FlutterEmbedderKeyResponder* responder = [[FlutterEmbedderKeyResponder alloc]
416 initWithSendEvent:^(const FlutterKeyEvent& event, _Nullable FlutterKeyEventCallback callback,
417 void* _Nullable user_data) {
418 [events addObject:[[TestKeyEvent alloc] initWithEvent:&event
419 callback:callback
420 userData:user_data]];
421 }];
422
423 last_handled = TRUE;
424 [responder handleEvent:keyEvent(NSEventTypeKeyDown, 0x100, @"a", @"a", TRUE, kKeyCodeKeyA)
425 callback:^(BOOL handled) {
426 last_handled = handled;
427 }];
428
429 EXPECT_EQ([events count], 1u);
430 event = [events lastObject].data;
431 ASSERT_NE(event, nullptr);
432 EXPECT_EQ(event->type, kFlutterKeyEventTypeDown);
433 EXPECT_EQ(event->physical, kPhysicalKeyA);
434 EXPECT_EQ(event->logical, kLogicalKeyA);
435 EXPECT_STREQ(event->character, "a");
436 EXPECT_EQ(event->synthesized, false);
437 EXPECT_EQ(last_handled, TRUE);
438 [[events lastObject] respond:FALSE];
439 EXPECT_EQ(last_handled, FALSE);
440
441 [events removeAllObjects];
442 }

References <FlutterKeyPrimaryResponder>::handleEvent:callback:.

## ◆ TEST() [34/118]

flutter::testing::TEST | ( | FlutterEmbedderKeyResponderUnittests | ,
|  | ConvertCapsLockEvents |
| ) |  |

Definition at line 1100 of file FlutterEmbedderKeyResponderTest.mm.

1100 {
1101 __block NSMutableArray<TestKeyEvent*>* events = [[NSMutableArray<TestKeyEvent*> alloc] init];
1102 __block BOOL last_handled = TRUE;
1103 id keyEventCallback = ^(BOOL handled) {
1104 last_handled = handled;
1105 };
1106 FlutterKeyEvent* event;
1107
1108 FlutterEmbedderKeyResponder* responder = [[FlutterEmbedderKeyResponder alloc]
1109 initWithSendEvent:^(const FlutterKeyEvent& event, _Nullable FlutterKeyEventCallback callback,
1110 void* _Nullable user_data) {
1111 [events addObject:[[TestKeyEvent alloc] initWithEvent:&event
1112 callback:callback
1113 userData:user_data]];
1114 }];
1115
1116 // In: CapsLock down
1117 // Out: CapsLock down & *CapsLock Up
1118 last_handled = FALSE;
1119 [responder
1120 handleEvent:keyEvent(NSEventTypeFlagsChanged, 0x10100, @"", @"", FALSE, kKeyCodeCapsLock)
1121 callback:keyEventCallback];
1122
1123 EXPECT_EQ([events count], 2u);
1124
1125 event = [events firstObject].data;
1126 ASSERT_NE(event, nullptr);
1127 EXPECT_EQ(event->type, kFlutterKeyEventTypeDown);
1128 EXPECT_EQ(event->physical, kPhysicalCapsLock);
1129 EXPECT_EQ(event->logical, kLogicalCapsLock);
1130 EXPECT_STREQ(event->character, nullptr);
1131 EXPECT_EQ(event->synthesized, false);
1132 EXPECT_TRUE([[events firstObject] hasCallback]);
1133
1134 event = [events lastObject].data;
1135 ASSERT_NE(event, nullptr);
1136 EXPECT_EQ(event->type, kFlutterKeyEventTypeUp);
1137 EXPECT_EQ(event->physical, kPhysicalCapsLock);
1138 EXPECT_EQ(event->logical, kLogicalCapsLock);
1139 EXPECT_STREQ(event->character, nullptr);
1140 EXPECT_EQ(event->synthesized, true);
1141 EXPECT_FALSE([[events lastObject] hasCallback]);
1142
1143 EXPECT_EQ(last_handled, FALSE);
1144 [[events firstObject] respond:TRUE];
1145 EXPECT_EQ(last_handled, TRUE);
1146
1147 [events removeAllObjects];
1148
1149 // In: CapsLock up
1150 // Out: CapsLock down & *CapsLock Up
1151 last_handled = FALSE;
1152 [responder handleEvent:keyEvent(NSEventTypeFlagsChanged, 0x100, @"", @"", FALSE, kKeyCodeCapsLock)
1153 callback:keyEventCallback];
1154
1155 EXPECT_EQ([events count], 2u);
1156
1157 event = [events firstObject].data;
1158 ASSERT_NE(event, nullptr);
1159 EXPECT_EQ(event->type, kFlutterKeyEventTypeDown);
1160 EXPECT_EQ(event->physical, kPhysicalCapsLock);
1161 EXPECT_EQ(event->logical, kLogicalCapsLock);
1162 EXPECT_STREQ(event->character, nullptr);
1163 EXPECT_EQ(event->synthesized, false);
1164 EXPECT_TRUE([[events firstObject] hasCallback]);
1165
1166 event = [events lastObject].data;
1167 ASSERT_NE(event, nullptr);
1168 EXPECT_EQ(event->type, kFlutterKeyEventTypeUp);
1169 EXPECT_EQ(event->physical, kPhysicalCapsLock);
1170 EXPECT_EQ(event->logical, kLogicalCapsLock);
1171 EXPECT_STREQ(event->character, nullptr);
1172 EXPECT_EQ(event->synthesized, true);
1173 EXPECT_FALSE([[events lastObject] hasCallback]);
1174
1175 EXPECT_EQ(last_handled, FALSE);
1176 [[events firstObject] respond:TRUE];
1177 EXPECT_EQ(last_handled, TRUE);
1178
1179 [events removeAllObjects];
1180 }

References <FlutterKeyPrimaryResponder>::handleEvent:callback:, and TestKeyEvent::hasCallback.

## ◆ TEST() [35/118]

flutter::testing::TEST | ( | FlutterEmbedderKeyResponderUnittests | ,
|  | IdentifyLeftAndRightModifiers |
| ) |  |

Definition at line 720 of file FlutterEmbedderKeyResponderTest.mm.

720 {
721 __block NSMutableArray<TestKeyEvent*>* events = [[NSMutableArray<TestKeyEvent*> alloc] init];
722 FlutterKeyEvent* event;
723
724 FlutterEmbedderKeyResponder* responder = [[FlutterEmbedderKeyResponder alloc]
725 initWithSendEvent:^(const FlutterKeyEvent& event, _Nullable FlutterKeyEventCallback callback,
726 void* _Nullable user_data) {
727 [events addObject:[[TestKeyEvent alloc] initWithEvent:&event
728 callback:callback
729 userData:user_data]];
730 }];
731
732 [responder
733 handleEvent:keyEvent(NSEventTypeFlagsChanged, 0x20102, @"", @"", FALSE, kKeyCodeShiftLeft)
734 callback:^(BOOL handled){
735 }];
736
737 EXPECT_EQ([events count], 1u);
738 event = [events lastObject].data;
739 ASSERT_NE(event, nullptr);
740 EXPECT_EQ(event->type, kFlutterKeyEventTypeDown);
741 EXPECT_EQ(event->physical, kPhysicalShiftLeft);
742 EXPECT_EQ(event->logical, kLogicalShiftLeft);
743 EXPECT_STREQ(event->character, nullptr);
744 EXPECT_EQ(event->synthesized, false);
745 [[events lastObject] respond:TRUE];
746
747 [events removeAllObjects];
748
749 [responder
750 handleEvent:keyEvent(NSEventTypeFlagsChanged, 0x20106, @"", @"", FALSE, kKeyCodeShiftRight)
751 callback:^(BOOL handled){
752 }];
753
754 EXPECT_EQ([events count], 1u);
755 event = [events lastObject].data;
756 ASSERT_NE(event, nullptr);
757 EXPECT_EQ(event->type, kFlutterKeyEventTypeDown);
758 EXPECT_EQ(event->physical, kPhysicalShiftRight);
759 EXPECT_EQ(event->logical, kLogicalShiftRight);
760 EXPECT_STREQ(event->character, nullptr);
761 EXPECT_EQ(event->synthesized, false);
762 [[events lastObject] respond:TRUE];
763
764 [events removeAllObjects];
765
766 [responder
767 handleEvent:keyEvent(NSEventTypeFlagsChanged, 0x20104, @"", @"", FALSE, kKeyCodeShiftLeft)
768 callback:^(BOOL handled){
769 }];
770
771 EXPECT_EQ([events count], 1u);
772 event = [events lastObject].data;
773 ASSERT_NE(event, nullptr);
774 EXPECT_EQ(event->type, kFlutterKeyEventTypeUp);
775 EXPECT_EQ(event->physical, kPhysicalShiftLeft);
776 EXPECT_EQ(event->logical, kLogicalShiftLeft);
777 EXPECT_STREQ(event->character, nullptr);
778 EXPECT_EQ(event->synthesized, false);
779 [[events lastObject] respond:TRUE];
780
781 [events removeAllObjects];
782
783 [responder
784 handleEvent:keyEvent(NSEventTypeFlagsChanged, 0x100, @"", @"", FALSE, kKeyCodeShiftRight)
785 callback:^(BOOL handled){
786 }];
787
788 EXPECT_EQ([events count], 1u);
789 event = [events lastObject].data;
790 ASSERT_NE(event, nullptr);
791 EXPECT_EQ(event->type, kFlutterKeyEventTypeUp);
792 EXPECT_EQ(event->physical, kPhysicalShiftRight);
793 EXPECT_EQ(event->logical, kLogicalShiftRight);
794 EXPECT_STREQ(event->character, nullptr);
795 EXPECT_EQ(event->synthesized, false);
796 [[events lastObject] respond:TRUE];
797
798 [events removeAllObjects];
799 }

References <FlutterKeyPrimaryResponder>::handleEvent:callback:.

## ◆ TEST() [36/118]

flutter::testing::TEST | ( | FlutterEmbedderKeyResponderUnittests | ,
|  | IgnoreDuplicateUpEvent |
| ) |  |

Definition at line 379 of file FlutterEmbedderKeyResponderTest.mm.

379 {
380 __block NSMutableArray<TestKeyEvent*>* events = [[NSMutableArray<TestKeyEvent*> alloc] init];
381 FlutterKeyEvent* event;
382 __block BOOL last_handled = TRUE;
383
384 FlutterEmbedderKeyResponder* responder = [[FlutterEmbedderKeyResponder alloc]
385 initWithSendEvent:^(const FlutterKeyEvent& event, _Nullable FlutterKeyEventCallback callback,
386 void* _Nullable user_data) {
387 [events addObject:[[TestKeyEvent alloc] initWithEvent:&event
388 callback:callback
389 userData:user_data]];
390 }];
391
392 last_handled = FALSE;
393 [responder handleEvent:keyEvent(NSEventTypeKeyUp, 0x100, @"a", @"a", FALSE, kKeyCodeKeyA)
394 callback:^(BOOL handled) {
395 last_handled = handled;
396 }];
397
398 EXPECT_EQ([events count], 1u);
399 EXPECT_EQ(last_handled, TRUE);
400 event = [events lastObject].data;
401 ASSERT_NE(event, nullptr);
402 EXPECT_EQ(event->physical, 0ull);
403 EXPECT_EQ(event->logical, 0ull);
404 EXPECT_FALSE([[events lastObject] hasCallback]);
405 EXPECT_EQ(last_handled, TRUE);
406
407 [events removeAllObjects];
408 }

References <FlutterKeyPrimaryResponder>::handleEvent:callback:, and TestKeyEvent::hasCallback.

## ◆ TEST() [37/118]

flutter::testing::TEST | ( | FlutterEmbedderKeyResponderUnittests | ,
|  | MultipleCharacters |
| ) |  |

Definition at line 274 of file FlutterEmbedderKeyResponderTest.mm.

274 {
275 __block NSMutableArray<TestKeyEvent*>* events = [[NSMutableArray<TestKeyEvent*> alloc] init];
276 FlutterKeyEvent* event;
277
278 FlutterEmbedderKeyResponder* responder = [[FlutterEmbedderKeyResponder alloc]
279 initWithSendEvent:^(const FlutterKeyEvent& event, _Nullable FlutterKeyEventCallback callback,
280 void* _Nullable user_data) {
281 [events addObject:[[TestKeyEvent alloc] initWithEvent:&event
282 callback:callback
283 userData:user_data]];
284 }];
285
286 [responder handleEvent:keyEvent(NSEventTypeKeyDown, 0, @"Ã n", @"Ã n", FALSE, kKeyCodeKeyA)
287 callback:^(BOOL handled){
288 }];
289
290 EXPECT_EQ([events count], 1u);
291 event = [events lastObject].data;
292 ASSERT_NE(event, nullptr);
293 EXPECT_EQ(event->type, kFlutterKeyEventTypeDown);
294 EXPECT_EQ(event->physical, kPhysicalKeyA);
295 EXPECT_EQ(event->logical, 0x1400000000ull);
296 EXPECT_STREQ(event->character, "Ã n");
297 EXPECT_EQ(event->synthesized, false);
298
299 [events removeAllObjects];
300
301 [responder handleEvent:keyEvent(NSEventTypeKeyUp, 0, @"a", @"a", FALSE, kKeyCodeKeyA)
302 callback:^(BOOL handled){
303 }];
304
305 EXPECT_EQ([events count], 1u);
306 event = [events lastObject].data;
307 ASSERT_NE(event, nullptr);
308 EXPECT_EQ(event->type, kFlutterKeyEventTypeUp);
309 EXPECT_EQ(event->physical, kPhysicalKeyA);
310 EXPECT_EQ(event->logical, 0x1400000000ull);
311 EXPECT_STREQ(event->character, nullptr);
312 EXPECT_EQ(event->synthesized, false);
313
314 [events removeAllObjects];
315 }

References <FlutterKeyPrimaryResponder>::handleEvent:callback:.

## ◆ TEST() [38/118]

flutter::testing::TEST | ( | FlutterEmbedderKeyResponderUnittests | ,
|  | NonAsciiCharacters |
| ) |  |

Definition at line 200 of file FlutterEmbedderKeyResponderTest.mm.

200 {
201 __block NSMutableArray<TestKeyEvent*>* events = [[NSMutableArray<TestKeyEvent*> alloc] init];
202 FlutterKeyEvent* event;
203
204 FlutterEmbedderKeyResponder* responder = [[FlutterEmbedderKeyResponder alloc]
205 initWithSendEvent:^(const FlutterKeyEvent& event, _Nullable FlutterKeyEventCallback callback,
206 void* _Nullable user_data) {
207 [events addObject:[[TestKeyEvent alloc] initWithEvent:&event
208 callback:callback
209 userData:user_data]];
210 }];
211
212 [responder
213 handleEvent:keyEvent(NSEventTypeFlagsChanged, 0x80140, @"", @"", FALSE, kKeyCodeAltRight)
214 callback:^(BOOL handled){
215 }];
216
217 EXPECT_EQ([events count], 1u);
218 event = [events lastObject].data;
219 ASSERT_NE(event, nullptr);
220 EXPECT_EQ(event->type, kFlutterKeyEventTypeDown);
221 EXPECT_EQ(event->physical, kPhysicalAltRight);
222 EXPECT_EQ(event->logical, kLogicalAltRight);
223 EXPECT_STREQ(event->character, nullptr);
224 EXPECT_EQ(event->synthesized, false);
225
226 [events removeAllObjects];
227
228 [responder handleEvent:keyEvent(NSEventTypeKeyDown, 0x80140, @"âˆ‘", @"w", FALSE, kKeyCodeKeyW)
229 callback:^(BOOL handled){
230 }];
231
232 EXPECT_EQ([events count], 1u);
233 event = [events lastObject].data;
234 ASSERT_NE(event, nullptr);
235 EXPECT_EQ(event->type, kFlutterKeyEventTypeDown);
236 EXPECT_EQ(event->physical, kPhysicalKeyW);
237 EXPECT_EQ(event->logical, kLogicalKeyW);
238 EXPECT_STREQ(event->character, "âˆ‘");
239 EXPECT_EQ(event->synthesized, false);
240
241 [events removeAllObjects];
242
243 [responder handleEvent:keyEvent(NSEventTypeFlagsChanged, 0x100, @"", @"", FALSE, kKeyCodeAltRight)
244 callback:^(BOOL handled){
245 }];
246
247 EXPECT_EQ([events count], 1u);
248 event = [events lastObject].data;
249 ASSERT_NE(event, nullptr);
250 EXPECT_EQ(event->type, kFlutterKeyEventTypeUp);
251 EXPECT_EQ(event->physical, kPhysicalAltRight);
252 EXPECT_EQ(event->logical, kLogicalAltRight);
253 EXPECT_STREQ(event->character, nullptr);
254 EXPECT_EQ(event->synthesized, false);
255
256 [events removeAllObjects];
257
258 [responder handleEvent:keyEvent(NSEventTypeKeyUp, 0x100, @"w", @"w", FALSE, kKeyCodeKeyW)
259 callback:^(BOOL handled){
260 }];
261
262 EXPECT_EQ([events count], 1u);
263 event = [events lastObject].data;
264 ASSERT_NE(event, nullptr);
265 EXPECT_EQ(event->type, kFlutterKeyEventTypeUp);
266 EXPECT_EQ(event->physical, kPhysicalKeyW);
267 EXPECT_EQ(event->logical, kLogicalKeyW);
268 EXPECT_STREQ(event->character, nullptr);
269 EXPECT_EQ(event->synthesized, false);
270
271 [events removeAllObjects];
272 }

References <FlutterKeyPrimaryResponder>::handleEvent:callback:.

## ◆ TEST() [39/118]

flutter::testing::TEST | ( | FlutterEmbedderKeyResponderUnittests | ,
|  | SpecialModiferFlags |
| ) |  |

Definition at line 564 of file FlutterEmbedderKeyResponderTest.mm.

564 {
565 __block NSMutableArray<TestKeyEvent*>* events = [[NSMutableArray<TestKeyEvent*> alloc] init];
566 FlutterKeyEvent* event;
567
568 FlutterEmbedderKeyResponder* responder = [[FlutterEmbedderKeyResponder alloc]
569 initWithSendEvent:^(const FlutterKeyEvent& event, _Nullable FlutterKeyEventCallback callback,
570 void* _Nullable user_data) {
571 [events addObject:[[TestKeyEvent alloc] initWithEvent:&event
572 callback:callback
573 userData:user_data]];
574 }];
575
576 // Keydown: Numpad1, F1, KeyA, ShiftLeft
577 // Then KeyUp: Numpad1, F1, KeyA, ShiftLeft
578
579 // Numpad 1
580 [responder handleEvent:keyEvent(NSEventTypeKeyDown, 0x200100, @"1", @"1", FALSE, kKeyCodeNumpad1)
581 callback:^(BOOL handled){
582 }];
583
584 EXPECT_EQ([events count], 1u);
585 event = [events lastObject].data;
586 ASSERT_NE(event, nullptr);
587 EXPECT_EQ(event->type, kFlutterKeyEventTypeDown);
588 EXPECT_EQ(event->physical, kPhysicalNumpad1);
589 EXPECT_EQ(event->logical, kLogicalNumpad1);
590 EXPECT_STREQ(event->character, "1");
591 EXPECT_EQ(event->synthesized, false);
592 [[events lastObject] respond:TRUE];
593
594 [events removeAllObjects];
595
596 // F1
597 [responder
598 handleEvent:keyEvent(NSEventTypeKeyDown, 0x800100, @"\uf704", @"\uf704", FALSE, kKeyCodeF1)
599 callback:^(BOOL handled){
600 }];
601
602 EXPECT_EQ([events count], 1u);
603 event = [events lastObject].data;
604 ASSERT_NE(event, nullptr);
605 EXPECT_EQ(event->type, kFlutterKeyEventTypeDown);
606 EXPECT_EQ(event->physical, kPhysicalF1);
607 EXPECT_EQ(event->logical, kLogicalF1);
608 EXPECT_STREQ(event->character, nullptr);
609 EXPECT_EQ(event->synthesized, false);
610 [[events lastObject] respond:TRUE];
611
612 [events removeAllObjects];
613
614 // KeyA
615 [responder handleEvent:keyEvent(NSEventTypeKeyDown, 0x100, @"a", @"a", FALSE, kKeyCodeKeyA)
616 callback:^(BOOL handled){
617 }];
618
619 EXPECT_EQ([events count], 1u);
620 event = [events lastObject].data;
621 ASSERT_NE(event, nullptr);
622 EXPECT_EQ(event->type, kFlutterKeyEventTypeDown);
623 EXPECT_EQ(event->physical, kPhysicalKeyA);
624 EXPECT_EQ(event->logical, kLogicalKeyA);
625 EXPECT_STREQ(event->character, "a");
626 EXPECT_EQ(event->synthesized, false);
627 [[events lastObject] respond:TRUE];
628
629 [events removeAllObjects];
630
631 // ShiftLeft
632 [responder
633 handleEvent:keyEvent(NSEventTypeFlagsChanged, 0x20102, @"", @"", FALSE, kKeyCodeShiftLeft)
634 callback:^(BOOL handled){
635 }];
636
637 EXPECT_EQ([events count], 1u);
638 event = [events lastObject].data;
639 ASSERT_NE(event, nullptr);
640 EXPECT_EQ(event->type, kFlutterKeyEventTypeDown);
641 EXPECT_EQ(event->physical, kPhysicalShiftLeft);
642 EXPECT_EQ(event->logical, kLogicalShiftLeft);
643 EXPECT_STREQ(event->character, nullptr);
644 EXPECT_EQ(event->synthesized, false);
645 [[events lastObject] respond:TRUE];
646
647 [events removeAllObjects];
648
649 // Numpad 1
650 [responder handleEvent:keyEvent(NSEventTypeKeyUp, 0x220102, @"1", @"1", FALSE, kKeyCodeNumpad1)
651 callback:^(BOOL handled){
652 }];
653
654 EXPECT_EQ([events count], 1u);
655 event = [events lastObject].data;
656 ASSERT_NE(event, nullptr);
657 EXPECT_EQ(event->type, kFlutterKeyEventTypeUp);
658 EXPECT_EQ(event->physical, kPhysicalNumpad1);
659 EXPECT_EQ(event->logical, kLogicalNumpad1);
660 EXPECT_STREQ(event->character, nullptr);
661 EXPECT_EQ(event->synthesized, false);
662 [[events lastObject] respond:TRUE];
663
664 [events removeAllObjects];
665
666 // F1
667 [responder
668 handleEvent:keyEvent(NSEventTypeKeyUp, 0x820102, @"\uF704", @"\uF704", FALSE, kKeyCodeF1)
669 callback:^(BOOL handled){
670 }];
671
672 EXPECT_EQ([events count], 1u);
673 event = [events lastObject].data;
674 ASSERT_NE(event, nullptr);
675 EXPECT_EQ(event->type, kFlutterKeyEventTypeUp);
676 EXPECT_EQ(event->physical, kPhysicalF1);
677 EXPECT_EQ(event->logical, kLogicalF1);
678 EXPECT_STREQ(event->character, nullptr);
679 EXPECT_EQ(event->synthesized, false);
680 [[events lastObject] respond:TRUE];
681
682 [events removeAllObjects];
683
684 // KeyA
685 [responder handleEvent:keyEvent(NSEventTypeKeyUp, 0x20102, @"a", @"a", FALSE, kKeyCodeKeyA)
686 callback:^(BOOL handled){
687 }];
688
689 EXPECT_EQ([events count], 1u);
690 event = [events lastObject].data;
691 ASSERT_NE(event, nullptr);
692 EXPECT_EQ(event->type, kFlutterKeyEventTypeUp);
693 EXPECT_EQ(event->physical, kPhysicalKeyA);
694 EXPECT_EQ(event->logical, kLogicalKeyA);
695 EXPECT_STREQ(event->character, nullptr);
696 EXPECT_EQ(event->synthesized, false);
697 [[events lastObject] respond:TRUE];
698
699 [events removeAllObjects];
700
701 // ShiftLeft
702 [responder
703 handleEvent:keyEvent(NSEventTypeFlagsChanged, 0x100, @"", @"", FALSE, kKeyCodeShiftLeft)
704 callback:^(BOOL handled){
705 }];
706
707 EXPECT_EQ([events count], 1u);
708 event = [events lastObject].data;
709 ASSERT_NE(event, nullptr);
710 EXPECT_EQ(event->type, kFlutterKeyEventTypeUp);
711 EXPECT_EQ(event->physical, kPhysicalShiftLeft);
712 EXPECT_EQ(event->logical, kLogicalShiftLeft);
713 EXPECT_STREQ(event->character, nullptr);
714 EXPECT_EQ(event->synthesized, false);
715 [[events lastObject] respond:TRUE];
716
717 [events removeAllObjects];
718 }

References <FlutterKeyPrimaryResponder>::handleEvent:callback:.

## ◆ TEST() [40/118]

flutter::testing::TEST | ( | FlutterEmbedderKeyResponderUnittests | ,
|  | SynchronizeCapsLockStateOnCapsLock |
| ) |  |

Definition at line 1183 of file FlutterEmbedderKeyResponderTest.mm.

1183 {
1184 __block NSMutableArray<TestKeyEvent*>* events = [[NSMutableArray<TestKeyEvent*> alloc] init];
1185 FlutterKeyEvent* event;
1186 __block BOOL last_handled = TRUE;
1187 id keyEventCallback = ^(BOOL handled) {
1188 last_handled = handled;
1189 };
1190
1191 FlutterEmbedderKeyResponder* responder = [[FlutterEmbedderKeyResponder alloc]
1192 initWithSendEvent:^(const FlutterKeyEvent& event, _Nullable FlutterKeyEventCallback callback,
1193 void* _Nullable user_data) {
1194 [events addObject:[[TestKeyEvent alloc] initWithEvent:&event
1195 callback:callback
1196 userData:user_data]];
1197 }];
1198
1199 // In: CapsLock down
1200 // Out: (empty)
1201 last_handled = FALSE;
1202 [responder handleEvent:keyEvent(NSEventTypeFlagsChanged, 0x100, @"", @"", FALSE, kKeyCodeCapsLock)
1203 callback:keyEventCallback];
1204
1205 EXPECT_EQ([events count], 1u);
1206 EXPECT_EQ(last_handled, TRUE);
1207 event = [events lastObject].data;
1208 ASSERT_NE(event, nullptr);
1209 EXPECT_EQ(event->physical, 0ull);
1210 EXPECT_EQ(event->logical, 0ull);
1211 EXPECT_FALSE([[events lastObject] hasCallback]);
1212 EXPECT_EQ(last_handled, TRUE);
1213
1214 [events removeAllObjects];
1215 }

References <FlutterKeyPrimaryResponder>::handleEvent:callback:, and TestKeyEvent::hasCallback.

## ◆ TEST() [41/118]

flutter::testing::TEST | ( | FlutterEmbedderKeyResponderUnittests | ,
|  | SynchronizeCapsLockStateOnNormalKey |
| ) |  |

Definition at line 1218 of file FlutterEmbedderKeyResponderTest.mm.

1218 {
1219 __block NSMutableArray<TestKeyEvent*>* events = [[NSMutableArray<TestKeyEvent*> alloc] init];
1220 __block BOOL last_handled = TRUE;
1221 id keyEventCallback = ^(BOOL handled) {
1222 last_handled = handled;
1223 };
1224 FlutterKeyEvent* event;
1225
1226 FlutterEmbedderKeyResponder* responder = [[FlutterEmbedderKeyResponder alloc]
1227 initWithSendEvent:^(const FlutterKeyEvent& event, _Nullable FlutterKeyEventCallback callback,
1228 void* _Nullable user_data) {
1229 [events addObject:[[TestKeyEvent alloc] initWithEvent:&event
1230 callback:callback
1231 userData:user_data]];
1232 }];
1233
1234 last_handled = FALSE;
1235 [responder handleEvent:keyEvent(NSEventTypeKeyDown, 0x10100, @"A", @"a", FALSE, kKeyCodeKeyA)
1236 callback:keyEventCallback];
1237
1238 EXPECT_EQ([events count], 3u);
1239
1240 event = events[0].data;
1241 ASSERT_NE(event, nullptr);
1242 EXPECT_EQ(event->type, kFlutterKeyEventTypeDown);
1243 EXPECT_EQ(event->physical, kPhysicalCapsLock);
1244 EXPECT_EQ(event->logical, kLogicalCapsLock);
1245 EXPECT_STREQ(event->character, nullptr);
1246 EXPECT_EQ(event->synthesized, true);
1247 EXPECT_FALSE([events[0] hasCallback]);
1248
1249 event = events[1].data;
1250 ASSERT_NE(event, nullptr);
1251 EXPECT_EQ(event->type, kFlutterKeyEventTypeUp);
1252 EXPECT_EQ(event->physical, kPhysicalCapsLock);
1253 EXPECT_EQ(event->logical, kLogicalCapsLock);
1254 EXPECT_STREQ(event->character, nullptr);
1255 EXPECT_EQ(event->synthesized, true);
1256 EXPECT_FALSE([events[1] hasCallback]);
1257
1258 event = events[2].data;
1259 ASSERT_NE(event, nullptr);
1260 EXPECT_EQ(event->type, kFlutterKeyEventTypeDown);
1261 EXPECT_EQ(event->physical, kPhysicalKeyA);
1262 EXPECT_EQ(event->logical, kLogicalKeyA);
1263 EXPECT_STREQ(event->character, "A");
1264 EXPECT_EQ(event->synthesized, false);
1265 EXPECT_TRUE([events[2] hasCallback]);
1266
1267 EXPECT_EQ(last_handled, FALSE);
1268 [[events lastObject] respond:TRUE];
1269 EXPECT_EQ(last_handled, TRUE);
1270
1271 [events removeAllObjects];
1272 }

References <FlutterKeyPrimaryResponder>::handleEvent:callback:, and TestKeyEvent::hasCallback.

## ◆ TEST() [42/118]

flutter::testing::TEST | ( | FlutterEmbedderKeyResponderUnittests | ,
|  | SynthesizeForDuplicateDownEvent |
| ) |  |

Definition at line 317 of file FlutterEmbedderKeyResponderTest.mm.

317 {
318 __block NSMutableArray<TestKeyEvent*>* events = [[NSMutableArray<TestKeyEvent*> alloc] init];
319 __block BOOL last_handled = TRUE;
320 FlutterKeyEvent* event;
321
322 FlutterEmbedderKeyResponder* responder = [[FlutterEmbedderKeyResponder alloc]
323 initWithSendEvent:^(const FlutterKeyEvent& event, _Nullable FlutterKeyEventCallback callback,
324 void* _Nullable user_data) {
325 [events addObject:[[TestKeyEvent alloc] initWithEvent:&event
326 callback:callback
327 userData:user_data]];
328 }];
329
330 last_handled = TRUE;
331 [responder handleEvent:keyEvent(NSEventTypeKeyDown, 0x100, @"a", @"a", FALSE, kKeyCodeKeyA)
332 callback:^(BOOL handled) {
333 last_handled = handled;
334 }];
335
336 EXPECT_EQ([events count], 1u);
337 event = [events lastObject].data;
338 ASSERT_NE(event, nullptr);
339 EXPECT_EQ(event->type, kFlutterKeyEventTypeDown);
340 EXPECT_EQ(event->physical, kPhysicalKeyA);
341 EXPECT_EQ(event->logical, kLogicalKeyA);
342 EXPECT_STREQ(event->character, "a");
343 EXPECT_EQ(event->synthesized, false);
344 EXPECT_EQ(last_handled, TRUE);
345 [[events lastObject] respond:FALSE];
346 EXPECT_EQ(last_handled, FALSE);
347
348 [events removeAllObjects];
349
350 last_handled = TRUE;
351 [responder handleEvent:keyEvent(NSEventTypeKeyDown, 0x100, @"Ã ", @"Ã ", FALSE, kKeyCodeKeyA)
352 callback:^(BOOL handled) {
353 last_handled = handled;
354 }];
355
356 EXPECT_EQ([events count], 2u);
357
358 event = [events firstObject].data;
359 ASSERT_NE(event, nullptr);
360 EXPECT_EQ(event->type, kFlutterKeyEventTypeUp);
361 EXPECT_EQ(event->physical, kPhysicalKeyA);
362 EXPECT_EQ(event->logical, kLogicalKeyA);
363 EXPECT_STREQ(event->character, NULL);
364 EXPECT_EQ(event->synthesized, true);
365
366 event = [events lastObject].data;
367 ASSERT_NE(event, nullptr);
368 EXPECT_EQ(event->type, kFlutterKeyEventTypeDown);
369 EXPECT_EQ(event->physical, kPhysicalKeyA);
370 EXPECT_EQ(event->logical, 0xE0ull /* Ã */);
371 EXPECT_STREQ(event->character, "Ã ");
372 EXPECT_EQ(event->synthesized, false);
373 [[events lastObject] respond:FALSE];
374 EXPECT_EQ(last_handled, FALSE);
375
376 [events removeAllObjects];
377 }

References <FlutterKeyPrimaryResponder>::handleEvent:callback:.

## ◆ TEST() [43/118]

flutter::testing::TEST | ( | FlutterEmbedderKeyResponderUnittests | ,
|  | SynthesizeMissedModifierEvents |
| ) |  |

Definition at line 806 of file FlutterEmbedderKeyResponderTest.mm.

806 {
807 __block NSMutableArray<TestKeyEvent*>* events = [[NSMutableArray<TestKeyEvent*> alloc] init];
808 __block BOOL last_handled = TRUE;
809 id keyEventCallback = ^(BOOL handled) {
810 last_handled = handled;
811 };
812 FlutterKeyEvent* event;
813
814 FlutterEmbedderKeyResponder* responder = [[FlutterEmbedderKeyResponder alloc]
815 initWithSendEvent:^(const FlutterKeyEvent& event, _Nullable FlutterKeyEventCallback callback,
816 void* _Nullable user_data) {
817 [events addObject:[[TestKeyEvent alloc] initWithEvent:&event
818 callback:callback
819 userData:user_data]];
820 }];
821
822 // Case 1:
823 // In: L down, (L up), L down, L up
824 // Out: L down, L up
825 last_handled = FALSE;
826 [responder
827 handleEvent:keyEvent(NSEventTypeFlagsChanged, 0x20102, @"", @"", FALSE, kKeyCodeShiftLeft)
828 callback:keyEventCallback];
829
830 EXPECT_EQ([events count], 1u);
831 event = [events lastObject].data;
832 ASSERT_NE(event, nullptr);
833 EXPECT_EQ(event->type, kFlutterKeyEventTypeDown);
834 EXPECT_EQ(event->physical, kPhysicalShiftLeft);
835 EXPECT_EQ(event->logical, kLogicalShiftLeft);
836 EXPECT_STREQ(event->character, nullptr);
837 EXPECT_EQ(event->synthesized, false);
838
839 EXPECT_EQ(last_handled, FALSE);
840 EXPECT_TRUE([[events lastObject] hasCallback]);
841 [[events lastObject] respond:TRUE];
842 EXPECT_EQ(last_handled, TRUE);
843
844 [events removeAllObjects];
845
846 last_handled = FALSE;
847 [responder
848 handleEvent:keyEvent(NSEventTypeFlagsChanged, 0x20102, @"", @"", FALSE, kKeyCodeShiftLeft)
849 callback:keyEventCallback];
850
851 EXPECT_EQ([events count], 1u);
852 event = [events lastObject].data;
853 ASSERT_NE(event, nullptr);
854 EXPECT_EQ(event->physical, 0u);
855 EXPECT_EQ(event->logical, 0u);
856 EXPECT_FALSE([[events lastObject] hasCallback]);
857 EXPECT_EQ(last_handled, TRUE);
858 [events removeAllObjects];
859
860 last_handled = FALSE;
861 [responder
862 handleEvent:keyEvent(NSEventTypeFlagsChanged, 0x100, @"", @"", FALSE, kKeyCodeShiftLeft)
863 callback:keyEventCallback];
864
865 EXPECT_EQ([events count], 1u);
866 event = [events lastObject].data;
867 ASSERT_NE(event, nullptr);
868 EXPECT_EQ(event->type, kFlutterKeyEventTypeUp);
869 EXPECT_EQ(event->physical, kPhysicalShiftLeft);
870 EXPECT_EQ(event->logical, kLogicalShiftLeft);
871 EXPECT_STREQ(event->character, nullptr);
872 EXPECT_EQ(event->synthesized, false);
873
874 EXPECT_EQ(last_handled, FALSE);
875 EXPECT_TRUE([[events lastObject] hasCallback]);
876 [[events lastObject] respond:TRUE];
877 EXPECT_EQ(last_handled, TRUE);
878
879 [events removeAllObjects];
880
881 // Case 2:
882 // In: (L down), L up
883 // Out:
884
885 last_handled = FALSE;
886 [responder
887 handleEvent:keyEvent(NSEventTypeFlagsChanged, 0x100, @"", @"", FALSE, kKeyCodeShiftLeft)
888 callback:keyEventCallback];
889
890 EXPECT_EQ([events count], 1u);
891 event = [events lastObject].data;
892 ASSERT_NE(event, nullptr);
893 EXPECT_EQ(event->physical, 0u);
894 EXPECT_EQ(event->logical, 0u);
895 EXPECT_FALSE([[events lastObject] hasCallback]);
896 EXPECT_EQ(last_handled, TRUE);
897 [events removeAllObjects];
898
899 // Case 3:
900 // In: L down, (L up), (R down), R up
901 // Out: L down, *L up
902
903 last_handled = FALSE;
904 [responder
905 handleEvent:keyEvent(NSEventTypeFlagsChanged, 0x20102, @"", @"", FALSE, kKeyCodeShiftLeft)
906 callback:keyEventCallback];
907
908 EXPECT_EQ([events count], 1u);
909 event = [events lastObject].data;
910 ASSERT_NE(event, nullptr);
911 EXPECT_EQ(event->type, kFlutterKeyEventTypeDown);
912 EXPECT_EQ(event->physical, kPhysicalShiftLeft);
913 EXPECT_EQ(event->logical, kLogicalShiftLeft);
914 EXPECT_STREQ(event->character, nullptr);
915 EXPECT_EQ(event->synthesized, false);
916
917 EXPECT_EQ(last_handled, FALSE);
918 EXPECT_TRUE([[events lastObject] hasCallback]);
919 [[events lastObject] respond:TRUE];
920 EXPECT_EQ(last_handled, TRUE);
921
922 [events removeAllObjects];
923
924 last_handled = FALSE;
925 [responder
926 handleEvent:keyEvent(NSEventTypeFlagsChanged, 0x100, @"", @"", FALSE, kKeyCodeShiftRight)
927 callback:keyEventCallback];
928
929 EXPECT_EQ([events count], 1u);
930 event = [events lastObject].data;
931 ASSERT_NE(event, nullptr);
932 EXPECT_EQ(event->type, kFlutterKeyEventTypeUp);
933 EXPECT_EQ(event->physical, kPhysicalShiftLeft);
934 EXPECT_EQ(event->logical, kLogicalShiftLeft);
935 EXPECT_STREQ(event->character, nullptr);
936 EXPECT_EQ(event->synthesized, true);
937
938 // The primary event is automatically replied with TRUE, unrelated to the received event.
939 EXPECT_EQ(last_handled, TRUE);
940 EXPECT_FALSE([[events lastObject] hasCallback]);
941
942 [events removeAllObjects];
943
944 // Case 4:
945 // In: L down, R down, (L up), R up
946 // Out: L down, R down *L up & R up
947
948 last_handled = FALSE;
949 [responder
950 handleEvent:keyEvent(NSEventTypeFlagsChanged, 0x20102, @"", @"", FALSE, kKeyCodeShiftLeft)
951 callback:keyEventCallback];
952
953 EXPECT_EQ([events count], 1u);
954 event = [events lastObject].data;
955 ASSERT_NE(event, nullptr);
956 EXPECT_EQ(event->type, kFlutterKeyEventTypeDown);
957 EXPECT_EQ(event->physical, kPhysicalShiftLeft);
958 EXPECT_EQ(event->logical, kLogicalShiftLeft);
959 EXPECT_STREQ(event->character, nullptr);
960 EXPECT_EQ(event->synthesized, false);
961
962 EXPECT_EQ(last_handled, FALSE);
963 EXPECT_TRUE([[events lastObject] hasCallback]);
964 [[events lastObject] respond:TRUE];
965 EXPECT_EQ(last_handled, TRUE);
966
967 [events removeAllObjects];
968
969 last_handled = FALSE;
970 [responder
971 handleEvent:keyEvent(NSEventTypeFlagsChanged, 0x20106, @"", @"", FALSE, kKeyCodeShiftRight)
972 callback:keyEventCallback];
973
974 EXPECT_EQ([events count], 1u);
975 event = [events lastObject].data;
976 ASSERT_NE(event, nullptr);
977 EXPECT_EQ(event->type, kFlutterKeyEventTypeDown);
978 EXPECT_EQ(event->physical, kPhysicalShiftRight);
979 EXPECT_EQ(event->logical, kLogicalShiftRight);
980 EXPECT_STREQ(event->character, nullptr);
981 EXPECT_EQ(event->synthesized, false);
982
983 EXPECT_EQ(last_handled, FALSE);
984 EXPECT_TRUE([[events lastObject] hasCallback]);
985 [[events lastObject] respond:TRUE];
986 EXPECT_EQ(last_handled, TRUE);
987
988 [events removeAllObjects];
989
990 last_handled = FALSE;
991 [responder
992 handleEvent:keyEvent(NSEventTypeFlagsChanged, 0x100, @"", @"", FALSE, kKeyCodeShiftRight)
993 callback:keyEventCallback];
994
995 EXPECT_EQ([events count], 2u);
996 event = [events firstObject].data;
997 ASSERT_NE(event, nullptr);
998 EXPECT_EQ(event->type, kFlutterKeyEventTypeUp);
999 EXPECT_EQ(event->physical, kPhysicalShiftLeft);
1000 EXPECT_EQ(event->logical, kLogicalShiftLeft);
1001 EXPECT_STREQ(event->character, nullptr);
1002 EXPECT_EQ(event->synthesized, true);
1003
1004 EXPECT_FALSE([[events firstObject] hasCallback]);
1005
1006 event = [events lastObject].data;
1007 ASSERT_NE(event, nullptr);
1008 EXPECT_EQ(event->type, kFlutterKeyEventTypeUp);
1009 EXPECT_EQ(event->physical, kPhysicalShiftRight);
1010 EXPECT_EQ(event->logical, kLogicalShiftRight);
1011 EXPECT_STREQ(event->character, nullptr);
1012 EXPECT_EQ(event->synthesized, false);
1013
1014 EXPECT_EQ(last_handled, FALSE);
1015 EXPECT_TRUE([[events lastObject] hasCallback]);
1016 [[events lastObject] respond:TRUE];
1017 EXPECT_EQ(last_handled, TRUE);
1018
1019 [events removeAllObjects];
1020 }

References <FlutterKeyPrimaryResponder>::handleEvent:callback:, and TestKeyEvent::hasCallback.

## ◆ TEST() [44/118]

flutter::testing::TEST | ( | FlutterEmbedderKeyResponderUnittests | ,
|  | SynthesizeMissedModifierEventsInNormalEvents |
| ) |  |

Definition at line 1022 of file FlutterEmbedderKeyResponderTest.mm.

1022 {
1023 __block NSMutableArray<TestKeyEvent*>* events = [[NSMutableArray<TestKeyEvent*> alloc] init];
1024 __block BOOL last_handled = TRUE;
1025 id keyEventCallback = ^(BOOL handled) {
1026 last_handled = handled;
1027 };
1028 FlutterKeyEvent* event;
1029
1030 FlutterEmbedderKeyResponder* responder = [[FlutterEmbedderKeyResponder alloc]
1031 initWithSendEvent:^(const FlutterKeyEvent& event, _Nullable FlutterKeyEventCallback callback,
1032 void* _Nullable user_data) {
1033 [events addObject:[[TestKeyEvent alloc] initWithEvent:&event
1034 callback:callback
1035 userData:user_data]];
1036 }];
1037
1038 // In: (LShift down), A down, (LShift up), A up
1039 // Out: *LS down & A down, *LS up & A up
1040
1041 last_handled = FALSE;
1042 [responder handleEvent:keyEvent(NSEventTypeKeyDown, 0x20102, @"A", @"A", FALSE, kKeyCodeKeyA)
1043 callback:keyEventCallback];
1044
1045 EXPECT_EQ([events count], 2u);
1046 event = [events firstObject].data;
1047 ASSERT_NE(event, nullptr);
1048 EXPECT_EQ(event->type, kFlutterKeyEventTypeDown);
1049 EXPECT_EQ(event->physical, kPhysicalShiftLeft);
1050 EXPECT_EQ(event->logical, kLogicalShiftLeft);
1051 EXPECT_STREQ(event->character, nullptr);
1052 EXPECT_EQ(event->synthesized, true);
1053 EXPECT_FALSE([[events firstObject] hasCallback]);
1054
1055 event = [events lastObject].data;
1056 ASSERT_NE(event, nullptr);
1057 EXPECT_EQ(event->type, kFlutterKeyEventTypeDown);
1058 EXPECT_EQ(event->physical, kPhysicalKeyA);
1059 EXPECT_EQ(event->logical, kLogicalKeyA);
1060 EXPECT_STREQ(event->character, "A");
1061 EXPECT_EQ(event->synthesized, false);
1062 EXPECT_TRUE([[events lastObject] hasCallback]);
1063
1064 EXPECT_EQ(last_handled, FALSE);
1065 [[events lastObject] respond:TRUE];
1066 EXPECT_EQ(last_handled, TRUE);
1067
1068 [events removeAllObjects];
1069
1070 last_handled = FALSE;
1071 [responder handleEvent:keyEvent(NSEventTypeKeyUp, 0x100, @"a", @"a", FALSE, kKeyCodeKeyA)
1072 callback:keyEventCallback];
1073
1074 EXPECT_EQ([events count], 2u);
1075 event = [events firstObject].data;
1076 ASSERT_NE(event, nullptr);
1077 EXPECT_EQ(event->type, kFlutterKeyEventTypeUp);
1078 EXPECT_EQ(event->physical, kPhysicalShiftLeft);
1079 EXPECT_EQ(event->logical, kLogicalShiftLeft);
1080 EXPECT_STREQ(event->character, nullptr);
1081 EXPECT_EQ(event->synthesized, true);
1082 EXPECT_FALSE([[events firstObject] hasCallback]);
1083
1084 event = [events lastObject].data;
1085 ASSERT_NE(event, nullptr);
1086 EXPECT_EQ(event->type, kFlutterKeyEventTypeUp);
1087 EXPECT_EQ(event->physical, kPhysicalKeyA);
1088 EXPECT_EQ(event->logical, kLogicalKeyA);
1089 EXPECT_STREQ(event->character, nullptr);
1090 EXPECT_EQ(event->synthesized, false);
1091 EXPECT_TRUE([[events lastObject] hasCallback]);
1092
1093 EXPECT_EQ(last_handled, FALSE);
1094 [[events lastObject] respond:TRUE];
1095 EXPECT_EQ(last_handled, TRUE);
1096
1097 [events removeAllObjects];
1098 }

References <FlutterKeyPrimaryResponder>::handleEvent:callback:, and TestKeyEvent::hasCallback.

## ◆ TEST() [45/118]

flutter::testing::TEST | ( | FlutterEmbedderKeyResponderUnittests | ,
|  | ToggleModifiersDuringKeyTap |
| ) |  |

Definition at line 448 of file FlutterEmbedderKeyResponderTest.mm.

448 {
449 __block NSMutableArray<TestKeyEvent*>* events = [[NSMutableArray<TestKeyEvent*> alloc] init];
450 FlutterKeyEvent* event;
451
452 FlutterEmbedderKeyResponder* responder = [[FlutterEmbedderKeyResponder alloc]
453 initWithSendEvent:^(const FlutterKeyEvent& event, _Nullable FlutterKeyEventCallback callback,
454 void* _Nullable user_data) {
455 [events addObject:[[TestKeyEvent alloc] initWithEvent:&event
456 callback:callback
457 userData:user_data]];
458 }];
459
460 [responder handleEvent:keyEvent(NSEventTypeFlagsChanged, 123.0f, 0x20104, @"", @"", FALSE,
461 kKeyCodeShiftRight)
462 callback:^(BOOL handled){
463 }];
464
465 EXPECT_EQ([events count], 1u);
466 event = [events lastObject].data;
467 ASSERT_NE(event, nullptr);
468 EXPECT_EQ(event->type, kFlutterKeyEventTypeDown);
469 EXPECT_EQ(event->timestamp, 123000000.0f);
470 EXPECT_EQ(event->physical, kPhysicalShiftRight);
471 EXPECT_EQ(event->logical, kLogicalShiftRight);
472 EXPECT_STREQ(event->character, nullptr);
473 EXPECT_EQ(event->synthesized, false);
474 [[events lastObject] respond:TRUE];
475
476 [events removeAllObjects];
477
478 [responder handleEvent:keyEvent(NSEventTypeKeyDown, 0x20104, @"A", @"A", FALSE, kKeyCodeKeyA)
479 callback:^(BOOL handled){
480 }];
481
482 EXPECT_EQ([events count], 1u);
483 event = [events lastObject].data;
484 ASSERT_NE(event, nullptr);
485 EXPECT_EQ(event->type, kFlutterKeyEventTypeDown);
486 EXPECT_EQ(event->physical, kPhysicalKeyA);
487 EXPECT_EQ(event->logical, kLogicalKeyA);
488 EXPECT_STREQ(event->character, "A");
489 EXPECT_EQ(event->synthesized, false);
490 [[events lastObject] respond:TRUE];
491
492 [events removeAllObjects];
493
494 [responder handleEvent:keyEvent(NSEventTypeKeyDown, 0x20104, @"A", @"A", TRUE, kKeyCodeKeyA)
495 callback:^(BOOL handled){
496 }];
497
498 EXPECT_EQ([events count], 1u);
499 event = [events lastObject].data;
500 ASSERT_NE(event, nullptr);
501 EXPECT_EQ(event->type, kFlutterKeyEventTypeRepeat);
502 EXPECT_EQ(event->physical, kPhysicalKeyA);
503 EXPECT_EQ(event->logical, kLogicalKeyA);
504 EXPECT_STREQ(event->character, "A");
505 EXPECT_EQ(event->synthesized, false);
506 [[events lastObject] respond:TRUE];
507
508 [events removeAllObjects];
509
510 [responder
511 handleEvent:keyEvent(NSEventTypeFlagsChanged, 0x100, @"", @"", FALSE, kKeyCodeShiftRight)
512 callback:^(BOOL handled){
513 }];
514
515 EXPECT_EQ([events count], 1u);
516 event = [events lastObject].data;
517 ASSERT_NE(event, nullptr);
518 EXPECT_EQ(event->type, kFlutterKeyEventTypeUp);
519 EXPECT_EQ(event->physical, kPhysicalShiftRight);
520 EXPECT_EQ(event->logical, kLogicalShiftRight);
521 EXPECT_STREQ(event->character, nullptr);
522 EXPECT_EQ(event->synthesized, false);
523 [[events lastObject] respond:TRUE];
524
525 [events removeAllObjects];
526
527 [responder handleEvent:keyEvent(NSEventTypeKeyDown, 0x100, @"a", @"a", TRUE, kKeyCodeKeyA)
528 callback:^(BOOL handled){
529 }];
530
531 EXPECT_EQ([events count], 1u);
532 event = [events lastObject].data;
533 ASSERT_NE(event, nullptr);
534 EXPECT_EQ(event->type, kFlutterKeyEventTypeRepeat);
535 EXPECT_EQ(event->physical, kPhysicalKeyA);
536 EXPECT_EQ(event->logical, kLogicalKeyA);
537 EXPECT_STREQ(event->character, "a");
538 EXPECT_EQ(event->synthesized, false);
539
540 [events removeAllObjects];
541
542 [responder handleEvent:keyEvent(NSEventTypeKeyUp, 0x100, @"a", @"a", FALSE, kKeyCodeKeyA)
543 callback:^(BOOL handled){
544 }];
545
546 EXPECT_EQ([events count], 1u);
547 event = [events lastObject].data;
548 ASSERT_NE(event, nullptr);
549 EXPECT_EQ(event->type, kFlutterKeyEventTypeUp);
550 EXPECT_EQ(event->physical, kPhysicalKeyA);
551 EXPECT_EQ(event->logical, kLogicalKeyA);
552 EXPECT_STREQ(event->character, nullptr);
553 EXPECT_EQ(event->synthesized, false);
554 [[events lastObject] respond:TRUE];
555
556 [events removeAllObjects];
557 }

References <FlutterKeyPrimaryResponder>::handleEvent:callback:.

## ◆ TEST() [46/118]

flutter::testing::TEST | ( | FlutterKeyboardManagerUnittests | ,
|  | CorrectLogicalKeyForLayouts |
| ) |  |

Definition at line 469 of file FlutterKeyboardManagerTest.mm.

469 {
470 ASSERT_TRUE([[FlutterKeyboardManagerUnittestsObjC alloc] correctLogicalKeyForLayouts]);
471 }
FlutterKeyboardManagerUnittestsObjC
Definition: FlutterKeyboardManagerTest.mm:428

## ◆ TEST() [47/118]

flutter::testing::TEST | ( | FlutterKeyboardManagerUnittests | ,
|  | DoublePrimaryResponder |
| ) |  |

Definition at line 445 of file FlutterKeyboardManagerTest.mm.

445 {
446 ASSERT_TRUE([[FlutterKeyboardManagerUnittestsObjC alloc] doublePrimaryResponder]);
447 }

## ◆ TEST() [48/118]

flutter::testing::TEST | ( | FlutterKeyboardManagerUnittests | ,
|  | EmptyNextResponder |
| ) |  |

Definition at line 453 of file FlutterKeyboardManagerTest.mm.

453 {
454 ASSERT_TRUE([[FlutterKeyboardManagerUnittestsObjC alloc] emptyNextResponder]);
455 }

## ◆ TEST() [49/118]

flutter::testing::TEST | ( | FlutterKeyboardManagerUnittests | ,
|  | GetPressedState |
| ) |  |

Definition at line 457 of file FlutterKeyboardManagerTest.mm.

457 {
458 ASSERT_TRUE([[FlutterKeyboardManagerUnittestsObjC alloc] getPressedState]);
459 }

## ◆ TEST() [50/118]

flutter::testing::TEST | ( | FlutterKeyboardManagerUnittests | ,
|  | KeyboardChannelGetPressedState |
| ) |  |

Definition at line 461 of file FlutterKeyboardManagerTest.mm.

461 {
462 ASSERT_TRUE([[FlutterKeyboardManagerUnittestsObjC alloc] keyboardChannelGetPressedState]);
463 }

## ◆ TEST() [51/118]

flutter::testing::TEST | ( | FlutterKeyboardManagerUnittests | ,
|  | RacingConditionBetweenKeyAndText |
| ) |  |

Definition at line 465 of file FlutterKeyboardManagerTest.mm.

465 {
466 ASSERT_TRUE([[FlutterKeyboardManagerUnittestsObjC alloc] racingConditionBetweenKeyAndText]);
467 }

## ◆ TEST() [52/118]

flutter::testing::TEST | ( | FlutterKeyboardManagerUnittests | ,
|  | ShouldNotHoldStrongReferenceToDelegate |
| ) |  |

Definition at line 473 of file FlutterKeyboardManagerTest.mm.

473 {
474 ASSERT_TRUE([[FlutterKeyboardManagerUnittestsObjC alloc] shouldNotHoldStrongReferenceToDelegate]);
475 }

## ◆ TEST() [53/118]

flutter::testing::TEST | ( | FlutterKeyboardManagerUnittests | ,
|  | SingleFinalResponder |
| ) |  |

Definition at line 449 of file FlutterKeyboardManagerTest.mm.

449 {
450 ASSERT_TRUE([[FlutterKeyboardManagerUnittestsObjC alloc] textInputPlugin]);
451 }

## ◆ TEST() [54/118]

flutter::testing::TEST | ( | FlutterKeyboardManagerUnittests | ,
|  | SinglePrimaryResponder |
| ) |  |

Definition at line 441 of file FlutterKeyboardManagerTest.mm.

441 {
442 ASSERT_TRUE([[FlutterKeyboardManagerUnittestsObjC alloc] singlePrimaryResponder]);
443 }

## ◆ TEST() [55/118]

flutter::testing::TEST | ( | FlutterPlatformNodeDelegateMac | ,
|  | Basics |
| ) |  |

Definition at line 32 of file FlutterPlatformNodeDelegateMacTest.mm.

32 {
33 FlutterViewController* viewController = CreateTestViewController();
34 FlutterEngine* engine = viewController.engine;
35 engine.semanticsEnabled = YES;
36 auto bridge = viewController.accessibilityBridge.lock();
37 // Initialize ax node data.
38 FlutterSemanticsNode2 root;
39 root.id = 0;
40 root.flags = static_cast<FlutterSemanticsFlag>(0);
41 ;
42 root.actions = static_cast<FlutterSemanticsAction>(0);
43 root.text_selection_base = -1;
44 root.text_selection_extent = -1;
45 root.label = "accessibility";
46 root.hint = "";
47 root.value = "";
48 root.increased_value = "";
49 root.decreased_value = "";
50 root.tooltip = "";
51 root.child_count = 0;
52 root.custom_accessibility_actions_count = 0;
53 bridge->AddFlutterSemanticsNodeUpdate(root);
54
55 bridge->CommitUpdates();
56
57 auto root_platform_node_delegate = bridge->GetFlutterPlatformNodeDelegateFromID(0).lock();
58 // Verify the accessibility attribute matches.
59 NSAccessibilityElement* native_accessibility =
60 root_platform_node_delegate->GetNativeViewAccessible();
61 std::string value = [native_accessibility.accessibilityValue UTF8String];
62 EXPECT_TRUE(value == "accessibility");
63 EXPECT_EQ(native_accessibility.accessibilityRole, NSAccessibilityStaticTextRole);
64 EXPECT_EQ([native_accessibility.accessibilityChildren count], 0u);
65 [engine shutDownEngine];
66 }
FlutterViewController::engine
FlutterEngine * engine
Definition: FlutterViewController.h:78

References FlutterViewController::engine.

## ◆ TEST() [56/118]

flutter::testing::TEST | ( | FlutterPlatformNodeDelegateMac | ,
|  | CanPerformAction |
| ) |  |

Definition at line 149 of file FlutterPlatformNodeDelegateMacTest.mm.

149 {
150 FlutterViewController* viewController = CreateTestViewController();
151 FlutterEngine* engine = viewController.engine;
152
153 // Attach the view to a NSWindow.
154 NSWindow* window = [[NSWindow alloc] initWithContentRect:NSMakeRect(0, 0, 800, 600)
155 styleMask:NSBorderlessWindowMask
156 backing:NSBackingStoreBuffered
157 defer:NO];
158 window.contentView = viewController.view;
159
160 engine.semanticsEnabled = YES;
161 auto bridge = viewController.accessibilityBridge.lock();
162 // Initialize ax node data.
163 FlutterSemanticsNode2 root;
164 root.id = 0;
165 root.label = "root";
166 root.hint = "";
167 root.value = "";
168 root.increased_value = "";
169 root.decreased_value = "";
170 root.tooltip = "";
171 root.child_count = 1;
172 int32_t children[] = {1};
173 root.children_in_traversal_order = children;
174 root.custom_accessibility_actions_count = 0;
175 bridge->AddFlutterSemanticsNodeUpdate(root);
176
177 FlutterSemanticsNode2 child1;
178 child1.id = 1;
179 child1.label = "child 1";
180 child1.hint = "";
181 child1.value = "";
182 child1.increased_value = "";
183 child1.decreased_value = "";
184 child1.tooltip = "";
185 child1.child_count = 0;
186 child1.custom_accessibility_actions_count = 0;
187 bridge->AddFlutterSemanticsNodeUpdate(child1);
188
189 bridge->CommitUpdates();
190
191 auto root_platform_node_delegate = bridge->GetFlutterPlatformNodeDelegateFromID(1).lock();
192
193 // Set up embedder API mock.
194 FlutterSemanticsAction called_action;
195 uint64_t called_id;
196
197 engine.embedderAPI.DispatchSemanticsAction = MOCK_ENGINE_PROC(
198 DispatchSemanticsAction,
199 ([&called_id, &called_action](auto engine, uint64_t id, FlutterSemanticsAction action,
200 const uint8_t* data, size_t data_length) {
201 called_id = id;
202 called_action = action;
203 return kSuccess;
204 }));
205
206 // Performs an AXAction.
207 ui::AXActionData action_data;
208 action_data.action = ax::mojom::Action::kDoDefault;
209 root_platform_node_delegate->AccessibilityPerformAction(action_data);
210
211 EXPECT_EQ(called_action, FlutterSemanticsAction::kFlutterSemanticsActionTap);
212 EXPECT_EQ(called_id, 1u);
213
214 [engine setViewController:nil];
215 [engine shutDownEngine];
216 }

References FlutterViewController::engine.

## ◆ TEST() [57/118]

flutter::testing::TEST | ( | FlutterPlatformNodeDelegateMac | ,
|  | ChangingFlagsUpdatesNativeViewAccessible |
| ) |  |

Definition at line 299 of file FlutterPlatformNodeDelegateMacTest.mm.

299 {
300 FlutterViewController* viewController = CreateTestViewController();
301 FlutterEngine* engine = viewController.engine;
302 [viewController loadView];
303
304 // Creates a NSWindow so that the native text field can become first responder.
305 NSWindow* window = [[NSWindow alloc] initWithContentRect:NSMakeRect(0, 0, 800, 600)
306 styleMask:NSBorderlessWindowMask
307 backing:NSBackingStoreBuffered
308 defer:NO];
309 window.contentView = viewController.view;
310 engine.semanticsEnabled = YES;
311
312 auto bridge = viewController.accessibilityBridge.lock();
313 // Initialize ax node data.
314 FlutterSemanticsNode2 root;
315 root.id = 0;
316 root.flags = static_cast<FlutterSemanticsFlag>(0);
317 root.actions = static_cast<FlutterSemanticsAction>(0);
318 root.label = "root";
319 root.hint = "";
320 root.value = "";
321 root.increased_value = "";
322 root.decreased_value = "";
323 root.tooltip = "";
324 root.child_count = 1;
325 int32_t children[] = {1};
326 root.children_in_traversal_order = children;
327 root.custom_accessibility_actions_count = 0;
328 root.rect = {0, 0, 100, 100}; // LTRB
329 root.transform = {1, 0, 0, 0, 1, 0, 0, 0, 1};
330 bridge->AddFlutterSemanticsNodeUpdate(root);
331
332 double rectSize = 50;
333 double transformFactor = 0.5;
334
335 FlutterSemanticsNode2 child1;
336 child1.id = 1;
337 child1.flags = static_cast<FlutterSemanticsFlag>(0);
338 child1.actions = static_cast<FlutterSemanticsAction>(0);
339 child1.label = "";
340 child1.hint = "";
341 child1.value = "textfield";
342 child1.increased_value = "";
343 child1.decreased_value = "";
344 child1.tooltip = "";
345 child1.text_selection_base = -1;
346 child1.text_selection_extent = -1;
347 child1.child_count = 0;
348 child1.custom_accessibility_actions_count = 0;
349 child1.rect = {0, 0, rectSize, rectSize}; // LTRB
350 child1.transform = {transformFactor, 0, 0, 0, transformFactor, 0, 0, 0, 1};
351 bridge->AddFlutterSemanticsNodeUpdate(child1);
352
353 bridge->CommitUpdates();
354
355 auto child_platform_node_delegate = bridge->GetFlutterPlatformNodeDelegateFromID(1).lock();
356 // Verify the accessibility attribute matches.
357 id native_accessibility = child_platform_node_delegate->GetNativeViewAccessible();
358 EXPECT_TRUE([[native_accessibility className] isEqualToString:@"AXPlatformNodeCocoa"]);
359
360 // Converting child to text field should produce `FlutterTextField` native view accessible.
361 child1.flags = FlutterSemanticsFlag::kFlutterSemanticsFlagIsTextField;
362 bridge->AddFlutterSemanticsNodeUpdate(child1);
363 bridge->CommitUpdates();
364
365 native_accessibility = child_platform_node_delegate->GetNativeViewAccessible();
366 EXPECT_TRUE([native_accessibility isKindOfClass:[FlutterTextField class]]);
367
368 child1.flags = static_cast<FlutterSemanticsFlag>(0);
369 bridge->AddFlutterSemanticsNodeUpdate(child1);
370 bridge->CommitUpdates();
371
372 native_accessibility = child_platform_node_delegate->GetNativeViewAccessible();
373 EXPECT_TRUE([[native_accessibility className] isEqualToString:@"AXPlatformNodeCocoa"]);
374 }
FlutterTextField
Definition: FlutterTextInputSemanticsObject.h:82

References FlutterViewController::engine.

## ◆ TEST() [58/118]

flutter::testing::TEST | ( | FlutterPlatformNodeDelegateMac | ,
|  | SelectableTextHasCorrectSemantics |
| ) |  |

Definition at line 68 of file FlutterPlatformNodeDelegateMacTest.mm.

68 {
69 FlutterViewController* viewController = CreateTestViewController();
70 FlutterEngine* engine = viewController.engine;
71 engine.semanticsEnabled = YES;
72 auto bridge = viewController.accessibilityBridge.lock();
73 // Initialize ax node data.
74 FlutterSemanticsNode2 root;
75 root.id = 0;
76 root.flags =
77 static_cast<FlutterSemanticsFlag>(FlutterSemanticsFlag::kFlutterSemanticsFlagIsTextField |
78 FlutterSemanticsFlag::kFlutterSemanticsFlagIsReadOnly);
79 root.actions = static_cast<FlutterSemanticsAction>(0);
80 root.text_selection_base = 1;
81 root.text_selection_extent = 3;
82 root.label = "";
83 root.hint = "";
84 // Selectable text store its text in value
85 root.value = "selectable text";
86 root.increased_value = "";
87 root.decreased_value = "";
88 root.tooltip = "";
89 root.child_count = 0;
90 root.custom_accessibility_actions_count = 0;
91 bridge->AddFlutterSemanticsNodeUpdate(root);
92
93 bridge->CommitUpdates();
94
95 auto root_platform_node_delegate = bridge->GetFlutterPlatformNodeDelegateFromID(0).lock();
96 // Verify the accessibility attribute matches.
97 NSAccessibilityElement* native_accessibility =
98 root_platform_node_delegate->GetNativeViewAccessible();
99 std::string value = [native_accessibility.accessibilityValue UTF8String];
100 EXPECT_EQ(value, "selectable text");
101 EXPECT_EQ(native_accessibility.accessibilityRole, NSAccessibilityStaticTextRole);
102 EXPECT_EQ([native_accessibility.accessibilityChildren count], 0u);
103 NSRange selection = native_accessibility.accessibilitySelectedTextRange;
104 EXPECT_EQ(selection.location, 1u);
105 EXPECT_EQ(selection.length, 2u);
106 std::string selected_text = [native_accessibility.accessibilitySelectedText UTF8String];
107 EXPECT_EQ(selected_text, "el");
108 }

References FlutterViewController::engine.

## ◆ TEST() [59/118]

flutter::testing::TEST | ( | FlutterPlatformNodeDelegateMac | ,
|  | SelectableTextWithoutSelectionReturnZeroRange |
| ) |  |

Definition at line 110 of file FlutterPlatformNodeDelegateMacTest.mm.

110 {
111 FlutterViewController* viewController = CreateTestViewController();
112 FlutterEngine* engine = viewController.engine;
113 engine.semanticsEnabled = YES;
114 auto bridge = viewController.accessibilityBridge.lock();
115 // Initialize ax node data.
116 FlutterSemanticsNode2 root;
117 root.id = 0;
118 root.flags =
119 static_cast<FlutterSemanticsFlag>(FlutterSemanticsFlag::kFlutterSemanticsFlagIsTextField |
120 FlutterSemanticsFlag::kFlutterSemanticsFlagIsReadOnly);
121 root.actions = static_cast<FlutterSemanticsAction>(0);
122 root.text_selection_base = -1;
123 root.text_selection_extent = -1;
124 root.label = "";
125 root.hint = "";
126 // Selectable text store its text in value
127 root.value = "selectable text";
128 root.increased_value = "";
129 root.decreased_value = "";
130 root.tooltip = "";
131 root.child_count = 0;
132 root.custom_accessibility_actions_count = 0;
133 bridge->AddFlutterSemanticsNodeUpdate(root);
134
135 bridge->CommitUpdates();
136
137 auto root_platform_node_delegate = bridge->GetFlutterPlatformNodeDelegateFromID(0).lock();
138 // Verify the accessibility attribute matches.
139 NSAccessibilityElement* native_accessibility =
140 root_platform_node_delegate->GetNativeViewAccessible();
141 NSRange selection = native_accessibility.accessibilitySelectedTextRange;
142 EXPECT_TRUE(selection.location == NSNotFound);
143 EXPECT_EQ(selection.length, 0u);
144 }

References FlutterViewController::engine.

## ◆ TEST() [60/118]

flutter::testing::TEST | ( | FlutterPlatformNodeDelegateMac | ,
|  | TextFieldUsesFlutterTextField |
| ) |  |

Definition at line 220 of file FlutterPlatformNodeDelegateMacTest.mm.

220 {
221 FlutterViewController* viewController = CreateTestViewController();
222 FlutterEngine* engine = viewController.engine;
223 [viewController loadView];
224
225 // Unit test localization is unnecessary.
226 // NOLINTNEXTLINE(clang-analyzer-optin.osx.cocoa.localizability.NonLocalizedStringChecker)
227 engine.textInputPlugin.string = @"textfield";
228 // Creates a NSWindow so that the native text field can become first responder.
229 NSWindow* window = [[NSWindow alloc] initWithContentRect:NSMakeRect(0, 0, 800, 600)
230 styleMask:NSBorderlessWindowMask
231 backing:NSBackingStoreBuffered
232 defer:NO];
233 window.contentView = viewController.view;
234 engine.semanticsEnabled = YES;
235
236 auto bridge = viewController.accessibilityBridge.lock();
237 // Initialize ax node data.
238 FlutterSemanticsNode2 root;
239 root.id = 0;
240 root.flags = static_cast<FlutterSemanticsFlag>(0);
241 root.actions = static_cast<FlutterSemanticsAction>(0);
242 root.label = "root";
243 root.hint = "";
244 root.value = "";
245 root.increased_value = "";
246 root.decreased_value = "";
247 root.tooltip = "";
248 root.child_count = 1;
249 int32_t children[] = {1};
250 root.children_in_traversal_order = children;
251 root.custom_accessibility_actions_count = 0;
252 root.rect = {0, 0, 100, 100}; // LTRB
253 root.transform = {1, 0, 0, 0, 1, 0, 0, 0, 1};
254 bridge->AddFlutterSemanticsNodeUpdate(root);
255
256 double rectSize = 50;
257 double transformFactor = 0.5;
258
259 FlutterSemanticsNode2 child1;
260 child1.id = 1;
261 child1.flags = FlutterSemanticsFlag::kFlutterSemanticsFlagIsTextField;
262 child1.actions = static_cast<FlutterSemanticsAction>(0);
263 child1.label = "";
264 child1.hint = "";
265 child1.value = "textfield";
266 child1.increased_value = "";
267 child1.decreased_value = "";
268 child1.tooltip = "";
269 child1.text_selection_base = -1;
270 child1.text_selection_extent = -1;
271 child1.child_count = 0;
272 child1.custom_accessibility_actions_count = 0;
273 child1.rect = {0, 0, rectSize, rectSize}; // LTRB
274 child1.transform = {transformFactor, 0, 0, 0, transformFactor, 0, 0, 0, 1};
275 bridge->AddFlutterSemanticsNodeUpdate(child1);
276
277 bridge->CommitUpdates();
278
279 auto child_platform_node_delegate = bridge->GetFlutterPlatformNodeDelegateFromID(1).lock();
280 // Verify the accessibility attribute matches.
281 id native_accessibility = child_platform_node_delegate->GetNativeViewAccessible();
282 EXPECT_EQ([native_accessibility isKindOfClass:[FlutterTextField class]], YES);
283 FlutterTextField* native_text_field = (FlutterTextField*)native_accessibility;
284
285 NSView* view = viewController.flutterView;
286 CGRect scaledBounds = [view convertRectToBacking:view.bounds];
287 CGSize scaledSize = scaledBounds.size;
288 double pixelRatio = view.bounds.size.width == 0 ? 1 : scaledSize.width / view.bounds.size.width;
289
290 double expectedFrameSize = rectSize * transformFactor / pixelRatio;
291 EXPECT_EQ(NSEqualRects(native_text_field.frame, NSMakeRect(0, 600 - expectedFrameSize,
292 expectedFrameSize, expectedFrameSize)),
293 YES);
294
295 [native_text_field startEditing];
296 EXPECT_EQ([native_text_field.stringValue isEqualToString:@"textfield"], YES);
297 }

References FlutterViewController::engine.

## ◆ TEST() [61/118]

flutter::testing::TEST | ( | FlutterPlatformNodeDelegateTest | ,
|  | canCalculateBoundsCorrectly |
| ) |  |

Definition at line 110 of file flutter_platform_node_delegate_unittests.cc.

110 {
111 std::shared_ptr<TestAccessibilityBridge> bridge =
112 std::make_shared<TestAccessibilityBridge>();
113 FlutterSemanticsNode2 root;
114 root.id = 0;
115 root.label = "root";
116 root.hint = "";
117 root.value = "";
118 root.increased_value = "";
119 root.decreased_value = "";
120 root.tooltip = "";
121 root.child_count = 1;
122 int32_t children[] = {1};
123 root.children_in_traversal_order = children;
124 root.custom_accessibility_actions_count = 0;
125 root.rect = {0, 0, 100, 100}; // LTRB
126 root.transform = {1, 0, 0, 0, 1, 0, 0, 0, 1};
127 bridge->AddFlutterSemanticsNodeUpdate(root);
128
129 FlutterSemanticsNode2 child1;
130 child1.id = 1;
131 child1.label = "child 1";
132 child1.hint = "";
133 child1.value = "";
134 child1.increased_value = "";
135 child1.decreased_value = "";
136 child1.tooltip = "";
137 child1.child_count = 0;
138 child1.custom_accessibility_actions_count = 0;
139 child1.rect = {0, 0, 50, 50}; // LTRB
140 child1.transform = {0.5, 0, 0, 0, 0.5, 0, 0, 0, 1};
141 bridge->AddFlutterSemanticsNodeUpdate(child1);
142
143 bridge->CommitUpdates();
144 auto child1_node = bridge->GetFlutterPlatformNodeDelegateFromID(1).lock();
145 ui::AXOffscreenResult result;
146 gfx::Rect bounds =
147 child1_node->GetBoundsRect(ui::AXCoordinateSystem::kScreenDIPs,
148 ui::AXClippingBehavior::kClipped, &result);
149 EXPECT_EQ(bounds.x(), 0);
150 EXPECT_EQ(bounds.y(), 0);
151 EXPECT_EQ(bounds.width(), 25);
152 EXPECT_EQ(bounds.height(), 25);
153 EXPECT_EQ(result, ui::AXOffscreenResult::kOnscreen);
154 }

## ◆ TEST() [62/118]

flutter::testing::TEST | ( | FlutterPlatformNodeDelegateTest | ,
|  | canCalculateOffScreenBoundsCorrectly |
| ) |  |

Definition at line 156 of file flutter_platform_node_delegate_unittests.cc.

156 {
157 std::shared_ptr<TestAccessibilityBridge> bridge =
158 std::make_shared<TestAccessibilityBridge>();
159 FlutterSemanticsNode2 root;
160 root.id = 0;
161 root.label = "root";
162 root.hint = "";
163 root.value = "";
164 root.increased_value = "";
165 root.decreased_value = "";
166 root.tooltip = "";
167 root.child_count = 1;
168 int32_t children[] = {1};
169 root.children_in_traversal_order = children;
170 root.custom_accessibility_actions_count = 0;
171 root.rect = {0, 0, 100, 100}; // LTRB
172 root.transform = {1, 0, 0, 0, 1, 0, 0, 0, 1};
173 bridge->AddFlutterSemanticsNodeUpdate(root);
174
175 FlutterSemanticsNode2 child1;
176 child1.id = 1;
177 child1.label = "child 1";
178 child1.hint = "";
179 child1.value = "";
180 child1.increased_value = "";
181 child1.decreased_value = "";
182 child1.tooltip = "";
183 child1.child_count = 0;
184 child1.custom_accessibility_actions_count = 0;
185 child1.rect = {90, 90, 100, 100}; // LTRB
186 child1.transform = {2, 0, 0, 0, 2, 0, 0, 0, 1};
187 bridge->AddFlutterSemanticsNodeUpdate(child1);
188
189 bridge->CommitUpdates();
190 auto child1_node = bridge->GetFlutterPlatformNodeDelegateFromID(1).lock();
191 ui::AXOffscreenResult result;
192 gfx::Rect bounds =
193 child1_node->GetBoundsRect(ui::AXCoordinateSystem::kScreenDIPs,
194 ui::AXClippingBehavior::kUnclipped, &result);
195 EXPECT_EQ(bounds.x(), 180);
196 EXPECT_EQ(bounds.y(), 180);
197 EXPECT_EQ(bounds.width(), 20);
198 EXPECT_EQ(bounds.height(), 20);
199 EXPECT_EQ(result, ui::AXOffscreenResult::kOffscreen);
200 }

## ◆ TEST() [63/118]

flutter::testing::TEST | ( | FlutterPlatformNodeDelegateTest | ,
|  | canGetAXNode |
| ) |  |

Definition at line 84 of file flutter_platform_node_delegate_unittests.cc.

84 {
85 // Set up a flutter accessibility node.
86 std::shared_ptr<TestAccessibilityBridge> bridge =
87 std::make_shared<TestAccessibilityBridge>();
88 FlutterSemanticsNode2 root;
89 root.id = 0;
90 root.flags = FlutterSemanticsFlag::kFlutterSemanticsFlagIsTextField;
91 root.actions = static_cast<FlutterSemanticsAction>(0);
92 root.text_selection_base = -1;
93 root.text_selection_extent = -1;
94 root.label = "root";
95 root.hint = "";
96 root.value = "";
97 root.increased_value = "";
98 root.decreased_value = "";
99 root.tooltip = "";
100 root.child_count = 0;
101 root.custom_accessibility_actions_count = 0;
102 bridge->AddFlutterSemanticsNodeUpdate(root);
103
104 bridge->CommitUpdates();
105
106 auto accessibility = bridge->GetFlutterPlatformNodeDelegateFromID(0).lock();
107 EXPECT_EQ(accessibility->GetData().id, 0);
108 }

## ◆ TEST() [64/118]

flutter::testing::TEST | ( | FlutterPlatformNodeDelegateTest | ,
|  | canGetFromNodeID |
| ) |  |

Definition at line 271 of file flutter_platform_node_delegate_unittests.cc.

271 {
272 std::shared_ptr<TestAccessibilityBridge> bridge =
273 std::make_shared<TestAccessibilityBridge>();
274 FlutterSemanticsNode2 root;
275 root.id = 0;
276 root.label = "root";
277 root.hint = "";
278 root.value = "";
279 root.increased_value = "";
280 root.decreased_value = "";
281 root.tooltip = "";
282 root.child_count = 1;
283 int32_t children[] = {1};
284 root.children_in_traversal_order = children;
285 root.custom_accessibility_actions_count = 0;
286 bridge->AddFlutterSemanticsNodeUpdate(root);
287
288 FlutterSemanticsNode2 child1;
289 child1.id = 1;
290 child1.label = "child 1";
291 child1.hint = "";
292 child1.value = "";
293 child1.increased_value = "";
294 child1.decreased_value = "";
295 child1.tooltip = "";
296 child1.child_count = 0;
297 child1.custom_accessibility_actions_count = 0;
298 bridge->AddFlutterSemanticsNodeUpdate(child1);
299
300 bridge->CommitUpdates();
301 auto root_node = bridge->GetFlutterPlatformNodeDelegateFromID(0).lock();
302 auto child1_node = bridge->GetFlutterPlatformNodeDelegateFromID(1).lock();
303 auto node_by_id = root_node->GetFromNodeID(1);
304 EXPECT_EQ(child1_node->GetPlatformNode(), node_by_id);
305 }

## ◆ TEST() [65/118]

flutter::testing::TEST | ( | FlutterPlatformNodeDelegateTest | ,
|  | canPerfomActions |
| ) |  |

Definition at line 40 of file flutter_platform_node_delegate_unittests.cc.

40 {
41 std::shared_ptr<TestAccessibilityBridge> bridge =
42 std::make_shared<TestAccessibilityBridge>();
43 FlutterSemanticsNode2 root;
44 root.id = 0;
45 root.flags = FlutterSemanticsFlag::kFlutterSemanticsFlagIsTextField;
46 root.actions = static_cast<FlutterSemanticsAction>(0);
47 root.text_selection_base = -1;
48 root.text_selection_extent = -1;
49 root.label = "root";
50 root.hint = "";
51 root.value = "";
52 root.increased_value = "";
53 root.decreased_value = "";
54 root.tooltip = "";
55 root.child_count = 0;
56 root.custom_accessibility_actions_count = 0;
57 bridge->AddFlutterSemanticsNodeUpdate(root);
58
59 bridge->CommitUpdates();
60
61 auto accessibility = bridge->GetFlutterPlatformNodeDelegateFromID(0).lock();
62 // Performs an AXAction.
63 ui::AXActionData action_data;
64 action_data.action = ax::mojom::Action::kDoDefault;
65 accessibility->AccessibilityPerformAction(action_data);
66 EXPECT_EQ(bridge->performed_actions.size(), size_t{1});
67 EXPECT_EQ(bridge->performed_actions[0],
68 FlutterSemanticsAction::kFlutterSemanticsActionTap);
69
70 action_data.action = ax::mojom::Action::kFocus;
71 accessibility->AccessibilityPerformAction(action_data);
72 EXPECT_EQ(bridge->performed_actions.size(), size_t{2});
73 EXPECT_EQ(
74 bridge->performed_actions[1],
75 FlutterSemanticsAction::kFlutterSemanticsActionDidGainAccessibilityFocus);
76
77 action_data.action = ax::mojom::Action::kScrollToMakeVisible;
78 accessibility->AccessibilityPerformAction(action_data);
79 EXPECT_EQ(bridge->performed_actions.size(), size_t{3});
80 EXPECT_EQ(bridge->performed_actions[2],
81 FlutterSemanticsAction::kFlutterSemanticsActionShowOnScreen);
82 }

## ◆ TEST() [66/118]

flutter::testing::TEST | ( | FlutterPlatformNodeDelegateTest | ,
|  | canUseOwnerBridge |
| ) |  |

Definition at line 202 of file flutter_platform_node_delegate_unittests.cc.

202 {
203 std::shared_ptr<TestAccessibilityBridge> bridge =
204 std::make_shared<TestAccessibilityBridge>();
205 FlutterSemanticsNode2 root;
206 root.id = 0;
207 root.label = "root";
208 root.hint = "";
209 root.value = "";
210 root.increased_value = "";
211 root.decreased_value = "";
212 root.tooltip = "";
213 root.child_count = 1;
214 int32_t children[] = {1};
215 root.children_in_traversal_order = children;
216 root.custom_accessibility_actions_count = 0;
217 root.rect = {0, 0, 100, 100}; // LTRB
218 root.transform = {1, 0, 0, 0, 1, 0, 0, 0, 1};
219 bridge->AddFlutterSemanticsNodeUpdate(root);
220
221 FlutterSemanticsNode2 child1;
222 child1.id = 1;
223 child1.label = "child 1";
224 child1.hint = "";
225 child1.value = "";
226 child1.increased_value = "";
227 child1.decreased_value = "";
228 child1.tooltip = "";
229 child1.child_count = 0;
230 child1.custom_accessibility_actions_count = 0;
231 child1.rect = {0, 0, 50, 50}; // LTRB
232 child1.transform = {0.5, 0, 0, 0, 0.5, 0, 0, 0, 1};
233 bridge->AddFlutterSemanticsNodeUpdate(child1);
234
235 bridge->CommitUpdates();
236 auto child1_node = bridge->GetFlutterPlatformNodeDelegateFromID(1).lock();
237 auto owner_bridge = child1_node->GetOwnerBridge().lock();
238
239 bool result;
240 gfx::RectF bounds = owner_bridge->RelativeToGlobalBounds(
241 child1_node->GetAXNode(), result, true);
242 EXPECT_EQ(bounds.x(), 0);
243 EXPECT_EQ(bounds.y(), 0);
244 EXPECT_EQ(bounds.width(), 25);
245 EXPECT_EQ(bounds.height(), 25);
246 EXPECT_EQ(result, false);
247 }

## ◆ TEST() [67/118]

flutter::testing::TEST | ( | FlutterPlatformNodeDelegateTest | ,
|  | NodeDelegateHasUniqueId |
| ) |  |

Definition at line 15 of file flutter_platform_node_delegate_unittests.cc.

15 {
16 std::shared_ptr<TestAccessibilityBridge> bridge =
17 std::make_shared<TestAccessibilityBridge>();
18
19 // Add node 0: root.
20 FlutterSemanticsNode2 node0{sizeof(FlutterSemanticsNode2), 0};
21 std::vector<int32_t> node0_children{1};
22 node0.child_count = node0_children.size();
23 node0.children_in_traversal_order = node0_children.data();
24 node0.children_in_hit_test_order = node0_children.data();
25
26 // Add node 1: text child of node 0.
27 FlutterSemanticsNode2 node1{sizeof(FlutterSemanticsNode2), 1};
28 node1.label = "prefecture";
29 node1.value = "Kyoto";
30
31 bridge->AddFlutterSemanticsNodeUpdate(node0);
32 bridge->AddFlutterSemanticsNodeUpdate(node1);
33 bridge->CommitUpdates();
34
35 auto node0_delegate = bridge->GetFlutterPlatformNodeDelegateFromID(0).lock();
36 auto node1_delegate = bridge->GetFlutterPlatformNodeDelegateFromID(1).lock();
37 EXPECT_TRUE(node0_delegate->GetUniqueId() != node1_delegate->GetUniqueId());
38 }

## ◆ TEST() [68/118]

flutter::testing::TEST | ( | FlutterPlatformNodeDelegateTest | ,
|  | selfIsLowestPlatformAncestor |
| ) |  |

Definition at line 249 of file flutter_platform_node_delegate_unittests.cc.

249 {
250 std::shared_ptr<TestAccessibilityBridge> bridge =
251 std::make_shared<TestAccessibilityBridge>();
252 FlutterSemanticsNode2 root;
253 root.id = 0;
254 root.label = "root";
255 root.hint = "";
256 root.value = "";
257 root.increased_value = "";
258 root.decreased_value = "";
259 root.tooltip = "";
260 root.child_count = 0;
261 root.children_in_traversal_order = nullptr;
262 root.custom_accessibility_actions_count = 0;
263 bridge->AddFlutterSemanticsNodeUpdate(root);
264
265 bridge->CommitUpdates();
266 auto root_node = bridge->GetFlutterPlatformNodeDelegateFromID(0).lock();
267 auto lowest_platform_ancestor = root_node->GetLowestPlatformAncestor();
268 EXPECT_EQ(root_node->GetNativeViewAccessible(), lowest_platform_ancestor);
269 }

## ◆ TEST() [69/118]

flutter::testing::TEST | ( | FlutterPlatformViewController | ,
|  | TestAcceptGesture |
| ) |  |

Definition at line 218 of file FlutterPlatformViewControllerTest.mm.

218 {
219 FlutterPlatformViewController* platformViewController =
220 [[FlutterPlatformViewController alloc] init];
221 [platformViewController registerViewFactory:[TestFlutterPlatformViewFactory alloc]
222 withId:@"MockPlatformView"];
223
224 // Create the PlatformView.
225 const NSNumber* viewId = [NSNumber numberWithLongLong:2];
226 FlutterMethodCall* methodCallOnCreate = [FlutterMethodCall
227 methodCallWithMethodName:@"create"
228 arguments:@{@"id" : viewId, @"viewType" : @"MockPlatformView"}];
229 __block bool created = false;
230 FlutterResult resultOnCreate = ^(id result) {
231 // If a platform view is successfully created, the result is nil.
232 if (result == nil) {
233 created = true;
234 }
235 };
236 [platformViewController handleMethodCall:methodCallOnCreate result:resultOnCreate];
237
238 // Call acceptGesture.
239 FlutterMethodCall* methodCallAcceptGesture =
240 [FlutterMethodCall methodCallWithMethodName:@"acceptGesture" arguments:@{@"id" : viewId}];
241 __block bool acceptGestureCalled = false;
242 FlutterResult resultAcceptGesture = ^(id result) {
243 // If a acceptGesture is successful, the result is nil.
244 if (result == nil) {
245 acceptGestureCalled = true;
246 }
247 };
248 [platformViewController handleMethodCall:methodCallAcceptGesture result:resultAcceptGesture];
249
250 EXPECT_TRUE(created);
251 EXPECT_TRUE(acceptGestureCalled);
252 }
FlutterResult
void(^ FlutterResult)(id _Nullable result)
Definition: FlutterChannels.h:194
FlutterMethodCall
Definition: FlutterCodecs.h:221
FlutterPlatformViewController
Definition: FlutterPlatformViewController.h:18
TestFlutterPlatformViewFactory
Definition: TestFlutterPlatformView.h:19

## ◆ TEST() [70/118]

flutter::testing::TEST | ( | FlutterPlatformViewController | ,
|  | TestAcceptGestureOnMissingViewId |
| ) |  |

Definition at line 254 of file FlutterPlatformViewControllerTest.mm.

254 {
255 FlutterPlatformViewController* platformViewController =
256 [[FlutterPlatformViewController alloc] init];
257 [platformViewController registerViewFactory:[TestFlutterPlatformViewFactory alloc]
258 withId:@"MockPlatformView"];
259
260 // Call rejectGesture.
261 FlutterMethodCall* methodCallAcceptGesture =
262 [FlutterMethodCall methodCallWithMethodName:@"acceptGesture" arguments:@{
263 @"id" : @20
264 }];
265 __block bool errored = false;
266 FlutterResult result = ^(id result) {
267 if ([result isKindOfClass:[FlutterError class]]) {
268 errored = true;
269 }
270 };
271 [platformViewController handleMethodCall:methodCallAcceptGesture result:result];
272
273 EXPECT_TRUE(errored);
274 }
FlutterError
Definition: FlutterCodecs.h:247

## ◆ TEST() [71/118]

flutter::testing::TEST | ( | FlutterPlatformViewController | ,
|  | TestCreateAndDispose |
| ) |  |

Definition at line 101 of file FlutterPlatformViewControllerTest.mm.

101 {
102 // Use id so we can access handleMethodCall method.
103 id platformViewController = [[FlutterPlatformViewController alloc] init];
104
105 TestFlutterPlatformViewFactory* factory = [TestFlutterPlatformViewFactory alloc];
106
107 [platformViewController registerViewFactory:factory withId:@"MockPlatformView"];
108
109 FlutterMethodCall* methodCallOnCreate =
110 [FlutterMethodCall methodCallWithMethodName:@"create"
111 arguments:@{
112 @"id" : @2,
113 @"viewType" : @"MockPlatformView"
114 }];
115
116 __block bool created = false;
117 FlutterResult resultOnCreate = ^(id result) {
118 // If a platform view is successfully created, the result is nil.
119 if (result == nil) {
120 created = true;
121 }
122 };
123
124 [platformViewController handleMethodCall:methodCallOnCreate result:resultOnCreate];
125
126 FlutterMethodCall* methodCallOnDispose =
127 [FlutterMethodCall methodCallWithMethodName:@"dispose"
128 arguments:[NSNumber numberWithLongLong:2]];
129
130 __block bool disposed = false;
131 FlutterResult resultOnDispose = ^(id result) {
132 // If a platform view is successfully created, the result is nil.
133 if (result == nil) {
134 disposed = true;
135 }
136 };
137
138 [platformViewController handleMethodCall:methodCallOnDispose result:resultOnDispose];
139
140 EXPECT_TRUE(created);
141 EXPECT_TRUE(disposed);
142 }

## ◆ TEST() [72/118]

flutter::testing::TEST | ( | FlutterPlatformViewController | ,
|  | TestCreatePlatformViewNoMatchingViewType |
| ) |  |

Definition at line 14 of file FlutterPlatformViewControllerTest.mm.

14 {
15 // Use id so we can access handleMethodCall method.
16 id platformViewController = [[FlutterPlatformViewController alloc] init];
17
18 FlutterMethodCall* methodCall =
19 [FlutterMethodCall methodCallWithMethodName:@"create"
20 arguments:@{
21 @"id" : @2,
22 @"viewType" : @"FlutterPlatformViewMock"
23 }];
24
25 __block bool errored = false;
26 FlutterResult result = ^(id result) {
27 if ([result isKindOfClass:[FlutterError class]]) {
28 errored = true;
29 }
30 };
31
32 [platformViewController handleMethodCall:methodCall result:result];
33
34 // We expect the call to error since no factories are registered.
35 EXPECT_TRUE(errored);
36 }

## ◆ TEST() [73/118]

flutter::testing::TEST | ( | FlutterPlatformViewController | ,
|  | TestDisposeOnMissingViewId |
| ) |  |

Definition at line 198 of file FlutterPlatformViewControllerTest.mm.

198 {
199 // Use id so we can access handleMethodCall method.
200 id platformViewController = [[FlutterPlatformViewController alloc] init];
201
202 FlutterMethodCall* methodCall =
203 [FlutterMethodCall methodCallWithMethodName:@"dispose"
204 arguments:[NSNumber numberWithLongLong:20]];
205
206 __block bool errored = false;
207 FlutterResult result = ^(id result) {
208 if ([result isKindOfClass:[FlutterError class]]) {
209 errored = true;
210 }
211 };
212
213 [platformViewController handleMethodCall:methodCall result:result];
214
215 EXPECT_TRUE(errored);
216 }

## ◆ TEST() [74/118]

flutter::testing::TEST | ( | FlutterPlatformViewController | ,
|  | TestRegisterPlatformViewFactoryAndCreate |
| ) |  |

Definition at line 38 of file FlutterPlatformViewControllerTest.mm.

38 {
39 // Use id so we can access handleMethodCall method.
40 id platformViewController = [[FlutterPlatformViewController alloc] init];
41
42 TestFlutterPlatformViewFactory* factory = [TestFlutterPlatformViewFactory alloc];
43
44 [platformViewController registerViewFactory:factory withId:@"MockPlatformView"];
45
46 NSDictionary* creationArgs = @{
47 @"album" : @"ã‚¹ã‚³ãƒƒãƒˆã�¨ãƒªãƒ�ãƒ¼ã‚¹",
48 @"releaseYear" : @2013,
49 @"artists" : @[ @"Scott Murphy", @"Rivers Cuomo" ],
50 @"playlist" : @[ @"ã�Šã�‹ã�—ã�„ã‚„ã�¤", @"ã�»ã�©ã�‘ã�¦ã�„ã�Ÿã‚“ã� " ],
51 };
52 NSObject<FlutterMessageCodec>* codec = [factory createArgsCodec];
53 FlutterStandardTypedData* creationArgsData =
54 [FlutterStandardTypedData typedDataWithBytes:[codec encode:creationArgs]];
55
56 FlutterMethodCall* methodCall =
57 [FlutterMethodCall methodCallWithMethodName:@"create"
58 arguments:@{
59 @"id" : @2,
60 @"viewType" : @"MockPlatformView",
61 @"params" : creationArgsData,
62 }];
63
64 __block bool success = false;
65 FlutterResult result = ^(id result) {
66 // If a platform view is successfully created, the result is nil.
67 if (result == nil) {
68 success = true;
69 }
70 };
71 [platformViewController handleMethodCall:methodCall result:result];
72 EXPECT_TRUE(success);
73
74 // Verify PlatformView parameters are decoded correctly.
75 TestFlutterPlatformView* view =
76 (TestFlutterPlatformView*)[platformViewController platformViewWithID:2];
77 ASSERT_TRUE(view != nil);
78 ASSERT_TRUE(view.args != nil);
79
80 // Verify string type.
81 NSString* album = [view.args objectForKey:@"album"];
82 EXPECT_TRUE([album isEqualToString:@"ã‚¹ã‚³ãƒƒãƒˆã�¨ãƒªãƒ�ãƒ¼ã‚¹"]);
83
84 // Verify int type.
85 NSNumber* releaseYear = [view.args objectForKey:@"releaseYear"];
86 EXPECT_EQ(releaseYear.intValue, 2013);
87
88 // Verify list/array types.
89 NSArray* artists = [view.args objectForKey:@"artists"];
90 ASSERT_TRUE(artists != nil);
91 ASSERT_EQ(artists.count, 2ul);
92 EXPECT_TRUE([artists[0] isEqualToString:@"Scott Murphy"]);
93 EXPECT_TRUE([artists[1] isEqualToString:@"Rivers Cuomo"]);
94
95 NSArray* playlist = [view.args objectForKey:@"playlist"];
96 ASSERT_EQ(playlist.count, 2ul);
97 EXPECT_TRUE([playlist[0] isEqualToString:@"ã�Šã�‹ã�—ã�„ã‚„ã�¤"]);
98 EXPECT_TRUE([playlist[1] isEqualToString:@"ã�»ã�©ã�‘ã�¦ã�„ã�Ÿã‚“ã� "]);
99 }
FlutterStandardTypedData
Definition: FlutterCodecs.h:301
TestFlutterPlatformView
Definition: TestFlutterPlatformView.h:13
TestFlutterPlatformView::args
id args
Arguments passed via the params value in the create method call.
Definition: TestFlutterPlatformView.h:15

References TestFlutterPlatformView::args.

## ◆ TEST() [75/118]

flutter::testing::TEST | ( | FlutterPlatformViewController | ,
|  | TestRejectGesture |
| ) |  |

Definition at line 276 of file FlutterPlatformViewControllerTest.mm.

276 {
277 FlutterPlatformViewController* platformViewController =
278 [[FlutterPlatformViewController alloc] init];
279 [platformViewController registerViewFactory:[TestFlutterPlatformViewFactory alloc]
280 withId:@"MockPlatformView"];
281
282 // Create the PlatformView.
283 const NSNumber* viewId = [NSNumber numberWithLongLong:2];
284 FlutterMethodCall* methodCallOnCreate = [FlutterMethodCall
285 methodCallWithMethodName:@"create"
286 arguments:@{@"id" : viewId, @"viewType" : @"MockPlatformView"}];
287 __block bool created = false;
288 FlutterResult resultOnCreate = ^(id result) {
289 // If a platform view is successfully created, the result is nil.
290 if (result == nil) {
291 created = true;
292 }
293 };
294 [platformViewController handleMethodCall:methodCallOnCreate result:resultOnCreate];
295
296 // Call rejectGesture.
297 FlutterMethodCall* methodCallRejectGesture =
298 [FlutterMethodCall methodCallWithMethodName:@"rejectGesture" arguments:@{@"id" : viewId}];
299 __block bool rejectGestureCalled = false;
300 FlutterResult resultRejectGesture = ^(id result) {
301 // If a rejectGesture is successful, the result is nil.
302 if (result == nil) {
303 rejectGestureCalled = true;
304 }
305 };
306 [platformViewController handleMethodCall:methodCallRejectGesture result:resultRejectGesture];
307
308 EXPECT_TRUE(created);
309 EXPECT_TRUE(rejectGestureCalled);
310 }

## ◆ TEST() [76/118]

flutter::testing::TEST | ( | FlutterPlatformViewController | ,
|  | TestRejectGestureOnMissingViewId |
| ) |  |

Definition at line 312 of file FlutterPlatformViewControllerTest.mm.

312 {
313 FlutterPlatformViewController* platformViewController =
314 [[FlutterPlatformViewController alloc] init];
315 [platformViewController registerViewFactory:[TestFlutterPlatformViewFactory alloc]
316 withId:@"MockPlatformView"];
317
318 // Call rejectGesture.
319 FlutterMethodCall* methodCallRejectGesture =
320 [FlutterMethodCall methodCallWithMethodName:@"rejectGesture" arguments:@{
321 @"id" : @20
322 }];
323 __block bool errored = false;
324 FlutterResult result = ^(id result) {
325 if ([result isKindOfClass:[FlutterError class]]) {
326 errored = true;
327 }
328 };
329 [platformViewController handleMethodCall:methodCallRejectGesture result:result];
330
331 EXPECT_TRUE(errored);
332 }

## ◆ TEST() [77/118]

flutter::testing::TEST | ( | FlutterPlatformViewController | ,
|  | TestReset |
| ) |  |

Definition at line 144 of file FlutterPlatformViewControllerTest.mm.

144 {
145 // Use id so we can access handleMethodCall method.
146 id platformViewController = [[FlutterPlatformViewController alloc] init];
147 TestFlutterPlatformViewFactory* factory = [TestFlutterPlatformViewFactory alloc];
148
149 [platformViewController registerViewFactory:factory withId:@"MockPlatformView"];
150
151 __block bool created = false;
152 FlutterResult resultOnCreate = ^(id result) {
153 // If a platform view is successfully created, the result is nil.
154 if (result == nil) {
155 created = true;
156 } else {
157 created = false;
158 }
159 };
160
161 // Create 2 views.
162 FlutterMethodCall* methodCallOnCreate0 =
163 [FlutterMethodCall methodCallWithMethodName:@"create"
164 arguments:@{
165 @"id" : @0,
166 @"viewType" : @"MockPlatformView"
167 }];
168
169 [platformViewController handleMethodCall:methodCallOnCreate0 result:resultOnCreate];
170 EXPECT_TRUE(created);
171
172 FlutterMethodCall* methodCallOnCreate1 =
173 [FlutterMethodCall methodCallWithMethodName:@"create"
174 arguments:@{
175 @"id" : @1,
176 @"viewType" : @"MockPlatformView"
177 }];
178 [platformViewController handleMethodCall:methodCallOnCreate1 result:resultOnCreate];
179 EXPECT_TRUE(created);
180
181 TestFlutterPlatformView* view = nil;
182
183 // Before the reset, the views exist.
184 view = (TestFlutterPlatformView*)[platformViewController platformViewWithID:0];
185 EXPECT_TRUE(view != nil);
186 view = (TestFlutterPlatformView*)[platformViewController platformViewWithID:1];
187 EXPECT_TRUE(view != nil);
188
189 // After a reset, the views should no longer exist.
190 [platformViewController reset];
191
192 view = (TestFlutterPlatformView*)[platformViewController platformViewWithID:0];
193 EXPECT_TRUE(view == nil);
194 view = (TestFlutterPlatformView*)[platformViewController platformViewWithID:1];
195 EXPECT_TRUE(view == nil);
196 }

## ◆ TEST() [78/118]

flutter::testing::TEST | ( | FlutterSurfaceManager | ,
|  | BackBufferCacheDoesNotLeak |
| ) |  |

Definition at line 98 of file FlutterSurfaceManagerTest.mm.

98 {
99 TestView* testView = [[TestView alloc] init];
100 FlutterSurfaceManager* surfaceManager = CreateSurfaceManager(testView);
101 EXPECT_EQ(surfaceManager.backBufferCache.count, 0ul);
102
103 auto surface1 = [surfaceManager surfaceForSize:CGSizeMake(100, 100)];
104 [surfaceManager presentSurfaces:@[ CreatePresentInfo(surface1) ] atTime:0 notify:nil];
105
106 EXPECT_EQ(surfaceManager.backBufferCache.count, 0ul);
107
108 auto surface2 = [surfaceManager surfaceForSize:CGSizeMake(110, 110)];
109 [surfaceManager presentSurfaces:@[ CreatePresentInfo(surface2) ] atTime:0 notify:nil];
110
111 EXPECT_EQ(surfaceManager.backBufferCache.count, 1ul);
112
113 auto surface3 = [surfaceManager surfaceForSize:CGSizeMake(120, 120)];
114 [surfaceManager presentSurfaces:@[ CreatePresentInfo(surface3) ] atTime:0 notify:nil];
115
116 // Cache should be cleaned during present and only contain the last visible
117 // surface(s).
118 EXPECT_EQ(surfaceManager.backBufferCache.count, 1ul);
119 auto surfaceFromCache = [surfaceManager surfaceForSize:CGSizeMake(110, 110)];
120 EXPECT_EQ(surfaceFromCache, surface2);
121
122 // Submit empty surfaces until the one in cache gets to age >= kSurfaceEvictionAge, in which case
123 // it should be removed.
124
125 for (int i = 0; i < 30 /* kSurfaceEvictionAge */; ++i) {
126 [surfaceManager presentSurfaces:@[] atTime:0 notify:nil];
127 EXPECT_EQ(surfaceManager.backBufferCache.count, 1ul);
128 }
129
130 [surfaceManager presentSurfaces:@[] atTime:0 notify:nil];
131 EXPECT_EQ(surfaceManager.backBufferCache.count, 0ul);
132 }
-[FlutterBackBufferCache count]
NSUInteger count()
Definition: FlutterSurfaceManager.mm:346
-[FlutterSurfaceManager surfaceForSize:]
nonnull FlutterSurface * surfaceForSize:(CGSize size)
Definition: FlutterSurfaceManager.mm:133
FlutterSurfaceManager::backBufferCache
FlutterBackBufferCache * backBufferCache
Definition: FlutterSurfaceManager.h:107
-[FlutterSurfaceManager presentSurfaces:atTime:notify:]
void presentSurfaces:atTime:notify:(nonnull NSArray< FlutterSurfacePresentInfo * > *surfaces,[atTime] CFTimeInterval presentationTime,[notify] nullable dispatch_block_t notify)
TestView
Definition: FlutterSurfaceManagerTest.mm:14
flutter::testing::CreateSurfaceManager
static FlutterSurfaceManager * CreateSurfaceManager(TestView *testView)
Definition: FlutterSurfaceManagerTest.mm:43

References FlutterSurfaceManager::backBufferCache, FlutterBackBufferCache::count, CreateSurfaceManager(), FlutterSurfaceManager::presentSurfaces:atTime:notify:, and FlutterSurfaceManager::surfaceForSize:.

## ◆ TEST() [79/118]

flutter::testing::TEST | ( | FlutterSurfaceManager | ,
|  | BackingStoreCacheSurfaceStuckInUse |
| ) |  |

Definition at line 173 of file FlutterSurfaceManagerTest.mm.

173 {
174 TestView* testView = [[TestView alloc] init];
175 FlutterSurfaceManager* surfaceManager = CreateSurfaceManager(testView);
176
177 auto surface1 = [surfaceManager surfaceForSize:CGSizeMake(100, 100)];
178
179 [surfaceManager presentSurfaces:@[ CreatePresentInfo(surface1) ] atTime:0 notify:nil];
180 // Pretend that compositor is holding on to the surface. The surface will be kept
181 // in cache until the age of kSurfaceEvictionAge is reached, and then evicted.
182 surface1.isInUseOverride = YES;
183
184 auto surface2 = [surfaceManager surfaceForSize:CGSizeMake(100, 100)];
185 [surfaceManager presentSurfaces:@[ CreatePresentInfo(surface2) ] atTime:0 notify:nil];
186 EXPECT_EQ(surfaceManager.backBufferCache.count, 1ul);
187
188 for (int i = 0; i < 30 /* kSurfaceEvictionAge */ - 1; ++i) {
189 auto surface3 = [surfaceManager surfaceForSize:CGSizeMake(100, 100)];
190 [surfaceManager presentSurfaces:@[ CreatePresentInfo(surface3) ] atTime:0 notify:nil];
191 EXPECT_EQ(surfaceManager.backBufferCache.count, 2ul);
192 }
193
194 auto surface4 = [surfaceManager surfaceForSize:CGSizeMake(100, 100)];
195 [surfaceManager presentSurfaces:@[ CreatePresentInfo(surface4) ] atTime:0 notify:nil];
196 // Surface in use should bet old enough at this point to be evicted.
197 EXPECT_EQ(surfaceManager.backBufferCache.count, 1ul);
198 }

References FlutterSurfaceManager::backBufferCache, FlutterBackBufferCache::count, CreateSurfaceManager(), FlutterSurfaceManager::presentSurfaces:atTime:notify:, and FlutterSurfaceManager::surfaceForSize:.

## ◆ TEST() [80/118]

flutter::testing::TEST | ( | FlutterSurfaceManager | ,
|  | LayerManagement |
| ) |  |

Definition at line 204 of file FlutterSurfaceManagerTest.mm.

204 {
205 TestView* testView = [[TestView alloc] init];
206 FlutterSurfaceManager* surfaceManager = CreateSurfaceManager(testView);
207
208 EXPECT_EQ(testView.layer.sublayers.count, 0ul);
209
210 auto surface1_1 = [surfaceManager surfaceForSize:CGSizeMake(50, 30)];
211 [surfaceManager presentSurfaces:@[ CreatePresentInfo(surface1_1, CGPointMake(20, 10)) ]
212 atTime:0
213 notify:nil];
214
215 EXPECT_EQ(testView.layer.sublayers.count, 1ul);
216 EXPECT_TRUE(CGSizeEqualToSize(testView.presentedFrameSize, CGSizeMake(70, 40)));
217
218 auto surface2_1 = [surfaceManager surfaceForSize:CGSizeMake(50, 30)];
219 auto surface2_2 = [surfaceManager surfaceForSize:CGSizeMake(20, 20)];
220 [surfaceManager presentSurfaces:@[
221 CreatePresentInfo(surface2_1, CGPointMake(20, 10), 1),
222 CreatePresentInfo(surface2_2, CGPointMake(40, 50), 2,
223 {
224 FlutterRect{0, 0, 20, 20},
225 FlutterRect{40, 0, 60, 20},
226 })
227 ]
228 atTime:0
229 notify:nil];
230
231 EXPECT_EQ(testView.layer.sublayers.count, 2ul);
232 EXPECT_EQ(testView.layer.sublayers[0].zPosition, 1.0);
233 EXPECT_EQ(testView.layer.sublayers[1].zPosition, 2.0);
234 CALayer* firstOverlaySublayer;
235 {
236 NSArray<CALayer*>* sublayers = testView.layer.sublayers[1].sublayers;
237 EXPECT_EQ(sublayers.count, 2ul);
238 EXPECT_TRUE(CGRectEqualToRect(sublayers[0].frame, CGRectMake(0, 0, 10, 10)));
239 EXPECT_TRUE(CGRectEqualToRect(sublayers[1].frame, CGRectMake(20, 0, 10, 10)));
240 EXPECT_TRUE(CGRectEqualToRect(sublayers[0].contentsRect, CGRectMake(0, 0, 1, 1)));
241 EXPECT_TRUE(CGRectEqualToRect(sublayers[1].contentsRect, CGRectMake(2, 0, 1, 1)));
242 EXPECT_EQ(sublayers[0].contents, sublayers[1].contents);
243 firstOverlaySublayer = sublayers[0];
244 }
245 EXPECT_TRUE(CGSizeEqualToSize(testView.presentedFrameSize, CGSizeMake(70, 70)));
246
247 // Check second overlay sublayer is removed while first is reused and updated
248 [surfaceManager presentSurfaces:@[
249 CreatePresentInfo(surface2_1, CGPointMake(20, 10), 1),
250 CreatePresentInfo(surface2_2, CGPointMake(40, 50), 2,
251 {
252 FlutterRect{0, 10, 20, 20},
253 })
254 ]
255 atTime:0
256 notify:nil];
257 EXPECT_EQ(testView.layer.sublayers.count, 2ul);
258 {
259 NSArray<CALayer*>* sublayers = testView.layer.sublayers[1].sublayers;
260 EXPECT_EQ(sublayers.count, 1ul);
261 EXPECT_EQ(sublayers[0], firstOverlaySublayer);
262 EXPECT_TRUE(CGRectEqualToRect(sublayers[0].frame, CGRectMake(0, 5, 10, 5)));
263 }
264
265 // Check that second overlay sublayer is added back while first is reused and updated
266 [surfaceManager presentSurfaces:@[
267 CreatePresentInfo(surface2_1, CGPointMake(20, 10), 1),
268 CreatePresentInfo(surface2_2, CGPointMake(40, 50), 2,
269 {
270 FlutterRect{0, 0, 20, 20},
271 FlutterRect{40, 0, 60, 20},
272 })
273 ]
274 atTime:0
275 notify:nil];
276
277 EXPECT_EQ(testView.layer.sublayers.count, 2ul);
278 {
279 NSArray<CALayer*>* sublayers = testView.layer.sublayers[1].sublayers;
280 EXPECT_EQ(sublayers.count, 2ul);
281 EXPECT_EQ(sublayers[0], firstOverlaySublayer);
282 EXPECT_TRUE(CGRectEqualToRect(sublayers[0].frame, CGRectMake(0, 0, 10, 10)));
283 EXPECT_TRUE(CGRectEqualToRect(sublayers[1].frame, CGRectMake(20, 0, 10, 10)));
284 EXPECT_EQ(sublayers[0].contents, sublayers[1].contents);
285 }
286
287 auto surface3_1 = [surfaceManager surfaceForSize:CGSizeMake(50, 30)];
288 [surfaceManager presentSurfaces:@[ CreatePresentInfo(surface3_1, CGPointMake(20, 10)) ]
289 atTime:0
290 notify:nil];
291
292 EXPECT_EQ(testView.layer.sublayers.count, 1ul);
293 EXPECT_TRUE(CGSizeEqualToSize(testView.presentedFrameSize, CGSizeMake(70, 40)));
294
295 // Check removal of all surfaces.
296 [surfaceManager presentSurfaces:@[] atTime:0 notify:nil];
297 EXPECT_EQ(testView.layer.sublayers.count, 0ul);
298 EXPECT_TRUE(CGSizeEqualToSize(testView.presentedFrameSize, CGSizeMake(0, 0)));
299 }
TestView::presentedFrameSize
CGSize presentedFrameSize
Definition: FlutterSurfaceManagerTest.mm:16

References CreateSurfaceManager(), TestView::presentedFrameSize, FlutterSurfaceManager::presentSurfaces:atTime:notify:, and FlutterSurfaceManager::surfaceForSize:.

## ◆ TEST() [81/118]

flutter::testing::TEST | ( | FlutterSurfaceManager | ,
|  | MetalTextureSizeMatchesSurfaceSize |
| ) |  |

Definition at line 66 of file FlutterSurfaceManagerTest.mm.

66 {
67 TestView* testView = [[TestView alloc] init];
68 FlutterSurfaceManager* surfaceManager = CreateSurfaceManager(testView);
69
70 // Get back buffer, lookup should work for borrowed surfaces util present.
71 auto surface = [surfaceManager surfaceForSize:CGSizeMake(100, 50)];
72 auto texture = surface.asFlutterMetalTexture;
73 id<MTLTexture> metalTexture = (__bridge id)texture.texture;
74 EXPECT_EQ(metalTexture.width, 100ul);
75 EXPECT_EQ(metalTexture.height, 50ul);
76 texture.destruction_callback(texture.user_data);
77 }

References FlutterSurface::asFlutterMetalTexture, CreateSurfaceManager(), and FlutterSurfaceManager::surfaceForSize:.

## ◆ TEST() [82/118]

flutter::testing::TEST | ( | FlutterSurfaceManager | ,
|  | SurfacesAreRecycled |
| ) |  |

Definition at line 134 of file FlutterSurfaceManagerTest.mm.

134 {
135 TestView* testView = [[TestView alloc] init];
136 FlutterSurfaceManager* surfaceManager = CreateSurfaceManager(testView);
137
138 EXPECT_EQ(surfaceManager.frontSurfaces.count, 0ul);
139
140 // Get first surface and present it.
141
142 auto surface1 = [surfaceManager surfaceForSize:CGSizeMake(100, 100)];
143 EXPECT_TRUE(CGSizeEqualToSize(surface1.size, CGSizeMake(100, 100)));
144
145 EXPECT_EQ(surfaceManager.backBufferCache.count, 0ul);
146 EXPECT_EQ(surfaceManager.frontSurfaces.count, 0ul);
147
148 [surfaceManager presentSurfaces:@[ CreatePresentInfo(surface1) ] atTime:0 notify:nil];
149
150 EXPECT_EQ(surfaceManager.backBufferCache.count, 0ul);
151 EXPECT_EQ(surfaceManager.frontSurfaces.count, 1ul);
152 EXPECT_EQ(testView.layer.sublayers.count, 1ul);
153
154 // Get second surface and present it.
155
156 auto surface2 = [surfaceManager surfaceForSize:CGSizeMake(100, 100)];
157 EXPECT_TRUE(CGSizeEqualToSize(surface2.size, CGSizeMake(100, 100)));
158
159 EXPECT_EQ(surfaceManager.backBufferCache.count, 0ul);
160
161 [surfaceManager presentSurfaces:@[ CreatePresentInfo(surface2) ] atTime:0 notify:nil];
162
163 // Check that current front surface returns to cache.
164 EXPECT_EQ(surfaceManager.backBufferCache.count, 1ul);
165 EXPECT_EQ(surfaceManager.frontSurfaces.count, 1ul);
166 EXPECT_EQ(testView.layer.sublayers.count, 1ull);
167
168 // Check that surface is properly reused.
169 auto surface3 = [surfaceManager surfaceForSize:CGSizeMake(100, 100)];
170 EXPECT_EQ(surface3, surface1);
171 }
FlutterSurfaceManager::frontSurfaces
NSArray< FlutterSurface * > * frontSurfaces
Definition: FlutterSurfaceManager.h:108

References FlutterSurfaceManager::backBufferCache, FlutterBackBufferCache::count, CreateSurfaceManager(), FlutterSurfaceManager::frontSurfaces, FlutterSurfaceManager::presentSurfaces:atTime:notify:, and FlutterSurfaceManager::surfaceForSize:.

## ◆ TEST() [83/118]

flutter::testing::TEST | ( | FlutterSurfaceManager | ,
|  | TestSurfaceLookupFromTexture |
| ) |  |

Definition at line 79 of file FlutterSurfaceManagerTest.mm.

79 {
80 TestView* testView = [[TestView alloc] init];
81 FlutterSurfaceManager* surfaceManager = CreateSurfaceManager(testView);
82
83 // Get back buffer, lookup should work for borrowed surfaces util present.
84 auto surface = [surfaceManager surfaceForSize:CGSizeMake(100, 50)];
85
86 // SurfaceManager should keep texture alive while borrowed.
87 auto texture = surface.asFlutterMetalTexture;
88 texture.destruction_callback(texture.user_data);
89
90 FlutterMetalTexture dummyTexture{.texture_id = 1, .texture = nullptr, .user_data = nullptr};
91 auto surface1 = [FlutterSurface fromFlutterMetalTexture:&dummyTexture];
92 EXPECT_EQ(surface1, nil);
93
94 auto surface2 = [FlutterSurface fromFlutterMetalTexture:&texture];
95 EXPECT_EQ(surface2, surface);
96 }
FlutterSurface
Definition: FlutterSurface.h:17
+[FlutterSurface fromFlutterMetalTexture:]
nullable FlutterSurface * fromFlutterMetalTexture:(nonnull const FlutterMetalTexture *texture)

References FlutterSurface::asFlutterMetalTexture, CreateSurfaceManager(), FlutterSurface::fromFlutterMetalTexture:, and FlutterSurfaceManager::surfaceForSize:.

## ◆ TEST() [84/118]

flutter::testing::TEST | ( | FlutterTextInputPluginTest | ,
|  | CanNotBecomeResponderIfNoViewController |
| ) |  |

Definition at line 2256 of file FlutterTextInputPluginTest.mm.

2256 {
2257 FlutterEngine* engine = CreateTestEngine();
2258 FlutterViewController* viewController = [[FlutterViewController alloc] initWithEngine:engine
2259 nibName:nil
2260 bundle:nil];
2261 [viewController loadView];
2262 // Creates a NSWindow so that the native text field can become first responder.
2263 NSWindow* window = [[NSWindow alloc] initWithContentRect:NSMakeRect(0, 0, 800, 600)
2264 styleMask:NSBorderlessWindowMask
2265 backing:NSBackingStoreBuffered
2266 defer:NO];
2267 window.contentView = viewController.view;
2268
2269 engine.semanticsEnabled = YES;
2270
2271 auto bridge = viewController.accessibilityBridge.lock();
2272 FlutterPlatformNodeDelegateMac delegate(bridge, viewController);
2273 ui::AXTree tree;
2274 ui::AXNode ax_node(&tree, nullptr, 0, 0);
2275 ui::AXNodeData node_data;
2276 node_data.SetValue("initial text");
2277 ax_node.SetData(node_data);
2278 delegate.Init(viewController.accessibilityBridge, &ax_node);
2279 FlutterTextPlatformNode text_platform_node(&delegate, viewController);
2280
2281 FlutterTextField* textField = text_platform_node.GetNativeViewAccessible();
2282 EXPECT_EQ([textField becomeFirstResponder], YES);
2283 // Removes view controller.
2284 [engine setViewController:nil];
2285 FlutterTextPlatformNode text_platform_node_no_controller(&delegate, nil);
2286 textField = text_platform_node_no_controller.GetNativeViewAccessible();
2287 EXPECT_EQ([textField becomeFirstResponder], NO);
2288 }

References flutter::FlutterTextPlatformNode::GetNativeViewAccessible(), and flutter::FlutterPlatformNodeDelegateMac::Init().

## ◆ TEST() [85/118]

flutter::testing::TEST | ( | FlutterTextInputPluginTest | ,
|  | CanWorkWithFlutterTextField |
| ) |  |

Definition at line 2190 of file FlutterTextInputPluginTest.mm.

2190 {
2191 FlutterEngine* engine = CreateTestEngine();
2192 FlutterViewController* viewController = [[FlutterViewController alloc] initWithEngine:engine
2193 nibName:nil
2194 bundle:nil];
2195 [viewController loadView];
2196 // Create a NSWindow so that the native text field can become first responder.
2197 NSWindow* window = [[NSWindow alloc] initWithContentRect:NSMakeRect(0, 0, 800, 600)
2198 styleMask:NSBorderlessWindowMask
2199 backing:NSBackingStoreBuffered
2200 defer:NO];
2201 window.contentView = viewController.view;
2202
2203 engine.semanticsEnabled = YES;
2204
2205 auto bridge = viewController.accessibilityBridge.lock();
2206 FlutterPlatformNodeDelegateMac delegate(bridge, viewController);
2207 ui::AXTree tree;
2208 ui::AXNode ax_node(&tree, nullptr, 0, 0);
2209 ui::AXNodeData node_data;
2210 node_data.SetValue("initial text");
2211 ax_node.SetData(node_data);
2212 delegate.Init(viewController.accessibilityBridge, &ax_node);
2213 {
2214 FlutterTextPlatformNode text_platform_node(&delegate, viewController);
2215
2216 FlutterTextFieldMock* mockTextField =
2217 [[FlutterTextFieldMock alloc] initWithPlatformNode:&text_platform_node
2218 fieldEditor:engine.textInputPlugin];
2219 [viewController.view addSubview:mockTextField];
2220 [mockTextField startEditing];
2221
2222 NSDictionary* setClientConfig = @{
2223 @"viewId" : @(flutter::kFlutterImplicitViewId),
2224 @"inputAction" : @"action",
2225 @"inputType" : @{@"name" : @"inputName"},
2226 };
2227 FlutterMethodCall* methodCall =
2228 [FlutterMethodCall methodCallWithMethodName:@"TextInput.setClient"
2229 arguments:@[ @(1), setClientConfig ]];
2230 FlutterResult result = ^(id result) {
2231 };
2232 [engine.textInputPlugin handleMethodCall:methodCall result:result];
2233
2234 NSDictionary* arguments = @{
2235 @"text" : @"new text",
2236 @"selectionBase" : @(1),
2237 @"selectionExtent" : @(2),
2238 @"composingBase" : @(-1),
2239 @"composingExtent" : @(-1),
2240 };
2241 methodCall = [FlutterMethodCall methodCallWithMethodName:@"TextInput.setEditingState"
2242 arguments:arguments];
2243 [engine.textInputPlugin handleMethodCall:methodCall result:result];
2244 EXPECT_EQ([mockTextField.lastUpdatedString isEqualToString:@"new text"], YES);
2245 EXPECT_EQ(NSEqualRanges(mockTextField.lastUpdatedSelection, NSMakeRange(1, 1)), YES);
2246
2247 // This blocks the FlutterTextFieldMock, which is held onto by the main event
2248 // loop, from crashing.
2249 [mockTextField setPlatformNode:nil];
2250 }
2251
2252 // This verifies that clearing the platform node works.
2253 [[NSRunLoop currentRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:0.1]];
2254 }
+[FlutterMethodCall methodCallWithMethodName:arguments:]
instancetype methodCallWithMethodName:arguments:(NSString *method,[arguments] id _Nullable arguments)
-[FlutterTextField startEditing]
void startEditing()
Definition: FlutterTextInputSemanticsObject.mm:112
FlutterTextFieldMock
Definition: FlutterTextInputPluginTest.mm:25
FlutterTextFieldMock::lastUpdatedSelection
NSRange lastUpdatedSelection
Definition: FlutterTextInputPluginTest.mm:27
FlutterTextFieldMock::lastUpdatedString
NSString * lastUpdatedString
Definition: FlutterTextInputPluginTest.mm:26

References flutter::FlutterPlatformNodeDelegateMac::Init(), FlutterTextFieldMock::lastUpdatedSelection, FlutterTextFieldMock::lastUpdatedString, FlutterMethodCall::methodCallWithMethodName:arguments:, and FlutterTextField::startEditing.

## ◆ TEST() [86/118]

flutter::testing::TEST | ( | FlutterTextInputPluginTest | ,
|  | FirstResponderIsCorrect |
| ) |  |

Definition at line 2332 of file FlutterTextInputPluginTest.mm.

2332 {
2333 FlutterEngine* engine = CreateTestEngine();
2334 FlutterViewController* viewController = [[FlutterViewController alloc] initWithEngine:engine
2335 nibName:nil
2336 bundle:nil];
2337 [viewController loadView];
2338
2339 NSWindow* window = [[NSWindow alloc] initWithContentRect:NSMakeRect(0, 0, 800, 600)
2340 styleMask:NSBorderlessWindowMask
2341 backing:NSBackingStoreBuffered
2342 defer:NO];
2343 window.contentView = viewController.view;
2344
2345 ASSERT_TRUE(viewController.flutterView.acceptsFirstResponder);
2346
2347 [window makeFirstResponder:viewController.flutterView];
2348
2349 NSDictionary* setClientConfig = @{
2350 @"viewId" : @(flutter::kFlutterImplicitViewId),
2351 };
2352 [engine.textInputPlugin
2353 handleMethodCall:[FlutterMethodCall methodCallWithMethodName:@"TextInput.setClient"
2354 arguments:@[ @(1), setClientConfig ]]
2355 result:^(id){
2356 }];
2357
2358 [engine.textInputPlugin
2359 handleMethodCall:[FlutterMethodCall methodCallWithMethodName:@"TextInput.show" arguments:@[]]
2360 result:^(id){
2361 }];
2362
2363 ASSERT_TRUE(window.firstResponder == engine.textInputPlugin);
2364
2365 ASSERT_FALSE(viewController.flutterView.acceptsFirstResponder);
2366
2367 [engine.textInputPlugin
2368 handleMethodCall:[FlutterMethodCall methodCallWithMethodName:@"TextInput.hide" arguments:@[]]
2369 result:^(id){
2370 }];
2371
2372 ASSERT_TRUE(viewController.flutterView.acceptsFirstResponder);
2373 ASSERT_TRUE(window.firstResponder == viewController.flutterView);
2374 }

References FlutterMethodCall::methodCallWithMethodName:arguments:.

## ◆ TEST() [87/118]

flutter::testing::TEST | ( | FlutterTextInputPluginTest | ,
|  | HandleArrowKeyWhenImePopoverIsActive |
| ) |  |

Definition at line 2114 of file FlutterTextInputPluginTest.mm.

2114 {
2115 ASSERT_TRUE([[FlutterInputPluginTestObjc alloc] handleArrowKeyWhenImePopoverIsActive]);
2116 }
FlutterInputPluginTestObjc
Definition: FlutterTextInputPluginTest.mm:56

## ◆ TEST() [88/118]

flutter::testing::TEST | ( | FlutterTextInputPluginTest | ,
|  | HasZeroSizeAndClipsToBounds |
| ) |  |

Definition at line 2376 of file FlutterTextInputPluginTest.mm.

2376 {
2377 id engineMock = flutter::testing::CreateMockFlutterEngine(@"");
2378 id binaryMessengerMock = OCMProtocolMock(@protocol(FlutterBinaryMessenger));
2379 OCMStub( // NOLINT(google-objc-avoid-throwing-exception)
2380 [engineMock binaryMessenger])
2381 .andReturn(binaryMessengerMock);
2382
2383 FlutterViewController* viewController = [[FlutterViewController alloc] initWithEngine:engineMock
2384 nibName:@""
2385 bundle:nil];
2386
2387 FlutterTextInputPluginTestDelegate* delegate =
2388 [[FlutterTextInputPluginTestDelegate alloc] initWithBinaryMessenger:binaryMessengerMock
2389 viewController:viewController];
2390
2391 FlutterTextInputPlugin* plugin = [[FlutterTextInputPlugin alloc] initWithDelegate:delegate];
2392
2393 ASSERT_TRUE(NSIsEmptyRect(plugin.frame));
2394 ASSERT_TRUE(plugin.clipsToBounds);
2395 }
FlutterTextInputPlugin
Definition: FlutterTextInputPlugin.h:42
FlutterTextInputPluginTestDelegate
Definition: FlutterTextInputPluginTest.mm:60
flutter::testing::CreateMockFlutterEngine
id CreateMockFlutterEngine(NSString *pasteboardString)
Definition: FlutterEngineTestUtils.mm:76
FlutterBinaryMessenger-p
Definition: FlutterBinaryMessenger.h:49

References CreateMockFlutterEngine().

## ◆ TEST() [89/118]

flutter::testing::TEST | ( | FlutterTextInputPluginTest | ,
|  | IsAddedAndRemovedFromViewHierarchy |
| ) |  |

Definition at line 2290 of file FlutterTextInputPluginTest.mm.

2290 {
2291 FlutterEngine* engine = CreateTestEngine();
2292 FlutterViewController* viewController = [[FlutterViewController alloc] initWithEngine:engine
2293 nibName:nil
2294 bundle:nil];
2295 [viewController loadView];
2296
2297 NSWindow* window = [[NSWindow alloc] initWithContentRect:NSMakeRect(0, 0, 800, 600)
2298 styleMask:NSBorderlessWindowMask
2299 backing:NSBackingStoreBuffered
2300 defer:NO];
2301 window.contentView = viewController.view;
2302
2303 ASSERT_EQ(engine.textInputPlugin.superview, nil);
2304 ASSERT_FALSE(window.firstResponder == engine.textInputPlugin);
2305
2306 NSDictionary* setClientConfig = @{
2307 @"viewId" : @(flutter::kFlutterImplicitViewId),
2308 };
2309 [engine.textInputPlugin
2310 handleMethodCall:[FlutterMethodCall methodCallWithMethodName:@"TextInput.setClient"
2311 arguments:@[ @(1), setClientConfig ]]
2312 result:^(id){
2313 }];
2314
2315 [engine.textInputPlugin
2316 handleMethodCall:[FlutterMethodCall methodCallWithMethodName:@"TextInput.show" arguments:@[]]
2317 result:^(id){
2318 }];
2319
2320 ASSERT_EQ(engine.textInputPlugin.superview, viewController.view);
2321 ASSERT_TRUE(window.firstResponder == engine.textInputPlugin);
2322
2323 [engine.textInputPlugin
2324 handleMethodCall:[FlutterMethodCall methodCallWithMethodName:@"TextInput.hide" arguments:@[]]
2325 result:^(id){
2326 }];
2327
2328 ASSERT_EQ(engine.textInputPlugin.superview, nil);
2329 ASSERT_FALSE(window.firstResponder == engine.textInputPlugin);
2330 }

References FlutterMethodCall::methodCallWithMethodName:arguments:.

## ◆ TEST() [90/118]

flutter::testing::TEST | ( | FlutterTextInputPluginTest | ,
|  | TestAttributedSubstringOutOfRange |
| ) |  |

Definition at line 2138 of file FlutterTextInputPluginTest.mm.

2138 {
2139 id engineMock = flutter::testing::CreateMockFlutterEngine(@"");
2140 id binaryMessengerMock = OCMProtocolMock(@protocol(FlutterBinaryMessenger));
2141 OCMStub( // NOLINT(google-objc-avoid-throwing-exception)
2142 [engineMock binaryMessenger])
2143 .andReturn(binaryMessengerMock);
2144
2145 FlutterViewController* viewController = [[FlutterViewController alloc] initWithEngine:engineMock
2146 nibName:@""
2147 bundle:nil];
2148
2149 FlutterTextInputPluginTestDelegate* delegate =
2150 [[FlutterTextInputPluginTestDelegate alloc] initWithBinaryMessenger:binaryMessengerMock
2151 viewController:viewController];
2152
2153 FlutterTextInputPlugin* plugin = [[FlutterTextInputPlugin alloc] initWithDelegate:delegate];
2154
2155 NSDictionary* setClientConfig = @{
2156 @"viewId" : @(kViewId),
2157 @"inputAction" : @"action",
2158 @"enableDeltaModel" : @"true",
2159 @"inputType" : @{@"name" : @"inputName"},
2160 };
2161 [plugin handleMethodCall:[FlutterMethodCall methodCallWithMethodName:@"TextInput.setClient"
2162 arguments:@[ @(1), setClientConfig ]]
2163 result:^(id){
2164 }];
2165
2166 FlutterMethodCall* call = [FlutterMethodCall methodCallWithMethodName:@"TextInput.setEditingState"
2167 arguments:@{
2168 @"text" : @"Text",
2169 @"selectionBase" : @(0),
2170 @"selectionExtent" : @(0),
2171 @"composingBase" : @(-1),
2172 @"composingExtent" : @(-1),
2173 }];
2174
2175 [plugin handleMethodCall:call
2176 result:^(id){
2177 }];
2178
2179 NSRange out;
2180 NSAttributedString* text = [plugin attributedSubstringForProposedRange:NSMakeRange(1, 10)
2181 actualRange:&out];
2182 EXPECT_TRUE([text.string isEqualToString:@"ext"]);
2183 EXPECT_EQ(out.location, 1u);
2184 EXPECT_EQ(out.length, 3u);
2185
2186 text = [plugin attributedSubstringForProposedRange:NSMakeRange(4, 10) actualRange:&out];
2187 EXPECT_EQ(text, nil);
2188 }
kViewId
static const FlutterViewIdentifier kViewId
Definition: FlutterTextInputPluginTest.mm:69
-[FlutterTextInputPlugin handleMethodCall:result:]
void handleMethodCall:result:(FlutterMethodCall *call,[result] FlutterResult result)

References CreateMockFlutterEngine(), FlutterTextInputPlugin::handleMethodCall:result:, kViewId, and FlutterMethodCall::methodCallWithMethodName:arguments:.

## ◆ TEST() [91/118]

flutter::testing::TEST | ( | FlutterTextInputPluginTest | ,
|  | TestAutocompleteDisabledWhenAutofillGroupIncludesPassword |
| ) |  |

Definition at line 2072 of file FlutterTextInputPluginTest.mm.

2072 {
2073 ASSERT_TRUE([[FlutterInputPluginTestObjc alloc]
2074 testAutocompleteDisabledWhenAutofillGroupIncludesPassword]);
2075 }

## ◆ TEST() [92/118]

flutter::testing::TEST | ( | FlutterTextInputPluginTest | ,
|  | TestAutocompleteDisabledWhenAutofillNotSet |
| ) |  |

Definition at line 2052 of file FlutterTextInputPluginTest.mm.

2052 {
2053 ASSERT_TRUE([[FlutterInputPluginTestObjc alloc] testAutocompleteDisabledWhenAutofillNotSet]);
2054 }

## ◆ TEST() [93/118]

flutter::testing::TEST | ( | FlutterTextInputPluginTest | ,
|  | TestAutocompleteDisabledWhenObscureTextSet |
| ) |  |

Definition at line 2064 of file FlutterTextInputPluginTest.mm.

2064 {
2065 ASSERT_TRUE([[FlutterInputPluginTestObjc alloc] testAutocompleteDisabledWhenObscureTextSet]);
2066 }

## ◆ TEST() [94/118]

flutter::testing::TEST | ( | FlutterTextInputPluginTest | ,
|  | TestAutocompleteDisabledWhenPasswordAutofillSet |
| ) |  |

Definition at line 2068 of file FlutterTextInputPluginTest.mm.

2068 {
2069 ASSERT_TRUE([[FlutterInputPluginTestObjc alloc] testAutocompleteDisabledWhenPasswordAutofillSet]);
2070 }

## ◆ TEST() [95/118]

flutter::testing::TEST | ( | FlutterTextInputPluginTest | ,
|  | TestAutocompleteEnabledWhenAutofillSet |
| ) |  |

Definition at line 2056 of file FlutterTextInputPluginTest.mm.

2056 {
2057 ASSERT_TRUE([[FlutterInputPluginTestObjc alloc] testAutocompleteEnabledWhenAutofillSet]);
2058 }

## ◆ TEST() [96/118]

flutter::testing::TEST | ( | FlutterTextInputPluginTest | ,
|  | TestAutocompleteEnabledWhenAutofillSetNoHint |
| ) |  |

Definition at line 2060 of file FlutterTextInputPluginTest.mm.

2060 {
2061 ASSERT_TRUE([[FlutterInputPluginTestObjc alloc] testAutocompleteEnabledWhenAutofillSetNoHint]);
2062 }

## ◆ TEST() [97/118]

flutter::testing::TEST | ( | FlutterTextInputPluginTest | ,
|  | TestClearClientDuringComposing |
| ) |  |

Definition at line 2048 of file FlutterTextInputPluginTest.mm.

2048 {
2049 ASSERT_TRUE([[FlutterInputPluginTestObjc alloc] testClearClientDuringComposing]);
2050 }

## ◆ TEST() [98/118]

flutter::testing::TEST | ( | FlutterTextInputPluginTest | ,
|  | TestComposingRegionRemovedByFramework |
| ) |  |

Definition at line 2044 of file FlutterTextInputPluginTest.mm.

2044 {
2045 ASSERT_TRUE([[FlutterInputPluginTestObjc alloc] testComposingRegionRemovedByFramework]);
2046 }

## ◆ TEST() [99/118]

flutter::testing::TEST | ( | FlutterTextInputPluginTest | ,
|  | TestComposingWithDelta |
| ) |  |

Definition at line 2098 of file FlutterTextInputPluginTest.mm.

2098 {
2099 ASSERT_TRUE([[FlutterInputPluginTestObjc alloc] testComposingWithDelta]);
2100 }

## ◆ TEST() [100/118]

flutter::testing::TEST | ( | FlutterTextInputPluginTest | ,
|  | TestComposingWithDeltasWhenSelectionIsActive |
| ) |  |

Definition at line 2102 of file FlutterTextInputPluginTest.mm.

2102 {
2103 ASSERT_TRUE([[FlutterInputPluginTestObjc alloc] testComposingWithDeltasWhenSelectionIsActive]);
2104 }

## ◆ TEST() [101/118]

flutter::testing::TEST | ( | FlutterTextInputPluginTest | ,
|  | TestEmptyCompositionRange |
| ) |  |

Definition at line 2032 of file FlutterTextInputPluginTest.mm.

2032 {
2033 ASSERT_TRUE([[FlutterInputPluginTestObjc alloc] testEmptyCompositionRange]);
2034 }

## ◆ TEST() [102/118]

flutter::testing::TEST | ( | FlutterTextInputPluginTest | ,
|  | TestFirstRectForCharacterRange |
| ) |  |

Definition at line 2077 of file FlutterTextInputPluginTest.mm.

2077 {
2078 ASSERT_TRUE([[FlutterInputPluginTestObjc alloc] testFirstRectForCharacterRange]);
2079 }

## ◆ TEST() [103/118]

flutter::testing::TEST | ( | FlutterTextInputPluginTest | ,
|  | TestFirstRectForCharacterRangeAtInfinity |
| ) |  |

Definition at line 2081 of file FlutterTextInputPluginTest.mm.

2081 {
2082 ASSERT_TRUE([[FlutterInputPluginTestObjc alloc] testFirstRectForCharacterRangeAtInfinity]);
2083 }

## ◆ TEST() [104/118]

flutter::testing::TEST | ( | FlutterTextInputPluginTest | ,
|  | TestFirstRectForCharacterRangeWithEsotericAffineTransform |
| ) |  |

Definition at line 2085 of file FlutterTextInputPluginTest.mm.

2085 {
2086 ASSERT_TRUE([[FlutterInputPluginTestObjc alloc]
2087 testFirstRectForCharacterRangeWithEsotericAffineTransform]);
2088 }

## ◆ TEST() [105/118]

flutter::testing::TEST | ( | FlutterTextInputPluginTest | ,
|  | TestInsertNewLine |
| ) |  |

Definition at line 2130 of file FlutterTextInputPluginTest.mm.

2130 {
2131 ASSERT_TRUE([[FlutterInputPluginTestObjc alloc] testInsertNewLine]);
2132 }

## ◆ TEST() [106/118]

flutter::testing::TEST | ( | FlutterTextInputPluginTest | ,
|  | TestLocalTextAndSelectionUpdateAfterDelta |
| ) |  |

Definition at line 2106 of file FlutterTextInputPluginTest.mm.

2106 {
2107 ASSERT_TRUE([[FlutterInputPluginTestObjc alloc] testLocalTextAndSelectionUpdateAfterDelta]);
2108 }

## ◆ TEST() [107/118]

flutter::testing::TEST | ( | FlutterTextInputPluginTest | ,
|  | TestOperationsThatTriggerDelta |
| ) |  |

Definition at line 2094 of file FlutterTextInputPluginTest.mm.

2094 {
2095 ASSERT_TRUE([[FlutterInputPluginTestObjc alloc] testOperationsThatTriggerDelta]);
2096 }

## ◆ TEST() [108/118]

flutter::testing::TEST | ( | FlutterTextInputPluginTest | ,
|  | TestPerformKeyEquivalent |
| ) |  |

Definition at line 2110 of file FlutterTextInputPluginTest.mm.

2110 {
2111 ASSERT_TRUE([[FlutterInputPluginTestObjc alloc] testPerformKeyEquivalent]);
2112 }

## ◆ TEST() [109/118]

flutter::testing::TEST | ( | FlutterTextInputPluginTest | ,
|  | TestSelectorsAreForwardedToFramework |
| ) |  |

Definition at line 2122 of file FlutterTextInputPluginTest.mm.

2122 {
2123 ASSERT_TRUE([[FlutterInputPluginTestObjc alloc] testSelectorsAreForwardedToFramework]);
2124 }

## ◆ TEST() [110/118]

flutter::testing::TEST | ( | FlutterTextInputPluginTest | ,
|  | TestSelectorsNotForwardedToFrameworkIfNoClient |
| ) |  |

Definition at line 2126 of file FlutterTextInputPluginTest.mm.

2126 {
2127 ASSERT_TRUE([[FlutterInputPluginTestObjc alloc] testSelectorsNotForwardedToFrameworkIfNoClient]);
2128 }

## ◆ TEST() [111/118]

flutter::testing::TEST | ( | FlutterTextInputPluginTest | ,
|  | TestSendActionDoNotInsertNewLine |
| ) |  |

Definition at line 2134 of file FlutterTextInputPluginTest.mm.

2134 {
2135 ASSERT_TRUE([[FlutterInputPluginTestObjc alloc] testSendActionDoNotInsertNewLine]);
2136 }

## ◆ TEST() [112/118]

flutter::testing::TEST | ( | FlutterTextInputPluginTest | ,
|  | TestSetEditingStateWithTextEditingDelta |
| ) |  |

Definition at line 2090 of file FlutterTextInputPluginTest.mm.

2090 {
2091 ASSERT_TRUE([[FlutterInputPluginTestObjc alloc] testSetEditingStateWithTextEditingDelta]);
2092 }

## ◆ TEST() [113/118]

flutter::testing::TEST | ( | FlutterTextInputPluginTest | ,
|  | TestSetMarkedTextWithReplacementRange |
| ) |  |

Definition at line 2040 of file FlutterTextInputPluginTest.mm.

2040 {
2041 ASSERT_TRUE([[FlutterInputPluginTestObjc alloc] testSetMarkedTextWithReplacementRange]);
2042 }

## ◆ TEST() [114/118]

flutter::testing::TEST | ( | FlutterTextInputPluginTest | ,
|  | TestSetMarkedTextWithSelectionChange |
| ) |  |

Definition at line 2036 of file FlutterTextInputPluginTest.mm.

2036 {
2037 ASSERT_TRUE([[FlutterInputPluginTestObjc alloc] testSetMarkedTextWithSelectionChange]);
2038 }

## ◆ TEST() [115/118]

flutter::testing::TEST | ( | FlutterTextInputPluginTest | ,
|  | UnhandledKeyEquivalent |
| ) |  |

Definition at line 2118 of file FlutterTextInputPluginTest.mm.

2118 {
2119 ASSERT_TRUE([[FlutterInputPluginTestObjc alloc] unhandledKeyEquivalent]);
2120 }

## ◆ TEST() [116/118]

flutter::testing::TEST | ( | FlutterTextInputSemanticsObjectTest | ,
|  | DoesInitialize |
| ) |  |

Definition at line 27 of file FlutterTextInputSemanticsObjectTest.mm.

27 {
28 FlutterEngine* engine = CreateTestEngine();
29 {
30 FlutterViewController* viewController = [[FlutterViewController alloc] initWithEngine:engine
31 nibName:nil
32 bundle:nil];
33 [viewController loadView];
34 // Create a NSWindow so that the native text field can become first responder.
35 NSWindow* window = [[NSWindow alloc] initWithContentRect:NSMakeRect(0, 0, 800, 600)
36 styleMask:NSBorderlessWindowMask
37 backing:NSBackingStoreBuffered
38 defer:NO];
39 window.contentView = viewController.view;
40
41 engine.semanticsEnabled = YES;
42
43 auto bridge = viewController.accessibilityBridge.lock();
44 FlutterPlatformNodeDelegateMac delegate(bridge, viewController);
45 ui::AXTree tree;
46 ui::AXNode ax_node(&tree, nullptr, 0, 0);
47 ui::AXNodeData node_data;
48 node_data.SetValue("initial text");
49 ax_node.SetData(node_data);
50 delegate.Init(viewController.accessibilityBridge, &ax_node);
51 // Verify that a FlutterTextField is attached to the view.
52 FlutterTextPlatformNode text_platform_node(&delegate, viewController);
53 id native_accessibility = text_platform_node.GetNativeViewAccessible();
54 EXPECT_TRUE([native_accessibility isKindOfClass:[FlutterTextField class]]);
55 auto subviews = [viewController.view subviews];
56 EXPECT_EQ([subviews count], 2u);
57 EXPECT_TRUE([subviews[0] isKindOfClass:[FlutterTextField class]]);
58 FlutterTextField* nativeTextField = subviews[0];
59 EXPECT_EQ(text_platform_node.GetNativeViewAccessible(), nativeTextField);
60 }
61
62 [engine shutDownEngine];
63 engine = nil;
64 // Pump the event loop to make sure no stray nodes cause crashes after the
65 // engine has been destroyed.
66 // From issue: https://github.com/flutter/flutter/issues/115599
67 [[NSRunLoop currentRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:0.1]];
68 }

References flutter::FlutterTextPlatformNode::GetNativeViewAccessible(), and flutter::FlutterPlatformNodeDelegateMac::Init().

## ◆ TEST() [117/118]

flutter::testing::TEST | ( | FlutterViewEngineProviderUnittests | ,
|  | GetViewReturnsTheCorrectView |
| ) |  |

Definition at line 19 of file FlutterViewEngineProviderTest.mm.

19 {
20 FlutterViewEngineProvider* viewProvider;
21 id mockEngine = CreateMockFlutterEngine(@"");
22 __block id mockFlutterViewController;
23 OCMStub([mockEngine viewControllerForIdentifier:0])
24 .ignoringNonObjectArgs()
25 .andDo(^(NSInvocation* invocation) {
26 FlutterViewIdentifier viewIdentifier;
27 [invocation getArgument:&viewIdentifier atIndex:2];
28 if (viewIdentifier == kFlutterImplicitViewId) {
29 if (mockFlutterViewController != nil) {
30 [invocation setReturnValue:&mockFlutterViewController];
31 }
32 }
33 });
34 viewProvider = [[FlutterViewEngineProvider alloc] initWithEngine:mockEngine];
35
36 // When the view controller is not set, the returned view is nil.
37 EXPECT_EQ([viewProvider viewForIdentifier:0], nil);
38
39 // When the view controller is set, the returned view is the controller's view.
40 mockFlutterViewController = OCMStrictClassMock([FlutterViewController class]);
41 id mockView = OCMStrictClassMock([FlutterView class]);
42 OCMStub([mockFlutterViewController flutterView]).andReturn(mockView);
43 EXPECT_EQ([viewProvider viewForIdentifier:0], mockView);
44 }
FlutterViewIdentifier
int64_t FlutterViewIdentifier
Definition: FlutterViewController.h:21
FlutterViewEngineProvider
Definition: FlutterViewEngineProvider.h:18
FlutterView
Definition: FlutterView.h:36

References CreateMockFlutterEngine().

## ◆ TEST() [118/118]

flutter::testing::TEST | ( | KeyMappingTest | ,
|  | HasExpectedValues |
| ) |  |

Definition at line 20 of file KeyCodeMapTest.mm.

20 {
21 // Has Space
22 EXPECT_NE(std::find(kLayoutGoals.begin(), kLayoutGoals.end(), LayoutGoal{0x31, 0x20, false}),
23 kLayoutGoals.end());
24 // Has Digit0
25 EXPECT_NE(std::find(kLayoutGoals.begin(), kLayoutGoals.end(), LayoutGoal{0x1d, 0x30, true}),
26 kLayoutGoals.end());
27 // Has KeyA
28 EXPECT_NE(std::find(kLayoutGoals.begin(), kLayoutGoals.end(), LayoutGoal{0x00, 0x61, true}),
29 kLayoutGoals.end());
30 // Has Equal
31 EXPECT_NE(std::find(kLayoutGoals.begin(), kLayoutGoals.end(), LayoutGoal{0x18, 0x3d, false}),
32 kLayoutGoals.end());
33 // Has IntlBackslash
34 EXPECT_NE(
35 std::find(kLayoutGoals.begin(), kLayoutGoals.end(), LayoutGoal{0x0a, 0x200000020, false}),
36 kLayoutGoals.end());
37 }
flutter::kLayoutGoals
const std::vector< LayoutGoal > kLayoutGoals
Definition: KeyCodeMap.g.mm:248

References flutter::kLayoutGoals.

## ◆ TEST_F() [1/77]

flutter::testing::TEST_F | ( | AccessibilityBridgeMacTest | ,
|  | DoesNotSendAccessibilityCreateNotificationWhenHeadless |
| ) |  |

Definition at line 213 of file AccessibilityBridgeMacTest.mm.

213 {
214 FlutterViewController* viewController = CreateTestViewController();
215 FlutterEngine* engine = viewController.engine;
216
217 // Setting up bridge so that the AccessibilityBridgeMacDelegateSpy
218 // can query semantics information from.
219 engine.semanticsEnabled = YES;
220 auto bridge = std::static_pointer_cast<AccessibilityBridgeMacSpy>(
221 viewController.accessibilityBridge.lock());
222 FlutterSemanticsNode2 root;
223 root.id = 0;
224 root.flags = static_cast<FlutterSemanticsFlag>(0);
225 root.actions = static_cast<FlutterSemanticsAction>(0);
226 root.text_selection_base = -1;
227 root.text_selection_extent = -1;
228 root.label = "root";
229 root.hint = "";
230 root.value = "";
231 root.increased_value = "";
232 root.decreased_value = "";
233 root.tooltip = "";
234 root.child_count = 0;
235 root.custom_accessibility_actions_count = 0;
236 bridge->AddFlutterSemanticsNodeUpdate(root);
237
238 bridge->CommitUpdates();
239 auto platform_node_delegate = bridge->GetFlutterPlatformNodeDelegateFromID(0).lock();
240
241 // Creates a targeted event.
242 ui::AXTree tree;
243 ui::AXNode ax_node(&tree, nullptr, 0, 0);
244 ui::AXNodeData node_data;
245 node_data.id = 0;
246 ax_node.SetData(node_data);
247 std::vector<ui::AXEventIntent> intent;
248 ui::AXEventGenerator::EventParams event_params(ui::AXEventGenerator::Event::CHILDREN_CHANGED,
249 ax::mojom::EventFrom::kNone, intent);
250 ui::AXEventGenerator::TargetedEvent targeted_event(&ax_node, event_params);
251
252 bridge->OnAccessibilityEvent(targeted_event);
253
254 // Does not send any notification if the engine is headless.
255 EXPECT_EQ(bridge->actual_notifications.size(), 0u);
256 [engine shutDownEngine];
257 }
-[FlutterEngine shutDownEngine]
void shutDownEngine()
Definition: FlutterEngine.mm:1177

References FlutterViewController::engine, and FlutterEngine::shutDownEngine.

## ◆ TEST_F() [2/77]

flutter::testing::TEST_F | ( | AccessibilityBridgeMacTest | ,
|  | DoesNotSendAccessibilityCreateNotificationWhenNoWindow |
| ) |  |

Definition at line 259 of file AccessibilityBridgeMacTest.mm.

259 {
260 FlutterViewController* viewController = CreateTestViewController();
261 FlutterEngine* engine = viewController.engine;
262
263 // Setting up bridge so that the AccessibilityBridgeMacDelegateSpy
264 // can query semantics information from.
265 engine.semanticsEnabled = YES;
266 auto bridge = std::static_pointer_cast<AccessibilityBridgeMacSpy>(
267 viewController.accessibilityBridge.lock());
268 FlutterSemanticsNode2 root;
269 root.id = 0;
270 root.flags = static_cast<FlutterSemanticsFlag>(0);
271 root.actions = static_cast<FlutterSemanticsAction>(0);
272 root.text_selection_base = -1;
273 root.text_selection_extent = -1;
274 root.label = "root";
275 root.hint = "";
276 root.value = "";
277 root.increased_value = "";
278 root.decreased_value = "";
279 root.tooltip = "";
280 root.child_count = 0;
281 root.custom_accessibility_actions_count = 0;
282 bridge->AddFlutterSemanticsNodeUpdate(root);
283
284 bridge->CommitUpdates();
285 auto platform_node_delegate = bridge->GetFlutterPlatformNodeDelegateFromID(0).lock();
286
287 // Creates a targeted event.
288 ui::AXTree tree;
289 ui::AXNode ax_node(&tree, nullptr, 0, 0);
290 ui::AXNodeData node_data;
291 node_data.id = 0;
292 ax_node.SetData(node_data);
293 std::vector<ui::AXEventIntent> intent;
294 ui::AXEventGenerator::EventParams event_params(ui::AXEventGenerator::Event::CHILDREN_CHANGED,
295 ax::mojom::EventFrom::kNone, intent);
296 ui::AXEventGenerator::TargetedEvent targeted_event(&ax_node, event_params);
297
298 bridge->OnAccessibilityEvent(targeted_event);
299
300 // Does not send any notification if the flutter view is not attached to a NSWindow.
301 EXPECT_EQ(bridge->actual_notifications.size(), 0u);
302 [engine shutDownEngine];
303 }

References FlutterViewController::engine, and FlutterEngine::shutDownEngine.

## ◆ TEST_F() [3/77]

flutter::testing::TEST_F | ( | AccessibilityBridgeMacWindowTest | ,
|  | NonZeroRootNodeId |
| ) |  |

Definition at line 147 of file AccessibilityBridgeMacTest.mm.

147 {
148 FlutterViewController* viewController = CreateTestViewController();
149 FlutterEngine* engine = viewController.engine;
150 NSWindow* expectedTarget = GetWindow();
151 expectedTarget.contentView = viewController.view;
152
153 // Setting up bridge so that the AccessibilityBridgeMacDelegateSpy
154 // can query semantics information from.
155 engine.semanticsEnabled = YES;
156 auto bridge = std::static_pointer_cast<AccessibilityBridgeMacSpy>(
157 viewController.accessibilityBridge.lock());
158
159 FlutterSemanticsNode2 node1;
160 std::vector<int32_t> node1_children{2};
161 node1.id = 1;
162 node1.flags = static_cast<FlutterSemanticsFlag>(0);
163 node1.actions = static_cast<FlutterSemanticsAction>(0);
164 node1.text_selection_base = -1;
165 node1.text_selection_extent = -1;
166 node1.label = "node1";
167 node1.hint = "";
168 node1.value = "";
169 node1.increased_value = "";
170 node1.decreased_value = "";
171 node1.tooltip = "";
172 node1.child_count = node1_children.size();
173 node1.children_in_traversal_order = node1_children.data();
174 node1.children_in_hit_test_order = node1_children.data();
175 node1.custom_accessibility_actions_count = 0;
176
177 FlutterSemanticsNode2 node2;
178 node2.id = 2;
179 node2.flags = static_cast<FlutterSemanticsFlag>(0);
180 node2.actions = static_cast<FlutterSemanticsAction>(0);
181 node2.text_selection_base = -1;
182 node2.text_selection_extent = -1;
183 node2.label = "node2";
184 node2.hint = "";
185 node2.value = "";
186 node2.increased_value = "";
187 node2.decreased_value = "";
188 node2.tooltip = "";
189 node2.child_count = 0;
190 node2.custom_accessibility_actions_count = 0;
191
192 bridge->AddFlutterSemanticsNodeUpdate(node1);
193 bridge->AddFlutterSemanticsNodeUpdate(node2);
194 bridge->CommitUpdates();
195
196 // Look up the root node delegate.
197 auto root_delegate = bridge->GetFlutterPlatformNodeDelegateFromID(1).lock();
198 ASSERT_TRUE(root_delegate);
199 ASSERT_EQ(root_delegate->GetChildCount(), 1);
200
201 // Look up the child node delegate.
202 auto child_delegate = bridge->GetFlutterPlatformNodeDelegateFromID(2).lock();
203 ASSERT_TRUE(child_delegate);
204 ASSERT_EQ(child_delegate->GetChildCount(), 0);
205
206 // Ensure a node with ID 0 does not exist.
207 auto invalid_delegate = bridge->GetFlutterPlatformNodeDelegateFromID(0).lock();
208 ASSERT_FALSE(invalid_delegate);
209
210 [engine shutDownEngine];
211 }

References FlutterViewController::engine, and FlutterEngine::shutDownEngine.

## ◆ TEST_F() [4/77]

flutter::testing::TEST_F | ( | AccessibilityBridgeMacWindowTest | ,
|  | SendsAccessibilityCreateNotificationFlutterViewWindow |
| ) |  |

Definition at line 90 of file AccessibilityBridgeMacTest.mm.

90 {
91 FlutterViewController* viewController = CreateTestViewController();
92 FlutterEngine* engine = viewController.engine;
93 NSWindow* expectedTarget = GetWindow();
94 expectedTarget.contentView = viewController.view;
95
96 // Setting up bridge so that the AccessibilityBridgeMacDelegateSpy
97 // can query semantics information from.
98 engine.semanticsEnabled = YES;
99 auto bridge = std::static_pointer_cast<AccessibilityBridgeMacSpy>(
100 viewController.accessibilityBridge.lock());
101 FlutterSemanticsNode2 root;
102 root.id = 0;
103 root.flags = static_cast<FlutterSemanticsFlag>(0);
104 root.actions = static_cast<FlutterSemanticsAction>(0);
105 root.text_selection_base = -1;
106 root.text_selection_extent = -1;
107 root.label = "root";
108 root.hint = "";
109 root.value = "";
110 root.increased_value = "";
111 root.decreased_value = "";
112 root.tooltip = "";
113 root.child_count = 0;
114 root.custom_accessibility_actions_count = 0;
115 bridge->AddFlutterSemanticsNodeUpdate(root);
116
117 bridge->CommitUpdates();
118 auto platform_node_delegate = bridge->GetFlutterPlatformNodeDelegateFromID(0).lock();
119
120 // Creates a targeted event.
121 ui::AXTree tree;
122 ui::AXNode ax_node(&tree, nullptr, 0, 0);
123 ui::AXNodeData node_data;
124 node_data.id = 0;
125 ax_node.SetData(node_data);
126 std::vector<ui::AXEventIntent> intent;
127 ui::AXEventGenerator::EventParams event_params(ui::AXEventGenerator::Event::CHILDREN_CHANGED,
128 ax::mojom::EventFrom::kNone, intent);
129 ui::AXEventGenerator::TargetedEvent targeted_event(&ax_node, event_params);
130
131 bridge->OnAccessibilityEvent(targeted_event);
132
133 ASSERT_EQ(bridge->actual_notifications.size(), 1u);
134 auto target = bridge->actual_notifications.find([NSAccessibilityCreatedNotification UTF8String]);
135 ASSERT_NE(target, bridge->actual_notifications.end());
136 EXPECT_EQ(target->second, expectedTarget);
137 [engine shutDownEngine];
138 }

References FlutterViewController::engine, and FlutterEngine::shutDownEngine.

## ◆ TEST_F() [5/77]

flutter::testing::TEST_F | ( | FlutterChannelKeyResponderTest | ,
|  | BasicKeyEvent |
| ) |  |

Definition at line 75 of file FlutterChannelKeyResponderTest.mm.

75 {
76 __block NSMutableArray<NSNumber*>* responses = [[NSMutableArray<NSNumber*> alloc] init];
77 FakeMessageChannel* channel = [[FakeMessageChannel alloc] init];
78 FlutterChannelKeyResponder* responder =
79 [[FlutterChannelKeyResponder alloc] initWithChannel:channel];
80
81 // Initial empty modifiers.
82 //
83 // This can happen when user opens window while modifier key is pressed and then releases the
84 // modifier. No events should be sent, but the callback should still be called.
85 // Regression test for https://github.com/flutter/flutter/issues/87339.
86 channel.nextResponse = @{@"handled" : @YES};
87 [responder handleEvent:CreateKeyEvent(NSEventTypeFlagsChanged, 0x100, @"", @"", NO, 60)
88 callback:^(BOOL handled) {
89 [responses addObject:@(handled)];
90 }];
91
92 EXPECT_EQ([channel.messages count], 0u);
93 ASSERT_EQ([responses count], 1u);
94 EXPECT_EQ([responses[0] boolValue], YES);
95 [responses removeAllObjects];
96
97 // Key down
98 channel.nextResponse = @{@"handled" : @YES};
99 [responder handleEvent:CreateKeyEvent(NSEventTypeKeyDown, 0x100, @"a", @"a", NO, 0)
100 callback:^(BOOL handled) {
101 [responses addObject:@(handled)];
102 }];
103
104 ASSERT_EQ([channel.messages count], 1u);
105 EXPECT_STREQ([[channel.messages lastObject][@"keymap"] UTF8String], "macos");
106 EXPECT_STREQ([[channel.messages lastObject][@"type"] UTF8String], "keydown");
107 EXPECT_EQ([[channel.messages lastObject][@"keyCode"] intValue], 0);
108 EXPECT_EQ([[channel.messages lastObject][@"modifiers"] intValue], 0x0);
109 EXPECT_STREQ([[channel.messages lastObject][@"characters"] UTF8String], "a");
110 EXPECT_STREQ([[channel.messages lastObject][@"charactersIgnoringModifiers"] UTF8String], "a");
111
112 ASSERT_EQ([responses count], 1u);
113 EXPECT_EQ([[responses lastObject] boolValue], YES);
114
115 [channel.messages removeAllObjects];
116 [responses removeAllObjects];
117
118 // Key up
119 channel.nextResponse = @{@"handled" : @NO};
120 [responder handleEvent:CreateKeyEvent(NSEventTypeKeyUp, 0x100, @"a", @"a", NO, 0)
121 callback:^(BOOL handled) {
122 [responses addObject:@(handled)];
123 }];
124
125 ASSERT_EQ([channel.messages count], 1u);
126 EXPECT_STREQ([[channel.messages lastObject][@"keymap"] UTF8String], "macos");
127 EXPECT_STREQ([[channel.messages lastObject][@"type"] UTF8String], "keyup");
128 EXPECT_EQ([[channel.messages lastObject][@"keyCode"] intValue], 0);
129 EXPECT_EQ([[channel.messages lastObject][@"modifiers"] intValue], 0);
130 EXPECT_STREQ([[channel.messages lastObject][@"characters"] UTF8String], "a");
131 EXPECT_STREQ([[channel.messages lastObject][@"charactersIgnoringModifiers"] UTF8String], "a");
132
133 ASSERT_EQ([responses count], 1u);
134 EXPECT_EQ([[responses lastObject] boolValue], NO);
135
136 [channel.messages removeAllObjects];
137 [responses removeAllObjects];
138
139 // LShift down
140 channel.nextResponse = @{@"handled" : @YES};
141 [responder handleEvent:CreateKeyEvent(NSEventTypeFlagsChanged, 0x20102, @"", @"", NO, 56)
142 callback:^(BOOL handled) {
143 [responses addObject:@(handled)];
144 }];
145
146 ASSERT_EQ([channel.messages count], 1u);
147 EXPECT_STREQ([[channel.messages lastObject][@"keymap"] UTF8String], "macos");
148 EXPECT_STREQ([[channel.messages lastObject][@"type"] UTF8String], "keydown");
149 EXPECT_EQ([[channel.messages lastObject][@"keyCode"] intValue], 56);
150 EXPECT_EQ([[channel.messages lastObject][@"modifiers"] intValue], 0x20002);
151
152 ASSERT_EQ([responses count], 1u);
153 EXPECT_EQ([[responses lastObject] boolValue], YES);
154
155 [channel.messages removeAllObjects];
156 [responses removeAllObjects];
157
158 // RShift down
159 channel.nextResponse = @{@"handled" : @NO};
160 [responder handleEvent:CreateKeyEvent(NSEventTypeFlagsChanged, 0x20006, @"", @"", NO, 60)
161 callback:^(BOOL handled) {
162 [responses addObject:@(handled)];
163 }];
164
165 ASSERT_EQ([channel.messages count], 1u);
166 EXPECT_STREQ([[channel.messages lastObject][@"keymap"] UTF8String], "macos");
167 EXPECT_STREQ([[channel.messages lastObject][@"type"] UTF8String], "keydown");
168 EXPECT_EQ([[channel.messages lastObject][@"keyCode"] intValue], 60);
169 EXPECT_EQ([[channel.messages lastObject][@"modifiers"] intValue], 0x20006);
170
171 ASSERT_EQ([responses count], 1u);
172 EXPECT_EQ([[responses lastObject] boolValue], NO);
173
174 [channel.messages removeAllObjects];
175 [responses removeAllObjects];
176
177 // LShift up
178 channel.nextResponse = @{@"handled" : @NO};
179 [responder handleEvent:CreateKeyEvent(NSEventTypeFlagsChanged, 0x20104, @"", @"", NO, 56)
180 callback:^(BOOL handled) {
181 [responses addObject:@(handled)];
182 }];
183
184 ASSERT_EQ([channel.messages count], 1u);
185 EXPECT_STREQ([[channel.messages lastObject][@"keymap"] UTF8String], "macos");
186 EXPECT_STREQ([[channel.messages lastObject][@"type"] UTF8String], "keyup");
187 EXPECT_EQ([[channel.messages lastObject][@"keyCode"] intValue], 56);
188 EXPECT_EQ([[channel.messages lastObject][@"modifiers"] intValue], 0x20004);
189
190 ASSERT_EQ([responses count], 1u);
191 EXPECT_EQ([[responses lastObject] boolValue], NO);
192
193 [channel.messages removeAllObjects];
194 [responses removeAllObjects];
195
196 // RShift up
197 channel.nextResponse = @{@"handled" : @NO};
198 [responder handleEvent:CreateKeyEvent(NSEventTypeFlagsChanged, 0, @"", @"", NO, 60)
199 callback:^(BOOL handled) {
200 [responses addObject:@(handled)];
201 }];
202
203 ASSERT_EQ([channel.messages count], 1u);
204 EXPECT_STREQ([[channel.messages lastObject][@"keymap"] UTF8String], "macos");
205 EXPECT_STREQ([[channel.messages lastObject][@"type"] UTF8String], "keyup");
206 EXPECT_EQ([[channel.messages lastObject][@"keyCode"] intValue], 60);
207 EXPECT_EQ([[channel.messages lastObject][@"modifiers"] intValue], 0);
208
209 ASSERT_EQ([responses count], 1u);
210 EXPECT_EQ([[responses lastObject] boolValue], NO);
211
212 [channel.messages removeAllObjects];
213 [responses removeAllObjects];
214
215 // RShift up again, should be ignored and not produce a keydown event, but the
216 // callback should be called.
217 channel.nextResponse = @{@"handled" : @NO};
218 [responder handleEvent:CreateKeyEvent(NSEventTypeFlagsChanged, 0x100, @"", @"", NO, 60)
219 callback:^(BOOL handled) {
220 [responses addObject:@(handled)];
221 }];
222
223 EXPECT_EQ([channel.messages count], 0u);
224 ASSERT_EQ([responses count], 1u);
225 EXPECT_EQ([responses[0] boolValue], YES);
226 }
FakeMessageChannel
Definition: FlutterChannelKeyResponderTest.mm:20
FakeMessageChannel::messages
NSMutableArray< id > * messages
Definition: FlutterChannelKeyResponderTest.mm:20
FakeMessageChannel::nextResponse
NSDictionary * nextResponse
Definition: FlutterChannelKeyResponderTest.mm:21
FlutterChannelKeyResponder
Definition: FlutterChannelKeyResponder.h:20

References <FlutterKeyPrimaryResponder>::handleEvent:callback:, FakeMessageChannel::messages, and FakeMessageChannel::nextResponse.

## ◆ TEST_F() [6/77]

flutter::testing::TEST_F | ( | FlutterChannelKeyResponderTest | ,
|  | EmptyResponseIsTakenAsHandled |
| ) |  |

Definition at line 228 of file FlutterChannelKeyResponderTest.mm.

228 {
229 __block NSMutableArray<NSNumber*>* responses = [[NSMutableArray<NSNumber*> alloc] init];
230 FakeMessageChannel* channel = [[FakeMessageChannel alloc] init];
231 FlutterChannelKeyResponder* responder =
232 [[FlutterChannelKeyResponder alloc] initWithChannel:channel];
233
234 channel.nextResponse = nil;
235 [responder handleEvent:CreateKeyEvent(NSEventTypeKeyDown, 0x100, @"a", @"a", NO, 0)
236 callback:^(BOOL handled) {
237 [responses addObject:@(handled)];
238 }];
239
240 ASSERT_EQ([channel.messages count], 1u);
241 EXPECT_STREQ([[channel.messages lastObject][@"keymap"] UTF8String], "macos");
242 EXPECT_STREQ([[channel.messages lastObject][@"type"] UTF8String], "keydown");
243 EXPECT_EQ([[channel.messages lastObject][@"keyCode"] intValue], 0);
244 EXPECT_EQ([[channel.messages lastObject][@"modifiers"] intValue], 0);
245 EXPECT_STREQ([[channel.messages lastObject][@"characters"] UTF8String], "a");
246 EXPECT_STREQ([[channel.messages lastObject][@"charactersIgnoringModifiers"] UTF8String], "a");
247
248 ASSERT_EQ([responses count], 1u);
249 EXPECT_EQ([[responses lastObject] boolValue], YES);
250 }

References <FlutterKeyPrimaryResponder>::handleEvent:callback:, FakeMessageChannel::messages, and FakeMessageChannel::nextResponse.

## ◆ TEST_F() [7/77]

flutter::testing::TEST_F | ( | FlutterChannelKeyResponderTest | ,
|  | FollowsLayoutMap |
| ) |  |

Definition at line 252 of file FlutterChannelKeyResponderTest.mm.

252 {
253 __block NSMutableArray<NSNumber*>* responses = [[NSMutableArray<NSNumber*> alloc] init];
254 FakeMessageChannel* channel = [[FakeMessageChannel alloc] init];
255 FlutterChannelKeyResponder* responder =
256 [[FlutterChannelKeyResponder alloc] initWithChannel:channel];
257
258 NSMutableDictionary<NSNumber*, NSNumber*>* layoutMap =
259 [NSMutableDictionary<NSNumber*, NSNumber*> dictionary];
260 responder.layoutMap = layoutMap;
261 // French layout
262 layoutMap[@(kVK_ANSI_A)] = @(kLogicalKeyQ);
263
264 channel.nextResponse = @{@"handled" : @YES};
265 [responder handleEvent:CreateKeyEvent(NSEventTypeKeyDown, kVK_ANSI_A, @"q", @"q", NO, 0)
266 callback:^(BOOL handled) {
267 [responses addObject:@(handled)];
268 }];
269
270 ASSERT_EQ([channel.messages count], 1u);
271 EXPECT_STREQ([[channel.messages lastObject][@"keymap"] UTF8String], "macos");
272 EXPECT_STREQ([[channel.messages lastObject][@"type"] UTF8String], "keydown");
273 EXPECT_EQ([[channel.messages lastObject][@"keyCode"] intValue], 0);
274 EXPECT_EQ([[channel.messages lastObject][@"modifiers"] intValue], 0x0);
275 EXPECT_STREQ([[channel.messages lastObject][@"characters"] UTF8String], "q");
276 EXPECT_STREQ([[channel.messages lastObject][@"charactersIgnoringModifiers"] UTF8String], "q");
277 EXPECT_EQ([channel.messages lastObject][@"specifiedLogicalKey"], @(kLogicalKeyQ));
278
279 ASSERT_EQ([responses count], 1u);
280 EXPECT_EQ([[responses lastObject] boolValue], YES);
281
282 [channel.messages removeAllObjects];
283 [responses removeAllObjects];
284 }
FlutterKeyPrimaryResponder-p::layoutMap
NSMutableDictionary< NSNumber *, NSNumber * > * layoutMap
Definition: FlutterKeyPrimaryResponder.h:46

References <FlutterKeyPrimaryResponder>::handleEvent:callback:, <FlutterKeyPrimaryResponder>::layoutMap, FakeMessageChannel::messages, and FakeMessageChannel::nextResponse.

## ◆ TEST_F() [8/77]

flutter::testing::TEST_F | ( | FlutterEmbedderExternalTextureTest | ,
|  | TestPopulateExternalTexture |
| ) |  |

Definition at line 154 of file FlutterEmbedderExternalTextureTest.mm.

154 {
155 // Constants.
156 const size_t width = 100;
157 const size_t height = 100;
158 const int64_t texture_id = 1;
159
160 // Set up the surface.
161 FlutterDarwinContextMetalSkia* darwinContextMetal =
162 [[FlutterDarwinContextMetalSkia alloc] initWithDefaultMTLDevice];
163 SkImageInfo info = SkImageInfo::MakeN32Premul(width, height);
164 GrDirectContext* grContext = darwinContextMetal.mainContext.get();
165 sk_sp<SkSurface> gpuSurface(SkSurfaces::RenderTarget(grContext, skgpu::Budgeted::kNo, info));
166
167 // Create a texture.
168 TestExternalTexture* testExternalTexture =
169 [[TestExternalTexture alloc] initWidth:width
170 height:height
171 pixelFormatType:kCVPixelFormatType_32BGRA];
172 FlutterExternalTexture* textureHolder =
173 [[FlutterExternalTexture alloc] initWithFlutterTexture:testExternalTexture
174 darwinMetalContext:darwinContextMetal];
175
176 // Callback to resolve the texture.
177 EmbedderExternalTextureMetal::ExternalTextureCallback callback = [&](int64_t texture_id, size_t w,
178 size_t h) {
179 EXPECT_TRUE(w == width);
180 EXPECT_TRUE(h == height);
181
182 auto texture = std::make_unique<FlutterMetalExternalTexture>();
183 [textureHolder populateTexture:texture.get()];
184
185 EXPECT_TRUE(texture->num_textures == 1);
186 EXPECT_TRUE(texture->textures != nullptr);
187 EXPECT_TRUE(texture->pixel_format == FlutterMetalExternalTexturePixelFormat::kRGBA);
188 return texture;
189 };
190
191 // Render the texture.
192 std::unique_ptr<flutter::Texture> texture =
193 std::make_unique<EmbedderExternalTextureMetal>(texture_id, callback);
194 DlRect bounds = DlRect::MakeWH(info.width(), info.height());
195 DlImageSampling sampling = DlImageSampling::kNearestNeighbor;
196 DlSkCanvasAdapter canvas(gpuSurface->getCanvas());
197 flutter::Texture::PaintContext context{
198 .canvas = &canvas,
199 .gr_context = grContext,
200 };
201 texture->Paint(context, bounds, /*freeze=*/false, sampling);
202
203 gpuSurface->makeImageSnapshot();
204 }
FlutterExternalTexture
Definition: FlutterExternalTexture.h:19
-[FlutterExternalTexture populateTexture:]
BOOL populateTexture:(nonnull FlutterMetalExternalTexture *metalTexture)
TestExternalTexture
Definition: FlutterEmbedderExternalTextureTest.mm:48
texture_id
int64_t texture_id
Definition: texture_registrar_unittests.cc:24

References FlutterExternalTexture::populateTexture:, and texture_id.

## ◆ TEST_F() [9/77]

flutter::testing::TEST_F | ( | FlutterEmbedderExternalTextureTest | ,
|  | TestPopulateExternalTextureImpeller |
| ) |  |

Definition at line 413 of file FlutterEmbedderExternalTextureTest.mm.

413 {
414 // Constants.
415 const size_t width = 100;
416 const size_t height = 100;
417 const int64_t texture_id = 1;
418
419 // Set up the surface.
420 FlutterDarwinContextMetalSkia* darwinContextMetal =
421 [[FlutterDarwinContextMetalSkia alloc] initWithDefaultMTLDevice];
422 impeller::AiksContext aiks_context(CreateImpellerContext(), nullptr);
423 SkImageInfo info = SkImageInfo::MakeN32Premul(width, height);
424
425 // Create a texture.
426 TestExternalTexture* testExternalTexture =
427 [[TestExternalTexture alloc] initWidth:width
428 height:height
429 pixelFormatType:kCVPixelFormatType_32BGRA];
430 FlutterExternalTexture* textureHolder =
431 [[FlutterExternalTexture alloc] initWithFlutterTexture:testExternalTexture
432 darwinMetalContext:darwinContextMetal];
433
434 // Callback to resolve the texture.
435 EmbedderExternalTextureMetal::ExternalTextureCallback callback = [&](int64_t texture_id, size_t w,
436 size_t h) {
437 EXPECT_TRUE(w == width);
438 EXPECT_TRUE(h == height);
439
440 auto texture = std::make_unique<FlutterMetalExternalTexture>();
441 [textureHolder populateTexture:texture.get()];
442
443 EXPECT_TRUE(texture->num_textures == 1);
444 EXPECT_TRUE(texture->textures != nullptr);
445 EXPECT_TRUE(texture->pixel_format == FlutterMetalExternalTexturePixelFormat::kRGBA);
446 return texture;
447 };
448
449 // Render the texture.
450 std::unique_ptr<flutter::Texture> texture =
451 std::make_unique<EmbedderExternalTextureMetal>(texture_id, callback);
452 DlRect bounds = DlRect::MakeWH(info.width(), info.height());
453 DlImageSampling sampling = DlImageSampling::kNearestNeighbor;
454
455 DisplayListBuilder builder;
456 flutter::Texture::PaintContext context{
457 .canvas = &builder,
458 .gr_context = nullptr,
459 .aiks_context = &aiks_context,
460 };
461 texture->Paint(context, bounds, /*freeze=*/false, sampling);
462 }
CreateImpellerContext
static std::shared_ptr< impeller::ContextMTL > CreateImpellerContext()
Definition: FlutterEmbedderExternalTextureTest.mm:34

References CreateImpellerContext(), FlutterExternalTexture::populateTexture:, and texture_id.

## ◆ TEST_F() [10/77]

flutter::testing::TEST_F | ( | FlutterEmbedderExternalTextureTest | ,
|  | TestPopulateExternalTextureYUVA |
| ) |  |

Definition at line 206 of file FlutterEmbedderExternalTextureTest.mm.

206 {
207 // Constants.
208 const size_t width = 100;
209 const size_t height = 100;
210 const int64_t texture_id = 1;
211
212 // Set up the surface.
213 FlutterDarwinContextMetalSkia* darwinContextMetal =
214 [[FlutterDarwinContextMetalSkia alloc] initWithDefaultMTLDevice];
215 SkImageInfo info = SkImageInfo::MakeN32Premul(width, height);
216 GrDirectContext* grContext = darwinContextMetal.mainContext.get();
217 sk_sp<SkSurface> gpuSurface(SkSurfaces::RenderTarget(grContext, skgpu::Budgeted::kNo, info));
218
219 // Create a texture.
220 TestExternalTexture* testExternalTexture =
221 [[TestExternalTexture alloc] initWidth:width
222 height:height
223 pixelFormatType:kCVPixelFormatType_420YpCbCr8BiPlanarVideoRange];
224 FlutterExternalTexture* textureHolder =
225 [[FlutterExternalTexture alloc] initWithFlutterTexture:testExternalTexture
226 darwinMetalContext:darwinContextMetal];
227
228 // Callback to resolve the texture.
229 EmbedderExternalTextureMetal::ExternalTextureCallback callback = [&](int64_t texture_id, size_t w,
230 size_t h) {
231 EXPECT_TRUE(w == width);
232 EXPECT_TRUE(h == height);
233
234 auto texture = std::make_unique<FlutterMetalExternalTexture>();
235 [textureHolder populateTexture:texture.get()];
236
237 EXPECT_TRUE(texture->num_textures == 2);
238 EXPECT_TRUE(texture->textures != nullptr);
239 EXPECT_TRUE(texture->pixel_format == FlutterMetalExternalTexturePixelFormat::kYUVA);
240 EXPECT_TRUE(texture->yuv_color_space ==
241 FlutterMetalExternalTextureYUVColorSpace::kBT601LimitedRange);
242 return texture;
243 };
244
245 // Render the texture.
246 std::unique_ptr<flutter::Texture> texture =
247 std::make_unique<EmbedderExternalTextureMetal>(texture_id, callback);
248 DlRect bounds = DlRect::MakeWH(info.width(), info.height());
249 DlImageSampling sampling = DlImageSampling::kNearestNeighbor;
250 DlSkCanvasAdapter canvas(gpuSurface->getCanvas());
251 flutter::Texture::PaintContext context{
252 .canvas = &canvas,
253 .gr_context = grContext,
254 };
255 texture->Paint(context, bounds, /*freeze=*/false, sampling);
256
257 gpuSurface->makeImageSnapshot();
258 }

References FlutterExternalTexture::populateTexture:, and texture_id.

## ◆ TEST_F() [11/77]

flutter::testing::TEST_F | ( | FlutterEmbedderExternalTextureTest | ,
|  | TestPopulateExternalTextureYUVA2 |
| ) |  |

Definition at line 260 of file FlutterEmbedderExternalTextureTest.mm.

260 {
261 // Constants.
262 const size_t width = 100;
263 const size_t height = 100;
264 const int64_t texture_id = 1;
265
266 // Set up the surface.
267 FlutterDarwinContextMetalSkia* darwinContextMetal =
268 [[FlutterDarwinContextMetalSkia alloc] initWithDefaultMTLDevice];
269 SkImageInfo info = SkImageInfo::MakeN32Premul(width, height);
270 GrDirectContext* grContext = darwinContextMetal.mainContext.get();
271 sk_sp<SkSurface> gpuSurface(SkSurfaces::RenderTarget(grContext, skgpu::Budgeted::kNo, info));
272
273 // Create a texture.
274 TestExternalTexture* testExternalTexture =
275 [[TestExternalTexture alloc] initWidth:width
276 height:height
277 pixelFormatType:kCVPixelFormatType_420YpCbCr8BiPlanarFullRange];
278 FlutterExternalTexture* textureHolder =
279 [[FlutterExternalTexture alloc] initWithFlutterTexture:testExternalTexture
280 darwinMetalContext:darwinContextMetal];
281
282 // Callback to resolve the texture.
283 EmbedderExternalTextureMetal::ExternalTextureCallback callback = [&](int64_t texture_id, size_t w,
284 size_t h) {
285 EXPECT_TRUE(w == width);
286 EXPECT_TRUE(h == height);
287
288 auto texture = std::make_unique<FlutterMetalExternalTexture>();
289 [textureHolder populateTexture:texture.get()];
290
291 EXPECT_TRUE(texture->num_textures == 2);
292 EXPECT_TRUE(texture->textures != nullptr);
293 EXPECT_TRUE(texture->pixel_format == FlutterMetalExternalTexturePixelFormat::kYUVA);
294 EXPECT_TRUE(texture->yuv_color_space ==
295 FlutterMetalExternalTextureYUVColorSpace::kBT601FullRange);
296 return texture;
297 };
298
299 // Render the texture.
300 std::unique_ptr<flutter::Texture> texture =
301 std::make_unique<EmbedderExternalTextureMetal>(texture_id, callback);
302 DlRect bounds = DlRect::MakeWH(info.width(), info.height());
303 DlImageSampling sampling = DlImageSampling::kNearestNeighbor;
304 DlSkCanvasAdapter canvas(gpuSurface->getCanvas());
305 flutter::Texture::PaintContext context{
306 .canvas = &canvas,
307 .gr_context = grContext,
308 };
309 texture->Paint(context, bounds, /*freeze=*/false, sampling);
310
311 gpuSurface->makeImageSnapshot();
312 }

References FlutterExternalTexture::populateTexture:, and texture_id.

## ◆ TEST_F() [12/77]

flutter::testing::TEST_F | ( | FlutterEmbedderExternalTextureTest | ,
|  | TestPopulateExternalTextureYUVA2Impeller |
| ) |  |

Definition at line 514 of file FlutterEmbedderExternalTextureTest.mm.

514 {
515 // Constants.
516 const size_t width = 100;
517 const size_t height = 100;
518 const int64_t texture_id = 1;
519
520 // Set up the surface.
521 FlutterDarwinContextMetalSkia* darwinContextMetal =
522 [[FlutterDarwinContextMetalSkia alloc] initWithDefaultMTLDevice];
523 impeller::AiksContext aiks_context(CreateImpellerContext(), nullptr);
524 SkImageInfo info = SkImageInfo::MakeN32Premul(width, height);
525
526 // Create a texture.
527 TestExternalTexture* testExternalTexture =
528 [[TestExternalTexture alloc] initWidth:width
529 height:height
530 pixelFormatType:kCVPixelFormatType_420YpCbCr8BiPlanarFullRange];
531 FlutterExternalTexture* textureHolder =
532 [[FlutterExternalTexture alloc] initWithFlutterTexture:testExternalTexture
533 darwinMetalContext:darwinContextMetal];
534
535 // Callback to resolve the texture.
536 EmbedderExternalTextureMetal::ExternalTextureCallback callback = [&](int64_t texture_id, size_t w,
537 size_t h) {
538 EXPECT_TRUE(w == width);
539 EXPECT_TRUE(h == height);
540
541 auto texture = std::make_unique<FlutterMetalExternalTexture>();
542 [textureHolder populateTexture:texture.get()];
543
544 EXPECT_TRUE(texture->num_textures == 2);
545 EXPECT_TRUE(texture->textures != nullptr);
546 EXPECT_TRUE(texture->pixel_format == FlutterMetalExternalTexturePixelFormat::kYUVA);
547 EXPECT_TRUE(texture->yuv_color_space ==
548 FlutterMetalExternalTextureYUVColorSpace::kBT601FullRange);
549 return texture;
550 };
551
552 // Render the texture.
553 std::unique_ptr<flutter::Texture> texture =
554 std::make_unique<EmbedderExternalTextureMetal>(texture_id, callback);
555 DlRect bounds = DlRect::MakeWH(info.width(), info.height());
556 DlImageSampling sampling = DlImageSampling::kNearestNeighbor;
557
558 DisplayListBuilder builder;
559 flutter::Texture::PaintContext context{
560 .canvas = &builder, .gr_context = nullptr, .aiks_context = &aiks_context};
561 texture->Paint(context, bounds, /*freeze=*/false, sampling);
562 }

References CreateImpellerContext(), FlutterExternalTexture::populateTexture:, and texture_id.

## ◆ TEST_F() [13/77]

flutter::testing::TEST_F | ( | FlutterEmbedderExternalTextureTest | ,
|  | TestPopulateExternalTextureYUVAImpeller |
| ) |  |

Definition at line 464 of file FlutterEmbedderExternalTextureTest.mm.

464 {
465 // Constants.
466 const size_t width = 100;
467 const size_t height = 100;
468 const int64_t texture_id = 1;
469
470 // Set up the surface.
471 FlutterDarwinContextMetalSkia* darwinContextMetal =
472 [[FlutterDarwinContextMetalSkia alloc] initWithDefaultMTLDevice];
473 impeller::AiksContext aiks_context(CreateImpellerContext(), nullptr);
474 SkImageInfo info = SkImageInfo::MakeN32Premul(width, height);
475
476 // Create a texture.
477 TestExternalTexture* testExternalTexture =
478 [[TestExternalTexture alloc] initWidth:width
479 height:height
480 pixelFormatType:kCVPixelFormatType_420YpCbCr8BiPlanarVideoRange];
481 FlutterExternalTexture* textureHolder =
482 [[FlutterExternalTexture alloc] initWithFlutterTexture:testExternalTexture
483 darwinMetalContext:darwinContextMetal];
484
485 // Callback to resolve the texture.
486 EmbedderExternalTextureMetal::ExternalTextureCallback callback = [&](int64_t texture_id, size_t w,
487 size_t h) {
488 EXPECT_TRUE(w == width);
489 EXPECT_TRUE(h == height);
490
491 auto texture = std::make_unique<FlutterMetalExternalTexture>();
492 [textureHolder populateTexture:texture.get()];
493
494 EXPECT_TRUE(texture->num_textures == 2);
495 EXPECT_TRUE(texture->textures != nullptr);
496 EXPECT_TRUE(texture->pixel_format == FlutterMetalExternalTexturePixelFormat::kYUVA);
497 EXPECT_TRUE(texture->yuv_color_space ==
498 FlutterMetalExternalTextureYUVColorSpace::kBT601LimitedRange);
499 return texture;
500 };
501
502 // Render the texture.
503 std::unique_ptr<flutter::Texture> texture =
504 std::make_unique<EmbedderExternalTextureMetal>(texture_id, callback);
505 DlRect bounds = DlRect::MakeWH(info.width(), info.height());
506 DlImageSampling sampling = DlImageSampling::kNearestNeighbor;
507
508 DisplayListBuilder builder;
509 flutter::Texture::PaintContext context{
510 .canvas = &builder, .gr_context = nullptr, .aiks_context = &aiks_context};
511 texture->Paint(context, bounds, /*freeze=*/false, sampling);
512 }

References CreateImpellerContext(), FlutterExternalTexture::populateTexture:, and texture_id.

## ◆ TEST_F() [14/77]

flutter::testing::TEST_F | ( | FlutterEmbedderExternalTextureTest | ,
|  | TestPopulateUnsupportedExternalTexture |
| ) |  |

Definition at line 314 of file FlutterEmbedderExternalTextureTest.mm.

314 {
315 // Constants.
316 const size_t width = 100;
317 const size_t height = 100;
318 const int64_t texture_id = 1;
319
320 // Set up the surface.
321 FlutterDarwinContextMetalSkia* darwinContextMetal =
322 [[FlutterDarwinContextMetalSkia alloc] initWithDefaultMTLDevice];
323 SkImageInfo info = SkImageInfo::MakeN32Premul(width, height);
324 GrDirectContext* grContext = darwinContextMetal.mainContext.get();
325 sk_sp<SkSurface> gpuSurface(SkSurfaces::RenderTarget(grContext, skgpu::Budgeted::kNo, info));
326
327 // Create a texture.
328 TestExternalTexture* testExternalTexture =
329 [[TestExternalTexture alloc] initWidth:width
330 height:height
331 pixelFormatType:kCVPixelFormatType_420YpCbCr8PlanarFullRange];
332 FlutterExternalTexture* textureHolder =
333 [[FlutterExternalTexture alloc] initWithFlutterTexture:testExternalTexture
334 darwinMetalContext:darwinContextMetal];
335
336 // Callback to resolve the texture.
337 EmbedderExternalTextureMetal::ExternalTextureCallback callback = [&](int64_t texture_id, size_t w,
338 size_t h) {
339 EXPECT_TRUE(w == width);
340 EXPECT_TRUE(h == height);
341
342 auto texture = std::make_unique<FlutterMetalExternalTexture>();
343 EXPECT_FALSE([textureHolder populateTexture:texture.get()]);
344 return nullptr;
345 };
346
347 // Render the texture.
348 std::unique_ptr<flutter::Texture> texture =
349 std::make_unique<EmbedderExternalTextureMetal>(texture_id, callback);
350 DlRect bounds = DlRect::MakeWH(info.width(), info.height());
351 DlImageSampling sampling = DlImageSampling::kNearestNeighbor;
352 DlSkCanvasAdapter canvas(gpuSurface->getCanvas());
353 flutter::Texture::PaintContext context{
354 .canvas = &canvas,
355 .gr_context = grContext,
356 };
357 texture->Paint(context, bounds, /*freeze=*/false, sampling);
358 }

References texture_id.

## ◆ TEST_F() [15/77]

flutter::testing::TEST_F | ( | FlutterEmbedderExternalTextureTest | ,
|  | TestPopulateUnsupportedExternalTextureImpeller |
| ) |  |

Definition at line 564 of file FlutterEmbedderExternalTextureTest.mm.

564 {
565 // Constants.
566 const size_t width = 100;
567 const size_t height = 100;
568 const int64_t texture_id = 1;
569
570 // Set up the surface.
571 FlutterDarwinContextMetalSkia* darwinContextMetal =
572 [[FlutterDarwinContextMetalSkia alloc] initWithDefaultMTLDevice];
573 impeller::AiksContext aiks_context(CreateImpellerContext(), nullptr);
574 SkImageInfo info = SkImageInfo::MakeN32Premul(width, height);
575
576 // Create a texture.
577 TestExternalTexture* testExternalTexture =
578 [[TestExternalTexture alloc] initWidth:width
579 height:height
580 pixelFormatType:kCVPixelFormatType_420YpCbCr8PlanarFullRange];
581 FlutterExternalTexture* textureHolder =
582 [[FlutterExternalTexture alloc] initWithFlutterTexture:testExternalTexture
583 darwinMetalContext:darwinContextMetal];
584
585 // Callback to resolve the texture.
586 EmbedderExternalTextureMetal::ExternalTextureCallback callback = [&](int64_t texture_id, size_t w,
587 size_t h) {
588 EXPECT_TRUE(w == width);
589 EXPECT_TRUE(h == height);
590
591 auto texture = std::make_unique<FlutterMetalExternalTexture>();
592 EXPECT_FALSE([textureHolder populateTexture:texture.get()]);
593 return nullptr;
594 };
595
596 // Render the texture.
597 std::unique_ptr<flutter::Texture> texture =
598 std::make_unique<EmbedderExternalTextureMetal>(texture_id, callback);
599 DlRect bounds = DlRect::MakeWH(info.width(), info.height());
600 DlImageSampling sampling = DlImageSampling::kNearestNeighbor;
601
602 DisplayListBuilder builder;
603 flutter::Texture::PaintContext context{
604 .canvas = &builder, .gr_context = nullptr, .aiks_context = &aiks_context};
605 texture->Paint(context, bounds, /*freeze=*/false, sampling);
606 }

References CreateImpellerContext(), and texture_id.

## ◆ TEST_F() [16/77]

flutter::testing::TEST_F | ( | FlutterEmbedderExternalTextureTest | ,
|  | TestTextureResolution |
| ) |  |

Definition at line 96 of file FlutterEmbedderExternalTextureTest.mm.

96 {
97 // Constants.
98 const size_t width = 100;
99 const size_t height = 100;
100 const int64_t texture_id = 1;
101
102 // Set up the surface.
103 FlutterDarwinContextMetalSkia* darwinContextMetal =
104 [[FlutterDarwinContextMetalSkia alloc] initWithDefaultMTLDevice];
105 SkImageInfo info = SkImageInfo::MakeN32Premul(width, height);
106 GrDirectContext* grContext = darwinContextMetal.mainContext.get();
107 sk_sp<SkSurface> gpuSurface(SkSurfaces::RenderTarget(grContext, skgpu::Budgeted::kNo, info));
108
109 // Create a texture.
110 MTLTextureDescriptor* textureDescriptor = [[MTLTextureDescriptor alloc] init];
111 textureDescriptor.pixelFormat = MTLPixelFormatBGRA8Unorm;
112 textureDescriptor.width = width;
113 textureDescriptor.height = height;
114 textureDescriptor.usage = MTLTextureUsageRenderTarget | MTLTextureUsageShaderRead;
115 id<MTLTexture> mtlTexture =
116 [darwinContextMetal.device newTextureWithDescriptor:textureDescriptor];
117 std::vector<FlutterMetalTextureHandle> textures = {
118 (__bridge FlutterMetalTextureHandle)mtlTexture,
119 };
120
121 // Callback to resolve the texture.
122 EmbedderExternalTextureMetal::ExternalTextureCallback callback = [&](int64_t texture_id, size_t w,
123 size_t h) {
124 EXPECT_TRUE(w == width);
125 EXPECT_TRUE(h == height);
126
127 auto texture = std::make_unique<FlutterMetalExternalTexture>();
128 texture->struct_size = sizeof(FlutterMetalExternalTexture);
129 texture->num_textures = 1;
130 texture->height = h;
131 texture->width = w;
132 texture->pixel_format = FlutterMetalExternalTexturePixelFormat::kRGBA;
133 texture->textures = textures.data();
134 return texture;
135 };
136
137 // Render the texture.
138 std::unique_ptr<flutter::Texture> texture =
139 std::make_unique<EmbedderExternalTextureMetal>(texture_id, callback);
140 DlRect bounds = DlRect::MakeWH(info.width(), info.height());
141 DlImageSampling sampling = DlImageSampling::kNearestNeighbor;
142 DlSkCanvasAdapter canvas(gpuSurface->getCanvas());
143 flutter::Texture::PaintContext context{
144 .canvas = &canvas,
145 .gr_context = grContext,
146 };
147 texture->Paint(context, bounds, /*freeze=*/false, sampling);
148
149 ASSERT_TRUE(mtlTexture != nil);
150
151 gpuSurface->makeImageSnapshot();
152 }

References texture_id.

## ◆ TEST_F() [17/77]

flutter::testing::TEST_F | ( | FlutterEmbedderExternalTextureTest | ,
|  | TestTextureResolutionImpeller |
| ) |  |

Definition at line 360 of file FlutterEmbedderExternalTextureTest.mm.

360 {
361 // Constants.
362 const size_t width = 100;
363 const size_t height = 100;
364 const int64_t texture_id = 1;
365
366 // Set up the surface.
367 auto device = ::MTLCreateSystemDefaultDevice();
368 impeller::AiksContext aiks_context(CreateImpellerContext(), nullptr);
369
370 SkImageInfo info = SkImageInfo::MakeN32Premul(width, height);
371
372 // Create a texture.
373 MTLTextureDescriptor* textureDescriptor = [[MTLTextureDescriptor alloc] init];
374 textureDescriptor.pixelFormat = MTLPixelFormatBGRA8Unorm;
375 textureDescriptor.width = width;
376 textureDescriptor.height = height;
377 textureDescriptor.usage = MTLTextureUsageRenderTarget | MTLTextureUsageShaderRead;
378 id<MTLTexture> mtlTexture = [device newTextureWithDescriptor:textureDescriptor];
379 std::vector<FlutterMetalTextureHandle> textures = {
380 (__bridge FlutterMetalTextureHandle)mtlTexture,
381 };
382
383 // Callback to resolve the texture.
384 EmbedderExternalTextureMetal::ExternalTextureCallback callback = [&](int64_t texture_id, size_t w,
385 size_t h) {
386 EXPECT_TRUE(w == width);
387 EXPECT_TRUE(h == height);
388
389 auto texture = std::make_unique<FlutterMetalExternalTexture>();
390 texture->struct_size = sizeof(FlutterMetalExternalTexture);
391 texture->num_textures = 1;
392 texture->height = h;
393 texture->width = w;
394 texture->pixel_format = FlutterMetalExternalTexturePixelFormat::kRGBA;
395 texture->textures = textures.data();
396 return texture;
397 };
398
399 // Render the texture.
400 std::unique_ptr<flutter::Texture> texture =
401 std::make_unique<EmbedderExternalTextureMetal>(texture_id, callback);
402 DlRect bounds = DlRect::MakeWH(info.width(), info.height());
403 DlImageSampling sampling = DlImageSampling::kNearestNeighbor;
404
405 DisplayListBuilder builder;
406 flutter::Texture::PaintContext context{
407 .canvas = &builder, .gr_context = nullptr, .aiks_context = &aiks_context};
408 texture->Paint(context, bounds, /*freeze=*/false, sampling);
409
410 ASSERT_TRUE(mtlTexture != nil);
411 }

References CreateImpellerContext(), and texture_id.

## ◆ TEST_F() [18/77]

flutter::testing::TEST_F | ( | FlutterEngineTest | ,
|  | CanGetEngineForId |
| ) |  |

Definition at line 872 of file FlutterEngineTest.mm.

872 {
873 FlutterEngine* engine = GetFlutterEngine();
874
875 fml::AutoResetWaitableEvent latch;
876 std::optional<int64_t> engineId;
877 AddNativeCallback("NotifyEngineId", CREATE_NATIVE_ENTRY([&](Dart_NativeArguments args) {
878 const auto argument = Dart_GetNativeArgument(args, 0);
879 if (!Dart_IsNull(argument)) {
880 const auto id = tonic::DartConverter<int64_t>::FromDart(argument);
881 engineId = id;
882 }
883 latch.Signal();
884 }));
885
886 EXPECT_TRUE([engine runWithEntrypoint:@"testEngineId"]);
887 latch.Wait();
888
889 EXPECT_TRUE(engineId.has_value());
890 if (!engineId.has_value()) {
891 return;
892 }
893 EXPECT_EQ(engine, [FlutterEngine engineForIdentifier:*engineId]);
894 ShutDownEngine();
895 }

## ◆ TEST_F() [19/77]

flutter::testing::TEST_F | ( | FlutterEngineTest | ,
|  | CanLaunch |
| ) |  |

Definition at line 141 of file FlutterEngineTest.mm.

141 {
142 FlutterEngine* engine = GetFlutterEngine();
143 EXPECT_TRUE([engine runWithEntrypoint:@"main"]);
144 ASSERT_TRUE(engine.running);
145 }

## ◆ TEST_F() [20/77]

flutter::testing::TEST_F | ( | FlutterEngineTest | ,
|  | CanLogToStdout |
| ) |  |

Definition at line 204 of file FlutterEngineTest.mm.

204 {
205 // Block until completion of print statement.
206 fml::AutoResetWaitableEvent latch;
207 AddNativeCallback("SignalNativeTest",
208 CREATE_NATIVE_ENTRY([&](Dart_NativeArguments args) { latch.Signal(); }));
209
210 // Replace stdout stream buffer with our own.
211 StreamCapture stdout_capture(&std::cout);
212
213 // Launch the test entrypoint.
214 FlutterEngine* engine = GetFlutterEngine();
215 EXPECT_TRUE([engine runWithEntrypoint:@"canLogToStdout"]);
216 ASSERT_TRUE(engine.running);
217
218 latch.Wait();
219
220 stdout_capture.Stop();
221
222 // Verify hello world was written to stdout.
223 EXPECT_TRUE(stdout_capture.GetOutput().find("Hello logging") != std::string::npos);
224 }

## ◆ TEST_F() [21/77]

flutter::testing::TEST_F | ( | FlutterEngineTest | ,
|  | CanToggleAccessibility |
| ) |  |

Definition at line 285 of file FlutterEngineTest.mm.

285 {
286 FlutterEngine* engine = GetFlutterEngine();
287 // Capture the update callbacks before the embedder API initializes.
288 auto original_init = engine.embedderAPI.Initialize;
289 std::function<void(const FlutterSemanticsUpdate2*, void*)> update_semantics_callback;
290 engine.embedderAPI.Initialize = MOCK_ENGINE_PROC(
291 Initialize, ([&update_semantics_callback, &original_init](
292 size_t version, const FlutterRendererConfig* config,
293 const FlutterProjectArgs* args, void* user_data, auto engine_out) {
294 update_semantics_callback = args->update_semantics_callback2;
295 return original_init(version, config, args, user_data, engine_out);
296 }));
297 EXPECT_TRUE([engine runWithEntrypoint:@"main"]);
298 // Set up view controller.
299 FlutterViewController* viewController = [[FlutterViewController alloc] initWithEngine:engine
300 nibName:nil
301 bundle:nil];
302 [viewController loadView];
303 // Enable the semantics.
304 bool enabled_called = false;
305 engine.embedderAPI.UpdateSemanticsEnabled =
306 MOCK_ENGINE_PROC(UpdateSemanticsEnabled, ([&enabled_called](auto engine, bool enabled) {
307 enabled_called = enabled;
308 return kSuccess;
309 }));
310 engine.semanticsEnabled = YES;
311 EXPECT_TRUE(enabled_called);
312 // Send flutter semantics updates.
313 FlutterSemanticsNode2 root;
314 root.id = 0;
315 root.flags = static_cast<FlutterSemanticsFlag>(0);
316 root.actions = static_cast<FlutterSemanticsAction>(0);
317 root.text_selection_base = -1;
318 root.text_selection_extent = -1;
319 root.label = "root";
320 root.hint = "";
321 root.value = "";
322 root.increased_value = "";
323 root.decreased_value = "";
324 root.tooltip = "";
325 root.child_count = 1;
326 int32_t children[] = {1};
327 root.children_in_traversal_order = children;
328 root.custom_accessibility_actions_count = 0;
329
330 FlutterSemanticsNode2 child1;
331 child1.id = 1;
332 child1.flags = static_cast<FlutterSemanticsFlag>(0);
333 child1.actions = static_cast<FlutterSemanticsAction>(0);
334 child1.text_selection_base = -1;
335 child1.text_selection_extent = -1;
336 child1.label = "child 1";
337 child1.hint = "";
338 child1.value = "";
339 child1.increased_value = "";
340 child1.decreased_value = "";
341 child1.tooltip = "";
342 child1.child_count = 0;
343 child1.custom_accessibility_actions_count = 0;
344
345 FlutterSemanticsUpdate2 update;
346 update.node_count = 2;
347 FlutterSemanticsNode2* nodes[] = {&root, &child1};
348 update.nodes = nodes;
349 update.custom_action_count = 0;
350 update_semantics_callback(&update, (__bridge void*)engine);
351
352 // Verify the accessibility tree is attached to the flutter view.
353 EXPECT_EQ([engine.viewController.flutterView.accessibilityChildren count], 1u);
354 NSAccessibilityElement* native_root = engine.viewController.flutterView.accessibilityChildren[0];
355 std::string root_label = [native_root.accessibilityLabel UTF8String];
356 EXPECT_TRUE(root_label == "root");
357 EXPECT_EQ(native_root.accessibilityRole, NSAccessibilityGroupRole);
358 EXPECT_EQ([native_root.accessibilityChildren count], 1u);
359 NSAccessibilityElement* native_child1 = native_root.accessibilityChildren[0];
360 std::string child1_value = [native_child1.accessibilityValue UTF8String];
361 EXPECT_TRUE(child1_value == "child 1");
362 EXPECT_EQ(native_child1.accessibilityRole, NSAccessibilityStaticTextRole);
363 EXPECT_EQ([native_child1.accessibilityChildren count], 0u);
364 // Disable the semantics.
365 bool semanticsEnabled = true;
366 engine.embedderAPI.UpdateSemanticsEnabled =
367 MOCK_ENGINE_PROC(UpdateSemanticsEnabled, ([&semanticsEnabled](auto engine, bool enabled) {
368 semanticsEnabled = enabled;
369 return kSuccess;
370 }));
371 engine.semanticsEnabled = NO;
372 EXPECT_FALSE(semanticsEnabled);
373 // Verify the accessibility tree is removed from the view.
374 EXPECT_EQ([engine.viewController.flutterView.accessibilityChildren count], 0u);
375
376 [engine setViewController:nil];
377 }
FlutterEngine::viewController
FlutterViewController * viewController
Definition: FlutterEngine.h:87
user_data
void * user_data
Definition: texture_registrar_unittests.cc:27

References user_data, and FlutterEngine::viewController.

## ◆ TEST_F() [22/77]

flutter::testing::TEST_F | ( | FlutterEngineTest | ,
|  | CanToggleAccessibilityWhenHeadless |
| ) |  |

Definition at line 379 of file FlutterEngineTest.mm.

379 {
380 FlutterEngine* engine = GetFlutterEngine();
381 // Capture the update callbacks before the embedder API initializes.
382 auto original_init = engine.embedderAPI.Initialize;
383 std::function<void(const FlutterSemanticsUpdate2*, void*)> update_semantics_callback;
384 engine.embedderAPI.Initialize = MOCK_ENGINE_PROC(
385 Initialize, ([&update_semantics_callback, &original_init](
386 size_t version, const FlutterRendererConfig* config,
387 const FlutterProjectArgs* args, void* user_data, auto engine_out) {
388 update_semantics_callback = args->update_semantics_callback2;
389 return original_init(version, config, args, user_data, engine_out);
390 }));
391 EXPECT_TRUE([engine runWithEntrypoint:@"main"]);
392
393 // Enable the semantics without attaching a view controller.
394 bool enabled_called = false;
395 engine.embedderAPI.UpdateSemanticsEnabled =
396 MOCK_ENGINE_PROC(UpdateSemanticsEnabled, ([&enabled_called](auto engine, bool enabled) {
397 enabled_called = enabled;
398 return kSuccess;
399 }));
400 engine.semanticsEnabled = YES;
401 EXPECT_TRUE(enabled_called);
402 // Send flutter semantics updates.
403 FlutterSemanticsNode2 root;
404 root.id = 0;
405 root.flags = static_cast<FlutterSemanticsFlag>(0);
406 root.actions = static_cast<FlutterSemanticsAction>(0);
407 root.text_selection_base = -1;
408 root.text_selection_extent = -1;
409 root.label = "root";
410 root.hint = "";
411 root.value = "";
412 root.increased_value = "";
413 root.decreased_value = "";
414 root.tooltip = "";
415 root.child_count = 1;
416 int32_t children[] = {1};
417 root.children_in_traversal_order = children;
418 root.custom_accessibility_actions_count = 0;
419
420 FlutterSemanticsNode2 child1;
421 child1.id = 1;
422 child1.flags = static_cast<FlutterSemanticsFlag>(0);
423 child1.actions = static_cast<FlutterSemanticsAction>(0);
424 child1.text_selection_base = -1;
425 child1.text_selection_extent = -1;
426 child1.label = "child 1";
427 child1.hint = "";
428 child1.value = "";
429 child1.increased_value = "";
430 child1.decreased_value = "";
431 child1.tooltip = "";
432 child1.child_count = 0;
433 child1.custom_accessibility_actions_count = 0;
434
435 FlutterSemanticsUpdate2 update;
436 update.node_count = 2;
437 FlutterSemanticsNode2* nodes[] = {&root, &child1};
438 update.nodes = nodes;
439 update.custom_action_count = 0;
440 // This call updates semantics for the implicit view, which does not exist,
441 // and therefore this call is invalid. But the engine should not crash.
442 update_semantics_callback(&update, (__bridge void*)engine);
443
444 // No crashes.
445 EXPECT_EQ(engine.viewController, nil);
446
447 // Disable the semantics.
448 bool semanticsEnabled = true;
449 engine.embedderAPI.UpdateSemanticsEnabled =
450 MOCK_ENGINE_PROC(UpdateSemanticsEnabled, ([&semanticsEnabled](auto engine, bool enabled) {
451 semanticsEnabled = enabled;
452 return kSuccess;
453 }));
454 engine.semanticsEnabled = NO;
455 EXPECT_FALSE(semanticsEnabled);
456 // Still no crashes
457 EXPECT_EQ(engine.viewController, nil);
458 }

References user_data, and FlutterEngine::viewController.

## ◆ TEST_F() [23/77]

flutter::testing::TEST_F | ( | FlutterEngineTest | ,
|  | Compositor |
| ) |  |

Definition at line 501 of file FlutterEngineTest.mm.

501 {
502 NSString* fixtures = @(flutter::testing::GetFixturesPath());
503 FlutterDartProject* project = [[FlutterDartProject alloc]
504 initWithAssetsPath:fixtures
505 ICUDataPath:[fixtures stringByAppendingString:@"/icudtl.dat"]];
506 FlutterEngine* engine = [[FlutterEngine alloc] initWithName:@"test" project:project];
507
508 FlutterViewController* viewController = [[FlutterViewController alloc] initWithEngine:engine
509 nibName:nil
510 bundle:nil];
511 [viewController loadView];
512 [viewController viewDidLoad];
513 viewController.flutterView.frame = CGRectMake(0, 0, 800, 600);
514
515 EXPECT_TRUE([engine runWithEntrypoint:@"canCompositePlatformViews"]);
516
517 [engine.platformViewController registerViewFactory:[[TestPlatformViewFactory alloc] init]
518 withId:@"factory_id"];
519 [engine.platformViewController
520 handleMethodCall:[FlutterMethodCall methodCallWithMethodName:@"create"
521 arguments:@{
522 @"id" : @(42),
523 @"viewType" : @"factory_id",
524 }]
525 result:^(id result){
526 }];
527
528 // Wait up to 1 second for Flutter to emit a frame.
529 CFAbsoluteTime start = CFAbsoluteTimeGetCurrent();
530 CALayer* rootLayer = viewController.flutterView.layer;
531 while (rootLayer.sublayers.count == 0) {
532 CFRunLoopRunInMode(kCFRunLoopDefaultMode, 1, YES);
533 if (CFAbsoluteTimeGetCurrent() - start > 1) {
534 break;
535 }
536 }
537
538 // There are two layers with Flutter contents and one view
539 EXPECT_EQ(rootLayer.sublayers.count, 2u);
540 EXPECT_EQ(viewController.flutterView.subviews.count, 1u);
541
542 // TODO(gw280): add support for screenshot tests in this test harness
543
544 [engine shutDownEngine];
545 }
TestPlatformViewFactory
Definition: FlutterEngineTest.mm:47

References FlutterMethodCall::methodCallWithMethodName:arguments:, and FlutterEngine::shutDownEngine.

## ◆ TEST_F() [24/77]

flutter::testing::TEST_F | ( | FlutterEngineTest | ,
|  | CompositorIgnoresUnknownView |
| ) |  |

Definition at line 547 of file FlutterEngineTest.mm.

547 {
548 FlutterEngine* engine = GetFlutterEngine();
549 auto original_init = engine.embedderAPI.Initialize;
550 ::FlutterCompositor compositor;
551 engine.embedderAPI.Initialize = MOCK_ENGINE_PROC(
552 Initialize, ([&compositor, &original_init](
553 size_t version, const FlutterRendererConfig* config,
554 const FlutterProjectArgs* args, void* user_data, auto engine_out) {
555 compositor = *args->compositor;
556 return original_init(version, config, args, user_data, engine_out);
557 }));
558
559 FlutterViewController* viewController = [[FlutterViewController alloc] initWithEngine:engine
560 nibName:nil
561 bundle:nil];
562 [viewController loadView];
563
564 EXPECT_TRUE([engine runWithEntrypoint:@"empty"]);
565
566 FlutterBackingStoreConfig config = {
567 .struct_size = sizeof(FlutterBackingStoreConfig),
568 .size = FlutterSize{10, 10},
569 };
570 FlutterBackingStore backing_store = {};
571 EXPECT_NE(compositor.create_backing_store_callback, nullptr);
572 EXPECT_TRUE(
573 compositor.create_backing_store_callback(&config, &backing_store, compositor.user_data));
574
575 FlutterLayer layer{
576 .type = kFlutterLayerContentTypeBackingStore,
577 .backing_store = &backing_store,
578 };
579 std::vector<FlutterLayer*> layers = {&layer};
580
581 FlutterPresentViewInfo info = {
582 .struct_size = sizeof(FlutterPresentViewInfo),
583 .view_id = 123,
584 .layers = const_cast<const FlutterLayer**>(layers.data()),
585 .layers_count = 1,
586 .user_data = compositor.user_data,
587 };
588 EXPECT_NE(compositor.present_view_callback, nullptr);
589 EXPECT_FALSE(compositor.present_view_callback(&info));
590 EXPECT_TRUE(compositor.collect_backing_store_callback(&backing_store, compositor.user_data));
591
592 (void)viewController;
593 [engine shutDownEngine];
594 }

References FlutterEngine::shutDownEngine, and user_data.

## ◆ TEST_F() [25/77]

flutter::testing::TEST_F | ( | FlutterEngineTest | ,
|  | DartEntrypointArguments |
| ) |  |

Definition at line 596 of file FlutterEngineTest.mm.

596 {
597 NSString* fixtures = @(flutter::testing::GetFixturesPath());
598 FlutterDartProject* project = [[FlutterDartProject alloc]
599 initWithAssetsPath:fixtures
600 ICUDataPath:[fixtures stringByAppendingString:@"/icudtl.dat"]];
601
602 project.dartEntrypointArguments = @[ @"arg1", @"arg2" ];
603 FlutterEngine* engine = [[FlutterEngine alloc] initWithName:@"test" project:project];
604
605 bool called = false;
606 auto original_init = engine.embedderAPI.Initialize;
607 engine.embedderAPI.Initialize = MOCK_ENGINE_PROC(
608 Initialize, ([&called, &original_init](size_t version, const FlutterRendererConfig* config,
609 const FlutterProjectArgs* args, void* user_data,
610 FLUTTER_API_SYMBOL(FlutterEngine) * engine_out) {
611 called = true;
612 EXPECT_EQ(args->dart_entrypoint_argc, 2);
613 NSString* arg1 = [[NSString alloc] initWithCString:args->dart_entrypoint_argv[0]
614 encoding:NSUTF8StringEncoding];
615 NSString* arg2 = [[NSString alloc] initWithCString:args->dart_entrypoint_argv[1]
616 encoding:NSUTF8StringEncoding];
617
618 EXPECT_TRUE([arg1 isEqualToString:@"arg1"]);
619 EXPECT_TRUE([arg2 isEqualToString:@"arg2"]);
620
621 return original_init(version, config, args, user_data, engine_out);
622 }));
623
624 EXPECT_TRUE([engine runWithEntrypoint:@"main"]);
625 EXPECT_TRUE(called);
626 [engine shutDownEngine];
627 }

References FlutterEngine::shutDownEngine, and user_data.

## ◆ TEST_F() [26/77]

flutter::testing::TEST_F | ( | FlutterEngineTest | ,
|  | DISABLED_BackgroundIsBlack |
| ) |  |

Definition at line 226 of file FlutterEngineTest.mm.

226 {
227 FlutterEngine* engine = GetFlutterEngine();
228
229 // Latch to ensure the entire layer tree has been generated and presented.
230 fml::AutoResetWaitableEvent latch;
231 AddNativeCallback("SignalNativeTest", CREATE_NATIVE_ENTRY([&](Dart_NativeArguments args) {
232 CALayer* rootLayer = engine.viewController.flutterView.layer;
233 EXPECT_TRUE(rootLayer.backgroundColor != nil);
234 if (rootLayer.backgroundColor != nil) {
235 NSColor* actualBackgroundColor =
236 [NSColor colorWithCGColor:rootLayer.backgroundColor];
237 EXPECT_EQ(actualBackgroundColor, [NSColor blackColor]);
238 }
239 latch.Signal();
240 }));
241
242 // Launch the test entrypoint.
243 EXPECT_TRUE([engine runWithEntrypoint:@"backgroundTest"]);
244 ASSERT_TRUE(engine.running);
245
246 FlutterViewController* viewController = [[FlutterViewController alloc] initWithEngine:engine
247 nibName:nil
248 bundle:nil];
249 [viewController loadView];
250 viewController.flutterView.frame = CGRectMake(0, 0, 800, 600);
251
252 latch.Wait();
253 }

References FlutterEngine::viewController.

## ◆ TEST_F() [27/77]

flutter::testing::TEST_F | ( | FlutterEngineTest | ,
|  | DISABLED_CanOverrideBackgroundColor |
| ) |  |

Definition at line 255 of file FlutterEngineTest.mm.

255 {
256 FlutterEngine* engine = GetFlutterEngine();
257
258 // Latch to ensure the entire layer tree has been generated and presented.
259 fml::AutoResetWaitableEvent latch;
260 AddNativeCallback("SignalNativeTest", CREATE_NATIVE_ENTRY([&](Dart_NativeArguments args) {
261 CALayer* rootLayer = engine.viewController.flutterView.layer;
262 EXPECT_TRUE(rootLayer.backgroundColor != nil);
263 if (rootLayer.backgroundColor != nil) {
264 NSColor* actualBackgroundColor =
265 [NSColor colorWithCGColor:rootLayer.backgroundColor];
266 EXPECT_EQ(actualBackgroundColor, [NSColor whiteColor]);
267 }
268 latch.Signal();
269 }));
270
271 // Launch the test entrypoint.
272 EXPECT_TRUE([engine runWithEntrypoint:@"backgroundTest"]);
273 ASSERT_TRUE(engine.running);
274
275 FlutterViewController* viewController = [[FlutterViewController alloc] initWithEngine:engine
276 nibName:nil
277 bundle:nil];
278 [viewController loadView];
279 viewController.flutterView.frame = CGRectMake(0, 0, 800, 600);
280 viewController.flutterView.backgroundColor = [NSColor whiteColor];
281
282 latch.Wait();
283 }
FlutterViewController::backgroundColor
NSColor * backgroundColor
Definition: FlutterViewController.h:210

References FlutterViewController::backgroundColor, and FlutterEngine::viewController.

## ◆ TEST_F() [28/77]

flutter::testing::TEST_F | ( | FlutterEngineTest | ,
|  | DisplaySizeIsInPhysicalPixel |
| ) |  |

Definition at line 1282 of file FlutterEngineTest.mm.

1282 {
1283 NSString* fixtures = @(testing::GetFixturesPath());
1284 FlutterDartProject* project = [[FlutterDartProject alloc]
1285 initWithAssetsPath:fixtures
1286 ICUDataPath:[fixtures stringByAppendingString:@"/icudtl.dat"]];
1287 project.rootIsolateCreateCallback = FlutterEngineTest::IsolateCreateCallback;
1288 MockableFlutterEngine* engine = [[MockableFlutterEngine alloc] initWithName:@"foobar"
1289 project:project
1290 allowHeadlessExecution:true];
1291 BOOL updated = NO;
1292 auto original_update_displays = engine.embedderAPI.NotifyDisplayUpdate;
1293 engine.embedderAPI.NotifyDisplayUpdate = MOCK_ENGINE_PROC(
1294 NotifyDisplayUpdate, ([&updated, &original_update_displays](
1295 auto engine, auto update_type, auto* displays, auto display_count) {
1296 EXPECT_EQ(display_count, 1UL);
1297 EXPECT_EQ(displays->display_id, 10UL);
1298 EXPECT_EQ(displays->width, 60UL);
1299 EXPECT_EQ(displays->height, 80UL);
1300 EXPECT_EQ(displays->device_pixel_ratio, 2UL);
1301 updated = YES;
1302 return original_update_displays(engine, update_type, displays, display_count);
1303 }));
1304 EXPECT_TRUE([engine runWithEntrypoint:@"main"]);
1305 EXPECT_TRUE(updated);
1306 [engine shutDownEngine];
1307 engine = nil;
1308 }
MockableFlutterEngine
Definition: FlutterEngineTest.mm:123

References FlutterEngine::shutDownEngine.

## ◆ TEST_F() [29/77]

flutter::testing::TEST_F | ( | FlutterEngineTest | ,
|  | FlutterBinaryMessengerDoesNotRetainEngine |
| ) |  |

Definition at line 635 of file FlutterEngineTest.mm.

635 {
636 __weak FlutterEngine* weakEngine;
637 id<FlutterBinaryMessenger> binaryMessenger = nil;
638 @autoreleasepool {
639 // Create a test engine.
640 NSString* fixtures = @(flutter::testing::GetFixturesPath());
641 FlutterDartProject* project = [[FlutterDartProject alloc]
642 initWithAssetsPath:fixtures
643 ICUDataPath:[fixtures stringByAppendingString:@"/icudtl.dat"]];
644 FlutterEngine* engine = [[FlutterEngine alloc] initWithName:@"test"
645 project:project
646 allowHeadlessExecution:YES];
647 weakEngine = engine;
648 binaryMessenger = engine.binaryMessenger;
649 }
650
651 // Once the engine has been deallocated, verify the weak engine pointer is nil, and thus not
652 // retained by the relay.
653 EXPECT_NE(binaryMessenger, nil);
654 EXPECT_EQ(weakEngine, nil);
655 }
FlutterEngine::binaryMessenger
id< FlutterBinaryMessenger > binaryMessenger
Definition: FlutterEngine.h:92

References FlutterEngine::binaryMessenger.

## ◆ TEST_F() [30/77]

flutter::testing::TEST_F | ( | FlutterEngineTest | ,
|  | FlutterTextureRegistryDoesNotReturnEngine |
| ) |  |

Definition at line 659 of file FlutterEngineTest.mm.

659 {
660 __weak FlutterEngine* weakEngine;
661 id<FlutterTextureRegistry> textureRegistry;
662 @autoreleasepool {
663 // Create a test engine.
664 NSString* fixtures = @(flutter::testing::GetFixturesPath());
665 FlutterDartProject* project = [[FlutterDartProject alloc]
666 initWithAssetsPath:fixtures
667 ICUDataPath:[fixtures stringByAppendingString:@"/icudtl.dat"]];
668 FlutterEngine* engine = [[FlutterEngine alloc] initWithName:@"test"
669 project:project
670 allowHeadlessExecution:YES];
671 id<FlutterPluginRegistrar> registrar = [engine registrarForPlugin:@"MyPlugin"];
672 textureRegistry = registrar.textures;
673 }
674
675 // Once the engine has been deallocated, verify the weak engine pointer is nil, and thus not
676 // retained via the texture registry.
677 EXPECT_NE(textureRegistry, nil);
678 EXPECT_EQ(weakEngine, nil);
679 }

## ◆ TEST_F() [31/77]

flutter::testing::TEST_F | ( | FlutterEngineTest | ,
|  | ForwardsPluginDelegateRegistration |
| ) |  |

Definition at line 1195 of file FlutterEngineTest.mm.

1195 {
1196 id<NSApplicationDelegate> previousDelegate = [[NSApplication sharedApplication] delegate];
1197 FakeLifecycleProvider* fakeAppDelegate = [[FakeLifecycleProvider alloc] init];
1198 [NSApplication sharedApplication].delegate = fakeAppDelegate;
1199
1200 FakeAppDelegatePlugin* plugin = [[FakeAppDelegatePlugin alloc] init];
1201 FlutterEngine* engine = CreateMockFlutterEngine(nil);
1202
1203 [[engine registrarForPlugin:@"TestPlugin"] addApplicationDelegate:plugin];
1204
1205 EXPECT_TRUE([fakeAppDelegate hasDelegate:plugin]);
1206
1207 [NSApplication sharedApplication].delegate = previousDelegate;
1208 }
FakeAppDelegatePlugin
Definition: FlutterEngineTest.mm:112
FakeLifecycleProvider
Definition: FlutterEngineTest.mm:70

References CreateMockFlutterEngine().

## ◆ TEST_F() [32/77]

flutter::testing::TEST_F | ( | FlutterEngineTest | ,
|  | HandleAccessibilityEvent |
| ) |  |

Definition at line 1101 of file FlutterEngineTest.mm.

1101 {
1102 __block BOOL announced = NO;
1103 id engineMock = CreateMockFlutterEngine(nil);
1104
1105 OCMStub([engineMock announceAccessibilityMessage:[OCMArg any]
1106 withPriority:NSAccessibilityPriorityMedium])
1107 .andDo((^(NSInvocation* invocation) {
1108 announced = TRUE;
1109 [invocation retainArguments];
1110 NSString* message;
1111 [invocation getArgument:&message atIndex:2];
1112 EXPECT_EQ(message, @"error message");
1113 }));
1114
1115 NSDictionary<NSString*, id>* annotatedEvent =
1116 @{@"type" : @"announce",
1117 @"data" : @{@"message" : @"error message"}};
1118
1119 [engineMock handleAccessibilityEvent:annotatedEvent];
1120
1121 EXPECT_TRUE(announced);
1122 }

References CreateMockFlutterEngine().

## ◆ TEST_F() [33/77]

flutter::testing::TEST_F | ( | FlutterEngineTest | ,
|  | HandleLifecycleStates |
| ) |  |

Definition at line 1124 of file FlutterEngineTest.mm.

1124 {
1125 __block flutter::AppLifecycleState sentState;
1126 id engineMock = CreateMockFlutterEngine(nil);
1127
1128 // Have to enumerate all the values because OCMStub can't capture
1129 // non-Objective-C object arguments.
1130 OCMStub([engineMock setApplicationState:flutter::AppLifecycleState::kDetached])
1131 .andDo((^(NSInvocation* invocation) {
1132 sentState = flutter::AppLifecycleState::kDetached;
1133 }));
1134 OCMStub([engineMock setApplicationState:flutter::AppLifecycleState::kResumed])
1135 .andDo((^(NSInvocation* invocation) {
1136 sentState = flutter::AppLifecycleState::kResumed;
1137 }));
1138 OCMStub([engineMock setApplicationState:flutter::AppLifecycleState::kInactive])
1139 .andDo((^(NSInvocation* invocation) {
1140 sentState = flutter::AppLifecycleState::kInactive;
1141 }));
1142 OCMStub([engineMock setApplicationState:flutter::AppLifecycleState::kHidden])
1143 .andDo((^(NSInvocation* invocation) {
1144 sentState = flutter::AppLifecycleState::kHidden;
1145 }));
1146 OCMStub([engineMock setApplicationState:flutter::AppLifecycleState::kPaused])
1147 .andDo((^(NSInvocation* invocation) {
1148 sentState = flutter::AppLifecycleState::kPaused;
1149 }));
1150
1151 __block NSApplicationOcclusionState visibility = NSApplicationOcclusionStateVisible;
1152 id mockApplication = OCMPartialMock([NSApplication sharedApplication]);
1153 OCMStub((NSApplicationOcclusionState)[mockApplication occlusionState])
1154 .andDo(^(NSInvocation* invocation) {
1155 [invocation setReturnValue:&visibility];
1156 });
1157
1158 NSNotification* willBecomeActive =
1159 [[NSNotification alloc] initWithName:NSApplicationWillBecomeActiveNotification
1160 object:nil
1161 userInfo:nil];
1162 NSNotification* willResignActive =
1163 [[NSNotification alloc] initWithName:NSApplicationWillResignActiveNotification
1164 object:nil
1165 userInfo:nil];
1166
1167 NSNotification* didChangeOcclusionState;
1168 didChangeOcclusionState =
1169 [[NSNotification alloc] initWithName:NSApplicationDidChangeOcclusionStateNotification
1170 object:nil
1171 userInfo:nil];
1172
1173 [engineMock handleDidChangeOcclusionState:didChangeOcclusionState];
1174 EXPECT_EQ(sentState, flutter::AppLifecycleState::kInactive);
1175
1176 [engineMock handleWillBecomeActive:willBecomeActive];
1177 EXPECT_EQ(sentState, flutter::AppLifecycleState::kResumed);
1178
1179 [engineMock handleWillResignActive:willResignActive];
1180 EXPECT_EQ(sentState, flutter::AppLifecycleState::kInactive);
1181
1182 visibility = 0;
1183 [engineMock handleDidChangeOcclusionState:didChangeOcclusionState];
1184 EXPECT_EQ(sentState, flutter::AppLifecycleState::kHidden);
1185
1186 [engineMock handleWillBecomeActive:willBecomeActive];
1187 EXPECT_EQ(sentState, flutter::AppLifecycleState::kHidden);
1188
1189 [engineMock handleWillResignActive:willResignActive];
1190 EXPECT_EQ(sentState, flutter::AppLifecycleState::kHidden);
1191
1192 [mockApplication stopMocking];
1193 }
flutter::AppLifecycleState
AppLifecycleState
Definition: app_lifecycle_state.h:32
flutter::AppLifecycleState::kPaused
@ kPaused
flutter::AppLifecycleState::kDetached
@ kDetached
flutter::AppLifecycleState::kHidden
@ kHidden
flutter::AppLifecycleState::kResumed
@ kResumed
flutter::AppLifecycleState::kInactive
@ kInactive

References CreateMockFlutterEngine(), flutter::kDetached, flutter::kHidden, flutter::kInactive, flutter::kPaused, and flutter::kResumed.

## ◆ TEST_F() [34/77]

flutter::testing::TEST_F | ( | FlutterEngineTest | ,
|  | HandlesTerminationRequest |
| ) |  |

Definition at line 1007 of file FlutterEngineTest.mm.

1007 {
1008 id engineMock = CreateMockFlutterEngine(nil);
1009 __block NSString* nextResponse = @"exit";
1010 __block BOOL triedToTerminate = NO;
1011 FlutterEngineTerminationHandler* terminationHandler =
1012 [[FlutterEngineTerminationHandler alloc] initWithEngine:engineMock
1013 terminator:^(id sender) {
1014 triedToTerminate = TRUE;
1015 // Don't actually terminate, of course.
1016 }];
1017 OCMStub([engineMock terminationHandler]).andReturn(terminationHandler);
1018 id binaryMessengerMock = OCMProtocolMock(@protocol(FlutterBinaryMessenger));
1019 OCMStub( // NOLINT(google-objc-avoid-throwing-exception)
1020 [engineMock binaryMessenger])
1021 .andReturn(binaryMessengerMock);
1022 OCMStub([engineMock sendOnChannel:@"flutter/platform"
1023 message:[OCMArg any]
1024 binaryReply:[OCMArg any]])
1025 .andDo((^(NSInvocation* invocation) {
1026 [invocation retainArguments];
1027 FlutterBinaryReply callback;
1028 NSData* returnedMessage;
1029 [invocation getArgument:&callback atIndex:4];
1030 if ([nextResponse isEqualToString:@"error"]) {
1031 FlutterError* errorResponse = [FlutterError errorWithCode:@"Error"
1032 message:@"Failed"
1033 details:@"Details"];
1034 returnedMessage =
1035 [[FlutterJSONMethodCodec sharedInstance] encodeErrorEnvelope:errorResponse];
1036 } else {
1037 NSDictionary* responseDict = @{@"response" : nextResponse};
1038 returnedMessage =
1039 [[FlutterJSONMethodCodec sharedInstance] encodeSuccessEnvelope:responseDict];
1040 }
1041 callback(returnedMessage);
1042 }));
1043 __block NSString* calledAfterTerminate = @"";
1044 FlutterResult appExitResult = ^(id result) {
1045 NSDictionary* resultDict = result;
1046 calledAfterTerminate = resultDict[@"response"];
1047 };
1048 FlutterMethodCall* methodExitApplication =
1049 [FlutterMethodCall methodCallWithMethodName:@"System.exitApplication"
1050 arguments:@{@"type" : @"cancelable"}];
1051
1052 // Always terminate when the binding isn't ready (which is the default).
1053 triedToTerminate = NO;
1054 calledAfterTerminate = @"";
1055 nextResponse = @"cancel";
1056 [engineMock handleMethodCall:methodExitApplication result:appExitResult];
1057 EXPECT_STREQ([calledAfterTerminate UTF8String], "");
1058 EXPECT_TRUE(triedToTerminate);
1059
1060 // Once the binding is ready, handle the request.
1061 terminationHandler.acceptingRequests = YES;
1062 triedToTerminate = NO;
1063 calledAfterTerminate = @"";
1064 nextResponse = @"exit";
1065 [engineMock handleMethodCall:methodExitApplication result:appExitResult];
1066 EXPECT_STREQ([calledAfterTerminate UTF8String], "exit");
1067 EXPECT_TRUE(triedToTerminate);
1068
1069 triedToTerminate = NO;
1070 calledAfterTerminate = @"";
1071 nextResponse = @"cancel";
1072 [engineMock handleMethodCall:methodExitApplication result:appExitResult];
1073 EXPECT_STREQ([calledAfterTerminate UTF8String], "cancel");
1074 EXPECT_FALSE(triedToTerminate);
1075
1076 // Check that it doesn't crash on error.
1077 triedToTerminate = NO;
1078 calledAfterTerminate = @"";
1079 nextResponse = @"error";
1080 [engineMock handleMethodCall:methodExitApplication result:appExitResult];
1081 EXPECT_STREQ([calledAfterTerminate UTF8String], "");
1082 EXPECT_TRUE(triedToTerminate);
1083 }
FlutterBinaryReply
NS_ASSUME_NONNULL_BEGIN typedef void(^ FlutterBinaryReply)(NSData *_Nullable reply)
FlutterEngineTerminationHandler
Definition: FlutterEngine.mm:192
FlutterEngineTerminationHandler::acceptingRequests
BOOL acceptingRequests
Definition: FlutterEngine_Internal.h:62
+[FlutterError errorWithCode:message:details:]
instancetype errorWithCode:message:details:(NSString *code,[message] NSString *_Nullable message,[details] id _Nullable details)
FlutterJSONMethodCodec
Definition: FlutterCodecs.h:455

References FlutterEngineTerminationHandler::acceptingRequests, CreateMockFlutterEngine(), FlutterError::errorWithCode:message:details:, FlutterBinaryReply, and FlutterMethodCall::methodCallWithMethodName:arguments:.

## ◆ TEST_F() [35/77]

flutter::testing::TEST_F | ( | FlutterEngineTest | ,
|  | HasNonNullExecutableName |
| ) |  |

Definition at line 147 of file FlutterEngineTest.mm.

147 {
148 FlutterEngine* engine = GetFlutterEngine();
149 std::string executable_name = [[engine executableName] UTF8String];
150 ASSERT_FALSE(executable_name.empty());
151
152 // Block until notified by the Dart test of the value of Platform.executable.
153 fml::AutoResetWaitableEvent latch;
154 AddNativeCallback("NotifyStringValue", CREATE_NATIVE_ENTRY([&](Dart_NativeArguments args) {
155 const auto dart_string = tonic::DartConverter<std::string>::FromDart(
156 Dart_GetNativeArgument(args, 0));
157 EXPECT_EQ(executable_name, dart_string);
158 latch.Signal();
159 }));
160
161 // Launch the test entrypoint.
162 EXPECT_TRUE([engine runWithEntrypoint:@"executableNameNotNull"]);
163
164 latch.Wait();
165 }

## ◆ TEST_F() [36/77]

flutter::testing::TEST_F | ( | FlutterEngineTest | ,
|  | HasStringsWhenPasteboardEmpty |
| ) |  |

Definition at line 794 of file FlutterEngineTest.mm.

794 {
795 id engineMock = CreateMockFlutterEngine(nil);
796
797 // Call hasStrings and expect it to be false.
798 __block bool calledAfterClear = false;
799 __block bool valueAfterClear;
800 FlutterResult resultAfterClear = ^(id result) {
801 calledAfterClear = true;
802 NSNumber* valueNumber = [result valueForKey:@"value"];
803 valueAfterClear = [valueNumber boolValue];
804 };
805 FlutterMethodCall* methodCallAfterClear =
806 [FlutterMethodCall methodCallWithMethodName:@"Clipboard.hasStrings" arguments:nil];
807 [engineMock handleMethodCall:methodCallAfterClear result:resultAfterClear];
808 EXPECT_TRUE(calledAfterClear);
809 EXPECT_FALSE(valueAfterClear);
810 }

References CreateMockFlutterEngine(), and FlutterMethodCall::methodCallWithMethodName:arguments:.

## ◆ TEST_F() [37/77]

flutter::testing::TEST_F | ( | FlutterEngineTest | ,
|  | HasStringsWhenPasteboardFull |
| ) |  |

Definition at line 812 of file FlutterEngineTest.mm.

812 {
813 id engineMock = CreateMockFlutterEngine(@"some string");
814
815 // Call hasStrings and expect it to be true.
816 __block bool called = false;
817 __block bool value;
818 FlutterResult result = ^(id result) {
819 called = true;
820 NSNumber* valueNumber = [result valueForKey:@"value"];
821 value = [valueNumber boolValue];
822 };
823 FlutterMethodCall* methodCall =
824 [FlutterMethodCall methodCallWithMethodName:@"Clipboard.hasStrings" arguments:nil];
825 [engineMock handleMethodCall:methodCall result:result];
826 EXPECT_TRUE(called);
827 EXPECT_TRUE(value);
828 }

References CreateMockFlutterEngine(), and FlutterMethodCall::methodCallWithMethodName:arguments:.

## ◆ TEST_F() [38/77]

flutter::testing::TEST_F | ( | FlutterEngineTest | ,
|  | IgnoresTerminationRequestIfNotFlutterAppDelegate |
| ) |  |

Definition at line 1085 of file FlutterEngineTest.mm.

1085 {
1086 id<NSApplicationDelegate> previousDelegate = [[NSApplication sharedApplication] delegate];
1087 id<NSApplicationDelegate> plainDelegate = [[PlainAppDelegate alloc] init];
1088 [NSApplication sharedApplication].delegate = plainDelegate;
1089
1090 // Creating the engine shouldn't fail here, even though the delegate isn't a
1091 // FlutterAppDelegate.
1092 CreateMockFlutterEngine(nil);
1093
1094 // Asking to terminate the app should cancel.
1095 EXPECT_EQ([[[NSApplication sharedApplication] delegate] applicationShouldTerminate:NSApp],
1096 NSTerminateCancel);
1097
1098 [NSApplication sharedApplication].delegate = previousDelegate;
1099 }
PlainAppDelegate
Definition: FlutterEngineTest.mm:58

References CreateMockFlutterEngine().

## ◆ TEST_F() [39/77]

flutter::testing::TEST_F | ( | FlutterEngineTest | ,
|  | ManageControllersIfInitiatedByController |
| ) |  |

Definition at line 911 of file FlutterEngineTest.mm.

911 {
912 NSString* fixtures = @(flutter::testing::GetFixturesPath());
913 FlutterDartProject* project = [[FlutterDartProject alloc]
914 initWithAssetsPath:fixtures
915 ICUDataPath:[fixtures stringByAppendingString:@"/icudtl.dat"]];
916
917 FlutterEngine* engine;
918 FlutterViewController* viewController1;
919
920 @autoreleasepool {
921 // Create FVC1.
922 viewController1 = [[FlutterViewController alloc] initWithProject:project];
923 EXPECT_EQ(viewController1.viewIdentifier, 0ll);
924
925 engine = viewController1.engine;
926 engine.viewController = nil;
927
928 // Create FVC2 based on the same engine.
929 FlutterViewController* viewController2 = [[FlutterViewController alloc] initWithEngine:engine
930 nibName:nil
931 bundle:nil];
932 EXPECT_EQ(engine.viewController, viewController2);
933 }
934 // FVC2 is deallocated but FVC1 is retained.
935
936 EXPECT_EQ(engine.viewController, nil);
937
938 engine.viewController = viewController1;
939 EXPECT_EQ(engine.viewController, viewController1);
940 EXPECT_EQ(viewController1.viewIdentifier, 0ll);
941 }
FlutterViewController::viewIdentifier
FlutterViewIdentifier viewIdentifier
Definition: FlutterViewController.h:130

References FlutterViewController::engine, FlutterEngine::viewController, and FlutterViewController::viewIdentifier.

## ◆ TEST_F() [40/77]

flutter::testing::TEST_F | ( | FlutterEngineTest | ,
|  | ManageControllersIfInitiatedByEngine |
| ) |  |

Definition at line 943 of file FlutterEngineTest.mm.

943 {
944 // Don't create the engine with `CreateMockFlutterEngine`, because it adds
945 // additional references to FlutterViewControllers, which is crucial to this
946 // test case.
947 FlutterEngine* engine = [[FlutterEngine alloc] initWithName:@"io.flutter"
948 project:nil
949 allowHeadlessExecution:NO];
950 FlutterViewController* viewController1;
951
952 @autoreleasepool {
953 viewController1 = [[FlutterViewController alloc] initWithEngine:engine nibName:nil bundle:nil];
954 EXPECT_EQ(viewController1.viewIdentifier, 0ll);
955 EXPECT_EQ(engine.viewController, viewController1);
956
957 engine.viewController = nil;
958
959 FlutterViewController* viewController2 = [[FlutterViewController alloc] initWithEngine:engine
960 nibName:nil
961 bundle:nil];
962 EXPECT_EQ(viewController2.viewIdentifier, 0ll);
963 EXPECT_EQ(engine.viewController, viewController2);
964 }
965 // FVC2 is deallocated but FVC1 is retained.
966
967 EXPECT_EQ(engine.viewController, nil);
968
969 engine.viewController = viewController1;
970 EXPECT_EQ(engine.viewController, viewController1);
971 EXPECT_EQ(viewController1.viewIdentifier, 0ll);
972 }

References FlutterEngine::viewController, and FlutterViewController::viewIdentifier.

## ◆ TEST_F() [41/77]

flutter::testing::TEST_F | ( | FlutterEngineTest | ,
|  | MessengerCleanupConnectionWorks |
| ) |  |

Definition at line 737 of file FlutterEngineTest.mm.

737 {
738 FlutterEngine* engine = GetFlutterEngine();
739 EXPECT_TRUE([engine runWithEntrypoint:@"main"]);
740
741 NSString* channel = @"_test_";
742 NSData* channel_data = [channel dataUsingEncoding:NSUTF8StringEncoding];
743
744 // Mock SendPlatformMessage so that if a message is sent to
745 // "test/send_message", act as if the framework has sent an empty message to
746 // the channel marked by the `sendOnChannel:message:` call's message.
747 engine.embedderAPI.SendPlatformMessage = MOCK_ENGINE_PROC(
748 SendPlatformMessage, ([](auto engine_, auto message_) {
749 if (strcmp(message_->channel, "test/send_message") == 0) {
750 // The simplest message that is acceptable to a method channel.
751 std::string message = R"|({"method": "a"})|";
752 std::string channel(reinterpret_cast<const char*>(message_->message),
753 message_->message_size);
754 reinterpret_cast<EmbedderEngine*>(engine_)
755 ->GetShell()
756 .GetPlatformView()
757 ->HandlePlatformMessage(std::make_unique<PlatformMessage>(
758 channel.c_str(), fml::MallocMapping::Copy(message.c_str(), message.length()),
759 fml::RefPtr<PlatformMessageResponse>()));
760 }
761 return kSuccess;
762 }));
763
764 __block int record = 0;
765
766 FlutterMethodChannel* channel1 =
767 [FlutterMethodChannel methodChannelWithName:channel
768 binaryMessenger:engine.binaryMessenger
769 codec:[FlutterJSONMethodCodec sharedInstance]];
770 [channel1 setMethodCallHandler:^(FlutterMethodCall* call, FlutterResult result) {
771 record += 1;
772 }];
773
774 [engine.binaryMessenger sendOnChannel:@"test/send_message" message:channel_data];
775 EXPECT_EQ(record, 1);
776
777 FlutterMethodChannel* channel2 =
778 [FlutterMethodChannel methodChannelWithName:channel
779 binaryMessenger:engine.binaryMessenger
780 codec:[FlutterJSONMethodCodec sharedInstance]];
781 [channel2 setMethodCallHandler:^(FlutterMethodCall* call, FlutterResult result) {
782 record += 10;
783 }];
784
785 [engine.binaryMessenger sendOnChannel:@"test/send_message" message:channel_data];
786 EXPECT_EQ(record, 11);
787
788 [channel1 setMethodCallHandler:nil];
789
790 [engine.binaryMessenger sendOnChannel:@"test/send_message" message:channel_data];
791 EXPECT_EQ(record, 21);
792 }
FlutterMethodChannel
Definition: FlutterChannels.h:221
-[FlutterMethodChannel setMethodCallHandler:]
void setMethodCallHandler:(FlutterMethodCallHandler _Nullable handler)
+[FlutterMethodChannel methodChannelWithName:binaryMessenger:codec:]
instancetype methodChannelWithName:binaryMessenger:codec:(NSString *name,[binaryMessenger] NSObject< FlutterBinaryMessenger > *messenger,[codec] NSObject< FlutterMethodCodec > *codec)

References FlutterMethodChannel::methodChannelWithName:binaryMessenger:codec:, and FlutterMethodChannel::setMethodCallHandler:.

## ◆ TEST_F() [42/77]

flutter::testing::TEST_F | ( | FlutterEngineTest | ,
|  | MessengerSend |
| ) |  |

Definition at line 185 of file FlutterEngineTest.mm.

185 {
186 FlutterEngine* engine = GetFlutterEngine();
187 EXPECT_TRUE([engine runWithEntrypoint:@"main"]);
188
189 NSData* test_message = [@"a message" dataUsingEncoding:NSUTF8StringEncoding];
190 bool called = false;
191
192 engine.embedderAPI.SendPlatformMessage = MOCK_ENGINE_PROC(
193 SendPlatformMessage, ([&called, test_message](auto engine, auto message) {
194 called = true;
195 EXPECT_STREQ(message->channel, "test");
196 EXPECT_EQ(memcmp(message->message, test_message.bytes, message->message_size), 0);
197 return kSuccess;
198 }));
199
200 [engine.binaryMessenger sendOnChannel:@"test" message:test_message];
201 EXPECT_TRUE(called);
202 }

## ◆ TEST_F() [43/77]

flutter::testing::TEST_F | ( | FlutterEngineTest | ,
|  | NativeCallbacks |
| ) |  |

Definition at line 485 of file FlutterEngineTest.mm.

485 {
486 fml::AutoResetWaitableEvent latch;
487 bool latch_called = false;
488 AddNativeCallback("SignalNativeTest", CREATE_NATIVE_ENTRY([&](Dart_NativeArguments args) {
489 latch_called = true;
490 latch.Signal();
491 }));
492
493 FlutterEngine* engine = GetFlutterEngine();
494 EXPECT_TRUE([engine runWithEntrypoint:@"nativeCallback"]);
495 ASSERT_TRUE(engine.running);
496
497 latch.Wait();
498 ASSERT_TRUE(latch_called);
499 }

## ◆ TEST_F() [44/77]

flutter::testing::TEST_F | ( | FlutterEngineTest | ,
|  | NotificationsUpdateDisplays |
| ) |  |

Definition at line 1252 of file FlutterEngineTest.mm.

1252 {
1253 BOOL updated = NO;
1254 FlutterEngine* engine = GetFlutterEngine();
1255 auto original_set_viewport_metrics = engine.embedderAPI.SendWindowMetricsEvent;
1256 engine.embedderAPI.SendWindowMetricsEvent = MOCK_ENGINE_PROC(
1257 SendWindowMetricsEvent,
1258 ([&updated, &original_set_viewport_metrics](auto engine, auto* window_metrics) {
1259 updated = YES;
1260 return original_set_viewport_metrics(engine, window_metrics);
1261 }));
1262
1263 EXPECT_TRUE([engine runWithEntrypoint:@"main"]);
1264
1265 updated = NO;
1266 [[NSNotificationCenter defaultCenter] postNotificationName:NSWindowDidChangeScreenNotification
1267 object:nil];
1268 // No VC.
1269 EXPECT_FALSE(updated);
1270
1271 FlutterViewController* viewController = [[FlutterViewController alloc] initWithEngine:engine
1272 nibName:nil
1273 bundle:nil];
1274 [viewController loadView];
1275 viewController.flutterView.frame = CGRectMake(0, 0, 800, 600);
1276
1277 [[NSNotificationCenter defaultCenter] postNotificationName:NSWindowDidChangeScreenNotification
1278 object:nil];
1279 EXPECT_TRUE(updated);
1280 }

## ◆ TEST_F() [45/77]

flutter::testing::TEST_F | ( | FlutterEngineTest | ,
|  | ProducesAccessibilityTreeWhenAddingViews |
| ) |  |

Definition at line 460 of file FlutterEngineTest.mm.

460 {
461 FlutterEngine* engine = GetFlutterEngine();
462 EXPECT_TRUE([engine runWithEntrypoint:@"main"]);
463
464 // Enable the semantics without attaching a view controller.
465 bool enabled_called = false;
466 engine.embedderAPI.UpdateSemanticsEnabled =
467 MOCK_ENGINE_PROC(UpdateSemanticsEnabled, ([&enabled_called](auto engine, bool enabled) {
468 enabled_called = enabled;
469 return kSuccess;
470 }));
471 engine.semanticsEnabled = YES;
472 EXPECT_TRUE(enabled_called);
473
474 EXPECT_EQ(engine.viewController, nil);
475
476 // Assign the view controller after enabling semantics
477 FlutterViewController* viewController = [[FlutterViewController alloc] initWithEngine:engine
478 nibName:nil
479 bundle:nil];
480 engine.viewController = viewController;
481
482 EXPECT_NE(viewController.accessibilityBridge.lock(), nullptr);
483 }

References FlutterEngine::viewController.

## ◆ TEST_F() [46/77]

flutter::testing::TEST_F | ( | FlutterEngineTest | ,
|  | PublishedValueNilForUnknownPlugin |
| ) |  |

Definition at line 681 of file FlutterEngineTest.mm.

681 {
682 NSString* fixtures = @(flutter::testing::GetFixturesPath());
683 FlutterDartProject* project = [[FlutterDartProject alloc]
684 initWithAssetsPath:fixtures
685 ICUDataPath:[fixtures stringByAppendingString:@"/icudtl.dat"]];
686 FlutterEngine* engine = [[FlutterEngine alloc] initWithName:@"test"
687 project:project
688 allowHeadlessExecution:YES];
689
690 EXPECT_EQ([engine valuePublishedByPlugin:@"NoSuchPlugin"], nil);
691 }

## ◆ TEST_F() [47/77]

flutter::testing::TEST_F | ( | FlutterEngineTest | ,
|  | PublishedValueNSNullIfNoPublishedValue |
| ) |  |

Definition at line 693 of file FlutterEngineTest.mm.

693 {
694 NSString* fixtures = @(flutter::testing::GetFixturesPath());
695 FlutterDartProject* project = [[FlutterDartProject alloc]
696 initWithAssetsPath:fixtures
697 ICUDataPath:[fixtures stringByAppendingString:@"/icudtl.dat"]];
698 FlutterEngine* engine = [[FlutterEngine alloc] initWithName:@"test"
699 project:project
700 allowHeadlessExecution:YES];
701 NSString* pluginName = @"MyPlugin";
702 // Request the registarar to register the plugin as existing.
703 [engine registrarForPlugin:pluginName];
704
705 // The documented behavior is that a plugin that exists but hasn't published
706 // anything returns NSNull, rather than nil, as on iOS.
707 EXPECT_EQ([engine valuePublishedByPlugin:pluginName], [NSNull null]);
708 }

## ◆ TEST_F() [48/77]

flutter::testing::TEST_F | ( | FlutterEngineTest | ,
|  | PublishedValueReturnsLastPublished |
| ) |  |

Definition at line 710 of file FlutterEngineTest.mm.

710 {
711 NSString* fixtures = @(flutter::testing::GetFixturesPath());
712 FlutterDartProject* project = [[FlutterDartProject alloc]
713 initWithAssetsPath:fixtures
714 ICUDataPath:[fixtures stringByAppendingString:@"/icudtl.dat"]];
715 FlutterEngine* engine = [[FlutterEngine alloc] initWithName:@"test"
716 project:project
717 allowHeadlessExecution:YES];
718 NSString* pluginName = @"MyPlugin";
719 id<FlutterPluginRegistrar> registrar = [engine registrarForPlugin:pluginName];
720
721 NSString* firstValue = @"A published value";
722 NSArray* secondValue = @[ @"A different published value" ];
723
724 [registrar publish:firstValue];
725 EXPECT_EQ([engine valuePublishedByPlugin:pluginName], firstValue);
726
727 [registrar publish:secondValue];
728 EXPECT_EQ([engine valuePublishedByPlugin:pluginName], secondValue);
729 }

## ◆ TEST_F() [49/77]

flutter::testing::TEST_F | ( | FlutterEngineTest | ,
|  | RemovingViewDisposesCompositorResources |
| ) |  |

Definition at line 974 of file FlutterEngineTest.mm.

974 {
975 NSString* fixtures = @(flutter::testing::GetFixturesPath());
976 FlutterDartProject* project = [[FlutterDartProject alloc]
977 initWithAssetsPath:fixtures
978 ICUDataPath:[fixtures stringByAppendingString:@"/icudtl.dat"]];
979 FlutterEngine* engine = [[FlutterEngine alloc] initWithName:@"test" project:project];
980
981 FlutterViewController* viewController = [[FlutterViewController alloc] initWithEngine:engine
982 nibName:nil
983 bundle:nil];
984 [viewController loadView];
985 [viewController viewDidLoad];
986 viewController.flutterView.frame = CGRectMake(0, 0, 800, 600);
987
988 EXPECT_TRUE([engine runWithEntrypoint:@"drawIntoAllViews"]);
989 // Wait up to 1 second for Flutter to emit a frame.
990 CFTimeInterval start = CACurrentMediaTime();
991 while (engine.macOSCompositor->DebugNumViews() == 0) {
992 CFRunLoopRunInMode(kCFRunLoopDefaultMode, 1, YES);
993 if (CACurrentMediaTime() - start > 1) {
994 break;
995 }
996 }
997
998 EXPECT_EQ(engine.macOSCompositor->DebugNumViews(), 1u);
999
1000 engine.viewController = nil;
1001 EXPECT_EQ(engine.macOSCompositor->DebugNumViews(), 0u);
1002
1003 [engine shutDownEngine];
1004 engine = nil;
1005 }

References FlutterEngine::shutDownEngine, and FlutterEngine::viewController.

## ◆ TEST_F() [50/77]

flutter::testing::TEST_F | ( | FlutterEngineTest | ,
|  | ReportsHourFormat |
| ) |  |

Definition at line 1310 of file FlutterEngineTest.mm.

1310 {
1311 __block BOOL expectedValue;
1312
1313 // Set up mocks.
1314 id channelMock = OCMClassMock([FlutterBasicMessageChannel class]);
1315 OCMStub([channelMock messageChannelWithName:@"flutter/settings"
1316 binaryMessenger:[OCMArg any]
1317 codec:[OCMArg any]])
1318 .andReturn(channelMock);
1319 OCMStub([channelMock sendMessage:[OCMArg any]]).andDo((^(NSInvocation* invocation) {
1320 __weak id message;
1321 [invocation getArgument:&message atIndex:2];
1322 EXPECT_EQ(message[@"alwaysUse24HourFormat"], @(expectedValue));
1323 }));
1324
1325 id mockHourFormat = OCMClassMock([FlutterHourFormat class]);
1326 OCMStub([mockHourFormat isAlwaysUse24HourFormat]).andDo((^(NSInvocation* invocation) {
1327 [invocation setReturnValue:&expectedValue];
1328 }));
1329
1330 id engineMock = CreateMockFlutterEngine(nil);
1331
1332 // Verify the YES case.
1333 expectedValue = YES;
1334 EXPECT_TRUE([engineMock runWithEntrypoint:@"main"]);
1335 [engineMock shutDownEngine];
1336
1337 // Verify the NO case.
1338 expectedValue = NO;
1339 EXPECT_TRUE([engineMock runWithEntrypoint:@"main"]);
1340 [engineMock shutDownEngine];
1341
1342 // Clean up mocks.
1343 [mockHourFormat stopMocking];
1344 [engineMock stopMocking];
1345 [channelMock stopMocking];
1346 }
FlutterBasicMessageChannel
Definition: FlutterChannels.h:38
FlutterHourFormat
Definition: FlutterHourFormat.h:11

References CreateMockFlutterEngine().

## ◆ TEST_F() [51/77]

flutter::testing::TEST_F | ( | FlutterEngineTest | ,
|  | ResizeSynchronizerNotBlockingRasterThreadAfterShutdown |
| ) |  |

Definition at line 897 of file FlutterEngineTest.mm.

897 {
898 FlutterResizeSynchronizer* threadSynchronizer = [[FlutterResizeSynchronizer alloc] init];
899 [threadSynchronizer shutDown];
900
901 std::thread rasterThread([&threadSynchronizer] {
902 [threadSynchronizer performCommitForSize:CGSizeMake(100, 100)
903 notify:^{
904 }
905 delay:0];
906 });
907
908 rasterThread.join();
909 }
FlutterResizeSynchronizer
Definition: FlutterResizeSynchronizer.h:17
-[FlutterResizeSynchronizer shutDown]
void shutDown()
Definition: FlutterResizeSynchronizer.mm:55
-[FlutterResizeSynchronizer performCommitForSize:notify:delay:]
void performCommitForSize:notify:delay:(CGSize size,[notify] nonnull dispatch_block_t notify,[delay] NSTimeInterval delay)
Definition: FlutterResizeSynchronizer.mm:40

References FlutterResizeSynchronizer::performCommitForSize:notify:delay:, and FlutterResizeSynchronizer::shutDown.

## ◆ TEST_F() [52/77]

flutter::testing::TEST_F | ( | FlutterEngineTest | ,
|  | ResponseAfterEngineDied |
| ) |  |

Definition at line 830 of file FlutterEngineTest.mm.

830 {
831 FlutterEngine* engine = GetFlutterEngine();
832 FlutterBasicMessageChannel* channel = [[FlutterBasicMessageChannel alloc]
833 initWithName:@"foo"
834 binaryMessenger:engine.binaryMessenger
835 codec:[FlutterStandardMessageCodec sharedInstance]];
836 __block BOOL didCallCallback = NO;
837 [channel setMessageHandler:^(id message, FlutterReply callback) {
838 ShutDownEngine();
839 callback(nil);
840 didCallCallback = YES;
841 }];
842 EXPECT_TRUE([engine runWithEntrypoint:@"sendFooMessage"]);
843 engine = nil;
844
845 while (!didCallCallback) {
846 [[NSRunLoop currentRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:0.1]];
847 }
848 }
-[FlutterBasicMessageChannel setMessageHandler:]
void setMessageHandler:(FlutterMessageHandler _Nullable handler)
FlutterStandardMessageCodec
Definition: FlutterCodecs.h:209
+[FlutterMessageCodec-p sharedInstance]
instancetype sharedInstance()

References FlutterBasicMessageChannel::setMessageHandler:, and <FlutterMessageCodec>::sharedInstance.

## ◆ TEST_F() [53/77]

flutter::testing::TEST_F | ( | FlutterEngineTest | ,
|  | ResponseFromBackgroundThread |
| ) |  |

Definition at line 850 of file FlutterEngineTest.mm.

850 {
851 FlutterEngine* engine = GetFlutterEngine();
852 FlutterBasicMessageChannel* channel = [[FlutterBasicMessageChannel alloc]
853 initWithName:@"foo"
854 binaryMessenger:engine.binaryMessenger
855 codec:[FlutterStandardMessageCodec sharedInstance]];
856 __block BOOL didCallCallback = NO;
857 [channel setMessageHandler:^(id message, FlutterReply callback) {
858 dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
859 callback(nil);
860 dispatch_async(dispatch_get_main_queue(), ^{
861 didCallCallback = YES;
862 });
863 });
864 }];
865 EXPECT_TRUE([engine runWithEntrypoint:@"sendFooMessage"]);
866
867 while (!didCallCallback) {
868 [[NSRunLoop currentRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:0.1]];
869 }
870 }

References FlutterBasicMessageChannel::setMessageHandler:, and <FlutterMessageCodec>::sharedInstance.

## ◆ TEST_F() [54/77]

flutter::testing::TEST_F | ( | FlutterEngineTest | ,
|  | RunWithEntrypointUpdatesDisplayConfig |
| ) |  |

Definition at line 1231 of file FlutterEngineTest.mm.

1231 {
1232 BOOL updated = NO;
1233 FlutterEngine* engine = GetFlutterEngine();
1234 auto original_update_displays = engine.embedderAPI.NotifyDisplayUpdate;
1235 engine.embedderAPI.NotifyDisplayUpdate = MOCK_ENGINE_PROC(
1236 NotifyDisplayUpdate, ([&updated, &original_update_displays](
1237 auto engine, auto update_type, auto* displays, auto display_count) {
1238 updated = YES;
1239 return original_update_displays(engine, update_type, displays, display_count);
1240 }));
1241
1242 EXPECT_TRUE([engine runWithEntrypoint:@"main"]);
1243 EXPECT_TRUE(updated);
1244
1245 updated = NO;
1246 [[NSNotificationCenter defaultCenter]
1247 postNotificationName:NSApplicationDidChangeScreenParametersNotification
1248 object:nil];
1249 EXPECT_TRUE(updated);
1250 }

## ◆ TEST_F() [55/77]

flutter::testing::TEST_F | ( | FlutterEngineTest | ,
|  | Switches |
| ) |  |

Definition at line 168 of file FlutterEngineTest.mm.

168 {
169 setenv("FLUTTER_ENGINE_SWITCHES", "2", 1);
170 setenv("FLUTTER_ENGINE_SWITCH_1", "abc", 1);
171 setenv("FLUTTER_ENGINE_SWITCH_2", "foo=\"bar, baz\"", 1);
172
173 FlutterEngine* engine = GetFlutterEngine();
174 std::vector<std::string> switches = engine.switches;
175 ASSERT_EQ(switches.size(), 2UL);
176 EXPECT_EQ(switches[0], "--abc");
177 EXPECT_EQ(switches[1], "--foo=\"bar, baz\"");
178
179 unsetenv("FLUTTER_ENGINE_SWITCHES");
180 unsetenv("FLUTTER_ENGINE_SWITCH_1");
181 unsetenv("FLUTTER_ENGINE_SWITCH_2");
182 }

## ◆ TEST_F() [56/77]

flutter::testing::TEST_F | ( | FlutterEngineTest | ,
|  | UnregistersPluginsOnEngineDestruction |
| ) |  |

Definition at line 1210 of file FlutterEngineTest.mm.

1210 {
1211 id<NSApplicationDelegate> previousDelegate = [[NSApplication sharedApplication] delegate];
1212 FakeLifecycleProvider* fakeAppDelegate = [[FakeLifecycleProvider alloc] init];
1213 [NSApplication sharedApplication].delegate = fakeAppDelegate;
1214
1215 FakeAppDelegatePlugin* plugin = [[FakeAppDelegatePlugin alloc] init];
1216
1217 @autoreleasepool {
1218 FlutterEngine* engine = [[FlutterEngine alloc] initWithName:@"test" project:nil];
1219
1220 [[engine registrarForPlugin:@"TestPlugin"] addApplicationDelegate:plugin];
1221 EXPECT_TRUE([fakeAppDelegate hasDelegate:plugin]);
1222 }
1223
1224 // When the engine is released, it should unregister any plugins it had
1225 // registered on its behalf.
1226 EXPECT_FALSE([fakeAppDelegate hasDelegate:plugin]);
1227
1228 [NSApplication sharedApplication].delegate = previousDelegate;
1229 }

## ◆ TEST_F() [57/77]

flutter::testing::TEST_F | ( | FlutterMenuPluginTest | ,
|  | TestSetMenu |
| ) |  |

Definition at line 86 of file FlutterMenuPluginTest.mm.

86 {
87 // Build a simulation of the default main menu.
88 NSMenu* mainMenu = [[NSMenu alloc] init];
89 NSMenuItem* appNameMenu = [[NSMenuItem alloc] initWithTitle:NSLocalizedString(@"APP_NAME", nil)
90 action:nil
91 keyEquivalent:@""];
92 NSMenu* submenu =
93 [[NSMenu alloc] initWithTitle:NSLocalizedString(@"Prexisting APP_NAME menu", nil)];
94 [submenu addItem:[[NSMenuItem alloc] initWithTitle:NSLocalizedString(@"About APP_NAME", nil)
95 action:nil
96 keyEquivalent:@""]];
97 appNameMenu.submenu = submenu;
98 [mainMenu addItem:appNameMenu];
99 [NSApp setMainMenu:mainMenu];
100
101 FakePluginRegistrar* registrar = [[FakePluginRegistrar alloc] init];
102 [FlutterMenuPlugin registerWithRegistrar:registrar];
103 FlutterMenuPlugin* plugin = [registrar plugin];
104
105 NSDictionary* testMenus = @{
106 @"0" : @[
107 @{
108 @"id" : [NSNumber numberWithInt:1],
109 @"label" : @"APP_NAME",
110 @"enabled" : @(YES),
111 @"children" : @[
112 @{
113 @"id" : [NSNumber numberWithInt:3],
114 @"platformProvidedMenu" : @(static_cast<int>(flutter::PlatformProvidedMenu::kQuit)),
115 @"enabled" : @(YES),
116 },
117 @{
118 @"id" : [NSNumber numberWithInt:2],
119 @"label" : @"APP_NAME Info",
120 @"enabled" : @(YES),
121 @"shortcutTrigger" : [NSNumber numberWithUnsignedLongLong:0x61],
122 @"shortcutModifiers" : [NSNumber numberWithUnsignedInt:0],
123 },
124 ],
125 },
126 @{
127 @"id" : [NSNumber numberWithInt:4],
128 @"label" : @"Help for APP_NAME",
129 @"enabled" : @(YES),
130 @"children" : @[
131 @{
132 @"id" : [NSNumber numberWithInt:5],
133 @"label" : @"Help me!",
134 @"enabled" : @(YES),
135 },
136 @{
137 @"id" : [NSNumber numberWithInt:6],
138 @"label" : @"",
139 @"enabled" : @(NO),
140 @"isDivider" : @(YES),
141 },
142 @{
143 @"id" : [NSNumber numberWithInt:7],
144 @"label" : @"Search help",
145 @"enabled" : @(NO),
146 },
147 ],
148 },
149 ],
150 };
151
152 __block id available = @NO;
153 [plugin handleMethodCall:[FlutterMethodCall methodCallWithMethodName:@"Menu.isPluginAvailable"
154 arguments:nil]
155 result:^(id _Nullable result) {
156 available = result;
157 }];
158
159 EXPECT_TRUE(available);
160
161 [plugin handleMethodCall:[FlutterMethodCall methodCallWithMethodName:@"Menu.setMenus"
162 arguments:testMenus]
163 result:^(id _Nullable result){
164 }];
165
166 EXPECT_EQ([NSApp.mainMenu numberOfItems], 2);
167 NSMenuItem* firstMenu = [NSApp.mainMenu itemAtIndex:0];
168 EXPECT_TRUE([[firstMenu title] isEqualToString:@"flutter_desktop_darwin_unittests"]);
169 EXPECT_EQ([firstMenu tag], 1);
170 EXPECT_TRUE([firstMenu isEnabled]);
171 EXPECT_FALSE([firstMenu isHidden]);
172 EXPECT_TRUE([[firstMenu keyEquivalent] isEqualToString:@"\0"]);
173
174 EXPECT_EQ([[firstMenu submenu] numberOfItems], 1);
175 NSMenuItem* firstItem = [[firstMenu submenu] itemAtIndex:0];
176 EXPECT_TRUE([[firstItem title] isEqualToString:@"flutter_desktop_darwin_unittests Info"]);
177 EXPECT_TRUE([[firstItem keyEquivalent] isEqualToString:@"a"]);
178 EXPECT_TRUE([firstItem isEnabled]);
179 EXPECT_FALSE([firstItem isHidden]);
180 EXPECT_TRUE(
181 [NSStringFromSelector([firstItem action]) isEqualToString:@"flutterMenuItemSelected:"]);
182 EXPECT_EQ([firstItem tag], 2);
183
184 NSMenuItem* secondMenu = [NSApp.mainMenu itemAtIndex:1];
185 EXPECT_TRUE([[secondMenu title] isEqualToString:@"Help for flutter_desktop_darwin_unittests"]);
186 EXPECT_EQ([secondMenu tag], 4);
187 EXPECT_TRUE([secondMenu isEnabled]);
188 EXPECT_FALSE([secondMenu isHidden]);
189
190 EXPECT_EQ([[secondMenu submenu] numberOfItems], 3);
191 NSMenuItem* secondMenuFirst = [[secondMenu submenu] itemAtIndex:0];
192 EXPECT_TRUE([[secondMenuFirst title] isEqualToString:@"Help me!"]);
193 EXPECT_TRUE([secondMenuFirst isEnabled]);
194 EXPECT_FALSE([secondMenuFirst isHidden]);
195 EXPECT_TRUE(
196 [NSStringFromSelector([secondMenuFirst action]) isEqualToString:@"flutterMenuItemSelected:"]);
197 EXPECT_EQ([secondMenuFirst tag], 5);
198
199 NSMenuItem* secondMenuDivider = [[secondMenu submenu] itemAtIndex:1];
200 EXPECT_TRUE([[secondMenuDivider title] isEqualToString:@""]);
201 EXPECT_TRUE([[secondMenuDivider keyEquivalent] isEqualToString:@""]);
202 EXPECT_FALSE([secondMenuDivider isEnabled]);
203 EXPECT_FALSE([secondMenuDivider isHidden]);
204 EXPECT_EQ([secondMenuDivider action], nil);
205 EXPECT_EQ([secondMenuDivider tag], 0);
206
207 NSMenuItem* secondMenuLast = [[secondMenu submenu] itemAtIndex:2];
208 EXPECT_TRUE([[secondMenuLast title] isEqualToString:@"Search help"]);
209 EXPECT_FALSE([secondMenuLast isEnabled]);
210 EXPECT_FALSE([secondMenuLast isHidden]);
211 EXPECT_TRUE(
212 [NSStringFromSelector([secondMenuLast action]) isEqualToString:@"flutterMenuItemSelected:"]);
213 EXPECT_EQ([secondMenuLast tag], 7);
214 }
FakePluginRegistrar
Definition: FlutterMenuPluginTest.mm:22
FakePluginRegistrar::plugin
id< FlutterPlugin > plugin
Definition: FlutterMenuPluginTest.mm:23
-[FlutterPlugin-p handleMethodCall:result:]
void handleMethodCall:result:(FlutterMethodCall *call,[result] FlutterResult result)

References <FlutterPlugin>::handleMethodCall:result:, FlutterMethodCall::methodCallWithMethodName:arguments:, FakePluginRegistrar::plugin, and FlutterMenuPlugin::registerWithRegistrar:.

## ◆ TEST_F() [58/77]

flutter::testing::TEST_F | ( | FlutterViewControllerMockEngineTest | ,
|  | TestCtrlTabKeyEventIsPropagated |
| ) |  |

Definition at line 278 of file FlutterViewControllerTest.mm.

278 {
279 id mockEngine = GetMockEngine();
280 ASSERT_TRUE([[FlutterViewControllerTestObjC alloc] testCtrlTabKeyEventIsPropagated:mockEngine]);
281 }
FlutterViewControllerTestObjC
Definition: FlutterViewControllerTest.mm:101

## ◆ TEST_F() [59/77]

flutter::testing::TEST_F | ( | FlutterViewControllerMockEngineTest | ,
|  | TestFlagsChangedEventsArePropagatedIfNotHandled |
| ) |  |

Definition at line 289 of file FlutterViewControllerTest.mm.

289 {
290 id mockEngine = GetMockEngine();
291 ASSERT_TRUE([[FlutterViewControllerTestObjC alloc]
292 testFlagsChangedEventsArePropagatedIfNotHandled:mockEngine]);
293 }

## ◆ TEST_F() [60/77]

flutter::testing::TEST_F | ( | FlutterViewControllerMockEngineTest | ,
|  | testFlutterViewIsConfigured |
| ) |  |

Definition at line 331 of file FlutterViewControllerTest.mm.

331 {
332 id mockEngine = GetMockEngine();
333 ASSERT_TRUE([[FlutterViewControllerTestObjC alloc] testFlutterViewIsConfigured:mockEngine]);
334 }

## ◆ TEST_F() [61/77]

flutter::testing::TEST_F | ( | FlutterViewControllerMockEngineTest | ,
|  | TestKeyboardIsRestartedOnEngineRestart |
| ) |  |

Definition at line 295 of file FlutterViewControllerTest.mm.

295 {
296 id mockEngine = GetMockEngine();
297 ASSERT_TRUE(
298 [[FlutterViewControllerTestObjC alloc] testKeyboardIsRestartedOnEngineRestart:mockEngine]);
299 }

## ◆ TEST_F() [62/77]

flutter::testing::TEST_F | ( | FlutterViewControllerMockEngineTest | ,
|  | TestKeyEquivalentIsPassedToTextInputPlugin |
| ) |  |

Definition at line 283 of file FlutterViewControllerTest.mm.

283 {
284 id mockEngine = GetMockEngine();
285 ASSERT_TRUE([[FlutterViewControllerTestObjC alloc]
286 testKeyEquivalentIsPassedToTextInputPlugin:mockEngine]);
287 }

## ◆ TEST_F() [63/77]

flutter::testing::TEST_F | ( | FlutterViewControllerMockEngineTest | ,
|  | TestKeyEventsAreNotPropagatedIfHandled |
| ) |  |

Definition at line 272 of file FlutterViewControllerTest.mm.

272 {
273 id mockEngine = GetMockEngine();
274 ASSERT_TRUE(
275 [[FlutterViewControllerTestObjC alloc] testKeyEventsAreNotPropagatedIfHandled:mockEngine]);
276 }

## ◆ TEST_F() [64/77]

flutter::testing::TEST_F | ( | FlutterViewControllerMockEngineTest | ,
|  | TestKeyEventsArePropagatedIfNotHandled |
| ) |  |

Definition at line 266 of file FlutterViewControllerTest.mm.

266 {
267 id mockEngine = GetMockEngine();
268 ASSERT_TRUE(
269 [[FlutterViewControllerTestObjC alloc] testKeyEventsArePropagatedIfNotHandled:mockEngine]);
270 }

## ◆ TEST_F() [65/77]

flutter::testing::TEST_F | ( | FlutterViewControllerMockEngineTest | ,
|  | TestKeyEventsAreSentToFramework |
| ) |  |

Definition at line 261 of file FlutterViewControllerTest.mm.

261 {
262 id mockEngine = GetMockEngine();
263 ASSERT_TRUE([[FlutterViewControllerTestObjC alloc] testKeyEventsAreSentToFramework:mockEngine]);
264 }

## ◆ TEST_F() [66/77]

flutter::testing::TEST_F | ( | FlutterViewControllerMockEngineTest | ,
|  | TestModifierKeysAreSynthesizedOnMouseMove |
| ) |  |

Definition at line 319 of file FlutterViewControllerTest.mm.

319 {
320 id mockEngine = GetMockEngine();
321 ASSERT_TRUE(
322 [[FlutterViewControllerTestObjC alloc] testModifierKeysAreSynthesizedOnMouseMove:mockEngine]);
323 }

## ◆ TEST_F() [67/77]

flutter::testing::TEST_F | ( | FlutterViewControllerMockEngineTest | ,
|  | TestmouseAndGestureEventsAreHandledSeparately |
| ) |  |

Definition at line 307 of file FlutterViewControllerTest.mm.

307 {
308 id mockEngine = GetMockEngine();
309 ASSERT_TRUE(
310 [[FlutterViewControllerTestObjC alloc] mouseAndGestureEventsAreHandledSeparately:mockEngine]);
311 }

## ◆ TEST_F() [68/77]

flutter::testing::TEST_F | ( | FlutterViewControllerMockEngineTest | ,
|  | TestMouseDownUpEventsSentToNextResponder |
| ) |  |

Definition at line 313 of file FlutterViewControllerTest.mm.

313 {
314 id mockEngine = GetMockEngine();
315 ASSERT_TRUE(
316 [[FlutterViewControllerTestObjC alloc] testMouseDownUpEventsSentToNextResponder:mockEngine]);
317 }

## ◆ TEST_F() [69/77]

flutter::testing::TEST_F | ( | FlutterViewControllerMockEngineTest | ,
|  | TestTrackpadGesturesAreSentToFramework |
| ) |  |

Definition at line 301 of file FlutterViewControllerTest.mm.

301 {
302 id mockEngine = GetMockEngine();
303 ASSERT_TRUE(
304 [[FlutterViewControllerTestObjC alloc] testTrackpadGesturesAreSentToFramework:mockEngine]);
305 }

## ◆ TEST_F() [70/77]

flutter::testing::TEST_F | ( | FlutterViewControllerMockEngineTest | ,
|  | testViewWillAppearCalledMultipleTimes |
| ) |  |

Definition at line 325 of file FlutterViewControllerTest.mm.

325 {
326 id mockEngine = GetMockEngine();
327 ASSERT_TRUE(
328 [[FlutterViewControllerTestObjC alloc] testViewWillAppearCalledMultipleTimes:mockEngine]);
329 }

## ◆ TEST_F() [71/77]

flutter::testing::TEST_F | ( | FlutterViewControllerTest | ,
|  | CanSetMouseTrackingModeBeforeViewLoaded |
| ) |  |

Definition at line 251 of file FlutterViewControllerTest.mm.

251 {
252 NSString* fixtures = @(testing::GetFixturesPath());
253 FlutterDartProject* project = [[FlutterDartProject alloc]
254 initWithAssetsPath:fixtures
255 ICUDataPath:[fixtures stringByAppendingString:@"/icudtl.dat"]];
256 FlutterViewController* viewController = [[FlutterViewController alloc] initWithProject:project];
257 viewController.mouseTrackingMode = kFlutterMouseTrackingModeInActiveApp;
258 ASSERT_EQ(viewController.mouseTrackingMode, kFlutterMouseTrackingModeInActiveApp);
259 }
FlutterViewController::mouseTrackingMode
FlutterMouseTrackingMode mouseTrackingMode
Definition: FlutterViewController.h:84

References FlutterViewController::mouseTrackingMode.

## ◆ TEST_F() [72/77]

flutter::testing::TEST_F | ( | FlutterViewControllerTest | ,
|  | FlutterViewAcceptsFirstMouse |
| ) |  |

Definition at line 208 of file FlutterViewControllerTest.mm.

208 {
209 FlutterViewController* viewControllerMock = CreateMockViewController();
210 [viewControllerMock loadView];
211 EXPECT_EQ([viewControllerMock.flutterView acceptsFirstMouse:nil], YES);
212 }
flutter::testing::CreateMockViewController
id CreateMockViewController()
Definition: FlutterViewControllerTestUtils.mm:9

References CreateMockViewController().

## ◆ TEST_F() [73/77]

flutter::testing::TEST_F | ( | FlutterViewControllerTest | ,
|  | HasViewThatHidesOtherViewsInAccessibility |
| ) |  |

Definition at line 187 of file FlutterViewControllerTest.mm.

187 {
188 FlutterViewController* viewControllerMock = CreateMockViewController();
189
190 [viewControllerMock loadView];
191 auto subViews = [viewControllerMock.view subviews];
192
193 EXPECT_EQ([subViews count], 1u);
194 EXPECT_EQ(subViews[0], viewControllerMock.flutterView);
195
196 NSTextField* textField = [[NSTextField alloc] initWithFrame:NSMakeRect(0, 0, 1, 1)];
197 [viewControllerMock.view addSubview:textField];
198
199 subViews = [viewControllerMock.view subviews];
200 EXPECT_EQ([subViews count], 2u);
201
202 auto accessibilityChildren = viewControllerMock.view.accessibilityChildren;
203 // The accessibilityChildren should only contains the FlutterView.
204 EXPECT_EQ([accessibilityChildren count], 1u);
205 EXPECT_EQ(accessibilityChildren[0], viewControllerMock.flutterView);
206 }

References CreateMockViewController().

## ◆ TEST_F() [74/77]

flutter::testing::TEST_F | ( | FlutterViewControllerTest | ,
|  | ReparentsPluginWhenAccessibilityDisabled |
| ) |  |

Definition at line 214 of file FlutterViewControllerTest.mm.

214 {
215 FlutterEngine* engine = CreateTestEngine();
216 FlutterViewController* viewController = [[FlutterViewController alloc] initWithEngine:engine
217 nibName:nil
218 bundle:nil];
219 [viewController loadView];
220 // Creates a NSWindow so that sub view can be first responder.
221 NSWindow* window = [[NSWindow alloc] initWithContentRect:NSMakeRect(0, 0, 800, 600)
222 styleMask:NSBorderlessWindowMask
223 backing:NSBackingStoreBuffered
224 defer:NO];
225 window.contentView = viewController.view;
226 NSView* dummyView = [[NSView alloc] initWithFrame:CGRectZero];
227 [viewController.view addSubview:dummyView];
228
229 NSDictionary* setClientConfig = @{
230 @"viewId" : @(flutter::kFlutterImplicitViewId),
231 };
232 FlutterMethodCall* methodCall =
233 [FlutterMethodCall methodCallWithMethodName:@"TextInput.setClient"
234 arguments:@[ @(1), setClientConfig ]];
235 FlutterResult result = ^(id result) {
236 };
237 [engine.textInputPlugin handleMethodCall:methodCall result:result];
238
239 // Attaches FlutterTextInputPlugin to the view;
240 [dummyView addSubview:engine.textInputPlugin];
241 // Makes sure the textInputPlugin can be the first responder.
242
243 EXPECT_TRUE([window makeFirstResponder:engine.textInputPlugin]);
244 EXPECT_EQ([window firstResponder], engine.textInputPlugin);
245 EXPECT_FALSE(engine.textInputPlugin.superview == viewController.view);
246 [viewController onAccessibilityStatusChanged:NO];
247 // FlutterView becomes child of view controller
248 EXPECT_TRUE(viewController.engine.textInputPlugin.superview == viewController.view);
249 }
-[FlutterViewController onAccessibilityStatusChanged:]
void onAccessibilityStatusChanged:(BOOL enabled)

References FlutterViewController::engine, FlutterMethodCall::methodCallWithMethodName:arguments:, and FlutterViewController::onAccessibilityStatusChanged:.

## ◆ TEST_F() [75/77]

flutter::testing::TEST_F | ( | FlutterViewControllerTest | ,
|  | testLookupKeyAssets |
| ) |  |

Definition at line 336 of file FlutterViewControllerTest.mm.

336 {
337 ASSERT_TRUE([[FlutterViewControllerTestObjC alloc] testLookupKeyAssets]);
338 }

## ◆ TEST_F() [76/77]

flutter::testing::TEST_F | ( | FlutterViewControllerTest | ,
|  | testLookupKeyAssetsWithPackage |
| ) |  |

Definition at line 340 of file FlutterViewControllerTest.mm.

340 {
341 ASSERT_TRUE([[FlutterViewControllerTestObjC alloc] testLookupKeyAssetsWithPackage]);
342 }

## ◆ TEST_F() [77/77]

flutter::testing::TEST_F | ( | FlutterViewControllerTest | ,
|  | testViewControllerIsReleased |
| ) |  |

Definition at line 344 of file FlutterViewControllerTest.mm.

344 {
345 ASSERT_TRUE([[FlutterViewControllerTestObjC alloc] testViewControllerIsReleased]);
346 }