Flutter macOS Embedder
flutter::testing Namespace Reference

Classes

class  FlutterEngineTest
 
class  MockFlutterEngineTest
 
class  FlutterMenuPluginTest
 
class  FlutterWindowControllerTest
 
class  FlutterWindowControllerRetainTest
 
class  FlutterWindowControllerSizeTest
 

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, EnableSDFsAlwaysReturnsYes)
 
 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, RegistrarCanReadValuePublishedByAnotherPlugin)
 
 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, DisabledTextFieldDoesNotUseFlutterTextField)
 
 TEST (FlutterPlatformNodeDelegateMac, ChangingFlagsUpdatesNativeViewAccessible)
 
 TEST (FlutterPlatformViewController, TestCreatePlatformViewNoMatchingViewType)
 
 TEST (FlutterPlatformViewController, TestCreatePlatformViewInvalidViewType)
 
 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, BOOL enableWideGamut=NO)
 
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 (FlutterSurfaceManager, WideGamutSurfaceHasCorrectPixelFormat)
 
 TEST (FlutterSurfaceManager, StandardGamutSurfaceHasCorrectPixelFormat)
 
 TEST (FlutterSurfaceManager, WideGamutLayerWorksWithoutExplicitContentsFormat)
 
 TEST (FlutterSurfaceManager, WideGamutIOSurfaceHasCorrectColorSpace)
 
 TEST (FlutterSurfaceManager, StandardGamutIOSurfaceHasCorrectColorSpace)
 
 TEST (FlutterSurfaceManager, WideGamutIOSurfaceHasCorrectPixelFormat)
 
 TEST (FlutterSurfaceManager, StandardGamutIOSurfaceHasCorrectPixelFormat)
 
 TEST (FlutterSurfaceManager, WideGamutIOSurfaceHasCorrectBytesPerElement)
 
 TEST (FlutterSurfaceManager, StandardGamutIOSurfaceHasCorrectBytesPerElement)
 
 TEST (FlutterSurfaceManager, SurfaceCacheDoesNotMixGamutModes)
 
 TEST (FlutterSurfaceManager, DynamicSwitchFromStandardToWideGamut)
 
 TEST (FlutterSurfaceManager, DynamicSwitchFromWideToStandardGamut)
 
 TEST (FlutterSurfaceManager, DynamicSwitchNoOpWhenSameValue)
 
 TEST (FlutterTextInputPluginTest, TestEmptyCompositionRange)
 
 TEST (FlutterTextInputPluginTest, TestSetMarkedTextWithSelectionChange)
 
 TEST (FlutterTextInputPluginTest, TestSetMarkedTextWithReplacementRange)
 
 TEST (FlutterTextInputPluginTest, TestSetMarkedTextWithSelectedRangeNotFound)
 
 TEST (FlutterTextInputPluginTest, TestSetMarkedTextWithOutOfBoundsRanges)
 
 TEST (FlutterTextInputPluginTest, TestSetEditingStateWithOutOfBoundsSelection)
 
 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, InsertTextWithReversedReplacementRange)
 
 TEST (FlutterTextInputPluginTest, InsertTextHandlesEmptyAttributedString)
 
 TEST (FlutterTextInputPluginTest, WillUseParentControllerIfCanNotBecomeKey)
 
 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, FixMoveRunLoopMode)
 
 TEST_F (FlutterWindowControllerTest, CreateRegularWindow)
 
 TEST_F (FlutterWindowControllerTest, CreateTooltipWindow)
 
 TEST_F (FlutterWindowControllerTest, CreatePopupWindow)
 
 TEST_F (FlutterWindowControllerRetainTest, WindowControllerDoesNotRetainEngine)
 
 TEST_F (FlutterWindowControllerTest, DestroyRegularWindow)
 
 TEST_F (FlutterWindowControllerTest, InternalFlutterWindowGetHandle)
 
 TEST_F (FlutterWindowControllerTest, WindowStates)
 
 TEST_F (FlutterWindowControllerTest, ClosesAllWindowsOnEngineRestart)
 
 TEST_F (FlutterWindowControllerTest, ViewMetricsRespectPositionCallbackConstraints)
 
 TEST_F (FlutterWindowControllerTest, GetOffsetInParent)
 
 TEST_F (FlutterWindowControllerSizeTest, SizedToContentResizable)
 
 TEST_F (FlutterWindowControllerSizeTest, SizedToContentNotResizable)
 
 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, DisabledButtonHasDisabledRestriction)
 
 TEST (AccessibilityBridgeTest, EnabledButtonHasNoRestriction)
 
 TEST (AccessibilityBridgeTest, ReadOnlyTextFieldHasReadOnlyRestriction)
 
 TEST (AccessibilityBridgeTest, ReadOnlyTextFieldHasTextFieldRole)
 
 TEST (AccessibilityBridgeTest, EditableTextFieldHasTextFieldRole)
 
 TEST (AccessibilityBridgeTest, CanSetCheckboxChecked)
 
 TEST (AccessibilityBridgeTest, CanReparentNode)
 
 TEST (AccessibilityBridgeTest, CanReparentMultipleNodes)
 
 TEST (AccessibilityBridgeTest, CanReparentNodeWithChild)
 
 TEST (AccessibilityBridgeTest, AXTreeManagerTest)
 
 TEST (AccessibilityBridgeTest, LineBreakingObjectTest)
 
 TEST (AccessibilityBridgeTest, IsSelectedAttribute)
 
 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

const CFAbsoluteTime kTestTimeout = 30.0
 
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

◆ FlutterViewControllerTest

using flutter::testing::FlutterViewControllerTest = typedef AutoreleasePoolTest

Definition at line 192 of file FlutterViewControllerTest.mm.

Function Documentation

◆ CreateMockFlutterEngine()

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

Definition at line 80 of file FlutterEngineTestUtils.mm.

80  {
81  NSString* fixtures = @(testing::GetFixturesPath());
82  FlutterDartProject* project = [[FlutterDartProject alloc]
83  initWithAssetsPath:fixtures
84  ICUDataPath:[fixtures stringByAppendingString:@"/icudtl.dat"]];
85  FlutterEngine* engine = [[FlutterEngine alloc] initWithName:@"test"
86  project:project
87  allowHeadlessExecution:true];
88 
89  FakePasteboard* pasteboardMock = [[FakePasteboard alloc] init];
90  [pasteboardMock setString:pasteboardString forType:NSPasteboardTypeString];
91  engine.pasteboard = pasteboardMock;
92  id engineMock = OCMPartialMock(engine);
93  return engineMock;
94 }

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 }

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 54 of file FlutterSurfaceManagerTest.mm.

58  {}) {
60  res.surface = surface;
61  res.offset = offset;
62  res.zIndex = index;
63  res.paintRegion = paintRegion;
64  return res;
65 }
std::vector< FlutterRect > paintRegion

◆ 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 }
FlutterSemanticsFlags kEmptyFlags

References kEmptyFlags.

Referenced by TEST().

◆ CreateSurfaceManager()

static FlutterSurfaceManager* flutter::testing::CreateSurfaceManager ( TestView *  testView,
BOOL  enableWideGamut = NO 
)
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  wideGamut:enableWideGamut];
52 }

Referenced by TEST().

◆ operator==()

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

Definition at line 201 of file FlutterSurfaceManagerTest.mm.

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

◆ TEST() [1/148]

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

Definition at line 79 of file accessibility_bridge_unittests.cc.

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

References CreateSemanticsNode().

◆ TEST() [2/148]

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

Definition at line 116 of file accessibility_bridge_unittests.cc.

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

References CreateSemanticsNode().

◆ TEST() [3/148]

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

Definition at line 655 of file accessibility_bridge_unittests.cc.

655  {
656  std::shared_ptr<TestAccessibilityBridge> bridge =
657  std::make_shared<TestAccessibilityBridge>();
658 
659  ui::AXTreeID tree_id = bridge->GetTreeID();
660  ui::AXTreeManager* manager =
661  ui::AXTreeManagerMap::GetInstance().GetManager(tree_id);
662  ASSERT_EQ(manager, static_cast<ui::AXTreeManager*>(bridge.get()));
663 }

◆ TEST() [4/148]

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  root.identifier = "identifier";
52  FlutterSemanticsNode2 child1 = CreateSemanticsNode(1, "child 1");
53  FlutterSemanticsNode2 child2 = CreateSemanticsNode(2, "child 2");
54 
55  bridge->AddFlutterSemanticsNodeUpdate(root);
56  bridge->AddFlutterSemanticsNodeUpdate(child1);
57  bridge->AddFlutterSemanticsNodeUpdate(child2);
58  bridge->CommitUpdates();
59 
60  auto root_node = bridge->GetFlutterPlatformNodeDelegateFromID(0).lock();
61  auto child1_node = bridge->GetFlutterPlatformNodeDelegateFromID(1).lock();
62  auto child2_node = bridge->GetFlutterPlatformNodeDelegateFromID(2).lock();
63  EXPECT_EQ(root_node->GetChildCount(), 2);
64  EXPECT_EQ(root_node->GetData().child_ids[0], 1);
65  EXPECT_EQ(root_node->GetData().child_ids[1], 2);
66  EXPECT_EQ(root_node->GetName(), "root");
67  EXPECT_EQ(root_node->GetAuthorUniqueId(), u"identifier");
68 
69  EXPECT_EQ(child1_node->GetChildCount(), 0);
70  EXPECT_EQ(child1_node->GetName(), "child 1");
71 
72  EXPECT_EQ(child2_node->GetChildCount(), 0);
73  EXPECT_EQ(child2_node->GetName(), "child 2");
74 }

References CreateSemanticsNode().

◆ TEST() [5/148]

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

Definition at line 167 of file accessibility_bridge_unittests.cc.

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

References CreateSemanticsNode().

◆ TEST() [6/148]

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

Definition at line 215 of file accessibility_bridge_unittests.cc.

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

References CreateSemanticsNode().

◆ TEST() [7/148]

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

Definition at line 481 of file accessibility_bridge_unittests.cc.

