| Flutter macOS Embedder |

Classes | Typedefs | Functions | Variables
flutter::testing Namespace Reference

## Classes
class | FlutterEngineTest
class | MockFlutterEngineTest
class | FlutterMenuPluginTest
class | FlutterWindowControllerTest
class | FlutterWindowControllerRetainTest

## 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, RegistrarForwardViewControllerLookUpToEngine)
| 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 (FlutterTextInputPluginTest, WorksWithoutViewId)
| TEST (FlutterTextInputPluginTest, InsertTextWithCollapsedSelectionInsideComposing)
| TEST (FlutterTextInputPluginTest, InsertTextHandlesNSAttributedString)
| TEST (FlutterTextInputPluginTest, InsertTextHandlesEmptyAttributedString)
| 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_F (FlutterWindowControllerTest, CreateRegularWindow)
| TEST_F (FlutterWindowControllerRetainTest, WindowControllerDoesNotRetainEngine)
| TEST_F (FlutterWindowControllerTest, DestroyRegularWindow)
| TEST_F (FlutterWindowControllerTest, InternalFlutter_Window_GetHandle)
| TEST_F (FlutterWindowControllerTest, WindowStates)
| 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)

## Variables
FlutterSemanticsFlags | kEmptyFlags = FlutterSemanticsFlags{}

## 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 20 of file accessibility_bridge_unittests.cc.

23 {
24 return {
25 .id = id,
26 // NOLINTNEXTLINE(clang-analyzer-optin.core.EnumCastOutOfRange)
27 .flags__deprecated__ = static_cast<FlutterSemanticsFlag>(0),
28 // NOLINTNEXTLINE(clang-analyzer-optin.core.EnumCastOutOfRange)
29 .actions = static_cast<FlutterSemanticsAction>(0),
30 .text_selection_base = -1,
31 .text_selection_extent = -1,
32 .label = label,
33 .hint = "",
34 .value = "",
35 .increased_value = "",
36 .decreased_value = "",
37 .child_count = children ? children->size() : 0,
38 .children_in_traversal_order = children ? children->data() : nullptr,
39 .custom_accessibility_actions_count = 0,
40 .tooltip = "",
41 .flags2 = &kEmptyFlags,
42 };
43 }
flutter::testing::kEmptyFlags
FlutterSemanticsFlags kEmptyFlags
Definition: accessibility_bridge_unittests.cc:18

References kEmptyFlags.

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/122]

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

Definition at line 77 of file accessibility_bridge_unittests.cc.

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

References CreateSemanticsNode().

## ◆ TEST() [2/122]

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

Definition at line 114 of file accessibility_bridge_unittests.cc.

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

References CreateSemanticsNode().

## ◆ TEST() [3/122]

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

Definition at line 564 of file accessibility_bridge_unittests.cc.

564 {
565 std::shared_ptr<TestAccessibilityBridge> bridge =
566 std::make_shared<TestAccessibilityBridge>();
567
568 ui::AXTreeID tree_id = bridge->GetTreeID();
569 ui::AXTreeManager* manager =
570 ui::AXTreeManagerMap::GetInstance().GetManager(tree_id);
571 ASSERT_EQ(manager, static_cast<ui::AXTreeManager*>(bridge.get()));
572 }

## ◆ TEST() [4/122]

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

Definition at line 45 of file accessibility_bridge_unittests.cc.

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

References CreateSemanticsNode().

## ◆ TEST() [5/122]

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

Definition at line 165 of file accessibility_bridge_unittests.cc.

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

References CreateSemanticsNode().

## ◆ TEST() [6/122]

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

Definition at line 213 of file accessibility_bridge_unittests.cc.

213 {
214 std::shared_ptr<TestAccessibilityBridge> bridge =
215 std::make_shared<TestAccessibilityBridge>();
216 FlutterSemanticsNode2 root = CreateSemanticsNode(0, "root");
217 auto flags = FlutterSemanticsFlags{
218 .is_focused = FlutterTristate::kFlutterTristateTrue,
219 .is_text_field = true,
220 };
221 root.flags2 = &flags;
222
223 bridge->AddFlutterSemanticsNodeUpdate(root);
224 bridge->CommitUpdates();
225
226 const ui::AXTreeData& tree = bridge->GetAXTreeData();
227 EXPECT_EQ(tree.sel_anchor_object_id, ui::AXNode::kInvalidAXID);
228 bridge->accessibility_events.clear();
229
230 // Update the selection.
231 root.text_selection_base = 0;
232 root.text_selection_extent = 5;
233 bridge->AddFlutterSemanticsNodeUpdate(root);
234
235 bridge->CommitUpdates();
236
237 EXPECT_EQ(tree.sel_anchor_object_id, 0);
238 EXPECT_EQ(tree.sel_anchor_offset, 0);
239 EXPECT_EQ(tree.sel_focus_object_id, 0);
240 EXPECT_EQ(tree.sel_focus_offset, 5);
241 ASSERT_EQ(bridge->accessibility_events.size(), size_t{2});
242 EXPECT_EQ(bridge->accessibility_events[0],
243 ui::AXEventGenerator::Event::DOCUMENT_SELECTION_CHANGED);
244 EXPECT_EQ(bridge->accessibility_events[1],
245 ui::AXEventGenerator::Event::OTHER_ATTRIBUTE_CHANGED);
246 }

References CreateSemanticsNode().

## ◆ TEST() [7/122]

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

Definition at line 390 of file accessibility_bridge_unittests.cc.

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

References CreateSemanticsNode().

## ◆ TEST() [8/122]

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

Definition at line 327 of file accessibility_bridge_unittests.cc.

327 {
328 std::shared_ptr<TestAccessibilityBridge> bridge =
329 std::make_shared<TestAccessibilityBridge>();
330
331 std::vector<int32_t> root_children{1};
332 std::vector<int32_t> child1_children{2};
333 FlutterSemanticsNode2 root = CreateSemanticsNode(0, "root", &root_children);
334 FlutterSemanticsNode2 child1 =
335 CreateSemanticsNode(1, "child 1", &child1_children);
336 FlutterSemanticsNode2 child2 = CreateSemanticsNode(2, "child 2");
337
338 bridge->AddFlutterSemanticsNodeUpdate(root);
339 bridge->AddFlutterSemanticsNodeUpdate(child1);
340 bridge->AddFlutterSemanticsNodeUpdate(child2);
341 bridge->CommitUpdates();
342 bridge->accessibility_events.clear();
343
344 // Reparent child2 from child1 to the root.
345 child1.child_count = 0;
346 child1.children_in_traversal_order = nullptr;
347
348 int32_t new_root_children[] = {1, 2};
349 root.child_count = 2;
350 root.children_in_traversal_order = new_root_children;
351
352 bridge->AddFlutterSemanticsNodeUpdate(root);
353 bridge->AddFlutterSemanticsNodeUpdate(child1);
354 bridge->AddFlutterSemanticsNodeUpdate(child2);
355 bridge->CommitUpdates();
356
357 auto root_node = bridge->GetFlutterPlatformNodeDelegateFromID(0).lock();
358 auto child1_node = bridge->GetFlutterPlatformNodeDelegateFromID(1).lock();
359 auto child2_node = bridge->GetFlutterPlatformNodeDelegateFromID(2).lock();
360
361 EXPECT_EQ(root_node->GetChildCount(), 2);
362 EXPECT_EQ(root_node->GetData().child_ids[0], 1);
363 EXPECT_EQ(root_node->GetData().child_ids[1], 2);
364 EXPECT_EQ(root_node->GetName(), "root");
365
366 EXPECT_EQ(child1_node->GetChildCount(), 0);
367 EXPECT_EQ(child1_node->GetName(), "child 1");
368
369 EXPECT_EQ(child2_node->GetChildCount(), 0);
370 EXPECT_EQ(child2_node->GetName(), "child 2");
371
372 ASSERT_EQ(bridge->accessibility_events.size(), size_t{5});
373
374 // Child2 is moved from child1 to root.
375 EXPECT_THAT(bridge->accessibility_events,
376 Contains(ui::AXEventGenerator::Event::CHILDREN_CHANGED).Times(2));
377 EXPECT_THAT(bridge->accessibility_events,
378 Contains(ui::AXEventGenerator::Event::SUBTREE_CREATED).Times(1));
379
380 // Child1 is no longer a parent. It loses its group role and disables its
381 // 'clip children' attribute.
382 EXPECT_THAT(
383 bridge->accessibility_events,
384 Contains(ui::AXEventGenerator::Event::OTHER_ATTRIBUTE_CHANGED).Times(1));
385 EXPECT_THAT(bridge->accessibility_events,
386 Contains(ui::AXEventGenerator::Event::ROLE_CHANGED).Times(1));
387 }

References CreateSemanticsNode().

## ◆ TEST() [9/122]

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

Definition at line 484 of file accessibility_bridge_unittests.cc.

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

References CreateSemanticsNode().

## ◆ TEST() [10/122]

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

Definition at line 308 of file accessibility_bridge_unittests.cc.

308 {
309 std::shared_ptr<TestAccessibilityBridge> bridge =
310 std::make_shared<TestAccessibilityBridge>();
311 FlutterSemanticsNode2 root = CreateSemanticsNode(0, "root");
312 auto flags = FlutterSemanticsFlags{
313 .is_checked = FlutterCheckState::kFlutterCheckStateTrue,
314 };
315
316 root.flags2 = &flags;
317 bridge->AddFlutterSemanticsNodeUpdate(root);
318 bridge->CommitUpdates();
319
320 auto root_node = bridge->GetFlutterPlatformNodeDelegateFromID(0).lock();
321 EXPECT_EQ(root_node->GetData().role, ax::mojom::Role::kCheckBox);
322 EXPECT_EQ(root_node->GetData().GetCheckedState(),
323 ax::mojom::CheckedState::kTrue);
324 }

References CreateSemanticsNode().

## ◆ TEST() [11/122]

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

Definition at line 248 of file accessibility_bridge_unittests.cc.

248 {
249 std::shared_ptr<TestAccessibilityBridge> bridge =
250 std::make_shared<TestAccessibilityBridge>();
251 FlutterSemanticsNode2 root = CreateSemanticsNode(0, "root");
252 auto flags = FlutterSemanticsFlags{
253 .is_text_field = true,
254 .is_read_only = true,
255 };
256 root.flags2 = &flags;
257
258 bridge->AddFlutterSemanticsNodeUpdate(root);
259 bridge->CommitUpdates();
260
261 auto root_node = bridge->GetFlutterPlatformNodeDelegateFromID(0).lock();
262
263 EXPECT_FALSE(root_node->GetData().GetBoolAttribute(
264 ax::mojom::BoolAttribute::kEditableRoot));
265 }

References CreateSemanticsNode().

## ◆ TEST() [12/122]

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

Definition at line 574 of file accessibility_bridge_unittests.cc.

574 {
575 std::shared_ptr<TestAccessibilityBridge> bridge =
576 std::make_shared<TestAccessibilityBridge>();
577
578 const int32_t root_id = 0;
579
580 FlutterSemanticsNode2 root = CreateSemanticsNode(root_id, "root", {});
581
582 bridge->AddFlutterSemanticsNodeUpdate(root);
583 bridge->CommitUpdates();
584
585 auto root_node = bridge->GetFlutterPlatformNodeDelegateFromID(root_id).lock();
586 auto root_data = root_node->GetData();
587 EXPECT_TRUE(root_data.HasBoolAttribute(
588 ax::mojom::BoolAttribute::kIsLineBreakingObject));
589 EXPECT_TRUE(root_data.GetBoolAttribute(
590 ax::mojom::BoolAttribute::kIsLineBreakingObject));
591 }

References CreateSemanticsNode().

## ◆ TEST() [13/122]

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

Definition at line 284 of file accessibility_bridge_unittests.cc.

284 {
285 std::shared_ptr<TestAccessibilityBridge> bridge =
286 std::make_shared<TestAccessibilityBridge>();
287 FlutterSemanticsNode2 root = CreateSemanticsNode(0, "root");
288 auto flags = FlutterSemanticsFlags{
289 .is_enabled = FlutterTristate::kFlutterTristateTrue,
290 .is_focused = FlutterTristate::kFlutterTristateFalse,
291 .is_slider = true,
292 };
293
294 root.flags2 = &flags;
295
296 bridge->AddFlutterSemanticsNodeUpdate(root);
297 bridge->CommitUpdates();
298
299 auto root_node = bridge->GetFlutterPlatformNodeDelegateFromID(0).lock();
300 EXPECT_EQ(root_node->GetData().role, ax::mojom::Role::kSlider);
301 }

References CreateSemanticsNode().

## ◆ TEST() [14/122]

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

Definition at line 267 of file accessibility_bridge_unittests.cc.

267 {
268 std::shared_ptr<TestAccessibilityBridge> bridge =
269 std::make_shared<TestAccessibilityBridge>();
270 FlutterSemanticsNode2 root = CreateSemanticsNode(0, "root");
271 auto flags = FlutterSemanticsFlags{
272 .is_enabled = FlutterTristate::kFlutterTristateTrue,
273 .is_toggled = FlutterTristate::kFlutterTristateFalse,
274 };
275
276 root.flags2 = &flags;
277 bridge->AddFlutterSemanticsNodeUpdate(root);
278 bridge->CommitUpdates();
279
280 auto root_node = bridge->GetFlutterPlatformNodeDelegateFromID(0).lock();
281 EXPECT_EQ(root_node->GetData().role, ax::mojom::Role::kSwitch);
282 }

References CreateSemanticsNode().

## ◆ TEST() [15/122]

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/122]

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/122]

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/122]

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/122]

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/122]

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/122]

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/122]

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/122]

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/122]

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/122]

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/122]

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/122]

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/122]

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/122]

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/122]

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/122]

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/122]

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/122]

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/122]

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/122]

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/122]

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/122]

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/122]

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/122]

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/122]

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/122]

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/122]

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/122]

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/122]

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/122]

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/122]

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/122]

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

