| Flutter Windows Embedder |

Classes | Functions | Variables
flutter::testing Namespace Reference

## Classes
class | CursorHandlerTest
class | MockIDirectManipulationViewport
class | MockIDirectManipulationContent
class | FlutterWindowsEngineTest
class | MockFlutterWindowsView
class | MockWindowsLifecycleManager
class | PlatformHandlerTest
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 (CompositorOpenGLTest, CreateBackingStore)
| TEST_F (CompositorOpenGLTest, CreateBackingStoreImpeller)
| TEST_F (CompositorOpenGLTest, InitializationFailure)
| TEST_F (CompositorOpenGLTest, Present)
| TEST_F (CompositorOpenGLTest, PresentEmpty)
| TEST_F (CompositorOpenGLTest, NoSurfaceIgnored)
| 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 (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, 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, 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, GetGraphicsAdapterWithLowPowerPreference)
| 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 (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 (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, 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, GetClipboardDataRequiresView)
| TEST_F (PlatformHandlerTest, GetClipboardDataReportsOpenFailure)
| TEST_F (PlatformHandlerTest, GetClipboardDataReportsGetDataFailure)
| TEST_F (PlatformHandlerTest, ClipboardHasStrings)
| TEST_F (PlatformHandlerTest, ClipboardHasStringsReturnsFalse)
| TEST_F (PlatformHandlerTest, ClipboardHasStringsRejectsUnknownContentType)
| TEST_F (PlatformHandlerTest, ClipboardHasStringsRequiresView)
| TEST_F (PlatformHandlerTest, ClipboardHasStringsIgnoresPermissionErrors)
| TEST_F (PlatformHandlerTest, ClipboardHasStringsReportsErrors)
| TEST_F (PlatformHandlerTest, ClipboardSetData)
| TEST_F (PlatformHandlerTest, ClipboardSetDataTextMustBeString)
| TEST_F (PlatformHandlerTest, ClipboardSetDataUnknownType)
| TEST_F (PlatformHandlerTest, ClipboardSetDataRequiresView)
| 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_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 (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 (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

## Function Documentation

## ◆ CreateSemanticsNode()

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

Definition at line 18 of file accessibility_bridge_unittests.cc.

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

Referenced by TEST().

## ◆ TEST() [1/161]

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

Definition at line 72 of file accessibility_bridge_unittests.cc.

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

References CreateSemanticsNode().

## ◆ TEST() [2/161]

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

Definition at line 109 of file accessibility_bridge_unittests.cc.

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

References CreateSemanticsNode().

## ◆ TEST() [3/161]

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

Definition at line 546 of file accessibility_bridge_unittests.cc.

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

## ◆ TEST() [4/161]

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

Definition at line 40 of file accessibility_bridge_unittests.cc.

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

References CreateSemanticsNode().

## ◆ TEST() [5/161]

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

Definition at line 160 of file accessibility_bridge_unittests.cc.

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

References CreateSemanticsNode().

## ◆ TEST() [6/161]

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

Definition at line 208 of file accessibility_bridge_unittests.cc.

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

References CreateSemanticsNode().

## ◆ TEST() [7/161]

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

Definition at line 372 of file accessibility_bridge_unittests.cc.

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

References CreateSemanticsNode().

## ◆ TEST() [8/161]

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

Definition at line 309 of file accessibility_bridge_unittests.cc.

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

References CreateSemanticsNode().

## ◆ TEST() [9/161]

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

Definition at line 466 of file accessibility_bridge_unittests.cc.

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

References CreateSemanticsNode().

## ◆ TEST() [10/161]

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

Definition at line 292 of file accessibility_bridge_unittests.cc.

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

References CreateSemanticsNode().

## ◆ TEST() [11/161]

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

Definition at line 240 of file accessibility_bridge_unittests.cc.

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

References CreateSemanticsNode().

## ◆ TEST() [12/161]

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

Definition at line 556 of file accessibility_bridge_unittests.cc.

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

References CreateSemanticsNode().

## ◆ TEST() [13/161]

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

Definition at line 271 of file accessibility_bridge_unittests.cc.

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

References CreateSemanticsNode().

## ◆ TEST() [14/161]

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

Definition at line 256 of file accessibility_bridge_unittests.cc.

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

References CreateSemanticsNode().

## ◆ TEST() [15/161]

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

Definition at line 269 of file accessibility_bridge_windows_unittests.cc.

269 {
270 auto engine = GetTestEngine();
271 FlutterWindowsViewSpy view{
272 engine.get(), std::make_unique<NiceMock<MockWindowBindingHandler>>()};
273 EngineModifier modifier{engine.get()};
274 modifier.SetImplicitView(&view);
275 view.OnUpdateSemanticsEnabled(true);
276
277 auto bridge = view.accessibility_bridge().lock();
278 PopulateAXTree(bridge);
279
280 FlutterSemanticsAction actual_action = kFlutterSemanticsActionTap;
281 modifier.embedder_api().SendSemanticsAction = MOCK_ENGINE_PROC(
282 SendSemanticsAction,
283 ([&actual_action](FLUTTER_API_SYMBOL(FlutterEngine) engine,
284 const FlutterSendSemanticsActionInfo* info) {
285 actual_action = info->action;
286 return kSuccess;
287 }));
288
289 AccessibilityBridgeWindows delegate(&view);
290 delegate.DispatchAccessibilityAction(1, kFlutterSemanticsActionCopy, {});
291 EXPECT_EQ(actual_action, kFlutterSemanticsActionCopy);
292 }

References flutter::AccessibilityBridgeWindows::DispatchAccessibilityAction().

## ◆ TEST() [16/161]

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

Definition at line 237 of file accessibility_bridge_windows_unittests.cc.

237 {
238 auto engine = GetTestEngine();
239 FlutterWindowsViewSpy view{
240 engine.get(), std::make_unique<NiceMock<MockWindowBindingHandler>>()};
241 EngineModifier modifier{engine.get()};
242 modifier.SetImplicitView(&view);
243 view.OnUpdateSemanticsEnabled(true);
244
245 auto bridge = view.accessibility_bridge().lock();
246 PopulateAXTree(bridge);
247
248 auto node0_delegate = bridge->GetFlutterPlatformNodeDelegateFromID(0).lock();
249 auto node1_delegate = bridge->GetFlutterPlatformNodeDelegateFromID(1).lock();
250 EXPECT_EQ(node0_delegate->GetNativeViewAccessible(),
251 node1_delegate->GetParent());
252 }

## ◆ TEST() [17/161]

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

Definition at line 254 of file accessibility_bridge_windows_unittests.cc.

254 {
255 auto engine = GetTestEngine();
256 FlutterWindowsViewSpy view{
257 engine.get(), std::make_unique<NiceMock<MockWindowBindingHandler>>()};
258 EngineModifier modifier{engine.get()};
259 modifier.SetImplicitView(&view);
260 view.OnUpdateSemanticsEnabled(true);
261
262 auto bridge = view.accessibility_bridge().lock();
263 PopulateAXTree(bridge);
264
265 auto node0_delegate = bridge->GetFlutterPlatformNodeDelegateFromID(0).lock();
266 ASSERT_TRUE(node0_delegate->GetParent() == nullptr);
267 }

## ◆ TEST() [18/161]

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

Definition at line 294 of file accessibility_bridge_windows_unittests.cc.

294 {
295 ExpectWinEventFromAXEvent(0, ui::AXEventGenerator::Event::ALERT,
296 ax::mojom::Event::kAlert);
297 }

## ◆ TEST() [19/161]

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

Definition at line 299 of file accessibility_bridge_windows_unittests.cc.

299 {
300 ExpectWinEventFromAXEvent(0, ui::AXEventGenerator::Event::CHILDREN_CHANGED,
301 ax::mojom::Event::kChildrenChanged);
302 }

## ◆ TEST() [20/161]

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

Definition at line 304 of file accessibility_bridge_windows_unittests.cc.

304 {
305 auto engine = GetTestEngine();
306 FlutterWindowsViewSpy view{
307 engine.get(), std::make_unique<NiceMock<MockWindowBindingHandler>>()};
308 EngineModifier modifier{engine.get()};
309 modifier.SetImplicitView(&view);
310 view.OnUpdateSemanticsEnabled(true);
311
312 auto bridge = GetAccessibilityBridgeSpy(view);
313 PopulateAXTree(bridge);
314
315 bridge->ResetRecords();
316 bridge->OnAccessibilityEvent({AXNodeFromID(bridge, 1),
317 {ui::AXEventGenerator::Event::FOCUS_CHANGED,
318 ax::mojom::EventFrom::kNone,
319 {}}});
320 ASSERT_EQ(bridge->dispatched_events().size(), 1);
321 EXPECT_EQ(bridge->dispatched_events()[0].event_type,
322 ax::mojom::Event::kFocus);
323
324 ASSERT_EQ(bridge->focused_nodes().size(), 1);
325 EXPECT_EQ(bridge->focused_nodes()[0], 1);
326 }

## ◆ TEST() [21/161]

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

Definition at line 328 of file accessibility_bridge_windows_unittests.cc.

328 {
329 // Static test nodes with no text, hint, or scrollability are ignored.
330 ExpectWinEventFromAXEvent(4, ui::AXEventGenerator::Event::IGNORED_CHANGED,
331 ax::mojom::Event::kHide);
332 }

## ◆ TEST() [22/161]

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

Definition at line 350 of file accessibility_bridge_windows_unittests.cc.

350 {
351 ExpectWinEventFromAXEvent(
352 1, ui::AXEventGenerator::Event::SCROLL_HORIZONTAL_POSITION_CHANGED,
353 ax::mojom::Event::kScrollPositionChanged);
354 }

## ◆ TEST() [23/161]

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

Definition at line 334 of file accessibility_bridge_windows_unittests.cc.

334 {
335 ExpectWinEventFromAXEvent(
336 1, ui::AXEventGenerator::Event::IMAGE_ANNOTATION_CHANGED,
337 ax::mojom::Event::kTextChanged);
338 }

## ◆ TEST() [24/161]

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

Definition at line 340 of file accessibility_bridge_windows_unittests.cc.

340 {
341 ExpectWinEventFromAXEvent(1, ui::AXEventGenerator::Event::LIVE_REGION_CHANGED,
342 ax::mojom::Event::kLiveRegionChanged);
343 }

## ◆ TEST() [25/161]

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

Definition at line 345 of file accessibility_bridge_windows_unittests.cc.

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

## ◆ TEST() [26/161]

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

Definition at line 362 of file accessibility_bridge_windows_unittests.cc.

362 {
363 ExpectWinEventFromAXEvent(1, ui::AXEventGenerator::Event::SELECTED_CHANGED,
364 ax::mojom::Event::kValueChanged);
365 }

## ◆ TEST() [27/161]

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

Definition at line 367 of file accessibility_bridge_windows_unittests.cc.

367 {
368 ExpectWinEventFromAXEvent(
369 2, ui::AXEventGenerator::Event::SELECTED_CHILDREN_CHANGED,
370 ax::mojom::Event::kSelectedChildrenChanged);
371 }

## ◆ TEST() [28/161]

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

Definition at line 383 of file accessibility_bridge_windows_unittests.cc.

383 {
384 ExpectWinEventFromAXEvent(
385 1, ui::AXEventGenerator::Event::WIN_IACCESSIBLE_STATE_CHANGED,
386 ax::mojom::Event::kStateChanged);
387 }

## ◆ TEST() [29/161]

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

Definition at line 373 of file accessibility_bridge_windows_unittests.cc.

373 {
374 ExpectWinEventFromAXEvent(0, ui::AXEventGenerator::Event::SUBTREE_CREATED,
375 ax::mojom::Event::kShow);
376 }

## ◆ TEST() [30/161]

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

Definition at line 378 of file accessibility_bridge_windows_unittests.cc.

378 {
379 ExpectWinEventFromAXEvent(1, ui::AXEventGenerator::Event::VALUE_CHANGED,
380 ax::mojom::Event::kValueChanged);
381 }

## ◆ TEST() [31/161]

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

Definition at line 356 of file accessibility_bridge_windows_unittests.cc.

356 {
357 ExpectWinEventFromAXEvent(
358 1, ui::AXEventGenerator::Event::SCROLL_VERTICAL_POSITION_CHANGED,
359 ax::mojom::Event::kScrollPositionChanged);
360 }

## ◆ TEST() [32/161]

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

Definition at line 389 of file accessibility_bridge_windows_unittests.cc.

389 {
390 ExpectWinEventFromAXEventOnFocusNode(
391 1, ui::AXEventGenerator::Event::DOCUMENT_SELECTION_CHANGED,
392 ax::mojom::Event::kDocumentSelectionChanged, 2);
393 }

## ◆ TEST() [33/161]

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(::testing::Invoke([&content](REFIID in, void** out) {
157 *out = &content;
158 return S_OK;
159 }))
160 .RetiresOnSaturation();
161 EXPECT_CALL(content, GetContentTransform(_, 6))
162 .WillOnce(::testing::Invoke([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(::testing::Invoke(
175 [scale, pan_x, pan_y](float* transform, DWORD size) {
176 transform[0] = scale;
177 transform[4] = pan_x;
178 transform[5] = pan_y;
179 return S_OK;
180 }));
181 EXPECT_CALL(delegate,
182 OnPointerPanZoomUpdate(device_id, pan_x, pan_y, scale, 0));
183 handler->OnContentUpdated((IDirectManipulationViewport*)&viewport,
184 (IDirectManipulationContent*)&content);
185 EXPECT_CALL(delegate, OnPointerPanZoomEnd(device_id));
186 EXPECT_CALL(viewport, GetViewportRect(_))
187 .WillOnce(::testing::Invoke([DISPLAY_WIDTH, DISPLAY_HEIGHT](RECT* rect) {
188 rect->left = 0;
189 rect->top = 0;
190 rect->right = DISPLAY_WIDTH;
191 rect->bottom = DISPLAY_HEIGHT;
192 return S_OK;
193 }));
194 EXPECT_CALL(viewport, ZoomToRect(0, 0, DISPLAY_WIDTH, DISPLAY_HEIGHT, false))
195 .WillOnce(::testing::Return(S_OK));
196 handler->OnViewportStatusChanged((IDirectManipulationViewport*)&viewport,
197 DIRECTMANIPULATION_INERTIA,
198 DIRECTMANIPULATION_RUNNING);
199 handler->OnViewportStatusChanged((IDirectManipulationViewport*)&viewport,
200 DIRECTMANIPULATION_READY,
201 DIRECTMANIPULATION_INERTIA);
202 }
content
union flutter::testing::@88::KeyboardChange::@0 content

References content.

## ◆ TEST() [34/161]

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

Definition at line 394 of file direct_manipulation_unittests.cc.

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

References content.

## ◆ TEST() [35/161]

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

Definition at line 340 of file direct_manipulation_unittests.cc.

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

References content.

## ◆ TEST() [36/161]

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

Definition at line 287 of file direct_manipulation_unittests.cc.

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

References content.

## ◆ TEST() [37/161]

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

Definition at line 205 of file direct_manipulation_unittests.cc.

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

References content.

## ◆ TEST() [38/161]

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:130
flutter::GetDpiForMonitor
UINT GetDpiForMonitor(HMONITOR monitor)
Definition: dpi_utils.cc:134

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

## ◆ TEST() [39/161]

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

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

Definition at line 110 of file flutter_platform_node_delegate_unittests.cc.

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

## ◆ TEST() [41/161]

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

Definition at line 156 of file flutter_platform_node_delegate_unittests.cc.

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

## ◆ TEST() [42/161]

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

Definition at line 84 of file flutter_platform_node_delegate_unittests.cc.

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

## ◆ TEST() [43/161]

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

Definition at line 271 of file flutter_platform_node_delegate_unittests.cc.

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

## ◆ TEST() [44/161]

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

Definition at line 40 of file flutter_platform_node_delegate_unittests.cc.

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

## ◆ TEST() [45/161]

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

Definition at line 202 of file flutter_platform_node_delegate_unittests.cc.

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

## ◆ TEST() [46/161]

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

Definition at line 15 of file flutter_platform_node_delegate_unittests.cc.

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

## ◆ TEST() [47/161]

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

Definition at line 249 of file flutter_platform_node_delegate_unittests.cc.

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

## ◆ TEST() [48/161]

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:60
FlutterDesktopEngineProperties::icu_data_path
const wchar_t * icu_data_path
Definition: flutter_windows.h:69
FlutterDesktopEngineProperties::assets_path
const wchar_t * assets_path
Definition: flutter_windows.h:64

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

## ◆ TEST() [49/161]

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

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:86
FlutterDesktopEngineProperties::dart_entrypoint_argv
const char ** dart_entrypoint_argv
Definition: flutter_windows.h:90

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

## ◆ TEST() [51/161]

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

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

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

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

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

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

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

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

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

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

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

Definition at line 781 of file flutter_windows_view_unittests.cc.

781 {
782 constexpr FlutterTransformation kIdentityTransform = {1, 0, 0, //
783 0, 1, 0, //
784 0, 0, 1};
785
786 std::unique_ptr<FlutterWindowsEngine> engine = GetTestEngine();
787 EngineModifier modifier(engine.get());
788 modifier.embedder_api().UpdateSemanticsEnabled =
789 [](FLUTTER_API_SYMBOL(FlutterEngine) engine, bool enabled) {
790 return kSuccess;
791 };
792
793 std::unique_ptr<FlutterWindowsView> view = engine->CreateView(
794 std::make_unique<NiceMock<MockWindowBindingHandler>>());
795
796 // Enable semantics to instantiate accessibility bridge.
797 view->OnUpdateSemanticsEnabled(true);
798
799 auto bridge = view->accessibility_bridge().lock();
800 ASSERT_TRUE(bridge);
801
802 // Add root node at origin. Size 500x500.
803 FlutterSemanticsNode2 node0{sizeof(FlutterSemanticsNode2), 0};
804 std::vector<int32_t> node0_children{1, 2};
805 node0.rect = {0, 0, 500, 500};
806 node0.transform = kIdentityTransform;
807 node0.child_count = node0_children.size();
808 node0.children_in_traversal_order = node0_children.data();
809 node0.children_in_hit_test_order = node0_children.data();
810
811 // Add node 1 located at 0,0 relative to node 0. Size 250x500.
812 FlutterSemanticsNode2 node1{sizeof(FlutterSemanticsNode2), 1};
813 node1.rect = {0, 0, 250, 500};
814 node1.transform = kIdentityTransform;
815 node1.label = "prefecture";
816 node1.value = "Kyoto";
817
818 // Add node 2 located at 250,0 relative to node 0. Size 250x500.
819 FlutterSemanticsNode2 node2{sizeof(FlutterSemanticsNode2), 2};
820 std::vector<int32_t> node2_children{3};
821 node2.rect = {0, 0, 250, 500};
822 node2.transform = {1, 0, 250, 0, 1, 0, 0, 0, 1};
823 node2.child_count = node2_children.size();
824 node2.children_in_traversal_order = node2_children.data();
825 node2.children_in_hit_test_order = node2_children.data();
826
827 // Add node 3 located at 0,250 relative to node 2. Size 250, 250.
828 FlutterSemanticsNode2 node3{sizeof(FlutterSemanticsNode2), 3};
829 node3.rect = {0, 0, 250, 250};
830 node3.transform = {1, 0, 0, 0, 1, 250, 0, 0, 1};
831 node3.label = "city";
832 node3.value = "Uji";
833
834 bridge->AddFlutterSemanticsNodeUpdate(node0);
835 bridge->AddFlutterSemanticsNodeUpdate(node1);
836 bridge->AddFlutterSemanticsNodeUpdate(node2);
837 bridge->AddFlutterSemanticsNodeUpdate(node3);
838 bridge->CommitUpdates();
839
840 // Look up the root windows node delegate.
841 auto node0_delegate = bridge->GetFlutterPlatformNodeDelegateFromID(0).lock();
842 ASSERT_TRUE(node0_delegate);
843 auto node1_delegate = bridge->GetFlutterPlatformNodeDelegateFromID(1).lock();
844 ASSERT_TRUE(node1_delegate);
845 auto node2_delegate = bridge->GetFlutterPlatformNodeDelegateFromID(2).lock();
846 ASSERT_TRUE(node2_delegate);
847 auto node3_delegate = bridge->GetFlutterPlatformNodeDelegateFromID(3).lock();
848 ASSERT_TRUE(node3_delegate);
849
850 // Get the native IAccessible root object.
851 IAccessible* node0_accessible = node0_delegate->GetNativeViewAccessible();
852 ASSERT_TRUE(node0_accessible != nullptr);
853
854 // Perform a hit test that should hit node 1.
855 VARIANT varchild{};
856 ASSERT_TRUE(SUCCEEDED(node0_accessible->accHitTest(150, 150, &varchild)));
857 EXPECT_EQ(varchild.vt, VT_DISPATCH);
858 EXPECT_EQ(varchild.pdispVal, node1_delegate->GetNativeViewAccessible());
859
860 // Perform a hit test that should hit node 2.
861 varchild = {};
862 ASSERT_TRUE(SUCCEEDED(node0_accessible->accHitTest(450, 150, &varchild)));
863 EXPECT_EQ(varchild.vt, VT_DISPATCH);
864 EXPECT_EQ(varchild.pdispVal, node2_delegate->GetNativeViewAccessible());
865
866 // Perform a hit test that should hit node 3.
867 varchild = {};
868 ASSERT_TRUE(SUCCEEDED(node0_accessible->accHitTest(450, 450, &varchild)));
869 EXPECT_EQ(varchild.vt, VT_DISPATCH);
870 EXPECT_EQ(varchild.pdispVal, node3_delegate->GetNativeViewAccessible());
871 }

## ◆ TEST() [62/161]

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

Definition at line 360 of file flutter_windows_view_unittests.cc.

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

References node_delegate.

## ◆ TEST() [63/161]

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

Definition at line 459 of file flutter_windows_view_unittests.cc.

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

References node_delegate.

## ◆ TEST() [64/161]

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

Definition at line 1131 of file flutter_windows_view_unittests.cc.

1131 {
1132 std::unique_ptr<FlutterWindowsEngine> engine = GetTestEngine();
1133 EngineModifier modifier(engine.get());
1134 modifier.embedder_api().UpdateSemanticsEnabled =
1135 [](FLUTTER_API_SYMBOL(FlutterEngine) engine, bool enabled) {
1136 return kSuccess;
1137 };
1138
1139 std::unique_ptr<FlutterWindowsView> view = engine->CreateView(
1140 std::make_unique<NiceMock<MockWindowBindingHandler>>());
1141
1142 // Enable semantics to instantiate accessibility bridge.
1143 view->OnUpdateSemanticsEnabled(true);
1144
1145 auto bridge = view->accessibility_bridge().lock();
1146 ASSERT_TRUE(bridge);
1147
1148 FlutterSemanticsNode2 root{sizeof(FlutterSemanticsNode2), 0};
1149 root.id = 0;
1150 root.label = "root";
1151 root.hint = "";
1152 root.value = "";
1153 root.increased_value = "";
1154 root.decreased_value = "";
1155 root.child_count = 0;
1156 root.custom_accessibility_actions_count = 0;
1157 root.flags = static_cast<FlutterSemanticsFlag>(
1158 FlutterSemanticsFlag::kFlutterSemanticsFlagHasCheckedState |
1159 FlutterSemanticsFlag::kFlutterSemanticsFlagIsChecked);
1160 bridge->AddFlutterSemanticsNodeUpdate(root);
1161
1162 bridge->CommitUpdates();
1163
1164 {
1165 auto root_node = bridge->GetFlutterPlatformNodeDelegateFromID(0).lock();
1166 EXPECT_EQ(root_node->GetData().role, ax::mojom::Role::kCheckBox);
1167 EXPECT_EQ(root_node->GetData().GetCheckedState(),
1168 ax::mojom::CheckedState::kTrue);
1169
1170 // Get the IAccessible for the root node.
1171 IAccessible* native_view = root_node->GetNativeViewAccessible();
1172 ASSERT_TRUE(native_view != nullptr);
1173
1174 // Look up against the node itself (not one of its children).
1175 VARIANT varchild = {};
1176 varchild.vt = VT_I4;
1177
1178 // Verify the checkbox is checked.
1179 varchild.lVal = CHILDID_SELF;
1180 VARIANT native_state = {};
1181 ASSERT_TRUE(SUCCEEDED(native_view->get_accState(varchild, &native_state)));
1182 EXPECT_TRUE(native_state.lVal & STATE_SYSTEM_CHECKED);
1183
1184 // Perform similar tests for UIA value;
1185 IRawElementProviderSimple* uia_node;
1186 native_view->QueryInterface(IID_PPV_ARGS(&uia_node));
1187 ASSERT_TRUE(SUCCEEDED(uia_node->GetPropertyValue(
1188 UIA_ToggleToggleStatePropertyId, &native_state)));
1189 EXPECT_EQ(native_state.lVal, ToggleState_On);
1190
1191 ASSERT_TRUE(SUCCEEDED(uia_node->GetPropertyValue(
1192 UIA_AriaPropertiesPropertyId, &native_state)));
1193 EXPECT_NE(std::wcsstr(native_state.bstrVal, L"checked=true"), nullptr);
1194 }
1195
1196 // Test unchecked too.
1197 root.flags = static_cast<FlutterSemanticsFlag>(
1198 FlutterSemanticsFlag::kFlutterSemanticsFlagHasCheckedState);
1199 bridge->AddFlutterSemanticsNodeUpdate(root);
1200 bridge->CommitUpdates();
1201
1202 {
1203 auto root_node = bridge->GetFlutterPlatformNodeDelegateFromID(0).lock();
1204 EXPECT_EQ(root_node->GetData().role, ax::mojom::Role::kCheckBox);
1205 EXPECT_EQ(root_node->GetData().GetCheckedState(),
1206 ax::mojom::CheckedState::kFalse);
1207
1208 // Get the IAccessible for the root node.
1209 IAccessible* native_view = root_node->GetNativeViewAccessible();
1210 ASSERT_TRUE(native_view != nullptr);
1211
1212 // Look up against the node itself (not one of its children).
1213 VARIANT varchild = {};
1214 varchild.vt = VT_I4;
1215
1216 // Verify the checkbox is unchecked.
1217 varchild.lVal = CHILDID_SELF;
1218 VARIANT native_state = {};
1219 ASSERT_TRUE(SUCCEEDED(native_view->get_accState(varchild, &native_state)));
1220 EXPECT_FALSE(native_state.lVal & STATE_SYSTEM_CHECKED);
1221
1222 // Perform similar tests for UIA value;
1223 IRawElementProviderSimple* uia_node;
1224 native_view->QueryInterface(IID_PPV_ARGS(&uia_node));
1225 ASSERT_TRUE(SUCCEEDED(uia_node->GetPropertyValue(
1226 UIA_ToggleToggleStatePropertyId, &native_state)));
1227 EXPECT_EQ(native_state.lVal, ToggleState_Off);
1228
1229 ASSERT_TRUE(SUCCEEDED(uia_node->GetPropertyValue(
1230 UIA_AriaPropertiesPropertyId, &native_state)));
1231 EXPECT_NE(std::wcsstr(native_state.bstrVal, L"checked=false"), nullptr);
1232 }
1233
1234 // Now check mixed state.
1235 root.flags = static_cast<FlutterSemanticsFlag>(
1236 FlutterSemanticsFlag::kFlutterSemanticsFlagHasCheckedState |
1237 FlutterSemanticsFlag::kFlutterSemanticsFlagIsCheckStateMixed);
1238 bridge->AddFlutterSemanticsNodeUpdate(root);
1239 bridge->CommitUpdates();
1240
1241 {
1242 auto root_node = bridge->GetFlutterPlatformNodeDelegateFromID(0).lock();
1243 EXPECT_EQ(root_node->GetData().role, ax::mojom::Role::kCheckBox);
1244 EXPECT_EQ(root_node->GetData().GetCheckedState(),
1245 ax::mojom::CheckedState::kMixed);
1246
1247 // Get the IAccessible for the root node.
1248 IAccessible* native_view = root_node->GetNativeViewAccessible();
1249 ASSERT_TRUE(native_view != nullptr);
1250
1251 // Look up against the node itself (not one of its children).
1252 VARIANT varchild = {};
1253 varchild.vt = VT_I4;
1254
1255 // Verify the checkbox is mixed.
1256 varchild.lVal = CHILDID_SELF;
1257 VARIANT native_state = {};
1258 ASSERT_TRUE(SUCCEEDED(native_view->get_accState(varchild, &native_state)));
1259 EXPECT_TRUE(native_state.lVal & STATE_SYSTEM_MIXED);
1260
1261 // Perform similar tests for UIA value;
1262 IRawElementProviderSimple* uia_node;
1263 native_view->QueryInterface(IID_PPV_ARGS(&uia_node));
1264 ASSERT_TRUE(SUCCEEDED(uia_node->GetPropertyValue(
1265 UIA_ToggleToggleStatePropertyId, &native_state)));
1266 EXPECT_EQ(native_state.lVal, ToggleState_Indeterminate);
1267
1268 ASSERT_TRUE(SUCCEEDED(uia_node->GetPropertyValue(
1269 UIA_AriaPropertiesPropertyId, &native_state)));
1270 EXPECT_NE(std::wcsstr(native_state.bstrVal, L"checked=mixed"), nullptr);
1271 }
1272 }

## ◆ TEST() [65/161]

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

Definition at line 1520 of file flutter_windows_view_unittests.cc.

1520 {
1521 auto windows_proc_table = std::make_shared<MockWindowsProcTable>();
1522 auto engine = std::make_unique<MockFlutterWindowsEngine>(windows_proc_table);
1523 auto egl_manager = std::make_unique<egl::MockManager>();
1524 egl::MockContext render_context;
1525 auto surface = std::make_unique<egl::MockWindowSurface>();
1526 auto surface_ptr = surface.get();
1527
1528 EXPECT_CALL(*engine.get(), running).WillRepeatedly(Return(true));
1529 EXPECT_CALL(*windows_proc_table.get(), DwmIsCompositionEnabled)
1530 .WillOnce(Return(true));
1531
1532 EXPECT_CALL(*egl_manager.get(), render_context)
1533 .WillOnce(Return(&render_context));
1534 EXPECT_CALL(*surface_ptr, IsValid).WillOnce(Return(true));
1535
1536 InSequence s;
1537 EXPECT_CALL(*egl_manager.get(), CreateWindowSurface)
1538 .WillOnce(Return(std::move(surface)));
1539 EXPECT_CALL(*engine.get(), PostRasterThreadTask)
1540 .WillOnce([](fml::closure callback) {
1541 callback();
1542 return true;
1543 });
1544 EXPECT_CALL(*surface_ptr, MakeCurrent).WillOnce(Return(true));
1545 EXPECT_CALL(*surface_ptr, SetVSyncEnabled(false)).WillOnce(Return(true));
1546 EXPECT_CALL(render_context, ClearCurrent).WillOnce(Return(true));
1547 EXPECT_CALL(*engine.get(), PostRasterThreadTask)
1548 .WillOnce([](fml::closure callback) {
1549 callback();
1550 return true;
1551 });
1552 EXPECT_CALL(*surface_ptr, Destroy).Times(1);
1553
1554 EngineModifier modifier{engine.get()};
1555 modifier.SetEGLManager(std::move(egl_manager));
1556
1557 std::unique_ptr<FlutterWindowsView> view = engine->CreateView(
1558 std::make_unique<NiceMock<MockWindowBindingHandler>>());
1559 }

References callback.

## ◆ TEST() [66/161]

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

Definition at line 1449 of file flutter_windows_view_unittests.cc.

1449 {
1450 auto windows_proc_table = std::make_shared<MockWindowsProcTable>();
1451 auto engine = std::make_unique<MockFlutterWindowsEngine>(windows_proc_table);
1452 auto egl_manager = std::make_unique<egl::MockManager>();
1453 egl::MockContext render_context;
1454 auto surface = std::make_unique<egl::MockWindowSurface>();
1455 auto surface_ptr = surface.get();
1456
1457 EXPECT_CALL(*engine.get(), running).WillRepeatedly(Return(false));
1458 EXPECT_CALL(*engine.get(), PostRasterThreadTask).Times(0);
1459
1460 EXPECT_CALL(*windows_proc_table.get(), DwmIsCompositionEnabled)
1461 .WillOnce(Return(true));
1462
1463 EXPECT_CALL(*egl_manager.get(), render_context)
1464 .WillOnce(Return(&render_context));
1465 EXPECT_CALL(*surface_ptr, IsValid).WillOnce(Return(true));
1466
1467 InSequence s;
1468 EXPECT_CALL(*egl_manager.get(), CreateWindowSurface)
1469 .WillOnce(Return(std::move(surface)));
1470 EXPECT_CALL(*surface_ptr, MakeCurrent).WillOnce(Return(true));
1471 EXPECT_CALL(*surface_ptr, SetVSyncEnabled(false)).WillOnce(Return(true));
1472 EXPECT_CALL(render_context, ClearCurrent).WillOnce(Return(true));
1473
1474 EXPECT_CALL(*surface_ptr, Destroy).Times(1);
1475
1476 EngineModifier modifier{engine.get()};
1477 modifier.SetEGLManager(std::move(egl_manager));
1478
1479 std::unique_ptr<FlutterWindowsView> view = engine->CreateView(
1480 std::make_unique<NiceMock<MockWindowBindingHandler>>());
1481 }

## ◆ TEST() [67/161]

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

Definition at line 338 of file flutter_windows_view_unittests.cc.

338 {
339 std::unique_ptr<FlutterWindowsEngine> engine = GetTestEngine();
340 EngineModifier modifier(engine.get());
341
342 bool semantics_enabled = false;
343 modifier.embedder_api().UpdateSemanticsEnabled = MOCK_ENGINE_PROC(
344 UpdateSemanticsEnabled,
345 [&semantics_enabled](FLUTTER_API_SYMBOL(FlutterEngine) engine,
346 bool enabled) {
347 semantics_enabled = enabled;
348 return kSuccess;
349 });
350
351 auto window_binding_handler =
352 std::make_unique<NiceMock<MockWindowBindingHandler>>();
353 std::unique_ptr<FlutterWindowsView> view =
354 engine->CreateView(std::move(window_binding_handler));
355
356 view->OnUpdateSemanticsEnabled(true);
357 EXPECT_TRUE(semantics_enabled);
358 }

## ◆ TEST() [68/161]

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

Definition at line 1563 of file flutter_windows_view_unittests.cc.

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

References callback.

## ◆ TEST() [69/161]

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

Definition at line 1485 of file flutter_windows_view_unittests.cc.

1485 {
1486 auto windows_proc_table = std::make_shared<MockWindowsProcTable>();
1487 auto engine = std::make_unique<MockFlutterWindowsEngine>(windows_proc_table);
1488 auto egl_manager = std::make_unique<egl::MockManager>();
1489 egl::MockContext render_context;
1490 auto surface = std::make_unique<egl::MockWindowSurface>();
1491 auto surface_ptr = surface.get();
1492
1493 EXPECT_CALL(*engine.get(), running).WillRepeatedly(Return(false));
1494 EXPECT_CALL(*engine.get(), PostRasterThreadTask).Times(0);
1495 EXPECT_CALL(*windows_proc_table.get(), DwmIsCompositionEnabled)
1496 .WillOnce(Return(false));
1497
1498 EXPECT_CALL(*egl_manager.get(), render_context)
1499 .WillOnce(Return(&render_context));
1500 EXPECT_CALL(*surface_ptr, IsValid).WillOnce(Return(true));
1501
1502 InSequence s;
1503 EXPECT_CALL(*egl_manager.get(), CreateWindowSurface)
1504 .WillOnce(Return(std::move(surface)));
1505 EXPECT_CALL(*surface_ptr, MakeCurrent).WillOnce(Return(true));
1506 EXPECT_CALL(*surface_ptr, SetVSyncEnabled(true)).WillOnce(Return(true));
1507 EXPECT_CALL(render_context, ClearCurrent).WillOnce(Return(true));
1508
1509 EXPECT_CALL(*surface_ptr, Destroy).Times(1);
1510
1511 EngineModifier modifier{engine.get()};
1512 modifier.SetEGLManager(std::move(egl_manager));
1513
1514 std::unique_ptr<FlutterWindowsView> view = engine->CreateView(
1515 std::make_unique<NiceMock<MockWindowBindingHandler>>());
1516 }

## ◆ TEST() [70/161]

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

Definition at line 1671 of file flutter_windows_view_unittests.cc.

1671 {
1672 std::unique_ptr<FlutterWindowsEngine> engine = GetTestEngine();
1673 auto window_binding_handler =
1674 std::make_unique<NiceMock<MockWindowBindingHandler>>();
1675 EXPECT_CALL(*window_binding_handler, Focus()).WillOnce(Return(true));
1676 std::unique_ptr<FlutterWindowsView> view =
1677 engine->CreateView(std::move(window_binding_handler));
1678 EXPECT_TRUE(view->Focus());
1679 }

## ◆ TEST() [71/161]

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

Definition at line 309 of file flutter_windows_view_unittests.cc.

309 {
310 std::unique_ptr<FlutterWindowsEngine> engine = GetTestEngine();
311
312 std::unique_ptr<FlutterWindowsView> view = engine->CreateView(
313 std::make_unique<NiceMock<MockWindowBindingHandler>>());
314
315 class MockCallback {
316 public:
317 MOCK_METHOD(void, Call, ());
318 };
319
320 NiceMock<MockCallback> callback_with_valid_view;
321 NiceMock<MockCallback> callback_with_invalid_view;
322
323 auto trigger_key_event = [&](NiceMock<MockCallback>& callback) {
324 view->OnKey(kVirtualKeyA, kScanCodeKeyA, WM_KEYDOWN, 'a', false, false,
325 [&](bool) { callback.Call(); });
326 };
327
328 EXPECT_CALL(callback_with_valid_view, Call()).Times(1);
329 EXPECT_CALL(callback_with_invalid_view, Call()).Times(0);
330
331 trigger_key_event(callback_with_valid_view);
332 engine->RemoveView(view->view_id());
333 trigger_key_event(callback_with_invalid_view);
334
335 key_event_logs.clear();
336 }
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() [72/161]

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

Definition at line 291 of file flutter_windows_view_unittests.cc.

291 {
292 std::unique_ptr<FlutterWindowsEngine> engine = GetTestEngine();
293
294 test_response = false;
295
296 std::unique_ptr<FlutterWindowsView> view = engine->CreateView(
297 std::make_unique<NiceMock<MockWindowBindingHandler>>());
298
299 view->OnKey(kVirtualKeyA, kScanCodeKeyA, WM_KEYDOWN, 'a', false, false,
300 [](bool handled) {});
301
302 EXPECT_EQ(key_event_logs.size(), 2);
303 EXPECT_EQ(key_event_logs[0], kKeyEventFromEmbedder);
304 EXPECT_EQ(key_event_logs[1], kKeyEventFromChannel);
305
306 key_event_logs.clear();
307 }

References kScanCodeKeyA, and kVirtualKeyA.

## ◆ TEST() [73/161]

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

Definition at line 655 of file flutter_windows_view_unittests.cc.

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

## ◆ TEST() [74/161]

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

Definition at line 1681 of file flutter_windows_view_unittests.cc.

1681 {
1682 std::unique_ptr<FlutterWindowsEngine> engine = GetTestEngine();
1683 auto window_binding_handler =
1684 std::make_unique<NiceMock<MockWindowBindingHandler>>();
1685 std::unique_ptr<FlutterWindowsView> view =
1686 engine->CreateView(std::move(window_binding_handler));
1687
1688 EngineModifier modifier(engine.get());
1689 bool received_focus_event = false;
1690 modifier.embedder_api().SendViewFocusEvent = MOCK_ENGINE_PROC(
1691 SendViewFocusEvent, [&](FLUTTER_API_SYMBOL(FlutterEngine) raw_engine,
1692 FlutterViewFocusEvent const* event) {
1693 EXPECT_EQ(event->state, FlutterViewFocusState::kFocused);
1694 EXPECT_EQ(event->direction, FlutterViewFocusDirection::kUndefined);
1695 EXPECT_EQ(event->view_id, view->view_id());
1696 EXPECT_EQ(event->struct_size, sizeof(FlutterViewFocusEvent));
1697 received_focus_event = true;
1698 return kSuccess;
1699 });
1700 view->OnFocus(FlutterViewFocusState::kFocused,
1701 FlutterViewFocusDirection::kUndefined);
1702 EXPECT_TRUE(received_focus_event);
1703 }

## ◆ TEST() [75/161]

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

Definition at line 241 of file flutter_windows_view_unittests.cc.

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

References callback.

## ◆ TEST() [76/161]

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
150 // Enable semantics to instantiate accessibility bridge.
151 view->OnUpdateSemanticsEnabled(true);
152
153 auto bridge = view->accessibility_bridge().lock();
154 ASSERT_TRUE(bridge);
155
156 FlutterSemanticsNode2 root{sizeof(FlutterSemanticsNode2), 0};
157 root.id = 0;
158 root.label = "root";
159 root.hint = "";
160 root.value = "";
161 root.increased_value = "";
162 root.decreased_value = "";
163 root.child_count = 0;
164 root.custom_accessibility_actions_count = 0;
165 root.flags = static_cast<FlutterSemanticsFlag>(
166 FlutterSemanticsFlag::kFlutterSemanticsFlagHasExpandedState |
167 FlutterSemanticsFlag::kFlutterSemanticsFlagIsExpanded);
168 bridge->AddFlutterSemanticsNodeUpdate(root);
169
170 bridge->CommitUpdates();
171
172 {
173 auto root_node = bridge->GetFlutterPlatformNodeDelegateFromID(0).lock();
174 EXPECT_TRUE(root_node->GetData().HasState(ax::mojom::State::kExpanded));
175
176 // Get the IAccessible for the root node.
177 IAccessible* native_view = root_node->GetNativeViewAccessible();
178 ASSERT_TRUE(native_view != nullptr);
179
180 // Look up against the node itself (not one of its children).
181 VARIANT varchild = {};
182 varchild.vt = VT_I4;
183
184 // Verify the submenu is expanded.
185 varchild.lVal = CHILDID_SELF;
186 VARIANT native_state = {};
187 ASSERT_TRUE(SUCCEEDED(native_view->get_accState(varchild, &native_state)));
188 EXPECT_TRUE(native_state.lVal & STATE_SYSTEM_EXPANDED);
189
190 // Perform similar tests for UIA value;
191 IRawElementProviderSimple* uia_node;
192 native_view->QueryInterface(IID_PPV_ARGS(&uia_node));
193 ASSERT_TRUE(SUCCEEDED(uia_node->GetPropertyValue(
194 UIA_ExpandCollapseExpandCollapseStatePropertyId, &native_state)));
195 EXPECT_EQ(native_state.lVal, ExpandCollapseState_Expanded);
196
197 ASSERT_TRUE(SUCCEEDED(uia_node->GetPropertyValue(
198 UIA_AriaPropertiesPropertyId, &native_state)));
199 EXPECT_NE(std::wcsstr(native_state.bstrVal, L"expanded=true"), nullptr);
200 }
201
202 // Test collapsed too.
203 root.flags = static_cast<FlutterSemanticsFlag>(
204 FlutterSemanticsFlag::kFlutterSemanticsFlagHasExpandedState);
205 bridge->AddFlutterSemanticsNodeUpdate(root);
206 bridge->CommitUpdates();
207
208 {
209 auto root_node = bridge->GetFlutterPlatformNodeDelegateFromID(0).lock();
210 EXPECT_TRUE(root_node->GetData().HasState(ax::mojom::State::kCollapsed));
211
212 // Get the IAccessible for the root node.
213 IAccessible* native_view = root_node->GetNativeViewAccessible();
214 ASSERT_TRUE(native_view != nullptr);
215
216 // Look up against the node itself (not one of its children).
217 VARIANT varchild = {};
218 varchild.vt = VT_I4;
219
220 // Verify the submenu is collapsed.
221 varchild.lVal = CHILDID_SELF;
222 VARIANT native_state = {};
223 ASSERT_TRUE(SUCCEEDED(native_view->get_accState(varchild, &native_state)));
224 EXPECT_TRUE(native_state.lVal & STATE_SYSTEM_COLLAPSED);
225
226 // Perform similar tests for UIA value;
227 IRawElementProviderSimple* uia_node;
228 native_view->QueryInterface(IID_PPV_ARGS(&uia_node));
229 ASSERT_TRUE(SUCCEEDED(uia_node->GetPropertyValue(
230 UIA_ExpandCollapseExpandCollapseStatePropertyId, &native_state)));
231 EXPECT_EQ(native_state.lVal, ExpandCollapseState_Collapsed);
232
233 ASSERT_TRUE(SUCCEEDED(uia_node->GetPropertyValue(
234 UIA_AriaPropertiesPropertyId, &native_state)));
235 EXPECT_NE(std::wcsstr(native_state.bstrVal, L"expanded=false"), nullptr);
236 }
237 }

## ◆ TEST() [77/161]

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

Definition at line 1275 of file flutter_windows_view_unittests.cc.

1275 {
1276 std::unique_ptr<FlutterWindowsEngine> engine = GetTestEngine();
1277 EngineModifier modifier(engine.get());
1278 modifier.embedder_api().UpdateSemanticsEnabled =
1279 [](FLUTTER_API_SYMBOL(FlutterEngine) engine, bool enabled) {
1280 return kSuccess;
1281 };
1282
1283 std::unique_ptr<FlutterWindowsView> view = engine->CreateView(
1284 std::make_unique<NiceMock<MockWindowBindingHandler>>());
1285
1286 // Enable semantics to instantiate accessibility bridge.
1287 view->OnUpdateSemanticsEnabled(true);
1288
1289 auto bridge = view->accessibility_bridge().lock();
1290 ASSERT_TRUE(bridge);
1291
1292 FlutterSemanticsNode2 root{sizeof(FlutterSemanticsNode2), 0};
1293 root.id = 0;
1294 root.label = "root";
1295 root.hint = "";
1296 root.value = "";
1297 root.increased_value = "";
1298 root.decreased_value = "";
1299 root.child_count = 0;
1300 root.custom_accessibility_actions_count = 0;
1301 root.flags = static_cast<FlutterSemanticsFlag>(
1302 FlutterSemanticsFlag::kFlutterSemanticsFlagHasToggledState |
1303 FlutterSemanticsFlag::kFlutterSemanticsFlagIsToggled);
1304 bridge->AddFlutterSemanticsNodeUpdate(root);
1305
1306 bridge->CommitUpdates();
1307
1308 {
1309 auto root_node = bridge->GetFlutterPlatformNodeDelegateFromID(0).lock();
1310 EXPECT_EQ(root_node->GetData().role, ax::mojom::Role::kSwitch);
1311 EXPECT_EQ(root_node->GetData().GetCheckedState(),
1312 ax::mojom::CheckedState::kTrue);
1313
1314 // Get the IAccessible for the root node.
1315 IAccessible* native_view = root_node->GetNativeViewAccessible();
1316 ASSERT_TRUE(native_view != nullptr);
1317
1318 // Look up against the node itself (not one of its children).
1319 VARIANT varchild = {};
1320 varchild.vt = VT_I4;
1321
1322 varchild.lVal = CHILDID_SELF;
1323 VARIANT varrole = {};
1324
1325 // Verify the role of the switch is CHECKBUTTON
1326 ASSERT_EQ(native_view->get_accRole(varchild, &varrole), S_OK);
1327 ASSERT_EQ(varrole.lVal, ROLE_SYSTEM_CHECKBUTTON);
1328
1329 // Verify the switch is pressed.
1330 VARIANT native_state = {};
1331 ASSERT_TRUE(SUCCEEDED(native_view->get_accState(varchild, &native_state)));
1332 EXPECT_TRUE(native_state.lVal & STATE_SYSTEM_PRESSED);
1333 EXPECT_TRUE(native_state.lVal & STATE_SYSTEM_CHECKED);
1334
1335 // Test similarly on UIA node.
1336 IRawElementProviderSimple* uia_node;
1337 native_view->QueryInterface(IID_PPV_ARGS(&uia_node));
1338 ASSERT_EQ(uia_node->GetPropertyValue(UIA_ControlTypePropertyId, &varrole),
1339 S_OK);
1340 EXPECT_EQ(varrole.lVal, UIA_ButtonControlTypeId);
1341 ASSERT_EQ(uia_node->GetPropertyValue(UIA_ToggleToggleStatePropertyId,
1342 &native_state),
1343 S_OK);
1344 EXPECT_EQ(native_state.lVal, ToggleState_On);
1345 ASSERT_EQ(
1346 uia_node->GetPropertyValue(UIA_AriaPropertiesPropertyId, &native_state),
1347 S_OK);
1348 EXPECT_NE(std::wcsstr(native_state.bstrVal, L"pressed=true"), nullptr);
1349 }
1350
1351 // Test unpressed too.
1352 root.flags = static_cast<FlutterSemanticsFlag>(
1353 FlutterSemanticsFlag::kFlutterSemanticsFlagHasToggledState);
1354 bridge->AddFlutterSemanticsNodeUpdate(root);
1355 bridge->CommitUpdates();
1356
1357 {
1358 auto root_node = bridge->GetFlutterPlatformNodeDelegateFromID(0).lock();
1359 EXPECT_EQ(root_node->GetData().role, ax::mojom::Role::kSwitch);
1360 EXPECT_EQ(root_node->GetData().GetCheckedState(),
1361 ax::mojom::CheckedState::kFalse);
1362
1363 // Get the IAccessible for the root node.
1364 IAccessible* native_view = root_node->GetNativeViewAccessible();
1365 ASSERT_TRUE(native_view != nullptr);
1366
1367 // Look up against the node itself (not one of its children).
1368 VARIANT varchild = {};
1369 varchild.vt = VT_I4;
1370
1371 // Verify the switch is not pressed.
1372 varchild.lVal = CHILDID_SELF;
1373 VARIANT native_state = {};
1374 ASSERT_TRUE(SUCCEEDED(native_view->get_accState(varchild, &native_state)));
1375 EXPECT_FALSE(native_state.lVal & STATE_SYSTEM_PRESSED);
1376 EXPECT_FALSE(native_state.lVal & STATE_SYSTEM_CHECKED);
1377
1378 // Test similarly on UIA node.
1379 IRawElementProviderSimple* uia_node;
1380 native_view->QueryInterface(IID_PPV_ARGS(&uia_node));
1381 ASSERT_EQ(uia_node->GetPropertyValue(UIA_ToggleToggleStatePropertyId,
1382 &native_state),
1383 S_OK);
1384 EXPECT_EQ(native_state.lVal, ToggleState_Off);
1385 ASSERT_EQ(
1386 uia_node->GetPropertyValue(UIA_AriaPropertiesPropertyId, &native_state),
1387 S_OK);
1388 EXPECT_NE(std::wcsstr(native_state.bstrVal, L"pressed=false"), nullptr);
1389 }
1390 }

## ◆ TEST() [78/161]

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

Definition at line 943 of file flutter_windows_view_unittests.cc.

943 {
944 auto windows_proc_table = std::make_shared<NiceMock<MockWindowsProcTable>>();
945 std::unique_ptr<FlutterWindowsEngine> engine =
946 GetTestEngine(windows_proc_table);
947
948 EngineModifier engine_modifier{engine.get()};
949 engine_modifier.embedder_api().PostRenderThreadTask = MOCK_ENGINE_PROC(
950 PostRenderThreadTask,
951 ([](auto engine, VoidCallback callback, void* user_data) {
952 callback(user_data);
953 return kSuccess;
954 }));
955
956 auto egl_manager = std::make_unique<egl::MockManager>();
957 auto surface = std::make_unique<egl::MockWindowSurface>();
958 auto resized_surface = std::make_unique<egl::MockWindowSurface>();
959 auto resized_surface_ptr = resized_surface.get();
960
961 EXPECT_CALL(*surface.get(), IsValid).WillRepeatedly(Return(true));
962 EXPECT_CALL(*surface.get(), Destroy).WillOnce(Return(true));
963
964 EXPECT_CALL(*egl_manager.get(),
965 CreateWindowSurface(_, /*width=*/500, /*height=*/500))
966 .WillOnce(Return(std::move((resized_surface))));
967 EXPECT_CALL(*resized_surface_ptr, MakeCurrent).WillOnce(Return(true));
968 EXPECT_CALL(*resized_surface_ptr, SetVSyncEnabled).WillOnce(Return(true));
969 EXPECT_CALL(*windows_proc_table.get(), DwmFlush).WillOnce(Return(S_OK));
970
971 EXPECT_CALL(*resized_surface_ptr, Destroy).WillOnce(Return(true));
972
973 fml::AutoResetWaitableEvent metrics_sent_latch;
974 engine_modifier.embedder_api().SendWindowMetricsEvent = MOCK_ENGINE_PROC(
975 SendWindowMetricsEvent,
976 ([&metrics_sent_latch](auto engine,
977 const FlutterWindowMetricsEvent* event) {
978 metrics_sent_latch.Signal();
979 return kSuccess;
980 }));
981
982 std::unique_ptr<FlutterWindowsView> view = engine->CreateView(
983 std::make_unique<NiceMock<MockWindowBindingHandler>>());
984
985 ViewModifier view_modifier{view.get()};
986 engine_modifier.SetEGLManager(std::move(egl_manager));
987 view_modifier.SetSurface(std::move(surface));
988
989 // Simulate raster thread.
990 std::thread([&metrics_sent_latch, &view]() {
991 metrics_sent_latch.Wait();
992
993 // Empty frame generated and presented from the raster thread.
994 EXPECT_TRUE(view->OnEmptyFrameGenerated());
995 view->OnFramePresented();
996 }).detach();
997
998 // Start the window resize. This sends the new window metrics
999 // and then blocks until another thread completes the window resize.
1000 EXPECT_TRUE(view->OnWindowSizeChanged(500, 500));
1001 }
VoidCallback
void(* VoidCallback)(void *)
Definition: flutter_windows.h:21

References callback, and user_data.

## ◆ TEST() [79/161]

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

Definition at line 1392 of file flutter_windows_view_unittests.cc.

1392 {
1393 std::unique_ptr<FlutterWindowsEngine> engine = GetTestEngine();
1394 EngineModifier modifier(engine.get());
1395 modifier.embedder_api().UpdateSemanticsEnabled =
1396 [](FLUTTER_API_SYMBOL(FlutterEngine) engine, bool enabled) {
1397 return kSuccess;
1398 };
1399
1400 std::unique_ptr<FlutterWindowsView> view = engine->CreateView(
1401 std::make_unique<NiceMock<MockWindowBindingHandler>>());
1402
1403 // Enable semantics to instantiate accessibility bridge.
1404 view->OnUpdateSemanticsEnabled(true);
1405
1406 auto bridge = view->accessibility_bridge().lock();
1407 ASSERT_TRUE(bridge);
1408
1409 FlutterSemanticsNode2 root{sizeof(FlutterSemanticsNode2), 0};
1410 root.id = 0;
1411 root.label = "root";
1412 root.hint = "";
1413 root.value = "";
1414 root.increased_value = "";
1415 root.decreased_value = "";
1416 root.tooltip = "tooltip";
1417 root.child_count = 0;
1418 root.custom_accessibility_actions_count = 0;
1419 root.flags = static_cast<FlutterSemanticsFlag>(
1420 FlutterSemanticsFlag::kFlutterSemanticsFlagIsTextField);
1421 bridge->AddFlutterSemanticsNodeUpdate(root);
1422
1423 bridge->CommitUpdates();
1424 auto root_node = bridge->GetFlutterPlatformNodeDelegateFromID(0).lock();
1425 std::string tooltip = root_node->GetData().GetStringAttribute(
1426 ax::mojom::StringAttribute::kTooltip);
1427 EXPECT_EQ(tooltip, "tooltip");
1428
1429 // Check that MSAA name contains the tooltip.
1430 IAccessible* native_view = bridge->GetFlutterPlatformNodeDelegateFromID(0)
1431 .lock()
1432 ->GetNativeViewAccessible();
1433 VARIANT varchild = {.vt = VT_I4, .lVal = CHILDID_SELF};
1434 BSTR bname;
1435 ASSERT_EQ(native_view->get_accName(varchild, &bname), S_OK);
1436 EXPECT_NE(std::wcsstr(bname, L"tooltip"), nullptr);
1437
1438 // Check that UIA help text is equal to the tooltip.
1439 IRawElementProviderSimple* uia_node;
1440 native_view->QueryInterface(IID_PPV_ARGS(&uia_node));
1441 VARIANT varname{};
1442 ASSERT_EQ(uia_node->GetPropertyValue(UIA_HelpTextPropertyId, &varname), S_OK);
1443 std::string uia_tooltip = _com_util::ConvertBSTRToString(varname.bstrVal);
1444 EXPECT_EQ(uia_tooltip, "tooltip");
1445 }

## ◆ TEST() [80/161]

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

Definition at line 1610 of file flutter_windows_view_unittests.cc.

1610 {
1611 auto windows_proc_table = std::make_shared<MockWindowsProcTable>();
1612 auto engine = std::make_unique<MockFlutterWindowsEngine>(windows_proc_table);
1613 auto egl_manager = std::make_unique<egl::MockManager>();
1614 egl::MockContext render_context;
1615 auto surface = std::make_unique<egl::MockWindowSurface>();
1616 auto surface_ptr = surface.get();
1617
1618 EXPECT_CALL(*engine.get(), running).WillRepeatedly(Return(true));
1619
1620 EXPECT_CALL(*engine.get(), PostRasterThreadTask)
1621 .WillRepeatedly([](fml::closure callback) {
1622 callback();
1623 return true;
1624 });
1625
1626 EXPECT_CALL(*egl_manager.get(), render_context)
1627 .WillRepeatedly(Return(&render_context));
1628
1629 EXPECT_CALL(*surface_ptr, IsValid).WillRepeatedly(Return(true));
1630 EXPECT_CALL(*surface_ptr, MakeCurrent).WillRepeatedly(Return(true));
1631 EXPECT_CALL(*surface_ptr, Destroy).Times(1);
1632 EXPECT_CALL(render_context, ClearCurrent).WillRepeatedly(Return(true));
1633
1634 InSequence s;
1635
1636 // Mock render surface initialization.
1637 std::unique_ptr<FlutterWindowsView> view;
1638 {
1639 EXPECT_CALL(*egl_manager, CreateWindowSurface)
1640 .WillOnce(Return(std::move(surface)));
1641 EXPECT_CALL(*windows_proc_table.get(), DwmIsCompositionEnabled)
1642 .WillOnce(Return(true));
1643 EXPECT_CALL(*surface_ptr, SetVSyncEnabled).WillOnce(Return(true));
1644
1645 EngineModifier engine_modifier{engine.get()};
1646 engine_modifier.SetEGLManager(std::move(egl_manager));
1647
1648 view = engine->CreateView(
1649 std::make_unique<NiceMock<MockWindowBindingHandler>>());
1650 }
1651
1652 // Disabling DWM composition should enable vsync blocking on the surface.
1653 {
1654 EXPECT_CALL(*windows_proc_table.get(), DwmIsCompositionEnabled)
1655 .WillOnce(Return(false));
1656 EXPECT_CALL(*surface_ptr, SetVSyncEnabled(true)).WillOnce(Return(true));
1657
1658 engine->OnDwmCompositionChanged();
1659 }
1660
1661 // Enabling DWM composition should disable vsync blocking on the surface.
1662 {
1663 EXPECT_CALL(*windows_proc_table.get(), DwmIsCompositionEnabled)
1664 .WillOnce(Return(true));
1665 EXPECT_CALL(*surface_ptr, SetVSyncEnabled(false)).WillOnce(Return(true));
1666
1667 engine->OnDwmCompositionChanged();
1668 }
1669 }

References callback.

## ◆ TEST() [81/161]

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

Definition at line 1107 of file flutter_windows_view_unittests.cc.

1107 {
1108 std::unique_ptr<FlutterWindowsEngine> engine = GetTestEngine();
1109 EngineModifier modifier(engine.get());
1110
1111 FlutterWindowsView view{kImplicitViewId, engine.get(),
1112 std::make_unique<flutter::FlutterWindow>(100, 100)};
1113
1114 bool schedule_frame_called = false;
1115 modifier.embedder_api().ScheduleFrame =
1116 MOCK_ENGINE_PROC(ScheduleFrame, ([&schedule_frame_called](auto engine) {
1117 schedule_frame_called = true;
1118 return kSuccess;
1119 }));
1120
1121 view.OnWindowRepaint();
1122 EXPECT_TRUE(schedule_frame_called);
1123 }
flutter::kImplicitViewId
constexpr FlutterViewId kImplicitViewId
Definition: flutter_windows_engine.h:55

References flutter::kImplicitViewId.

## ◆ TEST() [82/161]

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

Definition at line 1045 of file flutter_windows_view_unittests.cc.

1045 {
1046 std::unique_ptr<FlutterWindowsEngine> engine = GetTestEngine();
1047
1048 EngineModifier engine_modifier(engine.get());
1049 engine_modifier.embedder_api().PostRenderThreadTask = MOCK_ENGINE_PROC(
1050 PostRenderThreadTask,
1051 ([](auto engine, VoidCallback callback, void* user_data) {
1052 callback(user_data);
1053 return kSuccess;
1054 }));
1055
1056 auto egl_manager = std::make_unique<egl::MockManager>();
1057 auto surface = std::make_unique<egl::MockWindowSurface>();
1058
1059 EXPECT_CALL(*egl_manager.get(), CreateWindowSurface).Times(0);
1060 EXPECT_CALL(*surface.get(), IsValid).WillRepeatedly(Return(false));
1061 EXPECT_CALL(*surface.get(), Destroy).WillOnce(Return(false));
1062
1063 std::unique_ptr<FlutterWindowsView> view = engine->CreateView(
1064 std::make_unique<NiceMock<MockWindowBindingHandler>>());
1065
1066 ViewModifier view_modifier{view.get()};
1067 engine_modifier.SetEGLManager(std::move(egl_manager));
1068 view_modifier.SetSurface(std::move(surface));
1069
1070 auto metrics_sent = false;
1071 engine_modifier.embedder_api().SendWindowMetricsEvent = MOCK_ENGINE_PROC(
1072 SendWindowMetricsEvent,
1073 ([&metrics_sent](auto engine, const FlutterWindowMetricsEvent* event) {
1074 metrics_sent = true;
1075 return kSuccess;
1076 }));
1077
1078 view->OnWindowSizeChanged(500, 500);
1079 }

References callback, and user_data.

## ◆ TEST() [83/161]

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

Definition at line 1006 of file flutter_windows_view_unittests.cc.

1006 {
1007 std::unique_ptr<FlutterWindowsEngine> engine = GetTestEngine();
1008
1009 EngineModifier engine_modifier(engine.get());
1010 engine_modifier.embedder_api().PostRenderThreadTask = MOCK_ENGINE_PROC(
1011 PostRenderThreadTask,
1012 ([](auto engine, VoidCallback callback, void* user_data) {
1013 callback(user_data);
1014 return kSuccess;
1015 }));
1016
1017 auto egl_manager = std::make_unique<egl::MockManager>();
1018 auto surface = std::make_unique<egl::MockWindowSurface>();
1019
1020 EXPECT_CALL(*surface.get(), IsValid).WillRepeatedly(Return(true));
1021 EXPECT_CALL(*surface.get(), Destroy).WillOnce(Return(true));
1022
1023 std::unique_ptr<FlutterWindowsView> view = engine->CreateView(
1024 std::make_unique<NiceMock<MockWindowBindingHandler>>());
1025
1026 ViewModifier view_modifier{view.get()};
1027 engine_modifier.SetEGLManager(std::move(egl_manager));
1028 view_modifier.SetSurface(std::move(surface));
1029
1030 // Begin a frame.
1031 ASSERT_TRUE(view->OnFrameGenerated(100, 100));
1032
1033 // Inject a window resize between the frame generation and
1034 // frame presentation. The new size invalidates the current frame.
1035 EXPECT_FALSE(view->OnWindowSizeChanged(500, 500));
1036
1037 // Complete the invalidated frame while a resize is pending. Although this
1038 // might mean that we presented a frame with the wrong size, this should not
1039 // crash the app.
1040 view->OnFramePresented();
1041 }

References callback, and user_data.

## ◆ TEST() [84/161]

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

Definition at line 873 of file flutter_windows_view_unittests.cc.

873 {
874 auto windows_proc_table = std::make_shared<NiceMock<MockWindowsProcTable>>();
875 std::unique_ptr<FlutterWindowsEngine> engine =
876 GetTestEngine(windows_proc_table);
877
878 EngineModifier engine_modifier{engine.get()};
879 engine_modifier.embedder_api().PostRenderThreadTask = MOCK_ENGINE_PROC(
880 PostRenderThreadTask,
881 ([](auto engine, VoidCallback callback, void* user_data) {
882 callback(user_data);
883 return kSuccess;
884 }));
885
886 auto egl_manager = std::make_unique<egl::MockManager>();
887 auto surface = std::make_unique<egl::MockWindowSurface>();
888 auto resized_surface = std::make_unique<egl::MockWindowSurface>();
889 egl::MockContext render_context;
890
891 auto surface_ptr = surface.get();
892 auto resized_surface_ptr = resized_surface.get();
893
894 // Mock render surface creation
895 EXPECT_CALL(*egl_manager, CreateWindowSurface)
896 .WillOnce(Return(std::move(surface)));
897 EXPECT_CALL(*surface_ptr, IsValid).WillRepeatedly(Return(true));
898 EXPECT_CALL(*surface_ptr, MakeCurrent).WillOnce(Return(true));
899 EXPECT_CALL(*surface_ptr, SetVSyncEnabled).WillOnce(Return(true));
900 EXPECT_CALL(*egl_manager, render_context).WillOnce(Return(&render_context));
901 EXPECT_CALL(render_context, ClearCurrent).WillOnce(Return(true));
902
903 // Mock render surface resize
904 EXPECT_CALL(*surface_ptr, Destroy).WillOnce(Return(true));
905 EXPECT_CALL(*egl_manager.get(),
906 CreateWindowSurface(_, /*width=*/500, /*height=*/500))
907 .WillOnce(Return(std::move((resized_surface))));
908 EXPECT_CALL(*resized_surface_ptr, MakeCurrent).WillOnce(Return(true));
909 EXPECT_CALL(*resized_surface_ptr, SetVSyncEnabled).WillOnce(Return(true));
910 EXPECT_CALL(*windows_proc_table.get(), DwmFlush).WillOnce(Return(S_OK));
911
912 EXPECT_CALL(*resized_surface_ptr, Destroy).WillOnce(Return(true));
913
914 engine_modifier.SetEGLManager(std::move(egl_manager));
915
916 std::unique_ptr<FlutterWindowsView> view = engine->CreateView(
917 std::make_unique<NiceMock<MockWindowBindingHandler>>());
918
919 fml::AutoResetWaitableEvent metrics_sent_latch;
920 engine_modifier.embedder_api().SendWindowMetricsEvent = MOCK_ENGINE_PROC(
921 SendWindowMetricsEvent,
922 ([&metrics_sent_latch](auto engine,
923 const FlutterWindowMetricsEvent* event) {
924 metrics_sent_latch.Signal();
925 return kSuccess;
926 }));
927
928 // Simulate raster thread.
929 std::thread([&metrics_sent_latch, &view]() {
930 metrics_sent_latch.Wait();
931 // Frame generated and presented from the raster thread.
932 EXPECT_TRUE(view->OnFrameGenerated(500, 500));
933 view->OnFramePresented();
934 }).detach();
935
936 // Start the window resize. This sends the new window metrics
937 // and then blocks polling run loop until another thread completes the window
938 // resize.
939 EXPECT_TRUE(view->OnWindowSizeChanged(500, 500));
940 }

References callback, and user_data.

## ◆ TEST() [85/161]

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

Definition at line 1083 of file flutter_windows_view_unittests.cc.

1083 {
1084 std::unique_ptr<FlutterWindowsEngine> engine = GetTestEngine();
1085 EngineModifier modifier(engine.get());
1086
1087 auto egl_manager = std::make_unique<egl::MockManager>();
1088
1089 EXPECT_CALL(*egl_manager.get(), CreateWindowSurface).Times(0);
1090
1091 std::unique_ptr<FlutterWindowsView> view = engine->CreateView(
1092 std::make_unique<NiceMock<MockWindowBindingHandler>>());
1093
1094 modifier.SetEGLManager(std::move(egl_manager));
1095
1096 auto metrics_sent = false;
1097 modifier.embedder_api().SendWindowMetricsEvent = MOCK_ENGINE_PROC(
1098 SendWindowMetricsEvent,
1099 ([&metrics_sent](auto engine, const FlutterWindowMetricsEvent* event) {
1100 metrics_sent = true;
1101 return kSuccess;
1102 }));
1103
1104 view->OnWindowSizeChanged(500, 500);
1105 }

## ◆ TEST() [86/161]

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:17

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

## ◆ TEST() [87/161]

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

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

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

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

Definition at line 764 of file keyboard_key_embedder_handler_unittests.cc.

764 {
765 TestKeystate key_state;
766 std::vector<TestFlutterKeyEvent> results;
767 TestFlutterKeyEvent* event;
768 bool last_handled = false;
769
770 std::unique_ptr<KeyboardKeyEmbedderHandler> handler =
771 std::make_unique<KeyboardKeyEmbedderHandler>(
772 [&results](const FlutterKeyEvent& event,
773 FlutterKeyEventCallback callback, void* user_data) {
774 results.emplace_back(event, callback, user_data);
775 },
776 key_state.Getter(), DefaultMapVkToScan);
777 last_handled = false;
778
779 key_state.Set(kVirtualKeyA, true);
780
781 // Press A (with was_down true)
782 handler->KeyboardHook(
783 kVirtualKeyA, kScanCodeKeyA, WM_KEYDOWN, 'a', false, true,
784 [&last_handled](bool handled) { last_handled = handled; });
785 EXPECT_EQ(last_handled, false);
786 EXPECT_EQ(results.size(), 1);
787 event = &results[0];
788 EXPECT_EQ(event->type, kFlutterKeyEventTypeDown);
789 EXPECT_EQ(event->physical, kPhysicalKeyA);
790 EXPECT_EQ(event->logical, kLogicalKeyA);
791 EXPECT_STREQ(event->character, "a");
792 EXPECT_EQ(event->synthesized, false);
793
794 event->callback(true, event->user_data);
795 EXPECT_EQ(last_handled, true);
796 results.clear();
797
798 // Release A
799 last_handled = false;
800 key_state.Set(kVirtualKeyA, false);
801 handler->KeyboardHook(
802 kVirtualKeyA, kScanCodeKeyA, WM_KEYUP, 'a', false, true,
803 [&last_handled](bool handled) { last_handled = handled; });
804 EXPECT_EQ(last_handled, false);
805 EXPECT_EQ(results.size(), 1);
806 event = &results[0];
807 EXPECT_EQ(event->type, kFlutterKeyEventTypeUp);
808 EXPECT_EQ(event->physical, kPhysicalKeyA);
809 EXPECT_EQ(event->logical, kLogicalKeyA);
810 EXPECT_STREQ(event->character, "");
811 EXPECT_EQ(event->synthesized, false);
812
813 event->callback(true, event->user_data);
814 EXPECT_EQ(last_handled, true);
815 results.clear();
816 }
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() [91/161]

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

Definition at line 818 of file keyboard_key_embedder_handler_unittests.cc.

818 {
819 TestKeystate key_state;
820 std::vector<TestFlutterKeyEvent> results;
821 TestFlutterKeyEvent* event;
822 bool last_handled = false;
823
824 std::unique_ptr<KeyboardKeyEmbedderHandler> handler =
825 std::make_unique<KeyboardKeyEmbedderHandler>(
826 [&results](const FlutterKeyEvent& event,
827 FlutterKeyEventCallback callback, void* user_data) {
828 results.emplace_back(event, callback, user_data);
829 },
830 key_state.Getter(), DefaultMapVkToScan);
831 last_handled = false;
832
833 // KeyA's key down is missed.
834
835 key_state.Set(kVirtualKeyA, true);
836
837 // Press A again (should yield an empty event)
838 last_handled = false;
839 handler->KeyboardHook(
840 kVirtualKeyA, kScanCodeKeyA, WM_KEYUP, 'a', false, true,
841 [&last_handled](bool handled) { last_handled = handled; });
842 EXPECT_EQ(last_handled, true);
843 EXPECT_EQ(results.size(), 1);
844 event = &results[0];
845 EXPECT_EQ(event->physical, 0);
846 EXPECT_EQ(event->logical, 0);
847 EXPECT_EQ(event->callback, nullptr);
848 results.clear();
849 }

References callback, kScanCodeKeyA, kVirtualKeyA, and user_data.

## ◆ TEST() [92/161]

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

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

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

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

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

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

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

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 yield an empty event)
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, true);
756 EXPECT_EQ(results.size(), 1);
757 event = &results[0];
758 EXPECT_EQ(event->physical, 0);
759 EXPECT_EQ(event->logical, 0);
760 EXPECT_EQ(event->callback, nullptr);
761 results.clear();
762 }

References callback, kScanCodeKeyA, kVirtualKeyA, and user_data.

## ◆ TEST() [100/161]

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

Definition at line 851 of file keyboard_key_embedder_handler_unittests.cc.

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

References callback, kScanCodeKeyA, kVirtualKeyA, and user_data.

## ◆ TEST() [101/161]

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

Definition at line 939 of file keyboard_key_embedder_handler_unittests.cc.

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

References callback, kScanCodeKeyA, kVirtualKeyA, and user_data.

## ◆ TEST() [102/161]

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

Definition at line 1119 of file keyboard_key_embedder_handler_unittests.cc.

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

References callback, and user_data.

## ◆ TEST() [103/161]

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

Definition at line 1059 of file keyboard_key_embedder_handler_unittests.cc.

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

References callback, and user_data.

## ◆ TEST() [104/161]

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

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

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

Definition at line 1177 of file keyboard_key_embedder_handler_unittests.cc.

1177 {
1178 TestKeystate key_state;
1179 std::vector<TestFlutterKeyEvent> results;
1180 TestFlutterKeyEvent* event;
1181 bool last_handled = false;
1182
1183 // The app starts with NumLock toggled on
1184 key_state.Set(VK_NUMLOCK, false, true);
1185
1186 std::unique_ptr<KeyboardKeyEmbedderHandler> handler =
1187 std::make_unique<KeyboardKeyEmbedderHandler>(
1188 [&results](const FlutterKeyEvent& event,
1189 FlutterKeyEventCallback callback, void* user_data) {
1190 results.emplace_back(event, callback, user_data);
1191 },
1192 key_state.Getter(), DefaultMapVkToScan);
1193
1194 // NumLock key down
1195 key_state.Set(VK_NUMLOCK, true, false);
1196 handler->KeyboardHook(
1197 VK_NUMLOCK, kScanCodeNumLock, WM_KEYDOWN, 0, true, false,
1198 [&last_handled](bool handled) { last_handled = handled; });
1199 EXPECT_EQ(last_handled, false);
1200 EXPECT_EQ(results.size(), 1);
1201 event = &results[0];
1202 EXPECT_EQ(event->type, kFlutterKeyEventTypeDown);
1203 EXPECT_EQ(event->physical, kPhysicalNumLock);
1204 EXPECT_EQ(event->logical, kLogicalNumLock);
1205 EXPECT_STREQ(event->character, "");
1206 EXPECT_EQ(event->synthesized, false);
1207
1208 event->callback(true, event->user_data);
1209 EXPECT_EQ(last_handled, true);
1210 results.clear();
1211 }

References callback, and user_data.

## ◆ TEST() [107/161]

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

Definition at line 1213 of file keyboard_key_embedder_handler_unittests.cc.

1213 {
1214 TestKeystate key_state;
1215 std::vector<TestFlutterKeyEvent> results;
1216 TestFlutterKeyEvent* event;
1217 bool last_handled = false;
1218
1219 std::unique_ptr<KeyboardKeyEmbedderHandler> handler =
1220 std::make_unique<KeyboardKeyEmbedderHandler>(
1221 [&results](const FlutterKeyEvent& event,
1222 FlutterKeyEventCallback callback, void* user_data) {
1223 results.emplace_back(event, callback, user_data);
1224 },
1225 key_state.Getter(), DefaultMapVkToScan);
1226
1227 // Press KeyAltLeft.
1228 key_state.Set(VK_LMENU, true);
1229 handler->KeyboardHook(
1230 VK_LMENU, kScanCodeAltLeft, WM_SYSKEYDOWN, 0, false, false,
1231 [&last_handled](bool handled) { last_handled = handled; });
1232 EXPECT_EQ(last_handled, false);
1233 EXPECT_EQ(results.size(), 1);
1234 event = results.data();
1235 EXPECT_EQ(event->type, kFlutterKeyEventTypeDown);
1236 EXPECT_EQ(event->physical, kPhysicalAltLeft);
1237 EXPECT_EQ(event->logical, kLogicalAltLeft);
1238 EXPECT_STREQ(event->character, "");
1239 EXPECT_EQ(event->synthesized, false);
1240
1241 event->callback(true, event->user_data);
1242 EXPECT_EQ(last_handled, true);
1243 results.clear();
1244
1245 // Release KeyAltLeft.
1246 key_state.Set(VK_LMENU, false);
1247 handler->KeyboardHook(
1248 VK_LMENU, kScanCodeAltLeft, WM_SYSKEYUP, 0, false, true,
1249 [&last_handled](bool handled) { last_handled = handled; });
1250 EXPECT_EQ(results.size(), 1);
1251 event = results.data();
1252 EXPECT_EQ(event->type, kFlutterKeyEventTypeUp);
1253 EXPECT_EQ(event->physical, kPhysicalAltLeft);
1254 EXPECT_EQ(event->logical, kLogicalAltLeft);
1255 EXPECT_STREQ(event->character, "");
1256 EXPECT_EQ(event->synthesized, false);
1257 event->callback(false, event->user_data);
1258 }

References callback, and user_data.

## ◆ TEST() [108/161]

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

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

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

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

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

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

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

Definition at line 23 of file window_unittests.cc.

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

## ◆ TEST() [115/161]

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(Invoke([&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() [116/161]

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

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

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

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

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

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

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

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

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

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

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

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

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

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::@88::KeyboardChange::Type type

References type.

## ◆ TEST() [130/161]

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Definition at line 68 of file task_runner_unittests.cc.

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

## ◆ TEST() [154/161]

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

Definition at line 45 of file task_runner_unittests.cc.

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

## ◆ TEST() [155/161]

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

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

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

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

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

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

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

Definition at line 64 of file flutter_windows_unittests.cc.

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

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

## ◆ TEST_F() [1/163]

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

Definition at line 125 of file compositor_opengl_unittests.cc.

125 {
126 UseHeadlessEngine();
127
128 auto compositor =
129 CompositorOpenGL{engine(), kMockResolver, /*enable_impeller=*/false};
130
131 FlutterBackingStoreConfig config = {};
132 FlutterBackingStore backing_store = {};
133
134 EXPECT_CALL(*render_context(), MakeCurrent).WillOnce(Return(true));
135 ASSERT_TRUE(compositor.CreateBackingStore(config, &backing_store));
136 ASSERT_TRUE(compositor.CollectBackingStore(&backing_store));
137 }

## ◆ TEST_F() [2/163]

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

Definition at line 139 of file compositor_opengl_unittests.cc.

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

## ◆ TEST_F() [3/163]

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

Definition at line 153 of file compositor_opengl_unittests.cc.

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

## ◆ TEST_F() [4/163]

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

Definition at line 206 of file compositor_opengl_unittests.cc.

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

## ◆ TEST_F() [5/163]

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

Definition at line 166 of file compositor_opengl_unittests.cc.

166 {
167 UseEngineWithView();
168
169 auto compositor =
170 CompositorOpenGL{engine(), kMockResolver, /*enable_impeller=*/false};
171
172 FlutterBackingStoreConfig config = {};
173 FlutterBackingStore backing_store = {};
174
175 EXPECT_CALL(*render_context(), MakeCurrent).WillOnce(Return(true));
176 ASSERT_TRUE(compositor.CreateBackingStore(config, &backing_store));
177
178 FlutterLayer layer = {};
179 layer.type = kFlutterLayerContentTypeBackingStore;
180 layer.backing_store = &backing_store;
181 const FlutterLayer* layer_ptr = &layer;
182
183 EXPECT_CALL(*surface(), IsValid).WillRepeatedly(Return(true));
184 EXPECT_CALL(*surface(), MakeCurrent).WillOnce(Return(true));
185 EXPECT_CALL(*surface(), SwapBuffers).WillOnce(Return(true));
186 EXPECT_TRUE(compositor.Present(view(), &layer_ptr, 1));
187
188 ASSERT_TRUE(compositor.CollectBackingStore(&backing_store));
189 }

## ◆ TEST_F() [6/163]

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

Definition at line 191 of file compositor_opengl_unittests.cc.

191 {
192 UseEngineWithView();
193
194 auto compositor =
195 CompositorOpenGL{engine(), kMockResolver, /*enable_impeller=*/false};
196
197 // The context will be bound twice: first to initialize the compositor, second
198 // to clear the surface.
199 EXPECT_CALL(*render_context(), MakeCurrent).WillOnce(Return(true));
200 EXPECT_CALL(*surface(), IsValid).WillRepeatedly(Return(true));
201 EXPECT_CALL(*surface(), MakeCurrent).WillOnce(Return(true));
202 EXPECT_CALL(*surface(), SwapBuffers).WillOnce(Return(true));
203 EXPECT_TRUE(compositor.Present(view(), nullptr, 0));
204 }

## ◆ TEST_F() [7/163]

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

Definition at line 70 of file compositor_software_unittests.cc.

70 {
71 CompositorSoftware compositor;
72
73 FlutterBackingStoreConfig config = {};
74 FlutterBackingStore backing_store = {};
75
76 ASSERT_TRUE(compositor.CreateBackingStore(config, &backing_store));
77 ASSERT_TRUE(compositor.CollectBackingStore(&backing_store));
78 }

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

## ◆ TEST_F() [8/163]

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

Definition at line 80 of file compositor_software_unittests.cc.

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

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

## ◆ TEST_F() [9/163]

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

Definition at line 101 of file compositor_software_unittests.cc.

101 {
102 UseEngineWithView();
103
104 CompositorSoftware compositor;
105
106 EXPECT_CALL(*view(), ClearSoftwareBitmap).WillOnce(Return(true));
107 EXPECT_TRUE(compositor.Present(view(), nullptr, 0));
108 }

References flutter::CompositorSoftware::Present().

## ◆ TEST_F() [10/163]

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

Definition at line 117 of file compositor_software_unittests.cc.

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

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

## ◆ TEST_F() [11/163]

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

Definition at line 167 of file compositor_software_unittests.cc.

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

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

## ◆ TEST_F() [12/163]

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

Definition at line 100 of file cursor_handler_unittests.cc.

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

References kActivateSystemCursorMethod.

## ◆ TEST_F() [13/163]

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

Definition at line 127 of file cursor_handler_unittests.cc.

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

References kCreateCustomCursorMethod.

## ◆ TEST_F() [14/163]

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

Definition at line 229 of file cursor_handler_unittests.cc.

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

References kCreateCustomCursorMethod, and kDeleteCustomCursorMethod.

## ◆ TEST_F() [15/163]

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

Definition at line 267 of file cursor_handler_unittests.cc.

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

References kDeleteCustomCursorMethod.

## ◆ TEST_F() [16/163]

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

Definition at line 158 of file cursor_handler_unittests.cc.

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

References kCreateCustomCursorMethod, and kSetCustomCursorMethod.

## ◆ TEST_F() [17/163]

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

Definition at line 199 of file cursor_handler_unittests.cc.

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

References kSetCustomCursorMethod.

## ◆ TEST_F() [18/163]

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

Definition at line 671 of file flutter_windows_engine_unittests.cc.

671 {
672 auto& context = GetContext();
673 WindowsConfigBuilder builder{context};
674 builder.SetDartEntrypoint("sendAccessibilityAnnouncement");
675
676 bool done = false;
677 auto native_entry =
678 CREATE_NATIVE_ENTRY([&](Dart_NativeArguments args) { done = true; });
679 context.AddNativeFunction("Signal", native_entry);
680
681 EnginePtr engine{builder.RunHeadless()};
682 ASSERT_NE(engine, nullptr);
683
684 ui::AXPlatformNodeDelegateBase parent_delegate;
685 AlertPlatformNodeDelegate delegate{parent_delegate};
686
687 auto window_binding_handler =
688 std::make_unique<NiceMock<MockWindowBindingHandler>>();
689 EXPECT_CALL(*window_binding_handler, GetAlertDelegate)
690 .WillOnce(Return(&delegate));
691
692 auto windows_engine = reinterpret_cast<FlutterWindowsEngine*>(engine.get());
693 MockFlutterWindowsView view{windows_engine,
694 std::move(window_binding_handler)};
695 EngineModifier modifier{windows_engine};
696 modifier.SetImplicitView(&view);
697
698 windows_engine->UpdateSemanticsEnabled(true);
699
700 EXPECT_CALL(view, NotifyWinEventWrapper).Times(1);
701
702 // Rely on timeout mechanism in CI.
703 while (!done) {
704 windows_engine->task_runner()->ProcessTasks();
705 }
706 }

References flutter::FlutterWindowsEngine::UpdateSemanticsEnabled().

## ◆ TEST_F() [19/163]

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

Definition at line 709 of file flutter_windows_engine_unittests.cc.

709 {
710 auto& context = GetContext();
711 WindowsConfigBuilder builder{context};
712 builder.SetDartEntrypoint("sendAccessibilityAnnouncement");
713
714 bool done = false;
715 auto native_entry =
716 CREATE_NATIVE_ENTRY([&](Dart_NativeArguments args) { done = true; });
717 context.AddNativeFunction("Signal", native_entry);
718
719 EnginePtr engine{builder.RunHeadless()};
720 ASSERT_NE(engine, nullptr);
721
722 auto windows_engine = reinterpret_cast<FlutterWindowsEngine*>(engine.get());
723 windows_engine->UpdateSemanticsEnabled(true);
724
725 // Rely on timeout mechanism in CI.
726 while (!done) {
727 windows_engine->task_runner()->ProcessTasks();
728 }
729 }

References flutter::FlutterWindowsEngine::UpdateSemanticsEnabled().

## ◆ TEST_F() [20/163]

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

Definition at line 733 of file flutter_windows_engine_unittests.cc.

733 {
734 fml::testing::LogCapture log_capture;
735
736 auto& context = GetContext();
737 WindowsConfigBuilder builder{context};
738 builder.SetDartEntrypoint("sendAccessibilityTooltipEvent");
739
740 bool done = false;
741 auto native_entry =
742 CREATE_NATIVE_ENTRY([&](Dart_NativeArguments args) { done = true; });
743 context.AddNativeFunction("Signal", native_entry);
744
745 ViewControllerPtr controller{builder.Run()};
746 ASSERT_NE(controller, nullptr);
747
748 auto engine = FlutterDesktopViewControllerGetEngine(controller.get());
749 auto windows_engine = reinterpret_cast<FlutterWindowsEngine*>(engine);
750 windows_engine->UpdateSemanticsEnabled(true);
751
752 // Rely on timeout mechanism in CI.
753 while (!done) {
754 windows_engine->task_runner()->ProcessTasks();
755 }
756
757 // Verify no error was logged.
758 // Regression test for:
759 // https://github.com/flutter/flutter/issues/144274
760 EXPECT_EQ(log_capture.str().find("tooltip"), std::string::npos);
761 }
FlutterDesktopViewControllerGetEngine
FlutterDesktopEngineRef FlutterDesktopViewControllerGetEngine(FlutterDesktopViewControllerRef ref)
Definition: flutter_windows.cc:147

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

## ◆ TEST_F() [21/163]

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

Definition at line 523 of file flutter_windows_engine_unittests.cc.

523 {
524 FlutterWindowsEngineBuilder builder{GetContext()};
525 std::unique_ptr<FlutterWindowsEngine> engine = builder.Build();
526 EngineModifier modifier(engine.get());
527
528 MockEmbedderApiForKeyboard(modifier,
529 std::make_shared<MockKeyResponseController>());
530
531 engine->Run();
532
533 // Verify that destruction handlers don't overwrite each other.
534 int result1 = 0;
535 int result2 = 0;
536 engine->AddPluginRegistrarDestructionCallback(
537 [](FlutterDesktopPluginRegistrarRef ref) {
538 auto result = reinterpret_cast<int*>(ref);
539 *result = 1;
540 },
541 reinterpret_cast<FlutterDesktopPluginRegistrarRef>(&result1));
542 engine->AddPluginRegistrarDestructionCallback(
543 [](FlutterDesktopPluginRegistrarRef ref) {
544 auto result = reinterpret_cast<int*>(ref);
545 *result = 2;
546 },
547 reinterpret_cast<FlutterDesktopPluginRegistrarRef>(&result2));
548
549 engine->Stop();
550 EXPECT_EQ(result1, 1);
551 EXPECT_EQ(result2, 2);
552 }
FlutterDesktopPluginRegistrar
Definition: window_state.h:23

## ◆ TEST_F() [22/163]

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

Definition at line 1296 of file flutter_windows_engine_unittests.cc.

1296 {
1297 FlutterWindowsEngineBuilder builder{GetContext()};
1298 auto engine = builder.Build();
1299
1300 EngineModifier modifier{engine.get()};
1301
1302 modifier.embedder_api().RunsAOTCompiledDartCode = []() { return false; };
1303 modifier.embedder_api().AddView = MOCK_ENGINE_PROC(
1304 AddView,
1305 [](FLUTTER_API_SYMBOL(FlutterEngine) engine,
1306 const FlutterAddViewInfo* info) { return kInternalInconsistency; });
1307
1308 ASSERT_TRUE(engine->Run());
1309
1310 // Create the first view. This is the implicit view and isn't added to the
1311 // engine.
1312 auto implicit_window = std::make_unique<NiceMock<MockWindowBindingHandler>>();
1313
1314 std::unique_ptr<FlutterWindowsView> implicit_view =
1315 engine->CreateView(std::move(implicit_window));
1316
1317 EXPECT_TRUE(implicit_view);
1318
1319 // Create a second view. The embedder attempts to add it to the engine.
1320 auto second_window = std::make_unique<NiceMock<MockWindowBindingHandler>>();
1321
1322 EXPECT_DEBUG_DEATH(engine->CreateView(std::move(second_window)),
1323 "FlutterEngineAddView returned an unexpected result");
1324 }

References flutter::FlutterEngine::Run().

## ◆ TEST_F() [23/163]

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

Definition at line 1002 of file flutter_windows_engine_unittests.cc.

1002 {
1003 FlutterWindowsEngineBuilder builder{GetContext()};
1004
1005 auto engine = builder.Build();
1006 auto window_binding_handler =
1007 std::make_unique<::testing::NiceMock<MockWindowBindingHandler>>();
1008 MockFlutterWindowsView view(engine.get(), std::move(window_binding_handler));
1009
1010 EngineModifier modifier(engine.get());
1011 modifier.SetImplicitView(&view);
1012 modifier.embedder_api().RunsAOTCompiledDartCode = []() { return false; };
1013 auto handler = std::make_unique<MockWindowsLifecycleManager>(engine.get());
1014 EXPECT_CALL(*handler, IsLastWindowOfProcess).WillOnce(Return(false));
1015 modifier.SetLifecycleManager(std::move(handler));
1016 engine->lifecycle_manager()->BeginProcessingExit();
1017
1018 engine->lifecycle_manager()->ExternalWindowMessage(0, WM_CLOSE, 0, 0);
1019 }

## ◆ TEST_F() [24/163]

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

Definition at line 1246 of file flutter_windows_engine_unittests.cc.

1246 {
1247 FlutterWindowsEngineBuilder builder{GetContext()};
1248 builder.SetDartEntrypoint("enableLifecycleToFrom");
1249
1250 auto engine = builder.Build();
1251 auto window_binding_handler =
1252 std::make_unique<::testing::NiceMock<MockWindowBindingHandler>>();
1253 MockFlutterWindowsView view(engine.get(), std::move(window_binding_handler));
1254
1255 EngineModifier modifier(engine.get());
1256 modifier.SetImplicitView(&view);
1257 modifier.embedder_api().RunsAOTCompiledDartCode = []() { return false; };
1258
1259 bool lifecycle_began = false;
1260 auto handler = std::make_unique<MockWindowsLifecycleManager>(engine.get());
1261 handler->begin_processing_callback = [&]() { lifecycle_began = true; };
1262 modifier.SetLifecycleManager(std::move(handler));
1263
1264 engine->Run();
1265
1266 while (!lifecycle_began) {
1267 engine->task_runner()->ProcessTasks();
1268 }
1269 }

## ◆ TEST_F() [25/163]

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

Definition at line 181 of file flutter_windows_engine_unittests.cc.

181 {
182 FlutterWindowsEngineBuilder builder{GetContext()};
183 std::unique_ptr<FlutterWindowsEngine> engine = builder.Build();
184 EngineModifier modifier(engine.get());
185 bool on_vsync_called = false;
186
187 modifier.embedder_api().GetCurrentTime =
188 MOCK_ENGINE_PROC(GetCurrentTime, ([]() -> uint64_t { return 1; }));
189 modifier.embedder_api().OnVsync = MOCK_ENGINE_PROC(
190 OnVsync,
191 ([&on_vsync_called, engine_instance = engine.get()](
192 FLUTTER_API_SYMBOL(FlutterEngine) engine, intptr_t baton,
193 uint64_t frame_start_time_nanos, uint64_t frame_target_time_nanos) {
194 EXPECT_EQ(baton, 1);
195 EXPECT_EQ(frame_start_time_nanos, 16600000);
196 EXPECT_EQ(frame_target_time_nanos, 33200000);
197 on_vsync_called = true;
198 return kSuccess;
199 }));
200 modifier.SetStartTime(0);
201 modifier.SetFrameInterval(16600000);
202
203 engine->OnVsync(1);
204
205 EXPECT_TRUE(on_vsync_called);
206 }

## ◆ TEST_F() [26/163]

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

Definition at line 478 of file flutter_windows_engine_unittests.cc.

478 {
479 FlutterWindowsEngineBuilder builder{GetContext()};
480 std::unique_ptr<FlutterWindowsEngine> engine = builder.Build();
481 EngineModifier modifier(engine.get());
482
483 bool called = false;
484 std::string message = "Hello";
485 modifier.embedder_api().SendSemanticsAction = MOCK_ENGINE_PROC(
486 SendSemanticsAction, ([&called, &message](auto engine, auto info) {
487 called = true;
488 EXPECT_EQ(info->view_id, 456);
489 EXPECT_EQ(info->node_id, 42);
490 EXPECT_EQ(info->action, kFlutterSemanticsActionDismiss);
491 EXPECT_EQ(memcmp(info->data, message.c_str(), message.size()), 0);
492 EXPECT_EQ(info->data_length, message.size());
493 return kSuccess;
494 }));
495
496 auto data = fml::MallocMapping::Copy(message.c_str(), message.size());
497 engine->DispatchSemanticsAction(456, 42, kFlutterSemanticsActionDismiss,
498 std::move(data));
499 EXPECT_TRUE(called);
500 }

References message.

## ◆ TEST_F() [27/163]

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

Definition at line 982 of file flutter_windows_engine_unittests.cc.

982 {
983 FlutterWindowsEngineBuilder builder{GetContext()};
984
985 auto engine = builder.Build();
986 auto window_binding_handler =
987 std::make_unique<::testing::NiceMock<MockWindowBindingHandler>>();
988 MockFlutterWindowsView view(engine.get(), std::move(window_binding_handler));
989
990 EngineModifier modifier(engine.get());
991 modifier.SetImplicitView(&view);
992 modifier.embedder_api().RunsAOTCompiledDartCode = []() { return false; };
993 auto handler = std::make_unique<MockWindowsLifecycleManager>(engine.get());
994 EXPECT_CALL(*handler, IsLastWindowOfProcess).WillOnce(Return(false));
995 modifier.SetLifecycleManager(std::move(handler));
996 engine->lifecycle_manager()->BeginProcessingExit();
997
998 engine->window_proc_delegate_manager()->OnTopLevelWindowProc(0, WM_CLOSE, 0,
999 0);
1000 }

## ◆ TEST_F() [28/163]

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

Definition at line 1145 of file flutter_windows_engine_unittests.cc.

1145 {
1146 FlutterWindowsEngineBuilder builder{GetContext()};
1147 builder.SetDartEntrypoint("enableLifecycleTest");
1148 bool finished = false;
1149
1150 auto engine = builder.Build();
1151 auto window_binding_handler =
1152 std::make_unique<::testing::NiceMock<MockWindowBindingHandler>>();
1153 MockFlutterWindowsView view(engine.get(), std::move(window_binding_handler));
1154
1155 EngineModifier modifier(engine.get());
1156 modifier.SetImplicitView(&view);
1157 modifier.embedder_api().RunsAOTCompiledDartCode = []() { return false; };
1158 auto handler = std::make_unique<MockWindowsLifecycleManager>(engine.get());
1159 EXPECT_CALL(*handler, SetLifecycleState)
1160 .WillRepeatedly([handler_ptr = handler.get()](AppLifecycleState state) {
1161 handler_ptr->WindowsLifecycleManager::SetLifecycleState(state);
1162 });
1163 modifier.SetLifecycleManager(std::move(handler));
1164
1165 auto binary_messenger =
1166 std::make_unique<BinaryMessengerImpl>(engine->messenger());
1167 // Mark the test only as completed on receiving an inactive state message.
1168 binary_messenger->SetMessageHandler(
1169 "flutter/unittest", [&finished](const uint8_t* message,
1170 size_t message_size, BinaryReply reply) {
1171 std::string contents(message, message + message_size);
1172 EXPECT_NE(contents.find("AppLifecycleState.inactive"),
1173 std::string::npos);
1174 finished = true;
1175 char response[] = "";
1176 reply(reinterpret_cast<uint8_t*>(response), 0);
1177 });
1178
1179 engine->Run();
1180
1181 // Test that setting the state before enabling lifecycle does nothing.
1182 HWND hwnd = reinterpret_cast<HWND>(1);
1183 view.OnWindowStateEvent(hwnd, WindowStateEvent::kShow);
1184 view.OnWindowStateEvent(hwnd, WindowStateEvent::kHide);
1185 EXPECT_FALSE(finished);
1186
1187 // Test that we can set the state afterwards.
1188
1189 engine->lifecycle_manager()->BeginProcessingLifecycle();
1190 view.OnWindowStateEvent(hwnd, WindowStateEvent::kShow);
1191
1192 while (!finished) {
1193 engine->task_runner()->ProcessTasks();
1194 }
1195 }
flutter::AppLifecycleState
AppLifecycleState
Definition: app_lifecycle_state.h:32

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

## ◆ TEST_F() [29/163]

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

Definition at line 1075 of file flutter_windows_engine_unittests.cc.

1075 {
1076 FlutterWindowsEngineBuilder builder{GetContext()};
1077
1078 auto engine = builder.Build();
1079 auto window_binding_handler =
1080 std::make_unique<::testing::NiceMock<MockWindowBindingHandler>>();
1081 MockFlutterWindowsView view(engine.get(), std::move(window_binding_handler));
1082
1083 EngineModifier modifier(engine.get());
1084 modifier.SetImplicitView(&view);
1085 modifier.embedder_api().RunsAOTCompiledDartCode = []() { return false; };
1086 // Sets lifecycle state to resumed.
1087 engine->Run();
1088
1089 // Ensure HWND(1) is in the set of visible windows before hiding it.
1090 engine->ProcessExternalWindowMessage(reinterpret_cast<HWND>(1), WM_SHOWWINDOW,
1091 TRUE, NULL);
1092 engine->ProcessExternalWindowMessage(reinterpret_cast<HWND>(1), WM_SHOWWINDOW,
1093 FALSE, NULL);
1094
1095 while (engine->lifecycle_manager()->IsUpdateStateScheduled()) {
1096 PumpMessage();
1097 }
1098
1099 EXPECT_EQ(engine->lifecycle_manager()->GetLifecycleState(),
1100 AppLifecycleState::kHidden);
1101 }

References flutter::kHidden.

## ◆ TEST_F() [30/163]

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

Definition at line 586 of file flutter_windows_engine_unittests.cc.

586 {
587 FlutterWindowsEngineBuilder builder{GetContext()};
588 std::unique_ptr<FlutterWindowsEngine> engine = builder.Build();
589 EXPECT_EQ(engine->GetExecutableName(), "flutter_windows_unittests.exe");
590 }

## ◆ TEST_F() [31/163]

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

Definition at line 1103 of file flutter_windows_engine_unittests.cc.

1103 {
1104 FlutterWindowsEngineBuilder builder{GetContext()};
1105 HWND outer = reinterpret_cast<HWND>(1);
1106 HWND inner = reinterpret_cast<HWND>(2);
1107
1108 auto engine = builder.Build();
1109 auto window_binding_handler =
1110 std::make_unique<::testing::NiceMock<MockWindowBindingHandler>>();
1111 MockFlutterWindowsView view(engine.get(), std::move(window_binding_handler));
1112 ON_CALL(view, GetWindowHandle).WillByDefault([=]() { return inner; });
1113
1114 EngineModifier modifier(engine.get());
1115 modifier.SetImplicitView(&view);
1116 modifier.embedder_api().RunsAOTCompiledDartCode = []() { return false; };
1117 // Sets lifecycle state to resumed.
1118 engine->Run();
1119
1120 // Show both top-level and Flutter window.
1121 engine->window_proc_delegate_manager()->OnTopLevelWindowProc(
1122 outer, WM_SHOWWINDOW, TRUE, NULL);
1123 view.OnWindowStateEvent(inner, WindowStateEvent::kShow);
1124 view.OnWindowStateEvent(inner, WindowStateEvent::kFocus);
1125
1126 while (engine->lifecycle_manager()->IsUpdateStateScheduled()) {
1127 PumpMessage();
1128 }
1129
1130 EXPECT_EQ(engine->lifecycle_manager()->GetLifecycleState(),
1131 AppLifecycleState::kResumed);
1132
1133 // Hide Flutter window, but not top level window.
1134 view.OnWindowStateEvent(inner, WindowStateEvent::kHide);
1135
1136 while (engine->lifecycle_manager()->IsUpdateStateScheduled()) {
1137 PumpMessage();
1138 }
1139
1140 // The top-level window is still visible, so we ought not enter hidden state.
1141 EXPECT_EQ(engine->lifecycle_manager()->GetLifecycleState(),
1142 AppLifecycleState::kInactive);
1143 }

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

## ◆ TEST_F() [32/163]

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

Definition at line 963 of file flutter_windows_engine_unittests.cc.

963 {
964 FlutterWindowsEngineBuilder builder{GetContext()};
965
966 auto engine = builder.Build();
967 auto window_binding_handler =
968 std::make_unique<::testing::NiceMock<MockWindowBindingHandler>>();
969 MockFlutterWindowsView view(engine.get(), std::move(window_binding_handler));
970
971 EngineModifier modifier(engine.get());
972 modifier.SetImplicitView(&view);
973 modifier.embedder_api().RunsAOTCompiledDartCode = []() { return false; };
974 auto handler = std::make_unique<MockWindowsLifecycleManager>(engine.get());
975 EXPECT_CALL(*handler, IsLastWindowOfProcess).Times(0);
976 modifier.SetLifecycleManager(std::move(handler));
977
978 engine->window_proc_delegate_manager()->OnTopLevelWindowProc(0, WM_CLOSE, 0,
979 0);
980 }

## ◆ TEST_F() [33/163]

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

Definition at line 1197 of file flutter_windows_engine_unittests.cc.

1197 {
1198 FlutterWindowsEngineBuilder builder{GetContext()};
1199 builder.SetDartEntrypoint("enableLifecycleToFrom");
1200 bool enabled_lifecycle = false;
1201 bool dart_responded = false;
1202
1203 auto engine = builder.Build();
1204 auto window_binding_handler =
1205 std::make_unique<::testing::NiceMock<MockWindowBindingHandler>>();
1206 MockFlutterWindowsView view(engine.get(), std::move(window_binding_handler));
1207
1208 EngineModifier modifier(engine.get());
1209 modifier.SetImplicitView(&view);
1210 modifier.embedder_api().RunsAOTCompiledDartCode = []() { return false; };
1211 auto handler = std::make_unique<MockWindowsLifecycleManager>(engine.get());
1212 EXPECT_CALL(*handler, SetLifecycleState)
1213 .WillRepeatedly([handler_ptr = handler.get()](AppLifecycleState state) {
1214 handler_ptr->WindowsLifecycleManager::SetLifecycleState(state);
1215 });
1216 handler->begin_processing_callback = [&]() { enabled_lifecycle = true; };
1217 modifier.SetLifecycleManager(std::move(handler));
1218
1219 auto binary_messenger =
1220 std::make_unique<BinaryMessengerImpl>(engine->messenger());
1221 binary_messenger->SetMessageHandler(
1222 "flutter/unittest",
1223 [&](const uint8_t* message, size_t message_size, BinaryReply reply) {
1224 std::string contents(message, message + message_size);
1225 EXPECT_NE(contents.find("AppLifecycleState."), std::string::npos);
1226 dart_responded = true;
1227 char response[] = "";
1228 reply(reinterpret_cast<uint8_t*>(response), 0);
1229 });
1230
1231 engine->Run();
1232
1233 while (!enabled_lifecycle) {
1234 engine->task_runner()->ProcessTasks();
1235 }
1236
1237 HWND hwnd = reinterpret_cast<HWND>(1);
1238 view.OnWindowStateEvent(hwnd, WindowStateEvent::kShow);
1239 view.OnWindowStateEvent(hwnd, WindowStateEvent::kHide);
1240
1241 while (!dart_responded) {
1242 engine->task_runner()->ProcessTasks();
1243 }
1244 }

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

## ◆ TEST_F() [34/163]

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

Definition at line 1021 of file flutter_windows_engine_unittests.cc.

1021 {
1022 FlutterWindowsEngineBuilder builder{GetContext()};
1023
1024 auto engine = builder.Build();
1025 auto window_binding_handler =
1026 std::make_unique<::testing::NiceMock<MockWindowBindingHandler>>();
1027 MockFlutterWindowsView view(engine.get(), std::move(window_binding_handler));
1028
1029 EngineModifier modifier(engine.get());
1030 modifier.SetImplicitView(&view);
1031 modifier.embedder_api().RunsAOTCompiledDartCode = []() { return false; };
1032 engine->Run();
1033
1034 engine->window_proc_delegate_manager()->OnTopLevelWindowProc(
1035 (HWND)1, WM_SIZE, SIZE_RESTORED, 0);
1036
1037 while (engine->lifecycle_manager()->IsUpdateStateScheduled()) {
1038 PumpMessage();
1039 }
1040
1041 EXPECT_EQ(engine->lifecycle_manager()->GetLifecycleState(),
1042 AppLifecycleState::kInactive);
1043
1044 engine->lifecycle_manager()->OnWindowStateEvent((HWND)1,
1045 WindowStateEvent::kFocus);
1046
1047 while (engine->lifecycle_manager()->IsUpdateStateScheduled()) {
1048 PumpMessage();
1049 }
1050
1051 EXPECT_EQ(engine->lifecycle_manager()->GetLifecycleState(),
1052 AppLifecycleState::kResumed);
1053
1054 engine->window_proc_delegate_manager()->OnTopLevelWindowProc(
1055 (HWND)1, WM_SIZE, SIZE_MINIMIZED, 0);
1056
1057 while (engine->lifecycle_manager()->IsUpdateStateScheduled()) {
1058 PumpMessage();
1059 }
1060
1061 EXPECT_EQ(engine->lifecycle_manager()->GetLifecycleState(),
1062 AppLifecycleState::kHidden);
1063
1064 engine->window_proc_delegate_manager()->OnTopLevelWindowProc(
1065 (HWND)1, WM_SIZE, SIZE_RESTORED, 0);
1066
1067 while (engine->lifecycle_manager()->IsUpdateStateScheduled()) {
1068 PumpMessage();
1069 }
1070
1071 EXPECT_EQ(engine->lifecycle_manager()->GetLifecycleState(),
1072 AppLifecycleState::kInactive);
1073 }

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

## ◆ TEST_F() [35/163]

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

Definition at line 1344 of file flutter_windows_engine_unittests.cc.

1344 {
1345 auto& context = GetContext();
1346 WindowsConfigBuilder builder{context};
1347 builder.SetDartEntrypoint("mergedUIThread");
1348 builder.SetUIThreadPolicy(FlutterDesktopUIThreadPolicy::RunOnPlatformThread);
1349
1350 std::optional<std::thread::id> ui_thread_id;
1351
1352 auto native_entry = CREATE_NATIVE_ENTRY([&](Dart_NativeArguments args) {
1353 ui_thread_id = std::this_thread::get_id();
1354 });
1355 context.AddNativeFunction("Signal", native_entry);
1356
1357 EnginePtr engine{builder.RunHeadless()};
1358 while (!ui_thread_id) {
1359 PumpMessage();
1360 }
1361 ASSERT_EQ(*ui_thread_id, std::this_thread::get_id());
1362 }
RunOnPlatformThread
@ RunOnPlatformThread
Definition: flutter_windows.h:54

References RunOnPlatformThread.

## ◆ TEST_F() [36/163]

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

Definition at line 1364 of file flutter_windows_engine_unittests.cc.

1364 {
1365 FlutterWindowsEngineBuilder builder{GetContext()};
1366 std::unique_ptr<FlutterWindowsEngine> engine = builder.Build();
1367 auto window_binding_handler =
1368 std::make_unique<::testing::NiceMock<MockWindowBindingHandler>>();
1369 MockFlutterWindowsView view(engine.get(), std::move(window_binding_handler));
1370
1371 EngineModifier modifier(engine.get());
1372 modifier.SetImplicitView(&view);
1373
1374 FlutterViewFocusChangeRequest request;
1375 request.view_id = kImplicitViewId;
1376
1377 EXPECT_CALL(view, Focus()).WillOnce(Return(true));
1378 modifier.OnViewFocusChangeRequest(&request);
1379 }

References flutter::kImplicitViewId.

## ◆ TEST_F() [37/163]

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

Definition at line 368 of file flutter_windows_engine_unittests.cc.

368 {
369 FlutterWindowsEngineBuilder builder{GetContext()};
370 builder.SetDartEntrypoint("hiPlatformChannels");
371
372 std::unique_ptr<FlutterWindowsEngine> engine = builder.Build();
373
374 EngineModifier modifier(engine.get());
375 modifier.embedder_api().RunsAOTCompiledDartCode = []() { return false; };
376
377 auto binary_messenger =
378 std::make_unique<BinaryMessengerImpl>(engine->messenger());
379
380 engine->Run();
381 bool did_call_callback = false;
382 bool did_call_reply = false;
383 bool did_call_dart_reply = false;
384 std::string channel = "hi";
385 std::unique_ptr<std::thread> reply_thread;
386 binary_messenger->SetMessageHandler(
387 channel,
388 [&did_call_callback, &did_call_dart_reply, &reply_thread](
389 const uint8_t* message, size_t message_size, BinaryReply reply) {
390 if (message_size == 5) {
391 EXPECT_EQ(message[0], static_cast<uint8_t>('h'));
392 reply_thread.reset(new std::thread([reply = std::move(reply)]() {
393 char response[] = {'b', 'y', 'e'};
394 reply(reinterpret_cast<uint8_t*>(response), 3);
395 }));
396 did_call_callback = true;
397 } else {
398 EXPECT_EQ(message_size, 3);
399 EXPECT_EQ(message[0], static_cast<uint8_t>('b'));
400 did_call_dart_reply = true;
401 }
402 });
403 char payload[] = {'h', 'e', 'l', 'l', 'o'};
404 binary_messenger->Send(
405 channel, reinterpret_cast<uint8_t*>(payload), 5,
406 [&did_call_reply](const uint8_t* reply, size_t reply_size) {
407 EXPECT_EQ(reply_size, 5);
408 EXPECT_EQ(reply[0], static_cast<uint8_t>('h'));
409 did_call_reply = true;
410 });
411 // Rely on timeout mechanism in CI.
412 while (!did_call_callback || !did_call_reply || !did_call_dart_reply) {
413 engine->task_runner()->ProcessTasks();
414 }
415 ASSERT_TRUE(reply_thread);
416 reply_thread->join();
417 }

References message.

## ◆ TEST_F() [38/163]

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

Definition at line 323 of file flutter_windows_engine_unittests.cc.

323 {
324 FlutterWindowsEngineBuilder builder{GetContext()};
325 builder.SetDartEntrypoint("hiPlatformChannels");
326
327 std::unique_ptr<FlutterWindowsEngine> engine = builder.Build();
328 EngineModifier modifier(engine.get());
329 modifier.embedder_api().RunsAOTCompiledDartCode = []() { return false; };
330
331 auto binary_messenger =
332 std::make_unique<BinaryMessengerImpl>(engine->messenger());
333
334 engine->Run();
335 bool did_call_callback = false;
336 bool did_call_reply = false;
337 bool did_call_dart_reply = false;
338 std::string channel = "hi";
339 binary_messenger->SetMessageHandler(
340 channel,
341 [&did_call_callback, &did_call_dart_reply](
342 const uint8_t* message, size_t message_size, BinaryReply reply) {
343 if (message_size == 5) {
344 EXPECT_EQ(message[0], static_cast<uint8_t>('h'));
345 char response[] = {'b', 'y', 'e'};
346 reply(reinterpret_cast<uint8_t*>(response), 3);
347 did_call_callback = true;
348 } else {
349 EXPECT_EQ(message_size, 3);
350 EXPECT_EQ(message[0], static_cast<uint8_t>('b'));
351 did_call_dart_reply = true;
352 }
353 });
354 char payload[] = {'h', 'e', 'l', 'l', 'o'};
355 binary_messenger->Send(
356 channel, reinterpret_cast<uint8_t*>(payload), 5,
357 [&did_call_reply](const uint8_t* reply, size_t reply_size) {
358 EXPECT_EQ(reply_size, 5);
359 EXPECT_EQ(reply[0], static_cast<uint8_t>('h'));
360 did_call_reply = true;
361 });
362 // Rely on timeout mechanism in CI.
363 while (!did_call_callback || !did_call_reply || !did_call_dart_reply) {
364 engine->task_runner()->ProcessTasks();
365 }
366 }

References message.

## ◆ TEST_F() [39/163]

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

Definition at line 635 of file flutter_windows_engine_unittests.cc.

635 {
636 FlutterWindowsEngineBuilder builder{GetContext()};
637 std::unique_ptr<FlutterWindowsEngine> engine = builder.Build();
638 EngineModifier modifier(engine.get());
639
640 modifier.embedder_api().PostRenderThreadTask = MOCK_ENGINE_PROC(
641 PostRenderThreadTask, ([](auto engine, auto callback, auto context) {
642 callback(context);
643 return kSuccess;
644 }));
645
646 bool called = false;
647 engine->PostRasterThreadTask([&called]() { called = true; });
648
649 EXPECT_TRUE(called);
650 }

References callback.

## ◆ TEST_F() [40/163]

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

Definition at line 1271 of file flutter_windows_engine_unittests.cc.

1271 {
1272 FlutterWindowsEngineBuilder builder{GetContext()};
1273 builder.SetDartEntrypoint("sendCreatePlatformViewMethod");
1274 auto engine = builder.Build();
1275
1276 EngineModifier modifier{engine.get()};
1277 modifier.embedder_api().RunsAOTCompiledDartCode = []() { return false; };
1278
1279 bool received_call = false;
1280
1281 auto manager = std::make_unique<MockPlatformViewManager>(engine.get());
1282 EXPECT_CALL(*manager, AddPlatformView)
1283 .WillOnce([&](PlatformViewId id, std::string_view type_name) {
1284 received_call = true;
1285 return true;
1286 });
1287 modifier.SetPlatformViewPlugin(std::move(manager));
1288
1289 engine->Run();
1290
1291 while (!received_call) {
1292 engine->task_runner()->ProcessTasks();
1293 }
1294 }
PlatformViewId
int64_t PlatformViewId
Definition: flutter_windows_internal.h:42

## ◆ TEST_F() [41/163]

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

Definition at line 1326 of file flutter_windows_engine_unittests.cc.

1326 {
1327 FlutterWindowsEngineBuilder builder{GetContext()};
1328 builder.SetDartEntrypoint("sendCreatePlatformViewMethod");
1329 auto engine = builder.Build();
1330
1331 EngineModifier modifier{engine.get()};
1332
1333 modifier.embedder_api().RunsAOTCompiledDartCode = []() { return false; };
1334 modifier.embedder_api().RemoveView = MOCK_ENGINE_PROC(
1335 RemoveView,
1336 [](FLUTTER_API_SYMBOL(FlutterEngine) engine,
1337 const FlutterRemoveViewInfo* info) { return kInternalInconsistency; });
1338
1339 ASSERT_TRUE(engine->Run());
1340 EXPECT_DEBUG_DEATH(engine->RemoveView(123),
1341 "FlutterEngineRemoveView returned an unexpected result");
1342 }

References flutter::FlutterEngine::Run().

## ◆ TEST_F() [42/163]

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

Definition at line 64 of file flutter_windows_engine_unittests.cc.

64 {
65 FlutterWindowsEngineBuilder builder{GetContext()};
66 builder.AddDartEntrypointArgument("arg1");
67 builder.AddDartEntrypointArgument("arg2");
68
69 std::unique_ptr<FlutterWindowsEngine> engine = builder.Build();
70 EngineModifier modifier(engine.get());
71
72 // The engine should be run with expected configuration values.
73 bool run_called = false;
74 modifier.embedder_api().Run = MOCK_ENGINE_PROC(
75 Run, ([&run_called, engine_instance = engine.get()](
76 size_t version, const FlutterRendererConfig* config,
77 const FlutterProjectArgs* args, void* user_data,
78 FLUTTER_API_SYMBOL(FlutterEngine) * engine_out) {
79 run_called = true;
80 *engine_out = reinterpret_cast<FLUTTER_API_SYMBOL(FlutterEngine)>(1);
81
82 EXPECT_EQ(version, FLUTTER_ENGINE_VERSION);
83 EXPECT_NE(config, nullptr);
84 // We have an EGL manager, so this should be using OpenGL.
85 EXPECT_EQ(config->type, kOpenGL);
86 EXPECT_EQ(user_data, engine_instance);
87 // Spot-check arguments.
88 EXPECT_NE(args->assets_path, nullptr);
89 EXPECT_NE(args->icu_data_path, nullptr);
90 EXPECT_EQ(args->dart_entrypoint_argc, 2U);
91 EXPECT_EQ(strcmp(args->dart_entrypoint_argv[0], "arg1"), 0);
92 EXPECT_EQ(strcmp(args->dart_entrypoint_argv[1], "arg2"), 0);
93 EXPECT_NE(args->platform_message_callback, nullptr);
94 EXPECT_NE(args->custom_task_runners, nullptr);
95 EXPECT_NE(args->custom_task_runners->thread_priority_setter, nullptr);
96 EXPECT_EQ(args->custom_dart_entrypoint, nullptr);
97 EXPECT_NE(args->vsync_callback, nullptr);
98 EXPECT_EQ(args->update_semantics_callback, nullptr);
99 EXPECT_NE(args->update_semantics_callback2, nullptr);
100 EXPECT_EQ(args->update_semantics_node_callback, nullptr);
101 EXPECT_EQ(args->update_semantics_custom_action_callback, nullptr);
102 EXPECT_NE(args->view_focus_change_request_callback, nullptr);
103
104 args->custom_task_runners->thread_priority_setter(
105 FlutterThreadPriority::kRaster);
106 EXPECT_EQ(GetThreadPriority(GetCurrentThread()),
107 THREAD_PRIORITY_ABOVE_NORMAL);
108 return kSuccess;
109 }));
110 // Accessibility updates must do nothing when the embedder engine is mocked
111 modifier.embedder_api().UpdateAccessibilityFeatures = MOCK_ENGINE_PROC(
112 UpdateAccessibilityFeatures,
113 [](FLUTTER_API_SYMBOL(FlutterEngine) engine,
114 FlutterAccessibilityFeature flags) { return kSuccess; });
115
116 // It should send locale info.
117 bool update_locales_called = false;
118 modifier.embedder_api().UpdateLocales = MOCK_ENGINE_PROC(
119 UpdateLocales,
120 ([&update_locales_called](auto engine, const FlutterLocale** locales,
121 size_t locales_count) {
122 update_locales_called = true;
123
124 EXPECT_GT(locales_count, 0);
125 EXPECT_NE(locales, nullptr);
126
127 return kSuccess;
128 }));
129
130 // And it should send initial settings info.
131 bool settings_message_sent = false;
132 modifier.embedder_api().SendPlatformMessage = MOCK_ENGINE_PROC(
133 SendPlatformMessage,
134 ([&settings_message_sent](auto engine, auto message) {
135 if (std::string(message->channel) == std::string("flutter/settings")) {
136 settings_message_sent = true;
137 }
138
139 return kSuccess;
140 }));
141
142 // And it should send display info.
143 bool notify_display_update_called = false;
144 modifier.SetFrameInterval(16600000); // 60 fps.
145 modifier.embedder_api().NotifyDisplayUpdate = MOCK_ENGINE_PROC(
146 NotifyDisplayUpdate,
147 ([&notify_display_update_called, engine_instance = engine.get()](
148 FLUTTER_API_SYMBOL(FlutterEngine) raw_engine,
149 const FlutterEngineDisplaysUpdateType update_type,
150 const FlutterEngineDisplay* embedder_displays,
151 size_t display_count) {
152 EXPECT_EQ(update_type, kFlutterEngineDisplaysUpdateTypeStartup);
153 EXPECT_EQ(display_count, 1);
154
155 FlutterEngineDisplay display = embedder_displays[0];
156
157 EXPECT_EQ(display.display_id, 0);
158 EXPECT_EQ(display.single_display, true);
159 EXPECT_EQ(std::floor(display.refresh_rate), 60.0);
160
161 notify_display_update_called = true;
162 return kSuccess;
163 }));
164
165 // Set the EGL manager to !nullptr to test ANGLE rendering.
166 modifier.SetEGLManager(std::make_unique<egl::MockManager>());
167
168 engine->Run();
169
170 EXPECT_TRUE(run_called);
171 EXPECT_TRUE(update_locales_called);
172 EXPECT_TRUE(settings_message_sent);
173 EXPECT_TRUE(notify_display_update_called);
174
175 // Ensure that deallocation doesn't call the actual Shutdown with the bogus
176 // engine pointer that the overridden Run returned.
177 modifier.embedder_api().Shutdown = [](auto engine) { return kSuccess; };
178 modifier.ReleaseEGLManager();
179 }

References message, and user_data.

## ◆ TEST_F() [43/163]

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

Definition at line 52 of file flutter_windows_engine_unittests.cc.

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

References flutter::kImplicitViewId.

## ◆ TEST_F() [44/163]

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

Definition at line 261 of file flutter_windows_engine_unittests.cc.

261 {
262 FlutterWindowsEngineBuilder builder{GetContext()};
263 builder.SetSwitches({"--enable-impeller=true"});
264 std::unique_ptr<FlutterWindowsEngine> engine = builder.Build();
265 EngineModifier modifier(engine.get());
266
267 modifier.embedder_api().NotifyDisplayUpdate =
268 MOCK_ENGINE_PROC(NotifyDisplayUpdate,
269 ([engine_instance = engine.get()](
270 FLUTTER_API_SYMBOL(FlutterEngine) raw_engine,
271 const FlutterEngineDisplaysUpdateType update_type,
272 const FlutterEngineDisplay* embedder_displays,
273 size_t display_count) { return kSuccess; }));
274
275 // Accessibility updates must do nothing when the embedder engine is mocked
276 modifier.embedder_api().UpdateAccessibilityFeatures = MOCK_ENGINE_PROC(
277 UpdateAccessibilityFeatures,
278 [](FLUTTER_API_SYMBOL(FlutterEngine) engine,
279 FlutterAccessibilityFeature flags) { return kSuccess; });
280
281 // Stub out UpdateLocales and SendPlatformMessage as we don't have a fully
282 // initialized engine instance.
283 modifier.embedder_api().UpdateLocales = MOCK_ENGINE_PROC(
284 UpdateLocales, ([](auto engine, const FlutterLocale** locales,
285 size_t locales_count) { return kSuccess; }));
286 modifier.embedder_api().SendPlatformMessage =
287 MOCK_ENGINE_PROC(SendPlatformMessage,
288 ([](auto engine, auto message) { return kSuccess; }));
289
290 // Set the EGL manager to nullptr to test software fallback path.
291 modifier.SetEGLManager(nullptr);
292
293 EXPECT_FALSE(engine->Run());
294 }

References message.

## ◆ TEST_F() [45/163]

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

Definition at line 208 of file flutter_windows_engine_unittests.cc.

208 {
209 FlutterWindowsEngineBuilder builder{GetContext()};
210 std::unique_ptr<FlutterWindowsEngine> engine = builder.Build();
211 EngineModifier modifier(engine.get());
212
213 modifier.embedder_api().NotifyDisplayUpdate =
214 MOCK_ENGINE_PROC(NotifyDisplayUpdate,
215 ([engine_instance = engine.get()](
216 FLUTTER_API_SYMBOL(FlutterEngine) raw_engine,
217 const FlutterEngineDisplaysUpdateType update_type,
218 const FlutterEngineDisplay* embedder_displays,
219 size_t display_count) { return kSuccess; }));
220
221 // The engine should be run with expected configuration values.
222 bool run_called = false;
223 modifier.embedder_api().Run = MOCK_ENGINE_PROC(
224 Run, ([&run_called, engine_instance = engine.get()](
225 size_t version, const FlutterRendererConfig* config,
226 const FlutterProjectArgs* args, void* user_data,
227 FLUTTER_API_SYMBOL(FlutterEngine) * engine_out) {
228 run_called = true;
229 *engine_out = reinterpret_cast<FLUTTER_API_SYMBOL(FlutterEngine)>(1);
230 // We don't have an EGL Manager, so we should be using software.
231 EXPECT_EQ(config->type, kSoftware);
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 // Stub out UpdateLocales and SendPlatformMessage as we don't have a fully
241 // initialized engine instance.
242 modifier.embedder_api().UpdateLocales = MOCK_ENGINE_PROC(
243 UpdateLocales, ([](auto engine, const FlutterLocale** locales,
244 size_t locales_count) { return kSuccess; }));
245 modifier.embedder_api().SendPlatformMessage =
246 MOCK_ENGINE_PROC(SendPlatformMessage,
247 ([](auto engine, auto message) { return kSuccess; }));
248
249 // Set the EGL manager to nullptr to test software fallback path.
250 modifier.SetEGLManager(nullptr);
251
252 engine->Run();
253
254 EXPECT_TRUE(run_called);
255
256 // Ensure that deallocation doesn't call the actual Shutdown with the bogus
257 // engine pointer that the overridden Run returned.
258 modifier.embedder_api().Shutdown = [](auto engine) { return kSuccess; };
259 }

References message, and user_data.

## ◆ TEST_F() [46/163]

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

Definition at line 554 of file flutter_windows_engine_unittests.cc.

554 {
555 FlutterWindowsEngineBuilder builder{GetContext()};
556 std::unique_ptr<FlutterWindowsEngine> engine = builder.Build();
557 EngineModifier modifier(engine.get());
558
559 bool called = false;
560 modifier.embedder_api().ScheduleFrame =
561 MOCK_ENGINE_PROC(ScheduleFrame, ([&called](auto engine) {
562 called = true;
563 return kSuccess;
564 }));
565
566 engine->ScheduleFrame();
567 EXPECT_TRUE(called);
568 }

## ◆ TEST_F() [47/163]

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

Definition at line 296 of file flutter_windows_engine_unittests.cc.

296 {
297 FlutterWindowsEngineBuilder builder{GetContext()};
298 std::unique_ptr<FlutterWindowsEngine> engine = builder.Build();
299 EngineModifier modifier(engine.get());
300
301 const char* channel = "test";
302 const std::vector<uint8_t> test_message = {1, 2, 3, 4};
303
304 // Without a response, SendPlatformMessage should be a simple pass-through.
305 bool called = false;
306 modifier.embedder_api().SendPlatformMessage = MOCK_ENGINE_PROC(
307 SendPlatformMessage, ([&called, test_message](auto engine, auto message) {
308 called = true;
309 EXPECT_STREQ(message->channel, "test");
310 EXPECT_EQ(message->message_size, test_message.size());
311 EXPECT_EQ(memcmp(message->message, test_message.data(),
312 message->message_size),
313 0);
314 EXPECT_EQ(message->response_handle, nullptr);
315 return kSuccess;
316 }));
317
318 engine->SendPlatformMessage(channel, test_message.data(), test_message.size(),
319 nullptr, nullptr);
320 EXPECT_TRUE(called);
321 }

References message.

## ◆ TEST_F() [48/163]

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

Definition at line 419 of file flutter_windows_engine_unittests.cc.

419 {
420 FlutterWindowsEngineBuilder builder{GetContext()};
421 std::unique_ptr<FlutterWindowsEngine> engine = builder.Build();
422 EngineModifier modifier(engine.get());
423
424 const char* channel = "test";
425 const std::vector<uint8_t> test_message = {1, 2, 3, 4};
426 auto* dummy_response_handle =
427 reinterpret_cast<FlutterPlatformMessageResponseHandle*>(5);
428 const FlutterDesktopBinaryReply reply_handler = [](auto... args) {};
429 void* reply_user_data = reinterpret_cast<void*>(6);
430
431 // When a response is requested, a handle should be created, passed as part
432 // of the message, and then released.
433 bool create_response_handle_called = false;
434 modifier.embedder_api().PlatformMessageCreateResponseHandle =
435 MOCK_ENGINE_PROC(
436 PlatformMessageCreateResponseHandle,
437 ([&create_response_handle_called, &reply_handler, reply_user_data,
438 dummy_response_handle](auto engine, auto reply, auto user_data,
439 auto response_handle) {
440 create_response_handle_called = true;
441 EXPECT_EQ(reply, reply_handler);
442 EXPECT_EQ(user_data, reply_user_data);
443 EXPECT_NE(response_handle, nullptr);
444 *response_handle = dummy_response_handle;
445 return kSuccess;
446 }));
447 bool release_response_handle_called = false;
448 modifier.embedder_api().PlatformMessageReleaseResponseHandle =
449 MOCK_ENGINE_PROC(
450 PlatformMessageReleaseResponseHandle,
451 ([&release_response_handle_called, dummy_response_handle](
452 auto engine, auto response_handle) {
453 release_response_handle_called = true;
454 EXPECT_EQ(response_handle, dummy_response_handle);
455 return kSuccess;
456 }));
457 bool send_message_called = false;
458 modifier.embedder_api().SendPlatformMessage = MOCK_ENGINE_PROC(
459 SendPlatformMessage, ([&send_message_called, test_message,
460 dummy_response_handle](auto engine, auto message) {
461 send_message_called = true;
462 EXPECT_STREQ(message->channel, "test");
463 EXPECT_EQ(message->message_size, test_message.size());
464 EXPECT_EQ(memcmp(message->message, test_message.data(),
465 message->message_size),
466 0);
467 EXPECT_EQ(message->response_handle, dummy_response_handle);
468 return kSuccess;
469 }));
470
471 engine->SendPlatformMessage(channel, test_message.data(), test_message.size(),
472 reply_handler, reply_user_data);
473 EXPECT_TRUE(create_response_handle_called);
474 EXPECT_TRUE(release_response_handle_called);
475 EXPECT_TRUE(send_message_called);
476 }
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() [49/163]

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

Definition at line 570 of file flutter_windows_engine_unittests.cc.

570 {
571 FlutterWindowsEngineBuilder builder{GetContext()};
572 std::unique_ptr<FlutterWindowsEngine> engine = builder.Build();
573 EngineModifier modifier(engine.get());
574
575 bool called = false;
576 modifier.embedder_api().SetNextFrameCallback = MOCK_ENGINE_PROC(
577 SetNextFrameCallback, ([&called](auto engine, auto callback, auto data) {
578 called = true;
579 return kSuccess;
580 }));
581
582 engine->SetNextFrameCallback([]() {});
583 EXPECT_TRUE(called);
584 }

References callback.

## ◆ TEST_F() [50/163]

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

Definition at line 502 of file flutter_windows_engine_unittests.cc.

502 {
503 WindowsPlatformThreadPrioritySetter(FlutterThreadPriority::kBackground);
504 EXPECT_EQ(GetThreadPriority(GetCurrentThread()),
505 THREAD_PRIORITY_BELOW_NORMAL);
506
507 WindowsPlatformThreadPrioritySetter(FlutterThreadPriority::kDisplay);
508 EXPECT_EQ(GetThreadPriority(GetCurrentThread()),
509 THREAD_PRIORITY_ABOVE_NORMAL);
510
511 WindowsPlatformThreadPrioritySetter(FlutterThreadPriority::kRaster);
512 EXPECT_EQ(GetThreadPriority(GetCurrentThread()),
513 THREAD_PRIORITY_ABOVE_NORMAL);
514
515 // FlutterThreadPriority::kNormal does not change thread priority, reset to 0
516 // here.
517 SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_NORMAL);
518
519 WindowsPlatformThreadPrioritySetter(FlutterThreadPriority::kNormal);
520 EXPECT_EQ(GetThreadPriority(GetCurrentThread()), THREAD_PRIORITY_NORMAL);
521 }
flutter::WindowsPlatformThreadPrioritySetter
static void WindowsPlatformThreadPrioritySetter(FlutterThreadPriority priority)
Definition: flutter_windows_engine.h:60

References flutter::WindowsPlatformThreadPrioritySetter().

## ◆ TEST_F() [51/163]

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

Definition at line 788 of file flutter_windows_engine_unittests.cc.

788 {
789 FlutterWindowsEngineBuilder builder{GetContext()};
790 builder.SetDartEntrypoint("exitTestExit");
791 bool finished = false;
792
793 auto engine = builder.Build();
794 auto window_binding_handler =
795 std::make_unique<::testing::NiceMock<MockWindowBindingHandler>>();
796 MockFlutterWindowsView view(engine.get(), std::move(window_binding_handler));
797
798 EngineModifier modifier(engine.get());
799 modifier.SetImplicitView(&view);
800 modifier.embedder_api().RunsAOTCompiledDartCode = []() { return false; };
801 auto handler = std::make_unique<MockWindowsLifecycleManager>(engine.get());
802 EXPECT_CALL(*handler, Quit)
803 .WillOnce([&finished](std::optional<HWND> hwnd,
804 std::optional<WPARAM> wparam,
805 std::optional<LPARAM> lparam,
806 UINT exit_code) { finished = exit_code == 0; });
807 EXPECT_CALL(*handler, IsLastWindowOfProcess).WillRepeatedly(Return(true));
808 modifier.SetLifecycleManager(std::move(handler));
809
810 engine->lifecycle_manager()->BeginProcessingExit();
811
812 engine->Run();
813
814 engine->window_proc_delegate_manager()->OnTopLevelWindowProc(0, WM_CLOSE, 0,
815 0);
816
817 // The test will only succeed when this while loop exits. Otherwise it will
818 // timeout.
819 while (!finished) {
820 engine->task_runner()->ProcessTasks();
821 }
822 }

## ◆ TEST_F() [52/163]

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

Definition at line 824 of file flutter_windows_engine_unittests.cc.

824 {
825 FlutterWindowsEngineBuilder builder{GetContext()};
826 builder.SetDartEntrypoint("exitTestCancel");
827 bool did_call = false;
828
829 auto engine = builder.Build();
830 auto window_binding_handler =
831 std::make_unique<::testing::NiceMock<MockWindowBindingHandler>>();
832 MockFlutterWindowsView view(engine.get(), std::move(window_binding_handler));
833
834 EngineModifier modifier(engine.get());
835 modifier.SetImplicitView(&view);
836 modifier.embedder_api().RunsAOTCompiledDartCode = []() { return false; };
837 auto handler = std::make_unique<MockWindowsLifecycleManager>(engine.get());
838 EXPECT_CALL(*handler, IsLastWindowOfProcess).WillRepeatedly(Return(true));
839 EXPECT_CALL(*handler, Quit).Times(0);
840 modifier.SetLifecycleManager(std::move(handler));
841 engine->lifecycle_manager()->BeginProcessingExit();
842
843 auto binary_messenger =
844 std::make_unique<BinaryMessengerImpl>(engine->messenger());
845 binary_messenger->SetMessageHandler(
846 "flutter/platform", [&did_call](const uint8_t* message,
847 size_t message_size, BinaryReply reply) {
848 std::string contents(message, message + message_size);
849 EXPECT_NE(contents.find("\"method\":\"System.exitApplication\""),
850 std::string::npos);
851 EXPECT_NE(contents.find("\"type\":\"required\""), std::string::npos);
852 EXPECT_NE(contents.find("\"exitCode\":0"), std::string::npos);
853 did_call = true;
854 char response[] = "";
855 reply(reinterpret_cast<uint8_t*>(response), 0);
856 });
857
858 engine->Run();
859
860 engine->window_proc_delegate_manager()->OnTopLevelWindowProc(0, WM_CLOSE, 0,
861 0);
862
863 while (!did_call) {
864 engine->task_runner()->ProcessTasks();
865 }
866 }

References message.

## ◆ TEST_F() [53/163]

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

Definition at line 930 of file flutter_windows_engine_unittests.cc.

930 {
931 FlutterWindowsEngineBuilder builder{GetContext()};
932 builder.SetDartEntrypoint("exitTestExit");
933 bool finished = false;
934
935 auto engine = builder.Build();
936 auto window_binding_handler =
937 std::make_unique<::testing::NiceMock<MockWindowBindingHandler>>();
938 MockFlutterWindowsView view(engine.get(), std::move(window_binding_handler));
939
940 EngineModifier modifier(engine.get());
941 modifier.SetImplicitView(&view);
942 modifier.embedder_api().RunsAOTCompiledDartCode = []() { return false; };
943 auto handler = std::make_unique<MockWindowsLifecycleManager>(engine.get());
944 EXPECT_CALL(*handler, IsLastWindowOfProcess).WillOnce([&finished]() {
945 finished = true;
946 return false;
947 });
948 // Quit should not be called when there is more than one window.
949 EXPECT_CALL(*handler, Quit).Times(0);
950 modifier.SetLifecycleManager(std::move(handler));
951 engine->lifecycle_manager()->BeginProcessingExit();
952
953 engine->Run();
954
955 engine->window_proc_delegate_manager()->OnTopLevelWindowProc(0, WM_CLOSE, 0,
956 0);
957
958 while (!finished) {
959 engine->task_runner()->ProcessTasks();
960 }
961 }

## ◆ TEST_F() [54/163]

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

Definition at line 871 of file flutter_windows_engine_unittests.cc.

871 {
872 FlutterWindowsEngineBuilder builder{GetContext()};
873 builder.SetDartEntrypoint("exitTestExit");
874 bool second_close = false;
875
876 auto engine = builder.Build();
877 auto window_binding_handler =
878 std::make_unique<::testing::NiceMock<MockWindowBindingHandler>>();
879 MockFlutterWindowsView view(engine.get(), std::move(window_binding_handler));
880
881 EngineModifier modifier(engine.get());
882 modifier.SetImplicitView(&view);
883 modifier.embedder_api().RunsAOTCompiledDartCode = []() { return false; };
884 auto handler = std::make_unique<MockWindowsLifecycleManager>(engine.get());
885 EXPECT_CALL(*handler, IsLastWindowOfProcess).WillOnce(Return(true));
886 EXPECT_CALL(*handler, Quit)
887 .WillOnce([handler_ptr = handler.get()](
888 std::optional<HWND> hwnd, std::optional<WPARAM> wparam,
889 std::optional<LPARAM> lparam, UINT exit_code) {
890 handler_ptr->WindowsLifecycleManager::Quit(hwnd, wparam, lparam,
891 exit_code);
892 });
893 EXPECT_CALL(*handler, DispatchMessage)
894 .WillRepeatedly(
895 [&engine](HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) {
896 engine->window_proc_delegate_manager()->OnTopLevelWindowProc(
897 hwnd, msg, wparam, lparam);
898 });
899 modifier.SetLifecycleManager(std::move(handler));
900 engine->lifecycle_manager()->BeginProcessingExit();
901
902 engine->Run();
903
904 // This delegate will be registered after the lifecycle manager, so it will be
905 // called only when a message is not consumed by the lifecycle manager. This
906 // should be called on the second, synthesized WM_CLOSE message that the
907 // lifecycle manager posts.
908 engine->window_proc_delegate_manager()->RegisterTopLevelWindowProcDelegate(
909 [](HWND hwnd, UINT message, WPARAM wpar, LPARAM lpar, void* user_data,
910 LRESULT* result) {
911 switch (message) {
912 case WM_CLOSE: {
913 bool* called = reinterpret_cast<bool*>(user_data);
914 *called = true;
915 return true;
916 }
917 }
918 return false;
919 },
920 reinterpret_cast<void*>(&second_close));
921
922 engine->window_proc_delegate_manager()->OnTopLevelWindowProc(0, WM_CLOSE, 0,
923 0);
924
925 while (!second_close) {
926 engine->task_runner()->ProcessTasks();
927 }
928 }

References message, and user_data.

## ◆ TEST_F() [55/163]

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

Definition at line 594 of file flutter_windows_engine_unittests.cc.

594 {
595 auto windows_proc_table = std::make_shared<MockWindowsProcTable>();
596 EXPECT_CALL(*windows_proc_table, GetHighContrastEnabled)
597 .WillOnce(Return(true))
598 .WillOnce(Return(false));
599
600 FlutterWindowsEngineBuilder builder{GetContext()};
601 builder.SetWindowsProcTable(windows_proc_table);
602 std::unique_ptr<FlutterWindowsEngine> engine = builder.Build();
603 EngineModifier modifier(engine.get());
604
605 std::optional<FlutterAccessibilityFeature> engine_flags;
606 modifier.embedder_api().UpdateAccessibilityFeatures = MOCK_ENGINE_PROC(
607 UpdateAccessibilityFeatures, ([&engine_flags](auto engine, auto flags) {
608 engine_flags = flags;
609 return kSuccess;
610 }));
611 modifier.embedder_api().SendPlatformMessage = MOCK_ENGINE_PROC(
612 SendPlatformMessage,
613 [](auto engine, const auto message) { return kSuccess; });
614
615 // 1: High contrast is enabled.
616 engine->UpdateHighContrastMode();
617
618 EXPECT_TRUE(engine->high_contrast_enabled());
619 EXPECT_TRUE(engine_flags.has_value());
620 EXPECT_TRUE(
621 engine_flags.value() &
622 FlutterAccessibilityFeature::kFlutterAccessibilityFeatureHighContrast);
623
624 // 2: High contrast is disabled.
625 engine_flags.reset();
626 engine->UpdateHighContrastMode();
627
628 EXPECT_FALSE(engine->high_contrast_enabled());
629 EXPECT_TRUE(engine_flags.has_value());
630 EXPECT_FALSE(
631 engine_flags.value() &
632 FlutterAccessibilityFeature::kFlutterAccessibilityFeatureHighContrast);
633 }

References message.

## ◆ TEST_F() [56/163]

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

Definition at line 1381 of file flutter_windows_engine_unittests.cc.

1381 {
1382 auto& context = GetContext();
1383 WindowsConfigBuilder builder{context};
1384 builder.SetDartEntrypoint("sendSemanticsTreeInfo");
1385
1386 // Setup: a signal for when we have send out all of our semantics updates
1387 bool done = false;
1388 auto native_entry =
1389 CREATE_NATIVE_ENTRY([&](Dart_NativeArguments args) { done = true; });
1390 context.AddNativeFunction("Signal", native_entry);
1391
1392 // Setup: Create the engine and two views + enable semantics
1393 EnginePtr engine{builder.RunHeadless()};
1394 ASSERT_NE(engine, nullptr);
1395
1396 auto window_binding_handler1 =
1397 std::make_unique<NiceMock<MockWindowBindingHandler>>();
1398 auto window_binding_handler2 =
1399 std::make_unique<NiceMock<MockWindowBindingHandler>>();
1400
1401 // The following mocks are required by
1402 // FlutterWindowsView::CreateWindowMetricsEvent so that we create a valid
1403 // view.
1404 EXPECT_CALL(*window_binding_handler1, GetPhysicalWindowBounds)
1405 .WillRepeatedly(testing::Return(PhysicalWindowBounds{100, 100}));
1406 EXPECT_CALL(*window_binding_handler1, GetDpiScale)
1407 .WillRepeatedly(testing::Return(96.0));
1408 EXPECT_CALL(*window_binding_handler2, GetPhysicalWindowBounds)
1409 .WillRepeatedly(testing::Return(PhysicalWindowBounds{200, 200}));
1410 EXPECT_CALL(*window_binding_handler2, GetDpiScale)
1411 .WillRepeatedly(testing::Return(96.0));
1412
1413 auto windows_engine = reinterpret_cast<FlutterWindowsEngine*>(engine.get());
1414 EngineModifier modifier{windows_engine};
1415 modifier.embedder_api().RunsAOTCompiledDartCode = []() { return false; };
1416
1417 // We want to avoid adding an implicit view as the first view
1418 modifier.SetNextViewId(kImplicitViewId + 1);
1419
1420 auto view1 = windows_engine->CreateView(std::move(window_binding_handler1));
1421 auto view2 = windows_engine->CreateView(std::move(window_binding_handler2));
1422
1423 // Act: UpdateSemanticsEnabled will trigger the semantics updates
1424 // to get sent.
1425 windows_engine->UpdateSemanticsEnabled(true);
1426
1427 while (!done) {
1428 windows_engine->task_runner()->ProcessTasks();
1429 }
1430
1431 auto accessibility_bridge1 = view1->accessibility_bridge().lock();
1432 auto accessibility_bridge2 = view2->accessibility_bridge().lock();
1433
1434 // Expect: that the semantics trees are updated with their
1435 // respective nodes.
1436 while (
1437 !accessibility_bridge1->GetPlatformNodeFromTree(view1->view_id() + 1)) {
1438 windows_engine->task_runner()->ProcessTasks();
1439 }
1440
1441 while (
1442 !accessibility_bridge2->GetPlatformNodeFromTree(view2->view_id() + 1)) {
1443 windows_engine->task_runner()->ProcessTasks();
1444 }
1445
1446 // Rely on timeout mechanism in CI.
1447 auto tree1 = accessibility_bridge1->GetTree();
1448 auto tree2 = accessibility_bridge2->GetTree();
1449 EXPECT_NE(tree1->GetFromId(view1->view_id() + 1), nullptr);
1450 EXPECT_NE(tree2->GetFromId(view2->view_id() + 1), nullptr);
1451 }

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

## ◆ TEST_F() [57/163]

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

Definition at line 310 of file flutter_window_unittests.cc.

310 {
311 MockFlutterWindow win32window;
312
313 EXPECT_EQ(win32window.GetNativeViewAccessible(), nullptr);
314 }

## ◆ TEST_F() [58/163]

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

Definition at line 318 of file flutter_window_unittests.cc.

318 {
319 std::unique_ptr<FlutterWindowsEngine> engine =
320 FlutterWindowsEngineBuilder{GetContext()}.Build();
321 auto win32window = std::make_unique<MockFlutterWindow>();
322 EXPECT_CALL(*win32window.get(), GetAxFragmentRootDelegate())
323 .WillRepeatedly(Return(nullptr));
324 EXPECT_CALL(*win32window.get(), OnWindowStateEvent).Times(AnyNumber());
325 EXPECT_CALL(*win32window.get(), GetWindowHandle).Times(AnyNumber());
326 MockFlutterWindowsView view{engine.get(), std::move(win32window)};
327 std::wstring message = L"Test alert";
328 EXPECT_CALL(view, NotifyWinEventWrapper(_, ax::mojom::Event::kAlert))
329 .Times(1);
330 view.AnnounceAlert(message);
331
332 IAccessible* alert = view.AlertNode();
333 VARIANT self{.vt = VT_I4, .lVal = CHILDID_SELF};
334 BSTR strptr;
335 alert->get_accName(self, &strptr);
336 EXPECT_EQ(message, strptr);
337
338 alert->get_accDescription(self, &strptr);
339 EXPECT_EQ(message, strptr);
340
341 alert->get_accValue(self, &strptr);
342 EXPECT_EQ(message, strptr);
343
344 VARIANT role;
345 alert->get_accRole(self, &role);
346 EXPECT_EQ(role.vt, VT_I4);
347 EXPECT_EQ(role.lVal, ROLE_SYSTEM_ALERT);
348 }

References message.

## ◆ TEST_F() [59/163]

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

Definition at line 388 of file flutter_window_unittests.cc.

388 {
389 MockFlutterWindow win32window;
390 EXPECT_CALL(win32window, GetWindowHandle)
391 .WillRepeatedly(Return(reinterpret_cast<HWND>(1)));
392 EXPECT_CALL(win32window, OnWindowStateEvent)
393 .WillRepeatedly([&](WindowStateEvent event) {
394 win32window.FlutterWindow::OnWindowStateEvent(event);
395 });
396 EXPECT_CALL(win32window, OnResize).Times(1);
397
398 // Restore
399 win32window.InjectWindowMessage(WM_SIZE, 0, MAKEWORD(1, 1));
400
401 // Focus
402 win32window.InjectWindowMessage(WM_SETFOCUS, 0, 0);
403
404 MockWindowBindingHandlerDelegate delegate;
405 bool focused = false;
406 bool restored = false;
407 EXPECT_CALL(delegate, OnWindowStateEvent)
408 .WillRepeatedly([&](HWND hwnd, WindowStateEvent event) {
409 if (event == WindowStateEvent::kFocus) {
410 focused = true;
411 } else if (event == WindowStateEvent::kShow) {
412 restored = true;
413 }
414 });
415
416 EXPECT_CALL(delegate, OnFocus(Eq(FlutterViewFocusState::kFocused),
417 Eq(FlutterViewFocusDirection::kUndefined)))
418 .Times(1);
419 win32window.SetView(&delegate);
420 EXPECT_TRUE(focused);
421 EXPECT_TRUE(restored);
422 }
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() [60/163]

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

Definition at line 118 of file flutter_window_unittests.cc.

118 {
119 FlutterWindow window(800, 600);
120 ASSERT_TRUE(TRUE);
121 }

## ◆ TEST_F() [61/163]

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

Definition at line 350 of file flutter_window_unittests.cc.

350 {
351 MockFlutterWindow win32window;
352 EXPECT_CALL(win32window, GetWindowHandle)
353 .WillRepeatedly(Return(reinterpret_cast<HWND>(1)));
354 MockWindowBindingHandlerDelegate delegate;
355
356 WindowStateEvent last_event;
357 EXPECT_CALL(delegate, OnWindowStateEvent)
358 .WillRepeatedly([&last_event](HWND hwnd, WindowStateEvent event) {
359 last_event = event;
360 });
361 EXPECT_CALL(win32window, OnWindowStateEvent)
362 .WillRepeatedly([&](WindowStateEvent event) {
363 win32window.FlutterWindow::OnWindowStateEvent(event);
364 });
365 EXPECT_CALL(win32window, OnResize).Times(AnyNumber());
366
367 win32window.SetView(&delegate);
368
369 win32window.InjectWindowMessage(WM_SIZE, 0, 0);
370 EXPECT_EQ(last_event, WindowStateEvent::kHide);
371
372 win32window.InjectWindowMessage(WM_SIZE, 0, MAKEWORD(1, 1));
373 EXPECT_EQ(last_event, WindowStateEvent::kShow);
374
375 EXPECT_CALL(delegate, OnFocus(Eq(FlutterViewFocusState::kFocused),
376 Eq(FlutterViewFocusDirection::kUndefined)))
377 .Times(1);
378 win32window.InjectWindowMessage(WM_SETFOCUS, 0, 0);
379 EXPECT_EQ(last_event, WindowStateEvent::kFocus);
380
381 EXPECT_CALL(delegate, OnFocus(Eq(FlutterViewFocusState::kUnfocused),
382 Eq(FlutterViewFocusDirection::kUndefined)))
383 .Times(1);
384 win32window.InjectWindowMessage(WM_KILLFOCUS, 0, 0);
385 EXPECT_EQ(last_event, WindowStateEvent::kUnfocus);
386 }

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

## ◆ TEST_F() [62/163]

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

Definition at line 123 of file flutter_window_unittests.cc.

123 {
124 FlutterWindow win32window(100, 100);
125 int old_handle_count = GetGuiResources(GetCurrentProcess(), GR_GDIOBJECTS);
126
127 constexpr size_t row_bytes = 100 * 4;
128 constexpr size_t height = 100;
129 std::array<char, row_bytes * height> allocation;
130 win32window.OnBitmapSurfaceUpdated(allocation.data(), row_bytes, height);
131
132 int new_handle_count = GetGuiResources(GetCurrentProcess(), GR_GDIOBJECTS);
133 // Check GDI resources leak
134 EXPECT_EQ(old_handle_count, new_handle_count);
135 }

References flutter::FlutterWindow::OnBitmapSurfaceUpdated().

## ◆ TEST_F() [63/163]

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

Definition at line 153 of file flutter_window_unittests.cc.

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

## ◆ TEST_F() [64/163]

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

Definition at line 140 of file flutter_window_unittests.cc.

140 {
141 MockFlutterWindow win32window;
142 EXPECT_CALL(win32window, GetDpiScale()).WillOnce(Return(1.0));
143
144 Rect cursor_rect(Point(10, 20), Size(30, 40));
145 EXPECT_CALL(win32window, UpdateCursorRect(cursor_rect)).Times(1);
146
147 win32window.OnCursorRectUpdated(cursor_rect);
148 }

## ◆ TEST_F() [65/163]

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

Definition at line 164 of file flutter_window_unittests.cc.

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

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

## ◆ TEST_F() [66/163]

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

Definition at line 265 of file flutter_window_unittests.cc.

265 {
266 MockFlutterWindow win32window;
267 MockWindowBindingHandlerDelegate delegate;
268 EXPECT_CALL(win32window, OnWindowStateEvent).Times(AnyNumber());
269 win32window.SetView(&delegate);
270
271 EXPECT_CALL(win32window, GetWindowHandle).WillOnce([&win32window]() {
272 return win32window.FlutterWindow::GetWindowHandle();
273 });
274 EXPECT_CALL(win32window, GetScrollOffsetMultiplier).WillOnce(Return(120.0f));
275
276 EXPECT_CALL(delegate,
277 OnScroll(_, _, 0, 0, 120.0f, kFlutterPointerDeviceKindMouse,
278 kDefaultPointerDeviceId))
279 .Times(1);
280
281 win32window.OnScroll(0.0f, 0.0f, kFlutterPointerDeviceKindMouse,
282 kDefaultPointerDeviceId);
283 }

## ◆ TEST_F() [67/163]

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

Definition at line 296 of file flutter_window_unittests.cc.

296 {
297 MockFlutterWindow win32window;
298 MockWindowBindingHandlerDelegate delegate;
299 EXPECT_CALL(win32window, OnWindowStateEvent).Times(AnyNumber());
300 win32window.SetView(&delegate);
301
302 EXPECT_CALL(delegate, OnHighContrastChanged).Times(1);
303
304 win32window.InjectWindowMessage(WM_THEMECHANGED, 0, 0);
305 }

## ◆ TEST_F() [68/163]

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

Definition at line 285 of file flutter_window_unittests.cc.

285 {
286 MockFlutterWindow win32window;
287 MockWindowBindingHandlerDelegate delegate;
288 EXPECT_CALL(win32window, OnWindowStateEvent).Times(AnyNumber());
289 win32window.SetView(&delegate);
290
291 EXPECT_CALL(delegate, OnWindowRepaint()).Times(1);
292
293 win32window.InjectWindowMessage(WM_PAINT, 0, 0);
294 }

## ◆ TEST_F() [69/163]

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

Definition at line 1240 of file keyboard_unittests.cc.

1240 {
1241 KeyboardTester tester{GetContext()};
1242 tester.Responding(false);
1243
1244 // German Keyboard layout
1245
1246 // Press AltGr, which Win32 precedes with a ContrlLeft down.
1247 tester.InjectKeyboardChanges(std::vector<KeyboardChange>{
1248 KeyStateChange{VK_LCONTROL, true, true},
1249 WmKeyDownInfo{VK_LCONTROL, kScanCodeControl, kNotExtended, kWasUp}.Build(
1250 kWmResultZero),
1251 KeyStateChange{VK_RMENU, true, true},
1252 WmKeyDownInfo{VK_MENU, kScanCodeAlt, kExtended, kWasUp}.Build(
1253 kWmResultZero)});
1254
1255 EXPECT_EQ(tester.key_calls.size(), 2);
1256 EXPECT_CALL_IS_EVENT(tester.key_calls[0], kFlutterKeyEventTypeDown,
1257 kPhysicalControlLeft, kLogicalControlLeft, "",
1258 kNotSynthesized);
1259 EXPECT_CALL_IS_EVENT(tester.key_calls[1], kFlutterKeyEventTypeDown,
1260 kPhysicalAltRight, kLogicalAltRight, "",
1261 kNotSynthesized);
1262 tester.clear_key_calls();
1263 EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 2);
1264
1265 // Press Q
1266 tester.InjectKeyboardChanges(std::vector<KeyboardChange>{
1267 WmKeyDownInfo{kVirtualKeyQ, kScanCodeKeyQ, kNotExtended, kWasUp}.Build(
1268 kWmResultZero),
1269 WmCharInfo{'@', kScanCodeKeyQ, kNotExtended, kWasUp}.Build(
1270 kWmResultZero)});
1271
1272 EXPECT_EQ(tester.key_calls.size(), 2);
1273 EXPECT_CALL_IS_EVENT(tester.key_calls[0], kFlutterKeyEventTypeDown,
1274 kPhysicalKeyQ, kLogicalKeyQ, "@", kNotSynthesized);
1275 EXPECT_CALL_IS_TEXT(tester.key_calls[1], u"@");
1276 tester.clear_key_calls();
1277 EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 2);
1278
1279 // Release Q
1280 tester.InjectKeyboardChanges(std::vector<KeyboardChange>{
1281 WmKeyUpInfo{kVirtualKeyQ, kScanCodeKeyQ, kNotExtended}.Build(
1282 kWmResultZero)});
1283
1284 EXPECT_EQ(tester.key_calls.size(), 1);
1285 EXPECT_CALL_IS_EVENT(tester.key_calls[0], kFlutterKeyEventTypeUp,
1286 kPhysicalKeyQ, kLogicalKeyQ, "", kNotSynthesized);
1287 tester.clear_key_calls();
1288 EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 1);
1289
1290 // Release AltGr. Win32 doesn't dispatch ControlLeft up. Instead Flutter will
1291 // forge one. The AltGr is a system key, therefore will be handled by Win32's
1292 // default WndProc.
1293 tester.InjectKeyboardChanges(std::vector<KeyboardChange>{
1294 KeyStateChange{VK_LCONTROL, false, true},
1295 ExpectForgedMessage{
1296 WmKeyUpInfo{VK_CONTROL, kScanCodeControl, kNotExtended}.Build(
1297 kWmResultZero)},
1298 KeyStateChange{VK_RMENU, false, true},
1299 WmSysKeyUpInfo{VK_MENU, kScanCodeAlt, kExtended}.Build(
1300 kWmResultDefault)});
1301
1302 EXPECT_EQ(tester.key_calls.size(), 2);
1303 EXPECT_CALL_IS_EVENT(tester.key_calls[0], kFlutterKeyEventTypeUp,
1304 kPhysicalControlLeft, kLogicalControlLeft, "",
1305 kNotSynthesized);
1306 EXPECT_CALL_IS_EVENT(tester.key_calls[1], kFlutterKeyEventTypeUp,
1307 kPhysicalAltRight, kLogicalAltRight, "",
1308 kNotSynthesized);
1309 tester.clear_key_calls();
1310 // The sys key up must not be redispatched. The forged ControlLeft up will.
1311 EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 1);
1312 }
EXPECT_CALL_IS_TEXT
#define EXPECT_CALL_IS_TEXT(_key_call, u16_string)
Definition: keyboard_unittests.cc:560
EXPECT_CALL_IS_EVENT
#define EXPECT_CALL_IS_EVENT(_key_call, _type, _physical, _logical, _character, _synthesized)
Definition: keyboard_unittests.cc:554

References EXPECT_CALL_IS_EVENT, and EXPECT_CALL_IS_TEXT.

## ◆ TEST_F() [70/163]

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

Definition at line 1327 of file keyboard_unittests.cc.

1327 {
1328 KeyboardTester tester{GetContext()};
1329 tester.Responding(false);
1330
1331 // 1. AltGr down.
1332
1333 // The key down event causes a ControlLeft down and a AltRight (extended
1334 // AltLeft) down.
1335 tester.InjectKeyboardChanges(std::vector<KeyboardChange>{
1336 KeyStateChange{VK_LCONTROL, true, true},
1337 WmKeyDownInfo{VK_CONTROL, kScanCodeControl, kNotExtended, kWasUp}.Build(
1338 kWmResultZero),
1339 KeyStateChange{VK_RMENU, true, true},
1340 WmKeyDownInfo{VK_MENU, kScanCodeAlt, kExtended, kWasUp}.Build(
1341 kWmResultZero)});
1342
1343 EXPECT_EQ(tester.key_calls.size(), 2);
1344 EXPECT_CALL_IS_EVENT(tester.key_calls[0], kFlutterKeyEventTypeDown,
1345 kPhysicalControlLeft, kLogicalControlLeft, "",
1346 kNotSynthesized);
1347 EXPECT_CALL_IS_EVENT(tester.key_calls[1], kFlutterKeyEventTypeDown,
1348 kPhysicalAltRight, kLogicalAltRight, "",
1349 kNotSynthesized);
1350 tester.clear_key_calls();
1351 EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 2);
1352
1353 // 2. AltGr up.
1354
1355 // The key up event only causes a AltRight (extended AltLeft) up.
1356 tester.InjectKeyboardChanges(std::vector<KeyboardChange>{
1357 KeyStateChange{VK_LCONTROL, false, true},
1358 ExpectForgedMessage{
1359 WmKeyUpInfo{VK_CONTROL, kScanCodeControl, kNotExtended}.Build(
1360 kWmResultZero)},
1361 KeyStateChange{VK_RMENU, false, true},
1362 WmSysKeyUpInfo{VK_MENU, kScanCodeAlt, kExtended}.Build(
1363 kWmResultDefault)});
1364 EXPECT_EQ(tester.key_calls.size(), 2);
1365 EXPECT_CALL_IS_EVENT(tester.key_calls[0], kFlutterKeyEventTypeUp,
1366 kPhysicalControlLeft, kLogicalControlLeft, "",
1367 kNotSynthesized);
1368 EXPECT_CALL_IS_EVENT(tester.key_calls[1], kFlutterKeyEventTypeUp,
1369 kPhysicalAltRight, kLogicalAltRight, "",
1370 kNotSynthesized);
1371 tester.clear_key_calls();
1372 // The sys key up must not be redispatched. The forged ControlLeft up will.
1373 EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 1);
1374
1375 // 3. AltGr down (or: ControlLeft down then AltRight down.)
1376
1377 tester.InjectKeyboardChanges(std::vector<KeyboardChange>{
1378 KeyStateChange{VK_LCONTROL, true, false},
1379 WmKeyDownInfo{VK_CONTROL, kScanCodeControl, kNotExtended, kWasUp}.Build(
1380 kWmResultZero),
1381 KeyStateChange{VK_RMENU, true, true},
1382 WmKeyDownInfo{VK_MENU, kScanCodeAlt, kExtended, kWasUp}.Build(
1383 kWmResultZero)});
1384
1385 EXPECT_EQ(tester.key_calls.size(), 2);
1386 EXPECT_CALL_IS_EVENT(tester.key_calls[0], kFlutterKeyEventTypeDown,
1387 kPhysicalControlLeft, kLogicalControlLeft, "",
1388 kNotSynthesized);
1389 EXPECT_CALL_IS_EVENT(tester.key_calls[1], kFlutterKeyEventTypeDown,
1390 kPhysicalAltRight, kLogicalAltRight, "",
1391 kNotSynthesized);
1392 tester.clear_key_calls();
1393 EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 2);
1394
1395 // 4. AltGr up.
1396
1397 // The key up event only causes a AltRight (extended AltLeft) up.
1398 tester.InjectKeyboardChanges(std::vector<KeyboardChange>{
1399 KeyStateChange{VK_LCONTROL, false, false},
1400 ExpectForgedMessage{
1401 WmKeyUpInfo{VK_CONTROL, kScanCodeControl, kNotExtended}.Build(
1402 kWmResultZero)},
1403 KeyStateChange{VK_RMENU, false, false},
1404 WmSysKeyUpInfo{VK_MENU, kScanCodeAlt, kExtended}.Build(
1405 kWmResultDefault)});
1406 EXPECT_EQ(tester.key_calls.size(), 2);
1407 EXPECT_CALL_IS_EVENT(tester.key_calls[0], kFlutterKeyEventTypeUp,
1408 kPhysicalControlLeft, kLogicalControlLeft, "",
1409 kNotSynthesized);
1410 EXPECT_CALL_IS_EVENT(tester.key_calls[1], kFlutterKeyEventTypeUp,
1411 kPhysicalAltRight, kLogicalAltRight, "",
1412 kNotSynthesized);
1413 tester.clear_key_calls();
1414 // The sys key up must not be redispatched. The forged ControlLeft up will.
1415 EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 1);
1416
1417 // 5. For key sequence 2: a real ControlLeft up.
1418 tester.InjectKeyboardChanges(std::vector<KeyboardChange>{
1419 WmKeyUpInfo{VK_CONTROL, kScanCodeControl, kNotExtended}.Build(
1420 kWmResultZero)});
1421 EXPECT_EQ(tester.key_calls.size(), 1);
1422 EXPECT_CALL_IS_EVENT(tester.key_calls[0], kFlutterKeyEventTypeDown, 0, 0, "",
1423 kNotSynthesized);
1424 tester.clear_key_calls();
1425 EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 0);
1426 }