481  {
482  std::shared_ptr<TestAccessibilityBridge> bridge =
483  std::make_shared<TestAccessibilityBridge>();
484 
485  int32_t root_id = 0;
486  int32_t intermediary1_id = 1;
487  int32_t intermediary2_id = 2;
488  int32_t leaf1_id = 3;
489  int32_t leaf2_id = 4;
490  int32_t leaf3_id = 5;
491 
492  std::vector<int32_t> root_children{intermediary1_id, intermediary2_id};
493  std::vector<int32_t> intermediary1_children{leaf1_id};
494  std::vector<int32_t> intermediary2_children{leaf2_id, leaf3_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 = CreateSemanticsNode(
500  intermediary2_id, "intermediary 2", &intermediary2_children);
501  FlutterSemanticsNode2 leaf1 = CreateSemanticsNode(leaf1_id, "leaf 1");
502  FlutterSemanticsNode2 leaf2 = CreateSemanticsNode(leaf2_id, "leaf 2");
503  FlutterSemanticsNode2 leaf3 = CreateSemanticsNode(leaf3_id, "leaf 3");
504 
505  bridge->AddFlutterSemanticsNodeUpdate(root);
506  bridge->AddFlutterSemanticsNodeUpdate(intermediary1);
507  bridge->AddFlutterSemanticsNodeUpdate(intermediary2);
508  bridge->AddFlutterSemanticsNodeUpdate(leaf1);
509  bridge->AddFlutterSemanticsNodeUpdate(leaf2);
510  bridge->AddFlutterSemanticsNodeUpdate(leaf3);
511  bridge->CommitUpdates();
512  bridge->accessibility_events.clear();
513 
514  // Swap intermediary 1's and intermediary2's children.
515  int32_t new_intermediary1_children[] = {leaf2_id, leaf3_id};
516  intermediary1.child_count = 2;
517  intermediary1.children_in_traversal_order = new_intermediary1_children;
518 
519  int32_t new_intermediary2_children[] = {leaf1_id};
520  intermediary2.child_count = 1;
521  intermediary2.children_in_traversal_order = new_intermediary2_children;
522 
523  bridge->AddFlutterSemanticsNodeUpdate(intermediary1);
524  bridge->AddFlutterSemanticsNodeUpdate(intermediary2);
525  bridge->AddFlutterSemanticsNodeUpdate(leaf1);
526  bridge->AddFlutterSemanticsNodeUpdate(leaf2);
527  bridge->AddFlutterSemanticsNodeUpdate(leaf3);
528  bridge->CommitUpdates();
529 
530  auto root_node = bridge->GetFlutterPlatformNodeDelegateFromID(root_id).lock();
531  auto intermediary1_node =
532  bridge->GetFlutterPlatformNodeDelegateFromID(intermediary1_id).lock();
533  auto intermediary2_node =
534  bridge->GetFlutterPlatformNodeDelegateFromID(intermediary2_id).lock();
535  auto leaf1_node =
536  bridge->GetFlutterPlatformNodeDelegateFromID(leaf1_id).lock();
537  auto leaf2_node =
538  bridge->GetFlutterPlatformNodeDelegateFromID(leaf2_id).lock();
539  auto leaf3_node =
540  bridge->GetFlutterPlatformNodeDelegateFromID(leaf3_id).lock();
541 
542  EXPECT_EQ(root_node->GetChildCount(), 2);
543  EXPECT_EQ(root_node->GetData().child_ids[0], intermediary1_id);
544  EXPECT_EQ(root_node->GetData().child_ids[1], intermediary2_id);
545  EXPECT_EQ(root_node->GetName(), "root");
546 
547  EXPECT_EQ(intermediary1_node->GetChildCount(), 2);
548  EXPECT_EQ(intermediary1_node->GetData().child_ids[0], leaf2_id);
549  EXPECT_EQ(intermediary1_node->GetData().child_ids[1], leaf3_id);
550  EXPECT_EQ(intermediary1_node->GetName(), "intermediary 1");
551 
552  EXPECT_EQ(intermediary2_node->GetChildCount(), 1);
553  EXPECT_EQ(intermediary2_node->GetData().child_ids[0], leaf1_id);
554  EXPECT_EQ(intermediary2_node->GetName(), "intermediary 2");
555 
556  EXPECT_EQ(leaf1_node->GetChildCount(), 0);
557  EXPECT_EQ(leaf1_node->GetName(), "leaf 1");
558 
559  EXPECT_EQ(leaf2_node->GetChildCount(), 0);
560  EXPECT_EQ(leaf2_node->GetName(), "leaf 2");
561 
562  EXPECT_EQ(leaf3_node->GetChildCount(), 0);
563  EXPECT_EQ(leaf3_node->GetName(), "leaf 3");
564 
565  // Intermediary 1 and intermediary 2 have new children.
566  // Leaf 1, 2, and 3 are all moved.
567  ASSERT_EQ(bridge->accessibility_events.size(), size_t{5});
568  EXPECT_THAT(bridge->accessibility_events,
569  Contains(ui::AXEventGenerator::Event::CHILDREN_CHANGED).Times(2));
570  EXPECT_THAT(bridge->accessibility_events,
571  Contains(ui::AXEventGenerator::Event::SUBTREE_CREATED).Times(3));
572 }

References CreateSemanticsNode().

◆ TEST() [8/148]

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

Definition at line 418 of file accessibility_bridge_unittests.cc.

418  {
419  std::shared_ptr<TestAccessibilityBridge> bridge =
420  std::make_shared<TestAccessibilityBridge>();
421 
422  std::vector<int32_t> root_children{1};
423  std::vector<int32_t> child1_children{2};
424  FlutterSemanticsNode2 root = CreateSemanticsNode(0, "root", &root_children);
425  FlutterSemanticsNode2 child1 =
426  CreateSemanticsNode(1, "child 1", &child1_children);
427  FlutterSemanticsNode2 child2 = CreateSemanticsNode(2, "child 2");
428 
429  bridge->AddFlutterSemanticsNodeUpdate(root);
430  bridge->AddFlutterSemanticsNodeUpdate(child1);
431  bridge->AddFlutterSemanticsNodeUpdate(child2);
432  bridge->CommitUpdates();
433  bridge->accessibility_events.clear();
434 
435  // Reparent child2 from child1 to the root.
436  child1.child_count = 0;
437  child1.children_in_traversal_order = nullptr;
438 
439  int32_t new_root_children[] = {1, 2};
440  root.child_count = 2;
441  root.children_in_traversal_order = new_root_children;
442 
443  bridge->AddFlutterSemanticsNodeUpdate(root);
444  bridge->AddFlutterSemanticsNodeUpdate(child1);
445  bridge->AddFlutterSemanticsNodeUpdate(child2);
446  bridge->CommitUpdates();
447 
448  auto root_node = bridge->GetFlutterPlatformNodeDelegateFromID(0).lock();
449  auto child1_node = bridge->GetFlutterPlatformNodeDelegateFromID(1).lock();
450  auto child2_node = bridge->GetFlutterPlatformNodeDelegateFromID(2).lock();
451 
452  EXPECT_EQ(root_node->GetChildCount(), 2);
453  EXPECT_EQ(root_node->GetData().child_ids[0], 1);
454  EXPECT_EQ(root_node->GetData().child_ids[1], 2);
455  EXPECT_EQ(root_node->GetName(), "root");
456 
457  EXPECT_EQ(child1_node->GetChildCount(), 0);
458  EXPECT_EQ(child1_node->GetName(), "child 1");
459 
460  EXPECT_EQ(child2_node->GetChildCount(), 0);
461  EXPECT_EQ(child2_node->GetName(), "child 2");
462 
463  ASSERT_EQ(bridge->accessibility_events.size(), size_t{5});
464 
465  // Child2 is moved from child1 to root.
466  EXPECT_THAT(bridge->accessibility_events,
467  Contains(ui::AXEventGenerator::Event::CHILDREN_CHANGED).Times(2));
468  EXPECT_THAT(bridge->accessibility_events,
469  Contains(ui::AXEventGenerator::Event::SUBTREE_CREATED).Times(1));
470 
471  // Child1 is no longer a parent. It loses its group role and disables its
472  // 'clip children' attribute.
473  EXPECT_THAT(
474  bridge->accessibility_events,
475  Contains(ui::AXEventGenerator::Event::OTHER_ATTRIBUTE_CHANGED).Times(1));
476  EXPECT_THAT(bridge->accessibility_events,
477  Contains(ui::AXEventGenerator::Event::ROLE_CHANGED).Times(1));
478 }

References CreateSemanticsNode().

◆ TEST() [9/148]

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

Definition at line 575 of file accessibility_bridge_unittests.cc.

575  {
576  std::shared_ptr<TestAccessibilityBridge> bridge =
577  std::make_shared<TestAccessibilityBridge>();
578 
579  int32_t root_id = 0;
580  int32_t intermediary1_id = 1;
581  int32_t intermediary2_id = 2;
582  int32_t leaf1_id = 3;
583 
584  std::vector<int32_t> root_children{intermediary1_id, intermediary2_id};
585  std::vector<int32_t> intermediary1_children{leaf1_id};
586  FlutterSemanticsNode2 root =
587  CreateSemanticsNode(root_id, "root", &root_children);
588  FlutterSemanticsNode2 intermediary1 = CreateSemanticsNode(
589  intermediary1_id, "intermediary 1", &intermediary1_children);
590  FlutterSemanticsNode2 intermediary2 =
591  CreateSemanticsNode(intermediary2_id, "intermediary 2");
592  FlutterSemanticsNode2 leaf1 = CreateSemanticsNode(leaf1_id, "leaf 1");
593 
594  bridge->AddFlutterSemanticsNodeUpdate(root);
595  bridge->AddFlutterSemanticsNodeUpdate(intermediary1);
596  bridge->AddFlutterSemanticsNodeUpdate(intermediary2);
597  bridge->AddFlutterSemanticsNodeUpdate(leaf1);
598  bridge->CommitUpdates();
599  bridge->accessibility_events.clear();
600 
601  // Move intermediary1 from root to intermediary 2.
602  int32_t new_root_children[] = {intermediary2_id};
603  root.child_count = 1;
604  root.children_in_traversal_order = new_root_children;
605 
606  int32_t new_intermediary2_children[] = {intermediary1_id};
607  intermediary2.child_count = 1;
608  intermediary2.children_in_traversal_order = new_intermediary2_children;
609 
610  bridge->AddFlutterSemanticsNodeUpdate(root);
611  bridge->AddFlutterSemanticsNodeUpdate(intermediary1);
612  bridge->AddFlutterSemanticsNodeUpdate(intermediary2);
613  bridge->AddFlutterSemanticsNodeUpdate(leaf1);
614  bridge->CommitUpdates();
615 
616  auto root_node = bridge->GetFlutterPlatformNodeDelegateFromID(root_id).lock();
617  auto intermediary1_node =
618  bridge->GetFlutterPlatformNodeDelegateFromID(intermediary1_id).lock();
619  auto intermediary2_node =
620  bridge->GetFlutterPlatformNodeDelegateFromID(intermediary2_id).lock();
621  auto leaf1_node =
622  bridge->GetFlutterPlatformNodeDelegateFromID(leaf1_id).lock();
623 
624  EXPECT_EQ(root_node->GetChildCount(), 1);
625  EXPECT_EQ(root_node->GetData().child_ids[0], intermediary2_id);
626  EXPECT_EQ(root_node->GetName(), "root");
627 
628  EXPECT_EQ(intermediary2_node->GetChildCount(), 1);
629  EXPECT_EQ(intermediary2_node->GetData().child_ids[0], intermediary1_id);
630  EXPECT_EQ(intermediary2_node->GetName(), "intermediary 2");
631 
632  EXPECT_EQ(intermediary1_node->GetChildCount(), 1);
633  EXPECT_EQ(intermediary1_node->GetData().child_ids[0], leaf1_id);
634  EXPECT_EQ(intermediary1_node->GetName(), "intermediary 1");
635 
636  EXPECT_EQ(leaf1_node->GetChildCount(), 0);
637  EXPECT_EQ(leaf1_node->GetName(), "leaf 1");
638 
639  ASSERT_EQ(bridge->accessibility_events.size(), size_t{5});
640 
641  EXPECT_THAT(bridge->accessibility_events,
642  Contains(ui::AXEventGenerator::Event::CHILDREN_CHANGED).Times(2));
643  EXPECT_THAT(bridge->accessibility_events,
644  Contains(ui::AXEventGenerator::Event::SUBTREE_CREATED).Times(1));
645 
646  // Intermediary 2 becomes a parent node. It updates to group role and enables
647  // its 'clip children' attribute.
648  EXPECT_THAT(
649  bridge->accessibility_events,
650  Contains(ui::AXEventGenerator::Event::OTHER_ATTRIBUTE_CHANGED).Times(1));
651  EXPECT_THAT(bridge->accessibility_events,
652  Contains(ui::AXEventGenerator::Event::ROLE_CHANGED).Times(1));
653 }

References CreateSemanticsNode().

◆ TEST() [10/148]

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

Definition at line 399 of file accessibility_bridge_unittests.cc.

399  {
400  std::shared_ptr<TestAccessibilityBridge> bridge =
401  std::make_shared<TestAccessibilityBridge>();
402  FlutterSemanticsNode2 root = CreateSemanticsNode(0, "root");
403  auto flags = FlutterSemanticsFlags{
404  .is_checked = FlutterCheckState::kFlutterCheckStateTrue,
405  };
406 
407  root.flags2 = &flags;
408  bridge->AddFlutterSemanticsNodeUpdate(root);
409  bridge->CommitUpdates();
410 
411  auto root_node = bridge->GetFlutterPlatformNodeDelegateFromID(0).lock();
412  EXPECT_EQ(root_node->GetData().role, ax::mojom::Role::kCheckBox);
413  EXPECT_EQ(root_node->GetData().GetCheckedState(),
414  ax::mojom::CheckedState::kTrue);
415 }

References CreateSemanticsNode().

◆ TEST() [11/148]

flutter::testing::TEST ( AccessibilityBridgeTest  ,
DisabledButtonHasDisabledRestriction   
)

Definition at line 305 of file accessibility_bridge_unittests.cc.

305  {
306  std::shared_ptr<TestAccessibilityBridge> bridge =
307  std::make_shared<TestAccessibilityBridge>();
308  FlutterSemanticsNode2 root = CreateSemanticsNode(0, "root");
309  auto flags = FlutterSemanticsFlags{
310  .is_enabled = FlutterTristate::kFlutterTristateFalse,
311  .is_button = true,
312  };
313  root.flags2 = &flags;
314  bridge->AddFlutterSemanticsNodeUpdate(root);
315  bridge->CommitUpdates();
316 
317  auto root_node = bridge->GetFlutterPlatformNodeDelegateFromID(0).lock();
318  EXPECT_EQ(root_node->GetData().role, ax::mojom::Role::kButton);
319  EXPECT_EQ(root_node->GetData().GetRestriction(),
320  ax::mojom::Restriction::kDisabled);
321 }

References CreateSemanticsNode().

◆ TEST() [12/148]

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

Definition at line 250 of file accessibility_bridge_unittests.cc.

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

References CreateSemanticsNode().

◆ TEST() [13/148]

flutter::testing::TEST ( AccessibilityBridgeTest  ,
EditableTextFieldHasTextFieldRole   
)

Definition at line 376 of file accessibility_bridge_unittests.cc.

376  {
377  std::shared_ptr<TestAccessibilityBridge> bridge =
378  std::make_shared<TestAccessibilityBridge>();
379  FlutterSemanticsNode2 root = CreateSemanticsNode(0, "root");
380  auto flags = FlutterSemanticsFlags{
381  .is_enabled = FlutterTristate::kFlutterTristateTrue,
382  .is_text_field = true,
383  .is_read_only = false,
384  };
385  root.flags2 = &flags;
386  bridge->AddFlutterSemanticsNodeUpdate(root);
387  bridge->CommitUpdates();
388 
389  auto root_node = bridge->GetFlutterPlatformNodeDelegateFromID(0).lock();
390  EXPECT_EQ(root_node->GetData().role, ax::mojom::Role::kTextField);
391  EXPECT_TRUE(root_node->GetData().HasState(ax::mojom::State::kEditable));
392 }

References CreateSemanticsNode().

◆ TEST() [14/148]

flutter::testing::TEST ( AccessibilityBridgeTest  ,
EnabledButtonHasNoRestriction   
)

Definition at line 323 of file accessibility_bridge_unittests.cc.

323  {
324  std::shared_ptr<TestAccessibilityBridge> bridge =
325  std::make_shared<TestAccessibilityBridge>();
326  FlutterSemanticsNode2 root = CreateSemanticsNode(0, "root");
327  auto flags = FlutterSemanticsFlags{
328  .is_enabled = FlutterTristate::kFlutterTristateTrue,
329  .is_button = true,
330  };
331  root.flags2 = &flags;
332  bridge->AddFlutterSemanticsNodeUpdate(root);
333  bridge->CommitUpdates();
334 
335  auto root_node = bridge->GetFlutterPlatformNodeDelegateFromID(0).lock();
336  EXPECT_EQ(root_node->GetData().role, ax::mojom::Role::kButton);
337  EXPECT_EQ(root_node->GetData().GetRestriction(),
338  ax::mojom::Restriction::kNone);
339 }

References CreateSemanticsNode().

◆ TEST() [15/148]

flutter::testing::TEST ( AccessibilityBridgeTest  ,
IsSelectedAttribute   
)

Definition at line 684 of file accessibility_bridge_unittests.cc.

684  {
685  std::shared_ptr<TestAccessibilityBridge> bridge =
686  std::make_shared<TestAccessibilityBridge>();
687 
688  std::vector<int32_t> children{1, 2};
689  FlutterSemanticsNode2 node0 = CreateSemanticsNode(0, "node 0", &children);
690  auto flags0 = FlutterSemanticsFlags{
691  .is_selected = FlutterTristate::kFlutterTristateNone,
692  };
693  node0.flags2 = &flags0;
694 
695  FlutterSemanticsNode2 node1 = CreateSemanticsNode(1, "node 1");
696  auto flags1 = FlutterSemanticsFlags{
697  .is_selected = FlutterTristate::kFlutterTristateTrue,
698  };
699  node1.flags2 = &flags1;
700 
701  FlutterSemanticsNode2 node2 = CreateSemanticsNode(2, "node 2");
702  auto flags2 = FlutterSemanticsFlags{
703  .is_selected = FlutterTristate::kFlutterTristateFalse,
704  };
705  node2.flags2 = &flags2;
706 
707  bridge->AddFlutterSemanticsNodeUpdate(node0);
708  bridge->AddFlutterSemanticsNodeUpdate(node1);
709  bridge->AddFlutterSemanticsNodeUpdate(node2);
710  bridge->CommitUpdates();
711 
712  auto delegate0 = bridge->GetFlutterPlatformNodeDelegateFromID(0).lock();
713  auto delegate1 = bridge->GetFlutterPlatformNodeDelegateFromID(1).lock();
714  auto delegate2 = bridge->GetFlutterPlatformNodeDelegateFromID(2).lock();
715 
716  // For kFlutterTristateNone, selected should be false.
717  EXPECT_FALSE(delegate0->GetData().GetBoolAttribute(
718  ax::mojom::BoolAttribute::kSelected));
719  // For kFlutterTristateTrue, selected should be true.
720  EXPECT_TRUE(delegate1->GetData().GetBoolAttribute(
721  ax::mojom::BoolAttribute::kSelected));
722  // For kFlutterTristateFalse, selected should be false.
723  EXPECT_FALSE(delegate2->GetData().GetBoolAttribute(
724  ax::mojom::BoolAttribute::kSelected));
725 }

References CreateSemanticsNode().

◆ TEST() [16/148]

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

Definition at line 665 of file accessibility_bridge_unittests.cc.

665  {
666  std::shared_ptr<TestAccessibilityBridge> bridge =
667  std::make_shared<TestAccessibilityBridge>();
668 
669  const int32_t root_id = 0;
670 
671  FlutterSemanticsNode2 root = CreateSemanticsNode(root_id, "root", {});
672 
673  bridge->AddFlutterSemanticsNodeUpdate(root);
674  bridge->CommitUpdates();
675 
676  auto root_node = bridge->GetFlutterPlatformNodeDelegateFromID(root_id).lock();
677  auto root_data = root_node->GetData();
678  EXPECT_TRUE(root_data.HasBoolAttribute(
679  ax::mojom::BoolAttribute::kIsLineBreakingObject));
680  EXPECT_TRUE(root_data.GetBoolAttribute(
681  ax::mojom::BoolAttribute::kIsLineBreakingObject));
682 }

References CreateSemanticsNode().

◆ TEST() [17/148]

flutter::testing::TEST ( AccessibilityBridgeTest  ,
ReadOnlyTextFieldHasReadOnlyRestriction   
)

Definition at line 341 of file accessibility_bridge_unittests.cc.

341  {
342  std::shared_ptr<TestAccessibilityBridge> bridge =
343  std::make_shared<TestAccessibilityBridge>();
344  FlutterSemanticsNode2 root = CreateSemanticsNode(0, "root");
345  auto flags = FlutterSemanticsFlags{
346  .is_enabled = FlutterTristate::kFlutterTristateTrue,
347  .is_text_field = true,
348  .is_read_only = true,
349  };
350  root.flags2 = &flags;
351  bridge->AddFlutterSemanticsNodeUpdate(root);
352  bridge->CommitUpdates();
353 
354  auto root_node = bridge->GetFlutterPlatformNodeDelegateFromID(0).lock();
355  EXPECT_EQ(root_node->GetData().GetRestriction(),
356  ax::mojom::Restriction::kReadOnly);
357 }

References CreateSemanticsNode().

◆ TEST() [18/148]

flutter::testing::TEST ( AccessibilityBridgeTest  ,
ReadOnlyTextFieldHasTextFieldRole   
)

Definition at line 359 of file accessibility_bridge_unittests.cc.

359  {
360  std::shared_ptr<TestAccessibilityBridge> bridge =
361  std::make_shared<TestAccessibilityBridge>();
362  FlutterSemanticsNode2 root = CreateSemanticsNode(0, "root");
363  auto flags = FlutterSemanticsFlags{
364  .is_enabled = FlutterTristate::kFlutterTristateTrue,
365  .is_text_field = true,
366  .is_read_only = true,
367  };
368  root.flags2 = &flags;
369  bridge->AddFlutterSemanticsNodeUpdate(root);
370  bridge->CommitUpdates();
371 
372  auto root_node = bridge->GetFlutterPlatformNodeDelegateFromID(0).lock();
373  EXPECT_EQ(root_node->GetData().role, ax::mojom::Role::kTextField);
374 }

References CreateSemanticsNode().

◆ TEST() [19/148]

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

Definition at line 286 of file accessibility_bridge_unittests.cc.

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

References CreateSemanticsNode().

◆ TEST() [20/148]

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

Definition at line 269 of file accessibility_bridge_unittests.cc.

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

References CreateSemanticsNode().

◆ TEST() [21/148]

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

Definition at line 32 of file FlutterAppDelegateTest.mm.

32  {
33  FlutterAppDelegate* appDelegate = [[FlutterAppDelegate 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 }
void addApplicationLifecycleDelegate:(nonnull NSObject< FlutterAppLifecycleDelegate > *delegate)

References <FlutterAppLifecycleProvider>::addApplicationLifecycleDelegate:.

◆ TEST() [22/148]

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

Definition at line 57 of file FlutterAppDelegateTest.mm.

57  {
58  FlutterAppDelegate* appDelegate = [[FlutterAppDelegate 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 }

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

◆ TEST() [23/148]

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

Definition at line 43 of file FlutterAppDelegateTest.mm.

43  {
44  FlutterAppDelegate* appDelegate = [[FlutterAppDelegate 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() [24/148]

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

Definition at line 223 of file FlutterAppLifecycleDelegateTest.mm.

223  {
224  __weak FlutterAppLifecycleRegistrar* weakRegistrar;
225  __weak TestFlutterAppLifecycleDelegate* weakDelegate;
226  @autoreleasepool {
228  weakRegistrar = registrar;
230  weakDelegate = delegate;
231  [registrar addDelegate:delegate];
232  }
233  EXPECT_EQ(weakRegistrar, nil);
234  EXPECT_EQ(weakDelegate, nil);
235 }
void addDelegate:(NSObject< FlutterAppLifecycleDelegate > *delegate)

References FlutterAppLifecycleRegistrar::addDelegate:.

◆ TEST() [25/148]

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

Definition at line 109 of file FlutterAppLifecycleDelegateTest.mm.

109  {
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 }
void handleDidBecomeActive:(NSNotification *notification)

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

◆ TEST() [26/148]

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

Definition at line 209 of file FlutterAppLifecycleDelegateTest.mm.

209  {
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 }
void handleDidChangeOcclusionState:(NSNotification *notification)

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

◆ TEST() [27/148]

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

Definition at line 197 of file FlutterAppLifecycleDelegateTest.mm.

197  {
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 }
void handleDidChangeScreenParameters:(NSNotification *notification)

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

◆ TEST() [28/148]

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

Definition at line 87 of file FlutterAppLifecycleDelegateTest.mm.

87  {
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 }
void handleDidFinishLaunching:(NSNotification *notification)

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

◆ TEST() [29/148]

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

Definition at line 175 of file FlutterAppLifecycleDelegateTest.mm.

175  {
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 }
void handleDidHide:(NSNotification *notification)

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

◆ TEST() [30/148]

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

Definition at line 131 of file FlutterAppLifecycleDelegateTest.mm.

131  {
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 }
void handleDidResignActive:(NSNotification *notification)

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

◆ TEST() [31/148]

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

Definition at line 186 of file FlutterAppLifecycleDelegateTest.mm.

186  {
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 }
void handleDidUnhide:(NSNotification *notification)

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

◆ TEST() [32/148]

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

Definition at line 98 of file FlutterAppLifecycleDelegateTest.mm.

98  {
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 }
void handleWillBecomeActive:(NSNotification *notification)

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

◆ TEST() [33/148]

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

Definition at line 76 of file FlutterAppLifecycleDelegateTest.mm.

76  {
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 }
void handleWillFinishLaunching:(NSNotification *notification)

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

◆ TEST() [34/148]

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

Definition at line 153 of file FlutterAppLifecycleDelegateTest.mm.

153  {
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 }
void handleWillHide:(NSNotification *notification)

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

◆ TEST() [35/148]

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

Definition at line 120 of file FlutterAppLifecycleDelegateTest.mm.

120  {
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 }
void handleWillResignActive:(NSNotification *notification)

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

◆ TEST() [36/148]

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

Definition at line 142 of file FlutterAppLifecycleDelegateTest.mm.

142  {
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 }
void handleWillTerminate:(NSNotification *notification)

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

◆ TEST() [37/148]

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

Definition at line 164 of file FlutterAppLifecycleDelegateTest.mm.

164  {
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 }
void handleWillUnhide:(NSNotification *notification)

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

◆ TEST() [38/148]

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 
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 }
void handleEvent:callback:(nonnull NSEvent *event,[callback] nonnull FlutterAsyncKeyCallback callback)

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

◆ TEST() [39/148]

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Definition at line 469 of file FlutterKeyboardManagerTest.mm.

469  {
470  ASSERT_TRUE([[FlutterKeyboardManagerUnittestsObjC alloc] correctLogicalKeyForLayouts]);
471 }

◆ TEST() [53/148]

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

Definition at line 445 of file FlutterKeyboardManagerTest.mm.

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

◆ TEST() [54/148]

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

Definition at line 453 of file FlutterKeyboardManagerTest.mm.

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

◆ TEST() [55/148]

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

Definition at line 457 of file FlutterKeyboardManagerTest.mm.

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

◆ TEST() [56/148]

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

Definition at line 461 of file FlutterKeyboardManagerTest.mm.

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

◆ TEST() [57/148]

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

Definition at line 465 of file FlutterKeyboardManagerTest.mm.

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

◆ TEST() [58/148]

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

Definition at line 473 of file FlutterKeyboardManagerTest.mm.

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

◆ TEST() [59/148]

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

Definition at line 449 of file FlutterKeyboardManagerTest.mm.

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

◆ TEST() [60/148]

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

Definition at line 441 of file FlutterKeyboardManagerTest.mm.

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

◆ TEST() [61/148]

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

Definition at line 32 of file FlutterPlatformNodeDelegateMacTest.mm.

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

References FlutterViewController::engine.

◆ TEST() [62/148]

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

Definition at line 158 of file FlutterPlatformNodeDelegateMacTest.mm.

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

References FlutterViewController::engine.

◆ TEST() [63/148]

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

Definition at line 399 of file FlutterPlatformNodeDelegateMacTest.mm.

399  {
400  FlutterViewController* viewController = CreateTestViewController();
401  FlutterEngine* engine = viewController.engine;
402  [viewController loadView];
403 
404  // Creates a NSWindow so that the native text field can become first responder.
405  NSWindow* window = [[NSWindow alloc] initWithContentRect:NSMakeRect(0, 0, 800, 600)
406  styleMask:NSBorderlessWindowMask
407  backing:NSBackingStoreBuffered
408  defer:NO];
409  window.contentView = viewController.view;
410  engine.semanticsEnabled = YES;
411 
412  auto bridge = viewController.accessibilityBridge.lock();
413  // Initialize ax node data.
414  FlutterSemanticsNode2 root;
415  root.id = 0;
416  FlutterSemanticsFlags flags = FlutterSemanticsFlags{0};
417  root.flags2 = &flags;
418  // NOLINTNEXTLINE(clang-analyzer-optin.core.EnumCastOutOfRange)
419  root.actions = static_cast<FlutterSemanticsAction>(0);
420  root.label = "root";
421  root.hint = "";
422  root.value = "";
423  root.increased_value = "";
424  root.decreased_value = "";
425  root.tooltip = "";
426  root.child_count = 1;
427  int32_t children[] = {1};
428  root.children_in_traversal_order = children;
429  root.custom_accessibility_actions_count = 0;
430  root.identifier = "";
431  root.rect = {0, 0, 100, 100}; // LTRB
432  root.transform = {1, 0, 0, 0, 1, 0, 0, 0, 1};
433  bridge->AddFlutterSemanticsNodeUpdate(root);
434 
435  double rectSize = 50;
436  double transformFactor = 0.5;
437 
438  FlutterSemanticsNode2 child1;
439  FlutterSemanticsFlags child_flags = FlutterSemanticsFlags{0};
440  child1.flags2 = &child_flags;
441  child1.id = 1;
442  // NOLINTNEXTLINE(clang-analyzer-optin.core.EnumCastOutOfRange)
443  child1.actions = static_cast<FlutterSemanticsAction>(0);
444  child1.label = "";
445  child1.hint = "";
446  child1.value = "textfield";
447  child1.increased_value = "";
448  child1.decreased_value = "";
449  child1.tooltip = "";
450  child1.text_selection_base = -1;
451  child1.text_selection_extent = -1;
452  child1.child_count = 0;
453  child1.custom_accessibility_actions_count = 0;
454  child1.identifier = "";
455  child1.rect = {0, 0, rectSize, rectSize}; // LTRB
456  child1.transform = {transformFactor, 0, 0, 0, transformFactor, 0, 0, 0, 1};
457  bridge->AddFlutterSemanticsNodeUpdate(child1);
458 
459  bridge->CommitUpdates();
460 
461  auto child_platform_node_delegate = bridge->GetFlutterPlatformNodeDelegateFromID(1).lock();
462  // Verify the accessibility attribute matches.
463  id native_accessibility = child_platform_node_delegate->GetNativeViewAccessible();
464  EXPECT_TRUE([[native_accessibility className] isEqualToString:@"AXPlatformNodeCocoa"]);
465 
466  // Converting child to text field should produce `FlutterTextField` native view accessible.
467 
468  FlutterSemanticsFlags child_flags_updated_1 = FlutterSemanticsFlags{.is_text_field = true};
469  child1.flags2 = &child_flags_updated_1;
470  bridge->AddFlutterSemanticsNodeUpdate(child1);
471  bridge->CommitUpdates();
472 
473  native_accessibility = child_platform_node_delegate->GetNativeViewAccessible();
474  EXPECT_TRUE([native_accessibility isKindOfClass:[FlutterTextField class]]);
475 
476  FlutterSemanticsFlags child_flags_updated_2 = FlutterSemanticsFlags{.is_text_field = false};
477  child1.flags2 = &child_flags_updated_2;
478  bridge->AddFlutterSemanticsNodeUpdate(child1);
479  bridge->CommitUpdates();
480 
481  native_accessibility = child_platform_node_delegate->GetNativeViewAccessible();
482  EXPECT_TRUE([[native_accessibility className] isEqualToString:@"AXPlatformNodeCocoa"]);
483 }

References FlutterViewController::engine.

◆ TEST() [64/148]

flutter::testing::TEST ( FlutterPlatformNodeDelegateMac  ,
DisabledTextFieldDoesNotUseFlutterTextField   
)

Definition at line 326 of file FlutterPlatformNodeDelegateMacTest.mm.

326  {
327  FlutterViewController* viewController = CreateTestViewController();
328  FlutterEngine* engine = viewController.engine;
329  [viewController loadView];
330 
331  // Creates a NSWindow so that the native accessibility element has a hosting view.
332  NSWindow* window = [[NSWindow alloc] initWithContentRect:NSMakeRect(0, 0, 800, 600)
333  styleMask:NSBorderlessWindowMask
334  backing:NSBackingStoreBuffered
335  defer:NO];
336  window.contentView = viewController.view;
337  engine.semanticsEnabled = YES;
338 
339  auto bridge = viewController.accessibilityBridge.lock();
340  // Initialize ax node data.
341  FlutterSemanticsNode2 root = {};
342  FlutterSemanticsFlags flags = FlutterSemanticsFlags{0};
343  // A text field that is editable (not read-only) but disabled.
344  FlutterSemanticsFlags child_flags =
345  FlutterSemanticsFlags{.is_enabled = FlutterTristate::kFlutterTristateFalse,
346  .is_text_field = true,
347  .is_read_only = false};
348  root.id = 0;
349  root.flags2 = &flags;
350  // NOLINTNEXTLINE(clang-analyzer-optin.core.EnumCastOutOfRange)
351  root.actions = static_cast<FlutterSemanticsAction>(0);
352  root.label = "root";
353  root.hint = "";
354  root.value = "";
355  root.increased_value = "";
356  root.decreased_value = "";
357  root.tooltip = "";
358  root.child_count = 1;
359  int32_t children[] = {1};
360  root.children_in_traversal_order = children;
361  root.custom_accessibility_actions_count = 0;
362  root.identifier = "";
363  root.rect = {0, 0, 100, 100}; // LTRB
364  root.transform = {1, 0, 0, 0, 1, 0, 0, 0, 1};
365  bridge->AddFlutterSemanticsNodeUpdate(root);
366 
367  FlutterSemanticsNode2 child1 = {};
368  child1.id = 1;
369  child1.flags2 = &child_flags;
370  // NOLINTNEXTLINE(clang-analyzer-optin.core.EnumCastOutOfRange)
371  child1.actions = static_cast<FlutterSemanticsAction>(0);
372  child1.label = "";
373  child1.hint = "";
374  child1.value = "disabled textfield";
375  child1.increased_value = "";
376  child1.decreased_value = "";
377  child1.tooltip = "";
378  child1.text_selection_base = -1;
379  child1.text_selection_extent = -1;
380  child1.child_count = 0;
381  child1.custom_accessibility_actions_count = 0;
382  child1.identifier = "";
383  child1.rect = {0, 0, 50, 50}; // LTRB
384  child1.transform = {1, 0, 0, 0, 1, 0, 0, 0, 1};
385  bridge->AddFlutterSemanticsNodeUpdate(child1);
386 
387  bridge->CommitUpdates();
388 
389  auto child_platform_node_delegate = bridge->GetFlutterPlatformNodeDelegateFromID(1).lock();
390  // The disabled text field must not be backed by a `FlutterTextField`.
391  id native_accessibility = child_platform_node_delegate->GetNativeViewAccessible();
392  EXPECT_FALSE([native_accessibility isKindOfClass:[FlutterTextField class]]);
393  EXPECT_TRUE(
394  [[native_accessibility accessibilityRole] isEqualToString:NSAccessibilityStaticTextRole]);
395 
396  [engine shutDownEngine];
397 }

References FlutterViewController::engine.

◆ TEST() [65/148]

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

Definition at line 72 of file FlutterPlatformNodeDelegateMacTest.mm.

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

References FlutterViewController::engine.

◆ TEST() [66/148]

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

Definition at line 116 of file FlutterPlatformNodeDelegateMacTest.mm.

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

References FlutterViewController::engine.

◆ TEST() [67/148]

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

Definition at line 235 of file FlutterPlatformNodeDelegateMacTest.mm.

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

References FlutterViewController::engine.

◆ TEST() [68/148]

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

Definition at line 121 of file flutter_platform_node_delegate_unittests.cc.

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

◆ TEST() [69/148]

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

Definition at line 172 of file flutter_platform_node_delegate_unittests.cc.

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

◆ TEST() [70/148]

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

Definition at line 91 of file flutter_platform_node_delegate_unittests.cc.

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

◆ TEST() [71/148]

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

Definition at line 300 of file flutter_platform_node_delegate_unittests.cc.

300  {
301  std::shared_ptr<TestAccessibilityBridge> bridge =
302  std::make_shared<TestAccessibilityBridge>();
303  FlutterSemanticsFlags flags = FlutterSemanticsFlags{0};
304  FlutterSemanticsNode2 root;
305  root.id = 0;
306  root.label = "root";
307  root.hint = "";
308  root.value = "";
309  root.increased_value = "";
310  root.decreased_value = "";
311  root.tooltip = "";
312  root.child_count = 1;
313  root.flags2 = &flags;
314  int32_t children[] = {1};
315  root.children_in_traversal_order = children;
316  root.custom_accessibility_actions_count = 0;
317  root.identifier = "";
318  bridge->AddFlutterSemanticsNodeUpdate(root);
319 
320  FlutterSemanticsNode2 child1;
321  child1.id = 1;
322  child1.label = "child 1";
323  child1.hint = "";
324  child1.value = "";
325  child1.increased_value = "";
326  child1.decreased_value = "";
327  child1.tooltip = "";
328  child1.child_count = 0;
329  child1.flags2 = &flags;
330  child1.custom_accessibility_actions_count = 0;
331  child1.identifier = "";
332  bridge->AddFlutterSemanticsNodeUpdate(child1);
333 
334  bridge->CommitUpdates();
335  auto root_node = bridge->GetFlutterPlatformNodeDelegateFromID(0).lock();
336  auto child1_node = bridge->GetFlutterPlatformNodeDelegateFromID(1).lock();
337  auto node_by_id = root_node->GetFromNodeID(1);
338  EXPECT_EQ(child1_node->GetPlatformNode(), node_by_id);
339 }

◆ TEST() [72/148]

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  root.identifier = "";
64  bridge->AddFlutterSemanticsNodeUpdate(root);
65 
66  bridge->CommitUpdates();
67 
68  auto accessibility = bridge->GetFlutterPlatformNodeDelegateFromID(0).lock();
69  // Performs an AXAction.
70  ui::AXActionData action_data;
71  action_data.action = ax::mojom::Action::kDoDefault;
72  accessibility->AccessibilityPerformAction(action_data);
73  EXPECT_EQ(bridge->performed_actions.size(), size_t{1});
74  EXPECT_EQ(bridge->performed_actions[0],
75  FlutterSemanticsAction::kFlutterSemanticsActionTap);
76 
77  action_data.action = ax::mojom::Action::kFocus;
78  accessibility->AccessibilityPerformAction(action_data);
79  EXPECT_EQ(bridge->performed_actions.size(), size_t{2});
80  EXPECT_EQ(
81  bridge->performed_actions[1],
82  FlutterSemanticsAction::kFlutterSemanticsActionDidGainAccessibilityFocus);
83 
84  action_data.action = ax::mojom::Action::kScrollToMakeVisible;
85  accessibility->AccessibilityPerformAction(action_data);
86  EXPECT_EQ(bridge->performed_actions.size(), size_t{3});
87  EXPECT_EQ(bridge->performed_actions[2],
88  FlutterSemanticsAction::kFlutterSemanticsActionShowOnScreen);
89 }

◆ TEST() [73/148]

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

Definition at line 223 of file flutter_platform_node_delegate_unittests.cc.

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

◆ TEST() [74/148]

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

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

Definition at line 275 of file flutter_platform_node_delegate_unittests.cc.

275  {
276  std::shared_ptr<TestAccessibilityBridge> bridge =
277  std::make_shared<TestAccessibilityBridge>();
278  FlutterSemanticsFlags flags = FlutterSemanticsFlags{0};
279  FlutterSemanticsNode2 root;
280  root.id = 0;
281  root.label = "root";
282  root.hint = "";
283  root.value = "";
284  root.increased_value = "";
285  root.decreased_value = "";
286  root.tooltip = "";
287  root.child_count = 0;
288  root.flags2 = &flags;
289  root.children_in_traversal_order = nullptr;
290  root.custom_accessibility_actions_count = 0;
291  root.identifier = "";
292  bridge->AddFlutterSemanticsNodeUpdate(root);
293 
294  bridge->CommitUpdates();
295  auto root_node = bridge->GetFlutterPlatformNodeDelegateFromID(0).lock();
296  auto lowest_platform_ancestor = root_node->GetLowestPlatformAncestor();
297  EXPECT_EQ(root_node->GetNativeViewAccessible(), lowest_platform_ancestor);
298 }

◆ TEST() [76/148]

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

Definition at line 249 of file FlutterPlatformViewControllerTest.mm.

249  {
250  FlutterPlatformViewController* platformViewController =
251  [[FlutterPlatformViewController alloc] init];
252  [platformViewController registerViewFactory:[TestFlutterPlatformViewFactory alloc]
253  withId:@"MockPlatformView"];
254 
255  // Create the PlatformView.
256  const NSNumber* viewId = [NSNumber numberWithLongLong:2];
257  FlutterMethodCall* methodCallOnCreate = [FlutterMethodCall
258  methodCallWithMethodName:@"create"
259  arguments:@{@"id" : viewId, @"viewType" : @"MockPlatformView"}];
260  __block bool created = false;
261  FlutterResult resultOnCreate = ^(id result) {
262  // If a platform view is successfully created, the result is nil.
263  if (result == nil) {
264  created = true;
265  }
266  };
267  [platformViewController handleMethodCall:methodCallOnCreate result:resultOnCreate];
268 
269  // Call acceptGesture.
270  FlutterMethodCall* methodCallAcceptGesture =
271  [FlutterMethodCall methodCallWithMethodName:@"acceptGesture" arguments:@{@"id" : viewId}];
272  __block bool acceptGestureCalled = false;
273  FlutterResult resultAcceptGesture = ^(id result) {
274  // If a acceptGesture is successful, the result is nil.
275  if (result == nil) {
276  acceptGestureCalled = true;
277  }
278  };
279  [platformViewController handleMethodCall:methodCallAcceptGesture result:resultAcceptGesture];
280 
281  EXPECT_TRUE(created);
282  EXPECT_TRUE(acceptGestureCalled);
283 }
void(^ FlutterResult)(id _Nullable result)

◆ TEST() [77/148]

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

Definition at line 285 of file FlutterPlatformViewControllerTest.mm.

285  {
286  FlutterPlatformViewController* platformViewController =
287  [[FlutterPlatformViewController alloc] init];
288  [platformViewController registerViewFactory:[TestFlutterPlatformViewFactory alloc]
289  withId:@"MockPlatformView"];
290 
291  // Call rejectGesture.
292  FlutterMethodCall* methodCallAcceptGesture =
293  [FlutterMethodCall methodCallWithMethodName:@"acceptGesture" arguments:@{
294  @"id" : @20
295  }];
296  __block bool errored = false;
297  FlutterResult result = ^(id result) {
298  if ([result isKindOfClass:[FlutterError class]]) {
299  errored = true;
300  }
301  };
302  [platformViewController handleMethodCall:methodCallAcceptGesture result:result];
303 
304  EXPECT_TRUE(errored);
305 }

◆ TEST() [78/148]

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

Definition at line 132 of file FlutterPlatformViewControllerTest.mm.

132  {
133  // Use id so we can access handleMethodCall method.
134  id platformViewController = [[FlutterPlatformViewController alloc] init];
135 
137 
138  [platformViewController registerViewFactory:factory withId:@"MockPlatformView"];
139 
140  FlutterMethodCall* methodCallOnCreate =
141  [FlutterMethodCall methodCallWithMethodName:@"create"
142  arguments:@{
143  @"id" : @2,
144  @"viewType" : @"MockPlatformView"
145  }];
146 
147  __block bool created = false;
148  FlutterResult resultOnCreate = ^(id result) {
149  // If a platform view is successfully created, the result is nil.
150  if (result == nil) {
151  created = true;
152  }
153  };
154 
155  [platformViewController handleMethodCall:methodCallOnCreate result:resultOnCreate];
156 
157  FlutterMethodCall* methodCallOnDispose =
158  [FlutterMethodCall methodCallWithMethodName:@"dispose"
159  arguments:[NSNumber numberWithLongLong:2]];
160 
161  __block bool disposed = false;
162  FlutterResult resultOnDispose = ^(id result) {
163  // If a platform view is successfully created, the result is nil.
164  if (result == nil) {
165  disposed = true;
166  }
167  };
168 
169  [platformViewController handleMethodCall:methodCallOnDispose result:resultOnDispose];
170 
171  EXPECT_TRUE(created);
172  EXPECT_TRUE(disposed);
173 }

◆ TEST() [79/148]

flutter::testing::TEST ( FlutterPlatformViewController  ,
TestCreatePlatformViewInvalidViewType   
)

Definition at line 41 of file FlutterPlatformViewControllerTest.mm.

41  {
42  // Use id so we can access handleMethodCall method.
43  id platformViewController = [[FlutterPlatformViewController alloc] init];
44 
45  NSArray<NSDictionary*>* invalidArguments = @[
46  @{@"id" : @2}, // 'viewType' omitted.
47  @{@"id" : @2,
48  @"viewType" : [NSNull null]}, // 'viewType' explicitly null in Dart.
49  @{@"id" : @2,
50  @"viewType" : @7}, // 'viewType' not a string.
51  ];
52 
53  for (NSDictionary* arguments in invalidArguments) {
54  FlutterMethodCall* methodCall = [FlutterMethodCall methodCallWithMethodName:@"create"
55  arguments:arguments];
56  __block bool errored = false;
57  FlutterResult result = ^(id result) {
58  if ([result isKindOfClass:[FlutterError class]]) {
59  errored = true;
60  }
61  };
62 
63  [platformViewController handleMethodCall:methodCall result:result];
64 
65  EXPECT_TRUE(errored) << "arguments: " << arguments.description.UTF8String;
66  }
67 }

◆ TEST() [80/148]

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

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

Definition at line 229 of file FlutterPlatformViewControllerTest.mm.

229  {
230  // Use id so we can access handleMethodCall method.
231  id platformViewController = [[FlutterPlatformViewController alloc] init];
232 
233  FlutterMethodCall* methodCall =
234  [FlutterMethodCall methodCallWithMethodName:@"dispose"
235  arguments:[NSNumber numberWithLongLong:20]];
236 
237  __block bool errored = false;
238  FlutterResult result = ^(id result) {
239  if ([result isKindOfClass:[FlutterError class]]) {
240  errored = true;
241  }
242  };
243 
244  [platformViewController handleMethodCall:methodCall result:result];
245 
246  EXPECT_TRUE(errored);
247 }

◆ TEST() [82/148]

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

Definition at line 69 of file FlutterPlatformViewControllerTest.mm.

69  {
70  // Use id so we can access handleMethodCall method.
71  id platformViewController = [[FlutterPlatformViewController alloc] init];
72 
74 
75  [platformViewController registerViewFactory:factory withId:@"MockPlatformView"];
76 
77  NSDictionary* creationArgs = @{
78  @"album" : @"スコットとリバース",
79  @"releaseYear" : @2013,
80  @"artists" : @[ @"Scott Murphy", @"Rivers Cuomo" ],
81  @"playlist" : @[ @"おかしいやつ", @"ほどけていたんだ" ],
82  };
83  NSObject<FlutterMessageCodec>* codec = [factory createArgsCodec];
84  FlutterStandardTypedData* creationArgsData =
85  [FlutterStandardTypedData typedDataWithBytes:[codec encode:creationArgs]];
86 
87  FlutterMethodCall* methodCall =
88  [FlutterMethodCall methodCallWithMethodName:@"create"
89  arguments:@{
90  @"id" : @2,
91  @"viewType" : @"MockPlatformView",
92  @"params" : creationArgsData,
93  }];
94 
95  __block bool success = false;
96  FlutterResult result = ^(id result) {
97  // If a platform view is successfully created, the result is nil.
98  if (result == nil) {
99  success = true;
100  }
101  };
102  [platformViewController handleMethodCall:methodCall result:result];
103  EXPECT_TRUE(success);
104 
105  // Verify PlatformView parameters are decoded correctly.
107  (TestFlutterPlatformView*)[platformViewController platformViewWithID:2];
108  ASSERT_TRUE(view != nil);
109  ASSERT_TRUE(view.args != nil);
110 
111  // Verify string type.
112  NSString* album = [view.args objectForKey:@"album"];
113  EXPECT_TRUE([album isEqualToString:@"スコットとリバース"]);
114 
115  // Verify int type.
116  NSNumber* releaseYear = [view.args objectForKey:@"releaseYear"];
117  EXPECT_EQ(releaseYear.intValue, 2013);
118 
119  // Verify list/array types.
120  NSArray* artists = [view.args objectForKey:@"artists"];
121  ASSERT_TRUE(artists != nil);
122  ASSERT_EQ(artists.count, 2ul);
123  EXPECT_TRUE([artists[0] isEqualToString:@"Scott Murphy"]);
124  EXPECT_TRUE([artists[1] isEqualToString:@"Rivers Cuomo"]);
125 
126  NSArray* playlist = [view.args objectForKey:@"playlist"];
127  ASSERT_EQ(playlist.count, 2ul);
128  EXPECT_TRUE([playlist[0] isEqualToString:@"おかしいやつ"]);
129  EXPECT_TRUE([playlist[1] isEqualToString:@"ほどけていたんだ"]);
130 }
id args
Arguments passed via the params value in the create method call.

References TestFlutterPlatformView::args.

◆ TEST() [83/148]

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

Definition at line 307 of file FlutterPlatformViewControllerTest.mm.

307  {
308  FlutterPlatformViewController* platformViewController =
309  [[FlutterPlatformViewController alloc] init];
310  [platformViewController registerViewFactory:[TestFlutterPlatformViewFactory alloc]
311  withId:@"MockPlatformView"];
312 
313  // Create the PlatformView.
314  const NSNumber* viewId = [NSNumber numberWithLongLong:2];
315  FlutterMethodCall* methodCallOnCreate = [FlutterMethodCall
316  methodCallWithMethodName:@"create"
317  arguments:@{@"id" : viewId, @"viewType" : @"MockPlatformView"}];
318  __block bool created = false;
319  FlutterResult resultOnCreate = ^(id result) {
320  // If a platform view is successfully created, the result is nil.
321  if (result == nil) {
322  created = true;
323  }
324  };
325  [platformViewController handleMethodCall:methodCallOnCreate result:resultOnCreate];
326 
327  // Call rejectGesture.
328  FlutterMethodCall* methodCallRejectGesture =
329  [FlutterMethodCall methodCallWithMethodName:@"rejectGesture" arguments:@{@"id" : viewId}];
330  __block bool rejectGestureCalled = false;
331  FlutterResult resultRejectGesture = ^(id result) {
332  // If a rejectGesture is successful, the result is nil.
333  if (result == nil) {
334  rejectGestureCalled = true;
335  }
336  };
337  [platformViewController handleMethodCall:methodCallRejectGesture result:resultRejectGesture];
338 
339  EXPECT_TRUE(created);
340  EXPECT_TRUE(rejectGestureCalled);
341 }

◆ TEST() [84/148]

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

Definition at line 343 of file FlutterPlatformViewControllerTest.mm.

343  {
344  FlutterPlatformViewController* platformViewController =
345  [[FlutterPlatformViewController alloc] init];
346  [platformViewController registerViewFactory:[TestFlutterPlatformViewFactory alloc]
347  withId:@"MockPlatformView"];
348 
349  // Call rejectGesture.
350  FlutterMethodCall* methodCallRejectGesture =
351  [FlutterMethodCall methodCallWithMethodName:@"rejectGesture" arguments:@{
352  @"id" : @20
353  }];
354  __block bool errored = false;
355  FlutterResult result = ^(id result) {
356  if ([result isKindOfClass:[FlutterError class]]) {
357  errored = true;
358  }
359  };
360  [platformViewController handleMethodCall:methodCallRejectGesture result:result];
361 
362  EXPECT_TRUE(errored);
363 }

◆ TEST() [85/148]

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

Definition at line 175 of file FlutterPlatformViewControllerTest.mm.

175  {
176  // Use id so we can access handleMethodCall method.
177  id platformViewController = [[FlutterPlatformViewController alloc] init];
179 
180  [platformViewController registerViewFactory:factory withId:@"MockPlatformView"];
181 
182  __block bool created = false;
183  FlutterResult resultOnCreate = ^(id result) {
184  // If a platform view is successfully created, the result is nil.
185  if (result == nil) {
186  created = true;
187  } else {
188  created = false;
189  }
190  };
191 
192  // Create 2 views.
193  FlutterMethodCall* methodCallOnCreate0 =
194  [FlutterMethodCall methodCallWithMethodName:@"create"
195  arguments:@{
196  @"id" : @0,
197  @"viewType" : @"MockPlatformView"
198  }];
199 
200  [platformViewController handleMethodCall:methodCallOnCreate0 result:resultOnCreate];
201  EXPECT_TRUE(created);
202 
203  FlutterMethodCall* methodCallOnCreate1 =
204  [FlutterMethodCall methodCallWithMethodName:@"create"
205  arguments:@{
206  @"id" : @1,
207  @"viewType" : @"MockPlatformView"
208  }];
209  [platformViewController handleMethodCall:methodCallOnCreate1 result:resultOnCreate];
210  EXPECT_TRUE(created);
211 
212  TestFlutterPlatformView* view = nil;
213 
214  // Before the reset, the views exist.
215  view = (TestFlutterPlatformView*)[platformViewController platformViewWithID:0];
216  EXPECT_TRUE(view != nil);
217  view = (TestFlutterPlatformView*)[platformViewController platformViewWithID:1];
218  EXPECT_TRUE(view != nil);
219 
220  // After a reset, the views should no longer exist.
221  [platformViewController reset];
222 
223  view = (TestFlutterPlatformView*)[platformViewController platformViewWithID:0];
224  EXPECT_TRUE(view == nil);
225  view = (TestFlutterPlatformView*)[platformViewController platformViewWithID:1];
226  EXPECT_TRUE(view == nil);
227 }

◆ TEST() [86/148]

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

Definition at line 99 of file FlutterSurfaceManagerTest.mm.

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

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

◆ TEST() [87/148]

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

Definition at line 174 of file FlutterSurfaceManagerTest.mm.

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

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

◆ TEST() [88/148]

flutter::testing::TEST ( FlutterSurfaceManager  ,
DynamicSwitchFromStandardToWideGamut   
)

Definition at line 429 of file FlutterSurfaceManagerTest.mm.

429  {
430  TestView* testView = [[TestView alloc] init];
431  FlutterSurfaceManager* surfaceManager = CreateSurfaceManager(testView, /*enableWideGamut=*/NO);
432 
433  // Start with standard gamut surface.
434  auto surface1 = [surfaceManager surfaceForSize:CGSizeMake(100, 50)];
435  auto texture1 = surface1.asFlutterMetalTexture;
436  id<MTLTexture> metalTexture1 = (__bridge id)texture1.texture;
437  EXPECT_EQ(metalTexture1.pixelFormat, MTLPixelFormatBGRA8Unorm);
438  [surfaceManager presentSurfaces:@[ CreatePresentInfo(surface1) ] atTime:0 notify:nil];
439  texture1.destruction_callback(texture1.user_data);
440 
441  // Switch to wide gamut.
442  [surfaceManager setEnableWideGamut:YES];
443 
444  // Verify cache was flushed.
445  EXPECT_EQ(surfaceManager.backBufferCache.count, 0ul);
446 
447  // New surface should be wide gamut.
448  auto surface2 = [surfaceManager surfaceForSize:CGSizeMake(100, 50)];
449  auto texture2 = surface2.asFlutterMetalTexture;
450  id<MTLTexture> metalTexture2 = (__bridge id)texture2.texture;
451  EXPECT_EQ(metalTexture2.pixelFormat, MTLPixelFormatBGRA10_XR);
452  texture2.destruction_callback(texture2.user_data);
453 }
void setEnableWideGamut:(BOOL enableWideGamut)

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

◆ TEST() [89/148]

flutter::testing::TEST ( FlutterSurfaceManager  ,
DynamicSwitchFromWideToStandardGamut   
)

Definition at line 455 of file FlutterSurfaceManagerTest.mm.

455  {
456  TestView* testView = [[TestView alloc] init];
457  FlutterSurfaceManager* surfaceManager = CreateSurfaceManager(testView, /*enableWideGamut=*/YES);
458 
459  // Start with wide gamut surface.
460  auto surface1 = [surfaceManager surfaceForSize:CGSizeMake(100, 50)];
461  auto texture1 = surface1.asFlutterMetalTexture;
462  id<MTLTexture> metalTexture1 = (__bridge id)texture1.texture;
463  EXPECT_EQ(metalTexture1.pixelFormat, MTLPixelFormatBGRA10_XR);
464  [surfaceManager presentSurfaces:@[ CreatePresentInfo(surface1) ] atTime:0 notify:nil];
465  texture1.destruction_callback(texture1.user_data);
466 
467  // Switch to standard gamut.
468  [surfaceManager setEnableWideGamut:NO];
469 
470  // Verify cache was flushed.
471  EXPECT_EQ(surfaceManager.backBufferCache.count, 0ul);
472 
473  // New surface should be standard gamut.
474  auto surface2 = [surfaceManager surfaceForSize:CGSizeMake(100, 50)];
475  auto texture2 = surface2.asFlutterMetalTexture;
476  id<MTLTexture> metalTexture2 = (__bridge id)texture2.texture;
477  EXPECT_EQ(metalTexture2.pixelFormat, MTLPixelFormatBGRA8Unorm);
478  texture2.destruction_callback(texture2.user_data);
479 }

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

◆ TEST() [90/148]

flutter::testing::TEST ( FlutterSurfaceManager  ,
DynamicSwitchNoOpWhenSameValue   
)

Definition at line 481 of file FlutterSurfaceManagerTest.mm.

481  {
482  TestView* testView = [[TestView alloc] init];
483  FlutterSurfaceManager* surfaceManager = CreateSurfaceManager(testView, /*enableWideGamut=*/YES);
484 
485  // Cache a surface.
486  auto surface1 = [surfaceManager surfaceForSize:CGSizeMake(100, 100)];
487  [surfaceManager presentSurfaces:@[ CreatePresentInfo(surface1) ] atTime:0 notify:nil];
488 
489  auto surface2 = [surfaceManager surfaceForSize:CGSizeMake(100, 100)];
490  [surfaceManager presentSurfaces:@[ CreatePresentInfo(surface2) ] atTime:0 notify:nil];
491  EXPECT_EQ(surfaceManager.backBufferCache.count, 1ul);
492 
493  // Set same value — cache should not be flushed.
494  [surfaceManager setEnableWideGamut:YES];
495  EXPECT_EQ(surfaceManager.backBufferCache.count, 1ul);
496 }

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

◆ TEST() [91/148]

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

Definition at line 205 of file FlutterSurfaceManagerTest.mm.

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

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

◆ TEST() [92/148]

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

Definition at line 67 of file FlutterSurfaceManagerTest.mm.

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

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

◆ TEST() [93/148]

flutter::testing::TEST ( FlutterSurfaceManager  ,
StandardGamutIOSurfaceHasCorrectBytesPerElement   
)

Definition at line 397 of file FlutterSurfaceManagerTest.mm.

397  {
398  TestView* testView = [[TestView alloc] init];
399  FlutterSurfaceManager* surfaceManager = CreateSurfaceManager(testView, /*enableWideGamut=*/NO);
400 
401  auto surface = [surfaceManager surfaceForSize:CGSizeMake(100, 50)];
402  IOSurfaceRef ioSurface = surface.ioSurface;
403  size_t bytesPerElement = IOSurfaceGetBytesPerElement(ioSurface);
404  EXPECT_EQ(bytesPerElement, 4ul);
405 }

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

◆ TEST() [94/148]

flutter::testing::TEST ( FlutterSurfaceManager  ,
StandardGamutIOSurfaceHasCorrectColorSpace   
)

Definition at line 352 of file FlutterSurfaceManagerTest.mm.

352  {
353  TestView* testView = [[TestView alloc] init];
354  FlutterSurfaceManager* surfaceManager = CreateSurfaceManager(testView, /*enableWideGamut=*/NO);
355 
356  auto surface = [surfaceManager surfaceForSize:CGSizeMake(100, 50)];
357  IOSurfaceRef ioSurface = surface.ioSurface;
358  CFTypeRef colorSpace = IOSurfaceCopyValue(ioSurface, kIOSurfaceColorSpace);
359  if (colorSpace == nullptr) {
360  GTEST_FAIL() << "IOSurfaceCopyValue returned nullptr for kIOSurfaceColorSpace";
361  return;
362  }
363  EXPECT_TRUE(CFEqual(colorSpace, kCGColorSpaceSRGB));
364  CFRelease(colorSpace);
365 }

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

◆ TEST() [95/148]

flutter::testing::TEST ( FlutterSurfaceManager  ,
StandardGamutIOSurfaceHasCorrectPixelFormat   
)

Definition at line 377 of file FlutterSurfaceManagerTest.mm.

377  {
378  TestView* testView = [[TestView alloc] init];
379  FlutterSurfaceManager* surfaceManager = CreateSurfaceManager(testView, /*enableWideGamut=*/NO);
380 
381  auto surface = [surfaceManager surfaceForSize:CGSizeMake(100, 50)];
382  IOSurfaceRef ioSurface = surface.ioSurface;
383  uint32_t pixelFormat = (uint32_t)IOSurfaceGetPixelFormat(ioSurface);
384  EXPECT_EQ(pixelFormat, (uint32_t)kCVPixelFormatType_32BGRA);
385 }

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

◆ TEST() [96/148]

flutter::testing::TEST ( FlutterSurfaceManager  ,
StandardGamutSurfaceHasCorrectPixelFormat   
)

Definition at line 313 of file FlutterSurfaceManagerTest.mm.

313  {
314  TestView* testView = [[TestView alloc] init];
315  FlutterSurfaceManager* surfaceManager = CreateSurfaceManager(testView, /*enableWideGamut=*/NO);
316 
317  auto surface = [surfaceManager surfaceForSize:CGSizeMake(100, 50)];
318  auto texture = surface.asFlutterMetalTexture;
319  id<MTLTexture> metalTexture = (__bridge id)texture.texture;
320  EXPECT_EQ(metalTexture.pixelFormat, MTLPixelFormatBGRA8Unorm);
321  texture.destruction_callback(texture.user_data);
322 }

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

◆ TEST() [97/148]

flutter::testing::TEST ( FlutterSurfaceManager  ,
SurfaceCacheDoesNotMixGamutModes   
)

Definition at line 407 of file FlutterSurfaceManagerTest.mm.

407  {
408  TestView* testView = [[TestView alloc] init];
409  // Create a wide gamut surface manager.
410  FlutterSurfaceManager* wideManager = CreateSurfaceManager(testView, /*enableWideGamut=*/YES);
411 
412  auto wideSurface = [wideManager surfaceForSize:CGSizeMake(100, 100)];
413  auto wideTexture = wideSurface.asFlutterMetalTexture;
414  id<MTLTexture> wideMetalTexture = (__bridge id)wideTexture.texture;
415  EXPECT_EQ(wideMetalTexture.pixelFormat, MTLPixelFormatBGRA10_XR);
416 
417  // Present and get it cached.
418  [wideManager presentSurfaces:@[ CreatePresentInfo(wideSurface) ] atTime:0 notify:nil];
419  wideTexture.destruction_callback(wideTexture.user_data);
420 
421  // Request same size again - should get a recycled wide gamut surface.
422  auto recycledSurface = [wideManager surfaceForSize:CGSizeMake(100, 100)];
423  auto recycledTexture = recycledSurface.asFlutterMetalTexture;
424  id<MTLTexture> recycledMetalTexture = (__bridge id)recycledTexture.texture;
425  EXPECT_EQ(recycledMetalTexture.pixelFormat, MTLPixelFormatBGRA10_XR);
426  recycledTexture.destruction_callback(recycledTexture.user_data);
427 }

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

◆ TEST() [98/148]

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

Definition at line 135 of file FlutterSurfaceManagerTest.mm.

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

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

◆ TEST() [99/148]

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

Definition at line 80 of file FlutterSurfaceManagerTest.mm.

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

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

◆ TEST() [100/148]

flutter::testing::TEST ( FlutterSurfaceManager  ,
WideGamutIOSurfaceHasCorrectBytesPerElement   
)

Definition at line 387 of file FlutterSurfaceManagerTest.mm.

387  {
388  TestView* testView = [[TestView alloc] init];
389  FlutterSurfaceManager* surfaceManager = CreateSurfaceManager(testView, /*enableWideGamut=*/YES);
390 
391  auto surface = [surfaceManager surfaceForSize:CGSizeMake(100, 50)];
392  IOSurfaceRef ioSurface = surface.ioSurface;
393  size_t bytesPerElement = IOSurfaceGetBytesPerElement(ioSurface);
394  EXPECT_EQ(bytesPerElement, 8ul);
395 }

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

◆ TEST() [101/148]

flutter::testing::TEST ( FlutterSurfaceManager  ,
WideGamutIOSurfaceHasCorrectColorSpace   
)

Definition at line 337 of file FlutterSurfaceManagerTest.mm.

337  {
338  TestView* testView = [[TestView alloc] init];
339  FlutterSurfaceManager* surfaceManager = CreateSurfaceManager(testView, /*enableWideGamut=*/YES);
340 
341  auto surface = [surfaceManager surfaceForSize:CGSizeMake(100, 50)];
342  IOSurfaceRef ioSurface = surface.ioSurface;
343  CFTypeRef colorSpace = IOSurfaceCopyValue(ioSurface, kIOSurfaceColorSpace);
344  if (colorSpace == nullptr) {
345  GTEST_FAIL() << "IOSurfaceCopyValue returned nullptr for kIOSurfaceColorSpace";
346  return;
347  }
348  EXPECT_TRUE(CFEqual(colorSpace, kCGColorSpaceExtendedSRGB));
349  CFRelease(colorSpace);
350 }

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

◆ TEST() [102/148]

flutter::testing::TEST ( FlutterSurfaceManager  ,
WideGamutIOSurfaceHasCorrectPixelFormat   
)

Definition at line 367 of file FlutterSurfaceManagerTest.mm.

367  {
368  TestView* testView = [[TestView alloc] init];
369  FlutterSurfaceManager* surfaceManager = CreateSurfaceManager(testView, /*enableWideGamut=*/YES);
370 
371  auto surface = [surfaceManager surfaceForSize:CGSizeMake(100, 50)];
372  IOSurfaceRef ioSurface = surface.ioSurface;
373  uint32_t pixelFormat = (uint32_t)IOSurfaceGetPixelFormat(ioSurface);
374  EXPECT_EQ(pixelFormat, (uint32_t)kCVPixelFormatType_40ARGBLEWideGamut);
375 }

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

◆ TEST() [103/148]

flutter::testing::TEST ( FlutterSurfaceManager  ,
WideGamutLayerWorksWithoutExplicitContentsFormat   
)

Definition at line 324 of file FlutterSurfaceManagerTest.mm.

324  {
325  TestView* testView = [[TestView alloc] init];
326  FlutterSurfaceManager* surfaceManager = CreateSurfaceManager(testView, /*enableWideGamut=*/YES);
327 
328  auto surface = [surfaceManager surfaceForSize:CGSizeMake(50, 30)];
329  [surfaceManager presentSurfaces:@[ CreatePresentInfo(surface, CGPointMake(0, 0)) ]
330  atTime:0
331  notify:nil];
332 
333  EXPECT_EQ(testView.layer.sublayers.count, 1ul);
334  EXPECT_NE(testView.layer.sublayers[0].contents, nil);
335 }

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

◆ TEST() [104/148]

flutter::testing::TEST ( FlutterSurfaceManager  ,
WideGamutSurfaceHasCorrectPixelFormat   
)

Definition at line 302 of file FlutterSurfaceManagerTest.mm.

302  {
303  TestView* testView = [[TestView alloc] init];
304  FlutterSurfaceManager* surfaceManager = CreateSurfaceManager(testView, /*enableWideGamut=*/YES);
305 
306  auto surface = [surfaceManager surfaceForSize:CGSizeMake(100, 50)];
307  auto texture = surface.asFlutterMetalTexture;
308  id<MTLTexture> metalTexture = (__bridge id)texture.texture;
309  EXPECT_EQ(metalTexture.pixelFormat, MTLPixelFormatBGRA10_XR);
310  texture.destruction_callback(texture.user_data);
311 }

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

◆ TEST() [105/148]

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

Definition at line 2544 of file FlutterTextInputPluginTest.mm.

2544  {
2545  FlutterEngine* engine = CreateTestEngine();
2546  FlutterViewController* viewController = [[FlutterViewController alloc] initWithEngine:engine
2547  nibName:nil
2548  bundle:nil];
2549  [viewController loadView];
2550  // Creates a NSWindow so that the native text field can become first responder.
2551  NSWindow* window = [[NSWindow alloc] initWithContentRect:NSMakeRect(0, 0, 800, 600)
2552  styleMask:NSBorderlessWindowMask
2553  backing:NSBackingStoreBuffered
2554  defer:NO];
2555  window.contentView = viewController.view;
2556 
2557  engine.semanticsEnabled = YES;
2558 
2559  auto bridge = viewController.accessibilityBridge.lock();
2560  FlutterPlatformNodeDelegateMac delegate(bridge, viewController);
2561  ui::AXTree tree;
2562  ui::AXNode ax_node(&tree, nullptr, 0, 0);
2563  ui::AXNodeData node_data;
2564  node_data.SetValue("initial text");
2565  ax_node.SetData(node_data);
2566  delegate.Init(viewController.accessibilityBridge, &ax_node);
2567  FlutterTextPlatformNode text_platform_node(&delegate, viewController);
2568 
2569  FlutterTextField* textField = text_platform_node.GetNativeViewAccessible();
2570  EXPECT_EQ([textField becomeFirstResponder], YES);
2571  // Removes view controller.
2572  [engine setViewController:nil];
2573  FlutterTextPlatformNode text_platform_node_no_controller(&delegate, nil);
2574  textField = text_platform_node_no_controller.GetNativeViewAccessible();
2575  EXPECT_EQ([textField becomeFirstResponder], NO);
2576 }

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

◆ TEST() [106/148]

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

Definition at line 2478 of file FlutterTextInputPluginTest.mm.

2478  {
2479  FlutterEngine* engine = CreateTestEngine();
2480  FlutterViewController* viewController = [[FlutterViewController alloc] initWithEngine:engine
2481  nibName:nil
2482  bundle:nil];
2483  [viewController loadView];
2484  // Create a NSWindow so that the native text field can become first responder.
2485  NSWindow* window = [[NSWindow alloc] initWithContentRect:NSMakeRect(0, 0, 800, 600)
2486  styleMask:NSBorderlessWindowMask
2487  backing:NSBackingStoreBuffered
2488  defer:NO];
2489  window.contentView = viewController.view;
2490 
2491  engine.semanticsEnabled = YES;
2492 
2493  auto bridge = viewController.accessibilityBridge.lock();
2494  FlutterPlatformNodeDelegateMac delegate(bridge, viewController);
2495  ui::AXTree tree;
2496  ui::AXNode ax_node(&tree, nullptr, 0, 0);
2497  ui::AXNodeData node_data;
2498  node_data.SetValue("initial text");
2499  ax_node.SetData(node_data);
2500  delegate.Init(viewController.accessibilityBridge, &ax_node);
2501  {
2502  FlutterTextPlatformNode text_platform_node(&delegate, viewController);
2503 
2504  FlutterTextFieldMock* mockTextField =
2505  [[FlutterTextFieldMock alloc] initWithPlatformNode:&text_platform_node
2506  fieldEditor:engine.textInputPlugin];
2507  [viewController.view addSubview:mockTextField];
2508  [mockTextField startEditing];
2509 
2510  NSDictionary* setClientConfig = @{
2511  @"viewId" : @(flutter::kFlutterImplicitViewId),
2512  @"inputAction" : @"action",
2513  @"inputType" : @{@"name" : @"inputName"},
2514  };
2515  FlutterMethodCall* methodCall =
2516  [FlutterMethodCall methodCallWithMethodName:@"TextInput.setClient"
2517  arguments:@[ @(1), setClientConfig ]];
2518  FlutterResult result = ^(id result) {
2519  };
2520  [engine.textInputPlugin handleMethodCall:methodCall result:result];
2521 
2522  NSDictionary* arguments = @{
2523  @"text" : @"new text",
2524  @"selectionBase" : @(1),
2525  @"selectionExtent" : @(2),
2526  @"composingBase" : @(-1),
2527  @"composingExtent" : @(-1),
2528  };
2529  methodCall = [FlutterMethodCall methodCallWithMethodName:@"TextInput.setEditingState"
2530  arguments:arguments];
2531  [engine.textInputPlugin handleMethodCall:methodCall result:result];
2532  EXPECT_EQ([mockTextField.lastUpdatedString isEqualToString:@"new text"], YES);
2533  EXPECT_EQ(NSEqualRanges(mockTextField.lastUpdatedSelection, NSMakeRange(1, 1)), YES);
2534 
2535  // This blocks the FlutterTextFieldMock, which is held onto by the main event
2536  // loop, from crashing.
2537  [mockTextField setPlatformNode:nil];
2538  }
2539 
2540  // This verifies that clearing the platform node works.
2541  [[NSRunLoop currentRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:0.1]];
2542 }
instancetype methodCallWithMethodName:arguments:(NSString *method,[arguments] id _Nullable arguments)

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

◆ TEST() [107/148]

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

Definition at line 2620 of file FlutterTextInputPluginTest.mm.

2620  {
2621  FlutterEngine* engine = CreateTestEngine();
2622  FlutterViewController* viewController = [[FlutterViewController alloc] initWithEngine:engine
2623  nibName:nil
2624  bundle:nil];
2625  [viewController loadView];
2626 
2627  NSWindow* window = [[NSWindow alloc] initWithContentRect:NSMakeRect(0, 0, 800, 600)
2628  styleMask:NSBorderlessWindowMask
2629  backing:NSBackingStoreBuffered
2630  defer:NO];
2631  window.contentView = viewController.view;
2632 
2633  ASSERT_TRUE(viewController.flutterView.acceptsFirstResponder);
2634 
2635  [window makeFirstResponder:viewController.flutterView];
2636 
2637  NSDictionary* setClientConfig = @{
2638  @"viewId" : @(flutter::kFlutterImplicitViewId),
2639  };
2640  [engine.textInputPlugin
2641  handleMethodCall:[FlutterMethodCall methodCallWithMethodName:@"TextInput.setClient"
2642  arguments:@[ @(1), setClientConfig ]]
2643  result:^(id){
2644  }];
2645 
2646  [engine.textInputPlugin
2647  handleMethodCall:[FlutterMethodCall methodCallWithMethodName:@"TextInput.show" arguments:@[]]
2648  result:^(id){
2649  }];
2650 
2651  ASSERT_TRUE(window.firstResponder == engine.textInputPlugin);
2652 
2653  ASSERT_FALSE(viewController.flutterView.acceptsFirstResponder);
2654 
2655  [engine.textInputPlugin
2656  handleMethodCall:[FlutterMethodCall methodCallWithMethodName:@"TextInput.hide" arguments:@[]]
2657  result:^(id){
2658  }];
2659 
2660  ASSERT_TRUE(viewController.flutterView.acceptsFirstResponder);
2661  ASSERT_TRUE(window.firstResponder == viewController.flutterView);
2662 }

References FlutterMethodCall::methodCallWithMethodName:arguments:.

◆ TEST() [108/148]

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

Definition at line 2402 of file FlutterTextInputPluginTest.mm.

2402  {
2403  ASSERT_TRUE([[FlutterInputPluginTestObjc alloc] handleArrowKeyWhenImePopoverIsActive]);
2404 }

◆ TEST() [109/148]

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

Definition at line 2664 of file FlutterTextInputPluginTest.mm.

2664  {
2665  id engineMock = flutter::testing::CreateMockFlutterEngine(@"");
2666  id binaryMessengerMock = OCMProtocolMock(@protocol(FlutterBinaryMessenger));
2667  OCMStub( // NOLINT(google-objc-avoid-throwing-exception)
2668  [engineMock binaryMessenger])
2669  .andReturn(binaryMessengerMock);
2670 
2671  FlutterViewController* viewController = [[FlutterViewController alloc] initWithEngine:engineMock
2672  nibName:@""
2673  bundle:nil];
2674 
2676  [[FlutterTextInputPluginTestDelegate alloc] initWithBinaryMessenger:binaryMessengerMock
2677  viewController:viewController];
2678 
2679  FlutterTextInputPlugin* plugin = [[FlutterTextInputPlugin alloc] initWithDelegate:delegate];
2680 
2681  ASSERT_TRUE(NSIsEmptyRect(plugin.frame));
2682  ASSERT_TRUE(plugin.clipsToBounds);
2683 }
id CreateMockFlutterEngine(NSString *pasteboardString)

References CreateMockFlutterEngine().

◆ TEST() [110/148]

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

Definition at line 2805 of file FlutterTextInputPluginTest.mm.

2805  {
2806  id engineMock = flutter::testing::CreateMockFlutterEngine(@"");
2807  id binaryMessengerMock = OCMProtocolMock(@protocol(FlutterBinaryMessenger));
2808  OCMStub( // NOLINT(google-objc-avoid-throwing-exception)
2809  [engineMock binaryMessenger])
2810  .andReturn(binaryMessengerMock);
2811 
2812  FlutterViewController* viewController = [[FlutterViewController alloc] initWithEngine:engineMock
2813  nibName:@""
2814  bundle:nil];
2815 
2817  [[FlutterTextInputPluginTestDelegate alloc] initWithBinaryMessenger:binaryMessengerMock
2818  viewController:viewController];
2819 
2820  FlutterTextInputPlugin* plugin = [[FlutterTextInputPlugin alloc] initWithDelegate:delegate];
2821 
2822  NSDictionary* setClientConfig = @{
2823  @"viewId" : @(kViewId),
2824  @"inputAction" : @"action",
2825  @"inputType" : @{@"name" : @"inputName"},
2826  };
2827  [plugin handleMethodCall:[FlutterMethodCall methodCallWithMethodName:@"TextInput.setClient"
2828  arguments:@[ @(1), setClientConfig ]]
2829  result:^(id){
2830  }];
2831 
2832  // Test with empty NSAttributedString
2833  NSAttributedString* emptyAttributedString = [[NSAttributedString alloc] initWithString:@""];
2834  [plugin insertText:emptyAttributedString replacementRange:NSMakeRange(NSNotFound, 0)];
2835 
2836  NSDictionary* editingState = [plugin editingState];
2837  EXPECT_STREQ([editingState[@"text"] UTF8String], "");
2838  EXPECT_EQ([editingState[@"selectionBase"] intValue], 0);
2839  EXPECT_EQ([editingState[@"selectionExtent"] intValue], 0);
2840 }
static const FlutterViewIdentifier kViewId
void handleMethodCall:result:(FlutterMethodCall *call,[result] FlutterResult result)
NSDictionary * editingState()

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

◆ TEST() [111/148]

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

Definition at line 2718 of file FlutterTextInputPluginTest.mm.

2718  {
2719  id engineMock = flutter::testing::CreateMockFlutterEngine(@"");
2720  id binaryMessengerMock = OCMProtocolMock(@protocol(FlutterBinaryMessenger));
2721  OCMStub( // NOLINT(google-objc-avoid-throwing-exception)
2722  [engineMock binaryMessenger])
2723  .andReturn(binaryMessengerMock);
2724 
2725  FlutterViewController* viewController = [[FlutterViewController alloc] initWithEngine:engineMock
2726  nibName:@""
2727  bundle:nil];
2728 
2730  [[FlutterTextInputPluginTestDelegate alloc] initWithBinaryMessenger:binaryMessengerMock
2731  viewController:viewController];
2732 
2733  FlutterTextInputPlugin* plugin = [[FlutterTextInputPlugin alloc] initWithDelegate:delegate];
2734 
2735  NSDictionary* setClientConfig = @{
2736  @"viewId" : @(kViewId),
2737  @"inputAction" : @"action",
2738  @"inputType" : @{@"name" : @"inputName"},
2739  };
2740  [plugin handleMethodCall:[FlutterMethodCall methodCallWithMethodName:@"TextInput.setClient"
2741  arguments:@[ @(1), setClientConfig ]]
2742  result:^(id){
2743  }];
2744 
2745  // Test with NSAttributedString
2746  NSAttributedString* attributedString =
2747  [[NSAttributedString alloc] initWithString:@"attributed text"];
2748  [plugin insertText:attributedString replacementRange:NSMakeRange(NSNotFound, 0)];
2749 
2750  NSDictionary* editingState = [plugin editingState];
2751  EXPECT_STREQ([editingState[@"text"] UTF8String], "attributed text");
2752  EXPECT_EQ([editingState[@"selectionBase"] intValue], 15);
2753  EXPECT_EQ([editingState[@"selectionExtent"] intValue], 15);
2754 }

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

◆ TEST() [112/148]

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

Definition at line 2713 of file FlutterTextInputPluginTest.mm.

2713  {
2714  ASSERT_TRUE(
2715  [[FlutterInputPluginTestObjc alloc] testInsertTextWithCollapsedSelectionInsideComposing]);
2716 }

◆ TEST() [113/148]

flutter::testing::TEST ( FlutterTextInputPluginTest  ,
InsertTextWithReversedReplacementRange   
)

Definition at line 2756 of file FlutterTextInputPluginTest.mm.

2756  {
2757  id engineMock = flutter::testing::CreateMockFlutterEngine(@"");
2758  id binaryMessengerMock = OCMProtocolMock(@protocol(FlutterBinaryMessenger));
2759  OCMStub( // NOLINT(google-objc-avoid-throwing-exception)
2760  [engineMock binaryMessenger])
2761  .andReturn(binaryMessengerMock);
2762 
2763  FlutterViewController* viewController = [[FlutterViewController alloc] initWithEngine:engineMock
2764  nibName:@""
2765  bundle:nil];
2766 
2768  [[FlutterTextInputPluginTestDelegate alloc] initWithBinaryMessenger:binaryMessengerMock
2769  viewController:viewController];
2770 
2771  FlutterTextInputPlugin* plugin = [[FlutterTextInputPlugin alloc] initWithDelegate:delegate];
2772 
2773  NSDictionary* setClientConfig = @{
2774  @"viewId" : @(kViewId),
2775  @"inputAction" : @"action",
2776  @"inputType" : @{@"name" : @"inputName"},
2777  };
2778  [plugin handleMethodCall:[FlutterMethodCall methodCallWithMethodName:@"TextInput.setClient"
2779  arguments:@[ @(1), setClientConfig ]]
2780  result:^(id){
2781  }];
2782 
2783  [plugin handleMethodCall:[FlutterMethodCall methodCallWithMethodName:@"TextInput.setEditingState"
2784  arguments:@{
2785  @"text" : @"12345",
2786  @"selectionBase" : @(5),
2787  @"selectionExtent" : @(5),
2788  @"composingBase" : @(-1),
2789  @"composingExtent" : @(-1),
2790  }]
2791  result:^(id){
2792  }];
2793 
2794  // A selection made backwards arrives as a range whose length is negative when
2795  // read as a signed value. The two characters before the location are the ones
2796  // replaced; read unsigned, the range would instead cover the text after it.
2797  [plugin insertText:@"X" replacementRange:NSMakeRange(4, static_cast<NSUInteger>(-2))];
2798 
2799  NSDictionary* editingState = [plugin editingState];
2800  EXPECT_STREQ([editingState[@"text"] UTF8String], "12X5");
2801  EXPECT_EQ([editingState[@"selectionBase"] intValue], 3);
2802  EXPECT_EQ([editingState[@"selectionExtent"] intValue], 3);
2803 }

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

◆ TEST() [114/148]

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

Definition at line 2578 of file FlutterTextInputPluginTest.mm.

2578  {
2579  FlutterEngine* engine = CreateTestEngine();
2580  FlutterViewController* viewController = [[FlutterViewController alloc] initWithEngine:engine
2581  nibName:nil
2582  bundle:nil];
2583  [viewController loadView];
2584 
2585  NSWindow* window = [[NSWindow alloc] initWithContentRect:NSMakeRect(0, 0, 800, 600)
2586  styleMask:NSBorderlessWindowMask
2587  backing:NSBackingStoreBuffered
2588  defer:NO];
2589  window.contentView = viewController.view;
2590 
2591  ASSERT_EQ(engine.textInputPlugin.superview, nil);
2592  ASSERT_FALSE(window.firstResponder == engine.textInputPlugin);
2593 
2594  NSDictionary* setClientConfig = @{
2595  @"viewId" : @(flutter::kFlutterImplicitViewId),
2596  };
2597  [engine.textInputPlugin
2598  handleMethodCall:[FlutterMethodCall methodCallWithMethodName:@"TextInput.setClient"
2599  arguments:@[ @(1), setClientConfig ]]
2600  result:^(id){
2601  }];
2602 
2603  [engine.textInputPlugin
2604  handleMethodCall:[FlutterMethodCall methodCallWithMethodName:@"TextInput.show" arguments:@[]]
2605  result:^(id){
2606  }];
2607 
2608  ASSERT_EQ(engine.textInputPlugin.superview, viewController.view);
2609  ASSERT_TRUE(window.firstResponder == engine.textInputPlugin);
2610 
2611  [engine.textInputPlugin
2612  handleMethodCall:[FlutterMethodCall methodCallWithMethodName:@"TextInput.hide" arguments:@[]]
2613  result:^(id){
2614  }];
2615 
2616  ASSERT_EQ(engine.textInputPlugin.superview, nil);
2617  ASSERT_FALSE(window.firstResponder == engine.textInputPlugin);
2618 }

References FlutterMethodCall::methodCallWithMethodName:arguments:.

◆ TEST() [115/148]

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

Definition at line 2426 of file FlutterTextInputPluginTest.mm.

2426  {
2427  id engineMock = flutter::testing::CreateMockFlutterEngine(@"");
2428  id binaryMessengerMock = OCMProtocolMock(@protocol(FlutterBinaryMessenger));
2429  OCMStub( // NOLINT(google-objc-avoid-throwing-exception)
2430  [engineMock binaryMessenger])
2431  .andReturn(binaryMessengerMock);
2432 
2433  FlutterViewController* viewController = [[FlutterViewController alloc] initWithEngine:engineMock
2434  nibName:@""
2435  bundle:nil];
2436 
2438  [[FlutterTextInputPluginTestDelegate alloc] initWithBinaryMessenger:binaryMessengerMock
2439  viewController:viewController];
2440 
2441  FlutterTextInputPlugin* plugin = [[FlutterTextInputPlugin alloc] initWithDelegate:delegate];
2442 
2443  NSDictionary* setClientConfig = @{
2444  @"viewId" : @(kViewId),
2445  @"inputAction" : @"action",
2446  @"enableDeltaModel" : @"true",
2447  @"inputType" : @{@"name" : @"inputName"},
2448  };
2449  [plugin handleMethodCall:[FlutterMethodCall methodCallWithMethodName:@"TextInput.setClient"
2450  arguments:@[ @(1), setClientConfig ]]
2451  result:^(id){
2452  }];
2453 
2454  FlutterMethodCall* call = [FlutterMethodCall methodCallWithMethodName:@"TextInput.setEditingState"
2455  arguments:@{
2456  @"text" : @"Text",
2457  @"selectionBase" : @(0),
2458  @"selectionExtent" : @(0),
2459  @"composingBase" : @(-1),
2460  @"composingExtent" : @(-1),
2461  }];
2462 
2463  [plugin handleMethodCall:call
2464  result:^(id){
2465  }];
2466 
2467  NSRange out;
2468  NSAttributedString* text = [plugin attributedSubstringForProposedRange:NSMakeRange(1, 10)
2469  actualRange:&out];
2470  EXPECT_TRUE([text.string isEqualToString:@"ext"]);
2471  EXPECT_EQ(out.location, 1u);
2472  EXPECT_EQ(out.length, 3u);
2473 
2474  text = [plugin attributedSubstringForProposedRange:NSMakeRange(4, 10) actualRange:&out];
2475  EXPECT_EQ(text, nil);
2476 }

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

◆ TEST() [116/148]

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

Definition at line 2360 of file FlutterTextInputPluginTest.mm.

2360  {
2361  ASSERT_TRUE([[FlutterInputPluginTestObjc alloc]
2362  testAutocompleteDisabledWhenAutofillGroupIncludesPassword]);
2363 }

◆ TEST() [117/148]

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

Definition at line 2340 of file FlutterTextInputPluginTest.mm.

2340  {
2341  ASSERT_TRUE([[FlutterInputPluginTestObjc alloc] testAutocompleteDisabledWhenAutofillNotSet]);
2342 }

◆ TEST() [118/148]

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

Definition at line 2352 of file FlutterTextInputPluginTest.mm.

2352  {
2353  ASSERT_TRUE([[FlutterInputPluginTestObjc alloc] testAutocompleteDisabledWhenObscureTextSet]);
2354 }

◆ TEST() [119/148]

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

Definition at line 2356 of file FlutterTextInputPluginTest.mm.

2356  {
2357  ASSERT_TRUE([[FlutterInputPluginTestObjc alloc] testAutocompleteDisabledWhenPasswordAutofillSet]);
2358 }

◆ TEST() [120/148]

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

Definition at line 2344 of file FlutterTextInputPluginTest.mm.

2344  {
2345  ASSERT_TRUE([[FlutterInputPluginTestObjc alloc] testAutocompleteEnabledWhenAutofillSet]);
2346 }

◆ TEST() [121/148]

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

Definition at line 2348 of file FlutterTextInputPluginTest.mm.

2348  {
2349  ASSERT_TRUE([[FlutterInputPluginTestObjc alloc] testAutocompleteEnabledWhenAutofillSetNoHint]);
2350 }

◆ TEST() [122/148]

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

Definition at line 2336 of file FlutterTextInputPluginTest.mm.

2336  {
2337  ASSERT_TRUE([[FlutterInputPluginTestObjc alloc] testClearClientDuringComposing]);
2338 }

◆ TEST() [123/148]

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

Definition at line 2332 of file FlutterTextInputPluginTest.mm.

2332  {
2333  ASSERT_TRUE([[FlutterInputPluginTestObjc alloc] testComposingRegionRemovedByFramework]);
2334 }

◆ TEST() [124/148]

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

Definition at line 2386 of file FlutterTextInputPluginTest.mm.

2386  {
2387  ASSERT_TRUE([[FlutterInputPluginTestObjc alloc] testComposingWithDelta]);
2388 }

◆ TEST() [125/148]

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

Definition at line 2390 of file FlutterTextInputPluginTest.mm.

2390  {
2391  ASSERT_TRUE([[FlutterInputPluginTestObjc alloc] testComposingWithDeltasWhenSelectionIsActive]);
2392 }

◆ TEST() [126/148]

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

Definition at line 2308 of file FlutterTextInputPluginTest.mm.

2308  {
2309  ASSERT_TRUE([[FlutterInputPluginTestObjc alloc] testEmptyCompositionRange]);
2310 }

◆ TEST() [127/148]

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

Definition at line 2365 of file FlutterTextInputPluginTest.mm.

2365  {
2366  ASSERT_TRUE([[FlutterInputPluginTestObjc alloc] testFirstRectForCharacterRange]);
2367 }

◆ TEST() [128/148]

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

Definition at line 2369 of file FlutterTextInputPluginTest.mm.

2369  {
2370  ASSERT_TRUE([[FlutterInputPluginTestObjc alloc] testFirstRectForCharacterRangeAtInfinity]);
2371 }

◆ TEST() [129/148]

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

Definition at line 2373 of file FlutterTextInputPluginTest.mm.

2373  {
2374  ASSERT_TRUE([[FlutterInputPluginTestObjc alloc]
2375  testFirstRectForCharacterRangeWithEsotericAffineTransform]);
2376 }

◆ TEST() [130/148]

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

Definition at line 2418 of file FlutterTextInputPluginTest.mm.

2418  {
2419  ASSERT_TRUE([[FlutterInputPluginTestObjc alloc] testInsertNewLine]);
2420 }

◆ TEST() [131/148]

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

Definition at line 2394 of file FlutterTextInputPluginTest.mm.

2394  {
2395  ASSERT_TRUE([[FlutterInputPluginTestObjc alloc] testLocalTextAndSelectionUpdateAfterDelta]);
2396 }

◆ TEST() [132/148]

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

Definition at line 2382 of file FlutterTextInputPluginTest.mm.

2382  {
2383  ASSERT_TRUE([[FlutterInputPluginTestObjc alloc] testOperationsThatTriggerDelta]);
2384 }

◆ TEST() [133/148]

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

Definition at line 2398 of file FlutterTextInputPluginTest.mm.

2398  {
2399  ASSERT_TRUE([[FlutterInputPluginTestObjc alloc] testPerformKeyEquivalent]);
2400 }

◆ TEST() [134/148]

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

Definition at line 2410 of file FlutterTextInputPluginTest.mm.

2410  {
2411  ASSERT_TRUE([[FlutterInputPluginTestObjc alloc] testSelectorsAreForwardedToFramework]);
2412 }

◆ TEST() [135/148]

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

Definition at line 2414 of file FlutterTextInputPluginTest.mm.

2414  {
2415  ASSERT_TRUE([[FlutterInputPluginTestObjc alloc] testSelectorsNotForwardedToFrameworkIfNoClient]);
2416 }

◆ TEST() [136/148]

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

Definition at line 2422 of file FlutterTextInputPluginTest.mm.

2422  {
2423  ASSERT_TRUE([[FlutterInputPluginTestObjc alloc] testSendActionDoNotInsertNewLine]);
2424 }

◆ TEST() [137/148]

flutter::testing::TEST ( FlutterTextInputPluginTest  ,
TestSetEditingStateWithOutOfBoundsSelection   
)

Definition at line 2328 of file FlutterTextInputPluginTest.mm.

2328  {
2329  ASSERT_TRUE([[FlutterInputPluginTestObjc alloc] testSetEditingStateWithOutOfBoundsSelection]);
2330 }

◆ TEST() [138/148]

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

Definition at line 2378 of file FlutterTextInputPluginTest.mm.

2378  {
2379  ASSERT_TRUE([[FlutterInputPluginTestObjc alloc] testSetEditingStateWithTextEditingDelta]);
2380 }

◆ TEST() [139/148]

flutter::testing::TEST ( FlutterTextInputPluginTest  ,
TestSetMarkedTextWithOutOfBoundsRanges   
)

Definition at line 2324 of file FlutterTextInputPluginTest.mm.

2324  {
2325  ASSERT_TRUE([[FlutterInputPluginTestObjc alloc] testSetMarkedTextWithOutOfBoundsRanges]);
2326 }

◆ TEST() [140/148]

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

Definition at line 2316 of file FlutterTextInputPluginTest.mm.

2316  {
2317  ASSERT_TRUE([[FlutterInputPluginTestObjc alloc] testSetMarkedTextWithReplacementRange]);
2318 }

◆ TEST() [141/148]

flutter::testing::TEST ( FlutterTextInputPluginTest  ,
TestSetMarkedTextWithSelectedRangeNotFound   
)

Definition at line 2320 of file FlutterTextInputPluginTest.mm.

2320  {
2321  ASSERT_TRUE([[FlutterInputPluginTestObjc alloc] testSetMarkedTextWithSelectedRangeNotFound]);
2322 }

◆ TEST() [142/148]

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

Definition at line 2312 of file FlutterTextInputPluginTest.mm.

2312  {
2313  ASSERT_TRUE([[FlutterInputPluginTestObjc alloc] testSetMarkedTextWithSelectionChange]);
2314 }

◆ TEST() [143/148]

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

Definition at line 2406 of file FlutterTextInputPluginTest.mm.

2406  {
2407  ASSERT_TRUE([[FlutterInputPluginTestObjc alloc] unhandledKeyEquivalent]);
2408 }

◆ TEST() [144/148]

flutter::testing::TEST ( FlutterTextInputPluginTest  ,
WillUseParentControllerIfCanNotBecomeKey   
)

Definition at line 2842 of file FlutterTextInputPluginTest.mm.

2842  {
2843  id engineMock = flutter::testing::CreateMockFlutterEngine(@"");
2844  id binaryMessengerMock = OCMProtocolMock(@protocol(FlutterBinaryMessenger));
2845  OCMStub( // NOLINT(google-objc-avoid-throwing-exception)
2846  [engineMock binaryMessenger])
2847  .andReturn(binaryMessengerMock);
2848 
2849  [engineMock enableMultiView];
2850  [engineMock runWithEntrypoint:nil];
2851 
2852  // Create popupContoller1 first so that its viewId (1) matches kViewId
2853  FlutterViewController* popupController1 = [[FlutterViewController alloc] initWithEngine:engineMock
2854  nibName:nil
2855  bundle:nil];
2856  FlutterViewController* popupController2 = [[FlutterViewController alloc] initWithEngine:engineMock
2857  nibName:nil
2858  bundle:nil];
2859  FlutterViewController* rootViewController =
2860  [[FlutterViewController alloc] initWithEngine:engineMock nibName:nil bundle:nil];
2861 
2862  // Configure window hierarchy
2863  // RootWindow (canBecomeKeyWindow=YES)
2864  // PopupWindow1 (canBecomeKeyWindow=NO)
2865  // PopupWindow2 (canBecomeKeyWindow=NO)
2866 
2867  NSWindow* rootWindow = [[NSWindow alloc] initWithContentRect:NSZeroRect
2868  styleMask:NSWindowStyleMaskTitled
2869  backing:NSBackingStoreBuffered
2870  defer:NO];
2871  rootWindow.contentViewController = rootViewController;
2872 
2873  NSWindow* popupWindow1 = [[NSWindow alloc] initWithContentRect:NSZeroRect
2874  styleMask:NSWindowStyleMaskBorderless
2875  backing:NSBackingStoreBuffered
2876  defer:NO];
2877  popupWindow1.contentViewController = popupController1;
2878  [rootWindow addChildWindow:popupWindow1 ordered:NSWindowAbove];
2879 
2880  NSWindow* popupWindow2 = [[NSWindow alloc] initWithContentRect:NSZeroRect
2881  styleMask:NSWindowStyleMaskBorderless
2882  backing:NSBackingStoreBuffered
2883  defer:NO];
2884  popupWindow2.contentViewController = popupController2;
2885  [popupWindow1 addChildWindow:popupWindow2 ordered:NSWindowAbove];
2886 
2887  // Initialize delegate with PopupWindow2 (can not become key window)
2889  [[FlutterTextInputPluginTestDelegate alloc] initWithBinaryMessenger:binaryMessengerMock
2890  viewController:popupController2];
2891 
2892  FlutterTextInputPlugin* plugin = [[FlutterTextInputPlugin alloc] initWithDelegate:delegate];
2893 
2894  NSDictionary* setClientConfig = @{
2895  @"viewId" : @(kViewId),
2896  @"inputAction" : @"action",
2897  @"inputType" : @{@"name" : @"inputName"},
2898  };
2899  [plugin handleMethodCall:[FlutterMethodCall methodCallWithMethodName:@"TextInput.setClient"
2900  arguments:@[ @(1), setClientConfig ]]
2901  result:^(id){
2902  }];
2903 
2904  // Make sure that TextInputPlugin uses the ancestor controller that has
2905  // canBecomeKey set to YES.
2906  EXPECT_EQ(plugin.currentViewController, rootViewController);
2907 }
FlutterViewController * currentViewController

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

◆ TEST() [145/148]

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

Definition at line 2685 of file FlutterTextInputPluginTest.mm.

2685  {
2686  id engineMock = flutter::testing::CreateMockFlutterEngine(@"");
2687  id binaryMessengerMock = OCMProtocolMock(@protocol(FlutterBinaryMessenger));
2688  OCMStub( // NOLINT(google-objc-avoid-throwing-exception)
2689  [engineMock binaryMessenger])
2690  .andReturn(binaryMessengerMock);
2691 
2692  FlutterViewController* viewController = [[FlutterViewController alloc] initWithEngine:engineMock
2693  nibName:@""
2694  bundle:nil];
2695 
2697  [[FlutterTextInputPluginTestDelegate alloc] initWithBinaryMessenger:binaryMessengerMock
2698  implicitViewController:viewController];
2699 
2700  FlutterTextInputPlugin* plugin = [[FlutterTextInputPlugin alloc] initWithDelegate:delegate];
2701 
2702  NSDictionary* setClientConfig = @{
2703  // omit viewId
2704  };
2705  [plugin handleMethodCall:[FlutterMethodCall methodCallWithMethodName:@"TextInput.setClient"
2706  arguments:@[ @(1), setClientConfig ]]
2707  result:^(id){
2708  }];
2709 
2710  ASSERT_TRUE(plugin.currentViewController == viewController);
2711 }

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

◆ TEST() [146/148]

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

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 }
int64_t FlutterViewIdentifier

References CreateMockFlutterEngine().

◆ TEST() [148/148]

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 }
const std::vector< LayoutGoal > kLayoutGoals

References flutter::kLayoutGoals.

◆ TEST_F() [1/93]

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

Definition at line 222 of file AccessibilityBridgeMacTest.mm.

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

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

◆ TEST_F() [2/93]

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

Definition at line 271 of file AccessibilityBridgeMacTest.mm.

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

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

◆ TEST_F() [3/93]

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

Definition at line 151 of file AccessibilityBridgeMacTest.mm.

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

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

◆ TEST_F() [4/93]

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

Definition at line 91 of file AccessibilityBridgeMacTest.mm.

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

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

◆ TEST_F() [5/93]

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 }
NSMutableArray< id > * messages

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

◆ TEST_F() [6/93]

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

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 }
NSMutableDictionary< NSNumber *, NSNumber * > * layoutMap

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

◆ TEST_F() [8/93]

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 }
BOOL populateTexture:(nonnull FlutterMetalExternalTexture *metalTexture)
int64_t texture_id

References FlutterExternalTexture::populateTexture:, and texture_id.

◆ TEST_F() [9/93]

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 }
static std::shared_ptr< impeller::ContextMTL > CreateImpellerContext()

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