Definition at line 445 of file FlutterKeyboardManagerTest.mm.

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

## ◆ TEST() [48/122]

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

Definition at line 453 of file FlutterKeyboardManagerTest.mm.

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

## ◆ TEST() [49/122]

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

Definition at line 457 of file FlutterKeyboardManagerTest.mm.

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

## ◆ TEST() [50/122]

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

Definition at line 461 of file FlutterKeyboardManagerTest.mm.

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

## ◆ TEST() [51/122]

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

Definition at line 465 of file FlutterKeyboardManagerTest.mm.

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

## ◆ TEST() [52/122]

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

Definition at line 473 of file FlutterKeyboardManagerTest.mm.

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

## ◆ TEST() [53/122]

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

Definition at line 449 of file FlutterKeyboardManagerTest.mm.

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

## ◆ TEST() [54/122]

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

Definition at line 441 of file FlutterKeyboardManagerTest.mm.

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

## ◆ TEST() [55/122]

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 FlutterSemanticsFlags flags = FlutterSemanticsFlags{0};
40 root.id = 0;
41 root.flags2 = &flags;
42 // NOLINTNEXTLINE(clang-analyzer-optin.core.EnumCastOutOfRange)
43 root.actions = static_cast<FlutterSemanticsAction>(0);
44 root.text_selection_base = -1;
45 root.text_selection_extent = -1;
46 root.label = "accessibility";
47 root.hint = "";
48 root.value = "";
49 root.increased_value = "";
50 root.decreased_value = "";
51 root.tooltip = "";
52 root.child_count = 0;
53 root.custom_accessibility_actions_count = 0;
54 bridge->AddFlutterSemanticsNodeUpdate(root);
55
56 bridge->CommitUpdates();
57
58 auto root_platform_node_delegate = bridge->GetFlutterPlatformNodeDelegateFromID(0).lock();
59 // Verify the accessibility attribute matches.
60 NSAccessibilityElement* native_accessibility =
61 root_platform_node_delegate->GetNativeViewAccessible();
62 std::string value = [native_accessibility.accessibilityValue UTF8String];
63 EXPECT_TRUE(value == "accessibility");
64 EXPECT_EQ(native_accessibility.accessibilityRole, NSAccessibilityStaticTextRole);
65 EXPECT_EQ([native_accessibility.accessibilityChildren count], 0u);
66 [engine shutDownEngine];
67 }
FlutterViewController::engine
FlutterEngine * engine
Definition: FlutterViewController.h:78

References FlutterViewController::engine.

## ◆ TEST() [56/122]

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

Definition at line 150 of file FlutterPlatformNodeDelegateMacTest.mm.

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

References FlutterViewController::engine.

## ◆ TEST() [57/122]

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

Definition at line 308 of file FlutterPlatformNodeDelegateMacTest.mm.

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

References FlutterViewController::engine.

## ◆ TEST() [58/122]

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

Definition at line 69 of file FlutterPlatformNodeDelegateMacTest.mm.

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

References FlutterViewController::engine.

## ◆ TEST() [59/122]

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

Definition at line 111 of file FlutterPlatformNodeDelegateMacTest.mm.

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

References FlutterViewController::engine.

## ◆ TEST() [60/122]

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

Definition at line 225 of file FlutterPlatformNodeDelegateMacTest.mm.

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

References FlutterViewController::engine.

## ◆ TEST() [61/122]

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

Definition at line 119 of file flutter_platform_node_delegate_unittests.cc.

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

## ◆ TEST() [62/122]

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

Definition at line 168 of file flutter_platform_node_delegate_unittests.cc.

168 {
169 std::shared_ptr<TestAccessibilityBridge> bridge =
170 std::make_shared<TestAccessibilityBridge>();
171 FlutterSemanticsFlags flags = FlutterSemanticsFlags{0};
172 FlutterSemanticsNode2 root;
173 root.id = 0;
174 root.label = "root";
175 root.hint = "";
176 root.value = "";
177 root.increased_value = "";
178 root.decreased_value = "";
179 root.tooltip = "";
180 root.child_count = 1;
181 root.flags2 = &flags;
182 int32_t children[] = {1};
183 root.children_in_traversal_order = children;
184 root.custom_accessibility_actions_count = 0;
185 root.rect = {0, 0, 100, 100}; // LTRB
186 root.transform = {1, 0, 0, 0, 1, 0, 0, 0, 1};
187 bridge->AddFlutterSemanticsNodeUpdate(root);
188
189 FlutterSemanticsNode2 child1;
190 child1.id = 1;
191 child1.label = "child 1";
192 child1.hint = "";
193 child1.value = "";
194 child1.increased_value = "";
195 child1.decreased_value = "";
196 child1.tooltip = "";
197 child1.child_count = 0;
198 child1.flags2 = &flags;
199 child1.custom_accessibility_actions_count = 0;
200 child1.rect = {90, 90, 100, 100}; // LTRB
201 child1.transform = {2, 0, 0, 0, 2, 0, 0, 0, 1};
202 bridge->AddFlutterSemanticsNodeUpdate(child1);
203
204 bridge->CommitUpdates();
205 auto child1_node = bridge->GetFlutterPlatformNodeDelegateFromID(1).lock();
206 ui::AXOffscreenResult result;
207 gfx::Rect bounds =
208 child1_node->GetBoundsRect(ui::AXCoordinateSystem::kScreenDIPs,
209 ui::AXClippingBehavior::kUnclipped, &result);
210 EXPECT_EQ(bounds.x(), 180);
211 EXPECT_EQ(bounds.y(), 180);
212 EXPECT_EQ(bounds.width(), 20);
213 EXPECT_EQ(bounds.height(), 20);
214 EXPECT_EQ(result, ui::AXOffscreenResult::kOffscreen);
215 }

## ◆ TEST() [63/122]

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

Definition at line 90 of file flutter_platform_node_delegate_unittests.cc.

90 {
91 // Set up a flutter accessibility node.
92 std::shared_ptr<TestAccessibilityBridge> bridge =
93 std::make_shared<TestAccessibilityBridge>();
94 FlutterSemanticsNode2 root;
95 root.id = 0;
96 FlutterSemanticsFlags flags = FlutterSemanticsFlags{0};
97 flags.is_text_field = true;
98 root.flags2 = &flags;
99 // NOLINTNEXTLINE(clang-analyzer-optin.core.EnumCastOutOfRange)
100 root.actions = static_cast<FlutterSemanticsAction>(0);
101 root.text_selection_base = -1;
102 root.text_selection_extent = -1;
103 root.label = "root";
104 root.hint = "";
105 root.value = "";
106 root.increased_value = "";
107 root.decreased_value = "";
108 root.tooltip = "";
109 root.child_count = 0;
110 root.custom_accessibility_actions_count = 0;
111 bridge->AddFlutterSemanticsNodeUpdate(root);
112
113 bridge->CommitUpdates();
114
115 auto accessibility = bridge->GetFlutterPlatformNodeDelegateFromID(0).lock();
116 EXPECT_EQ(accessibility->GetData().id, 0);
117 }

## ◆ TEST() [64/122]

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

Definition at line 291 of file flutter_platform_node_delegate_unittests.cc.

291 {
292 std::shared_ptr<TestAccessibilityBridge> bridge =
293 std::make_shared<TestAccessibilityBridge>();
294 FlutterSemanticsFlags flags = FlutterSemanticsFlags{0};
295 FlutterSemanticsNode2 root;
296 root.id = 0;
297 root.label = "root";
298 root.hint = "";
299 root.value = "";
300 root.increased_value = "";
301 root.decreased_value = "";
302 root.tooltip = "";
303 root.child_count = 1;
304 root.flags2 = &flags;
305 int32_t children[] = {1};
306 root.children_in_traversal_order = children;
307 root.custom_accessibility_actions_count = 0;
308 bridge->AddFlutterSemanticsNodeUpdate(root);
309
310 FlutterSemanticsNode2 child1;
311 child1.id = 1;
312 child1.label = "child 1";
313 child1.hint = "";
314 child1.value = "";
315 child1.increased_value = "";
316 child1.decreased_value = "";
317 child1.tooltip = "";
318 child1.child_count = 0;
319 child1.flags2 = &flags;
320 child1.custom_accessibility_actions_count = 0;
321 bridge->AddFlutterSemanticsNodeUpdate(child1);
322
323 bridge->CommitUpdates();
324 auto root_node = bridge->GetFlutterPlatformNodeDelegateFromID(0).lock();
325 auto child1_node = bridge->GetFlutterPlatformNodeDelegateFromID(1).lock();
326 auto node_by_id = root_node->GetFromNodeID(1);
327 EXPECT_EQ(child1_node->GetPlatformNode(), node_by_id);
328 }

## ◆ TEST() [65/122]

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

Definition at line 43 of file flutter_platform_node_delegate_unittests.cc.

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

## ◆ TEST() [66/122]

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

Definition at line 217 of file flutter_platform_node_delegate_unittests.cc.

217 {
218 std::shared_ptr<TestAccessibilityBridge> bridge =
219 std::make_shared<TestAccessibilityBridge>();
220 FlutterSemanticsFlags flags = FlutterSemanticsFlags{0};
221 FlutterSemanticsNode2 root{sizeof(FlutterSemanticsNode2), 0};
222 root.label = "root";
223 root.hint = "";
224 root.value = "";
225 root.increased_value = "";
226 root.decreased_value = "";
227 root.tooltip = "";
228 root.heading_level = 0;
229 root.child_count = 1;
230 root.flags2 = &flags;
231 int32_t children[] = {1};
232 root.children_in_traversal_order = children;
233 root.custom_accessibility_actions_count = 0;
234 root.rect = {0, 0, 100, 100}; // LTRB
235 root.transform = {1, 0, 0, 0, 1, 0, 0, 0, 1};
236 bridge->AddFlutterSemanticsNodeUpdate(root);
237
238 FlutterSemanticsNode2 child1{sizeof(FlutterSemanticsNode2), 1};
239 child1.label = "child 1";
240 child1.hint = "";
241 child1.value = "";
242 child1.increased_value = "";
243 child1.decreased_value = "";
244 child1.tooltip = "";
245 child1.heading_level = 0;
246 child1.child_count = 0;
247 child1.flags2 = &flags;
248 child1.custom_accessibility_actions_count = 0;
249 child1.rect = {0, 0, 50, 50}; // LTRB
250 child1.transform = {0.5, 0, 0, 0, 0.5, 0, 0, 0, 1};
251 bridge->AddFlutterSemanticsNodeUpdate(child1);
252
253 bridge->CommitUpdates();
254 auto child1_node = bridge->GetFlutterPlatformNodeDelegateFromID(1).lock();
255 auto owner_bridge = child1_node->GetOwnerBridge().lock();
256
257 bool result;
258 gfx::RectF bounds = owner_bridge->RelativeToGlobalBounds(
259 child1_node->GetAXNode(), result, true);
260 EXPECT_EQ(bounds.x(), 0);
261 EXPECT_EQ(bounds.y(), 0);
262 EXPECT_EQ(bounds.width(), 25);
263 EXPECT_EQ(bounds.height(), 25);
264 EXPECT_EQ(result, false);
265 }

## ◆ TEST() [67/122]

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 FlutterSemanticsFlags emptyFlags = FlutterSemanticsFlags{};
23 node0.child_count = node0_children.size();
24 node0.children_in_traversal_order = node0_children.data();
25 node0.children_in_hit_test_order = node0_children.data();
26 node0.flags2 = &emptyFlags;
27
28 // Add node 1: text child of node 0.
29 FlutterSemanticsNode2 node1{sizeof(FlutterSemanticsNode2), 1};
30 node1.label = "prefecture";
31 node1.value = "Kyoto";
32 node1.flags2 = &emptyFlags;
33
34 bridge->AddFlutterSemanticsNodeUpdate(node0);
35 bridge->AddFlutterSemanticsNodeUpdate(node1);
36 bridge->CommitUpdates();
37
38 auto node0_delegate = bridge->GetFlutterPlatformNodeDelegateFromID(0).lock();
39 auto node1_delegate = bridge->GetFlutterPlatformNodeDelegateFromID(1).lock();
40 EXPECT_TRUE(node0_delegate->GetUniqueId() != node1_delegate->GetUniqueId());
41 }

## ◆ TEST() [68/122]

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

Definition at line 267 of file flutter_platform_node_delegate_unittests.cc.

267 {
268 std::shared_ptr<TestAccessibilityBridge> bridge =
269 std::make_shared<TestAccessibilityBridge>();
270 FlutterSemanticsFlags flags = FlutterSemanticsFlags{0};
271 FlutterSemanticsNode2 root;
272 root.id = 0;
273 root.label = "root";
274 root.hint = "";
275 root.value = "";
276 root.increased_value = "";
277 root.decreased_value = "";
278 root.tooltip = "";
279 root.child_count = 0;
280 root.flags2 = &flags;
281 root.children_in_traversal_order = nullptr;
282 root.custom_accessibility_actions_count = 0;
283 bridge->AddFlutterSemanticsNodeUpdate(root);
284
285 bridge->CommitUpdates();
286 auto root_node = bridge->GetFlutterPlatformNodeDelegateFromID(0).lock();
287 auto lowest_platform_ancestor = root_node->GetLowestPlatformAncestor();
288 EXPECT_EQ(root_node->GetNativeViewAccessible(), lowest_platform_ancestor);
289 }

## ◆ TEST() [69/122]

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/122]

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/122]

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/122]

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/122]

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/122]

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/122]

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/122]

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/122]

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/122]

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/122]

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/122]

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/122]

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/122]

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/122]

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/122]

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

Definition at line 2314 of file FlutterTextInputPluginTest.mm.