References EXPECT_CALL_IS_EVENT.

## ◆ TEST_F() [71/163]

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

Definition at line 837 of file keyboard_unittests.cc.

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

References EXPECT_CALL_IS_EVENT.

## ◆ TEST_F() [72/163]

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

Definition at line 870 of file keyboard_unittests.cc.

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

References EXPECT_CALL_IS_EVENT.

## ◆ TEST_F() [73/163]

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

Definition at line 631 of file keyboard_unittests.cc.

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

References EXPECT_CALL_IS_EVENT.

## ◆ TEST_F() [74/163]

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

Definition at line 662 of file keyboard_unittests.cc.

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

References EXPECT_CALL_IS_EVENT.

## ◆ TEST_F() [75/163]

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

Definition at line 1150 of file keyboard_unittests.cc.

1150 {
1151 KeyboardTester tester{GetContext()};
1152 tester.Responding(false);
1153
1154 // US Keyboard layout
1155
1156 // Press ControlLeft
1157 tester.InjectKeyboardChanges(std::vector<KeyboardChange>{
1158 KeyStateChange{VK_LCONTROL, true, true},
1159 WmKeyDownInfo{VK_CONTROL, kScanCodeControl, kNotExtended, kWasUp}.Build(
1160 kWmResultZero)});
1161
1162 EXPECT_EQ(tester.key_calls.size(), 1);
1163 EXPECT_CALL_IS_EVENT(tester.key_calls[0], kFlutterKeyEventTypeDown,
1164 kPhysicalControlLeft, kLogicalControlLeft, "",
1165 kNotSynthesized);
1166 tester.clear_key_calls();
1167 EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 1);
1168
1169 // Press 1
1170 tester.InjectKeyboardChanges(std::vector<KeyboardChange>{
1171 WmKeyDownInfo{kVirtualDigit1, kScanCodeDigit1, kNotExtended, kWasUp}
1172 .Build(kWmResultZero)});
1173
1174 EXPECT_EQ(tester.key_calls.size(), 1);
1175 EXPECT_CALL_IS_EVENT(tester.key_calls[0], kFlutterKeyEventTypeDown,
1176 kPhysicalDigit1, kLogicalDigit1, "", kNotSynthesized);
1177 tester.clear_key_calls();
1178 EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 1);
1179
1180 // Release 1
1181 tester.InjectKeyboardChanges(std::vector<KeyboardChange>{
1182 WmKeyUpInfo{kVirtualDigit1, kScanCodeDigit1, kNotExtended}.Build(
1183 kWmResultZero)});
1184
1185 EXPECT_EQ(tester.key_calls.size(), 1);
1186 EXPECT_CALL_IS_EVENT(tester.key_calls[0], kFlutterKeyEventTypeUp,
1187 kPhysicalDigit1, kLogicalDigit1, "", kNotSynthesized);
1188 tester.clear_key_calls();
1189 EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 1);
1190
1191 // Release ControlLeft
1192 tester.InjectKeyboardChanges(std::vector<KeyboardChange>{
1193 KeyStateChange{VK_LCONTROL, false, true},
1194 WmKeyUpInfo{VK_CONTROL, kScanCodeControl, kNotExtended}.Build(
1195 kWmResultZero)});
1196
1197 EXPECT_EQ(tester.key_calls.size(), 1);
1198 EXPECT_CALL_IS_EVENT(tester.key_calls[0], kFlutterKeyEventTypeUp,
1199 kPhysicalControlLeft, kLogicalControlLeft, "",
1200 kNotSynthesized);
1201 tester.clear_key_calls();
1202 EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 1);
1203 }