◆ TEST_F() [10/93]

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

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

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

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

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

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

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

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

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

Definition at line 932 of file FlutterEngineTest.mm.

932  {
933  FlutterEngine* engine = GetFlutterEngine();
934 
935  BOOL signaled = NO;
936  std::optional<int64_t> engineId;
937  AddFfiNativeCallback("NotifyEngineId", CREATE_FFI_LAMBDA([&](Dart_Handle argument) {
938  if (!Dart_IsNull(argument)) {
939  const auto id = tonic::DartConverter<int64_t>::FromDart(argument);
940  engineId = id;
941  }
942  signaled = YES;
943  }));
944 
945  EXPECT_TRUE([engine runWithEntrypoint:@"testEngineId"]);
946  while (!signaled) {
947  CFRunLoopRunInMode(kCFRunLoopDefaultMode, 1, YES);
948  }
949 
950  EXPECT_TRUE(engineId.has_value());
951  if (!engineId.has_value()) {
952  return;
953  }
954  id<FlutterPluginRegistrar> registrar = [engine registrarForPlugin:@"MyPlugin"];
955  EXPECT_EQ(engine.engineIdentifier, *engineId);
956  EXPECT_EQ(registrar.engineIdentifier, *engineId);
957  EXPECT_EQ(engine, [FlutterEngine engineForIdentifier:*engineId]);
958  ShutDownEngine();
959 }