2314 {
2315 FlutterEngine* engine = CreateTestEngine();
2316 FlutterViewController* viewController = [[FlutterViewController alloc] initWithEngine:engine
2317 nibName:nil
2318 bundle:nil];
2319 [viewController loadView];
2320 // Creates a NSWindow so that the native text field can become first responder.
2321 NSWindow* window = [[NSWindow alloc] initWithContentRect:NSMakeRect(0, 0, 800, 600)
2322 styleMask:NSBorderlessWindowMask
2323 backing:NSBackingStoreBuffered
2324 defer:NO];
2325 window.contentView = viewController.view;
2326
2327 engine.semanticsEnabled = YES;
2328
2329 auto bridge = viewController.accessibilityBridge.lock();
2330 FlutterPlatformNodeDelegateMac delegate(bridge, viewController);
2331 ui::AXTree tree;
2332 ui::AXNode ax_node(&tree, nullptr, 0, 0);
2333 ui::AXNodeData node_data;
2334 node_data.SetValue("initial text");
2335 ax_node.SetData(node_data);
2336 delegate.Init(viewController.accessibilityBridge, &ax_node);
2337 FlutterTextPlatformNode text_platform_node(&delegate, viewController);
2338
2339 FlutterTextField* textField = text_platform_node.GetNativeViewAccessible();
2340 EXPECT_EQ([textField becomeFirstResponder], YES);
2341 // Removes view controller.
2342 [engine setViewController:nil];
2343 FlutterTextPlatformNode text_platform_node_no_controller(&delegate, nil);
2344 textField = text_platform_node_no_controller.GetNativeViewAccessible();
2345 EXPECT_EQ([textField becomeFirstResponder], NO);
2346 }

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

## ◆ TEST() [85/122]

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

Definition at line 2248 of file FlutterTextInputPluginTest.mm.

2248 {
2249 FlutterEngine* engine = CreateTestEngine();
2250 FlutterViewController* viewController = [[FlutterViewController alloc] initWithEngine:engine
2251 nibName:nil
2252 bundle:nil];
2253 [viewController loadView];
2254 // Create a NSWindow so that the native text field can become first responder.
2255 NSWindow* window = [[NSWindow alloc] initWithContentRect:NSMakeRect(0, 0, 800, 600)
2256 styleMask:NSBorderlessWindowMask
2257 backing:NSBackingStoreBuffered
2258 defer:NO];
2259 window.contentView = viewController.view;
2260
2261 engine.semanticsEnabled = YES;
2262
2263 auto bridge = viewController.accessibilityBridge.lock();
2264 FlutterPlatformNodeDelegateMac delegate(bridge, viewController);
2265 ui::AXTree tree;
2266 ui::AXNode ax_node(&tree, nullptr, 0, 0);
2267 ui::AXNodeData node_data;
2268 node_data.SetValue("initial text");
2269 ax_node.SetData(node_data);
2270 delegate.Init(viewController.accessibilityBridge, &ax_node);
2271 {
2272 FlutterTextPlatformNode text_platform_node(&delegate, viewController);
2273
2274 FlutterTextFieldMock* mockTextField =
2275 [[FlutterTextFieldMock alloc] initWithPlatformNode:&text_platform_node
2276 fieldEditor:engine.textInputPlugin];
2277 [viewController.view addSubview:mockTextField];
2278 [mockTextField startEditing];
2279
2280 NSDictionary* setClientConfig = @{
2281 @"viewId" : @(flutter::kFlutterImplicitViewId),
2282 @"inputAction" : @"action",
2283 @"inputType" : @{@"name" : @"inputName"},
2284 };
2285 FlutterMethodCall* methodCall =
2286 [FlutterMethodCall methodCallWithMethodName:@"TextInput.setClient"
2287 arguments:@[ @(1), setClientConfig ]];
2288 FlutterResult result = ^(id result) {
2289 };
2290 [engine.textInputPlugin handleMethodCall:methodCall result:result];
2291
2292 NSDictionary* arguments = @{
2293 @"text" : @"new text",
2294 @"selectionBase" : @(1),
2295 @"selectionExtent" : @(2),
2296 @"composingBase" : @(-1),
2297 @"composingExtent" : @(-1),
2298 };
2299 methodCall = [FlutterMethodCall methodCallWithMethodName:@"TextInput.setEditingState"
2300 arguments:arguments];
2301 [engine.textInputPlugin handleMethodCall:methodCall result:result];
2302 EXPECT_EQ([mockTextField.lastUpdatedString isEqualToString:@"new text"], YES);
2303 EXPECT_EQ(NSEqualRanges(mockTextField.lastUpdatedSelection, NSMakeRange(1, 1)), YES);
2304
2305 // This blocks the FlutterTextFieldMock, which is held onto by the main event
2306 // loop, from crashing.
2307 [mockTextField setPlatformNode:nil];
2308 }
2309
2310 // This verifies that clearing the platform node works.
2311 [[NSRunLoop currentRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:0.1]];
2312 }
+[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/122]

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

Definition at line 2390 of file FlutterTextInputPluginTest.mm.

2390 {
2391 FlutterEngine* engine = CreateTestEngine();
2392 FlutterViewController* viewController = [[FlutterViewController alloc] initWithEngine:engine
2393 nibName:nil
2394 bundle:nil];
2395 [viewController loadView];
2396
2397 NSWindow* window = [[NSWindow alloc] initWithContentRect:NSMakeRect(0, 0, 800, 600)
2398 styleMask:NSBorderlessWindowMask
2399 backing:NSBackingStoreBuffered
2400 defer:NO];
2401 window.contentView = viewController.view;
2402
2403 ASSERT_TRUE(viewController.flutterView.acceptsFirstResponder);
2404
2405 [window makeFirstResponder:viewController.flutterView];
2406
2407 NSDictionary* setClientConfig = @{
2408 @"viewId" : @(flutter::kFlutterImplicitViewId),
2409 };
2410 [engine.textInputPlugin
2411 handleMethodCall:[FlutterMethodCall methodCallWithMethodName:@"TextInput.setClient"
2412 arguments:@[ @(1), setClientConfig ]]
2413 result:^(id){
2414 }];
2415
2416 [engine.textInputPlugin
2417 handleMethodCall:[FlutterMethodCall methodCallWithMethodName:@"TextInput.show" arguments:@[]]
2418 result:^(id){
2419 }];
2420
2421 ASSERT_TRUE(window.firstResponder == engine.textInputPlugin);
2422
2423 ASSERT_FALSE(viewController.flutterView.acceptsFirstResponder);
2424
2425 [engine.textInputPlugin
2426 handleMethodCall:[FlutterMethodCall methodCallWithMethodName:@"TextInput.hide" arguments:@[]]
2427 result:^(id){
2428 }];
2429
2430 ASSERT_TRUE(viewController.flutterView.acceptsFirstResponder);
2431 ASSERT_TRUE(window.firstResponder == viewController.flutterView);
2432 }

References FlutterMethodCall::methodCallWithMethodName:arguments:.

## ◆ TEST() [87/122]

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

Definition at line 2172 of file FlutterTextInputPluginTest.mm.

2172 {
2173 ASSERT_TRUE([[FlutterInputPluginTestObjc alloc] handleArrowKeyWhenImePopoverIsActive]);
2174 }
FlutterInputPluginTestObjc
Definition: FlutterTextInputPluginTest.mm:56

## ◆ TEST() [88/122]

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

Definition at line 2434 of file FlutterTextInputPluginTest.mm.

2434 {
2435 id engineMock = flutter::testing::CreateMockFlutterEngine(@"");
2436 id binaryMessengerMock = OCMProtocolMock(@protocol(FlutterBinaryMessenger));
2437 OCMStub( // NOLINT(google-objc-avoid-throwing-exception)
2438 [engineMock binaryMessenger])
2439 .andReturn(binaryMessengerMock);
2440
2441 FlutterViewController* viewController = [[FlutterViewController alloc] initWithEngine:engineMock
2442 nibName:@""
2443 bundle:nil];
2444
2445 FlutterTextInputPluginTestDelegate* delegate =
2446 [[FlutterTextInputPluginTestDelegate alloc] initWithBinaryMessenger:binaryMessengerMock
2447 viewController:viewController];
2448
2449 FlutterTextInputPlugin* plugin = [[FlutterTextInputPlugin alloc] initWithDelegate:delegate];
2450
2451 ASSERT_TRUE(NSIsEmptyRect(plugin.frame));
2452 ASSERT_TRUE(plugin.clipsToBounds);
2453 }
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/122]

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

Definition at line 2526 of file FlutterTextInputPluginTest.mm.

2526 {
2527 id engineMock = flutter::testing::CreateMockFlutterEngine(@"");
2528 id binaryMessengerMock = OCMProtocolMock(@protocol(FlutterBinaryMessenger));
2529 OCMStub( // NOLINT(google-objc-avoid-throwing-exception)
2530 [engineMock binaryMessenger])
2531 .andReturn(binaryMessengerMock);
2532
2533 FlutterViewController* viewController = [[FlutterViewController alloc] initWithEngine:engineMock
2534 nibName:@""
2535 bundle:nil];
2536
2537 FlutterTextInputPluginTestDelegate* delegate =
2538 [[FlutterTextInputPluginTestDelegate alloc] initWithBinaryMessenger:binaryMessengerMock
2539 viewController:viewController];
2540
2541 FlutterTextInputPlugin* plugin = [[FlutterTextInputPlugin alloc] initWithDelegate:delegate];
2542
2543 NSDictionary* setClientConfig = @{
2544 @"viewId" : @(kViewId),
2545 @"inputAction" : @"action",
2546 @"inputType" : @{@"name" : @"inputName"},
2547 };
2548 [plugin handleMethodCall:[FlutterMethodCall methodCallWithMethodName:@"TextInput.setClient"
2549 arguments:@[ @(1), setClientConfig ]]
2550 result:^(id){
2551 }];
2552
2553 // Test with empty NSAttributedString
2554 NSAttributedString* emptyAttributedString = [[NSAttributedString alloc] initWithString:@""];
2555 [plugin insertText:emptyAttributedString replacementRange:NSMakeRange(NSNotFound, 0)];
2556
2557 NSDictionary* editingState = [plugin editingState];
2558 EXPECT_STREQ([editingState[@"text"] UTF8String], "");
2559 EXPECT_EQ([editingState[@"selectionBase"] intValue], 0);
2560 EXPECT_EQ([editingState[@"selectionExtent"] intValue], 0);
2561 }
kViewId
static const FlutterViewIdentifier kViewId
Definition: FlutterTextInputPluginTest.mm:70
-[FlutterTextInputPlugin handleMethodCall:result:]
void handleMethodCall:result:(FlutterMethodCall *call,[result] FlutterResult result)
-[FlutterTextInputPlugin editingState]
NSDictionary * editingState()

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

## ◆ TEST() [90/122]

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

Definition at line 2488 of file FlutterTextInputPluginTest.mm.

2488 {
2489 id engineMock = flutter::testing::CreateMockFlutterEngine(@"");
2490 id binaryMessengerMock = OCMProtocolMock(@protocol(FlutterBinaryMessenger));
2491 OCMStub( // NOLINT(google-objc-avoid-throwing-exception)
2492 [engineMock binaryMessenger])
2493 .andReturn(binaryMessengerMock);
2494
2495 FlutterViewController* viewController = [[FlutterViewController alloc] initWithEngine:engineMock
2496 nibName:@""
2497 bundle:nil];
2498
2499 FlutterTextInputPluginTestDelegate* delegate =
2500 [[FlutterTextInputPluginTestDelegate alloc] initWithBinaryMessenger:binaryMessengerMock
2501 viewController:viewController];
2502
2503 FlutterTextInputPlugin* plugin = [[FlutterTextInputPlugin alloc] initWithDelegate:delegate];
2504
2505 NSDictionary* setClientConfig = @{
2506 @"viewId" : @(kViewId),
2507 @"inputAction" : @"action",
2508 @"inputType" : @{@"name" : @"inputName"},
2509 };
2510 [plugin handleMethodCall:[FlutterMethodCall methodCallWithMethodName:@"TextInput.setClient"
2511 arguments:@[ @(1), setClientConfig ]]
2512 result:^(id){
2513 }];
2514
2515 // Test with NSAttributedString
2516 NSAttributedString* attributedString =
2517 [[NSAttributedString alloc] initWithString:@"attributed text"];
2518 [plugin insertText:attributedString replacementRange:NSMakeRange(NSNotFound, 0)];
2519
2520 NSDictionary* editingState = [plugin editingState];
2521 EXPECT_STREQ([editingState[@"text"] UTF8String], "attributed text");
2522 EXPECT_EQ([editingState[@"selectionBase"] intValue], 15);
2523 EXPECT_EQ([editingState[@"selectionExtent"] intValue], 15);
2524 }

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

## ◆ TEST() [91/122]

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

Definition at line 2483 of file FlutterTextInputPluginTest.mm.

2483 {
2484 ASSERT_TRUE(
2485 [[FlutterInputPluginTestObjc alloc] testInsertTextWithCollapsedSelectionInsideComposing]);
2486 }

## ◆ TEST() [92/122]

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

Definition at line 2348 of file FlutterTextInputPluginTest.mm.

2348 {
2349 FlutterEngine* engine = CreateTestEngine();
2350 FlutterViewController* viewController = [[FlutterViewController alloc] initWithEngine:engine
2351 nibName:nil
2352 bundle:nil];
2353 [viewController loadView];
2354
2355 NSWindow* window = [[NSWindow alloc] initWithContentRect:NSMakeRect(0, 0, 800, 600)
2356 styleMask:NSBorderlessWindowMask
2357 backing:NSBackingStoreBuffered
2358 defer:NO];
2359 window.contentView = viewController.view;
2360
2361 ASSERT_EQ(engine.textInputPlugin.superview, nil);
2362 ASSERT_FALSE(window.firstResponder == engine.textInputPlugin);
2363
2364 NSDictionary* setClientConfig = @{
2365 @"viewId" : @(flutter::kFlutterImplicitViewId),
2366 };
2367 [engine.textInputPlugin
2368 handleMethodCall:[FlutterMethodCall methodCallWithMethodName:@"TextInput.setClient"
2369 arguments:@[ @(1), setClientConfig ]]
2370 result:^(id){
2371 }];
2372
2373 [engine.textInputPlugin
2374 handleMethodCall:[FlutterMethodCall methodCallWithMethodName:@"TextInput.show" arguments:@[]]
2375 result:^(id){
2376 }];
2377
2378 ASSERT_EQ(engine.textInputPlugin.superview, viewController.view);
2379 ASSERT_TRUE(window.firstResponder == engine.textInputPlugin);
2380
2381 [engine.textInputPlugin
2382 handleMethodCall:[FlutterMethodCall methodCallWithMethodName:@"TextInput.hide" arguments:@[]]
2383 result:^(id){
2384 }];
2385
2386 ASSERT_EQ(engine.textInputPlugin.superview, nil);
2387 ASSERT_FALSE(window.firstResponder == engine.textInputPlugin);
2388 }