References EXPECT_CALL_IS_EVENT.

## ◆ TEST_F() [76/163]

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

Definition at line 1092 of file keyboard_unittests.cc.

1092 {
1093 KeyboardTester tester{GetContext()};
1094 tester.Responding(false);
1095
1096 // US Keyboard layout
1097
1098 // Press ControlLeft
1099 tester.InjectKeyboardChanges(std::vector<KeyboardChange>{
1100 KeyStateChange{VK_LCONTROL, true, true},
1101 WmKeyDownInfo{VK_CONTROL, kScanCodeControl, kNotExtended, kWasUp}.Build(
1102 kWmResultZero)});
1103
1104 EXPECT_EQ(tester.key_calls.size(), 1);
1105 EXPECT_CALL_IS_EVENT(tester.key_calls[0], kFlutterKeyEventTypeDown,
1106 kPhysicalControlLeft, kLogicalControlLeft, "",
1107 kNotSynthesized);
1108 tester.clear_key_calls();
1109 EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 1);
1110
1111 // Press A
1112 tester.InjectKeyboardChanges(std::vector<KeyboardChange>{
1113 WmKeyDownInfo{kVirtualKeyA, kScanCodeKeyA, kNotExtended, kWasUp}.Build(
1114 kWmResultZero),
1115 WmCharInfo{0x01, kScanCodeKeyA, kNotExtended, kWasUp}.Build(
1116 kWmResultZero)});
1117
1118 EXPECT_EQ(tester.key_calls.size(), 1);
1119 EXPECT_CALL_IS_EVENT(tester.key_calls[0], kFlutterKeyEventTypeDown,
1120 kPhysicalKeyA, kLogicalKeyA, "", kNotSynthesized);
1121 tester.clear_key_calls();
1122 EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 2);
1123
1124 // Release A
1125 tester.InjectKeyboardChanges(std::vector<KeyboardChange>{
1126 WmKeyUpInfo{kVirtualKeyA, kScanCodeKeyA, kNotExtended}.Build(
1127 kWmResultZero)});
1128
1129 EXPECT_EQ(tester.key_calls.size(), 1);
1130 EXPECT_CALL_IS_EVENT(tester.key_calls[0], kFlutterKeyEventTypeUp,
1131 kPhysicalKeyA, kLogicalKeyA, "", kNotSynthesized);
1132 tester.clear_key_calls();
1133 EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 1);
1134
1135 // Release ControlLeft
1136 tester.InjectKeyboardChanges(std::vector<KeyboardChange>{
1137 KeyStateChange{VK_LCONTROL, false, true},
1138 WmKeyUpInfo{VK_CONTROL, kScanCodeControl, kNotExtended}.Build(
1139 kWmResultZero)});
1140
1141 EXPECT_EQ(tester.key_calls.size(), 1);
1142 EXPECT_CALL_IS_EVENT(tester.key_calls[0], kFlutterKeyEventTypeUp,
1143 kPhysicalControlLeft, kLogicalControlLeft, "",
1144 kNotSynthesized);
1145 tester.clear_key_calls();
1146 EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 1);
1147 }