◆ TEST_F() [19/93]

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

Definition at line 144 of file FlutterEngineTest.mm.

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

◆ TEST_F() [20/93]

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

Definition at line 217 of file FlutterEngineTest.mm.

217  {
218  // Block until completion of print statement.
219  BOOL signaled = NO;
220  AddFfiNativeCallback("SignalNativeTest", CREATE_FFI_LAMBDA([&]() { signaled = YES; }));
221 
222  // Replace stdout stream buffer with our own.
223  FlutterStringOutputWriter* writer = [[FlutterStringOutputWriter alloc] init];
224  writer.expectedOutput = @"Hello logging";
225  FlutterLogger.outputWriter = writer;
226 
227  // Launch the test entrypoint.
228  FlutterEngine* engine = GetFlutterEngine();
229  EXPECT_TRUE([engine runWithEntrypoint:@"canLogToStdout"]);
230  ASSERT_TRUE(engine.running);
231 
232  while (!signaled) {
233  CFRunLoopRunInMode(kCFRunLoopDefaultMode, 1, YES);
234  }
235 
236  // Verify hello world was written to stdout.
237  EXPECT_TRUE(writer.gotExpectedOutput);
238 }

◆ TEST_F() [21/93]

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

Definition at line 303 of file FlutterEngineTest.mm.

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