References FlutterMethodCall::methodCallWithMethodName:arguments:.

## ◆ TEST() [93/122]

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

Definition at line 2196 of file FlutterTextInputPluginTest.mm.

2196 {
2197 id engineMock = flutter::testing::CreateMockFlutterEngine(@"");
2198 id binaryMessengerMock = OCMProtocolMock(@protocol(FlutterBinaryMessenger));
2199 OCMStub( // NOLINT(google-objc-avoid-throwing-exception)
2200 [engineMock binaryMessenger])
2201 .andReturn(binaryMessengerMock);
2202
2203 FlutterViewController* viewController = [[FlutterViewController alloc] initWithEngine:engineMock
2204 nibName:@""
2205 bundle:nil];
2206
2207 FlutterTextInputPluginTestDelegate* delegate =
2208 [[FlutterTextInputPluginTestDelegate alloc] initWithBinaryMessenger:binaryMessengerMock
2209 viewController:viewController];
2210
2211 FlutterTextInputPlugin* plugin = [[FlutterTextInputPlugin alloc] initWithDelegate:delegate];
2212
2213 NSDictionary* setClientConfig = @{
2214 @"viewId" : @(kViewId),
2215 @"inputAction" : @"action",
2216 @"enableDeltaModel" : @"true",
2217 @"inputType" : @{@"name" : @"inputName"},
2218 };
2219 [plugin handleMethodCall:[FlutterMethodCall methodCallWithMethodName:@"TextInput.setClient"
2220 arguments:@[ @(1), setClientConfig ]]
2221 result:^(id){
2222 }];
2223
2224 FlutterMethodCall* call = [FlutterMethodCall methodCallWithMethodName:@"TextInput.setEditingState"
2225 arguments:@{
2226 @"text" : @"Text",
2227 @"selectionBase" : @(0),
2228 @"selectionExtent" : @(0),
2229 @"composingBase" : @(-1),
2230 @"composingExtent" : @(-1),
2231 }];
2232
2233 [plugin handleMethodCall:call
2234 result:^(id){
2235 }];
2236
2237 NSRange out;
2238 NSAttributedString* text = [plugin attributedSubstringForProposedRange:NSMakeRange(1, 10)
2239 actualRange:&out];
2240 EXPECT_TRUE([text.string isEqualToString:@"ext"]);
2241 EXPECT_EQ(out.location, 1u);
2242 EXPECT_EQ(out.length, 3u);
2243
2244 text = [plugin attributedSubstringForProposedRange:NSMakeRange(4, 10) actualRange:&out];
2245 EXPECT_EQ(text, nil);
2246 }

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

## ◆ TEST() [94/122]

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

Definition at line 2130 of file FlutterTextInputPluginTest.mm.

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

## ◆ TEST() [95/122]

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

Definition at line 2110 of file FlutterTextInputPluginTest.mm.

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

## ◆ TEST() [96/122]

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

Definition at line 2122 of file FlutterTextInputPluginTest.mm.

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

## ◆ TEST() [97/122]

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

Definition at line 2126 of file FlutterTextInputPluginTest.mm.

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

## ◆ TEST() [98/122]

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

Definition at line 2114 of file FlutterTextInputPluginTest.mm.

2114 {
2115 ASSERT_TRUE([[FlutterInputPluginTestObjc alloc] testAutocompleteEnabledWhenAutofillSet]);
2116 }

## ◆ TEST() [99/122]

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

Definition at line 2118 of file FlutterTextInputPluginTest.mm.

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

## ◆ TEST() [100/122]

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

Definition at line 2106 of file FlutterTextInputPluginTest.mm.

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

## ◆ TEST() [101/122]

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

Definition at line 2102 of file FlutterTextInputPluginTest.mm.

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

## ◆ TEST() [102/122]

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

Definition at line 2156 of file FlutterTextInputPluginTest.mm.

2156 {
2157 ASSERT_TRUE([[FlutterInputPluginTestObjc alloc] testComposingWithDelta]);
2158 }

## ◆ TEST() [103/122]

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

Definition at line 2160 of file FlutterTextInputPluginTest.mm.

2160 {
2161 ASSERT_TRUE([[FlutterInputPluginTestObjc alloc] testComposingWithDeltasWhenSelectionIsActive]);
2162 }

## ◆ TEST() [104/122]

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

Definition at line 2090 of file FlutterTextInputPluginTest.mm.

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

## ◆ TEST() [105/122]

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

Definition at line 2135 of file FlutterTextInputPluginTest.mm.

2135 {
2136 ASSERT_TRUE([[FlutterInputPluginTestObjc alloc] testFirstRectForCharacterRange]);
2137 }

## ◆ TEST() [106/122]

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

Definition at line 2139 of file FlutterTextInputPluginTest.mm.

2139 {
2140 ASSERT_TRUE([[FlutterInputPluginTestObjc alloc] testFirstRectForCharacterRangeAtInfinity]);
2141 }

## ◆ TEST() [107/122]

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

Definition at line 2143 of file FlutterTextInputPluginTest.mm.

2143 {
2144 ASSERT_TRUE([[FlutterInputPluginTestObjc alloc]
2145 testFirstRectForCharacterRangeWithEsotericAffineTransform]);
2146 }

## ◆ TEST() [108/122]

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

Definition at line 2188 of file FlutterTextInputPluginTest.mm.

2188 {
2189 ASSERT_TRUE([[FlutterInputPluginTestObjc alloc] testInsertNewLine]);
2190 }

## ◆ TEST() [109/122]

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

Definition at line 2164 of file FlutterTextInputPluginTest.mm.

2164 {
2165 ASSERT_TRUE([[FlutterInputPluginTestObjc alloc] testLocalTextAndSelectionUpdateAfterDelta]);
2166 }

## ◆ TEST() [110/122]

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

Definition at line 2152 of file FlutterTextInputPluginTest.mm.

2152 {
2153 ASSERT_TRUE([[FlutterInputPluginTestObjc alloc] testOperationsThatTriggerDelta]);
2154 }

## ◆ TEST() [111/122]

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

Definition at line 2168 of file FlutterTextInputPluginTest.mm.

2168 {
2169 ASSERT_TRUE([[FlutterInputPluginTestObjc alloc] testPerformKeyEquivalent]);
2170 }

## ◆ TEST() [112/122]

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

Definition at line 2180 of file FlutterTextInputPluginTest.mm.

2180 {
2181 ASSERT_TRUE([[FlutterInputPluginTestObjc alloc] testSelectorsAreForwardedToFramework]);
2182 }

## ◆ TEST() [113/122]

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

Definition at line 2184 of file FlutterTextInputPluginTest.mm.

2184 {
2185 ASSERT_TRUE([[FlutterInputPluginTestObjc alloc] testSelectorsNotForwardedToFrameworkIfNoClient]);
2186 }

## ◆ TEST() [114/122]

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

Definition at line 2192 of file FlutterTextInputPluginTest.mm.

2192 {
2193 ASSERT_TRUE([[FlutterInputPluginTestObjc alloc] testSendActionDoNotInsertNewLine]);
2194 }

## ◆ TEST() [115/122]

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

Definition at line 2148 of file FlutterTextInputPluginTest.mm.

2148 {
2149 ASSERT_TRUE([[FlutterInputPluginTestObjc alloc] testSetEditingStateWithTextEditingDelta]);
2150 }

## ◆ TEST() [116/122]

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

Definition at line 2098 of file FlutterTextInputPluginTest.mm.

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

## ◆ TEST() [117/122]

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

Definition at line 2094 of file FlutterTextInputPluginTest.mm.

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

## ◆ TEST() [118/122]

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

Definition at line 2176 of file FlutterTextInputPluginTest.mm.

2176 {
2177 ASSERT_TRUE([[FlutterInputPluginTestObjc alloc] unhandledKeyEquivalent]);
2178 }

## ◆ TEST() [119/122]

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

Definition at line 2455 of file FlutterTextInputPluginTest.mm.

2455 {
2456 id engineMock = flutter::testing::CreateMockFlutterEngine(@"");
2457 id binaryMessengerMock = OCMProtocolMock(@protocol(FlutterBinaryMessenger));
2458 OCMStub( // NOLINT(google-objc-avoid-throwing-exception)
2459 [engineMock binaryMessenger])
2460 .andReturn(binaryMessengerMock);
2461
2462 FlutterViewController* viewController = [[FlutterViewController alloc] initWithEngine:engineMock
2463 nibName:@""
2464 bundle:nil];
2465
2466 FlutterTextInputPluginTestDelegate* delegate =
2467 [[FlutterTextInputPluginTestDelegate alloc] initWithBinaryMessenger:binaryMessengerMock
2468 implicitViewController:viewController];
2469
2470 FlutterTextInputPlugin* plugin = [[FlutterTextInputPlugin alloc] initWithDelegate:delegate];
2471
2472 NSDictionary* setClientConfig = @{
2473 // omit viewId
2474 };
2475 [plugin handleMethodCall:[FlutterMethodCall methodCallWithMethodName:@"TextInput.setClient"
2476 arguments:@[ @(1), setClientConfig ]]
2477 result:^(id){
2478 }];
2479
2480 ASSERT_TRUE(plugin.currentViewController == viewController);
2481 }
FlutterTextInputPlugin::currentViewController
FlutterViewController * currentViewController
Definition: FlutterTextInputPlugin.h:54

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

## ◆ TEST() [120/122]

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() [121/122]

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() [122/122]

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/83]

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

Definition at line 218 of file AccessibilityBridgeMacTest.mm.

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

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

## ◆ TEST_F() [2/83]

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

Definition at line 266 of file AccessibilityBridgeMacTest.mm.

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

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

## ◆ TEST_F() [3/83]

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

Definition at line 149 of file AccessibilityBridgeMacTest.mm.

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

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

## ◆ TEST_F() [4/83]

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 FlutterSemanticsFlags flags = FlutterSemanticsFlags{0};
103 root.id = 0;
104 root.flags2 = &flags;
105 // NOLINTNEXTLINE(clang-analyzer-optin.core.EnumCastOutOfRange)
106 root.actions = static_cast<FlutterSemanticsAction>(0);
107 root.text_selection_base = -1;
108 root.text_selection_extent = -1;
109 root.label = "root";
110 root.hint = "";
111 root.value = "";
112 root.increased_value = "";
113 root.decreased_value = "";
114 root.tooltip = "";
115 root.child_count = 0;
116 root.custom_accessibility_actions_count = 0;
117 bridge->AddFlutterSemanticsNodeUpdate(root);
118
119 bridge->CommitUpdates();
120 auto platform_node_delegate = bridge->GetFlutterPlatformNodeDelegateFromID(0).lock();
121
122 // Creates a targeted event.
123 ui::AXTree tree;
124 ui::AXNode ax_node(&tree, nullptr, 0, 0);
125 ui::AXNodeData node_data;
126 node_data.id = 0;
127 ax_node.SetData(node_data);
128 std::vector<ui::AXEventIntent> intent;
129 ui::AXEventGenerator::EventParams event_params(ui::AXEventGenerator::Event::CHILDREN_CHANGED,
130 ax::mojom::EventFrom::kNone, intent);
131 ui::AXEventGenerator::TargetedEvent targeted_event(&ax_node, event_params);
132
133 bridge->OnAccessibilityEvent(targeted_event);
134
135 ASSERT_EQ(bridge->actual_notifications.size(), 1u);
136 auto target = bridge->actual_notifications.find([NSAccessibilityCreatedNotification UTF8String]);
137 ASSERT_NE(target, bridge->actual_notifications.end());
138 EXPECT_EQ(target->second, expectedTarget);
139 [engine shutDownEngine];
140 }

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

## ◆ TEST_F() [5/83]

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/83]

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/83]

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/83]

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/83]

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/83]

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/83]

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/83]

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/83]

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/83]

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/83]

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/83]

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/83]

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/83]

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

Definition at line 903 of file FlutterEngineTest.mm.

903 {
904 FlutterEngine* engine = GetFlutterEngine();
905
906 BOOL signaled = NO;
907 std::optional<int64_t> engineId;
908 AddNativeCallback("NotifyEngineId", CREATE_NATIVE_ENTRY([&](Dart_NativeArguments args) {
909 const auto argument = Dart_GetNativeArgument(args, 0);
910 if (!Dart_IsNull(argument)) {
911 const auto id = tonic::DartConverter<int64_t>::FromDart(argument);
912 engineId = id;
913 }
914 signaled = YES;
915 }));
916
917 EXPECT_TRUE([engine runWithEntrypoint:@"testEngineId"]);
918 while (!signaled) {
919 CFRunLoopRunInMode(kCFRunLoopDefaultMode, 1, YES);
920 }
921
922 EXPECT_TRUE(engineId.has_value());
923 if (!engineId.has_value()) {
924 return;
925 }
926 EXPECT_EQ(engine, [FlutterEngine engineForIdentifier:*engineId]);
927 ShutDownEngine();
928 }

## ◆ TEST_F() [19/83]

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

Definition at line 142 of file FlutterEngineTest.mm.

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

## ◆ TEST_F() [20/83]

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

Definition at line 207 of file FlutterEngineTest.mm.