References EXPECT_CALL_IS_EVENT, kScanCodeKeyA, and kVirtualKeyA.

## ◆ TEST_F() [77/163]

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

Definition at line 771 of file keyboard_unittests.cc.

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

References EXPECT_CALL_IS_EVENT.

## ◆ TEST_F() [78/163]

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

Definition at line 804 of file keyboard_unittests.cc.

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

References EXPECT_CALL_IS_EVENT.

## ◆ TEST_F() [79/163]

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

Definition at line 1430 of file keyboard_unittests.cc.

1430 {
1431 KeyboardTester tester{GetContext()};
1432 tester.Responding(false);
1433
1434 tester.SetLayout(LayoutFrench);
1435
1436 // Press ^¨ (US: Left bracket)
1437 tester.InjectKeyboardChanges(std::vector<KeyboardChange>{
1438 WmKeyDownInfo{0xDD, kScanCodeBracketLeft, kNotExtended, kWasUp}.Build(
1439 kWmResultZero),
1440 WmDeadCharInfo{'^', kScanCodeBracketLeft, kNotExtended, kWasUp}.Build(
1441 kWmResultZero)});
1442
1443 EXPECT_EQ(tester.key_calls.size(), 1);
1444 EXPECT_CALL_IS_EVENT(tester.key_calls[0], kFlutterKeyEventTypeDown,
1445 kPhysicalBracketLeft, kLogicalBracketRight, "^",
1446 kNotSynthesized);
1447 tester.clear_key_calls();
1448 EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 2);
1449
1450 // Release ^¨
1451 tester.InjectKeyboardChanges(std::vector<KeyboardChange>{
1452 WmKeyUpInfo{0xDD, kScanCodeBracketLeft, kNotExtended}.Build(
1453 kWmResultZero)});
1454
1455 EXPECT_EQ(tester.key_calls.size(), 1);
1456 EXPECT_CALL_IS_EVENT(tester.key_calls[0], kFlutterKeyEventTypeUp,
1457 kPhysicalBracketLeft, kLogicalBracketRight, "",
1458 kNotSynthesized);
1459 tester.clear_key_calls();
1460 EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 1);
1461
1462 // Press E
1463 tester.InjectKeyboardChanges(std::vector<KeyboardChange>{
1464 WmKeyDownInfo{kVirtualKeyE, kScanCodeKeyE, kNotExtended, kWasUp}.Build(
1465 kWmResultZero),
1466 WmCharInfo{0xEA, kScanCodeKeyE, kNotExtended, kWasUp}.Build(
1467 kWmResultZero)});
1468
1469 EXPECT_EQ(tester.key_calls.size(), 2);
1470 EXPECT_CALL_IS_EVENT(tester.key_calls[0], kFlutterKeyEventTypeDown,
1471 kPhysicalKeyE, kLogicalKeyE, "ê", kNotSynthesized);
1472 EXPECT_CALL_IS_TEXT(tester.key_calls[1], u"ê");
1473 tester.clear_key_calls();
1474 EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 2);
1475
1476 // Release E
1477 tester.InjectKeyboardChanges(std::vector<KeyboardChange>{
1478 WmKeyUpInfo{kVirtualKeyE, kScanCodeKeyE, kNotExtended}.Build(
1479 kWmResultZero)});
1480
1481 EXPECT_EQ(tester.key_calls.size(), 1);
1482 EXPECT_CALL_IS_EVENT(tester.key_calls[0], kFlutterKeyEventTypeUp,
1483 kPhysicalKeyE, kLogicalKeyE, "", kNotSynthesized);
1484 tester.clear_key_calls();
1485 EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 1);
1486 }

