| Flutter Windows Embedder |

Classes | Functions | Variables
flutter::testing Namespace Reference

## Classes
class | AccessibilityPluginTest
class | CursorHandlerTest
class | MockIDirectManipulationViewport
class | MockIDirectManipulationContent
class | DisplayManagerWin32Test
class | FlutterWindowsEngineTest
class | MockFlutterWindowsView
class | MockWindowsLifecycleManager
class | PlatformHandlerTest
class | TestTaskRunnerWindow
class | TextInputPluginTest
class | WindowsLifecycleManagerTest

## Functions
| TEST (AccessibilityBridgeWindows, GetParent)
| TEST (AccessibilityBridgeWindows, GetParentOnRootRetunsNullptr)
| TEST (AccessibilityBridgeWindows, DispatchAccessibilityAction)
| TEST (AccessibilityBridgeWindows, OnAccessibilityEventAlert)
| TEST (AccessibilityBridgeWindows, OnAccessibilityEventChildrenChanged)
| TEST (AccessibilityBridgeWindows, OnAccessibilityEventFocusChanged)
| TEST (AccessibilityBridgeWindows, OnAccessibilityEventIgnoredChanged)
| TEST (AccessibilityBridgeWindows, OnAccessibilityImageAnnotationChanged)
| TEST (AccessibilityBridgeWindows, OnAccessibilityLiveRegionChanged)
| TEST (AccessibilityBridgeWindows, OnAccessibilityNameChanged)
| TEST (AccessibilityBridgeWindows, OnAccessibilityHScrollPosChanged)
| TEST (AccessibilityBridgeWindows, OnAccessibilityVScrollPosChanged)
| TEST (AccessibilityBridgeWindows, OnAccessibilitySelectedChanged)
| TEST (AccessibilityBridgeWindows, OnAccessibilitySelectedChildrenChanged)
| TEST (AccessibilityBridgeWindows, OnAccessibilitySubtreeCreated)
| TEST (AccessibilityBridgeWindows, OnAccessibilityValueChanged)
| TEST (AccessibilityBridgeWindows, OnAccessibilityStateChanged)
| TEST (AccessibilityBridgeWindows, OnDocumentSelectionChanged)
| TEST_F (AccessibilityPluginTest, DirectAnnounceCall)
| TEST_F (AccessibilityPluginTest, AnnounceWithInt32ViewId)
| TEST_F (AccessibilityPluginTest, AnnounceWithInt64ViewId)
| TEST_F (AccessibilityPluginTest, AnnounceWithInvalidViewIdType)
| TEST_F (AccessibilityPluginTest, AnnounceWithMissingMessage)
| TEST_F (CompositorOpenGLTest, CreateBackingStore)
| TEST_F (CompositorOpenGLTest, CreateBackingStoreImpeller)
| TEST_F (CompositorOpenGLTest, InitializationFailure)
| TEST_F (CompositorOpenGLTest, InitializationRequiresBlit)
| TEST_F (CompositorOpenGLTest, Present)
| TEST_F (CompositorOpenGLTest, PresentEmpty)
| TEST_F (CompositorOpenGLTest, NoSurfaceIgnored)
| TEST_F (CompositorOpenGLTest, PresentUsingANGLEBlitExtension)
| TEST_F (CompositorSoftwareTest, CreateBackingStore)
| TEST_F (CompositorSoftwareTest, Present)
| TEST_F (CompositorSoftwareTest, PresentEmpty)
| TEST_F (CompositorSoftwareTest, PresentMultiLayers)
| TEST_F (CompositorSoftwareTest, PresentOffsetLayers)
| TEST_F (CursorHandlerTest, ActivateSystemCursor)
| TEST_F (CursorHandlerTest, CreateCustomCursor)
| TEST_F (CursorHandlerTest, SetCustomCursor)
| TEST_F (CursorHandlerTest, SetNonexistentCustomCursor)
| TEST_F (CursorHandlerTest, DeleteCustomCursor)
| TEST_F (CursorHandlerTest, DeleteNonexistentCustomCursor)
| TEST (DirectManipulationTest, TestGesture)
| TEST (DirectManipulationTest, TestRounding)
| TEST (DirectManipulationTest, TestInertiaCancelSentForUserCancel)
| TEST (DirectManipulationTest, TestInertiaCamcelNotSentAtInertiaEnd)
| TEST (DirectManipulationTest, TestGestureWithInitialData)
| TEST_F (DisplayManagerWin32Test, MultipleMonitors)
| TEST_F (DisplayManagerWin32Test, HandleDisplayChangeMessage)
| TEST (DpiUtilsTest, NonZero)
| TEST (DpiUtilsTest, NullHwndUsesPrimaryMonitor)
| TEST (FlutterProjectBundle, BasicPropertiesAbsolutePaths)
| TEST (FlutterProjectBundle, BasicPropertiesRelativePaths)
| TEST (FlutterProjectBundle, SwitchesEmpty)
| TEST (FlutterProjectBundle, DartEntrypointArguments)
| TEST (FlutterProjectBundle, Switches)
| TEST_F (FlutterWindowTest, CreateDestroy)
| TEST_F (FlutterWindowTest, OnBitmapSurfaceUpdated)
| TEST_F (FlutterWindowTest, OnCursorRectUpdatedRegularDPI)
| TEST_F (FlutterWindowTest, OnCursorRectUpdatedHighDPI)
| TEST_F (FlutterWindowTest, OnPointerStarSendsDeviceType)
| TEST_F (FlutterWindowTest, OnStylusPointerDown)
| TEST_F (FlutterWindowTest, OnStylusPointerMove)
| TEST_F (FlutterWindowTest, OnStylusPointerUp)
| TEST_F (FlutterWindowTest, OnStylusPointerLeave)
| TEST_F (FlutterWindowTest, OnStylusPointerHover)
| TEST_F (FlutterWindowTest, OnMousePointerDown)
| TEST_F (FlutterWindowTest, OnTouchPointerDown)
| TEST_F (FlutterWindowTest, OnScrollCallsGetScrollOffsetMultiplier)
| TEST_F (FlutterWindowTest, OnWindowRepaint)
| TEST_F (FlutterWindowTest, OnThemeChange)
| TEST_F (FlutterWindowTest, AccessibilityNodeWithoutView)
| TEST_F (FlutterWindowTest, AlertNode)
| TEST_F (FlutterWindowTest, LifecycleFocusMessages)
| TEST_F (FlutterWindowTest, CachedLifecycleMessage)
| TEST_F (FlutterWindowsEngineTest, RunHeadless)
| TEST_F (FlutterWindowsEngineTest, TaskRunnerDelayedTask)
| TEST_F (FlutterWindowsEngineTest, TaskRunnerDoesNotDeadlock)
| TEST_F (FlutterWindowsEngineTest, RunDoesExpectedInitialization)
| TEST_F (FlutterWindowsEngineTest, ConfiguresFrameVsync)
| TEST_F (FlutterWindowsEngineTest, RunWithoutANGLEUsesSoftware)
| TEST_F (FlutterWindowsEngineTest, RunWithoutANGLEOnImpellerFailsToStart)
| TEST_F (FlutterWindowsEngineTest, SendPlatformMessageWithoutResponse)
| TEST_F (FlutterWindowsEngineTest, PlatformMessageRoundTrip)
| TEST_F (FlutterWindowsEngineTest, PlatformMessageRespondOnDifferentThread)
| TEST_F (FlutterWindowsEngineTest, SendPlatformMessageWithResponse)
| TEST_F (FlutterWindowsEngineTest, DispatchSemanticsAction)
| TEST_F (FlutterWindowsEngineTest, SetsThreadPriority)
| TEST_F (FlutterWindowsEngineTest, AddPluginRegistrarDestructionCallback)
| TEST_F (FlutterWindowsEngineTest, ScheduleFrame)
| TEST_F (FlutterWindowsEngineTest, SetNextFrameCallback)
| TEST_F (FlutterWindowsEngineTest, GetExecutableName)
| TEST_F (FlutterWindowsEngineTest, UpdateHighContrastFeature)
| TEST_F (FlutterWindowsEngineTest, PostRasterThreadTask)
| TEST_F (FlutterWindowsEngineTest, AccessibilityAnnouncement)
| TEST_F (FlutterWindowsEngineTest, AccessibilityAnnouncementHeadless)
| TEST_F (FlutterWindowsEngineTest, AccessibilityTooltip)
| TEST_F (FlutterWindowsEngineTest, TestExit)
| TEST_F (FlutterWindowsEngineTest, TestExitCancel)
| TEST_F (FlutterWindowsEngineTest, TestExitSecondCloseMessage)
| TEST_F (FlutterWindowsEngineTest, TestExitCloseMultiWindow)
| TEST_F (FlutterWindowsEngineTest, LifecycleManagerDisabledByDefault)
| TEST_F (FlutterWindowsEngineTest, EnableApplicationLifecycle)
| TEST_F (FlutterWindowsEngineTest, ApplicationLifecycleExternalWindow)
| TEST_F (FlutterWindowsEngineTest, LifecycleStateTransition)
| TEST_F (FlutterWindowsEngineTest, ExternalWindowMessage)
| TEST_F (FlutterWindowsEngineTest, InnerWindowHidden)
| TEST_F (FlutterWindowsEngineTest, EnableLifecycleState)
| TEST_F (FlutterWindowsEngineTest, LifecycleStateToFrom)
| TEST_F (FlutterWindowsEngineTest, ChannelListenedTo)
| TEST_F (FlutterWindowsEngineTest, ReceivePlatformViewMessage)
| TEST_F (FlutterWindowsEngineTest, AddViewFailureDoesNotHang)
| TEST_F (FlutterWindowsEngineTest, RemoveViewFailureDoesNotHang)
| TEST_F (FlutterWindowsEngineTest, MergedUIThread)
| TEST_F (FlutterWindowsEngineTest, OnViewFocusChangeRequest)
| TEST_F (FlutterWindowsEngineTest, UpdateSemanticsMultiView)
| TEST (FlutterWindowsTextureRegistrarTest, CreateDestroy)
| TEST (FlutterWindowsTextureRegistrarTest, RegisterUnregisterTexture)
| TEST (FlutterWindowsTextureRegistrarTest, RegisterUnknownTextureType)
| TEST (FlutterWindowsTextureRegistrarTest, PopulatePixelBufferTexture)
| TEST (FlutterWindowsTextureRegistrarTest, PopulateD3dTextureWithHandle)
| TEST (FlutterWindowsTextureRegistrarTest, PopulateD3dTexture)
| TEST (FlutterWindowsTextureRegistrarTest, PopulateInvalidTexture)
| TEST (FlutterWindowsTextureRegistrarTest, UnregisterTextureWithEngineDownInvokesCallback)
| TEST (WindowsNoFixtureTest, GetTextureRegistrar)
| TEST_F (WindowsTest, LaunchMain)
| TEST_F (WindowsTest, LaunchMainHasNoOutput)
| TEST_F (WindowsTest, LaunchCustomEntrypoint)
| TEST_F (WindowsTest, LaunchCustomEntrypointInEngineRunInvocation)
| TEST_F (WindowsTest, LaunchHeadlessEngine)
| TEST_F (WindowsTest, EngineCanTransitionToHeadless)
| TEST_F (WindowsTest, LaunchRefreshesAccessibility)
| TEST_F (WindowsTest, LaunchConflictingCustomEntrypoints)
| TEST_F (WindowsTest, VerifyNativeFunction)
| TEST_F (WindowsTest, VerifyNativeFunctionWithParameters)
| TEST_F (WindowsTest, PlatformExecutable)
| TEST_F (WindowsTest, VerifyNativeFunctionWithReturn)
| TEST_F (WindowsTest, NextFrameCallback)
| TEST_F (WindowsTest, PresentHeadless)
| TEST_F (WindowsTest, GetViewId)
| TEST_F (WindowsTest, GetGraphicsAdapter)
| TEST_F (WindowsTest, GetEngineGraphicsAdapter)
| TEST_F (WindowsTest, GetGraphicsAdapterWithLowPowerPreference)
| TEST_F (WindowsTest, GetGraphicsAdapterWithHighPerformancePreference)
| TEST_F (WindowsTest, GetEngineGraphicsAdapterWithLowPowerPreference)
| TEST_F (WindowsTest, GetEngineGraphicsAdapterWithHighPerformancePreference)
| TEST_F (WindowsTest, PluginRegistrarGetImplicitView)
| TEST_F (WindowsTest, PluginRegistrarGetView)
| TEST_F (WindowsTest, PluginRegistrarGetViewHeadless)
| TEST_F (WindowsTest, SurfaceOptional)
| TEST_F (WindowsTest, Lifecycle)
| TEST_F (WindowsTest, GetKeyboardStateHeadless)
| TEST_F (WindowsTest, AddRemoveView)
| TEST_F (WindowsTest, EngineId)
| TEST_F (WindowsTest, EnableIAccessible)
| TEST_F (WindowsTest, EnableIAccessibleEx)
| TEST (FlutterWindowsViewTest, SubMenuExpandedState)
| TEST (FlutterWindowsViewTest, Shutdown)
| TEST (FlutterWindowsViewTest, KeySequence)
| TEST (FlutterWindowsViewTest, KeyEventCallback)
| TEST (FlutterWindowsViewTest, EnableSemantics)
| TEST (FlutterWindowsViewTest, AddSemanticsNodeUpdate)
| TEST (FlutterWindowsViewTest, AddSemanticsNodeUpdateWithChildren)
| TEST (FlutterWindowsViewTest, NonZeroSemanticsRoot)
| TEST (FlutterWindowsViewTest, AccessibilityHitTesting)
| TEST (FlutterWindowsViewTest, WindowResizeTests)
| TEST (FlutterWindowsViewTest, TestEmptyFrameResizes)
| TEST (FlutterWindowsViewTest, WindowResizeRace)
| TEST (FlutterWindowsViewTest, WindowResizeInvalidSurface)
| TEST (FlutterWindowsViewTest, WindowResizeWithoutSurface)
| TEST (FlutterWindowsViewTest, WindowRepaintTests)
| TEST (FlutterWindowsViewTest, CheckboxNativeState)
| TEST (FlutterWindowsViewTest, SwitchNativeState)
| TEST (FlutterWindowsViewTest, TooltipNodeData)
| TEST (FlutterWindowsViewTest, DisablesVSyncAtStartup)
| TEST (FlutterWindowsViewTest, EnablesVSyncAtStartup)
| TEST (FlutterWindowsViewTest, DisablesVSyncAfterStartup)
| TEST (FlutterWindowsViewTest, EnablesVSyncAfterStartup)
| TEST (FlutterWindowsViewTest, UpdatesVSyncOnDwmUpdates)
| TEST (FlutterWindowsViewTest, FocusTriggersWindowFocus)
| TEST (FlutterWindowsViewTest, OnFocusTriggersSendFocusViewEvent)
| TEST (FlutterWindowsViewTest, WindowMetricsEventContainsDisplayId)
| TEST (FlutterWindowsViewTest, SizeChangeTriggersMetricsEventWhichHasDisplayId)
| TEST (FlutterWindowsViewTest, FirstFrameCallbackFiresOnFramePresented)
| TEST (FlutterWindowsViewTest, FirstFrameCallbackFiresOnSoftwareBitmapPresent)
| TEST (FlutterWindowsViewTest, FirstFrameCallbackFiresOnlyOnce)
| TEST (FlutterWindowsViewTest, FirstFrameCallbackSkippedOnFailedSoftwarePresent)
| TEST (KeyboardKeyChannelHandlerTest, KeyboardHookHandling)
| TEST (KeyboardKeyChannelHandlerTest, ExtendedKeysAreSentToRedispatch)
| TEST (KeyboardKeyChannelHandlerTest, DeadKeysDoNotCrash)
| TEST (KeyboardKeyChannelHandlerTest, EmptyResponsesDoNotCrash)
| TEST (KeyboardKeyEmbedderHandlerTest, ConvertChar32ToUtf8)
| TEST (KeyboardKeyEmbedderHandlerTest, BasicKeyPressingAndHolding)
| TEST (KeyboardKeyEmbedderHandlerTest, ToggleNumLockDuringNumpadPress)
| TEST (KeyboardKeyEmbedderHandlerTest, ImeEventsAreIgnored)
| TEST (KeyboardKeyEmbedderHandlerTest, ModifierKeysByExtendedBit)
| TEST (KeyboardKeyEmbedderHandlerTest, ModifierKeysByVirtualKey)
| TEST (KeyboardKeyEmbedderHandlerTest, SynthesizeModifierLeftKeyDownWhenNotPressed)
| TEST (KeyboardKeyEmbedderHandlerTest, DoNotSynthesizeModifierDownWhenPressed)
| TEST (KeyboardKeyEmbedderHandlerTest, SynthesizeModifierUpWhenPressed)
| TEST (KeyboardKeyEmbedderHandlerTest, DoNotSynthesizeModifierUpWhenNotPressed)
| TEST (KeyboardKeyEmbedderHandlerTest, RepeatedDownIsIgnored)
| TEST (KeyboardKeyEmbedderHandlerTest, AbruptRepeatIsConvertedToDown)
| TEST (KeyboardKeyEmbedderHandlerTest, AbruptUpIsIgnored)
| TEST (KeyboardKeyEmbedderHandlerTest, SynthesizeForDesyncPressingState)
| TEST (KeyboardKeyEmbedderHandlerTest, SynthesizeForDesyncToggledState)
| TEST (KeyboardKeyEmbedderHandlerTest, SynthesizeForDesyncToggledStateByItselfsUp)
| TEST (KeyboardKeyEmbedderHandlerTest, SynthesizeForDesyncToggledStateByItselfsDown)
| TEST (KeyboardKeyEmbedderHandlerTest, SynthesizeWithInitialTogglingState)
| TEST (KeyboardKeyEmbedderHandlerTest, SysKeyPress)
| TEST (KeyboardKeyHandlerTest, SingleDelegateWithAsyncResponds)
| TEST (KeyboardKeyHandlerTest, SingleDelegateWithSyncResponds)
| TEST (KeyboardKeyHandlerTest, HandlerGetPressedState)
| TEST (KeyboardKeyHandlerTest, KeyboardChannelGetPressedState)
| TEST_F (KeyboardTest, LowerCaseAHandled)
| TEST_F (KeyboardTest, LowerCaseAUnhandled)
| TEST_F (KeyboardTest, ArrowLeftHandled)
| TEST_F (KeyboardTest, ArrowLeftUnhandled)
| TEST_F (KeyboardTest, ShiftLeftUnhandled)
| TEST_F (KeyboardTest, ShiftRightUnhandled)
| TEST_F (KeyboardTest, CtrlLeftUnhandled)
| TEST_F (KeyboardTest, CtrlRightUnhandled)
| TEST_F (KeyboardTest, AltLeftUnhandled)
| TEST_F (KeyboardTest, AltRightUnhandled)
| TEST_F (KeyboardTest, MetaLeftUnhandled)
| TEST_F (KeyboardTest, MetaRightUnhandled)
| TEST_F (KeyboardTest, RepeatA)
| TEST_F (KeyboardTest, RestartClearsKeyboardState)
| TEST_F (KeyboardTest, FreshKeyDownAfterMissedUpIsDelivered)
| TEST_F (KeyboardTest, ShiftLeftKeyA)
| TEST_F (KeyboardTest, CtrlLeftKeyA)
| TEST_F (KeyboardTest, CtrlLeftDigit1)
| TEST_F (KeyboardTest, Digit1OnFrenchLayout)
| TEST_F (KeyboardTest, AltGrModifiedKey)
| TEST_F (KeyboardTest, AltGrTwice)
| TEST_F (KeyboardTest, DeadKeyThatCombines)
| TEST_F (KeyboardTest, DeadKeyWithoutDeadMaskThatCombines)
| TEST_F (KeyboardTest, DeadKeyThatDoesNotCombine)
| TEST_F (KeyboardTest, DeadKeyTwiceThenLetter)
| TEST_F (KeyboardTest, MultibyteCharacter)
| TEST_F (KeyboardTest, SynthesizeModifiers)
| TEST_F (KeyboardTest, ImeExtendedEventsAreIgnored)
| TEST_F (KeyboardTest, UpOnlyImeEventsAreCorrectlyHandled)
| TEST_F (KeyboardTest, SlowFrameworkResponse)
| TEST_F (KeyboardTest, SlowFrameworkResponseForIdenticalEvents)
| TEST_F (KeyboardTest, TextInputSubmit)
| TEST_F (KeyboardTest, VietnameseTelexAddDiacriticWithFastResponse)
void | VietnameseTelexAddDiacriticWithSlowResponse (WindowsTestContext &context, bool backspace_response)
| TEST_F (KeyboardTest, VietnameseTelexAddDiacriticWithSlowFalseResponse)
| TEST_F (KeyboardTest, VietnameseTelexAddDiacriticWithSlowTrueResponse)
| TEST_F (KeyboardTest, DoubleCapsLock)
| TEST (KeyboardWin32CommonTest, EncodeUtf16)
| TEST_F (PlatformHandlerTest, GetClipboardData)
| TEST_F (PlatformHandlerTest, GetClipboardDataRejectsUnknownContentType)
| TEST_F (PlatformHandlerTest, GetClipboardDataReportsOpenFailure)
| TEST_F (PlatformHandlerTest, GetClipboardDataReportsGetDataFailure)
| TEST_F (PlatformHandlerTest, ClipboardHasStrings)
| TEST_F (PlatformHandlerTest, ClipboardHasStringsReturnsFalse)
| TEST_F (PlatformHandlerTest, ClipboardHasStringsRejectsUnknownContentType)
| TEST_F (PlatformHandlerTest, ClipboardHasStringsIgnoresPermissionErrors)
| TEST_F (PlatformHandlerTest, ClipboardHasStringsReportsErrors)
| TEST_F (PlatformHandlerTest, ClipboardSetData)
| TEST_F (PlatformHandlerTest, ClipboardSetDataTextMustBeString)
| TEST_F (PlatformHandlerTest, ClipboardSetDataUnknownType)
| TEST_F (PlatformHandlerTest, ClipboardSetDataReportsOpenFailure)
| TEST_F (PlatformHandlerTest, ClipboardSetDataReportsSetDataFailure)
| TEST_F (PlatformHandlerTest, PlaySystemSound)
| TEST_F (PlatformHandlerTest, SystemExitApplicationRequired)
| TEST_F (PlatformHandlerTest, SystemExitApplicationCancelableCancel)
| TEST_F (PlatformHandlerTest, SystemExitApplicationCancelableExit)
| TEST (SequentialIdGeneratorTest, RemoveMultipleNumbers)
| TEST (SequentialIdGeneratorTest, MaybeRemoveNumbers)
| TEST (SettingsPluginTest, SendSettingsSendsMessage)
| TEST (SettingsPluginTest, SendSettingsGetsSettings)
| TEST (SettingsPluginTest, StartWatchingStartsWatchingChanges)
| TEST (SettingsPluginTest, HighContrastModeHonored)
| TEST (SystemUtils, GetPreferredLanguageInfo)
| TEST (SystemUtils, GetPreferredLanguages)
| TEST (SystemUtils, ParseLanguageNameGeneric)
| TEST (SystemUtils, ParseLanguageNameWithRegion)
| TEST (SystemUtils, ParseLanguageNameWithScript)
| TEST (SystemUtils, ParseLanguageNameWithRegionAndScript)
| TEST (SystemUtils, ParseLanguageNameWithSuplementalLanguage)
| TEST (SystemUtils, ParseLanguageNameWithThreeCharacterLanguage)
| TEST (SystemUtils, GetUserTimeFormat)
| TEST (SystemUtils, Prefer24HourTimeHandlesEmptyFormat)
| TEST (SystemUtils, Prefer24HourTimeHandles12Hour)
| TEST (SystemUtils, Prefer24HourTimeHandles24Hour)
| TEST (TaskRunnerTest, MaybeExecuteTaskWithExactOrder)
| TEST (TaskRunnerTest, MaybeExecuteTaskOnlyExpired)
| TEST (TaskRunnerTest, TimerThreadDoesNotCancelEarlierScheduledTasks)
| TEST (TaskRunnerTest, EmptyTaskRunnerReturnsNanoSecondsMax)
| TEST (TaskRunnerTest, TaskRunnerWindowCoalescesWakeUpMessages)
| TEST_F (TextInputPluginTest, TextMethodsWorksWithEmptyModel)
| TEST_F (TextInputPluginTest, ClearClientResetsComposing)
| TEST_F (TextInputPluginTest, ClearClientRequiresView)
| TEST_F (TextInputPluginTest, VerifyComposingSendStateUpdate)
| TEST_F (TextInputPluginTest, VerifyInputActionNewlineInsertNewLine)
| TEST_F (TextInputPluginTest, VerifyInputActionSendDoesNotInsertNewLine)
| TEST_F (TextInputPluginTest, SetClientRequiresViewId)
| TEST_F (TextInputPluginTest, SetClientRequiresViewIdToBeInteger)
| TEST_F (TextInputPluginTest, TextEditingWorksWithDeltaModel)
| TEST_F (TextInputPluginTest, CompositionCursorPos)
| TEST_F (TextInputPluginTest, TransformCursorRect)
| TEST_F (TextInputPluginTest, SetMarkedTextRectRequiresView)
| TEST_F (TextInputPluginTest, SetAndUseMultipleClients)
| TEST_F (WindowManagerTest, WindowingInitialize)
| TEST_F (WindowManagerTest, CreateRegularWindow)
| TEST_F (WindowManagerTest, GetWindowHandle)
| TEST_F (WindowManagerTest, GetWindowSize)
| TEST_F (WindowManagerTest, SetWindowSize)
| TEST_F (WindowManagerTest, CanConstrainByMinimiumSize)
| TEST_F (WindowManagerTest, CanConstrainByMaximumSize)
| TEST_F (WindowManagerTest, CanFullscreenWindow)
| TEST_F (WindowManagerTest, CanUnfullscreenWindow)
| TEST_F (WindowManagerTest, CanSetWindowSizeWhileFullscreen)
| TEST_F (WindowManagerTest, CanSetWindowConstraintsWhileFullscreen)
| TEST_F (WindowManagerTest, CreateModelessDialogWindow)
| TEST_F (WindowManagerTest, CreateModalDialogWindow)
| TEST_F (WindowManagerTest, DialogCanNeverBeFullscreen)
| TEST_F (WindowManagerTest, CreateTooltipWindow)
| TEST_F (WindowManagerTest, TooltipWindowHasNoActivateStyle)
| TEST_F (WindowManagerTest, TooltipWindowDoesNotStealFocus)
| TEST_F (WindowManagerTest, TooltipWindowReturnsNoActivateOnMouseClick)
| TEST_F (WindowManagerTest, TooltipWindowUpdatesPositionOnViewSizeChange)
| TEST (WindowProcDelegateManagerTest, CallsCorrectly)
| TEST (WindowProcDelegateManagerTest, ReplacementRegister)
| TEST (WindowProcDelegateManagerTest, RegisterMultiple)
| TEST (WindowProcDelegateManagerTest, Ordered)
| TEST (WindowProcDelegateManagerTest, ConflictingDelegates)
| TEST (WindowProcDelegateManagerTest, Unregister)
| TEST (MockWindow, CreateDestroy)
| TEST (MockWindow, GetDpiAfterCreate)
| TEST (MockWindow, VerticalScroll)
| TEST (MockWindow, OnImeCompositionCompose)
| TEST (MockWindow, OnImeCompositionResult)
| TEST (MockWindow, OnImeCompositionResultAndCompose)
| TEST (MockWindow, OnImeCompositionClearChange)
| TEST (MockWindow, HorizontalScroll)
| TEST (MockWindow, MouseLeave)
| TEST (MockWindow, KeyDown)
| TEST (MockWindow, KeyUp)
| TEST (MockWindow, SysKeyDown)
| TEST (MockWindow, SysKeyUp)
| TEST (MockWindow, KeyDownPrintable)
| TEST (MockWindow, KeyDownWithCtrl)
| TEST (MockWindow, KeyDownWithCtrlToggled)
| TEST (MockWindow, Paint)
| TEST (MockWindow, PointerHitTest)
| TEST (MockWindow, TouchPadHitTest)
| TEST (MockWindow, UnknownPointerTypeSkipsDirectManipulation)
| TEST (MockWindow, DISABLED_GetObjectUia)
static void | WaitUntilUpdated (const WindowsLifecycleManager &manager)
| TEST_F (WindowsLifecycleManagerTest, StateTransitions)
FlutterSemanticsNode2 | CreateSemanticsNode (int32_t id, const char *label, const std::vector< int32_t > *children=nullptr)
| TEST (AccessibilityBridgeTest, BasicTest)
| TEST (AccessibilityBridgeTest, AccessibilityRootId)
| TEST (AccessibilityBridgeTest, AddOrder)
| TEST (AccessibilityBridgeTest, CanFireChildrenChangedCorrectly)
| TEST (AccessibilityBridgeTest, CanHandleSelectionChangeCorrectly)
| TEST (AccessibilityBridgeTest, DoesNotAssignEditableRootToSelectableText)
| TEST (AccessibilityBridgeTest, SwitchHasSwitchRole)
| TEST (AccessibilityBridgeTest, SliderHasSliderRole)
| TEST (AccessibilityBridgeTest, CanSetCheckboxChecked)
| TEST (AccessibilityBridgeTest, CanReparentNode)
| TEST (AccessibilityBridgeTest, CanReparentMultipleNodes)
| TEST (AccessibilityBridgeTest, CanReparentNodeWithChild)
| TEST (AccessibilityBridgeTest, AXTreeManagerTest)
| TEST (AccessibilityBridgeTest, LineBreakingObjectTest)
| TEST (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
constexpr uint64_t | kScanCodeKeyA = 0x1e
constexpr uint64_t | kVirtualKeyA = 0x41
FlutterSemanticsFlags | kEmptyFlags = FlutterSemanticsFlags{}

## Function Documentation

## ◆ CreateSemanticsNode()

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

Definition at line 20 of file accessibility_bridge_unittests.cc.

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

References kEmptyFlags.

Referenced by TEST().

## ◆ TEST() [1/171]

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 }
flutter::testing::CreateSemanticsNode
FlutterSemanticsNode2 CreateSemanticsNode(int32_t id, const char *label, const std::vector< int32_t > *children=nullptr)
Definition: accessibility_bridge_unittests.cc:20

References CreateSemanticsNode().

## ◆ TEST() [2/171]

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

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

Definition at line 566 of file accessibility_bridge_unittests.cc.

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

## ◆ TEST() [4/171]

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

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

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

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

Definition at line 392 of file accessibility_bridge_unittests.cc.

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

References CreateSemanticsNode().

## ◆ TEST() [8/171]

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

Definition at line 329 of file accessibility_bridge_unittests.cc.

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

References CreateSemanticsNode().

## ◆ TEST() [9/171]

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

Definition at line 486 of file accessibility_bridge_unittests.cc.

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

References CreateSemanticsNode().

## ◆ TEST() [10/171]

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

Definition at line 310 of file accessibility_bridge_unittests.cc.

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

References CreateSemanticsNode().

## ◆ TEST() [11/171]

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

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

Definition at line 595 of file accessibility_bridge_unittests.cc.

595 {
596 std::shared_ptr<TestAccessibilityBridge> bridge =
597 std::make_shared<TestAccessibilityBridge>();
598
599 std::vector<int32_t> children{1, 2};
600 FlutterSemanticsNode2 node0 = CreateSemanticsNode(0, "node 0", &children);
601 auto flags0 = FlutterSemanticsFlags{
602 .is_selected = FlutterTristate::kFlutterTristateNone,
603 };
604 node0.flags2 = &flags0;
605
606 FlutterSemanticsNode2 node1 = CreateSemanticsNode(1, "node 1");
607 auto flags1 = FlutterSemanticsFlags{
608 .is_selected = FlutterTristate::kFlutterTristateTrue,
609 };
610 node1.flags2 = &flags1;
611
612 FlutterSemanticsNode2 node2 = CreateSemanticsNode(2, "node 2");
613 auto flags2 = FlutterSemanticsFlags{
614 .is_selected = FlutterTristate::kFlutterTristateFalse,
615 };
616 node2.flags2 = &flags2;
617
618 bridge->AddFlutterSemanticsNodeUpdate(node0);
619 bridge->AddFlutterSemanticsNodeUpdate(node1);
620 bridge->AddFlutterSemanticsNodeUpdate(node2);
621 bridge->CommitUpdates();
622
623 auto delegate0 = bridge->GetFlutterPlatformNodeDelegateFromID(0).lock();
624 auto delegate1 = bridge->GetFlutterPlatformNodeDelegateFromID(1).lock();
625 auto delegate2 = bridge->GetFlutterPlatformNodeDelegateFromID(2).lock();
626
627 // For kFlutterTristateNone, selected should be false.
628 EXPECT_FALSE(delegate0->GetData().GetBoolAttribute(
629 ax::mojom::BoolAttribute::kSelected));
630 // For kFlutterTristateTrue, selected should be true.
631 EXPECT_TRUE(delegate1->GetData().GetBoolAttribute(
632 ax::mojom::BoolAttribute::kSelected));
633 // For kFlutterTristateFalse, selected should be false.
634 EXPECT_FALSE(delegate2->GetData().GetBoolAttribute(
635 ax::mojom::BoolAttribute::kSelected));
636 }

References CreateSemanticsNode().

## ◆ TEST() [13/171]

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

Definition at line 576 of file accessibility_bridge_unittests.cc.

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

References CreateSemanticsNode().

## ◆ TEST() [14/171]

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

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

flutter::testing::TEST | ( | AccessibilityBridgeWindows | ,
|  | DispatchAccessibilityAction |
| ) |  |

Definition at line 279 of file accessibility_bridge_windows_unittests.cc.

279 {
280 auto engine = GetTestEngine();
281 FlutterWindowsViewSpy view{
282 engine.get(), std::make_unique<NiceMock<MockWindowBindingHandler>>()};
283 EngineModifier modifier{engine.get()};
284 modifier.SetImplicitView(&view);
285 view.OnUpdateSemanticsEnabled(true);
286
287 auto bridge = view.accessibility_bridge().lock();
288 PopulateAXTree(bridge);
289
290 FlutterSemanticsAction actual_action = kFlutterSemanticsActionTap;
291 modifier.embedder_api().SendSemanticsAction = MOCK_ENGINE_PROC(
292 SendSemanticsAction,
293 ([&actual_action](FLUTTER_API_SYMBOL(FlutterEngine) engine,
294 const FlutterSendSemanticsActionInfo* info) {
295 actual_action = info->action;
296 return kSuccess;
297 }));
298
299 AccessibilityBridgeWindows delegate(&view);
300 delegate.DispatchAccessibilityAction(1, kFlutterSemanticsActionCopy, {});
301 EXPECT_EQ(actual_action, kFlutterSemanticsActionCopy);
302 }

References flutter::AccessibilityBridgeWindows::DispatchAccessibilityAction().

## ◆ TEST() [17/171]

flutter::testing::TEST | ( | AccessibilityBridgeWindows | ,
|  | GetParent |
| ) |  |

Definition at line 247 of file accessibility_bridge_windows_unittests.cc.

247 {
248 auto engine = GetTestEngine();
249 FlutterWindowsViewSpy view{
250 engine.get(), std::make_unique<NiceMock<MockWindowBindingHandler>>()};
251 EngineModifier modifier{engine.get()};
252 modifier.SetImplicitView(&view);
253 view.OnUpdateSemanticsEnabled(true);
254
255 auto bridge = view.accessibility_bridge().lock();
256 PopulateAXTree(bridge);
257
258 auto node0_delegate = bridge->GetFlutterPlatformNodeDelegateFromID(0).lock();
259 auto node1_delegate = bridge->GetFlutterPlatformNodeDelegateFromID(1).lock();
260 EXPECT_EQ(node0_delegate->GetNativeViewAccessible(),
261 node1_delegate->GetParent());
262 }

## ◆ TEST() [18/171]

flutter::testing::TEST | ( | AccessibilityBridgeWindows | ,
|  | GetParentOnRootRetunsNullptr |
| ) |  |

Definition at line 264 of file accessibility_bridge_windows_unittests.cc.

264 {
265 auto engine = GetTestEngine();
266 FlutterWindowsViewSpy view{
267 engine.get(), std::make_unique<NiceMock<MockWindowBindingHandler>>()};
268 EngineModifier modifier{engine.get()};
269 modifier.SetImplicitView(&view);
270 view.OnUpdateSemanticsEnabled(true);
271
272 auto bridge = view.accessibility_bridge().lock();
273 PopulateAXTree(bridge);
274
275 auto node0_delegate = bridge->GetFlutterPlatformNodeDelegateFromID(0).lock();
276 ASSERT_TRUE(node0_delegate->GetParent() == nullptr);
277 }

## ◆ TEST() [19/171]

flutter::testing::TEST | ( | AccessibilityBridgeWindows | ,
|  | OnAccessibilityEventAlert |
| ) |  |

Definition at line 304 of file accessibility_bridge_windows_unittests.cc.

304 {
305 ExpectWinEventFromAXEvent(0, ui::AXEventGenerator::Event::ALERT,
306 ax::mojom::Event::kAlert);
307 }

## ◆ TEST() [20/171]

flutter::testing::TEST | ( | AccessibilityBridgeWindows | ,
|  | OnAccessibilityEventChildrenChanged |
| ) |  |

Definition at line 309 of file accessibility_bridge_windows_unittests.cc.

309 {
310 ExpectWinEventFromAXEvent(0, ui::AXEventGenerator::Event::CHILDREN_CHANGED,
311 ax::mojom::Event::kChildrenChanged);
312 }

## ◆ TEST() [21/171]

flutter::testing::TEST | ( | AccessibilityBridgeWindows | ,
|  | OnAccessibilityEventFocusChanged |
| ) |  |

Definition at line 314 of file accessibility_bridge_windows_unittests.cc.

314 {
315 auto engine = GetTestEngine();
316 FlutterWindowsViewSpy view{
317 engine.get(), std::make_unique<NiceMock<MockWindowBindingHandler>>()};
318 EngineModifier modifier{engine.get()};
319 modifier.SetImplicitView(&view);
320 view.OnUpdateSemanticsEnabled(true);
321
322 auto bridge = GetAccessibilityBridgeSpy(view);
323 PopulateAXTree(bridge);
324
325 bridge->ResetRecords();
326 bridge->OnAccessibilityEvent({AXNodeFromID(bridge, 1),
327 {ui::AXEventGenerator::Event::FOCUS_CHANGED,
328 ax::mojom::EventFrom::kNone,
329 {}}});
330 ASSERT_EQ(bridge->dispatched_events().size(), 1);
331 EXPECT_EQ(bridge->dispatched_events()[0].event_type,
332 ax::mojom::Event::kFocus);
333
334 ASSERT_EQ(bridge->focused_nodes().size(), 1);
335 EXPECT_EQ(bridge->focused_nodes()[0], 1);
336 }

## ◆ TEST() [22/171]

flutter::testing::TEST | ( | AccessibilityBridgeWindows | ,
|  | OnAccessibilityEventIgnoredChanged |
| ) |  |

Definition at line 338 of file accessibility_bridge_windows_unittests.cc.

338 {
339 // Static test nodes with no text, hint, or scrollability are ignored.
340 ExpectWinEventFromAXEvent(4, ui::AXEventGenerator::Event::IGNORED_CHANGED,
341 ax::mojom::Event::kHide);
342 }

## ◆ TEST() [23/171]

flutter::testing::TEST | ( | AccessibilityBridgeWindows | ,
|  | OnAccessibilityHScrollPosChanged |
| ) |  |

Definition at line 360 of file accessibility_bridge_windows_unittests.cc.

360 {
361 ExpectWinEventFromAXEvent(
362 1, ui::AXEventGenerator::Event::SCROLL_HORIZONTAL_POSITION_CHANGED,
363 ax::mojom::Event::kScrollPositionChanged);
364 }

## ◆ TEST() [24/171]

flutter::testing::TEST | ( | AccessibilityBridgeWindows | ,
|  | OnAccessibilityImageAnnotationChanged |
| ) |  |

Definition at line 344 of file accessibility_bridge_windows_unittests.cc.

344 {
345 ExpectWinEventFromAXEvent(
346 1, ui::AXEventGenerator::Event::IMAGE_ANNOTATION_CHANGED,
347 ax::mojom::Event::kTextChanged);
348 }

## ◆ TEST() [25/171]

flutter::testing::TEST | ( | AccessibilityBridgeWindows | ,
|  | OnAccessibilityLiveRegionChanged |
| ) |  |

Definition at line 350 of file accessibility_bridge_windows_unittests.cc.

350 {
351 ExpectWinEventFromAXEvent(1, ui::AXEventGenerator::Event::LIVE_REGION_CHANGED,
352 ax::mojom::Event::kLiveRegionChanged);
353 }

## ◆ TEST() [26/171]

flutter::testing::TEST | ( | AccessibilityBridgeWindows | ,
|  | OnAccessibilityNameChanged |
| ) |  |

Definition at line 355 of file accessibility_bridge_windows_unittests.cc.

355 {
356 ExpectWinEventFromAXEvent(1, ui::AXEventGenerator::Event::NAME_CHANGED,
357 ax::mojom::Event::kTextChanged);
358 }

## ◆ TEST() [27/171]

flutter::testing::TEST | ( | AccessibilityBridgeWindows | ,
|  | OnAccessibilitySelectedChanged |
| ) |  |

Definition at line 372 of file accessibility_bridge_windows_unittests.cc.

372 {
373 ExpectWinEventFromAXEvent(1, ui::AXEventGenerator::Event::SELECTED_CHANGED,
374 ax::mojom::Event::kValueChanged);
375 }

## ◆ TEST() [28/171]

flutter::testing::TEST | ( | AccessibilityBridgeWindows | ,
|  | OnAccessibilitySelectedChildrenChanged |
| ) |  |

Definition at line 377 of file accessibility_bridge_windows_unittests.cc.

377 {
378 ExpectWinEventFromAXEvent(
379 2, ui::AXEventGenerator::Event::SELECTED_CHILDREN_CHANGED,
380 ax::mojom::Event::kSelectedChildrenChanged);
381 }

## ◆ TEST() [29/171]

flutter::testing::TEST | ( | AccessibilityBridgeWindows | ,
|  | OnAccessibilityStateChanged |
| ) |  |

Definition at line 393 of file accessibility_bridge_windows_unittests.cc.

393 {
394 ExpectWinEventFromAXEvent(
395 1, ui::AXEventGenerator::Event::WIN_IACCESSIBLE_STATE_CHANGED,
396 ax::mojom::Event::kStateChanged);
397 }

## ◆ TEST() [30/171]

flutter::testing::TEST | ( | AccessibilityBridgeWindows | ,
|  | OnAccessibilitySubtreeCreated |
| ) |  |

Definition at line 383 of file accessibility_bridge_windows_unittests.cc.

383 {
384 ExpectWinEventFromAXEvent(0, ui::AXEventGenerator::Event::SUBTREE_CREATED,
385 ax::mojom::Event::kShow);
386 }

## ◆ TEST() [31/171]

flutter::testing::TEST | ( | AccessibilityBridgeWindows | ,
|  | OnAccessibilityValueChanged |
| ) |  |

Definition at line 388 of file accessibility_bridge_windows_unittests.cc.

388 {
389 ExpectWinEventFromAXEvent(1, ui::AXEventGenerator::Event::VALUE_CHANGED,
390 ax::mojom::Event::kValueChanged);
391 }

## ◆ TEST() [32/171]

flutter::testing::TEST | ( | AccessibilityBridgeWindows | ,
|  | OnAccessibilityVScrollPosChanged |
| ) |  |

Definition at line 366 of file accessibility_bridge_windows_unittests.cc.

366 {
367 ExpectWinEventFromAXEvent(
368 1, ui::AXEventGenerator::Event::SCROLL_VERTICAL_POSITION_CHANGED,
369 ax::mojom::Event::kScrollPositionChanged);
370 }

## ◆ TEST() [33/171]

flutter::testing::TEST | ( | AccessibilityBridgeWindows | ,
|  | OnDocumentSelectionChanged |
| ) |  |

Definition at line 399 of file accessibility_bridge_windows_unittests.cc.

399 {
400 ExpectWinEventFromAXEventOnFocusNode(
401 1, ui::AXEventGenerator::Event::DOCUMENT_SELECTION_CHANGED,
402 ax::mojom::Event::kDocumentSelectionChanged, 2);
403 }

## ◆ TEST() [34/171]

flutter::testing::TEST | ( | DirectManipulationTest | ,
|  | TestGesture |
| ) |  |

Definition at line 141 of file direct_manipulation_unittests.cc.

141 {
142 MockIDirectManipulationContent content;
143 MockWindowBindingHandlerDelegate delegate;
144 MockIDirectManipulationViewport viewport;
145 const float scale = 1.5;
146 const float pan_x = 32.0;
147 const float pan_y = 16.0;
148 const int DISPLAY_WIDTH = 800;
149 const int DISPLAY_HEIGHT = 600;
150 auto owner = std::make_unique<DirectManipulationOwner>(nullptr);
151 owner->SetBindingHandlerDelegate(&delegate);
152 auto handler =
153 fml::MakeRefCounted<DirectManipulationEventHandler>(owner.get());
154 int32_t device_id = (int32_t)reinterpret_cast<int64_t>(handler.get());
155 EXPECT_CALL(viewport, GetPrimaryContent(_, _))
156 .WillOnce([&content](REFIID in, void** out) {
157 *out = &content;
158 return S_OK;
159 })
160 .RetiresOnSaturation();
161 EXPECT_CALL(content, GetContentTransform(_, 6))
162 .WillOnce([scale](float* transform, DWORD size) {
163 transform[0] = 1.0f;
164 transform[4] = 0.0;
165 transform[5] = 0.0;
166 return S_OK;
167 })
168 .RetiresOnSaturation();
169 EXPECT_CALL(delegate, OnPointerPanZoomStart(device_id));
170 handler->OnViewportStatusChanged((IDirectManipulationViewport*)&viewport,
171 DIRECTMANIPULATION_RUNNING,
172 DIRECTMANIPULATION_READY);
173 EXPECT_CALL(content, GetContentTransform(_, 6))
174 .WillOnce([scale, pan_x, pan_y](float* transform, DWORD size) {
175 transform[0] = scale;
176 transform[4] = pan_x;
177 transform[5] = pan_y;
178 return S_OK;
179 });
180 EXPECT_CALL(delegate,
181 OnPointerPanZoomUpdate(device_id, pan_x, pan_y, scale, 0));
182 handler->OnContentUpdated((IDirectManipulationViewport*)&viewport,
183 (IDirectManipulationContent*)&content);
184 EXPECT_CALL(delegate, OnPointerPanZoomEnd(device_id));
185 EXPECT_CALL(viewport, GetViewportRect(_))
186 .WillOnce([DISPLAY_WIDTH, DISPLAY_HEIGHT](RECT* rect) {
187 rect->left = 0;
188 rect->top = 0;
189 rect->right = DISPLAY_WIDTH;
190 rect->bottom = DISPLAY_HEIGHT;
191 return S_OK;
192 });
193 EXPECT_CALL(viewport, ZoomToRect(0, 0, DISPLAY_WIDTH, DISPLAY_HEIGHT, false))
194 .WillOnce(::testing::Return(S_OK));
195 handler->OnViewportStatusChanged((IDirectManipulationViewport*)&viewport,
196 DIRECTMANIPULATION_INERTIA,
197 DIRECTMANIPULATION_RUNNING);
198 handler->OnViewportStatusChanged((IDirectManipulationViewport*)&viewport,
199 DIRECTMANIPULATION_READY,
200 DIRECTMANIPULATION_INERTIA);
201 }
content
union flutter::testing::@100::KeyboardChange::@0 content

References content.

## ◆ TEST() [35/171]

flutter::testing::TEST | ( | DirectManipulationTest | ,
|  | TestGestureWithInitialData |
| ) |  |

Definition at line 393 of file direct_manipulation_unittests.cc.

393 {
394 MockIDirectManipulationContent content;
395 MockWindowBindingHandlerDelegate delegate;
396 MockIDirectManipulationViewport viewport;
397 const float scale = 1.5;
398 const float pan_x = 32.0;
399 const float pan_y = 16.0;
400 const int DISPLAY_WIDTH = 800;
401 const int DISPLAY_HEIGHT = 600;
402 auto owner = std::make_unique<DirectManipulationOwner>(nullptr);
403 owner->SetBindingHandlerDelegate(&delegate);
404 auto handler =
405 fml::MakeRefCounted<DirectManipulationEventHandler>(owner.get());
406 int32_t device_id = (int32_t)reinterpret_cast<int64_t>(handler.get());
407 EXPECT_CALL(viewport, GetPrimaryContent(_, _))
408 .WillOnce([&content](REFIID in, void** out) {
409 *out = &content;
410 return S_OK;
411 })
412 .RetiresOnSaturation();
413 EXPECT_CALL(content, GetContentTransform(_, 6))
414 .WillOnce([scale](float* transform, DWORD size) {
415 transform[0] = 2.0f;
416 transform[4] = 234.0;
417 transform[5] = 345.0;
418 return S_OK;
419 })
420 .RetiresOnSaturation();
421 EXPECT_CALL(delegate, OnPointerPanZoomStart(device_id));
422 handler->OnViewportStatusChanged((IDirectManipulationViewport*)&viewport,
423 DIRECTMANIPULATION_RUNNING,
424 DIRECTMANIPULATION_READY);
425 EXPECT_CALL(content, GetContentTransform(_, 6))
426 .WillOnce([scale, pan_x, pan_y](float* transform, DWORD size) {
427 transform[0] = 2.0f * scale;
428 transform[4] = 234.0 + pan_x;
429 transform[5] = 345.0 + pan_y;
430 return S_OK;
431 });
432 EXPECT_CALL(delegate,
433 OnPointerPanZoomUpdate(device_id, pan_x, pan_y, scale, 0));
434 handler->OnContentUpdated((IDirectManipulationViewport*)&viewport,
435 (IDirectManipulationContent*)&content);
436 EXPECT_CALL(delegate, OnPointerPanZoomEnd(device_id));
437 EXPECT_CALL(viewport, GetViewportRect(_))
438 .WillOnce([DISPLAY_WIDTH, DISPLAY_HEIGHT](RECT* rect) {
439 rect->left = 0;
440 rect->top = 0;
441 rect->right = DISPLAY_WIDTH;
442 rect->bottom = DISPLAY_HEIGHT;
443 return S_OK;
444 });
445 EXPECT_CALL(viewport, ZoomToRect(0, 0, DISPLAY_WIDTH, DISPLAY_HEIGHT, false))
446 .WillOnce(::testing::Return(S_OK));
447 handler->OnViewportStatusChanged((IDirectManipulationViewport*)&viewport,
448 DIRECTMANIPULATION_INERTIA,
449 DIRECTMANIPULATION_RUNNING);
450 handler->OnViewportStatusChanged((IDirectManipulationViewport*)&viewport,
451 DIRECTMANIPULATION_READY,
452 DIRECTMANIPULATION_INERTIA);
453 }

References content.

## ◆ TEST() [36/171]

flutter::testing::TEST | ( | DirectManipulationTest | ,
|  | TestInertiaCamcelNotSentAtInertiaEnd |
| ) |  |

Definition at line 339 of file direct_manipulation_unittests.cc.

339 {
340 MockIDirectManipulationContent content;
341 MockWindowBindingHandlerDelegate delegate;
342 MockIDirectManipulationViewport viewport;
343 const int DISPLAY_WIDTH = 800;
344 const int DISPLAY_HEIGHT = 600;
345 auto owner = std::make_unique<DirectManipulationOwner>(nullptr);
346 owner->SetBindingHandlerDelegate(&delegate);
347 auto handler =
348 fml::MakeRefCounted<DirectManipulationEventHandler>(owner.get());
349 int32_t device_id = (int32_t)reinterpret_cast<int64_t>(handler.get());
350 // No need to mock the actual gesture, just start at the end.
351 EXPECT_CALL(viewport, GetViewportRect(_))
352 .WillOnce([DISPLAY_WIDTH, DISPLAY_HEIGHT](RECT* rect) {
353 rect->left = 0;
354 rect->top = 0;
355 rect->right = DISPLAY_WIDTH;
356 rect->bottom = DISPLAY_HEIGHT;
357 return S_OK;
358 });
359 EXPECT_CALL(viewport, ZoomToRect(0, 0, DISPLAY_WIDTH, DISPLAY_HEIGHT, false))
360 .WillOnce(::testing::Return(S_OK));
361 EXPECT_CALL(delegate, OnPointerPanZoomEnd(device_id));
362 handler->OnViewportStatusChanged((IDirectManipulationViewport*)&viewport,
363 DIRECTMANIPULATION_INERTIA,
364 DIRECTMANIPULATION_RUNNING);
365 // Have no change in pan between events.
366 EXPECT_CALL(content, GetContentTransform(_, 6))
367 .WillOnce([](float* transform, DWORD size) {
368 transform[0] = 1;
369 transform[4] = 0;
370 transform[5] = 140;
371 return S_OK;
372 });
373 handler->OnContentUpdated((IDirectManipulationViewport*)&viewport,
374 (IDirectManipulationContent*)&content);
375 EXPECT_CALL(content, GetContentTransform(_, 6))
376 .WillOnce([](float* transform, DWORD size) {
377 transform[0] = 1;
378 transform[4] = 0;
379 transform[5] = 140;
380 return S_OK;
381 });
382 handler->OnContentUpdated((IDirectManipulationViewport*)&viewport,
383 (IDirectManipulationContent*)&content);
384 // OnScrollInertiaCancel should not be called.
385 EXPECT_CALL(delegate, OnScrollInertiaCancel(device_id)).Times(0);
386 handler->OnViewportStatusChanged((IDirectManipulationViewport*)&viewport,
387 DIRECTMANIPULATION_READY,
388 DIRECTMANIPULATION_INERTIA);
389 }

References content.

## ◆ TEST() [37/171]

flutter::testing::TEST | ( | DirectManipulationTest | ,
|  | TestInertiaCancelSentForUserCancel |
| ) |  |

Definition at line 286 of file direct_manipulation_unittests.cc.

286 {
287 MockIDirectManipulationContent content;
288 MockWindowBindingHandlerDelegate delegate;
289 MockIDirectManipulationViewport viewport;
290 const int DISPLAY_WIDTH = 800;
291 const int DISPLAY_HEIGHT = 600;
292 auto owner = std::make_unique<DirectManipulationOwner>(nullptr);
293 owner->SetBindingHandlerDelegate(&delegate);
294 auto handler =
295 fml::MakeRefCounted<DirectManipulationEventHandler>(owner.get());
296 int32_t device_id = (int32_t)reinterpret_cast<int64_t>(handler.get());
297 // No need to mock the actual gesture, just start at the end.
298 EXPECT_CALL(viewport, GetViewportRect(_))
299 .WillOnce([DISPLAY_WIDTH, DISPLAY_HEIGHT](RECT* rect) {
300 rect->left = 0;
301 rect->top = 0;
302 rect->right = DISPLAY_WIDTH;
303 rect->bottom = DISPLAY_HEIGHT;
304 return S_OK;
305 });
306 EXPECT_CALL(viewport, ZoomToRect(0, 0, DISPLAY_WIDTH, DISPLAY_HEIGHT, false))
307 .WillOnce(::testing::Return(S_OK));
308 EXPECT_CALL(delegate, OnPointerPanZoomEnd(device_id));
309 handler->OnViewportStatusChanged((IDirectManipulationViewport*)&viewport,
310 DIRECTMANIPULATION_INERTIA,
311 DIRECTMANIPULATION_RUNNING);
312 // Have pan_y change by 10 between inertia updates.
313 EXPECT_CALL(content, GetContentTransform(_, 6))
314 .WillOnce([](float* transform, DWORD size) {
315 transform[0] = 1;
316 transform[4] = 0;
317 transform[5] = 100;
318 return S_OK;
319 });
320 handler->OnContentUpdated((IDirectManipulationViewport*)&viewport,
321 (IDirectManipulationContent*)&content);
322 EXPECT_CALL(content, GetContentTransform(_, 6))
323 .WillOnce([](float* transform, DWORD size) {
324 transform[0] = 1;
325 transform[4] = 0;
326 transform[5] = 110;
327 return S_OK;
328 });
329 handler->OnContentUpdated((IDirectManipulationViewport*)&viewport,
330 (IDirectManipulationContent*)&content);
331 // This looks like an interruption in the middle of synthetic inertia because
332 // of user input.
333 EXPECT_CALL(delegate, OnScrollInertiaCancel(device_id));
334 handler->OnViewportStatusChanged((IDirectManipulationViewport*)&viewport,
335 DIRECTMANIPULATION_READY,
336 DIRECTMANIPULATION_INERTIA);
337 }

References content.

## ◆ TEST() [38/171]

flutter::testing::TEST | ( | DirectManipulationTest | ,
|  | TestRounding |
| ) |  |

Definition at line 204 of file direct_manipulation_unittests.cc.

204 {
205 MockIDirectManipulationContent content;
206 MockWindowBindingHandlerDelegate delegate;
207 MockIDirectManipulationViewport viewport;
208 const float scale = 1.5;
209 const int DISPLAY_WIDTH = 800;
210 const int DISPLAY_HEIGHT = 600;
211 auto owner = std::make_unique<DirectManipulationOwner>(nullptr);
212 owner->SetBindingHandlerDelegate(&delegate);
213 auto handler =
214 fml::MakeRefCounted<DirectManipulationEventHandler>(owner.get());
215 int32_t device_id = (int32_t)reinterpret_cast<int64_t>(handler.get());
216 EXPECT_CALL(viewport, GetPrimaryContent(_, _))
217 .WillOnce([&content](REFIID in, void** out) {
218 *out = &content;
219 return S_OK;
220 })
221 .RetiresOnSaturation();
222 EXPECT_CALL(content, GetContentTransform(_, 6))
223 .WillOnce([scale](float* transform, DWORD size) {
224 transform[0] = 1.0f;
225 transform[4] = 0.0;
226 transform[5] = 0.0;
227 return S_OK;
228 })
229 .RetiresOnSaturation();
230 EXPECT_CALL(delegate, OnPointerPanZoomStart(device_id));
231 handler->OnViewportStatusChanged((IDirectManipulationViewport*)&viewport,
232 DIRECTMANIPULATION_RUNNING,
233 DIRECTMANIPULATION_READY);
234 EXPECT_CALL(content, GetContentTransform(_, 6))
235 .WillOnce([scale](float* transform, DWORD size) {
236 transform[0] = 1.5000001f;
237 transform[4] = 4.0;
238 transform[5] = 0.0;
239 return S_OK;
240 })
241 .RetiresOnSaturation();
242 EXPECT_CALL(delegate,
243 OnPointerPanZoomUpdate(device_id, 4.0, 0, 1.5000001f, 0))
244 .Times(0);
245 EXPECT_CALL(delegate, OnPointerPanZoomUpdate(device_id, 4.0, 0, 1.5f, 0))
246 .Times(1)
247 .RetiresOnSaturation();
248 EXPECT_CALL(content, GetContentTransform(_, 6))
249 .WillOnce([scale](float* transform, DWORD size) {
250 transform[0] = 1.50000065f;
251 transform[4] = 2.0;
252 transform[5] = 0.0;
253 return S_OK;
254 })
255 .RetiresOnSaturation();
256 EXPECT_CALL(delegate,
257 OnPointerPanZoomUpdate(device_id, 2.0, 0, 1.50000065f, 0))
258 .Times(0);
259 EXPECT_CALL(delegate,
260 OnPointerPanZoomUpdate(device_id, 2.0, 0, 1.50000047f, 0))
261 .Times(1)
262 .RetiresOnSaturation();
263 EXPECT_CALL(delegate, OnPointerPanZoomEnd(device_id));
264 EXPECT_CALL(viewport, GetViewportRect(_))
265 .WillOnce([DISPLAY_WIDTH, DISPLAY_HEIGHT](RECT* rect) {
266 rect->left = 0;
267 rect->top = 0;
268 rect->right = DISPLAY_WIDTH;
269 rect->bottom = DISPLAY_HEIGHT;
270 return S_OK;
271 });
272 EXPECT_CALL(viewport, ZoomToRect(0, 0, DISPLAY_WIDTH, DISPLAY_HEIGHT, false))
273 .WillOnce(::testing::Return(S_OK));
274 handler->OnContentUpdated((IDirectManipulationViewport*)&viewport,
275 (IDirectManipulationContent*)&content);
276 handler->OnContentUpdated((IDirectManipulationViewport*)&viewport,
277 (IDirectManipulationContent*)&content);
278 handler->OnViewportStatusChanged((IDirectManipulationViewport*)&viewport,
279 DIRECTMANIPULATION_INERTIA,
280 DIRECTMANIPULATION_RUNNING);
281 handler->OnViewportStatusChanged((IDirectManipulationViewport*)&viewport,
282 DIRECTMANIPULATION_READY,
283 DIRECTMANIPULATION_INERTIA);
284 }

References content.

## ◆ TEST() [39/171]

flutter::testing::TEST | ( | DpiUtilsTest | ,
|  | NonZero |
| ) |  |

Definition at line 13 of file dpi_utils_unittests.cc.

13 {
14 ASSERT_GT(GetDpiForHWND(nullptr), 0);
15 ASSERT_GT(GetDpiForMonitor(nullptr), 0);
16 };
flutter::GetDpiForHWND
UINT GetDpiForHWND(HWND hwnd)
Definition: dpi_utils.cc:128
flutter::GetDpiForMonitor
UINT GetDpiForMonitor(HMONITOR monitor)
Definition: dpi_utils.cc:132

References flutter::GetDpiForHWND(), and flutter::GetDpiForMonitor().

## ◆ TEST() [40/171]

flutter::testing::TEST | ( | DpiUtilsTest | ,
|  | NullHwndUsesPrimaryMonitor |
| ) |  |

Definition at line 18 of file dpi_utils_unittests.cc.

18 {
19 const POINT target_point = {0, 0};
20 HMONITOR monitor = MonitorFromPoint(target_point, MONITOR_DEFAULTTOPRIMARY);
21 ASSERT_EQ(GetDpiForHWND(nullptr), GetDpiForMonitor(monitor));
22 };

References flutter::GetDpiForHWND(), and flutter::GetDpiForMonitor().

## ◆ TEST() [41/171]

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

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

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

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

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

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

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

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

flutter::testing::TEST | ( | FlutterProjectBundle | ,
|  | BasicPropertiesAbsolutePaths |
| ) |  |

Definition at line 11 of file flutter_project_bundle_unittests.cc.

11 {
12 FlutterDesktopEngineProperties properties = {};
13 properties.assets_path = L"C:\\foo\\flutter_assets";
14 properties.icu_data_path = L"C:\\foo\\icudtl.dat";
15
16 FlutterProjectBundle project(properties);
17
18 EXPECT_TRUE(project.HasValidPaths());
19 EXPECT_EQ(project.assets_path().string(), "C:\\foo\\flutter_assets");
20 EXPECT_EQ(project.icu_path().string(), "C:\\foo\\icudtl.dat");
21 }
FlutterDesktopEngineProperties
Definition: flutter_windows.h:75
FlutterDesktopEngineProperties::icu_data_path
const wchar_t * icu_data_path
Definition: flutter_windows.h:84
FlutterDesktopEngineProperties::assets_path
const wchar_t * assets_path
Definition: flutter_windows.h:79

References flutter::FlutterProjectBundle::assets_path(), FlutterDesktopEngineProperties::assets_path, flutter::FlutterProjectBundle::HasValidPaths(), FlutterDesktopEngineProperties::icu_data_path, and flutter::FlutterProjectBundle::icu_path().

## ◆ TEST() [50/171]

flutter::testing::TEST | ( | FlutterProjectBundle | ,
|  | BasicPropertiesRelativePaths |
| ) |  |

Definition at line 23 of file flutter_project_bundle_unittests.cc.

23 {
24 FlutterDesktopEngineProperties properties = {};
25 properties.assets_path = L"foo\\flutter_assets";
26 properties.icu_data_path = L"foo\\icudtl.dat";
27
28 FlutterProjectBundle project(properties);
29
30 EXPECT_TRUE(project.HasValidPaths());
31 EXPECT_TRUE(project.assets_path().is_absolute());
32 EXPECT_EQ(project.assets_path().filename().string(), "flutter_assets");
33 EXPECT_TRUE(project.icu_path().is_absolute());
34 EXPECT_EQ(project.icu_path().filename().string(), "icudtl.dat");
35 }

References flutter::FlutterProjectBundle::assets_path(), FlutterDesktopEngineProperties::assets_path, flutter::FlutterProjectBundle::HasValidPaths(), FlutterDesktopEngineProperties::icu_data_path, and flutter::FlutterProjectBundle::icu_path().

## ◆ TEST() [51/171]

flutter::testing::TEST | ( | FlutterProjectBundle | ,
|  | DartEntrypointArguments |
| ) |  |

Definition at line 50 of file flutter_project_bundle_unittests.cc.

50 {
51 FlutterDesktopEngineProperties properties = {};
52 properties.assets_path = L"foo\\flutter_assets";
53 properties.icu_data_path = L"foo\\icudtl.dat";
54
55 std::vector<const char*> test_arguments = {"arg1", "arg2"};
56 properties.dart_entrypoint_argc = test_arguments.size();
57 properties.dart_entrypoint_argv = test_arguments.data();
58
59 FlutterProjectBundle project(properties);
60
61 std::vector<std::string> retrieved_arguments =
62 project.dart_entrypoint_arguments();
63 EXPECT_EQ(retrieved_arguments.size(), 2U);
64 EXPECT_EQ(retrieved_arguments[0], "arg1");
65 EXPECT_EQ(retrieved_arguments[1], "arg2");
66 }
FlutterDesktopEngineProperties::dart_entrypoint_argc
int dart_entrypoint_argc
Definition: flutter_windows.h:101
FlutterDesktopEngineProperties::dart_entrypoint_argv
const char ** dart_entrypoint_argv
Definition: flutter_windows.h:105

References FlutterDesktopEngineProperties::assets_path, FlutterDesktopEngineProperties::dart_entrypoint_argc, flutter::FlutterProjectBundle::dart_entrypoint_arguments(), FlutterDesktopEngineProperties::dart_entrypoint_argv, and FlutterDesktopEngineProperties::icu_data_path.

## ◆ TEST() [52/171]

flutter::testing::TEST | ( | FlutterProjectBundle | ,
|  | Switches |
| ) |  |

Definition at line 69 of file flutter_project_bundle_unittests.cc.

69 {
70 FlutterDesktopEngineProperties properties = {};
71 properties.assets_path = L"foo\\flutter_assets";
72 properties.icu_data_path = L"foo\\icudtl.dat";
73
74 _putenv_s("FLUTTER_ENGINE_SWITCHES", "2");
75 _putenv_s("FLUTTER_ENGINE_SWITCH_1", "abc");
76 _putenv_s("FLUTTER_ENGINE_SWITCH_2", "foo=\"bar, baz\"");
77
78 FlutterProjectBundle project(properties);
79
80 std::vector<std::string> switches = project.GetSwitches();
81 EXPECT_EQ(switches.size(), 2);
82 EXPECT_EQ(switches[0], "--abc");
83 EXPECT_EQ(switches[1], "--foo=\"bar, baz\"");
84 }

References FlutterDesktopEngineProperties::assets_path, flutter::FlutterProjectBundle::GetSwitches(), and FlutterDesktopEngineProperties::icu_data_path.

## ◆ TEST() [53/171]

flutter::testing::TEST | ( | FlutterProjectBundle | ,
|  | SwitchesEmpty |
| ) |  |

Definition at line 37 of file flutter_project_bundle_unittests.cc.

37 {
38 FlutterDesktopEngineProperties properties = {};
39 properties.assets_path = L"foo\\flutter_assets";
40 properties.icu_data_path = L"foo\\icudtl.dat";
41
42 // Clear the main environment variable, since test order is not guaranteed.
43 _putenv_s("FLUTTER_ENGINE_SWITCHES", "");
44
45 FlutterProjectBundle project(properties);
46
47 EXPECT_EQ(project.GetSwitches().size(), 0);
48 }

References FlutterDesktopEngineProperties::assets_path, flutter::FlutterProjectBundle::GetSwitches(), and FlutterDesktopEngineProperties::icu_data_path.

## ◆ TEST() [54/171]

flutter::testing::TEST | ( | FlutterWindowsTextureRegistrarTest | ,
|  | CreateDestroy |
| ) |  |

Definition at line 67 of file flutter_windows_texture_registrar_unittests.cc.

67 {
68 std::unique_ptr<FlutterWindowsEngine> engine = GetTestEngine();
69 auto gl = std::make_shared<egl::MockProcTable>();
70 FlutterWindowsTextureRegistrar registrar(engine.get(), gl);
71
72 EXPECT_TRUE(true);
73 }

## ◆ TEST() [55/171]

flutter::testing::TEST | ( | FlutterWindowsTextureRegistrarTest | ,
|  | PopulateD3dTexture |
| ) |  |

Definition at line 267 of file flutter_windows_texture_registrar_unittests.cc.

267 {
268 std::unique_ptr<FlutterWindowsEngine> engine = GetTestEngine();
269 auto gl = std::make_shared<egl::MockProcTable>();
270 FlutterWindowsTextureRegistrar registrar(engine.get(), gl);
271
272 UINT width = 100;
273 UINT height = 100;
274 auto d3d_texture = CreateD3dTexture(engine.get(), width, height);
275 EXPECT_TRUE(d3d_texture);
276
277 bool release_callback_called = false;
278 FlutterDesktopGpuSurfaceDescriptor surface_descriptor = {};
279 surface_descriptor.struct_size = sizeof(FlutterDesktopGpuSurfaceDescriptor);
280 surface_descriptor.handle = d3d_texture.Get();
281 surface_descriptor.width = surface_descriptor.visible_width = width;
282 surface_descriptor.height = surface_descriptor.visible_height = height;
283 surface_descriptor.release_context = &release_callback_called;
284 surface_descriptor.release_callback = [](void* release_context) {
285 bool* called = reinterpret_cast<bool*>(release_context);
286 *called = true;
287 };
288
289 FlutterDesktopTextureInfo texture_info = {};
290 texture_info.type = kFlutterDesktopGpuSurfaceTexture;
291 texture_info.gpu_surface_config.struct_size =
292 sizeof(FlutterDesktopGpuSurfaceTextureConfig);
293 texture_info.gpu_surface_config.type =
294 kFlutterDesktopGpuSurfaceTypeD3d11Texture2D;
295 texture_info.gpu_surface_config.user_data = &surface_descriptor;
296 texture_info.gpu_surface_config.callback =
297 [](size_t width, size_t height,
298 void* user_data) -> const FlutterDesktopGpuSurfaceDescriptor* {
299 return reinterpret_cast<const FlutterDesktopGpuSurfaceDescriptor*>(
300 user_data);
301 };
302
303 FlutterOpenGLTexture flutter_texture = {};
304 auto texture_id = registrar.RegisterTexture(&texture_info);
305 EXPECT_NE(texture_id, -1);
306
307 EXPECT_CALL(*gl.get(), GenTextures(1, _))
308 .Times(1)
309 .WillOnce([](GLsizei n, GLuint* textures) { textures[0] = 1; });
310 EXPECT_CALL(*gl.get(), BindTexture).Times(1);
311 EXPECT_CALL(*gl.get(), TexParameteri).Times(AtLeast(1));
312 EXPECT_CALL(*gl.get(), DeleteTextures(1, _)).Times(1);
313
314 auto result =
315 registrar.PopulateTexture(texture_id, 640, 480, &flutter_texture);
316 EXPECT_TRUE(result);
317 EXPECT_EQ(flutter_texture.width, width);
318 EXPECT_EQ(flutter_texture.height, height);
319 EXPECT_EQ(flutter_texture.target, GL_TEXTURE_2D);
320 EXPECT_TRUE(release_callback_called);
321 }
texture_id
uint32_t texture_id
Definition: compositor_opengl.cc:20
kFlutterDesktopGpuSurfaceTypeD3d11Texture2D
@ kFlutterDesktopGpuSurfaceTypeD3d11Texture2D
Definition: flutter_texture_registrar.h:40
kFlutterDesktopGpuSurfaceTexture
@ kFlutterDesktopGpuSurfaceTexture
Definition: flutter_texture_registrar.h:28
user_data
void * user_data
Definition: flutter_windows_view_unittests.cc:53
FlutterDesktopGpuSurfaceDescriptor
Definition: flutter_texture_registrar.h:70
FlutterDesktopGpuSurfaceDescriptor::height
size_t height
Definition: flutter_texture_registrar.h:90
FlutterDesktopGpuSurfaceDescriptor::visible_height
size_t visible_height
Definition: flutter_texture_registrar.h:96
FlutterDesktopGpuSurfaceDescriptor::visible_width
size_t visible_width
Definition: flutter_texture_registrar.h:93
FlutterDesktopGpuSurfaceDescriptor::handle
void * handle
Definition: flutter_texture_registrar.h:86
FlutterDesktopGpuSurfaceDescriptor::release_context
void * release_context
Definition: flutter_texture_registrar.h:102
FlutterDesktopGpuSurfaceDescriptor::release_callback
void(* release_callback)(void *release_context)
Definition: flutter_texture_registrar.h:100
FlutterDesktopGpuSurfaceDescriptor::width
size_t width
Definition: flutter_texture_registrar.h:88
FlutterDesktopGpuSurfaceDescriptor::struct_size
size_t struct_size
Definition: flutter_texture_registrar.h:73
FlutterDesktopGpuSurfaceTextureConfig
Definition: flutter_texture_registrar.h:138
FlutterDesktopGpuSurfaceTextureConfig::callback
FlutterDesktopGpuSurfaceTextureCallback callback
Definition: flutter_texture_registrar.h:146
FlutterDesktopGpuSurfaceTextureConfig::type
FlutterDesktopGpuSurfaceType type
Definition: flutter_texture_registrar.h:144
FlutterDesktopGpuSurfaceTextureConfig::user_data
void * user_data
Definition: flutter_texture_registrar.h:148
FlutterDesktopGpuSurfaceTextureConfig::struct_size
size_t struct_size
Definition: flutter_texture_registrar.h:141
FlutterDesktopTextureInfo
Definition: flutter_texture_registrar.h:151
FlutterDesktopTextureInfo::gpu_surface_config
FlutterDesktopGpuSurfaceTextureConfig gpu_surface_config
Definition: flutter_texture_registrar.h:155
FlutterDesktopTextureInfo::type
FlutterDesktopTextureType type
Definition: flutter_texture_registrar.h:152

References FlutterDesktopGpuSurfaceTextureConfig::callback, FlutterDesktopTextureInfo::gpu_surface_config, FlutterDesktopGpuSurfaceDescriptor::handle, FlutterDesktopGpuSurfaceDescriptor::height, kFlutterDesktopGpuSurfaceTexture, kFlutterDesktopGpuSurfaceTypeD3d11Texture2D, flutter::FlutterWindowsTextureRegistrar::PopulateTexture(), flutter::FlutterWindowsTextureRegistrar::RegisterTexture(), FlutterDesktopGpuSurfaceDescriptor::release_callback, FlutterDesktopGpuSurfaceDescriptor::release_context, FlutterDesktopGpuSurfaceDescriptor::struct_size, FlutterDesktopGpuSurfaceTextureConfig::struct_size, texture_id, FlutterDesktopGpuSurfaceTextureConfig::type, FlutterDesktopTextureInfo::type, FlutterDesktopGpuSurfaceTextureConfig::user_data, user_data, FlutterDesktopGpuSurfaceDescriptor::visible_height, FlutterDesktopGpuSurfaceDescriptor::visible_width, and FlutterDesktopGpuSurfaceDescriptor::width.

## ◆ TEST() [56/171]

flutter::testing::TEST | ( | FlutterWindowsTextureRegistrarTest | ,
|  | PopulateD3dTextureWithHandle |
| ) |  |

Definition at line 205 of file flutter_windows_texture_registrar_unittests.cc.

205 {
206 std::unique_ptr<FlutterWindowsEngine> engine = GetTestEngine();
207 auto gl = std::make_shared<egl::MockProcTable>();
208 FlutterWindowsTextureRegistrar registrar(engine.get(), gl);
209
210 UINT width = 100;
211 UINT height = 100;
212 auto d3d_texture = CreateD3dTexture(engine.get(), width, height);
213 EXPECT_TRUE(d3d_texture);
214
215 ComPtr<IDXGIResource> shared_resource;
216 EXPECT_TRUE(SUCCEEDED(d3d_texture.As(&shared_resource)));
217
218 HANDLE shared_handle;
219 EXPECT_TRUE(SUCCEEDED(shared_resource->GetSharedHandle(&shared_handle)));
220
221 bool release_callback_called = false;
222 FlutterDesktopGpuSurfaceDescriptor surface_descriptor = {};
223 surface_descriptor.struct_size = sizeof(FlutterDesktopGpuSurfaceDescriptor);
224 surface_descriptor.handle = shared_handle;
225 surface_descriptor.width = surface_descriptor.visible_width = width;
226 surface_descriptor.height = surface_descriptor.visible_height = height;
227 surface_descriptor.release_context = &release_callback_called;
228 surface_descriptor.release_callback = [](void* release_context) {
229 bool* called = reinterpret_cast<bool*>(release_context);
230 *called = true;
231 };
232
233 FlutterDesktopTextureInfo texture_info = {};
234 texture_info.type = kFlutterDesktopGpuSurfaceTexture;
235 texture_info.gpu_surface_config.struct_size =
236 sizeof(FlutterDesktopGpuSurfaceTextureConfig);
237 texture_info.gpu_surface_config.type =
238 kFlutterDesktopGpuSurfaceTypeDxgiSharedHandle;
239 texture_info.gpu_surface_config.user_data = &surface_descriptor;
240 texture_info.gpu_surface_config.callback =
241 [](size_t width, size_t height,
242 void* user_data) -> const FlutterDesktopGpuSurfaceDescriptor* {
243 return reinterpret_cast<const FlutterDesktopGpuSurfaceDescriptor*>(
244 user_data);
245 };
246
247 FlutterOpenGLTexture flutter_texture = {};
248 auto texture_id = registrar.RegisterTexture(&texture_info);
249 EXPECT_NE(texture_id, -1);
250
251 EXPECT_CALL(*gl.get(), GenTextures(1, _))
252 .Times(1)
253 .WillOnce([](GLsizei n, GLuint* textures) { textures[0] = 1; });
254 EXPECT_CALL(*gl.get(), BindTexture).Times(1);
255 EXPECT_CALL(*gl.get(), TexParameteri).Times(AtLeast(1));
256 EXPECT_CALL(*gl.get(), DeleteTextures(1, _)).Times(1);
257
258 auto result =
259 registrar.PopulateTexture(texture_id, 640, 480, &flutter_texture);
260 EXPECT_TRUE(result);
261 EXPECT_EQ(flutter_texture.width, width);
262 EXPECT_EQ(flutter_texture.height, height);
263 EXPECT_EQ(flutter_texture.target, GL_TEXTURE_2D);
264 EXPECT_TRUE(release_callback_called);
265 }
kFlutterDesktopGpuSurfaceTypeDxgiSharedHandle
@ kFlutterDesktopGpuSurfaceTypeDxgiSharedHandle
Definition: flutter_texture_registrar.h:38

References FlutterDesktopGpuSurfaceTextureConfig::callback, FlutterDesktopTextureInfo::gpu_surface_config, FlutterDesktopGpuSurfaceDescriptor::handle, FlutterDesktopGpuSurfaceDescriptor::height, kFlutterDesktopGpuSurfaceTexture, kFlutterDesktopGpuSurfaceTypeDxgiSharedHandle, flutter::FlutterWindowsTextureRegistrar::PopulateTexture(), flutter::FlutterWindowsTextureRegistrar::RegisterTexture(), FlutterDesktopGpuSurfaceDescriptor::release_callback, FlutterDesktopGpuSurfaceDescriptor::release_context, FlutterDesktopGpuSurfaceDescriptor::struct_size, FlutterDesktopGpuSurfaceTextureConfig::struct_size, texture_id, FlutterDesktopGpuSurfaceTextureConfig::type, FlutterDesktopTextureInfo::type, FlutterDesktopGpuSurfaceTextureConfig::user_data, user_data, FlutterDesktopGpuSurfaceDescriptor::visible_height, FlutterDesktopGpuSurfaceDescriptor::visible_width, and FlutterDesktopGpuSurfaceDescriptor::width.

## ◆ TEST() [57/171]

flutter::testing::TEST | ( | FlutterWindowsTextureRegistrarTest | ,
|  | PopulateInvalidTexture |
| ) |  |

Definition at line 323 of file flutter_windows_texture_registrar_unittests.cc.

323 {
324 std::unique_ptr<FlutterWindowsEngine> engine = GetTestEngine();
325 auto gl = std::make_shared<egl::MockProcTable>();
326
327 FlutterWindowsTextureRegistrar registrar(engine.get(), gl);
328
329 auto result = registrar.PopulateTexture(1, 640, 480, nullptr);
330 EXPECT_FALSE(result);
331 }

References flutter::FlutterWindowsTextureRegistrar::PopulateTexture().

## ◆ TEST() [58/171]

flutter::testing::TEST | ( | FlutterWindowsTextureRegistrarTest | ,
|  | PopulatePixelBufferTexture |
| ) |  |

Definition at line 154 of file flutter_windows_texture_registrar_unittests.cc.

154 {
155 std::unique_ptr<FlutterWindowsEngine> engine = GetTestEngine();
156 auto gl = std::make_shared<egl::MockProcTable>();
157
158 FlutterWindowsTextureRegistrar registrar(engine.get(), gl);
159
160 bool release_callback_called = false;
161 size_t width = 100;
162 size_t height = 100;
163 std::unique_ptr<uint8_t[]> pixels =
164 std::make_unique<uint8_t[]>(width * height * 4);
165 FlutterDesktopPixelBuffer pixel_buffer = {};
166 pixel_buffer.width = width;
167 pixel_buffer.height = height;
168 pixel_buffer.buffer = pixels.get();
169 pixel_buffer.release_context = &release_callback_called;
170 pixel_buffer.release_callback = [](void* release_context) {
171 bool* called = reinterpret_cast<bool*>(release_context);
172 *called = true;
173 };
174
175 FlutterDesktopTextureInfo texture_info = {};
176 texture_info.type = kFlutterDesktopPixelBufferTexture;
177 texture_info.pixel_buffer_config.user_data = &pixel_buffer;
178 texture_info.pixel_buffer_config.callback =
179 [](size_t width, size_t height,
180 void* user_data) -> const FlutterDesktopPixelBuffer* {
181 return reinterpret_cast<const FlutterDesktopPixelBuffer*>(user_data);
182 };
183
184 FlutterOpenGLTexture flutter_texture = {};
185 auto texture_id = registrar.RegisterTexture(&texture_info);
186 EXPECT_NE(texture_id, -1);
187
188 EXPECT_CALL(*gl.get(), GenTextures(1, _))
189 .Times(1)
190 .WillOnce([](GLsizei n, GLuint* textures) { textures[0] = 1; });
191 EXPECT_CALL(*gl.get(), BindTexture).Times(1);
192 EXPECT_CALL(*gl.get(), TexParameteri).Times(AtLeast(1));
193 EXPECT_CALL(*gl.get(), TexImage2D).Times(1);
194 EXPECT_CALL(*gl.get(), DeleteTextures(1, _)).Times(1);
195
196 auto result =
197 registrar.PopulateTexture(texture_id, 640, 480, &flutter_texture);
198 EXPECT_TRUE(result);
199 EXPECT_EQ(flutter_texture.width, width);
200 EXPECT_EQ(flutter_texture.height, height);
201 EXPECT_EQ(flutter_texture.target, GL_TEXTURE_2D);
202 EXPECT_TRUE(release_callback_called);
203 }
kFlutterDesktopPixelBufferTexture
@ kFlutterDesktopPixelBufferTexture
Definition: flutter_texture_registrar.h:26
FlutterDesktopPixelBuffer
Definition: flutter_texture_registrar.h:56
FlutterDesktopPixelBuffer::width
size_t width
Definition: flutter_texture_registrar.h:60
FlutterDesktopPixelBuffer::release_callback
void(* release_callback)(void *release_context)
Definition: flutter_texture_registrar.h:64
FlutterDesktopPixelBuffer::buffer
const uint8_t * buffer
Definition: flutter_texture_registrar.h:58
FlutterDesktopPixelBuffer::release_context
void * release_context
Definition: flutter_texture_registrar.h:66
FlutterDesktopPixelBuffer::height
size_t height
Definition: flutter_texture_registrar.h:62
FlutterDesktopPixelBufferTextureConfig::user_data
void * user_data
Definition: flutter_texture_registrar.h:134
FlutterDesktopPixelBufferTextureConfig::callback
FlutterDesktopPixelBufferTextureCallback callback
Definition: flutter_texture_registrar.h:132
FlutterDesktopTextureInfo::pixel_buffer_config
FlutterDesktopPixelBufferTextureConfig pixel_buffer_config
Definition: flutter_texture_registrar.h:154

References FlutterDesktopPixelBuffer::buffer, FlutterDesktopPixelBufferTextureConfig::callback, FlutterDesktopPixelBuffer::height, kFlutterDesktopPixelBufferTexture, FlutterDesktopTextureInfo::pixel_buffer_config, flutter::FlutterWindowsTextureRegistrar::PopulateTexture(), flutter::FlutterWindowsTextureRegistrar::RegisterTexture(), FlutterDesktopPixelBuffer::release_callback, FlutterDesktopPixelBuffer::release_context, texture_id, FlutterDesktopTextureInfo::type, FlutterDesktopPixelBufferTextureConfig::user_data, user_data, and FlutterDesktopPixelBuffer::width.

## ◆ TEST() [59/171]

flutter::testing::TEST | ( | FlutterWindowsTextureRegistrarTest | ,
|  | RegisterUnknownTextureType |
| ) |  |

Definition at line 140 of file flutter_windows_texture_registrar_unittests.cc.

140 {
141 std::unique_ptr<FlutterWindowsEngine> engine = GetTestEngine();
142 auto gl = std::make_shared<egl::MockProcTable>();
143
144 FlutterWindowsTextureRegistrar registrar(engine.get(), gl);
145
146 FlutterDesktopTextureInfo texture_info = {};
147 texture_info.type = static_cast<FlutterDesktopTextureType>(1234);
148
149 auto texture_id = registrar.RegisterTexture(&texture_info);
150
151 EXPECT_EQ(texture_id, -1);
152 }
FlutterDesktopTextureType
FlutterDesktopTextureType
Definition: flutter_texture_registrar.h:24

References flutter::FlutterWindowsTextureRegistrar::RegisterTexture(), texture_id, and FlutterDesktopTextureInfo::type.

## ◆ TEST() [60/171]

flutter::testing::TEST | ( | FlutterWindowsTextureRegistrarTest | ,
|  | RegisterUnregisterTexture |
| ) |  |

Definition at line 75 of file flutter_windows_texture_registrar_unittests.cc.

75 {
76 std::unique_ptr<FlutterWindowsEngine> engine = GetTestEngine();
77 EngineModifier modifier(engine.get());
78 auto gl = std::make_shared<egl::MockProcTable>();
79
80 FlutterWindowsTextureRegistrar registrar(engine.get(), gl);
81
82 FlutterDesktopTextureInfo texture_info = {};
83 texture_info.type = kFlutterDesktopPixelBufferTexture;
84 texture_info.pixel_buffer_config.callback =
85 [](size_t width, size_t height,
86 void* user_data) -> const FlutterDesktopPixelBuffer* {
87 return nullptr;
88 };
89
90 int64_t registered_texture_id = 0;
91 bool register_called = false;
92 modifier.embedder_api().RegisterExternalTexture = MOCK_ENGINE_PROC(
93 RegisterExternalTexture, ([&register_called, &registered_texture_id](
94 auto engine, auto texture_id) {
95 register_called = true;
96 registered_texture_id = texture_id;
97 return kSuccess;
98 }));
99
100 bool unregister_called = false;
101 modifier.embedder_api().UnregisterExternalTexture = MOCK_ENGINE_PROC(
102 UnregisterExternalTexture, ([&unregister_called, &registered_texture_id](
103 auto engine, auto texture_id) {
104 unregister_called = true;
105 EXPECT_EQ(registered_texture_id, texture_id);
106 return kSuccess;
107 }));
108
109 bool mark_frame_available_called = false;
110 modifier.embedder_api().MarkExternalTextureFrameAvailable =
111 MOCK_ENGINE_PROC(MarkExternalTextureFrameAvailable,
112 ([&mark_frame_available_called, &registered_texture_id](
113 auto engine, auto texture_id) {
114 mark_frame_available_called = true;
115 EXPECT_EQ(registered_texture_id, texture_id);
116 return kSuccess;
117 }));
118
119 modifier.embedder_api().PostRenderThreadTask =
120 MOCK_ENGINE_PROC(PostRenderThreadTask,
121 [](auto engine, auto callback, void* callback_data) {
122 callback(callback_data);
123 return kSuccess;
124 });
125
126 auto texture_id = registrar.RegisterTexture(&texture_info);
127 EXPECT_TRUE(register_called);
128 EXPECT_NE(texture_id, -1);
129 EXPECT_EQ(texture_id, registered_texture_id);
130
131 EXPECT_TRUE(registrar.MarkTextureFrameAvailable(texture_id));
132 EXPECT_TRUE(mark_frame_available_called);
133
134 fml::AutoResetWaitableEvent latch;
135 registrar.UnregisterTexture(texture_id, [&]() { latch.Signal(); });
136 latch.Wait();
137 ASSERT_TRUE(unregister_called);
138 }
callback
FlutterDesktopBinaryReply callback
Definition: flutter_windows_view_unittests.cc:52

References FlutterDesktopPixelBufferTextureConfig::callback, callback, kFlutterDesktopPixelBufferTexture, flutter::FlutterWindowsTextureRegistrar::MarkTextureFrameAvailable(), FlutterDesktopTextureInfo::pixel_buffer_config, flutter::FlutterWindowsTextureRegistrar::RegisterTexture(), texture_id, FlutterDesktopTextureInfo::type, flutter::FlutterWindowsTextureRegistrar::UnregisterTexture(), and user_data.

## ◆ TEST() [61/171]

flutter::testing::TEST | ( | FlutterWindowsTextureRegistrarTest | ,
|  | UnregisterTextureWithEngineDownInvokesCallback |
| ) |  |

Definition at line 333 of file flutter_windows_texture_registrar_unittests.cc.

334 {
335 std::unique_ptr<FlutterWindowsEngine> engine = GetTestEngine();
336 auto gl = std::make_shared<egl::MockProcTable>();
337
338 FlutterWindowsTextureRegistrar registrar(engine.get(), gl);
339
340 fml::AutoResetWaitableEvent latch;
341 registrar.UnregisterTexture(1234, [&]() { latch.Signal(); });
342 latch.Wait();
343 }

References flutter::FlutterWindowsTextureRegistrar::UnregisterTexture().

## ◆ TEST() [62/171]

flutter::testing::TEST | ( | FlutterWindowsViewTest | ,
|  | AccessibilityHitTesting |
| ) |  |

Definition at line 803 of file flutter_windows_view_unittests.cc.

803 {
804 constexpr FlutterTransformation kIdentityTransform = {1, 0, 0, //
805 0, 1, 0, //
806 0, 0, 1};
807
808 std::unique_ptr<FlutterWindowsEngine> engine = GetTestEngine();
809 EngineModifier modifier(engine.get());
810 modifier.embedder_api().UpdateSemanticsEnabled =
811 [](FLUTTER_API_SYMBOL(FlutterEngine) engine, bool enabled) {
812 return kSuccess;
813 };
814
815 std::unique_ptr<FlutterWindowsView> view =
816 engine->CreateView(std::make_unique<NiceMock<MockWindowBindingHandler>>(),
817 /*is_sized_to_content=*/false, BoxConstraints());
818
819 // Enable semantics to instantiate accessibility bridge.
820 view->OnUpdateSemanticsEnabled(true);
821
822 auto bridge = view->accessibility_bridge().lock();
823 ASSERT_TRUE(bridge);
824
825 // Add root node at origin. Size 500x500.
826 FlutterSemanticsNode2 node0{sizeof(FlutterSemanticsNode2), 0};
827 auto empty_flags = FlutterSemanticsFlags{};
828 std::vector<int32_t> node0_children{1, 2};
829 node0.rect = {0, 0, 500, 500};
830 node0.transform = kIdentityTransform;
831 node0.child_count = node0_children.size();
832 node0.children_in_traversal_order = node0_children.data();
833 node0.children_in_hit_test_order = node0_children.data();
834 node0.flags2 = &empty_flags;
835
836 // Add node 1 located at 0,0 relative to node 0. Size 250x500.
837 FlutterSemanticsNode2 node1{sizeof(FlutterSemanticsNode2), 1};
838 node1.rect = {0, 0, 250, 500};
839 node1.transform = kIdentityTransform;
840 node1.label = "prefecture";
841 node1.value = "Kyoto";
842 node1.flags2 = &empty_flags;
843
844 // Add node 2 located at 250,0 relative to node 0. Size 250x500.
845 FlutterSemanticsNode2 node2{sizeof(FlutterSemanticsNode2), 2};
846 std::vector<int32_t> node2_children{3};
847 node2.rect = {0, 0, 250, 500};
848 node2.transform = {1, 0, 250, 0, 1, 0, 0, 0, 1};
849 node2.child_count = node2_children.size();
850 node2.children_in_traversal_order = node2_children.data();
851 node2.children_in_hit_test_order = node2_children.data();
852 node2.flags2 = &empty_flags;
853
854 // Add node 3 located at 0,250 relative to node 2. Size 250, 250.
855 FlutterSemanticsNode2 node3{sizeof(FlutterSemanticsNode2), 3};
856 node3.rect = {0, 0, 250, 250};
857 node3.transform = {1, 0, 0, 0, 1, 250, 0, 0, 1};
858 node3.label = "city";
859 node3.value = "Uji";
860 node3.flags2 = &empty_flags;
861
862 bridge->AddFlutterSemanticsNodeUpdate(node0);
863 bridge->AddFlutterSemanticsNodeUpdate(node1);
864 bridge->AddFlutterSemanticsNodeUpdate(node2);
865 bridge->AddFlutterSemanticsNodeUpdate(node3);
866 bridge->CommitUpdates();
867
868 // Look up the root windows node delegate.
869 auto node0_delegate = bridge->GetFlutterPlatformNodeDelegateFromID(0).lock();
870 ASSERT_TRUE(node0_delegate);
871 auto node1_delegate = bridge->GetFlutterPlatformNodeDelegateFromID(1).lock();
872 ASSERT_TRUE(node1_delegate);
873 auto node2_delegate = bridge->GetFlutterPlatformNodeDelegateFromID(2).lock();
874 ASSERT_TRUE(node2_delegate);
875 auto node3_delegate = bridge->GetFlutterPlatformNodeDelegateFromID(3).lock();
876 ASSERT_TRUE(node3_delegate);
877
878 // Get the native IAccessible root object.
879 IAccessible* node0_accessible = node0_delegate->GetNativeViewAccessible();
880 ASSERT_TRUE(node0_accessible != nullptr);
881
882 // Perform a hit test that should hit node 1.
883 VARIANT varchild{};
884 ASSERT_TRUE(SUCCEEDED(node0_accessible->accHitTest(150, 150, &varchild)));
885 EXPECT_EQ(varchild.vt, VT_DISPATCH);
886 EXPECT_EQ(varchild.pdispVal, node1_delegate->GetNativeViewAccessible());
887
888 // Perform a hit test that should hit node 2.
889 varchild = {};
890 ASSERT_TRUE(SUCCEEDED(node0_accessible->accHitTest(450, 150, &varchild)));
891 EXPECT_EQ(varchild.vt, VT_DISPATCH);
892 EXPECT_EQ(varchild.pdispVal, node2_delegate->GetNativeViewAccessible());
893
894 // Perform a hit test that should hit node 3.
895 varchild = {};
896 ASSERT_TRUE(SUCCEEDED(node0_accessible->accHitTest(450, 450, &varchild)));
897 EXPECT_EQ(varchild.vt, VT_DISPATCH);
898 EXPECT_EQ(varchild.pdispVal, node3_delegate->GetNativeViewAccessible());
899 }
flutter::AccessibilityMode::IAccessible
@ IAccessible

References flutter::IAccessible.

## ◆ TEST() [63/171]

flutter::testing::TEST | ( | FlutterWindowsViewTest | ,
|  | AddSemanticsNodeUpdate |
| ) |  |

Definition at line 370 of file flutter_windows_view_unittests.cc.

370 {
371 std::unique_ptr<FlutterWindowsEngine> engine = GetTestEngine();
372 EngineModifier modifier(engine.get());
373 modifier.embedder_api().UpdateSemanticsEnabled =
374 [](FLUTTER_API_SYMBOL(FlutterEngine) engine, bool enabled) {
375 return kSuccess;
376 };
377
378 auto window_binding_handler =
379 std::make_unique<NiceMock<MockWindowBindingHandler>>();
380 std::unique_ptr<FlutterWindowsView> view =
381 engine->CreateView(std::move(window_binding_handler),
382 /*is_sized_to_content=*/false, BoxConstraints());
383
384 // Enable semantics to instantiate accessibility bridge.
385 view->OnUpdateSemanticsEnabled(true);
386
387 auto bridge = view->accessibility_bridge().lock();
388 ASSERT_TRUE(bridge);
389
390 // Add root node.
391 FlutterSemanticsNode2 node{sizeof(FlutterSemanticsNode2), 0};
392 node.label = "name";
393 node.value = "value";
394 node.platform_view_id = -1;
395 auto flags = FlutterSemanticsFlags{};
396 node.flags2 = &flags;
397 bridge->AddFlutterSemanticsNodeUpdate(node);
398 bridge->CommitUpdates();
399
400 // Look up the root windows node delegate.
401 auto node_delegate = bridge->GetFlutterPlatformNodeDelegateFromID(0).lock();
402 ASSERT_TRUE(node_delegate);
403 EXPECT_EQ(node_delegate->GetChildCount(), 0);
404
405 // Get the native IAccessible object.
406 IAccessible* native_view = node_delegate->GetNativeViewAccessible();
407 ASSERT_TRUE(native_view != nullptr);
408
409 // Property lookups will be made against this node itself.
410 VARIANT varchild{};
411 varchild.vt = VT_I4;
412 varchild.lVal = CHILDID_SELF;
413
414 // Verify node name matches our label.
415 BSTR bname = nullptr;
416 ASSERT_EQ(native_view->get_accName(varchild, &bname), S_OK);
417 std::string name(_com_util::ConvertBSTRToString(bname));
418 EXPECT_EQ(name, "name");
419
420 // Verify node value matches.
421 BSTR bvalue = nullptr;
422 ASSERT_EQ(native_view->get_accValue(varchild, &bvalue), S_OK);
423 std::string value(_com_util::ConvertBSTRToString(bvalue));
424 EXPECT_EQ(value, "value");
425
426 // Verify node type is static text.
427 VARIANT varrole{};
428 varrole.vt = VT_I4;
429 ASSERT_EQ(native_view->get_accRole(varchild, &varrole), S_OK);
430 EXPECT_EQ(varrole.lVal, ROLE_SYSTEM_STATICTEXT);
431
432 // Get the IRawElementProviderFragment object.
433 IRawElementProviderSimple* uia_view;
434 native_view->QueryInterface(IID_PPV_ARGS(&uia_view));
435 ASSERT_TRUE(uia_view != nullptr);
436
437 // Verify name property matches our label.
438 VARIANT varname{};
439 ASSERT_EQ(uia_view->GetPropertyValue(UIA_NamePropertyId, &varname), S_OK);
440 EXPECT_EQ(varname.vt, VT_BSTR);
441 name = _com_util::ConvertBSTRToString(varname.bstrVal);
442 EXPECT_EQ(name, "name");
443
444 // Verify value property matches our label.
445 VARIANT varvalue{};
446 ASSERT_EQ(uia_view->GetPropertyValue(UIA_ValueValuePropertyId, &varvalue),
447 S_OK);
448 EXPECT_EQ(varvalue.vt, VT_BSTR);
449 value = _com_util::ConvertBSTRToString(varvalue.bstrVal);
450 EXPECT_EQ(value, "value");
451
452 // Verify node control type is text.
453 varrole = {};
454 ASSERT_EQ(uia_view->GetPropertyValue(UIA_ControlTypePropertyId, &varrole),
455 S_OK);
456 EXPECT_EQ(varrole.vt, VT_I4);
457 EXPECT_EQ(varrole.lVal, UIA_TextControlTypeId);
458 }
node_delegate
std::shared_ptr< FlutterPlatformNodeDelegateWindows > node_delegate
Definition: accessibility_bridge_windows_unittests.cc:33

References flutter::IAccessible, and node_delegate.

## ◆ TEST() [64/171]

flutter::testing::TEST | ( | FlutterWindowsViewTest | ,
|  | AddSemanticsNodeUpdateWithChildren |
| ) |  |

Definition at line 472 of file flutter_windows_view_unittests.cc.

472 {
473 std::unique_ptr<FlutterWindowsEngine> engine = GetTestEngine();
474 EngineModifier modifier(engine.get());
475 modifier.embedder_api().UpdateSemanticsEnabled =
476 [](FLUTTER_API_SYMBOL(FlutterEngine) engine, bool enabled) {
477 return kSuccess;
478 };
479
480 std::unique_ptr<FlutterWindowsView> view =
481 engine->CreateView(std::make_unique<NiceMock<MockWindowBindingHandler>>(),
482 /*is_sized_to_content=*/false, BoxConstraints());
483
484 // Enable semantics to instantiate accessibility bridge.
485 view->OnUpdateSemanticsEnabled(true);
486
487 auto bridge = view->accessibility_bridge().lock();
488 ASSERT_TRUE(bridge);
489
490 // Add root node.
491 FlutterSemanticsNode2 node0{sizeof(FlutterSemanticsNode2), 0};
492 std::vector<int32_t> node0_children{1, 2};
493 node0.child_count = node0_children.size();
494 node0.children_in_traversal_order = node0_children.data();
495 node0.children_in_hit_test_order = node0_children.data();
496 auto empty_flags = FlutterSemanticsFlags{};
497 node0.flags2 = &empty_flags;
498
499 FlutterSemanticsNode2 node1{sizeof(FlutterSemanticsNode2), 1};
500 node1.label = "prefecture";
501 node1.value = "Kyoto";
502 node1.flags2 = &empty_flags;
503 FlutterSemanticsNode2 node2{sizeof(FlutterSemanticsNode2), 2};
504 std::vector<int32_t> node2_children{3};
505 node2.child_count = node2_children.size();
506 node2.children_in_traversal_order = node2_children.data();
507 node2.children_in_hit_test_order = node2_children.data();
508 node2.flags2 = &empty_flags;
509 FlutterSemanticsNode2 node3{sizeof(FlutterSemanticsNode2), 3};
510 node3.label = "city";
511 node3.value = "Uji";
512 node3.flags2 = &empty_flags;
513
514 bridge->AddFlutterSemanticsNodeUpdate(node0);
515 bridge->AddFlutterSemanticsNodeUpdate(node1);
516 bridge->AddFlutterSemanticsNodeUpdate(node2);
517 bridge->AddFlutterSemanticsNodeUpdate(node3);
518 bridge->CommitUpdates();
519
520 // Look up the root windows node delegate.
521 auto node_delegate = bridge->GetFlutterPlatformNodeDelegateFromID(0).lock();
522 ASSERT_TRUE(node_delegate);
523 EXPECT_EQ(node_delegate->GetChildCount(), 2);
524
525 // Get the native IAccessible object.
526 IAccessible* node0_accessible = node_delegate->GetNativeViewAccessible();
527 ASSERT_TRUE(node0_accessible != nullptr);
528
529 // Property lookups will be made against this node itself.
530 VARIANT varchild{};
531 varchild.vt = VT_I4;
532 varchild.lVal = CHILDID_SELF;
533
534 // Verify node type is a group.
535 VARIANT varrole{};
536 varrole.vt = VT_I4;
537 ASSERT_EQ(node0_accessible->get_accRole(varchild, &varrole), S_OK);
538 EXPECT_EQ(varrole.lVal, ROLE_SYSTEM_GROUPING);
539
540 // Verify child count.
541 long node0_child_count = 0;
542 ASSERT_EQ(node0_accessible->get_accChildCount(&node0_child_count), S_OK);
543 EXPECT_EQ(node0_child_count, 2);
544
545 {
546 // Look up first child of node0 (node1), a static text node.
547 varchild.lVal = 1;
548 IDispatch* node1_dispatch = nullptr;
549 ASSERT_EQ(node0_accessible->get_accChild(varchild, &node1_dispatch), S_OK);
550 ASSERT_TRUE(node1_dispatch != nullptr);
551 IAccessible* node1_accessible = nullptr;
552 ASSERT_EQ(node1_dispatch->QueryInterface(
553 IID_IAccessible, reinterpret_cast<void**>(&node1_accessible)),
554 S_OK);
555 ASSERT_TRUE(node1_accessible != nullptr);
556
557 // Verify node name matches our label.
558 varchild.lVal = CHILDID_SELF;
559 BSTR bname = nullptr;
560 ASSERT_EQ(node1_accessible->get_accName(varchild, &bname), S_OK);
561 std::string name(_com_util::ConvertBSTRToString(bname));
562 EXPECT_EQ(name, "prefecture");
563
564 // Verify node value matches.
565 BSTR bvalue = nullptr;
566 ASSERT_EQ(node1_accessible->get_accValue(varchild, &bvalue), S_OK);
567 std::string value(_com_util::ConvertBSTRToString(bvalue));
568 EXPECT_EQ(value, "Kyoto");
569
570 // Verify node type is static text.
571 VARIANT varrole{};
572 varrole.vt = VT_I4;
573 ASSERT_EQ(node1_accessible->get_accRole(varchild, &varrole), S_OK);
574 EXPECT_EQ(varrole.lVal, ROLE_SYSTEM_STATICTEXT);
575
576 // Verify the parent node is the root.
577 IDispatch* parent_dispatch;
578 node1_accessible->get_accParent(&parent_dispatch);
579 IAccessible* parent_accessible;
580 ASSERT_EQ(
581 parent_dispatch->QueryInterface(
582 IID_IAccessible, reinterpret_cast<void**>(&parent_accessible)),
583 S_OK);
584 EXPECT_EQ(parent_accessible, node0_accessible);
585 }
586
587 // Look up second child of node0 (node2), a parent group for node3.
588 varchild.lVal = 2;
589 IDispatch* node2_dispatch = nullptr;
590 ASSERT_EQ(node0_accessible->get_accChild(varchild, &node2_dispatch), S_OK);
591 ASSERT_TRUE(node2_dispatch != nullptr);
592 IAccessible* node2_accessible = nullptr;
593 ASSERT_EQ(node2_dispatch->QueryInterface(
594 IID_IAccessible, reinterpret_cast<void**>(&node2_accessible)),
595 S_OK);
596 ASSERT_TRUE(node2_accessible != nullptr);
597
598 {
599 // Verify child count.
600 long node2_child_count = 0;
601 ASSERT_EQ(node2_accessible->get_accChildCount(&node2_child_count), S_OK);
602 EXPECT_EQ(node2_child_count, 1);
603
604 // Verify node type is static text.
605 varchild.lVal = CHILDID_SELF;
606 VARIANT varrole{};
607 varrole.vt = VT_I4;
608 ASSERT_EQ(node2_accessible->get_accRole(varchild, &varrole), S_OK);
609 EXPECT_EQ(varrole.lVal, ROLE_SYSTEM_GROUPING);
610
611 // Verify the parent node is the root.
612 IDispatch* parent_dispatch;
613 node2_accessible->get_accParent(&parent_dispatch);
614 IAccessible* parent_accessible;
615 ASSERT_EQ(
616 parent_dispatch->QueryInterface(
617 IID_IAccessible, reinterpret_cast<void**>(&parent_accessible)),
618 S_OK);
619 EXPECT_EQ(parent_accessible, node0_accessible);
620 }
621
622 {
623 // Look up only child of node2 (node3), a static text node.
624 varchild.lVal = 1;
625 IDispatch* node3_dispatch = nullptr;
626 ASSERT_EQ(node2_accessible->get_accChild(varchild, &node3_dispatch), S_OK);
627 ASSERT_TRUE(node3_dispatch != nullptr);
628 IAccessible* node3_accessible = nullptr;
629 ASSERT_EQ(node3_dispatch->QueryInterface(
630 IID_IAccessible, reinterpret_cast<void**>(&node3_accessible)),
631 S_OK);
632 ASSERT_TRUE(node3_accessible != nullptr);
633
634 // Verify node name matches our label.
635 varchild.lVal = CHILDID_SELF;
636 BSTR bname = nullptr;
637 ASSERT_EQ(node3_accessible->get_accName(varchild, &bname), S_OK);
638 std::string name(_com_util::ConvertBSTRToString(bname));
639 EXPECT_EQ(name, "city");
640
641 // Verify node value matches.
642 BSTR bvalue = nullptr;
643 ASSERT_EQ(node3_accessible->get_accValue(varchild, &bvalue), S_OK);
644 std::string value(_com_util::ConvertBSTRToString(bvalue));
645 EXPECT_EQ(value, "Uji");
646
647 // Verify node type is static text.
648 VARIANT varrole{};
649 varrole.vt = VT_I4;
650 ASSERT_EQ(node3_accessible->get_accRole(varchild, &varrole), S_OK);
651 EXPECT_EQ(varrole.lVal, ROLE_SYSTEM_STATICTEXT);
652
653 // Verify the parent node is node2.
654 IDispatch* parent_dispatch;
655 node3_accessible->get_accParent(&parent_dispatch);
656 IAccessible* parent_accessible;
657 ASSERT_EQ(
658 parent_dispatch->QueryInterface(
659 IID_IAccessible, reinterpret_cast<void**>(&parent_accessible)),
660 S_OK);
661 EXPECT_EQ(parent_accessible, node2_accessible);
662 }
663 }

References flutter::IAccessible, and node_delegate.

## ◆ TEST() [65/171]

flutter::testing::TEST | ( | FlutterWindowsViewTest | ,
|  | CheckboxNativeState |
| ) |  |

Definition at line 1168 of file flutter_windows_view_unittests.cc.

1168 {
1169 std::unique_ptr<FlutterWindowsEngine> engine = GetTestEngine();
1170 EngineModifier modifier(engine.get());
1171 modifier.embedder_api().UpdateSemanticsEnabled =
1172 [](FLUTTER_API_SYMBOL(FlutterEngine) engine, bool enabled) {
1173 return kSuccess;
1174 };
1175
1176 std::unique_ptr<FlutterWindowsView> view =
1177 engine->CreateView(std::make_unique<NiceMock<MockWindowBindingHandler>>(),
1178 /*is_sized_to_content=*/false, BoxConstraints());
1179
1180 // Enable semantics to instantiate accessibility bridge.
1181 view->OnUpdateSemanticsEnabled(true);
1182
1183 auto bridge = view->accessibility_bridge().lock();
1184 ASSERT_TRUE(bridge);
1185
1186 FlutterSemanticsNode2 root{sizeof(FlutterSemanticsNode2), 0};
1187 root.id = 0;
1188 root.label = "root";
1189 root.hint = "";
1190 root.value = "";
1191 root.increased_value = "";
1192 root.decreased_value = "";
1193 root.child_count = 0;
1194 root.custom_accessibility_actions_count = 0;
1195 auto flags = FlutterSemanticsFlags{
1196 .is_checked = FlutterCheckState::kFlutterCheckStateTrue,
1197 };
1198 root.flags2 = &flags;
1199 bridge->AddFlutterSemanticsNodeUpdate(root);
1200
1201 bridge->CommitUpdates();
1202
1203 {
1204 auto root_node = bridge->GetFlutterPlatformNodeDelegateFromID(0).lock();
1205 EXPECT_EQ(root_node->GetData().role, ax::mojom::Role::kCheckBox);
1206 EXPECT_EQ(root_node->GetData().GetCheckedState(),
1207 ax::mojom::CheckedState::kTrue);
1208
1209 // Get the IAccessible for the root node.
1210 IAccessible* native_view = root_node->GetNativeViewAccessible();
1211 ASSERT_TRUE(native_view != nullptr);
1212
1213 // Look up against the node itself (not one of its children).
1214 VARIANT varchild = {};
1215 varchild.vt = VT_I4;
1216
1217 // Verify the checkbox is checked.
1218 varchild.lVal = CHILDID_SELF;
1219 VARIANT native_state = {};
1220 ASSERT_TRUE(SUCCEEDED(native_view->get_accState(varchild, &native_state)));
1221 EXPECT_TRUE(native_state.lVal & STATE_SYSTEM_CHECKED);
1222
1223 // Perform similar tests for UIA value;
1224 IRawElementProviderSimple* uia_node;
1225 native_view->QueryInterface(IID_PPV_ARGS(&uia_node));
1226 ASSERT_TRUE(SUCCEEDED(uia_node->GetPropertyValue(
1227 UIA_ToggleToggleStatePropertyId, &native_state)));
1228 EXPECT_EQ(native_state.lVal, ToggleState_On);
1229
1230 ASSERT_TRUE(SUCCEEDED(uia_node->GetPropertyValue(
1231 UIA_AriaPropertiesPropertyId, &native_state)));
1232 EXPECT_NE(std::wcsstr(native_state.bstrVal, L"checked=true"), nullptr);
1233 }
1234
1235 // Test unchecked too.
1236 auto updated_flags = FlutterSemanticsFlags{
1237 .is_checked = FlutterCheckState::kFlutterCheckStateFalse,
1238 };
1239 root.flags2 = &updated_flags;
1240 bridge->AddFlutterSemanticsNodeUpdate(root);
1241 bridge->CommitUpdates();
1242
1243 {
1244 auto root_node = bridge->GetFlutterPlatformNodeDelegateFromID(0).lock();
1245 EXPECT_EQ(root_node->GetData().role, ax::mojom::Role::kCheckBox);
1246 EXPECT_EQ(root_node->GetData().GetCheckedState(),
1247 ax::mojom::CheckedState::kFalse);
1248
1249 // Get the IAccessible for the root node.
1250 IAccessible* native_view = root_node->GetNativeViewAccessible();
1251 ASSERT_TRUE(native_view != nullptr);
1252
1253 // Look up against the node itself (not one of its children).
1254 VARIANT varchild = {};
1255 varchild.vt = VT_I4;
1256
1257 // Verify the checkbox is unchecked.
1258 varchild.lVal = CHILDID_SELF;
1259 VARIANT native_state = {};
1260 ASSERT_TRUE(SUCCEEDED(native_view->get_accState(varchild, &native_state)));
1261 EXPECT_FALSE(native_state.lVal & STATE_SYSTEM_CHECKED);
1262
1263 // Perform similar tests for UIA value;
1264 IRawElementProviderSimple* uia_node;
1265 native_view->QueryInterface(IID_PPV_ARGS(&uia_node));
1266 ASSERT_TRUE(SUCCEEDED(uia_node->GetPropertyValue(
1267 UIA_ToggleToggleStatePropertyId, &native_state)));
1268 EXPECT_EQ(native_state.lVal, ToggleState_Off);
1269
1270 ASSERT_TRUE(SUCCEEDED(uia_node->GetPropertyValue(
1271 UIA_AriaPropertiesPropertyId, &native_state)));
1272 EXPECT_NE(std::wcsstr(native_state.bstrVal, L"checked=false"), nullptr);
1273 }
1274
1275 // Now check mixed state.
1276 auto updated_mixe_flags = FlutterSemanticsFlags{
1277 .is_checked = FlutterCheckState::kFlutterCheckStateMixed,
1278 };
1279 root.flags2 = &updated_mixe_flags;
1280 bridge->AddFlutterSemanticsNodeUpdate(root);
1281 bridge->CommitUpdates();
1282
1283 {
1284 auto root_node = bridge->GetFlutterPlatformNodeDelegateFromID(0).lock();
1285 EXPECT_EQ(root_node->GetData().role, ax::mojom::Role::kCheckBox);
1286 EXPECT_EQ(root_node->GetData().GetCheckedState(),
1287 ax::mojom::CheckedState::kMixed);
1288
1289 // Get the IAccessible for the root node.
1290 IAccessible* native_view = root_node->GetNativeViewAccessible();
1291 ASSERT_TRUE(native_view != nullptr);
1292
1293 // Look up against the node itself (not one of its children).
1294 VARIANT varchild = {};
1295 varchild.vt = VT_I4;
1296
1297 // Verify the checkbox is mixed.
1298 varchild.lVal = CHILDID_SELF;
1299 VARIANT native_state = {};
1300 ASSERT_TRUE(SUCCEEDED(native_view->get_accState(varchild, &native_state)));
1301 EXPECT_TRUE(native_state.lVal & STATE_SYSTEM_MIXED);
1302
1303 // Perform similar tests for UIA value;
1304 IRawElementProviderSimple* uia_node;
1305 native_view->QueryInterface(IID_PPV_ARGS(&uia_node));
1306 ASSERT_TRUE(SUCCEEDED(uia_node->GetPropertyValue(
1307 UIA_ToggleToggleStatePropertyId, &native_state)));
1308 EXPECT_EQ(native_state.lVal, ToggleState_Indeterminate);
1309
1310 ASSERT_TRUE(SUCCEEDED(uia_node->GetPropertyValue(
1311 UIA_AriaPropertiesPropertyId, &native_state)));
1312 EXPECT_NE(std::wcsstr(native_state.bstrVal, L"checked=mixed"), nullptr);
1313 }
1314 }

References flutter::IAccessible.

## ◆ TEST() [66/171]

flutter::testing::TEST | ( | FlutterWindowsViewTest | ,
|  | DisablesVSyncAfterStartup |
| ) |  |

Definition at line 1573 of file flutter_windows_view_unittests.cc.

1573 {
1574 auto windows_proc_table = std::make_shared<MockWindowsProcTable>();
1575 auto engine = std::make_unique<MockFlutterWindowsEngine>(windows_proc_table);
1576 auto egl_manager = std::make_unique<egl::MockManager>();
1577 egl::MockContext render_context;
1578 auto surface = std::make_unique<egl::MockWindowSurface>();
1579 auto surface_ptr = surface.get();
1580
1581 EXPECT_CALL(*engine.get(), running).WillRepeatedly(Return(true));
1582 EXPECT_CALL(*windows_proc_table.get(), DwmIsCompositionEnabled)
1583 .WillOnce(Return(true));
1584
1585 EXPECT_CALL(*egl_manager.get(), render_context)
1586 .WillOnce(Return(&render_context));
1587 EXPECT_CALL(*surface_ptr, IsValid).WillOnce(Return(true));
1588
1589 InSequence s;
1590 EXPECT_CALL(*egl_manager.get(), CreateWindowSurface)
1591 .WillOnce(Return(std::move(surface)));
1592 EXPECT_CALL(*engine.get(), PostRasterThreadTask)
1593 .WillOnce([](fml::closure callback) {
1594 callback();
1595 return true;
1596 });
1597 EXPECT_CALL(*surface_ptr, MakeCurrent).WillOnce(Return(true));
1598 EXPECT_CALL(*surface_ptr, SetVSyncEnabled(false)).WillOnce(Return(true));
1599 EXPECT_CALL(render_context, ClearCurrent).WillOnce(Return(true));
1600 EXPECT_CALL(*engine.get(), PostRasterThreadTask)
1601 .WillOnce([](fml::closure callback) {
1602 callback();
1603 return true;
1604 });
1605 EXPECT_CALL(*surface_ptr, Destroy).Times(1);
1606
1607 EngineModifier modifier{engine.get()};
1608 modifier.SetEGLManager(std::move(egl_manager));
1609
1610 std::unique_ptr<FlutterWindowsView> view =
1611 engine->CreateView(std::make_unique<NiceMock<MockWindowBindingHandler>>(),
1612 /*is_sized_to_content=*/false, BoxConstraints());
1613 }

References callback.

## ◆ TEST() [67/171]

flutter::testing::TEST | ( | FlutterWindowsViewTest | ,
|  | DisablesVSyncAtStartup |
| ) |  |

Definition at line 1500 of file flutter_windows_view_unittests.cc.

1500 {
1501 auto windows_proc_table = std::make_shared<MockWindowsProcTable>();
1502 auto engine = std::make_unique<MockFlutterWindowsEngine>(windows_proc_table);
1503 auto egl_manager = std::make_unique<egl::MockManager>();
1504 egl::MockContext render_context;
1505 auto surface = std::make_unique<egl::MockWindowSurface>();
1506 auto surface_ptr = surface.get();
1507
1508 EXPECT_CALL(*engine.get(), running).WillRepeatedly(Return(false));
1509 EXPECT_CALL(*engine.get(), PostRasterThreadTask).Times(0);
1510
1511 EXPECT_CALL(*windows_proc_table.get(), DwmIsCompositionEnabled)
1512 .WillOnce(Return(true));
1513
1514 EXPECT_CALL(*egl_manager.get(), render_context)
1515 .WillOnce(Return(&render_context));
1516 EXPECT_CALL(*surface_ptr, IsValid).WillOnce(Return(true));
1517
1518 InSequence s;
1519 EXPECT_CALL(*egl_manager.get(), CreateWindowSurface)
1520 .WillOnce(Return(std::move(surface)));
1521 EXPECT_CALL(*surface_ptr, MakeCurrent).WillOnce(Return(true));
1522 EXPECT_CALL(*surface_ptr, SetVSyncEnabled(false)).WillOnce(Return(true));
1523 EXPECT_CALL(render_context, ClearCurrent).WillOnce(Return(true));
1524
1525 EXPECT_CALL(*surface_ptr, Destroy).Times(1);
1526
1527 EngineModifier modifier{engine.get()};
1528 modifier.SetEGLManager(std::move(egl_manager));
1529
1530 std::unique_ptr<FlutterWindowsView> view =
1531 engine->CreateView(std::make_unique<NiceMock<MockWindowBindingHandler>>(),
1532 /*is_sized_to_content=*/false, BoxConstraints());
1533 }

## ◆ TEST() [68/171]

flutter::testing::TEST | ( | FlutterWindowsViewTest | ,
|  | EnableSemantics |
| ) |  |

Definition at line 347 of file flutter_windows_view_unittests.cc.

347 {
348 std::unique_ptr<FlutterWindowsEngine> engine = GetTestEngine();
349 EngineModifier modifier(engine.get());
350
351 bool semantics_enabled = false;
352 modifier.embedder_api().UpdateSemanticsEnabled = MOCK_ENGINE_PROC(
353 UpdateSemanticsEnabled,
354 [&semantics_enabled](FLUTTER_API_SYMBOL(FlutterEngine) engine,
355 bool enabled) {
356 semantics_enabled = enabled;
357 return kSuccess;
358 });
359
360 auto window_binding_handler =
361 std::make_unique<NiceMock<MockWindowBindingHandler>>();
362 std::unique_ptr<FlutterWindowsView> view =
363 engine->CreateView(std::move(window_binding_handler),
364 /*is_sized_to_content=*/false, BoxConstraints());
365
366 view->OnUpdateSemanticsEnabled(true);
367 EXPECT_TRUE(semantics_enabled);
368 }

## ◆ TEST() [69/171]

flutter::testing::TEST | ( | FlutterWindowsViewTest | ,
|  | EnablesVSyncAfterStartup |
| ) |  |

Definition at line 1617 of file flutter_windows_view_unittests.cc.

1617 {
1618 auto windows_proc_table = std::make_shared<MockWindowsProcTable>();
1619 auto engine = std::make_unique<MockFlutterWindowsEngine>(windows_proc_table);
1620 auto egl_manager = std::make_unique<egl::MockManager>();
1621 egl::MockContext render_context;
1622 auto surface = std::make_unique<egl::MockWindowSurface>();
1623 auto surface_ptr = surface.get();
1624
1625 EXPECT_CALL(*engine.get(), running).WillRepeatedly(Return(true));
1626
1627 EXPECT_CALL(*windows_proc_table.get(), DwmIsCompositionEnabled)
1628 .WillOnce(Return(false));
1629
1630 EXPECT_CALL(*egl_manager.get(), render_context)
1631 .WillOnce(Return(&render_context));
1632 EXPECT_CALL(*surface_ptr, IsValid).WillOnce(Return(true));
1633
1634 InSequence s;
1635 EXPECT_CALL(*egl_manager.get(), CreateWindowSurface)
1636 .WillOnce(Return(std::move(surface)));
1637 EXPECT_CALL(*engine.get(), PostRasterThreadTask)
1638 .WillOnce([](fml::closure callback) {
1639 callback();
1640 return true;
1641 });
1642
1643 EXPECT_CALL(*surface_ptr, MakeCurrent).WillOnce(Return(true));
1644 EXPECT_CALL(*surface_ptr, SetVSyncEnabled(true)).WillOnce(Return(true));
1645 EXPECT_CALL(render_context, ClearCurrent).WillOnce(Return(true));
1646
1647 EXPECT_CALL(*engine.get(), PostRasterThreadTask)
1648 .WillOnce([](fml::closure callback) {
1649 callback();
1650 return true;
1651 });
1652 EXPECT_CALL(*surface_ptr, Destroy).Times(1);
1653
1654 EngineModifier modifier{engine.get()};
1655 modifier.SetEGLManager(std::move(egl_manager));
1656
1657 std::unique_ptr<FlutterWindowsView> view =
1658 engine->CreateView(std::make_unique<NiceMock<MockWindowBindingHandler>>(),
1659 /*is_sized_to_content=*/false, BoxConstraints());
1660 }

References callback.

## ◆ TEST() [70/171]

flutter::testing::TEST | ( | FlutterWindowsViewTest | ,
|  | EnablesVSyncAtStartup |
| ) |  |

Definition at line 1537 of file flutter_windows_view_unittests.cc.

1537 {
1538 auto windows_proc_table = std::make_shared<MockWindowsProcTable>();
1539 auto engine = std::make_unique<MockFlutterWindowsEngine>(windows_proc_table);
1540 auto egl_manager = std::make_unique<egl::MockManager>();
1541 egl::MockContext render_context;
1542 auto surface = std::make_unique<egl::MockWindowSurface>();
1543 auto surface_ptr = surface.get();
1544
1545 EXPECT_CALL(*engine.get(), running).WillRepeatedly(Return(false));
1546 EXPECT_CALL(*engine.get(), PostRasterThreadTask).Times(0);
1547 EXPECT_CALL(*windows_proc_table.get(), DwmIsCompositionEnabled)
1548 .WillOnce(Return(false));
1549
1550 EXPECT_CALL(*egl_manager.get(), render_context)
1551 .WillOnce(Return(&render_context));
1552 EXPECT_CALL(*surface_ptr, IsValid).WillOnce(Return(true));
1553
1554 InSequence s;
1555 EXPECT_CALL(*egl_manager.get(), CreateWindowSurface)
1556 .WillOnce(Return(std::move(surface)));
1557 EXPECT_CALL(*surface_ptr, MakeCurrent).WillOnce(Return(true));
1558 EXPECT_CALL(*surface_ptr, SetVSyncEnabled(true)).WillOnce(Return(true));
1559 EXPECT_CALL(render_context, ClearCurrent).WillOnce(Return(true));
1560
1561 EXPECT_CALL(*surface_ptr, Destroy).Times(1);
1562
1563 EngineModifier modifier{engine.get()};
1564 modifier.SetEGLManager(std::move(egl_manager));
1565
1566 std::unique_ptr<FlutterWindowsView> view =
1567 engine->CreateView(std::make_unique<NiceMock<MockWindowBindingHandler>>(),
1568 /*is_sized_to_content=*/false, BoxConstraints());
1569 }

## ◆ TEST() [71/171]

flutter::testing::TEST | ( | FlutterWindowsViewTest | ,
|  | FirstFrameCallbackFiresOnFramePresented |
| ) |  |

Definition at line 1806 of file flutter_windows_view_unittests.cc.

1806 {
1807 std::unique_ptr<FlutterWindowsEngine> engine = GetTestEngine();
1808
1809 std::unique_ptr<FlutterWindowsView> view =
1810 engine->CreateView(std::make_unique<NiceMock<MockWindowBindingHandler>>(),
1811 /*is_sized_to_content=*/false, BoxConstraints());
1812
1813 bool callback_fired = false;
1814 view->SetFirstFrameCallback([&callback_fired]() { callback_fired = true; });
1815
1816 // Simulate the raster thread presenting a frame.
1817 view->OnFramePresented();
1818
1819 // The callback is posted to the platform thread's task runner.
1820 // Process pending tasks to execute it.
1821 engine->task_runner()->ProcessTasks();
1822
1823 EXPECT_TRUE(callback_fired);
1824 }

## ◆ TEST() [72/171]

flutter::testing::TEST | ( | FlutterWindowsViewTest | ,
|  | FirstFrameCallbackFiresOnlyOnce |
| ) |  |

Definition at line 1855 of file flutter_windows_view_unittests.cc.

1855 {
1856 std::unique_ptr<FlutterWindowsEngine> engine = GetTestEngine();
1857
1858 std::unique_ptr<FlutterWindowsView> view =
1859 engine->CreateView(std::make_unique<NiceMock<MockWindowBindingHandler>>(),
1860 /*is_sized_to_content=*/false, BoxConstraints());
1861
1862 int callback_count = 0;
1863 view->SetFirstFrameCallback([&callback_count]() { callback_count++; });
1864
1865 // Present two frames.
1866 view->OnFramePresented();
1867 view->OnFramePresented();
1868
1869 // Process all pending tasks.
1870 engine->task_runner()->ProcessTasks();
1871
1872 EXPECT_EQ(callback_count, 1);
1873 }

## ◆ TEST() [73/171]

flutter::testing::TEST | ( | FlutterWindowsViewTest | ,
|  | FirstFrameCallbackFiresOnSoftwareBitmapPresent |
| ) |  |

Definition at line 1828 of file flutter_windows_view_unittests.cc.

1828 {
1829 std::unique_ptr<FlutterWindowsEngine> engine = GetTestEngine();
1830
1831 auto window_binding_handler =
1832 std::make_unique<NiceMock<MockWindowBindingHandler>>();
1833 EXPECT_CALL(*window_binding_handler, OnBitmapSurfaceUpdated)
1834 .WillOnce(Return(true));
1835
1836 std::unique_ptr<FlutterWindowsView> view =
1837 engine->CreateView(std::move(window_binding_handler),
1838 /*is_sized_to_content=*/false, BoxConstraints());
1839
1840 bool callback_fired = false;
1841 view->SetFirstFrameCallback([&callback_fired]() { callback_fired = true; });
1842
1843 // Simulate software rendering presenting a bitmap.
1844 const uint32_t pixel = 0;
1845 view->PresentSoftwareBitmap(&pixel, sizeof(pixel), 1);
1846
1847 // Process pending tasks.
1848 engine->task_runner()->ProcessTasks();
1849
1850 EXPECT_TRUE(callback_fired);
1851 }

## ◆ TEST() [74/171]

flutter::testing::TEST | ( | FlutterWindowsViewTest | ,
|  | FirstFrameCallbackSkippedOnFailedSoftwarePresent |
| ) |  |

Definition at line 1877 of file flutter_windows_view_unittests.cc.

1877 {
1878 std::unique_ptr<FlutterWindowsEngine> engine = GetTestEngine();
1879
1880 auto window_binding_handler =
1881 std::make_unique<NiceMock<MockWindowBindingHandler>>();
1882 EXPECT_CALL(*window_binding_handler, OnBitmapSurfaceUpdated)
1883 .WillOnce(Return(false));
1884
1885 std::unique_ptr<FlutterWindowsView> view =
1886 engine->CreateView(std::move(window_binding_handler),
1887 /*is_sized_to_content=*/false, BoxConstraints());
1888
1889 bool callback_fired = false;
1890 view->SetFirstFrameCallback([&callback_fired]() { callback_fired = true; });
1891
1892 const uint32_t pixel = 0;
1893 view->PresentSoftwareBitmap(&pixel, sizeof(pixel), 1);
1894
1895 engine->task_runner()->ProcessTasks();
1896
1897 EXPECT_FALSE(callback_fired);
1898 }

## ◆ TEST() [75/171]

flutter::testing::TEST | ( | FlutterWindowsViewTest | ,
|  | FocusTriggersWindowFocus |
| ) |  |

Definition at line 1727 of file flutter_windows_view_unittests.cc.

1727 {
1728 std::unique_ptr<FlutterWindowsEngine> engine = GetTestEngine();
1729 auto window_binding_handler =
1730 std::make_unique<NiceMock<MockWindowBindingHandler>>();
1731 EXPECT_CALL(*window_binding_handler, Focus()).WillOnce(Return(true));
1732 std::unique_ptr<FlutterWindowsView> view =
1733 engine->CreateView(std::move(window_binding_handler),
1734 /*is_sized_to_content=*/false, BoxConstraints());
1735 EXPECT_TRUE(view->Focus());
1736 }

## ◆ TEST() [76/171]

flutter::testing::TEST | ( | FlutterWindowsViewTest | ,
|  | KeyEventCallback |
| ) |  |

Definition at line 317 of file flutter_windows_view_unittests.cc.

317 {
318 std::unique_ptr<FlutterWindowsEngine> engine = GetTestEngine();
319
320 std::unique_ptr<FlutterWindowsView> view =
321 engine->CreateView(std::make_unique<NiceMock<MockWindowBindingHandler>>(),
322 /*is_sized_to_content=*/false, BoxConstraints());
323
324 class MockCallback {
325 public:
326 MOCK_METHOD(void, Call, ());
327 };
328
329 NiceMock<MockCallback> callback_with_valid_view;
330 NiceMock<MockCallback> callback_with_invalid_view;
331
332 auto trigger_key_event = [&](NiceMock<MockCallback>& callback) {
333 view->OnKey(kVirtualKeyA, kScanCodeKeyA, WM_KEYDOWN, 'a', false, false,
334 [&](bool) { callback.Call(); });
335 };
336
337 EXPECT_CALL(callback_with_valid_view, Call()).Times(1);
338 EXPECT_CALL(callback_with_invalid_view, Call()).Times(0);
339
340 trigger_key_event(callback_with_valid_view);
341 engine->RemoveView(view->view_id());
342 trigger_key_event(callback_with_invalid_view);
343
344 key_event_logs.clear();
345 }
flutter::testing::kScanCodeKeyA
constexpr uint64_t kScanCodeKeyA
Definition: flutter_windows_view_unittests.cc:42
flutter::testing::kVirtualKeyA
constexpr uint64_t kVirtualKeyA
Definition: flutter_windows_view_unittests.cc:43

References callback, kScanCodeKeyA, and kVirtualKeyA.

## ◆ TEST() [77/171]

flutter::testing::TEST | ( | FlutterWindowsViewTest | ,
|  | KeySequence |
| ) |  |

Definition at line 298 of file flutter_windows_view_unittests.cc.

298 {
299 std::unique_ptr<FlutterWindowsEngine> engine = GetTestEngine();
300
301 test_response = false;
302
303 std::unique_ptr<FlutterWindowsView> view =
304 engine->CreateView(std::make_unique<NiceMock<MockWindowBindingHandler>>(),
305 /*is_sized_to_content=*/false, BoxConstraints());
306
307 view->OnKey(kVirtualKeyA, kScanCodeKeyA, WM_KEYDOWN, 'a', false, false,
308 [](bool handled) {});
309
310 EXPECT_EQ(key_event_logs.size(), 2);
311 EXPECT_EQ(key_event_logs[0], kKeyEventFromEmbedder);
312 EXPECT_EQ(key_event_logs[1], kKeyEventFromChannel);
313
314 key_event_logs.clear();
315 }

References kScanCodeKeyA, and kVirtualKeyA.

## ◆ TEST() [78/171]

flutter::testing::TEST | ( | FlutterWindowsViewTest | ,
|  | NonZeroSemanticsRoot |
| ) |  |

Definition at line 674 of file flutter_windows_view_unittests.cc.

674 {
675 std::unique_ptr<FlutterWindowsEngine> engine = GetTestEngine();
676 EngineModifier modifier(engine.get());
677 modifier.embedder_api().UpdateSemanticsEnabled =
678 [](FLUTTER_API_SYMBOL(FlutterEngine) engine, bool enabled) {
679 return kSuccess;
680 };
681
682 std::unique_ptr<FlutterWindowsView> view =
683 engine->CreateView(std::make_unique<NiceMock<MockWindowBindingHandler>>(),
684 /*is_sized_to_content=*/false, BoxConstraints());
685
686 // Enable semantics to instantiate accessibility bridge.
687 view->OnUpdateSemanticsEnabled(true);
688
689 auto bridge = view->accessibility_bridge().lock();
690 ASSERT_TRUE(bridge);
691
692 // Add root node.
693 FlutterSemanticsNode2 node1{sizeof(FlutterSemanticsNode2), 1};
694 std::vector<int32_t> node1_children{2};
695 node1.child_count = node1_children.size();
696 node1.children_in_traversal_order = node1_children.data();
697 node1.children_in_hit_test_order = node1_children.data();
698 auto empty_flags = FlutterSemanticsFlags{};
699 node1.flags2 = &empty_flags;
700
701 FlutterSemanticsNode2 node2{sizeof(FlutterSemanticsNode2), 2};
702 node2.label = "prefecture";
703 node2.value = "Kyoto";
704 node2.flags2 = &empty_flags;
705 bridge->AddFlutterSemanticsNodeUpdate(node1);
706 bridge->AddFlutterSemanticsNodeUpdate(node2);
707 bridge->CommitUpdates();
708
709 // Look up the root windows node delegate.
710 auto root_delegate = bridge->GetFlutterPlatformNodeDelegateFromID(1).lock();
711 ASSERT_TRUE(root_delegate);
712 EXPECT_EQ(root_delegate->GetChildCount(), 1);
713
714 // Look up the child node delegate
715 auto child_delegate = bridge->GetFlutterPlatformNodeDelegateFromID(2).lock();
716 ASSERT_TRUE(child_delegate);
717 EXPECT_EQ(child_delegate->GetChildCount(), 0);
718
719 // Ensure a node with ID 0 does not exist.
720 auto fake_delegate = bridge->GetFlutterPlatformNodeDelegateFromID(0).lock();
721 ASSERT_FALSE(fake_delegate);
722
723 // Get the root's native IAccessible object.
724 IAccessible* node1_accessible = root_delegate->GetNativeViewAccessible();
725 ASSERT_TRUE(node1_accessible != nullptr);
726
727 // Property lookups will be made against this node itself.
728 VARIANT varchild{};
729 varchild.vt = VT_I4;
730 varchild.lVal = CHILDID_SELF;
731
732 // Verify node type is a group.
733 VARIANT varrole{};
734 varrole.vt = VT_I4;
735 ASSERT_EQ(node1_accessible->get_accRole(varchild, &varrole), S_OK);
736 EXPECT_EQ(varrole.lVal, ROLE_SYSTEM_GROUPING);
737
738 // Verify child count.
739 long node1_child_count = 0;
740 ASSERT_EQ(node1_accessible->get_accChildCount(&node1_child_count), S_OK);
741 EXPECT_EQ(node1_child_count, 1);
742
743 {
744 // Look up first child of node1 (node0), a static text node.
745 varchild.lVal = 1;
746 IDispatch* node2_dispatch = nullptr;
747 ASSERT_EQ(node1_accessible->get_accChild(varchild, &node2_dispatch), S_OK);
748 ASSERT_TRUE(node2_dispatch != nullptr);
749 IAccessible* node2_accessible = nullptr;
750 ASSERT_EQ(node2_dispatch->QueryInterface(
751 IID_IAccessible, reinterpret_cast<void**>(&node2_accessible)),
752 S_OK);
753 ASSERT_TRUE(node2_accessible != nullptr);
754
755 // Verify node name matches our label.
756 varchild.lVal = CHILDID_SELF;
757 BSTR bname = nullptr;
758 ASSERT_EQ(node2_accessible->get_accName(varchild, &bname), S_OK);
759 std::string name(_com_util::ConvertBSTRToString(bname));
760 EXPECT_EQ(name, "prefecture");
761
762 // Verify node value matches.
763 BSTR bvalue = nullptr;
764 ASSERT_EQ(node2_accessible->get_accValue(varchild, &bvalue), S_OK);
765 std::string value(_com_util::ConvertBSTRToString(bvalue));
766 EXPECT_EQ(value, "Kyoto");
767
768 // Verify node type is static text.
769 VARIANT varrole{};
770 varrole.vt = VT_I4;
771 ASSERT_EQ(node2_accessible->get_accRole(varchild, &varrole), S_OK);
772 EXPECT_EQ(varrole.lVal, ROLE_SYSTEM_STATICTEXT);
773
774 // Verify the parent node is the root.
775 IDispatch* parent_dispatch;
776 node2_accessible->get_accParent(&parent_dispatch);
777 IAccessible* parent_accessible;
778 ASSERT_EQ(
779 parent_dispatch->QueryInterface(
780 IID_IAccessible, reinterpret_cast<void**>(&parent_accessible)),
781 S_OK);
782 EXPECT_EQ(parent_accessible, node1_accessible);
783 }
784 }

References flutter::IAccessible.

## ◆ TEST() [79/171]

flutter::testing::TEST | ( | FlutterWindowsViewTest | ,
|  | OnFocusTriggersSendFocusViewEvent |
| ) |  |

Definition at line 1738 of file flutter_windows_view_unittests.cc.

1738 {
1739 std::unique_ptr<FlutterWindowsEngine> engine = GetTestEngine();
1740 auto window_binding_handler =
1741 std::make_unique<NiceMock<MockWindowBindingHandler>>();
1742 std::unique_ptr<FlutterWindowsView> view =
1743 engine->CreateView(std::move(window_binding_handler),
1744 /*is_sized_to_content=*/false, BoxConstraints());
1745
1746 EngineModifier modifier(engine.get());
1747 bool received_focus_event = false;
1748 modifier.embedder_api().SendViewFocusEvent = MOCK_ENGINE_PROC(
1749 SendViewFocusEvent, [&](FLUTTER_API_SYMBOL(FlutterEngine) raw_engine,
1750 FlutterViewFocusEvent const* event) {
1751 EXPECT_EQ(event->state, FlutterViewFocusState::kFocused);
1752 EXPECT_EQ(event->direction, FlutterViewFocusDirection::kUndefined);
1753 EXPECT_EQ(event->view_id, view->view_id());
1754 EXPECT_EQ(event->struct_size, sizeof(FlutterViewFocusEvent));
1755 received_focus_event = true;
1756 return kSuccess;
1757 });
1758 view->OnFocus(FlutterViewFocusState::kFocused,
1759 FlutterViewFocusDirection::kUndefined);
1760 EXPECT_TRUE(received_focus_event);
1761 }

## ◆ TEST() [80/171]

flutter::testing::TEST | ( | FlutterWindowsViewTest | ,
|  | Shutdown |
| ) |  |

Definition at line 247 of file flutter_windows_view_unittests.cc.

247 {
248 auto engine = std::make_unique<MockFlutterWindowsEngine>();
249 auto window_binding_handler =
250 std::make_unique<NiceMock<MockWindowBindingHandler>>();
251 auto egl_manager = std::make_unique<egl::MockManager>();
252 auto surface = std::make_unique<egl::MockWindowSurface>();
253 egl::MockContext render_context;
254
255 auto engine_ptr = engine.get();
256 auto surface_ptr = surface.get();
257 auto egl_manager_ptr = egl_manager.get();
258
259 EngineModifier modifier{engine.get()};
260 modifier.SetEGLManager(std::move(egl_manager));
261
262 InSequence s;
263 std::unique_ptr<FlutterWindowsView> view;
264
265 // Mock render surface initialization.
266 {
267 EXPECT_CALL(*egl_manager_ptr, CreateWindowSurface)
268 .WillOnce(Return(std::move(surface)));
269 EXPECT_CALL(*engine_ptr, running).WillOnce(Return(false));
270 EXPECT_CALL(*surface_ptr, IsValid).WillOnce(Return(true));
271 EXPECT_CALL(*surface_ptr, MakeCurrent).WillOnce(Return(true));
272 EXPECT_CALL(*surface_ptr, SetVSyncEnabled).WillOnce(Return(true));
273 EXPECT_CALL(*egl_manager_ptr, render_context)
274 .WillOnce(Return(&render_context));
275 EXPECT_CALL(render_context, ClearCurrent).WillOnce(Return(true));
276
277 view = engine->CreateView(std::move(window_binding_handler), false,
278 BoxConstraints());
279 }
280
281 // The view must be removed before the surface can be destroyed.
282 {
283 auto view_id = view->view_id();
284 FlutterWindowsViewController controller{std::move(engine), std::move(view)};
285
286 EXPECT_CALL(*engine_ptr, running).WillOnce(Return(true));
287 EXPECT_CALL(*engine_ptr, RemoveView(view_id)).Times(1);
288 EXPECT_CALL(*engine_ptr, running).WillOnce(Return(true));
289 EXPECT_CALL(*engine_ptr, PostRasterThreadTask)
290 .WillOnce([](fml::closure callback) {
291 callback();
292 return true;
293 });
294 EXPECT_CALL(*surface_ptr, Destroy).Times(1);
295 }
296 }

References callback.

## ◆ TEST() [81/171]

flutter::testing::TEST | ( | FlutterWindowsViewTest | ,
|  | SizeChangeTriggersMetricsEventWhichHasDisplayId |
| ) |  |

Definition at line 1779 of file flutter_windows_view_unittests.cc.

1779 {
1780 std::unique_ptr<FlutterWindowsEngine> engine = GetTestEngine();
1781 EngineModifier modifier(engine.get());
1782
1783 auto window_binding_handler =
1784 std::make_unique<NiceMock<MockWindowBindingHandler>>();
1785 EXPECT_CALL(*window_binding_handler, GetDisplayId)
1786 .WillOnce(testing::Return(12));
1787 FlutterWindowsView view{kImplicitViewId, engine.get(),
1788 std::move(window_binding_handler), false,
1789 BoxConstraints()};
1790
1791 bool received_metrics = false;
1792 modifier.embedder_api().SendWindowMetricsEvent = MOCK_ENGINE_PROC(
1793 SendWindowMetricsEvent,
1794 ([&received_metrics](auto engine,
1795 const FlutterWindowMetricsEvent* event) {
1796 received_metrics = true;
1797 EXPECT_EQ(event->display_id, 12);
1798 return kSuccess;
1799 }));
1800 view.OnWindowSizeChanged(100, 100);
1801 EXPECT_TRUE(received_metrics);
1802 }
flutter::kImplicitViewId
constexpr FlutterViewId kImplicitViewId
Definition: flutter_windows_engine.h:56

References flutter::kImplicitViewId.

## ◆ TEST() [82/171]

flutter::testing::TEST | ( | FlutterWindowsViewTest | ,
|  | SubMenuExpandedState |
| ) |  |

Definition at line 137 of file flutter_windows_view_unittests.cc.

137 {
138 std::unique_ptr<FlutterWindowsEngine> engine = GetTestEngine();
139 EngineModifier modifier(engine.get());
140 modifier.embedder_api().UpdateSemanticsEnabled =
141 [](FLUTTER_API_SYMBOL(FlutterEngine) engine, bool enabled) {
142 return kSuccess;
143 };
144
145 auto window_binding_handler =
146 std::make_unique<NiceMock<MockWindowBindingHandler>>();
147 std::unique_ptr<FlutterWindowsView> view =
148 engine->CreateView(std::move(window_binding_handler),
149 /*is_sized_to_content=*/false, BoxConstraints());
150
151 // Enable semantics to instantiate accessibility bridge.
152 view->OnUpdateSemanticsEnabled(true);
153
154 auto bridge = view->accessibility_bridge().lock();
155 ASSERT_TRUE(bridge);
156
157 FlutterSemanticsNode2 root{sizeof(FlutterSemanticsNode2), 0};
158 root.id = 0;
159 root.label = "root";
160 root.hint = "";
161 root.value = "";
162 root.increased_value = "";
163 root.decreased_value = "";
164 root.child_count = 0;
165 root.custom_accessibility_actions_count = 0;
166 auto flags = FlutterSemanticsFlags{
167 .is_expanded = FlutterTristate::kFlutterTristateTrue,
168 };
169 root.flags2 = &flags;
170
171 bridge->AddFlutterSemanticsNodeUpdate(root);
172
173 bridge->CommitUpdates();
174
175 {
176 auto root_node = bridge->GetFlutterPlatformNodeDelegateFromID(0).lock();
177 EXPECT_TRUE(root_node->GetData().HasState(ax::mojom::State::kExpanded));
178
179 // Get the IAccessible for the root node.
180 IAccessible* native_view = root_node->GetNativeViewAccessible();
181 ASSERT_TRUE(native_view != nullptr);
182
183 // Look up against the node itself (not one of its children).
184 VARIANT varchild = {};
185 varchild.vt = VT_I4;
186
187 // Verify the submenu is expanded.
188 varchild.lVal = CHILDID_SELF;
189 VARIANT native_state = {};
190 ASSERT_TRUE(SUCCEEDED(native_view->get_accState(varchild, &native_state)));
191 EXPECT_TRUE(native_state.lVal & STATE_SYSTEM_EXPANDED);
192
193 // Perform similar tests for UIA value;
194 IRawElementProviderSimple* uia_node;
195 native_view->QueryInterface(IID_PPV_ARGS(&uia_node));
196 ASSERT_TRUE(SUCCEEDED(uia_node->GetPropertyValue(
197 UIA_ExpandCollapseExpandCollapseStatePropertyId, &native_state)));
198 EXPECT_EQ(native_state.lVal, ExpandCollapseState_Expanded);
199
200 ASSERT_TRUE(SUCCEEDED(uia_node->GetPropertyValue(
201 UIA_AriaPropertiesPropertyId, &native_state)));
202 EXPECT_NE(std::wcsstr(native_state.bstrVal, L"expanded=true"), nullptr);
203 }
204
205 // Test collapsed too.
206 auto updated_flags = FlutterSemanticsFlags{
207 .is_expanded = FlutterTristate::kFlutterTristateFalse,
208 };
209 root.flags2 = &updated_flags;
210
211 bridge->AddFlutterSemanticsNodeUpdate(root);
212 bridge->CommitUpdates();
213
214 {
215 auto root_node = bridge->GetFlutterPlatformNodeDelegateFromID(0).lock();
216 EXPECT_TRUE(root_node->GetData().HasState(ax::mojom::State::kCollapsed));
217
218 // Get the IAccessible for the root node.
219 IAccessible* native_view = root_node->GetNativeViewAccessible();
220 ASSERT_TRUE(native_view != nullptr);
221
222 // Look up against the node itself (not one of its children).
223 VARIANT varchild = {};
224 varchild.vt = VT_I4;
225
226 // Verify the submenu is collapsed.
227 varchild.lVal = CHILDID_SELF;
228 VARIANT native_state = {};
229 ASSERT_TRUE(SUCCEEDED(native_view->get_accState(varchild, &native_state)));
230 EXPECT_TRUE(native_state.lVal & STATE_SYSTEM_COLLAPSED);
231
232 // Perform similar tests for UIA value;
233 IRawElementProviderSimple* uia_node;
234 native_view->QueryInterface(IID_PPV_ARGS(&uia_node));
235 ASSERT_TRUE(SUCCEEDED(uia_node->GetPropertyValue(
236 UIA_ExpandCollapseExpandCollapseStatePropertyId, &native_state)));
237 EXPECT_EQ(native_state.lVal, ExpandCollapseState_Collapsed);
238
239 ASSERT_TRUE(SUCCEEDED(uia_node->GetPropertyValue(
240 UIA_AriaPropertiesPropertyId, &native_state)));
241 EXPECT_NE(std::wcsstr(native_state.bstrVal, L"expanded=false"), nullptr);
242 }
243 }

References flutter::IAccessible.

## ◆ TEST() [83/171]

flutter::testing::TEST | ( | FlutterWindowsViewTest | ,
|  | SwitchNativeState |
| ) |  |

Definition at line 1317 of file flutter_windows_view_unittests.cc.

1317 {
1318 std::unique_ptr<FlutterWindowsEngine> engine = GetTestEngine();
1319 EngineModifier modifier(engine.get());
1320 modifier.embedder_api().UpdateSemanticsEnabled =
1321 [](FLUTTER_API_SYMBOL(FlutterEngine) engine, bool enabled) {
1322 return kSuccess;
1323 };
1324
1325 std::unique_ptr<FlutterWindowsView> view =
1326 engine->CreateView(std::make_unique<NiceMock<MockWindowBindingHandler>>(),
1327 /*is_sized_to_content=*/false, BoxConstraints());
1328
1329 // Enable semantics to instantiate accessibility bridge.
1330 view->OnUpdateSemanticsEnabled(true);
1331
1332 auto bridge = view->accessibility_bridge().lock();
1333 ASSERT_TRUE(bridge);
1334
1335 FlutterSemanticsNode2 root{sizeof(FlutterSemanticsNode2), 0};
1336 root.id = 0;
1337 root.label = "root";
1338 root.hint = "";
1339 root.value = "";
1340 root.increased_value = "";
1341 root.decreased_value = "";
1342 root.child_count = 0;
1343 root.custom_accessibility_actions_count = 0;
1344
1345 auto flags = FlutterSemanticsFlags{
1346 .is_toggled = FlutterTristate::kFlutterTristateTrue,
1347 };
1348 root.flags2 = &flags;
1349 bridge->AddFlutterSemanticsNodeUpdate(root);
1350
1351 bridge->CommitUpdates();
1352
1353 {
1354 auto root_node = bridge->GetFlutterPlatformNodeDelegateFromID(0).lock();
1355 EXPECT_EQ(root_node->GetData().role, ax::mojom::Role::kSwitch);
1356 EXPECT_EQ(root_node->GetData().GetCheckedState(),
1357 ax::mojom::CheckedState::kTrue);
1358
1359 // Get the IAccessible for the root node.
1360 IAccessible* native_view = root_node->GetNativeViewAccessible();
1361 ASSERT_TRUE(native_view != nullptr);
1362
1363 // Look up against the node itself (not one of its children).
1364 VARIANT varchild = {};
1365 varchild.vt = VT_I4;
1366
1367 varchild.lVal = CHILDID_SELF;
1368 VARIANT varrole = {};
1369
1370 // Verify the role of the switch is CHECKBUTTON
1371 ASSERT_EQ(native_view->get_accRole(varchild, &varrole), S_OK);
1372 ASSERT_EQ(varrole.lVal, ROLE_SYSTEM_CHECKBUTTON);
1373
1374 // Verify the switch is pressed.
1375 VARIANT native_state = {};
1376 ASSERT_TRUE(SUCCEEDED(native_view->get_accState(varchild, &native_state)));
1377 EXPECT_TRUE(native_state.lVal & STATE_SYSTEM_PRESSED);
1378 EXPECT_TRUE(native_state.lVal & STATE_SYSTEM_CHECKED);
1379
1380 // Test similarly on UIA node.
1381 IRawElementProviderSimple* uia_node;
1382 native_view->QueryInterface(IID_PPV_ARGS(&uia_node));
1383 ASSERT_EQ(uia_node->GetPropertyValue(UIA_ControlTypePropertyId, &varrole),
1384 S_OK);
1385 EXPECT_EQ(varrole.lVal, UIA_ButtonControlTypeId);
1386 ASSERT_EQ(uia_node->GetPropertyValue(UIA_ToggleToggleStatePropertyId,
1387 &native_state),
1388 S_OK);
1389 EXPECT_EQ(native_state.lVal, ToggleState_On);
1390 ASSERT_EQ(
1391 uia_node->GetPropertyValue(UIA_AriaPropertiesPropertyId, &native_state),
1392 S_OK);
1393 EXPECT_NE(std::wcsstr(native_state.bstrVal, L"pressed=true"), nullptr);
1394 }
1395
1396 // Test unpressed too.
1397 auto updated_flags = FlutterSemanticsFlags{
1398 .is_toggled = FlutterTristate::kFlutterTristateFalse,
1399 };
1400 root.flags2 = &updated_flags;
1401
1402 bridge->AddFlutterSemanticsNodeUpdate(root);
1403 bridge->CommitUpdates();
1404
1405 {
1406 auto root_node = bridge->GetFlutterPlatformNodeDelegateFromID(0).lock();
1407 EXPECT_EQ(root_node->GetData().role, ax::mojom::Role::kSwitch);
1408 EXPECT_EQ(root_node->GetData().GetCheckedState(),
1409 ax::mojom::CheckedState::kFalse);
1410
1411 // Get the IAccessible for the root node.
1412 IAccessible* native_view = root_node->GetNativeViewAccessible();
1413 ASSERT_TRUE(native_view != nullptr);
1414
1415 // Look up against the node itself (not one of its children).
1416 VARIANT varchild = {};
1417 varchild.vt = VT_I4;
1418
1419 // Verify the switch is not pressed.
1420 varchild.lVal = CHILDID_SELF;
1421 VARIANT native_state = {};
1422 ASSERT_TRUE(SUCCEEDED(native_view->get_accState(varchild, &native_state)));
1423 EXPECT_FALSE(native_state.lVal & STATE_SYSTEM_PRESSED);
1424 EXPECT_FALSE(native_state.lVal & STATE_SYSTEM_CHECKED);
1425
1426 // Test similarly on UIA node.
1427 IRawElementProviderSimple* uia_node;
1428 native_view->QueryInterface(IID_PPV_ARGS(&uia_node));
1429 ASSERT_EQ(uia_node->GetPropertyValue(UIA_ToggleToggleStatePropertyId,
1430 &native_state),
1431 S_OK);
1432 EXPECT_EQ(native_state.lVal, ToggleState_Off);
1433 ASSERT_EQ(
1434 uia_node->GetPropertyValue(UIA_AriaPropertiesPropertyId, &native_state),
1435 S_OK);
1436 EXPECT_NE(std::wcsstr(native_state.bstrVal, L"pressed=false"), nullptr);
1437 }
1438 }

References flutter::IAccessible.

## ◆ TEST() [84/171]

flutter::testing::TEST | ( | FlutterWindowsViewTest | ,
|  | TestEmptyFrameResizes |
| ) |  |

Definition at line 973 of file flutter_windows_view_unittests.cc.

973 {
974 auto windows_proc_table = std::make_shared<NiceMock<MockWindowsProcTable>>();
975 std::unique_ptr<FlutterWindowsEngine> engine =
976 GetTestEngine(windows_proc_table);
977
978 EngineModifier engine_modifier{engine.get()};
979 engine_modifier.embedder_api().PostRenderThreadTask = MOCK_ENGINE_PROC(
980 PostRenderThreadTask,
981 ([](auto engine, VoidCallback callback, void* user_data) {
982 callback(user_data);
983 return kSuccess;
984 }));
985
986 auto egl_manager = std::make_unique<egl::MockManager>();
987 auto surface = std::make_unique<egl::MockWindowSurface>();
988 auto resized_surface = std::make_unique<egl::MockWindowSurface>();
989 auto resized_surface_ptr = resized_surface.get();
990
991 EXPECT_CALL(*surface.get(), IsValid).WillRepeatedly(Return(true));
992 EXPECT_CALL(*surface.get(), Destroy).WillOnce(Return(true));
993
994 EXPECT_CALL(*egl_manager.get(),
995 CreateWindowSurface(_, /*width=*/500, /*height=*/500))
996 .WillOnce(Return(std::move((resized_surface))));
997 EXPECT_CALL(*resized_surface_ptr, MakeCurrent).WillOnce(Return(true));
998 EXPECT_CALL(*resized_surface_ptr, SetVSyncEnabled).WillOnce(Return(true));
999 EXPECT_CALL(*windows_proc_table.get(), DwmFlush).WillOnce(Return(S_OK));
1000
1001 EXPECT_CALL(*resized_surface_ptr, Destroy).WillOnce(Return(true));
1002
1003 fml::AutoResetWaitableEvent metrics_sent_latch;
1004 engine_modifier.embedder_api().SendWindowMetricsEvent = MOCK_ENGINE_PROC(
1005 SendWindowMetricsEvent,
1006 ([&metrics_sent_latch](auto engine,
1007 const FlutterWindowMetricsEvent* event) {
1008 metrics_sent_latch.Signal();
1009 return kSuccess;
1010 }));
1011
1012 std::unique_ptr<FlutterWindowsView> view =
1013 engine->CreateView(std::make_unique<NiceMock<MockWindowBindingHandler>>(),
1014 /*is_sized_to_content=*/false, BoxConstraints());
1015
1016 ViewModifier view_modifier{view.get()};
1017 engine_modifier.SetEGLManager(std::move(egl_manager));
1018 view_modifier.SetSurface(std::move(surface));
1019
1020 // Simulate raster thread.
1021 std::thread frame_thread([&metrics_sent_latch, &view]() {
1022 metrics_sent_latch.Wait();
1023
1024 // Empty frame generated and presented from the raster thread.
1025 EXPECT_TRUE(view->OnEmptyFrameGenerated());
1026 view->OnFramePresented();
1027 });
1028
1029 // Start the window resize. This sends the new window metrics
1030 // and then blocks until another thread completes the window resize.
1031 EXPECT_TRUE(view->OnWindowSizeChanged(500, 500));
1032 frame_thread.join();
1033 }
VoidCallback
void(* VoidCallback)(void *)
Definition: flutter_windows.h:21

References callback, and user_data.

## ◆ TEST() [85/171]

flutter::testing::TEST | ( | FlutterWindowsViewTest | ,
|  | TooltipNodeData |
| ) |  |

Definition at line 1440 of file flutter_windows_view_unittests.cc.

1440 {
1441 std::unique_ptr<FlutterWindowsEngine> engine = GetTestEngine();
1442 EngineModifier modifier(engine.get());
1443 modifier.embedder_api().UpdateSemanticsEnabled =
1444 [](FLUTTER_API_SYMBOL(FlutterEngine) engine, bool enabled) {
1445 return kSuccess;
1446 };
1447
1448 std::unique_ptr<FlutterWindowsView> view =
1449 engine->CreateView(std::make_unique<NiceMock<MockWindowBindingHandler>>(),
1450 /*is_sized_to_content=*/false, BoxConstraints());
1451
1452 // Enable semantics to instantiate accessibility bridge.
1453 view->OnUpdateSemanticsEnabled(true);
1454
1455 auto bridge = view->accessibility_bridge().lock();
1456 ASSERT_TRUE(bridge);
1457
1458 FlutterSemanticsNode2 root{sizeof(FlutterSemanticsNode2), 0};
1459 root.id = 0;
1460 root.label = "root";
1461 root.hint = "";
1462 root.value = "";
1463 root.increased_value = "";
1464 root.decreased_value = "";
1465 root.tooltip = "tooltip";
1466 root.child_count = 0;
1467 root.custom_accessibility_actions_count = 0;
1468 auto flags = FlutterSemanticsFlags{
1469 .is_text_field = true,
1470 };
1471 root.flags2 = &flags;
1472 bridge->AddFlutterSemanticsNodeUpdate(root);
1473
1474 bridge->CommitUpdates();
1475 auto root_node = bridge->GetFlutterPlatformNodeDelegateFromID(0).lock();
1476 std::string tooltip = root_node->GetData().GetStringAttribute(
1477 ax::mojom::StringAttribute::kTooltip);
1478 EXPECT_EQ(tooltip, "tooltip");
1479
1480 // Check that MSAA name contains the tooltip.
1481 IAccessible* native_view = bridge->GetFlutterPlatformNodeDelegateFromID(0)
1482 .lock()
1483 ->GetNativeViewAccessible();
1484 VARIANT varchild = {.vt = VT_I4, .lVal = CHILDID_SELF};
1485 BSTR bname;
1486 ASSERT_EQ(native_view->get_accName(varchild, &bname), S_OK);
1487 EXPECT_NE(std::wcsstr(bname, L"tooltip"), nullptr);
1488
1489 // Check that UIA help text is equal to the tooltip.
1490 IRawElementProviderSimple* uia_node;
1491 native_view->QueryInterface(IID_PPV_ARGS(&uia_node));
1492 VARIANT varname{};
1493 ASSERT_EQ(uia_node->GetPropertyValue(UIA_HelpTextPropertyId, &varname), S_OK);
1494 std::string uia_tooltip = _com_util::ConvertBSTRToString(varname.bstrVal);
1495 EXPECT_EQ(uia_tooltip, "tooltip");
1496 }

References flutter::IAccessible.

## ◆ TEST() [86/171]

flutter::testing::TEST | ( | FlutterWindowsViewTest | ,
|  | UpdatesVSyncOnDwmUpdates |
| ) |  |

Definition at line 1665 of file flutter_windows_view_unittests.cc.

1665 {
1666 auto windows_proc_table = std::make_shared<MockWindowsProcTable>();
1667 auto engine = std::make_unique<MockFlutterWindowsEngine>(windows_proc_table);
1668 auto egl_manager = std::make_unique<egl::MockManager>();
1669 egl::MockContext render_context;
1670 auto surface = std::make_unique<egl::MockWindowSurface>();
1671 auto surface_ptr = surface.get();
1672
1673 EXPECT_CALL(*engine.get(), running).WillRepeatedly(Return(true));
1674
1675 EXPECT_CALL(*engine.get(), PostRasterThreadTask)
1676 .WillRepeatedly([](fml::closure callback) {
1677 callback();
1678 return true;
1679 });
1680
1681 EXPECT_CALL(*egl_manager.get(), render_context)
1682 .WillRepeatedly(Return(&render_context));
1683
1684 EXPECT_CALL(*surface_ptr, IsValid).WillRepeatedly(Return(true));
1685 EXPECT_CALL(*surface_ptr, MakeCurrent).WillRepeatedly(Return(true));
1686 EXPECT_CALL(*surface_ptr, Destroy).Times(1);
1687 EXPECT_CALL(render_context, ClearCurrent).WillRepeatedly(Return(true));
1688
1689 InSequence s;
1690
1691 // Mock render surface initialization.
1692 std::unique_ptr<FlutterWindowsView> view;
1693 {
1694 EXPECT_CALL(*egl_manager, CreateWindowSurface)
1695 .WillOnce(Return(std::move(surface)));
1696 EXPECT_CALL(*windows_proc_table.get(), DwmIsCompositionEnabled)
1697 .WillOnce(Return(true));
1698 EXPECT_CALL(*surface_ptr, SetVSyncEnabled).WillOnce(Return(true));
1699
1700 EngineModifier engine_modifier{engine.get()};
1701 engine_modifier.SetEGLManager(std::move(egl_manager));
1702
1703 view = engine->CreateView(
1704 std::make_unique<NiceMock<MockWindowBindingHandler>>(), false,
1705 BoxConstraints());
1706 }
1707
1708 // Disabling DWM composition should enable vsync blocking on the surface.
1709 {
1710 EXPECT_CALL(*windows_proc_table.get(), DwmIsCompositionEnabled)
1711 .WillOnce(Return(false));
1712 EXPECT_CALL(*surface_ptr, SetVSyncEnabled(true)).WillOnce(Return(true));
1713
1714 engine->OnDwmCompositionChanged();
1715 }
1716
1717 // Enabling DWM composition should disable vsync blocking on the surface.
1718 {
1719 EXPECT_CALL(*windows_proc_table.get(), DwmIsCompositionEnabled)
1720 .WillOnce(Return(true));
1721 EXPECT_CALL(*surface_ptr, SetVSyncEnabled(false)).WillOnce(Return(true));
1722
1723 engine->OnDwmCompositionChanged();
1724 }
1725 }

References callback.

## ◆ TEST() [87/171]

flutter::testing::TEST | ( | FlutterWindowsViewTest | ,
|  | WindowMetricsEventContainsDisplayId |
| ) |  |

Definition at line 1763 of file flutter_windows_view_unittests.cc.

1763 {
1764 std::unique_ptr<FlutterWindowsEngine> engine = GetTestEngine();
1765 EngineModifier modifier(engine.get());
1766
1767 auto window_binding_handler =
1768 std::make_unique<NiceMock<MockWindowBindingHandler>>();
1769 EXPECT_CALL(*window_binding_handler, GetDisplayId)
1770 .WillOnce(testing::Return(12));
1771 FlutterWindowsView view{kImplicitViewId, engine.get(),
1772 std::move(window_binding_handler), false,
1773 BoxConstraints()};
1774
1775 FlutterWindowMetricsEvent event = view.CreateWindowMetricsEvent();
1776 EXPECT_EQ(event.display_id, 12);
1777 }

References flutter::kImplicitViewId.

## ◆ TEST() [88/171]

flutter::testing::TEST | ( | FlutterWindowsViewTest | ,
|  | WindowRepaintTests |
| ) |  |

Definition at line 1142 of file flutter_windows_view_unittests.cc.

1142 {
1143 std::unique_ptr<FlutterWindowsEngine> engine = GetTestEngine();
1144 EngineModifier modifier(engine.get());
1145
1146 FlutterWindowsView view{kImplicitViewId, engine.get(),
1147 std::make_unique<flutter::FlutterWindow>(
1148 100, 100, engine->display_manager()),
1149 /*is_sized_to_content=*/false, BoxConstraints()};
1150
1151 bool schedule_frame_called = false;
1152 modifier.embedder_api().ScheduleFrame =
1153 MOCK_ENGINE_PROC(ScheduleFrame, ([&schedule_frame_called](auto engine) {
1154 schedule_frame_called = true;
1155 return kSuccess;
1156 }));
1157
1158 view.OnWindowRepaint();
1159 EXPECT_TRUE(schedule_frame_called);
1160 }

References flutter::kImplicitViewId.

## ◆ TEST() [89/171]

flutter::testing::TEST | ( | FlutterWindowsViewTest | ,
|  | WindowResizeInvalidSurface |
| ) |  |

Definition at line 1078 of file flutter_windows_view_unittests.cc.

1078 {
1079 std::unique_ptr<FlutterWindowsEngine> engine = GetTestEngine();
1080
1081 EngineModifier engine_modifier(engine.get());
1082 engine_modifier.embedder_api().PostRenderThreadTask = MOCK_ENGINE_PROC(
1083 PostRenderThreadTask,
1084 ([](auto engine, VoidCallback callback, void* user_data) {
1085 callback(user_data);
1086 return kSuccess;
1087 }));
1088
1089 auto egl_manager = std::make_unique<egl::MockManager>();
1090 auto surface = std::make_unique<egl::MockWindowSurface>();
1091
1092 EXPECT_CALL(*egl_manager.get(), CreateWindowSurface).Times(0);
1093 EXPECT_CALL(*surface.get(), IsValid).WillRepeatedly(Return(false));
1094 EXPECT_CALL(*surface.get(), Destroy).WillOnce(Return(false));
1095
1096 std::unique_ptr<FlutterWindowsView> view =
1097 engine->CreateView(std::make_unique<NiceMock<MockWindowBindingHandler>>(),
1098 /*is_sized_to_content=*/false, BoxConstraints());
1099
1100 ViewModifier view_modifier{view.get()};
1101 engine_modifier.SetEGLManager(std::move(egl_manager));
1102 view_modifier.SetSurface(std::move(surface));
1103
1104 auto metrics_sent = false;
1105 engine_modifier.embedder_api().SendWindowMetricsEvent = MOCK_ENGINE_PROC(
1106 SendWindowMetricsEvent,
1107 ([&metrics_sent](auto engine, const FlutterWindowMetricsEvent* event) {
1108 metrics_sent = true;
1109 return kSuccess;
1110 }));
1111
1112 view->OnWindowSizeChanged(500, 500);
1113 }

References callback, and user_data.

## ◆ TEST() [90/171]

flutter::testing::TEST | ( | FlutterWindowsViewTest | ,
|  | WindowResizeRace |
| ) |  |

Definition at line 1038 of file flutter_windows_view_unittests.cc.

1038 {
1039 std::unique_ptr<FlutterWindowsEngine> engine = GetTestEngine();
1040
1041 EngineModifier engine_modifier(engine.get());
1042 engine_modifier.embedder_api().PostRenderThreadTask = MOCK_ENGINE_PROC(
1043 PostRenderThreadTask,
1044 ([](auto engine, VoidCallback callback, void* user_data) {
1045 callback(user_data);
1046 return kSuccess;
1047 }));
1048
1049 auto egl_manager = std::make_unique<egl::MockManager>();
1050 auto surface = std::make_unique<egl::MockWindowSurface>();
1051
1052 EXPECT_CALL(*surface.get(), IsValid).WillRepeatedly(Return(true));
1053 EXPECT_CALL(*surface.get(), Destroy).WillOnce(Return(true));
1054
1055 std::unique_ptr<FlutterWindowsView> view =
1056 engine->CreateView(std::make_unique<NiceMock<MockWindowBindingHandler>>(),
1057 /*is_sized_to_content=*/false, BoxConstraints());
1058
1059 ViewModifier view_modifier{view.get()};
1060 engine_modifier.SetEGLManager(std::move(egl_manager));
1061 view_modifier.SetSurface(std::move(surface));
1062
1063 // Begin a frame.
1064 ASSERT_TRUE(view->OnFrameGenerated(100, 100));
1065
1066 // Inject a window resize between the frame generation and
1067 // frame presentation. The new size invalidates the current frame.
1068 EXPECT_FALSE(view->OnWindowSizeChanged(500, 500));
1069
1070 // Complete the invalidated frame while a resize is pending. Although this
1071 // might mean that we presented a frame with the wrong size, this should not
1072 // crash the app.
1073 view->OnFramePresented();
1074 }

References callback, and user_data.

## ◆ TEST() [91/171]

flutter::testing::TEST | ( | FlutterWindowsViewTest | ,
|  | WindowResizeTests |
| ) |  |

Definition at line 901 of file flutter_windows_view_unittests.cc.

901 {
902 auto windows_proc_table = std::make_shared<NiceMock<MockWindowsProcTable>>();
903 std::unique_ptr<FlutterWindowsEngine> engine =
904 GetTestEngine(windows_proc_table);
905
906 EngineModifier engine_modifier{engine.get()};
907 engine_modifier.embedder_api().PostRenderThreadTask = MOCK_ENGINE_PROC(
908 PostRenderThreadTask,
909 ([](auto engine, VoidCallback callback, void* user_data) {
910 callback(user_data);
911 return kSuccess;
912 }));
913
914 auto egl_manager = std::make_unique<egl::MockManager>();
915 auto surface = std::make_unique<egl::MockWindowSurface>();
916 auto resized_surface = std::make_unique<egl::MockWindowSurface>();
917 egl::MockContext render_context;
918
919 auto surface_ptr = surface.get();
920 auto resized_surface_ptr = resized_surface.get();
921
922 // Mock render surface creation
923 EXPECT_CALL(*egl_manager, CreateWindowSurface)
924 .WillOnce(Return(std::move(surface)));
925 EXPECT_CALL(*surface_ptr, IsValid).WillRepeatedly(Return(true));
926 EXPECT_CALL(*surface_ptr, MakeCurrent).WillOnce(Return(true));
927 EXPECT_CALL(*surface_ptr, SetVSyncEnabled).WillOnce(Return(true));
928 EXPECT_CALL(*egl_manager, render_context).WillOnce(Return(&render_context));
929 EXPECT_CALL(render_context, ClearCurrent).WillOnce(Return(true));
930
931 // Mock render surface resize
932 EXPECT_CALL(*surface_ptr, Destroy).WillOnce(Return(true));
933 EXPECT_CALL(*egl_manager.get(),
934 CreateWindowSurface(_, /*width=*/500, /*height=*/500))
935 .WillOnce(Return(std::move((resized_surface))));
936 EXPECT_CALL(*resized_surface_ptr, MakeCurrent).WillOnce(Return(true));
937 EXPECT_CALL(*resized_surface_ptr, SetVSyncEnabled).WillOnce(Return(true));
938 EXPECT_CALL(*windows_proc_table.get(), DwmFlush).WillOnce(Return(S_OK));
939
940 EXPECT_CALL(*resized_surface_ptr, Destroy).WillOnce(Return(true));
941
942 engine_modifier.SetEGLManager(std::move(egl_manager));
943
944 std::unique_ptr<FlutterWindowsView> view =
945 engine->CreateView(std::make_unique<NiceMock<MockWindowBindingHandler>>(),
946 /*is_sized_to_content=*/false, BoxConstraints());
947
948 fml::AutoResetWaitableEvent metrics_sent_latch;
949 engine_modifier.embedder_api().SendWindowMetricsEvent = MOCK_ENGINE_PROC(
950 SendWindowMetricsEvent,
951 ([&metrics_sent_latch](auto engine,
952 const FlutterWindowMetricsEvent* event) {
953 metrics_sent_latch.Signal();
954 return kSuccess;
955 }));
956
957 // Simulate raster thread.
958 std::thread frame_thread([&metrics_sent_latch, &view]() {
959 metrics_sent_latch.Wait();
960 // Frame generated and presented from the raster thread.
961 EXPECT_TRUE(view->OnFrameGenerated(500, 500));
962 view->OnFramePresented();
963 });
964
965 // Start the window resize. This sends the new window metrics
966 // and then blocks polling run loop until another thread completes the window
967 // resize.
968 EXPECT_TRUE(view->OnWindowSizeChanged(500, 500));
969 frame_thread.join();
970 }

References callback, and user_data.

## ◆ TEST() [92/171]

flutter::testing::TEST | ( | FlutterWindowsViewTest | ,
|  | WindowResizeWithoutSurface |
| ) |  |

Definition at line 1117 of file flutter_windows_view_unittests.cc.

1117 {
1118 std::unique_ptr<FlutterWindowsEngine> engine = GetTestEngine();
1119 EngineModifier modifier(engine.get());
1120
1121 auto egl_manager = std::make_unique<egl::MockManager>();
1122
1123 EXPECT_CALL(*egl_manager.get(), CreateWindowSurface).Times(0);
1124
1125 std::unique_ptr<FlutterWindowsView> view =
1126 engine->CreateView(std::make_unique<NiceMock<MockWindowBindingHandler>>(),
1127 /*is_sized_to_content=*/false, BoxConstraints());
1128
1129 modifier.SetEGLManager(std::move(egl_manager));
1130
1131 auto metrics_sent = false;
1132 modifier.embedder_api().SendWindowMetricsEvent = MOCK_ENGINE_PROC(
1133 SendWindowMetricsEvent,
1134 ([&metrics_sent](auto engine, const FlutterWindowMetricsEvent* event) {
1135 metrics_sent = true;
1136 return kSuccess;
1137 }));
1138
1139 view->OnWindowSizeChanged(500, 500);
1140 }

## ◆ TEST() [93/171]

flutter::testing::TEST | ( | KeyboardKeyChannelHandlerTest | ,
|  | DeadKeysDoNotCrash |
| ) |  |

Definition at line 128 of file keyboard_key_channel_handler_unittests.cc.

128 {
129 bool received = false;
130 TestBinaryMessenger messenger(
131 [&received](const std::string& channel, const uint8_t* message,
132 size_t message_size, BinaryReply reply) {
133 if (channel == "flutter/keyevent") {
134 auto message_doc = JsonMessageCodec::GetInstance().DecodeMessage(
135 message, message_size);
136 uint32_t character = (*message_doc)[kCharacterCodePointKey].GetUint();
137 EXPECT_EQ(character, (uint32_t)'^');
138 received = true;
139 }
140 return true;
141 });
142
143 KeyboardKeyChannelHandler handler(&messenger);
144 // Extended key flag is passed to redispatched events if set.
145 handler.KeyboardHook(0xDD, 0x1a, WM_KEYDOWN, 0x8000005E, false, false,
146 [](bool handled) {});
147
148 // EXPECT is done during the callback above.
149 EXPECT_TRUE(received);
150 }
character
char32_t character
Definition: keyboard_key_handler_unittests.cc:117
message
Win32Message message
Definition: keyboard_unittests.cc:137
flutter::BinaryReply
std::function< void(const uint8_t *reply, size_t reply_size)> BinaryReply
Definition: binary_messenger.h:18

References character, flutter::MessageCodec< T >::DecodeMessage(), flutter::JsonMessageCodec::GetInstance(), and message.

## ◆ TEST() [94/171]

flutter::testing::TEST | ( | KeyboardKeyChannelHandlerTest | ,
|  | EmptyResponsesDoNotCrash |
| ) |  |

Definition at line 152 of file keyboard_key_channel_handler_unittests.cc.

152 {
153 bool received = false;
154 TestBinaryMessenger messenger(
155 [&received](const std::string& channel, const uint8_t* message,
156 size_t message_size, BinaryReply reply) {
157 if (channel == "flutter/keyevent") {
158 std::string empty_message = "";
159 std::vector<uint8_t> empty_response(empty_message.begin(),
160 empty_message.end());
161 reply(empty_response.data(), empty_response.size());
162 received = true;
163 }
164 return true;
165 });
166
167 KeyboardKeyChannelHandler handler(&messenger);
168 handler.KeyboardHook(64, kUnhandledScanCode, WM_KEYDOWN, L'b', false, false,
169 [](bool handled) {});
170
171 // Passes if it does not crash.
172 EXPECT_TRUE(received);
173 }

References message.

## ◆ TEST() [95/171]

flutter::testing::TEST | ( | KeyboardKeyChannelHandlerTest | ,
|  | ExtendedKeysAreSentToRedispatch |
| ) |  |

Definition at line 88 of file keyboard_key_channel_handler_unittests.cc.

88 {
89 auto handled_message = CreateResponse(true);
90 auto unhandled_message = CreateResponse(false);
91 int received_scancode = 0;
92
93 TestBinaryMessenger messenger(
94 [&received_scancode, &handled_message, &unhandled_message](
95 const std::string& channel, const uint8_t* message,
96 size_t message_size, BinaryReply reply) {
97 if (channel == "flutter/keyevent") {
98 auto message_doc = JsonMessageCodec::GetInstance().DecodeMessage(
99 message, message_size);
100 received_scancode = (*message_doc)[kScanCodeKey].GetInt();
101 if (received_scancode == kHandledScanCode) {
102 reply(handled_message->data(), handled_message->size());
103 } else {
104 reply(unhandled_message->data(), unhandled_message->size());
105 }
106 }
107 });
108
109 KeyboardKeyChannelHandler handler(&messenger);
110 bool last_handled = true;
111
112 // Extended key flag is passed to redispatched events if set.
113 handler.KeyboardHook(
114 64, kUnhandledScanCode, WM_KEYDOWN, L'b', true, false,
115 [&last_handled](bool handled) { last_handled = handled; });
116 EXPECT_EQ(last_handled, false);
117 EXPECT_EQ(received_scancode, kUnhandledScanCodeExtended);
118
119 last_handled = true;
120 // Extended key flag is not passed to redispatched events if not set.
121 handler.KeyboardHook(
122 64, kUnhandledScanCode, WM_KEYDOWN, L'b', false, false,
123 [&last_handled](bool handled) { last_handled = handled; });
124 EXPECT_EQ(last_handled, false);
125 EXPECT_EQ(received_scancode, kUnhandledScanCode);
126 }

References flutter::MessageCodec< T >::DecodeMessage(), flutter::JsonMessageCodec::GetInstance(), and message.

## ◆ TEST() [96/171]

flutter::testing::TEST | ( | KeyboardKeyChannelHandlerTest | ,
|  | KeyboardHookHandling |
| ) |  |

Definition at line 33 of file keyboard_key_channel_handler_unittests.cc.

33 {
34 auto handled_message = CreateResponse(true);
35 auto unhandled_message = CreateResponse(false);
36 int received_scancode = 0;
37
38 TestBinaryMessenger messenger(
39 [&received_scancode, &handled_message, &unhandled_message](
40 const std::string& channel, const uint8_t* message,
41 size_t message_size, BinaryReply reply) {
42 if (channel == "flutter/keyevent") {
43 auto message_doc = JsonMessageCodec::GetInstance().DecodeMessage(
44 message, message_size);
45 received_scancode = (*message_doc)[kScanCodeKey].GetInt();
46 if (received_scancode == kHandledScanCode) {
47 reply(handled_message->data(), handled_message->size());
48 } else {
49 reply(unhandled_message->data(), unhandled_message->size());
50 }
51 }
52 });
53
54 KeyboardKeyChannelHandler handler(&messenger);
55 bool last_handled = false;
56
57 handler.KeyboardHook(
58 64, kHandledScanCode, WM_KEYDOWN, L'a', false, false,
59 [&last_handled](bool handled) { last_handled = handled; });
60 EXPECT_EQ(received_scancode, kHandledScanCode);
61 EXPECT_EQ(last_handled, true);
62
63 received_scancode = 0;
64
65 handler.KeyboardHook(
66 64, kUnhandledScanCode, WM_KEYDOWN, L'b', false, false,
67 [&last_handled](bool handled) { last_handled = handled; });
68 EXPECT_EQ(received_scancode, kUnhandledScanCode);
69 EXPECT_EQ(last_handled, false);
70
71 received_scancode = 0;
72
73 handler.KeyboardHook(
74 64, kHandledScanCode, WM_SYSKEYDOWN, L'a', false, false,
75 [&last_handled](bool handled) { last_handled = handled; });
76 EXPECT_EQ(received_scancode, kHandledScanCode);
77 EXPECT_EQ(last_handled, true);
78
79 received_scancode = 0;
80
81 handler.KeyboardHook(
82 64, kUnhandledScanCode, WM_SYSKEYDOWN, L'c', false, false,
83 [&last_handled](bool handled) { last_handled = handled; });
84 EXPECT_EQ(received_scancode, kUnhandledScanCode);
85 EXPECT_EQ(last_handled, false);
86 }

References flutter::MessageCodec< T >::DecodeMessage(), flutter::JsonMessageCodec::GetInstance(), and message.

## ◆ TEST() [97/171]

flutter::testing::TEST | ( | KeyboardKeyEmbedderHandlerTest | ,
|  | AbruptRepeatIsConvertedToDown |
| ) |  |

Definition at line 777 of file keyboard_key_embedder_handler_unittests.cc.

777 {
778 TestKeystate key_state;
779 std::vector<TestFlutterKeyEvent> results;
780 TestFlutterKeyEvent* event;
781 bool last_handled = false;
782
783 std::unique_ptr<KeyboardKeyEmbedderHandler> handler =
784 std::make_unique<KeyboardKeyEmbedderHandler>(
785 [&results](const FlutterKeyEvent& event,
786 FlutterKeyEventCallback callback, void* user_data) {
787 results.emplace_back(event, callback, user_data);
788 },
789 key_state.Getter(), DefaultMapVkToScan);
790 last_handled = false;
791
792 key_state.Set(kVirtualKeyA, true);
793
794 // Press A (with was_down true)
795 handler->KeyboardHook(
796 kVirtualKeyA, kScanCodeKeyA, WM_KEYDOWN, 'a', false, true,
797 [&last_handled](bool handled) { last_handled = handled; });
798 EXPECT_EQ(last_handled, false);
799 EXPECT_EQ(results.size(), 1);
800 event = &results[0];
801 EXPECT_EQ(event->type, kFlutterKeyEventTypeDown);
802 EXPECT_EQ(event->physical, kPhysicalKeyA);
803 EXPECT_EQ(event->logical, kLogicalKeyA);
804 EXPECT_STREQ(event->character, "a");
805 EXPECT_EQ(event->synthesized, false);
806
807 event->callback(true, event->user_data);
808 EXPECT_EQ(last_handled, true);
809 results.clear();
810
811 // Release A
812 last_handled = false;
813 key_state.Set(kVirtualKeyA, false);
814 handler->KeyboardHook(
815 kVirtualKeyA, kScanCodeKeyA, WM_KEYUP, 'a', false, true,
816 [&last_handled](bool handled) { last_handled = handled; });
817 EXPECT_EQ(last_handled, false);
818 EXPECT_EQ(results.size(), 1);
819 event = &results[0];
820 EXPECT_EQ(event->type, kFlutterKeyEventTypeUp);
821 EXPECT_EQ(event->physical, kPhysicalKeyA);
822 EXPECT_EQ(event->logical, kLogicalKeyA);
823 EXPECT_STREQ(event->character, "");
824 EXPECT_EQ(event->synthesized, false);
825
826 event->callback(true, event->user_data);
827 EXPECT_EQ(last_handled, true);
828 results.clear();
829 }
user_data
void * user_data
Definition: keyboard_key_embedder_handler_unittests.cc:48
callback
FlutterKeyEventCallback callback
Definition: keyboard_key_embedder_handler_unittests.cc:47

References callback, kScanCodeKeyA, kVirtualKeyA, and user_data.

## ◆ TEST() [98/171]

flutter::testing::TEST | ( | KeyboardKeyEmbedderHandlerTest | ,
|  | AbruptUpIsIgnored |
| ) |  |

Definition at line 831 of file keyboard_key_embedder_handler_unittests.cc.

831 {
832 TestKeystate key_state;
833 std::vector<TestFlutterKeyEvent> results;
834 TestFlutterKeyEvent* event;
835 bool last_handled = false;
836
837 std::unique_ptr<KeyboardKeyEmbedderHandler> handler =
838 std::make_unique<KeyboardKeyEmbedderHandler>(
839 [&results](const FlutterKeyEvent& event,
840 FlutterKeyEventCallback callback, void* user_data) {
841 results.emplace_back(event, callback, user_data);
842 },
843 key_state.Getter(), DefaultMapVkToScan);
844 last_handled = false;
845
846 // KeyA's key down is missed.
847
848 key_state.Set(kVirtualKeyA, true);
849
850 // Press A again (should yield an empty event)
851 last_handled = false;
852 handler->KeyboardHook(
853 kVirtualKeyA, kScanCodeKeyA, WM_KEYUP, 'a', false, true,
854 [&last_handled](bool handled) { last_handled = handled; });
855 EXPECT_EQ(last_handled, true);
856 EXPECT_EQ(results.size(), 1);
857 event = &results[0];
858 EXPECT_EQ(event->physical, 0);
859 EXPECT_EQ(event->logical, 0);
860 EXPECT_EQ(event->callback, nullptr);
861 results.clear();
862 }

References callback, kScanCodeKeyA, kVirtualKeyA, and user_data.

## ◆ TEST() [99/171]

flutter::testing::TEST | ( | KeyboardKeyEmbedderHandlerTest | ,
|  | BasicKeyPressingAndHolding |
| ) |  |

Definition at line 119 of file keyboard_key_embedder_handler_unittests.cc.

119 {
120 TestKeystate key_state;
121 std::vector<TestFlutterKeyEvent> results;
122 TestFlutterKeyEvent* event;
123 bool last_handled = false;
124
125 std::unique_ptr<KeyboardKeyEmbedderHandler> handler =
126 std::make_unique<KeyboardKeyEmbedderHandler>(
127 [&results](const FlutterKeyEvent& event,
128 FlutterKeyEventCallback callback, void* user_data) {
129 results.emplace_back(event, callback, user_data);
130 },
131 key_state.Getter(), DefaultMapVkToScan);
132
133 // Press KeyA.
134 handler->KeyboardHook(
135 kVirtualKeyA, kScanCodeKeyA, WM_KEYDOWN, 'a', false, false,
136 [&last_handled](bool handled) { last_handled = handled; });
137 EXPECT_EQ(last_handled, false);
138 EXPECT_EQ(results.size(), 1);
139 event = &results[0];
140 EXPECT_EQ(event->type, kFlutterKeyEventTypeDown);
141 EXPECT_EQ(event->physical, kPhysicalKeyA);
142 EXPECT_EQ(event->logical, kLogicalKeyA);
143 EXPECT_STREQ(event->character, "a");
144 EXPECT_EQ(event->synthesized, false);
145
146 event->callback(true, event->user_data);
147 EXPECT_EQ(last_handled, true);
148 results.clear();
149 key_state.Set(kVirtualKeyA, true);
150
151 // Hold KeyA.
152 handler->KeyboardHook(
153 kVirtualKeyA, kScanCodeKeyA, WM_KEYDOWN, 'a', false, true,
154 [&last_handled](bool handled) { last_handled = handled; });
155 EXPECT_EQ(last_handled, true);
156 EXPECT_EQ(results.size(), 1);
157 event = &results[0];
158 EXPECT_EQ(event->type, kFlutterKeyEventTypeRepeat);
159 EXPECT_EQ(event->physical, kPhysicalKeyA);
160 EXPECT_EQ(event->logical, kLogicalKeyA);
161 EXPECT_STREQ(event->character, "a");
162 EXPECT_EQ(event->synthesized, false);
163
164 event->callback(false, event->user_data);
165 EXPECT_EQ(last_handled, false);
166 results.clear();
167
168 // Release KeyA.
169 handler->KeyboardHook(
170 kVirtualKeyA, kScanCodeKeyA, WM_KEYUP, 0, false, true,
171 [&last_handled](bool handled) { last_handled = handled; });
172 EXPECT_EQ(results.size(), 1);
173 event = &results[0];
174 EXPECT_EQ(event->type, kFlutterKeyEventTypeUp);
175 EXPECT_EQ(event->physical, kPhysicalKeyA);
176 EXPECT_EQ(event->logical, kLogicalKeyA);
177 EXPECT_STREQ(event->character, "");
178 EXPECT_EQ(event->synthesized, false);
179 event->callback(false, event->user_data);
180 }

References callback, kScanCodeKeyA, kVirtualKeyA, and user_data.

## ◆ TEST() [100/171]

flutter::testing::TEST | ( | KeyboardKeyEmbedderHandlerTest | ,
|  | ConvertChar32ToUtf8 |
| ) |  |

Definition at line 90 of file keyboard_key_embedder_handler_unittests.cc.

90 {
91 std::string result;
92
93 result = ConvertChar32ToUtf8(0x0024);
94 EXPECT_EQ(result.length(), 1);
95 EXPECT_EQ(result[0], '\x24');
96
97 result = ConvertChar32ToUtf8(0x00A2);
98 EXPECT_EQ(result.length(), 2);
99 EXPECT_EQ(result[0], '\xC2');
100 EXPECT_EQ(result[1], '\xA2');
101
102 result = ConvertChar32ToUtf8(0x0939);
103 EXPECT_EQ(result.length(), 3);
104 EXPECT_EQ(result[0], '\xE0');
105 EXPECT_EQ(result[1], '\xA4');
106 EXPECT_EQ(result[2], '\xB9');
107
108 result = ConvertChar32ToUtf8(0x10348);
109 EXPECT_EQ(result.length(), 4);
110 EXPECT_EQ(result[0], '\xF0');
111 EXPECT_EQ(result[1], '\x90');
112 EXPECT_EQ(result[2], '\x8D');
113 EXPECT_EQ(result[3], '\x88');
114 }
flutter::ConvertChar32ToUtf8
std::string ConvertChar32ToUtf8(char32_t ch)
Definition: keyboard_key_embedder_handler.cc:38

References flutter::ConvertChar32ToUtf8().

## ◆ TEST() [101/171]

flutter::testing::TEST | ( | KeyboardKeyEmbedderHandlerTest | ,
|  | DoNotSynthesizeModifierDownWhenPressed |
| ) |  |

Definition at line 562 of file keyboard_key_embedder_handler_unittests.cc.

562 {
563 TestKeystate key_state;
564 std::vector<TestFlutterKeyEvent> results;
565 TestFlutterKeyEvent* event;
566 bool last_handled = false;
567
568 std::unique_ptr<KeyboardKeyEmbedderHandler> handler =
569 std::make_unique<KeyboardKeyEmbedderHandler>(
570 [&results](const FlutterKeyEvent& event,
571 FlutterKeyEventCallback callback, void* user_data) {
572 results.emplace_back(event, callback, user_data);
573 },
574 key_state.Getter(), DefaultMapVkToScan);
575
576 // Should not synthesize shift left key down event when shift left key
577 // is already pressed.
578 handler->KeyboardHook(
579 VK_LSHIFT, kScanCodeShiftLeft, WM_KEYDOWN, 0, false, true,
580 [&last_handled](bool handled) { last_handled = handled; });
581 results.clear();
582 handler->SyncModifiersIfNeeded(kShift);
583 EXPECT_EQ(results.size(), 0);
584
585 // Should not synthesize shift left key down event when shift right key
586 // is already pressed.
587 handler->KeyboardHook(
588 VK_RSHIFT, kScanCodeShiftRight, WM_KEYDOWN, 0, false, true,
589 [&last_handled](bool handled) { last_handled = handled; });
590 results.clear();
591 handler->SyncModifiersIfNeeded(kShift);
592 EXPECT_EQ(results.size(), 0);
593
594 // Should not synthesize control left key down event when control left key
595 // is already pressed.
596 handler->KeyboardHook(
597 VK_LCONTROL, kScanCodeControlLeft, WM_KEYDOWN, 0, false, true,
598 [&last_handled](bool handled) { last_handled = handled; });
599 results.clear();
600 handler->SyncModifiersIfNeeded(kControl);
601 EXPECT_EQ(results.size(), 0);
602
603 // Should not synthesize control left key down event when control right key
604 // is already pressed .
605 handler->KeyboardHook(
606 VK_RCONTROL, kScanCodeControlRight, WM_KEYDOWN, 0, true, true,
607 [&last_handled](bool handled) { last_handled = handled; });
608 results.clear();
609 handler->SyncModifiersIfNeeded(kControl);
610 EXPECT_EQ(results.size(), 0);
611 }
flutter::kShift
constexpr int kShift
Definition: keyboard_utils.h:14
flutter::kScanCodeShiftRight
constexpr int kScanCodeShiftRight
Definition: keyboard_utils.h:17
flutter::kScanCodeShiftLeft
constexpr int kScanCodeShiftLeft
Definition: keyboard_utils.h:16
flutter::kScanCodeControlRight
constexpr int kScanCodeControlRight
Definition: keyboard_utils.h:20
flutter::kScanCodeControlLeft
constexpr int kScanCodeControlLeft
Definition: keyboard_utils.h:19
flutter::kControl
constexpr int kControl
Definition: keyboard_utils.h:15

References callback, flutter::kControl, flutter::kScanCodeControlLeft, flutter::kScanCodeControlRight, flutter::kScanCodeShiftLeft, flutter::kScanCodeShiftRight, flutter::kShift, and user_data.

## ◆ TEST() [102/171]

flutter::testing::TEST | ( | KeyboardKeyEmbedderHandlerTest | ,
|  | DoNotSynthesizeModifierUpWhenNotPressed |
| ) |  |

Definition at line 696 of file keyboard_key_embedder_handler_unittests.cc.

696 {
697 TestKeystate key_state;
698 std::vector<TestFlutterKeyEvent> results;
699 TestFlutterKeyEvent* event;
700 bool last_handled = false;
701
702 std::unique_ptr<KeyboardKeyEmbedderHandler> handler =
703 std::make_unique<KeyboardKeyEmbedderHandler>(
704 [&results](const FlutterKeyEvent& event,
705 FlutterKeyEventCallback callback, void* user_data) {
706 results.emplace_back(event, callback, user_data);
707 },
708 key_state.Getter(), DefaultMapVkToScan);
709
710 // Should not synthesize up events when no modifier key is pressed
711 // in pressing state and modifiers state is zero.
712 handler->SyncModifiersIfNeeded(0);
713 EXPECT_EQ(results.size(), 0);
714 }

References callback, and user_data.

## ◆ TEST() [103/171]

flutter::testing::TEST | ( | KeyboardKeyEmbedderHandlerTest | ,
|  | ImeEventsAreIgnored |
| ) |  |

Definition at line 259 of file keyboard_key_embedder_handler_unittests.cc.

259 {
260 TestKeystate key_state;
261 std::vector<TestFlutterKeyEvent> results;
262 TestFlutterKeyEvent* event;
263 bool last_handled = false;
264
265 std::unique_ptr<KeyboardKeyEmbedderHandler> handler =
266 std::make_unique<KeyboardKeyEmbedderHandler>(
267 [&results](const FlutterKeyEvent& event,
268 FlutterKeyEventCallback callback, void* user_data) {
269 results.emplace_back(event, callback, user_data);
270 },
271 key_state.Getter(), DefaultMapVkToScan);
272
273 // Press A in an IME
274 last_handled = false;
275 handler->KeyboardHook(
276 VK_PROCESSKEY, kScanCodeKeyA, WM_KEYDOWN, 0, true, false,
277 [&last_handled](bool handled) { last_handled = handled; });
278 EXPECT_EQ(last_handled, true);
279
280 // The A key down should yield an empty event.
281 EXPECT_EQ(results.size(), 1);
282 event = &results[0];
283 EXPECT_EQ(event->physical, 0);
284 EXPECT_EQ(event->logical, 0);
285 EXPECT_EQ(event->callback, nullptr);
286 results.clear();
287
288 // Release A in an IME
289 last_handled = false;
290 handler->KeyboardHook(
291 // The up event for an IME press has a normal virtual key.
292 kVirtualKeyA, kScanCodeKeyA, WM_KEYUP, 0, true, true,
293 [&last_handled](bool handled) { last_handled = handled; });
294 EXPECT_EQ(last_handled, true);
295
296 // The A key up should yield an empty event.
297 EXPECT_EQ(results.size(), 1);
298 event = &results[0];
299 EXPECT_EQ(event->physical, 0);
300 EXPECT_EQ(event->logical, 0);
301 EXPECT_EQ(event->callback, nullptr);
302 results.clear();
303
304 // Press A out of an IME
305 key_state.Set(kVirtualKeyA, true);
306 last_handled = false;
307 handler->KeyboardHook(
308 kVirtualKeyA, kScanCodeKeyA, WM_KEYDOWN, 0, true, false,
309 [&last_handled](bool handled) { last_handled = handled; });
310 // Not decided yet
311 EXPECT_EQ(last_handled, false);
312 EXPECT_EQ(results.size(), 1);
313 event = &results[0];
314 event->callback(true, event->user_data);
315 EXPECT_EQ(last_handled, true);
316 results.clear();
317
318 last_handled = false;
319 key_state.Set(kVirtualKeyA, false);
320 handler->KeyboardHook(
321 kVirtualKeyA, kScanCodeKeyA, WM_KEYUP, 0, true, false,
322 [&last_handled](bool handled) { last_handled = handled; });
323 EXPECT_EQ(last_handled, false);
324 EXPECT_EQ(results.size(), 1);
325 event = &results[0];
326 event->callback(true, event->user_data);
327 EXPECT_EQ(last_handled, true);
328 }

References callback, kScanCodeKeyA, kVirtualKeyA, and user_data.

## ◆ TEST() [104/171]

flutter::testing::TEST | ( | KeyboardKeyEmbedderHandlerTest | ,
|  | ModifierKeysByExtendedBit |
| ) |  |

Definition at line 333 of file keyboard_key_embedder_handler_unittests.cc.

333 {
334 TestKeystate key_state;
335 std::vector<TestFlutterKeyEvent> results;
336 TestFlutterKeyEvent* event;
337 bool last_handled = false;
338
339 std::unique_ptr<KeyboardKeyEmbedderHandler> handler =
340 std::make_unique<KeyboardKeyEmbedderHandler>(
341 [&results](const FlutterKeyEvent& event,
342 FlutterKeyEventCallback callback, void* user_data) {
343 results.emplace_back(event, callback, user_data);
344 },
345 key_state.Getter(), DefaultMapVkToScan);
346
347 // Press Ctrl left.
348 last_handled = false;
349 key_state.Set(VK_LCONTROL, true);
350 handler->KeyboardHook(
351 VK_LCONTROL, kScanCodeControl, WM_KEYDOWN, 0, false, false,
352 [&last_handled](bool handled) { last_handled = handled; });
353 EXPECT_EQ(last_handled, false);
354 EXPECT_EQ(results.size(), 1);
355 event = &results[0];
356 EXPECT_EQ(event->type, kFlutterKeyEventTypeDown);
357 EXPECT_EQ(event->physical, kPhysicalControlLeft);
358 EXPECT_EQ(event->logical, kLogicalControlLeft);
359 EXPECT_STREQ(event->character, "");
360 EXPECT_EQ(event->synthesized, false);
361
362 event->callback(true, event->user_data);
363 EXPECT_EQ(last_handled, true);
364 results.clear();
365
366 // Press Ctrl right.
367 last_handled = false;
368 key_state.Set(VK_RCONTROL, true);
369 handler->KeyboardHook(
370 VK_RCONTROL, kScanCodeControl, WM_KEYDOWN, 0, true, true,
371 [&last_handled](bool handled) { last_handled = handled; });
372 EXPECT_EQ(last_handled, false);
373 EXPECT_EQ(results.size(), 1);
374 event = &results[0];
375 EXPECT_EQ(event->type, kFlutterKeyEventTypeDown);
376 EXPECT_EQ(event->physical, kPhysicalControlRight);
377 EXPECT_EQ(event->logical, kLogicalControlRight);
378 EXPECT_STREQ(event->character, "");
379 EXPECT_EQ(event->synthesized, false);
380
381 event->callback(true, event->user_data);
382 EXPECT_EQ(last_handled, true);
383 results.clear();
384
385 // Release Ctrl left.
386 last_handled = false;
387 key_state.Set(VK_LCONTROL, false);
388 handler->KeyboardHook(
389 VK_LCONTROL, kScanCodeControl, WM_KEYUP, 0, false, true,
390 [&last_handled](bool handled) { last_handled = handled; });
391 EXPECT_EQ(last_handled, false);
392 EXPECT_EQ(results.size(), 1);
393 event = &results[0];
394 EXPECT_EQ(event->type, kFlutterKeyEventTypeUp);
395 EXPECT_EQ(event->physical, kPhysicalControlLeft);
396 EXPECT_EQ(event->logical, kLogicalControlLeft);
397 EXPECT_STREQ(event->character, "");
398 EXPECT_EQ(event->synthesized, false);
399
400 event->callback(true, event->user_data);
401 EXPECT_EQ(last_handled, true);
402 results.clear();
403
404 // Release Ctrl right.
405 last_handled = false;
406 key_state.Set(VK_RCONTROL, false);
407 handler->KeyboardHook(
408 VK_RCONTROL, kScanCodeControl, WM_KEYUP, 0, true, true,
409 [&last_handled](bool handled) { last_handled = handled; });
410 EXPECT_EQ(last_handled, false);
411 EXPECT_EQ(results.size(), 1);
412 event = &results[0];
413 EXPECT_EQ(event->type, kFlutterKeyEventTypeUp);
414 EXPECT_EQ(event->physical, kPhysicalControlRight);
415 EXPECT_EQ(event->logical, kLogicalControlRight);
416 EXPECT_STREQ(event->character, "");
417 EXPECT_EQ(event->synthesized, false);
418
419 event->callback(true, event->user_data);
420 EXPECT_EQ(last_handled, true);
421 results.clear();
422 }

References callback, and user_data.

## ◆ TEST() [105/171]

flutter::testing::TEST | ( | KeyboardKeyEmbedderHandlerTest | ,
|  | ModifierKeysByVirtualKey |
| ) |  |

Definition at line 426 of file keyboard_key_embedder_handler_unittests.cc.

426 {
427 TestKeystate key_state;
428 std::vector<TestFlutterKeyEvent> results;
429 TestFlutterKeyEvent* event;
430 bool last_handled = false;
431
432 std::unique_ptr<KeyboardKeyEmbedderHandler> handler =
433 std::make_unique<KeyboardKeyEmbedderHandler>(
434 [&results](const FlutterKeyEvent& event,
435 FlutterKeyEventCallback callback, void* user_data) {
436 results.emplace_back(event, callback, user_data);
437 },
438 key_state.Getter(), DefaultMapVkToScan);
439
440 // Press Shift left.
441 last_handled = false;
442 key_state.Set(VK_LSHIFT, true);
443 handler->KeyboardHook(
444 VK_LSHIFT, kScanCodeShiftLeft, WM_KEYDOWN, 0, false, false,
445 [&last_handled](bool handled) { last_handled = handled; });
446 EXPECT_EQ(last_handled, false);
447 EXPECT_EQ(results.size(), 1);
448 event = &results[0];
449 EXPECT_EQ(event->type, kFlutterKeyEventTypeDown);
450 EXPECT_EQ(event->physical, kPhysicalShiftLeft);
451 EXPECT_EQ(event->logical, kLogicalShiftLeft);
452 EXPECT_STREQ(event->character, "");
453 EXPECT_EQ(event->synthesized, false);
454
455 event->callback(true, event->user_data);
456 EXPECT_EQ(last_handled, true);
457 results.clear();
458
459 // Press Shift right.
460 last_handled = false;
461 key_state.Set(VK_RSHIFT, true);
462 handler->KeyboardHook(
463 VK_RSHIFT, kScanCodeShiftRight, WM_KEYDOWN, 0, false, false,
464 [&last_handled](bool handled) { last_handled = handled; });
465 EXPECT_EQ(last_handled, false);
466 EXPECT_EQ(results.size(), 1);
467 event = &results[0];
468 EXPECT_EQ(event->type, kFlutterKeyEventTypeDown);
469 EXPECT_EQ(event->physical, kPhysicalShiftRight);
470 EXPECT_EQ(event->logical, kLogicalShiftRight);
471 EXPECT_STREQ(event->character, "");
472 EXPECT_EQ(event->synthesized, false);
473
474 event->callback(true, event->user_data);
475 EXPECT_EQ(last_handled, true);
476 results.clear();
477
478 // Release Shift left.
479 last_handled = false;
480 key_state.Set(VK_LSHIFT, false);
481 handler->KeyboardHook(
482 VK_LSHIFT, kScanCodeShiftLeft, WM_KEYUP, 0, false, true,
483 [&last_handled](bool handled) { last_handled = handled; });
484 EXPECT_EQ(last_handled, false);
485 EXPECT_EQ(results.size(), 1);
486 event = &results[0];
487 EXPECT_EQ(event->type, kFlutterKeyEventTypeUp);
488 EXPECT_EQ(event->physical, kPhysicalShiftLeft);
489 EXPECT_EQ(event->logical, kLogicalShiftLeft);
490 EXPECT_STREQ(event->character, "");
491 EXPECT_EQ(event->synthesized, false);
492
493 event->callback(true, event->user_data);
494 EXPECT_EQ(last_handled, true);
495 results.clear();
496
497 // Release Shift right.
498 last_handled = false;
499 key_state.Set(VK_RSHIFT, false);
500 handler->KeyboardHook(
501 VK_RSHIFT, kScanCodeShiftRight, WM_KEYUP, 0, false, true,
502 [&last_handled](bool handled) { last_handled = handled; });
503 EXPECT_EQ(last_handled, false);
504 EXPECT_EQ(results.size(), 1);
505 event = &results[0];
506 EXPECT_EQ(event->type, kFlutterKeyEventTypeUp);
507 EXPECT_EQ(event->physical, kPhysicalShiftRight);
508 EXPECT_EQ(event->logical, kLogicalShiftRight);
509 EXPECT_STREQ(event->character, "");
510 EXPECT_EQ(event->synthesized, false);
511
512 event->callback(true, event->user_data);
513 EXPECT_EQ(last_handled, true);
514 results.clear();
515 }

References callback, flutter::kScanCodeShiftLeft, flutter::kScanCodeShiftRight, and user_data.

## ◆ TEST() [106/171]

flutter::testing::TEST | ( | KeyboardKeyEmbedderHandlerTest | ,
|  | RepeatedDownIsIgnored |
| ) |  |

Definition at line 716 of file keyboard_key_embedder_handler_unittests.cc.

716 {
717 TestKeystate key_state;
718 std::vector<TestFlutterKeyEvent> results;
719 TestFlutterKeyEvent* event;
720 bool last_handled = false;
721
722 std::unique_ptr<KeyboardKeyEmbedderHandler> handler =
723 std::make_unique<KeyboardKeyEmbedderHandler>(
724 [&results](const FlutterKeyEvent& event,
725 FlutterKeyEventCallback callback, void* user_data) {
726 results.emplace_back(event, callback, user_data);
727 },
728 key_state.Getter(), DefaultMapVkToScan);
729 last_handled = false;
730
731 // Press A (should yield a normal event)
732 handler->KeyboardHook(
733 kVirtualKeyA, kScanCodeKeyA, WM_KEYDOWN, 'a', false, false,
734 [&last_handled](bool handled) { last_handled = handled; });
735 EXPECT_EQ(last_handled, false);
736 EXPECT_EQ(results.size(), 1);
737 event = &results[0];
738 EXPECT_EQ(event->type, kFlutterKeyEventTypeDown);
739 EXPECT_EQ(event->physical, kPhysicalKeyA);
740 EXPECT_EQ(event->logical, kLogicalKeyA);
741 EXPECT_STREQ(event->character, "a");
742 EXPECT_EQ(event->synthesized, false);
743
744 event->callback(true, event->user_data);
745 EXPECT_EQ(last_handled, true);
746 results.clear();
747
748 // KeyA's key up is missed.
749
750 // Press A again (should synthesize an up event followed by a new down).
751 last_handled = false;
752 handler->KeyboardHook(
753 kVirtualKeyA, kScanCodeKeyA, WM_KEYDOWN, 'a', false, false,
754 [&last_handled](bool handled) { last_handled = handled; });
755 EXPECT_EQ(last_handled, false);
756 ASSERT_EQ(results.size(), 2u);
757
758 event = &results[0];
759 EXPECT_EQ(event->type, kFlutterKeyEventTypeUp);
760 EXPECT_EQ(event->physical, kPhysicalKeyA);
761 EXPECT_EQ(event->logical, kLogicalKeyA);
762 EXPECT_STREQ(event->character, "");
763 EXPECT_EQ(event->synthesized, true);
764 EXPECT_EQ(event->callback, nullptr);
765
766 event = &results[1];
767 EXPECT_EQ(event->type, kFlutterKeyEventTypeDown);
768 EXPECT_EQ(event->physical, kPhysicalKeyA);
769 EXPECT_EQ(event->logical, kLogicalKeyA);
770 EXPECT_STREQ(event->character, "a");
771 EXPECT_EQ(event->synthesized, false);
772 event->callback(true, event->user_data);
773 EXPECT_EQ(last_handled, true);
774 results.clear();
775 }

References callback, kScanCodeKeyA, kVirtualKeyA, and user_data.

## ◆ TEST() [107/171]

flutter::testing::TEST | ( | KeyboardKeyEmbedderHandlerTest | ,
|  | SynthesizeForDesyncPressingState |
| ) |  |

Definition at line 864 of file keyboard_key_embedder_handler_unittests.cc.

864 {
865 TestKeystate key_state;
866 std::vector<TestFlutterKeyEvent> results;
867 TestFlutterKeyEvent* event;
868 bool last_handled = false;
869
870 std::unique_ptr<KeyboardKeyEmbedderHandler> handler =
871 std::make_unique<KeyboardKeyEmbedderHandler>(
872 [&results](const FlutterKeyEvent& event,
873 FlutterKeyEventCallback callback, void* user_data) {
874 results.emplace_back(event, callback, user_data);
875 },
876 key_state.Getter(), DefaultMapVkToScan);
877
878 // A key down of control left is missed.
879 key_state.Set(VK_LCONTROL, true);
880
881 // Send a normal event
882 key_state.Set(kVirtualKeyA, true);
883 handler->KeyboardHook(
884 kVirtualKeyA, kScanCodeKeyA, WM_KEYDOWN, 'a', false, false,
885 [&last_handled](bool handled) { last_handled = handled; });
886 EXPECT_EQ(last_handled, false);
887 EXPECT_EQ(results.size(), 2);
888 event = &results[0];
889 EXPECT_EQ(event->type, kFlutterKeyEventTypeDown);
890 EXPECT_EQ(event->physical, kPhysicalControlLeft);
891 EXPECT_EQ(event->logical, kLogicalControlLeft);
892 EXPECT_STREQ(event->character, "");
893 EXPECT_EQ(event->synthesized, true);
894 EXPECT_EQ(event->callback, nullptr);
895
896 event = &results[1];
897 EXPECT_EQ(event->type, kFlutterKeyEventTypeDown);
898 EXPECT_EQ(event->physical, kPhysicalKeyA);
899 EXPECT_EQ(event->logical, kLogicalKeyA);
900 EXPECT_STREQ(event->character, "a");
901 EXPECT_EQ(event->synthesized, false);
902
903 last_handled = true;
904 event->callback(false, event->user_data);
905 EXPECT_EQ(last_handled, false);
906 results.clear();
907
908 // A key down of control right is missed.
909 key_state.Set(VK_LCONTROL, false);
910
911 // Hold KeyA.
912 handler->KeyboardHook(
913 kVirtualKeyA, kScanCodeKeyA, WM_KEYDOWN, 'a', false, true,
914 [&last_handled](bool handled) { last_handled = handled; });
915 EXPECT_EQ(last_handled, false);
916 EXPECT_EQ(results.size(), 2);
917 event = &results[0];
918 EXPECT_EQ(event->type, kFlutterKeyEventTypeUp);
919 EXPECT_EQ(event->physical, kPhysicalControlLeft);
920 EXPECT_EQ(event->logical, kLogicalControlLeft);
921 EXPECT_STREQ(event->character, "");
922 EXPECT_EQ(event->synthesized, true);
923 EXPECT_EQ(event->callback, nullptr);
924
925 event = &results[1];
926 EXPECT_EQ(event->type, kFlutterKeyEventTypeRepeat);
927 EXPECT_EQ(event->physical, kPhysicalKeyA);
928 EXPECT_EQ(event->logical, kLogicalKeyA);
929 EXPECT_STREQ(event->character, "a");
930 EXPECT_EQ(event->synthesized, false);
931
932 last_handled = true;
933 event->callback(false, event->user_data);
934 EXPECT_EQ(last_handled, false);
935 results.clear();
936
937 // Release KeyA.
938 key_state.Set(kVirtualKeyA, false);
939 handler->KeyboardHook(
940 kVirtualKeyA, kScanCodeKeyA, WM_KEYUP, 0, false, true,
941 [&last_handled](bool handled) { last_handled = handled; });
942 EXPECT_EQ(results.size(), 1);
943 event = &results[0];
944 EXPECT_EQ(event->type, kFlutterKeyEventTypeUp);
945 EXPECT_EQ(event->physical, kPhysicalKeyA);
946 EXPECT_EQ(event->logical, kLogicalKeyA);
947 EXPECT_STREQ(event->character, "");
948 EXPECT_EQ(event->synthesized, false);
949 event->callback(false, event->user_data);
950 }

References callback, kScanCodeKeyA, kVirtualKeyA, and user_data.

## ◆ TEST() [108/171]

flutter::testing::TEST | ( | KeyboardKeyEmbedderHandlerTest | ,
|  | SynthesizeForDesyncToggledState |
| ) |  |

Definition at line 952 of file keyboard_key_embedder_handler_unittests.cc.

952 {
953 TestKeystate key_state;
954 std::vector<TestFlutterKeyEvent> results;
955 TestFlutterKeyEvent* event;
956 bool last_handled = false;
957
958 std::unique_ptr<KeyboardKeyEmbedderHandler> handler =
959 std::make_unique<KeyboardKeyEmbedderHandler>(
960 [&results](const FlutterKeyEvent& event,
961 FlutterKeyEventCallback callback, void* user_data) {
962 results.emplace_back(event, callback, user_data);
963 },
964 key_state.Getter(), DefaultMapVkToScan);
965
966 // The NumLock is desynchronized by toggled on
967 key_state.Set(VK_NUMLOCK, false, true);
968
969 // Send a normal event
970 key_state.Set(kVirtualKeyA, true);
971 handler->KeyboardHook(
972 kVirtualKeyA, kScanCodeKeyA, WM_KEYDOWN, 'a', false, false,
973 [&last_handled](bool handled) { last_handled = handled; });
974 EXPECT_EQ(last_handled, false);
975 EXPECT_EQ(results.size(), 3);
976 event = &results[0];
977 EXPECT_EQ(event->type, kFlutterKeyEventTypeDown);
978 EXPECT_EQ(event->physical, kPhysicalNumLock);
979 EXPECT_EQ(event->logical, kLogicalNumLock);
980 EXPECT_STREQ(event->character, "");
981 EXPECT_EQ(event->synthesized, true);
982
983 event = &results[1];
984 EXPECT_EQ(event->type, kFlutterKeyEventTypeUp);
985 EXPECT_EQ(event->physical, kPhysicalNumLock);
986 EXPECT_EQ(event->logical, kLogicalNumLock);
987 EXPECT_STREQ(event->character, "");
988 EXPECT_EQ(event->synthesized, true);
989
990 event = &results[2];
991 EXPECT_EQ(event->type, kFlutterKeyEventTypeDown);
992 EXPECT_EQ(event->physical, kPhysicalKeyA);
993 EXPECT_EQ(event->logical, kLogicalKeyA);
994 EXPECT_STREQ(event->character, "a");
995 EXPECT_EQ(event->synthesized, false);
996
997 event->callback(true, event->user_data);
998 EXPECT_EQ(last_handled, true);
999 results.clear();
1000
1001 // Test if the NumLock is mis-toggled while it should also be pressed
1002 key_state.Set(VK_NUMLOCK, true, true);
1003
1004 // Send a normal event
1005 handler->KeyboardHook(
1006 kVirtualKeyA, kScanCodeKeyA, WM_KEYDOWN, 'a', false, true,
1007 [&last_handled](bool handled) { last_handled = handled; });
1008 EXPECT_EQ(last_handled, true);
1009 EXPECT_EQ(results.size(), 2);
1010 event = &results[0];
1011 EXPECT_EQ(event->type, kFlutterKeyEventTypeDown);
1012 EXPECT_EQ(event->physical, kPhysicalNumLock);
1013 EXPECT_EQ(event->logical, kLogicalNumLock);
1014 EXPECT_STREQ(event->character, "");
1015 EXPECT_EQ(event->synthesized, true);
1016
1017 event = &results[1];
1018 EXPECT_EQ(event->type, kFlutterKeyEventTypeRepeat);
1019 EXPECT_EQ(event->physical, kPhysicalKeyA);
1020 EXPECT_EQ(event->logical, kLogicalKeyA);
1021 EXPECT_STREQ(event->character, "a");
1022 EXPECT_EQ(event->synthesized, false);
1023
1024 event->callback(false, event->user_data);
1025 EXPECT_EQ(last_handled, false);
1026 results.clear();
1027
1028 // Numlock is pressed at this moment.
1029
1030 // Test if the NumLock is mis-toggled while it should also be released
1031 key_state.Set(VK_NUMLOCK, false, false);
1032
1033 // Send a normal event
1034 key_state.Set(kVirtualKeyA, false);
1035 handler->KeyboardHook(
1036 kVirtualKeyA, kScanCodeKeyA, WM_KEYUP, 0, false, true,
1037 [&last_handled](bool handled) { last_handled = handled; });
1038 EXPECT_EQ(results.size(), 4);
1039 event = &results[0];
1040 EXPECT_EQ(event->type, kFlutterKeyEventTypeUp);
1041 EXPECT_EQ(event->physical, kPhysicalNumLock);
1042 EXPECT_EQ(event->logical, kLogicalNumLock);
1043 EXPECT_STREQ(event->character, "");
1044 EXPECT_EQ(event->synthesized, true);
1045 EXPECT_EQ(event->callback, nullptr);
1046
1047 event = &results[1];
1048 EXPECT_EQ(event->type, kFlutterKeyEventTypeDown);
1049 EXPECT_EQ(event->physical, kPhysicalNumLock);
1050 EXPECT_EQ(event->logical, kLogicalNumLock);
1051 EXPECT_STREQ(event->character, "");
1052 EXPECT_EQ(event->synthesized, true);
1053 EXPECT_EQ(event->callback, nullptr);
1054
1055 event = &results[2];
1056 EXPECT_EQ(event->type, kFlutterKeyEventTypeUp);
1057 EXPECT_EQ(event->physical, kPhysicalNumLock);
1058 EXPECT_EQ(event->logical, kLogicalNumLock);
1059 EXPECT_STREQ(event->character, "");
1060 EXPECT_EQ(event->synthesized, true);
1061 EXPECT_EQ(event->callback, nullptr);
1062
1063 event = &results[3];
1064 EXPECT_EQ(event->type, kFlutterKeyEventTypeUp);
1065 EXPECT_EQ(event->physical, kPhysicalKeyA);
1066 EXPECT_EQ(event->logical, kLogicalKeyA);
1067 EXPECT_STREQ(event->character, "");
1068 EXPECT_EQ(event->synthesized, false);
1069 event->callback(false, event->user_data);
1070 }

References callback, kScanCodeKeyA, kVirtualKeyA, and user_data.

## ◆ TEST() [109/171]

flutter::testing::TEST | ( | KeyboardKeyEmbedderHandlerTest | ,
|  | SynthesizeForDesyncToggledStateByItselfsDown |
| ) |  |

Definition at line 1132 of file keyboard_key_embedder_handler_unittests.cc.

1133 {
1134 TestKeystate key_state;
1135 std::vector<TestFlutterKeyEvent> results;
1136 TestFlutterKeyEvent* event;
1137 bool last_handled = false;
1138
1139 // NumLock is started up and disabled
1140 key_state.Set(VK_NUMLOCK, false, false);
1141 std::unique_ptr<KeyboardKeyEmbedderHandler> handler =
1142 std::make_unique<KeyboardKeyEmbedderHandler>(
1143 [&results](const FlutterKeyEvent& event,
1144 FlutterKeyEventCallback callback, void* user_data) {
1145 results.emplace_back(event, callback, user_data);
1146 },
1147 key_state.Getter(), DefaultMapVkToScan);
1148
1149 // NumLock is toggled somewhere else
1150 // key_state.Set(VK_NUMLOCK, false, true);
1151
1152 // NumLock is pressed
1153 key_state.Set(VK_NUMLOCK, true, false);
1154 handler->KeyboardHook(
1155 VK_NUMLOCK, kScanCodeNumLock, WM_KEYDOWN, 0, true, false,
1156 [&last_handled](bool handled) { last_handled = handled; });
1157 EXPECT_EQ(last_handled, false);
1158 // 4 total events should be fired:
1159 // Pre-synchronization toggle, pre-sync press,
1160 // main event, and post-sync press.
1161 EXPECT_EQ(results.size(), 4);
1162 event = &results[0];
1163 EXPECT_EQ(event->type, kFlutterKeyEventTypeDown);
1164 EXPECT_EQ(event->physical, kPhysicalNumLock);
1165 EXPECT_EQ(event->logical, kLogicalNumLock);
1166 EXPECT_STREQ(event->character, "");
1167 EXPECT_EQ(event->synthesized, true);
1168 EXPECT_EQ(event->callback, nullptr);
1169
1170 event = &results[1];
1171 EXPECT_EQ(event->type, kFlutterKeyEventTypeUp);
1172 EXPECT_EQ(event->physical, kPhysicalNumLock);
1173 EXPECT_EQ(event->logical, kLogicalNumLock);
1174 EXPECT_STREQ(event->character, "");
1175 EXPECT_EQ(event->synthesized, true);
1176 EXPECT_EQ(event->callback, nullptr);
1177
1178 event = &results[2];
1179 EXPECT_EQ(event->type, kFlutterKeyEventTypeDown);
1180 EXPECT_EQ(event->physical, kPhysicalNumLock);
1181 EXPECT_EQ(event->logical, kLogicalNumLock);
1182 EXPECT_STREQ(event->character, "");
1183 EXPECT_EQ(event->synthesized, false);
1184
1185 last_handled = false;
1186 event->callback(true, event->user_data);
1187 EXPECT_EQ(last_handled, true);
1188 }

References callback, and user_data.

## ◆ TEST() [110/171]

flutter::testing::TEST | ( | KeyboardKeyEmbedderHandlerTest | ,
|  | SynthesizeForDesyncToggledStateByItselfsUp |
| ) |  |

Definition at line 1072 of file keyboard_key_embedder_handler_unittests.cc.

1073 {
1074 TestKeystate key_state;
1075 std::vector<TestFlutterKeyEvent> results;
1076 TestFlutterKeyEvent* event;
1077 bool last_handled = false;
1078
1079 std::unique_ptr<KeyboardKeyEmbedderHandler> handler =
1080 std::make_unique<KeyboardKeyEmbedderHandler>(
1081 [&results](const FlutterKeyEvent& event,
1082 FlutterKeyEventCallback callback, void* user_data) {
1083 results.emplace_back(event, callback, user_data);
1084 },
1085 key_state.Getter(), DefaultMapVkToScan);
1086
1087 // When NumLock is down
1088 key_state.Set(VK_NUMLOCK, true, true);
1089 handler->KeyboardHook(
1090 VK_NUMLOCK, kScanCodeNumLock, WM_KEYDOWN, 0, true, false,
1091 [&last_handled](bool handled) { last_handled = handled; });
1092 event = &results.back();
1093 event->callback(false, event->user_data);
1094 results.clear();
1095
1096 // Numlock is desynchronized by being off and released
1097 key_state.Set(VK_NUMLOCK, false, false);
1098 // Send a NumLock key up
1099 handler->KeyboardHook(
1100 VK_NUMLOCK, kScanCodeNumLock, WM_KEYUP, 0, true, true,
1101 [&last_handled](bool handled) { last_handled = handled; });
1102 EXPECT_EQ(last_handled, false);
1103 EXPECT_EQ(results.size(), 3);
1104 event = &results[0];
1105 EXPECT_EQ(event->type, kFlutterKeyEventTypeUp);
1106 EXPECT_EQ(event->physical, kPhysicalNumLock);
1107 EXPECT_EQ(event->logical, kLogicalNumLock);
1108 EXPECT_STREQ(event->character, "");
1109 EXPECT_EQ(event->synthesized, true);
1110 EXPECT_EQ(event->callback, nullptr);
1111
1112 event = &results[1];
1113 EXPECT_EQ(event->type, kFlutterKeyEventTypeDown);
1114 EXPECT_EQ(event->physical, kPhysicalNumLock);
1115 EXPECT_EQ(event->logical, kLogicalNumLock);
1116 EXPECT_STREQ(event->character, "");
1117 EXPECT_EQ(event->synthesized, true);
1118 EXPECT_EQ(event->callback, nullptr);
1119
1120 event = &results[2];
1121 EXPECT_EQ(event->type, kFlutterKeyEventTypeUp);
1122 EXPECT_EQ(event->physical, kPhysicalNumLock);
1123 EXPECT_EQ(event->logical, kLogicalNumLock);
1124 EXPECT_STREQ(event->character, "");
1125 EXPECT_EQ(event->synthesized, false);
1126
1127 last_handled = false;
1128 event->callback(true, event->user_data);
1129 EXPECT_EQ(last_handled, true);
1130 }

References callback, and user_data.

## ◆ TEST() [111/171]

flutter::testing::TEST | ( | KeyboardKeyEmbedderHandlerTest | ,
|  | SynthesizeModifierLeftKeyDownWhenNotPressed |
| ) |  |

Definition at line 519 of file keyboard_key_embedder_handler_unittests.cc.

520 {
521 TestKeystate key_state;
522 std::vector<TestFlutterKeyEvent> results;
523 TestFlutterKeyEvent* event;
524 bool last_handled = false;
525
526 std::unique_ptr<KeyboardKeyEmbedderHandler> handler =
527 std::make_unique<KeyboardKeyEmbedderHandler>(
528 [&results](const FlutterKeyEvent& event,
529 FlutterKeyEventCallback callback, void* user_data) {
530 results.emplace_back(event, callback, user_data);
531 },
532 key_state.Getter(), DefaultMapVkToScan);
533
534 // Should synthesize shift left key down event.
535 handler->SyncModifiersIfNeeded(kShift);
536 EXPECT_EQ(results.size(), 1);
537 event = &results[0];
538 EXPECT_EQ(event->type, kFlutterKeyEventTypeDown);
539 EXPECT_EQ(event->physical, kPhysicalShiftLeft);
540 EXPECT_EQ(event->logical, kLogicalShiftLeft);
541 EXPECT_STREQ(event->character, "");
542 EXPECT_EQ(event->synthesized, true);
543 results.clear();
544
545 // Clear the pressing state.
546 handler->SyncModifiersIfNeeded(0);
547 results.clear();
548
549 // Should synthesize control left key down event.
550 handler->SyncModifiersIfNeeded(kControl);
551 EXPECT_EQ(results.size(), 1);
552 event = &results[0];
553 EXPECT_EQ(event->type, kFlutterKeyEventTypeDown);
554 EXPECT_EQ(event->physical, kPhysicalControlLeft);
555 EXPECT_EQ(event->logical, kLogicalControlLeft);
556 EXPECT_STREQ(event->character, "");
557 EXPECT_EQ(event->synthesized, true);
558 }

References callback, flutter::kControl, flutter::kShift, and user_data.

## ◆ TEST() [112/171]

flutter::testing::TEST | ( | KeyboardKeyEmbedderHandlerTest | ,
|  | SynthesizeModifierUpWhenPressed |
| ) |  |

Definition at line 615 of file keyboard_key_embedder_handler_unittests.cc.

615 {
616 TestKeystate key_state;
617 std::vector<TestFlutterKeyEvent> results;
618 TestFlutterKeyEvent* event;
619 bool last_handled = false;
620
621 std::unique_ptr<KeyboardKeyEmbedderHandler> handler =
622 std::make_unique<KeyboardKeyEmbedderHandler>(
623 [&results](const FlutterKeyEvent& event,
624 FlutterKeyEventCallback callback, void* user_data) {
625 results.emplace_back(event, callback, user_data);
626 },
627 key_state.Getter(), DefaultMapVkToScan);
628
629 // Should synthesize shift left key up event when shift left key is
630 // already pressed and modifiers state is zero.
631 handler->KeyboardHook(
632 VK_LSHIFT, kScanCodeShiftLeft, WM_KEYDOWN, 0, false, true,
633 [&last_handled](bool handled) { last_handled = handled; });
634 results.clear();
635 handler->SyncModifiersIfNeeded(0);
636 EXPECT_EQ(results.size(), 1);
637 event = &results[0];
638 EXPECT_EQ(event->type, kFlutterKeyEventTypeUp);
639 EXPECT_EQ(event->physical, kPhysicalShiftLeft);
640 EXPECT_EQ(event->logical, kLogicalShiftLeft);
641 EXPECT_STREQ(event->character, "");
642 EXPECT_EQ(event->synthesized, true);
643 results.clear();
644
645 // Should synthesize shift right key up event when shift right key is
646 // already pressed and modifiers state is zero.
647 handler->KeyboardHook(
648 VK_RSHIFT, kScanCodeShiftRight, WM_KEYDOWN, 0, false, true,
649 [&last_handled](bool handled) { last_handled = handled; });
650 results.clear();
651 handler->SyncModifiersIfNeeded(0);
652 EXPECT_EQ(results.size(), 1);
653 event = &results[0];
654 EXPECT_EQ(event->type, kFlutterKeyEventTypeUp);
655 EXPECT_EQ(event->physical, kPhysicalShiftRight);
656 EXPECT_EQ(event->logical, kLogicalShiftRight);
657 EXPECT_STREQ(event->character, "");
658 EXPECT_EQ(event->synthesized, true);
659 results.clear();
660
661 // Should synthesize control left key up event when control left key is
662 // already pressed and modifiers state is zero.
663 handler->KeyboardHook(
664 VK_LCONTROL, kScanCodeControlLeft, WM_KEYDOWN, 0, false, true,
665 [&last_handled](bool handled) { last_handled = handled; });
666 results.clear();
667 handler->SyncModifiersIfNeeded(0);
668 EXPECT_EQ(results.size(), 1);
669 event = &results[0];
670 EXPECT_EQ(event->type, kFlutterKeyEventTypeUp);
671 EXPECT_EQ(event->physical, kPhysicalControlLeft);
672 EXPECT_EQ(event->logical, kLogicalControlLeft);
673 EXPECT_STREQ(event->character, "");
674 EXPECT_EQ(event->synthesized, true);
675 results.clear();
676
677 // Should synthesize control right key up event when control right key is
678 // already pressed and modifiers state is zero.
679 handler->KeyboardHook(
680 VK_RCONTROL, kScanCodeControlRight, WM_KEYDOWN, 0, true, true,
681 [&last_handled](bool handled) { last_handled = handled; });
682 results.clear();
683 handler->SyncModifiersIfNeeded(0);
684 EXPECT_EQ(results.size(), 1);
685 event = &results[0];
686 EXPECT_EQ(event->type, kFlutterKeyEventTypeUp);
687 EXPECT_EQ(event->physical, kPhysicalControlRight);
688 EXPECT_EQ(event->logical, kLogicalControlRight);
689 EXPECT_STREQ(event->character, "");
690 EXPECT_EQ(event->synthesized, true);
691 results.clear();
692 }

References callback, flutter::kScanCodeControlLeft, flutter::kScanCodeControlRight, flutter::kScanCodeShiftLeft, flutter::kScanCodeShiftRight, and user_data.

## ◆ TEST() [113/171]

flutter::testing::TEST | ( | KeyboardKeyEmbedderHandlerTest | ,
|  | SynthesizeWithInitialTogglingState |
| ) |  |

Definition at line 1190 of file keyboard_key_embedder_handler_unittests.cc.

1190 {
1191 TestKeystate key_state;
1192 std::vector<TestFlutterKeyEvent> results;
1193 TestFlutterKeyEvent* event;
1194 bool last_handled = false;
1195
1196 // The app starts with NumLock toggled on
1197 key_state.Set(VK_NUMLOCK, false, true);
1198
1199 std::unique_ptr<KeyboardKeyEmbedderHandler> handler =
1200 std::make_unique<KeyboardKeyEmbedderHandler>(
1201 [&results](const FlutterKeyEvent& event,
1202 FlutterKeyEventCallback callback, void* user_data) {
1203 results.emplace_back(event, callback, user_data);
1204 },
1205 key_state.Getter(), DefaultMapVkToScan);
1206
1207 // NumLock key down
1208 key_state.Set(VK_NUMLOCK, true, false);
1209 handler->KeyboardHook(
1210 VK_NUMLOCK, kScanCodeNumLock, WM_KEYDOWN, 0, true, false,
1211 [&last_handled](bool handled) { last_handled = handled; });
1212 EXPECT_EQ(last_handled, false);
1213 EXPECT_EQ(results.size(), 1);
1214 event = &results[0];
1215 EXPECT_EQ(event->type, kFlutterKeyEventTypeDown);
1216 EXPECT_EQ(event->physical, kPhysicalNumLock);
1217 EXPECT_EQ(event->logical, kLogicalNumLock);
1218 EXPECT_STREQ(event->character, "");
1219 EXPECT_EQ(event->synthesized, false);
1220
1221 event->callback(true, event->user_data);
1222 EXPECT_EQ(last_handled, true);
1223 results.clear();
1224 }

References callback, and user_data.

## ◆ TEST() [114/171]

flutter::testing::TEST | ( | KeyboardKeyEmbedderHandlerTest | ,
|  | SysKeyPress |
| ) |  |

Definition at line 1226 of file keyboard_key_embedder_handler_unittests.cc.

1226 {
1227 TestKeystate key_state;
1228 std::vector<TestFlutterKeyEvent> results;
1229 TestFlutterKeyEvent* event;
1230 bool last_handled = false;
1231
1232 std::unique_ptr<KeyboardKeyEmbedderHandler> handler =
1233 std::make_unique<KeyboardKeyEmbedderHandler>(
1234 [&results](const FlutterKeyEvent& event,
1235 FlutterKeyEventCallback callback, void* user_data) {
1236 results.emplace_back(event, callback, user_data);
1237 },
1238 key_state.Getter(), DefaultMapVkToScan);
1239
1240 // Press KeyAltLeft.
1241 key_state.Set(VK_LMENU, true);
1242 handler->KeyboardHook(
1243 VK_LMENU, kScanCodeAltLeft, WM_SYSKEYDOWN, 0, false, false,
1244 [&last_handled](bool handled) { last_handled = handled; });
1245 EXPECT_EQ(last_handled, false);
1246 EXPECT_EQ(results.size(), 1);
1247 event = results.data();
1248 EXPECT_EQ(event->type, kFlutterKeyEventTypeDown);
1249 EXPECT_EQ(event->physical, kPhysicalAltLeft);
1250 EXPECT_EQ(event->logical, kLogicalAltLeft);
1251 EXPECT_STREQ(event->character, "");
1252 EXPECT_EQ(event->synthesized, false);
1253
1254 event->callback(true, event->user_data);
1255 EXPECT_EQ(last_handled, true);
1256 results.clear();
1257
1258 // Release KeyAltLeft.
1259 key_state.Set(VK_LMENU, false);
1260 handler->KeyboardHook(
1261 VK_LMENU, kScanCodeAltLeft, WM_SYSKEYUP, 0, false, true,
1262 [&last_handled](bool handled) { last_handled = handled; });
1263 EXPECT_EQ(results.size(), 1);
1264 event = results.data();
1265 EXPECT_EQ(event->type, kFlutterKeyEventTypeUp);
1266 EXPECT_EQ(event->physical, kPhysicalAltLeft);
1267 EXPECT_EQ(event->logical, kLogicalAltLeft);
1268 EXPECT_STREQ(event->character, "");
1269 EXPECT_EQ(event->synthesized, false);
1270 event->callback(false, event->user_data);
1271 }

References callback, and user_data.

## ◆ TEST() [115/171]

flutter::testing::TEST | ( | KeyboardKeyEmbedderHandlerTest | ,
|  | ToggleNumLockDuringNumpadPress |
| ) |  |

Definition at line 187 of file keyboard_key_embedder_handler_unittests.cc.

187 {
188 TestKeystate key_state;
189 std::vector<TestFlutterKeyEvent> results;
190 TestFlutterKeyEvent* event;
191 bool last_handled = false;
192
193 std::unique_ptr<KeyboardKeyEmbedderHandler> handler =
194 std::make_unique<KeyboardKeyEmbedderHandler>(
195 [&results](const FlutterKeyEvent& event,
196 FlutterKeyEventCallback callback, void* user_data) {
197 results.emplace_back(event, callback, user_data);
198 },
199 key_state.Getter(), DefaultMapVkToScan);
200
201 // Press NumPad1.
202 key_state.Set(VK_NUMPAD1, true);
203 handler->KeyboardHook(
204 VK_NUMPAD1, kScanCodeNumpad1, WM_KEYDOWN, 0, false, false,
205 [&last_handled](bool handled) { last_handled = handled; });
206 EXPECT_EQ(results.size(), 1);
207 event = &results[0];
208 EXPECT_EQ(event->type, kFlutterKeyEventTypeDown);
209 EXPECT_EQ(event->physical, kPhysicalNumpad1);
210 EXPECT_EQ(event->logical, kLogicalNumpad1);
211 // EXPECT_STREQ(event->character, "1"); // TODO
212 EXPECT_EQ(event->synthesized, false);
213 results.clear();
214
215 // Press NumLock.
216 key_state.Set(VK_NUMLOCK, true, true);
217 handler->KeyboardHook(
218 VK_NUMLOCK, kScanCodeNumLock, WM_KEYDOWN, 0, true, false,
219 [&last_handled](bool handled) { last_handled = handled; });
220 EXPECT_EQ(results.size(), 1);
221 event = &results[0];
222 EXPECT_EQ(event->type, kFlutterKeyEventTypeDown);
223 EXPECT_EQ(event->physical, kPhysicalNumLock);
224 EXPECT_EQ(event->logical, kLogicalNumLock);
225 EXPECT_STREQ(event->character, "");
226 EXPECT_EQ(event->synthesized, false);
227 results.clear();
228
229 // Release NumLock.
230 key_state.Set(VK_NUMLOCK, false, true);
231 handler->KeyboardHook(
232 VK_NUMLOCK, kScanCodeNumLock, WM_KEYUP, 0, true, true,
233 [&last_handled](bool handled) { last_handled = handled; });
234 EXPECT_EQ(results.size(), 1);
235 event = &results[0];
236 EXPECT_EQ(event->type, kFlutterKeyEventTypeUp);
237 EXPECT_EQ(event->physical, kPhysicalNumLock);
238 EXPECT_EQ(event->logical, kLogicalNumLock);
239 EXPECT_STREQ(event->character, "");
240 EXPECT_EQ(event->synthesized, false);
241 results.clear();
242
243 // Release NumPad1. (The logical key is now NumpadEnd)
244 handler->KeyboardHook(
245 VK_END, kScanCodeNumpad1, WM_KEYUP, 0, false, true,
246 [&last_handled](bool handled) { last_handled = handled; });
247 EXPECT_EQ(results.size(), 1);
248 event = &results[0];
249 EXPECT_EQ(event->type, kFlutterKeyEventTypeUp);
250 EXPECT_EQ(event->physical, kPhysicalNumpad1);
251 EXPECT_EQ(event->logical, kLogicalNumpad1);
252 EXPECT_STREQ(event->character, "");
253 EXPECT_EQ(event->synthesized, false);
254 results.clear();
255 }

References callback, and user_data.

## ◆ TEST() [116/171]

flutter::testing::TEST | ( | KeyboardKeyHandlerTest | ,
|  | HandlerGetPressedState |
| ) |  |

Definition at line 311 of file keyboard_key_handler_unittests.cc.

311 {
312 TestKeystate key_state;
313
314 TestBinaryMessenger messenger([](const std::string& channel,
315 const uint8_t* message, size_t message_size,
316 BinaryReply reply) {});
317 KeyboardKeyHandler handler(&messenger);
318
319 std::unique_ptr<KeyboardKeyEmbedderHandler> embedder_handler =
320 std::make_unique<KeyboardKeyEmbedderHandler>(
321 [](const FlutterKeyEvent& event, FlutterKeyEventCallback callback,
322 void* user_data) {},
323 key_state.Getter(), DefaultMapVkToScan);
324 handler.AddDelegate(std::move(embedder_handler));
325
326 // Dispatch a key event.
327 handler.KeyboardHook(kVirtualKeyA, kScanCodeKeyA, WM_KEYDOWN, 'a', false,
328 false, OnKeyEventResult);
329
330 std::map<uint64_t, uint64_t> pressed_state = handler.GetPressedState();
331 EXPECT_EQ(pressed_state.size(), 1);
332 EXPECT_EQ(pressed_state.at(kPhysicalKeyA), kLogicalKeyA);
333 }
user_data
void * user_data
Definition: keyboard_key_handler_unittests.cc:56
callback
FlutterKeyEventCallback callback
Definition: keyboard_key_handler_unittests.cc:55

References callback, kScanCodeKeyA, kVirtualKeyA, message, and user_data.

## ◆ TEST() [117/171]

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

Definition at line 335 of file keyboard_key_handler_unittests.cc.

335 {
336 TestKeystate key_state;
337 TestBinaryMessenger messenger;
338 KeyboardKeyHandler handler(&messenger);
339
340 std::unique_ptr<KeyboardKeyEmbedderHandler> embedder_handler =
341 std::make_unique<KeyboardKeyEmbedderHandler>(
342 [](const FlutterKeyEvent& event, FlutterKeyEventCallback callback,
343 void* user_data) {},
344 key_state.Getter(), DefaultMapVkToScan);
345 handler.AddDelegate(std::move(embedder_handler));
346 handler.InitKeyboardChannel();
347
348 // Dispatch a key event.
349 handler.KeyboardHook(kVirtualKeyA, kScanCodeKeyA, WM_KEYDOWN, 'a', false,
350 false, OnKeyEventResult);
351
352 bool success = false;
353
354 MethodResultFunctions<> result_handler(
355 [&success](const EncodableValue* result) {
356 success = true;
357 auto& map = std::get<EncodableMap>(*result);
358 EXPECT_EQ(map.size(), 1);
359 EncodableValue physical_value(static_cast<long long>(kPhysicalKeyA));
360 EncodableValue logical_value(static_cast<long long>(kLogicalKeyA));
361 EXPECT_EQ(map.at(physical_value), logical_value);
362 },
363 nullptr, nullptr);
364
365 SimulateKeyboardMessage(&messenger, kGetKeyboardStateMethod, nullptr,
366 &result_handler);
367 EXPECT_TRUE(success);
368 }

References flutter::KeyboardKeyHandler::AddDelegate(), callback, flutter::KeyboardKeyHandler::InitKeyboardChannel(), flutter::KeyboardKeyHandler::KeyboardHook(), kScanCodeKeyA, kVirtualKeyA, and user_data.

## ◆ TEST() [118/171]

flutter::testing::TEST | ( | KeyboardKeyHandlerTest | ,
|  | SingleDelegateWithAsyncResponds |
| ) |  |

Test 1: One event that is handled by the framework

Test 2: Two events that are unhandled by the framework

Definition at line 208 of file keyboard_key_handler_unittests.cc.

208 {
209 std::list<MockKeyHandlerDelegate::KeyboardHookCall> hook_history;
210
211 TestBinaryMessenger messenger([](const std::string& channel,
212 const uint8_t* message, size_t message_size,
213 BinaryReply reply) {});
214 KeyboardKeyHandler handler(&messenger);
215
216 // Add one delegate
217 auto delegate = std::make_unique<MockKeyHandlerDelegate>(1, &hook_history);
218 handler.AddDelegate(std::move(delegate));
219
220 /// Test 1: One event that is handled by the framework
221
222 // Dispatch a key event
223 handler.KeyboardHook(64, kHandledScanCode, WM_KEYDOWN, L'a', false, true,
224 OnKeyEventResult);
225 EXPECT_EQ(key_event_response, kNoResponse);
226 EXPECT_EQ(hook_history.size(), 1);
227 EXPECT_EQ(hook_history.back().delegate_id, 1);
228 EXPECT_EQ(hook_history.back().scancode, kHandledScanCode);
229 EXPECT_EQ(hook_history.back().was_down, true);
230
231 EXPECT_EQ(key_event_response, kNoResponse);
232 hook_history.back().callback(true);
233 EXPECT_EQ(key_event_response, kHandled);
234
235 key_event_response = kNoResponse;
236 hook_history.clear();
237
238 /// Test 2: Two events that are unhandled by the framework
239
240 handler.KeyboardHook(64, kHandledScanCode, WM_KEYDOWN, L'a', false, false,
241 OnKeyEventResult);
242 EXPECT_EQ(key_event_response, kNoResponse);
243 EXPECT_EQ(hook_history.size(), 1);
244 EXPECT_EQ(hook_history.back().delegate_id, 1);
245 EXPECT_EQ(hook_history.back().scancode, kHandledScanCode);
246 EXPECT_EQ(hook_history.back().was_down, false);
247
248 // Dispatch another key event
249 handler.KeyboardHook(65, kHandledScanCode2, WM_KEYUP, L'b', false, true,
250 OnKeyEventResult);
251 EXPECT_EQ(key_event_response, kNoResponse);
252 EXPECT_EQ(hook_history.size(), 2);
253 EXPECT_EQ(hook_history.back().delegate_id, 1);
254 EXPECT_EQ(hook_history.back().scancode, kHandledScanCode2);
255 EXPECT_EQ(hook_history.back().was_down, true);
256
257 // Resolve the second event first to test out-of-order response
258 hook_history.back().callback(false);
259 EXPECT_EQ(key_event_response, kUnhandled);
260 key_event_response = kNoResponse;
261
262 // Resolve the first event then
263 hook_history.front().callback(false);
264 EXPECT_EQ(key_event_response, kUnhandled);
265
266 hook_history.clear();
267 key_event_response = kNoResponse;
268 }
hook_history
std::list< KeyboardHookCall > * hook_history
Definition: keyboard_key_handler_unittests.cc:171

References hook_history, and message.

## ◆ TEST() [119/171]

flutter::testing::TEST | ( | KeyboardKeyHandlerTest | ,
|  | SingleDelegateWithSyncResponds |
| ) |  |

Test 1: One event that is handled by the framework

Test 2: An event unhandled by the framework

Definition at line 270 of file keyboard_key_handler_unittests.cc.

270 {
271 std::list<MockKeyHandlerDelegate::KeyboardHookCall> hook_history;
272
273 TestBinaryMessenger messenger([](const std::string& channel,
274 const uint8_t* message, size_t message_size,
275 BinaryReply reply) {});
276 KeyboardKeyHandler handler(&messenger);
277 // Add one delegate
278 auto delegate = std::make_unique<MockKeyHandlerDelegate>(1, &hook_history);
279 CallbackHandler& delegate_handler = delegate->callback_handler;
280 handler.AddDelegate(std::move(delegate));
281
282 /// Test 1: One event that is handled by the framework
283
284 // Dispatch a key event
285 delegate_handler = respond_true;
286 handler.KeyboardHook(64, kHandledScanCode, WM_KEYDOWN, L'a', false, false,
287 OnKeyEventResult);
288 EXPECT_EQ(key_event_response, kHandled);
289 EXPECT_EQ(hook_history.size(), 1);
290 EXPECT_EQ(hook_history.back().delegate_id, 1);
291 EXPECT_EQ(hook_history.back().scancode, kHandledScanCode);
292 EXPECT_EQ(hook_history.back().was_down, false);
293
294 hook_history.clear();
295
296 /// Test 2: An event unhandled by the framework
297
298 delegate_handler = respond_false;
299 handler.KeyboardHook(64, kHandledScanCode, WM_KEYDOWN, L'a', false, false,
300 OnKeyEventResult);
301 EXPECT_EQ(key_event_response, kUnhandled);
302 EXPECT_EQ(hook_history.size(), 1);
303 EXPECT_EQ(hook_history.back().delegate_id, 1);
304 EXPECT_EQ(hook_history.back().scancode, kHandledScanCode);
305 EXPECT_EQ(hook_history.back().was_down, false);
306
307 hook_history.clear();
308 key_event_response = kNoResponse;
309 }

References hook_history, and message.

## ◆ TEST() [120/171]

flutter::testing::TEST | ( | KeyboardWin32CommonTest | ,
|  | EncodeUtf16 |
| ) |  |

Definition at line 11 of file keyboard_utils_unittests.cc.

11 {
12 std::u16string result;
13
14 result = EncodeUtf16(0x24);
15 EXPECT_EQ(result.size(), 1);
16 EXPECT_EQ(result[0], 0x24);
17
18 result = EncodeUtf16(0x20AC);
19 EXPECT_EQ(result.size(), 1);
20 EXPECT_EQ(result[0], 0x20AC);
21
22 result = EncodeUtf16(0x10437);
23 EXPECT_EQ(result.size(), 2);
24 EXPECT_EQ(result[0], 0xD801);
25 EXPECT_EQ(result[1], 0xDC37);
26
27 result = EncodeUtf16(0x24B62);
28 EXPECT_EQ(result.size(), 2);
29 EXPECT_EQ(result[0], 0xD852);
30 EXPECT_EQ(result[1], 0xDF62);
31 }
flutter::EncodeUtf16
std::u16string EncodeUtf16(char32_t character)
Definition: keyboard_utils.cc:11

References flutter::EncodeUtf16().

## ◆ TEST() [121/171]

flutter::testing::TEST | ( | MockWindow | ,
|  | CreateDestroy |
| ) |  |

Definition at line 23 of file window_unittests.cc.

23 {
24 MockWindow window;
25 ASSERT_TRUE(TRUE);
26 }

## ◆ TEST() [122/171]

flutter::testing::TEST | ( | MockWindow | ,
|  | DISABLED_GetObjectUia |
| ) |  |

Definition at line 364 of file window_unittests.cc.

364 {
365 MockWindow window;
366 bool uia_called = false;
367 ON_CALL(window, OnGetObject)
368 .WillByDefault([&uia_called](UINT msg, WPARAM wpar, LPARAM lpar) {
369 #ifdef FLUTTER_ENGINE_USE_UIA
370 uia_called = true;
371 #endif // FLUTTER_ENGINE_USE_UIA
372 return static_cast<LRESULT>(0);
373 });
374 EXPECT_CALL(window, OnGetObject).Times(1);
375
376 window.InjectWindowMessage(WM_GETOBJECT, 0, UiaRootObjectId);
377
378 EXPECT_TRUE(uia_called);
379 }

## ◆ TEST() [123/171]

flutter::testing::TEST | ( | MockWindow | ,
|  | GetDpiAfterCreate |
| ) |  |

Definition at line 28 of file window_unittests.cc.

28 {
29 MockWindow window;
30 ASSERT_TRUE(window.GetDpi() > 0);
31 }

## ◆ TEST() [124/171]

flutter::testing::TEST | ( | MockWindow | ,
|  | HorizontalScroll |
| ) |  |

Definition at line 152 of file window_unittests.cc.

152 {
153 MockWindow window;
154 const int scroll_amount = 10;
155 // Vertical scroll should be passed along, adjusted for scroll tick size.
156 EXPECT_CALL(window, OnScroll(scroll_amount / 120.0, 0,
157 kFlutterPointerDeviceKindMouse, 0))
158 .Times(1);
159
160 window.InjectWindowMessage(WM_MOUSEHWHEEL, MAKEWPARAM(0, scroll_amount), 0);
161 }

## ◆ TEST() [125/171]

flutter::testing::TEST | ( | MockWindow | ,
|  | KeyDown |
| ) |  |

Definition at line 179 of file window_unittests.cc.

179 {
180 MockWindow window;
181 EXPECT_CALL(window, OnKey(_, _, _, _, _, _, _)).Times(1);
182 LPARAM lparam = CreateKeyEventLparam(42, false, false);
183 // send a "Shift" key down event.
184 window.InjectWindowMessage(WM_KEYDOWN, 16, lparam);
185 }

## ◆ TEST() [126/171]

flutter::testing::TEST | ( | MockWindow | ,
|  | KeyDownPrintable |
| ) |  |

Definition at line 211 of file window_unittests.cc.

211 {
212 MockWindow window;
213 LPARAM lparam = CreateKeyEventLparam(30, false, false);
214
215 auto respond_false = [](int key, int scancode, int action, char32_t character,
216 bool extended, bool was_down,
217 std::function<void(bool)> callback) {
218 callback(false);
219 };
220 EXPECT_CALL(window, OnKey(65, 30, WM_KEYDOWN, 0, false, false, _))
221 .Times(1)
222 .WillOnce(respond_false);
223 EXPECT_CALL(window, OnText(_)).Times(1);
224 std::array<Win32Message, 2> messages = {
225 Win32Message{WM_KEYDOWN, 65, lparam, kWmResultDontCheck},
226 Win32Message{WM_CHAR, 65, lparam, kWmResultDontCheck}};
227 window.InjectMessageList(2, messages.data());
228 }
extended
bool extended
Definition: keyboard_key_handler_unittests.cc:118
key
int key
Definition: keyboard_key_handler_unittests.cc:114
action
int action
Definition: keyboard_key_handler_unittests.cc:116
scancode
int scancode
Definition: keyboard_key_handler_unittests.cc:115
was_down
bool was_down
Definition: keyboard_key_handler_unittests.cc:119

References action, callback, character, extended, key, scancode, and was_down.

## ◆ TEST() [127/171]

flutter::testing::TEST | ( | MockWindow | ,
|  | KeyDownWithCtrl |
| ) |  |

Definition at line 230 of file window_unittests.cc.

230 {
231 MockWindow window;
232
233 // Simulate CONTROL pressed
234 std::array<BYTE, 256> keyboard_state;
235 keyboard_state[VK_CONTROL] = -1;
236 SetKeyboardState(keyboard_state.data());
237
238 LPARAM lparam = CreateKeyEventLparam(30, false, false);
239
240 // Expect OnKey, but not OnText, because Control + Key is not followed by
241 // WM_CHAR
242 EXPECT_CALL(window, OnKey(65, 30, WM_KEYDOWN, 0, false, false, _)).Times(1);
243 EXPECT_CALL(window, OnText(_)).Times(0);
244
245 window.InjectWindowMessage(WM_KEYDOWN, 65, lparam);
246
247 keyboard_state.fill(0);
248 SetKeyboardState(keyboard_state.data());
249 }

## ◆ TEST() [128/171]

flutter::testing::TEST | ( | MockWindow | ,
|  | KeyDownWithCtrlToggled |
| ) |  |

Definition at line 251 of file window_unittests.cc.

251 {
252 MockWindow window;
253
254 auto respond_false = [](int key, int scancode, int action, char32_t character,
255 bool extended, bool was_down,
256 std::function<void(bool)> callback) {
257 callback(false);
258 };
259
260 // Simulate CONTROL toggled
261 std::array<BYTE, 256> keyboard_state;
262 keyboard_state[VK_CONTROL] = 1;
263 SetKeyboardState(keyboard_state.data());
264
265 LPARAM lparam = CreateKeyEventLparam(30, false, false);
266
267 EXPECT_CALL(window, OnKey(65, 30, WM_KEYDOWN, 0, false, false, _))
268 .Times(1)
269 .WillOnce(respond_false);
270 EXPECT_CALL(window, OnText(_)).Times(1);
271
272 // send a "A" key down event.
273 Win32Message messages[] = {{WM_KEYDOWN, 65, lparam, kWmResultDontCheck},
274 {WM_CHAR, 65, lparam, kWmResultDontCheck}};
275 window.InjectMessageList(2, messages);
276
277 keyboard_state.fill(0);
278 SetKeyboardState(keyboard_state.data());
279 }

References action, callback, character, extended, key, scancode, and was_down.

## ◆ TEST() [129/171]

flutter::testing::TEST | ( | MockWindow | ,
|  | KeyUp |
| ) |  |

Definition at line 187 of file window_unittests.cc.

187 {
188 MockWindow window;
189 EXPECT_CALL(window, OnKey(_, _, _, _, _, _, _)).Times(1);
190 LPARAM lparam = CreateKeyEventLparam(42, false, true);
191 // send a "Shift" key up event.
192 window.InjectWindowMessage(WM_KEYUP, 16, lparam);
193 }

## ◆ TEST() [130/171]

flutter::testing::TEST | ( | MockWindow | ,
|  | MouseLeave |
| ) |  |

Definition at line 163 of file window_unittests.cc.

163 {
164 MockWindow window;
165 const double mouse_x = 10.0;
166 const double mouse_y = 20.0;
167
168 EXPECT_CALL(window, OnPointerMove(mouse_x, mouse_y,
169 kFlutterPointerDeviceKindMouse, 0, 0, 0, 0))
170 .Times(1);
171 EXPECT_CALL(window, OnPointerLeave(mouse_x, mouse_y,
172 kFlutterPointerDeviceKindMouse, 0))
173 .Times(1);
174
175 window.InjectWindowMessage(WM_MOUSEMOVE, 0, MAKELPARAM(mouse_x, mouse_y));
176 window.InjectWindowMessage(WM_MOUSELEAVE, 0, 0);
177 }

## ◆ TEST() [131/171]

flutter::testing::TEST | ( | MockWindow | ,
|  | OnImeCompositionClearChange |
| ) |  |

Definition at line 135 of file window_unittests.cc.

135 {
136 auto windows_proc_table = std::make_unique<MockWindowsProcTable>();
137 auto* text_input_manager = new MockTextInputManager();
138 std::unique_ptr<TextInputManager> text_input_manager_ptr(text_input_manager);
139 MockWindow window(std::move(windows_proc_table),
140 std::move(text_input_manager_ptr));
141 EXPECT_CALL(window, OnComposeChange(std::u16string(u""), 0)).Times(1);
142 EXPECT_CALL(window, OnComposeCommit()).Times(1);
143 ON_CALL(window, OnImeComposition)
144 .WillByDefault(Invoke(&window, &MockWindow::CallOnImeComposition));
145 EXPECT_CALL(window, OnImeComposition(_, _, _)).Times(1);
146
147 // send an IME_COMPOSITION event that contains both the result string and the
148 // composition string.
149 window.InjectWindowMessage(WM_IME_COMPOSITION, 0, 0);
150 }

## ◆ TEST() [132/171]

flutter::testing::TEST | ( | MockWindow | ,
|  | OnImeCompositionCompose |
| ) |  |

Definition at line 45 of file window_unittests.cc.

45 {
46 auto windows_proc_table = std::make_unique<MockWindowsProcTable>();
47 auto* text_input_manager = new MockTextInputManager();
48 std::unique_ptr<TextInputManager> text_input_manager_ptr(text_input_manager);
49 MockWindow window(std::move(windows_proc_table),
50 std::move(text_input_manager_ptr));
51 EXPECT_CALL(*text_input_manager, GetComposingString())
52 .WillRepeatedly(
53 Return(std::optional<std::u16string>(std::u16string(u"nihao"))));
54 EXPECT_CALL(*text_input_manager, GetResultString())
55 .WillRepeatedly(
56 Return(std::optional<std::u16string>(std::u16string(u"`}"))));
57 EXPECT_CALL(*text_input_manager, GetComposingCursorPosition())
58 .WillRepeatedly(Return((int)0));
59
60 EXPECT_CALL(window, OnComposeChange(std::u16string(u"nihao"), 0)).Times(1);
61 EXPECT_CALL(window, OnComposeChange(std::u16string(u"`}"), 0)).Times(0);
62 EXPECT_CALL(window, OnComposeCommit()).Times(0);
63 ON_CALL(window, OnImeComposition)
64 .WillByDefault(Invoke(&window, &MockWindow::CallOnImeComposition));
65 EXPECT_CALL(window, OnImeComposition(_, _, _)).Times(1);
66
67 // Send an IME_COMPOSITION event that contains just the composition string.
68 window.InjectWindowMessage(WM_IME_COMPOSITION, 0, GCS_COMPSTR);
69 }

## ◆ TEST() [133/171]

flutter::testing::TEST | ( | MockWindow | ,
|  | OnImeCompositionResult |
| ) |  |

Definition at line 71 of file window_unittests.cc.

71 {
72 auto windows_proc_table = std::make_unique<MockWindowsProcTable>();
73 auto* text_input_manager = new MockTextInputManager();
74 std::unique_ptr<TextInputManager> text_input_manager_ptr(text_input_manager);
75 MockWindow window(std::move(windows_proc_table),
76 std::move(text_input_manager_ptr));
77 EXPECT_CALL(*text_input_manager, GetComposingString())
78 .WillRepeatedly(
79 Return(std::optional<std::u16string>(std::u16string(u"nihao"))));
80 EXPECT_CALL(*text_input_manager, GetResultString())
81 .WillRepeatedly(
82 Return(std::optional<std::u16string>(std::u16string(u"`}"))));
83 EXPECT_CALL(*text_input_manager, GetComposingCursorPosition())
84 .WillRepeatedly(Return((int)0));
85
86 EXPECT_CALL(window, OnComposeChange(std::u16string(u"nihao"), 0)).Times(0);
87 EXPECT_CALL(window, OnComposeChange(std::u16string(u"`}"), 0)).Times(1);
88 EXPECT_CALL(window, OnComposeCommit()).Times(1);
89 ON_CALL(window, OnImeComposition)
90 .WillByDefault(Invoke(&window, &MockWindow::CallOnImeComposition));
91 EXPECT_CALL(window, OnImeComposition(_, _, _)).Times(1);
92
93 // Send an IME_COMPOSITION event that contains just the result string.
94 window.InjectWindowMessage(WM_IME_COMPOSITION, 0, GCS_RESULTSTR);
95 }

## ◆ TEST() [134/171]

flutter::testing::TEST | ( | MockWindow | ,
|  | OnImeCompositionResultAndCompose |
| ) |  |

Definition at line 97 of file window_unittests.cc.

97 {
98 auto windows_proc_table = std::make_unique<MockWindowsProcTable>();
99 auto* text_input_manager = new MockTextInputManager();
100 std::unique_ptr<TextInputManager> text_input_manager_ptr(text_input_manager);
101 MockWindow window(std::move(windows_proc_table),
102 std::move(text_input_manager_ptr));
103
104 // This situation is that Google Japanese Input finished composing "今日" in
105 // "今日は" but is still composing "は".
106 {
107 InSequence dummy;
108 EXPECT_CALL(*text_input_manager, GetResultString())
109 .WillRepeatedly(
110 Return(std::optional<std::u16string>(std::u16string(u"今日"))));
111 EXPECT_CALL(*text_input_manager, GetComposingString())
112 .WillRepeatedly(
113 Return(std::optional<std::u16string>(std::u16string(u"は"))));
114 }
115 {
116 InSequence dummy;
117 EXPECT_CALL(window, OnComposeChange(std::u16string(u"今日"), 0)).Times(1);
118 EXPECT_CALL(window, OnComposeCommit()).Times(1);
119 EXPECT_CALL(window, OnComposeChange(std::u16string(u"は"), 0)).Times(1);
120 }
121
122 EXPECT_CALL(*text_input_manager, GetComposingCursorPosition())
123 .WillRepeatedly(Return((int)0));
124
125 ON_CALL(window, OnImeComposition)
126 .WillByDefault(Invoke(&window, &MockWindow::CallOnImeComposition));
127 EXPECT_CALL(window, OnImeComposition(_, _, _)).Times(1);
128
129 // send an IME_COMPOSITION event that contains both the result string and the
130 // composition string.
131 window.InjectWindowMessage(WM_IME_COMPOSITION, 0,
132 GCS_COMPSTR | GCS_RESULTSTR);
133 }

## ◆ TEST() [135/171]

flutter::testing::TEST | ( | MockWindow | ,
|  | Paint |
| ) |  |

Definition at line 281 of file window_unittests.cc.

281 {
282 MockWindow window;
283 EXPECT_CALL(window, OnPaint()).Times(1);
284 window.InjectWindowMessage(WM_PAINT, 0, 0);
285 }

## ◆ TEST() [136/171]

flutter::testing::TEST | ( | MockWindow | ,
|  | PointerHitTest |
| ) |  |

Definition at line 288 of file window_unittests.cc.

288 {
289 UINT32 pointer_id = 123;
290 auto windows_proc_table = std::make_unique<MockWindowsProcTable>();
291 auto text_input_manager = std::make_unique<MockTextInputManager>();
292
293 EXPECT_CALL(*windows_proc_table, GetPointerType(Eq(pointer_id), _))
294 .Times(1)
295 .WillOnce([](UINT32 pointer_id, POINTER_INPUT_TYPE* type) {
296 *type = PT_POINTER;
297 return TRUE;
298 });
299
300 MockWindow window(std::move(windows_proc_table),
301 std::move(text_input_manager));
302
303 auto direct_manipulation =
304 std::make_unique<MockDirectManipulationOwner>(&window);
305
306 EXPECT_CALL(*direct_manipulation, SetContact).Times(0);
307
308 window.SetDirectManipulationOwner(std::move(direct_manipulation));
309 window.InjectWindowMessage(DM_POINTERHITTEST, MAKEWPARAM(pointer_id, 0), 0);
310 }
type
enum flutter::testing::@100::KeyboardChange::Type type

References type.

## ◆ TEST() [137/171]

flutter::testing::TEST | ( | MockWindow | ,
|  | SysKeyDown |
| ) |  |

Definition at line 195 of file window_unittests.cc.

195 {
196 MockWindow window;
197 EXPECT_CALL(window, OnKey(_, _, _, _, _, _, _)).Times(1);
198 LPARAM lparam = CreateKeyEventLparam(42, false, false);
199 // send a "Shift" key down event.
200 window.InjectWindowMessage(WM_SYSKEYDOWN, 16, lparam);
201 }

## ◆ TEST() [138/171]

flutter::testing::TEST | ( | MockWindow | ,
|  | SysKeyUp |
| ) |  |

Definition at line 203 of file window_unittests.cc.

203 {
204 MockWindow window;
205 EXPECT_CALL(window, OnKey(_, _, _, _, _, _, _)).Times(1);
206 LPARAM lparam = CreateKeyEventLparam(42, false, true);
207 // send a "Shift" key up event.
208 window.InjectWindowMessage(WM_SYSKEYUP, 16, lparam);
209 }

## ◆ TEST() [139/171]

flutter::testing::TEST | ( | MockWindow | ,
|  | TouchPadHitTest |
| ) |  |

Definition at line 313 of file window_unittests.cc.

313 {
314 UINT32 pointer_id = 123;
315 auto windows_proc_table = std::make_unique<MockWindowsProcTable>();
316 auto text_input_manager = std::make_unique<MockTextInputManager>();
317
318 EXPECT_CALL(*windows_proc_table, GetPointerType(Eq(pointer_id), _))
319 .Times(1)
320 .WillOnce([](UINT32 pointer_id, POINTER_INPUT_TYPE* type) {
321 *type = PT_TOUCHPAD;
322 return TRUE;
323 });
324
325 MockWindow window(std::move(windows_proc_table),
326 std::move(text_input_manager));
327
328 auto direct_manipulation =
329 std::make_unique<MockDirectManipulationOwner>(&window);
330
331 EXPECT_CALL(*direct_manipulation, SetContact(Eq(pointer_id))).Times(1);
332
333 window.SetDirectManipulationOwner(std::move(direct_manipulation));
334 window.InjectWindowMessage(DM_POINTERHITTEST, MAKEWPARAM(pointer_id, 0), 0);
335 }

References type.

## ◆ TEST() [140/171]

flutter::testing::TEST | ( | MockWindow | ,
|  | UnknownPointerTypeSkipsDirectManipulation |
| ) |  |

Definition at line 341 of file window_unittests.cc.

341 {
342 UINT32 pointer_id = 123;
343 auto windows_proc_table = std::make_unique<MockWindowsProcTable>();
344 auto text_input_manager = std::make_unique<MockTextInputManager>();
345
346 EXPECT_CALL(*windows_proc_table, GetPointerType(Eq(pointer_id), _))
347 .Times(1)
348 .WillOnce(
349 [](UINT32 pointer_id, POINTER_INPUT_TYPE* type) { return FALSE; });
350
351 MockWindow window(std::move(windows_proc_table),
352 std::move(text_input_manager));
353
354 auto direct_manipulation =
355 std::make_unique<MockDirectManipulationOwner>(&window);
356
357 EXPECT_CALL(*direct_manipulation, SetContact).Times(0);
358
359 window.SetDirectManipulationOwner(std::move(direct_manipulation));
360 window.InjectWindowMessage(DM_POINTERHITTEST, MAKEWPARAM(pointer_id, 0), 0);
361 }

References type.

## ◆ TEST() [141/171]

flutter::testing::TEST | ( | MockWindow | ,
|  | VerticalScroll |
| ) |  |

Definition at line 33 of file window_unittests.cc.

33 {
34 MockWindow window;
35 const int scroll_amount = 10;
36 // Vertical scroll should be passed along, adjusted for scroll tick size
37 // and direction.
38 EXPECT_CALL(window, OnScroll(0, -scroll_amount / 120.0,
39 kFlutterPointerDeviceKindMouse, 0))
40 .Times(1);
41
42 window.InjectWindowMessage(WM_MOUSEWHEEL, MAKEWPARAM(0, scroll_amount), 0);
43 }

## ◆ TEST() [142/171]

flutter::testing::TEST | ( | SequentialIdGeneratorTest | ,
|  | MaybeRemoveNumbers |
| ) |  |

Definition at line 35 of file sequential_id_generator_unittests.cc.

35 {
36 const uint32_t kMinId = 0;
37 const uint32_t kMaxId = 128;
38
39 SequentialIdGenerator generator(kMinId, kMaxId);
40
41 EXPECT_EQ(0U, generator.GetGeneratedId(42));
42
43 generator.ReleaseNumber(42);
44 EXPECT_FALSE(generator.HasGeneratedIdFor(42));
45 generator.ReleaseNumber(42);
46 }

References flutter::SequentialIdGenerator::GetGeneratedId(), flutter::SequentialIdGenerator::HasGeneratedIdFor(), and flutter::SequentialIdGenerator::ReleaseNumber().

## ◆ TEST() [143/171]

flutter::testing::TEST | ( | SequentialIdGeneratorTest | ,
|  | RemoveMultipleNumbers |
| ) |  |

Definition at line 12 of file sequential_id_generator_unittests.cc.

12 {
13 const uint32_t kMinId = 4;
14 const uint32_t kMaxId = 128;
15
16 SequentialIdGenerator generator(kMinId, kMaxId);
17
18 EXPECT_EQ(4U, generator.GetGeneratedId(45));
19 EXPECT_EQ(5U, generator.GetGeneratedId(55));
20 EXPECT_EQ(6U, generator.GetGeneratedId(15));
21
22 generator.ReleaseNumber(45);
23 EXPECT_FALSE(generator.HasGeneratedIdFor(45));
24 generator.ReleaseNumber(15);
25 EXPECT_FALSE(generator.HasGeneratedIdFor(15));
26
27 EXPECT_EQ(5U, generator.GetGeneratedId(55));
28 EXPECT_EQ(4U, generator.GetGeneratedId(12));
29
30 generator.ReleaseNumber(12);
31 generator.ReleaseNumber(55);
32 EXPECT_EQ(4U, generator.GetGeneratedId(0));
33 }

References flutter::SequentialIdGenerator::GetGeneratedId(), flutter::SequentialIdGenerator::HasGeneratedIdFor(), and flutter::SequentialIdGenerator::ReleaseNumber().

## ◆ TEST() [144/171]

flutter::testing::TEST | ( | SettingsPluginTest | ,
|  | HighContrastModeHonored |
| ) |  |

Definition at line 80 of file settings_plugin_unittests.cc.

80 {
81 int times = 0;
82 TestBinaryMessenger messenger(
83 [&times](const std::string& channel, const uint8_t* message,
84 size_t message_size, BinaryReply reply) {
85 ASSERT_EQ(channel, "flutter/settings");
86 times++;
87 });
88 ::testing::NiceMock<MockSettingsPlugin> settings_plugin(&messenger, nullptr);
89
90 settings_plugin.UpdateHighContrastMode(true);
91 EXPECT_TRUE(settings_plugin.is_high_contrast());
92
93 settings_plugin.UpdateHighContrastMode(false);
94 EXPECT_FALSE(settings_plugin.is_high_contrast());
95
96 EXPECT_EQ(times, 2);
97 }

References message.

## ◆ TEST() [145/171]

flutter::testing::TEST | ( | SettingsPluginTest | ,
|  | SendSettingsGetsSettings |
| ) |  |

Definition at line 55 of file settings_plugin_unittests.cc.

55 {
56 TestBinaryMessenger messenger([](const std::string& channel,
57 const uint8_t* message, size_t message_size,
58 BinaryReply reply) {});
59 ::testing::NiceMock<MockSettingsPlugin> settings_plugin(&messenger, nullptr);
60
61 EXPECT_CALL(settings_plugin, GetAlwaysUse24HourFormat).Times(1);
62 EXPECT_CALL(settings_plugin, GetTextScaleFactor).Times(1);
63 EXPECT_CALL(settings_plugin, GetPreferredBrightness).Times(1);
64
65 settings_plugin.SendSettings();
66 }

References message.

## ◆ TEST() [146/171]

flutter::testing::TEST | ( | SettingsPluginTest | ,
|  | SendSettingsSendsMessage |
| ) |  |

Definition at line 42 of file settings_plugin_unittests.cc.

42 {
43 bool message_is_sent = false;
44 TestBinaryMessenger messenger(
45 [&message_is_sent](const std::string& channel, const uint8_t* message,
46 size_t message_size,
47 BinaryReply reply) { message_is_sent = true; });
48 ::testing::NiceMock<MockSettingsPlugin> settings_plugin(&messenger, nullptr);
49
50 settings_plugin.SendSettings();
51
52 EXPECT_TRUE(message_is_sent);
53 }

References message.

## ◆ TEST() [147/171]

flutter::testing::TEST | ( | SettingsPluginTest | ,
|  | StartWatchingStartsWatchingChanges |
| ) |  |

Definition at line 68 of file settings_plugin_unittests.cc.

68 {
69 TestBinaryMessenger messenger([](const std::string& channel,
70 const uint8_t* message, size_t message_size,
71 BinaryReply reply) {});
72 ::testing::NiceMock<MockSettingsPlugin> settings_plugin(&messenger, nullptr);
73
74 EXPECT_CALL(settings_plugin, WatchPreferredBrightnessChanged).Times(1);
75 EXPECT_CALL(settings_plugin, WatchTextScaleFactorChanged).Times(1);
76
77 settings_plugin.StartWatching();
78 }

References message.

## ◆ TEST() [148/171]

flutter::testing::TEST | ( | SystemUtils | ,
|  | GetPreferredLanguageInfo |
| ) |  |

Definition at line 16 of file system_utils_unittests.cc.

16 {
17 WindowsProcTable proc_table;
18 std::vector<LanguageInfo> languages =
19 GetPreferredLanguageInfo(WindowsProcTable());
20 // There should be at least one language.
21 ASSERT_GE(languages.size(), 1);
22 // The info should have a valid languge.
23 EXPECT_GE(languages[0].language.size(), 2);
24 }
flutter::GetPreferredLanguageInfo
std::vector< LanguageInfo > GetPreferredLanguageInfo(const WindowsProcTable &windows_proc_table)
Definition: system_utils.cc:15

References flutter::GetPreferredLanguageInfo().

## ◆ TEST() [149/171]

flutter::testing::TEST | ( | SystemUtils | ,
|  | GetPreferredLanguages |
| ) |  |

Definition at line 26 of file system_utils_unittests.cc.

26 {
27 MockWindowsProcTable proc_table;
28 EXPECT_CALL(proc_table, GetThreadPreferredUILanguages)
29 .WillRepeatedly(
30 [](DWORD flags, PULONG count, PZZWSTR languages, PULONG size) {
31 // Languages string ends in a double-null.
32 static const wchar_t lang[] = L"en-US\0";
33 static const size_t lang_len = sizeof(lang) / sizeof(wchar_t);
34 static const int cnt = 1;
35 if (languages == nullptr) {
36 *size = lang_len;
37 *count = cnt;
38 } else if (*size >= lang_len) {
39 memcpy(languages, lang, lang_len * sizeof(wchar_t));
40 }
41 return TRUE;
42 });
43 std::vector<std::wstring> languages = GetPreferredLanguages(proc_table);
44 // There should be at least one language.
45 ASSERT_GE(languages.size(), 1);
46 // The language should be non-empty.
47 EXPECT_FALSE(languages[0].empty());
48 // There should not be a trailing null from the parsing step.
49 EXPECT_EQ(languages[0].size(), wcslen(languages[0].c_str()));
50 EXPECT_EQ(languages[0], L"en-US");
51 }
flutter::GetPreferredLanguages
std::vector< std::wstring > GetPreferredLanguages(const WindowsProcTable &windows_proc_table)
Definition: system_utils.cc:45

References flutter::GetPreferredLanguages().

## ◆ TEST() [150/171]

flutter::testing::TEST | ( | SystemUtils | ,
|  | GetUserTimeFormat |
| ) |  |

Definition at line 96 of file system_utils_unittests.cc.

96 {
97 // The value varies based on machine; just ensure that something is returned.
98 EXPECT_FALSE(GetUserTimeFormat().empty());
99 }
flutter::GetUserTimeFormat
std::wstring GetUserTimeFormat()
Definition: system_utils.cc:101

References flutter::GetUserTimeFormat().

## ◆ TEST() [151/171]

flutter::testing::TEST | ( | SystemUtils | ,
|  | ParseLanguageNameGeneric |
| ) |  |

Definition at line 53 of file system_utils_unittests.cc.

53 {
54 LanguageInfo info = ParseLanguageName(L"en");
55 EXPECT_EQ(info.language, "en");
56 EXPECT_TRUE(info.region.empty());
57 EXPECT_TRUE(info.script.empty());
58 }
flutter::ParseLanguageName
LanguageInfo ParseLanguageName(std::wstring language_name)
Definition: system_utils.cc:71

References flutter::LanguageInfo::language, flutter::ParseLanguageName(), flutter::LanguageInfo::region, and flutter::LanguageInfo::script.

## ◆ TEST() [152/171]

flutter::testing::TEST | ( | SystemUtils | ,
|  | ParseLanguageNameWithRegion |
| ) |  |

Definition at line 60 of file system_utils_unittests.cc.

60 {
61 LanguageInfo info = ParseLanguageName(L"hu-HU");
62 EXPECT_EQ(info.language, "hu");
63 EXPECT_EQ(info.region, "HU");
64 EXPECT_TRUE(info.script.empty());
65 }

References flutter::LanguageInfo::language, flutter::ParseLanguageName(), flutter::LanguageInfo::region, and flutter::LanguageInfo::script.

## ◆ TEST() [153/171]

flutter::testing::TEST | ( | SystemUtils | ,
|  | ParseLanguageNameWithRegionAndScript |
| ) |  |

Definition at line 74 of file system_utils_unittests.cc.

74 {
75 LanguageInfo info = ParseLanguageName(L"uz-Latn-UZ");
76 EXPECT_EQ(info.language, "uz");
77 EXPECT_EQ(info.region, "UZ");
78 EXPECT_EQ(info.script, "Latn");
79 }

References flutter::LanguageInfo::language, flutter::ParseLanguageName(), flutter::LanguageInfo::region, and flutter::LanguageInfo::script.

## ◆ TEST() [154/171]

flutter::testing::TEST | ( | SystemUtils | ,
|  | ParseLanguageNameWithScript |
| ) |  |

Definition at line 67 of file system_utils_unittests.cc.

67 {
68 LanguageInfo info = ParseLanguageName(L"us-Latn");
69 EXPECT_EQ(info.language, "us");
70 EXPECT_TRUE(info.region.empty());
71 EXPECT_EQ(info.script, "Latn");
72 }

References flutter::LanguageInfo::language, flutter::ParseLanguageName(), flutter::LanguageInfo::region, and flutter::LanguageInfo::script.

## ◆ TEST() [155/171]

flutter::testing::TEST | ( | SystemUtils | ,
|  | ParseLanguageNameWithSuplementalLanguage |
| ) |  |

Definition at line 81 of file system_utils_unittests.cc.

81 {
82 LanguageInfo info = ParseLanguageName(L"en-US-x-fabricam");
83 EXPECT_EQ(info.language, "en");
84 EXPECT_EQ(info.region, "US");
85 EXPECT_TRUE(info.script.empty());
86 }

References flutter::LanguageInfo::language, flutter::ParseLanguageName(), flutter::LanguageInfo::region, and flutter::LanguageInfo::script.

## ◆ TEST() [156/171]

flutter::testing::TEST | ( | SystemUtils | ,
|  | ParseLanguageNameWithThreeCharacterLanguage |
| ) |  |

Definition at line 89 of file system_utils_unittests.cc.

89 {
90 LanguageInfo info = ParseLanguageName(L"ale-ZZ");
91 EXPECT_EQ(info.language, "ale");
92 EXPECT_EQ(info.region, "ZZ");
93 EXPECT_TRUE(info.script.empty());
94 }

References flutter::LanguageInfo::language, flutter::ParseLanguageName(), flutter::LanguageInfo::region, and flutter::LanguageInfo::script.

## ◆ TEST() [157/171]

flutter::testing::TEST | ( | SystemUtils | ,
|  | Prefer24HourTimeHandles12Hour |
| ) |  |

Definition at line 105 of file system_utils_unittests.cc.

105 {
106 EXPECT_FALSE(Prefer24HourTime(L"h:mm:ss tt"));
107 }
flutter::Prefer24HourTime
bool Prefer24HourTime(std::wstring time_format)
Definition: system_utils.cc:113

References flutter::Prefer24HourTime().

## ◆ TEST() [158/171]

flutter::testing::TEST | ( | SystemUtils | ,
|  | Prefer24HourTimeHandles24Hour |
| ) |  |

Definition at line 109 of file system_utils_unittests.cc.

109 {
110 EXPECT_TRUE(Prefer24HourTime(L"HH:mm:ss"));
111 }

References flutter::Prefer24HourTime().

## ◆ TEST() [159/171]

flutter::testing::TEST | ( | SystemUtils | ,
|  | Prefer24HourTimeHandlesEmptyFormat |
| ) |  |

Definition at line 101 of file system_utils_unittests.cc.

101 {
102 EXPECT_FALSE(Prefer24HourTime(L""));
103 }

References flutter::Prefer24HourTime().

## ◆ TEST() [160/171]

flutter::testing::TEST | ( | TaskRunnerTest | ,
|  | EmptyTaskRunnerReturnsNanoSecondsMax |
| ) |  |

Definition at line 124 of file task_runner_unittests.cc.

124 {
125 TaskRunner runner(MockGetCurrentTime, [](const FlutterTask*) {});
126 auto res = runner.ProcessTasks();
127 EXPECT_EQ(res, std::chrono::nanoseconds::max());
128 }

References flutter::TaskRunner::ProcessTasks().

## ◆ TEST() [161/171]

flutter::testing::TEST | ( | TaskRunnerTest | ,
|  | MaybeExecuteTaskOnlyExpired |
| ) |  |

Definition at line 72 of file task_runner_unittests.cc.

72 {
73 std::set<uint64_t> executed_task;
74 auto runner = MockTaskRunner(
75 MockGetCurrentTime, [&executed_task](const FlutterTask* expired_task) {
76 executed_task.insert(expired_task->task);
77 });
78
79 uint64_t task_expired_before_now = 1;
80 uint64_t time_before_now = 0;
81 runner.PostFlutterTask(FlutterTask{nullptr, task_expired_before_now},
82 time_before_now);
83
84 uint64_t task_expired_after_now = 2;
85 uint64_t time_after_now = MockGetCurrentTime() * 2;
86 runner.PostFlutterTask(FlutterTask{nullptr, task_expired_after_now},
87 time_after_now);
88
89 runner.SimulateTimerAwake();
90
91 std::set<uint64_t> only_task_expired_before_now{task_expired_before_now};
92 EXPECT_EQ(executed_task, only_task_expired_before_now);
93 }

## ◆ TEST() [162/171]

flutter::testing::TEST | ( | TaskRunnerTest | ,
|  | MaybeExecuteTaskWithExactOrder |
| ) |  |

Definition at line 49 of file task_runner_unittests.cc.

49 {
50 std::vector<uint64_t> executed_task_order;
51 auto runner =
52 MockTaskRunner(MockGetCurrentTime,
53 [&executed_task_order](const FlutterTask* expired_task) {
54 executed_task_order.push_back(expired_task->task);
55 });
56
57 uint64_t time_now = MockGetCurrentTime();
58
59 runner.PostFlutterTask(FlutterTask{nullptr, 1}, time_now);
60 runner.PostFlutterTask(FlutterTask{nullptr, 2}, time_now);
61 runner.PostTask(
62 [&executed_task_order]() { executed_task_order.push_back(3); });
63 runner.PostTask(
64 [&executed_task_order]() { executed_task_order.push_back(4); });
65
66 runner.SimulateTimerAwake();
67
68 std::vector<uint64_t> posted_task_order{1, 2, 3, 4};
69 EXPECT_EQ(executed_task_order, posted_task_order);
70 }

## ◆ TEST() [163/171]

flutter::testing::TEST | ( | TaskRunnerTest | ,
|  | TaskRunnerWindowCoalescesWakeUpMessages |
| ) |  |

Definition at line 130 of file task_runner_unittests.cc.

130 {
131 class Delegate : public TaskRunnerWindow::Delegate {
132 public:
133 Delegate() {}
134
135 std::chrono::nanoseconds ProcessTasks() override {
136 process_tasks_call_count_++;
137 return std::chrono::nanoseconds::max();
138 }
139
140 int process_tasks_call_count_ = 0;
141 };
142
143 Delegate delegate;
144 TestTaskRunnerWindow window;
145
146 window.AddDelegate(&delegate);
147
148 window.WakeUp();
149 window.WakeUp();
150
151 ::MSG msg;
152 while (PeekMessage(&msg, nullptr, 0, 0, PM_REMOVE)) {
153 TranslateMessage(&msg);
154 DispatchMessage(&msg);
155 }
156
157 EXPECT_EQ(delegate.process_tasks_call_count_, 1);
158 }

References flutter::TaskRunnerWindow::AddDelegate(), and flutter::TaskRunnerWindow::WakeUp().

## ◆ TEST() [164/171]

flutter::testing::TEST | ( | TaskRunnerTest | ,
|  | TimerThreadDoesNotCancelEarlierScheduledTasks |
| ) |  |

Definition at line 95 of file task_runner_unittests.cc.

95 {
96 std::atomic_bool signaled = false;
97 std::optional<std::chrono::high_resolution_clock::time_point> callback_time;
98 TimerThread timer_thread([&]() {
99 callback_time = std::chrono::high_resolution_clock::now();
100 signaled = true;
101 });
102 timer_thread.Start();
103 auto now = std::chrono::high_resolution_clock::now();
104 // Make sure that subsequent call to schedule does not cancel earlier task
105 // as documented in TimerThread::ScheduleAt.
106 timer_thread.ScheduleAt(now + std::chrono::milliseconds(20));
107 timer_thread.ScheduleAt(now + std::chrono::seconds(10));
108
109 while (!signaled.load()) {
110 std::this_thread::sleep_for(std::chrono::milliseconds(5));
111 }
112
113 EXPECT_TRUE(callback_time.has_value());
114 EXPECT_GE(*callback_time, now + std::chrono::milliseconds(20));
115
116 timer_thread.Stop();
117 }

References flutter::TimerThread::Start().

## ◆ TEST() [165/171]

flutter::testing::TEST | ( | WindowProcDelegateManagerTest | ,
|  | CallsCorrectly |
| ) |  |

Definition at line 54 of file window_proc_delegate_manager_unittests.cc.

54 {
55 WindowProcDelegateManager manager;
56 HWND dummy_hwnd;
57
58 bool called = false;
59 TestWindowProcDelegate delegate = [&called, &dummy_hwnd](
60 HWND hwnd, UINT message, WPARAM wparam,
61 LPARAM lparam) {
62 called = true;
63 EXPECT_EQ(hwnd, dummy_hwnd);
64 EXPECT_EQ(message, 2);
65 EXPECT_EQ(wparam, 3);
66 EXPECT_EQ(lparam, 4);
67 return std::optional<LRESULT>();
68 };
69 manager.RegisterTopLevelWindowProcDelegate(TestWindowProcCallback, &delegate);
70 auto result = manager.OnTopLevelWindowProc(dummy_hwnd, 2, 3, 4);
71
72 EXPECT_TRUE(called);
73 EXPECT_FALSE(result);
74 }

References message, flutter::WindowProcDelegateManager::OnTopLevelWindowProc(), and flutter::WindowProcDelegateManager::RegisterTopLevelWindowProcDelegate().

## ◆ TEST() [166/171]

flutter::testing::TEST | ( | WindowProcDelegateManagerTest | ,
|  | ConflictingDelegates |
| ) |  |

Definition at line 163 of file window_proc_delegate_manager_unittests.cc.

163 {
164 WindowProcDelegateManager manager;
165
166 bool called_a = false;
167 TestWindowProcDelegate delegate_a =
168 [&called_a](HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam) {
169 called_a = true;
170 return std::optional<LRESULT>(1);
171 };
172 bool called_b = false;
173 TestWindowProcDelegate delegate_b =
174 [&called_b](HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam) {
175 called_b = true;
176 return std::optional<LRESULT>(1);
177 };
178 manager.RegisterTopLevelWindowProcDelegate(TestWindowProcCallback,
179 &delegate_a);
180 manager.RegisterTopLevelWindowProcDelegate(TestWindowProcCallback2,
181 &delegate_b);
182 auto result = manager.OnTopLevelWindowProc(nullptr, 0, 0, 0);
183
184 EXPECT_TRUE(result);
185 // Exactly one of the handlers should be called since each will claim to have
186 // handled the message. Which one is unspecified, since the calling order is
187 // unspecified.
188 EXPECT_TRUE(called_a || called_b);
189 EXPECT_NE(called_a, called_b);
190 }

References message, flutter::WindowProcDelegateManager::OnTopLevelWindowProc(), and flutter::WindowProcDelegateManager::RegisterTopLevelWindowProcDelegate().

## ◆ TEST() [167/171]

flutter::testing::TEST | ( | WindowProcDelegateManagerTest | ,
|  | Ordered |
| ) |  |

Definition at line 128 of file window_proc_delegate_manager_unittests.cc.

128 {
129 TestWindowProcDelegate delegate_1 = [](HWND hwnd, UINT message, WPARAM wparam,
130 LPARAM lparam) { return 1; };
131 TestWindowProcDelegate delegate_2 = [](HWND hwnd, UINT message, WPARAM wparam,
132 LPARAM lparam) { return 2; };
133
134 // Result should be 1 if delegate '1' is registered before delegate '2'.
135 {
136 WindowProcDelegateManager manager;
137 manager.RegisterTopLevelWindowProcDelegate(TestWindowProcCallback,
138 &delegate_1);
139 manager.RegisterTopLevelWindowProcDelegate(TestWindowProcCallback2,
140 &delegate_2);
141
142 std::optional<LRESULT> result =
143 manager.OnTopLevelWindowProc(nullptr, 0, 0, 0);
144
145 EXPECT_EQ(result, 1);
146 }
147
148 // Result should be 2 if delegate '2' is registered before delegate '1'.
149 {
150 WindowProcDelegateManager manager;
151 manager.RegisterTopLevelWindowProcDelegate(TestWindowProcCallback2,
152 &delegate_2);
153 manager.RegisterTopLevelWindowProcDelegate(TestWindowProcCallback,
154 &delegate_1);
155
156 std::optional<LRESULT> result =
157 manager.OnTopLevelWindowProc(nullptr, 0, 0, 0);
158
159 EXPECT_EQ(result, 2);
160 }
161 }

References message, flutter::WindowProcDelegateManager::OnTopLevelWindowProc(), and flutter::WindowProcDelegateManager::RegisterTopLevelWindowProcDelegate().

## ◆ TEST() [168/171]

flutter::testing::TEST | ( | WindowProcDelegateManagerTest | ,
|  | RegisterMultiple |
| ) |  |

Definition at line 102 of file window_proc_delegate_manager_unittests.cc.

102 {
103 WindowProcDelegateManager manager;
104
105 bool called_a = false;
106 TestWindowProcDelegate delegate_a =
107 [&called_a](HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam) {
108 called_a = true;
109 return std::optional<LRESULT>();
110 };
111 bool called_b = false;
112 TestWindowProcDelegate delegate_b =
113 [&called_b](HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam) {
114 called_b = true;
115 return std::optional<LRESULT>();
116 };
117 manager.RegisterTopLevelWindowProcDelegate(TestWindowProcCallback,
118 &delegate_a);
119 // Function pointer is different, so both should be called.
120 manager.RegisterTopLevelWindowProcDelegate(TestWindowProcCallback2,
121 &delegate_b);
122 manager.OnTopLevelWindowProc(nullptr, 0, 0, 0);
123
124 EXPECT_TRUE(called_a);
125 EXPECT_TRUE(called_b);
126 }

References message, flutter::WindowProcDelegateManager::OnTopLevelWindowProc(), and flutter::WindowProcDelegateManager::RegisterTopLevelWindowProcDelegate().

## ◆ TEST() [169/171]

flutter::testing::TEST | ( | WindowProcDelegateManagerTest | ,
|  | ReplacementRegister |
| ) |  |

Definition at line 76 of file window_proc_delegate_manager_unittests.cc.

76 {
77 WindowProcDelegateManager manager;
78
79 bool called_a = false;
80 TestWindowProcDelegate delegate_a =
81 [&called_a](HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam) {
82 called_a = true;
83 return std::optional<LRESULT>();
84 };
85 bool called_b = false;
86 TestWindowProcDelegate delegate_b =
87 [&called_b](HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam) {
88 called_b = true;
89 return std::optional<LRESULT>();
90 };
91 manager.RegisterTopLevelWindowProcDelegate(TestWindowProcCallback,
92 &delegate_a);
93 // The function pointer is the same, so this should replace, not add.
94 manager.RegisterTopLevelWindowProcDelegate(TestWindowProcCallback,
95 &delegate_b);
96 manager.OnTopLevelWindowProc(nullptr, 0, 0, 0);
97
98 EXPECT_FALSE(called_a);
99 EXPECT_TRUE(called_b);
100 }

References message, flutter::WindowProcDelegateManager::OnTopLevelWindowProc(), and flutter::WindowProcDelegateManager::RegisterTopLevelWindowProcDelegate().

## ◆ TEST() [170/171]

flutter::testing::TEST | ( | WindowProcDelegateManagerTest | ,
|  | Unregister |
| ) |  |

Definition at line 192 of file window_proc_delegate_manager_unittests.cc.

192 {
193 WindowProcDelegateManager manager;
194
195 bool called = false;
196 TestWindowProcDelegate delegate = [&called](HWND hwnd, UINT message,
197 WPARAM wparam, LPARAM lparam) {
198 called = true;
199 return std::optional<LRESULT>();
200 };
201 manager.RegisterTopLevelWindowProcDelegate(TestWindowProcCallback, &delegate);
202 manager.UnregisterTopLevelWindowProcDelegate(TestWindowProcCallback);
203 auto result = manager.OnTopLevelWindowProc(nullptr, 0, 0, 0);
204
205 EXPECT_FALSE(result);
206 EXPECT_FALSE(called);
207 }

References message, flutter::WindowProcDelegateManager::OnTopLevelWindowProc(), flutter::WindowProcDelegateManager::RegisterTopLevelWindowProcDelegate(), and flutter::WindowProcDelegateManager::UnregisterTopLevelWindowProcDelegate().

## ◆ TEST() [171/171]

flutter::testing::TEST | ( | WindowsNoFixtureTest | ,
|  | GetTextureRegistrar |
| ) |  |

Definition at line 66 of file flutter_windows_unittests.cc.

66 {
67 FlutterDesktopEngineProperties properties = {};
68 properties.assets_path = L"";
69 properties.icu_data_path = L"icudtl.dat";
70 auto engine = FlutterDesktopEngineCreate(&properties);
71 ASSERT_NE(engine, nullptr);
72 auto texture_registrar = FlutterDesktopEngineGetTextureRegistrar(engine);
73 EXPECT_NE(texture_registrar, nullptr);
74 FlutterDesktopEngineDestroy(engine);
75 }
FlutterDesktopEngineCreate
FlutterDesktopEngineRef FlutterDesktopEngineCreate(const FlutterDesktopEngineProperties *engine_properties)
Definition: flutter_windows.cc:184
FlutterDesktopEngineDestroy
bool FlutterDesktopEngineDestroy(FlutterDesktopEngineRef engine_ref)
Definition: flutter_windows.cc:191
FlutterDesktopEngineGetTextureRegistrar
FlutterDesktopTextureRegistrarRef FlutterDesktopEngineGetTextureRegistrar(FlutterDesktopEngineRef engine)
Definition: flutter_windows.cc:240

References FlutterDesktopEngineProperties::assets_path, FlutterDesktopEngineCreate(), FlutterDesktopEngineDestroy(), FlutterDesktopEngineGetTextureRegistrar(), and FlutterDesktopEngineProperties::icu_data_path.

## ◆ TEST_F() [1/204]

flutter::testing::TEST_F | ( | AccessibilityPluginTest | ,
|  | AnnounceWithInt32ViewId |
| ) |  |

Definition at line 112 of file accessibility_plugin_unittests.cc.

112 {
113 EXPECT_CALL(*view(), AnnounceAlert(::testing::Eq(L"Hello"))).Times(1);
114
115 SendAnnounceMessage("Hello", EncodableValue{static_cast<int32_t>(0)});
116
117 // Verify expectations are met
118 ::testing::Mock::VerifyAndClearExpectations(view());
119 }

## ◆ TEST_F() [2/204]

flutter::testing::TEST_F | ( | AccessibilityPluginTest | ,
|  | AnnounceWithInt64ViewId |
| ) |  |

Definition at line 121 of file accessibility_plugin_unittests.cc.

121 {
122 EXPECT_CALL(*view(), AnnounceAlert(::testing::Eq(L"Hello World"))).Times(1);
123
124 SendAnnounceMessage("Hello World", EncodableValue{static_cast<int64_t>(0)});
125
126 // Verify expectations are met
127 ::testing::Mock::VerifyAndClearExpectations(view());
128 }

## ◆ TEST_F() [3/204]

flutter::testing::TEST_F | ( | AccessibilityPluginTest | ,
|  | AnnounceWithInvalidViewIdType |
| ) |  |

Definition at line 130 of file accessibility_plugin_unittests.cc.

130 {
131 // Should not be called with invalid viewId type
132 EXPECT_CALL(*view(), AnnounceAlert(_)).Times(0);
133
134 SendAnnounceMessage("Hello", EncodableValue{"invalid"});
135 }

## ◆ TEST_F() [4/204]

flutter::testing::TEST_F | ( | AccessibilityPluginTest | ,
|  | AnnounceWithMissingMessage |
| ) |  |

Definition at line 136 of file accessibility_plugin_unittests.cc.

136 {
137 // Should not be called when message is missing
138 EXPECT_CALL(*view(), AnnounceAlert(_)).Times(0);
139
140 EncodableMap data;
141 data[EncodableValue{"viewId"}] = EncodableValue{static_cast<int32_t>(0)};
142
143 EncodableMap msg;
144 msg[EncodableValue{"type"}] = EncodableValue{"announce"};
145 msg[EncodableValue{"data"}] = EncodableValue{data};
146
147 auto encoded =
148 StandardMessageCodec::GetInstance().EncodeMessage(EncodableValue{msg});
149
150 messenger()->SimulateEngineMessage(
151 kAccessibilityChannelName, encoded->data(), encoded->size(),
152 [](const uint8_t* reply, size_t reply_size) {});
153 }
kAccessibilityChannelName
static constexpr char kAccessibilityChannelName[]
Definition: flutter_windows_engine.cc:36
flutter::EncodableMap
std::map< EncodableValue, EncodableValue > EncodableMap
Definition: encodable_value.h:96

References flutter::MessageCodec< T >::EncodeMessage(), flutter::StandardMessageCodec::GetInstance(), and kAccessibilityChannelName.

## ◆ TEST_F() [5/204]

flutter::testing::TEST_F | ( | AccessibilityPluginTest | ,
|  | DirectAnnounceCall |
| ) |  |

Definition at line 102 of file accessibility_plugin_unittests.cc.

102 {
103 // Test calling Announce directly, bypassing the message channel
104 EXPECT_CALL(*view(), AnnounceAlert(::testing::Eq(L"Direct"))).Times(1);
105
106 AccessibilityPlugin plugin(engine());
107 plugin.Announce(0, "Direct");
108
109 ::testing::Mock::VerifyAndClearExpectations(view());
110 }

References flutter::AccessibilityPlugin::Announce().

## ◆ TEST_F() [6/204]

flutter::testing::TEST_F | ( | CompositorOpenGLTest | ,
|  | CreateBackingStore |
| ) |  |

Definition at line 140 of file compositor_opengl_unittests.cc.

140 {
141 UseHeadlessEngine();
142
143 auto compositor =
144 CompositorOpenGL{engine(), kMockResolver, /*enable_impeller=*/false};
145
146 FlutterBackingStoreConfig config = {};
147 FlutterBackingStore backing_store = {};
148
149 EXPECT_CALL(*render_context(), MakeCurrent).WillOnce(Return(true));
150 ASSERT_TRUE(compositor.CreateBackingStore(config, &backing_store));
151 ASSERT_TRUE(compositor.CollectBackingStore(&backing_store));
152 }

## ◆ TEST_F() [7/204]

flutter::testing::TEST_F | ( | CompositorOpenGLTest | ,
|  | CreateBackingStoreImpeller |
| ) |  |

Definition at line 154 of file compositor_opengl_unittests.cc.

154 {
155 UseHeadlessEngine();
156
157 auto compositor =
158 CompositorOpenGL{engine(), kMockResolver, /*enable_impeller=*/true};
159
160 FlutterBackingStoreConfig config = {};
161 FlutterBackingStore backing_store = {};
162
163 EXPECT_CALL(*render_context(), MakeCurrent).WillOnce(Return(true));
164 ASSERT_TRUE(compositor.CreateBackingStore(config, &backing_store));
165 ASSERT_TRUE(compositor.CollectBackingStore(&backing_store));
166 }

## ◆ TEST_F() [8/204]

flutter::testing::TEST_F | ( | CompositorOpenGLTest | ,
|  | InitializationFailure |
| ) |  |

Definition at line 168 of file compositor_opengl_unittests.cc.

168 {
169 UseHeadlessEngine();
170
171 auto compositor =
172 CompositorOpenGL{engine(), kMockResolver, /*enable_impeller=*/false};
173
174 FlutterBackingStoreConfig config = {};
175 FlutterBackingStore backing_store = {};
176
177 EXPECT_CALL(*render_context(), MakeCurrent).WillOnce(Return(false));
178 EXPECT_FALSE(compositor.CreateBackingStore(config, &backing_store));
179 }

## ◆ TEST_F() [9/204]

flutter::testing::TEST_F | ( | CompositorOpenGLTest | ,
|  | InitializationRequiresBlit |
| ) |  |

Definition at line 181 of file compositor_opengl_unittests.cc.

181 {
182 UseHeadlessEngine();
183
184 const impeller::ProcTableGLES::Resolver resolver = [](const char* name) {
185 std::string function_name{name};
186
187 if (function_name == "glBlitFramebuffer" ||
188 function_name == "glBlitFramebufferANGLE") {
189 return (void*)nullptr;
190 }
191
192 return kMockResolver(name);
193 };
194
195 auto compositor =
196 CompositorOpenGL{engine(), resolver, /*enable_impeller=*/false};
197
198 FlutterBackingStoreConfig config = {};
199 FlutterBackingStore backing_store = {};
200
201 EXPECT_CALL(*render_context(), MakeCurrent).WillOnce(Return(true));
202 ASSERT_FALSE(compositor.CreateBackingStore(config, &backing_store));
203 }

## ◆ TEST_F() [10/204]

flutter::testing::TEST_F | ( | CompositorOpenGLTest | ,
|  | NoSurfaceIgnored |
| ) |  |

Definition at line 245 of file compositor_opengl_unittests.cc.

245 {
246 UseEngineWithView(/*add_surface = */ false);
247
248 auto compositor =
249 CompositorOpenGL{engine(), kMockResolver, /*enable_impeller=*/false};
250
251 FlutterBackingStoreConfig config = {};
252 FlutterBackingStore backing_store = {};
253
254 EXPECT_CALL(*render_context(), MakeCurrent).WillOnce(Return(true));
255 ASSERT_TRUE(compositor.CreateBackingStore(config, &backing_store));
256
257 FlutterLayer layer = {};
258 layer.type = kFlutterLayerContentTypeBackingStore;
259 layer.backing_store = &backing_store;
260 const FlutterLayer* layer_ptr = &layer;
261
262 EXPECT_FALSE(compositor.Present(view(), &layer_ptr, 1));
263
264 ASSERT_TRUE(compositor.CollectBackingStore(&backing_store));
265 }

## ◆ TEST_F() [11/204]

flutter::testing::TEST_F | ( | CompositorOpenGLTest | ,
|  | Present |
| ) |  |

Definition at line 205 of file compositor_opengl_unittests.cc.

205 {
206 UseEngineWithView();
207
208 auto compositor =
209 CompositorOpenGL{engine(), kMockResolver, /*enable_impeller=*/false};
210
211 FlutterBackingStoreConfig config = {};
212 FlutterBackingStore backing_store = {};
213
214 EXPECT_CALL(*render_context(), MakeCurrent).WillOnce(Return(true));
215 ASSERT_TRUE(compositor.CreateBackingStore(config, &backing_store));
216
217 FlutterLayer layer = {};
218 layer.type = kFlutterLayerContentTypeBackingStore;
219 layer.backing_store = &backing_store;
220 const FlutterLayer* layer_ptr = &layer;
221
222 EXPECT_CALL(*surface(), IsValid).WillRepeatedly(Return(true));
223 EXPECT_CALL(*surface(), MakeCurrent).WillOnce(Return(true));
224 EXPECT_CALL(*surface(), SwapBuffers).WillOnce(Return(true));
225 EXPECT_TRUE(compositor.Present(view(), &layer_ptr, 1));
226
227 ASSERT_TRUE(compositor.CollectBackingStore(&backing_store));
228 }

## ◆ TEST_F() [12/204]

flutter::testing::TEST_F | ( | CompositorOpenGLTest | ,
|  | PresentEmpty |
| ) |  |

Definition at line 230 of file compositor_opengl_unittests.cc.

230 {
231 UseEngineWithView();
232
233 auto compositor =
234 CompositorOpenGL{engine(), kMockResolver, /*enable_impeller=*/false};
235
236 // The context will be bound twice: first to initialize the compositor, second
237 // to clear the surface.
238 EXPECT_CALL(*render_context(), MakeCurrent).WillOnce(Return(true));
239 EXPECT_CALL(*surface(), IsValid).WillRepeatedly(Return(true));
240 EXPECT_CALL(*surface(), MakeCurrent).WillOnce(Return(true));
241 EXPECT_CALL(*surface(), SwapBuffers).WillOnce(Return(true));
242 EXPECT_TRUE(compositor.Present(view(), nullptr, 0));
243 }

## ◆ TEST_F() [13/204]

flutter::testing::TEST_F | ( | CompositorOpenGLTest | ,
|  | PresentUsingANGLEBlitExtension |
| ) |  |

Definition at line 267 of file compositor_opengl_unittests.cc.

267 {
268 UseEngineWithView();
269
270 bool resolved_ANGLE_blit = false;
271 const impeller::ProcTableGLES::Resolver resolver =
272 [&resolved_ANGLE_blit](const char* name) {
273 std::string function_name{name};
274
275 if (function_name == "glBlitFramebuffer") {
276 return (void*)nullptr;
277 } else if (function_name == "glBlitFramebufferANGLE") {
278 resolved_ANGLE_blit = true;
279 return reinterpret_cast<void*>(&DoNothing);
280 }
281
282 return kMockResolver(name);
283 };
284
285 auto compositor =
286 CompositorOpenGL{engine(), resolver, /*enable_impeller=*/false};
287
288 FlutterBackingStoreConfig config = {};
289 FlutterBackingStore backing_store = {};
290
291 EXPECT_CALL(*render_context(), MakeCurrent).WillOnce(Return(true));
292 ASSERT_TRUE(compositor.CreateBackingStore(config, &backing_store));
293
294 FlutterLayer layer = {};
295 layer.type = kFlutterLayerContentTypeBackingStore;
296 layer.backing_store = &backing_store;
297 const FlutterLayer* layer_ptr = &layer;
298
299 EXPECT_CALL(*surface(), IsValid).WillRepeatedly(Return(true));
300 EXPECT_CALL(*surface(), MakeCurrent).WillOnce(Return(true));
301 EXPECT_CALL(*surface(), SwapBuffers).WillOnce(Return(true));
302 EXPECT_TRUE(compositor.Present(view(), &layer_ptr, 1));
303 EXPECT_TRUE(resolved_ANGLE_blit);
304
305 ASSERT_TRUE(compositor.CollectBackingStore(&backing_store));
306 }

## ◆ TEST_F() [14/204]

flutter::testing::TEST_F | ( | CompositorSoftwareTest | ,
|  | CreateBackingStore |
| ) |  |

Definition at line 74 of file compositor_software_unittests.cc.

74 {
75 CompositorSoftware compositor;
76
77 FlutterBackingStoreConfig config = {};
78 FlutterBackingStore backing_store = {};
79
80 ASSERT_TRUE(compositor.CreateBackingStore(config, &backing_store));
81 ASSERT_TRUE(compositor.CollectBackingStore(&backing_store));
82 }

References flutter::CompositorSoftware::CollectBackingStore(), and flutter::CompositorSoftware::CreateBackingStore().

## ◆ TEST_F() [15/204]

flutter::testing::TEST_F | ( | CompositorSoftwareTest | ,
|  | Present |
| ) |  |

Definition at line 84 of file compositor_software_unittests.cc.

84 {
85 UseEngineWithView();
86
87 CompositorSoftware compositor;
88
89 FlutterBackingStoreConfig config = {};
90 FlutterBackingStore backing_store = {};
91
92 ASSERT_TRUE(compositor.CreateBackingStore(config, &backing_store));
93
94 FlutterLayer layer = {};
95 layer.type = kFlutterLayerContentTypeBackingStore;
96 layer.backing_store = &backing_store;
97 const FlutterLayer* layer_ptr = &layer;
98
99 EXPECT_CALL(*view(), PresentSoftwareBitmap).WillOnce(Return(true));
100 EXPECT_TRUE(compositor.Present(view(), &layer_ptr, 1));
101
102 ASSERT_TRUE(compositor.CollectBackingStore(&backing_store));
103 }

References flutter::CompositorSoftware::CollectBackingStore(), flutter::CompositorSoftware::CreateBackingStore(), and flutter::CompositorSoftware::Present().

## ◆ TEST_F() [16/204]

flutter::testing::TEST_F | ( | CompositorSoftwareTest | ,
|  | PresentEmpty |
| ) |  |

Definition at line 105 of file compositor_software_unittests.cc.

105 {
106 UseEngineWithView();
107
108 CompositorSoftware compositor;
109
110 EXPECT_CALL(*view(), ClearSoftwareBitmap).WillOnce(Return(true));
111 EXPECT_TRUE(compositor.Present(view(), nullptr, 0));
112 }

References flutter::CompositorSoftware::Present().

## ◆ TEST_F() [17/204]

flutter::testing::TEST_F | ( | CompositorSoftwareTest | ,
|  | PresentMultiLayers |
| ) |  |

Definition at line 121 of file compositor_software_unittests.cc.

121 {
122 UseEngineWithView();
123
124 CompositorSoftware compositor;
125
126 FlutterBackingStoreConfig config = {sizeof(config), {2, 2}};
127 FlutterBackingStore backing_store0 = {sizeof(FlutterBackingStore), nullptr};
128 FlutterBackingStore backing_store1 = {sizeof(FlutterBackingStore), nullptr};
129
130 ASSERT_TRUE(compositor.CreateBackingStore(config, &backing_store0));
131 ASSERT_TRUE(compositor.CreateBackingStore(config, &backing_store1));
132
133 uint32_t pixels0[4] = {0xff000000, 0xff0000ff, 0xff00ff00, 0xffffffff};
134 uint32_t pixels1[4] = {0x7f0000ff, 0x00ffffff, 0x7fff0000, 0xff000000};
135
136 std::memcpy(const_cast<void*>(backing_store0.software.allocation), pixels0,
137 sizeof(uint32_t) * 4);
138 std::memcpy(const_cast<void*>(backing_store1.software.allocation), pixels1,
139 sizeof(uint32_t) * 4);
140
141 FlutterLayer layer0 = {};
142 layer0.type = kFlutterLayerContentTypeBackingStore;
143 layer0.backing_store = &backing_store0;
144 layer0.offset = {0, 0};
145 layer0.size = {2, 2};
146
147 FlutterLayer layer1 = layer0;
148 layer1.backing_store = &backing_store1;
149 const FlutterLayer* layer_ptr[2] = {&layer0, &layer1};
150
151 EXPECT_CALL(*view(), PresentSoftwareBitmap)
152 .WillOnce([&](const void* allocation, size_t row_bytes, size_t height) {
153 auto pixel_data = static_cast<const uint32_t*>(allocation);
154 EXPECT_EQ(row_bytes, 2 * sizeof(uint32_t));
155 EXPECT_EQ(height, 2);
156 EXPECT_EQ(pixel_data[0], 0xff00007f);
157 EXPECT_EQ(pixel_data[1], 0xff0000ff);
158 EXPECT_EQ(pixel_data[2], 0xff7f8000);
159 EXPECT_EQ(pixel_data[3], 0xff000000);
160 return true;
161 });
162 EXPECT_TRUE(compositor.Present(view(), layer_ptr, 2));
163
164 ASSERT_TRUE(compositor.CollectBackingStore(&backing_store0));
165 ASSERT_TRUE(compositor.CollectBackingStore(&backing_store1));
166 }

References flutter::CompositorSoftware::CollectBackingStore(), flutter::CompositorSoftware::CreateBackingStore(), and flutter::CompositorSoftware::Present().

## ◆ TEST_F() [18/204]

flutter::testing::TEST_F | ( | CompositorSoftwareTest | ,
|  | PresentOffsetLayers |
| ) |  |

Definition at line 171 of file compositor_software_unittests.cc.

171 {
172 UseEngineWithView();
173
174 CompositorSoftware compositor;
175
176 FlutterBackingStoreConfig config0 = {sizeof(FlutterBackingStoreConfig),
177 {1, 1}};
178 FlutterBackingStore backing_store0 = {sizeof(FlutterBackingStore), nullptr};
179 FlutterBackingStoreConfig config1 = {sizeof(FlutterBackingStoreConfig),
180 {2, 1}};
181 FlutterBackingStore backing_store1 = {sizeof(FlutterBackingStore), nullptr};
182
183 ASSERT_TRUE(compositor.CreateBackingStore(config0, &backing_store0));
184 ASSERT_TRUE(compositor.CreateBackingStore(config1, &backing_store1));
185
186 uint32_t pixels0 = 0xff0000ff;
187 uint32_t pixels1[2] = {0xffff0000, 0xffff0000};
188
189 std::memcpy(const_cast<void*>(backing_store0.software.allocation), &pixels0,
190 sizeof(uint32_t) * 1);
191 std::memcpy(const_cast<void*>(backing_store1.software.allocation), pixels1,
192 sizeof(uint32_t) * 2);
193
194 FlutterLayer layer0 = {};
195 layer0.type = kFlutterLayerContentTypeBackingStore;
196 layer0.backing_store = &backing_store0;
197 layer0.offset = {0, 0};
198 layer0.size = {1, 1};
199
200 FlutterLayer layer1 = layer0;
201 layer1.backing_store = &backing_store1;
202 layer1.offset = {0, 1};
203 layer1.size = {2, 1};
204 const FlutterLayer* layer_ptr[2] = {&layer0, &layer1};
205
206 EXPECT_CALL(*view(), PresentSoftwareBitmap)
207 .WillOnce([&](const void* allocation, size_t row_bytes, size_t height) {
208 auto pixel_data = static_cast<const uint32_t*>(allocation);
209 EXPECT_EQ(row_bytes, 2 * sizeof(uint32_t));
210 EXPECT_EQ(height, 2);
211 EXPECT_EQ(pixel_data[0], 0xff0000ff);
212 EXPECT_EQ(pixel_data[1], 0xff000000);
213 EXPECT_EQ(pixel_data[2], 0xffff0000);
214 EXPECT_EQ(pixel_data[3], 0xffff0000);
215 return true;
216 });
217 EXPECT_TRUE(compositor.Present(view(), layer_ptr, 2));
218
219 ASSERT_TRUE(compositor.CollectBackingStore(&backing_store0));
220 ASSERT_TRUE(compositor.CollectBackingStore(&backing_store1));
221 }

References flutter::CompositorSoftware::CollectBackingStore(), flutter::CompositorSoftware::CreateBackingStore(), and flutter::CompositorSoftware::Present().

## ◆ TEST_F() [19/204]

flutter::testing::TEST_F | ( | CursorHandlerTest | ,
|  | ActivateSystemCursor |
| ) |  |

Definition at line 102 of file cursor_handler_unittests.cc.

102 {
103 UseEngineWithView();
104
105 TestBinaryMessenger messenger;
106 CursorHandler cursor_handler(&messenger, engine());
107
108 EXPECT_CALL(*proc_table(), LoadCursor(IsNull(), IDC_HAND)).Times(1);
109 EXPECT_CALL(*proc_table(), SetCursor).Times(1);
110
111 bool success = false;
112 MethodResultFunctions<> result_handler(
113 [&success](const EncodableValue* result) {
114 success = true;
115 EXPECT_EQ(result, nullptr);
116 },
117 nullptr, nullptr);
118
119 SimulateCursorMessage(&messenger, kActivateSystemCursorMethod,
120 std::make_unique<EncodableValue>(EncodableMap{
121 {EncodableValue("device"), EncodableValue(0)},
122 {EncodableValue("kind"), EncodableValue("click")},
123 }),
124 &result_handler);
125
126 EXPECT_TRUE(success);
127 }
kActivateSystemCursorMethod
static constexpr char kActivateSystemCursorMethod[]
Definition: cursor_handler.cc:14

References kActivateSystemCursorMethod.

## ◆ TEST_F() [20/204]

flutter::testing::TEST_F | ( | CursorHandlerTest | ,
|  | CreateCustomCursor |
| ) |  |

Definition at line 129 of file cursor_handler_unittests.cc.

129 {
130 UseEngineWithView();
131
132 TestBinaryMessenger messenger;
133 CursorHandler cursor_handler(&messenger, engine());
134
135 // Create a 4x4 raw BGRA test cursor buffer.
136 std::vector<uint8_t> buffer(4 * 4 * 4, 0);
137
138 bool success = false;
139 MethodResultFunctions<> result_handler(
140 [&success](const EncodableValue* result) {
141 success = true;
142 EXPECT_EQ(std::get<std::string>(*result), "hello");
143 },
144 nullptr, nullptr);
145
146 SimulateCursorMessage(&messenger, kCreateCustomCursorMethod,
147 std::make_unique<EncodableValue>(EncodableMap{
148 {EncodableValue("name"), EncodableValue("hello")},
149 {EncodableValue("buffer"), EncodableValue(buffer)},
150 {EncodableValue("width"), EncodableValue(4)},
151 {EncodableValue("height"), EncodableValue(4)},
152 {EncodableValue("hotX"), EncodableValue(0.0)},
153 {EncodableValue("hotY"), EncodableValue(0.0)},
154 }),
155 &result_handler);
156
157 EXPECT_TRUE(success);
158 }
kCreateCustomCursorMethod
static constexpr char kCreateCustomCursorMethod[]
Definition: cursor_handler.cc:19

References kCreateCustomCursorMethod.

## ◆ TEST_F() [21/204]

flutter::testing::TEST_F | ( | CursorHandlerTest | ,
|  | DeleteCustomCursor |
| ) |  |

Definition at line 231 of file cursor_handler_unittests.cc.

231 {
232 UseEngineWithView();
233
234 TestBinaryMessenger messenger;
235 CursorHandler cursor_handler(&messenger, engine());
236
237 // Create a 4x4 raw BGRA test cursor buffer.
238 std::vector<uint8_t> buffer(4 * 4 * 4, 0);
239
240 bool success = false;
241 MethodResultFunctions<> create_result_handler(nullptr, nullptr, nullptr);
242 MethodResultFunctions<> delete_result_handler(
243 [&success](const EncodableValue* result) {
244 success = true;
245 EXPECT_EQ(result, nullptr);
246 },
247 nullptr, nullptr);
248
249 SimulateCursorMessage(&messenger, kCreateCustomCursorMethod,
250 std::make_unique<EncodableValue>(EncodableMap{
251 {EncodableValue("name"), EncodableValue("hello")},
252 {EncodableValue("buffer"), EncodableValue(buffer)},
253 {EncodableValue("width"), EncodableValue(4)},
254 {EncodableValue("height"), EncodableValue(4)},
255 {EncodableValue("hotX"), EncodableValue(0.0)},
256 {EncodableValue("hotY"), EncodableValue(0.0)},
257 }),
258 &create_result_handler);
259
260 SimulateCursorMessage(&messenger, kDeleteCustomCursorMethod,
261 std::make_unique<EncodableValue>(EncodableMap{
262 {EncodableValue("name"), EncodableValue("hello")},
263 }),
264 &delete_result_handler);
265
266 EXPECT_TRUE(success);
267 }
kDeleteCustomCursorMethod
static constexpr char kDeleteCustomCursorMethod[]
Definition: cursor_handler.cc:41

References kCreateCustomCursorMethod, and kDeleteCustomCursorMethod.

## ◆ TEST_F() [22/204]

flutter::testing::TEST_F | ( | CursorHandlerTest | ,
|  | DeleteNonexistentCustomCursor |
| ) |  |

Definition at line 269 of file cursor_handler_unittests.cc.

269 {
270 UseEngineWithView();
271
272 TestBinaryMessenger messenger;
273 CursorHandler cursor_handler(&messenger, engine());
274
275 bool success = false;
276 MethodResultFunctions<> result_handler(
277 [&success](const EncodableValue* result) {
278 success = true;
279 EXPECT_EQ(result, nullptr);
280 },
281 nullptr, nullptr);
282
283 SimulateCursorMessage(&messenger, kDeleteCustomCursorMethod,
284 std::make_unique<EncodableValue>(EncodableMap{
285 {EncodableValue("name"), EncodableValue("fake")},
286 }),
287 &result_handler);
288
289 EXPECT_TRUE(success);
290 }

References kDeleteCustomCursorMethod.

## ◆ TEST_F() [23/204]

flutter::testing::TEST_F | ( | CursorHandlerTest | ,
|  | SetCustomCursor |
| ) |  |

Definition at line 160 of file cursor_handler_unittests.cc.

160 {
161 UseEngineWithView();
162
163 TestBinaryMessenger messenger;
164 CursorHandler cursor_handler(&messenger, engine());
165
166 // Create a 4x4 raw BGRA test cursor buffer.
167 std::vector<uint8_t> buffer(4 * 4 * 4, 0);
168
169 bool success = false;
170 MethodResultFunctions<> create_result_handler(nullptr, nullptr, nullptr);
171 MethodResultFunctions<> set_result_handler(
172 [&success](const EncodableValue* result) {
173 success = true;
174 EXPECT_EQ(result, nullptr);
175 },
176 nullptr, nullptr);
177
178 EXPECT_CALL(*proc_table(), LoadCursor).Times(0);
179 EXPECT_CALL(*proc_table(), SetCursor(NotNull())).Times(1);
180
181 SimulateCursorMessage(&messenger, kCreateCustomCursorMethod,
182 std::make_unique<EncodableValue>(EncodableMap{
183 {EncodableValue("name"), EncodableValue("hello")},
184 {EncodableValue("buffer"), EncodableValue(buffer)},
185 {EncodableValue("width"), EncodableValue(4)},
186 {EncodableValue("height"), EncodableValue(4)},
187 {EncodableValue("hotX"), EncodableValue(0.0)},
188 {EncodableValue("hotY"), EncodableValue(0.0)},
189 }),
190 &create_result_handler);
191
192 SimulateCursorMessage(&messenger, kSetCustomCursorMethod,
193 std::make_unique<EncodableValue>(EncodableMap{
194 {EncodableValue("name"), EncodableValue("hello")},
195 }),
196 &set_result_handler);
197
198 EXPECT_TRUE(success);
199 }
kSetCustomCursorMethod
static constexpr char kSetCustomCursorMethod[]
Definition: cursor_handler.cc:37

References kCreateCustomCursorMethod, and kSetCustomCursorMethod.

## ◆ TEST_F() [24/204]

flutter::testing::TEST_F | ( | CursorHandlerTest | ,
|  | SetNonexistentCustomCursor |
| ) |  |

Definition at line 201 of file cursor_handler_unittests.cc.

201 {
202 UseEngineWithView();
203
204 TestBinaryMessenger messenger;
205 CursorHandler cursor_handler(&messenger, engine());
206
207 bool error = false;
208 MethodResultFunctions<> result_handler(
209 nullptr,
210 [&error](const std::string& error_code, const std::string& error_message,
211 const EncodableValue* value) {
212 error = true;
213 EXPECT_EQ(
214 error_message,
215 "The custom cursor identified by the argument key cannot be found");
216 },
217 nullptr);
218
219 EXPECT_CALL(*proc_table(), LoadCursor).Times(0);
220 EXPECT_CALL(*proc_table(), SetCursor).Times(0);
221
222 SimulateCursorMessage(&messenger, kSetCustomCursorMethod,
223 std::make_unique<EncodableValue>(EncodableMap{
224 {EncodableValue("name"), EncodableValue("hello")},
225 }),
226 &result_handler);
227
228 EXPECT_TRUE(error);
229 }

References kSetCustomCursorMethod.

## ◆ TEST_F() [25/204]

flutter::testing::TEST_F | ( | DisplayManagerWin32Test | ,
|  | HandleDisplayChangeMessage |
| ) |  |

Definition at line 89 of file display_manager_unittests.cc.

89 {
90 // Create a mock Windows proc table
91 auto mock_windows_proc_table =
92 std::make_shared<NiceMock<MockWindowsProcTable>>();
93
94 // Create a mock engine
95 FlutterWindowsEngineBuilder builder(GetContext());
96 builder.SetWindowsProcTable(mock_windows_proc_table);
97 std::unique_ptr<FlutterWindowsEngine> engine = builder.Build();
98
99 EXPECT_CALL(*mock_windows_proc_table, EnumDisplayMonitors(_, _, _, _))
100 .WillRepeatedly(Return(TRUE));
101
102 // Create the display manager with the mock engine
103 auto display_manager = std::make_unique<DisplayManagerWin32>(engine.get());
104
105 // Test handling a display change message
106 HWND dummy_hwnd = reinterpret_cast<HWND>(1);
107 LRESULT result = 0;
108
109 // Verify that WM_DISPLAYCHANGE is handled
110 EXPECT_FALSE(display_manager->HandleWindowMessage(
111 dummy_hwnd, WM_DISPLAYCHANGE, 0, 0, &result));
112
113 // Verify that WM_DPICHANGED is handled
114 EXPECT_FALSE(display_manager->HandleWindowMessage(dummy_hwnd, WM_DPICHANGED,
115 0, 0, &result));
116
117 // Verify that other messages are not handled
118 EXPECT_FALSE(display_manager->HandleWindowMessage(dummy_hwnd, WM_PAINT, 0, 0,
119 &result));
120 }
display_manager
const DisplayManagerWin32 * display_manager
Definition: display_manager.cc:18

References display_manager.

## ◆ TEST_F() [26/204]

flutter::testing::TEST_F | ( | DisplayManagerWin32Test | ,
|  | MultipleMonitors |
| ) |  |

Definition at line 34 of file display_manager_unittests.cc.

34 {
35 auto mock_windows_proc_table =
36 std::make_shared<NiceMock<MockWindowsProcTable>>();
37
38 FlutterWindowsEngineBuilder builder(GetContext());
39 builder.SetWindowsProcTable(mock_windows_proc_table);
40 std::unique_ptr<FlutterWindowsEngine> engine = builder.Build();
41
42 HMONITOR mock_monitor1 = reinterpret_cast<HMONITOR>(123);
43 HMONITOR mock_monitor2 = reinterpret_cast<HMONITOR>(456);
44
45 MONITORINFOEXW monitor_info1 = {};
46 monitor_info1.cbSize = sizeof(MONITORINFOEXW);
47 monitor_info1.rcMonitor = {0, 0, 1920, 1080};
48 monitor_info1.rcWork = {0, 0, 1920, 1080};
49 monitor_info1.dwFlags = MONITORINFOF_PRIMARY;
50 wcscpy_s(monitor_info1.szDevice, L"\\\\.\\DISPLAY1");
51
52 MONITORINFOEXW monitor_info2 = {};
53 monitor_info2.cbSize = sizeof(MONITORINFOEXW);
54 monitor_info2.rcMonitor = {1920, 0, 1920 + 2560, 1440};
55 monitor_info2.rcWork = {1920, 0, 1920 + 2560, 1440};
56 monitor_info2.dwFlags = 0;
57 wcscpy_s(monitor_info2.szDevice, L"\\\\.\\DISPLAY2");
58
59 EXPECT_CALL(*mock_windows_proc_table, GetMonitorInfoW(mock_monitor1, _))
60 .WillOnce(DoAll(SetArgPointee<1>(monitor_info1), Return(TRUE)));
61 EXPECT_CALL(*mock_windows_proc_table, GetMonitorInfoW(mock_monitor2, _))
62 .WillOnce(DoAll(SetArgPointee<1>(monitor_info2), Return(TRUE)));
63
64 EXPECT_CALL(*mock_windows_proc_table,
65 EnumDisplayMonitors(nullptr, nullptr, _, _))
66 .WillOnce([&](HDC hdc, LPCRECT lprcClip, MONITORENUMPROC lpfnEnum,
67 LPARAM dwData) {
68 lpfnEnum(mock_monitor1, nullptr, &monitor_info1.rcMonitor, dwData);
69 lpfnEnum(mock_monitor2, nullptr, &monitor_info2.rcMonitor, dwData);
70 return TRUE;
71 });
72
73 // Set up GetDpiForMonitor to return different DPI values
74 EXPECT_CALL(*mock_windows_proc_table, GetDpiForMonitor(mock_monitor1, _))
75 .WillRepeatedly(Return(96)); // Default/Standard DPI
76 EXPECT_CALL(*mock_windows_proc_table, GetDpiForMonitor(mock_monitor2, _))
77 .WillRepeatedly(Return(144)); // High DPI
78
79 EXPECT_CALL(*mock_windows_proc_table, EnumDisplaySettings(_, _, _))
80 .WillRepeatedly(Return(TRUE));
81
82 // Create the display manager with the mock engine
83 auto display_manager = std::make_unique<DisplayManagerWin32>(engine.get());
84
85 display_manager->UpdateDisplays();
86 }

References display_manager, and flutter::GetDpiForMonitor().

## ◆ TEST_F() [27/204]

flutter::testing::TEST_F | ( | FlutterWindowsEngineTest | ,
|  | AccessibilityAnnouncement |
| ) |  |

Definition at line 791 of file flutter_windows_engine_unittests.cc.

791 {
792 auto& context = GetContext();
793 WindowsConfigBuilder builder{context};
794 builder.SetDartEntrypoint("sendAccessibilityAnnouncement");
795
796 bool done = false;
797 auto native_entry =
798 CREATE_NATIVE_ENTRY([&](Dart_NativeArguments args) { done = true; });
799 context.AddNativeFunction("Signal", native_entry);
800
801 EnginePtr engine{builder.RunHeadless()};
802 ASSERT_NE(engine, nullptr);
803
804 ui::AXPlatformNodeDelegateBase parent_delegate;
805 AlertPlatformNodeDelegate delegate{parent_delegate};
806
807 auto window_binding_handler =
808 std::make_unique<NiceMock<MockWindowBindingHandler>>();
809 EXPECT_CALL(*window_binding_handler, GetAlertDelegate)
810 .WillOnce(Return(&delegate));
811
812 auto windows_engine = reinterpret_cast<FlutterWindowsEngine*>(engine.get());
813 MockFlutterWindowsView view{windows_engine,
814 std::move(window_binding_handler)};
815 EngineModifier modifier{windows_engine};
816 modifier.SetImplicitView(&view);
817
818 windows_engine->UpdateSemanticsEnabled(true);
819
820 EXPECT_CALL(view, NotifyWinEventWrapper).Times(1);
821
822 // Rely on timeout mechanism in CI.
823 while (!done) {
824 windows_engine->task_runner()->ProcessTasks();
825 }
826 }

References flutter::FlutterWindowsEngine::UpdateSemanticsEnabled().

## ◆ TEST_F() [28/204]

flutter::testing::TEST_F | ( | FlutterWindowsEngineTest | ,
|  | AccessibilityAnnouncementHeadless |
| ) |  |

Definition at line 829 of file flutter_windows_engine_unittests.cc.

829 {
830 auto& context = GetContext();
831 WindowsConfigBuilder builder{context};
832 builder.SetDartEntrypoint("sendAccessibilityAnnouncement");
833
834 bool done = false;
835 auto native_entry =
836 CREATE_NATIVE_ENTRY([&](Dart_NativeArguments args) { done = true; });
837 context.AddNativeFunction("Signal", native_entry);
838
839 EnginePtr engine{builder.RunHeadless()};
840 ASSERT_NE(engine, nullptr);
841
842 auto windows_engine = reinterpret_cast<FlutterWindowsEngine*>(engine.get());
843 windows_engine->UpdateSemanticsEnabled(true);
844
845 // Rely on timeout mechanism in CI.
846 while (!done) {
847 windows_engine->task_runner()->ProcessTasks();
848 }
849 }

References flutter::FlutterWindowsEngine::UpdateSemanticsEnabled().

## ◆ TEST_F() [29/204]

flutter::testing::TEST_F | ( | FlutterWindowsEngineTest | ,
|  | AccessibilityTooltip |
| ) |  |

Definition at line 853 of file flutter_windows_engine_unittests.cc.

853 {
854 fml::testing::LogCapture log_capture;
855
856 auto& context = GetContext();
857 WindowsConfigBuilder builder{context};
858 builder.SetDartEntrypoint("sendAccessibilityTooltipEvent");
859
860 bool done = false;
861 auto native_entry =
862 CREATE_NATIVE_ENTRY([&](Dart_NativeArguments args) { done = true; });
863 context.AddNativeFunction("Signal", native_entry);
864
865 ViewControllerPtr controller{builder.Run()};
866 ASSERT_NE(controller, nullptr);
867
868 auto engine = FlutterDesktopViewControllerGetEngine(controller.get());
869 auto windows_engine = reinterpret_cast<FlutterWindowsEngine*>(engine);
870 windows_engine->UpdateSemanticsEnabled(true);
871
872 // Rely on timeout mechanism in CI.
873 while (!done) {
874 windows_engine->task_runner()->ProcessTasks();
875 }
876
877 // Verify no error was logged.
878 // Regression test for:
879 // https://github.com/flutter/flutter/issues/144274
880 EXPECT_EQ(log_capture.str().find("tooltip"), std::string::npos);
881 }
FlutterDesktopViewControllerGetEngine
FlutterDesktopEngineRef FlutterDesktopViewControllerGetEngine(FlutterDesktopViewControllerRef ref)
Definition: flutter_windows.cc:148

References FlutterDesktopViewControllerGetEngine(), and flutter::FlutterWindowsEngine::UpdateSemanticsEnabled().

## ◆ TEST_F() [30/204]

flutter::testing::TEST_F | ( | FlutterWindowsEngineTest | ,
|  | AddPluginRegistrarDestructionCallback |
| ) |  |

Definition at line 639 of file flutter_windows_engine_unittests.cc.

639 {
640 FlutterWindowsEngineBuilder builder{GetContext()};
641 std::unique_ptr<FlutterWindowsEngine> engine = builder.Build();
642 EngineModifier modifier(engine.get());
643
644 MockEmbedderApiForKeyboard(modifier,
645 std::make_shared<MockKeyResponseController>());
646
647 engine->Run();
648
649 // Verify that destruction handlers don't overwrite each other.
650 int result1 = 0;
651 int result2 = 0;
652 engine->AddPluginRegistrarDestructionCallback(
653 [](FlutterDesktopPluginRegistrarRef ref) {
654 auto result = reinterpret_cast<int*>(ref);
655 *result = 1;
656 },
657 reinterpret_cast<FlutterDesktopPluginRegistrarRef>(&result1));
658 engine->AddPluginRegistrarDestructionCallback(
659 [](FlutterDesktopPluginRegistrarRef ref) {
660 auto result = reinterpret_cast<int*>(ref);
661 *result = 2;
662 },
663 reinterpret_cast<FlutterDesktopPluginRegistrarRef>(&result2));
664
665 engine->Stop();
666 EXPECT_EQ(result1, 1);
667 EXPECT_EQ(result2, 2);
668 }
FlutterDesktopPluginRegistrar
Definition: window_state.h:23

## ◆ TEST_F() [31/204]

flutter::testing::TEST_F | ( | FlutterWindowsEngineTest | ,
|  | AddViewFailureDoesNotHang |
| ) |  |

Definition at line 1416 of file flutter_windows_engine_unittests.cc.

1416 {
1417 FlutterWindowsEngineBuilder builder{GetContext()};
1418 auto engine = builder.Build();
1419
1420 EngineModifier modifier{engine.get()};
1421
1422 modifier.embedder_api().RunsAOTCompiledDartCode = []() { return false; };
1423 modifier.embedder_api().AddView = MOCK_ENGINE_PROC(
1424 AddView,
1425 [](FLUTTER_API_SYMBOL(FlutterEngine) engine,
1426 const FlutterAddViewInfo* info) { return kInternalInconsistency; });
1427
1428 ASSERT_TRUE(engine->Run());
1429
1430 // Create the first view. This is the implicit view and isn't added to the
1431 // engine.
1432 auto implicit_window = std::make_unique<NiceMock<MockWindowBindingHandler>>();
1433
1434 std::unique_ptr<FlutterWindowsView> implicit_view =
1435 engine->CreateView(std::move(implicit_window),
1436 /*is_sized_to_content=*/false, BoxConstraints());
1437
1438 EXPECT_TRUE(implicit_view);
1439
1440 // Create a second view. The embedder attempts to add it to the engine.
1441 auto second_window = std::make_unique<NiceMock<MockWindowBindingHandler>>();
1442
1443 EXPECT_DEBUG_DEATH(
1444 engine->CreateView(std::move(second_window),
1445 /*is_sized_to_content=*/false, BoxConstraints()),
1446 "FlutterEngineAddView returned an unexpected result");
1447 }

References flutter::FlutterEngine::Run().

## ◆ TEST_F() [32/204]

flutter::testing::TEST_F | ( | FlutterWindowsEngineTest | ,
|  | ApplicationLifecycleExternalWindow |
| ) |  |

Definition at line 1122 of file flutter_windows_engine_unittests.cc.

1122 {
1123 FlutterWindowsEngineBuilder builder{GetContext()};
1124
1125 auto engine = builder.Build();
1126 auto window_binding_handler =
1127 std::make_unique<::testing::NiceMock<MockWindowBindingHandler>>();
1128 MockFlutterWindowsView view(engine.get(), std::move(window_binding_handler));
1129
1130 EngineModifier modifier(engine.get());
1131 modifier.SetImplicitView(&view);
1132 modifier.embedder_api().RunsAOTCompiledDartCode = []() { return false; };
1133 auto handler = std::make_unique<MockWindowsLifecycleManager>(engine.get());
1134 EXPECT_CALL(*handler, IsLastWindowOfProcess).WillOnce(Return(false));
1135 modifier.SetLifecycleManager(std::move(handler));
1136 engine->lifecycle_manager()->BeginProcessingExit();
1137
1138 engine->lifecycle_manager()->ExternalWindowMessage(0, WM_CLOSE, 0, 0);
1139 }

## ◆ TEST_F() [33/204]

flutter::testing::TEST_F | ( | FlutterWindowsEngineTest | ,
|  | ChannelListenedTo |
| ) |  |

Definition at line 1366 of file flutter_windows_engine_unittests.cc.

1366 {
1367 FlutterWindowsEngineBuilder builder{GetContext()};
1368 builder.SetDartEntrypoint("enableLifecycleToFrom");
1369
1370 auto engine = builder.Build();
1371 auto window_binding_handler =
1372 std::make_unique<::testing::NiceMock<MockWindowBindingHandler>>();
1373 MockFlutterWindowsView view(engine.get(), std::move(window_binding_handler));
1374
1375 EngineModifier modifier(engine.get());
1376 modifier.SetImplicitView(&view);
1377 modifier.embedder_api().RunsAOTCompiledDartCode = []() { return false; };
1378
1379 bool lifecycle_began = false;
1380 auto handler = std::make_unique<MockWindowsLifecycleManager>(engine.get());
1381 handler->begin_processing_callback = [&]() { lifecycle_began = true; };
1382 modifier.SetLifecycleManager(std::move(handler));
1383
1384 engine->Run();
1385
1386 while (!lifecycle_began) {
1387 engine->task_runner()->ProcessTasks();
1388 }
1389 }

## ◆ TEST_F() [34/204]

flutter::testing::TEST_F | ( | FlutterWindowsEngineTest | ,
|  | ConfiguresFrameVsync |
| ) |  |

Definition at line 297 of file flutter_windows_engine_unittests.cc.

297 {
298 FlutterWindowsEngineBuilder builder{GetContext()};
299 std::unique_ptr<FlutterWindowsEngine> engine = builder.Build();
300 EngineModifier modifier(engine.get());
301 bool on_vsync_called = false;
302
303 modifier.embedder_api().GetCurrentTime =
304 MOCK_ENGINE_PROC(GetCurrentTime, ([]() -> uint64_t { return 1; }));
305 modifier.embedder_api().OnVsync = MOCK_ENGINE_PROC(
306 OnVsync,
307 ([&on_vsync_called, engine_instance = engine.get()](
308 FLUTTER_API_SYMBOL(FlutterEngine) engine, intptr_t baton,
309 uint64_t frame_start_time_nanos, uint64_t frame_target_time_nanos) {
310 EXPECT_EQ(baton, 1);
311 EXPECT_EQ(frame_start_time_nanos, 16600000);
312 EXPECT_EQ(frame_target_time_nanos, 33200000);
313 on_vsync_called = true;
314 return kSuccess;
315 }));
316 modifier.SetStartTime(0);
317 modifier.SetFrameInterval(16600000);
318
319 engine->OnVsync(1);
320
321 EXPECT_TRUE(on_vsync_called);
322 }

## ◆ TEST_F() [35/204]

flutter::testing::TEST_F | ( | FlutterWindowsEngineTest | ,
|  | DispatchSemanticsAction |
| ) |  |

Definition at line 594 of file flutter_windows_engine_unittests.cc.

594 {
595 FlutterWindowsEngineBuilder builder{GetContext()};
596 std::unique_ptr<FlutterWindowsEngine> engine = builder.Build();
597 EngineModifier modifier(engine.get());
598
599 bool called = false;
600 std::string message = "Hello";
601 modifier.embedder_api().SendSemanticsAction = MOCK_ENGINE_PROC(
602 SendSemanticsAction, ([&called, &message](auto engine, auto info) {
603 called = true;
604 EXPECT_EQ(info->view_id, 456);
605 EXPECT_EQ(info->node_id, 42);
606 EXPECT_EQ(info->action, kFlutterSemanticsActionDismiss);
607 EXPECT_EQ(memcmp(info->data, message.c_str(), message.size()), 0);
608 EXPECT_EQ(info->data_length, message.size());
609 return kSuccess;
610 }));
611
612 auto data = fml::MallocMapping::Copy(message.c_str(), message.size());
613 engine->DispatchSemanticsAction(456, 42, kFlutterSemanticsActionDismiss,
614 std::move(data));
615 EXPECT_TRUE(called);
616 }

References message.

## ◆ TEST_F() [36/204]

flutter::testing::TEST_F | ( | FlutterWindowsEngineTest | ,
|  | EnableApplicationLifecycle |
| ) |  |

Definition at line 1102 of file flutter_windows_engine_unittests.cc.

1102 {
1103 FlutterWindowsEngineBuilder builder{GetContext()};
1104
1105 auto engine = builder.Build();
1106 auto window_binding_handler =
1107 std::make_unique<::testing::NiceMock<MockWindowBindingHandler>>();
1108 MockFlutterWindowsView view(engine.get(), std::move(window_binding_handler));
1109
1110 EngineModifier modifier(engine.get());
1111 modifier.SetImplicitView(&view);
1112 modifier.embedder_api().RunsAOTCompiledDartCode = []() { return false; };
1113 auto handler = std::make_unique<MockWindowsLifecycleManager>(engine.get());
1114 EXPECT_CALL(*handler, IsLastWindowOfProcess).WillOnce(Return(false));
1115 modifier.SetLifecycleManager(std::move(handler));
1116 engine->lifecycle_manager()->BeginProcessingExit();
1117
1118 engine->window_proc_delegate_manager()->OnTopLevelWindowProc(0, WM_CLOSE, 0,
1119 0);
1120 }

## ◆ TEST_F() [37/204]

flutter::testing::TEST_F | ( | FlutterWindowsEngineTest | ,
|  | EnableLifecycleState |
| ) |  |

Definition at line 1265 of file flutter_windows_engine_unittests.cc.

1265 {
1266 FlutterWindowsEngineBuilder builder{GetContext()};
1267 builder.SetDartEntrypoint("enableLifecycleTest");
1268 bool finished = false;
1269
1270 auto engine = builder.Build();
1271 auto window_binding_handler =
1272 std::make_unique<::testing::NiceMock<MockWindowBindingHandler>>();
1273 MockFlutterWindowsView view(engine.get(), std::move(window_binding_handler));
1274
1275 EngineModifier modifier(engine.get());
1276 modifier.SetImplicitView(&view);
1277 modifier.embedder_api().RunsAOTCompiledDartCode = []() { return false; };
1278 auto handler = std::make_unique<MockWindowsLifecycleManager>(engine.get());
1279 EXPECT_CALL(*handler, SetLifecycleState)
1280 .WillRepeatedly([handler_ptr = handler.get()](AppLifecycleState state) {
1281 handler_ptr->WindowsLifecycleManager::SetLifecycleState(state);
1282 });
1283 modifier.SetLifecycleManager(std::move(handler));
1284
1285 auto binary_messenger =
1286 std::make_unique<BinaryMessengerImpl>(engine->messenger());
1287 // Mark the test only as completed on receiving an inactive state message.
1288 binary_messenger->SetMessageHandler(
1289 "flutter/unittest", [&finished](const uint8_t* message,
1290 size_t message_size, BinaryReply reply) {
1291 std::string contents(message, message + message_size);
1292 EXPECT_NE(contents.find("AppLifecycleState.inactive"),
1293 std::string::npos);
1294 finished = true;
1295 char response[] = "";
1296 reply(reinterpret_cast<uint8_t*>(response), 0);
1297 });
1298
1299 engine->Run();
1300
1301 // Test that setting the state before enabling lifecycle does nothing.
1302 HWND hwnd = reinterpret_cast<HWND>(1);
1303 view.OnWindowStateEvent(hwnd, WindowStateEvent::kShow);
1304 view.OnWindowStateEvent(hwnd, WindowStateEvent::kHide);
1305 EXPECT_FALSE(finished);
1306
1307 // Test that we can set the state afterwards.
1308
1309 engine->lifecycle_manager()->BeginProcessingLifecycle();
1310 view.OnWindowStateEvent(hwnd, WindowStateEvent::kShow);
1311
1312 while (!finished) {
1313 engine->task_runner()->ProcessTasks();
1314 }
1315 }
flutter::AppLifecycleState
AppLifecycleState
Definition: app_lifecycle_state.h:32

References flutter::kHide, flutter::kShow, and message.

## ◆ TEST_F() [38/204]

flutter::testing::TEST_F | ( | FlutterWindowsEngineTest | ,
|  | ExternalWindowMessage |
| ) |  |

Definition at line 1195 of file flutter_windows_engine_unittests.cc.

1195 {
1196 FlutterWindowsEngineBuilder builder{GetContext()};
1197
1198 auto engine = builder.Build();
1199 auto window_binding_handler =
1200 std::make_unique<::testing::NiceMock<MockWindowBindingHandler>>();
1201 MockFlutterWindowsView view(engine.get(), std::move(window_binding_handler));
1202
1203 EngineModifier modifier(engine.get());
1204 modifier.SetImplicitView(&view);
1205 modifier.embedder_api().RunsAOTCompiledDartCode = []() { return false; };
1206 // Sets lifecycle state to resumed.
1207 engine->Run();
1208
1209 // Ensure HWND(1) is in the set of visible windows before hiding it.
1210 engine->ProcessExternalWindowMessage(reinterpret_cast<HWND>(1), WM_SHOWWINDOW,
1211 TRUE, NULL);
1212 engine->ProcessExternalWindowMessage(reinterpret_cast<HWND>(1), WM_SHOWWINDOW,
1213 FALSE, NULL);
1214
1215 while (engine->lifecycle_manager()->IsUpdateStateScheduled()) {
1216 PumpMessage();
1217 }
1218
1219 EXPECT_EQ(engine->lifecycle_manager()->GetLifecycleState(),
1220 AppLifecycleState::kHidden);
1221 }

References flutter::kHidden.

## ◆ TEST_F() [39/204]

flutter::testing::TEST_F | ( | FlutterWindowsEngineTest | ,
|  | GetExecutableName |
| ) |  |

Definition at line 702 of file flutter_windows_engine_unittests.cc.

702 {
703 FlutterWindowsEngineBuilder builder{GetContext()};
704 std::unique_ptr<FlutterWindowsEngine> engine = builder.Build();
705 EXPECT_EQ(engine->GetExecutableName(), "flutter_windows_unittests.exe");
706 }

## ◆ TEST_F() [40/204]

flutter::testing::TEST_F | ( | FlutterWindowsEngineTest | ,
|  | InnerWindowHidden |
| ) |  |

Definition at line 1223 of file flutter_windows_engine_unittests.cc.

1223 {
1224 FlutterWindowsEngineBuilder builder{GetContext()};
1225 HWND outer = reinterpret_cast<HWND>(1);
1226 HWND inner = reinterpret_cast<HWND>(2);
1227
1228 auto engine = builder.Build();
1229 auto window_binding_handler =
1230 std::make_unique<::testing::NiceMock<MockWindowBindingHandler>>();
1231 MockFlutterWindowsView view(engine.get(), std::move(window_binding_handler));
1232 ON_CALL(view, GetWindowHandle).WillByDefault([=]() { return inner; });
1233
1234 EngineModifier modifier(engine.get());
1235 modifier.SetImplicitView(&view);
1236 modifier.embedder_api().RunsAOTCompiledDartCode = []() { return false; };
1237 // Sets lifecycle state to resumed.
1238 engine->Run();
1239
1240 // Show both top-level and Flutter window.
1241 engine->window_proc_delegate_manager()->OnTopLevelWindowProc(
1242 outer, WM_SHOWWINDOW, TRUE, NULL);
1243 view.OnWindowStateEvent(inner, WindowStateEvent::kShow);
1244 view.OnWindowStateEvent(inner, WindowStateEvent::kFocus);
1245
1246 while (engine->lifecycle_manager()->IsUpdateStateScheduled()) {
1247 PumpMessage();
1248 }
1249
1250 EXPECT_EQ(engine->lifecycle_manager()->GetLifecycleState(),
1251 AppLifecycleState::kResumed);
1252
1253 // Hide Flutter window, but not top level window.
1254 view.OnWindowStateEvent(inner, WindowStateEvent::kHide);
1255
1256 while (engine->lifecycle_manager()->IsUpdateStateScheduled()) {
1257 PumpMessage();
1258 }
1259
1260 // The top-level window is still visible, so we ought not enter hidden state.
1261 EXPECT_EQ(engine->lifecycle_manager()->GetLifecycleState(),
1262 AppLifecycleState::kInactive);
1263 }

References flutter::kFocus, flutter::kHide, flutter::kInactive, flutter::kResumed, and flutter::kShow.

## ◆ TEST_F() [41/204]

flutter::testing::TEST_F | ( | FlutterWindowsEngineTest | ,
|  | LifecycleManagerDisabledByDefault |
| ) |  |

Definition at line 1083 of file flutter_windows_engine_unittests.cc.

1083 {
1084 FlutterWindowsEngineBuilder builder{GetContext()};
1085
1086 auto engine = builder.Build();
1087 auto window_binding_handler =
1088 std::make_unique<::testing::NiceMock<MockWindowBindingHandler>>();
1089 MockFlutterWindowsView view(engine.get(), std::move(window_binding_handler));
1090
1091 EngineModifier modifier(engine.get());
1092 modifier.SetImplicitView(&view);
1093 modifier.embedder_api().RunsAOTCompiledDartCode = []() { return false; };
1094 auto handler = std::make_unique<MockWindowsLifecycleManager>(engine.get());
1095 EXPECT_CALL(*handler, IsLastWindowOfProcess).Times(0);
1096 modifier.SetLifecycleManager(std::move(handler));
1097
1098 engine->window_proc_delegate_manager()->OnTopLevelWindowProc(0, WM_CLOSE, 0,
1099 0);
1100 }

## ◆ TEST_F() [42/204]

flutter::testing::TEST_F | ( | FlutterWindowsEngineTest | ,
|  | LifecycleStateToFrom |
| ) |  |

Definition at line 1317 of file flutter_windows_engine_unittests.cc.

1317 {
1318 FlutterWindowsEngineBuilder builder{GetContext()};
1319 builder.SetDartEntrypoint("enableLifecycleToFrom");
1320 bool enabled_lifecycle = false;
1321 bool dart_responded = false;
1322
1323 auto engine = builder.Build();
1324 auto window_binding_handler =
1325 std::make_unique<::testing::NiceMock<MockWindowBindingHandler>>();
1326 MockFlutterWindowsView view(engine.get(), std::move(window_binding_handler));
1327
1328 EngineModifier modifier(engine.get());
1329 modifier.SetImplicitView(&view);
1330 modifier.embedder_api().RunsAOTCompiledDartCode = []() { return false; };
1331 auto handler = std::make_unique<MockWindowsLifecycleManager>(engine.get());
1332 EXPECT_CALL(*handler, SetLifecycleState)
1333 .WillRepeatedly([handler_ptr = handler.get()](AppLifecycleState state) {
1334 handler_ptr->WindowsLifecycleManager::SetLifecycleState(state);
1335 });
1336 handler->begin_processing_callback = [&]() { enabled_lifecycle = true; };
1337 modifier.SetLifecycleManager(std::move(handler));
1338
1339 auto binary_messenger =
1340 std::make_unique<BinaryMessengerImpl>(engine->messenger());
1341 binary_messenger->SetMessageHandler(
1342 "flutter/unittest",
1343 [&](const uint8_t* message, size_t message_size, BinaryReply reply) {
1344 std::string contents(message, message + message_size);
1345 EXPECT_NE(contents.find("AppLifecycleState."), std::string::npos);
1346 dart_responded = true;
1347 char response[] = "";
1348 reply(reinterpret_cast<uint8_t*>(response), 0);
1349 });
1350
1351 engine->Run();
1352
1353 while (!enabled_lifecycle) {
1354 engine->task_runner()->ProcessTasks();
1355 }
1356
1357 HWND hwnd = reinterpret_cast<HWND>(1);
1358 view.OnWindowStateEvent(hwnd, WindowStateEvent::kShow);
1359 view.OnWindowStateEvent(hwnd, WindowStateEvent::kHide);
1360
1361 while (!dart_responded) {
1362 engine->task_runner()->ProcessTasks();
1363 }
1364 }

References flutter::kHide, flutter::kShow, and message.

## ◆ TEST_F() [43/204]

flutter::testing::TEST_F | ( | FlutterWindowsEngineTest | ,
|  | LifecycleStateTransition |
| ) |  |

Definition at line 1141 of file flutter_windows_engine_unittests.cc.

1141 {
1142 FlutterWindowsEngineBuilder builder{GetContext()};
1143
1144 auto engine = builder.Build();
1145 auto window_binding_handler =
1146 std::make_unique<::testing::NiceMock<MockWindowBindingHandler>>();
1147 MockFlutterWindowsView view(engine.get(), std::move(window_binding_handler));
1148
1149 EngineModifier modifier(engine.get());
1150 modifier.SetImplicitView(&view);
1151 modifier.embedder_api().RunsAOTCompiledDartCode = []() { return false; };
1152 engine->Run();
1153
1154 engine->window_proc_delegate_manager()->OnTopLevelWindowProc(
1155 (HWND)1, WM_SIZE, SIZE_RESTORED, 0);
1156
1157 while (engine->lifecycle_manager()->IsUpdateStateScheduled()) {
1158 PumpMessage();
1159 }
1160
1161 EXPECT_EQ(engine->lifecycle_manager()->GetLifecycleState(),
1162 AppLifecycleState::kInactive);
1163
1164 engine->lifecycle_manager()->OnWindowStateEvent((HWND)1,
1165 WindowStateEvent::kFocus);
1166
1167 while (engine->lifecycle_manager()->IsUpdateStateScheduled()) {
1168 PumpMessage();
1169 }
1170
1171 EXPECT_EQ(engine->lifecycle_manager()->GetLifecycleState(),
1172 AppLifecycleState::kResumed);
1173
1174 engine->window_proc_delegate_manager()->OnTopLevelWindowProc(
1175 (HWND)1, WM_SIZE, SIZE_MINIMIZED, 0);
1176
1177 while (engine->lifecycle_manager()->IsUpdateStateScheduled()) {
1178 PumpMessage();
1179 }
1180
1181 EXPECT_EQ(engine->lifecycle_manager()->GetLifecycleState(),
1182 AppLifecycleState::kHidden);
1183
1184 engine->window_proc_delegate_manager()->OnTopLevelWindowProc(
1185 (HWND)1, WM_SIZE, SIZE_RESTORED, 0);
1186
1187 while (engine->lifecycle_manager()->IsUpdateStateScheduled()) {
1188 PumpMessage();
1189 }
1190
1191 EXPECT_EQ(engine->lifecycle_manager()->GetLifecycleState(),
1192 AppLifecycleState::kInactive);
1193 }

References flutter::kFocus, flutter::kHidden, flutter::kInactive, and flutter::kResumed.

## ◆ TEST_F() [44/204]

flutter::testing::TEST_F | ( | FlutterWindowsEngineTest | ,
|  | MergedUIThread |
| ) |  |

Definition at line 1467 of file flutter_windows_engine_unittests.cc.

1467 {
1468 auto& context = GetContext();
1469 WindowsConfigBuilder builder{context};
1470 builder.SetDartEntrypoint("mergedUIThread");
1471 builder.SetUIThreadPolicy(FlutterDesktopUIThreadPolicy::RunOnPlatformThread);
1472
1473 std::optional<std::thread::id> ui_thread_id;
1474
1475 auto native_entry = CREATE_NATIVE_ENTRY([&](Dart_NativeArguments args) {
1476 ui_thread_id = std::this_thread::get_id();
1477 });
1478 context.AddNativeFunction("Signal", native_entry);
1479
1480 EnginePtr engine{builder.RunHeadless()};
1481 while (!ui_thread_id) {
1482 PumpMessage();
1483 }
1484 ASSERT_EQ(*ui_thread_id, std::this_thread::get_id());
1485 }
RunOnPlatformThread
@ RunOnPlatformThread
Definition: flutter_windows.h:58

References RunOnPlatformThread.

## ◆ TEST_F() [45/204]

flutter::testing::TEST_F | ( | FlutterWindowsEngineTest | ,
|  | OnViewFocusChangeRequest |
| ) |  |

Definition at line 1487 of file flutter_windows_engine_unittests.cc.

1487 {
1488 FlutterWindowsEngineBuilder builder{GetContext()};
1489 std::unique_ptr<FlutterWindowsEngine> engine = builder.Build();
1490 auto window_binding_handler =
1491 std::make_unique<::testing::NiceMock<MockWindowBindingHandler>>();
1492 MockFlutterWindowsView view(engine.get(), std::move(window_binding_handler));
1493
1494 EngineModifier modifier(engine.get());
1495 modifier.SetImplicitView(&view);
1496
1497 FlutterViewFocusChangeRequest request;
1498 request.view_id = kImplicitViewId;
1499
1500 EXPECT_CALL(view, Focus()).WillOnce(Return(true));
1501 modifier.OnViewFocusChangeRequest(&request);
1502 }

References flutter::kImplicitViewId.

## ◆ TEST_F() [46/204]

flutter::testing::TEST_F | ( | FlutterWindowsEngineTest | ,
|  | PlatformMessageRespondOnDifferentThread |
| ) |  |

Definition at line 484 of file flutter_windows_engine_unittests.cc.

484 {
485 FlutterWindowsEngineBuilder builder{GetContext()};
486 builder.SetDartEntrypoint("hiPlatformChannels");
487
488 std::unique_ptr<FlutterWindowsEngine> engine = builder.Build();
489
490 EngineModifier modifier(engine.get());
491 modifier.embedder_api().RunsAOTCompiledDartCode = []() { return false; };
492
493 auto binary_messenger =
494 std::make_unique<BinaryMessengerImpl>(engine->messenger());
495
496 engine->Run();
497 bool did_call_callback = false;
498 bool did_call_reply = false;
499 bool did_call_dart_reply = false;
500 std::string channel = "hi";
501 std::unique_ptr<std::thread> reply_thread;
502 binary_messenger->SetMessageHandler(
503 channel,
504 [&did_call_callback, &did_call_dart_reply, &reply_thread](
505 const uint8_t* message, size_t message_size, BinaryReply reply) {
506 if (message_size == 5) {
507 EXPECT_EQ(message[0], static_cast<uint8_t>('h'));
508 reply_thread.reset(new std::thread([reply = std::move(reply)]() {
509 char response[] = {'b', 'y', 'e'};
510 reply(reinterpret_cast<uint8_t*>(response), 3);
511 }));
512 did_call_callback = true;
513 } else {
514 EXPECT_EQ(message_size, 3);
515 EXPECT_EQ(message[0], static_cast<uint8_t>('b'));
516 did_call_dart_reply = true;
517 }
518 });
519 char payload[] = {'h', 'e', 'l', 'l', 'o'};
520 binary_messenger->Send(
521 channel, reinterpret_cast<uint8_t*>(payload), 5,
522 [&did_call_reply](const uint8_t* reply, size_t reply_size) {
523 EXPECT_EQ(reply_size, 5);
524 EXPECT_EQ(reply[0], static_cast<uint8_t>('h'));
525 did_call_reply = true;
526 });
527 // Rely on timeout mechanism in CI.
528 while (!did_call_callback || !did_call_reply || !did_call_dart_reply) {
529 engine->task_runner()->ProcessTasks();
530 }
531 ASSERT_TRUE(reply_thread);
532 reply_thread->join();
533 }

References message.

## ◆ TEST_F() [47/204]

flutter::testing::TEST_F | ( | FlutterWindowsEngineTest | ,
|  | PlatformMessageRoundTrip |
| ) |  |

Definition at line 439 of file flutter_windows_engine_unittests.cc.

439 {
440 FlutterWindowsEngineBuilder builder{GetContext()};
441 builder.SetDartEntrypoint("hiPlatformChannels");
442
443 std::unique_ptr<FlutterWindowsEngine> engine = builder.Build();
444 EngineModifier modifier(engine.get());
445 modifier.embedder_api().RunsAOTCompiledDartCode = []() { return false; };
446
447 auto binary_messenger =
448 std::make_unique<BinaryMessengerImpl>(engine->messenger());
449
450 engine->Run();
451 bool did_call_callback = false;
452 bool did_call_reply = false;
453 bool did_call_dart_reply = false;
454 std::string channel = "hi";
455 binary_messenger->SetMessageHandler(
456 channel,
457 [&did_call_callback, &did_call_dart_reply](
458 const uint8_t* message, size_t message_size, BinaryReply reply) {
459 if (message_size == 5) {
460 EXPECT_EQ(message[0], static_cast<uint8_t>('h'));
461 char response[] = {'b', 'y', 'e'};
462 reply(reinterpret_cast<uint8_t*>(response), 3);
463 did_call_callback = true;
464 } else {
465 EXPECT_EQ(message_size, 3);
466 EXPECT_EQ(message[0], static_cast<uint8_t>('b'));
467 did_call_dart_reply = true;
468 }
469 });
470 char payload[] = {'h', 'e', 'l', 'l', 'o'};
471 binary_messenger->Send(
472 channel, reinterpret_cast<uint8_t*>(payload), 5,
473 [&did_call_reply](const uint8_t* reply, size_t reply_size) {
474 EXPECT_EQ(reply_size, 5);
475 EXPECT_EQ(reply[0], static_cast<uint8_t>('h'));
476 did_call_reply = true;
477 });
478 // Rely on timeout mechanism in CI.
479 while (!did_call_callback || !did_call_reply || !did_call_dart_reply) {
480 engine->task_runner()->ProcessTasks();
481 }
482 }

References message.

## ◆ TEST_F() [48/204]

flutter::testing::TEST_F | ( | FlutterWindowsEngineTest | ,
|  | PostRasterThreadTask |
| ) |  |

Definition at line 751 of file flutter_windows_engine_unittests.cc.

751 {
752 FlutterWindowsEngineBuilder builder{GetContext()};
753 std::unique_ptr<FlutterWindowsEngine> engine = builder.Build();
754 EngineModifier modifier(engine.get());
755
756 modifier.embedder_api().PostRenderThreadTask = MOCK_ENGINE_PROC(
757 PostRenderThreadTask, ([](auto engine, auto callback, auto context) {
758 callback(context);
759 return kSuccess;
760 }));
761
762 bool called = false;
763 engine->PostRasterThreadTask([&called]() { called = true; });
764
765 EXPECT_TRUE(called);
766 }

References callback.

## ◆ TEST_F() [49/204]

flutter::testing::TEST_F | ( | FlutterWindowsEngineTest | ,
|  | ReceivePlatformViewMessage |
| ) |  |

Definition at line 1391 of file flutter_windows_engine_unittests.cc.

1391 {
1392 FlutterWindowsEngineBuilder builder{GetContext()};
1393 builder.SetDartEntrypoint("sendCreatePlatformViewMethod");
1394 auto engine = builder.Build();
1395
1396 EngineModifier modifier{engine.get()};
1397 modifier.embedder_api().RunsAOTCompiledDartCode = []() { return false; };
1398
1399 bool received_call = false;
1400
1401 auto manager = std::make_unique<MockPlatformViewManager>(engine.get());
1402 EXPECT_CALL(*manager, AddPlatformView)
1403 .WillOnce([&](PlatformViewId id, std::string_view type_name) {
1404 received_call = true;
1405 return true;
1406 });
1407 modifier.SetPlatformViewPlugin(std::move(manager));
1408
1409 engine->Run();
1410
1411 while (!received_call) {
1412 engine->task_runner()->ProcessTasks();
1413 }
1414 }
PlatformViewId
int64_t PlatformViewId
Definition: flutter_windows_internal.h:42

## ◆ TEST_F() [50/204]

flutter::testing::TEST_F | ( | FlutterWindowsEngineTest | ,
|  | RemoveViewFailureDoesNotHang |
| ) |  |

Definition at line 1449 of file flutter_windows_engine_unittests.cc.

1449 {
1450 FlutterWindowsEngineBuilder builder{GetContext()};
1451 builder.SetDartEntrypoint("sendCreatePlatformViewMethod");
1452 auto engine = builder.Build();
1453
1454 EngineModifier modifier{engine.get()};
1455
1456 modifier.embedder_api().RunsAOTCompiledDartCode = []() { return false; };
1457 modifier.embedder_api().RemoveView = MOCK_ENGINE_PROC(
1458 RemoveView,
1459 [](FLUTTER_API_SYMBOL(FlutterEngine) engine,
1460 const FlutterRemoveViewInfo* info) { return kInternalInconsistency; });
1461
1462 ASSERT_TRUE(engine->Run());
1463 EXPECT_DEBUG_DEATH(engine->RemoveView(123),
1464 "FlutterEngineRemoveView returned an unexpected result");
1465 }

References flutter::FlutterEngine::Run().

## ◆ TEST_F() [51/204]

flutter::testing::TEST_F | ( | FlutterWindowsEngineTest | ,
|  | RunDoesExpectedInitialization |
| ) |  |

Definition at line 137 of file flutter_windows_engine_unittests.cc.

137 {
138 FlutterWindowsEngineBuilder builder{GetContext()};
139 builder.AddDartEntrypointArgument("arg1");
140 builder.AddDartEntrypointArgument("arg2");
141
142 auto windows_proc_table = std::make_shared<MockWindowsProcTable>();
143
144 HMONITOR mock_monitor = reinterpret_cast<HMONITOR>(1);
145
146 MONITORINFOEXW monitor_info = {};
147 monitor_info.cbSize = sizeof(MONITORINFOEXW);
148 monitor_info.rcMonitor = {0, 0, 1920, 1080};
149 monitor_info.rcWork = {0, 0, 1920, 1080};
150 monitor_info.dwFlags = MONITORINFOF_PRIMARY;
151 wcscpy_s(monitor_info.szDevice, L"\\\\.\\DISPLAY1");
152
153 EXPECT_CALL(*windows_proc_table, GetMonitorInfoW(mock_monitor, _))
154 .WillRepeatedly(DoAll(SetArgPointee<1>(monitor_info), Return(TRUE)));
155
156 EXPECT_CALL(*windows_proc_table, EnumDisplayMonitors(nullptr, nullptr, _, _))
157 .WillRepeatedly([&](HDC hdc, LPCRECT lprcClip, MONITORENUMPROC lpfnEnum,
158 LPARAM dwData) {
159 lpfnEnum(mock_monitor, nullptr, &monitor_info.rcMonitor, dwData);
160 return TRUE;
161 });
162
163 EXPECT_CALL(*windows_proc_table, GetDpiForMonitor(mock_monitor, _))
164 .WillRepeatedly(Return(96));
165
166 // Mock locale information
167 EXPECT_CALL(*windows_proc_table, GetThreadPreferredUILanguages(_, _, _, _))
168 .WillRepeatedly(
169 [](DWORD flags, PULONG count, PZZWSTR languages, PULONG length) {
170 // We need to mock the locale information twice because the first
171 // call is to get the size and the second call is to fill the
172 // buffer.
173 if (languages == nullptr) {
174 // First call is to get the size
175 *count = 1; // One language
176 *length = 10; // "fr-FR\0\0" (double null-terminated)
177 return TRUE;
178 } else {
179 // Second call is to fill the buffer
180 *count = 1;
181 // Fill with "fr-FR\0\0" (double null-terminated)
182 wchar_t* lang_buffer = languages;
183 wcscpy(lang_buffer, L"fr-FR");
184 // Move past the first null terminator to add the second
185 lang_buffer += wcslen(L"fr-FR") + 1;
186 *lang_buffer = L'\0';
187 return TRUE;
188 }
189 });
190
191 builder.SetWindowsProcTable(windows_proc_table);
192
193 std::unique_ptr<FlutterWindowsEngine> engine = builder.Build();
194 EngineModifier modifier(engine.get());
195
196 // The engine should be run with expected configuration values.
197 bool run_called = false;
198 modifier.embedder_api().Run = MOCK_ENGINE_PROC(
199 Run, ([&run_called, engine_instance = engine.get()](
200 size_t version, const FlutterRendererConfig* config,
201 const FlutterProjectArgs* args, void* user_data,
202 FLUTTER_API_SYMBOL(FlutterEngine) * engine_out) {
203 run_called = true;
204 *engine_out = reinterpret_cast<FLUTTER_API_SYMBOL(FlutterEngine)>(1);
205
206 EXPECT_EQ(version, FLUTTER_ENGINE_VERSION);
207 EXPECT_NE(config, nullptr);
208 // We have an EGL manager, so this should be using OpenGL.
209 EXPECT_EQ(config->type, kOpenGL);
210 EXPECT_EQ(user_data, engine_instance);
211 // Spot-check arguments.
212 EXPECT_NE(args->assets_path, nullptr);
213 EXPECT_NE(args->icu_data_path, nullptr);
214 EXPECT_EQ(args->dart_entrypoint_argc, 2U);
215 EXPECT_EQ(strcmp(args->dart_entrypoint_argv[0], "arg1"), 0);
216 EXPECT_EQ(strcmp(args->dart_entrypoint_argv[1], "arg2"), 0);
217 EXPECT_NE(args->platform_message_callback, nullptr);
218 EXPECT_NE(args->custom_task_runners, nullptr);
219 EXPECT_NE(args->custom_task_runners->thread_priority_setter, nullptr);
220 EXPECT_EQ(args->custom_dart_entrypoint, nullptr);
221 EXPECT_NE(args->vsync_callback, nullptr);
222 EXPECT_EQ(args->update_semantics_callback, nullptr);
223 EXPECT_NE(args->update_semantics_callback2, nullptr);
224 EXPECT_EQ(args->update_semantics_node_callback, nullptr);
225 EXPECT_EQ(args->update_semantics_custom_action_callback, nullptr);
226 EXPECT_NE(args->view_focus_change_request_callback, nullptr);
227
228 args->custom_task_runners->thread_priority_setter(
229 FlutterThreadPriority::kRaster);
230 EXPECT_EQ(GetThreadPriority(GetCurrentThread()),
231 THREAD_PRIORITY_ABOVE_NORMAL);
232 return kSuccess;
233 }));
234 // Accessibility updates must do nothing when the embedder engine is mocked
235 modifier.embedder_api().UpdateAccessibilityFeatures = MOCK_ENGINE_PROC(
236 UpdateAccessibilityFeatures,
237 [](FLUTTER_API_SYMBOL(FlutterEngine) engine,
238 FlutterAccessibilityFeature flags) { return kSuccess; });
239
240 // It should send locale info.
241 bool update_locales_called = false;
242 modifier.embedder_api().UpdateLocales = MOCK_ENGINE_PROC(
243 UpdateLocales,
244 ([&update_locales_called](auto engine, const FlutterLocale** locales,
245 size_t locales_count) {
246 update_locales_called = true;
247
248 EXPECT_GT(locales_count, 0);
249 EXPECT_NE(locales, nullptr);
250
251 return kSuccess;
252 }));
253
254 // And it should send initial settings info.
255 bool settings_message_sent = false;
256 modifier.embedder_api().SendPlatformMessage = MOCK_ENGINE_PROC(
257 SendPlatformMessage,
258 ([&settings_message_sent](auto engine, auto message) {
259 if (std::string(message->channel) == std::string("flutter/settings")) {
260 settings_message_sent = true;
261 }
262
263 return kSuccess;
264 }));
265
266 // And it should send display info.
267 bool notify_display_update_called = false;
268
269 modifier.embedder_api().NotifyDisplayUpdate = MOCK_ENGINE_PROC(
270 NotifyDisplayUpdate,
271 ([&notify_display_update_called](
272 FLUTTER_API_SYMBOL(FlutterEngine) raw_engine,
273 const FlutterEngineDisplaysUpdateType update_type,
274 const FlutterEngineDisplay* embedder_displays,
275 size_t display_count) {
276 EXPECT_EQ(update_type, kFlutterEngineDisplaysUpdateTypeStartup);
277 notify_display_update_called = true;
278 return kSuccess;
279 }));
280
281 // Set the EGL manager to !nullptr to test ANGLE rendering.
282 modifier.SetEGLManager(std::make_unique<egl::MockManager>());
283
284 engine->Run();
285
286 EXPECT_TRUE(run_called);
287 EXPECT_TRUE(update_locales_called);
288 EXPECT_TRUE(settings_message_sent);
289 EXPECT_TRUE(notify_display_update_called);
290
291 // Ensure that deallocation doesn't call the actual Shutdown with the bogus
292 // engine pointer that the overridden Run returned.
293 modifier.embedder_api().Shutdown = [](auto engine) { return kSuccess; };
294 modifier.ReleaseEGLManager();
295 }

References flutter::GetDpiForMonitor(), message, and user_data.

## ◆ TEST_F() [52/204]

flutter::testing::TEST_F | ( | FlutterWindowsEngineTest | ,
|  | RunHeadless |
| ) |  |

Definition at line 55 of file flutter_windows_engine_unittests.cc.

55 {
56 FlutterWindowsEngineBuilder builder{GetContext()};
57 std::unique_ptr<FlutterWindowsEngine> engine = builder.Build();
58
59 EngineModifier modifier(engine.get());
60 modifier.embedder_api().RunsAOTCompiledDartCode = []() { return false; };
61
62 ASSERT_TRUE(engine->Run());
63 ASSERT_EQ(engine->view(kImplicitViewId), nullptr);
64 ASSERT_EQ(engine->view(123), nullptr);
65 }

References flutter::kImplicitViewId.

## ◆ TEST_F() [53/204]

flutter::testing::TEST_F | ( | FlutterWindowsEngineTest | ,
|  | RunWithoutANGLEOnImpellerFailsToStart |
| ) |  |

Definition at line 377 of file flutter_windows_engine_unittests.cc.

377 {
378 FlutterWindowsEngineBuilder builder{GetContext()};
379 builder.SetSwitches({"--enable-impeller=true"});
380 std::unique_ptr<FlutterWindowsEngine> engine = builder.Build();
381 EngineModifier modifier(engine.get());
382
383 modifier.embedder_api().NotifyDisplayUpdate =
384 MOCK_ENGINE_PROC(NotifyDisplayUpdate,
385 ([engine_instance = engine.get()](
386 FLUTTER_API_SYMBOL(FlutterEngine) raw_engine,
387 const FlutterEngineDisplaysUpdateType update_type,
388 const FlutterEngineDisplay* embedder_displays,
389 size_t display_count) { return kSuccess; }));
390
391 // Accessibility updates must do nothing when the embedder engine is mocked
392 modifier.embedder_api().UpdateAccessibilityFeatures = MOCK_ENGINE_PROC(
393 UpdateAccessibilityFeatures,
394 [](FLUTTER_API_SYMBOL(FlutterEngine) engine,
395 FlutterAccessibilityFeature flags) { return kSuccess; });
396
397 // Stub out UpdateLocales and SendPlatformMessage as we don't have a fully
398 // initialized engine instance.
399 modifier.embedder_api().UpdateLocales = MOCK_ENGINE_PROC(
400 UpdateLocales, ([](auto engine, const FlutterLocale** locales,
401 size_t locales_count) { return kSuccess; }));
402 modifier.embedder_api().SendPlatformMessage =
403 MOCK_ENGINE_PROC(SendPlatformMessage,
404 ([](auto engine, auto message) { return kSuccess; }));
405
406 // Set the EGL manager to nullptr to test software fallback path.
407 modifier.SetEGLManager(nullptr);
408
409 EXPECT_FALSE(engine->Run());
410 }

References message.

## ◆ TEST_F() [54/204]

flutter::testing::TEST_F | ( | FlutterWindowsEngineTest | ,
|  | RunWithoutANGLEUsesSoftware |
| ) |  |

Definition at line 324 of file flutter_windows_engine_unittests.cc.

324 {
325 FlutterWindowsEngineBuilder builder{GetContext()};
326 std::unique_ptr<FlutterWindowsEngine> engine = builder.Build();
327 EngineModifier modifier(engine.get());
328
329 modifier.embedder_api().NotifyDisplayUpdate =
330 MOCK_ENGINE_PROC(NotifyDisplayUpdate,
331 ([engine_instance = engine.get()](
332 FLUTTER_API_SYMBOL(FlutterEngine) raw_engine,
333 const FlutterEngineDisplaysUpdateType update_type,
334 const FlutterEngineDisplay* embedder_displays,
335 size_t display_count) { return kSuccess; }));
336
337 // The engine should be run with expected configuration values.
338 bool run_called = false;
339 modifier.embedder_api().Run = MOCK_ENGINE_PROC(
340 Run, ([&run_called, engine_instance = engine.get()](
341 size_t version, const FlutterRendererConfig* config,
342 const FlutterProjectArgs* args, void* user_data,
343 FLUTTER_API_SYMBOL(FlutterEngine) * engine_out) {
344 run_called = true;
345 *engine_out = reinterpret_cast<FLUTTER_API_SYMBOL(FlutterEngine)>(1);
346 // We don't have an EGL Manager, so we should be using software.
347 EXPECT_EQ(config->type, kSoftware);
348 return kSuccess;
349 }));
350 // Accessibility updates must do nothing when the embedder engine is mocked
351 modifier.embedder_api().UpdateAccessibilityFeatures = MOCK_ENGINE_PROC(
352 UpdateAccessibilityFeatures,
353 [](FLUTTER_API_SYMBOL(FlutterEngine) engine,
354 FlutterAccessibilityFeature flags) { return kSuccess; });
355
356 // Stub out UpdateLocales and SendPlatformMessage as we don't have a fully
357 // initialized engine instance.
358 modifier.embedder_api().UpdateLocales = MOCK_ENGINE_PROC(
359 UpdateLocales, ([](auto engine, const FlutterLocale** locales,
360 size_t locales_count) { return kSuccess; }));
361 modifier.embedder_api().SendPlatformMessage =
362 MOCK_ENGINE_PROC(SendPlatformMessage,
363 ([](auto engine, auto message) { return kSuccess; }));
364
365 // Set the EGL manager to nullptr to test software fallback path.
366 modifier.SetEGLManager(nullptr);
367
368 engine->Run();
369
370 EXPECT_TRUE(run_called);
371
372 // Ensure that deallocation doesn't call the actual Shutdown with the bogus
373 // engine pointer that the overridden Run returned.
374 modifier.embedder_api().Shutdown = [](auto engine) { return kSuccess; };
375 }

References message, and user_data.

## ◆ TEST_F() [55/204]

flutter::testing::TEST_F | ( | FlutterWindowsEngineTest | ,
|  | ScheduleFrame |
| ) |  |

Definition at line 670 of file flutter_windows_engine_unittests.cc.

670 {
671 FlutterWindowsEngineBuilder builder{GetContext()};
672 std::unique_ptr<FlutterWindowsEngine> engine = builder.Build();
673 EngineModifier modifier(engine.get());
674
675 bool called = false;
676 modifier.embedder_api().ScheduleFrame =
677 MOCK_ENGINE_PROC(ScheduleFrame, ([&called](auto engine) {
678 called = true;
679 return kSuccess;
680 }));
681
682 engine->ScheduleFrame();
683 EXPECT_TRUE(called);
684 }

## ◆ TEST_F() [56/204]

flutter::testing::TEST_F | ( | FlutterWindowsEngineTest | ,
|  | SendPlatformMessageWithoutResponse |
| ) |  |

Definition at line 412 of file flutter_windows_engine_unittests.cc.

412 {
413 FlutterWindowsEngineBuilder builder{GetContext()};
414 std::unique_ptr<FlutterWindowsEngine> engine = builder.Build();
415 EngineModifier modifier(engine.get());
416
417 const char* channel = "test";
418 const std::vector<uint8_t> test_message = {1, 2, 3, 4};
419
420 // Without a response, SendPlatformMessage should be a simple pass-through.
421 bool called = false;
422 modifier.embedder_api().SendPlatformMessage = MOCK_ENGINE_PROC(
423 SendPlatformMessage, ([&called, test_message](auto engine, auto message) {
424 called = true;
425 EXPECT_STREQ(message->channel, "test");
426 EXPECT_EQ(message->message_size, test_message.size());
427 EXPECT_EQ(memcmp(message->message, test_message.data(),
428 message->message_size),
429 0);
430 EXPECT_EQ(message->response_handle, nullptr);
431 return kSuccess;
432 }));
433
434 engine->SendPlatformMessage(channel, test_message.data(), test_message.size(),
435 nullptr, nullptr);
436 EXPECT_TRUE(called);
437 }

References message.

## ◆ TEST_F() [57/204]

flutter::testing::TEST_F | ( | FlutterWindowsEngineTest | ,
|  | SendPlatformMessageWithResponse |
| ) |  |

Definition at line 535 of file flutter_windows_engine_unittests.cc.

535 {
536 FlutterWindowsEngineBuilder builder{GetContext()};
537 std::unique_ptr<FlutterWindowsEngine> engine = builder.Build();
538 EngineModifier modifier(engine.get());
539
540 const char* channel = "test";
541 const std::vector<uint8_t> test_message = {1, 2, 3, 4};
542 auto* dummy_response_handle =
543 reinterpret_cast<FlutterPlatformMessageResponseHandle*>(5);
544 const FlutterDesktopBinaryReply reply_handler = [](auto... args) {};
545 void* reply_user_data = reinterpret_cast<void*>(6);
546
547 // When a response is requested, a handle should be created, passed as part
548 // of the message, and then released.
549 bool create_response_handle_called = false;
550 modifier.embedder_api().PlatformMessageCreateResponseHandle =
551 MOCK_ENGINE_PROC(
552 PlatformMessageCreateResponseHandle,
553 ([&create_response_handle_called, &reply_handler, reply_user_data,
554 dummy_response_handle](auto engine, auto reply, auto user_data,
555 auto response_handle) {
556 create_response_handle_called = true;
557 EXPECT_EQ(reply, reply_handler);
558 EXPECT_EQ(user_data, reply_user_data);
559 EXPECT_NE(response_handle, nullptr);
560 *response_handle = dummy_response_handle;
561 return kSuccess;
562 }));
563 bool release_response_handle_called = false;
564 modifier.embedder_api().PlatformMessageReleaseResponseHandle =
565 MOCK_ENGINE_PROC(
566 PlatformMessageReleaseResponseHandle,
567 ([&release_response_handle_called, dummy_response_handle](
568 auto engine, auto response_handle) {
569 release_response_handle_called = true;
570 EXPECT_EQ(response_handle, dummy_response_handle);
571 return kSuccess;
572 }));
573 bool send_message_called = false;
574 modifier.embedder_api().SendPlatformMessage = MOCK_ENGINE_PROC(
575 SendPlatformMessage, ([&send_message_called, test_message,
576 dummy_response_handle](auto engine, auto message) {
577 send_message_called = true;
578 EXPECT_STREQ(message->channel, "test");
579 EXPECT_EQ(message->message_size, test_message.size());
580 EXPECT_EQ(memcmp(message->message, test_message.data(),
581 message->message_size),
582 0);
583 EXPECT_EQ(message->response_handle, dummy_response_handle);
584 return kSuccess;
585 }));
586
587 engine->SendPlatformMessage(channel, test_message.data(), test_message.size(),
588 reply_handler, reply_user_data);
589 EXPECT_TRUE(create_response_handle_called);
590 EXPECT_TRUE(release_response_handle_called);
591 EXPECT_TRUE(send_message_called);
592 }
FlutterDesktopBinaryReply
void(* FlutterDesktopBinaryReply)(const uint8_t *data, size_t data_size, void *user_data)
Definition: flutter_messenger.h:26

References message, and user_data.

## ◆ TEST_F() [58/204]

flutter::testing::TEST_F | ( | FlutterWindowsEngineTest | ,
|  | SetNextFrameCallback |
| ) |  |

Definition at line 686 of file flutter_windows_engine_unittests.cc.

686 {
687 FlutterWindowsEngineBuilder builder{GetContext()};
688 std::unique_ptr<FlutterWindowsEngine> engine = builder.Build();
689 EngineModifier modifier(engine.get());
690
691 bool called = false;
692 modifier.embedder_api().SetNextFrameCallback = MOCK_ENGINE_PROC(
693 SetNextFrameCallback, ([&called](auto engine, auto callback, auto data) {
694 called = true;
695 return kSuccess;
696 }));
697
698 engine->SetNextFrameCallback([]() {});
699 EXPECT_TRUE(called);
700 }

References callback.

## ◆ TEST_F() [59/204]

flutter::testing::TEST_F | ( | FlutterWindowsEngineTest | ,
|  | SetsThreadPriority |
| ) |  |

Definition at line 618 of file flutter_windows_engine_unittests.cc.

618 {
619 WindowsPlatformThreadPrioritySetter(FlutterThreadPriority::kBackground);
620 EXPECT_EQ(GetThreadPriority(GetCurrentThread()),
621 THREAD_PRIORITY_BELOW_NORMAL);
622
623 WindowsPlatformThreadPrioritySetter(FlutterThreadPriority::kDisplay);
624 EXPECT_EQ(GetThreadPriority(GetCurrentThread()),
625 THREAD_PRIORITY_ABOVE_NORMAL);
626
627 WindowsPlatformThreadPrioritySetter(FlutterThreadPriority::kRaster);
628 EXPECT_EQ(GetThreadPriority(GetCurrentThread()),
629 THREAD_PRIORITY_ABOVE_NORMAL);
630
631 // FlutterThreadPriority::kNormal does not change thread priority, reset to 0
632 // here.
633 SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_NORMAL);
634
635 WindowsPlatformThreadPrioritySetter(FlutterThreadPriority::kNormal);
636 EXPECT_EQ(GetThreadPriority(GetCurrentThread()), THREAD_PRIORITY_NORMAL);
637 }
flutter::WindowsPlatformThreadPrioritySetter
static void WindowsPlatformThreadPrioritySetter(FlutterThreadPriority priority)
Definition: flutter_windows_engine.h:62

References flutter::WindowsPlatformThreadPrioritySetter().

## ◆ TEST_F() [60/204]

flutter::testing::TEST_F | ( | FlutterWindowsEngineTest | ,
|  | TaskRunnerDelayedTask |
| ) |  |

Definition at line 67 of file flutter_windows_engine_unittests.cc.

67 {
68 bool finished = false;
69 auto runner = std::make_unique<TaskRunner>(
70 [] {
71 return static_cast<uint64_t>(
72 fml::TimePoint::Now().ToEpochDelta().ToNanoseconds());
73 },
74 [&](const FlutterTask*) { finished = true; });
75 runner->PostFlutterTask(
76 FlutterTask{},
77 static_cast<uint64_t>((fml::TimePoint::Now().ToEpochDelta() +
78 fml::TimeDelta::FromMilliseconds(50))
79 .ToNanoseconds()));
80 auto start = fml::TimePoint::Now();
81 while (!finished) {
82 PumpMessage();
83 }
84 auto duration = fml::TimePoint::Now() - start;
85 EXPECT_GE(duration, fml::TimeDelta::FromMilliseconds(50));
86 }

## ◆ TEST_F() [61/204]

flutter::testing::TEST_F | ( | FlutterWindowsEngineTest | ,
|  | TaskRunnerDoesNotDeadlock |
| ) |  |

Definition at line 89 of file flutter_windows_engine_unittests.cc.

89 {
90 auto runner = std::make_unique<TaskRunner>(
91 [] {
92 return static_cast<uint64_t>(
93 fml::TimePoint::Now().ToEpochDelta().ToNanoseconds());
94 },
95 [&](const FlutterTask*) {});
96
97 struct RunnerHolder {
98 void PostTaskLoop() {
99 runner->PostTask([this] { PostTaskLoop(); });
100 }
101 std::unique_ptr<TaskRunner> runner;
102 };
103
104 RunnerHolder container{.runner = std::move(runner)};
105 // Spam flutter tasks.
106 container.PostTaskLoop();
107
108 const LPCWSTR class_name = L"FlutterTestWindowClass";
109 WNDCLASS wc = {0};
110 wc.lpfnWndProc = DefWindowProc;
111 wc.lpszClassName = class_name;
112 RegisterClass(&wc);
113
114 HWND window;
115 container.runner->PostTask([&] {
116 window = CreateWindowEx(0, class_name, L"Empty Window", WS_OVERLAPPEDWINDOW,
117 CW_USEDEFAULT, CW_USEDEFAULT, 800, 600, nullptr,
118 nullptr, nullptr, nullptr);
119 ShowWindow(window, SW_SHOW);
120 });
121
122 while (true) {
123 ::MSG msg;
124 if (::GetMessage(&msg, nullptr, 0, 0)) {
125 if (msg.message == WM_PAINT) {
126 break;
127 }
128 ::TranslateMessage(&msg);
129 ::DispatchMessage(&msg);
130 }
131 }
132
133 DestroyWindow(window);
134 UnregisterClassW(class_name, nullptr);
135 }

## ◆ TEST_F() [62/204]

flutter::testing::TEST_F | ( | FlutterWindowsEngineTest | ,
|  | TestExit |
| ) |  |

Definition at line 908 of file flutter_windows_engine_unittests.cc.

908 {
909 FlutterWindowsEngineBuilder builder{GetContext()};
910 builder.SetDartEntrypoint("exitTestExit");
911 bool finished = false;
912
913 auto engine = builder.Build();
914 auto window_binding_handler =
915 std::make_unique<::testing::NiceMock<MockWindowBindingHandler>>();
916 MockFlutterWindowsView view(engine.get(), std::move(window_binding_handler));
917
918 EngineModifier modifier(engine.get());
919 modifier.SetImplicitView(&view);
920 modifier.embedder_api().RunsAOTCompiledDartCode = []() { return false; };
921 auto handler = std::make_unique<MockWindowsLifecycleManager>(engine.get());
922 EXPECT_CALL(*handler, Quit)
923 .WillOnce([&finished](std::optional<HWND> hwnd,
924 std::optional<WPARAM> wparam,
925 std::optional<LPARAM> lparam,
926 UINT exit_code) { finished = exit_code == 0; });
927 EXPECT_CALL(*handler, IsLastWindowOfProcess).WillRepeatedly(Return(true));
928 modifier.SetLifecycleManager(std::move(handler));
929
930 engine->lifecycle_manager()->BeginProcessingExit();
931
932 engine->Run();
933
934 engine->window_proc_delegate_manager()->OnTopLevelWindowProc(0, WM_CLOSE, 0,
935 0);
936
937 // The test will only succeed when this while loop exits. Otherwise it will
938 // timeout.
939 while (!finished) {
940 engine->task_runner()->ProcessTasks();
941 }
942 }

## ◆ TEST_F() [63/204]

flutter::testing::TEST_F | ( | FlutterWindowsEngineTest | ,
|  | TestExitCancel |
| ) |  |

Definition at line 944 of file flutter_windows_engine_unittests.cc.

944 {
945 FlutterWindowsEngineBuilder builder{GetContext()};
946 builder.SetDartEntrypoint("exitTestCancel");
947 bool did_call = false;
948
949 auto engine = builder.Build();
950 auto window_binding_handler =
951 std::make_unique<::testing::NiceMock<MockWindowBindingHandler>>();
952 MockFlutterWindowsView view(engine.get(), std::move(window_binding_handler));
953
954 EngineModifier modifier(engine.get());
955 modifier.SetImplicitView(&view);
956 modifier.embedder_api().RunsAOTCompiledDartCode = []() { return false; };
957 auto handler = std::make_unique<MockWindowsLifecycleManager>(engine.get());
958 EXPECT_CALL(*handler, IsLastWindowOfProcess).WillRepeatedly(Return(true));
959 EXPECT_CALL(*handler, Quit).Times(0);
960 modifier.SetLifecycleManager(std::move(handler));
961 engine->lifecycle_manager()->BeginProcessingExit();
962
963 auto binary_messenger =
964 std::make_unique<BinaryMessengerImpl>(engine->messenger());
965 binary_messenger->SetMessageHandler(
966 "flutter/platform", [&did_call](const uint8_t* message,
967 size_t message_size, BinaryReply reply) {
968 std::string contents(message, message + message_size);
969 EXPECT_NE(contents.find("\"method\":\"System.exitApplication\""),
970 std::string::npos);
971 EXPECT_NE(contents.find("\"type\":\"required\""), std::string::npos);
972 EXPECT_NE(contents.find("\"exitCode\":0"), std::string::npos);
973 did_call = true;
974 char response[] = "";
975 reply(reinterpret_cast<uint8_t*>(response), 0);
976 });
977
978 engine->Run();
979
980 engine->window_proc_delegate_manager()->OnTopLevelWindowProc(0, WM_CLOSE, 0,
981 0);
982
983 while (!did_call) {
984 engine->task_runner()->ProcessTasks();
985 }
986 }

References message.

## ◆ TEST_F() [64/204]

flutter::testing::TEST_F | ( | FlutterWindowsEngineTest | ,
|  | TestExitCloseMultiWindow |
| ) |  |

Definition at line 1050 of file flutter_windows_engine_unittests.cc.

1050 {
1051 FlutterWindowsEngineBuilder builder{GetContext()};
1052 builder.SetDartEntrypoint("exitTestExit");
1053 bool finished = false;
1054
1055 auto engine = builder.Build();
1056 auto window_binding_handler =
1057 std::make_unique<::testing::NiceMock<MockWindowBindingHandler>>();
1058 MockFlutterWindowsView view(engine.get(), std::move(window_binding_handler));
1059
1060 EngineModifier modifier(engine.get());
1061 modifier.SetImplicitView(&view);
1062 modifier.embedder_api().RunsAOTCompiledDartCode = []() { return false; };
1063 auto handler = std::make_unique<MockWindowsLifecycleManager>(engine.get());
1064 EXPECT_CALL(*handler, IsLastWindowOfProcess).WillOnce([&finished]() {
1065 finished = true;
1066 return false;
1067 });
1068 // Quit should not be called when there is more than one window.
1069 EXPECT_CALL(*handler, Quit).Times(0);
1070 modifier.SetLifecycleManager(std::move(handler));
1071 engine->lifecycle_manager()->BeginProcessingExit();
1072
1073 engine->Run();
1074
1075 engine->window_proc_delegate_manager()->OnTopLevelWindowProc(0, WM_CLOSE, 0,
1076 0);
1077
1078 while (!finished) {
1079 engine->task_runner()->ProcessTasks();
1080 }
1081 }

## ◆ TEST_F() [65/204]

flutter::testing::TEST_F | ( | FlutterWindowsEngineTest | ,
|  | TestExitSecondCloseMessage |
| ) |  |

Definition at line 991 of file flutter_windows_engine_unittests.cc.

991 {
992 FlutterWindowsEngineBuilder builder{GetContext()};
993 builder.SetDartEntrypoint("exitTestExit");
994 bool second_close = false;
995
996 auto engine = builder.Build();
997 auto window_binding_handler =
998 std::make_unique<::testing::NiceMock<MockWindowBindingHandler>>();
999 MockFlutterWindowsView view(engine.get(), std::move(window_binding_handler));
1000
1001 EngineModifier modifier(engine.get());
1002 modifier.SetImplicitView(&view);
1003 modifier.embedder_api().RunsAOTCompiledDartCode = []() { return false; };
1004 auto handler = std::make_unique<MockWindowsLifecycleManager>(engine.get());
1005 EXPECT_CALL(*handler, IsLastWindowOfProcess).WillOnce(Return(true));
1006 EXPECT_CALL(*handler, Quit)
1007 .WillOnce([handler_ptr = handler.get()](
1008 std::optional<HWND> hwnd, std::optional<WPARAM> wparam,
1009 std::optional<LPARAM> lparam, UINT exit_code) {
1010 handler_ptr->WindowsLifecycleManager::Quit(hwnd, wparam, lparam,
1011 exit_code);
1012 });
1013 EXPECT_CALL(*handler, DispatchMessage)
1014 .WillRepeatedly(
1015 [&engine](HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) {
1016 engine->window_proc_delegate_manager()->OnTopLevelWindowProc(
1017 hwnd, msg, wparam, lparam);
1018 });
1019 modifier.SetLifecycleManager(std::move(handler));
1020 engine->lifecycle_manager()->BeginProcessingExit();
1021
1022 engine->Run();
1023
1024 // This delegate will be registered after the lifecycle manager, so it will be
1025 // called only when a message is not consumed by the lifecycle manager. This
1026 // should be called on the second, synthesized WM_CLOSE message that the
1027 // lifecycle manager posts.
1028 engine->window_proc_delegate_manager()->RegisterTopLevelWindowProcDelegate(
1029 [](HWND hwnd, UINT message, WPARAM wpar, LPARAM lpar, void* user_data,
1030 LRESULT* result) {
1031 switch (message) {
1032 case WM_CLOSE: {
1033 bool* called = reinterpret_cast<bool*>(user_data);
1034 *called = true;
1035 return true;
1036 }
1037 }
1038 return false;
1039 },
1040 reinterpret_cast<void*>(&second_close));
1041
1042 engine->window_proc_delegate_manager()->OnTopLevelWindowProc(0, WM_CLOSE, 0,
1043 0);
1044
1045 while (!second_close) {
1046 engine->task_runner()->ProcessTasks();
1047 }
1048 }

References message, and user_data.

## ◆ TEST_F() [66/204]

flutter::testing::TEST_F | ( | FlutterWindowsEngineTest | ,
|  | UpdateHighContrastFeature |
| ) |  |

Definition at line 710 of file flutter_windows_engine_unittests.cc.

710 {
711 auto windows_proc_table = std::make_shared<MockWindowsProcTable>();
712 EXPECT_CALL(*windows_proc_table, GetHighContrastEnabled)
713 .WillOnce(Return(true))
714 .WillOnce(Return(false));
715
716 FlutterWindowsEngineBuilder builder{GetContext()};
717 builder.SetWindowsProcTable(windows_proc_table);
718 std::unique_ptr<FlutterWindowsEngine> engine = builder.Build();
719 EngineModifier modifier(engine.get());
720
721 std::optional<FlutterAccessibilityFeature> engine_flags;
722 modifier.embedder_api().UpdateAccessibilityFeatures = MOCK_ENGINE_PROC(
723 UpdateAccessibilityFeatures, ([&engine_flags](auto engine, auto flags) {
724 engine_flags = flags;
725 return kSuccess;
726 }));
727 modifier.embedder_api().SendPlatformMessage = MOCK_ENGINE_PROC(
728 SendPlatformMessage,
729 [](auto engine, const auto message) { return kSuccess; });
730
731 // 1: High contrast is enabled.
732 engine->UpdateHighContrastMode();
733
734 EXPECT_TRUE(engine->high_contrast_enabled());
735 EXPECT_TRUE(engine_flags.has_value());
736 EXPECT_TRUE(
737 engine_flags.value() &
738 FlutterAccessibilityFeature::kFlutterAccessibilityFeatureHighContrast);
739
740 // 2: High contrast is disabled.
741 engine_flags.reset();
742 engine->UpdateHighContrastMode();
743
744 EXPECT_FALSE(engine->high_contrast_enabled());
745 EXPECT_TRUE(engine_flags.has_value());
746 EXPECT_FALSE(
747 engine_flags.value() &
748 FlutterAccessibilityFeature::kFlutterAccessibilityFeatureHighContrast);
749 }

References message.

## ◆ TEST_F() [67/204]

flutter::testing::TEST_F | ( | FlutterWindowsEngineTest | ,
|  | UpdateSemanticsMultiView |
| ) |  |

Definition at line 1504 of file flutter_windows_engine_unittests.cc.

1504 {
1505 auto& context = GetContext();
1506 WindowsConfigBuilder builder{context};
1507 builder.SetDartEntrypoint("sendSemanticsTreeInfo");
1508
1509 // Setup: a signal for when we have send out all of our semantics updates
1510 bool done = false;
1511 auto native_entry =
1512 CREATE_NATIVE_ENTRY([&](Dart_NativeArguments args) { done = true; });
1513 context.AddNativeFunction("Signal", native_entry);
1514
1515 // Setup: Create the engine and two views + enable semantics
1516 EnginePtr engine{builder.RunHeadless()};
1517 ASSERT_NE(engine, nullptr);
1518
1519 auto window_binding_handler1 =
1520 std::make_unique<NiceMock<MockWindowBindingHandler>>();
1521 auto window_binding_handler2 =
1522 std::make_unique<NiceMock<MockWindowBindingHandler>>();
1523
1524 // The following mocks are required by
1525 // FlutterWindowsView::CreateWindowMetricsEvent so that we create a valid
1526 // view.
1527 EXPECT_CALL(*window_binding_handler1, GetPhysicalWindowBounds)
1528 .WillRepeatedly(testing::Return(PhysicalWindowBounds{100, 100}));
1529 EXPECT_CALL(*window_binding_handler1, GetDpiScale)
1530 .WillRepeatedly(testing::Return(96.0));
1531 EXPECT_CALL(*window_binding_handler2, GetPhysicalWindowBounds)
1532 .WillRepeatedly(testing::Return(PhysicalWindowBounds{200, 200}));
1533 EXPECT_CALL(*window_binding_handler2, GetDpiScale)
1534 .WillRepeatedly(testing::Return(96.0));
1535
1536 auto windows_engine = reinterpret_cast<FlutterWindowsEngine*>(engine.get());
1537 EngineModifier modifier{windows_engine};
1538 modifier.embedder_api().RunsAOTCompiledDartCode = []() { return false; };
1539
1540 // We want to avoid adding an implicit view as the first view
1541 modifier.SetNextViewId(kImplicitViewId + 1);
1542
1543 auto view1 = windows_engine->CreateView(std::move(window_binding_handler1),
1544 /*is_sized_to_content=*/false,
1545 BoxConstraints());
1546 auto view2 = windows_engine->CreateView(std::move(window_binding_handler2),
1547 /*is_sized_to_content=*/false,
1548 BoxConstraints());
1549
1550 // Act: UpdateSemanticsEnabled will trigger the semantics updates
1551 // to get sent.
1552 windows_engine->UpdateSemanticsEnabled(true);
1553
1554 while (!done) {
1555 windows_engine->task_runner()->ProcessTasks();
1556 }
1557
1558 auto accessibility_bridge1 = view1->accessibility_bridge().lock();
1559 auto accessibility_bridge2 = view2->accessibility_bridge().lock();
1560
1561 // Expect: that the semantics trees are updated with their
1562 // respective nodes.
1563 while (
1564 !accessibility_bridge1->GetPlatformNodeFromTree(view1->view_id() + 1)) {
1565 windows_engine->task_runner()->ProcessTasks();
1566 }
1567
1568 while (
1569 !accessibility_bridge2->GetPlatformNodeFromTree(view2->view_id() + 1)) {
1570 windows_engine->task_runner()->ProcessTasks();
1571 }
1572
1573 // Rely on timeout mechanism in CI.
1574 auto tree1 = accessibility_bridge1->GetTree();
1575 auto tree2 = accessibility_bridge2->GetTree();
1576 EXPECT_NE(tree1->GetFromId(view1->view_id() + 1), nullptr);
1577 EXPECT_NE(tree2->GetFromId(view2->view_id() + 1), nullptr);
1578 }

References flutter::FlutterWindowsEngine::CreateView(), and flutter::kImplicitViewId.

## ◆ TEST_F() [68/204]

flutter::testing::TEST_F | ( | FlutterWindowTest | ,
|  | AccessibilityNodeWithoutView |
| ) |  |

Definition at line 574 of file flutter_window_unittests.cc.

574 {
575 MockFlutterWindow win32window;
576
577 EXPECT_EQ(win32window.GetNativeViewAccessible(), nullptr);
578 }

## ◆ TEST_F() [69/204]

flutter::testing::TEST_F | ( | FlutterWindowTest | ,
|  | AlertNode |
| ) |  |

Definition at line 582 of file flutter_window_unittests.cc.

582 {
583 std::unique_ptr<FlutterWindowsEngine> engine =
584 FlutterWindowsEngineBuilder{GetContext()}.Build();
585 auto win32window = std::make_unique<MockFlutterWindow>();
586 EXPECT_CALL(*win32window.get(), GetAxFragmentRootDelegate())
587 .WillRepeatedly(Return(nullptr));
588 EXPECT_CALL(*win32window.get(), OnWindowStateEvent).Times(AnyNumber());
589 EXPECT_CALL(*win32window.get(), GetWindowHandle).Times(AnyNumber());
590 MockFlutterWindowsView view{engine.get(), std::move(win32window)};
591 std::wstring message = L"Test alert";
592 EXPECT_CALL(view, NotifyWinEventWrapper(_, ax::mojom::Event::kAlert))
593 .Times(1);
594 view.AnnounceAlert(message);
595
596 IAccessible* alert = view.AlertNode();
597 VARIANT self{.vt = VT_I4, .lVal = CHILDID_SELF};
598 BSTR strptr;
599 alert->get_accName(self, &strptr);
600 EXPECT_EQ(message, strptr);
601
602 alert->get_accDescription(self, &strptr);
603 EXPECT_EQ(message, strptr);
604
605 alert->get_accValue(self, &strptr);
606 EXPECT_EQ(message, strptr);
607
608 VARIANT role;
609 alert->get_accRole(self, &role);
610 EXPECT_EQ(role.vt, VT_I4);
611 EXPECT_EQ(role.lVal, ROLE_SYSTEM_ALERT);
612 }

References flutter::IAccessible, and message.

## ◆ TEST_F() [70/204]

flutter::testing::TEST_F | ( | FlutterWindowTest | ,
|  | CachedLifecycleMessage |
| ) |  |

Definition at line 652 of file flutter_window_unittests.cc.

652 {
653 MockFlutterWindow win32window;
654 EXPECT_CALL(win32window, GetWindowHandle)
655 .WillRepeatedly(Return(reinterpret_cast<HWND>(1)));
656 EXPECT_CALL(win32window, OnWindowStateEvent)
657 .WillRepeatedly([&](WindowStateEvent event) {
658 win32window.FlutterWindow::OnWindowStateEvent(event);
659 });
660 EXPECT_CALL(win32window, OnResize).Times(1);
661
662 // Restore
663 win32window.InjectWindowMessage(WM_SIZE, 0, MAKEWORD(1, 1));
664
665 // Focus
666 win32window.InjectWindowMessage(WM_SETFOCUS, 0, 0);
667
668 MockWindowBindingHandlerDelegate delegate;
669 bool focused = false;
670 bool restored = false;
671 EXPECT_CALL(delegate, OnWindowStateEvent)
672 .WillRepeatedly([&](HWND hwnd, WindowStateEvent event) {
673 if (event == WindowStateEvent::kFocus) {
674 focused = true;
675 } else if (event == WindowStateEvent::kShow) {
676 restored = true;
677 }
678 });
679
680 EXPECT_CALL(delegate, OnFocus(Eq(FlutterViewFocusState::kFocused),
681 Eq(FlutterViewFocusDirection::kUndefined)))
682 .Times(1);
683 win32window.SetView(&delegate);
684 EXPECT_TRUE(focused);
685 EXPECT_TRUE(restored);
686 }
flutter::WindowStateEvent
WindowStateEvent
An event representing a change in window state that may update the.
Definition: windows_lifecycle_manager.h:24

References flutter::kFocus, and flutter::kShow.

## ◆ TEST_F() [71/204]

flutter::testing::TEST_F | ( | FlutterWindowTest | ,
|  | CreateDestroy |
| ) |  |

Definition at line 110 of file flutter_window_unittests.cc.

110 {
111 std::unique_ptr<FlutterWindowsEngine> engine =
112 FlutterWindowsEngineBuilder{GetContext()}.Build();
113 FlutterWindow window(800, 600, engine->display_manager());
114 ASSERT_TRUE(TRUE);
115 }

## ◆ TEST_F() [72/204]

flutter::testing::TEST_F | ( | FlutterWindowTest | ,
|  | LifecycleFocusMessages |
| ) |  |

Definition at line 614 of file flutter_window_unittests.cc.

614 {
615 MockFlutterWindow win32window;
616 EXPECT_CALL(win32window, GetWindowHandle)
617 .WillRepeatedly(Return(reinterpret_cast<HWND>(1)));
618 MockWindowBindingHandlerDelegate delegate;
619
620 WindowStateEvent last_event;
621 EXPECT_CALL(delegate, OnWindowStateEvent)
622 .WillRepeatedly([&last_event](HWND hwnd, WindowStateEvent event) {
623 last_event = event;
624 });
625 EXPECT_CALL(win32window, OnWindowStateEvent)
626 .WillRepeatedly([&](WindowStateEvent event) {
627 win32window.FlutterWindow::OnWindowStateEvent(event);
628 });
629 EXPECT_CALL(win32window, OnResize).Times(AnyNumber());
630
631 win32window.SetView(&delegate);
632
633 win32window.InjectWindowMessage(WM_SIZE, 0, 0);
634 EXPECT_EQ(last_event, WindowStateEvent::kHide);
635
636 win32window.InjectWindowMessage(WM_SIZE, 0, MAKEWORD(1, 1));
637 EXPECT_EQ(last_event, WindowStateEvent::kShow);
638
639 EXPECT_CALL(delegate, OnFocus(Eq(FlutterViewFocusState::kFocused),
640 Eq(FlutterViewFocusDirection::kUndefined)))
641 .Times(1);
642 win32window.InjectWindowMessage(WM_SETFOCUS, 0, 0);
643 EXPECT_EQ(last_event, WindowStateEvent::kFocus);
644
645 EXPECT_CALL(delegate, OnFocus(Eq(FlutterViewFocusState::kUnfocused),
646 Eq(FlutterViewFocusDirection::kUndefined)))
647 .Times(1);
648 win32window.InjectWindowMessage(WM_KILLFOCUS, 0, 0);
649 EXPECT_EQ(last_event, WindowStateEvent::kUnfocus);
650 }

References flutter::kFocus, flutter::kHide, flutter::kShow, and flutter::kUnfocus.

## ◆ TEST_F() [73/204]

flutter::testing::TEST_F | ( | FlutterWindowTest | ,
|  | OnBitmapSurfaceUpdated |
| ) |  |

Definition at line 117 of file flutter_window_unittests.cc.

117 {
118 std::unique_ptr<FlutterWindowsEngine> engine =
119 FlutterWindowsEngineBuilder{GetContext()}.Build();
120 FlutterWindow win32window(100, 100, engine->display_manager());
121 int old_handle_count = GetGuiResources(GetCurrentProcess(), GR_GDIOBJECTS);
122
123 constexpr size_t row_bytes = 100 * 4;
124 constexpr size_t height = 100;
125 std::array<char, row_bytes * height> allocation;
126 win32window.OnBitmapSurfaceUpdated(allocation.data(), row_bytes, height);
127
128 int new_handle_count = GetGuiResources(GetCurrentProcess(), GR_GDIOBJECTS);
129 // Check GDI resources leak
130 EXPECT_EQ(old_handle_count, new_handle_count);
131 }

References flutter::FlutterWindow::OnBitmapSurfaceUpdated().

## ◆ TEST_F() [74/204]

flutter::testing::TEST_F | ( | FlutterWindowTest | ,
|  | OnCursorRectUpdatedHighDPI |
| ) |  |

Definition at line 149 of file flutter_window_unittests.cc.

149 {
150 MockFlutterWindow win32window;
151 EXPECT_CALL(win32window, GetDpiScale()).WillOnce(Return(1.5));
152
153 Rect expected_cursor_rect(Point(15, 30), Size(45, 60));
154 EXPECT_CALL(win32window, UpdateCursorRect(expected_cursor_rect)).Times(1);
155
156 Rect cursor_rect(Point(10, 20), Size(30, 40));
157 win32window.OnCursorRectUpdated(cursor_rect);
158 }

## ◆ TEST_F() [75/204]

flutter::testing::TEST_F | ( | FlutterWindowTest | ,
|  | OnCursorRectUpdatedRegularDPI |
| ) |  |

Definition at line 136 of file flutter_window_unittests.cc.

136 {
137 MockFlutterWindow win32window;
138 EXPECT_CALL(win32window, GetDpiScale()).WillOnce(Return(1.0));
139
140 Rect cursor_rect(Point(10, 20), Size(30, 40));
141 EXPECT_CALL(win32window, UpdateCursorRect(cursor_rect)).Times(1);
142
143 win32window.OnCursorRectUpdated(cursor_rect);
144 }

## ◆ TEST_F() [76/204]

flutter::testing::TEST_F | ( | FlutterWindowTest | ,
|  | OnMousePointerDown |
| ) |  |

Definition at line 469 of file flutter_window_unittests.cc.

469 {
470 auto mock_proc_table = std::make_shared<MockWindowsProcTable>();
471
472 EXPECT_CALL(*mock_proc_table, GetPointerInfo(_, _))
473 .WillRepeatedly([](UINT32 pointer_id, POINTER_INFO* pointer_info) {
474 if (pointer_info != nullptr) {
475 pointer_info->pointerType = PT_MOUSE;
476 pointer_info->pointerId = pointer_id;
477 pointer_info->pointerFlags = POINTER_FLAG_INCONTACT;
478 }
479 return TRUE;
480 });
481
482 MockFlutterWindow win32window(100, 100, mock_proc_table);
483 MockWindowBindingHandlerDelegate delegate;
484 win32window.SetView(&delegate);
485
486 EXPECT_CALL(delegate, OnPointerDown(45, 50, kFlutterPointerDeviceKindMouse,
487 kDefaultPointerDeviceId,
488 kFlutterPointerButtonMousePrimary, 0, 0))
489 .Times(1);
490
491 UINT32 pointerId = 1;
492 WPARAM wparam = static_cast<WPARAM>(pointerId);
493 LPARAM lparam = MAKELPARAM(45, 50);
494
495 win32window.InjectWindowMessage(WM_POINTERDOWN, wparam, lparam);
496 }

## ◆ TEST_F() [77/204]

flutter::testing::TEST_F | ( | FlutterWindowTest | ,
|  | OnPointerStarSendsDeviceType |
| ) |  |

Definition at line 160 of file flutter_window_unittests.cc.

160 {
161 std::unique_ptr<FlutterWindowsEngine> engine =
162 FlutterWindowsEngineBuilder{GetContext()}.Build();
163 FlutterWindow win32window(100, 100, engine->display_manager());
164 MockWindowBindingHandlerDelegate delegate;
165 EXPECT_CALL(delegate, OnWindowStateEvent).Times(AnyNumber());
166 win32window.SetView(&delegate);
167
168 // Move
169 EXPECT_CALL(delegate,
170 OnPointerMove(10.0, 10.0, kFlutterPointerDeviceKindMouse,
171 kDefaultPointerDeviceId, 0, 0, 0))
172 .Times(1);
173 EXPECT_CALL(delegate,
174 OnPointerMove(10.0, 10.0, kFlutterPointerDeviceKindTouch,
175 kDefaultPointerDeviceId, 0, 0, 0))
176 .Times(1);
177 EXPECT_CALL(delegate,
178 OnPointerMove(10.0, 10.0, kFlutterPointerDeviceKindStylus,
179 kDefaultPointerDeviceId, 0, 0, 0))
180 .Times(1);
181
182 // Down
183 EXPECT_CALL(delegate,
184 OnPointerDown(10.0, 10.0, kFlutterPointerDeviceKindMouse,
185 kDefaultPointerDeviceId,
186 kFlutterPointerButtonMousePrimary, 0, 0))
187 .Times(1);
188 EXPECT_CALL(delegate,
189 OnPointerDown(10.0, 10.0, kFlutterPointerDeviceKindTouch,
190 kDefaultPointerDeviceId,
191 kFlutterPointerButtonMousePrimary, 0, 0))
192 .Times(1);
193 EXPECT_CALL(delegate,
194 OnPointerDown(10.0, 10.0, kFlutterPointerDeviceKindStylus,
195 kDefaultPointerDeviceId,
196 kFlutterPointerButtonMousePrimary, 0, 0))
197 .Times(1);
198
199 // Up
200 EXPECT_CALL(delegate, OnPointerUp(10.0, 10.0, kFlutterPointerDeviceKindMouse,
201 kDefaultPointerDeviceId,
202 kFlutterPointerButtonMousePrimary))
203 .Times(1);
204 EXPECT_CALL(delegate, OnPointerUp(10.0, 10.0, kFlutterPointerDeviceKindTouch,
205 kDefaultPointerDeviceId,
206 kFlutterPointerButtonMousePrimary))
207 .Times(1);
208 EXPECT_CALL(delegate, OnPointerUp(10.0, 10.0, kFlutterPointerDeviceKindStylus,
209 kDefaultPointerDeviceId,
210 kFlutterPointerButtonMousePrimary))
211 .Times(1);
212
213 // Leave
214 EXPECT_CALL(delegate,
215 OnPointerLeave(10.0, 10.0, kFlutterPointerDeviceKindMouse,
216 kDefaultPointerDeviceId))
217 .Times(1);
218 EXPECT_CALL(delegate,
219 OnPointerLeave(10.0, 10.0, kFlutterPointerDeviceKindTouch,
220 kDefaultPointerDeviceId))
221 .Times(1);
222 EXPECT_CALL(delegate,
223 OnPointerLeave(10.0, 10.0, kFlutterPointerDeviceKindStylus,
224 kDefaultPointerDeviceId))
225 .Times(1);
226
227 win32window.OnPointerMove(10.0, 10.0, kFlutterPointerDeviceKindMouse,
228 kDefaultPointerDeviceId, 0, 0, 0);
229 win32window.OnPointerDown(10.0, 10.0, kFlutterPointerDeviceKindMouse,
230 kDefaultPointerDeviceId, WM_LBUTTONDOWN, 0, 0);
231 win32window.OnPointerUp(10.0, 10.0, kFlutterPointerDeviceKindMouse,
232 kDefaultPointerDeviceId, WM_LBUTTONDOWN);
233 win32window.OnPointerLeave(10.0, 10.0, kFlutterPointerDeviceKindMouse,
234 kDefaultPointerDeviceId);
235
236 // Touch
237 win32window.OnPointerMove(10.0, 10.0, kFlutterPointerDeviceKindTouch,
238 kDefaultPointerDeviceId, 0, 0, 0);
239 win32window.OnPointerDown(10.0, 10.0, kFlutterPointerDeviceKindTouch,
240 kDefaultPointerDeviceId, WM_LBUTTONDOWN, 0, 0);
241 win32window.OnPointerUp(10.0, 10.0, kFlutterPointerDeviceKindTouch,
242 kDefaultPointerDeviceId, WM_LBUTTONDOWN);
243 win32window.OnPointerLeave(10.0, 10.0, kFlutterPointerDeviceKindTouch,
244 kDefaultPointerDeviceId);
245
246 // Pen
247 win32window.OnPointerMove(10.0, 10.0, kFlutterPointerDeviceKindStylus,
248 kDefaultPointerDeviceId, 0, 0, 0);
249 win32window.OnPointerDown(10.0, 10.0, kFlutterPointerDeviceKindStylus,
250 kDefaultPointerDeviceId, WM_LBUTTONDOWN, 0, 0);
251 win32window.OnPointerUp(10.0, 10.0, kFlutterPointerDeviceKindStylus,
252 kDefaultPointerDeviceId, WM_LBUTTONDOWN);
253 win32window.OnPointerLeave(10.0, 10.0, kFlutterPointerDeviceKindStylus,
254 kDefaultPointerDeviceId);
255
256 // Destruction of win32window sends a HIDE update. In situ, the window is
257 // owned by the delegate, and so is destructed first. Not so here.
258 win32window.SetView(nullptr);
259 }

References flutter::FlutterWindow::OnPointerDown(), flutter::FlutterWindow::OnPointerLeave(), flutter::FlutterWindow::OnPointerMove(), flutter::FlutterWindow::OnPointerUp(), and flutter::FlutterWindow::SetView().

## ◆ TEST_F() [78/204]

flutter::testing::TEST_F | ( | FlutterWindowTest | ,
|  | OnScrollCallsGetScrollOffsetMultiplier |
| ) |  |

Definition at line 529 of file flutter_window_unittests.cc.

529 {
530 MockFlutterWindow win32window;
531 MockWindowBindingHandlerDelegate delegate;
532 EXPECT_CALL(win32window, OnWindowStateEvent).Times(AnyNumber());
533 win32window.SetView(&delegate);
534
535 EXPECT_CALL(win32window, GetWindowHandle).WillOnce([&win32window]() {
536 return win32window.FlutterWindow::GetWindowHandle();
537 });
538 EXPECT_CALL(win32window, GetScrollOffsetMultiplier).WillOnce(Return(120.0f));
539
540 EXPECT_CALL(delegate,
541 OnScroll(_, _, 0, 0, 120.0f, kFlutterPointerDeviceKindMouse,
542 kDefaultPointerDeviceId))
543 .Times(1);
544
545 win32window.OnScroll(0.0f, 0.0f, kFlutterPointerDeviceKindMouse,
546 kDefaultPointerDeviceId);
547 }

## ◆ TEST_F() [79/204]

flutter::testing::TEST_F | ( | FlutterWindowTest | ,
|  | OnStylusPointerDown |
| ) |  |

Definition at line 261 of file flutter_window_unittests.cc.

261 {
262 auto mock_proc_table = std::make_shared<MockWindowsProcTable>();
263
264 // Set up expectations for the mock
265 EXPECT_CALL(*mock_proc_table, GetPointerInfo(_, _))
266 .WillRepeatedly([](UINT32 pointer_id, POINTER_INFO* pointer_info) {
267 if (pointer_info != nullptr) {
268 pointer_info->pointerType = PT_PEN;
269 pointer_info->pointerId = pointer_id;
270 pointer_info->pointerFlags = POINTER_FLAG_INCONTACT;
271 }
272 return TRUE;
273 });
274
275 EXPECT_CALL(*mock_proc_table, GetPointerPenInfo(_, _))
276 .WillRepeatedly([](UINT32 pointer_id, POINTER_PEN_INFO* pen_info) {
277 if (pen_info != nullptr) {
278 pen_info->pressure = 720; // Non-zero pressure for contact events
279 pen_info->rotation = 0;
280 }
281 return TRUE;
282 });
283
284 POINTER_INFO test_pointer_info = {};
285 BOOL result = mock_proc_table->GetPointerInfo(1, &test_pointer_info);
286
287 MockFlutterWindow win32window(100, 100, mock_proc_table);
288 MockWindowBindingHandlerDelegate delegate;
289
290 win32window.SetView(&delegate);
291
292 EXPECT_CALL(delegate,
293 OnPointerDown(10.0, 10.0, kFlutterPointerDeviceKindStylus,
294 kDefaultPointerDeviceId,
295 kFlutterPointerButtonMousePrimary, 720, 0))
296 .Times(1);
297
298 UINT32 pointerId = 1;
299 WPARAM wparam = static_cast<WPARAM>(pointerId);
300 LPARAM lparam = MAKELPARAM(10, 10);
301
302 win32window.InjectWindowMessage(WM_POINTERDOWN, wparam, lparam);
303 }

## ◆ TEST_F() [80/204]

flutter::testing::TEST_F | ( | FlutterWindowTest | ,
|  | OnStylusPointerHover |
| ) |  |

Definition at line 418 of file flutter_window_unittests.cc.

418 {
419 // Test that WM_POINTERUPDATE without POINTER_FLAG_INCONTACT (hover) is
420 // handled
421 auto mock_proc_table = std::make_shared<MockWindowsProcTable>();
422
423 EXPECT_CALL(*mock_proc_table, GetPointerInfo(_, _))
424 .WillRepeatedly([](UINT32 pointer_id, POINTER_INFO* pointer_info) {
425 if (pointer_info != nullptr) {
426 pointer_info->pointerId = 1;
427 pointer_info->pointerType = PT_PEN;
428 // No POINTER_FLAG_INCONTACT - this simulates a hover event
429 pointer_info->pointerFlags = POINTER_FLAG_UPDATE;
430 pointer_info->ptPixelLocation.x = 45;
431 pointer_info->ptPixelLocation.y = 50;
432 }
433 return TRUE;
434 });
435
436 EXPECT_CALL(*mock_proc_table, GetPointerPenInfo(_, _))
437 .WillRepeatedly([](UINT32 pointer_id, POINTER_PEN_INFO* pen_info) {
438 if (pen_info != nullptr) {
439 pen_info->pressure = 0;
440 pen_info->rotation = 0;
441 }
442 return TRUE;
443 });
444
445 MockFlutterWindow win32window(100, 100, mock_proc_table);
446 MockWindowBindingHandlerDelegate delegate;
447 win32window.SetView(&delegate);
448
449 // First establish the pointer with WM_POINTERDOWN
450 EXPECT_CALL(delegate,
451 OnPointerDown(45, 50, kFlutterPointerDeviceKindStylus, 0,
452 kFlutterPointerButtonMousePrimary, 0, 0))
453 .Times(1);
454
455 UINT32 pointerId = 1;
456 WPARAM wparam = static_cast<WPARAM>(pointerId);
457 LPARAM lparam = MAKELPARAM(45, 50);
458 win32window.InjectWindowMessage(WM_POINTERDOWN, wparam, lparam);
459
460 // Now expect OnPointerMove to be called for hover events
461 EXPECT_CALL(delegate, OnPointerMove(45, 50, kFlutterPointerDeviceKindStylus,
462 0, 0, 0, 0))
463 .Times(1);
464
465 // Inject WM_POINTERUPDATE message (hover event)
466 win32window.InjectWindowMessage(WM_POINTERUPDATE, wparam, lparam);
467 }

## ◆ TEST_F() [81/204]

flutter::testing::TEST_F | ( | FlutterWindowTest | ,
|  | OnStylusPointerLeave |
| ) |  |

Definition at line 381 of file flutter_window_unittests.cc.

381 {
382 auto mock_proc_table = std::make_shared<MockWindowsProcTable>();
383
384 EXPECT_CALL(*mock_proc_table, GetPointerInfo(_, _))
385 .WillRepeatedly([](UINT32 pointer_id, POINTER_INFO* pointer_info) {
386 if (pointer_info != nullptr) {
387 pointer_info->pointerType = PT_PEN;
388 pointer_info->pointerId = pointer_id;
389 pointer_info->pointerFlags = POINTER_FLAG_UP;
390 }
391 return TRUE;
392 });
393
394 EXPECT_CALL(*mock_proc_table, GetPointerPenInfo(_, _))
395 .WillRepeatedly([](UINT32 pointer_id, POINTER_PEN_INFO* pen_info) {
396 if (pen_info != nullptr) {
397 pen_info->pressure = 720;
398 pen_info->rotation = 0;
399 }
400 return TRUE;
401 });
402
403 MockFlutterWindow win32window(100, 100, mock_proc_table);
404 MockWindowBindingHandlerDelegate delegate;
405 win32window.SetView(&delegate);
406
407 EXPECT_CALL(delegate, OnPointerLeave(35, 40, kFlutterPointerDeviceKindStylus,
408 kDefaultPointerDeviceId))
409 .Times(1);
410
411 UINT32 pointerId = 1;
412 WPARAM wparam = static_cast<WPARAM>(pointerId);
413 LPARAM lparam = MAKELPARAM(35, 40);
414
415 win32window.InjectWindowMessage(WM_POINTERLEAVE, wparam, lparam);
416 }

## ◆ TEST_F() [82/204]

flutter::testing::TEST_F | ( | FlutterWindowTest | ,
|  | OnStylusPointerMove |
| ) |  |

Definition at line 305 of file flutter_window_unittests.cc.

305 {
306 auto mock_proc_table = std::make_shared<MockWindowsProcTable>();
307
308 EXPECT_CALL(*mock_proc_table, GetPointerInfo(_, _))
309 .WillRepeatedly([](UINT32 pointer_id, POINTER_INFO* pointer_info) {
310 if (pointer_info != nullptr) {
311 pointer_info->pointerType = PT_PEN;
312 pointer_info->pointerId = pointer_id;
313 pointer_info->pointerFlags =
314 POINTER_FLAG_INCONTACT | POINTER_FLAG_UPDATE;
315 }
316 return TRUE;
317 });
318
319 EXPECT_CALL(*mock_proc_table, GetPointerPenInfo(_, _))
320 .WillRepeatedly([](UINT32 pointer_id, POINTER_PEN_INFO* pen_info) {
321 if (pen_info != nullptr) {
322 pen_info->pressure = 720; // Non-zero pressure for contact events
323 pen_info->rotation = 10; // This is PRE-transformation to radians.
324 }
325 return TRUE;
326 });
327
328 MockFlutterWindow win32window(100, 100, mock_proc_table);
329 MockWindowBindingHandlerDelegate delegate;
330 win32window.SetView(&delegate);
331
332 EXPECT_CALL(delegate, OnPointerMove(15, 20, kFlutterPointerDeviceKindStylus,
333 kDefaultPointerDeviceId, 10, 720, 0))
334 .Times(1);
335
336 UINT32 pointerId = 1;
337 WPARAM wparam = static_cast<WPARAM>(pointerId);
338 LPARAM lparam = MAKELPARAM(15, 20);
339
340 win32window.InjectWindowMessage(WM_POINTERUPDATE, wparam, lparam);
341 }

## ◆ TEST_F() [83/204]

flutter::testing::TEST_F | ( | FlutterWindowTest | ,
|  | OnStylusPointerUp |
| ) |  |

Definition at line 343 of file flutter_window_unittests.cc.

343 {
344 auto mock_proc_table = std::make_shared<MockWindowsProcTable>();
345
346 EXPECT_CALL(*mock_proc_table, GetPointerInfo(_, _))
347 .WillRepeatedly([](UINT32 pointer_id, POINTER_INFO* pointer_info) {
348 if (pointer_info != nullptr) {
349 pointer_info->pointerType = PT_PEN;
350 pointer_info->pointerId = pointer_id;
351 pointer_info->pointerFlags = POINTER_FLAG_UP;
352 }
353 return TRUE;
354 });
355
356 EXPECT_CALL(*mock_proc_table, GetPointerPenInfo(_, _))
357 .WillRepeatedly([](UINT32 pointer_id, POINTER_PEN_INFO* pen_info) {
358 if (pen_info != nullptr) {
359 pen_info->pressure = 720;
360 pen_info->rotation = 0;
361 }
362 return TRUE;
363 });
364
365 MockFlutterWindow win32window(100, 100, mock_proc_table);
366 MockWindowBindingHandlerDelegate delegate;
367 win32window.SetView(&delegate);
368
369 EXPECT_CALL(delegate, OnPointerUp(25, 30, kFlutterPointerDeviceKindStylus,
370 kDefaultPointerDeviceId,
371 kFlutterPointerButtonMousePrimary))
372 .Times(1);
373
374 UINT32 pointerId = 1;
375 WPARAM wparam = static_cast<WPARAM>(pointerId);
376 LPARAM lparam = MAKELPARAM(25, 30);
377
378 win32window.InjectWindowMessage(WM_POINTERUP, wparam, lparam);
379 }

## ◆ TEST_F() [84/204]

flutter::testing::TEST_F | ( | FlutterWindowTest | ,
|  | OnThemeChange |
| ) |  |

Definition at line 560 of file flutter_window_unittests.cc.

560 {
561 MockFlutterWindow win32window;
562 MockWindowBindingHandlerDelegate delegate;
563 EXPECT_CALL(win32window, OnWindowStateEvent).Times(AnyNumber());
564 win32window.SetView(&delegate);
565
566 EXPECT_CALL(delegate, OnHighContrastChanged).Times(1);
567
568 win32window.InjectWindowMessage(WM_THEMECHANGED, 0, 0);
569 }

## ◆ TEST_F() [85/204]

flutter::testing::TEST_F | ( | FlutterWindowTest | ,
|  | OnTouchPointerDown |
| ) |  |

Definition at line 498 of file flutter_window_unittests.cc.

498 {
499 auto mock_proc_table = std::make_shared<MockWindowsProcTable>();
500
501 EXPECT_CALL(*mock_proc_table, GetPointerInfo(_, _))
502 .WillRepeatedly([](UINT32 pointer_id, POINTER_INFO* pointer_info) {
503 if (pointer_info != nullptr) {
504 pointer_info->pointerType = PT_TOUCH;
505 pointer_info->pointerId = pointer_id;
506 pointer_info->pointerFlags = POINTER_FLAG_INCONTACT;
507 }
508 return TRUE;
509 });
510
511 MockFlutterWindow win32window(100, 100, mock_proc_table);
512 MockWindowBindingHandlerDelegate delegate;
513 win32window.SetView(&delegate);
514
515 EXPECT_CALL(delegate, OnPointerDown(55, 60, kFlutterPointerDeviceKindTouch,
516 kDefaultPointerDeviceId,
517 kFlutterPointerButtonMousePrimary, 0, 0))
518 .Times(1);
519
520 UINT32 pointerId = 1;
521 WPARAM wparam = static_cast<WPARAM>(pointerId);
522 LPARAM lparam = MAKELPARAM(55, 60);
523
524 win32window.InjectWindowMessage(WM_POINTERDOWN, wparam, lparam);
525 }

## ◆ TEST_F() [86/204]

flutter::testing::TEST_F | ( | FlutterWindowTest | ,
|  | OnWindowRepaint |
| ) |  |

Definition at line 549 of file flutter_window_unittests.cc.

549 {
550 MockFlutterWindow win32window;
551 MockWindowBindingHandlerDelegate delegate;
552 EXPECT_CALL(win32window, OnWindowStateEvent).Times(AnyNumber());
553 win32window.SetView(&delegate);
554
555 EXPECT_CALL(delegate, OnWindowRepaint()).Times(1);
556
557 win32window.InjectWindowMessage(WM_PAINT, 0, 0);
558 }

## ◆ TEST_F() [87/204]

flutter::testing::TEST_F | ( | KeyboardTest | ,
|  | AltGrModifiedKey |
| ) |  |

Definition at line 1278 of file keyboard_unittests.cc.

1278 {
1279 KeyboardTester tester{GetContext()};
1280 tester.Responding(false);
1281
1282 // German Keyboard layout
1283
1284 // Press AltGr, which Win32 precedes with a ContrlLeft down.
1285 tester.InjectKeyboardChanges(std::vector<KeyboardChange>{
1286 KeyStateChange{VK_LCONTROL, true, true},
1287 WmKeyDownInfo{VK_LCONTROL, kScanCodeControl, kNotExtended, kWasUp}.Build(
1288 kWmResultZero),
1289 KeyStateChange{VK_RMENU, true, true},
1290 WmKeyDownInfo{VK_MENU, kScanCodeAlt, kExtended, kWasUp}.Build(
1291 kWmResultZero)});
1292
1293 EXPECT_EQ(tester.key_calls.size(), 2);
1294 EXPECT_CALL_IS_EVENT(tester.key_calls[0], kFlutterKeyEventTypeDown,
1295 kPhysicalControlLeft, kLogicalControlLeft, "",
1296 kNotSynthesized);
1297 EXPECT_CALL_IS_EVENT(tester.key_calls[1], kFlutterKeyEventTypeDown,
1298 kPhysicalAltRight, kLogicalAltRight, "",
1299 kNotSynthesized);
1300 tester.clear_key_calls();
1301 EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 2);
1302
1303 // Press Q
1304 tester.InjectKeyboardChanges(std::vector<KeyboardChange>{
1305 WmKeyDownInfo{kVirtualKeyQ, kScanCodeKeyQ, kNotExtended, kWasUp}.Build(
1306 kWmResultZero),
1307 WmCharInfo{'@', kScanCodeKeyQ, kNotExtended, kWasUp}.Build(
1308 kWmResultZero)});
1309
1310 EXPECT_EQ(tester.key_calls.size(), 2);
1311 EXPECT_CALL_IS_EVENT(tester.key_calls[0], kFlutterKeyEventTypeDown,
1312 kPhysicalKeyQ, kLogicalKeyQ, "@", kNotSynthesized);
1313 EXPECT_CALL_IS_TEXT(tester.key_calls[1], u"@");
1314 tester.clear_key_calls();
1315 EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 2);
1316
1317 // Release Q
1318 tester.InjectKeyboardChanges(std::vector<KeyboardChange>{
1319 WmKeyUpInfo{kVirtualKeyQ, kScanCodeKeyQ, kNotExtended}.Build(
1320 kWmResultZero)});
1321
1322 EXPECT_EQ(tester.key_calls.size(), 1);
1323 EXPECT_CALL_IS_EVENT(tester.key_calls[0], kFlutterKeyEventTypeUp,
1324 kPhysicalKeyQ, kLogicalKeyQ, "", kNotSynthesized);
1325 tester.clear_key_calls();
1326 EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 1);
1327
1328 // Release AltGr. Win32 doesn't dispatch ControlLeft up. Instead Flutter will
1329 // forge one. The AltGr is a system key, therefore will be handled by Win32's
1330 // default WndProc.
1331 tester.InjectKeyboardChanges(std::vector<KeyboardChange>{
1332 KeyStateChange{VK_LCONTROL, false, true},
1333 ExpectForgedMessage{
1334 WmKeyUpInfo{VK_CONTROL, kScanCodeControl, kNotExtended}.Build(
1335 kWmResultZero)},
1336 KeyStateChange{VK_RMENU, false, true},
1337 WmSysKeyUpInfo{VK_MENU, kScanCodeAlt, kExtended}.Build(
1338 kWmResultDefault)});
1339
1340 EXPECT_EQ(tester.key_calls.size(), 2);
1341 EXPECT_CALL_IS_EVENT(tester.key_calls[0], kFlutterKeyEventTypeUp,
1342 kPhysicalControlLeft, kLogicalControlLeft, "",
1343 kNotSynthesized);
1344 EXPECT_CALL_IS_EVENT(tester.key_calls[1], kFlutterKeyEventTypeUp,
1345 kPhysicalAltRight, kLogicalAltRight, "",
1346 kNotSynthesized);
1347 tester.clear_key_calls();
1348 // The sys key up must not be redispatched. The forged ControlLeft up will.
1349 EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 1);
1350 }
EXPECT_CALL_IS_TEXT
#define EXPECT_CALL_IS_TEXT(_key_call, u16_string)
Definition: keyboard_unittests.cc:564
EXPECT_CALL_IS_EVENT
#define EXPECT_CALL_IS_EVENT(_key_call, _type, _physical, _logical, _character, _synthesized)
Definition: keyboard_unittests.cc:558

References EXPECT_CALL_IS_EVENT, and EXPECT_CALL_IS_TEXT.

## ◆ TEST_F() [88/204]

flutter::testing::TEST_F | ( | KeyboardTest | ,
|  | AltGrTwice |
| ) |  |

Definition at line 1365 of file keyboard_unittests.cc.

1365 {
1366 KeyboardTester tester{GetContext()};
1367 tester.Responding(false);
1368
1369 // 1. AltGr down.
1370
1371 // The key down event causes a ControlLeft down and a AltRight (extended
1372 // AltLeft) down.
1373 tester.InjectKeyboardChanges(std::vector<KeyboardChange>{
1374 KeyStateChange{VK_LCONTROL, true, true},
1375 WmKeyDownInfo{VK_CONTROL, kScanCodeControl, kNotExtended, kWasUp}.Build(
1376 kWmResultZero),
1377 KeyStateChange{VK_RMENU, true, true},
1378 WmKeyDownInfo{VK_MENU, kScanCodeAlt, kExtended, kWasUp}.Build(
1379 kWmResultZero)});
1380
1381 EXPECT_EQ(tester.key_calls.size(), 2);
1382 EXPECT_CALL_IS_EVENT(tester.key_calls[0], kFlutterKeyEventTypeDown,
1383 kPhysicalControlLeft, kLogicalControlLeft, "",
1384 kNotSynthesized);
1385 EXPECT_CALL_IS_EVENT(tester.key_calls[1], kFlutterKeyEventTypeDown,
1386 kPhysicalAltRight, kLogicalAltRight, "",
1387 kNotSynthesized);
1388 tester.clear_key_calls();
1389 EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 2);
1390
1391 // 2. AltGr up.
1392
1393 // The key up event only causes a AltRight (extended AltLeft) up.
1394 tester.InjectKeyboardChanges(std::vector<KeyboardChange>{
1395 KeyStateChange{VK_LCONTROL, false, true},
1396 ExpectForgedMessage{
1397 WmKeyUpInfo{VK_CONTROL, kScanCodeControl, kNotExtended}.Build(
1398 kWmResultZero)},
1399 KeyStateChange{VK_RMENU, false, true},
1400 WmSysKeyUpInfo{VK_MENU, kScanCodeAlt, kExtended}.Build(
1401 kWmResultDefault)});
1402 EXPECT_EQ(tester.key_calls.size(), 2);
1403 EXPECT_CALL_IS_EVENT(tester.key_calls[0], kFlutterKeyEventTypeUp,
1404 kPhysicalControlLeft, kLogicalControlLeft, "",
1405 kNotSynthesized);
1406 EXPECT_CALL_IS_EVENT(tester.key_calls[1], kFlutterKeyEventTypeUp,
1407 kPhysicalAltRight, kLogicalAltRight, "",
1408 kNotSynthesized);
1409 tester.clear_key_calls();
1410 // The sys key up must not be redispatched. The forged ControlLeft up will.
1411 EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 1);
1412
1413 // 3. AltGr down (or: ControlLeft down then AltRight down.)
1414
1415 tester.InjectKeyboardChanges(std::vector<KeyboardChange>{
1416 KeyStateChange{VK_LCONTROL, true, false},
1417 WmKeyDownInfo{VK_CONTROL, kScanCodeControl, kNotExtended, kWasUp}.Build(
1418 kWmResultZero),
1419 KeyStateChange{VK_RMENU, true, true},
1420 WmKeyDownInfo{VK_MENU, kScanCodeAlt, kExtended, kWasUp}.Build(
1421 kWmResultZero)});
1422
1423 EXPECT_EQ(tester.key_calls.size(), 2);
1424 EXPECT_CALL_IS_EVENT(tester.key_calls[0], kFlutterKeyEventTypeDown,
1425 kPhysicalControlLeft, kLogicalControlLeft, "",
1426 kNotSynthesized);
1427 EXPECT_CALL_IS_EVENT(tester.key_calls[1], kFlutterKeyEventTypeDown,
1428 kPhysicalAltRight, kLogicalAltRight, "",
1429 kNotSynthesized);
1430 tester.clear_key_calls();
1431 EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 2);
1432
1433 // 4. AltGr up.
1434
1435 // The key up event only causes a AltRight (extended AltLeft) up.
1436 tester.InjectKeyboardChanges(std::vector<KeyboardChange>{
1437 KeyStateChange{VK_LCONTROL, false, false},
1438 ExpectForgedMessage{
1439 WmKeyUpInfo{VK_CONTROL, kScanCodeControl, kNotExtended}.Build(
1440 kWmResultZero)},
1441 KeyStateChange{VK_RMENU, false, false},
1442 WmSysKeyUpInfo{VK_MENU, kScanCodeAlt, kExtended}.Build(
1443 kWmResultDefault)});
1444 EXPECT_EQ(tester.key_calls.size(), 2);
1445 EXPECT_CALL_IS_EVENT(tester.key_calls[0], kFlutterKeyEventTypeUp,
1446 kPhysicalControlLeft, kLogicalControlLeft, "",
1447 kNotSynthesized);
1448 EXPECT_CALL_IS_EVENT(tester.key_calls[1], kFlutterKeyEventTypeUp,
1449 kPhysicalAltRight, kLogicalAltRight, "",
1450 kNotSynthesized);
1451 tester.clear_key_calls();
1452 // The sys key up must not be redispatched. The forged ControlLeft up will.
1453 EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 1);
1454
1455 // 5. For key sequence 2: a real ControlLeft up.
1456 tester.InjectKeyboardChanges(std::vector<KeyboardChange>{
1457 WmKeyUpInfo{VK_CONTROL, kScanCodeControl, kNotExtended}.Build(
1458 kWmResultZero)});
1459 EXPECT_EQ(tester.key_calls.size(), 1);
1460 EXPECT_CALL_IS_EVENT(tester.key_calls[0], kFlutterKeyEventTypeDown, 0, 0, "",
1461 kNotSynthesized);
1462 tester.clear_key_calls();
1463 EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 0);
1464 }

References EXPECT_CALL_IS_EVENT.

## ◆ TEST_F() [89/204]

flutter::testing::TEST_F | ( | KeyboardTest | ,
|  | AltLeftUnhandled |
| ) |  |

Definition at line 841 of file keyboard_unittests.cc.

841 {
842 KeyboardTester tester{GetContext()};
843 tester.Responding(false);
844
845 // US Keyboard layout
846
847 // Press AltLeft. AltLeft is a SysKeyDown event.
848 tester.InjectKeyboardChanges(std::vector<KeyboardChange>{
849 KeyStateChange{VK_LMENU, true, false},
850 WmSysKeyDownInfo{VK_MENU, kScanCodeAlt, kNotExtended, kWasUp}.Build(
851 kWmResultDefault)}); // Always pass to the default WndProc.
852
853 EXPECT_EQ(tester.key_calls.size(), 1);
854 EXPECT_CALL_IS_EVENT(tester.key_calls[0], kFlutterKeyEventTypeDown,
855 kPhysicalAltLeft, kLogicalAltLeft, "", kNotSynthesized);
856 tester.clear_key_calls();
857 // Don't redispatch sys messages.
858 EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 0);
859
860 // Release AltLeft. AltLeft is a SysKeyUp event.
861 tester.InjectKeyboardChanges(std::vector<KeyboardChange>{
862 KeyStateChange{VK_LMENU, false, true},
863 WmSysKeyUpInfo{VK_MENU, kScanCodeAlt, kNotExtended}.Build(
864 kWmResultDefault)}); // Always pass to the default WndProc.
865
866 EXPECT_EQ(tester.key_calls.size(), 1);
867 EXPECT_CALL_IS_EVENT(tester.key_calls[0], kFlutterKeyEventTypeUp,
868 kPhysicalAltLeft, kLogicalAltLeft, "", kNotSynthesized);
869 tester.clear_key_calls();
870 // Don't redispatch sys messages.
871 EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 0);
872 }

References EXPECT_CALL_IS_EVENT.

## ◆ TEST_F() [90/204]

flutter::testing::TEST_F | ( | KeyboardTest | ,
|  | AltRightUnhandled |
| ) |  |

Definition at line 874 of file keyboard_unittests.cc.

874 {
875 KeyboardTester tester{GetContext()};
876 tester.Responding(false);
877
878 // US Keyboard layout
879
880 // Press AltRight. AltRight is a SysKeyDown event.
881 tester.InjectKeyboardChanges(std::vector<KeyboardChange>{
882 KeyStateChange{VK_RMENU, true, false},
883 WmSysKeyDownInfo{VK_MENU, kScanCodeAlt, kExtended, kWasUp}.Build(
884 kWmResultDefault)}); // Always pass to the default WndProc.
885
886 EXPECT_EQ(tester.key_calls.size(), 1);
887 EXPECT_CALL_IS_EVENT(tester.key_calls[0], kFlutterKeyEventTypeDown,
888 kPhysicalAltRight, kLogicalAltRight, "",
889 kNotSynthesized);
890 tester.clear_key_calls();
891 // Don't redispatch sys messages.
892 EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 0);
893
894 // Release AltRight. AltRight is a SysKeyUp event.
895 tester.InjectKeyboardChanges(std::vector<KeyboardChange>{
896 KeyStateChange{VK_RMENU, false, true},
897 WmSysKeyUpInfo{VK_MENU, kScanCodeAlt, kExtended}.Build(
898 kWmResultDefault)}); // Always pass to the default WndProc.
899
900 EXPECT_EQ(tester.key_calls.size(), 1);
901 EXPECT_CALL_IS_EVENT(tester.key_calls[0], kFlutterKeyEventTypeUp,
902 kPhysicalAltRight, kLogicalAltRight, "",
903 kNotSynthesized);
904 tester.clear_key_calls();
905 // Don't redispatch sys messages.
906 EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 0);
907 }

References EXPECT_CALL_IS_EVENT.

## ◆ TEST_F() [91/204]

flutter::testing::TEST_F | ( | KeyboardTest | ,
|  | ArrowLeftHandled |
| ) |  |

Definition at line 635 of file keyboard_unittests.cc.

635 {
636 KeyboardTester tester{GetContext()};
637 tester.Responding(true);
638
639 // US Keyboard layout
640
641 // Press ArrowLeft
642 tester.InjectKeyboardChanges(std::vector<KeyboardChange>{
643 WmKeyDownInfo{VK_LEFT, kScanCodeArrowLeft, kExtended, kWasUp}.Build(
644 kWmResultZero)});
645
646 EXPECT_EQ(tester.key_calls.size(), 1);
647 EXPECT_CALL_IS_EVENT(tester.key_calls[0], kFlutterKeyEventTypeDown,
648 kPhysicalArrowLeft, kLogicalArrowLeft, "",
649 kNotSynthesized);
650 tester.clear_key_calls();
651 EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 0);
652
653 // Release ArrowLeft
654 tester.InjectKeyboardChanges(std::vector<KeyboardChange>{
655 WmKeyUpInfo{VK_LEFT, kScanCodeArrowLeft, kExtended}.Build(
656 kWmResultZero)});
657
658 EXPECT_EQ(tester.key_calls.size(), 1);
659 EXPECT_CALL_IS_EVENT(tester.key_calls[0], kFlutterKeyEventTypeUp,
660 kPhysicalArrowLeft, kLogicalArrowLeft, "",
661 kNotSynthesized);
662 tester.clear_key_calls();
663 EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 0);
664 }

References EXPECT_CALL_IS_EVENT.

## ◆ TEST_F() [92/204]

flutter::testing::TEST_F | ( | KeyboardTest | ,
|  | ArrowLeftUnhandled |
| ) |  |

Definition at line 666 of file keyboard_unittests.cc.

666 {
667 KeyboardTester tester{GetContext()};
668 tester.Responding(false);
669
670 // US Keyboard layout
671
672 // Press ArrowLeft
673 tester.InjectKeyboardChanges(std::vector<KeyboardChange>{
674 WmKeyDownInfo{VK_LEFT, kScanCodeArrowLeft, kExtended, kWasUp}.Build(
675 kWmResultZero)});
676
677 EXPECT_EQ(tester.key_calls.size(), 1);
678 EXPECT_CALL_IS_EVENT(tester.key_calls[0], kFlutterKeyEventTypeDown,
679 kPhysicalArrowLeft, kLogicalArrowLeft, "",
680 kNotSynthesized);
681 tester.clear_key_calls();
682 EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 1);
683
684 // Release ArrowLeft
685 tester.InjectKeyboardChanges(std::vector<KeyboardChange>{
686 WmKeyUpInfo{VK_LEFT, kScanCodeArrowLeft, kExtended}.Build(
687 kWmResultZero)});
688
689 EXPECT_EQ(tester.key_calls.size(), 1);
690 EXPECT_CALL_IS_EVENT(tester.key_calls[0], kFlutterKeyEventTypeUp,
691 kPhysicalArrowLeft, kLogicalArrowLeft, "",
692 kNotSynthesized);
693 tester.clear_key_calls();
694 EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 1);
695 }

References EXPECT_CALL_IS_EVENT.

## ◆ TEST_F() [93/204]

flutter::testing::TEST_F | ( | KeyboardTest | ,
|  | CtrlLeftDigit1 |
| ) |  |

Definition at line 1188 of file keyboard_unittests.cc.

1188 {
1189 KeyboardTester tester{GetContext()};
1190 tester.Responding(false);
1191
1192 // US Keyboard layout
1193
1194 // Press ControlLeft
1195 tester.InjectKeyboardChanges(std::vector<KeyboardChange>{
1196 KeyStateChange{VK_LCONTROL, true, true},
1197 WmKeyDownInfo{VK_CONTROL, kScanCodeControl, kNotExtended, kWasUp}.Build(
1198 kWmResultZero)});
1199
1200 EXPECT_EQ(tester.key_calls.size(), 1);
1201 EXPECT_CALL_IS_EVENT(tester.key_calls[0], kFlutterKeyEventTypeDown,
1202 kPhysicalControlLeft, kLogicalControlLeft, "",
1203 kNotSynthesized);
1204 tester.clear_key_calls();
1205 EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 1);
1206
1207 // Press 1
1208 tester.InjectKeyboardChanges(std::vector<KeyboardChange>{
1209 WmKeyDownInfo{kVirtualDigit1, kScanCodeDigit1, kNotExtended, kWasUp}
1210 .Build(kWmResultZero)});
1211
1212 EXPECT_EQ(tester.key_calls.size(), 1);
1213 EXPECT_CALL_IS_EVENT(tester.key_calls[0], kFlutterKeyEventTypeDown,
1214 kPhysicalDigit1, kLogicalDigit1, "", kNotSynthesized);
1215 tester.clear_key_calls();
1216 EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 1);
1217
1218 // Release 1
1219 tester.InjectKeyboardChanges(std::vector<KeyboardChange>{
1220 WmKeyUpInfo{kVirtualDigit1, kScanCodeDigit1, kNotExtended}.Build(
1221 kWmResultZero)});
1222
1223 EXPECT_EQ(tester.key_calls.size(), 1);
1224 EXPECT_CALL_IS_EVENT(tester.key_calls[0], kFlutterKeyEventTypeUp,
1225 kPhysicalDigit1, kLogicalDigit1, "", kNotSynthesized);
1226 tester.clear_key_calls();
1227 EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 1);
1228
1229 // Release ControlLeft
1230 tester.InjectKeyboardChanges(std::vector<KeyboardChange>{
1231 KeyStateChange{VK_LCONTROL, false, true},
1232 WmKeyUpInfo{VK_CONTROL, kScanCodeControl, kNotExtended}.Build(
1233 kWmResultZero)});
1234
1235 EXPECT_EQ(tester.key_calls.size(), 1);
1236 EXPECT_CALL_IS_EVENT(tester.key_calls[0], kFlutterKeyEventTypeUp,
1237 kPhysicalControlLeft, kLogicalControlLeft, "",
1238 kNotSynthesized);
1239 tester.clear_key_calls();
1240 EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 1);
1241 }

References EXPECT_CALL_IS_EVENT.

## ◆ TEST_F() [94/204]

flutter::testing::TEST_F | ( | KeyboardTest | ,
|  | CtrlLeftKeyA |
| ) |  |

Definition at line 1130 of file keyboard_unittests.cc.

1130 {
1131 KeyboardTester tester{GetContext()};
1132 tester.Responding(false);
1133
1134 // US Keyboard layout
1135
1136 // Press ControlLeft
1137 tester.InjectKeyboardChanges(std::vector<KeyboardChange>{
1138 KeyStateChange{VK_LCONTROL, true, true},
1139 WmKeyDownInfo{VK_CONTROL, kScanCodeControl, kNotExtended, kWasUp}.Build(
1140 kWmResultZero)});
1141
1142 EXPECT_EQ(tester.key_calls.size(), 1);
1143 EXPECT_CALL_IS_EVENT(tester.key_calls[0], kFlutterKeyEventTypeDown,
1144 kPhysicalControlLeft, kLogicalControlLeft, "",
1145 kNotSynthesized);
1146 tester.clear_key_calls();
1147 EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 1);
1148
1149 // Press A
1150 tester.InjectKeyboardChanges(std::vector<KeyboardChange>{
1151 WmKeyDownInfo{kVirtualKeyA, kScanCodeKeyA, kNotExtended, kWasUp}.Build(
1152 kWmResultZero),
1153 WmCharInfo{0x01, kScanCodeKeyA, kNotExtended, kWasUp}.Build(
1154 kWmResultZero)});
1155
1156 EXPECT_EQ(tester.key_calls.size(), 1);
1157 EXPECT_CALL_IS_EVENT(tester.key_calls[0], kFlutterKeyEventTypeDown,
1158 kPhysicalKeyA, kLogicalKeyA, "", kNotSynthesized);
1159 tester.clear_key_calls();
1160 EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 2);
1161
1162 // Release A
1163 tester.InjectKeyboardChanges(std::vector<KeyboardChange>{
1164 WmKeyUpInfo{kVirtualKeyA, kScanCodeKeyA, kNotExtended}.Build(
1165 kWmResultZero)});
1166
1167 EXPECT_EQ(tester.key_calls.size(), 1);
1168 EXPECT_CALL_IS_EVENT(tester.key_calls[0], kFlutterKeyEventTypeUp,
1169 kPhysicalKeyA, kLogicalKeyA, "", kNotSynthesized);
1170 tester.clear_key_calls();
1171 EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 1);
1172
1173 // Release ControlLeft
1174 tester.InjectKeyboardChanges(std::vector<KeyboardChange>{
1175 KeyStateChange{VK_LCONTROL, false, true},
1176 WmKeyUpInfo{VK_CONTROL, kScanCodeControl, kNotExtended}.Build(
1177 kWmResultZero)});
1178
1179 EXPECT_EQ(tester.key_calls.size(), 1);
1180 EXPECT_CALL_IS_EVENT(tester.key_calls[0], kFlutterKeyEventTypeUp,
1181 kPhysicalControlLeft, kLogicalControlLeft, "",
1182 kNotSynthesized);
1183 tester.clear_key_calls();
1184 EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 1);
1185 }

References EXPECT_CALL_IS_EVENT, kScanCodeKeyA, and kVirtualKeyA.

## ◆ TEST_F() [95/204]

flutter::testing::TEST_F | ( | KeyboardTest | ,
|  | CtrlLeftUnhandled |
| ) |  |

Definition at line 775 of file keyboard_unittests.cc.

775 {
776 KeyboardTester tester{GetContext()};
777 tester.Responding(false);
778
779 // US Keyboard layout
780
781 // Press CtrlLeft
782 tester.InjectKeyboardChanges(std::vector<KeyboardChange>{
783 KeyStateChange{VK_LCONTROL, true, false},
784 WmKeyDownInfo{VK_CONTROL, kScanCodeControl, kNotExtended, kWasUp}.Build(
785 kWmResultZero)});
786
787 EXPECT_EQ(tester.key_calls.size(), 1);
788 EXPECT_CALL_IS_EVENT(tester.key_calls[0], kFlutterKeyEventTypeDown,
789 kPhysicalControlLeft, kLogicalControlLeft, "",
790 kNotSynthesized);
791 tester.clear_key_calls();
792 EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 1);
793
794 // Release CtrlLeft
795 tester.InjectKeyboardChanges(std::vector<KeyboardChange>{
796 KeyStateChange{VK_LCONTROL, false, true},
797 WmKeyUpInfo{VK_SHIFT, kScanCodeControl, kNotExtended}.Build(
798 kWmResultZero)});
799
800 EXPECT_EQ(tester.key_calls.size(), 1);
801 EXPECT_CALL_IS_EVENT(tester.key_calls[0], kFlutterKeyEventTypeUp,
802 kPhysicalControlLeft, kLogicalControlLeft, "",
803 kNotSynthesized);
804 tester.clear_key_calls();
805 EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 1);
806 }

References EXPECT_CALL_IS_EVENT.

## ◆ TEST_F() [96/204]

flutter::testing::TEST_F | ( | KeyboardTest | ,
|  | CtrlRightUnhandled |
| ) |  |

Definition at line 808 of file keyboard_unittests.cc.

808 {
809 KeyboardTester tester{GetContext()};
810 tester.Responding(false);
811
812 // US Keyboard layout
813
814 // Press CtrlRight
815 tester.InjectKeyboardChanges(std::vector<KeyboardChange>{
816 KeyStateChange{VK_RCONTROL, true, false},
817 WmKeyDownInfo{VK_CONTROL, kScanCodeControl, kExtended, kWasUp}.Build(
818 kWmResultZero)});
819
820 EXPECT_EQ(tester.key_calls.size(), 1);
821 EXPECT_CALL_IS_EVENT(tester.key_calls[0], kFlutterKeyEventTypeDown,
822 kPhysicalControlRight, kLogicalControlRight, "",
823 kNotSynthesized);
824 tester.clear_key_calls();
825 EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 1);
826
827 // Release CtrlRight
828 tester.InjectKeyboardChanges(std::vector<KeyboardChange>{
829 KeyStateChange{VK_RCONTROL, false, true},
830 WmKeyUpInfo{VK_CONTROL, kScanCodeControl, kExtended}.Build(
831 kWmResultZero)});
832
833 EXPECT_EQ(tester.key_calls.size(), 1);
834 EXPECT_CALL_IS_EVENT(tester.key_calls[0], kFlutterKeyEventTypeUp,
835 kPhysicalControlRight, kLogicalControlRight, "",
836 kNotSynthesized);
837 tester.clear_key_calls();
838 EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 1);
839 }

References EXPECT_CALL_IS_EVENT.

## ◆ TEST_F() [97/204]

flutter::testing::TEST_F | ( | KeyboardTest | ,
|  | DeadKeyThatCombines |
| ) |  |

Definition at line 1468 of file keyboard_unittests.cc.

1468 {
1469 KeyboardTester tester{GetContext()};
1470 tester.Responding(false);
1471
1472 tester.SetLayout(LayoutFrench);
1473
1474 // Press ^¨ (US: Left bracket)
1475 tester.InjectKeyboardChanges(std::vector<KeyboardChange>{
1476 WmKeyDownInfo{0xDD, kScanCodeBracketLeft, kNotExtended, kWasUp}.Build(
1477 kWmResultZero),
1478 WmDeadCharInfo{'^', kScanCodeBracketLeft, kNotExtended, kWasUp}.Build(
1479 kWmResultZero)});
1480
1481 EXPECT_EQ(tester.key_calls.size(), 1);
1482 EXPECT_CALL_IS_EVENT(tester.key_calls[0], kFlutterKeyEventTypeDown,
1483 kPhysicalBracketLeft, kLogicalBracketRight, "^",
1484 kNotSynthesized);
1485 tester.clear_key_calls();
1486 EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 2);
1487
1488 // Release ^¨
1489 tester.InjectKeyboardChanges(std::vector<KeyboardChange>{
1490 WmKeyUpInfo{0xDD, kScanCodeBracketLeft, kNotExtended}.Build(
1491 kWmResultZero)});
1492
1493 EXPECT_EQ(tester.key_calls.size(), 1);
1494 EXPECT_CALL_IS_EVENT(tester.key_calls[0], kFlutterKeyEventTypeUp,
1495 kPhysicalBracketLeft, kLogicalBracketRight, "",
1496 kNotSynthesized);
1497 tester.clear_key_calls();
1498 EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 1);
1499
1500 // Press E
1501 tester.InjectKeyboardChanges(std::vector<KeyboardChange>{
1502 WmKeyDownInfo{kVirtualKeyE, kScanCodeKeyE, kNotExtended, kWasUp}.Build(
1503 kWmResultZero),
1504 WmCharInfo{0xEA, kScanCodeKeyE, kNotExtended, kWasUp}.Build(
1505 kWmResultZero)});
1506
1507 EXPECT_EQ(tester.key_calls.size(), 2);
1508 EXPECT_CALL_IS_EVENT(tester.key_calls[0], kFlutterKeyEventTypeDown,
1509 kPhysicalKeyE, kLogicalKeyE, "ê", kNotSynthesized);
1510 EXPECT_CALL_IS_TEXT(tester.key_calls[1], u"ê");
1511 tester.clear_key_calls();
1512 EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 2);
1513
1514 // Release E
1515 tester.InjectKeyboardChanges(std::vector<KeyboardChange>{
1516 WmKeyUpInfo{kVirtualKeyE, kScanCodeKeyE, kNotExtended}.Build(
1517 kWmResultZero)});
1518
1519 EXPECT_EQ(tester.key_calls.size(), 1);
1520 EXPECT_CALL_IS_EVENT(tester.key_calls[0], kFlutterKeyEventTypeUp,
1521 kPhysicalKeyE, kLogicalKeyE, "", kNotSynthesized);
1522 tester.clear_key_calls();
1523 EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 1);
1524 }

References EXPECT_CALL_IS_EVENT, and EXPECT_CALL_IS_TEXT.

## ◆ TEST_F() [98/204]

flutter::testing::TEST_F | ( | KeyboardTest | ,
|  | DeadKeyThatDoesNotCombine |
| ) |  |

Definition at line 1612 of file keyboard_unittests.cc.

1612 {
1613 KeyboardTester tester{GetContext()};
1614 tester.Responding(false);
1615
1616 tester.SetLayout(LayoutFrench);
1617
1618 // Press ^¨ (US: Left bracket)
1619 tester.InjectKeyboardChanges(std::vector<KeyboardChange>{
1620 WmKeyDownInfo{0xDD, kScanCodeBracketLeft, kNotExtended, kWasUp}.Build(
1621 kWmResultZero),
1622 WmDeadCharInfo{'^', kScanCodeBracketLeft, kNotExtended, kWasUp}.Build(
1623 kWmResultZero)});
1624
1625 EXPECT_EQ(tester.key_calls.size(), 1);
1626 EXPECT_CALL_IS_EVENT(tester.key_calls[0], kFlutterKeyEventTypeDown,
1627 kPhysicalBracketLeft, kLogicalBracketRight, "^",
1628 kNotSynthesized);
1629 tester.clear_key_calls();
1630 EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 2);
1631
1632 // Release ^¨
1633 tester.InjectKeyboardChanges(std::vector<KeyboardChange>{
1634 WmKeyUpInfo{0xDD, kScanCodeBracketLeft, kNotExtended}.Build(
1635 kWmResultZero)});
1636
1637 EXPECT_EQ(tester.key_calls.size(), 1);
1638 EXPECT_CALL_IS_EVENT(tester.key_calls[0], kFlutterKeyEventTypeUp,
1639 kPhysicalBracketLeft, kLogicalBracketRight, "",
1640 kNotSynthesized);
1641 tester.clear_key_calls();
1642 EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 1);
1643
1644 // Press 1
1645 tester.InjectKeyboardChanges(std::vector<KeyboardChange>{
1646 WmKeyDownInfo{kVirtualDigit1, kScanCodeDigit1, kNotExtended, kWasUp}
1647 .Build(kWmResultZero),
1648 WmCharInfo{'^', kScanCodeDigit1, kNotExtended, kWasUp}.Build(
1649 kWmResultZero),
1650 WmCharInfo{'&', kScanCodeDigit1, kNotExtended, kWasUp}.Build(
1651 kWmResultZero)});
1652
1653 EXPECT_EQ(tester.key_calls.size(), 3);
1654 EXPECT_CALL_IS_EVENT(tester.key_calls[0], kFlutterKeyEventTypeDown,
1655 kPhysicalDigit1, kLogicalDigit1, "^", kNotSynthesized);
1656 EXPECT_CALL_IS_TEXT(tester.key_calls[1], u"^");
1657 EXPECT_CALL_IS_TEXT(tester.key_calls[2], u"&");
1658 tester.clear_key_calls();
1659 // TODO(dkwingsmt): This count should probably be 3. Currently the '^'
1660 // message is redispatched due to being part of the KeyDown session, which is
1661 // not handled by the framework, while the '&' message is not redispatched
1662 // for being a standalone message. We should resolve this inconsistency.
1663 // https://github.com/flutter/flutter/issues/98306
1664 EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 2);
1665
1666 // Release 1
1667 tester.InjectKeyboardChanges(std::vector<KeyboardChange>{
1668 WmKeyUpInfo{kVirtualDigit1, kScanCodeDigit1, kNotExtended}.Build(
1669 kWmResultZero)});
1670
1671 EXPECT_EQ(tester.key_calls.size(), 1);
1672 EXPECT_CALL_IS_EVENT(tester.key_calls[0], kFlutterKeyEventTypeUp,
1673 kPhysicalDigit1, kLogicalDigit1, "", kNotSynthesized);
1674 tester.clear_key_calls();
1675 EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 1);
1676 }

References EXPECT_CALL_IS_EVENT, and EXPECT_CALL_IS_TEXT.

## ◆ TEST_F() [99/204]

flutter::testing::TEST_F | ( | KeyboardTest | ,
|  | DeadKeyTwiceThenLetter |
| ) |  |

Definition at line 1681 of file keyboard_unittests.cc.

1681 {
1682 KeyboardTester tester{GetContext()};
1683 tester.Responding(false);
1684
1685 // US INTL layout.
1686
1687 // Press `
1688 tester.InjectKeyboardChanges(std::vector<KeyboardChange>{
1689 WmKeyDownInfo{0xC0, kScanCodeBackquote, kNotExtended, kWasUp}.Build(
1690 kWmResultZero),
1691 WmDeadCharInfo{'`', kScanCodeBackquote, kNotExtended, kWasUp}.Build(
1692 kWmResultZero)});
1693
1694 EXPECT_EQ(tester.key_calls.size(), 1);
1695 EXPECT_CALL_IS_EVENT(tester.key_calls[0], kFlutterKeyEventTypeDown,
1696 kPhysicalBackquote, kLogicalBackquote, "`",
1697 kNotSynthesized);
1698 tester.clear_key_calls();
1699 EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 2);
1700
1701 // Release `
1702 tester.InjectKeyboardChanges(std::vector<KeyboardChange>{
1703 WmKeyUpInfo{0xC0, kScanCodeBackquote, kNotExtended}.Build(
1704 kWmResultZero)});
1705
1706 EXPECT_EQ(tester.key_calls.size(), 1);
1707 EXPECT_CALL_IS_EVENT(tester.key_calls[0], kFlutterKeyEventTypeUp,
1708 kPhysicalBackquote, kLogicalBackquote, "",
1709 kNotSynthesized);
1710 tester.clear_key_calls();
1711 EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 1);
1712
1713 // Press ` again.
1714 // The response should be slow.
1715 std::vector<MockKeyResponseController::ResponseCallback> recorded_callbacks;
1716 tester.LateResponding(
1717 [&recorded_callbacks](
1718 const FlutterKeyEvent* event,
1719 MockKeyResponseController::ResponseCallback callback) {
1720 recorded_callbacks.push_back(callback);
1721 });
1722
1723 tester.InjectKeyboardChanges(std::vector<KeyboardChange>{
1724 WmKeyDownInfo{0xC0, kScanCodeBackquote, kNotExtended, kWasUp}.Build(
1725 kWmResultZero),
1726 WmCharInfo{'`', kScanCodeBackquote, kNotExtended, kWasUp, kBeingReleased,
1727 kNoContext, 1, /*bit25*/ true}
1728 .Build(kWmResultZero),
1729 WmCharInfo{'`', kScanCodeBackquote, kNotExtended, kWasUp}.Build(
1730 kWmResultZero)});
1731
1732 EXPECT_EQ(recorded_callbacks.size(), 1);
1733 EXPECT_EQ(tester.key_calls.size(), 1);
1734 EXPECT_CALL_IS_EVENT(tester.key_calls[0], kFlutterKeyEventTypeDown,
1735 kPhysicalBackquote, kLogicalBackquote, "`",
1736 kNotSynthesized);
1737 tester.clear_key_calls();
1738 // Key down event responded with false.
1739 recorded_callbacks.front()(false);
1740 EXPECT_EQ(tester.key_calls.size(), 2);
1741 EXPECT_CALL_IS_TEXT(tester.key_calls[0], u"`");
1742 EXPECT_CALL_IS_TEXT(tester.key_calls[1], u"`");
1743 tester.clear_key_calls();
1744 // TODO(dkwingsmt): This count should probably be 3. See the comment above
1745 // that is marked with the same issue.
1746 // https://github.com/flutter/flutter/issues/98306
1747 EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 2);
1748
1749 tester.Responding(false);
1750
1751 // Release `
1752 tester.InjectKeyboardChanges(std::vector<KeyboardChange>{
1753 WmKeyUpInfo{0xC0, kScanCodeBackquote, kNotExtended}.Build(
1754 kWmResultZero)});
1755
1756 EXPECT_EQ(tester.key_calls.size(), 1);
1757 EXPECT_CALL_IS_EVENT(tester.key_calls[0], kFlutterKeyEventTypeUp,
1758 kPhysicalBackquote, kLogicalBackquote, "",
1759 kNotSynthesized);
1760 tester.clear_key_calls();
1761 EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 1);
1762 }

References callback, EXPECT_CALL_IS_EVENT, and EXPECT_CALL_IS_TEXT.

## ◆ TEST_F() [100/204]

flutter::testing::TEST_F | ( | KeyboardTest | ,
|  | DeadKeyWithoutDeadMaskThatCombines |
| ) |  |

Definition at line 1531 of file keyboard_unittests.cc.

1531 {
1532 KeyboardTester tester{GetContext()};
1533 tester.Responding(false);
1534
1535 // Press ShiftLeft
1536 tester.InjectKeyboardChanges(std::vector<KeyboardChange>{
1537 KeyStateChange{VK_LSHIFT, true, true},
1538 WmKeyDownInfo{VK_SHIFT, kScanCodeShiftLeft, kNotExtended, kWasUp}.Build(
1539 kWmResultZero)});
1540
1541 EXPECT_EQ(tester.key_calls.size(), 1);
1542 EXPECT_CALL_IS_EVENT(tester.key_calls[0], kFlutterKeyEventTypeDown,
1543 kPhysicalShiftLeft, kLogicalShiftLeft, "",
1544 kNotSynthesized);
1545 tester.clear_key_calls();
1546 EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 1);
1547
1548 // Press 6^
1549 tester.InjectKeyboardChanges(std::vector<KeyboardChange>{
1550 WmKeyDownInfo{'6', kScanCodeDigit6, kNotExtended, kWasUp}.Build(
1551 kWmResultZero),
1552 WmDeadCharInfo{'^', kScanCodeDigit6, kNotExtended, kWasUp}.Build(
1553 kWmResultZero)});
1554
1555 EXPECT_EQ(tester.key_calls.size(), 1);
1556 EXPECT_CALL_IS_EVENT(tester.key_calls[0], kFlutterKeyEventTypeDown,
1557 kPhysicalDigit6, kLogicalDigit6, "6", kNotSynthesized);
1558 tester.clear_key_calls();
1559 EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 2);
1560
1561 // Release 6^
1562 tester.InjectKeyboardChanges(std::vector<KeyboardChange>{
1563 WmKeyUpInfo{'6', kScanCodeDigit6, kNotExtended}.Build(kWmResultZero)});
1564
1565 EXPECT_EQ(tester.key_calls.size(), 1);
1566 EXPECT_CALL_IS_EVENT(tester.key_calls[0], kFlutterKeyEventTypeUp,
1567 kPhysicalDigit6, kLogicalDigit6, "", kNotSynthesized);
1568 tester.clear_key_calls();
1569 EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 1);
1570
1571 // Release ShiftLeft
1572 tester.InjectKeyboardChanges(std::vector<KeyboardChange>{
1573 KeyStateChange{VK_LSHIFT, false, true},
1574 WmKeyUpInfo{VK_SHIFT, kScanCodeShiftLeft, kNotExtended}.Build(
1575 kWmResultZero)});
1576
1577 EXPECT_EQ(tester.key_calls.size(), 1);
1578 EXPECT_CALL_IS_EVENT(tester.key_calls[0], kFlutterKeyEventTypeUp,
1579 kPhysicalShiftLeft, kLogicalShiftLeft, "",
1580 kNotSynthesized);
1581 tester.clear_key_calls();
1582 EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 1);
1583
1584 // Press E
1585 tester.InjectKeyboardChanges(std::vector<KeyboardChange>{
1586 WmKeyDownInfo{kVirtualKeyE, kScanCodeKeyE, kNotExtended, kWasUp}.Build(
1587 kWmResultZero),
1588 WmCharInfo{0xEA, kScanCodeKeyE, kNotExtended, kWasUp}.Build(
1589 kWmResultZero)});
1590
1591 EXPECT_EQ(tester.key_calls.size(), 2);
1592 EXPECT_CALL_IS_EVENT(tester.key_calls[0], kFlutterKeyEventTypeDown,
1593 kPhysicalKeyE, kLogicalKeyE, "ê", kNotSynthesized);
1594 EXPECT_CALL_IS_TEXT(tester.key_calls[1], u"ê");
1595 tester.clear_key_calls();
1596 EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 2);
1597
1598 // Release E
1599 tester.InjectKeyboardChanges(std::vector<KeyboardChange>{
1600 WmKeyUpInfo{kVirtualKeyE, kScanCodeKeyE, kNotExtended}.Build(
1601 kWmResultZero)});
1602
1603 EXPECT_EQ(tester.key_calls.size(), 1);
1604 EXPECT_CALL_IS_EVENT(tester.key_calls[0], kFlutterKeyEventTypeUp,
1605 kPhysicalKeyE, kLogicalKeyE, "", kNotSynthesized);
1606 tester.clear_key_calls();
1607 EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 1);
1608 }

References EXPECT_CALL_IS_EVENT, EXPECT_CALL_IS_TEXT, and flutter::kScanCodeShiftLeft.

## ◆ TEST_F() [101/204]

flutter::testing::TEST_F | ( | KeyboardTest | ,
|  | Digit1OnFrenchLayout |
| ) |  |

Definition at line 1245 of file keyboard_unittests.cc.

1245 {
1246 KeyboardTester tester{GetContext()};
1247 tester.Responding(false);
1248
1249 tester.SetLayout(LayoutFrench);
1250
1251 // Press 1
1252 tester.InjectKeyboardChanges(std::vector<KeyboardChange>{
1253 WmKeyDownInfo{kVirtualDigit1, kScanCodeDigit1, kNotExtended, kWasUp}
1254 .Build(kWmResultZero),
1255 WmCharInfo{'&', kScanCodeDigit1, kNotExtended, kWasUp}.Build(
1256 kWmResultZero)});
1257
1258 EXPECT_EQ(tester.key_calls.size(), 2);
1259 EXPECT_CALL_IS_EVENT(tester.key_calls[0], kFlutterKeyEventTypeDown,
1260 kPhysicalDigit1, kLogicalDigit1, "&", kNotSynthesized);
1261 EXPECT_CALL_IS_TEXT(tester.key_calls[1], u"&");
1262 tester.clear_key_calls();
1263 EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 2);
1264
1265 // Release 1
1266 tester.InjectKeyboardChanges(std::vector<KeyboardChange>{
1267 WmKeyUpInfo{kVirtualDigit1, kScanCodeDigit1, kNotExtended}.Build(
1268 kWmResultZero)});
1269
1270 EXPECT_EQ(tester.key_calls.size(), 1);
1271 EXPECT_CALL_IS_EVENT(tester.key_calls[0], kFlutterKeyEventTypeUp,
1272 kPhysicalDigit1, kLogicalDigit1, "", kNotSynthesized);
1273 tester.clear_key_calls();
1274 EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 1);
1275 }

References EXPECT_CALL_IS_EVENT, and EXPECT_CALL_IS_TEXT.

## ◆ TEST_F() [102/204]

flutter::testing::TEST_F | ( | KeyboardTest | ,
|  | DoubleCapsLock |
| ) |  |

Definition at line 2504 of file keyboard_unittests.cc.

2504 {
2505 KeyboardTester tester{GetContext()};
2506 tester.Responding(false);
2507
2508 tester.InjectKeyboardChanges(std::vector<KeyboardChange>{
2509 WmKeyDownInfo{VK_CAPITAL, 0, kNotExtended}.Build(),
2510 WmKeyUpInfo{VK_CAPITAL, 0, kNotExtended}.Build()});
2511
2512 tester.clear_key_calls();
2513 }

## ◆ TEST_F() [103/204]

flutter::testing::TEST_F | ( | KeyboardTest | ,
|  | FreshKeyDownAfterMissedUpIsDelivered |
| ) |  |

Definition at line 1036 of file keyboard_unittests.cc.

1036 {
1037 KeyboardTester tester{GetContext()};
1038 tester.Responding(true);
1039
1040 tester.InjectKeyboardChanges(std::vector<KeyboardChange>{
1041 WmKeyDownInfo{VK_RETURN, kScanCodeEnter, kNotExtended, kWasUp}.Build(
1042 kWmResultZero)});
1043
1044 tester.InjectKeyboardChanges(std::vector<KeyboardChange>{
1045 WmKeyDownInfo{VK_RETURN, kScanCodeEnter, kNotExtended, kWasUp}.Build(
1046 kWmResultZero)});
1047
1048 ASSERT_EQ(tester.key_calls.size(), 3u);
1049 EXPECT_CALL_IS_EVENT(tester.key_calls[0], kFlutterKeyEventTypeDown,
1050 kPhysicalEnter, kLogicalEnter, "", kNotSynthesized);
1051 EXPECT_CALL_IS_EVENT(tester.key_calls[1], kFlutterKeyEventTypeUp,
1052 kPhysicalEnter, kLogicalEnter, "", kSynthesized);
1053 EXPECT_CALL_IS_EVENT(tester.key_calls[2], kFlutterKeyEventTypeDown,
1054 kPhysicalEnter, kLogicalEnter, "", kNotSynthesized);
1055 tester.clear_key_calls();
1056
1057 tester.InjectKeyboardChanges(std::vector<KeyboardChange>{
1058 WmKeyUpInfo{VK_RETURN, kScanCodeEnter, kNotExtended}.Build(
1059 kWmResultZero)});
1060
1061 ASSERT_EQ(tester.key_calls.size(), 1u);
1062 EXPECT_CALL_IS_EVENT(tester.key_calls[0], kFlutterKeyEventTypeUp,
1063 kPhysicalEnter, kLogicalEnter, "", kNotSynthesized);
1064 tester.clear_key_calls();
1065 EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 0u);
1066 }

References EXPECT_CALL_IS_EVENT.

## ◆ TEST_F() [104/204]

flutter::testing::TEST_F | ( | KeyboardTest | ,
|  | ImeExtendedEventsAreIgnored |
| ) |  |

Definition at line 2030 of file keyboard_unittests.cc.

2030 {
2031 KeyboardTester tester{GetContext()};
2032 tester.Responding(false);
2033
2034 // US Keyboard layout.
2035
2036 // There should be preceding key events to make the keyboard into IME mode.
2037 // Omit them in this test since they are not relavent.
2038
2039 // Press CtrlRight in IME mode.
2040 tester.InjectKeyboardChanges(std::vector<KeyboardChange>{
2041 KeyStateChange{VK_RCONTROL, true, false},
2042 WmKeyDownInfo{VK_PROCESSKEY, kScanCodeControl, kExtended, kWasUp}.Build(
2043 kWmResultZero)});
2044
2045 EXPECT_EQ(tester.key_calls.size(), 1);
2046 EXPECT_CALL_IS_EVENT(tester.key_calls[0], kFlutterKeyEventTypeDown, 0, 0, "",
2047 kNotSynthesized);
2048 tester.clear_key_calls();
2049 EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 0);
2050 }

References EXPECT_CALL_IS_EVENT.

## ◆ TEST_F() [105/204]

flutter::testing::TEST_F | ( | KeyboardTest | ,
|  | LowerCaseAHandled |
| ) |  |

Definition at line 572 of file keyboard_unittests.cc.

572 {
573 KeyboardTester tester{GetContext()};
574 tester.Responding(true);
575
576 // US Keyboard layout
577
578 // Press A
579 tester.InjectKeyboardChanges(std::vector<KeyboardChange>{
580 WmKeyDownInfo{kVirtualKeyA, kScanCodeKeyA, kNotExtended, kWasUp}.Build(
581 kWmResultZero),
582 WmCharInfo{'a', kScanCodeKeyA, kNotExtended, kWasUp}.Build(
583 kWmResultZero)});
584
585 EXPECT_EQ(tester.key_calls.size(), 1);
586 EXPECT_CALL_IS_EVENT(tester.key_calls[0], kFlutterKeyEventTypeDown,
587 kPhysicalKeyA, kLogicalKeyA, "a", kNotSynthesized);
588 tester.clear_key_calls();
589 EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 0);
590
591 // Release A
592 tester.InjectKeyboardChanges(std::vector<KeyboardChange>{
593 WmKeyUpInfo{kVirtualKeyA, kScanCodeKeyA, kNotExtended}.Build(
594 kWmResultZero)});
595
596 EXPECT_EQ(tester.key_calls.size(), 1);
597 EXPECT_CALL_IS_EVENT(tester.key_calls[0], kFlutterKeyEventTypeUp,
598 kPhysicalKeyA, kLogicalKeyA, "", kNotSynthesized);
599 tester.clear_key_calls();
600 EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 0);
601 }

References EXPECT_CALL_IS_EVENT, kScanCodeKeyA, and kVirtualKeyA.

## ◆ TEST_F() [106/204]

flutter::testing::TEST_F | ( | KeyboardTest | ,
|  | LowerCaseAUnhandled |
| ) |  |

Definition at line 603 of file keyboard_unittests.cc.

603 {
604 KeyboardTester tester{GetContext()};
605 tester.Responding(false);
606
607 // US Keyboard layout
608
609 // Press A
610 tester.InjectKeyboardChanges(std::vector<KeyboardChange>{
611 WmKeyDownInfo{kVirtualKeyA, kScanCodeKeyA, kNotExtended, kWasUp}.Build(
612 kWmResultZero),
613 WmCharInfo{'a', kScanCodeKeyA, kNotExtended, kWasUp}.Build(
614 kWmResultZero)});
615
616 EXPECT_EQ(tester.key_calls.size(), 2);
617 EXPECT_CALL_IS_EVENT(tester.key_calls[0], kFlutterKeyEventTypeDown,
618 kPhysicalKeyA, kLogicalKeyA, "a", kNotSynthesized);
619 EXPECT_CALL_IS_TEXT(tester.key_calls[1], u"a");
620 tester.clear_key_calls();
621 EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 2);
622
623 // Release A
624 tester.InjectKeyboardChanges(std::vector<KeyboardChange>{
625 WmKeyUpInfo{kVirtualKeyA, kScanCodeKeyA, kNotExtended}.Build(
626 kWmResultZero)});
627
628 EXPECT_EQ(tester.key_calls.size(), 1);
629 EXPECT_CALL_IS_EVENT(tester.key_calls[0], kFlutterKeyEventTypeUp,
630 kPhysicalKeyA, kLogicalKeyA, "", kNotSynthesized);
631 tester.clear_key_calls();
632 EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 1);
633 }

References EXPECT_CALL_IS_EVENT, EXPECT_CALL_IS_TEXT, kScanCodeKeyA, and kVirtualKeyA.

## ◆ TEST_F() [107/204]

flutter::testing::TEST_F | ( | KeyboardTest | ,
|  | MetaLeftUnhandled |
| ) |  |

Definition at line 909 of file keyboard_unittests.cc.

909 {
910 KeyboardTester tester{GetContext()};
911 tester.Responding(false);
912
913 // US Keyboard layout
914
915 // Press MetaLeft
916 tester.InjectKeyboardChanges(std::vector<KeyboardChange>{
917 KeyStateChange{VK_LWIN, true, false},
918 WmKeyDownInfo{VK_LWIN, kScanCodeMetaLeft, kExtended, kWasUp}.Build(
919 kWmResultZero)});
920
921 EXPECT_EQ(tester.key_calls.size(), 1);
922 EXPECT_CALL_IS_EVENT(tester.key_calls[0], kFlutterKeyEventTypeDown,
923 kPhysicalMetaLeft, kLogicalMetaLeft, "",
924 kNotSynthesized);
925 tester.clear_key_calls();
926 EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 1);
927
928 // Release MetaLeft
929 tester.InjectKeyboardChanges(std::vector<KeyboardChange>{
930 KeyStateChange{VK_LWIN, false, true},
931 WmKeyUpInfo{VK_LWIN, kScanCodeMetaLeft, kExtended}.Build(kWmResultZero)});
932
933 EXPECT_EQ(tester.key_calls.size(), 1);
934 EXPECT_CALL_IS_EVENT(tester.key_calls[0], kFlutterKeyEventTypeUp,
935 kPhysicalMetaLeft, kLogicalMetaLeft, "",
936 kNotSynthesized);
937 tester.clear_key_calls();
938 EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 1);
939 }

References EXPECT_CALL_IS_EVENT.

## ◆ TEST_F() [108/204]

flutter::testing::TEST_F | ( | KeyboardTest | ,
|  | MetaRightUnhandled |
| ) |  |

Definition at line 941 of file keyboard_unittests.cc.

941 {
942 KeyboardTester tester{GetContext()};
943 tester.Responding(false);
944
945 // US Keyboard layout
946
947 // Press MetaRight
948 tester.InjectKeyboardChanges(std::vector<KeyboardChange>{
949 KeyStateChange{VK_RWIN, true, false},
950 WmKeyDownInfo{VK_RWIN, kScanCodeMetaRight, kExtended, kWasUp}.Build(
951 kWmResultZero)});
952
953 EXPECT_EQ(tester.key_calls.size(), 1);
954 EXPECT_CALL_IS_EVENT(tester.key_calls[0], kFlutterKeyEventTypeDown,
955 kPhysicalMetaRight, kLogicalMetaRight, "",
956 kNotSynthesized);
957 tester.clear_key_calls();
958 EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 1);
959
960 // Release MetaRight
961 tester.InjectKeyboardChanges(std::vector<KeyboardChange>{
962 KeyStateChange{VK_RWIN, false, true},
963 WmKeyUpInfo{VK_RWIN, kScanCodeMetaRight, kExtended}.Build(
964 kWmResultZero)});
965
966 EXPECT_EQ(tester.key_calls.size(), 1);
967 EXPECT_CALL_IS_EVENT(tester.key_calls[0], kFlutterKeyEventTypeUp,
968 kPhysicalMetaRight, kLogicalMetaRight, "",
969 kNotSynthesized);
970 tester.clear_key_calls();
971 EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 1);
972 }

References EXPECT_CALL_IS_EVENT.

## ◆ TEST_F() [109/204]

flutter::testing::TEST_F | ( | KeyboardTest | ,
|  | MultibyteCharacter |
| ) |  |

Definition at line 1765 of file keyboard_unittests.cc.

1765 {
1766 KeyboardTester tester{GetContext()};
1767 tester.Responding(false);
1768
1769 // Gothic Keyboard layout. (We need a layout that yields non-BMP characters
1770 // without IME, which is actually very rare.)
1771
1772 // Press key W of a US keyboard, which should yield character '𐍅'.
1773 tester.InjectKeyboardChanges(std::vector<KeyboardChange>{
1774 WmKeyDownInfo{kVirtualKeyW, kScanCodeKeyW, kNotExtended, kWasUp}.Build(
1775 kWmResultZero),
1776 WmCharInfo{0xd800, kScanCodeKeyW, kNotExtended, kWasUp}.Build(
1777 kWmResultZero),
1778 WmCharInfo{0xdf45, kScanCodeKeyW, kNotExtended, kWasUp}.Build(
1779 kWmResultZero)});
1780
1781 const char* st = tester.key_calls[0].key_event.character;
1782
1783 EXPECT_EQ(tester.key_calls.size(), 2);
1784 EXPECT_CALL_IS_EVENT(tester.key_calls[0], kFlutterKeyEventTypeDown,
1785 kPhysicalKeyW, kLogicalKeyW, "𐍅", kNotSynthesized);
1786 EXPECT_CALL_IS_TEXT(tester.key_calls[1], u"𐍅");
1787 tester.clear_key_calls();
1788 EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 3);
1789
1790 // Release W
1791 tester.InjectKeyboardChanges(std::vector<KeyboardChange>{
1792 WmKeyUpInfo{kVirtualKeyW, kScanCodeKeyW, kNotExtended}.Build(
1793 kWmResultZero)});
1794
1795 EXPECT_EQ(tester.key_calls.size(), 1);
1796 EXPECT_CALL_IS_EVENT(tester.key_calls[0], kFlutterKeyEventTypeUp,
1797 kPhysicalKeyW, kLogicalKeyW, "", kNotSynthesized);
1798 tester.clear_key_calls();
1799 EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 1);
1800 }

References EXPECT_CALL_IS_EVENT, and EXPECT_CALL_IS_TEXT.

## ◆ TEST_F() [110/204]

flutter::testing::TEST_F | ( | KeyboardTest | ,
|  | RepeatA |
| ) |  |

Definition at line 975 of file keyboard_unittests.cc.

975 {
976 KeyboardTester tester{GetContext()};
977 tester.Responding(true);
978
979 // Press A
980 tester.InjectKeyboardChanges(std::vector<KeyboardChange>{
981 WmKeyDownInfo{kVirtualKeyA, kScanCodeKeyA, kNotExtended, kWasUp}.Build(
982 kWmResultZero),
983 WmCharInfo{'a', kScanCodeKeyA, kNotExtended, kWasUp}.Build(
984 kWmResultZero)});
985
986 // Hold A
987 tester.InjectKeyboardChanges(std::vector<KeyboardChange>{
988 WmKeyDownInfo{kVirtualKeyA, kScanCodeKeyA, kNotExtended, kWasDown}.Build(
989 kWmResultZero),
990 WmCharInfo{'a', kScanCodeKeyA, kNotExtended, kWasDown}.Build(
991 kWmResultZero)});
992
993 EXPECT_EQ(tester.key_calls.size(), 2);
994 EXPECT_CALL_IS_EVENT(tester.key_calls[0], kFlutterKeyEventTypeDown,
995 kPhysicalKeyA, kLogicalKeyA, "a", kNotSynthesized);
996 EXPECT_CALL_IS_EVENT(tester.key_calls[1], kFlutterKeyEventTypeRepeat,
997 kPhysicalKeyA, kLogicalKeyA, "a", kNotSynthesized);
998 EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 0);
999 }

References EXPECT_CALL_IS_EVENT, kScanCodeKeyA, and kVirtualKeyA.

## ◆ TEST_F() [111/204]

flutter::testing::TEST_F | ( | KeyboardTest | ,
|  | RestartClearsKeyboardState |
| ) |  |

Definition at line 1004 of file keyboard_unittests.cc.

1004 {
1005 KeyboardTester tester{GetContext()};
1006 tester.Responding(true);
1007
1008 // Press A
1009 tester.InjectKeyboardChanges(std::vector<KeyboardChange>{
1010 WmKeyDownInfo{kVirtualKeyA, kScanCodeKeyA, kNotExtended, kWasUp}.Build(
1011 kWmResultZero),
1012 WmCharInfo{'a', kScanCodeKeyA, kNotExtended, kWasUp}.Build(
1013 kWmResultZero)});
1014
1015 // Reset the keyboard's state.
1016 tester.ResetKeyboard();
1017
1018 // Hold A. Notice the message declares the key is already down, however, the
1019 // the keyboard does not send a repeat event as its state was reset.
1020 tester.InjectKeyboardChanges(std::vector<KeyboardChange>{
1021 WmKeyDownInfo{kVirtualKeyA, kScanCodeKeyA, kNotExtended, kWasDown}.Build(
1022 kWmResultZero),
1023 WmCharInfo{'a', kScanCodeKeyA, kNotExtended, kWasDown}.Build(
1024 kWmResultZero)});
1025
1026 EXPECT_EQ(tester.key_calls.size(), 2);
1027 EXPECT_CALL_IS_EVENT(tester.key_calls[0], kFlutterKeyEventTypeDown,
1028 kPhysicalKeyA, kLogicalKeyA, "a", kNotSynthesized);
1029 EXPECT_CALL_IS_EVENT(tester.key_calls[1], kFlutterKeyEventTypeDown,
1030 kPhysicalKeyA, kLogicalKeyA, "a", kNotSynthesized);
1031 EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 0);
1032 }

References EXPECT_CALL_IS_EVENT, kScanCodeKeyA, and kVirtualKeyA.

## ◆ TEST_F() [112/204]

flutter::testing::TEST_F | ( | KeyboardTest | ,
|  | ShiftLeftKeyA |
| ) |  |

Definition at line 1070 of file keyboard_unittests.cc.

1070 {
1071 KeyboardTester tester{GetContext()};
1072 tester.Responding(false);
1073
1074 // US Keyboard layout
1075
1076 // Press ShiftLeft
1077 tester.InjectKeyboardChanges(std::vector<KeyboardChange>{
1078 KeyStateChange{VK_LSHIFT, true, true},
1079 WmKeyDownInfo{VK_SHIFT, kScanCodeShiftLeft, kNotExtended, kWasUp}.Build(
1080 kWmResultZero)});
1081
1082 EXPECT_EQ(tester.key_calls.size(), 1);
1083 EXPECT_CALL_IS_EVENT(tester.key_calls[0], kFlutterKeyEventTypeDown,
1084 kPhysicalShiftLeft, kLogicalShiftLeft, "",
1085 kNotSynthesized);
1086 tester.clear_key_calls();
1087 EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 1);
1088
1089 // Press A
1090 tester.InjectKeyboardChanges(std::vector<KeyboardChange>{
1091 WmKeyDownInfo{kVirtualKeyA, kScanCodeKeyA, kNotExtended, kWasUp}.Build(
1092 kWmResultZero),
1093 WmCharInfo{'A', kScanCodeKeyA, kNotExtended, kWasUp}.Build(
1094 kWmResultZero)});
1095
1096 EXPECT_EQ(tester.key_calls.size(), 2);
1097 EXPECT_CALL_IS_EVENT(tester.key_calls[0], kFlutterKeyEventTypeDown,
1098 kPhysicalKeyA, kLogicalKeyA, "A", kNotSynthesized);
1099 EXPECT_CALL_IS_TEXT(tester.key_calls[1], u"A");
1100 tester.clear_key_calls();
1101 EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 2);
1102
1103 // Release ShiftLeft
1104 tester.InjectKeyboardChanges(std::vector<KeyboardChange>{
1105 KeyStateChange{VK_LSHIFT, false, true},
1106 WmKeyUpInfo{VK_SHIFT, kScanCodeShiftLeft, kNotExtended}.Build(
1107 kWmResultZero)});
1108
1109 EXPECT_EQ(tester.key_calls.size(), 1);
1110 EXPECT_CALL_IS_EVENT(tester.key_calls[0], kFlutterKeyEventTypeUp,
1111 kPhysicalShiftLeft, kLogicalShiftLeft, "",
1112 kNotSynthesized);
1113 tester.clear_key_calls();
1114 EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 1);
1115
1116 // Release A
1117 tester.InjectKeyboardChanges(std::vector<KeyboardChange>{
1118 WmKeyUpInfo{kVirtualKeyA, kScanCodeKeyA, kNotExtended}.Build(
1119 kWmResultZero)});
1120
1121 EXPECT_EQ(tester.key_calls.size(), 1);
1122 EXPECT_CALL_IS_EVENT(tester.key_calls[0], kFlutterKeyEventTypeUp,
1123 kPhysicalKeyA, kLogicalKeyA, "", kNotSynthesized);
1124 tester.clear_key_calls();
1125 EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 1);
1126 }

References EXPECT_CALL_IS_EVENT, EXPECT_CALL_IS_TEXT, kScanCodeKeyA, flutter::kScanCodeShiftLeft, and kVirtualKeyA.

## ◆ TEST_F() [113/204]

flutter::testing::TEST_F | ( | KeyboardTest | ,
|  | ShiftLeftUnhandled |
| ) |  |

Definition at line 697 of file keyboard_unittests.cc.

697 {
698 KeyboardTester tester{GetContext()};
699 tester.Responding(false);
700
701 // US Keyboard layout
702
703 // Press ShiftLeft
704 tester.InjectKeyboardChanges(std::vector<KeyboardChange>{
705 KeyStateChange{VK_LSHIFT, true, false},
706 WmKeyDownInfo{VK_SHIFT, kScanCodeShiftLeft, kNotExtended, kWasUp}.Build(
707 kWmResultZero)});
708
709 EXPECT_EQ(tester.key_calls.size(), 1);
710 EXPECT_CALL_IS_EVENT(tester.key_calls[0], kFlutterKeyEventTypeDown,
711 kPhysicalShiftLeft, kLogicalShiftLeft, "",
712 kNotSynthesized);
713 tester.clear_key_calls();
714 EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 1);
715
716 // Hold ShiftLeft
717 tester.InjectKeyboardChanges(std::vector<KeyboardChange>{
718 WmKeyDownInfo{VK_SHIFT, kScanCodeShiftLeft, kNotExtended, kWasDown}.Build(
719 kWmResultZero)});
720
721 EXPECT_EQ(tester.key_calls.size(), 1);
722 EXPECT_CALL_IS_EVENT(tester.key_calls[0], kFlutterKeyEventTypeRepeat,
723 kPhysicalShiftLeft, kLogicalShiftLeft, "",
724 kNotSynthesized);
725 tester.clear_key_calls();
726 EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 1);
727
728 // Release ShiftLeft
729 tester.InjectKeyboardChanges(std::vector<KeyboardChange>{
730 KeyStateChange{VK_LSHIFT, false, true},
731 WmKeyUpInfo{VK_SHIFT, kScanCodeShiftLeft, kNotExtended}.Build(
732 kWmResultZero)});
733
734 EXPECT_EQ(tester.key_calls.size(), 1);
735 EXPECT_CALL_IS_EVENT(tester.key_calls[0], kFlutterKeyEventTypeUp,
736 kPhysicalShiftLeft, kLogicalShiftLeft, "",
737 kNotSynthesized);
738 tester.clear_key_calls();
739 EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 1);
740 }

References EXPECT_CALL_IS_EVENT, and flutter::kScanCodeShiftLeft.

## ◆ TEST_F() [114/204]

flutter::testing::TEST_F | ( | KeyboardTest | ,
|  | ShiftRightUnhandled |
| ) |  |

Definition at line 742 of file keyboard_unittests.cc.

742 {
743 KeyboardTester tester{GetContext()};
744 tester.Responding(false);
745
746 // US Keyboard layout
747
748 // Press ShiftRight
749 tester.InjectKeyboardChanges(std::vector<KeyboardChange>{
750 KeyStateChange{VK_RSHIFT, true, false},
751 WmKeyDownInfo{VK_SHIFT, kScanCodeShiftRight, kNotExtended, kWasUp}.Build(
752 kWmResultZero)});
753
754 EXPECT_EQ(tester.key_calls.size(), 1);
755 EXPECT_CALL_IS_EVENT(tester.key_calls[0], kFlutterKeyEventTypeDown,
756 kPhysicalShiftRight, kLogicalShiftRight, "",
757 kNotSynthesized);
758 tester.clear_key_calls();
759 EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 1);
760
761 // Release ShiftRight
762 tester.InjectKeyboardChanges(std::vector<KeyboardChange>{
763 KeyStateChange{VK_RSHIFT, false, true},
764 WmKeyUpInfo{VK_SHIFT, kScanCodeShiftRight, kNotExtended}.Build(
765 kWmResultZero)});
766
767 EXPECT_EQ(tester.key_calls.size(), 1);
768 EXPECT_CALL_IS_EVENT(tester.key_calls[0], kFlutterKeyEventTypeUp,
769 kPhysicalShiftRight, kLogicalShiftRight, "",
770 kNotSynthesized);
771 tester.clear_key_calls();
772 EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 1);
773 }

References EXPECT_CALL_IS_EVENT, and flutter::kScanCodeShiftRight.

## ◆ TEST_F() [115/204]

flutter::testing::TEST_F | ( | KeyboardTest | ,
|  | SlowFrameworkResponse |
| ) |  |

Definition at line 2097 of file keyboard_unittests.cc.

2097 {
2098 KeyboardTester tester{GetContext()};
2099
2100 std::vector<MockKeyResponseController::ResponseCallback> recorded_callbacks;
2101
2102 // Store callbacks to manually call them.
2103 tester.LateResponding(
2104 [&recorded_callbacks](
2105 const FlutterKeyEvent* event,
2106 MockKeyResponseController::ResponseCallback callback) {
2107 recorded_callbacks.push_back(callback);
2108 });
2109
2110 // Press A
2111 tester.InjectKeyboardChanges(std::vector<KeyboardChange>{
2112 WmKeyDownInfo{kVirtualKeyA, kScanCodeKeyA, kNotExtended, kWasUp}.Build(
2113 kWmResultZero),
2114 WmCharInfo{'a', kScanCodeKeyA, kNotExtended, kWasUp}.Build(
2115 kWmResultZero)});
2116
2117 // Hold A
2118 tester.InjectKeyboardChanges(std::vector<KeyboardChange>{
2119 WmKeyDownInfo{kVirtualKeyA, kScanCodeKeyA, kNotExtended, kWasDown}.Build(
2120 kWmResultZero),
2121 WmCharInfo{'a', kScanCodeKeyA, kNotExtended, kWasDown}.Build(
2122 kWmResultZero)});
2123
2124 EXPECT_EQ(tester.key_calls.size(), 1);
2125 EXPECT_CALL_IS_EVENT(tester.key_calls[0], kFlutterKeyEventTypeDown,
2126 kPhysicalKeyA, kLogicalKeyA, "a", kNotSynthesized);
2127 EXPECT_EQ(recorded_callbacks.size(), 1);
2128 EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 0);
2129
2130 // The first response.
2131 recorded_callbacks.front()(false);
2132
2133 EXPECT_EQ(tester.key_calls.size(), 3);
2134 EXPECT_EQ(recorded_callbacks.size(), 2);
2135 EXPECT_CALL_IS_TEXT(tester.key_calls[1], u"a");
2136 EXPECT_CALL_IS_EVENT(tester.key_calls[2], kFlutterKeyEventTypeRepeat,
2137 kPhysicalKeyA, kLogicalKeyA, "a", kNotSynthesized);
2138 EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 2);
2139
2140 // The second response.
2141 recorded_callbacks.back()(false);
2142
2143 EXPECT_EQ(tester.key_calls.size(), 4);
2144 EXPECT_CALL_IS_TEXT(tester.key_calls[3], u"a");
2145 tester.clear_key_calls();
2146 EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 2);
2147 }

References callback, EXPECT_CALL_IS_EVENT, EXPECT_CALL_IS_TEXT, kScanCodeKeyA, and kVirtualKeyA.

## ◆ TEST_F() [116/204]

flutter::testing::TEST_F | ( | KeyboardTest | ,
|  | SlowFrameworkResponseForIdenticalEvents |
| ) |  |

Definition at line 2160 of file keyboard_unittests.cc.

2160 {
2161 KeyboardTester tester{GetContext()};
2162 std::vector<MockKeyResponseController::ResponseCallback> recorded_callbacks;
2163
2164 // Store callbacks to manually call them.
2165 tester.LateResponding(
2166 [&recorded_callbacks](
2167 const FlutterKeyEvent* event,
2168 MockKeyResponseController::ResponseCallback callback) {
2169 recorded_callbacks.push_back(callback);
2170 });
2171
2172 // Press A
2173 tester.InjectKeyboardChanges(std::vector<KeyboardChange>{
2174 WmKeyDownInfo{kVirtualKeyA, kScanCodeKeyA, kNotExtended, kWasUp}.Build(
2175 kWmResultZero),
2176 WmCharInfo{'a', kScanCodeKeyA, kNotExtended, kWasUp}.Build(
2177 kWmResultZero)});
2178
2179 EXPECT_EQ(tester.key_calls.size(), 1);
2180 EXPECT_CALL_IS_EVENT(tester.key_calls[0], kFlutterKeyEventTypeDown,
2181 kPhysicalKeyA, kLogicalKeyA, "a", kNotSynthesized);
2182 tester.clear_key_calls();
2183 EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 0);
2184
2185 // Release A
2186 tester.InjectKeyboardChanges(std::vector<KeyboardChange>{
2187 WmKeyUpInfo{kVirtualKeyA, kScanCodeKeyA, kNotExtended}.Build(
2188 kWmResultZero)});
2189
2190 EXPECT_EQ(tester.key_calls.size(), 0);
2191 EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 0);
2192
2193 // The first down event responded with false.
2194 EXPECT_EQ(recorded_callbacks.size(), 1);
2195 recorded_callbacks.front()(false);
2196
2197 EXPECT_EQ(tester.key_calls.size(), 2);
2198 EXPECT_CALL_IS_TEXT(tester.key_calls[0], u"a");
2199 EXPECT_CALL_IS_EVENT(tester.key_calls[1], kFlutterKeyEventTypeUp,
2200 kPhysicalKeyA, kLogicalKeyA, "", kNotSynthesized);
2201 tester.clear_key_calls();
2202 EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 2);
2203
2204 // Press A again
2205 tester.InjectKeyboardChanges(std::vector<KeyboardChange>{
2206 WmKeyDownInfo{kVirtualKeyA, kScanCodeKeyA, kNotExtended, kWasUp}.Build(
2207 kWmResultZero),
2208 WmCharInfo{'a', kScanCodeKeyA, kNotExtended, kWasUp}.Build(
2209 kWmResultZero)});
2210
2211 // Nothing more was dispatched because the first up event hasn't been
2212 // responded yet.
2213 EXPECT_EQ(recorded_callbacks.size(), 2);
2214 EXPECT_EQ(tester.key_calls.size(), 0);
2215 EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 0);
2216
2217 // The first up event responded with false, which was redispatched, and caused
2218 // the down event to be dispatched.
2219 recorded_callbacks.back()(false);
2220 EXPECT_EQ(tester.key_calls.size(), 1);
2221 EXPECT_CALL_IS_EVENT(tester.key_calls[0], kFlutterKeyEventTypeDown,
2222 kPhysicalKeyA, kLogicalKeyA, "a", kNotSynthesized);
2223 tester.clear_key_calls();
2224 EXPECT_EQ(recorded_callbacks.size(), 3);
2225 EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 1);
2226
2227 // Release A again
2228 tester.InjectKeyboardChanges(std::vector<KeyboardChange>{
2229 WmKeyUpInfo{kVirtualKeyA, kScanCodeKeyA, kNotExtended}.Build(
2230 kWmResultZero)});
2231
2232 EXPECT_EQ(tester.key_calls.size(), 0);
2233 EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 0);
2234 }

References callback, EXPECT_CALL_IS_EVENT, EXPECT_CALL_IS_TEXT, kScanCodeKeyA, and kVirtualKeyA.

## ◆ TEST_F() [117/204]

flutter::testing::TEST_F | ( | KeyboardTest | ,
|  | SynthesizeModifiers |
| ) |  |

Definition at line 1802 of file keyboard_unittests.cc.

1802 {
1803 KeyboardTester tester{GetContext()};
1804 tester.Responding(false);
1805
1806 // Two dummy events used to trigger synthesization.
1807 Win32Message event1 =
1808 WmKeyDownInfo{VK_BACK, kScanCodeBackspace, kNotExtended, kWasUp}.Build(
1809 kWmResultZero);
1810 Win32Message event2 =
1811 WmKeyUpInfo{VK_BACK, kScanCodeBackspace, kNotExtended}.Build(
1812 kWmResultZero);
1813
1814 // ShiftLeft
1815 tester.InjectKeyboardChanges(std::vector<KeyboardChange>{
1816 KeyStateChange{VK_LSHIFT, true, true}, event1});
1817 EXPECT_EQ(tester.key_calls.size(), 2);
1818 EXPECT_CALL_IS_EVENT(tester.key_calls[0], kFlutterKeyEventTypeDown,
1819 kPhysicalShiftLeft, kLogicalShiftLeft, "", kSynthesized);
1820 tester.clear_key_calls();
1821 EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 1);
1822
1823 tester.InjectKeyboardChanges(std::vector<KeyboardChange>{
1824 KeyStateChange{VK_LSHIFT, false, true}, event2});
1825 EXPECT_EQ(tester.key_calls.size(), 2);
1826 EXPECT_CALL_IS_EVENT(tester.key_calls[0], kFlutterKeyEventTypeUp,
1827 kPhysicalShiftLeft, kLogicalShiftLeft, "", kSynthesized);
1828 tester.clear_key_calls();
1829 EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 1);
1830
1831 // ShiftRight
1832 tester.InjectKeyboardChanges(std::vector<KeyboardChange>{
1833 KeyStateChange{VK_RSHIFT, true, true}, event1});
1834 EXPECT_EQ(tester.key_calls.size(), 2);
1835 EXPECT_CALL_IS_EVENT(tester.key_calls[0], kFlutterKeyEventTypeDown,
1836 kPhysicalShiftRight, kLogicalShiftRight, "",
1837 kSynthesized);
1838 tester.clear_key_calls();
1839 EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 1);
1840
1841 tester.InjectKeyboardChanges(std::vector<KeyboardChange>{
1842 KeyStateChange{VK_RSHIFT, false, true}, event2});
1843 EXPECT_EQ(tester.key_calls.size(), 2);
1844 EXPECT_CALL_IS_EVENT(tester.key_calls[0], kFlutterKeyEventTypeUp,
1845 kPhysicalShiftRight, kLogicalShiftRight, "",
1846 kSynthesized);
1847 tester.clear_key_calls();
1848 EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 1);
1849
1850 // ControlLeft
1851 tester.InjectKeyboardChanges(std::vector<KeyboardChange>{
1852 KeyStateChange{VK_LCONTROL, true, true}, event1});
1853 EXPECT_EQ(tester.key_calls.size(), 2);
1854 EXPECT_CALL_IS_EVENT(tester.key_calls[0], kFlutterKeyEventTypeDown,
1855 kPhysicalControlLeft, kLogicalControlLeft, "",
1856 kSynthesized);
1857 tester.clear_key_calls();
1858 EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 1);
1859
1860 tester.InjectKeyboardChanges(std::vector<KeyboardChange>{
1861 KeyStateChange{VK_LCONTROL, false, true}, event2});
1862 EXPECT_EQ(tester.key_calls.size(), 2);
1863 EXPECT_CALL_IS_EVENT(tester.key_calls[0], kFlutterKeyEventTypeUp,
1864 kPhysicalControlLeft, kLogicalControlLeft, "",
1865 kSynthesized);
1866 tester.clear_key_calls();
1867 EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 1);
1868
1869 // ControlRight
1870 tester.InjectKeyboardChanges(std::vector<KeyboardChange>{
1871 KeyStateChange{VK_RCONTROL, true, true}, event1});
1872 EXPECT_EQ(tester.key_calls.size(), 2);
1873 EXPECT_CALL_IS_EVENT(tester.key_calls[0], kFlutterKeyEventTypeDown,
1874 kPhysicalControlRight, kLogicalControlRight, "",
1875 kSynthesized);
1876 tester.clear_key_calls();
1877 EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 1);
1878
1879 tester.InjectKeyboardChanges(std::vector<KeyboardChange>{
1880 KeyStateChange{VK_RCONTROL, false, true}, event2});
1881 EXPECT_EQ(tester.key_calls.size(), 2);
1882 EXPECT_CALL_IS_EVENT(tester.key_calls[0], kFlutterKeyEventTypeUp,
1883 kPhysicalControlRight, kLogicalControlRight, "",
1884 kSynthesized);
1885 tester.clear_key_calls();
1886 EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 1);
1887
1888 // AltLeft
1889 tester.InjectKeyboardChanges(std::vector<KeyboardChange>{
1890 KeyStateChange{VK_LMENU, true, true}, event1});
1891 EXPECT_EQ(tester.key_calls.size(), 2);
1892 EXPECT_CALL_IS_EVENT(tester.key_calls[0], kFlutterKeyEventTypeDown,
1893 kPhysicalAltLeft, kLogicalAltLeft, "", kSynthesized);
1894 tester.clear_key_calls();
1895 EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 1);
1896
1897 tester.InjectKeyboardChanges(std::vector<KeyboardChange>{
1898 KeyStateChange{VK_LMENU, false, true}, event2});
1899 EXPECT_EQ(tester.key_calls.size(), 2);
1900 EXPECT_CALL_IS_EVENT(tester.key_calls[0], kFlutterKeyEventTypeUp,
1901 kPhysicalAltLeft, kLogicalAltLeft, "", kSynthesized);
1902 tester.clear_key_calls();
1903 EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 1);
1904
1905 // AltRight
1906 tester.InjectKeyboardChanges(std::vector<KeyboardChange>{
1907 KeyStateChange{VK_RMENU, true, true}, event1});
1908 EXPECT_EQ(tester.key_calls.size(), 2);
1909 EXPECT_CALL_IS_EVENT(tester.key_calls[0], kFlutterKeyEventTypeDown,
1910 kPhysicalAltRight, kLogicalAltRight, "", kSynthesized);
1911 tester.clear_key_calls();
1912 EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 1);
1913
1914 tester.InjectKeyboardChanges(std::vector<KeyboardChange>{
1915 KeyStateChange{VK_RMENU, false, true}, event2});
1916 EXPECT_EQ(tester.key_calls.size(), 2);
1917 EXPECT_CALL_IS_EVENT(tester.key_calls[0], kFlutterKeyEventTypeUp,
1918 kPhysicalAltRight, kLogicalAltRight, "", kSynthesized);
1919 tester.clear_key_calls();
1920 EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 1);
1921
1922 // MetaLeft
1923 tester.InjectKeyboardChanges(
1924 std::vector<KeyboardChange>{KeyStateChange{VK_LWIN, true, true}, event1});
1925 EXPECT_EQ(tester.key_calls.size(), 2);
1926 EXPECT_CALL_IS_EVENT(tester.key_calls[0], kFlutterKeyEventTypeDown,
1927 kPhysicalMetaLeft, kLogicalMetaLeft, "", kSynthesized);
1928 tester.clear_key_calls();
1929 EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 1);
1930
1931 tester.InjectKeyboardChanges(std::vector<KeyboardChange>{
1932 KeyStateChange{VK_LWIN, false, true}, event2});
1933 EXPECT_EQ(tester.key_calls.size(), 2);
1934 EXPECT_CALL_IS_EVENT(tester.key_calls[0], kFlutterKeyEventTypeUp,
1935 kPhysicalMetaLeft, kLogicalMetaLeft, "", kSynthesized);
1936 tester.clear_key_calls();
1937 EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 1);
1938
1939 // MetaRight
1940 tester.InjectKeyboardChanges(
1941 std::vector<KeyboardChange>{KeyStateChange{VK_RWIN, true, true}, event1});
1942 EXPECT_EQ(tester.key_calls.size(), 2);
1943 EXPECT_CALL_IS_EVENT(tester.key_calls[0], kFlutterKeyEventTypeDown,
1944 kPhysicalMetaRight, kLogicalMetaRight, "", kSynthesized);
1945 tester.clear_key_calls();
1946 EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 1);
1947
1948 tester.InjectKeyboardChanges(std::vector<KeyboardChange>{
1949 KeyStateChange{VK_RWIN, false, true}, event2});
1950 EXPECT_EQ(tester.key_calls.size(), 2);
1951 EXPECT_CALL_IS_EVENT(tester.key_calls[0], kFlutterKeyEventTypeUp,
1952 kPhysicalMetaRight, kLogicalMetaRight, "", kSynthesized);
1953 tester.clear_key_calls();
1954 EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 1);
1955
1956 // CapsLock, phase 0 -> 2 -> 0.
1957 // (For phases, see |SynchronizeCriticalToggledStates|.)
1958 tester.InjectKeyboardChanges(std::vector<KeyboardChange>{
1959 KeyStateChange{VK_CAPITAL, false, true}, event1});
1960 EXPECT_EQ(tester.key_calls.size(), 3);
1961 EXPECT_CALL_IS_EVENT(tester.key_calls[0], kFlutterKeyEventTypeDown,
1962 kPhysicalCapsLock, kLogicalCapsLock, "", kSynthesized);
1963 EXPECT_CALL_IS_EVENT(tester.key_calls[1], kFlutterKeyEventTypeUp,
1964 kPhysicalCapsLock, kLogicalCapsLock, "", kSynthesized);
1965 tester.clear_key_calls();
1966 EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 1);
1967
1968 tester.InjectKeyboardChanges(std::vector<KeyboardChange>{
1969 KeyStateChange{VK_CAPITAL, false, false}, event2});
1970 EXPECT_EQ(tester.key_calls.size(), 3);
1971 EXPECT_CALL_IS_EVENT(tester.key_calls[0], kFlutterKeyEventTypeDown,
1972 kPhysicalCapsLock, kLogicalCapsLock, "", kSynthesized);
1973 EXPECT_CALL_IS_EVENT(tester.key_calls[1], kFlutterKeyEventTypeUp,
1974 kPhysicalCapsLock, kLogicalCapsLock, "", kSynthesized);
1975 tester.clear_key_calls();
1976 EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 1);
1977
1978 // ScrollLock, phase 0 -> 1 -> 3
1979 tester.InjectKeyboardChanges(std::vector<KeyboardChange>{
1980 KeyStateChange{VK_SCROLL, true, true}, event1});
1981 EXPECT_EQ(tester.key_calls.size(), 2);
1982 EXPECT_CALL_IS_EVENT(tester.key_calls[0], kFlutterKeyEventTypeDown,
1983 kPhysicalScrollLock, kLogicalScrollLock, "",
1984 kSynthesized);
1985 tester.clear_key_calls();
1986 EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 1);
1987
1988 tester.InjectKeyboardChanges(std::vector<KeyboardChange>{
1989 KeyStateChange{VK_SCROLL, true, false}, event2});
1990 EXPECT_EQ(tester.key_calls.size(), 3);
1991 EXPECT_CALL_IS_EVENT(tester.key_calls[0], kFlutterKeyEventTypeUp,
1992 kPhysicalScrollLock, kLogicalScrollLock, "",
1993 kSynthesized);
1994 EXPECT_CALL_IS_EVENT(tester.key_calls[1], kFlutterKeyEventTypeDown,
1995 kPhysicalScrollLock, kLogicalScrollLock, "",
1996 kSynthesized);
1997 tester.clear_key_calls();
1998 EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 1);
1999
2000 // NumLock, phase 0 -> 3 -> 2
2001 tester.InjectKeyboardChanges(std::vector<KeyboardChange>{
2002 KeyStateChange{VK_NUMLOCK, true, false}, event1});
2003 // TODO(dkwingsmt): Synthesizing from phase 0 to 3 should yield a full key
2004 // tap and a key down. Fix the algorithm so that the following result becomes
2005 // 4 keycalls with an extra pair of key down and up.
2006 // https://github.com/flutter/flutter/issues/98533
2007 EXPECT_EQ(tester.key_calls.size(), 2);
2008 EXPECT_CALL_IS_EVENT(tester.key_calls[0], kFlutterKeyEventTypeDown,
2009 kPhysicalNumLock, kLogicalNumLock, "", kSynthesized);
2010 tester.clear_key_calls();
2011 EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 1);
2012
2013 tester.InjectKeyboardChanges(std::vector<KeyboardChange>{
2014 KeyStateChange{VK_NUMLOCK, false, true}, event2});
2015 EXPECT_EQ(tester.key_calls.size(), 4);
2016 EXPECT_CALL_IS_EVENT(tester.key_calls[0], kFlutterKeyEventTypeUp,
2017 kPhysicalNumLock, kLogicalNumLock, "", kSynthesized);
2018 EXPECT_CALL_IS_EVENT(tester.key_calls[1], kFlutterKeyEventTypeDown,
2019 kPhysicalNumLock, kLogicalNumLock, "", kSynthesized);
2020 EXPECT_CALL_IS_EVENT(tester.key_calls[2], kFlutterKeyEventTypeUp,
2021 kPhysicalNumLock, kLogicalNumLock, "", kSynthesized);
2022 tester.clear_key_calls();
2023 EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 1);
2024 }

References EXPECT_CALL_IS_EVENT.

## ◆ TEST_F() [118/204]

flutter::testing::TEST_F | ( | KeyboardTest | ,
|  | TextInputSubmit |
| ) |  |

Definition at line 2236 of file keyboard_unittests.cc.

2236 {
2237 KeyboardTester tester{GetContext()};
2238 tester.Responding(false);
2239
2240 // US Keyboard layout
2241
2242 tester.InjectPlatformMessage(
2243 "flutter/textinput", "TextInput.setClient",
2244 R"|([108, {"inputAction": "TextInputAction.none", "viewId": 0}])|");
2245
2246 // Press Enter
2247 tester.InjectKeyboardChanges(std::vector<KeyboardChange>{
2248 WmKeyDownInfo{VK_RETURN, kScanCodeEnter, kNotExtended, kWasUp}.Build(
2249 kWmResultZero),
2250 WmCharInfo{'\n', kScanCodeEnter, kNotExtended, kWasUp}.Build(
2251 kWmResultZero)});
2252
2253 EXPECT_EQ(tester.key_calls.size(), 2);
2254 EXPECT_CALL_IS_EVENT(tester.key_calls[0], kFlutterKeyEventTypeDown,
2255 kPhysicalEnter, kLogicalEnter, "", kNotSynthesized);
2256 EXPECT_CALL_IS_TEXT_METHOD_CALL(
2257 tester.key_calls[1],
2258 "{"
2259 R"|("method":"TextInputClient.performAction",)|"
2260 R"|("args":[108,"TextInputAction.none"])|"
2261 "}");
2262 tester.clear_key_calls();
2263 EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 2);
2264
2265 // Release Enter
2266 tester.InjectKeyboardChanges(std::vector<KeyboardChange>{
2267 WmKeyUpInfo{VK_RETURN, kScanCodeEnter, kNotExtended}.Build(
2268 kWmResultZero)});
2269
2270 EXPECT_EQ(tester.key_calls.size(), 1);
2271 EXPECT_CALL_IS_EVENT(tester.key_calls[0], kFlutterKeyEventTypeUp,
2272 kPhysicalEnter, kLogicalEnter, "", kNotSynthesized);
2273 tester.clear_key_calls();
2274 EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 1);
2275
2276 // Make sure OnText is not obstructed after pressing Enter.
2277 //
2278 // Regression test for https://github.com/flutter/flutter/issues/97706.
2279
2280 // Press A
2281 tester.InjectKeyboardChanges(std::vector<KeyboardChange>{
2282 WmKeyDownInfo{kVirtualKeyA, kScanCodeKeyA, kNotExtended, kWasUp}.Build(
2283 kWmResultZero),
2284 WmCharInfo{'a', kScanCodeKeyA, kNotExtended, kWasUp}.Build(
2285 kWmResultZero)});
2286
2287 EXPECT_EQ(tester.key_calls.size(), 2);
2288 EXPECT_CALL_IS_EVENT(tester.key_calls[0], kFlutterKeyEventTypeDown,
2289 kPhysicalKeyA, kLogicalKeyA, "a", kNotSynthesized);
2290 EXPECT_CALL_IS_TEXT(tester.key_calls[1], u"a");
2291 tester.clear_key_calls();
2292
2293 // Release A
2294 tester.InjectKeyboardChanges(std::vector<KeyboardChange>{
2295 WmKeyUpInfo{kVirtualKeyA, kScanCodeKeyA, kNotExtended}.Build(
2296 kWmResultZero)});
2297
2298 EXPECT_EQ(tester.key_calls.size(), 1);
2299 EXPECT_CALL_IS_EVENT(tester.key_calls[0], kFlutterKeyEventTypeUp,
2300 kPhysicalKeyA, kLogicalKeyA, "", kNotSynthesized);
2301 tester.clear_key_calls();
2302 }
EXPECT_CALL_IS_TEXT_METHOD_CALL
#define EXPECT_CALL_IS_TEXT_METHOD_CALL(_key_call, json_string)
Definition: keyboard_unittests.cc:568

References EXPECT_CALL_IS_EVENT, EXPECT_CALL_IS_TEXT, EXPECT_CALL_IS_TEXT_METHOD_CALL, kScanCodeKeyA, and kVirtualKeyA.

## ◆ TEST_F() [119/204]

flutter::testing::TEST_F | ( | KeyboardTest | ,
|  | UpOnlyImeEventsAreCorrectlyHandled |
| ) |  |

Definition at line 2058 of file keyboard_unittests.cc.

2058 {
2059 KeyboardTester tester{GetContext()};
2060 tester.Responding(true);
2061
2062 // US Keyboard layout.
2063
2064 // Press CtrlRight in IME mode.
2065 tester.InjectKeyboardChanges(std::vector<KeyboardChange>{
2066 KeyStateChange{VK_LSHIFT, true, false},
2067 WmKeyDownInfo{VK_SHIFT, kScanCodeShiftLeft, kNotExtended, kWasUp}.Build(
2068 kWmResultZero),
2069 WmKeyDownInfo{VK_PROCESSKEY, kScanCodeDigit2, kNotExtended, kWasUp}.Build(
2070 kWmResultZero),
2071 KeyStateChange{VK_LSHIFT, false, true},
2072 WmKeyUpInfo{VK_PROCESSKEY, kScanCodeShiftLeft, kNotExtended}.Build(
2073 kWmResultZero),
2074 WmKeyUpInfo{'2', kScanCodeDigit2, kNotExtended, kWasUp}.Build(
2075 kWmResultZero)});
2076
2077 EXPECT_EQ(tester.key_calls.size(), 4);
2078 EXPECT_CALL_IS_EVENT(tester.key_calls[0], kFlutterKeyEventTypeDown,
2079 kPhysicalShiftLeft, kLogicalShiftLeft, "",
2080 kNotSynthesized);
2081 EXPECT_CALL_IS_EVENT(tester.key_calls[1], kFlutterKeyEventTypeDown, 0, 0, "",
2082 kNotSynthesized);
2083 EXPECT_CALL_IS_EVENT(tester.key_calls[2], kFlutterKeyEventTypeUp,
2084 kPhysicalShiftLeft, kLogicalShiftLeft, "",
2085 kNotSynthesized);
2086 EXPECT_CALL_IS_EVENT(tester.key_calls[3], kFlutterKeyEventTypeDown, 0, 0, "",
2087 kNotSynthesized);
2088 tester.clear_key_calls();
2089 }

References EXPECT_CALL_IS_EVENT, and flutter::kScanCodeShiftLeft.

## ◆ TEST_F() [120/204]

flutter::testing::TEST_F | ( | KeyboardTest | ,
|  | VietnameseTelexAddDiacriticWithFastResponse |
| ) |  |

Definition at line 2304 of file keyboard_unittests.cc.

2304 {
2305 // In this test, the user presses the folloing keys:
2306 //
2307 // Key Current text
2308 // ===========================
2309 // A a
2310 // F à
2311 //
2312 // And the Backspace event is responded immediately.
2313
2314 KeyboardTester tester{GetContext()};
2315 tester.Responding(false);
2316
2317 // US Keyboard layout
2318
2319 // Press A
2320 tester.InjectKeyboardChanges(std::vector<KeyboardChange>{
2321 WmKeyDownInfo{kVirtualKeyA, kScanCodeKeyA, kNotExtended, kWasUp}.Build(
2322 kWmResultZero),
2323 WmCharInfo{'a', kScanCodeKeyA, kNotExtended, kWasUp}.Build(
2324 kWmResultZero)});
2325
2326 EXPECT_EQ(tester.key_calls.size(), 2);
2327 EXPECT_CALL_IS_EVENT(tester.key_calls[0], kFlutterKeyEventTypeDown,
2328 kPhysicalKeyA, kLogicalKeyA, "a", kNotSynthesized);
2329 EXPECT_CALL_IS_TEXT(tester.key_calls[1], u"a");
2330 tester.clear_key_calls();
2331 EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 2);
2332
2333 // Release A
2334 tester.InjectKeyboardChanges(std::vector<KeyboardChange>{
2335 WmKeyUpInfo{kVirtualKeyA, kScanCodeKeyA, kNotExtended}.Build(
2336 kWmResultZero)});
2337
2338 EXPECT_EQ(tester.key_calls.size(), 1);
2339 EXPECT_CALL_IS_EVENT(tester.key_calls[0], kFlutterKeyEventTypeUp,
2340 kPhysicalKeyA, kLogicalKeyA, "", kNotSynthesized);
2341 tester.clear_key_calls();
2342 EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 1);
2343
2344 // Press F, which is translated to:
2345 //
2346 // Backspace down, char & up, then VK_PACKET('à').
2347 tester.InjectKeyboardChanges(std::vector<KeyboardChange>{
2348 WmKeyDownInfo{VK_BACK, kScanCodeBackspace, kNotExtended, kWasUp}.Build(
2349 kWmResultZero),
2350 WmCharInfo{0x8, kScanCodeBackspace, kNotExtended, kWasUp}.Build(
2351 kWmResultZero),
2352 WmKeyUpInfo{VK_BACK, kScanCodeBackspace, kNotExtended}.Build(
2353 kWmResultZero),
2354 WmKeyDownInfo{VK_PACKET, 0, kNotExtended, kWasUp}.Build(kWmResultDefault),
2355 WmCharInfo{0xe0 /*'à'*/, 0, kNotExtended, kWasUp}.Build(kWmResultZero),
2356 WmKeyUpInfo{VK_PACKET, 0, kNotExtended}.Build(kWmResultDefault)});
2357
2358 EXPECT_EQ(tester.key_calls.size(), 3);
2359 EXPECT_CALL_IS_EVENT(tester.key_calls[0], kFlutterKeyEventTypeDown,
2360 kPhysicalBackspace, kLogicalBackspace, "",
2361 kNotSynthesized);
2362 EXPECT_CALL_IS_EVENT(tester.key_calls[1], kFlutterKeyEventTypeUp,
2363 kPhysicalBackspace, kLogicalBackspace, "",
2364 kNotSynthesized);
2365 EXPECT_CALL_IS_TEXT(tester.key_calls[2], u"à");
2366 tester.clear_key_calls();
2367 // TODO(dkwingsmt): This count should probably be 4. Currently the CHAR 0x8
2368 // message is redispatched due to being part of the KeyDown session, which is
2369 // not handled by the framework, while the 'à' message is not redispatched
2370 // for being a standalone message. We should resolve this inconsistency.
2371 // https://github.com/flutter/flutter/issues/98306
2372 EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 3);
2373
2374 // Release F
2375 tester.InjectKeyboardChanges(std::vector<KeyboardChange>{
2376 WmKeyUpInfo{kVirtualKeyF, kScanCodeKeyF, kNotExtended,
2377 /* overwrite_prev_state_0 */ true}
2378 .Build(kWmResultZero)});
2379
2380 EXPECT_EQ(tester.key_calls.size(), 1);
2381 EXPECT_CALL_IS_EVENT(tester.key_calls[0], kFlutterKeyEventTypeDown, 0, 0, "",
2382 kNotSynthesized);
2383 tester.clear_key_calls();
2384 EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 0);
2385 }

References EXPECT_CALL_IS_EVENT, EXPECT_CALL_IS_TEXT, kScanCodeKeyA, and kVirtualKeyA.

## ◆ TEST_F() [121/204]

flutter::testing::TEST_F | ( | KeyboardTest | ,
|  | VietnameseTelexAddDiacriticWithSlowFalseResponse |
| ) |  |

Definition at line 2494 of file keyboard_unittests.cc.

2494 {
2495 VietnameseTelexAddDiacriticWithSlowResponse(GetContext(), false);
2496 }
flutter::testing::VietnameseTelexAddDiacriticWithSlowResponse
void VietnameseTelexAddDiacriticWithSlowResponse(WindowsTestContext &context, bool backspace_response)
Definition: keyboard_unittests.cc:2387

References VietnameseTelexAddDiacriticWithSlowResponse().

## ◆ TEST_F() [122/204]

flutter::testing::TEST_F | ( | KeyboardTest | ,
|  | VietnameseTelexAddDiacriticWithSlowTrueResponse |
| ) |  |

Definition at line 2498 of file keyboard_unittests.cc.

2498 {
2499 VietnameseTelexAddDiacriticWithSlowResponse(GetContext(), true);
2500 }

References VietnameseTelexAddDiacriticWithSlowResponse().

## ◆ TEST_F() [123/204]

flutter::testing::TEST_F | ( | PlatformHandlerTest | ,
|  | ClipboardHasStrings |
| ) |  |

Definition at line 240 of file platform_handler_unittests.cc.

240 {
241 UseHeadlessEngine();
242
243 TestBinaryMessenger messenger;
244 PlatformHandler platform_handler(&messenger, engine(), []() {
245 auto clipboard = std::make_unique<MockScopedClipboard>();
246
247 EXPECT_CALL(*clipboard.get(), Open)
248 .Times(1)
249 .WillOnce(Return(kErrorSuccess));
250 EXPECT_CALL(*clipboard.get(), HasString).Times(1).WillOnce(Return(true));
251
252 return clipboard;
253 });
254
255 std::string result =
256 SimulatePlatformMessage(&messenger, kClipboardHasStringsMessage);
257
258 EXPECT_EQ(result, "[{\"value\":true}]");
259 }
kErrorSuccess
static constexpr int kErrorSuccess
Definition: platform_handler.cc:45

References kErrorSuccess.

## ◆ TEST_F() [124/204]

flutter::testing::TEST_F | ( | PlatformHandlerTest | ,
|  | ClipboardHasStringsIgnoresPermissionErrors |
| ) |  |

Definition at line 295 of file platform_handler_unittests.cc.

295 {
296 UseHeadlessEngine();
297
298 TestBinaryMessenger messenger;
299 PlatformHandler platform_handler(&messenger, engine(), []() {
300 auto clipboard = std::make_unique<MockScopedClipboard>();
301
302 EXPECT_CALL(*clipboard.get(), Open)
303 .Times(1)
304 .WillOnce(Return(kAccessDeniedErrorCode));
305
306 return clipboard;
307 });
308
309 std::string result =
310 SimulatePlatformMessage(&messenger, kClipboardHasStringsMessage);
311
312 EXPECT_EQ(result, "[{\"value\":false}]");
313 }
kAccessDeniedErrorCode
static constexpr int kAccessDeniedErrorCode
Definition: platform_handler.cc:44

References kAccessDeniedErrorCode.

## ◆ TEST_F() [125/204]

flutter::testing::TEST_F | ( | PlatformHandlerTest | ,
|  | ClipboardHasStringsRejectsUnknownContentType |
| ) |  |

Definition at line 282 of file platform_handler_unittests.cc.

282 {
283 UseHeadlessEngine();
284
285 TestBinaryMessenger messenger;
286 PlatformHandler platform_handler(&messenger, engine());
287
288 std::string result = SimulatePlatformMessage(
289 &messenger, kClipboardHasStringsFakeContentTypeMessage);
290
291 EXPECT_EQ(result, "[\"Clipboard error\",\"Unknown clipboard format\",null]");
292 }

## ◆ TEST_F() [126/204]

flutter::testing::TEST_F | ( | PlatformHandlerTest | ,
|  | ClipboardHasStringsReportsErrors |
| ) |  |

Definition at line 315 of file platform_handler_unittests.cc.

315 {
316 UseHeadlessEngine();
317
318 TestBinaryMessenger messenger;
319 PlatformHandler platform_handler(&messenger, engine(), []() {
320 auto clipboard = std::make_unique<MockScopedClipboard>();
321
322 EXPECT_CALL(*clipboard.get(), Open)
323 .Times(1)
324 .WillOnce(Return(kArbitraryErrorCode));
325
326 return clipboard;
327 });
328
329 std::string result =
330 SimulatePlatformMessage(&messenger, kClipboardHasStringsMessage);
331
332 EXPECT_EQ(result, "[\"Clipboard error\",\"Unable to open clipboard\",1]");
333 }

## ◆ TEST_F() [127/204]

flutter::testing::TEST_F | ( | PlatformHandlerTest | ,
|  | ClipboardHasStringsReturnsFalse |
| ) |  |

Definition at line 261 of file platform_handler_unittests.cc.

261 {
262 UseHeadlessEngine();
263
264 TestBinaryMessenger messenger;
265 PlatformHandler platform_handler(&messenger, engine(), []() {
266 auto clipboard = std::make_unique<MockScopedClipboard>();
267
268 EXPECT_CALL(*clipboard.get(), Open)
269 .Times(1)
270 .WillOnce(Return(kErrorSuccess));
271 EXPECT_CALL(*clipboard.get(), HasString).Times(1).WillOnce(Return(false));
272
273 return clipboard;
274 });
275
276 std::string result =
277 SimulatePlatformMessage(&messenger, kClipboardHasStringsMessage);
278
279 EXPECT_EQ(result, "[{\"value\":false}]");
280 }

References kErrorSuccess.

## ◆ TEST_F() [128/204]

flutter::testing::TEST_F | ( | PlatformHandlerTest | ,
|  | ClipboardSetData |
| ) |  |

Definition at line 335 of file platform_handler_unittests.cc.

335 {
336 UseHeadlessEngine();
337
338 TestBinaryMessenger messenger;
339 PlatformHandler platform_handler(&messenger, engine(), []() {
340 auto clipboard = std::make_unique<MockScopedClipboard>();
341
342 EXPECT_CALL(*clipboard.get(), Open)
343 .Times(1)
344 .WillOnce(Return(kErrorSuccess));
345 EXPECT_CALL(*clipboard.get(), SetString)
346 .Times(1)
347 .WillOnce([](std::wstring string) {
348 EXPECT_EQ(string, L"hello");
349 return kErrorSuccess;
350 });
351
352 return clipboard;
353 });
354
355 std::string result =
356 SimulatePlatformMessage(&messenger, kClipboardSetDataMessage);
357
358 EXPECT_EQ(result, "[null]");
359 }

References kErrorSuccess.

## ◆ TEST_F() [129/204]

flutter::testing::TEST_F | ( | PlatformHandlerTest | ,
|  | ClipboardSetDataReportsOpenFailure |
| ) |  |

Definition at line 386 of file platform_handler_unittests.cc.

386 {
387 UseHeadlessEngine();
388
389 TestBinaryMessenger messenger;
390 PlatformHandler platform_handler(&messenger, engine(), []() {
391 auto clipboard = std::make_unique<MockScopedClipboard>();
392
393 EXPECT_CALL(*clipboard.get(), Open)
394 .Times(1)
395 .WillOnce(Return(kArbitraryErrorCode));
396
397 return clipboard;
398 });
399
400 std::string result =
401 SimulatePlatformMessage(&messenger, kClipboardSetDataMessage);
402
403 EXPECT_EQ(result, "[\"Clipboard error\",\"Unable to open clipboard\",1]");
404 }

## ◆ TEST_F() [130/204]

flutter::testing::TEST_F | ( | PlatformHandlerTest | ,
|  | ClipboardSetDataReportsSetDataFailure |
| ) |  |

Definition at line 406 of file platform_handler_unittests.cc.

406 {
407 UseHeadlessEngine();
408
409 TestBinaryMessenger messenger;
410 PlatformHandler platform_handler(&messenger, engine(), []() {
411 auto clipboard = std::make_unique<MockScopedClipboard>();
412
413 EXPECT_CALL(*clipboard.get(), Open)
414 .Times(1)
415 .WillOnce(Return(kErrorSuccess));
416 EXPECT_CALL(*clipboard.get(), SetString)
417 .Times(1)
418 .WillOnce(Return(kArbitraryErrorCode));
419
420 return clipboard;
421 });
422
423 std::string result =
424 SimulatePlatformMessage(&messenger, kClipboardSetDataMessage);
425
426 EXPECT_EQ(result, "[\"Clipboard error\",\"Unable to set clipboard data\",1]");
427 }

References kErrorSuccess.

## ◆ TEST_F() [131/204]

flutter::testing::TEST_F | ( | PlatformHandlerTest | ,
|  | ClipboardSetDataTextMustBeString |
| ) |  |

Definition at line 362 of file platform_handler_unittests.cc.

362 {
363 UseHeadlessEngine();
364
365 TestBinaryMessenger messenger;
366 PlatformHandler platform_handler(&messenger, engine());
367
368 std::string result =
369 SimulatePlatformMessage(&messenger, kClipboardSetDataNullTextMessage);
370
371 EXPECT_EQ(result, "[\"Clipboard error\",\"Unknown clipboard format\",null]");
372 }

## ◆ TEST_F() [132/204]

flutter::testing::TEST_F | ( | PlatformHandlerTest | ,
|  | ClipboardSetDataUnknownType |
| ) |  |

Definition at line 374 of file platform_handler_unittests.cc.

374 {
375 UseHeadlessEngine();
376
377 TestBinaryMessenger messenger;
378 PlatformHandler platform_handler(&messenger, engine());
379
380 std::string result =
381 SimulatePlatformMessage(&messenger, kClipboardSetDataUnknownTypeMessage);
382
383 EXPECT_EQ(result, "[\"Clipboard error\",\"Unknown clipboard format\",null]");
384 }

## ◆ TEST_F() [133/204]

flutter::testing::TEST_F | ( | PlatformHandlerTest | ,
|  | GetClipboardData |
| ) |  |

Definition at line 159 of file platform_handler_unittests.cc.

159 {
160 UseHeadlessEngine();
161
162 TestBinaryMessenger messenger;
163 PlatformHandler platform_handler(&messenger, engine(), []() {
164 auto clipboard = std::make_unique<MockScopedClipboard>();
165
166 EXPECT_CALL(*clipboard.get(), Open)
167 .Times(1)
168 .WillOnce(Return(kErrorSuccess));
169 EXPECT_CALL(*clipboard.get(), HasString).Times(1).WillOnce(Return(true));
170 EXPECT_CALL(*clipboard.get(), GetString)
171 .Times(1)
172 .WillOnce(Return(std::wstring(L"Hello world")));
173
174 return clipboard;
175 });
176
177 std::string result =
178 SimulatePlatformMessage(&messenger, kClipboardGetDataMessage);
179
180 EXPECT_EQ(result, "[{\"text\":\"Hello world\"}]");
181 }

References kErrorSuccess.

## ◆ TEST_F() [134/204]

flutter::testing::TEST_F | ( | PlatformHandlerTest | ,
|  | GetClipboardDataRejectsUnknownContentType |
| ) |  |

Definition at line 183 of file platform_handler_unittests.cc.

183 {
184 UseHeadlessEngine();
185
186 TestBinaryMessenger messenger;
187 PlatformHandler platform_handler(&messenger, engine());
188
189 // Requesting an unknown content type is an error.
190 std::string result = SimulatePlatformMessage(
191 &messenger, kClipboardGetDataFakeContentTypeMessage);
192
193 EXPECT_EQ(result, "[\"Clipboard error\",\"Unknown clipboard format\",null]");
194 }

## ◆ TEST_F() [135/204]

flutter::testing::TEST_F | ( | PlatformHandlerTest | ,
|  | GetClipboardDataReportsGetDataFailure |
| ) |  |

Definition at line 216 of file platform_handler_unittests.cc.

216 {
217 UseHeadlessEngine();
218
219 TestBinaryMessenger messenger;
220 PlatformHandler platform_handler(&messenger, engine(), []() {
221 auto clipboard = std::make_unique<MockScopedClipboard>();
222
223 EXPECT_CALL(*clipboard.get(), Open)
224 .Times(1)
225 .WillOnce(Return(kErrorSuccess));
226 EXPECT_CALL(*clipboard.get(), HasString).Times(1).WillOnce(Return(true));
227 EXPECT_CALL(*clipboard.get(), GetString)
228 .Times(1)
229 .WillOnce(Return(kArbitraryErrorCode));
230
231 return clipboard;
232 });
233
234 std::string result =
235 SimulatePlatformMessage(&messenger, kClipboardGetDataMessage);
236
237 EXPECT_EQ(result, "[\"Clipboard error\",\"Unable to get clipboard data\",1]");
238 }

References kErrorSuccess.

## ◆ TEST_F() [136/204]

flutter::testing::TEST_F | ( | PlatformHandlerTest | ,
|  | GetClipboardDataReportsOpenFailure |
| ) |  |

Definition at line 196 of file platform_handler_unittests.cc.

196 {
197 UseHeadlessEngine();
198
199 TestBinaryMessenger messenger;
200 PlatformHandler platform_handler(&messenger, engine(), []() {
201 auto clipboard = std::make_unique<MockScopedClipboard>();
202
203 EXPECT_CALL(*clipboard.get(), Open)
204 .Times(1)
205 .WillOnce(Return(kArbitraryErrorCode));
206
207 return clipboard;
208 });
209
210 std::string result =
211 SimulatePlatformMessage(&messenger, kClipboardGetDataMessage);
212
213 EXPECT_EQ(result, "[\"Clipboard error\",\"Unable to open clipboard\",1]");
214 }

## ◆ TEST_F() [137/204]

flutter::testing::TEST_F | ( | PlatformHandlerTest | ,
|  | PlaySystemSound |
| ) |  |

Definition at line 429 of file platform_handler_unittests.cc.

429 {
430 UseHeadlessEngine();
431
432 TestBinaryMessenger messenger;
433 MockPlatformHandler platform_handler(&messenger, engine());
434
435 EXPECT_CALL(platform_handler, SystemSoundPlay("SystemSoundType.alert", _))
436 .WillOnce([](const std::string& sound,
437 std::unique_ptr<MethodResult<rapidjson::Document>> result) {
438 result->Success();
439 });
440
441 std::string result =
442 SimulatePlatformMessage(&messenger, kSystemSoundTypeAlertMessage);
443
444 EXPECT_EQ(result, "[null]");
445 }

## ◆ TEST_F() [138/204]

flutter::testing::TEST_F | ( | PlatformHandlerTest | ,
|  | SystemExitApplicationCancelableCancel |
| ) |  |

Definition at line 469 of file platform_handler_unittests.cc.

469 {
470 UseHeadlessEngine();
471 bool called_cancel = false;
472
473 TestBinaryMessenger messenger(
474 [&called_cancel](const std::string& channel, const uint8_t* message,
475 size_t size, BinaryReply reply) {
476 reply(reinterpret_cast<const uint8_t*>(kExitResponseCancelMessage),
477 sizeof(kExitResponseCancelMessage));
478 called_cancel = true;
479 });
480 MockPlatformHandler platform_handler(&messenger, engine());
481
482 EXPECT_CALL(platform_handler, QuitApplication).Times(0);
483
484 std::string result = SimulatePlatformMessage(
485 &messenger, kSystemExitApplicationCancelableMessage);
486 EXPECT_EQ(result, "[{\"response\":\"cancel\"}]");
487 EXPECT_TRUE(called_cancel);
488 }

References message.

## ◆ TEST_F() [139/204]

flutter::testing::TEST_F | ( | PlatformHandlerTest | ,
|  | SystemExitApplicationCancelableExit |
| ) |  |

Definition at line 490 of file platform_handler_unittests.cc.

490 {
491 UseHeadlessEngine();
492 bool called_cancel = false;
493 UINT exit_code = 0;
494
495 TestBinaryMessenger messenger(
496 [&called_cancel](const std::string& channel, const uint8_t* message,
497 size_t size, BinaryReply reply) {
498 reply(reinterpret_cast<const uint8_t*>(kExitResponseExitMessage),
499 sizeof(kExitResponseExitMessage));
500 called_cancel = true;
501 });
502 MockPlatformHandler platform_handler(&messenger, engine());
503
504 ON_CALL(platform_handler, QuitApplication)
505 .WillByDefault([&exit_code](std::optional<HWND> hwnd,
506 std::optional<WPARAM> wparam,
507 std::optional<LPARAM> lparam,
508 UINT ec) { exit_code = ec; });
509 EXPECT_CALL(platform_handler, QuitApplication).Times(1);
510
511 std::string result = SimulatePlatformMessage(
512 &messenger, kSystemExitApplicationCancelableMessage);
513 EXPECT_EQ(result, "[{\"response\":\"cancel\"}]");
514 EXPECT_TRUE(called_cancel);
515 EXPECT_EQ(exit_code, 2);
516 }

References message.

## ◆ TEST_F() [140/204]

flutter::testing::TEST_F | ( | PlatformHandlerTest | ,
|  | SystemExitApplicationRequired |
| ) |  |

Definition at line 447 of file platform_handler_unittests.cc.

447 {
448 UseHeadlessEngine();
449 UINT exit_code = 0;
450
451 TestBinaryMessenger messenger([](const std::string& channel,
452 const uint8_t* message, size_t size,
453 BinaryReply reply) {});
454 MockPlatformHandler platform_handler(&messenger, engine());
455
456 ON_CALL(platform_handler, QuitApplication)
457 .WillByDefault([&exit_code](std::optional<HWND> hwnd,
458 std::optional<WPARAM> wparam,
459 std::optional<LPARAM> lparam,
460 UINT ec) { exit_code = ec; });
461 EXPECT_CALL(platform_handler, QuitApplication).Times(1);
462
463 std::string result = SimulatePlatformMessage(
464 &messenger, kSystemExitApplicationRequiredMessage);
465 EXPECT_EQ(result, "[{\"response\":\"exit\"}]");
466 EXPECT_EQ(exit_code, 1);
467 }

References message.

## ◆ TEST_F() [141/204]

flutter::testing::TEST_F | ( | TextInputPluginTest | ,
|  | ClearClientRequiresView |
| ) |  |

Definition at line 244 of file text_input_plugin_unittest.cc.

244 {
245 UseHeadlessEngine();
246
247 TestBinaryMessenger messenger([](const std::string& channel,
248 const uint8_t* message, size_t message_size,
249 BinaryReply reply) {});
250
251 std::string reply;
252 BinaryReply reply_handler = [&reply](const uint8_t* reply_bytes,
253 size_t reply_size) {
254 reply = std::string(reinterpret_cast<const char*>(reply_bytes), reply_size);
255 };
256
257 TextInputPlugin handler(&messenger, engine());
258
259 auto& codec = JsonMethodCodec::GetInstance();
260 auto message = codec.EncodeMethodCall({"TextInput.clearClient", nullptr});
261 messenger.SimulateEngineMessage(kChannelName, message->data(),
262 message->size(), reply_handler);
263
264 EXPECT_EQ(
265 reply,
266 "[\"Internal Consistency Error\",\"Text input is not available because "
267 "view with view_id=0 cannot be found\",null]");
268 }
kChannelName
static constexpr char kChannelName[]
Definition: cursor_handler.cc:12

References flutter::JsonMethodCodec::GetInstance(), kChannelName, and message.

## ◆ TEST_F() [142/204]

flutter::testing::TEST_F | ( | TextInputPluginTest | ,
|  | ClearClientResetsComposing |
| ) |  |

Definition at line 223 of file text_input_plugin_unittest.cc.

223 {
224 UseEngineWithView();
225
226 TestBinaryMessenger messenger([](const std::string& channel,
227 const uint8_t* message, size_t message_size,
228 BinaryReply reply) {});
229 BinaryReply reply_handler = [](const uint8_t* reply, size_t reply_size) {};
230
231 TextInputPlugin handler(&messenger, engine());
232 TextInputPluginModifier modifier(&handler);
233 modifier.SetViewId(456);
234
235 EXPECT_CALL(*view(), OnResetImeComposing());
236
237 auto& codec = JsonMethodCodec::GetInstance();
238 auto message = codec.EncodeMethodCall({"TextInput.clearClient", nullptr});
239 messenger.SimulateEngineMessage(kChannelName, message->data(),
240 message->size(), reply_handler);
241 }

References flutter::JsonMethodCodec::GetInstance(), kChannelName, message, and flutter::TextInputPluginModifier::SetViewId().

## ◆ TEST_F() [143/204]

flutter::testing::TEST_F | ( | TextInputPluginTest | ,
|  | CompositionCursorPos |
| ) |  |

Definition at line 558 of file text_input_plugin_unittest.cc.

558 {
559 UseEngineWithView();
560
561 int selection_base = -1;
562 TestBinaryMessenger messenger([&](const std::string& channel,
563 const uint8_t* message, size_t size,
564 BinaryReply reply) {
565 auto method = JsonMethodCodec::GetInstance().DecodeMethodCall(
566 std::vector<uint8_t>(message, message + size));
567 if (method->method_name() == kUpdateEditingStateMethod) {
568 const auto& args = *method->arguments();
569 const auto& editing_state = args[1];
570 auto base = editing_state.FindMember(kSelectionBaseKey);
571 auto extent = editing_state.FindMember(kSelectionExtentKey);
572 ASSERT_NE(base, editing_state.MemberEnd());
573 ASSERT_TRUE(base->value.IsInt());
574 ASSERT_NE(extent, editing_state.MemberEnd());
575 ASSERT_TRUE(extent->value.IsInt());
576 selection_base = base->value.GetInt();
577 EXPECT_EQ(extent->value.GetInt(), selection_base);
578 }
579 });
580
581 TextInputPlugin plugin(&messenger, engine());
582
583 auto args = std::make_unique<rapidjson::Document>(rapidjson::kArrayType);
584 auto& allocator = args->GetAllocator();
585 args->PushBack(123, allocator); // client_id
586 rapidjson::Value client_config(rapidjson::kObjectType);
587 client_config.AddMember(kViewId, 456, allocator);
588 args->PushBack(client_config, allocator);
589 auto encoded = JsonMethodCodec::GetInstance().EncodeMethodCall(
590 MethodCall<rapidjson::Document>(kSetClientMethod, std::move(args)));
591 EXPECT_TRUE(messenger.SimulateEngineMessage(
592 kChannelName, encoded->data(), encoded->size(),
593 [](const uint8_t* reply, size_t reply_size) {}));
594
595 plugin.ComposeBeginHook();
596 EXPECT_EQ(selection_base, 0);
597 plugin.ComposeChangeHook(u"abc", 3);
598 EXPECT_EQ(selection_base, 3);
599
600 plugin.ComposeCommitHook();
601 plugin.ComposeEndHook();
602 EXPECT_EQ(selection_base, 3);
603
604 plugin.ComposeBeginHook();
605 plugin.ComposeChangeHook(u"1", 1);
606 EXPECT_EQ(selection_base, 4);
607
608 plugin.ComposeChangeHook(u"12", 2);
609 EXPECT_EQ(selection_base, 5);
610
611 plugin.ComposeChangeHook(u"12", 1);
612 EXPECT_EQ(selection_base, 4);
613
614 plugin.ComposeChangeHook(u"12", 2);
615 EXPECT_EQ(selection_base, 5);
616 }
kSelectionExtentKey
static constexpr char kSelectionExtentKey[]
Definition: text_input_plugin.cc:49
kSetClientMethod
static constexpr char kSetClientMethod[]
Definition: text_input_plugin.cc:19
kUpdateEditingStateMethod
static constexpr char kUpdateEditingStateMethod[]
Definition: text_input_plugin.cc:28
kViewId
static constexpr char kViewId[]
Definition: text_input_plugin.cc:41
kSelectionBaseKey
static constexpr char kSelectionBaseKey[]
Definition: text_input_plugin.cc:48

References flutter::MethodCodec< T >::DecodeMethodCall(), flutter::MethodCodec< T >::EncodeMethodCall(), flutter::JsonMethodCodec::GetInstance(), kChannelName, kSelectionBaseKey, kSelectionExtentKey, kSetClientMethod, kUpdateEditingStateMethod, kViewId, and message.

## ◆ TEST_F() [144/204]

flutter::testing::TEST_F | ( | TextInputPluginTest | ,
|  | SetAndUseMultipleClients |
| ) |  |

Definition at line 728 of file text_input_plugin_unittest.cc.

728 {
729 UseEngineWithView(); // Creates the default view
730 AddViewWithId(789); // Creates the next view
731
732 bool sent_message = false;
733 TestBinaryMessenger messenger(
734 [&sent_message](const std::string& channel, const uint8_t* message,
735 size_t message_size,
736 BinaryReply reply) { sent_message = true; });
737
738 TextInputPlugin handler(&messenger, engine());
739
740 auto const set_client_and_send_message = [&](int client_id, int view_id) {
741 auto args = std::make_unique<rapidjson::Document>(rapidjson::kArrayType);
742 auto& allocator = args->GetAllocator();
743 args->PushBack(client_id, allocator); // client_id
744
745 rapidjson::Value client_config(rapidjson::kObjectType);
746 client_config.AddMember(kViewId, view_id, allocator); // view_id
747
748 args->PushBack(client_config, allocator);
749 auto encoded = JsonMethodCodec::GetInstance().EncodeMethodCall(
750 MethodCall<rapidjson::Document>(kSetClientMethod, std::move(args)));
751
752 std::string reply;
753 BinaryReply reply_handler = [&reply](const uint8_t* reply_bytes,
754 size_t reply_size) {
755 reply =
756 std::string(reinterpret_cast<const char*>(reply_bytes), reply_size);
757 };
758
759 EXPECT_TRUE(messenger.SimulateEngineMessage(
760 kChannelName, encoded->data(), encoded->size(), reply_handler));
761
762 sent_message = false;
763 handler.ComposeBeginHook();
764 EXPECT_TRUE(sent_message);
765 sent_message = false;
766 handler.ComposeChangeHook(u"4", 1);
767 EXPECT_TRUE(sent_message);
768 sent_message = false;
769 handler.ComposeCommitHook();
770 EXPECT_FALSE(sent_message);
771 sent_message = false;
772 handler.ComposeEndHook();
773 EXPECT_TRUE(sent_message);
774 };
775
776 set_client_and_send_message(123, 456); // Set and send for the first view
777 set_client_and_send_message(123, 789); // Set and send for the next view
778 }

References flutter::MethodCodec< T >::EncodeMethodCall(), flutter::JsonMethodCodec::GetInstance(), kChannelName, kSetClientMethod, kViewId, and message.

## ◆ TEST_F() [145/204]

flutter::testing::TEST_F | ( | TextInputPluginTest | ,
|  | SetClientRequiresViewId |
| ) |  |

Definition at line 434 of file text_input_plugin_unittest.cc.

434 {
435 UseEngineWithView();
436
437 TestBinaryMessenger messenger([](const std::string& channel,
438 const uint8_t* message, size_t message_size,
439 BinaryReply reply) {});
440
441 TextInputPlugin handler(&messenger, engine());
442
443 auto args = std::make_unique<rapidjson::Document>(rapidjson::kArrayType);
444 auto& allocator = args->GetAllocator();
445 args->PushBack(123, allocator); // client_id
446
447 rapidjson::Value client_config(rapidjson::kObjectType);
448
449 args->PushBack(client_config, allocator);
450 auto encoded = JsonMethodCodec::GetInstance().EncodeMethodCall(
451 MethodCall<rapidjson::Document>(kSetClientMethod, std::move(args)));
452
453 std::string reply;
454 BinaryReply reply_handler = [&reply](const uint8_t* reply_bytes,
455 size_t reply_size) {
456 reply = std::string(reinterpret_cast<const char*>(reply_bytes), reply_size);
457 };
458
459 EXPECT_TRUE(messenger.SimulateEngineMessage(kChannelName, encoded->data(),
460 encoded->size(), reply_handler));
461 EXPECT_EQ(
462 reply,
463 "[\"Bad Arguments\",\"Could not set client, view ID is null.\",null]");
464 }

References flutter::MethodCodec< T >::EncodeMethodCall(), flutter::JsonMethodCodec::GetInstance(), kChannelName, kSetClientMethod, and message.

## ◆ TEST_F() [146/204]

flutter::testing::TEST_F | ( | TextInputPluginTest | ,
|  | SetClientRequiresViewIdToBeInteger |
| ) |  |

Definition at line 466 of file text_input_plugin_unittest.cc.

466 {
467 UseEngineWithView();
468
469 TestBinaryMessenger messenger([](const std::string& channel,
470 const uint8_t* message, size_t message_size,
471 BinaryReply reply) {});
472
473 TextInputPlugin handler(&messenger, engine());
474
475 auto args = std::make_unique<rapidjson::Document>(rapidjson::kArrayType);
476 auto& allocator = args->GetAllocator();
477 args->PushBack(123, allocator); // client_id
478
479 rapidjson::Value client_config(rapidjson::kObjectType);
480 client_config.AddMember(kViewId, "Not an integer", allocator); // view_id
481
482 args->PushBack(client_config, allocator);
483 auto encoded = JsonMethodCodec::GetInstance().EncodeMethodCall(
484 MethodCall<rapidjson::Document>(kSetClientMethod, std::move(args)));
485
486 std::string reply;
487 BinaryReply reply_handler = [&reply](const uint8_t* reply_bytes,
488 size_t reply_size) {
489 reply = std::string(reinterpret_cast<const char*>(reply_bytes), reply_size);
490 };
491
492 EXPECT_TRUE(messenger.SimulateEngineMessage(kChannelName, encoded->data(),
493 encoded->size(), reply_handler));
494 EXPECT_EQ(
495 reply,
496 "[\"Bad Arguments\",\"Could not set client, view ID is null.\",null]");
497 }

References flutter::MethodCodec< T >::EncodeMethodCall(), flutter::JsonMethodCodec::GetInstance(), kChannelName, kSetClientMethod, kViewId, and message.

## ◆ TEST_F() [147/204]

flutter::testing::TEST_F | ( | TextInputPluginTest | ,
|  | SetMarkedTextRectRequiresView |
| ) |  |

Definition at line 691 of file text_input_plugin_unittest.cc.

691 {
692 UseHeadlessEngine();
693
694 TestBinaryMessenger messenger([](const std::string& channel,
695 const uint8_t* message, size_t message_size,
696 BinaryReply reply) {});
697
698 std::string reply;
699 BinaryReply reply_handler = [&reply](const uint8_t* reply_bytes,
700 size_t reply_size) {
701 reply = std::string(reinterpret_cast<const char*>(reply_bytes), reply_size);
702 };
703
704 TextInputPlugin handler(&messenger, engine());
705
706 auto& codec = JsonMethodCodec::GetInstance();
707
708 auto arguments =
709 std::make_unique<rapidjson::Document>(rapidjson::kObjectType);
710 auto& allocator = arguments->GetAllocator();
711
712 arguments->AddMember("x", 0, allocator);
713 arguments->AddMember("y", 0, allocator);
714 arguments->AddMember("width", 0, allocator);
715 arguments->AddMember("height", 0, allocator);
716
717 auto message = codec.EncodeMethodCall(
718 {"TextInput.setMarkedTextRect", std::move(arguments)});
719 messenger.SimulateEngineMessage(kChannelName, message->data(),
720 message->size(), reply_handler);
721
722 EXPECT_EQ(
723 reply,
724 "[\"Internal Consistency Error\",\"Text input is not available because "
725 "view with view_id=0 cannot be found\",null]");
726 }

References flutter::JsonMethodCodec::GetInstance(), kChannelName, and message.

## ◆ TEST_F() [148/204]

flutter::testing::TEST_F | ( | TextInputPluginTest | ,
|  | TextEditingWorksWithDeltaModel |
| ) |  |

Definition at line 499 of file text_input_plugin_unittest.cc.

499 {
500 UseEngineWithView();
501
502 auto handled_message = CreateResponse(true);
503 auto unhandled_message = CreateResponse(false);
504 int received_scancode = 0;
505
506 TestBinaryMessenger messenger(
507 [&received_scancode, &handled_message, &unhandled_message](
508 const std::string& channel, const uint8_t* message,
509 size_t message_size, BinaryReply reply) {});
510
511 int redispatch_scancode = 0;
512 TextInputPlugin handler(&messenger, engine());
513
514 auto args = std::make_unique<rapidjson::Document>(rapidjson::kArrayType);
515 auto& allocator = args->GetAllocator();
516 args->PushBack(123, allocator); // client_id
517
518 rapidjson::Value client_config(rapidjson::kObjectType);
519 client_config.AddMember(kEnableDeltaModel, true, allocator);
520 client_config.AddMember(kViewId, 456, allocator);
521
522 args->PushBack(client_config, allocator);
523 auto encoded = JsonMethodCodec::GetInstance().EncodeMethodCall(
524 MethodCall<rapidjson::Document>(kSetClientMethod, std::move(args)));
525
526 EXPECT_TRUE(messenger.SimulateEngineMessage(
527 kChannelName, encoded->data(), encoded->size(),
528 [](const uint8_t* reply, size_t reply_size) {}));
529
530 handler.KeyboardHook(VK_RETURN, 100, WM_KEYDOWN, '\n', false, false);
531 handler.ComposeBeginHook();
532 std::u16string text;
533 text.push_back('\n');
534 handler.ComposeChangeHook(text, 1);
535 handler.ComposeEndHook();
536
537 handler.KeyboardHook(0x4E, 100, WM_KEYDOWN, 'n', false, false);
538 handler.ComposeBeginHook();
539 std::u16string textN;
540 text.push_back('n');
541 handler.ComposeChangeHook(textN, 1);
542 handler.KeyboardHook(0x49, 100, WM_KEYDOWN, 'i', false, false);
543 std::u16string textNi;
544 text.push_back('n');
545 text.push_back('i');
546 handler.ComposeChangeHook(textNi, 2);
547 handler.KeyboardHook(VK_RETURN, 100, WM_KEYDOWN, '\n', false, false);
548 std::u16string textChineseCharacter;
549 text.push_back(u'\u4F60');
550 handler.ComposeChangeHook(textChineseCharacter, 1);
551 handler.ComposeCommitHook();
552 handler.ComposeEndHook();
553
554 // Passes if it did not crash
555 }
text
std::u16string text
Definition: keyboard_unittests.cc:332
kEnableDeltaModel
static constexpr char kEnableDeltaModel[]
Definition: text_input_plugin.cc:39

References flutter::TextInputPlugin::ComposeBeginHook(), flutter::TextInputPlugin::ComposeChangeHook(), flutter::TextInputPlugin::ComposeCommitHook(), flutter::TextInputPlugin::ComposeEndHook(), flutter::MethodCodec< T >::EncodeMethodCall(), flutter::JsonMethodCodec::GetInstance(), kChannelName, kEnableDeltaModel, flutter::TextInputPlugin::KeyboardHook(), kSetClientMethod, kViewId, message, and text.

## ◆ TEST_F() [149/204]

flutter::testing::TEST_F | ( | TextInputPluginTest | ,
|  | TextMethodsWorksWithEmptyModel |
| ) |  |

Definition at line 198 of file text_input_plugin_unittest.cc.

198 {
199 UseEngineWithView();
200
201 auto handled_message = CreateResponse(true);
202 auto unhandled_message = CreateResponse(false);
203 int received_scancode = 0;
204
205 TestBinaryMessenger messenger(
206 [&received_scancode, &handled_message, &unhandled_message](
207 const std::string& channel, const uint8_t* message,
208 size_t message_size, BinaryReply reply) {});
209
210 int redispatch_scancode = 0;
211 TextInputPlugin handler(&messenger, engine());
212
213 handler.KeyboardHook(VK_RETURN, 100, WM_KEYDOWN, '\n', false, false);
214 handler.ComposeBeginHook();
215 std::u16string text;
216 text.push_back('\n');
217 handler.ComposeChangeHook(text, 1);
218 handler.ComposeEndHook();
219
220 // Passes if it did not crash
221 }

References flutter::TextInputPlugin::ComposeBeginHook(), flutter::TextInputPlugin::ComposeChangeHook(), flutter::TextInputPlugin::ComposeEndHook(), flutter::TextInputPlugin::KeyboardHook(), message, and text.

## ◆ TEST_F() [150/204]

flutter::testing::TEST_F | ( | TextInputPluginTest | ,
|  | TransformCursorRect |
| ) |  |

Definition at line 618 of file text_input_plugin_unittest.cc.

618 {
619 UseEngineWithView();
620
621 // A position of `EditableText`.
622 double view_x = 100;
623 double view_y = 200;
624
625 // A position and size of marked text, in `EditableText` local coordinates.
626 double ime_x = 3;
627 double ime_y = 4;
628 double ime_width = 50;
629 double ime_height = 60;
630
631 // Transformation matrix.
632 std::array<std::array<double, 4>, 4> editabletext_transform = {
633 1.0, 0.0, 0.0, view_x, //
634 0.0, 1.0, 0.0, view_y, //
635 0.0, 0.0, 0.0, 0.0, //
636 0.0, 0.0, 0.0, 1.0};
637
638 TestBinaryMessenger messenger([](const std::string& channel,
639 const uint8_t* message, size_t message_size,
640 BinaryReply reply) {});
641 BinaryReply reply_handler = [](const uint8_t* reply, size_t reply_size) {};
642
643 TextInputPlugin handler(&messenger, engine());
644 TextInputPluginModifier modifier(&handler);
645 modifier.SetViewId(456);
646
647 auto& codec = JsonMethodCodec::GetInstance();
648
649 EXPECT_CALL(*view(), OnCursorRectUpdated(Rect{{view_x, view_y}, {0, 0}}));
650
651 {
652 auto arguments =
653 std::make_unique<rapidjson::Document>(rapidjson::kObjectType);
654 auto& allocator = arguments->GetAllocator();
655
656 rapidjson::Value transoform(rapidjson::kArrayType);
657 for (int i = 0; i < 4 * 4; i++) {
658 // Pack 2-dimensional array by column-major order.
659 transoform.PushBack(editabletext_transform[i % 4][i / 4], allocator);
660 }
661
662 arguments->AddMember("transform", transoform, allocator);
663
664 auto message = codec.EncodeMethodCall(
665 {"TextInput.setEditableSizeAndTransform", std::move(arguments)});
666 messenger.SimulateEngineMessage(kChannelName, message->data(),
667 message->size(), reply_handler);
668 }
669
670 EXPECT_CALL(*view(),
671 OnCursorRectUpdated(Rect{{view_x + ime_x, view_y + ime_y},
672 {ime_width, ime_height}}));
673
674 {
675 auto arguments =
676 std::make_unique<rapidjson::Document>(rapidjson::kObjectType);
677 auto& allocator = arguments->GetAllocator();
678
679 arguments->AddMember("x", ime_x, allocator);
680 arguments->AddMember("y", ime_y, allocator);
681 arguments->AddMember("width", ime_width, allocator);
682 arguments->AddMember("height", ime_height, allocator);
683
684 auto message = codec.EncodeMethodCall(
685 {"TextInput.setMarkedTextRect", std::move(arguments)});
686 messenger.SimulateEngineMessage(kChannelName, message->data(),
687 message->size(), reply_handler);
688 }
689 }

References flutter::JsonMethodCodec::GetInstance(), kChannelName, message, and flutter::TextInputPluginModifier::SetViewId().

## ◆ TEST_F() [151/204]

flutter::testing::TEST_F | ( | TextInputPluginTest | ,
|  | VerifyComposingSendStateUpdate |
| ) |  |

Definition at line 272 of file text_input_plugin_unittest.cc.

272 {
273 UseEngineWithView();
274
275 bool sent_message = false;
276 TestBinaryMessenger messenger(
277 [&sent_message](const std::string& channel, const uint8_t* message,
278 size_t message_size,
279 BinaryReply reply) { sent_message = true; });
280 BinaryReply reply_handler = [](const uint8_t* reply, size_t reply_size) {};
281
282 TextInputPlugin handler(&messenger, engine());
283
284 auto& codec = JsonMethodCodec::GetInstance();
285
286 // Call TextInput.setClient to initialize the TextInputModel.
287 auto arguments = std::make_unique<rapidjson::Document>(rapidjson::kArrayType);
288 auto& allocator = arguments->GetAllocator();
289 arguments->PushBack(kDefaultClientId, allocator);
290 rapidjson::Value config(rapidjson::kObjectType);
291 config.AddMember("inputAction", "done", allocator);
292 config.AddMember("inputType", "text", allocator);
293 config.AddMember(kEnableDeltaModel, false, allocator);
294 config.AddMember(kViewId, 456, allocator);
295 arguments->PushBack(config, allocator);
296 auto message =
297 codec.EncodeMethodCall({"TextInput.setClient", std::move(arguments)});
298 messenger.SimulateEngineMessage("flutter/textinput", message->data(),
299 message->size(), reply_handler);
300
301 // ComposeBeginHook should send state update.
302 sent_message = false;
303 handler.ComposeBeginHook();
304 EXPECT_TRUE(sent_message);
305
306 // ComposeChangeHook should send state update.
307 sent_message = false;
308 handler.ComposeChangeHook(u"4", 1);
309 EXPECT_TRUE(sent_message);
310
311 // ComposeCommitHook should NOT send state update.
312 //
313 // Commit messages are always immediately followed by a change message or an
314 // end message, both of which will send an update. Sending intermediate state
315 // with a collapsed composing region will trigger the framework to assume
316 // composing has ended, which is not the case until a WM_IME_ENDCOMPOSING
317 // event is received in the main event loop, which will trigger a call to
318 // ComposeEndHook.
319 sent_message = false;
320 handler.ComposeCommitHook();
321 EXPECT_FALSE(sent_message);
322
323 // ComposeEndHook should send state update.
324 sent_message = false;
325 handler.ComposeEndHook();
326 EXPECT_TRUE(sent_message);
327 }

References flutter::TextInputPlugin::ComposeBeginHook(), flutter::TextInputPlugin::ComposeChangeHook(), flutter::TextInputPlugin::ComposeCommitHook(), flutter::TextInputPlugin::ComposeEndHook(), flutter::JsonMethodCodec::GetInstance(), kEnableDeltaModel, kViewId, and message.

## ◆ TEST_F() [152/204]

flutter::testing::TEST_F | ( | TextInputPluginTest | ,
|  | VerifyInputActionNewlineInsertNewLine |
| ) |  |

Definition at line 329 of file text_input_plugin_unittest.cc.

329 {
330 UseEngineWithView();
331
332 // Store messages as std::string for convenience.
333 std::vector<std::string> messages;
334
335 TestBinaryMessenger messenger(
336 [&messages](const std::string& channel, const uint8_t* message,
337 size_t message_size, BinaryReply reply) {
338 std::string last_message(reinterpret_cast<const char*>(message),
339 message_size);
340 messages.push_back(last_message);
341 });
342 BinaryReply reply_handler = [](const uint8_t* reply, size_t reply_size) {};
343
344 TextInputPlugin handler(&messenger, engine());
345
346 auto& codec = JsonMethodCodec::GetInstance();
347
348 // Call TextInput.setClient to initialize the TextInputModel.
349 auto set_client_arguments =
350 EncodedClientConfig("TextInputType.multiline", "TextInputAction.newline");
351 auto message = codec.EncodeMethodCall(
352 {"TextInput.setClient", std::move(set_client_arguments)});
353 messenger.SimulateEngineMessage("flutter/textinput", message->data(),
354 message->size(), reply_handler);
355
356 // Simulate a key down event for '\n'.
357 handler.KeyboardHook(VK_RETURN, 100, WM_KEYDOWN, '\n', false, false);
358
359 // Two messages are expected, the first is TextInput.updateEditingState and
360 // the second is TextInputClient.performAction.
361 EXPECT_EQ(messages.size(), 2);
362
363 // Editing state should have been updated.
364 auto encoded_arguments = EncodedEditingState("\n", TextRange(1));
365 auto update_state_message = codec.EncodeMethodCall(
366 {kUpdateEditingStateMethod, std::move(encoded_arguments)});
367
368 EXPECT_TRUE(std::equal(update_state_message->begin(),
369 update_state_message->end(),
370 messages.front().begin()));
371
372 // TextInputClient.performAction should have been called.
373 auto arguments = std::make_unique<rapidjson::Document>(rapidjson::kArrayType);
374 auto& allocator = arguments->GetAllocator();
375 arguments->PushBack(kDefaultClientId, allocator);
376 arguments->PushBack(
377 rapidjson::Value("TextInputAction.newline", allocator).Move(), allocator);
378 auto invoke_action_message = codec.EncodeMethodCall(
379 {"TextInputClient.performAction", std::move(arguments)});
380
381 EXPECT_TRUE(std::equal(invoke_action_message->begin(),
382 invoke_action_message->end(),
383 messages.back().begin()));
384 }

References flutter::JsonMethodCodec::GetInstance(), flutter::TextInputPlugin::KeyboardHook(), kUpdateEditingStateMethod, and message.

## ◆ TEST_F() [153/204]

flutter::testing::TEST_F | ( | TextInputPluginTest | ,
|  | VerifyInputActionSendDoesNotInsertNewLine |
| ) |  |

Definition at line 387 of file text_input_plugin_unittest.cc.

387 {
388 UseEngineWithView();
389
390 std::vector<std::vector<uint8_t>> messages;
391
392 TestBinaryMessenger messenger(
393 [&messages](const std::string& channel, const uint8_t* message,
394 size_t message_size, BinaryReply reply) {
395 int length = static_cast<int>(message_size);
396 std::vector<uint8_t> last_message(length);
397 memcpy(&last_message[0], &message[0], length * sizeof(uint8_t));
398 messages.push_back(last_message);
399 });
400 BinaryReply reply_handler = [](const uint8_t* reply, size_t reply_size) {};
401
402 TextInputPlugin handler(&messenger, engine());
403
404 auto& codec = JsonMethodCodec::GetInstance();
405
406 // Call TextInput.setClient to initialize the TextInputModel.
407 auto set_client_arguments =
408 EncodedClientConfig("TextInputType.multiline", "TextInputAction.send");
409 auto message = codec.EncodeMethodCall(
410 {"TextInput.setClient", std::move(set_client_arguments)});
411 messenger.SimulateEngineMessage("flutter/textinput", message->data(),
412 message->size(), reply_handler);
413
414 // Simulate a key down event for '\n'.
415 handler.KeyboardHook(VK_RETURN, 100, WM_KEYDOWN, '\n', false, false);
416
417 // Only a call to TextInputClient.performAction is expected.
418 EXPECT_EQ(messages.size(), 1);
419
420 // TextInputClient.performAction should have been called.
421 auto arguments = std::make_unique<rapidjson::Document>(rapidjson::kArrayType);
422 auto& allocator = arguments->GetAllocator();
423 arguments->PushBack(kDefaultClientId, allocator);
424 arguments->PushBack(
425 rapidjson::Value("TextInputAction.send", allocator).Move(), allocator);
426 auto invoke_action_message = codec.EncodeMethodCall(
427 {"TextInputClient.performAction", std::move(arguments)});
428
429 EXPECT_TRUE(std::equal(invoke_action_message->begin(),
430 invoke_action_message->end(),
431 messages.front().begin()));
432 }

References flutter::JsonMethodCodec::GetInstance(), flutter::TextInputPlugin::KeyboardHook(), and message.

## ◆ TEST_F() [154/204]

flutter::testing::TEST_F | ( | WindowManagerTest | ,
|  | CanConstrainByMaximumSize |
| ) |  |

Definition at line 175 of file window_manager_unittests.cc.

175 {
176 IsolateScope isolate_scope(isolate());
177
178 const int64_t view_id =
179 InternalFlutterWindows_WindowManager_CreateRegularWindow(
180 engine_id(), regular_creation_request());
181 const HWND window_handle =
182 InternalFlutterWindows_WindowManager_GetTopLevelWindowHandle(engine_id(),
183 view_id);
184 WindowConstraints constraints{.has_view_constraints = true,
185 .view_min_width = 0,
186 .view_min_height = 0,
187 .view_max_width = 500,
188 .view_max_height = 500};
189 InternalFlutterWindows_WindowManager_SetWindowConstraints(window_handle,
190 &constraints);
191
192 ActualWindowSize actual_size =
193 InternalFlutterWindows_WindowManager_GetWindowContentSize(window_handle);
194 EXPECT_EQ(actual_size.width, 500);
195 EXPECT_EQ(actual_size.height, 500);
196 }
InternalFlutterWindows_WindowManager_SetWindowConstraints
void InternalFlutterWindows_WindowManager_SetWindowConstraints(HWND hwnd, const flutter::WindowConstraints *constraints)
Definition: window_manager.cc:212
InternalFlutterWindows_WindowManager_CreateRegularWindow
FlutterViewId InternalFlutterWindows_WindowManager_CreateRegularWindow(int64_t engine_id, const flutter::RegularWindowCreationRequest *request)
Definition: window_manager.cc:139
InternalFlutterWindows_WindowManager_GetWindowContentSize
flutter::ActualWindowSize InternalFlutterWindows_WindowManager_GetWindowContentSize(HWND hwnd)
Definition: window_manager.cc:179
InternalFlutterWindows_WindowManager_GetTopLevelWindowHandle
HWND InternalFlutterWindows_WindowManager_GetTopLevelWindowHandle(int64_t engine_id, FlutterViewId view_id)
Definition: window_manager.cc:165

References flutter::WindowConstraints::has_view_constraints, flutter::ActualWindowSize::height, InternalFlutterWindows_WindowManager_CreateRegularWindow(), InternalFlutterWindows_WindowManager_GetTopLevelWindowHandle(), InternalFlutterWindows_WindowManager_GetWindowContentSize(), InternalFlutterWindows_WindowManager_SetWindowConstraints(), and flutter::ActualWindowSize::width.

## ◆ TEST_F() [155/204]

flutter::testing::TEST_F | ( | WindowManagerTest | ,
|  | CanConstrainByMinimiumSize |
| ) |  |

Definition at line 152 of file window_manager_unittests.cc.

152 {
153 IsolateScope isolate_scope(isolate());
154
155 const int64_t view_id =
156 InternalFlutterWindows_WindowManager_CreateRegularWindow(
157 engine_id(), regular_creation_request());
158 const HWND window_handle =
159 InternalFlutterWindows_WindowManager_GetTopLevelWindowHandle(engine_id(),
160 view_id);
161 WindowConstraints constraints{.has_view_constraints = true,
162 .view_min_width = 900,
163 .view_min_height = 700,
164 .view_max_width = 10000,
165 .view_max_height = 10000};
166 InternalFlutterWindows_WindowManager_SetWindowConstraints(window_handle,
167 &constraints);
168
169 ActualWindowSize actual_size =
170 InternalFlutterWindows_WindowManager_GetWindowContentSize(window_handle);
171 EXPECT_EQ(actual_size.width, 900);
172 EXPECT_EQ(actual_size.height, 700);
173 }

References flutter::WindowConstraints::has_view_constraints, flutter::ActualWindowSize::height, InternalFlutterWindows_WindowManager_CreateRegularWindow(), InternalFlutterWindows_WindowManager_GetTopLevelWindowHandle(), InternalFlutterWindows_WindowManager_GetWindowContentSize(), InternalFlutterWindows_WindowManager_SetWindowConstraints(), and flutter::ActualWindowSize::width.

## ◆ TEST_F() [156/204]

flutter::testing::TEST_F | ( | WindowManagerTest | ,
|  | CanFullscreenWindow |
| ) |  |

Definition at line 198 of file window_manager_unittests.cc.

198 {
199 IsolateScope isolate_scope(isolate());
200
201 const int64_t view_id =
202 InternalFlutterWindows_WindowManager_CreateRegularWindow(
203 engine_id(), regular_creation_request());
204 const HWND window_handle =
205 InternalFlutterWindows_WindowManager_GetTopLevelWindowHandle(engine_id(),
206 view_id);
207
208 FullscreenRequest request{.fullscreen = true, .has_display_id = false};
209 InternalFlutterWindows_WindowManager_SetFullscreen(window_handle, &request);
210
211 int screen_width = GetSystemMetrics(SM_CXSCREEN);
212 int screen_height = GetSystemMetrics(SM_CYSCREEN);
213 ActualWindowSize actual_size =
214 InternalFlutterWindows_WindowManager_GetWindowContentSize(window_handle);
215 EXPECT_EQ(actual_size.width, screen_width);
216 EXPECT_EQ(actual_size.height, screen_height);
217 EXPECT_TRUE(
218 InternalFlutterWindows_WindowManager_GetFullscreen(window_handle));
219 }
InternalFlutterWindows_WindowManager_GetFullscreen
bool InternalFlutterWindows_WindowManager_GetFullscreen(HWND hwnd)
Definition: window_manager.cc:234
InternalFlutterWindows_WindowManager_SetFullscreen
void InternalFlutterWindows_WindowManager_SetFullscreen(HWND hwnd, const flutter::FullscreenRequest *request)
Definition: window_manager.cc:221

References flutter::FullscreenRequest::fullscreen, flutter::ActualWindowSize::height, InternalFlutterWindows_WindowManager_CreateRegularWindow(), InternalFlutterWindows_WindowManager_GetFullscreen(), InternalFlutterWindows_WindowManager_GetTopLevelWindowHandle(), InternalFlutterWindows_WindowManager_GetWindowContentSize(), InternalFlutterWindows_WindowManager_SetFullscreen(), and flutter::ActualWindowSize::width.

## ◆ TEST_F() [157/204]

flutter::testing::TEST_F | ( | WindowManagerTest | ,
|  | CanSetWindowConstraintsWhileFullscreen |
| ) |  |

Definition at line 276 of file window_manager_unittests.cc.

276 {
277 IsolateScope isolate_scope(isolate());
278
279 const int64_t view_id =
280 InternalFlutterWindows_WindowManager_CreateRegularWindow(
281 engine_id(), regular_creation_request());
282 const HWND window_handle =
283 InternalFlutterWindows_WindowManager_GetTopLevelWindowHandle(engine_id(),
284 view_id);
285
286 FullscreenRequest request{.fullscreen = true, .has_display_id = false};
287 InternalFlutterWindows_WindowManager_SetFullscreen(window_handle, &request);
288
289 WindowConstraints constraints{.has_view_constraints = true,
290 .view_min_width = 0,
291 .view_min_height = 0,
292 .view_max_width = 500,
293 .view_max_height = 500};
294 InternalFlutterWindows_WindowManager_SetWindowConstraints(window_handle,
295 &constraints);
296
297 request.fullscreen = false;
298 InternalFlutterWindows_WindowManager_SetFullscreen(window_handle, &request);
299
300 ActualWindowSize actual_size =
301 InternalFlutterWindows_WindowManager_GetWindowContentSize(window_handle);
302 EXPECT_EQ(actual_size.width, 500);
303 EXPECT_EQ(actual_size.height, 500);
304 }

References flutter::FullscreenRequest::fullscreen, flutter::WindowConstraints::has_view_constraints, flutter::ActualWindowSize::height, InternalFlutterWindows_WindowManager_CreateRegularWindow(), InternalFlutterWindows_WindowManager_GetTopLevelWindowHandle(), InternalFlutterWindows_WindowManager_GetWindowContentSize(), InternalFlutterWindows_WindowManager_SetFullscreen(), InternalFlutterWindows_WindowManager_SetWindowConstraints(), and flutter::ActualWindowSize::width.

## ◆ TEST_F() [158/204]

flutter::testing::TEST_F | ( | WindowManagerTest | ,
|  | CanSetWindowSizeWhileFullscreen |
| ) |  |

Definition at line 245 of file window_manager_unittests.cc.

245 {
246 IsolateScope isolate_scope(isolate());
247
248 const int64_t view_id =
249 InternalFlutterWindows_WindowManager_CreateRegularWindow(
250 engine_id(), regular_creation_request());
251 const HWND window_handle =
252 InternalFlutterWindows_WindowManager_GetTopLevelWindowHandle(engine_id(),
253 view_id);
254
255 FullscreenRequest request{.fullscreen = true, .has_display_id = false};
256 InternalFlutterWindows_WindowManager_SetFullscreen(window_handle, &request);
257
258 WindowSizeRequest requestedSize{
259
260 .has_preferred_view_size = true,
261 .preferred_view_width = 500,
262 .preferred_view_height = 500,
263 };
264 InternalFlutterWindows_WindowManager_SetWindowSize(window_handle,
265 &requestedSize);
266
267 request.fullscreen = false;
268 InternalFlutterWindows_WindowManager_SetFullscreen(window_handle, &request);
269
270 ActualWindowSize actual_size =
271 InternalFlutterWindows_WindowManager_GetWindowContentSize(window_handle);
272 EXPECT_EQ(actual_size.width, 500);
273 EXPECT_EQ(actual_size.height, 500);
274 }
InternalFlutterWindows_WindowManager_SetWindowSize
void InternalFlutterWindows_WindowManager_SetWindowSize(HWND hwnd, const flutter::WindowSizeRequest *size)
Definition: window_manager.cc:183

References flutter::FullscreenRequest::fullscreen, flutter::WindowSizeRequest::has_preferred_view_size, flutter::ActualWindowSize::height, InternalFlutterWindows_WindowManager_CreateRegularWindow(), InternalFlutterWindows_WindowManager_GetTopLevelWindowHandle(), InternalFlutterWindows_WindowManager_GetWindowContentSize(), InternalFlutterWindows_WindowManager_SetFullscreen(), InternalFlutterWindows_WindowManager_SetWindowSize(), and flutter::ActualWindowSize::width.

## ◆ TEST_F() [159/204]

flutter::testing::TEST_F | ( | WindowManagerTest | ,
|  | CanUnfullscreenWindow |
| ) |  |

Definition at line 221 of file window_manager_unittests.cc.

221 {
222 IsolateScope isolate_scope(isolate());
223
224 const int64_t view_id =
225 InternalFlutterWindows_WindowManager_CreateRegularWindow(
226 engine_id(), regular_creation_request());
227 const HWND window_handle =
228 InternalFlutterWindows_WindowManager_GetTopLevelWindowHandle(engine_id(),
229 view_id);
230
231 FullscreenRequest request{.fullscreen = true, .has_display_id = false};
232 InternalFlutterWindows_WindowManager_SetFullscreen(window_handle, &request);
233
234 request.fullscreen = false;
235 InternalFlutterWindows_WindowManager_SetFullscreen(window_handle, &request);
236
237 ActualWindowSize actual_size =
238 InternalFlutterWindows_WindowManager_GetWindowContentSize(window_handle);
239 EXPECT_EQ(actual_size.width, 800);
240 EXPECT_EQ(actual_size.height, 600);
241 EXPECT_FALSE(
242 InternalFlutterWindows_WindowManager_GetFullscreen(window_handle));
243 }

References flutter::FullscreenRequest::fullscreen, flutter::ActualWindowSize::height, InternalFlutterWindows_WindowManager_CreateRegularWindow(), InternalFlutterWindows_WindowManager_GetFullscreen(), InternalFlutterWindows_WindowManager_GetTopLevelWindowHandle(), InternalFlutterWindows_WindowManager_GetWindowContentSize(), InternalFlutterWindows_WindowManager_SetFullscreen(), and flutter::ActualWindowSize::width.

## ◆ TEST_F() [160/204]

flutter::testing::TEST_F | ( | WindowManagerTest | ,
|  | CreateModalDialogWindow |
| ) |  |

Definition at line 321 of file window_manager_unittests.cc.

321 {
322 IsolateScope isolate_scope(isolate());
323
324 const int64_t parent_view_id =
325 InternalFlutterWindows_WindowManager_CreateRegularWindow(
326 engine_id(), regular_creation_request());
327 const HWND parent_window_handle =
328 InternalFlutterWindows_WindowManager_GetTopLevelWindowHandle(
329 engine_id(), parent_view_id);
330
331 DialogWindowCreationRequest creation_request{
332 .preferred_size =
333 {
334 .has_preferred_view_size = true,
335 .preferred_view_width = 800,
336 .preferred_view_height = 600,
337 },
338 .preferred_constraints = {.has_view_constraints = false},
339 .title = L"Hello World",
340 .parent_or_null = parent_window_handle};
341
342 const int64_t view_id =
343 InternalFlutterWindows_WindowManager_CreateDialogWindow(
344 engine_id(), &creation_request);
345 EXPECT_EQ(view_id, 1);
346
347 const HWND window_handle =
348 InternalFlutterWindows_WindowManager_GetTopLevelWindowHandle(engine_id(),
349 view_id);
350 HostWindow* host_window = HostWindow::GetThisFromHandle(window_handle);
351 EXPECT_EQ(host_window->GetOwnerWindow()->GetWindowHandle(),
352 parent_window_handle);
353 }
InternalFlutterWindows_WindowManager_CreateDialogWindow
FLUTTER_EXPORT FlutterViewId InternalFlutterWindows_WindowManager_CreateDialogWindow(int64_t engine_id, const flutter::DialogWindowCreationRequest *request)
Definition: window_manager.cc:148

References flutter::HostWindow::GetOwnerWindow(), flutter::HostWindow::GetThisFromHandle(), flutter::HostWindow::GetWindowHandle(), flutter::WindowSizeRequest::has_preferred_view_size, InternalFlutterWindows_WindowManager_CreateDialogWindow(), InternalFlutterWindows_WindowManager_CreateRegularWindow(), InternalFlutterWindows_WindowManager_GetTopLevelWindowHandle(), and flutter::DialogWindowCreationRequest::preferred_size.

## ◆ TEST_F() [161/204]

flutter::testing::TEST_F | ( | WindowManagerTest | ,
|  | CreateModelessDialogWindow |
| ) |  |

Definition at line 306 of file window_manager_unittests.cc.

306 {
307 IsolateScope isolate_scope(isolate());
308 DialogWindowCreationRequest creation_request{
309 .preferred_size = {.has_preferred_view_size = true,
310 .preferred_view_width = 800,
311 .preferred_view_height = 600},
312 .preferred_constraints = {.has_view_constraints = false},
313 .title = L"Hello World",
314 .parent_or_null = nullptr};
315 const int64_t view_id =
316 InternalFlutterWindows_WindowManager_CreateDialogWindow(
317 engine_id(), &creation_request);
318 EXPECT_EQ(view_id, 0);
319 }

References flutter::WindowSizeRequest::has_preferred_view_size, InternalFlutterWindows_WindowManager_CreateDialogWindow(), and flutter::DialogWindowCreationRequest::preferred_size.

## ◆ TEST_F() [162/204]

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

Definition at line 87 of file window_manager_unittests.cc.

87 {
88 IsolateScope isolate_scope(isolate());
89
90 const int64_t view_id =
91 InternalFlutterWindows_WindowManager_CreateRegularWindow(
92 engine_id(), regular_creation_request());
93 EXPECT_EQ(view_id, 0);
94 }

References InternalFlutterWindows_WindowManager_CreateRegularWindow().

## ◆ TEST_F() [163/204]

flutter::testing::TEST_F | ( | WindowManagerTest | ,
|  | CreateTooltipWindow |
| ) |  |

Definition at line 379 of file window_manager_unittests.cc.

379 {
380 IsolateScope isolate_scope(isolate());
381
382 const int64_t parent_view_id =
383 InternalFlutterWindows_WindowManager_CreateRegularWindow(
384 engine_id(), regular_creation_request());
385 const HWND parent_window_handle =
386 InternalFlutterWindows_WindowManager_GetTopLevelWindowHandle(
387 engine_id(), parent_view_id);
388
389 auto position_callback = [](const WindowSize& child_size,
390 const WindowRect& parent_rect,
391 const WindowRect& output_rect) -> WindowRect* {
392 WindowRect* rect = static_cast<WindowRect*>(malloc(sizeof(WindowRect)));
393 rect->left = parent_rect.left + 10;
394 rect->top = parent_rect.top + 10;
395 rect->width = child_size.width;
396 rect->height = child_size.height;
397 return rect;
398 };
399
400 TooltipWindowCreationRequest creation_request{
401 .preferred_constraints = {.has_view_constraints = true,
402 .view_min_width = 100,
403 .view_min_height = 50,
404 .view_max_width = 300,
405 .view_max_height = 200},
406 .parent = parent_window_handle,
407 .get_position_callback = position_callback};
408
409 const int64_t tooltip_view_id =
410 InternalFlutterWindows_WindowManager_CreateTooltipWindow(
411 engine_id(), &creation_request);
412
413 EXPECT_NE(tooltip_view_id, -1);
414 HWND tooltip_window_handle =
415 InternalFlutterWindows_WindowManager_GetTopLevelWindowHandle(
416 engine_id(), tooltip_view_id);
417 EXPECT_NE(tooltip_window_handle, nullptr);
418 }
InternalFlutterWindows_WindowManager_CreateTooltipWindow
FLUTTER_EXPORT FlutterViewId InternalFlutterWindows_WindowManager_CreateTooltipWindow(int64_t engine_id, const flutter::TooltipWindowCreationRequest *request)
Definition: window_manager.cc:157

References flutter::WindowConstraints::has_view_constraints, flutter::WindowRect::height, flutter::WindowSize::height, InternalFlutterWindows_WindowManager_CreateRegularWindow(), InternalFlutterWindows_WindowManager_CreateTooltipWindow(), InternalFlutterWindows_WindowManager_GetTopLevelWindowHandle(), flutter::WindowRect::left, flutter::TooltipWindowCreationRequest::preferred_constraints, flutter::WindowRect::top, flutter::WindowRect::width, and flutter::WindowSize::width.

## ◆ TEST_F() [164/204]

flutter::testing::TEST_F | ( | WindowManagerTest | ,
|  | DialogCanNeverBeFullscreen |
| ) |  |

Definition at line 355 of file window_manager_unittests.cc.

355 {
356 IsolateScope isolate_scope(isolate());
357
358 DialogWindowCreationRequest creation_request{
359 .preferred_size = {.has_preferred_view_size = true,
360 .preferred_view_width = 800,
361 .preferred_view_height = 600},
362 .preferred_constraints = {.has_view_constraints = false},
363 .title = L"Hello World",
364 .parent_or_null = nullptr};
365
366 const int64_t view_id =
367 InternalFlutterWindows_WindowManager_CreateDialogWindow(
368 engine_id(), &creation_request);
369 const HWND window_handle =
370 InternalFlutterWindows_WindowManager_GetTopLevelWindowHandle(engine_id(),
371 view_id);
372
373 FullscreenRequest request{.fullscreen = true, .has_display_id = false};
374 InternalFlutterWindows_WindowManager_SetFullscreen(window_handle, &request);
375 EXPECT_FALSE(
376 InternalFlutterWindows_WindowManager_GetFullscreen(window_handle));
377 }

References flutter::FullscreenRequest::fullscreen, flutter::WindowSizeRequest::has_preferred_view_size, InternalFlutterWindows_WindowManager_CreateDialogWindow(), InternalFlutterWindows_WindowManager_GetFullscreen(), InternalFlutterWindows_WindowManager_GetTopLevelWindowHandle(), InternalFlutterWindows_WindowManager_SetFullscreen(), and flutter::DialogWindowCreationRequest::preferred_size.

## ◆ TEST_F() [165/204]

flutter::testing::TEST_F | ( | WindowManagerTest | ,
|  | GetWindowHandle |
| ) |  |

Definition at line 96 of file window_manager_unittests.cc.

96 {
97 IsolateScope isolate_scope(isolate());
98
99 const int64_t view_id =
100 InternalFlutterWindows_WindowManager_CreateRegularWindow(
101 engine_id(), regular_creation_request());
102 const HWND window_handle =
103 InternalFlutterWindows_WindowManager_GetTopLevelWindowHandle(engine_id(),
104 view_id);
105 EXPECT_NE(window_handle, nullptr);
106 }

References InternalFlutterWindows_WindowManager_CreateRegularWindow(), and InternalFlutterWindows_WindowManager_GetTopLevelWindowHandle().

## ◆ TEST_F() [166/204]

flutter::testing::TEST_F | ( | WindowManagerTest | ,
|  | GetWindowSize |
| ) |  |

Definition at line 108 of file window_manager_unittests.cc.

108 {
109 IsolateScope isolate_scope(isolate());
110
111 const int64_t view_id =
112 InternalFlutterWindows_WindowManager_CreateRegularWindow(
113 engine_id(), regular_creation_request());
114 const HWND window_handle =
115 InternalFlutterWindows_WindowManager_GetTopLevelWindowHandle(engine_id(),
116 view_id);
117
118 ActualWindowSize size =
119 InternalFlutterWindows_WindowManager_GetWindowContentSize(window_handle);
120
121 EXPECT_EQ(size.width,
122 regular_creation_request()->preferred_size.preferred_view_width);
123 EXPECT_EQ(size.height,
124 regular_creation_request()->preferred_size.preferred_view_height);
125 }

References flutter::ActualWindowSize::height, InternalFlutterWindows_WindowManager_CreateRegularWindow(), InternalFlutterWindows_WindowManager_GetTopLevelWindowHandle(), InternalFlutterWindows_WindowManager_GetWindowContentSize(), and flutter::ActualWindowSize::width.

## ◆ TEST_F() [167/204]

flutter::testing::TEST_F | ( | WindowManagerTest | ,
|  | SetWindowSize |
| ) |  |

Definition at line 127 of file window_manager_unittests.cc.

127 {
128 IsolateScope isolate_scope(isolate());
129
130 const int64_t view_id =
131 InternalFlutterWindows_WindowManager_CreateRegularWindow(
132 engine_id(), regular_creation_request());
133 const HWND window_handle =
134 InternalFlutterWindows_WindowManager_GetTopLevelWindowHandle(engine_id(),
135 view_id);
136
137 WindowSizeRequest requestedSize{
138
139 .has_preferred_view_size = true,
140 .preferred_view_width = 640,
141 .preferred_view_height = 480,
142 };
143 InternalFlutterWindows_WindowManager_SetWindowSize(window_handle,
144 &requestedSize);
145
146 ActualWindowSize actual_size =
147 InternalFlutterWindows_WindowManager_GetWindowContentSize(window_handle);
148 EXPECT_EQ(actual_size.width, 640);
149 EXPECT_EQ(actual_size.height, 480);
150 }

References flutter::WindowSizeRequest::has_preferred_view_size, flutter::ActualWindowSize::height, InternalFlutterWindows_WindowManager_CreateRegularWindow(), InternalFlutterWindows_WindowManager_GetTopLevelWindowHandle(), InternalFlutterWindows_WindowManager_GetWindowContentSize(), InternalFlutterWindows_WindowManager_SetWindowSize(), and flutter::ActualWindowSize::width.

## ◆ TEST_F() [168/204]

flutter::testing::TEST_F | ( | WindowManagerTest | ,
|  | TooltipWindowDoesNotStealFocus |
| ) |  |

Definition at line 462 of file window_manager_unittests.cc.

462 {
463 IsolateScope isolate_scope(isolate());
464
465 const int64_t parent_view_id =
466 InternalFlutterWindows_WindowManager_CreateRegularWindow(
467 engine_id(), regular_creation_request());
468 const HWND parent_window_handle =
469 InternalFlutterWindows_WindowManager_GetTopLevelWindowHandle(
470 engine_id(), parent_view_id);
471
472 // Give focus to the parent window
473 SetFocus(parent_window_handle);
474 HWND focused_before = GetFocus();
475
476 auto position_callback = [](const WindowSize& child_size,
477 const WindowRect& parent_rect,
478 const WindowRect& output_rect) -> WindowRect* {
479 WindowRect* rect = static_cast<WindowRect*>(malloc(sizeof(WindowRect)));
480 rect->left = parent_rect.left + 10;
481 rect->top = parent_rect.top + 10;
482 rect->width = child_size.width;
483 rect->height = child_size.height;
484 return rect;
485 };
486
487 TooltipWindowCreationRequest creation_request{
488 .preferred_constraints = {.has_view_constraints = true,
489 .view_min_width = 100,
490 .view_min_height = 50,
491 .view_max_width = 300,
492 .view_max_height = 200},
493 .parent = parent_window_handle,
494 .get_position_callback = position_callback};
495
496 const int64_t tooltip_view_id =
497 InternalFlutterWindows_WindowManager_CreateTooltipWindow(
498 engine_id(), &creation_request);
499
500 HWND tooltip_window_handle =
501 InternalFlutterWindows_WindowManager_GetTopLevelWindowHandle(
502 engine_id(), tooltip_view_id);
503
504 // Verify focus remains with the parent window
505 HWND focused_after = GetFocus();
506 EXPECT_EQ(focused_before, focused_after);
507 EXPECT_NE(focused_after, tooltip_window_handle);
508 }

References flutter::WindowConstraints::has_view_constraints, flutter::WindowRect::height, flutter::WindowSize::height, InternalFlutterWindows_WindowManager_CreateRegularWindow(), InternalFlutterWindows_WindowManager_CreateTooltipWindow(), InternalFlutterWindows_WindowManager_GetTopLevelWindowHandle(), flutter::WindowRect::left, flutter::TooltipWindowCreationRequest::preferred_constraints, flutter::WindowRect::top, flutter::WindowRect::width, and flutter::WindowSize::width.

## ◆ TEST_F() [169/204]

flutter::testing::TEST_F | ( | WindowManagerTest | ,
|  | TooltipWindowHasNoActivateStyle |
| ) |  |

Definition at line 420 of file window_manager_unittests.cc.

420 {
421 IsolateScope isolate_scope(isolate());
422
423 const int64_t parent_view_id =
424 InternalFlutterWindows_WindowManager_CreateRegularWindow(
425 engine_id(), regular_creation_request());
426 const HWND parent_window_handle =
427 InternalFlutterWindows_WindowManager_GetTopLevelWindowHandle(
428 engine_id(), parent_view_id);
429
430 auto position_callback = [](const WindowSize& child_size,
431 const WindowRect& parent_rect,
432 const WindowRect& output_rect) -> WindowRect* {
433 WindowRect* rect = static_cast<WindowRect*>(malloc(sizeof(WindowRect)));
434 rect->left = parent_rect.left + 10;
435 rect->top = parent_rect.top + 10;
436 rect->width = child_size.width;
437 rect->height = child_size.height;
438 return rect;
439 };
440
441 TooltipWindowCreationRequest creation_request{
442 .preferred_constraints = {.has_view_constraints = true,
443 .view_min_width = 100,
444 .view_min_height = 50,
445 .view_max_width = 300,
446 .view_max_height = 200},
447 .parent = parent_window_handle,
448 .get_position_callback = position_callback};
449
450 const int64_t tooltip_view_id =
451 InternalFlutterWindows_WindowManager_CreateTooltipWindow(
452 engine_id(), &creation_request);
453
454 HWND tooltip_window_handle =
455 InternalFlutterWindows_WindowManager_GetTopLevelWindowHandle(
456 engine_id(), tooltip_view_id);
457
458 DWORD ex_style = GetWindowLong(tooltip_window_handle, GWL_EXSTYLE);
459 EXPECT_TRUE(ex_style & WS_EX_NOACTIVATE);
460 }

References flutter::WindowConstraints::has_view_constraints, flutter::WindowRect::height, flutter::WindowSize::height, InternalFlutterWindows_WindowManager_CreateRegularWindow(), InternalFlutterWindows_WindowManager_CreateTooltipWindow(), InternalFlutterWindows_WindowManager_GetTopLevelWindowHandle(), flutter::WindowRect::left, flutter::TooltipWindowCreationRequest::preferred_constraints, flutter::WindowRect::top, flutter::WindowRect::width, and flutter::WindowSize::width.

## ◆ TEST_F() [170/204]

flutter::testing::TEST_F | ( | WindowManagerTest | ,
|  | TooltipWindowReturnsNoActivateOnMouseClick |
| ) |  |

Definition at line 510 of file window_manager_unittests.cc.

510 {
511 IsolateScope isolate_scope(isolate());
512
513 const int64_t parent_view_id =
514 InternalFlutterWindows_WindowManager_CreateRegularWindow(
515 engine_id(), regular_creation_request());
516 const HWND parent_window_handle =
517 InternalFlutterWindows_WindowManager_GetTopLevelWindowHandle(
518 engine_id(), parent_view_id);
519
520 auto position_callback = [](const WindowSize& child_size,
521 const WindowRect& parent_rect,
522 const WindowRect& output_rect) -> WindowRect* {
523 WindowRect* rect = static_cast<WindowRect*>(malloc(sizeof(WindowRect)));
524 rect->left = parent_rect.left + 10;
525 rect->top = parent_rect.top + 10;
526 rect->width = child_size.width;
527 rect->height = child_size.height;
528 return rect;
529 };
530
531 TooltipWindowCreationRequest creation_request{
532 .preferred_constraints = {.has_view_constraints = true,
533 .view_min_width = 100,
534 .view_min_height = 50,
535 .view_max_width = 300,
536 .view_max_height = 200},
537 .parent = parent_window_handle,
538 .get_position_callback = position_callback};
539
540 const int64_t tooltip_view_id =
541 InternalFlutterWindows_WindowManager_CreateTooltipWindow(
542 engine_id(), &creation_request);
543
544 HWND tooltip_window_handle =
545 InternalFlutterWindows_WindowManager_GetTopLevelWindowHandle(
546 engine_id(), tooltip_view_id);
547
548 // Send WM_MOUSEACTIVATE message to the tooltip window
549 LRESULT result = SendMessage(tooltip_window_handle, WM_MOUSEACTIVATE,
550 reinterpret_cast<WPARAM>(parent_window_handle),
551 MAKELPARAM(HTCLIENT, WM_LBUTTONDOWN));
552
553 // Verify the tooltip returns MA_NOACTIVATE
554 EXPECT_EQ(result, MA_NOACTIVATE);
555 }

References flutter::WindowConstraints::has_view_constraints, flutter::WindowRect::height, flutter::WindowSize::height, InternalFlutterWindows_WindowManager_CreateRegularWindow(), InternalFlutterWindows_WindowManager_CreateTooltipWindow(), InternalFlutterWindows_WindowManager_GetTopLevelWindowHandle(), flutter::WindowRect::left, flutter::TooltipWindowCreationRequest::preferred_constraints, flutter::WindowRect::top, flutter::WindowRect::width, and flutter::WindowSize::width.

## ◆ TEST_F() [171/204]

flutter::testing::TEST_F | ( | WindowManagerTest | ,
|  | TooltipWindowUpdatesPositionOnViewSizeChange |
| ) |  |

Definition at line 557 of file window_manager_unittests.cc.

557 {
558 IsolateScope isolate_scope(isolate());
559
560 const int64_t parent_view_id =
561 InternalFlutterWindows_WindowManager_CreateRegularWindow(
562 engine_id(), regular_creation_request());
563 const HWND parent_window_handle =
564 InternalFlutterWindows_WindowManager_GetTopLevelWindowHandle(
565 engine_id(), parent_view_id);
566
567 // Track the child size passed to the callback
568 static int callback_count = 0;
569 static int last_width = 0;
570 static int last_height = 0;
571
572 auto position_callback = [](const WindowSize& child_size,
573 const WindowRect& parent_rect,
574 const WindowRect& output_rect) -> WindowRect* {
575 callback_count++;
576 last_width = child_size.width;
577 last_height = child_size.height;
578
579 // Use malloc since the caller will use free()
580 WindowRect* rect = static_cast<WindowRect*>(malloc(sizeof(WindowRect)));
581 rect->left = parent_rect.left + callback_count * 5;
582 rect->top = parent_rect.top + callback_count * 5;
583 rect->width = child_size.width;
584 rect->height = child_size.height;
585 return rect;
586 };
587
588 TooltipWindowCreationRequest creation_request{
589 .preferred_constraints = {.has_view_constraints = true,
590 .view_min_width = 100,
591 .view_min_height = 50,
592 .view_max_width = 300,
593 .view_max_height = 200},
594 .parent = parent_window_handle,
595 .get_position_callback = position_callback};
596
597 // Reset callback tracking
598 callback_count = 0;
599 last_width = 0;
600 last_height = 0;
601
602 const int64_t tooltip_view_id =
603 InternalFlutterWindows_WindowManager_CreateTooltipWindow(
604 engine_id(), &creation_request);
605
606 HWND tooltip_window_handle =
607 InternalFlutterWindows_WindowManager_GetTopLevelWindowHandle(
608 engine_id(), tooltip_view_id);
609
610 // Get the view associated with the tooltip window
611 FlutterWindowsView* view =
612 engine()->GetViewFromTopLevelWindow(tooltip_window_handle);
613 ASSERT_NE(view, nullptr);
614
615 // Get initial position
616 RECT initial_rect;
617 GetWindowRect(tooltip_window_handle, &initial_rect);
618 int initial_callback_count = callback_count;
619
620 // Simulate a frame being generated with new dimensions
621 // This should trigger DidUpdateViewSize which calls UpdatePosition
622 view->OnFrameGenerated(150, 100);
623
624 // Process any pending tasks to ensure the callback is executed
625 engine()->task_runner()->ProcessTasks();
626
627 // Verify the callback was called again with the new dimensions
628 EXPECT_GT(callback_count, initial_callback_count);
629 EXPECT_EQ(last_width, 150);
630 EXPECT_EQ(last_height, 100);
631
632 // Get new position and verify it changed
633 RECT new_rect;
634 GetWindowRect(tooltip_window_handle, &new_rect);
635
636 // The position should have changed due to our callback logic
637 // (we offset by callback_count * 5)
638 EXPECT_NE(initial_rect.left, new_rect.left);
639 EXPECT_NE(initial_rect.top, new_rect.top);
640 }

References flutter::WindowConstraints::has_view_constraints, flutter::WindowRect::height, flutter::WindowSize::height, InternalFlutterWindows_WindowManager_CreateRegularWindow(), InternalFlutterWindows_WindowManager_CreateTooltipWindow(), InternalFlutterWindows_WindowManager_GetTopLevelWindowHandle(), flutter::WindowRect::left, flutter::FlutterWindowsView::OnFrameGenerated(), flutter::TooltipWindowCreationRequest::preferred_constraints, flutter::WindowRect::top, flutter::WindowRect::width, and flutter::WindowSize::width.

## ◆ TEST_F() [172/204]

flutter::testing::TEST_F | ( | WindowManagerTest | ,
|  | WindowingInitialize |
| ) |  |

Definition at line 70 of file window_manager_unittests.cc.

70 {
71 IsolateScope isolate_scope(isolate());
72
73 static bool received_message = false;
74 WindowingInitRequest init_request{
75 .on_message = [](WindowsMessage* message) { received_message = true; }};
76
77 InternalFlutterWindows_WindowManager_Initialize(engine_id(), &init_request);
78 const int64_t view_id =
79 InternalFlutterWindows_WindowManager_CreateRegularWindow(
80 engine_id(), regular_creation_request());
81 DestroyWindow(InternalFlutterWindows_WindowManager_GetTopLevelWindowHandle(
82 engine_id(), view_id));
83
84 EXPECT_TRUE(received_message);
85 }
InternalFlutterWindows_WindowManager_Initialize
void InternalFlutterWindows_WindowManager_Initialize(int64_t engine_id, const flutter::WindowingInitRequest *request)
Definition: window_manager.cc:131

References InternalFlutterWindows_WindowManager_CreateRegularWindow(), InternalFlutterWindows_WindowManager_GetTopLevelWindowHandle(), InternalFlutterWindows_WindowManager_Initialize(), message, and flutter::WindowingInitRequest::on_message.

## ◆ TEST_F() [173/204]

flutter::testing::TEST_F | ( | WindowsLifecycleManagerTest | ,
|  | StateTransitions |
| ) |  |

Definition at line 26 of file windows_lifecycle_manager_unittests.cc.

26 {
27 FlutterWindowsEngineBuilder builder{GetContext()};
28 std::unique_ptr<FlutterWindowsEngine> engine = builder.Build();
29
30 WindowsLifecycleManager manager{engine.get()};
31 HWND win1 = reinterpret_cast<HWND>(1);
32 HWND win2 = reinterpret_cast<HWND>(2);
33
34 // Hidden to inactive upon window shown.
35 manager.SetLifecycleState(AppLifecycleState::kHidden);
36 manager.OnWindowStateEvent(win1, WindowStateEvent::kShow);
37 WaitUntilUpdated(manager);
38 EXPECT_EQ(manager.GetLifecycleState(), AppLifecycleState::kInactive);
39
40 // Showing a second window does not change state.
41 manager.OnWindowStateEvent(win2, WindowStateEvent::kShow);
42 WaitUntilUpdated(manager);
43 EXPECT_EQ(manager.GetLifecycleState(), AppLifecycleState::kInactive);
44
45 // Inactive to resumed upon window focus.
46 manager.OnWindowStateEvent(win2, WindowStateEvent::kFocus);
47 WaitUntilUpdated(manager);
48 EXPECT_EQ(manager.GetLifecycleState(), AppLifecycleState::kResumed);
49
50 // Showing a second window does not change state.
51 manager.OnWindowStateEvent(win1, WindowStateEvent::kFocus);
52 WaitUntilUpdated(manager);
53 EXPECT_EQ(manager.GetLifecycleState(), AppLifecycleState::kResumed);
54
55 // Unfocusing one window does not change state while another is focused.
56 manager.OnWindowStateEvent(win1, WindowStateEvent::kUnfocus);
57 WaitUntilUpdated(manager);
58 EXPECT_EQ(manager.GetLifecycleState(), AppLifecycleState::kResumed);
59
60 // Unfocusing final remaining focused window transitions to inactive.
61 manager.OnWindowStateEvent(win2, WindowStateEvent::kUnfocus);
62 WaitUntilUpdated(manager);
63 EXPECT_EQ(manager.GetLifecycleState(), AppLifecycleState::kInactive);
64
65 // Hiding one of two visible windows does not change state.
66 manager.OnWindowStateEvent(win2, WindowStateEvent::kHide);
67 WaitUntilUpdated(manager);
68 EXPECT_EQ(manager.GetLifecycleState(), AppLifecycleState::kInactive);
69
70 // Hiding only visible window transitions to hidden.
71 manager.OnWindowStateEvent(win1, WindowStateEvent::kHide);
72 WaitUntilUpdated(manager);
73 EXPECT_EQ(manager.GetLifecycleState(), AppLifecycleState::kHidden);
74
75 // Transition directly from resumed to hidden when the window is hidden.
76 manager.OnWindowStateEvent(win1, WindowStateEvent::kShow);
77 manager.OnWindowStateEvent(win1, WindowStateEvent::kFocus);
78 manager.OnWindowStateEvent(win1, WindowStateEvent::kHide);
79 WaitUntilUpdated(manager);
80 EXPECT_EQ(manager.GetLifecycleState(), AppLifecycleState::kHidden);
81 }
flutter::testing::WaitUntilUpdated
static void WaitUntilUpdated(const WindowsLifecycleManager &manager)
Definition: windows_lifecycle_manager_unittests.cc:16

References flutter::kFocus, flutter::kHidden, flutter::kHide, flutter::kInactive, flutter::kResumed, flutter::kShow, flutter::kUnfocus, flutter::WindowsLifecycleManager::SetLifecycleState(), and WaitUntilUpdated().

## ◆ TEST_F() [174/204]

flutter::testing::TEST_F | ( | WindowsTest | ,
|  | AddRemoveView |
| ) |  |

Definition at line 701 of file flutter_windows_unittests.cc.

701 {
702 std::mutex mutex;
703 std::string view_ids;
704
705 auto& context = GetContext();
706 WindowsConfigBuilder builder(context);
707 builder.SetDartEntrypoint("onMetricsChangedSignalViewIds");
708
709 bool ready = false;
710 context.AddNativeFunction(
711 "Signal",
712 CREATE_NATIVE_ENTRY([&](Dart_NativeArguments args) { ready = true; }));
713
714 context.AddNativeFunction(
715 "SignalStringValue", CREATE_NATIVE_ENTRY([&](Dart_NativeArguments args) {
716 auto handle = Dart_GetNativeArgument(args, 0);
717 ASSERT_FALSE(Dart_IsError(handle));
718
719 std::scoped_lock lock{mutex};
720 view_ids = tonic::DartConverter<std::string>::FromDart(handle);
721 }));
722
723 // Create the implicit view.
724 ViewControllerPtr first_controller{builder.Run()};
725 ASSERT_NE(first_controller, nullptr);
726
727 while (!ready) {
728 PumpMessage();
729 }
730
731 // Create a second view.
732 FlutterDesktopEngineRef engine =
733 FlutterDesktopViewControllerGetEngine(first_controller.get());
734 FlutterDesktopViewControllerProperties properties = {};
735 properties.width = 100;
736 properties.height = 100;
737 ViewControllerPtr second_controller{
738 FlutterDesktopEngineCreateViewController(engine, &properties)};
739 ASSERT_NE(second_controller, nullptr);
740
741 // Pump messages for the Windows platform task runner until the view is added.
742 while (true) {
743 PumpMessage();
744 std::scoped_lock lock{mutex};
745 if (view_ids == "View IDs: [0, 1]") {
746 break;
747 }
748 }
749
750 // Delete the second view and pump messages for the Windows platform task
751 // runner until the view is removed.
752 second_controller.reset();
753 while (true) {
754 PumpMessage();
755 std::scoped_lock lock{mutex};
756 if (view_ids == "View IDs: [0]") {
757 break;
758 }
759 }
760 }
FlutterDesktopEngineCreateViewController
FlutterDesktopViewControllerRef FlutterDesktopEngineCreateViewController(FlutterDesktopEngineRef engine, const FlutterDesktopViewControllerProperties *properties)
Definition: flutter_windows.cc:129
FlutterDesktopEngineRef
struct FlutterDesktopEngine * FlutterDesktopEngineRef
Definition: flutter_windows.h:33
FlutterDesktopViewControllerProperties
Definition: flutter_windows_internal.h:18
FlutterDesktopViewControllerProperties::width
int width
Definition: flutter_windows_internal.h:20
FlutterDesktopViewControllerProperties::height
int height
Definition: flutter_windows_internal.h:23

References FlutterDesktopEngineCreateViewController(), FlutterDesktopViewControllerGetEngine(), FlutterDesktopViewControllerProperties::height, and FlutterDesktopViewControllerProperties::width.

## ◆ TEST_F() [175/204]

flutter::testing::TEST_F | ( | WindowsTest | ,
|  | EnableIAccessible |
| ) |  |

Definition at line 788 of file flutter_windows_unittests.cc.

788 {
789 auto& context = GetContext();
790 WindowsConfigBuilder builder(context);
791 builder.SetAccessibilityMode(
792 FlutterDesktopAccessibilityMode::IAccessibleMode);
793 builder.SetDartEntrypoint("sendSemanticsTree");
794
795 // Setup: a signal for when we have send out all of our semantics updates
796 bool done = false;
797 auto native_entry =
798 CREATE_NATIVE_ENTRY([&](Dart_NativeArguments args) { done = true; });
799 context.AddNativeFunction("Signal", native_entry);
800
801 // Setup: Create a view
802 ViewControllerPtr controller{builder.Run()};
803 ASSERT_NE(controller, nullptr);
804
805 auto view = FlutterDesktopViewControllerGetView(controller.get());
806 ASSERT_NE(view, nullptr);
807
808 // Setup: UpdateSemanticsEnabled will trigger the semantics updates
809 // to get sent.
810 auto windows_view = reinterpret_cast<FlutterWindowsView*>(view);
811 windows_view->OnUpdateSemanticsEnabled(true);
812
813 while (!done) {
814 PumpMessage();
815 }
816
817 HWND hwnd = FlutterDesktopViewGetHWND(view);
818 ASSERT_NE(hwnd, nullptr);
819
820 LRESULT lres = SendMessage(hwnd, WM_GETOBJECT, 0, OBJID_CLIENT);
821 ASSERT_NE(lres, 0);
822
823 // In IAccessible mode, the object returned from WM_GETOBJECT should support
824 // IAccessible but not IAccessibleEx.
825 IAccessible* accessible = nullptr;
826 HRESULT hr = ObjectFromLresult(lres, IID_IAccessible, 0, (void**)&accessible);
827 ASSERT_TRUE(SUCCEEDED(hr));
828 ASSERT_NE(accessible, nullptr);
829
830 IAccessibleEx* accessible_ex = nullptr;
831 hr = ObjectFromLresult(lres, IID_IAccessibleEx, 0, (void**)&accessible_ex);
832 ASSERT_TRUE(FAILED(hr));
833 ASSERT_EQ(accessible_ex, nullptr);
834 }
FlutterDesktopViewGetHWND
HWND FlutterDesktopViewGetHWND(FlutterDesktopViewRef view)
Definition: flutter_windows.cc:253
FlutterDesktopViewControllerGetView
FlutterDesktopViewRef FlutterDesktopViewControllerGetView(FlutterDesktopViewControllerRef ref)
Definition: flutter_windows.cc:154
IAccessibleMode
@ IAccessibleMode
Definition: flutter_windows.h:69
flutter::AccessibilityMode::IAccessibleEx
@ IAccessibleEx

References FlutterDesktopViewControllerGetView(), FlutterDesktopViewGetHWND(), flutter::IAccessible, flutter::IAccessibleEx, IAccessibleMode, and flutter::FlutterWindowsView::OnUpdateSemanticsEnabled().

## ◆ TEST_F() [176/204]

flutter::testing::TEST_F | ( | WindowsTest | ,
|  | EnableIAccessibleEx |
| ) |  |

Definition at line 836 of file flutter_windows_unittests.cc.

836 {
837 auto& context = GetContext();
838 WindowsConfigBuilder builder(context);
839 builder.SetAccessibilityMode(
840 FlutterDesktopAccessibilityMode::IAccessibleExMode);
841 builder.SetDartEntrypoint("sendSemanticsTree");
842
843 // Setup: a signal for when we have send out all of our semantics updates
844 bool done = false;
845 auto native_entry =
846 CREATE_NATIVE_ENTRY([&](Dart_NativeArguments args) { done = true; });
847 context.AddNativeFunction("Signal", native_entry);
848
849 // Setup: Create a view
850 ViewControllerPtr controller{builder.Run()};
851 ASSERT_NE(controller, nullptr);
852
853 auto view = FlutterDesktopViewControllerGetView(controller.get());
854 ASSERT_NE(view, nullptr);
855
856 // Setup: UpdateSemanticsEnabled will trigger the semantics updates
857 // to get sent.
858 auto windows_view = reinterpret_cast<FlutterWindowsView*>(view);
859 windows_view->OnUpdateSemanticsEnabled(true);
860
861 while (!done) {
862 PumpMessage();
863 }
864
865 HWND hwnd = FlutterDesktopViewGetHWND(view);
866 ASSERT_NE(hwnd, nullptr);
867
868 LRESULT lres = SendMessage(hwnd, WM_GETOBJECT, 0, OBJID_CLIENT);
869 ASSERT_NE(lres, 0);
870
871 // In IAccessibleEx mode, the object returned from WM_GETOBJECT should
872 // support IAccessibleEx.
873 IAccessibleEx* accessible_ex = nullptr;
874 HRESULT hr =
875 ObjectFromLresult(lres, IID_IAccessibleEx, 0, (void**)&accessible_ex);
876 ASSERT_TRUE(SUCCEEDED(hr));
877 ASSERT_NE(accessible_ex, nullptr);
878 accessible_ex->Release();
879 }
IAccessibleExMode
@ IAccessibleExMode
Definition: flutter_windows.h:71

References FlutterDesktopViewControllerGetView(), FlutterDesktopViewGetHWND(), flutter::IAccessibleEx, IAccessibleExMode, and flutter::FlutterWindowsView::OnUpdateSemanticsEnabled().

## ◆ TEST_F() [177/204]

flutter::testing::TEST_F | ( | WindowsTest | ,
|  | EngineCanTransitionToHeadless |
| ) |  |

Definition at line 155 of file flutter_windows_unittests.cc.

155 {
156 auto& context = GetContext();
157 WindowsConfigBuilder builder(context);
158 EnginePtr engine{builder.RunHeadless()};
159 ASSERT_NE(engine, nullptr);
160
161 // Create and then destroy a view controller that does not own its engine.
162 // This causes the engine to transition back to headless mode.
163 {
164 FlutterDesktopViewControllerProperties properties = {};
165 ViewControllerPtr controller{
166 FlutterDesktopEngineCreateViewController(engine.get(), &properties)};
167
168 ASSERT_NE(controller, nullptr);
169 }
170
171 // The engine is back in headless mode now.
172 ASSERT_NE(engine, nullptr);
173
174 auto engine_ptr = reinterpret_cast<FlutterWindowsEngine*>(engine.get());
175 ASSERT_TRUE(engine_ptr->running());
176 }

References FlutterDesktopEngineCreateViewController().

## ◆ TEST_F() [178/204]

flutter::testing::TEST_F | ( | WindowsTest | ,
|  | EngineId |
| ) |  |

Definition at line 762 of file flutter_windows_unittests.cc.

762 {
763 auto& context = GetContext();
764 WindowsConfigBuilder builder(context);
765 builder.SetDartEntrypoint("testEngineId");
766
767 std::optional<int64_t> engineId;
768 context.AddNativeFunction(
769 "NotifyEngineId", CREATE_NATIVE_ENTRY([&](Dart_NativeArguments args) {
770 const auto argument = Dart_GetNativeArgument(args, 0);
771 if (!Dart_IsNull(argument)) {
772 const auto handle = tonic::DartConverter<int64_t>::FromDart(argument);
773 engineId = handle;
774 }
775 }));
776 // Create the implicit view.
777 ViewControllerPtr first_controller{builder.Run()};
778 ASSERT_NE(first_controller, nullptr);
779
780 while (!engineId.has_value()) {
781 PumpMessage();
782 }
783
784 auto engine = FlutterDesktopViewControllerGetEngine(first_controller.get());
785 EXPECT_EQ(engine, FlutterDesktopEngineForId(*engineId));
786 }
FlutterDesktopEngineForId
FLUTTER_EXPORT FlutterDesktopEngineRef FlutterDesktopEngineForId(int64_t engine_id)
Definition: flutter_windows.cc:202

References FlutterDesktopEngineForId(), and FlutterDesktopViewControllerGetEngine().

## ◆ TEST_F() [179/204]

flutter::testing::TEST_F | ( | WindowsTest | ,
|  | GetEngineGraphicsAdapter |
| ) |  |

Definition at line 435 of file flutter_windows_unittests.cc.

435 {
436 auto& context = GetContext();
437 WindowsConfigBuilder builder(context);
438 ViewControllerPtr controller{builder.Run()};
439 ASSERT_NE(controller, nullptr);
440 auto engine = FlutterDesktopViewControllerGetEngine(controller.get());
441
442 Microsoft::WRL::ComPtr<IDXGIAdapter> dxgi_adapter;
443 dxgi_adapter = FlutterDesktopEngineGetGraphicsAdapter(engine);
444 ASSERT_NE(dxgi_adapter, nullptr);
445 DXGI_ADAPTER_DESC desc{};
446 ASSERT_TRUE(SUCCEEDED(dxgi_adapter->GetDesc(&desc)));
447 }
FlutterDesktopEngineGetGraphicsAdapter
IDXGIAdapter * FlutterDesktopEngineGetGraphicsAdapter(FlutterDesktopEngineRef engine)
Definition: flutter_windows.cc:262

References FlutterDesktopEngineGetGraphicsAdapter(), and FlutterDesktopViewControllerGetEngine().

## ◆ TEST_F() [180/204]

flutter::testing::TEST_F | ( | WindowsTest | ,
|  | GetEngineGraphicsAdapterWithHighPerformancePreference |
| ) |  |

Definition at line 516 of file flutter_windows_unittests.cc.

516 {
517 std::optional<LUID> luid = egl::Manager::GetHighPerformanceGpuLuid();
518 if (!luid) {
519 GTEST_SKIP() << "Not able to find high performance GPU, nothing to check.";
520 }
521
522 auto& context = GetContext();
523 WindowsConfigBuilder builder(context);
524 builder.SetGpuPreference(
525 FlutterDesktopGpuPreference::HighPerformancePreference);
526 ViewControllerPtr controller{builder.Run()};
527 ASSERT_NE(controller, nullptr);
528 auto engine = FlutterDesktopViewControllerGetEngine(controller.get());
529
530 Microsoft::WRL::ComPtr<IDXGIAdapter> dxgi_adapter;
531 dxgi_adapter = FlutterDesktopEngineGetGraphicsAdapter(engine);
532 ASSERT_NE(dxgi_adapter, nullptr);
533 DXGI_ADAPTER_DESC desc{};
534 ASSERT_TRUE(SUCCEEDED(dxgi_adapter->GetDesc(&desc)));
535 ASSERT_EQ(desc.AdapterLuid.HighPart, luid->HighPart);
536 ASSERT_EQ(desc.AdapterLuid.LowPart, luid->LowPart);
537 }
HighPerformancePreference
@ HighPerformancePreference
Definition: flutter_windows.h:49

References FlutterDesktopEngineGetGraphicsAdapter(), FlutterDesktopViewControllerGetEngine(), flutter::egl::Manager::GetHighPerformanceGpuLuid(), and HighPerformancePreference.

## ◆ TEST_F() [181/204]

flutter::testing::TEST_F | ( | WindowsTest | ,
|  | GetEngineGraphicsAdapterWithLowPowerPreference |
| ) |  |

Definition at line 494 of file flutter_windows_unittests.cc.

494 {
495 std::optional<LUID> luid = egl::Manager::GetLowPowerGpuLuid();
496 if (!luid) {
497 GTEST_SKIP() << "Not able to find low power GPU, nothing to check.";
498 }
499
500 auto& context = GetContext();
501 WindowsConfigBuilder builder(context);
502 builder.SetGpuPreference(FlutterDesktopGpuPreference::LowPowerPreference);
503 ViewControllerPtr controller{builder.Run()};
504 ASSERT_NE(controller, nullptr);
505 auto engine = FlutterDesktopViewControllerGetEngine(controller.get());
506
507 Microsoft::WRL::ComPtr<IDXGIAdapter> dxgi_adapter;
508 dxgi_adapter = FlutterDesktopEngineGetGraphicsAdapter(engine);
509 ASSERT_NE(dxgi_adapter, nullptr);
510 DXGI_ADAPTER_DESC desc{};
511 ASSERT_TRUE(SUCCEEDED(dxgi_adapter->GetDesc(&desc)));
512 ASSERT_EQ(desc.AdapterLuid.HighPart, luid->HighPart);
513 ASSERT_EQ(desc.AdapterLuid.LowPart, luid->LowPart);
514 }
LowPowerPreference
@ LowPowerPreference
Definition: flutter_windows.h:45

References FlutterDesktopEngineGetGraphicsAdapter(), FlutterDesktopViewControllerGetEngine(), flutter::egl::Manager::GetLowPowerGpuLuid(), and LowPowerPreference.

## ◆ TEST_F() [182/204]

flutter::testing::TEST_F | ( | WindowsTest | ,
|  | GetGraphicsAdapter |
| ) |  |

Definition at line 421 of file flutter_windows_unittests.cc.

421 {
422 auto& context = GetContext();
423 WindowsConfigBuilder builder(context);
424 ViewControllerPtr controller{builder.Run()};
425 ASSERT_NE(controller, nullptr);
426 auto view = FlutterDesktopViewControllerGetView(controller.get());
427
428 Microsoft::WRL::ComPtr<IDXGIAdapter> dxgi_adapter;
429 dxgi_adapter = FlutterDesktopViewGetGraphicsAdapter(view);
430 ASSERT_NE(dxgi_adapter, nullptr);
431 DXGI_ADAPTER_DESC desc{};
432 ASSERT_TRUE(SUCCEEDED(dxgi_adapter->GetDesc(&desc)));
433 }
FlutterDesktopViewGetGraphicsAdapter
IDXGIAdapter * FlutterDesktopViewGetGraphicsAdapter(FlutterDesktopViewRef view)
Definition: flutter_windows.cc:257

References FlutterDesktopViewControllerGetView(), and FlutterDesktopViewGetGraphicsAdapter().

## ◆ TEST_F() [183/204]

flutter::testing::TEST_F | ( | WindowsTest | ,
|  | GetGraphicsAdapterWithHighPerformancePreference |
| ) |  |

Definition at line 471 of file flutter_windows_unittests.cc.

471 {
472 std::optional<LUID> luid = egl::Manager::GetHighPerformanceGpuLuid();
473 if (!luid) {
474 GTEST_SKIP() << "Not able to find high performance GPU, nothing to check.";
475 }
476
477 auto& context = GetContext();
478 WindowsConfigBuilder builder(context);
479 builder.SetGpuPreference(
480 FlutterDesktopGpuPreference::HighPerformancePreference);
481 ViewControllerPtr controller{builder.Run()};
482 ASSERT_NE(controller, nullptr);
483 auto view = FlutterDesktopViewControllerGetView(controller.get());
484
485 Microsoft::WRL::ComPtr<IDXGIAdapter> dxgi_adapter;
486 dxgi_adapter = FlutterDesktopViewGetGraphicsAdapter(view);
487 ASSERT_NE(dxgi_adapter, nullptr);
488 DXGI_ADAPTER_DESC desc{};
489 ASSERT_TRUE(SUCCEEDED(dxgi_adapter->GetDesc(&desc)));
490 ASSERT_EQ(desc.AdapterLuid.HighPart, luid->HighPart);
491 ASSERT_EQ(desc.AdapterLuid.LowPart, luid->LowPart);
492 }

References FlutterDesktopViewControllerGetView(), FlutterDesktopViewGetGraphicsAdapter(), flutter::egl::Manager::GetHighPerformanceGpuLuid(), and HighPerformancePreference.

## ◆ TEST_F() [184/204]

flutter::testing::TEST_F | ( | WindowsTest | ,
|  | GetGraphicsAdapterWithLowPowerPreference |
| ) |  |

Definition at line 449 of file flutter_windows_unittests.cc.

449 {
450 std::optional<LUID> luid = egl::Manager::GetLowPowerGpuLuid();
451 if (!luid) {
452 GTEST_SKIP() << "Not able to find low power GPU, nothing to check.";
453 }
454
455 auto& context = GetContext();
456 WindowsConfigBuilder builder(context);
457 builder.SetGpuPreference(FlutterDesktopGpuPreference::LowPowerPreference);
458 ViewControllerPtr controller{builder.Run()};
459 ASSERT_NE(controller, nullptr);
460 auto view = FlutterDesktopViewControllerGetView(controller.get());
461
462 Microsoft::WRL::ComPtr<IDXGIAdapter> dxgi_adapter;
463 dxgi_adapter = FlutterDesktopViewGetGraphicsAdapter(view);
464 ASSERT_NE(dxgi_adapter, nullptr);
465 DXGI_ADAPTER_DESC desc{};
466 ASSERT_TRUE(SUCCEEDED(dxgi_adapter->GetDesc(&desc)));
467 ASSERT_EQ(desc.AdapterLuid.HighPart, luid->HighPart);
468 ASSERT_EQ(desc.AdapterLuid.LowPart, luid->LowPart);
469 }

References FlutterDesktopViewControllerGetView(), FlutterDesktopViewGetGraphicsAdapter(), flutter::egl::Manager::GetLowPowerGpuLuid(), and LowPowerPreference.

## ◆ TEST_F() [185/204]

flutter::testing::TEST_F | ( | WindowsTest | ,
|  | GetKeyboardStateHeadless |
| ) |  |

Definition at line 675 of file flutter_windows_unittests.cc.

675 {
676 auto& context = GetContext();
677 WindowsConfigBuilder builder(context);
678 builder.SetDartEntrypoint("sendGetKeyboardState");
679
680 std::atomic<bool> done = false;
681 context.AddNativeFunction(
682 "SignalStringValue", CREATE_NATIVE_ENTRY([&](Dart_NativeArguments args) {
683 auto handle = Dart_GetNativeArgument(args, 0);
684 ASSERT_FALSE(Dart_IsError(handle));
685 auto value = tonic::DartConverter<std::string>::FromDart(handle);
686 EXPECT_EQ(value, "Success");
687 done = true;
688 }));
689
690 ViewControllerPtr controller{builder.Run()};
691 ASSERT_NE(controller, nullptr);
692
693 // Pump messages for the Windows platform task runner.
694 ::MSG msg;
695 while (!done) {
696 PumpMessage();
697 }
698 }

## ◆ TEST_F() [186/204]

flutter::testing::TEST_F | ( | WindowsTest | ,
|  | GetViewId |
| ) |  |

Definition at line 410 of file flutter_windows_unittests.cc.

410 {
411 auto& context = GetContext();
412 WindowsConfigBuilder builder(context);
413 ViewControllerPtr controller{builder.Run()};
414 ASSERT_NE(controller, nullptr);
415 FlutterDesktopViewId view_id =
416 FlutterDesktopViewControllerGetViewId(controller.get());
417
418 ASSERT_EQ(view_id, static_cast<FlutterDesktopViewId>(kImplicitViewId));
419 }
FlutterDesktopViewControllerGetViewId
FlutterDesktopViewId FlutterDesktopViewControllerGetViewId(FlutterDesktopViewControllerRef ref)
Definition: flutter_windows.cc:142
FlutterDesktopViewId
int64_t FlutterDesktopViewId
Definition: flutter_windows.h:36

References FlutterDesktopViewControllerGetViewId(), and flutter::kImplicitViewId.

## ◆ TEST_F() [187/204]

flutter::testing::TEST_F | ( | WindowsTest | ,
|  | LaunchConflictingCustomEntrypoints |
| ) |  |

Definition at line 204 of file flutter_windows_unittests.cc.

204 {
205 auto& context = GetContext();
206 WindowsConfigBuilder builder(context);
207 builder.SetDartEntrypoint("customEntrypoint");
208 EnginePtr engine{builder.InitializeEngine()};
209 ASSERT_NE(engine, nullptr);
210
211 ASSERT_FALSE(FlutterDesktopEngineRun(engine.get(), "conflictingEntrypoint"));
212 }
FlutterDesktopEngineRun
bool FlutterDesktopEngineRun(FlutterDesktopEngineRef engine, const char *entry_point)
Definition: flutter_windows.cc:207

References FlutterDesktopEngineRun().

## ◆ TEST_F() [188/204]

flutter::testing::TEST_F | ( | WindowsTest | ,
|  | LaunchCustomEntrypoint |
| ) |  |

Definition at line 103 of file flutter_windows_unittests.cc.

103 {
104 auto& context = GetContext();
105 WindowsConfigBuilder builder(context);
106 builder.SetDartEntrypoint("customEntrypoint");
107 ViewControllerPtr controller{builder.Run()};
108 ASSERT_NE(controller, nullptr);
109 }

## ◆ TEST_F() [189/204]

flutter::testing::TEST_F | ( | WindowsTest | ,
|  | LaunchCustomEntrypointInEngineRunInvocation |
| ) |  |

Definition at line 116 of file flutter_windows_unittests.cc.

116 {
117 auto& context = GetContext();
118 WindowsConfigBuilder builder(context);
119 EnginePtr engine{builder.InitializeEngine()};
120 ASSERT_NE(engine, nullptr);
121
122 ASSERT_TRUE(FlutterDesktopEngineRun(engine.get(), "customEntrypoint"));
123 }

References FlutterDesktopEngineRun().

## ◆ TEST_F() [190/204]

flutter::testing::TEST_F | ( | WindowsTest | ,
|  | LaunchHeadlessEngine |
| ) |  |

Definition at line 126 of file flutter_windows_unittests.cc.

126 {
127 auto& context = GetContext();
128 WindowsConfigBuilder builder(context);
129 builder.SetDartEntrypoint("signalViewIds");
130 EnginePtr engine{builder.RunHeadless()};
131 ASSERT_NE(engine, nullptr);
132
133 std::string view_ids;
134 bool signaled = false;
135 context.AddNativeFunction(
136 "SignalStringValue", CREATE_NATIVE_ENTRY([&](Dart_NativeArguments args) {
137 auto handle = Dart_GetNativeArgument(args, 0);
138 ASSERT_FALSE(Dart_IsError(handle));
139 view_ids = tonic::DartConverter<std::string>::FromDart(handle);
140 signaled = true;
141 }));
142
143 ViewControllerPtr controller{builder.Run()};
144 ASSERT_NE(controller, nullptr);
145
146 while (!signaled) {
147 PumpMessage();
148 }
149
150 // Verify a headless app has the implicit view.
151 EXPECT_EQ(view_ids, "View IDs: [0]");
152 }

## ◆ TEST_F() [191/204]

flutter::testing::TEST_F | ( | WindowsTest | ,
|  | LaunchMain |
| ) |  |

Definition at line 78 of file flutter_windows_unittests.cc.

78 {
79 auto& context = GetContext();
80 WindowsConfigBuilder builder(context);
81 ViewControllerPtr controller{builder.Run()};
82 ASSERT_NE(controller, nullptr);
83 }

## ◆ TEST_F() [192/204]

flutter::testing::TEST_F | ( | WindowsTest | ,
|  | LaunchMainHasNoOutput |
| ) |  |

Definition at line 86 of file flutter_windows_unittests.cc.

86 {
87 // Replace stderr stream buffer with our own. (stdout may contain expected
88 // output printed by Dart, such as the Dart VM service startup message)
89 StreamCapture stderr_capture(&std::cerr);
90
91 auto& context = GetContext();
92 WindowsConfigBuilder builder(context);
93 ViewControllerPtr controller{builder.Run()};
94 ASSERT_NE(controller, nullptr);
95
96 stderr_capture.Stop();
97
98 // Verify stderr has no output.
99 EXPECT_TRUE(stderr_capture.GetOutput().empty());
100 }

## ◆ TEST_F() [193/204]

flutter::testing::TEST_F | ( | WindowsTest | ,
|  | LaunchRefreshesAccessibility |
| ) |  |

Definition at line 179 of file flutter_windows_unittests.cc.

179 {
180 auto& context = GetContext();
181 WindowsConfigBuilder builder(context);
182 EnginePtr engine{builder.InitializeEngine()};
183 EngineModifier modifier{
184 reinterpret_cast<FlutterWindowsEngine*>(engine.get())};
185
186 auto called = false;
187 modifier.embedder_api().UpdateAccessibilityFeatures = MOCK_ENGINE_PROC(
188 UpdateAccessibilityFeatures, ([&called](auto engine, auto flags) {
189 called = true;
190 return kSuccess;
191 }));
192
193 ViewControllerPtr controller{
194 FlutterDesktopViewControllerCreate(0, 0, engine.release())};
195
196 ASSERT_TRUE(called);
197 }
FlutterDesktopViewControllerCreate
FlutterDesktopViewControllerRef FlutterDesktopViewControllerCreate(int width, int height, FlutterDesktopEngineRef engine)
Definition: flutter_windows.cc:122

References FlutterDesktopViewControllerCreate(), and flutter::FlutterWindowsEngine::UpdateAccessibilityFeatures().

## ◆ TEST_F() [194/204]

flutter::testing::TEST_F | ( | WindowsTest | ,
|  | Lifecycle |
| ) |  |

Definition at line 617 of file flutter_windows_unittests.cc.

617 {
618 auto& context = GetContext();
619 WindowsConfigBuilder builder(context);
620 EnginePtr engine{builder.InitializeEngine()};
621 auto windows_engine = reinterpret_cast<FlutterWindowsEngine*>(engine.get());
622 EngineModifier modifier{windows_engine};
623
624 auto lifecycle_manager =
625 std::make_unique<MockWindowsLifecycleManager>(windows_engine);
626 auto lifecycle_manager_ptr = lifecycle_manager.get();
627 modifier.SetLifecycleManager(std::move(lifecycle_manager));
628
629 EXPECT_CALL(*lifecycle_manager_ptr,
630 SetLifecycleState(AppLifecycleState::kInactive))
631 .WillOnce([lifecycle_manager_ptr](AppLifecycleState state) {
632 lifecycle_manager_ptr->WindowsLifecycleManager::SetLifecycleState(
633 state);
634 });
635
636 EXPECT_CALL(*lifecycle_manager_ptr,
637 SetLifecycleState(AppLifecycleState::kHidden))
638 .WillOnce([lifecycle_manager_ptr](AppLifecycleState state) {
639 lifecycle_manager_ptr->WindowsLifecycleManager::SetLifecycleState(
640 state);
641 });
642
643 FlutterDesktopViewControllerProperties properties = {0, 0};
644
645 // Create a controller. This launches the engine and sets the app lifecycle
646 // to the "resumed" state.
647 ViewControllerPtr controller{
648 FlutterDesktopEngineCreateViewController(engine.get(), &properties)};
649
650 FlutterDesktopViewRef view =
651 FlutterDesktopViewControllerGetView(controller.get());
652 ASSERT_NE(view, nullptr);
653
654 HWND hwnd = FlutterDesktopViewGetHWND(view);
655 ASSERT_NE(hwnd, nullptr);
656
657 // Give the window a non-zero size to show it. This does not change the app
658 // lifecycle directly. However, destroying the view will now result in a
659 // "hidden" app lifecycle event.
660 ::MoveWindow(hwnd, /* X */ 0, /* Y */ 0, /* nWidth*/ 100, /* nHeight*/ 100,
661 /* bRepaint*/ false);
662
663 while (lifecycle_manager_ptr->IsUpdateStateScheduled()) {
664 PumpMessage();
665 }
666
667 // Resets the view, simulating the window being hidden.
668 controller.reset();
669
670 while (lifecycle_manager_ptr->IsUpdateStateScheduled()) {
671 PumpMessage();
672 }
673 }
FlutterDesktopViewRef
struct FlutterDesktopView * FlutterDesktopViewRef
Definition: flutter_windows.h:29

References FlutterDesktopEngineCreateViewController(), FlutterDesktopViewControllerGetView(), FlutterDesktopViewGetHWND(), flutter::kHidden, and flutter::kInactive.

## ◆ TEST_F() [195/204]

flutter::testing::TEST_F | ( | WindowsTest | ,
|  | NextFrameCallback |
| ) |  |

Definition at line 320 of file flutter_windows_unittests.cc.

320 {
321 struct Captures {
322 fml::AutoResetWaitableEvent frame_scheduled_latch;
323 std::thread::id thread_id;
324 bool done = false;
325 };
326 Captures captures;
327
328 auto platform_thread = std::make_unique<fml::Thread>("test_platform_thread");
329 platform_thread->GetTaskRunner()->PostTask([&]() {
330 captures.thread_id = std::this_thread::get_id();
331
332 auto& context = GetContext();
333 WindowsConfigBuilder builder(context);
334 builder.SetDartEntrypoint("drawHelloWorld");
335
336 auto native_entry = CREATE_NATIVE_ENTRY([&](Dart_NativeArguments args) {
337 captures.frame_scheduled_latch.Signal();
338 });
339 context.AddNativeFunction("NotifyFirstFrameScheduled", native_entry);
340
341 ViewControllerPtr controller{builder.Run()};
342 EXPECT_NE(controller, nullptr);
343
344 auto engine = FlutterDesktopViewControllerGetEngine(controller.get());
345
346 FlutterDesktopEngineSetNextFrameCallback(
347 engine,
348 [](void* user_data) {
349 auto captures = static_cast<Captures*>(user_data);
350
351 EXPECT_TRUE(captures->frame_scheduled_latch.IsSignaledForTest());
352
353 // Callback should execute on platform thread.
354 EXPECT_EQ(std::this_thread::get_id(), captures->thread_id);
355
356 // Signal the test passed and end the Windows message loop.
357 captures->done = true;
358 },
359 &captures);
360
361 // Pump messages for the Windows platform task runner.
362 while (!captures.done) {
363 PumpMessage();
364 }
365 });
366
367 // Wait for the platform thread to exit.
368 platform_thread->Join();
369 }
FlutterDesktopEngineSetNextFrameCallback
void FlutterDesktopEngineSetNextFrameCallback(FlutterDesktopEngineRef engine, VoidCallback callback, void *user_data)
Definition: flutter_windows.cc:246

References FlutterDesktopEngineSetNextFrameCallback(), FlutterDesktopViewControllerGetEngine(), and user_data.

## ◆ TEST_F() [196/204]

flutter::testing::TEST_F | ( | WindowsTest | ,
|  | PlatformExecutable |
| ) |  |

Definition at line 261 of file flutter_windows_unittests.cc.

261 {
262 auto& context = GetContext();
263 WindowsConfigBuilder builder(context);
264 builder.SetDartEntrypoint("readPlatformExecutable");
265
266 std::string executable_name;
267 bool signaled = false;
268 auto native_entry = CREATE_NATIVE_ENTRY([&](Dart_NativeArguments args) {
269 auto handle = Dart_GetNativeArgument(args, 0);
270 ASSERT_FALSE(Dart_IsError(handle));
271 executable_name = tonic::DartConverter<std::string>::FromDart(handle);
272 signaled = true;
273 });
274 context.AddNativeFunction("SignalStringValue", native_entry);
275
276 ViewControllerPtr controller{builder.Run()};
277 ASSERT_NE(controller, nullptr);
278
279 // Wait until signalStringValue has been called.
280 while (!signaled) {
281 PumpMessage();
282 }
283 EXPECT_EQ(executable_name, "flutter_windows_unittests.exe");
284 }

## ◆ TEST_F() [197/204]

flutter::testing::TEST_F | ( | WindowsTest | ,
|  | PluginRegistrarGetImplicitView |
| ) |  |

Definition at line 540 of file flutter_windows_unittests.cc.

540 {
541 auto& context = GetContext();
542 WindowsConfigBuilder builder(context);
543 ViewControllerPtr controller{builder.Run()};
544 ASSERT_NE(controller, nullptr);
545
546 FlutterDesktopEngineRef engine =
547 FlutterDesktopViewControllerGetEngine(controller.get());
548 FlutterDesktopPluginRegistrarRef registrar =
549 FlutterDesktopEngineGetPluginRegistrar(engine, "foo_bar");
550 FlutterDesktopViewRef implicit_view =
551 FlutterDesktopPluginRegistrarGetView(registrar);
552
553 ASSERT_NE(implicit_view, nullptr);
554 }
FlutterDesktopEngineGetPluginRegistrar
FlutterDesktopPluginRegistrarRef FlutterDesktopEngineGetPluginRegistrar(FlutterDesktopEngineRef engine, const char *plugin_name)
Definition: flutter_windows.cc:225
FlutterDesktopPluginRegistrarGetView
FlutterDesktopViewRef FlutterDesktopPluginRegistrarGetView(FlutterDesktopPluginRegistrarRef registrar)
Definition: flutter_windows.cc:303

References FlutterDesktopEngineGetPluginRegistrar(), FlutterDesktopPluginRegistrarGetView(), and FlutterDesktopViewControllerGetEngine().

## ◆ TEST_F() [198/204]

flutter::testing::TEST_F | ( | WindowsTest | ,
|  | PluginRegistrarGetView |
| ) |  |

Definition at line 556 of file flutter_windows_unittests.cc.

556 {
557 auto& context = GetContext();
558 WindowsConfigBuilder builder(context);
559 ViewControllerPtr controller{builder.Run()};
560 ASSERT_NE(controller, nullptr);
561
562 FlutterDesktopEngineRef engine =
563 FlutterDesktopViewControllerGetEngine(controller.get());
564 FlutterDesktopPluginRegistrarRef registrar =
565 FlutterDesktopEngineGetPluginRegistrar(engine, "foo_bar");
566
567 FlutterDesktopViewId view_id =
568 FlutterDesktopViewControllerGetViewId(controller.get());
569 FlutterDesktopViewRef view =
570 FlutterDesktopPluginRegistrarGetViewById(registrar, view_id);
571
572 FlutterDesktopViewRef view_123 = FlutterDesktopPluginRegistrarGetViewById(
573 registrar, static_cast<FlutterDesktopViewId>(123));
574
575 ASSERT_NE(view, nullptr);
576 ASSERT_EQ(view_123, nullptr);
577 }
FlutterDesktopPluginRegistrarGetViewById
FlutterDesktopViewRef FlutterDesktopPluginRegistrarGetViewById(FlutterDesktopPluginRegistrarRef registrar, FlutterDesktopViewId view_id)
Definition: flutter_windows.cc:308

References FlutterDesktopEngineGetPluginRegistrar(), FlutterDesktopPluginRegistrarGetViewById(), FlutterDesktopViewControllerGetEngine(), and FlutterDesktopViewControllerGetViewId().

## ◆ TEST_F() [199/204]

flutter::testing::TEST_F | ( | WindowsTest | ,
|  | PluginRegistrarGetViewHeadless |
| ) |  |

Definition at line 579 of file flutter_windows_unittests.cc.

579 {
580 auto& context = GetContext();
581 WindowsConfigBuilder builder(context);
582 EnginePtr engine{builder.RunHeadless()};
583 ASSERT_NE(engine, nullptr);
584
585 FlutterDesktopPluginRegistrarRef registrar =
586 FlutterDesktopEngineGetPluginRegistrar(engine.get(), "foo_bar");
587
588 FlutterDesktopViewRef implicit_view =
589 FlutterDesktopPluginRegistrarGetView(registrar);
590 FlutterDesktopViewRef view_123 = FlutterDesktopPluginRegistrarGetViewById(
591 registrar, static_cast<FlutterDesktopViewId>(123));
592
593 ASSERT_EQ(implicit_view, nullptr);
594 ASSERT_EQ(view_123, nullptr);
595 }

References FlutterDesktopEngineGetPluginRegistrar(), FlutterDesktopPluginRegistrarGetView(), and FlutterDesktopPluginRegistrarGetViewById().

## ◆ TEST_F() [200/204]

flutter::testing::TEST_F | ( | WindowsTest | ,
|  | PresentHeadless |
| ) |  |

Definition at line 373 of file flutter_windows_unittests.cc.

373 {
374 auto& context = GetContext();
375 WindowsConfigBuilder builder(context);
376 builder.SetDartEntrypoint("renderImplicitView");
377
378 EnginePtr engine{builder.RunHeadless()};
379 ASSERT_NE(engine, nullptr);
380
381 bool done = false;
382 FlutterDesktopEngineSetNextFrameCallback(
383 engine.get(),
384 [](void* user_data) {
385 // This executes on the platform thread.
386 auto done = reinterpret_cast<std::atomic<bool>*>(user_data);
387 *done = true;
388 },
389 &done);
390
391 // This app is in headless mode, however, the engine assumes the implicit
392 // view always exists. Send window metrics for the implicit view, causing
393 // the engine to present to the implicit view. The embedder must not crash.
394 auto engine_ptr = reinterpret_cast<FlutterWindowsEngine*>(engine.get());
395 FlutterWindowMetricsEvent metrics = {};
396 metrics.struct_size = sizeof(FlutterWindowMetricsEvent);
397 metrics.width = 100;
398 metrics.height = 100;
399 metrics.pixel_ratio = 1.0;
400 metrics.view_id = kImplicitViewId;
401 engine_ptr->SendWindowMetricsEvent(metrics);
402
403 // Pump messages for the Windows platform task runner.
404 while (!done) {
405 PumpMessage();
406 }
407 }

References FlutterDesktopEngineSetNextFrameCallback(), flutter::kImplicitViewId, and user_data.

## ◆ TEST_F() [201/204]

flutter::testing::TEST_F | ( | WindowsTest | ,
|  | SurfaceOptional |
| ) |  |

Definition at line 599 of file flutter_windows_unittests.cc.

599 {
600 auto& context = GetContext();
601 WindowsConfigBuilder builder(context);
602 EnginePtr engine{builder.InitializeEngine()};
603 EngineModifier modifier{
604 reinterpret_cast<FlutterWindowsEngine*>(engine.get())};
605
606 auto egl_manager = std::make_unique<HalfBrokenEGLManager>();
607 ASSERT_TRUE(egl_manager->IsValid());
608 modifier.SetEGLManager(std::move(egl_manager));
609
610 ViewControllerPtr controller{
611 FlutterDesktopViewControllerCreate(0, 0, engine.release())};
612
613 ASSERT_NE(controller, nullptr);
614 }

References FlutterDesktopViewControllerCreate().

## ◆ TEST_F() [202/204]

flutter::testing::TEST_F | ( | WindowsTest | ,
|  | VerifyNativeFunction |
| ) |  |

Definition at line 215 of file flutter_windows_unittests.cc.

215 {
216 auto& context = GetContext();
217 WindowsConfigBuilder builder(context);
218 builder.SetDartEntrypoint("verifyNativeFunction");
219
220 bool signaled = false;
221 auto native_entry =
222 CREATE_NATIVE_ENTRY([&](Dart_NativeArguments args) { signaled = true; });
223 context.AddNativeFunction("Signal", native_entry);
224
225 ViewControllerPtr controller{builder.Run()};
226 ASSERT_NE(controller, nullptr);
227
228 // Wait until signal has been called.
229 while (!signaled) {
230 PumpMessage();
231 }
232 }

## ◆ TEST_F() [203/204]

flutter::testing::TEST_F | ( | WindowsTest | ,
|  | VerifyNativeFunctionWithParameters |
| ) |  |

Definition at line 236 of file flutter_windows_unittests.cc.

236 {
237 auto& context = GetContext();
238 WindowsConfigBuilder builder(context);
239 builder.SetDartEntrypoint("verifyNativeFunctionWithParameters");
240
241 bool bool_value = false;
242 bool signaled = false;
243 auto native_entry = CREATE_NATIVE_ENTRY([&](Dart_NativeArguments args) {
244 auto handle = Dart_GetNativeBooleanArgument(args, 0, &bool_value);
245 ASSERT_FALSE(Dart_IsError(handle));
246 signaled = true;
247 });
248 context.AddNativeFunction("SignalBoolValue", native_entry);
249
250 ViewControllerPtr controller{builder.Run()};
251 ASSERT_NE(controller, nullptr);
252
253 // Wait until signalBoolValue has been called.
254 while (!signaled) {
255 PumpMessage();
256 }
257 EXPECT_TRUE(bool_value);
258 }

## ◆ TEST_F() [204/204]

flutter::testing::TEST_F | ( | WindowsTest | ,
|  | VerifyNativeFunctionWithReturn |
| ) |  |

Definition at line 288 of file flutter_windows_unittests.cc.

288 {
289 auto& context = GetContext();
290 WindowsConfigBuilder builder(context);
291 builder.SetDartEntrypoint("verifyNativeFunctionWithReturn");
292
293 bool bool_value_to_return = true;
294 int count = 2;
295 auto bool_return_entry = CREATE_NATIVE_ENTRY([&](Dart_NativeArguments args) {
296 Dart_SetBooleanReturnValue(args, bool_value_to_return);
297 --count;
298 });
299 context.AddNativeFunction("SignalBoolReturn", bool_return_entry);
300
301 bool bool_value_passed = false;
302 auto bool_pass_entry = CREATE_NATIVE_ENTRY([&](Dart_NativeArguments args) {
303 auto handle = Dart_GetNativeBooleanArgument(args, 0, &bool_value_passed);
304 ASSERT_FALSE(Dart_IsError(handle));
305 --count;
306 });
307 context.AddNativeFunction("SignalBoolValue", bool_pass_entry);
308
309 ViewControllerPtr controller{builder.Run()};
310 ASSERT_NE(controller, nullptr);
311
312 // Wait until signalBoolReturn and signalBoolValue have been called.
313 while (count > 0) {
314 PumpMessage();
315 }
316 EXPECT_TRUE(bool_value_passed);
317 }

## ◆ VietnameseTelexAddDiacriticWithSlowResponse()

void flutter::testing::VietnameseTelexAddDiacriticWithSlowResponse | ( | WindowsTestContext & | context,
|  | bool | backspace_response
| ) |  |

Definition at line 2387 of file keyboard_unittests.cc.

2388 {
2389 // In this test, the user presses the following keys:
2390 //
2391 // Key Current text
2392 // ===========================
2393 // A a
2394 // F à
2395 //
2396 // And the Backspace down event is responded slowly with `backspace_response`.
2397
2398 KeyboardTester tester{context};
2399 tester.Responding(false);
2400
2401 // US Keyboard layout
2402
2403 // Press A
2404 tester.InjectKeyboardChanges(std::vector<KeyboardChange>{
2405 WmKeyDownInfo{kVirtualKeyA, kScanCodeKeyA, kNotExtended, kWasUp}.Build(
2406 kWmResultZero),
2407 WmCharInfo{'a', kScanCodeKeyA, kNotExtended, kWasUp}.Build(
2408 kWmResultZero)});
2409
2410 EXPECT_EQ(tester.key_calls.size(), 2);
2411 EXPECT_CALL_IS_EVENT(tester.key_calls[0], kFlutterKeyEventTypeDown,
2412 kPhysicalKeyA, kLogicalKeyA, "a", kNotSynthesized);
2413 EXPECT_CALL_IS_TEXT(tester.key_calls[1], u"a");
2414 tester.clear_key_calls();
2415 EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 2);
2416
2417 // Release A
2418 tester.InjectKeyboardChanges(std::vector<KeyboardChange>{
2419 WmKeyUpInfo{kVirtualKeyA, kScanCodeKeyA, kNotExtended}.Build(
2420 kWmResultZero)});
2421
2422 EXPECT_EQ(tester.key_calls.size(), 1);
2423 EXPECT_CALL_IS_EVENT(tester.key_calls[0], kFlutterKeyEventTypeUp,
2424 kPhysicalKeyA, kLogicalKeyA, "", kNotSynthesized);
2425 tester.clear_key_calls();
2426 EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 1);
2427
2428 std::vector<MockKeyResponseController::ResponseCallback> recorded_callbacks;
2429 tester.LateResponding(
2430 [&recorded_callbacks](
2431 const FlutterKeyEvent* event,
2432 MockKeyResponseController::ResponseCallback callback) {
2433 recorded_callbacks.push_back(callback);
2434 });
2435
2436 // Press F, which is translated to:
2437 //
2438 // Backspace down, char & up, VK_PACKET('à').
2439 tester.InjectKeyboardChanges(std::vector<KeyboardChange>{
2440 WmKeyDownInfo{VK_BACK, kScanCodeBackspace, kNotExtended, kWasUp}.Build(
2441 kWmResultZero),
2442 WmCharInfo{0x8, kScanCodeBackspace, kNotExtended, kWasUp}.Build(
2443 kWmResultZero),
2444 WmKeyUpInfo{VK_BACK, kScanCodeBackspace, kNotExtended}.Build(
2445 kWmResultZero),
2446 WmKeyDownInfo{VK_PACKET, 0, kNotExtended, kWasUp}.Build(kWmResultDefault),
2447 WmCharInfo{0xe0 /*'à'*/, 0, kNotExtended, kWasUp}.Build(kWmResultZero),
2448 WmKeyUpInfo{VK_PACKET, 0, kNotExtended}.Build(kWmResultDefault)});
2449
2450 // The Backspace event has not responded yet, therefore the char message must
2451 // hold. This is because when the framework is handling the Backspace event,
2452 // it will send a setEditingState message that updates the text state that has
2453 // the last character deleted (denoted by `string1`). Processing the char
2454 // message before then will cause the final text to set to `string1`.
2455 EXPECT_EQ(tester.key_calls.size(), 1);
2456 EXPECT_CALL_IS_EVENT(tester.key_calls[0], kFlutterKeyEventTypeDown,
2457 kPhysicalBackspace, kLogicalBackspace, "",
2458 kNotSynthesized);
2459 tester.clear_key_calls();
2460 EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 0);
2461
2462 EXPECT_EQ(recorded_callbacks.size(), 1);
2463 recorded_callbacks[0](backspace_response);
2464
2465 EXPECT_EQ(tester.key_calls.size(), 1);
2466 EXPECT_CALL_IS_EVENT(tester.key_calls[0], kFlutterKeyEventTypeUp,
2467 kPhysicalBackspace, kLogicalBackspace, "",
2468 kNotSynthesized);
2469 tester.clear_key_calls();
2470 EXPECT_EQ(tester.RedispatchedMessageCountAndClear(),
2471 backspace_response ? 0 : 2);
2472
2473 recorded_callbacks[1](false);
2474 EXPECT_EQ(tester.key_calls.size(), 1);
2475 EXPECT_CALL_IS_TEXT(tester.key_calls[0], u"à");
2476 tester.clear_key_calls();
2477 EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 1);
2478
2479 tester.Responding(false);
2480
2481 // Release F
2482 tester.InjectKeyboardChanges(std::vector<KeyboardChange>{
2483 WmKeyUpInfo{kVirtualKeyF, kScanCodeKeyF, kNotExtended,
2484 /* overwrite_prev_state_0 */ true}
2485 .Build(kWmResultZero)});
2486
2487 EXPECT_EQ(tester.key_calls.size(), 1);
2488 EXPECT_CALL_IS_EVENT(tester.key_calls[0], kFlutterKeyEventTypeDown, 0, 0, "",
2489 kNotSynthesized);
2490 tester.clear_key_calls();
2491 EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 0);
2492 }

References callback, EXPECT_CALL_IS_EVENT, EXPECT_CALL_IS_TEXT, kScanCodeKeyA, and kVirtualKeyA.

Referenced by TEST_F().

## ◆ WaitUntilUpdated()

static void flutter::testing::WaitUntilUpdated | ( | const WindowsLifecycleManager & | manager | ) |
| static

Definition at line 16 of file windows_lifecycle_manager_unittests.cc.

16 {
17 while (manager.IsUpdateStateScheduled()) {
18 ::MSG msg;
19 if (::GetMessage(&msg, nullptr, 0, 0)) {
20 ::TranslateMessage(&msg);
21 ::DispatchMessage(&msg);
22 }
23 }
24 }

References flutter::WindowsLifecycleManager::IsUpdateStateScheduled().

Referenced by TEST_F().

## Variable Documentation

## ◆ kEmptyFlags

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

Definition at line 18 of file accessibility_bridge_unittests.cc.

Referenced by CreateSemanticsNode().

## ◆ kScanCodeKeyA

constexpr uint64_t flutter::testing::kScanCodeKeyA = 0x1e
| constexpr

Definition at line 42 of file flutter_windows_view_unittests.cc.

Referenced by TEST(), TEST_F(), and VietnameseTelexAddDiacriticWithSlowResponse().

## ◆ kVirtualKeyA

constexpr uint64_t flutter::testing::kVirtualKeyA = 0x41
| constexpr

Definition at line 43 of file flutter_windows_view_unittests.cc.

Referenced by TEST(), TEST_F(), and VietnameseTelexAddDiacriticWithSlowResponse().