207 {
208 // Block until completion of print statement.
209 BOOL signaled = NO;
210 AddNativeCallback("SignalNativeTest",
211 CREATE_NATIVE_ENTRY([&](Dart_NativeArguments args) { signaled = YES; }));
212
213 // Replace stdout stream buffer with our own.
214 FlutterStringOutputWriter* writer = [[FlutterStringOutputWriter alloc] init];
215 writer.expectedOutput = @"Hello logging";
216 FlutterLogger.outputWriter = writer;
217
218 // Launch the test entrypoint.
219 FlutterEngine* engine = GetFlutterEngine();
220 EXPECT_TRUE([engine runWithEntrypoint:@"canLogToStdout"]);
221 ASSERT_TRUE(engine.running);
222
223 while (!signaled) {
224 CFRunLoopRunInMode(kCFRunLoopDefaultMode, 1, YES);
225 }
226
227 // Verify hello world was written to stdout.
228 EXPECT_TRUE(writer.gotExpectedOutput);
229 }

## ◆ TEST_F() [21/83]

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

Definition at line 294 of file FlutterEngineTest.mm.

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

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

Definition at line 392 of file FlutterEngineTest.mm.

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

References user_data, and FlutterEngine::viewController.

## ◆ TEST_F() [23/83]

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

Definition at line 517 of file FlutterEngineTest.mm.

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

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

## ◆ TEST_F() [24/83]

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

Definition at line 563 of file FlutterEngineTest.mm.

563 {
564 FlutterEngine* engine = GetFlutterEngine();
565 auto original_init = engine.embedderAPI.Initialize;
566 ::FlutterCompositor compositor;
567 engine.embedderAPI.Initialize = MOCK_ENGINE_PROC(
568 Initialize, ([&compositor, &original_init](
569 size_t version, const FlutterRendererConfig* config,
570 const FlutterProjectArgs* args, void* user_data, auto engine_out) {
571 compositor = *args->compositor;
572 return original_init(version, config, args, user_data, engine_out);
573 }));
574
575 FlutterViewController* viewController = [[FlutterViewController alloc] initWithEngine:engine
576 nibName:nil
577 bundle:nil];
578 [viewController loadView];
579
580 EXPECT_TRUE([engine runWithEntrypoint:@"empty"]);
581
582 FlutterBackingStoreConfig config = {
583 .struct_size = sizeof(FlutterBackingStoreConfig),
584 .size = FlutterSize{10, 10},
585 };
586 FlutterBackingStore backing_store = {};
587 EXPECT_NE(compositor.create_backing_store_callback, nullptr);
588 EXPECT_TRUE(
589 compositor.create_backing_store_callback(&config, &backing_store, compositor.user_data));
590
591 FlutterLayer layer{
592 .type = kFlutterLayerContentTypeBackingStore,
593 .backing_store = &backing_store,
594 };
595 std::vector<FlutterLayer*> layers = {&layer};
596
597 FlutterPresentViewInfo info = {
598 .struct_size = sizeof(FlutterPresentViewInfo),
599 .view_id = 123,
600 .layers = const_cast<const FlutterLayer**>(layers.data()),
601 .layers_count = 1,
602 .user_data = compositor.user_data,
603 };
604 EXPECT_NE(compositor.present_view_callback, nullptr);
605 EXPECT_FALSE(compositor.present_view_callback(&info));
606 EXPECT_TRUE(compositor.collect_backing_store_callback(&backing_store, compositor.user_data));
607
608 (void)viewController;
609 [engine shutDownEngine];
610 }

References FlutterEngine::shutDownEngine, and user_data.

## ◆ TEST_F() [25/83]

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

Definition at line 612 of file FlutterEngineTest.mm.

612 {
613 NSString* fixtures = @(flutter::testing::GetFixturesPath());
614 FlutterDartProject* project = [[FlutterDartProject alloc]
615 initWithAssetsPath:fixtures
616 ICUDataPath:[fixtures stringByAppendingString:@"/icudtl.dat"]];
617
618 project.dartEntrypointArguments = @[ @"arg1", @"arg2" ];
619 FlutterEngine* engine = [[FlutterEngine alloc] initWithName:@"test" project:project];
620
621 bool called = false;
622 auto original_init = engine.embedderAPI.Initialize;
623 engine.embedderAPI.Initialize = MOCK_ENGINE_PROC(
624 Initialize, ([&called, &original_init](size_t version, const FlutterRendererConfig* config,
625 const FlutterProjectArgs* args, void* user_data,
626 FLUTTER_API_SYMBOL(FlutterEngine) * engine_out) {
627 called = true;
628 EXPECT_EQ(args->dart_entrypoint_argc, 2);
629 NSString* arg1 = [[NSString alloc] initWithCString:args->dart_entrypoint_argv[0]
630 encoding:NSUTF8StringEncoding];
631 NSString* arg2 = [[NSString alloc] initWithCString:args->dart_entrypoint_argv[1]
632 encoding:NSUTF8StringEncoding];
633
634 EXPECT_TRUE([arg1 isEqualToString:@"arg1"]);
635 EXPECT_TRUE([arg2 isEqualToString:@"arg2"]);
636
637 return original_init(version, config, args, user_data, engine_out);
638 }));
639
640 EXPECT_TRUE([engine runWithEntrypoint:@"main"]);
641 EXPECT_TRUE(called);
642 [engine shutDownEngine];
643 }

References FlutterEngine::shutDownEngine, and user_data.

## ◆ TEST_F() [26/83]

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

Definition at line 231 of file FlutterEngineTest.mm.

231 {
232 FlutterEngine* engine = GetFlutterEngine();
233
234 // Latch to ensure the entire layer tree has been generated and presented.
235 BOOL signaled = NO;
236 AddNativeCallback("SignalNativeTest", CREATE_NATIVE_ENTRY([&](Dart_NativeArguments args) {
237 CALayer* rootLayer = engine.viewController.flutterView.layer;
238 EXPECT_TRUE(rootLayer.backgroundColor != nil);
239 if (rootLayer.backgroundColor != nil) {
240 NSColor* actualBackgroundColor =
241 [NSColor colorWithCGColor:rootLayer.backgroundColor];
242 EXPECT_EQ(actualBackgroundColor, [NSColor blackColor]);
243 }
244 signaled = YES;
245 }));
246
247 // Launch the test entrypoint.
248 EXPECT_TRUE([engine runWithEntrypoint:@"backgroundTest"]);
249 ASSERT_TRUE(engine.running);
250
251 FlutterViewController* viewController = [[FlutterViewController alloc] initWithEngine:engine
252 nibName:nil
253 bundle:nil];
254 [viewController loadView];
255 viewController.flutterView.frame = CGRectMake(0, 0, 800, 600);
256
257 while (!signaled) {
258 CFRunLoopRunInMode(kCFRunLoopDefaultMode, 1, YES);
259 }
260 }

References FlutterEngine::viewController.

## ◆ TEST_F() [27/83]

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

Definition at line 262 of file FlutterEngineTest.mm.

262 {
263 FlutterEngine* engine = GetFlutterEngine();
264
265 // Latch to ensure the entire layer tree has been generated and presented.
266 BOOL signaled = NO;
267 AddNativeCallback("SignalNativeTest", CREATE_NATIVE_ENTRY([&](Dart_NativeArguments args) {
268 CALayer* rootLayer = engine.viewController.flutterView.layer;
269 EXPECT_TRUE(rootLayer.backgroundColor != nil);
270 if (rootLayer.backgroundColor != nil) {
271 NSColor* actualBackgroundColor =
272 [NSColor colorWithCGColor:rootLayer.backgroundColor];
273 EXPECT_EQ(actualBackgroundColor, [NSColor whiteColor]);
274 }
275 signaled = YES;
276 }));
277
278 // Launch the test entrypoint.
279 EXPECT_TRUE([engine runWithEntrypoint:@"backgroundTest"]);
280 ASSERT_TRUE(engine.running);
281
282 FlutterViewController* viewController = [[FlutterViewController alloc] initWithEngine:engine
283 nibName:nil
284 bundle:nil];
285 [viewController loadView];
286 viewController.flutterView.frame = CGRectMake(0, 0, 800, 600);
287 viewController.flutterView.backgroundColor = [NSColor whiteColor];
288
289 while (!signaled) {
290 CFRunLoopRunInMode(kCFRunLoopDefaultMode, 1, YES);
291 }
292 }
FlutterViewController::backgroundColor
NSColor * backgroundColor
Definition: FlutterViewController.h:210

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

## ◆ TEST_F() [28/83]

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

Definition at line 1315 of file FlutterEngineTest.mm.

1315 {
1316 NSString* fixtures = @(testing::GetFixturesPath());
1317 FlutterDartProject* project = [[FlutterDartProject alloc]
1318 initWithAssetsPath:fixtures
1319 ICUDataPath:[fixtures stringByAppendingString:@"/icudtl.dat"]];
1320 project.rootIsolateCreateCallback = FlutterEngineTest::IsolateCreateCallback;
1321 MockableFlutterEngine* engine = [[MockableFlutterEngine alloc] initWithName:@"foobar"
1322 project:project
1323 allowHeadlessExecution:true];
1324 BOOL updated = NO;
1325 auto original_update_displays = engine.embedderAPI.NotifyDisplayUpdate;
1326 engine.embedderAPI.NotifyDisplayUpdate = MOCK_ENGINE_PROC(
1327 NotifyDisplayUpdate, ([&updated, &original_update_displays](
1328 auto engine, auto update_type, auto* displays, auto display_count) {
1329 EXPECT_EQ(display_count, 1UL);
1330 EXPECT_EQ(displays->display_id, 10UL);
1331 EXPECT_EQ(displays->width, 60UL);
1332 EXPECT_EQ(displays->height, 80UL);
1333 EXPECT_EQ(displays->device_pixel_ratio, 2UL);
1334 updated = YES;
1335 return original_update_displays(engine, update_type, displays, display_count);
1336 }));
1337 EXPECT_TRUE([engine runWithEntrypoint:@"main"]);
1338 EXPECT_TRUE(updated);
1339 [engine shutDownEngine];
1340 engine = nil;
1341 }
MockableFlutterEngine
Definition: FlutterEngineTest.mm:124

References FlutterEngine::shutDownEngine.

## ◆ TEST_F() [29/83]

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

Definition at line 651 of file FlutterEngineTest.mm.

651 {
652 __weak FlutterEngine* weakEngine;
653 id<FlutterBinaryMessenger> binaryMessenger = nil;
654 @autoreleasepool {
655 // Create a test engine.
656 NSString* fixtures = @(flutter::testing::GetFixturesPath());
657 FlutterDartProject* project = [[FlutterDartProject alloc]
658 initWithAssetsPath:fixtures
659 ICUDataPath:[fixtures stringByAppendingString:@"/icudtl.dat"]];
660 FlutterEngine* engine = [[FlutterEngine alloc] initWithName:@"test"
661 project:project
662 allowHeadlessExecution:YES];
663 weakEngine = engine;
664 binaryMessenger = engine.binaryMessenger;
665 }
666
667 // Once the engine has been deallocated, verify the weak engine pointer is nil, and thus not
668 // retained by the relay.
669 EXPECT_NE(binaryMessenger, nil);
670 EXPECT_EQ(weakEngine, nil);
671 }
FlutterEngine::binaryMessenger
id< FlutterBinaryMessenger > binaryMessenger
Definition: FlutterEngine.h:92

References FlutterEngine::binaryMessenger.

## ◆ TEST_F() [30/83]

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

Definition at line 675 of file FlutterEngineTest.mm.

675 {
676 __weak FlutterEngine* weakEngine;
677 id<FlutterTextureRegistry> textureRegistry;
678 @autoreleasepool {
679 // Create a test engine.
680 NSString* fixtures = @(flutter::testing::GetFixturesPath());
681 FlutterDartProject* project = [[FlutterDartProject alloc]
682 initWithAssetsPath:fixtures
683 ICUDataPath:[fixtures stringByAppendingString:@"/icudtl.dat"]];
684 FlutterEngine* engine = [[FlutterEngine alloc] initWithName:@"test"
685 project:project
686 allowHeadlessExecution:YES];
687 id<FlutterPluginRegistrar> registrar = [engine registrarForPlugin:@"MyPlugin"];
688 textureRegistry = registrar.textures;
689 }
690
691 // Once the engine has been deallocated, verify the weak engine pointer is nil, and thus not
692 // retained via the texture registry.
693 EXPECT_NE(textureRegistry, nil);
694 EXPECT_EQ(weakEngine, nil);
695 }

## ◆ TEST_F() [31/83]

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

Definition at line 1228 of file FlutterEngineTest.mm.

1228 {
1229 id<NSApplicationDelegate> previousDelegate = [[NSApplication sharedApplication] delegate];
1230 FakeLifecycleProvider* fakeAppDelegate = [[FakeLifecycleProvider alloc] init];
1231 [NSApplication sharedApplication].delegate = fakeAppDelegate;
1232
1233 FakeAppDelegatePlugin* plugin = [[FakeAppDelegatePlugin alloc] init];
1234 FlutterEngine* engine = CreateMockFlutterEngine(nil);
1235
1236 [[engine registrarForPlugin:@"TestPlugin"] addApplicationDelegate:plugin];
1237
1238 EXPECT_TRUE([fakeAppDelegate hasDelegate:plugin]);
1239
1240 [NSApplication sharedApplication].delegate = previousDelegate;
1241 }
FakeAppDelegatePlugin
Definition: FlutterEngineTest.mm:113
FakeLifecycleProvider
Definition: FlutterEngineTest.mm:71

References CreateMockFlutterEngine().

## ◆ TEST_F() [32/83]

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

Definition at line 1134 of file FlutterEngineTest.mm.