References EXPECT_CALL_IS_EVENT, and EXPECT_CALL_IS_TEXT.

## ◆ TEST_F() [80/163]

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

Definition at line 1574 of file keyboard_unittests.cc.

1574 {
1575 KeyboardTester tester{GetContext()};
1576 tester.Responding(false);
1577
1578 tester.SetLayout(LayoutFrench);
1579
1580 // Press ^¨ (US: Left bracket)
1581 tester.InjectKeyboardChanges(std::vector<KeyboardChange>{
1582 WmKeyDownInfo{0xDD, kScanCodeBracketLeft, kNotExtended, kWasUp}.Build(
1583 kWmResultZero),
1584 WmDeadCharInfo{'^', kScanCodeBracketLeft, kNotExtended, kWasUp}.Build(
1585 kWmResultZero)});
1586
1587 EXPECT_EQ(tester.key_calls.size(), 1);
1588 EXPECT_CALL_IS_EVENT(tester.key_calls[0], kFlutterKeyEventTypeDown,
1589 kPhysicalBracketLeft, kLogicalBracketRight, "^",
1590 kNotSynthesized);
1591 tester.clear_key_calls();
1592 EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 2);
1593
1594 // Release ^¨
1595 tester.InjectKeyboardChanges(std::vector<KeyboardChange>{
1596 WmKeyUpInfo{0xDD, kScanCodeBracketLeft, kNotExtended}.Build(
1597 kWmResultZero)});
1598
1599 EXPECT_EQ(tester.key_calls.size(), 1);
1600 EXPECT_CALL_IS_EVENT(tester.key_calls[0], kFlutterKeyEventTypeUp,
1601 kPhysicalBracketLeft, kLogicalBracketRight, "",
1602 kNotSynthesized);
1603 tester.clear_key_calls();
1604 EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 1);
1605
1606 // Press 1
1607 tester.InjectKeyboardChanges(std::vector<KeyboardChange>{
1608 WmKeyDownInfo{kVirtualDigit1, kScanCodeDigit1, kNotExtended, kWasUp}
1609 .Build(kWmResultZero),
1610 WmCharInfo{'^', kScanCodeDigit1, kNotExtended, kWasUp}.Build(
1611 kWmResultZero),
1612 WmCharInfo{'&', kScanCodeDigit1, kNotExtended, kWasUp}.Build(
1613 kWmResultZero)});
1614
1615 EXPECT_EQ(tester.key_calls.size(), 3);
1616 EXPECT_CALL_IS_EVENT(tester.key_calls[0], kFlutterKeyEventTypeDown,
1617 kPhysicalDigit1, kLogicalDigit1, "^", kNotSynthesized);
1618 EXPECT_CALL_IS_TEXT(tester.key_calls[1], u"^");
1619 EXPECT_CALL_IS_TEXT(tester.key_calls[2], u"&");
1620 tester.clear_key_calls();
1621 // TODO(dkwingsmt): This count should probably be 3. Currently the '^'
1622 // message is redispatched due to being part of the KeyDown session, which is
1623 // not handled by the framework, while the '&' message is not redispatched
1624 // for being a standalone message. We should resolve this inconsistency.
1625 // https://github.com/flutter/flutter/issues/98306
1626 EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 2);
1627
1628 // Release 1
1629 tester.InjectKeyboardChanges(std::vector<KeyboardChange>{
1630 WmKeyUpInfo{kVirtualDigit1, kScanCodeDigit1, kNotExtended}.Build(
1631 kWmResultZero)});
1632
1633 EXPECT_EQ(tester.key_calls.size(), 1);
1634 EXPECT_CALL_IS_EVENT(tester.key_calls[0], kFlutterKeyEventTypeUp,
1635 kPhysicalDigit1, kLogicalDigit1, "", kNotSynthesized);
1636 tester.clear_key_calls();
1637 EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 1);
1638 }