References user_data, and FlutterEngine::viewController.

◆ TEST_F() [22/93]

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

Definition at line 401 of file FlutterEngineTest.mm.

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

References user_data, and FlutterEngine::viewController.

◆ TEST_F() [23/93]

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

Definition at line 525 of file FlutterEngineTest.mm.

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

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

◆ TEST_F() [24/93]

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

Definition at line 571 of file FlutterEngineTest.mm.

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

References FlutterEngine::shutDownEngine, and user_data.

◆ TEST_F() [25/93]

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

Definition at line 620 of file FlutterEngineTest.mm.

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

References FlutterEngine::shutDownEngine, and user_data.

◆ TEST_F() [26/93]

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

Definition at line 240 of file FlutterEngineTest.mm.

240  {
241  FlutterEngine* engine = GetFlutterEngine();
242 
243  // Latch to ensure the entire layer tree has been generated and presented.
244  BOOL signaled = NO;
245  AddFfiNativeCallback("SignalNativeTest", CREATE_FFI_LAMBDA([&]() {
246  CALayer* rootLayer = engine.viewController.flutterView.layer;
247  EXPECT_TRUE(rootLayer.backgroundColor != nil);
248  if (rootLayer.backgroundColor != nil) {
249  NSColor* actualBackgroundColor =
250  [NSColor colorWithCGColor:rootLayer.backgroundColor];
251  EXPECT_EQ(actualBackgroundColor, [NSColor blackColor]);
252  }
253  signaled = YES;
254  }));
255 
256  // Launch the test entrypoint.
257  EXPECT_TRUE([engine runWithEntrypoint:@"backgroundTest"]);
258  ASSERT_TRUE(engine.running);
259 
260  FlutterViewController* viewController = [[FlutterViewController alloc] initWithEngine:engine
261  nibName:nil
262  bundle:nil];
263  [viewController loadView];
264  viewController.flutterView.frame = CGRectMake(0, 0, 800, 600);
265 
266  while (!signaled) {
267  CFRunLoopRunInMode(kCFRunLoopDefaultMode, 1, YES);
268  }
269 }