1134 {
1135 __block BOOL announced = NO;
1136 id engineMock = CreateMockFlutterEngine(nil);
1137
1138 OCMStub([engineMock announceAccessibilityMessage:[OCMArg any]
1139 withPriority:NSAccessibilityPriorityMedium])
1140 .andDo((^(NSInvocation* invocation) {
1141 announced = TRUE;
1142 [invocation retainArguments];
1143 NSString* message;
1144 [invocation getArgument:&message atIndex:2];
1145 EXPECT_EQ(message, @"error message");
1146 }));
1147
1148 NSDictionary<NSString*, id>* annotatedEvent =
1149 @{@"type" : @"announce",
1150 @"data" : @{@"message" : @"error message"}};
1151
1152 [engineMock handleAccessibilityEvent:annotatedEvent];
1153
1154 EXPECT_TRUE(announced);
1155 }

References CreateMockFlutterEngine().

## ◆ TEST_F() [33/83]

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

Definition at line 1157 of file FlutterEngineTest.mm.

1157 {
1158 __block flutter::AppLifecycleState sentState;
1159 id engineMock = CreateMockFlutterEngine(nil);
1160
1161 // Have to enumerate all the values because OCMStub can't capture
1162 // non-Objective-C object arguments.
1163 OCMStub([engineMock setApplicationState:flutter::AppLifecycleState::kDetached])
1164 .andDo((^(NSInvocation* invocation) {
1165 sentState = flutter::AppLifecycleState::kDetached;
1166 }));
1167 OCMStub([engineMock setApplicationState:flutter::AppLifecycleState::kResumed])
1168 .andDo((^(NSInvocation* invocation) {
1169 sentState = flutter::AppLifecycleState::kResumed;
1170 }));
1171 OCMStub([engineMock setApplicationState:flutter::AppLifecycleState::kInactive])
1172 .andDo((^(NSInvocation* invocation) {
1173 sentState = flutter::AppLifecycleState::kInactive;
1174 }));
1175 OCMStub([engineMock setApplicationState:flutter::AppLifecycleState::kHidden])
1176 .andDo((^(NSInvocation* invocation) {
1177 sentState = flutter::AppLifecycleState::kHidden;
1178 }));
1179 OCMStub([engineMock setApplicationState:flutter::AppLifecycleState::kPaused])
1180 .andDo((^(NSInvocation* invocation) {
1181 sentState = flutter::AppLifecycleState::kPaused;
1182 }));
1183
1184 __block NSApplicationOcclusionState visibility = NSApplicationOcclusionStateVisible;
1185 id mockApplication = OCMPartialMock([NSApplication sharedApplication]);
1186 OCMStub((NSApplicationOcclusionState)[mockApplication occlusionState])
1187 .andDo(^(NSInvocation* invocation) {
1188 [invocation setReturnValue:&visibility];
1189 });
1190
1191 NSNotification* willBecomeActive =
1192 [[NSNotification alloc] initWithName:NSApplicationWillBecomeActiveNotification
1193 object:nil
1194 userInfo:nil];
1195 NSNotification* willResignActive =
1196 [[NSNotification alloc] initWithName:NSApplicationWillResignActiveNotification
1197 object:nil
1198 userInfo:nil];
1199
1200 NSNotification* didChangeOcclusionState;
1201 didChangeOcclusionState =
1202 [[NSNotification alloc] initWithName:NSApplicationDidChangeOcclusionStateNotification
1203 object:nil
1204 userInfo:nil];
1205
1206 [engineMock handleDidChangeOcclusionState:didChangeOcclusionState];
1207 EXPECT_EQ(sentState, flutter::AppLifecycleState::kInactive);
1208
1209 [engineMock handleWillBecomeActive:willBecomeActive];
1210 EXPECT_EQ(sentState, flutter::AppLifecycleState::kResumed);
1211
1212 [engineMock handleWillResignActive:willResignActive];
1213 EXPECT_EQ(sentState, flutter::AppLifecycleState::kInactive);
1214
1215 visibility = 0;
1216 [engineMock handleDidChangeOcclusionState:didChangeOcclusionState];
1217 EXPECT_EQ(sentState, flutter::AppLifecycleState::kHidden);
1218
1219 [engineMock handleWillBecomeActive:willBecomeActive];
1220 EXPECT_EQ(sentState, flutter::AppLifecycleState::kHidden);
1221
1222 [engineMock handleWillResignActive:willResignActive];
1223 EXPECT_EQ(sentState, flutter::AppLifecycleState::kHidden);
1224
1225 [mockApplication stopMocking];
1226 }
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/83]

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

Definition at line 1040 of file FlutterEngineTest.mm.

1040 {
1041 id engineMock = CreateMockFlutterEngine(nil);
1042 __block NSString* nextResponse = @"exit";
1043 __block BOOL triedToTerminate = NO;
1044 FlutterEngineTerminationHandler* terminationHandler =
1045 [[FlutterEngineTerminationHandler alloc] initWithEngine:engineMock
1046 terminator:^(id sender) {
1047 triedToTerminate = TRUE;
1048 // Don't actually terminate, of course.
1049 }];
1050 OCMStub([engineMock terminationHandler]).andReturn(terminationHandler);
1051 id binaryMessengerMock = OCMProtocolMock(@protocol(FlutterBinaryMessenger));
1052 OCMStub( // NOLINT(google-objc-avoid-throwing-exception)
1053 [engineMock binaryMessenger])
1054 .andReturn(binaryMessengerMock);
1055 OCMStub([engineMock sendOnChannel:@"flutter/platform"
1056 message:[OCMArg any]
1057 binaryReply:[OCMArg any]])
1058 .andDo((^(NSInvocation* invocation) {
1059 [invocation retainArguments];
1060 FlutterBinaryReply callback;
1061 NSData* returnedMessage;
1062 [invocation getArgument:&callback atIndex:4];
1063 if ([nextResponse isEqualToString:@"error"]) {
1064 FlutterError* errorResponse = [FlutterError errorWithCode:@"Error"
1065 message:@"Failed"
1066 details:@"Details"];
1067 returnedMessage =
1068 [[FlutterJSONMethodCodec sharedInstance] encodeErrorEnvelope:errorResponse];
1069 } else {
1070 NSDictionary* responseDict = @{@"response" : nextResponse};
1071 returnedMessage =
1072 [[FlutterJSONMethodCodec sharedInstance] encodeSuccessEnvelope:responseDict];
1073 }
1074 callback(returnedMessage);
1075 }));
1076 __block NSString* calledAfterTerminate = @"";
1077 FlutterResult appExitResult = ^(id result) {
1078 NSDictionary* resultDict = result;
1079 calledAfterTerminate = resultDict[@"response"];
1080 };
1081 FlutterMethodCall* methodExitApplication =
1082 [FlutterMethodCall methodCallWithMethodName:@"System.exitApplication"
1083 arguments:@{@"type" : @"cancelable"}];
1084
1085 // Always terminate when the binding isn't ready (which is the default).
1086 triedToTerminate = NO;
1087 calledAfterTerminate = @"";
1088 nextResponse = @"cancel";
1089 [engineMock handleMethodCall:methodExitApplication result:appExitResult];
1090 EXPECT_STREQ([calledAfterTerminate UTF8String], "");
1091 EXPECT_TRUE(triedToTerminate);
1092
1093 // Once the binding is ready, handle the request.
1094 terminationHandler.acceptingRequests = YES;
1095 triedToTerminate = NO;
1096 calledAfterTerminate = @"";
1097 nextResponse = @"exit";
1098 [engineMock handleMethodCall:methodExitApplication result:appExitResult];
1099 EXPECT_STREQ([calledAfterTerminate UTF8String], "exit");
1100 EXPECT_TRUE(triedToTerminate);
1101
1102 triedToTerminate = NO;
1103 calledAfterTerminate = @"";
1104 nextResponse = @"cancel";
1105 [engineMock handleMethodCall:methodExitApplication result:appExitResult];
1106 EXPECT_STREQ([calledAfterTerminate UTF8String], "cancel");
1107 EXPECT_FALSE(triedToTerminate);
1108
1109 // Check that it doesn't crash on error.
1110 triedToTerminate = NO;
1111 calledAfterTerminate = @"";
1112 nextResponse = @"error";
1113 [engineMock handleMethodCall:methodExitApplication result:appExitResult];
1114 EXPECT_STREQ([calledAfterTerminate UTF8String], "");
1115 EXPECT_TRUE(triedToTerminate);
1116 }
FlutterBinaryReply
NS_ASSUME_NONNULL_BEGIN typedef void(^ FlutterBinaryReply)(NSData *_Nullable reply)
FlutterEngineTerminationHandler
Definition: FlutterEngine.mm:194
FlutterEngineTerminationHandler::acceptingRequests
BOOL acceptingRequests
Definition: FlutterEngine_Internal.h:63
+[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/83]

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

Definition at line 148 of file FlutterEngineTest.mm.

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

## ◆ TEST_F() [36/83]

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

Definition at line 825 of file FlutterEngineTest.mm.

825 {
826 id engineMock = CreateMockFlutterEngine(nil);
827
828 // Call hasStrings and expect it to be false.
829 __block bool calledAfterClear = false;
830 __block bool valueAfterClear;
831 FlutterResult resultAfterClear = ^(id result) {
832 calledAfterClear = true;
833 NSNumber* valueNumber = [result valueForKey:@"value"];
834 valueAfterClear = [valueNumber boolValue];
835 };
836 FlutterMethodCall* methodCallAfterClear =
837 [FlutterMethodCall methodCallWithMethodName:@"Clipboard.hasStrings" arguments:nil];
838 [engineMock handleMethodCall:methodCallAfterClear result:resultAfterClear];
839 EXPECT_TRUE(calledAfterClear);
840 EXPECT_FALSE(valueAfterClear);
841 }

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

## ◆ TEST_F() [37/83]

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

Definition at line 843 of file FlutterEngineTest.mm.

843 {
844 id engineMock = CreateMockFlutterEngine(@"some string");
845
846 // Call hasStrings and expect it to be true.
847 __block bool called = false;
848 __block bool value;
849 FlutterResult result = ^(id result) {
850 called = true;
851 NSNumber* valueNumber = [result valueForKey:@"value"];
852 value = [valueNumber boolValue];
853 };
854 FlutterMethodCall* methodCall =
855 [FlutterMethodCall methodCallWithMethodName:@"Clipboard.hasStrings" arguments:nil];
856 [engineMock handleMethodCall:methodCall result:result];
857 EXPECT_TRUE(called);
858 EXPECT_TRUE(value);
859 }

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

## ◆ TEST_F() [38/83]

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

Definition at line 1118 of file FlutterEngineTest.mm.

1118 {
1119 id<NSApplicationDelegate> previousDelegate = [[NSApplication sharedApplication] delegate];
1120 id<NSApplicationDelegate> plainDelegate = [[PlainAppDelegate alloc] init];
1121 [NSApplication sharedApplication].delegate = plainDelegate;
1122
1123 // Creating the engine shouldn't fail here, even though the delegate isn't a
1124 // FlutterAppDelegate.
1125 CreateMockFlutterEngine(nil);
1126
1127 // Asking to terminate the app should cancel.
1128 EXPECT_EQ([[[NSApplication sharedApplication] delegate] applicationShouldTerminate:NSApp],
1129 NSTerminateCancel);
1130
1131 [NSApplication sharedApplication].delegate = previousDelegate;
1132 }
PlainAppDelegate
Definition: FlutterEngineTest.mm:59

References CreateMockFlutterEngine().

## ◆ TEST_F() [39/83]

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

Definition at line 944 of file FlutterEngineTest.mm.

944 {
945 NSString* fixtures = @(flutter::testing::GetFixturesPath());
946 FlutterDartProject* project = [[FlutterDartProject alloc]
947 initWithAssetsPath:fixtures
948 ICUDataPath:[fixtures stringByAppendingString:@"/icudtl.dat"]];
949
950 FlutterEngine* engine;
951 FlutterViewController* viewController1;
952
953 @autoreleasepool {
954 // Create FVC1.
955 viewController1 = [[FlutterViewController alloc] initWithProject:project];
956 EXPECT_EQ(viewController1.viewIdentifier, 0ll);
957
958 engine = viewController1.engine;
959 engine.viewController = nil;
960
961 // Create FVC2 based on the same engine.
962 FlutterViewController* viewController2 = [[FlutterViewController alloc] initWithEngine:engine
963 nibName:nil
964 bundle:nil];
965 EXPECT_EQ(engine.viewController, viewController2);
966 }
967 // FVC2 is deallocated but FVC1 is retained.
968
969 EXPECT_EQ(engine.viewController, nil);
970
971 engine.viewController = viewController1;
972 EXPECT_EQ(engine.viewController, viewController1);
973 EXPECT_EQ(viewController1.viewIdentifier, 0ll);
974 }
FlutterViewController::viewIdentifier
FlutterViewIdentifier viewIdentifier
Definition: FlutterViewController.h:130

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

## ◆ TEST_F() [40/83]

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

Definition at line 976 of file FlutterEngineTest.mm.

976 {
977 // Don't create the engine with `CreateMockFlutterEngine`, because it adds
978 // additional references to FlutterViewControllers, which is crucial to this
979 // test case.
980 FlutterEngine* engine = [[FlutterEngine alloc] initWithName:@"io.flutter"
981 project:nil
982 allowHeadlessExecution:NO];
983 FlutterViewController* viewController1;
984
985 @autoreleasepool {
986 viewController1 = [[FlutterViewController alloc] initWithEngine:engine nibName:nil bundle:nil];
987 EXPECT_EQ(viewController1.viewIdentifier, 0ll);
988 EXPECT_EQ(engine.viewController, viewController1);
989
990 engine.viewController = nil;
991
992 FlutterViewController* viewController2 = [[FlutterViewController alloc] initWithEngine:engine
993 nibName:nil
994 bundle:nil];
995 EXPECT_EQ(viewController2.viewIdentifier, 0ll);
996 EXPECT_EQ(engine.viewController, viewController2);
997 }
998 // FVC2 is deallocated but FVC1 is retained.
999
1000 EXPECT_EQ(engine.viewController, nil);
1001
1002 engine.viewController = viewController1;
1003 EXPECT_EQ(engine.viewController, viewController1);
1004 EXPECT_EQ(viewController1.viewIdentifier, 0ll);
1005 }

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