References EXPECT_CALL_IS_EVENT, and EXPECT_CALL_IS_TEXT.

## ◆ TEST_F() [81/163]

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

Definition at line 1643 of file keyboard_unittests.cc.

1643 {
1644 KeyboardTester tester{GetContext()};
1645 tester.Responding(false);
1646
1647 // US INTL layout.
1648
1649 // Press `
1650 tester.InjectKeyboardChanges(std::vector<KeyboardChange>{
1651 WmKeyDownInfo{0xC0, kScanCodeBackquote, kNotExtended, kWasUp}.Build(
1652 kWmResultZero),
1653 WmDeadCharInfo{'`', kScanCodeBackquote, kNotExtended, kWasUp}.Build(
1654 kWmResultZero)});
1655
1656 EXPECT_EQ(tester.key_calls.size(), 1);
1657 EXPECT_CALL_IS_EVENT(tester.key_calls[0], kFlutterKeyEventTypeDown,
1658 kPhysicalBackquote, kLogicalBackquote, "`",
1659 kNotSynthesized);
1660 tester.clear_key_calls();
1661 EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 2);
1662
1663 // Release `
1664 tester.InjectKeyboardChanges(std::vector<KeyboardChange>{
1665 WmKeyUpInfo{0xC0, kScanCodeBackquote, kNotExtended}.Build(
1666 kWmResultZero)});
1667
1668 EXPECT_EQ(tester.key_calls.size(), 1);
1669 EXPECT_CALL_IS_EVENT(tester.key_calls[0], kFlutterKeyEventTypeUp,
1670 kPhysicalBackquote, kLogicalBackquote, "",
1671 kNotSynthesized);
1672 tester.clear_key_calls();
1673 EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 1);
1674
1675 // Press ` again.
1676 // The response should be slow.
1677 std::vector<MockKeyResponseController::ResponseCallback> recorded_callbacks;
1678 tester.LateResponding(
1679 [&recorded_callbacks](
1680 const FlutterKeyEvent* event,
1681 MockKeyResponseController::ResponseCallback callback) {
1682 recorded_callbacks.push_back(callback);
1683 });
1684
1685 tester.InjectKeyboardChanges(std::vector<KeyboardChange>{
1686 WmKeyDownInfo{0xC0, kScanCodeBackquote, kNotExtended, kWasUp}.Build(
1687 kWmResultZero),
1688 WmCharInfo{'`', kScanCodeBackquote, kNotExtended, kWasUp, kBeingReleased,
1689 kNoContext, 1, /*bit25*/ true}
1690 .Build(kWmResultZero),
1691 WmCharInfo{'`', kScanCodeBackquote, kNotExtended, kWasUp}.Build(
1692 kWmResultZero)});
1693
1694 EXPECT_EQ(recorded_callbacks.size(), 1);
1695 EXPECT_EQ(tester.key_calls.size(), 1);
1696 EXPECT_CALL_IS_EVENT(tester.key_calls[0], kFlutterKeyEventTypeDown,
1697 kPhysicalBackquote, kLogicalBackquote, "`",
1698 kNotSynthesized);
1699 tester.clear_key_calls();
1700 // Key down event responded with false.
1701 recorded_callbacks.front()(false);
1702 EXPECT_EQ(tester.key_calls.size(), 2);
1703 EXPECT_CALL_IS_TEXT(tester.key_calls[0], u"`");
1704 EXPECT_CALL_IS_TEXT(tester.key_calls[1], u"`");
1705 tester.clear_key_calls();
1706 // TODO(dkwingsmt): This count should probably be 3. See the comment above
1707 // that is marked with the same issue.
1708 // https://github.com/flutter/flutter/issues/98306
1709 EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 2);
1710
1711 tester.Responding(false);
1712
1713 // Release `
1714 tester.InjectKeyboardChanges(std::vector<KeyboardChange>{
1715 WmKeyUpInfo{0xC0, kScanCodeBackquote, kNotExtended}.Build(
1716 kWmResultZero)});
1717
1718 EXPECT_EQ(tester.key_calls.size(), 1);
1719 EXPECT_CALL_IS_EVENT(tester.key_calls[0], kFlutterKeyEventTypeUp,
1720 kPhysicalBackquote, kLogicalBackquote, "",
1721 kNotSynthesized);
1722 tester.clear_key_calls();
1723 EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 1);
1724 }

References callback, EXPECT_CALL_IS_EVENT, and EXPECT_CALL_IS_TEXT.

## ◆ TEST_F() [82/163]

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

Definition at line 1493 of file keyboard_unittests.cc.

1493 {
1494 KeyboardTester tester{GetContext()};
1495 tester.Responding(false);
1496
1497 // Press ShiftLeft
1498 tester.InjectKeyboardChanges(std::vector<KeyboardChange>{
1499 KeyStateChange{VK_LSHIFT, true, true},
1500 WmKeyDownInfo{VK_SHIFT, kScanCodeShiftLeft, kNotExtended, kWasUp}.Build(
1501 kWmResultZero)});
1502
1503 EXPECT_EQ(tester.key_calls.size(), 1);
1504 EXPECT_CALL_IS_EVENT(tester.key_calls[0], kFlutterKeyEventTypeDown,
1505 kPhysicalShiftLeft, kLogicalShiftLeft, "",
1506 kNotSynthesized);
1507 tester.clear_key_calls();
1508 EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 1);
1509
1510 // Press 6^
1511 tester.InjectKeyboardChanges(std::vector<KeyboardChange>{
1512 WmKeyDownInfo{'6', kScanCodeDigit6, kNotExtended, kWasUp}.Build(
1513 kWmResultZero),
1514 WmDeadCharInfo{'^', kScanCodeDigit6, kNotExtended, kWasUp}.Build(
1515 kWmResultZero)});
1516
1517 EXPECT_EQ(tester.key_calls.size(), 1);
1518 EXPECT_CALL_IS_EVENT(tester.key_calls[0], kFlutterKeyEventTypeDown,
1519 kPhysicalDigit6, kLogicalDigit6, "6", kNotSynthesized);
1520 tester.clear_key_calls();
1521 EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 2);
1522
1523 // Release 6^
1524 tester.InjectKeyboardChanges(std::vector<KeyboardChange>{
1525 WmKeyUpInfo{'6', kScanCodeDigit6, kNotExtended}.Build(kWmResultZero)});
1526
1527 EXPECT_EQ(tester.key_calls.size(), 1);
1528 EXPECT_CALL_IS_EVENT(tester.key_calls[0], kFlutterKeyEventTypeUp,
1529 kPhysicalDigit6, kLogicalDigit6, "", kNotSynthesized);
1530 tester.clear_key_calls();
1531 EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 1);
1532
1533 // Release ShiftLeft
1534 tester.InjectKeyboardChanges(std::vector<KeyboardChange>{
1535 KeyStateChange{VK_LSHIFT, false, true},
1536 WmKeyUpInfo{VK_SHIFT, kScanCodeShiftLeft, kNotExtended}.Build(
1537 kWmResultZero)});
1538
1539 EXPECT_EQ(tester.key_calls.size(), 1);
1540 EXPECT_CALL_IS_EVENT(tester.key_calls[0], kFlutterKeyEventTypeUp,
1541 kPhysicalShiftLeft, kLogicalShiftLeft, "",
1542 kNotSynthesized);
1543 tester.clear_key_calls();
1544 EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 1);
1545
1546 // Press E
1547 tester.InjectKeyboardChanges(std::vector<KeyboardChange>{
1548 WmKeyDownInfo{kVirtualKeyE, kScanCodeKeyE, kNotExtended, kWasUp}.Build(
1549 kWmResultZero),
1550 WmCharInfo{0xEA, kScanCodeKeyE, kNotExtended, kWasUp}.Build(
1551 kWmResultZero)});
1552
1553 EXPECT_EQ(tester.key_calls.size(), 2);
1554 EXPECT_CALL_IS_EVENT(tester.key_calls[0], kFlutterKeyEventTypeDown,
1555 kPhysicalKeyE, kLogicalKeyE, "ê", kNotSynthesized);
1556 EXPECT_CALL_IS_TEXT(tester.key_calls[1], u"ê");
1557 tester.clear_key_calls();
1558 EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 2);
1559
1560 // Release E
1561 tester.InjectKeyboardChanges(std::vector<KeyboardChange>{
1562 WmKeyUpInfo{kVirtualKeyE, kScanCodeKeyE, kNotExtended}.Build(
1563 kWmResultZero)});
1564
1565 EXPECT_EQ(tester.key_calls.size(), 1);
1566 EXPECT_CALL_IS_EVENT(tester.key_calls[0], kFlutterKeyEventTypeUp,
1567 kPhysicalKeyE, kLogicalKeyE, "", kNotSynthesized);
1568 tester.clear_key_calls();
1569 EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 1);
1570 }

References EXPECT_CALL_IS_EVENT, EXPECT_CALL_IS_TEXT, and flutter::kScanCodeShiftLeft.

## ◆ TEST_F() [83/163]

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

Definition at line 1207 of file keyboard_unittests.cc.

1207 {
1208 KeyboardTester tester{GetContext()};
1209 tester.Responding(false);
1210
1211 tester.SetLayout(LayoutFrench);
1212
1213 // Press 1
1214 tester.InjectKeyboardChanges(std::vector<KeyboardChange>{
1215 WmKeyDownInfo{kVirtualDigit1, kScanCodeDigit1, kNotExtended, kWasUp}
1216 .Build(kWmResultZero),
1217 WmCharInfo{'&', kScanCodeDigit1, kNotExtended, kWasUp}.Build(
1218 kWmResultZero)});
1219
1220 EXPECT_EQ(tester.key_calls.size(), 2);
1221 EXPECT_CALL_IS_EVENT(tester.key_calls[0], kFlutterKeyEventTypeDown,
1222 kPhysicalDigit1, kLogicalDigit1, "&", kNotSynthesized);
1223 EXPECT_CALL_IS_TEXT(tester.key_calls[1], u"&");
1224 tester.clear_key_calls();
1225 EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 2);
1226
1227 // Release 1
1228 tester.InjectKeyboardChanges(std::vector<KeyboardChange>{
1229 WmKeyUpInfo{kVirtualDigit1, kScanCodeDigit1, kNotExtended}.Build(
1230 kWmResultZero)});
1231
1232 EXPECT_EQ(tester.key_calls.size(), 1);
1233 EXPECT_CALL_IS_EVENT(tester.key_calls[0], kFlutterKeyEventTypeUp,
1234 kPhysicalDigit1, kLogicalDigit1, "", kNotSynthesized);
1235 tester.clear_key_calls();
1236 EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 1);
1237 }

References EXPECT_CALL_IS_EVENT, and EXPECT_CALL_IS_TEXT.

## ◆ TEST_F() [84/163]

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

Definition at line 2466 of file keyboard_unittests.cc.

2466 {
2467 KeyboardTester tester{GetContext()};
2468 tester.Responding(false);
2469
2470 tester.InjectKeyboardChanges(std::vector<KeyboardChange>{
2471 WmKeyDownInfo{VK_CAPITAL, 0, kNotExtended}.Build(),
2472 WmKeyUpInfo{VK_CAPITAL, 0, kNotExtended}.Build()});
2473
2474 tester.clear_key_calls();
2475 }

## ◆ TEST_F() [85/163]

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

Definition at line 1992 of file keyboard_unittests.cc.

1992 {
1993 KeyboardTester tester{GetContext()};
1994 tester.Responding(false);
1995
1996 // US Keyboard layout.
1997
1998 // There should be preceding key events to make the keyboard into IME mode.
1999 // Omit them in this test since they are not relavent.
2000
2001 // Press CtrlRight in IME mode.
2002 tester.InjectKeyboardChanges(std::vector<KeyboardChange>{
2003 KeyStateChange{VK_RCONTROL, true, false},
2004 WmKeyDownInfo{VK_PROCESSKEY, kScanCodeControl, kExtended, kWasUp}.Build(
2005 kWmResultZero)});
2006
2007 EXPECT_EQ(tester.key_calls.size(), 1);
2008 EXPECT_CALL_IS_EVENT(tester.key_calls[0], kFlutterKeyEventTypeDown, 0, 0, "",
2009 kNotSynthesized);
2010 tester.clear_key_calls();
2011 EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 0);
2012 }

References EXPECT_CALL_IS_EVENT.

## ◆ TEST_F() [86/163]

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

Definition at line 568 of file keyboard_unittests.cc.

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

References EXPECT_CALL_IS_EVENT, kScanCodeKeyA, and kVirtualKeyA.

## ◆ TEST_F() [87/163]

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

Definition at line 599 of file keyboard_unittests.cc.

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

References EXPECT_CALL_IS_EVENT, EXPECT_CALL_IS_TEXT, kScanCodeKeyA, and kVirtualKeyA.

## ◆ TEST_F() [88/163]

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

Definition at line 905 of file keyboard_unittests.cc.

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

References EXPECT_CALL_IS_EVENT.

## ◆ TEST_F() [89/163]

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

Definition at line 937 of file keyboard_unittests.cc.

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

References EXPECT_CALL_IS_EVENT.

## ◆ TEST_F() [90/163]

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

Definition at line 1727 of file keyboard_unittests.cc.

1727 {
1728 KeyboardTester tester{GetContext()};
1729 tester.Responding(false);
1730
1731 // Gothic Keyboard layout. (We need a layout that yields non-BMP characters
1732 // without IME, which is actually very rare.)
1733
1734 // Press key W of a US keyboard, which should yield character '𐍅'.
1735 tester.InjectKeyboardChanges(std::vector<KeyboardChange>{
1736 WmKeyDownInfo{kVirtualKeyW, kScanCodeKeyW, kNotExtended, kWasUp}.Build(
1737 kWmResultZero),
1738 WmCharInfo{0xd800, kScanCodeKeyW, kNotExtended, kWasUp}.Build(
1739 kWmResultZero),
1740 WmCharInfo{0xdf45, kScanCodeKeyW, kNotExtended, kWasUp}.Build(
1741 kWmResultZero)});
1742
1743 const char* st = tester.key_calls[0].key_event.character;
1744
1745 EXPECT_EQ(tester.key_calls.size(), 2);
1746 EXPECT_CALL_IS_EVENT(tester.key_calls[0], kFlutterKeyEventTypeDown,
1747 kPhysicalKeyW, kLogicalKeyW, "𐍅", kNotSynthesized);
1748 EXPECT_CALL_IS_TEXT(tester.key_calls[1], u"𐍅");
1749 tester.clear_key_calls();
1750 EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 3);
1751
1752 // Release W
1753 tester.InjectKeyboardChanges(std::vector<KeyboardChange>{
1754 WmKeyUpInfo{kVirtualKeyW, kScanCodeKeyW, kNotExtended}.Build(
1755 kWmResultZero)});
1756
1757 EXPECT_EQ(tester.key_calls.size(), 1);
1758 EXPECT_CALL_IS_EVENT(tester.key_calls[0], kFlutterKeyEventTypeUp,
1759 kPhysicalKeyW, kLogicalKeyW, "", kNotSynthesized);
1760 tester.clear_key_calls();
1761 EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 1);
1762 }

References EXPECT_CALL_IS_EVENT, and EXPECT_CALL_IS_TEXT.

## ◆ TEST_F() [91/163]

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

Definition at line 971 of file keyboard_unittests.cc.

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

References EXPECT_CALL_IS_EVENT, kScanCodeKeyA, and kVirtualKeyA.

## ◆ TEST_F() [92/163]

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

Definition at line 1000 of file keyboard_unittests.cc.

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

References EXPECT_CALL_IS_EVENT, kScanCodeKeyA, and kVirtualKeyA.

## ◆ TEST_F() [93/163]

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

Definition at line 1032 of file keyboard_unittests.cc.

1032 {
1033 KeyboardTester tester{GetContext()};
1034 tester.Responding(false);
1035
1036 // US Keyboard layout
1037
1038 // Press ShiftLeft
1039 tester.InjectKeyboardChanges(std::vector<KeyboardChange>{
1040 KeyStateChange{VK_LSHIFT, true, true},
1041 WmKeyDownInfo{VK_SHIFT, kScanCodeShiftLeft, kNotExtended, kWasUp}.Build(
1042 kWmResultZero)});
1043
1044 EXPECT_EQ(tester.key_calls.size(), 1);
1045 EXPECT_CALL_IS_EVENT(tester.key_calls[0], kFlutterKeyEventTypeDown,
1046 kPhysicalShiftLeft, kLogicalShiftLeft, "",
1047 kNotSynthesized);
1048 tester.clear_key_calls();
1049 EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 1);
1050
1051 // Press A
1052 tester.InjectKeyboardChanges(std::vector<KeyboardChange>{
1053 WmKeyDownInfo{kVirtualKeyA, kScanCodeKeyA, kNotExtended, kWasUp}.Build(
1054 kWmResultZero),
1055 WmCharInfo{'A', kScanCodeKeyA, kNotExtended, kWasUp}.Build(
1056 kWmResultZero)});
1057
1058 EXPECT_EQ(tester.key_calls.size(), 2);
1059 EXPECT_CALL_IS_EVENT(tester.key_calls[0], kFlutterKeyEventTypeDown,
1060 kPhysicalKeyA, kLogicalKeyA, "A", kNotSynthesized);
1061 EXPECT_CALL_IS_TEXT(tester.key_calls[1], u"A");
1062 tester.clear_key_calls();
1063 EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 2);
1064
1065 // Release ShiftLeft
1066 tester.InjectKeyboardChanges(std::vector<KeyboardChange>{
1067 KeyStateChange{VK_LSHIFT, false, true},
1068 WmKeyUpInfo{VK_SHIFT, kScanCodeShiftLeft, kNotExtended}.Build(
1069 kWmResultZero)});
1070
1071 EXPECT_EQ(tester.key_calls.size(), 1);
1072 EXPECT_CALL_IS_EVENT(tester.key_calls[0], kFlutterKeyEventTypeUp,
1073 kPhysicalShiftLeft, kLogicalShiftLeft, "",
1074 kNotSynthesized);
1075 tester.clear_key_calls();
1076 EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 1);
1077
1078 // Release A
1079 tester.InjectKeyboardChanges(std::vector<KeyboardChange>{
1080 WmKeyUpInfo{kVirtualKeyA, kScanCodeKeyA, kNotExtended}.Build(
1081 kWmResultZero)});
1082
1083 EXPECT_EQ(tester.key_calls.size(), 1);
1084 EXPECT_CALL_IS_EVENT(tester.key_calls[0], kFlutterKeyEventTypeUp,
1085 kPhysicalKeyA, kLogicalKeyA, "", kNotSynthesized);
1086 tester.clear_key_calls();
1087 EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 1);
1088 }

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

## ◆ TEST_F() [94/163]

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

Definition at line 693 of file keyboard_unittests.cc.

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

References EXPECT_CALL_IS_EVENT, and flutter::kScanCodeShiftLeft.

## ◆ TEST_F() [95/163]

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

Definition at line 738 of file keyboard_unittests.cc.

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

References EXPECT_CALL_IS_EVENT, and flutter::kScanCodeShiftRight.

## ◆ TEST_F() [96/163]

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

Definition at line 2059 of file keyboard_unittests.cc.