References FlutterEngine::viewController.

◆ TEST_F() [27/93]

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

Definition at line 271 of file FlutterEngineTest.mm.

271  {
272  FlutterEngine* engine = GetFlutterEngine();
273 
274  // Latch to ensure the entire layer tree has been generated and presented.
275  BOOL signaled = NO;
276  AddFfiNativeCallback("SignalNativeTest", CREATE_FFI_LAMBDA([&]() {
277  CALayer* rootLayer = engine.viewController.flutterView.layer;
278  EXPECT_TRUE(rootLayer.backgroundColor != nil);
279  if (rootLayer.backgroundColor != nil) {
280  NSColor* actualBackgroundColor =
281  [NSColor colorWithCGColor:rootLayer.backgroundColor];
282  EXPECT_EQ(actualBackgroundColor, [NSColor whiteColor]);
283  }
284  signaled = YES;
285  }));
286 
287  // Launch the test entrypoint.
288  EXPECT_TRUE([engine runWithEntrypoint:@"backgroundTest"]);
289  ASSERT_TRUE(engine.running);
290 
291  FlutterViewController* viewController = [[FlutterViewController alloc] initWithEngine:engine
292  nibName:nil
293  bundle:nil];
294  [viewController loadView];
295  viewController.flutterView.frame = CGRectMake(0, 0, 800, 600);
296  viewController.flutterView.backgroundColor = [NSColor whiteColor];
297 
298  while (!signaled) {
299  CFRunLoopRunInMode(kCFRunLoopDefaultMode, 1, YES);
300  }
301 }

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

◆ TEST_F() [28/93]

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

Definition at line 1374 of file FlutterEngineTest.mm.

1374  {
1375  NSString* fixtures = @(testing::GetFixturesPath());
1376  FlutterDartProject* project = [[FlutterDartProject alloc]
1377  initWithAssetsPath:fixtures
1378  ICUDataPath:[fixtures stringByAppendingString:@"/icudtl.dat"]];
1379  project.rootIsolateCreateCallback = FlutterEngineTest::IsolateCreateCallback;
1380  MockableFlutterEngine* engine = [[MockableFlutterEngine alloc] initWithName:@"foobar"
1381  project:project
1382  allowHeadlessExecution:true];
1383  BOOL updated = NO;
1384  auto original_update_displays = engine.embedderAPI.NotifyDisplayUpdate;
1385  engine.embedderAPI.NotifyDisplayUpdate = MOCK_ENGINE_PROC(
1386  NotifyDisplayUpdate, ([&updated, &original_update_displays](
1387  auto engine, auto update_type, auto* displays, auto display_count) {
1388  EXPECT_EQ(display_count, 1UL);
1389  EXPECT_EQ(displays->display_id, 10UL);
1390  EXPECT_EQ(displays->width, 60UL);
1391  EXPECT_EQ(displays->height, 80UL);
1392  EXPECT_EQ(displays->device_pixel_ratio, 2UL);
1393  updated = YES;
1394  return original_update_displays(engine, update_type, displays, display_count);
1395  }));
1396  EXPECT_TRUE([engine runWithEntrypoint:@"main"]);
1397  EXPECT_TRUE(updated);
1398  [engine shutDownEngine];
1399  engine = nil;
1400 }

References FlutterEngine::shutDownEngine.

◆ TEST_F() [29/93]

flutter::testing::TEST_F ( FlutterEngineTest  ,
EnableSDFsAlwaysReturnsYes   
)

Definition at line 190 of file FlutterEngineTest.mm.

190  {
191  NSString* fixtures = @(flutter::testing::GetFixturesPath());
192  FlutterDartProject* project = [[FlutterDartProject alloc]
193  initWithAssetsPath:fixtures
194  ICUDataPath:[fixtures stringByAppendingString:@"/icudtl.dat"]];
195  EXPECT_TRUE([project enableSDFs]);
196 }

◆ TEST_F() [30/93]

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

Definition at line 659 of file FlutterEngineTest.mm.

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

References FlutterEngine::binaryMessenger.

◆ TEST_F() [31/93]

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

Definition at line 683 of file FlutterEngineTest.mm.

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

◆ TEST_F() [32/93]

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

Definition at line 1287 of file FlutterEngineTest.mm.

1287  {
1288  id<NSApplicationDelegate> previousDelegate = [[NSApplication sharedApplication] delegate];
1289  FakeLifecycleProvider* fakeAppDelegate = [[FakeLifecycleProvider alloc] init];
1290  [NSApplication sharedApplication].delegate = fakeAppDelegate;
1291 
1292  FakeAppDelegatePlugin* plugin = [[FakeAppDelegatePlugin alloc] init];
1293  FlutterEngine* engine = CreateMockFlutterEngine(nil);
1294 
1295  [[engine registrarForPlugin:@"TestPlugin"] addApplicationDelegate:plugin];
1296 
1297  EXPECT_TRUE([fakeAppDelegate hasDelegate:plugin]);
1298 
1299  [NSApplication sharedApplication].delegate = previousDelegate;
1300 }

References CreateMockFlutterEngine().

◆ TEST_F() [33/93]

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

Definition at line 1165 of file FlutterEngineTest.mm.

1165  {
1166  __block BOOL announced = NO;
1167  id engineMock = CreateMockFlutterEngine(nil);
1168 
1169  OCMStub([engineMock announceAccessibilityMessage:[OCMArg any]
1170  withPriority:NSAccessibilityPriorityMedium])
1171  .andDo((^(NSInvocation* invocation) {
1172  announced = TRUE;
1173  [invocation retainArguments];
1174  NSString* message;
1175  [invocation getArgument:&message atIndex:2];
1176  EXPECT_EQ(message, @"error message");
1177  }));
1178 
1179  NSDictionary<NSString*, id>* annotatedEvent =
1180  @{@"type" : @"announce",
1181  @"data" : @{@"message" : @"error message"}};
1182 
1183  [engineMock handleAccessibilityEvent:annotatedEvent];
1184 
1185  EXPECT_TRUE(announced);
1186 }

References CreateMockFlutterEngine().

◆ TEST_F() [34/93]

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

Definition at line 1188 of file FlutterEngineTest.mm.

1188  {
1189  __block flutter::AppLifecycleState sentState;
1190  id engineMock = CreateMockFlutterEngine(nil);
1191 
1192  // Have to enumerate all the values because OCMStub can't capture
1193  // non-Objective-C object arguments.
1194  OCMStub([engineMock setApplicationState:flutter::AppLifecycleState::kDetached])
1195  .andDo((^(NSInvocation* invocation) {
1197  }));
1198  OCMStub([engineMock setApplicationState:flutter::AppLifecycleState::kResumed])
1199  .andDo((^(NSInvocation* invocation) {
1201  }));
1202  OCMStub([engineMock setApplicationState:flutter::AppLifecycleState::kInactive])
1203  .andDo((^(NSInvocation* invocation) {
1205  }));
1206  OCMStub([engineMock setApplicationState:flutter::AppLifecycleState::kHidden])
1207  .andDo((^(NSInvocation* invocation) {
1209  }));
1210  OCMStub([engineMock setApplicationState:flutter::AppLifecycleState::kPaused])
1211  .andDo((^(NSInvocation* invocation) {
1213  }));
1214 
1215  __block NSApplicationOcclusionState visibility = NSApplicationOcclusionStateVisible;
1216  id mockApplication = OCMPartialMock([NSApplication sharedApplication]);
1217  OCMStub((NSApplicationOcclusionState)[mockApplication occlusionState])
1218  .andDo(^(NSInvocation* invocation) {
1219  [invocation setReturnValue:&visibility];
1220  });
1221 
1222  // handleWillBecomeActive derives visibility from the windows (not from the
1223  // occlusion state, which can latch stale), so provide a window whose visibility
1224  // we can toggle independently.
1225  __block BOOL windowVisible = YES;
1226  id mockWindow = OCMClassMock([NSWindow class]);
1227  OCMStub([mockWindow isVisible]).andDo(^(NSInvocation* invocation) {
1228  [invocation setReturnValue:&windowVisible];
1229  });
1230  OCMStub([mockApplication windows]).andReturn(@[ mockWindow ]);
1231 
1232  NSNotification* willBecomeActive =
1233  [[NSNotification alloc] initWithName:NSApplicationWillBecomeActiveNotification
1234  object:nil
1235  userInfo:nil];
1236  NSNotification* willResignActive =
1237  [[NSNotification alloc] initWithName:NSApplicationWillResignActiveNotification
1238  object:nil
1239  userInfo:nil];
1240 
1241  NSNotification* didChangeOcclusionState;
1242  didChangeOcclusionState =
1243  [[NSNotification alloc] initWithName:NSApplicationDidChangeOcclusionStateNotification
1244  object:nil
1245  userInfo:nil];
1246 
1247  [engineMock handleDidChangeOcclusionState:didChangeOcclusionState];
1248  EXPECT_EQ(sentState, flutter::AppLifecycleState::kInactive);
1249 
1250  [engineMock handleWillBecomeActive:willBecomeActive];
1251  EXPECT_EQ(sentState, flutter::AppLifecycleState::kResumed);
1252 
1253  [engineMock handleWillResignActive:willResignActive];
1254  EXPECT_EQ(sentState, flutter::AppLifecycleState::kInactive);
1255 
1256  visibility = 0;
1257  [engineMock handleDidChangeOcclusionState:didChangeOcclusionState];
1258  EXPECT_EQ(sentState, flutter::AppLifecycleState::kHidden);
1259 
1260  // Becoming active with an on-screen window resumes even though occlusionState still
1261  // reads not-visible (the stale-latch case). Regression test for #155977.
1262  [engineMock handleWillBecomeActive:willBecomeActive];
1263  EXPECT_EQ(sentState, flutter::AppLifecycleState::kResumed);
1264 
1265  // The app is now active and considered visible, so resigning active makes it
1266  // inactive (not hidden) until a real occlusion notification hides it.
1267  [engineMock handleWillResignActive:willResignActive];
1268  EXPECT_EQ(sentState, flutter::AppLifecycleState::kInactive);
1269 
1270  // Occlusion stays authoritative after a becomeActive resume: a genuine
1271  // not-visible occlusion notification still hides the app.
1272  visibility = 0;
1273  [engineMock handleDidChangeOcclusionState:didChangeOcclusionState];
1274  EXPECT_EQ(sentState, flutter::AppLifecycleState::kHidden);
1275 
1276  // Becoming active while no window is visible (e.g. activated with all windows
1277  // minimized, which does not deminiaturize) must not resume: visibility is
1278  // derived from the windows, not from the activation itself.
1279  windowVisible = NO;
1280  [engineMock handleWillBecomeActive:willBecomeActive];
1281  EXPECT_EQ(sentState, flutter::AppLifecycleState::kHidden);
1282 
1283  [mockWindow stopMocking];
1284  [mockApplication stopMocking];
1285 }

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

◆ TEST_F() [35/93]

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

Definition at line 1071 of file FlutterEngineTest.mm.

1071  {
1072  id engineMock = CreateMockFlutterEngine(nil);
1073  __block NSString* nextResponse = @"exit";
1074  __block BOOL triedToTerminate = NO;
1075  FlutterEngineTerminationHandler* terminationHandler =
1076  [[FlutterEngineTerminationHandler alloc] initWithEngine:engineMock
1077  terminator:^(id sender) {
1078  triedToTerminate = TRUE;
1079  // Don't actually terminate, of course.
1080  }];
1081  OCMStub([engineMock terminationHandler]).andReturn(terminationHandler);
1082  id binaryMessengerMock = OCMProtocolMock(@protocol(FlutterBinaryMessenger));
1083  OCMStub( // NOLINT(google-objc-avoid-throwing-exception)
1084  [engineMock binaryMessenger])
1085  .andReturn(binaryMessengerMock);
1086  OCMStub([engineMock sendOnChannel:@"flutter/platform"
1087  message:[OCMArg any]
1088  binaryReply:[OCMArg any]])
1089  .andDo((^(NSInvocation* invocation) {
1090  [invocation retainArguments];
1091  FlutterBinaryReply callback;
1092  NSData* returnedMessage;
1093  [invocation getArgument:&callback atIndex:4];
1094  if ([nextResponse isEqualToString:@"error"]) {
1095  FlutterError* errorResponse = [FlutterError errorWithCode:@"Error"
1096  message:@"Failed"
1097  details:@"Details"];
1098  returnedMessage =
1099  [[FlutterJSONMethodCodec sharedInstance] encodeErrorEnvelope:errorResponse];
1100  } else {
1101  NSDictionary* responseDict = @{@"response" : nextResponse};
1102  returnedMessage =
1103  [[FlutterJSONMethodCodec sharedInstance] encodeSuccessEnvelope:responseDict];
1104  }
1105  callback(returnedMessage);
1106  }));
1107  __block NSString* calledAfterTerminate = @"";
1108  FlutterResult appExitResult = ^(id result) {
1109  NSDictionary* resultDict = result;
1110  calledAfterTerminate = resultDict[@"response"];
1111  };
1112  FlutterMethodCall* methodExitApplication =
1113  [FlutterMethodCall methodCallWithMethodName:@"System.exitApplication"
1114  arguments:@{@"type" : @"cancelable"}];
1115 
1116  // Always terminate when the binding isn't ready (which is the default).
1117  triedToTerminate = NO;
1118  calledAfterTerminate = @"";
1119  nextResponse = @"cancel";
1120  [engineMock handleMethodCall:methodExitApplication result:appExitResult];
1121  EXPECT_STREQ([calledAfterTerminate UTF8String], "");
1122  EXPECT_TRUE(triedToTerminate);
1123 
1124  // Once the binding is ready, handle the request.
1125  terminationHandler.acceptingRequests = YES;
1126  triedToTerminate = NO;
1127  calledAfterTerminate = @"";
1128  nextResponse = @"exit";
1129  [engineMock handleMethodCall:methodExitApplication result:appExitResult];
1130  EXPECT_STREQ([calledAfterTerminate UTF8String], "exit");
1131  EXPECT_TRUE(triedToTerminate);
1132 
1133  triedToTerminate = NO;
1134  calledAfterTerminate = @"";
1135  nextResponse = @"cancel";
1136  [engineMock handleMethodCall:methodExitApplication result:appExitResult];
1137  EXPECT_STREQ([calledAfterTerminate UTF8String], "cancel");
1138  EXPECT_FALSE(triedToTerminate);
1139 
1140  // Check that it doesn't crash on error.
1141  triedToTerminate = NO;
1142  calledAfterTerminate = @"";
1143  nextResponse = @"error";
1144  [engineMock handleMethodCall:methodExitApplication result:appExitResult];
1145  EXPECT_STREQ([calledAfterTerminate UTF8String], "");
1146  EXPECT_TRUE(triedToTerminate);
1147 }
NS_ASSUME_NONNULL_BEGIN typedef void(^ FlutterBinaryReply)(NSData *_Nullable reply)
instancetype errorWithCode:message:details:(NSString *code,[message] NSString *_Nullable message,[details] id _Nullable details)

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

◆ TEST_F() [36/93]

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

Definition at line 150 of file FlutterEngineTest.mm.

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

◆ TEST_F() [37/93]

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

Definition at line 854 of file FlutterEngineTest.mm.

854  {
855  id engineMock = CreateMockFlutterEngine(nil);
856 
857  // Call hasStrings and expect it to be false.
858  __block bool calledAfterClear = false;
859  __block bool valueAfterClear;
860  FlutterResult resultAfterClear = ^(id result) {
861  calledAfterClear = true;
862  NSNumber* valueNumber = [result valueForKey:@"value"];
863  valueAfterClear = [valueNumber boolValue];
864  };
865  FlutterMethodCall* methodCallAfterClear =
866  [FlutterMethodCall methodCallWithMethodName:@"Clipboard.hasStrings" arguments:nil];
867  [engineMock handleMethodCall:methodCallAfterClear result:resultAfterClear];
868  EXPECT_TRUE(calledAfterClear);
869  EXPECT_FALSE(valueAfterClear);
870 }

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

◆ TEST_F() [38/93]

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

Definition at line 872 of file FlutterEngineTest.mm.

872  {
873  id engineMock = CreateMockFlutterEngine(@"some string");
874 
875  // Call hasStrings and expect it to be true.
876  __block bool called = false;
877  __block bool value;
878  FlutterResult result = ^(id result) {
879  called = true;
880  NSNumber* valueNumber = [result valueForKey:@"value"];
881  value = [valueNumber boolValue];
882  };
883  FlutterMethodCall* methodCall =
884  [FlutterMethodCall methodCallWithMethodName:@"Clipboard.hasStrings" arguments:nil];
885  [engineMock handleMethodCall:methodCall result:result];
886  EXPECT_TRUE(called);
887  EXPECT_TRUE(value);
888 }

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

◆ TEST_F() [39/93]

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

Definition at line 1149 of file FlutterEngineTest.mm.

1149  {
1150  id<NSApplicationDelegate> previousDelegate = [[NSApplication sharedApplication] delegate];
1151  id<NSApplicationDelegate> plainDelegate = [[PlainAppDelegate alloc] init];
1152  [NSApplication sharedApplication].delegate = plainDelegate;
1153 
1154  // Creating the engine shouldn't fail here, even though the delegate isn't a
1155  // FlutterAppDelegate.
1157 
1158  // Asking to terminate the app should cancel.
1159  EXPECT_EQ([[[NSApplication sharedApplication] delegate] applicationShouldTerminate:NSApp],
1160  NSTerminateCancel);
1161 
1162  [NSApplication sharedApplication].delegate = previousDelegate;
1163 }

References CreateMockFlutterEngine().

◆ TEST_F() [40/93]

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

Definition at line 975 of file FlutterEngineTest.mm.

975  {
976  NSString* fixtures = @(flutter::testing::GetFixturesPath());
977  FlutterDartProject* project = [[FlutterDartProject alloc]
978  initWithAssetsPath:fixtures
979  ICUDataPath:[fixtures stringByAppendingString:@"/icudtl.dat"]];
980 
981  FlutterEngine* engine;
982  FlutterViewController* viewController1;
983 
984  @autoreleasepool {
985  // Create FVC1.
986  viewController1 = [[FlutterViewController alloc] initWithProject:project];
987  EXPECT_EQ(viewController1.viewIdentifier, 0ll);
988 
989  engine = viewController1.engine;
990  engine.viewController = nil;
991 
992  // Create FVC2 based on the same engine.
993  FlutterViewController* viewController2 = [[FlutterViewController alloc] initWithEngine:engine
994  nibName:nil
995  bundle:nil];
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 }
FlutterViewIdentifier viewIdentifier

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

◆ TEST_F() [41/93]

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

Definition at line 1007 of file FlutterEngineTest.mm.

1007  {
1008  // Don't create the engine with `CreateMockFlutterEngine`, because it adds
1009  // additional references to FlutterViewControllers, which is crucial to this
1010  // test case.
1011  FlutterEngine* engine = [[FlutterEngine alloc] initWithName:@"io.flutter"
1012  project:nil
1013  allowHeadlessExecution:NO];
1014  FlutterViewController* viewController1;
1015 
1016  @autoreleasepool {
1017  viewController1 = [[FlutterViewController alloc] initWithEngine:engine nibName:nil bundle:nil];
1018  EXPECT_EQ(viewController1.viewIdentifier, 0ll);
1019  EXPECT_EQ(engine.viewController, viewController1);
1020 
1021  engine.viewController = nil;
1022 
1023  FlutterViewController* viewController2 = [[FlutterViewController alloc] initWithEngine:engine
1024  nibName:nil
1025  bundle:nil];
1026  EXPECT_EQ(viewController2.viewIdentifier, 0ll);
1027  EXPECT_EQ(engine.viewController, viewController2);
1028  }
1029  // FVC2 is deallocated but FVC1 is retained.
1030 
1031  EXPECT_EQ(engine.viewController, nil);
1032 
1033  engine.viewController = viewController1;
1034  EXPECT_EQ(engine.viewController, viewController1);
1035  EXPECT_EQ(viewController1.viewIdentifier, 0ll);
1036 }

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

◆ TEST_F() [42/93]

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

Definition at line 797 of file FlutterEngineTest.mm.

797  {
798  FlutterEngine* engine = GetFlutterEngine();
799  EXPECT_TRUE([engine runWithEntrypoint:@"main"]);
800 
801  NSString* channel = @"_test_";
802  NSData* channel_data = [channel dataUsingEncoding:NSUTF8StringEncoding];
803 
804  // Mock SendPlatformMessage so that if a message is sent to
805  // "test/send_message", act as if the framework has sent an empty message to
806  // the channel marked by the `sendOnChannel:message:` call's message.
807  engine.embedderAPI.SendPlatformMessage = MOCK_ENGINE_PROC(
808  SendPlatformMessage, ([](auto engine_, auto message_) {
809  if (strcmp(message_->channel, "test/send_message") == 0) {
810  // The simplest message that is acceptable to a method channel.
811  std::string message = R"|({"method": "a"})|";
812  std::string channel(reinterpret_cast<const char*>(message_->message),
813  message_->message_size);
814  reinterpret_cast<EmbedderEngine*>(engine_)
815  ->GetShell()
816  .GetPlatformView()
817  ->HandlePlatformMessage(std::make_unique<PlatformMessage>(
818  channel.c_str(), fml::MallocMapping::Copy(message.c_str(), message.length()),
819  fml::RefPtr<PlatformMessageResponse>()));
820  }
821  return kSuccess;
822  }));
823 
824  __block int record = 0;
825 
826  FlutterMethodChannel* channel1 =
828  binaryMessenger:engine.binaryMessenger
829  codec:[FlutterJSONMethodCodec sharedInstance]];
830  [channel1 setMethodCallHandler:^(FlutterMethodCall* call, FlutterResult result) {
831  record += 1;
832  }];
833 
834  [engine.binaryMessenger sendOnChannel:@"test/send_message" message:channel_data];
835  EXPECT_EQ(record, 1);
836 
837  FlutterMethodChannel* channel2 =
839  binaryMessenger:engine.binaryMessenger
840  codec:[FlutterJSONMethodCodec sharedInstance]];
841  [channel2 setMethodCallHandler:^(FlutterMethodCall* call, FlutterResult result) {
842  record += 10;
843  }];
844 
845  [engine.binaryMessenger sendOnChannel:@"test/send_message" message:channel_data];
846  EXPECT_EQ(record, 11);
847 
848  [channel1 setMethodCallHandler:nil];
849 
850  [engine.binaryMessenger sendOnChannel:@"test/send_message" message:channel_data];
851  EXPECT_EQ(record, 21);
852 }
void setMethodCallHandler:(FlutterMethodCallHandler _Nullable handler)
instancetype methodChannelWithName:binaryMessenger:codec:(NSString *name,[binaryMessenger] NSObject< FlutterBinaryMessenger > *messenger,[codec] NSObject< FlutterMethodCodec > *codec)

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

◆ TEST_F() [43/93]

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

Definition at line 198 of file FlutterEngineTest.mm.