## ◆ TEST_F() [41/83]

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

Definition at line 768 of file FlutterEngineTest.mm.

768 {
769 FlutterEngine* engine = GetFlutterEngine();
770 EXPECT_TRUE([engine runWithEntrypoint:@"main"]);
771
772 NSString* channel = @"_test_";
773 NSData* channel_data = [channel dataUsingEncoding:NSUTF8StringEncoding];
774
775 // Mock SendPlatformMessage so that if a message is sent to
776 // "test/send_message", act as if the framework has sent an empty message to
777 // the channel marked by the `sendOnChannel:message:` call's message.
778 engine.embedderAPI.SendPlatformMessage = MOCK_ENGINE_PROC(
779 SendPlatformMessage, ([](auto engine_, auto message_) {
780 if (strcmp(message_->channel, "test/send_message") == 0) {
781 // The simplest message that is acceptable to a method channel.
782 std::string message = R"|({"method": "a"})|";
783 std::string channel(reinterpret_cast<const char*>(message_->message),
784 message_->message_size);
785 reinterpret_cast<EmbedderEngine*>(engine_)
786 ->GetShell()
787 .GetPlatformView()
788 ->HandlePlatformMessage(std::make_unique<PlatformMessage>(
789 channel.c_str(), fml::MallocMapping::Copy(message.c_str(), message.length()),
790 fml::RefPtr<PlatformMessageResponse>()));
791 }
792 return kSuccess;
793 }));
794
795 __block int record = 0;
796
797 FlutterMethodChannel* channel1 =
798 [FlutterMethodChannel methodChannelWithName:channel
799 binaryMessenger:engine.binaryMessenger
800 codec:[FlutterJSONMethodCodec sharedInstance]];
801 [channel1 setMethodCallHandler:^(FlutterMethodCall* call, FlutterResult result) {
802 record += 1;
803 }];
804
805 [engine.binaryMessenger sendOnChannel:@"test/send_message" message:channel_data];
806 EXPECT_EQ(record, 1);
807
808 FlutterMethodChannel* channel2 =
809 [FlutterMethodChannel methodChannelWithName:channel
810 binaryMessenger:engine.binaryMessenger
811 codec:[FlutterJSONMethodCodec sharedInstance]];
812 [channel2 setMethodCallHandler:^(FlutterMethodCall* call, FlutterResult result) {
813 record += 10;
814 }];
815
816 [engine.binaryMessenger sendOnChannel:@"test/send_message" message:channel_data];
817 EXPECT_EQ(record, 11);
818
819 [channel1 setMethodCallHandler:nil];
820
821 [engine.binaryMessenger sendOnChannel:@"test/send_message" message:channel_data];
822 EXPECT_EQ(record, 21);
823 }
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/83]

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

Definition at line 188 of file FlutterEngineTest.mm.

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

## ◆ TEST_F() [43/83]

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

Definition at line 502 of file FlutterEngineTest.mm.

502 {
503 BOOL latch_called = NO;
504 AddNativeCallback("SignalNativeTest",
505 CREATE_NATIVE_ENTRY([&](Dart_NativeArguments args) { latch_called = YES; }));
506
507 FlutterEngine* engine = GetFlutterEngine();
508 EXPECT_TRUE([engine runWithEntrypoint:@"nativeCallback"]);
509 ASSERT_TRUE(engine.running);
510
511 while (!latch_called) {
512 CFRunLoopRunInMode(kCFRunLoopDefaultMode, 1, YES);
513 }
514 ASSERT_TRUE(latch_called);
515 }

## ◆ TEST_F() [44/83]

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

Definition at line 1285 of file FlutterEngineTest.mm.

1285 {
1286 BOOL updated = NO;
1287 FlutterEngine* engine = GetFlutterEngine();
1288 auto original_set_viewport_metrics = engine.embedderAPI.SendWindowMetricsEvent;
1289 engine.embedderAPI.SendWindowMetricsEvent = MOCK_ENGINE_PROC(
1290 SendWindowMetricsEvent,
1291 ([&updated, &original_set_viewport_metrics](auto engine, auto* window_metrics) {
1292 updated = YES;
1293 return original_set_viewport_metrics(engine, window_metrics);
1294 }));
1295
1296 EXPECT_TRUE([engine runWithEntrypoint:@"main"]);
1297
1298 updated = NO;
1299 [[NSNotificationCenter defaultCenter] postNotificationName:NSWindowDidChangeScreenNotification
1300 object:nil];
1301 // No VC.
1302 EXPECT_FALSE(updated);
1303
1304 FlutterViewController* viewController = [[FlutterViewController alloc] initWithEngine:engine
1305 nibName:nil
1306 bundle:nil];
1307 [viewController loadView];
1308 viewController.flutterView.frame = CGRectMake(0, 0, 800, 600);
1309
1310 [[NSNotificationCenter defaultCenter] postNotificationName:NSWindowDidChangeScreenNotification
1311 object:nil];
1312 EXPECT_TRUE(updated);
1313 }

## ◆ TEST_F() [45/83]

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

Definition at line 477 of file FlutterEngineTest.mm.

477 {
478 FlutterEngine* engine = GetFlutterEngine();
479 EXPECT_TRUE([engine runWithEntrypoint:@"main"]);
480
481 // Enable the semantics without attaching a view controller.
482 bool enabled_called = false;
483 engine.embedderAPI.UpdateSemanticsEnabled =
484 MOCK_ENGINE_PROC(UpdateSemanticsEnabled, ([&enabled_called](auto engine, bool enabled) {
485 enabled_called = enabled;
486 return kSuccess;
487 }));
488 engine.semanticsEnabled = YES;
489 EXPECT_TRUE(enabled_called);
490
491 EXPECT_EQ(engine.viewController, nil);
492
493 // Assign the view controller after enabling semantics
494 FlutterViewController* viewController = [[FlutterViewController alloc] initWithEngine:engine
495 nibName:nil
496 bundle:nil];
497 engine.viewController = viewController;
498
499 EXPECT_NE(viewController.accessibilityBridge.lock(), nullptr);
500 }

References FlutterEngine::viewController.

## ◆ TEST_F() [46/83]

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

Definition at line 697 of file FlutterEngineTest.mm.

697 {
698 NSString* fixtures = @(flutter::testing::GetFixturesPath());
699 FlutterDartProject* project = [[FlutterDartProject alloc]
700 initWithAssetsPath:fixtures
701 ICUDataPath:[fixtures stringByAppendingString:@"/icudtl.dat"]];
702 FlutterEngine* engine = [[FlutterEngine alloc] initWithName:@"test"
703 project:project
704 allowHeadlessExecution:YES];
705
706 EXPECT_EQ([engine valuePublishedByPlugin:@"NoSuchPlugin"], nil);
707 }

## ◆ TEST_F() [47/83]

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

Definition at line 709 of file FlutterEngineTest.mm.

709 {
710 NSString* fixtures = @(flutter::testing::GetFixturesPath());
711 FlutterDartProject* project = [[FlutterDartProject alloc]
712 initWithAssetsPath:fixtures
713 ICUDataPath:[fixtures stringByAppendingString:@"/icudtl.dat"]];
714 FlutterEngine* engine = [[FlutterEngine alloc] initWithName:@"test"
715 project:project
716 allowHeadlessExecution:YES];
717 NSString* pluginName = @"MyPlugin";
718 // Request the registarar to register the plugin as existing.
719 [engine registrarForPlugin:pluginName];
720
721 // The documented behavior is that a plugin that exists but hasn't published
722 // anything returns NSNull, rather than nil, as on iOS.
723 EXPECT_EQ([engine valuePublishedByPlugin:pluginName], [NSNull null]);
724 }

## ◆ TEST_F() [48/83]

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

Definition at line 726 of file FlutterEngineTest.mm.

726 {
727 NSString* fixtures = @(flutter::testing::GetFixturesPath());
728 FlutterDartProject* project = [[FlutterDartProject alloc]
729 initWithAssetsPath:fixtures
730 ICUDataPath:[fixtures stringByAppendingString:@"/icudtl.dat"]];
731 FlutterEngine* engine = [[FlutterEngine alloc] initWithName:@"test"
732 project:project
733 allowHeadlessExecution:YES];
734 NSString* pluginName = @"MyPlugin";
735 id<FlutterPluginRegistrar> registrar = [engine registrarForPlugin:pluginName];
736
737 NSString* firstValue = @"A published value";
738 NSArray* secondValue = @[ @"A different published value" ];
739
740 [registrar publish:firstValue];
741 EXPECT_EQ([engine valuePublishedByPlugin:pluginName], firstValue);
742
743 [registrar publish:secondValue];
744 EXPECT_EQ([engine valuePublishedByPlugin:pluginName], secondValue);
745 }

## ◆ TEST_F() [49/83]

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

Definition at line 747 of file FlutterEngineTest.mm.

747 {
748 NSString* fixtures = @(flutter::testing::GetFixturesPath());
749 FlutterDartProject* project = [[FlutterDartProject alloc]
750 initWithAssetsPath:fixtures
751 ICUDataPath:[fixtures stringByAppendingString:@"/icudtl.dat"]];
752 FlutterEngine* engine = [[FlutterEngine alloc] initWithName:@"test" project:project];
753
754 FlutterViewController* viewController = [[FlutterViewController alloc] initWithEngine:engine
755 nibName:nil
756 bundle:nil];
757 id<FlutterPluginRegistrar> registrar = [engine registrarForPlugin:@"MyPlugin"];
758
759 EXPECT_EQ([registrar viewController], viewController);
760 }

## ◆ TEST_F() [50/83]

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

Definition at line 1007 of file FlutterEngineTest.mm.

1007 {
1008 NSString* fixtures = @(flutter::testing::GetFixturesPath());
1009 FlutterDartProject* project = [[FlutterDartProject alloc]
1010 initWithAssetsPath:fixtures
1011 ICUDataPath:[fixtures stringByAppendingString:@"/icudtl.dat"]];
1012 FlutterEngine* engine = [[FlutterEngine alloc] initWithName:@"test" project:project];
1013
1014 FlutterViewController* viewController = [[FlutterViewController alloc] initWithEngine:engine
1015 nibName:nil
1016 bundle:nil];
1017 [viewController loadView];
1018 [viewController viewDidLoad];
1019 viewController.flutterView.frame = CGRectMake(0, 0, 800, 600);
1020
1021 EXPECT_TRUE([engine runWithEntrypoint:@"drawIntoAllViews"]);
1022 // Wait up to 1 second for Flutter to emit a frame.
1023 CFTimeInterval start = CACurrentMediaTime();
1024 while (engine.macOSCompositor->DebugNumViews() == 0) {
1025 CFRunLoopRunInMode(kCFRunLoopDefaultMode, 1, YES);
1026 if (CACurrentMediaTime() - start > 1) {
1027 break;
1028 }
1029 }
1030
1031 EXPECT_EQ(engine.macOSCompositor->DebugNumViews(), 1u);
1032
1033 engine.viewController = nil;
1034 EXPECT_EQ(engine.macOSCompositor->DebugNumViews(), 0u);
1035
1036 [engine shutDownEngine];
1037 engine = nil;
1038 }

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

## ◆ TEST_F() [51/83]

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

Definition at line 1343 of file FlutterEngineTest.mm.

1343 {
1344 __block BOOL expectedValue;
1345
1346 // Set up mocks.
1347 id channelMock = OCMClassMock([FlutterBasicMessageChannel class]);
1348 OCMStub([channelMock messageChannelWithName:@"flutter/settings"
1349 binaryMessenger:[OCMArg any]
1350 codec:[OCMArg any]])
1351 .andReturn(channelMock);
1352 OCMStub([channelMock sendMessage:[OCMArg any]]).andDo((^(NSInvocation* invocation) {
1353 __weak id message;
1354 [invocation getArgument:&message atIndex:2];
1355 EXPECT_EQ(message[@"alwaysUse24HourFormat"], @(expectedValue));
1356 }));
1357
1358 id mockHourFormat = OCMClassMock([FlutterHourFormat class]);
1359 OCMStub([mockHourFormat isAlwaysUse24HourFormat]).andDo((^(NSInvocation* invocation) {
1360 [invocation setReturnValue:&expectedValue];
1361 }));
1362
1363 id engineMock = CreateMockFlutterEngine(nil);
1364
1365 // Verify the YES case.
1366 expectedValue = YES;
1367 EXPECT_TRUE([engineMock runWithEntrypoint:@"main"]);
1368 [engineMock shutDownEngine];
1369
1370 // Verify the NO case.
1371 expectedValue = NO;
1372 EXPECT_TRUE([engineMock runWithEntrypoint:@"main"]);
1373 [engineMock shutDownEngine];
1374
1375 // Clean up mocks.
1376 [mockHourFormat stopMocking];
1377 [engineMock stopMocking];
1378 [channelMock stopMocking];
1379 }
FlutterBasicMessageChannel
Definition: FlutterChannels.h:38
FlutterHourFormat
Definition: FlutterHourFormat.h:11

References CreateMockFlutterEngine().

## ◆ TEST_F() [52/83]

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

Definition at line 930 of file FlutterEngineTest.mm.

930 {
931 FlutterResizeSynchronizer* threadSynchronizer = [[FlutterResizeSynchronizer alloc] init];
932 [threadSynchronizer shutDown];
933
934 std::thread rasterThread([&threadSynchronizer] {
935 [threadSynchronizer performCommitForSize:CGSizeMake(100, 100)
936 afterDelay:0
937 notify:^{
938 }];
939 });
940
941 rasterThread.join();
942 }

## ◆ TEST_F() [53/83]

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

Definition at line 861 of file FlutterEngineTest.mm.