2059 {
2060 KeyboardTester tester{GetContext()};
2061
2062 std::vector<MockKeyResponseController::ResponseCallback> recorded_callbacks;
2063
2064 // Store callbacks to manually call them.
2065 tester.LateResponding(
2066 [&recorded_callbacks](
2067 const FlutterKeyEvent* event,
2068 MockKeyResponseController::ResponseCallback callback) {
2069 recorded_callbacks.push_back(callback);
2070 });
2071
2072 // Press A
2073 tester.InjectKeyboardChanges(std::vector<KeyboardChange>{
2074 WmKeyDownInfo{kVirtualKeyA, kScanCodeKeyA, kNotExtended, kWasUp}.Build(
2075 kWmResultZero),
2076 WmCharInfo{'a', kScanCodeKeyA, kNotExtended, kWasUp}.Build(
2077 kWmResultZero)});
2078
2079 // Hold A
2080 tester.InjectKeyboardChanges(std::vector<KeyboardChange>{
2081 WmKeyDownInfo{kVirtualKeyA, kScanCodeKeyA, kNotExtended, kWasDown}.Build(
2082 kWmResultZero),
2083 WmCharInfo{'a', kScanCodeKeyA, kNotExtended, kWasDown}.Build(
2084 kWmResultZero)});
2085
2086 EXPECT_EQ(tester.key_calls.size(), 1);
2087 EXPECT_CALL_IS_EVENT(tester.key_calls[0], kFlutterKeyEventTypeDown,
2088 kPhysicalKeyA, kLogicalKeyA, "a", kNotSynthesized);
2089 EXPECT_EQ(recorded_callbacks.size(), 1);
2090 EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 0);
2091
2092 // The first response.
2093 recorded_callbacks.front()(false);
2094
2095 EXPECT_EQ(tester.key_calls.size(), 3);
2096 EXPECT_EQ(recorded_callbacks.size(), 2);
2097 EXPECT_CALL_IS_TEXT(tester.key_calls[1], u"a");
2098 EXPECT_CALL_IS_EVENT(tester.key_calls[2], kFlutterKeyEventTypeRepeat,
2099 kPhysicalKeyA, kLogicalKeyA, "a", kNotSynthesized);
2100 EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 2);
2101
2102 // The second response.
2103 recorded_callbacks.back()(false);
2104
2105 EXPECT_EQ(tester.key_calls.size(), 4);
2106 EXPECT_CALL_IS_TEXT(tester.key_calls[3], u"a");
2107 tester.clear_key_calls();
2108 EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 2);
2109 }

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

## ◆ TEST_F() [97/163]

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

Definition at line 2122 of file keyboard_unittests.cc.

2122 {
2123 KeyboardTester tester{GetContext()};
2124 std::vector<MockKeyResponseController::ResponseCallback> recorded_callbacks;
2125
2126 // Store callbacks to manually call them.
2127 tester.LateResponding(
2128 [&recorded_callbacks](
2129 const FlutterKeyEvent* event,
2130 MockKeyResponseController::ResponseCallback callback) {
2131 recorded_callbacks.push_back(callback);
2132 });
2133
2134 // Press A
2135 tester.InjectKeyboardChanges(std::vector<KeyboardChange>{
2136 WmKeyDownInfo{kVirtualKeyA, kScanCodeKeyA, kNotExtended, kWasUp}.Build(
2137 kWmResultZero),
2138 WmCharInfo{'a', kScanCodeKeyA, kNotExtended, kWasUp}.Build(
2139 kWmResultZero)});
2140
2141 EXPECT_EQ(tester.key_calls.size(), 1);
2142 EXPECT_CALL_IS_EVENT(tester.key_calls[0], kFlutterKeyEventTypeDown,
2143 kPhysicalKeyA, kLogicalKeyA, "a", kNotSynthesized);
2144 tester.clear_key_calls();
2145 EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 0);
2146
2147 // Release A
2148 tester.InjectKeyboardChanges(std::vector<KeyboardChange>{
2149 WmKeyUpInfo{kVirtualKeyA, kScanCodeKeyA, kNotExtended}.Build(
2150 kWmResultZero)});
2151
2152 EXPECT_EQ(tester.key_calls.size(), 0);
2153 EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 0);
2154
2155 // The first down event responded with false.
2156 EXPECT_EQ(recorded_callbacks.size(), 1);
2157 recorded_callbacks.front()(false);
2158
2159 EXPECT_EQ(tester.key_calls.size(), 2);
2160 EXPECT_CALL_IS_TEXT(tester.key_calls[0], u"a");
2161 EXPECT_CALL_IS_EVENT(tester.key_calls[1], kFlutterKeyEventTypeUp,
2162 kPhysicalKeyA, kLogicalKeyA, "", kNotSynthesized);
2163 tester.clear_key_calls();
2164 EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 2);
2165
2166 // Press A again
2167 tester.InjectKeyboardChanges(std::vector<KeyboardChange>{
2168 WmKeyDownInfo{kVirtualKeyA, kScanCodeKeyA, kNotExtended, kWasUp}.Build(
2169 kWmResultZero),
2170 WmCharInfo{'a', kScanCodeKeyA, kNotExtended, kWasUp}.Build(
2171 kWmResultZero)});
2172
2173 // Nothing more was dispatched because the first up event hasn't been
2174 // responded yet.
2175 EXPECT_EQ(recorded_callbacks.size(), 2);
2176 EXPECT_EQ(tester.key_calls.size(), 0);
2177 EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 0);
2178
2179 // The first up event responded with false, which was redispatched, and caused
2180 // the down event to be dispatched.
2181 recorded_callbacks.back()(false);
2182 EXPECT_EQ(tester.key_calls.size(), 1);
2183 EXPECT_CALL_IS_EVENT(tester.key_calls[0], kFlutterKeyEventTypeDown,
2184 kPhysicalKeyA, kLogicalKeyA, "a", kNotSynthesized);
2185 tester.clear_key_calls();
2186 EXPECT_EQ(recorded_callbacks.size(), 3);
2187 EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 1);
2188
2189 // Release A again
2190 tester.InjectKeyboardChanges(std::vector<KeyboardChange>{
2191 WmKeyUpInfo{kVirtualKeyA, kScanCodeKeyA, kNotExtended}.Build(
2192 kWmResultZero)});
2193
2194 EXPECT_EQ(tester.key_calls.size(), 0);
2195 EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 0);
2196 }

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

## ◆ TEST_F() [98/163]

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

Definition at line 1764 of file keyboard_unittests.cc.

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

References EXPECT_CALL_IS_EVENT.

## ◆ TEST_F() [99/163]

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

Definition at line 2198 of file keyboard_unittests.cc.

2198 {
2199 KeyboardTester tester{GetContext()};
2200 tester.Responding(false);
2201
2202 // US Keyboard layout
2203
2204 tester.InjectPlatformMessage(
2205 "flutter/textinput", "TextInput.setClient",
2206 R"|([108, {"inputAction": "TextInputAction.none", "viewId": 0}])|");
2207
2208 // Press Enter
2209 tester.InjectKeyboardChanges(std::vector<KeyboardChange>{
2210 WmKeyDownInfo{VK_RETURN, kScanCodeEnter, kNotExtended, kWasUp}.Build(
2211 kWmResultZero),
2212 WmCharInfo{'\n', kScanCodeEnter, kNotExtended, kWasUp}.Build(
2213 kWmResultZero)});
2214
2215 EXPECT_EQ(tester.key_calls.size(), 2);
2216 EXPECT_CALL_IS_EVENT(tester.key_calls[0], kFlutterKeyEventTypeDown,
2217 kPhysicalEnter, kLogicalEnter, "", kNotSynthesized);
2218 EXPECT_CALL_IS_TEXT_METHOD_CALL(
2219 tester.key_calls[1],
2220 "{"
2221 R"|("method":"TextInputClient.performAction",)|"
2222 R"|("args":[108,"TextInputAction.none"])|"
2223 "}");
2224 tester.clear_key_calls();
2225 EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 2);
2226
2227 // Release Enter
2228 tester.InjectKeyboardChanges(std::vector<KeyboardChange>{
2229 WmKeyUpInfo{VK_RETURN, kScanCodeEnter, kNotExtended}.Build(
2230 kWmResultZero)});
2231
2232 EXPECT_EQ(tester.key_calls.size(), 1);
2233 EXPECT_CALL_IS_EVENT(tester.key_calls[0], kFlutterKeyEventTypeUp,
2234 kPhysicalEnter, kLogicalEnter, "", kNotSynthesized);
2235 tester.clear_key_calls();
2236 EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 1);
2237
2238 // Make sure OnText is not obstructed after pressing Enter.
2239 //
2240 // Regression test for https://github.com/flutter/flutter/issues/97706.
2241
2242 // Press A
2243 tester.InjectKeyboardChanges(std::vector<KeyboardChange>{
2244 WmKeyDownInfo{kVirtualKeyA, kScanCodeKeyA, kNotExtended, kWasUp}.Build(
2245 kWmResultZero),
2246 WmCharInfo{'a', kScanCodeKeyA, kNotExtended, kWasUp}.Build(
2247 kWmResultZero)});
2248
2249 EXPECT_EQ(tester.key_calls.size(), 2);
2250 EXPECT_CALL_IS_EVENT(tester.key_calls[0], kFlutterKeyEventTypeDown,
2251 kPhysicalKeyA, kLogicalKeyA, "a", kNotSynthesized);
2252 EXPECT_CALL_IS_TEXT(tester.key_calls[1], u"a");
2253 tester.clear_key_calls();
2254
2255 // Release A
2256 tester.InjectKeyboardChanges(std::vector<KeyboardChange>{
2257 WmKeyUpInfo{kVirtualKeyA, kScanCodeKeyA, kNotExtended}.Build(
2258 kWmResultZero)});
2259
2260 EXPECT_EQ(tester.key_calls.size(), 1);
2261 EXPECT_CALL_IS_EVENT(tester.key_calls[0], kFlutterKeyEventTypeUp,
2262 kPhysicalKeyA, kLogicalKeyA, "", kNotSynthesized);
2263 tester.clear_key_calls();
2264 }
EXPECT_CALL_IS_TEXT_METHOD_CALL
#define EXPECT_CALL_IS_TEXT_METHOD_CALL(_key_call, json_string)
Definition: keyboard_unittests.cc:564

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

## ◆ TEST_F() [100/163]

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

Definition at line 2020 of file keyboard_unittests.cc.

2020 {
2021 KeyboardTester tester{GetContext()};
2022 tester.Responding(true);
2023
2024 // US Keyboard layout.
2025
2026 // Press CtrlRight in IME mode.
2027 tester.InjectKeyboardChanges(std::vector<KeyboardChange>{
2028 KeyStateChange{VK_LSHIFT, true, false},
2029 WmKeyDownInfo{VK_SHIFT, kScanCodeShiftLeft, kNotExtended, kWasUp}.Build(
2030 kWmResultZero),
2031 WmKeyDownInfo{VK_PROCESSKEY, kScanCodeDigit2, kNotExtended, kWasUp}.Build(
2032 kWmResultZero),
2033 KeyStateChange{VK_LSHIFT, false, true},
2034 WmKeyUpInfo{VK_PROCESSKEY, kScanCodeShiftLeft, kNotExtended}.Build(
2035 kWmResultZero),
2036 WmKeyUpInfo{'2', kScanCodeDigit2, kNotExtended, kWasUp}.Build(
2037 kWmResultZero)});
2038
2039 EXPECT_EQ(tester.key_calls.size(), 4);
2040 EXPECT_CALL_IS_EVENT(tester.key_calls[0], kFlutterKeyEventTypeDown,
2041 kPhysicalShiftLeft, kLogicalShiftLeft, "",
2042 kNotSynthesized);
2043 EXPECT_CALL_IS_EVENT(tester.key_calls[1], kFlutterKeyEventTypeDown, 0, 0, "",
2044 kNotSynthesized);
2045 EXPECT_CALL_IS_EVENT(tester.key_calls[2], kFlutterKeyEventTypeUp,
2046 kPhysicalShiftLeft, kLogicalShiftLeft, "",
2047 kNotSynthesized);
2048 EXPECT_CALL_IS_EVENT(tester.key_calls[3], kFlutterKeyEventTypeDown, 0, 0, "",
2049 kNotSynthesized);
2050 tester.clear_key_calls();
2051 }

References EXPECT_CALL_IS_EVENT, and flutter::kScanCodeShiftLeft.

## ◆ TEST_F() [101/163]

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

Definition at line 2266 of file keyboard_unittests.cc.

2266 {
2267 // In this test, the user presses the folloing keys:
2268 //
2269 // Key Current text
2270 // ===========================
2271 // A a
2272 // F à
2273 //
2274 // And the Backspace event is responded immediately.
2275
2276 KeyboardTester tester{GetContext()};
2277 tester.Responding(false);
2278
2279 // US Keyboard layout
2280
2281 // Press A
2282 tester.InjectKeyboardChanges(std::vector<KeyboardChange>{
2283 WmKeyDownInfo{kVirtualKeyA, kScanCodeKeyA, kNotExtended, kWasUp}.Build(
2284 kWmResultZero),
2285 WmCharInfo{'a', kScanCodeKeyA, kNotExtended, kWasUp}.Build(
2286 kWmResultZero)});
2287
2288 EXPECT_EQ(tester.key_calls.size(), 2);
2289 EXPECT_CALL_IS_EVENT(tester.key_calls[0], kFlutterKeyEventTypeDown,
2290 kPhysicalKeyA, kLogicalKeyA, "a", kNotSynthesized);
2291 EXPECT_CALL_IS_TEXT(tester.key_calls[1], u"a");
2292 tester.clear_key_calls();
2293 EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 2);
2294
2295 // Release A
2296 tester.InjectKeyboardChanges(std::vector<KeyboardChange>{
2297 WmKeyUpInfo{kVirtualKeyA, kScanCodeKeyA, kNotExtended}.Build(
2298 kWmResultZero)});
2299
2300 EXPECT_EQ(tester.key_calls.size(), 1);
2301 EXPECT_CALL_IS_EVENT(tester.key_calls[0], kFlutterKeyEventTypeUp,
2302 kPhysicalKeyA, kLogicalKeyA, "", kNotSynthesized);
2303 tester.clear_key_calls();
2304 EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 1);
2305
2306 // Press F, which is translated to:
2307 //
2308 // Backspace down, char & up, then VK_PACKET('à').
2309 tester.InjectKeyboardChanges(std::vector<KeyboardChange>{
2310 WmKeyDownInfo{VK_BACK, kScanCodeBackspace, kNotExtended, kWasUp}.Build(
2311 kWmResultZero),
2312 WmCharInfo{0x8, kScanCodeBackspace, kNotExtended, kWasUp}.Build(
2313 kWmResultZero),
2314 WmKeyUpInfo{VK_BACK, kScanCodeBackspace, kNotExtended}.Build(
2315 kWmResultZero),
2316 WmKeyDownInfo{VK_PACKET, 0, kNotExtended, kWasUp}.Build(kWmResultDefault),
2317 WmCharInfo{0xe0 /*'à'*/, 0, kNotExtended, kWasUp}.Build(kWmResultZero),
2318 WmKeyUpInfo{VK_PACKET, 0, kNotExtended}.Build(kWmResultDefault)});
2319
2320 EXPECT_EQ(tester.key_calls.size(), 3);
2321 EXPECT_CALL_IS_EVENT(tester.key_calls[0], kFlutterKeyEventTypeDown,
2322 kPhysicalBackspace, kLogicalBackspace, "",
2323 kNotSynthesized);
2324 EXPECT_CALL_IS_EVENT(tester.key_calls[1], kFlutterKeyEventTypeUp,
2325 kPhysicalBackspace, kLogicalBackspace, "",
2326 kNotSynthesized);
2327 EXPECT_CALL_IS_TEXT(tester.key_calls[2], u"à");
2328 tester.clear_key_calls();
2329 // TODO(dkwingsmt): This count should probably be 4. Currently the CHAR 0x8
2330 // message is redispatched due to being part of the KeyDown session, which is
2331 // not handled by the framework, while the 'à' message is not redispatched
2332 // for being a standalone message. We should resolve this inconsistency.
2333 // https://github.com/flutter/flutter/issues/98306
2334 EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 3);
2335
2336 // Release F
2337 tester.InjectKeyboardChanges(std::vector<KeyboardChange>{
2338 WmKeyUpInfo{kVirtualKeyF, kScanCodeKeyF, kNotExtended,
2339 /* overwrite_prev_state_0 */ true}
2340 .Build(kWmResultZero)});
2341
2342 EXPECT_EQ(tester.key_calls.size(), 1);
2343 EXPECT_CALL_IS_EVENT(tester.key_calls[0], kFlutterKeyEventTypeDown, 0, 0, "",
2344 kNotSynthesized);
2345 tester.clear_key_calls();
2346 EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 0);
2347 }

References EXPECT_CALL_IS_EVENT, EXPECT_CALL_IS_TEXT, kScanCodeKeyA, and kVirtualKeyA.

## ◆ TEST_F() [102/163]

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

Definition at line 2456 of file keyboard_unittests.cc.

2456 {
2457 VietnameseTelexAddDiacriticWithSlowResponse(GetContext(), false);
2458 }
flutter::testing::VietnameseTelexAddDiacriticWithSlowResponse
void VietnameseTelexAddDiacriticWithSlowResponse(WindowsTestContext &context, bool backspace_response)
Definition: keyboard_unittests.cc:2349

References VietnameseTelexAddDiacriticWithSlowResponse().

## ◆ TEST_F() [103/163]

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

Definition at line 2460 of file keyboard_unittests.cc.

2460 {
2461 VietnameseTelexAddDiacriticWithSlowResponse(GetContext(), true);
2462 }

References VietnameseTelexAddDiacriticWithSlowResponse().

## ◆ TEST_F() [104/163]

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

Definition at line 267 of file platform_handler_unittests.cc.

267 {
268 UseEngineWithView();
269
270 TestBinaryMessenger messenger;
271 PlatformHandler platform_handler(&messenger, engine(), []() {
272 auto clipboard = std::make_unique<MockScopedClipboard>();
273
274 EXPECT_CALL(*clipboard.get(), Open)
275 .Times(1)
276 .WillOnce(Return(kErrorSuccess));
277 EXPECT_CALL(*clipboard.get(), HasString).Times(1).WillOnce(Return(true));
278
279 return clipboard;
280 });
281
282 std::string result =
283 SimulatePlatformMessage(&messenger, kClipboardHasStringsMessage);
284
285 EXPECT_EQ(result, "[{\"value\":true}]");
286 }
kErrorSuccess
static constexpr int kErrorSuccess
Definition: platform_handler.cc:45

References kErrorSuccess.

## ◆ TEST_F() [105/163]

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

Definition at line 336 of file platform_handler_unittests.cc.

336 {
337 UseEngineWithView();
338
339 TestBinaryMessenger messenger;
340 PlatformHandler platform_handler(&messenger, engine(), []() {
341 auto clipboard = std::make_unique<MockScopedClipboard>();
342
343 EXPECT_CALL(*clipboard.get(), Open)
344 .Times(1)
345 .WillOnce(Return(kAccessDeniedErrorCode));
346
347 return clipboard;
348 });
349
350 std::string result =
351 SimulatePlatformMessage(&messenger, kClipboardHasStringsMessage);
352
353 EXPECT_EQ(result, "[{\"value\":false}]");
354 }
kAccessDeniedErrorCode
static constexpr int kAccessDeniedErrorCode
Definition: platform_handler.cc:44

References kAccessDeniedErrorCode.

## ◆ TEST_F() [106/163]

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

Definition at line 309 of file platform_handler_unittests.cc.

309 {
310 UseEngineWithView();
311
312 TestBinaryMessenger messenger;
313 PlatformHandler platform_handler(&messenger, engine());
314
315 std::string result = SimulatePlatformMessage(
316 &messenger, kClipboardHasStringsFakeContentTypeMessage);
317
318 EXPECT_EQ(result, "[\"Clipboard error\",\"Unknown clipboard format\",null]");
319 }

## ◆ TEST_F() [107/163]

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

Definition at line 356 of file platform_handler_unittests.cc.

356 {
357 UseEngineWithView();
358
359 TestBinaryMessenger messenger;
360 PlatformHandler platform_handler(&messenger, engine(), []() {
361 auto clipboard = std::make_unique<MockScopedClipboard>();
362
363 EXPECT_CALL(*clipboard.get(), Open)
364 .Times(1)
365 .WillOnce(Return(kArbitraryErrorCode));
366
367 return clipboard;
368 });
369
370 std::string result =
371 SimulatePlatformMessage(&messenger, kClipboardHasStringsMessage);
372
373 EXPECT_EQ(result, "[\"Clipboard error\",\"Unable to open clipboard\",1]");
374 }

## ◆ TEST_F() [108/163]

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

Definition at line 321 of file platform_handler_unittests.cc.

321 {
322 UseHeadlessEngine();
323
324 TestBinaryMessenger messenger;
325 PlatformHandler platform_handler(&messenger, engine());
326
327 std::string result =
328 SimulatePlatformMessage(&messenger, kClipboardHasStringsMessage);
329
330 EXPECT_EQ(result,
331 "[\"Clipboard error\",\"Clipboard is not available in Windows "
332 "headless mode\",null]");
333 }

## ◆ TEST_F() [109/163]

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

Definition at line 288 of file platform_handler_unittests.cc.

288 {
289 UseEngineWithView();
290
291 TestBinaryMessenger messenger;
292 PlatformHandler platform_handler(&messenger, engine(), []() {
293 auto clipboard = std::make_unique<MockScopedClipboard>();
294
295 EXPECT_CALL(*clipboard.get(), Open)
296 .Times(1)
297 .WillOnce(Return(kErrorSuccess));
298 EXPECT_CALL(*clipboard.get(), HasString).Times(1).WillOnce(Return(false));
299
300 return clipboard;
301 });
302
303 std::string result =
304 SimulatePlatformMessage(&messenger, kClipboardHasStringsMessage);
305
306 EXPECT_EQ(result, "[{\"value\":false}]");
307 }

References kErrorSuccess.

## ◆ TEST_F() [110/163]

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

Definition at line 376 of file platform_handler_unittests.cc.

376 {
377 UseEngineWithView();
378
379 TestBinaryMessenger messenger;
380 PlatformHandler platform_handler(&messenger, engine(), []() {
381 auto clipboard = std::make_unique<MockScopedClipboard>();
382
383 EXPECT_CALL(*clipboard.get(), Open)
384 .Times(1)
385 .WillOnce(Return(kErrorSuccess));
386 EXPECT_CALL(*clipboard.get(), SetString)
387 .Times(1)
388 .WillOnce([](std::wstring string) {
389 EXPECT_EQ(string, L"hello");
390 return kErrorSuccess;
391 });
392
393 return clipboard;
394 });
395
396 std::string result =
397 SimulatePlatformMessage(&messenger, kClipboardSetDataMessage);
398
399 EXPECT_EQ(result, "[null]");
400 }

References kErrorSuccess.

## ◆ TEST_F() [111/163]

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

Definition at line 441 of file platform_handler_unittests.cc.

441 {
442 UseEngineWithView();
443
444 TestBinaryMessenger messenger;
445 PlatformHandler platform_handler(&messenger, engine(), []() {
446 auto clipboard = std::make_unique<MockScopedClipboard>();
447
448 EXPECT_CALL(*clipboard.get(), Open)
449 .Times(1)
450 .WillOnce(Return(kArbitraryErrorCode));
451
452 return clipboard;
453 });
454
455 std::string result =
456 SimulatePlatformMessage(&messenger, kClipboardSetDataMessage);
457
458 EXPECT_EQ(result, "[\"Clipboard error\",\"Unable to open clipboard\",1]");
459 }

## ◆ TEST_F() [112/163]

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

Definition at line 461 of file platform_handler_unittests.cc.

461 {
462 UseEngineWithView();
463
464 TestBinaryMessenger messenger;
465 PlatformHandler platform_handler(&messenger, engine(), []() {
466 auto clipboard = std::make_unique<MockScopedClipboard>();
467
468 EXPECT_CALL(*clipboard.get(), Open)
469 .Times(1)
470 .WillOnce(Return(kErrorSuccess));
471 EXPECT_CALL(*clipboard.get(), SetString)
472 .Times(1)
473 .WillOnce(Return(kArbitraryErrorCode));
474
475 return clipboard;
476 });
477
478 std::string result =
479 SimulatePlatformMessage(&messenger, kClipboardSetDataMessage);
480
481 EXPECT_EQ(result, "[\"Clipboard error\",\"Unable to set clipboard data\",1]");
482 }

References kErrorSuccess.

## ◆ TEST_F() [113/163]

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

Definition at line 427 of file platform_handler_unittests.cc.

427 {
428 UseHeadlessEngine();
429
430 TestBinaryMessenger messenger;
431 PlatformHandler platform_handler(&messenger, engine());
432
433 std::string result =
434 SimulatePlatformMessage(&messenger, kClipboardSetDataMessage);
435
436 EXPECT_EQ(result,
437 "[\"Clipboard error\",\"Clipboard is not available in Windows "
438 "headless mode\",null]");
439 }

## ◆ TEST_F() [114/163]

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

Definition at line 403 of file platform_handler_unittests.cc.

403 {
404 UseEngineWithView();
405
406 TestBinaryMessenger messenger;
407 PlatformHandler platform_handler(&messenger, engine());
408
409 std::string result =
410 SimulatePlatformMessage(&messenger, kClipboardSetDataNullTextMessage);
411
412 EXPECT_EQ(result, "[\"Clipboard error\",\"Unknown clipboard format\",null]");
413 }

## ◆ TEST_F() [115/163]

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

Definition at line 415 of file platform_handler_unittests.cc.

415 {
416 UseEngineWithView();
417
418 TestBinaryMessenger messenger;
419 PlatformHandler platform_handler(&messenger, engine());
420
421 std::string result =
422 SimulatePlatformMessage(&messenger, kClipboardSetDataUnknownTypeMessage);
423
424 EXPECT_EQ(result, "[\"Clipboard error\",\"Unknown clipboard format\",null]");
425 }

## ◆ TEST_F() [116/163]

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

Definition at line 172 of file platform_handler_unittests.cc.

172 {
173 UseEngineWithView();
174
175 TestBinaryMessenger messenger;
176 PlatformHandler platform_handler(&messenger, engine(), []() {
177 auto clipboard = std::make_unique<MockScopedClipboard>();
178
179 EXPECT_CALL(*clipboard.get(), Open)
180 .Times(1)
181 .WillOnce(Return(kErrorSuccess));
182 EXPECT_CALL(*clipboard.get(), HasString).Times(1).WillOnce(Return(true));
183 EXPECT_CALL(*clipboard.get(), GetString)
184 .Times(1)
185 .WillOnce(Return(std::wstring(L"Hello world")));
186
187 return clipboard;
188 });
189
190 std::string result =
191 SimulatePlatformMessage(&messenger, kClipboardGetDataMessage);
192
193 EXPECT_EQ(result, "[{\"text\":\"Hello world\"}]");
194 }

References kErrorSuccess.

## ◆ TEST_F() [117/163]

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

Definition at line 196 of file platform_handler_unittests.cc.

196 {
197 UseEngineWithView();
198
199 TestBinaryMessenger messenger;
200 PlatformHandler platform_handler(&messenger, engine());
201
202 // Requesting an unknown content type is an error.
203 std::string result = SimulatePlatformMessage(
204 &messenger, kClipboardGetDataFakeContentTypeMessage);
205
206 EXPECT_EQ(result, "[\"Clipboard error\",\"Unknown clipboard format\",null]");
207 }

## ◆ TEST_F() [118/163]

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

Definition at line 243 of file platform_handler_unittests.cc.

243 {
244 UseEngineWithView();
245
246 TestBinaryMessenger messenger;
247 PlatformHandler platform_handler(&messenger, engine(), []() {
248 auto clipboard = std::make_unique<MockScopedClipboard>();
249
250 EXPECT_CALL(*clipboard.get(), Open)
251 .Times(1)
252 .WillOnce(Return(kErrorSuccess));
253 EXPECT_CALL(*clipboard.get(), HasString).Times(1).WillOnce(Return(true));
254 EXPECT_CALL(*clipboard.get(), GetString)
255 .Times(1)
256 .WillOnce(Return(kArbitraryErrorCode));
257
258 return clipboard;
259 });
260
261 std::string result =
262 SimulatePlatformMessage(&messenger, kClipboardGetDataMessage);
263
264 EXPECT_EQ(result, "[\"Clipboard error\",\"Unable to get clipboard data\",1]");
265 }

References kErrorSuccess.

## ◆ TEST_F() [119/163]

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

Definition at line 223 of file platform_handler_unittests.cc.

223 {
224 UseEngineWithView();
225
226 TestBinaryMessenger messenger;
227 PlatformHandler platform_handler(&messenger, engine(), []() {
228 auto clipboard = std::make_unique<MockScopedClipboard>();
229
230 EXPECT_CALL(*clipboard.get(), Open)
231 .Times(1)
232 .WillOnce(Return(kArbitraryErrorCode));
233
234 return clipboard;
235 });
236
237 std::string result =
238 SimulatePlatformMessage(&messenger, kClipboardGetDataMessage);
239
240 EXPECT_EQ(result, "[\"Clipboard error\",\"Unable to open clipboard\",1]");
241 }

## ◆ TEST_F() [120/163]

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

Definition at line 209 of file platform_handler_unittests.cc.

209 {
210 UseHeadlessEngine();
211
212 TestBinaryMessenger messenger;
213 PlatformHandler platform_handler(&messenger, engine());
214
215 std::string result =
216 SimulatePlatformMessage(&messenger, kClipboardGetDataMessage);
217
218 EXPECT_EQ(result,
219 "[\"Clipboard error\",\"Clipboard is not available in "
220 "Windows headless mode\",null]");
221 }

## ◆ TEST_F() [121/163]

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

Definition at line 484 of file platform_handler_unittests.cc.

484 {
485 UseHeadlessEngine();
486
487 TestBinaryMessenger messenger;
488 MockPlatformHandler platform_handler(&messenger, engine());
489
490 EXPECT_CALL(platform_handler, SystemSoundPlay("SystemSoundType.alert", _))
491 .WillOnce([](const std::string& sound,
492 std::unique_ptr<MethodResult<rapidjson::Document>> result) {
493 result->Success();
494 });
495
496 std::string result =
497 SimulatePlatformMessage(&messenger, kSystemSoundTypeAlertMessage);
498
499 EXPECT_EQ(result, "[null]");
500 }

## ◆ TEST_F() [122/163]

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

Definition at line 524 of file platform_handler_unittests.cc.

524 {
525 UseHeadlessEngine();
526 bool called_cancel = false;
527
528 TestBinaryMessenger messenger(
529 [&called_cancel](const std::string& channel, const uint8_t* message,
530 size_t size, BinaryReply reply) {
531 reply(reinterpret_cast<const uint8_t*>(kExitResponseCancelMessage),
532 sizeof(kExitResponseCancelMessage));
533 called_cancel = true;
534 });
535 MockPlatformHandler platform_handler(&messenger, engine());
536
537 EXPECT_CALL(platform_handler, QuitApplication).Times(0);
538
539 std::string result = SimulatePlatformMessage(
540 &messenger, kSystemExitApplicationCancelableMessage);
541 EXPECT_EQ(result, "[{\"response\":\"cancel\"}]");
542 EXPECT_TRUE(called_cancel);
543 }

References message.

## ◆ TEST_F() [123/163]

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

Definition at line 545 of file platform_handler_unittests.cc.

545 {
546 UseHeadlessEngine();
547 bool called_cancel = false;
548 UINT exit_code = 0;
549
550 TestBinaryMessenger messenger(
551 [&called_cancel](const std::string& channel, const uint8_t* message,
552 size_t size, BinaryReply reply) {
553 reply(reinterpret_cast<const uint8_t*>(kExitResponseExitMessage),
554 sizeof(kExitResponseExitMessage));
555 called_cancel = true;
556 });
557 MockPlatformHandler platform_handler(&messenger, engine());
558
559 ON_CALL(platform_handler, QuitApplication)
560 .WillByDefault([&exit_code](std::optional<HWND> hwnd,
561 std::optional<WPARAM> wparam,
562 std::optional<LPARAM> lparam,
563 UINT ec) { exit_code = ec; });
564 EXPECT_CALL(platform_handler, QuitApplication).Times(1);
565
566 std::string result = SimulatePlatformMessage(
567 &messenger, kSystemExitApplicationCancelableMessage);
568 EXPECT_EQ(result, "[{\"response\":\"cancel\"}]");
569 EXPECT_TRUE(called_cancel);
570 EXPECT_EQ(exit_code, 2);
571 }

References message.

## ◆ TEST_F() [124/163]

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

Definition at line 502 of file platform_handler_unittests.cc.

502 {
503 UseHeadlessEngine();
504 UINT exit_code = 0;
505
506 TestBinaryMessenger messenger([](const std::string& channel,
507 const uint8_t* message, size_t size,
508 BinaryReply reply) {});
509 MockPlatformHandler platform_handler(&messenger, engine());
510
511 ON_CALL(platform_handler, QuitApplication)
512 .WillByDefault([&exit_code](std::optional<HWND> hwnd,
513 std::optional<WPARAM> wparam,
514 std::optional<LPARAM> lparam,
515 UINT ec) { exit_code = ec; });
516 EXPECT_CALL(platform_handler, QuitApplication).Times(1);
517
518 std::string result = SimulatePlatformMessage(
519 &messenger, kSystemExitApplicationRequiredMessage);
520 EXPECT_EQ(result, "[{\"response\":\"exit\"}]");
521 EXPECT_EQ(exit_code, 1);
522 }

References message.

## ◆ TEST_F() [125/163]

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

Definition at line 240 of file text_input_plugin_unittest.cc.

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

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

## ◆ TEST_F() [126/163]

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

Definition at line 219 of file text_input_plugin_unittest.cc.

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

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

## ◆ TEST_F() [127/163]

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

Definition at line 554 of file text_input_plugin_unittest.cc.

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

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

Definition at line 724 of file text_input_plugin_unittest.cc.

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

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