198  {
199  FlutterEngine* engine = GetFlutterEngine();
200  EXPECT_TRUE([engine runWithEntrypoint:@"main"]);
201 
202  NSData* test_message = [@"a message" dataUsingEncoding:NSUTF8StringEncoding];
203  bool called = false;
204 
205  engine.embedderAPI.SendPlatformMessage = MOCK_ENGINE_PROC(
206  SendPlatformMessage, ([&called, test_message](auto engine, auto message) {
207  called = true;
208  EXPECT_STREQ(message->channel, "test");
209  EXPECT_EQ(memcmp(message->message, test_message.bytes, message->message_size), 0);
210  return kSuccess;
211  }));
212 
213  [engine.binaryMessenger sendOnChannel:@"test" message:test_message];
214  EXPECT_TRUE(called);
215 }

◆ TEST_F() [44/93]

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

Definition at line 511 of file FlutterEngineTest.mm.

511  {
512  BOOL latch_called = NO;
513  AddFfiNativeCallback("SignalNativeTest", CREATE_FFI_LAMBDA([&]() { latch_called = YES; }));
514 
515  FlutterEngine* engine = GetFlutterEngine();
516  EXPECT_TRUE([engine runWithEntrypoint:@"nativeCallback"]);
517  ASSERT_TRUE(engine.running);
518 
519  while (!latch_called) {
520  CFRunLoopRunInMode(kCFRunLoopDefaultMode, 1, YES);
521  }
522  ASSERT_TRUE(latch_called);
523 }

◆ TEST_F() [45/93]

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

Definition at line 1344 of file FlutterEngineTest.mm.

1344  {
1345  BOOL updated = NO;
1346  FlutterEngine* engine = GetFlutterEngine();
1347  auto original_set_viewport_metrics = engine.embedderAPI.SendWindowMetricsEvent;
1348  engine.embedderAPI.SendWindowMetricsEvent = MOCK_ENGINE_PROC(
1349  SendWindowMetricsEvent,
1350  ([&updated, &original_set_viewport_metrics](auto engine, auto* window_metrics) {
1351  updated = YES;
1352  return original_set_viewport_metrics(engine, window_metrics);
1353  }));
1354 
1355  EXPECT_TRUE([engine runWithEntrypoint:@"main"]);
1356 
1357  updated = NO;
1358  [[NSNotificationCenter defaultCenter] postNotificationName:NSWindowDidChangeScreenNotification
1359  object:nil];
1360  // No VC.
1361  EXPECT_FALSE(updated);
1362 
1363  FlutterViewController* viewController = [[FlutterViewController alloc] initWithEngine:engine
1364  nibName:nil
1365  bundle:nil];
1366  [viewController loadView];
1367  viewController.flutterView.frame = CGRectMake(0, 0, 800, 600);
1368 
1369  [[NSNotificationCenter defaultCenter] postNotificationName:NSWindowDidChangeScreenNotification
1370  object:nil];
1371  EXPECT_TRUE(updated);
1372 }

◆ TEST_F() [46/93]

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

Definition at line 486 of file FlutterEngineTest.mm.

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

References FlutterEngine::viewController.

◆ TEST_F() [47/93]

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

Definition at line 705 of file FlutterEngineTest.mm.

705  {
706  NSString* fixtures = @(flutter::testing::GetFixturesPath());
707  FlutterDartProject* project = [[FlutterDartProject alloc]
708  initWithAssetsPath:fixtures
709  ICUDataPath:[fixtures stringByAppendingString:@"/icudtl.dat"]];
710  FlutterEngine* engine = [[FlutterEngine alloc] initWithName:@"test"
711  project:project
712  allowHeadlessExecution:YES];
713 
714  EXPECT_EQ([engine valuePublishedByPlugin:@"NoSuchPlugin"], nil);
715 }

◆ TEST_F() [48/93]

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

Definition at line 717 of file FlutterEngineTest.mm.

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

◆ TEST_F() [49/93]

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

Definition at line 734 of file FlutterEngineTest.mm.

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

◆ TEST_F() [50/93]

flutter::testing::TEST_F ( FlutterEngineTest  ,
RegistrarCanReadValuePublishedByAnotherPlugin   
)

Definition at line 755 of file FlutterEngineTest.mm.

755  {
756  NSString* fixtures = @(flutter::testing::GetFixturesPath());
757  FlutterDartProject* project = [[FlutterDartProject alloc]
758  initWithAssetsPath:fixtures
759  ICUDataPath:[fixtures stringByAppendingPathComponent:@"icudtl.dat"]];
760  FlutterEngine* engine = [[FlutterEngine alloc] initWithName:@"test"
761  project:project
762  allowHeadlessExecution:YES];
763  NSString* publisherPluginName = @"PublisherPlugin";
764  NSString* readerPluginName = @"ReaderPlugin";
765  id<FlutterPluginRegistrar> publisher = [engine registrarForPlugin:publisherPluginName];
766  id<FlutterPluginRegistrar> reader = [engine registrarForPlugin:readerPluginName];
767 
768  NSString* publishedValue = @"A published value";
769  [publisher publish:publishedValue];
770 
771  EXPECT_EQ([reader valuePublishedByPlugin:publisherPluginName], publishedValue);
772  EXPECT_EQ([reader valuePublishedByPlugin:@"NoSuchPlugin"], nil);
773  EXPECT_EQ([reader valuePublishedByPlugin:readerPluginName], [NSNull null]);
774 }

◆ TEST_F() [51/93]

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

Definition at line 776 of file FlutterEngineTest.mm.

776  {
777  NSString* fixtures = @(flutter::testing::GetFixturesPath());
778  FlutterDartProject* project = [[FlutterDartProject alloc]
779  initWithAssetsPath:fixtures
780  ICUDataPath:[fixtures stringByAppendingString:@"/icudtl.dat"]];
781  FlutterEngine* engine = [[FlutterEngine alloc] initWithName:@"test" project:project];
782 
783  FlutterViewController* viewController = [[FlutterViewController alloc] initWithEngine:engine
784  nibName:nil
785  bundle:nil];
786  id<FlutterPluginRegistrar> registrar = [engine registrarForPlugin:@"MyPlugin"];
787 
788  EXPECT_EQ([registrar viewController], viewController);
789 }

◆ TEST_F() [52/93]

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

Definition at line 1038 of file FlutterEngineTest.mm.

1038  {
1039  NSString* fixtures = @(flutter::testing::GetFixturesPath());
1040  FlutterDartProject* project = [[FlutterDartProject alloc]
1041  initWithAssetsPath:fixtures
1042  ICUDataPath:[fixtures stringByAppendingString:@"/icudtl.dat"]];
1043  FlutterEngine* engine = [[FlutterEngine alloc] initWithName:@"test" project:project];
1044 
1045  FlutterViewController* viewController = [[FlutterViewController alloc] initWithEngine:engine
1046  nibName:nil
1047  bundle:nil];
1048  [viewController loadView];
1049  [viewController viewDidLoad];
1050  viewController.flutterView.frame = CGRectMake(0, 0, 800, 600);
1051 
1052  EXPECT_TRUE([engine runWithEntrypoint:@"drawIntoAllViews"]);
1053  // Wait up to 1 second for Flutter to emit a frame.
1054  CFTimeInterval start = CACurrentMediaTime();
1055  while (engine.macOSCompositor->DebugNumViews() == 0) {
1056  CFRunLoopRunInMode(kCFRunLoopDefaultMode, 1, YES);
1057  if (CACurrentMediaTime() - start > 1) {
1058  break;
1059  }
1060  }
1061 
1062  EXPECT_EQ(engine.macOSCompositor->DebugNumViews(), 1u);
1063 
1064  engine.viewController = nil;
1065  EXPECT_EQ(engine.macOSCompositor->DebugNumViews(), 0u);
1066 
1067  [engine shutDownEngine];
1068  engine = nil;
1069 }

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

◆ TEST_F() [53/93]

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

Definition at line 1402 of file FlutterEngineTest.mm.

1402  {
1403  __block BOOL expectedValue;
1404 
1405  // Set up mocks.
1406  id channelMock = OCMClassMock([FlutterBasicMessageChannel class]);
1407  OCMStub([channelMock messageChannelWithName:@"flutter/settings"
1408  binaryMessenger:[OCMArg any]
1409  codec:[OCMArg any]])
1410  .andReturn(channelMock);
1411  OCMStub([channelMock sendMessage:[OCMArg any]]).andDo((^(NSInvocation* invocation) {
1412  __weak id message;
1413  [invocation getArgument:&message atIndex:2];
1414  EXPECT_EQ(message[@"alwaysUse24HourFormat"], @(expectedValue));
1415  }));
1416 
1417  id mockHourFormat = OCMClassMock([FlutterHourFormat class]);
1418  OCMStub([mockHourFormat isAlwaysUse24HourFormat]).andDo((^(NSInvocation* invocation) {
1419  [invocation setReturnValue:&expectedValue];
1420  }));
1421 
1422  id engineMock = CreateMockFlutterEngine(nil);
1423 
1424  // Verify the YES case.
1425  expectedValue = YES;
1426  EXPECT_TRUE([engineMock runWithEntrypoint:@"main"]);
1427  [engineMock shutDownEngine];
1428 
1429  // Verify the NO case.
1430  expectedValue = NO;
1431  EXPECT_TRUE([engineMock runWithEntrypoint:@"main"]);
1432  [engineMock shutDownEngine];
1433 
1434  // Clean up mocks.
1435  [mockHourFormat stopMocking];
1436  [engineMock stopMocking];
1437  [channelMock stopMocking];
1438 }

References CreateMockFlutterEngine().

◆ TEST_F() [54/93]

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

Definition at line 961 of file FlutterEngineTest.mm.

961  {
962  FlutterResizeSynchronizer* threadSynchronizer = [[FlutterResizeSynchronizer alloc] init];
963  [threadSynchronizer shutDown];
964 
965  std::thread rasterThread([&threadSynchronizer] {
966  [threadSynchronizer performCommitForSize:CGSizeMake(100, 100)
967  afterDelay:0
968  notify:^{
969  }];
970  });
971 
972  rasterThread.join();
973 }

◆ TEST_F() [55/93]

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

Definition at line 890 of file FlutterEngineTest.mm.

890  {
891  FlutterEngine* engine = GetFlutterEngine();
893  initWithName:@"foo"
894  binaryMessenger:engine.binaryMessenger
896  __block BOOL didCallCallback = NO;
897  [channel setMessageHandler:^(id message, FlutterReply callback) {
898  ShutDownEngine();
899  callback(nil);
900  didCallCallback = YES;
901  }];
902  EXPECT_TRUE([engine runWithEntrypoint:@"sendFooMessage"]);
903  engine = nil;
904 
905  while (!didCallCallback) {
906  [[NSRunLoop currentRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:0.1]];
907  }
908 }
void setMessageHandler:(FlutterMessageHandler _Nullable handler)
instancetype sharedInstance()

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

◆ TEST_F() [56/93]

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

Definition at line 910 of file FlutterEngineTest.mm.

910  {
911  FlutterEngine* engine = GetFlutterEngine();
913  initWithName:@"foo"
914  binaryMessenger:engine.binaryMessenger
916  __block BOOL didCallCallback = NO;
917  [channel setMessageHandler:^(id message, FlutterReply callback) {
918  dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
919  callback(nil);
920  dispatch_async(dispatch_get_main_queue(), ^{
921  didCallCallback = YES;
922  });
923  });
924  }];
925  EXPECT_TRUE([engine runWithEntrypoint:@"sendFooMessage"]);
926 
927  while (!didCallCallback) {
928  [[NSRunLoop currentRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:0.1]];
929  }
930 }

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

◆ TEST_F() [57/93]

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

Definition at line 1323 of file FlutterEngineTest.mm.

1323  {
1324  BOOL updated = NO;
1325  FlutterEngine* engine = GetFlutterEngine();
1326  auto original_update_displays = engine.embedderAPI.NotifyDisplayUpdate;
1327  engine.embedderAPI.NotifyDisplayUpdate = MOCK_ENGINE_PROC(
1328  NotifyDisplayUpdate, ([&updated, &original_update_displays](
1329  auto engine, auto update_type, auto* displays, auto display_count) {
1330  updated = YES;
1331  return original_update_displays(engine, update_type, displays, display_count);
1332  }));
1333 
1334  EXPECT_TRUE([engine runWithEntrypoint:@"main"]);
1335  EXPECT_TRUE(updated);
1336 
1337  updated = NO;
1338  [[NSNotificationCenter defaultCenter]
1339  postNotificationName:NSApplicationDidChangeScreenParametersNotification
1340  object:nil];
1341  EXPECT_TRUE(updated);
1342 }

◆ TEST_F() [58/93]

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

Definition at line 173 of file FlutterEngineTest.mm.

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

◆ TEST_F() [59/93]

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

Definition at line 1302 of file FlutterEngineTest.mm.

1302  {
1303  id<NSApplicationDelegate> previousDelegate = [[NSApplication sharedApplication] delegate];
1304  FakeLifecycleProvider* fakeAppDelegate = [[FakeLifecycleProvider alloc] init];
1305  [NSApplication sharedApplication].delegate = fakeAppDelegate;
1306 
1307  FakeAppDelegatePlugin* plugin = [[FakeAppDelegatePlugin alloc] init];
1308 
1309  @autoreleasepool {
1310  FlutterEngine* engine = [[FlutterEngine alloc] initWithName:@"test" project:nil];
1311 
1312  [[engine registrarForPlugin:@"TestPlugin"] addApplicationDelegate:plugin];
1313  EXPECT_TRUE([fakeAppDelegate hasDelegate:plugin]);
1314  }
1315 
1316  // When the engine is released, it should unregister any plugins it had
1317  // registered on its behalf.
1318  EXPECT_FALSE([fakeAppDelegate hasDelegate:plugin]);
1319 
1320  [NSApplication sharedApplication].delegate = previousDelegate;
1321 }

◆ TEST_F() [60/93]

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

Definition at line 95 of file FlutterMenuPluginTest.mm.

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

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

◆ TEST_F() [61/93]

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

Definition at line 286 of file FlutterViewControllerTest.mm.

286  {
287  id mockEngine = GetMockEngine();
288  ASSERT_TRUE([[FlutterViewControllerTestObjC alloc] testCtrlTabKeyEventIsPropagated:mockEngine]);
289 }

◆ TEST_F() [62/93]

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

Definition at line 297 of file FlutterViewControllerTest.mm.

297  {
298  id mockEngine = GetMockEngine();
299  ASSERT_TRUE([[FlutterViewControllerTestObjC alloc]
300  testFlagsChangedEventsArePropagatedIfNotHandled:mockEngine]);
301 }

◆ TEST_F() [63/93]

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

Definition at line 339 of file FlutterViewControllerTest.mm.

339  {
340  id mockEngine = GetMockEngine();
341  ASSERT_TRUE([[FlutterViewControllerTestObjC alloc] testFlutterViewIsConfigured:mockEngine]);
342 }

◆ TEST_F() [64/93]

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

Definition at line 303 of file FlutterViewControllerTest.mm.

303  {
304  id mockEngine = GetMockEngine();
305  ASSERT_TRUE(
306  [[FlutterViewControllerTestObjC alloc] testKeyboardIsRestartedOnEngineRestart:mockEngine]);
307 }

◆ TEST_F() [65/93]

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

Definition at line 291 of file FlutterViewControllerTest.mm.

291  {
292  id mockEngine = GetMockEngine();
293  ASSERT_TRUE([[FlutterViewControllerTestObjC alloc]
294  testKeyEquivalentIsPassedToTextInputPlugin:mockEngine]);
295 }

◆ TEST_F() [66/93]

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

Definition at line 280 of file FlutterViewControllerTest.mm.

280  {
281  id mockEngine = GetMockEngine();
282  ASSERT_TRUE(
283  [[FlutterViewControllerTestObjC alloc] testKeyEventsAreNotPropagatedIfHandled:mockEngine]);
284 }

◆ TEST_F() [67/93]

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

Definition at line 274 of file FlutterViewControllerTest.mm.

274  {
275  id mockEngine = GetMockEngine();
276  ASSERT_TRUE(
277  [[FlutterViewControllerTestObjC alloc] testKeyEventsArePropagatedIfNotHandled:mockEngine]);
278 }

◆ TEST_F() [68/93]

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

Definition at line 269 of file FlutterViewControllerTest.mm.

269  {
270  id mockEngine = GetMockEngine();
271  ASSERT_TRUE([[FlutterViewControllerTestObjC alloc] testKeyEventsAreSentToFramework:mockEngine]);
272 }

◆ TEST_F() [69/93]

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

Definition at line 327 of file FlutterViewControllerTest.mm.

327  {
328  id mockEngine = GetMockEngine();
329  ASSERT_TRUE(
330  [[FlutterViewControllerTestObjC alloc] testModifierKeysAreSynthesizedOnMouseMove:mockEngine]);
331 }

◆ TEST_F() [70/93]

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

Definition at line 315 of file FlutterViewControllerTest.mm.

315  {
316  id mockEngine = GetMockEngine();
317  ASSERT_TRUE(
318  [[FlutterViewControllerTestObjC alloc] mouseAndGestureEventsAreHandledSeparately:mockEngine]);
319 }

◆ TEST_F() [71/93]

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

Definition at line 321 of file FlutterViewControllerTest.mm.

321  {
322  id mockEngine = GetMockEngine();
323  ASSERT_TRUE(
324  [[FlutterViewControllerTestObjC alloc] testMouseDownUpEventsSentToNextResponder:mockEngine]);
325 }

◆ TEST_F() [72/93]

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

Definition at line 309 of file FlutterViewControllerTest.mm.

309  {
310  id mockEngine = GetMockEngine();
311  ASSERT_TRUE(
312  [[FlutterViewControllerTestObjC alloc] testTrackpadGesturesAreSentToFramework:mockEngine]);
313 }

◆ TEST_F() [73/93]

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

Definition at line 333 of file FlutterViewControllerTest.mm.

333  {
334  id mockEngine = GetMockEngine();
335  ASSERT_TRUE(
336  [[FlutterViewControllerTestObjC alloc] testViewWillAppearCalledMultipleTimes:mockEngine]);
337 }

◆ TEST_F() [74/93]

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

Definition at line 259 of file FlutterViewControllerTest.mm.

259  {
260  NSString* fixtures = @(testing::GetFixturesPath());
261  FlutterDartProject* project = [[FlutterDartProject alloc]
262  initWithAssetsPath:fixtures
263  ICUDataPath:[fixtures stringByAppendingString:@"/icudtl.dat"]];
264  FlutterViewController* viewController = [[FlutterViewController alloc] initWithProject:project];
265  viewController.mouseTrackingMode = kFlutterMouseTrackingModeInActiveApp;
266  ASSERT_EQ(viewController.mouseTrackingMode, kFlutterMouseTrackingModeInActiveApp);
267 }
FlutterMouseTrackingMode mouseTrackingMode

References FlutterViewController::mouseTrackingMode.

◆ TEST_F() [75/93]

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

Definition at line 216 of file FlutterViewControllerTest.mm.

216  {
217  FlutterViewController* viewControllerMock = CreateMockViewController();
218  [viewControllerMock loadView];
219  EXPECT_EQ([viewControllerMock.flutterView acceptsFirstMouse:nil], YES);
220 }

References CreateMockViewController().

◆ TEST_F() [76/93]

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

Definition at line 195 of file FlutterViewControllerTest.mm.

195  {
196  FlutterViewController* viewControllerMock = CreateMockViewController();
197 
198  [viewControllerMock loadView];
199  auto subViews = [viewControllerMock.view subviews];
200 
201  EXPECT_EQ([subViews count], 1u);
202  EXPECT_EQ(subViews[0], viewControllerMock.flutterView);
203 
204  NSTextField* textField = [[NSTextField alloc] initWithFrame:NSMakeRect(0, 0, 1, 1)];
205  [viewControllerMock.view addSubview:textField];
206 
207  subViews = [viewControllerMock.view subviews];
208  EXPECT_EQ([subViews count], 2u);
209 
210  auto accessibilityChildren = viewControllerMock.view.accessibilityChildren;
211  // The accessibilityChildren should only contains the FlutterView.
212  EXPECT_EQ([accessibilityChildren count], 1u);
213  EXPECT_EQ(accessibilityChildren[0], viewControllerMock.flutterView);
214 }

References CreateMockViewController().

◆ TEST_F() [77/93]

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

Definition at line 222 of file FlutterViewControllerTest.mm.

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

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

◆ TEST_F() [78/93]

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

Definition at line 344 of file FlutterViewControllerTest.mm.

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

◆ TEST_F() [79/93]

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

Definition at line 348 of file FlutterViewControllerTest.mm.

348  {
349  ASSERT_TRUE([[FlutterViewControllerTestObjC alloc] testLookupKeyAssetsWithPackage]);
350 }

◆ TEST_F() [80/93]

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

Definition at line 352 of file FlutterViewControllerTest.mm.

352  {
353  ASSERT_TRUE([[FlutterViewControllerTestObjC alloc] testViewControllerIsReleased]);
354 }

◆ TEST_F() [81/93]

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

Definition at line 197 of file FlutterWindowControllerTest.mm.

197  {
199  .has_size = true,
200  .size = {.width = 800, .height = 600},
201  .resizable = true,
202  .on_should_close = [] {},
203  .on_will_close = [] {},
204  .notify_listeners = [] {},
205  };
206 
207  __weak FlutterEngine* weakEngine = nil;
208  @autoreleasepool {
209  NSString* fixtures = @(flutter::testing::GetFixturesPath());
210  NSLog(@"Fixtures path: %@", fixtures);
211  FlutterDartProject* project = [[FlutterDartProject alloc]
212  initWithAssetsPath:fixtures
213  ICUDataPath:[fixtures stringByAppendingString:@"/icudtl.dat"]];
214 
215  static std::optional<flutter::Isolate> isolate;
216  isolate = std::nullopt;
217 
218  project.rootIsolateCreateCallback = [](void*) { isolate = flutter::Isolate::Current(); };
219  FlutterEngine* engine = [[FlutterEngine alloc] initWithName:@"test"
220  project:project
221  allowHeadlessExecution:YES];
222  weakEngine = engine;
223  [engine runWithEntrypoint:@"testWindowControllerRetainCycle"];
224 
225  CFRunLoopRunInMode(kCFRunLoopDefaultMode, 1, false);
226 
227  int64_t engineId = reinterpret_cast<int64_t>(engine);
228 
229  {
230  FML_DCHECK(isolate.has_value());
231  // NOLINTNEXTLINE(bugprone-unchecked-optional-access)
232  IsolateScope isolateScope(*isolate);
233  int64_t handle = InternalFlutter_WindowController_CreateRegularWindow(engineId, &request);
234  EXPECT_EQ(handle, 1);
235  }
236 
237  CFRunLoopRunInMode(kCFRunLoopDefaultMode, 1, false);
238 
239  [engine.windowController closeAllWindows];
240  [engine shutDownEngine];
241  }
242  EXPECT_EQ(weakEngine, nil);
243 }
FLUTTER_DARWIN_EXPORT int64_t InternalFlutter_WindowController_CreateRegularWindow(int64_t engine_id, const FlutterWindowCreationRequest *request)
static Isolate Current()
Definition: isolate_scope.cc:9

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

◆ TEST_F() [82/93]

flutter::testing::TEST_F ( FlutterWindowControllerSizeTest  ,
SizedToContentNotResizable   
)

Definition at line 525 of file FlutterWindowControllerTest.mm.