861 {
862 FlutterEngine* engine = GetFlutterEngine();
863 FlutterBasicMessageChannel* channel = [[FlutterBasicMessageChannel alloc]
864 initWithName:@"foo"
865 binaryMessenger:engine.binaryMessenger
866 codec:[FlutterStandardMessageCodec sharedInstance]];
867 __block BOOL didCallCallback = NO;
868 [channel setMessageHandler:^(id message, FlutterReply callback) {
869 ShutDownEngine();
870 callback(nil);
871 didCallCallback = YES;
872 }];
873 EXPECT_TRUE([engine runWithEntrypoint:@"sendFooMessage"]);
874 engine = nil;
875
876 while (!didCallCallback) {
877 [[NSRunLoop currentRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:0.1]];
878 }
879 }
-[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() [54/83]

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

Definition at line 881 of file FlutterEngineTest.mm.

881 {
882 FlutterEngine* engine = GetFlutterEngine();
883 FlutterBasicMessageChannel* channel = [[FlutterBasicMessageChannel alloc]
884 initWithName:@"foo"
885 binaryMessenger:engine.binaryMessenger
886 codec:[FlutterStandardMessageCodec sharedInstance]];
887 __block BOOL didCallCallback = NO;
888 [channel setMessageHandler:^(id message, FlutterReply callback) {
889 dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
890 callback(nil);
891 dispatch_async(dispatch_get_main_queue(), ^{
892 didCallCallback = YES;
893 });
894 });
895 }];
896 EXPECT_TRUE([engine runWithEntrypoint:@"sendFooMessage"]);
897
898 while (!didCallCallback) {
899 [[NSRunLoop currentRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:0.1]];
900 }
901 }

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

## ◆ TEST_F() [55/83]

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

Definition at line 1264 of file FlutterEngineTest.mm.

1264 {
1265 BOOL updated = NO;
1266 FlutterEngine* engine = GetFlutterEngine();
1267 auto original_update_displays = engine.embedderAPI.NotifyDisplayUpdate;
1268 engine.embedderAPI.NotifyDisplayUpdate = MOCK_ENGINE_PROC(
1269 NotifyDisplayUpdate, ([&updated, &original_update_displays](
1270 auto engine, auto update_type, auto* displays, auto display_count) {
1271 updated = YES;
1272 return original_update_displays(engine, update_type, displays, display_count);
1273 }));
1274
1275 EXPECT_TRUE([engine runWithEntrypoint:@"main"]);
1276 EXPECT_TRUE(updated);
1277
1278 updated = NO;
1279 [[NSNotificationCenter defaultCenter]
1280 postNotificationName:NSApplicationDidChangeScreenParametersNotification
1281 object:nil];
1282 EXPECT_TRUE(updated);
1283 }

## ◆ TEST_F() [56/83]

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

Definition at line 171 of file FlutterEngineTest.mm.

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

## ◆ TEST_F() [57/83]

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

Definition at line 1243 of file FlutterEngineTest.mm.

1243 {
1244 id<NSApplicationDelegate> previousDelegate = [[NSApplication sharedApplication] delegate];
1245 FakeLifecycleProvider* fakeAppDelegate = [[FakeLifecycleProvider alloc] init];
1246 [NSApplication sharedApplication].delegate = fakeAppDelegate;
1247
1248 FakeAppDelegatePlugin* plugin = [[FakeAppDelegatePlugin alloc] init];
1249
1250 @autoreleasepool {
1251 FlutterEngine* engine = [[FlutterEngine alloc] initWithName:@"test" project:nil];
1252
1253 [[engine registrarForPlugin:@"TestPlugin"] addApplicationDelegate:plugin];
1254 EXPECT_TRUE([fakeAppDelegate hasDelegate:plugin]);
1255 }
1256
1257 // When the engine is released, it should unregister any plugins it had
1258 // registered on its behalf.
1259 EXPECT_FALSE([fakeAppDelegate hasDelegate:plugin]);
1260
1261 [NSApplication sharedApplication].delegate = previousDelegate;
1262 }

## ◆ TEST_F() [58/83]

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

Definition at line 90 of file FlutterMenuPluginTest.mm.

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

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() [60/83]

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() [61/83]

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() [62/83]

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() [63/83]

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() [64/83]

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() [65/83]

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() [66/83]

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() [67/83]

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() [68/83]

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() [69/83]

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() [70/83]

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() [71/83]

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() [72/83]

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() [73/83]

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() [74/83]

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() [75/83]

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() [76/83]

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

Definition at line 336 of file FlutterViewControllerTest.mm.

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

## ◆ TEST_F() [77/83]

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

Definition at line 340 of file FlutterViewControllerTest.mm.

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

## ◆ TEST_F() [78/83]

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

Definition at line 344 of file FlutterViewControllerTest.mm.

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

## ◆ TEST_F() [79/83]

flutter::testing::TEST_F | ( | FlutterWindowControllerRetainTest | ,
|  | WindowControllerDoesNotRetainEngine |
| ) |  |

Definition at line 81 of file FlutterWindowControllerTest.mm.

81 {
82 FlutterWindowCreationRequest request{
83 .contentSize = {.has_size = true, .width = 800, .height = 600},
84 .on_close = [] {},
85 .on_size_change = [] {},
86 };
87
88 __weak FlutterEngine* weakEngine = nil;
89 @autoreleasepool {
90 NSString* fixtures = @(flutter::testing::GetFixturesPath());
91 NSLog(@"Fixtures path: %@", fixtures);
92 FlutterDartProject* project = [[FlutterDartProject alloc]
93 initWithAssetsPath:fixtures
94 ICUDataPath:[fixtures stringByAppendingString:@"/icudtl.dat"]];
95
96 static std::optional<flutter::Isolate> isolate;
97 isolate = std::nullopt;
98
99 project.rootIsolateCreateCallback = [](void*) { isolate = flutter::Isolate::Current(); };
100 FlutterEngine* engine = [[FlutterEngine alloc] initWithName:@"test"
101 project:project
102 allowHeadlessExecution:YES];
103 weakEngine = engine;
104 [engine runWithEntrypoint:@"testWindowControllerRetainCycle"];
105
106 int64_t engineId = reinterpret_cast<int64_t>(engine);
107
108 {
109 FML_DCHECK(isolate.has_value());
110 // NOLINTNEXTLINE(bugprone-unchecked-optional-access)
111 IsolateScope isolateScope(*isolate);
112 int64_t handle = InternalFlutter_WindowController_CreateRegularWindow(engineId, &request);
113 EXPECT_EQ(handle, 1);
114 }
115
116 [engine.windowController closeAllWindows];
117 [engine shutDownEngine];
118 }
119 EXPECT_EQ(weakEngine, nil);
120 }
InternalFlutter_WindowController_CreateRegularWindow
FLUTTER_DARWIN_EXPORT int64_t InternalFlutter_WindowController_CreateRegularWindow(int64_t engine_id, const FlutterWindowCreationRequest *request)
Definition: FlutterWindowController.mm:181
flutter::Isolate::Current
static Isolate Current()
Definition: isolate_scope.cc:9
FlutterWindowCreationRequest
Definition: FlutterWindowController.h:38
FlutterWindowCreationRequest::contentSize
FlutterWindowSizing contentSize
Definition: FlutterWindowController.h:39
FlutterWindowSizing::has_size
bool has_size
Definition: FlutterWindowController.h:28

References FlutterWindowCreationRequest::contentSize, flutter::Isolate::Current(), FlutterWindowSizing::has_size, and InternalFlutter_WindowController_CreateRegularWindow().

## ◆ TEST_F() [80/83]

flutter::testing::TEST_F | ( | FlutterWindowControllerTest | ,
|  | CreateRegularWindow |
| ) |  |

Definition at line 58 of file FlutterWindowControllerTest.mm.

58 {
59 FlutterWindowCreationRequest request{
60 .contentSize = {.has_size = true, .width = 800, .height = 600},
61 .on_close = [] {},
62 .on_size_change = [] {},
63 };
64
65 FlutterEngine* engine = GetFlutterEngine();
66 int64_t engineId = reinterpret_cast<int64_t>(engine);
67
68 {
69 IsolateScope isolate_scope(isolate());
70 int64_t handle = InternalFlutter_WindowController_CreateRegularWindow(engineId, &request);
71 EXPECT_EQ(handle, 1);
72
73 FlutterViewController* viewController = [engine viewControllerForIdentifier:handle];
74 EXPECT_NE(viewController, nil);
75 CGSize size = viewController.view.frame.size;
76 EXPECT_EQ(size.width, 800);
77 EXPECT_EQ(size.height, 600);
78 }
79 }

References FlutterWindowCreationRequest::contentSize, FlutterWindowSizing::has_size, and InternalFlutter_WindowController_CreateRegularWindow().

## ◆ TEST_F() [81/83]

flutter::testing::TEST_F | ( | FlutterWindowControllerTest | ,
|  | DestroyRegularWindow |
| ) |  |

Definition at line 122 of file FlutterWindowControllerTest.mm.

122 {
123 FlutterWindowCreationRequest request{
124 .contentSize = {.has_size = true, .width = 800, .height = 600},
125 .on_close = [] {},
126 .on_size_change = [] {},
127 };
128
129 FlutterEngine* engine = GetFlutterEngine();
130 int64_t engine_id = reinterpret_cast<int64_t>(engine);
131
132 IsolateScope isolate_scope(isolate());
133 int64_t handle = InternalFlutter_WindowController_CreateRegularWindow(engine_id, &request);
134 FlutterViewController* viewController = [engine viewControllerForIdentifier:handle];
135
136 InternalFlutter_Window_Destroy(engine_id, (__bridge void*)viewController.view.window);
137 viewController = [engine viewControllerForIdentifier:handle];
138 EXPECT_EQ(viewController, nil);
139 }
InternalFlutter_Window_Destroy
FLUTTER_DARWIN_EXPORT void InternalFlutter_Window_Destroy(int64_t engine_id, void *window)
Definition: FlutterWindowController.mm:189

References FlutterWindowCreationRequest::contentSize, FlutterWindowSizing::has_size, InternalFlutter_Window_Destroy(), and InternalFlutter_WindowController_CreateRegularWindow().

## ◆ TEST_F() [82/83]

flutter::testing::TEST_F | ( | FlutterWindowControllerTest | ,
|  | InternalFlutter_Window_GetHandle |
| ) |  |

Definition at line 141 of file FlutterWindowControllerTest.mm.

141 {
142 FlutterWindowCreationRequest request{
143 .contentSize = {.has_size = true, .width = 800, .height = 600},
144 .on_close = [] {},
145 .on_size_change = [] {},
146 };
147
148 FlutterEngine* engine = GetFlutterEngine();
149 int64_t engine_id = reinterpret_cast<int64_t>(engine);
150
151 IsolateScope isolate_scope(isolate());
152 int64_t handle = InternalFlutter_WindowController_CreateRegularWindow(engine_id, &request);
153 FlutterViewController* viewController = [engine viewControllerForIdentifier:handle];
154
155 void* window_handle = InternalFlutter_Window_GetHandle(engine_id, handle);
156 EXPECT_EQ(window_handle, (__bridge void*)viewController.view.window);
157 }
InternalFlutter_Window_GetHandle
FLUTTER_DARWIN_EXPORT void * InternalFlutter_Window_GetHandle(int64_t engine_id, FlutterViewIdentifier view_id)
Definition: FlutterWindowController.mm:195

References FlutterWindowCreationRequest::contentSize, FlutterWindowSizing::has_size, InternalFlutter_Window_GetHandle(), and InternalFlutter_WindowController_CreateRegularWindow().

## ◆ TEST_F() [83/83]

flutter::testing::TEST_F | ( | FlutterWindowControllerTest | ,
|  | WindowStates |
| ) |  |

Definition at line 159 of file FlutterWindowControllerTest.mm.

159 {
160 FlutterWindowCreationRequest request{
161 .contentSize = {.has_size = true, .width = 800, .height = 600},
162 .on_close = [] {},
163 .on_size_change = [] {},
164 };
165
166 FlutterEngine* engine = GetFlutterEngine();
167 int64_t engine_id = reinterpret_cast<int64_t>(engine);
168
169 IsolateScope isolate_scope(isolate());
170 int64_t handle = InternalFlutter_WindowController_CreateRegularWindow(engine_id, &request);
171
172 FlutterViewController* viewController = [engine viewControllerForIdentifier:handle];
173 NSWindow* window = viewController.view.window;
174 void* windowHandle = (__bridge void*)window;
175
176 EXPECT_EQ(window.zoomed, NO);
177 EXPECT_EQ(window.miniaturized, NO);
178 EXPECT_EQ(window.styleMask & NSWindowStyleMaskFullScreen, 0u);
179
180 InternalFlutter_Window_SetMaximized(windowHandle, true);
181 CFRunLoopRunInMode(kCFRunLoopDefaultMode, 0.5, false);
182 EXPECT_EQ(window.zoomed, YES);
183
184 InternalFlutter_Window_SetMaximized(windowHandle, false);
185 CFRunLoopRunInMode(kCFRunLoopDefaultMode, 0.5, false);
186 EXPECT_EQ(window.zoomed, NO);
187
188 // FullScreen toggle does not seem to work when the application is not run from a bundle.
189
190 InternalFlutter_Window_Minimize(windowHandle);
191 CFRunLoopRunInMode(kCFRunLoopDefaultMode, 0.5, false);
192 EXPECT_EQ(window.miniaturized, YES);
193 }
InternalFlutter_Window_SetMaximized
FLUTTER_DARWIN_EXPORT void InternalFlutter_Window_SetMaximized(void *window, bool maximized)
Definition: FlutterWindowController.mm:219
InternalFlutter_Window_Minimize
FLUTTER_DARWIN_EXPORT void InternalFlutter_Window_Minimize(void *window)
Definition: FlutterWindowController.mm:233

References FlutterWindowCreationRequest::contentSize, FlutterWindowSizing::has_size, InternalFlutter_Window_Minimize(), InternalFlutter_Window_SetMaximized(), and InternalFlutter_WindowController_CreateRegularWindow().

## Variable Documentation

## ◆ kEmptyFlags

FlutterSemanticsFlags flutter::testing::kEmptyFlags = FlutterSemanticsFlags{}

Definition at line 18 of file accessibility_bridge_unittests.cc.

Referenced by CreateSemanticsNode().