## ◆ TEST_F() [129/163]

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

Definition at line 430 of file text_input_plugin_unittest.cc.

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

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

## ◆ TEST_F() [130/163]

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

Definition at line 462 of file text_input_plugin_unittest.cc.

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

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

## ◆ TEST_F() [131/163]

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

Definition at line 687 of file text_input_plugin_unittest.cc.

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

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

## ◆ TEST_F() [132/163]

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

Definition at line 495 of file text_input_plugin_unittest.cc.

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

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

Definition at line 194 of file text_input_plugin_unittest.cc.

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

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

## ◆ TEST_F() [134/163]

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

Definition at line 614 of file text_input_plugin_unittest.cc.

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

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

## ◆ TEST_F() [135/163]

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

Definition at line 268 of file text_input_plugin_unittest.cc.

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

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

## ◆ TEST_F() [136/163]

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

Definition at line 325 of file text_input_plugin_unittest.cc.

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

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

## ◆ TEST_F() [137/163]

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

Definition at line 383 of file text_input_plugin_unittest.cc.

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

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

## ◆ TEST_F() [138/163]

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

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

Definition at line 609 of file flutter_windows_unittests.cc.

609 {
610 std::mutex mutex;
611 std::string view_ids;
612
613 auto& context = GetContext();
614 WindowsConfigBuilder builder(context);
615 builder.SetDartEntrypoint("onMetricsChangedSignalViewIds");
616
617 fml::AutoResetWaitableEvent ready_latch;
618 context.AddNativeFunction(
619 "Signal", CREATE_NATIVE_ENTRY(
620 [&](Dart_NativeArguments args) { ready_latch.Signal(); }));
621
622 context.AddNativeFunction(
623 "SignalStringValue", CREATE_NATIVE_ENTRY([&](Dart_NativeArguments args) {
624 auto handle = Dart_GetNativeArgument(args, 0);
625 ASSERT_FALSE(Dart_IsError(handle));
626
627 std::scoped_lock lock{mutex};
628 view_ids = tonic::DartConverter<std::string>::FromDart(handle);
629 }));
630
631 // Create the implicit view.
632 ViewControllerPtr first_controller{builder.Run()};
633 ASSERT_NE(first_controller, nullptr);
634
635 ready_latch.Wait();
636
637 // Create a second view.
638 FlutterDesktopEngineRef engine =
639 FlutterDesktopViewControllerGetEngine(first_controller.get());
640 FlutterDesktopViewControllerProperties properties = {};
641 properties.width = 100;
642 properties.height = 100;
643 ViewControllerPtr second_controller{
644 FlutterDesktopEngineCreateViewController(engine, &properties)};
645 ASSERT_NE(second_controller, nullptr);
646
647 // Pump messages for the Windows platform task runner until the view is added.
648 while (true) {
649 PumpMessage();
650 std::scoped_lock lock{mutex};
651 if (view_ids == "View IDs: [0, 1]") {
652 break;
653 }
654 }
655
656 // Delete the second view and pump messages for the Windows platform task
657 // runner until the view is removed.
658 second_controller.reset();
659 while (true) {
660 PumpMessage();
661 std::scoped_lock lock{mutex};
662 if (view_ids == "View IDs: [0]") {
663 break;
664 }
665 }
666 }
FlutterDesktopEngineCreateViewController
FlutterDesktopViewControllerRef FlutterDesktopEngineCreateViewController(FlutterDesktopEngineRef engine, const FlutterDesktopViewControllerProperties *properties)
Definition: flutter_windows.cc:128
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() [140/163]

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

Definition at line 152 of file flutter_windows_unittests.cc.

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

References FlutterDesktopEngineCreateViewController().

## ◆ TEST_F() [141/163]

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

Definition at line 668 of file flutter_windows_unittests.cc.

668 {
669 auto& context = GetContext();
670 WindowsConfigBuilder builder(context);
671 builder.SetDartEntrypoint("testEngineId");
672
673 fml::AutoResetWaitableEvent latch;
674 std::optional<int64_t> engineId;
675 context.AddNativeFunction(
676 "NotifyEngineId", CREATE_NATIVE_ENTRY([&](Dart_NativeArguments args) {
677 const auto argument = Dart_GetNativeArgument(args, 0);
678 if (!Dart_IsNull(argument)) {
679 const auto handle = tonic::DartConverter<int64_t>::FromDart(argument);
680 engineId = handle;
681 }
682 latch.Signal();
683 }));
684 // Create the implicit view.
685 ViewControllerPtr first_controller{builder.Run()};
686 ASSERT_NE(first_controller, nullptr);
687
688 latch.Wait();
689 EXPECT_TRUE(engineId.has_value());
690 if (!engineId.has_value()) {
691 return;
692 }
693 auto engine = FlutterDesktopViewControllerGetEngine(first_controller.get());
694 EXPECT_EQ(engine, FlutterDesktopEngineForId(*engineId));
695 }
FlutterDesktopEngineForId
FLUTTER_EXPORT FlutterDesktopEngineRef FlutterDesktopEngineForId(int64_t engine_id)
Definition: flutter_windows.cc:200

References FlutterDesktopEngineForId(), and FlutterDesktopViewControllerGetEngine().

## ◆ TEST_F() [142/163]

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

Definition at line 411 of file flutter_windows_unittests.cc.

411 {
412 auto& context = GetContext();
413 WindowsConfigBuilder builder(context);
414 ViewControllerPtr controller{builder.Run()};
415 ASSERT_NE(controller, nullptr);
416 auto view = FlutterDesktopViewControllerGetView(controller.get());
417
418 Microsoft::WRL::ComPtr<IDXGIAdapter> dxgi_adapter;
419 dxgi_adapter = FlutterDesktopViewGetGraphicsAdapter(view);
420 ASSERT_NE(dxgi_adapter, nullptr);
421 DXGI_ADAPTER_DESC desc{};
422 ASSERT_TRUE(SUCCEEDED(dxgi_adapter->GetDesc(&desc)));
423 }
FlutterDesktopViewGetGraphicsAdapter
IDXGIAdapter * FlutterDesktopViewGetGraphicsAdapter(FlutterDesktopViewRef view)
Definition: flutter_windows.cc:256
FlutterDesktopViewControllerGetView
FlutterDesktopViewRef FlutterDesktopViewControllerGetView(FlutterDesktopViewControllerRef ref)
Definition: flutter_windows.cc:153

References FlutterDesktopViewControllerGetView(), and FlutterDesktopViewGetGraphicsAdapter().

## ◆ TEST_F() [143/163]

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

Definition at line 425 of file flutter_windows_unittests.cc.

425 {
426 std::optional<LUID> luid = egl::Manager::GetLowPowerGpuLuid();
427 if (!luid) {
428 GTEST_SKIP() << "Not able to find low power GPU, nothing to check.";
429 }
430
431 auto& context = GetContext();
432 WindowsConfigBuilder builder(context);
433 builder.SetGpuPreference(FlutterDesktopGpuPreference::LowPowerPreference);
434 ViewControllerPtr controller{builder.Run()};
435 ASSERT_NE(controller, nullptr);
436 auto view = FlutterDesktopViewControllerGetView(controller.get());
437
438 Microsoft::WRL::ComPtr<IDXGIAdapter> dxgi_adapter;
439 dxgi_adapter = FlutterDesktopViewGetGraphicsAdapter(view);
440 ASSERT_NE(dxgi_adapter, nullptr);
441 DXGI_ADAPTER_DESC desc{};
442 ASSERT_TRUE(SUCCEEDED(dxgi_adapter->GetDesc(&desc)));
443 ASSERT_EQ(desc.AdapterLuid.HighPart, luid->HighPart);
444 ASSERT_EQ(desc.AdapterLuid.LowPart, luid->LowPart);
445 }
LowPowerPreference
@ LowPowerPreference
Definition: flutter_windows.h:45

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

## ◆ TEST_F() [144/163]

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

Definition at line 583 of file flutter_windows_unittests.cc.

583 {
584 auto& context = GetContext();
585 WindowsConfigBuilder builder(context);
586 builder.SetDartEntrypoint("sendGetKeyboardState");
587
588 std::atomic<bool> done = false;
589 context.AddNativeFunction(
590 "SignalStringValue", CREATE_NATIVE_ENTRY([&](Dart_NativeArguments args) {
591 auto handle = Dart_GetNativeArgument(args, 0);
592 ASSERT_FALSE(Dart_IsError(handle));
593 auto value = tonic::DartConverter<std::string>::FromDart(handle);
594 EXPECT_EQ(value, "Success");
595 done = true;
596 }));
597
598 ViewControllerPtr controller{builder.Run()};
599 ASSERT_NE(controller, nullptr);
600
601 // Pump messages for the Windows platform task runner.
602 ::MSG msg;
603 while (!done) {
604 PumpMessage();
605 }
606 }

## ◆ TEST_F() [145/163]

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

Definition at line 400 of file flutter_windows_unittests.cc.

400 {
401 auto& context = GetContext();
402 WindowsConfigBuilder builder(context);
403 ViewControllerPtr controller{builder.Run()};
404 ASSERT_NE(controller, nullptr);
405 FlutterDesktopViewId view_id =
406 FlutterDesktopViewControllerGetViewId(controller.get());
407
408 ASSERT_EQ(view_id, static_cast<FlutterDesktopViewId>(kImplicitViewId));
409 }
FlutterDesktopViewControllerGetViewId
FlutterDesktopViewId FlutterDesktopViewControllerGetViewId(FlutterDesktopViewControllerRef ref)
Definition: flutter_windows.cc:141
FlutterDesktopViewId
int64_t FlutterDesktopViewId
Definition: flutter_windows.h:36

References FlutterDesktopViewControllerGetViewId(), and flutter::kImplicitViewId.

## ◆ TEST_F() [146/163]

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

Definition at line 201 of file flutter_windows_unittests.cc.

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

References FlutterDesktopEngineRun().

## ◆ TEST_F() [147/163]

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

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

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 fml::AutoResetWaitableEvent latch;
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 latch.Signal();
141 }));
142
143 ViewControllerPtr controller{builder.Run()};
144 ASSERT_NE(controller, nullptr);
145
146 // Verify a headless app has the implicit view.
147 latch.Wait();
148 EXPECT_EQ(view_ids, "View IDs: [0]");
149 }

## ◆ TEST_F() [150/163]

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

Definition at line 76 of file flutter_windows_unittests.cc.

76 {
77 auto& context = GetContext();
78 WindowsConfigBuilder builder(context);
79 ViewControllerPtr controller{builder.Run()};
80 ASSERT_NE(controller, nullptr);
81 }

## ◆ TEST_F() [151/163]

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

Definition at line 84 of file flutter_windows_unittests.cc.

84 {
85 // Replace stdout & stderr stream buffers with our own.
86 StreamCapture stdout_capture(&std::cout);
87 StreamCapture stderr_capture(&std::cerr);
88
89 auto& context = GetContext();
90 WindowsConfigBuilder builder(context);
91 ViewControllerPtr controller{builder.Run()};
92 ASSERT_NE(controller, nullptr);
93
94 stdout_capture.Stop();
95 stderr_capture.Stop();
96
97 // Verify stdout & stderr have no output.
98 EXPECT_TRUE(stdout_capture.GetOutput().empty());
99 EXPECT_TRUE(stderr_capture.GetOutput().empty());
100 }

## ◆ TEST_F() [152/163]

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

Definition at line 176 of file flutter_windows_unittests.cc.

176 {
177 auto& context = GetContext();
178 WindowsConfigBuilder builder(context);
179 EnginePtr engine{builder.InitializeEngine()};
180 EngineModifier modifier{
181 reinterpret_cast<FlutterWindowsEngine*>(engine.get())};
182
183 auto called = false;
184 modifier.embedder_api().UpdateAccessibilityFeatures = MOCK_ENGINE_PROC(
185 UpdateAccessibilityFeatures, ([&called](auto engine, auto flags) {
186 called = true;
187 return kSuccess;
188 }));
189
190 ViewControllerPtr controller{
191 FlutterDesktopViewControllerCreate(0, 0, engine.release())};
192
193 ASSERT_TRUE(called);
194 }
FlutterDesktopViewControllerCreate
FlutterDesktopViewControllerRef FlutterDesktopViewControllerCreate(int width, int height, FlutterDesktopEngineRef engine)
Definition: flutter_windows.cc:121

References FlutterDesktopViewControllerCreate(), and flutter::FlutterWindowsEngine::UpdateAccessibilityFeatures().

## ◆ TEST_F() [153/163]

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

Definition at line 525 of file flutter_windows_unittests.cc.

525 {
526 auto& context = GetContext();
527 WindowsConfigBuilder builder(context);
528 EnginePtr engine{builder.InitializeEngine()};
529 auto windows_engine = reinterpret_cast<FlutterWindowsEngine*>(engine.get());
530 EngineModifier modifier{windows_engine};
531
532 auto lifecycle_manager =
533 std::make_unique<MockWindowsLifecycleManager>(windows_engine);
534 auto lifecycle_manager_ptr = lifecycle_manager.get();
535 modifier.SetLifecycleManager(std::move(lifecycle_manager));
536
537 EXPECT_CALL(*lifecycle_manager_ptr,
538 SetLifecycleState(AppLifecycleState::kInactive))
539 .WillOnce([lifecycle_manager_ptr](AppLifecycleState state) {
540 lifecycle_manager_ptr->WindowsLifecycleManager::SetLifecycleState(
541 state);
542 });
543
544 EXPECT_CALL(*lifecycle_manager_ptr,
545 SetLifecycleState(AppLifecycleState::kHidden))
546 .WillOnce([lifecycle_manager_ptr](AppLifecycleState state) {
547 lifecycle_manager_ptr->WindowsLifecycleManager::SetLifecycleState(
548 state);
549 });
550
551 FlutterDesktopViewControllerProperties properties = {0, 0};
552
553 // Create a controller. This launches the engine and sets the app lifecycle
554 // to the "resumed" state.
555 ViewControllerPtr controller{
556 FlutterDesktopEngineCreateViewController(engine.get(), &properties)};
557
558 FlutterDesktopViewRef view =
559 FlutterDesktopViewControllerGetView(controller.get());
560 ASSERT_NE(view, nullptr);
561
562 HWND hwnd = FlutterDesktopViewGetHWND(view);
563 ASSERT_NE(hwnd, nullptr);
564
565 // Give the window a non-zero size to show it. This does not change the app
566 // lifecycle directly. However, destroying the view will now result in a
567 // "hidden" app lifecycle event.
568 ::MoveWindow(hwnd, /* X */ 0, /* Y */ 0, /* nWidth*/ 100, /* nHeight*/ 100,
569 /* bRepaint*/ false);
570
571 while (lifecycle_manager_ptr->IsUpdateStateScheduled()) {
572 PumpMessage();
573 }
574
575 // Resets the view, simulating the window being hidden.
576 controller.reset();
577
578 while (lifecycle_manager_ptr->IsUpdateStateScheduled()) {
579 PumpMessage();
580 }
581 }
FlutterDesktopViewGetHWND
HWND FlutterDesktopViewGetHWND(FlutterDesktopViewRef view)
Definition: flutter_windows.cc:252
FlutterDesktopViewRef
struct FlutterDesktopView * FlutterDesktopViewRef
Definition: flutter_windows.h:29

References FlutterDesktopEngineCreateViewController(), FlutterDesktopViewControllerGetView(), FlutterDesktopViewGetHWND(), flutter::kHidden, and flutter::kInactive.

## ◆ TEST_F() [154/163]

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

Definition at line 309 of file flutter_windows_unittests.cc.

309 {
310 struct Captures {
311 fml::AutoResetWaitableEvent frame_scheduled_latch;
312 fml::AutoResetWaitableEvent frame_drawn_latch;
313 std::thread::id thread_id;
314 bool done = false;
315 };
316 Captures captures;
317
318 CreateNewThread("test_platform_thread")->PostTask([&]() {
319 captures.thread_id = std::this_thread::get_id();
320
321 auto& context = GetContext();
322 WindowsConfigBuilder builder(context);
323 builder.SetDartEntrypoint("drawHelloWorld");
324
325 auto native_entry = CREATE_NATIVE_ENTRY([&](Dart_NativeArguments args) {
326 ASSERT_FALSE(captures.frame_drawn_latch.IsSignaledForTest());
327 captures.frame_scheduled_latch.Signal();
328 });
329 context.AddNativeFunction("NotifyFirstFrameScheduled", native_entry);
330
331 ViewControllerPtr controller{builder.Run()};
332 ASSERT_NE(controller, nullptr);
333
334 auto engine = FlutterDesktopViewControllerGetEngine(controller.get());
335
336 FlutterDesktopEngineSetNextFrameCallback(
337 engine,
338 [](void* user_data) {
339 auto captures = static_cast<Captures*>(user_data);
340
341 ASSERT_TRUE(captures->frame_scheduled_latch.IsSignaledForTest());
342
343 // Callback should execute on platform thread.
344 ASSERT_EQ(std::this_thread::get_id(), captures->thread_id);
345
346 // Signal the test passed and end the Windows message loop.
347 captures->done = true;
348 captures->frame_drawn_latch.Signal();
349 },
350 &captures);
351
352 // Pump messages for the Windows platform task runner.
353 while (!captures.done) {
354 PumpMessage();
355 }
356 });
357
358 captures.frame_drawn_latch.Wait();
359 }
FlutterDesktopEngineSetNextFrameCallback
void FlutterDesktopEngineSetNextFrameCallback(FlutterDesktopEngineRef engine, VoidCallback callback, void *user_data)
Definition: flutter_windows.cc:245

References FlutterDesktopEngineSetNextFrameCallback(), FlutterDesktopViewControllerGetEngine(), and user_data.

## ◆ TEST_F() [155/163]

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

Definition at line 254 of file flutter_windows_unittests.cc.

254 {
255 auto& context = GetContext();
256 WindowsConfigBuilder builder(context);
257 builder.SetDartEntrypoint("readPlatformExecutable");
258
259 std::string executable_name;
260 fml::AutoResetWaitableEvent latch;
261 auto native_entry = CREATE_NATIVE_ENTRY([&](Dart_NativeArguments args) {
262 auto handle = Dart_GetNativeArgument(args, 0);
263 ASSERT_FALSE(Dart_IsError(handle));
264 executable_name = tonic::DartConverter<std::string>::FromDart(handle);
265 latch.Signal();
266 });
267 context.AddNativeFunction("SignalStringValue", native_entry);
268
269 ViewControllerPtr controller{builder.Run()};
270 ASSERT_NE(controller, nullptr);
271
272 // Wait until signalStringValue has been called.
273 latch.Wait();
274 EXPECT_EQ(executable_name, "flutter_windows_unittests.exe");
275 }

## ◆ TEST_F() [156/163]

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

Definition at line 448 of file flutter_windows_unittests.cc.

448 {
449 auto& context = GetContext();
450 WindowsConfigBuilder builder(context);
451 ViewControllerPtr controller{builder.Run()};
452 ASSERT_NE(controller, nullptr);
453
454 FlutterDesktopEngineRef engine =
455 FlutterDesktopViewControllerGetEngine(controller.get());
456 FlutterDesktopPluginRegistrarRef registrar =
457 FlutterDesktopEngineGetPluginRegistrar(engine, "foo_bar");
458 FlutterDesktopViewRef implicit_view =
459 FlutterDesktopPluginRegistrarGetView(registrar);
460
461 ASSERT_NE(implicit_view, nullptr);
462 }
FlutterDesktopEngineGetPluginRegistrar
FlutterDesktopPluginRegistrarRef FlutterDesktopEngineGetPluginRegistrar(FlutterDesktopEngineRef engine, const char *plugin_name)
Definition: flutter_windows.cc:224
FlutterDesktopPluginRegistrarGetView
FlutterDesktopViewRef FlutterDesktopPluginRegistrarGetView(FlutterDesktopPluginRegistrarRef registrar)
Definition: flutter_windows.cc:296

References FlutterDesktopEngineGetPluginRegistrar(), FlutterDesktopPluginRegistrarGetView(), and FlutterDesktopViewControllerGetEngine().

## ◆ TEST_F() [157/163]

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

Definition at line 464 of file flutter_windows_unittests.cc.

464 {
465 auto& context = GetContext();
466 WindowsConfigBuilder builder(context);
467 ViewControllerPtr controller{builder.Run()};
468 ASSERT_NE(controller, nullptr);
469
470 FlutterDesktopEngineRef engine =
471 FlutterDesktopViewControllerGetEngine(controller.get());
472 FlutterDesktopPluginRegistrarRef registrar =
473 FlutterDesktopEngineGetPluginRegistrar(engine, "foo_bar");
474
475 FlutterDesktopViewId view_id =
476 FlutterDesktopViewControllerGetViewId(controller.get());
477 FlutterDesktopViewRef view =
478 FlutterDesktopPluginRegistrarGetViewById(registrar, view_id);
479
480 FlutterDesktopViewRef view_123 = FlutterDesktopPluginRegistrarGetViewById(
481 registrar, static_cast<FlutterDesktopViewId>(123));
482
483 ASSERT_NE(view, nullptr);
484 ASSERT_EQ(view_123, nullptr);
485 }
FlutterDesktopPluginRegistrarGetViewById
FlutterDesktopViewRef FlutterDesktopPluginRegistrarGetViewById(FlutterDesktopPluginRegistrarRef registrar, FlutterDesktopViewId view_id)
Definition: flutter_windows.cc:301

References FlutterDesktopEngineGetPluginRegistrar(), FlutterDesktopPluginRegistrarGetViewById(), FlutterDesktopViewControllerGetEngine(), and FlutterDesktopViewControllerGetViewId().

## ◆ TEST_F() [158/163]

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

Definition at line 487 of file flutter_windows_unittests.cc.

487 {
488 auto& context = GetContext();
489 WindowsConfigBuilder builder(context);
490 EnginePtr engine{builder.RunHeadless()};
491 ASSERT_NE(engine, nullptr);
492
493 FlutterDesktopPluginRegistrarRef registrar =
494 FlutterDesktopEngineGetPluginRegistrar(engine.get(), "foo_bar");
495
496 FlutterDesktopViewRef implicit_view =
497 FlutterDesktopPluginRegistrarGetView(registrar);
498 FlutterDesktopViewRef view_123 = FlutterDesktopPluginRegistrarGetViewById(
499 registrar, static_cast<FlutterDesktopViewId>(123));
500
501 ASSERT_EQ(implicit_view, nullptr);
502 ASSERT_EQ(view_123, nullptr);
503 }

References FlutterDesktopEngineGetPluginRegistrar(), FlutterDesktopPluginRegistrarGetView(), and FlutterDesktopPluginRegistrarGetViewById().

## ◆ TEST_F() [159/163]

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

Definition at line 363 of file flutter_windows_unittests.cc.

363 {
364 auto& context = GetContext();
365 WindowsConfigBuilder builder(context);
366 builder.SetDartEntrypoint("renderImplicitView");
367
368 EnginePtr engine{builder.RunHeadless()};
369 ASSERT_NE(engine, nullptr);
370
371 bool done = false;
372 FlutterDesktopEngineSetNextFrameCallback(
373 engine.get(),
374 [](void* user_data) {
375 // This executes on the platform thread.
376 auto done = reinterpret_cast<std::atomic<bool>*>(user_data);
377 *done = true;
378 },
379 &done);
380
381 // This app is in headless mode, however, the engine assumes the implicit
382 // view always exists. Send window metrics for the implicit view, causing
383 // the engine to present to the implicit view. The embedder must not crash.
384 auto engine_ptr = reinterpret_cast<FlutterWindowsEngine*>(engine.get());
385 FlutterWindowMetricsEvent metrics = {};
386 metrics.struct_size = sizeof(FlutterWindowMetricsEvent);
387 metrics.width = 100;
388 metrics.height = 100;
389 metrics.pixel_ratio = 1.0;
390 metrics.view_id = kImplicitViewId;
391 engine_ptr->SendWindowMetricsEvent(metrics);
392
393 // Pump messages for the Windows platform task runner.
394 while (!done) {
395 PumpMessage();
396 }
397 }

References FlutterDesktopEngineSetNextFrameCallback(), flutter::kImplicitViewId, and user_data.

## ◆ TEST_F() [160/163]

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

Definition at line 507 of file flutter_windows_unittests.cc.

507 {
508 auto& context = GetContext();
509 WindowsConfigBuilder builder(context);
510 EnginePtr engine{builder.InitializeEngine()};
511 EngineModifier modifier{
512 reinterpret_cast<FlutterWindowsEngine*>(engine.get())};
513
514 auto egl_manager = std::make_unique<HalfBrokenEGLManager>();
515 ASSERT_TRUE(egl_manager->IsValid());
516 modifier.SetEGLManager(std::move(egl_manager));
517
518 ViewControllerPtr controller{
519 FlutterDesktopViewControllerCreate(0, 0, engine.release())};
520
521 ASSERT_NE(controller, nullptr);
522 }

References FlutterDesktopViewControllerCreate().

## ◆ TEST_F() [161/163]

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

Definition at line 212 of file flutter_windows_unittests.cc.

212 {
213 auto& context = GetContext();
214 WindowsConfigBuilder builder(context);
215 builder.SetDartEntrypoint("verifyNativeFunction");
216
217 fml::AutoResetWaitableEvent latch;
218 auto native_entry =
219 CREATE_NATIVE_ENTRY([&](Dart_NativeArguments args) { latch.Signal(); });
220 context.AddNativeFunction("Signal", native_entry);
221
222 ViewControllerPtr controller{builder.Run()};
223 ASSERT_NE(controller, nullptr);
224
225 // Wait until signal has been called.
226 latch.Wait();
227 }

## ◆ TEST_F() [162/163]

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

Definition at line 231 of file flutter_windows_unittests.cc.

231 {
232 auto& context = GetContext();
233 WindowsConfigBuilder builder(context);
234 builder.SetDartEntrypoint("verifyNativeFunctionWithParameters");
235
236 bool bool_value = false;
237 fml::AutoResetWaitableEvent latch;
238 auto native_entry = CREATE_NATIVE_ENTRY([&](Dart_NativeArguments args) {
239 auto handle = Dart_GetNativeBooleanArgument(args, 0, &bool_value);
240 ASSERT_FALSE(Dart_IsError(handle));
241 latch.Signal();
242 });
243 context.AddNativeFunction("SignalBoolValue", native_entry);
244
245 ViewControllerPtr controller{builder.Run()};
246 ASSERT_NE(controller, nullptr);
247
248 // Wait until signalBoolValue has been called.
249 latch.Wait();
250 EXPECT_TRUE(bool_value);
251 }

## ◆ TEST_F() [163/163]

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

Definition at line 279 of file flutter_windows_unittests.cc.

279 {
280 auto& context = GetContext();
281 WindowsConfigBuilder builder(context);
282 builder.SetDartEntrypoint("verifyNativeFunctionWithReturn");
283
284 bool bool_value_to_return = true;
285 fml::CountDownLatch latch(2);
286 auto bool_return_entry = CREATE_NATIVE_ENTRY([&](Dart_NativeArguments args) {
287 Dart_SetBooleanReturnValue(args, bool_value_to_return);
288 latch.CountDown();
289 });
290 context.AddNativeFunction("SignalBoolReturn", bool_return_entry);
291
292 bool bool_value_passed = false;
293 auto bool_pass_entry = CREATE_NATIVE_ENTRY([&](Dart_NativeArguments args) {
294 auto handle = Dart_GetNativeBooleanArgument(args, 0, &bool_value_passed);
295 ASSERT_FALSE(Dart_IsError(handle));
296 latch.CountDown();
297 });
298 context.AddNativeFunction("SignalBoolValue", bool_pass_entry);
299
300 ViewControllerPtr controller{builder.Run()};
301 ASSERT_NE(controller, nullptr);
302
303 // Wait until signalBoolReturn and signalBoolValue have been called.
304 latch.Wait();
305 EXPECT_TRUE(bool_value_passed);
306 }

## ◆ VietnameseTelexAddDiacriticWithSlowResponse()

void flutter::testing::VietnameseTelexAddDiacriticWithSlowResponse | ( | WindowsTestContext & | context,
|  | bool | backspace_response
| ) |  |

Definition at line 2349 of file keyboard_unittests.cc.

2350 {
2351 // In this test, the user presses the following keys:
2352 //
2353 // Key Current text
2354 // ===========================
2355 // A a
2356 // F à
2357 //
2358 // And the Backspace down event is responded slowly with `backspace_response`.
2359
2360 KeyboardTester tester{context};
2361 tester.Responding(false);
2362
2363 // US Keyboard layout
2364
2365 // Press A
2366 tester.InjectKeyboardChanges(std::vector<KeyboardChange>{
2367 WmKeyDownInfo{kVirtualKeyA, kScanCodeKeyA, kNotExtended, kWasUp}.Build(
2368 kWmResultZero),
2369 WmCharInfo{'a', kScanCodeKeyA, kNotExtended, kWasUp}.Build(
2370 kWmResultZero)});
2371
2372 EXPECT_EQ(tester.key_calls.size(), 2);
2373 EXPECT_CALL_IS_EVENT(tester.key_calls[0], kFlutterKeyEventTypeDown,
2374 kPhysicalKeyA, kLogicalKeyA, "a", kNotSynthesized);
2375 EXPECT_CALL_IS_TEXT(tester.key_calls[1], u"a");
2376 tester.clear_key_calls();
2377 EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 2);
2378
2379 // Release A
2380 tester.InjectKeyboardChanges(std::vector<KeyboardChange>{
2381 WmKeyUpInfo{kVirtualKeyA, kScanCodeKeyA, kNotExtended}.Build(
2382 kWmResultZero)});
2383
2384 EXPECT_EQ(tester.key_calls.size(), 1);
2385 EXPECT_CALL_IS_EVENT(tester.key_calls[0], kFlutterKeyEventTypeUp,
2386 kPhysicalKeyA, kLogicalKeyA, "", kNotSynthesized);
2387 tester.clear_key_calls();
2388 EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 1);
2389
2390 std::vector<MockKeyResponseController::ResponseCallback> recorded_callbacks;
2391 tester.LateResponding(
2392 [&recorded_callbacks](
2393 const FlutterKeyEvent* event,
2394 MockKeyResponseController::ResponseCallback callback) {
2395 recorded_callbacks.push_back(callback);
2396 });
2397
2398 // Press F, which is translated to:
2399 //
2400 // Backspace down, char & up, VK_PACKET('à').
2401 tester.InjectKeyboardChanges(std::vector<KeyboardChange>{
2402 WmKeyDownInfo{VK_BACK, kScanCodeBackspace, kNotExtended, kWasUp}.Build(
2403 kWmResultZero),
2404 WmCharInfo{0x8, kScanCodeBackspace, kNotExtended, kWasUp}.Build(
2405 kWmResultZero),
2406 WmKeyUpInfo{VK_BACK, kScanCodeBackspace, kNotExtended}.Build(
2407 kWmResultZero),
2408 WmKeyDownInfo{VK_PACKET, 0, kNotExtended, kWasUp}.Build(kWmResultDefault),
2409 WmCharInfo{0xe0 /*'à'*/, 0, kNotExtended, kWasUp}.Build(kWmResultZero),
2410 WmKeyUpInfo{VK_PACKET, 0, kNotExtended}.Build(kWmResultDefault)});
2411
2412 // The Backspace event has not responded yet, therefore the char message must
2413 // hold. This is because when the framework is handling the Backspace event,
2414 // it will send a setEditingState message that updates the text state that has
2415 // the last character deleted (denoted by `string1`). Processing the char
2416 // message before then will cause the final text to set to `string1`.
2417 EXPECT_EQ(tester.key_calls.size(), 1);
2418 EXPECT_CALL_IS_EVENT(tester.key_calls[0], kFlutterKeyEventTypeDown,
2419 kPhysicalBackspace, kLogicalBackspace, "",
2420 kNotSynthesized);
2421 tester.clear_key_calls();
2422 EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 0);
2423
2424 EXPECT_EQ(recorded_callbacks.size(), 1);
2425 recorded_callbacks[0](backspace_response);
2426
2427 EXPECT_EQ(tester.key_calls.size(), 1);
2428 EXPECT_CALL_IS_EVENT(tester.key_calls[0], kFlutterKeyEventTypeUp,
2429 kPhysicalBackspace, kLogicalBackspace, "",
2430 kNotSynthesized);
2431 tester.clear_key_calls();
2432 EXPECT_EQ(tester.RedispatchedMessageCountAndClear(),
2433 backspace_response ? 0 : 2);
2434
2435 recorded_callbacks[1](false);
2436 EXPECT_EQ(tester.key_calls.size(), 1);
2437 EXPECT_CALL_IS_TEXT(tester.key_calls[0], u"à");
2438 tester.clear_key_calls();
2439 EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 1);
2440
2441 tester.Responding(false);
2442
2443 // Release F
2444 tester.InjectKeyboardChanges(std::vector<KeyboardChange>{
2445 WmKeyUpInfo{kVirtualKeyF, kScanCodeKeyF, kNotExtended,
2446 /* overwrite_prev_state_0 */ true}
2447 .Build(kWmResultZero)});
2448
2449 EXPECT_EQ(tester.key_calls.size(), 1);
2450 EXPECT_CALL_IS_EVENT(tester.key_calls[0], kFlutterKeyEventTypeDown, 0, 0, "",
2451 kNotSynthesized);
2452 tester.clear_key_calls();
2453 EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 0);
2454 }

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

## ◆ 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().