525  {
527  .has_size = false,
528  .has_constraints = true,
529  .constraints{
530  .min_width = 0,
531  .min_height = 0,
532  .max_width = 1000,
533  .max_height = 1000,
534  },
535  .resizable = false,
536  .on_should_close = [] {},
537  .on_will_close = [] {},
538  .notify_listeners = [] {},
539  };
540 
541  std::optional<Isolate> isolate;
542 
543  bool signaled = false;
544  AddFfiNativeCallback("SignalNativeTest", CREATE_FFI_LAMBDA([&](Dart_NativeArguments args) {
545  signaled = true;
546  isolate = Isolate::Current();
547  }));
548 
549  auto engine = GetFlutterEngine();
550  [engine runWithEntrypoint:@"testRenderSizedToContent"];
551 
552  auto engineId = reinterpret_cast<int64_t>(GetFlutterEngine());
553 
554  while (!signaled) {
555  CFRunLoopRunInMode(kCFRunLoopDefaultMode, 0.1, true);
556  }
557 
558  int64_t viewId = 0;
559  {
560  IsolateScope isolate_scope(*isolate);
561  viewId = InternalFlutter_WindowController_CreateRegularWindow(engineId, &request);
562  }
563 
564  auto controller = [engine viewControllerForIdentifier:viewId];
565  auto window = controller.view.window;
566 
567  CFAbsoluteTime startTime = CFAbsoluteTimeGetCurrent();
568  double pixelRatio = [window backingScaleFactor];
569  while (window.frame.size.width != 300 / pixelRatio &&
570  CFAbsoluteTimeGetCurrent() - startTime < kTestTimeout) {
571  CFRunLoopRunInMode(kCFRunLoopDefaultMode, 0.1, true);
572  }
573 
574  NSRect contentRect = [window contentRectForFrameRect:window.frame];
575  EXPECT_EQ(contentRect.size.width, 300 / pixelRatio);
576  EXPECT_EQ(contentRect.size.height, 300 / pixelRatio);
577  EXPECT_TRUE((window.styleMask & NSWindowStyleMaskResizable) == 0);
578 
579  // Wait until the second frame is rendered, which should resize the window based
580  // on new content.
581  startTime = CFAbsoluteTimeGetCurrent();
582  while (window.frame.size.width == 300 / pixelRatio &&
583  CFAbsoluteTimeGetCurrent() - startTime < kTestTimeout) {
584  CFRunLoopRunInMode(kCFRunLoopDefaultMode, 0.1, true);
585  }
586 
587  contentRect = [window contentRectForFrameRect:window.frame];
588  EXPECT_EQ(contentRect.size.width, 200 / pixelRatio);
589  EXPECT_EQ(contentRect.size.height, 200 / pixelRatio);
590 
591  [engine.windowController closeAllWindows];
592  [engine shutDownEngine];
593 }
const CFAbsoluteTime kTestTimeout

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

◆ TEST_F() [83/93]

flutter::testing::TEST_F ( FlutterWindowControllerSizeTest  ,
SizedToContentResizable   
)

Definition at line 468 of file FlutterWindowControllerTest.mm.

468  {
470  .has_size = false,
471  .has_constraints = true,
472  .constraints{
473  .min_width = 0,
474  .min_height = 0,
475  .max_width = 1000,
476  .max_height = 1000,
477  },
478  .resizable = true,
479  .on_should_close = [] {},
480  .on_will_close = [] {},
481  .notify_listeners = [] {},
482  };
483 
484  std::optional<Isolate> isolate;
485 
486  bool signaled = false;
487  AddFfiNativeCallback("SignalNativeTest", CREATE_FFI_LAMBDA([&](Dart_NativeArguments args) {
488  signaled = true;
489  isolate = Isolate::Current();
490  }));
491 
492  auto engine = GetFlutterEngine();
493  [engine runWithEntrypoint:@"testRenderSizedToContentResizable"];
494 
495  auto engineId = reinterpret_cast<int64_t>(GetFlutterEngine());
496 
497  while (!signaled) {
498  CFRunLoopRunInMode(kCFRunLoopDefaultMode, 0.1, true);
499  }
500 
501  int64_t viewId = 0;
502  {
503  IsolateScope isolate_scope(*isolate);
504  viewId = InternalFlutter_WindowController_CreateRegularWindow(engineId, &request);
505  }
506 
507  auto controller = [engine viewControllerForIdentifier:viewId];
508  auto window = controller.view.window;
509  CFAbsoluteTime startTime = CFAbsoluteTimeGetCurrent();
510  double pixelRatio = [window backingScaleFactor];
511  while (window.frame.size.width != 300 / pixelRatio &&
512  CFAbsoluteTimeGetCurrent() - startTime < kTestTimeout) {
513  CFRunLoopRunInMode(kCFRunLoopDefaultMode, 0.1, true);
514  }
515 
516  NSRect contentRect = [window contentRectForFrameRect:window.frame];
517  EXPECT_EQ(contentRect.size.width, 300 / pixelRatio);
518  EXPECT_EQ(contentRect.size.height, 300 / pixelRatio);
519  EXPECT_TRUE((window.styleMask & NSWindowStyleMaskResizable) != 0);
520 
521  [engine.windowController closeAllWindows];
522  [engine shutDownEngine];
523 }

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

◆ TEST_F() [84/93]

flutter::testing::TEST_F ( FlutterWindowControllerTest  ,
ClosesAllWindowsOnEngineRestart   
)

Definition at line 327 of file FlutterWindowControllerTest.mm.

327  {
329  .has_size = true,
330  .size = {.width = 800, .height = 600},
331  .resizable = true,
332  .on_should_close = [] {},
333  .on_will_close = [] {},
334  .notify_listeners = [] {},
335  };
336  FlutterEngine* engine = GetFlutterEngine();
337  int64_t engine_id = reinterpret_cast<int64_t>(engine);
338 
339  IsolateScope isolate_scope(isolate());
340 
341  // Create multiple windows
342  int64_t handle1 = InternalFlutter_WindowController_CreateRegularWindow(engine_id, &request);
343  int64_t handle2 = InternalFlutter_WindowController_CreateRegularWindow(engine_id, &request);
344  int64_t handle3 = InternalFlutter_WindowController_CreateRegularWindow(engine_id, &request);
345 
346  // Verify windows are created
347  FlutterViewController* viewController1 = [engine viewControllerForIdentifier:handle1];
348  FlutterViewController* viewController2 = [engine viewControllerForIdentifier:handle2];
349  FlutterViewController* viewController3 = [engine viewControllerForIdentifier:handle3];
350  EXPECT_NE(viewController1, nil);
351  EXPECT_NE(viewController2, nil);
352  EXPECT_NE(viewController3, nil);
353 
354  // Close all windows on engine restart
355  [engine engineCallbackOnPreEngineRestart];
356 
357  // Verify all windows are closed and view controllers are disposed
358  viewController1 = [engine viewControllerForIdentifier:handle1];
359  viewController2 = [engine viewControllerForIdentifier:handle2];
360  viewController3 = [engine viewControllerForIdentifier:handle3];
361  EXPECT_EQ(viewController1, nil);
362  EXPECT_EQ(viewController2, nil);
363  EXPECT_EQ(viewController3, nil);
364 };

References FlutterWindowCreationRequest::has_size, and InternalFlutter_WindowController_CreateRegularWindow().

◆ TEST_F() [85/93]

flutter::testing::TEST_F ( FlutterWindowControllerTest  ,
CreatePopupWindow   
)

Definition at line 151 of file FlutterWindowControllerTest.mm.

151  {
152  IsolateScope isolate_scope(isolate());
153  FlutterEngine* engine = GetFlutterEngine();
154  int64_t engineId = reinterpret_cast<int64_t>(engine);
155 
156  auto request = FlutterWindowCreationRequest{
157  .has_size = true,
158  .size = {.width = 800, .height = 600},
159  .resizable = true,
160  .on_should_close = [] {},
161  .on_will_close = [] {},
162  .notify_listeners = [] {},
163  };
164  int64_t parentViewId = InternalFlutter_WindowController_CreateRegularWindow(engineId, &request);
165  EXPECT_EQ(parentViewId, 1);
166 
167  auto position_callback = [](const FlutterWindowSize& child_size,
168  const FlutterWindowRect& parent_rect,
169  const FlutterWindowRect& output_rect) -> FlutterWindowRect* {
170  FlutterWindowRect* rect = static_cast<FlutterWindowRect*>(malloc(sizeof(FlutterWindowRect)));
171  rect->left = parent_rect.left + 10;
172  rect->top = parent_rect.top + 10;
173  rect->width = child_size.width;
174  rect->height = child_size.height;
175  return rect;
176  };
177 
179  .has_constraints = true,
180  .constraints{
181  .max_width = 1000,
182  .max_height = 1000,
183  },
184  .resizable = true,
185  .parent_view_id = parentViewId,
186  .on_should_close = [] {},
187  .on_will_close = [] {},
188  .notify_listeners = [] {},
189  .on_get_window_position = position_callback,
190  };
191 
192  const int64_t tooltipViewId =
194  EXPECT_NE(tooltipViewId, 0);
195 }
FLUTTER_DARWIN_EXPORT int64_t InternalFlutter_WindowController_CreatePopupWindow(int64_t engine_id, const FlutterWindowCreationRequest *request)

References FlutterWindowCreationRequest::has_constraints, FlutterWindowCreationRequest::has_size, FlutterWindowRect::height, FlutterWindowSize::height, InternalFlutter_WindowController_CreatePopupWindow(), InternalFlutter_WindowController_CreateRegularWindow(), FlutterWindowRect::left, FlutterWindowRect::top, FlutterWindowRect::width, and FlutterWindowSize::width.

◆ TEST_F() [86/93]

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

Definition at line 79 of file FlutterWindowControllerTest.mm.

79  {
81  .has_size = true,
82  .size = {.width = 800, .height = 600},
83  .resizable = true,
84  .on_should_close = [] {},
85  .on_will_close = [] {},
86  .notify_listeners = [] {},
87  };
88 
89  FlutterEngine* engine = GetFlutterEngine();
90  int64_t engineId = reinterpret_cast<int64_t>(engine);
91 
92  {
93  IsolateScope isolate_scope(isolate());
94  int64_t handle = InternalFlutter_WindowController_CreateRegularWindow(engineId, &request);
95  EXPECT_EQ(handle, 1);
96 
97  FlutterViewController* viewController = [engine viewControllerForIdentifier:handle];
98  EXPECT_NE(viewController, nil);
99  CGSize size = viewController.view.frame.size;
100  EXPECT_EQ(size.width, 800);
101  EXPECT_EQ(size.height, 600);
102  }
103 }

References FlutterWindowCreationRequest::has_size, and InternalFlutter_WindowController_CreateRegularWindow().

◆ TEST_F() [87/93]

flutter::testing::TEST_F ( FlutterWindowControllerTest  ,
CreateTooltipWindow   
)

Definition at line 105 of file FlutterWindowControllerTest.mm.

105  {
106  IsolateScope isolate_scope(isolate());
107  FlutterEngine* engine = GetFlutterEngine();
108  int64_t engineId = reinterpret_cast<int64_t>(engine);
109 
110  auto request = FlutterWindowCreationRequest{
111  .has_size = true,
112  .size = {.width = 800, .height = 600},
113  .resizable = true,
114  .on_should_close = [] {},
115  .on_will_close = [] {},
116  .notify_listeners = [] {},
117  };
118  int64_t parentViewId = InternalFlutter_WindowController_CreateRegularWindow(engineId, &request);
119  EXPECT_EQ(parentViewId, 1);
120 
121  auto position_callback = [](const FlutterWindowSize& child_size,
122  const FlutterWindowRect& parent_rect,
123  const FlutterWindowRect& output_rect) -> FlutterWindowRect* {
124  FlutterWindowRect* rect = static_cast<FlutterWindowRect*>(malloc(sizeof(FlutterWindowRect)));
125  rect->left = parent_rect.left + 10;
126  rect->top = parent_rect.top + 10;
127  rect->width = child_size.width;
128  rect->height = child_size.height;
129  return rect;
130  };
131 
133  .has_constraints = true,
134  .constraints{
135  .max_width = 1000,
136  .max_height = 1000,
137  },
138  .resizable = true,
139  .parent_view_id = parentViewId,
140  .on_should_close = [] {},
141  .on_will_close = [] {},
142  .notify_listeners = [] {},
143  .on_get_window_position = position_callback,
144  };
145 
146  const int64_t tooltipViewId =
148  EXPECT_NE(tooltipViewId, 0);
149 }
FLUTTER_DARWIN_EXPORT int64_t InternalFlutter_WindowController_CreateTooltipWindow(int64_t engine_id, const FlutterWindowCreationRequest *request)

References FlutterWindowCreationRequest::has_constraints, FlutterWindowCreationRequest::has_size, FlutterWindowRect::height, FlutterWindowSize::height, InternalFlutter_WindowController_CreateRegularWindow(), InternalFlutter_WindowController_CreateTooltipWindow(), FlutterWindowRect::left, FlutterWindowRect::top, FlutterWindowRect::width, and FlutterWindowSize::width.

◆ TEST_F() [88/93]

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

Definition at line 245 of file FlutterWindowControllerTest.mm.

245  {
247  .has_size = true,
248  .size = {.width = 800, .height = 600},
249  .resizable = true,
250  .on_should_close = [] {},
251  .on_will_close = [] {},
252  .notify_listeners = [] {},
253  };
254 
255  FlutterEngine* engine = GetFlutterEngine();
256  int64_t engine_id = reinterpret_cast<int64_t>(engine);
257 
258  IsolateScope isolate_scope(isolate());
259  int64_t handle = InternalFlutter_WindowController_CreateRegularWindow(engine_id, &request);
260  FlutterViewController* viewController = [engine viewControllerForIdentifier:handle];
261 
262  InternalFlutter_Window_Destroy(engine_id, (__bridge void*)viewController.view.window);
263  viewController = [engine viewControllerForIdentifier:handle];
264  EXPECT_EQ(viewController, nil);
265 }
FLUTTER_DARWIN_EXPORT void InternalFlutter_Window_Destroy(int64_t engine_id, void *window)

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

◆ TEST_F() [89/93]

flutter::testing::TEST_F ( FlutterWindowControllerTest  ,
FixMoveRunLoopMode   
)

Definition at line 65 of file FlutterWindowControllerTest.mm.

65  {
66  FlutterEngine* engine = GetFlutterEngine();
67  [engine.windowController fixMoveRunLoopModeIfNeeded];
68 
69  // Make sure that after fixMoveRunLoopMode _NSMoveTimerRunLoopMode becomes
70  // common run loop mode.
71  __block BOOL signalled = NO;
72  CFRunLoopPerformBlock(CFRunLoopGetCurrent(), kCFRunLoopCommonModes, ^{
73  signalled = YES;
74  });
75  CFRunLoopRunInMode(CFSTR("_NSMoveTimerRunLoopMode"), 1.0, YES);
76  EXPECT_TRUE(signalled);
77 }

◆ TEST_F() [90/93]

flutter::testing::TEST_F ( FlutterWindowControllerTest  ,
GetOffsetInParent   
)

Definition at line 430 of file FlutterWindowControllerTest.mm.

430  {
431  NSWindow* parentWindow = [[NSWindow alloc] initWithContentRect:NSMakeRect(0, 0, 800, 600)
432  styleMask:NSWindowStyleMaskTitled
433  backing:NSBackingStoreBuffered
434  defer:NO];
435  [parentWindow setReleasedWhenClosed:NO];
436  NSWindow* childWindow = [[NSWindow alloc] initWithContentRect:NSMakeRect(0, 0, 100, 100)
437  styleMask:NSWindowStyleMaskBorderless
438  backing:NSBackingStoreBuffered
439  defer:NO];
440  [childWindow setReleasedWhenClosed:NO];
441 
442  // Bottom left origin.
443  [parentWindow setFrame:NSMakeRect(100, 100, 800, 600) display:NO];
444  [childWindow setFrame:NSMakeRect(150, 150, 100, 100) display:NO];
445 
446  // Establish the parent-child relationship required by GetOffsetInParent.
447  [parentWindow addChildWindow:childWindow ordered:NSWindowAbove];
448 
449  FlutterWindowOffset offset =
450  InternalFlutter_Window_GetOffsetInParent((__bridge void*)childWindow);
451 
452  // GetOffsetInParent has relative coordinates with top left origin.
453  NSRect parentContentRect = [parentWindow contentRectForFrameRect:parentWindow.frame];
454 
455  double expectedX = 150 - parentContentRect.origin.x;
456  double expectedY = (parentContentRect.origin.y + parentContentRect.size.height) - (150 + 100);
457 
458  EXPECT_NEAR(offset.x, expectedX, 0.001);
459  EXPECT_NEAR(offset.y, expectedY, 0.001);
460 
461  [parentWindow removeChildWindow:childWindow];
462  [childWindow close];
463  [parentWindow close];
464 }
FLUTTER_DARWIN_EXPORT FlutterWindowOffset InternalFlutter_Window_GetOffsetInParent(void *window)

References InternalFlutter_Window_GetOffsetInParent(), FlutterWindowOffset::x, and FlutterWindowOffset::y.

◆ TEST_F() [91/93]

flutter::testing::TEST_F ( FlutterWindowControllerTest  ,
InternalFlutterWindowGetHandle   
)

Definition at line 267 of file FlutterWindowControllerTest.mm.

267  {
269  .has_size = true,
270  .size = {.width = 800, .height = 600},
271  .resizable = true,
272  .on_should_close = [] {},
273  .on_will_close = [] {},
274  .notify_listeners = [] {},
275  };
276 
277  FlutterEngine* engine = GetFlutterEngine();
278  int64_t engine_id = reinterpret_cast<int64_t>(engine);
279 
280  IsolateScope isolate_scope(isolate());
281  int64_t handle = InternalFlutter_WindowController_CreateRegularWindow(engine_id, &request);
282  FlutterViewController* viewController = [engine viewControllerForIdentifier:handle];
283 
284  void* window_handle = InternalFlutter_Window_GetHandle(engine_id, handle);
285  EXPECT_EQ(window_handle, (__bridge void*)viewController.view.window);
286 }
FLUTTER_DARWIN_EXPORT void * InternalFlutter_Window_GetHandle(int64_t engine_id, FlutterViewIdentifier view_id)

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

◆ TEST_F() [92/93]

flutter::testing::TEST_F ( FlutterWindowControllerTest  ,
ViewMetricsRespectPositionCallbackConstraints   
)

Definition at line 366 of file FlutterWindowControllerTest.mm.

366  {
367  IsolateScope isolate_scope(isolate());
368  FlutterEngine* engine = GetFlutterEngine();
369  int64_t engineId = reinterpret_cast<int64_t>(engine);
370 
371  // Create parent window.
372  auto parentRequest = FlutterWindowCreationRequest{
373  .has_size = true,
374  .size = {.width = 800, .height = 600},
375  .resizable = true,
376  .on_should_close = [] {},
377  .on_will_close = [] {},
378  .notify_listeners = [] {},
379  };
380  int64_t parentViewId =
382  EXPECT_EQ(parentViewId, 1);
383 
384  auto position_callback = [](const FlutterWindowSize& child_size,
385  const FlutterWindowRect& parent_rect,
386  const FlutterWindowRect& output_rect) -> FlutterWindowRect* {
387  FlutterWindowRect* rect = static_cast<FlutterWindowRect*>(malloc(sizeof(FlutterWindowRect)));
388  rect->left = parent_rect.left;
389  rect->top = parent_rect.top;
390  rect->width = 500;
391  rect->height = 400;
392  return rect;
393  };
394 
395  auto tooltipRequest = FlutterWindowCreationRequest{
396  .has_constraints = true,
397  .constraints{
398  .min_width = 0,
399  .min_height = 0,
400  .max_width = 1000,
401  .max_height = 1000,
402  },
403  .parent_view_id = parentViewId,
404  .on_should_close = [] {},
405  .on_will_close = [] {},
406  .notify_listeners = [] {},
407  .on_get_window_position = position_callback,
408  };
409 
410  const int64_t tooltipViewId =
411  InternalFlutter_WindowController_CreateTooltipWindow(engineId, &tooltipRequest);
412  EXPECT_NE(tooltipViewId, 0);
413 
414  FlutterViewController* viewController = [engine viewControllerForIdentifier:tooltipViewId];
415  FlutterView* flutterView = viewController.flutterView;
416 
417  EXPECT_EQ(flutterView.sizedToContents, YES);
418 
419  CFRunLoopRunInMode(kCFRunLoopDefaultMode, 0.1, false);
420 
421  [flutterView.contentDelegate viewDidUpdateContents:flutterView withSize:NSMakeSize(1000, 1000)];
422 
423  // The constraints from request are 1000x1000, but additional constraints came from the positioner
424  // and must be respected.
425  CGSize maxSize = flutterView.maximumContentSize;
426  EXPECT_LE(maxSize.width, 500);
427  EXPECT_LE(maxSize.height, 400);
428 }
CGSize maximumContentSize
Definition: FlutterView.h:142
BOOL sizedToContents
Definition: FlutterView.h:130
id< FlutterViewContentDelegate > contentDelegate
Definition: FlutterView.h:98

References FlutterView::contentDelegate, FlutterWindowCreationRequest::has_constraints, FlutterWindowCreationRequest::has_size, FlutterWindowRect::height, InternalFlutter_WindowController_CreateRegularWindow(), InternalFlutter_WindowController_CreateTooltipWindow(), FlutterWindowRect::left, FlutterView::maximumContentSize, FlutterView::sizedToContents, FlutterWindowRect::top, and FlutterWindowRect::width.

◆ TEST_F() [93/93]

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

Definition at line 288 of file FlutterWindowControllerTest.mm.

288  {
290  .has_size = true,
291  .size = {.width = 800, .height = 600},
292  .resizable = true,
293  .on_should_close = [] {},
294  .on_will_close = [] {},
295  .notify_listeners = [] {},
296  };
297 
298  FlutterEngine* engine = GetFlutterEngine();
299  int64_t engine_id = reinterpret_cast<int64_t>(engine);
300 
301  IsolateScope isolate_scope(isolate());
302  int64_t handle = InternalFlutter_WindowController_CreateRegularWindow(engine_id, &request);
303 
304  FlutterViewController* viewController = [engine viewControllerForIdentifier:handle];
305  NSWindow* window = viewController.view.window;
306  void* windowHandle = (__bridge void*)window;
307 
308  EXPECT_EQ(window.zoomed, NO);
309  EXPECT_EQ(window.miniaturized, NO);
310  EXPECT_EQ(window.styleMask & NSWindowStyleMaskFullScreen, 0u);
311 
312  InternalFlutter_Window_SetMaximized(windowHandle, true);
313  CFRunLoopRunInMode(kCFRunLoopDefaultMode, 0.5, false);
314  EXPECT_EQ(window.zoomed, YES);
315 
316  InternalFlutter_Window_SetMaximized(windowHandle, false);
317  CFRunLoopRunInMode(kCFRunLoopDefaultMode, 0.5, false);
318  EXPECT_EQ(window.zoomed, NO);
319 
320  // FullScreen toggle does not seem to work when the application is not run from a bundle.
321 
322  InternalFlutter_Window_Minimize(windowHandle);
323  CFRunLoopRunInMode(kCFRunLoopDefaultMode, 0.5, false);
324  EXPECT_EQ(window.miniaturized, YES);
325 }
FLUTTER_DARWIN_EXPORT void InternalFlutter_Window_SetMaximized(void *window, bool maximized)
FLUTTER_DARWIN_EXPORT void InternalFlutter_Window_Minimize(void *window)

References FlutterWindowCreationRequest::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().

◆ kTestTimeout

const CFAbsoluteTime flutter::testing::kTestTimeout = 30.0

Definition at line 466 of file FlutterWindowControllerTest.mm.

Referenced by TEST_F().