| Flutter Windows Embedder |

Classes | Functions | Variables
flutter::testing Namespace Reference

## Classes
class | CursorHandlerTest
class | FlutterWindowsEngineTest
class | MockFlutterWindowsView
class | MockIDirectManipulationContent
class | MockIDirectManipulationViewport
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 (CursorHandlerTest, ActivateSystemCursor)
| TEST_F (CursorHandlerTest, ActivateSystemCursorRequiresView)
| TEST_F (CursorHandlerTest, CreateCustomCursor)
| TEST_F (CursorHandlerTest, SetCustomCursor)
| TEST_F (CursorHandlerTest, SetCustomCursorRequiresView)
| 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 (FlutterWindowTest, CreateDestroy)
| TEST (FlutterWindowTest, OnBitmapSurfaceUpdated)
| TEST (FlutterWindowTest, OnCursorRectUpdatedRegularDPI)
| TEST (FlutterWindowTest, OnCursorRectUpdatedHighDPI)
| TEST (FlutterWindowTest, OnPointerStarSendsDeviceType)
| TEST (FlutterWindowTest, OnScrollCallsGetScrollOffsetMultiplier)
| TEST (FlutterWindowTest, OnWindowRepaint)
| TEST (FlutterWindowTest, OnThemeChange)
| TEST (FlutterWindowTest, AccessibilityNodeWithoutView)
| TEST (FlutterWindowTest, AlertNode)
| TEST (FlutterWindowTest, LifecycleFocusMessages)
| TEST (FlutterWindowTest, CachedLifecycleMessage)
| TEST (FlutterWindowTest, PosthumousWindowMessage)
| 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, AlertPlatformMessage)
| 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, AppStartsInResumedState)
| 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 (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, 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, GetGraphicsAdapter)
| TEST (FlutterWindowsViewTest, SubMenuExpandedState)
| TEST (FlutterWindowsViewTest, Shutdown)
| TEST (FlutterWindowsViewTest, KeySequence)
| TEST (FlutterWindowsViewTest, EnableSemantics)
| TEST (FlutterWindowsViewTest, AddSemanticsNodeUpdate)
| TEST (FlutterWindowsViewTest, AddSemanticsNodeUpdateWithChildren)
| TEST (FlutterWindowsViewTest, NonZeroSemanticsRoot)
| TEST (FlutterWindowsViewTest, AccessibilityHitTesting)
| TEST (FlutterWindowsViewTest, WindowResizeTests)
| 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 (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, TextEditingWorksWithDeltaModel)
| TEST_F (TextInputPluginTest, CompositionCursorPos)
| TEST_F (TextInputPluginTest, TransformCursorRect)
| TEST_F (TextInputPluginTest, SetMarkedTextRectRequiresView)
| TEST (WindowProcDelegateManagerTest, CallsCorrectly)
| TEST (WindowProcDelegateManagerTest, ReplacementRegister)
| TEST (WindowProcDelegateManagerTest, RegisterMultiple)
| 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)
| 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/166]

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 }

References CreateSemanticsNode().

## ◆ TEST() [2/166]

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Definition at line 267 of file accessibility_bridge_windows_unittests.cc.

267 {
268 auto engine = GetTestEngine();
269 auto window_binding_handler =
270 std::make_unique<::testing::NiceMock<MockWindowBindingHandler>>();
271 FlutterWindowsViewSpy view(std::move(window_binding_handler));
272 view.SetEngine(engine.get());
273 view.OnUpdateSemanticsEnabled(true);
274
275 auto bridge = view.accessibility_bridge().lock();
276 PopulateAXTree(bridge);
277
278 FlutterSemanticsAction actual_action = kFlutterSemanticsActionTap;
279 EngineModifier modifier(view.GetEngine());
280 modifier.embedder_api().DispatchSemanticsAction = MOCK_ENGINE_PROC(
281 DispatchSemanticsAction,
282 ([&actual_action](FLUTTER_API_SYMBOL(FlutterEngine) engine, uint64_t id,
283 FlutterSemanticsAction action, const uint8_t* data,
284 size_t data_length) {
285 actual_action = action;
286 return kSuccess;
287 }));
288
289 AccessibilityBridgeWindows delegate(&view);
290 delegate.DispatchAccessibilityAction(1, kFlutterSemanticsActionCopy, {});
291 EXPECT_EQ(actual_action, kFlutterSemanticsActionCopy);
292 }

References action, and flutter::AccessibilityBridgeWindows::DispatchAccessibilityAction().

## ◆ TEST() [16/166]

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

Definition at line 235 of file accessibility_bridge_windows_unittests.cc.

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

## ◆ TEST() [17/166]

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

Definition at line 252 of file accessibility_bridge_windows_unittests.cc.

252 {
253 auto engine = GetTestEngine();
254 auto window_binding_handler =
255 std::make_unique<::testing::NiceMock<MockWindowBindingHandler>>();
256 FlutterWindowsViewSpy view(std::move(window_binding_handler));
257 view.SetEngine(engine.get());
258 view.OnUpdateSemanticsEnabled(true);
259
260 auto bridge = view.accessibility_bridge().lock();
261 PopulateAXTree(bridge);
262
263 auto node0_delegate = bridge->GetFlutterPlatformNodeDelegateFromID(0).lock();
264 ASSERT_TRUE(node0_delegate->GetParent() == nullptr);
265 }

## ◆ TEST() [18/166]

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

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

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

Definition at line 304 of file accessibility_bridge_windows_unittests.cc.

304 {
305 auto engine = GetTestEngine();
306 auto window_binding_handler =
307 std::make_unique<::testing::NiceMock<MockWindowBindingHandler>>();
308 FlutterWindowsViewSpy view(std::move(window_binding_handler));
309 view.SetEngine(engine.get());
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/166]

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

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

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

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

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

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

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

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

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

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

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

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

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 }

References content.

## ◆ TEST() [34/166]

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

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

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

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

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 };

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

## ◆ TEST() [39/166]

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

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

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

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

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

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

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

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

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

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 }

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

## ◆ TEST() [49/166]

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

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 }

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

## ◆ TEST() [51/166]

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

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

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

Definition at line 66 of file flutter_windows_texture_registrar_unittests.cc.

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

## ◆ TEST() [54/166]

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

Definition at line 266 of file flutter_windows_texture_registrar_unittests.cc.

266 {
267 std::unique_ptr<FlutterWindowsEngine> engine = GetTestEngine();
268 std::shared_ptr<MockGlProcTable> gl = std::make_shared<MockGlProcTable>();
269 FlutterWindowsTextureRegistrar registrar(engine.get(), gl);
270
271 UINT width = 100;
272 UINT height = 100;
273 auto d3d_texture = CreateD3dTexture(engine.get(), width, height);
274 EXPECT_TRUE(d3d_texture);
275
276 bool release_callback_called = false;
277 FlutterDesktopGpuSurfaceDescriptor surface_descriptor = {};
278 surface_descriptor.struct_size = sizeof(FlutterDesktopGpuSurfaceDescriptor);
279 surface_descriptor.handle = d3d_texture.Get();
280 surface_descriptor.width = surface_descriptor.visible_width = width;
281 surface_descriptor.height = surface_descriptor.visible_height = height;
282 surface_descriptor.release_context = &release_callback_called;
283 surface_descriptor.release_callback = [](void* release_context) {
284 bool* called = reinterpret_cast<bool*>(release_context);
285 *called = true;
286 };
287
288 FlutterDesktopTextureInfo texture_info = {};
289 texture_info.type = kFlutterDesktopGpuSurfaceTexture;
290 texture_info.gpu_surface_config.struct_size =
291 sizeof(FlutterDesktopGpuSurfaceTextureConfig);
292 texture_info.gpu_surface_config.type =
293 kFlutterDesktopGpuSurfaceTypeD3d11Texture2D;
294 texture_info.gpu_surface_config.user_data = &surface_descriptor;
295 texture_info.gpu_surface_config.callback =
296 [](size_t width, size_t height,
297 void* user_data) -> const FlutterDesktopGpuSurfaceDescriptor* {
298 return reinterpret_cast<const FlutterDesktopGpuSurfaceDescriptor*>(
299 user_data);
300 };
301
302 FlutterOpenGLTexture flutter_texture = {};
303 auto texture_id = registrar.RegisterTexture(&texture_info);
304 EXPECT_NE(texture_id, -1);
305
306 EXPECT_CALL(*gl.get(), GenTextures(1, _))
307 .Times(1)
308 .WillOnce([](GLsizei n, GLuint* textures) { textures[0] = 1; });
309 EXPECT_CALL(*gl.get(), BindTexture).Times(1);
310 EXPECT_CALL(*gl.get(), TexParameteri).Times(AtLeast(1));
311 EXPECT_CALL(*gl.get(), DeleteTextures(1, _)).Times(1);
312
313 auto result =
314 registrar.PopulateTexture(texture_id, 640, 480, &flutter_texture);
315 EXPECT_TRUE(result);
316 EXPECT_EQ(flutter_texture.width, width);
317 EXPECT_EQ(flutter_texture.height, height);
318 EXPECT_EQ(flutter_texture.target, GL_TEXTURE_2D);
319 EXPECT_TRUE(release_callback_called);
320 }

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, user_data, FlutterDesktopGpuSurfaceTextureConfig::user_data, FlutterDesktopGpuSurfaceDescriptor::visible_height, FlutterDesktopGpuSurfaceDescriptor::visible_width, and FlutterDesktopGpuSurfaceDescriptor::width.

## ◆ TEST() [55/166]

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

Definition at line 204 of file flutter_windows_texture_registrar_unittests.cc.

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

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, user_data, FlutterDesktopGpuSurfaceTextureConfig::user_data, FlutterDesktopGpuSurfaceDescriptor::visible_height, FlutterDesktopGpuSurfaceDescriptor::visible_width, and FlutterDesktopGpuSurfaceDescriptor::width.

## ◆ TEST() [56/166]

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

Definition at line 322 of file flutter_windows_texture_registrar_unittests.cc.

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

References flutter::FlutterWindowsTextureRegistrar::PopulateTexture().

## ◆ TEST() [57/166]

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

Definition at line 153 of file flutter_windows_texture_registrar_unittests.cc.

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

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, user_data, FlutterDesktopPixelBufferTextureConfig::user_data, and FlutterDesktopPixelBuffer::width.

## ◆ TEST() [58/166]

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

Definition at line 139 of file flutter_windows_texture_registrar_unittests.cc.

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

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

## ◆ TEST() [59/166]

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

Definition at line 74 of file flutter_windows_texture_registrar_unittests.cc.

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

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

## ◆ TEST() [60/166]

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

Definition at line 332 of file flutter_windows_texture_registrar_unittests.cc.

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

References flutter::FlutterWindowsTextureRegistrar::UnregisterTexture().

## ◆ TEST() [61/166]

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

Definition at line 718 of file flutter_windows_view_unittests.cc.

718 {
719 constexpr FlutterTransformation kIdentityTransform = {1, 0, 0, //
720 0, 1, 0, //
721 0, 0, 1};
722
723 std::unique_ptr<FlutterWindowsEngine> engine = GetTestEngine();
724 EngineModifier modifier(engine.get());
725 modifier.embedder_api().UpdateSemanticsEnabled =
726 [](FLUTTER_API_SYMBOL(FlutterEngine) engine, bool enabled) {
727 return kSuccess;
728 };
729
730 auto window_binding_handler =
731 std::make_unique<NiceMock<MockWindowBindingHandler>>();
732 FlutterWindowsView view(std::move(window_binding_handler));
733 view.SetEngine(engine.get());
734
735 // Enable semantics to instantiate accessibility bridge.
736 view.OnUpdateSemanticsEnabled(true);
737
738 auto bridge = view.accessibility_bridge().lock();
739 ASSERT_TRUE(bridge);
740
741 // Add root node at origin. Size 500x500.
742 FlutterSemanticsNode2 node0{sizeof(FlutterSemanticsNode2), 0};
743 std::vector<int32_t> node0_children{1, 2};
744 node0.rect = {0, 0, 500, 500};
745 node0.transform = kIdentityTransform;
746 node0.child_count = node0_children.size();
747 node0.children_in_traversal_order = node0_children.data();
748 node0.children_in_hit_test_order = node0_children.data();
749
750 // Add node 1 located at 0,0 relative to node 0. Size 250x500.
751 FlutterSemanticsNode2 node1{sizeof(FlutterSemanticsNode2), 1};
752 node1.rect = {0, 0, 250, 500};
753 node1.transform = kIdentityTransform;
754 node1.label = "prefecture";
755 node1.value = "Kyoto";
756
757 // Add node 2 located at 250,0 relative to node 0. Size 250x500.
758 FlutterSemanticsNode2 node2{sizeof(FlutterSemanticsNode2), 2};
759 std::vector<int32_t> node2_children{3};
760 node2.rect = {0, 0, 250, 500};
761 node2.transform = {1, 0, 250, 0, 1, 0, 0, 0, 1};
762 node2.child_count = node2_children.size();
763 node2.children_in_traversal_order = node2_children.data();
764 node2.children_in_hit_test_order = node2_children.data();
765
766 // Add node 3 located at 0,250 relative to node 2. Size 250, 250.
767 FlutterSemanticsNode2 node3{sizeof(FlutterSemanticsNode2), 3};
768 node3.rect = {0, 0, 250, 250};
769 node3.transform = {1, 0, 0, 0, 1, 250, 0, 0, 1};
770 node3.label = "city";
771 node3.value = "Uji";
772
773 bridge->AddFlutterSemanticsNodeUpdate(node0);
774 bridge->AddFlutterSemanticsNodeUpdate(node1);
775 bridge->AddFlutterSemanticsNodeUpdate(node2);
776 bridge->AddFlutterSemanticsNodeUpdate(node3);
777 bridge->CommitUpdates();
778
779 // Look up the root windows node delegate.
780 auto node0_delegate = bridge->GetFlutterPlatformNodeDelegateFromID(0).lock();
781 ASSERT_TRUE(node0_delegate);
782 auto node1_delegate = bridge->GetFlutterPlatformNodeDelegateFromID(1).lock();
783 ASSERT_TRUE(node1_delegate);
784 auto node2_delegate = bridge->GetFlutterPlatformNodeDelegateFromID(2).lock();
785 ASSERT_TRUE(node2_delegate);
786 auto node3_delegate = bridge->GetFlutterPlatformNodeDelegateFromID(3).lock();
787 ASSERT_TRUE(node3_delegate);
788
789 // Get the native IAccessible root object.
790 IAccessible* node0_accessible = node0_delegate->GetNativeViewAccessible();
791 ASSERT_TRUE(node0_accessible != nullptr);
792
793 // Perform a hit test that should hit node 1.
794 VARIANT varchild{};
795 ASSERT_TRUE(SUCCEEDED(node0_accessible->accHitTest(150, 150, &varchild)));
796 EXPECT_EQ(varchild.vt, VT_DISPATCH);
797 EXPECT_EQ(varchild.pdispVal, node1_delegate->GetNativeViewAccessible());
798
799 // Perform a hit test that should hit node 2.
800 varchild = {};
801 ASSERT_TRUE(SUCCEEDED(node0_accessible->accHitTest(450, 150, &varchild)));
802 EXPECT_EQ(varchild.vt, VT_DISPATCH);
803 EXPECT_EQ(varchild.pdispVal, node2_delegate->GetNativeViewAccessible());
804
805 // Perform a hit test that should hit node 3.
806 varchild = {};
807 ASSERT_TRUE(SUCCEEDED(node0_accessible->accHitTest(450, 450, &varchild)));
808 EXPECT_EQ(varchild.vt, VT_DISPATCH);
809 EXPECT_EQ(varchild.pdispVal, node3_delegate->GetNativeViewAccessible());
810 }

## ◆ TEST() [62/166]

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

Definition at line 293 of file flutter_windows_view_unittests.cc.

293 {
294 std::unique_ptr<FlutterWindowsEngine> engine = GetTestEngine();
295 EngineModifier modifier(engine.get());
296 modifier.embedder_api().UpdateSemanticsEnabled =
297 [](FLUTTER_API_SYMBOL(FlutterEngine) engine, bool enabled) {
298 return kSuccess;
299 };
300
301 auto window_binding_handler =
302 std::make_unique<NiceMock<MockWindowBindingHandler>>();
303 FlutterWindowsView view(std::move(window_binding_handler));
304 view.SetEngine(engine.get());
305
306 // Enable semantics to instantiate accessibility bridge.
307 view.OnUpdateSemanticsEnabled(true);
308
309 auto bridge = view.accessibility_bridge().lock();
310 ASSERT_TRUE(bridge);
311
312 // Add root node.
313 FlutterSemanticsNode2 node{sizeof(FlutterSemanticsNode2), 0};
314 node.label = "name";
315 node.value = "value";
316 node.platform_view_id = -1;
317 bridge->AddFlutterSemanticsNodeUpdate(node);
318 bridge->CommitUpdates();
319
320 // Look up the root windows node delegate.
321 auto node_delegate = bridge->GetFlutterPlatformNodeDelegateFromID(0).lock();
322 ASSERT_TRUE(node_delegate);
323 EXPECT_EQ(node_delegate->GetChildCount(), 0);
324
325 // Get the native IAccessible object.
326 IAccessible* native_view = node_delegate->GetNativeViewAccessible();
327 ASSERT_TRUE(native_view != nullptr);
328
329 // Property lookups will be made against this node itself.
330 VARIANT varchild{};
331 varchild.vt = VT_I4;
332 varchild.lVal = CHILDID_SELF;
333
334 // Verify node name matches our label.
335 BSTR bname = nullptr;
336 ASSERT_EQ(native_view->get_accName(varchild, &bname), S_OK);
337 std::string name(_com_util::ConvertBSTRToString(bname));
338 EXPECT_EQ(name, "name");
339
340 // Verify node value matches.
341 BSTR bvalue = nullptr;
342 ASSERT_EQ(native_view->get_accValue(varchild, &bvalue), S_OK);
343 std::string value(_com_util::ConvertBSTRToString(bvalue));
344 EXPECT_EQ(value, "value");
345
346 // Verify node type is static text.
347 VARIANT varrole{};
348 varrole.vt = VT_I4;
349 ASSERT_EQ(native_view->get_accRole(varchild, &varrole), S_OK);
350 EXPECT_EQ(varrole.lVal, ROLE_SYSTEM_STATICTEXT);
351
352 // Get the IRawElementProviderFragment object.
353 IRawElementProviderSimple* uia_view;
354 native_view->QueryInterface(IID_PPV_ARGS(&uia_view));
355 ASSERT_TRUE(uia_view != nullptr);
356
357 // Verify name property matches our label.
358 VARIANT varname{};
359 ASSERT_EQ(uia_view->GetPropertyValue(UIA_NamePropertyId, &varname), S_OK);
360 EXPECT_EQ(varname.vt, VT_BSTR);
361 name = _com_util::ConvertBSTRToString(varname.bstrVal);
362 EXPECT_EQ(name, "name");
363
364 // Verify value property matches our label.
365 VARIANT varvalue{};
366 ASSERT_EQ(uia_view->GetPropertyValue(UIA_ValueValuePropertyId, &varvalue),
367 S_OK);
368 EXPECT_EQ(varvalue.vt, VT_BSTR);
369 value = _com_util::ConvertBSTRToString(varvalue.bstrVal);
370 EXPECT_EQ(value, "value");
371
372 // Verify node control type is text.
373 varrole = {};
374 ASSERT_EQ(uia_view->GetPropertyValue(UIA_ControlTypePropertyId, &varrole),
375 S_OK);
376 EXPECT_EQ(varrole.vt, VT_I4);
377 EXPECT_EQ(varrole.lVal, UIA_TextControlTypeId);
378 }

References node_delegate.

## ◆ TEST() [63/166]

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

Definition at line 392 of file flutter_windows_view_unittests.cc.

392 {
393 std::unique_ptr<FlutterWindowsEngine> engine = GetTestEngine();
394 EngineModifier modifier(engine.get());
395 modifier.embedder_api().UpdateSemanticsEnabled =
396 [](FLUTTER_API_SYMBOL(FlutterEngine) engine, bool enabled) {
397 return kSuccess;
398 };
399
400 auto window_binding_handler =
401 std::make_unique<NiceMock<MockWindowBindingHandler>>();
402 FlutterWindowsView view(std::move(window_binding_handler));
403 view.SetEngine(engine.get());
404
405 // Enable semantics to instantiate accessibility bridge.
406 view.OnUpdateSemanticsEnabled(true);
407
408 auto bridge = view.accessibility_bridge().lock();
409 ASSERT_TRUE(bridge);
410
411 // Add root node.
412 FlutterSemanticsNode2 node0{sizeof(FlutterSemanticsNode2), 0};
413 std::vector<int32_t> node0_children{1, 2};
414 node0.child_count = node0_children.size();
415 node0.children_in_traversal_order = node0_children.data();
416 node0.children_in_hit_test_order = node0_children.data();
417
418 FlutterSemanticsNode2 node1{sizeof(FlutterSemanticsNode2), 1};
419 node1.label = "prefecture";
420 node1.value = "Kyoto";
421 FlutterSemanticsNode2 node2{sizeof(FlutterSemanticsNode2), 2};
422 std::vector<int32_t> node2_children{3};
423 node2.child_count = node2_children.size();
424 node2.children_in_traversal_order = node2_children.data();
425 node2.children_in_hit_test_order = node2_children.data();
426 FlutterSemanticsNode2 node3{sizeof(FlutterSemanticsNode2), 3};
427 node3.label = "city";
428 node3.value = "Uji";
429
430 bridge->AddFlutterSemanticsNodeUpdate(node0);
431 bridge->AddFlutterSemanticsNodeUpdate(node1);
432 bridge->AddFlutterSemanticsNodeUpdate(node2);
433 bridge->AddFlutterSemanticsNodeUpdate(node3);
434 bridge->CommitUpdates();
435
436 // Look up the root windows node delegate.
437 auto node_delegate = bridge->GetFlutterPlatformNodeDelegateFromID(0).lock();
438 ASSERT_TRUE(node_delegate);
439 EXPECT_EQ(node_delegate->GetChildCount(), 2);
440
441 // Get the native IAccessible object.
442 IAccessible* node0_accessible = node_delegate->GetNativeViewAccessible();
443 ASSERT_TRUE(node0_accessible != nullptr);
444
445 // Property lookups will be made against this node itself.
446 VARIANT varchild{};
447 varchild.vt = VT_I4;
448 varchild.lVal = CHILDID_SELF;
449
450 // Verify node type is a group.
451 VARIANT varrole{};
452 varrole.vt = VT_I4;
453 ASSERT_EQ(node0_accessible->get_accRole(varchild, &varrole), S_OK);
454 EXPECT_EQ(varrole.lVal, ROLE_SYSTEM_GROUPING);
455
456 // Verify child count.
457 long node0_child_count = 0;
458 ASSERT_EQ(node0_accessible->get_accChildCount(&node0_child_count), S_OK);
459 EXPECT_EQ(node0_child_count, 2);
460
461 {
462 // Look up first child of node0 (node1), a static text node.
463 varchild.lVal = 1;
464 IDispatch* node1_dispatch = nullptr;
465 ASSERT_EQ(node0_accessible->get_accChild(varchild, &node1_dispatch), S_OK);
466 ASSERT_TRUE(node1_dispatch != nullptr);
467 IAccessible* node1_accessible = nullptr;
468 ASSERT_EQ(node1_dispatch->QueryInterface(
469 IID_IAccessible, reinterpret_cast<void**>(&node1_accessible)),
470 S_OK);
471 ASSERT_TRUE(node1_accessible != nullptr);
472
473 // Verify node name matches our label.
474 varchild.lVal = CHILDID_SELF;
475 BSTR bname = nullptr;
476 ASSERT_EQ(node1_accessible->get_accName(varchild, &bname), S_OK);
477 std::string name(_com_util::ConvertBSTRToString(bname));
478 EXPECT_EQ(name, "prefecture");
479
480 // Verify node value matches.
481 BSTR bvalue = nullptr;
482 ASSERT_EQ(node1_accessible->get_accValue(varchild, &bvalue), S_OK);
483 std::string value(_com_util::ConvertBSTRToString(bvalue));
484 EXPECT_EQ(value, "Kyoto");
485
486 // Verify node type is static text.
487 VARIANT varrole{};
488 varrole.vt = VT_I4;
489 ASSERT_EQ(node1_accessible->get_accRole(varchild, &varrole), S_OK);
490 EXPECT_EQ(varrole.lVal, ROLE_SYSTEM_STATICTEXT);
491
492 // Verify the parent node is the root.
493 IDispatch* parent_dispatch;
494 node1_accessible->get_accParent(&parent_dispatch);
495 IAccessible* parent_accessible;
496 ASSERT_EQ(
497 parent_dispatch->QueryInterface(
498 IID_IAccessible, reinterpret_cast<void**>(&parent_accessible)),
499 S_OK);
500 EXPECT_EQ(parent_accessible, node0_accessible);
501 }
502
503 // Look up second child of node0 (node2), a parent group for node3.
504 varchild.lVal = 2;
505 IDispatch* node2_dispatch = nullptr;
506 ASSERT_EQ(node0_accessible->get_accChild(varchild, &node2_dispatch), S_OK);
507 ASSERT_TRUE(node2_dispatch != nullptr);
508 IAccessible* node2_accessible = nullptr;
509 ASSERT_EQ(node2_dispatch->QueryInterface(
510 IID_IAccessible, reinterpret_cast<void**>(&node2_accessible)),
511 S_OK);
512 ASSERT_TRUE(node2_accessible != nullptr);
513
514 {
515 // Verify child count.
516 long node2_child_count = 0;
517 ASSERT_EQ(node2_accessible->get_accChildCount(&node2_child_count), S_OK);
518 EXPECT_EQ(node2_child_count, 1);
519
520 // Verify node type is static text.
521 varchild.lVal = CHILDID_SELF;
522 VARIANT varrole{};
523 varrole.vt = VT_I4;
524 ASSERT_EQ(node2_accessible->get_accRole(varchild, &varrole), S_OK);
525 EXPECT_EQ(varrole.lVal, ROLE_SYSTEM_GROUPING);
526
527 // Verify the parent node is the root.
528 IDispatch* parent_dispatch;
529 node2_accessible->get_accParent(&parent_dispatch);
530 IAccessible* parent_accessible;
531 ASSERT_EQ(
532 parent_dispatch->QueryInterface(
533 IID_IAccessible, reinterpret_cast<void**>(&parent_accessible)),
534 S_OK);
535 EXPECT_EQ(parent_accessible, node0_accessible);
536 }
537
538 {
539 // Look up only child of node2 (node3), a static text node.
540 varchild.lVal = 1;
541 IDispatch* node3_dispatch = nullptr;
542 ASSERT_EQ(node2_accessible->get_accChild(varchild, &node3_dispatch), S_OK);
543 ASSERT_TRUE(node3_dispatch != nullptr);
544 IAccessible* node3_accessible = nullptr;
545 ASSERT_EQ(node3_dispatch->QueryInterface(
546 IID_IAccessible, reinterpret_cast<void**>(&node3_accessible)),
547 S_OK);
548 ASSERT_TRUE(node3_accessible != nullptr);
549
550 // Verify node name matches our label.
551 varchild.lVal = CHILDID_SELF;
552 BSTR bname = nullptr;
553 ASSERT_EQ(node3_accessible->get_accName(varchild, &bname), S_OK);
554 std::string name(_com_util::ConvertBSTRToString(bname));
555 EXPECT_EQ(name, "city");
556
557 // Verify node value matches.
558 BSTR bvalue = nullptr;
559 ASSERT_EQ(node3_accessible->get_accValue(varchild, &bvalue), S_OK);
560 std::string value(_com_util::ConvertBSTRToString(bvalue));
561 EXPECT_EQ(value, "Uji");
562
563 // Verify node type is static text.
564 VARIANT varrole{};
565 varrole.vt = VT_I4;
566 ASSERT_EQ(node3_accessible->get_accRole(varchild, &varrole), S_OK);
567 EXPECT_EQ(varrole.lVal, ROLE_SYSTEM_STATICTEXT);
568
569 // Verify the parent node is node2.
570 IDispatch* parent_dispatch;
571 node3_accessible->get_accParent(&parent_dispatch);
572 IAccessible* parent_accessible;
573 ASSERT_EQ(
574 parent_dispatch->QueryInterface(
575 IID_IAccessible, reinterpret_cast<void**>(&parent_accessible)),
576 S_OK);
577 EXPECT_EQ(parent_accessible, node2_accessible);
578 }
579 }

References node_delegate.

## ◆ TEST() [64/166]

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

Definition at line 884 of file flutter_windows_view_unittests.cc.

884 {
885 std::unique_ptr<FlutterWindowsEngine> engine = GetTestEngine();
886 EngineModifier modifier(engine.get());
887 modifier.embedder_api().UpdateSemanticsEnabled =
888 [](FLUTTER_API_SYMBOL(FlutterEngine) engine, bool enabled) {
889 return kSuccess;
890 };
891
892 auto window_binding_handler =
893 std::make_unique<NiceMock<MockWindowBindingHandler>>();
894 FlutterWindowsView view(std::move(window_binding_handler));
895 view.SetEngine(engine.get());
896
897 // Enable semantics to instantiate accessibility bridge.
898 view.OnUpdateSemanticsEnabled(true);
899
900 auto bridge = view.accessibility_bridge().lock();
901 ASSERT_TRUE(bridge);
902
903 FlutterSemanticsNode2 root{sizeof(FlutterSemanticsNode2), 0};
904 root.id = 0;
905 root.label = "root";
906 root.hint = "";
907 root.value = "";
908 root.increased_value = "";
909 root.decreased_value = "";
910 root.child_count = 0;
911 root.custom_accessibility_actions_count = 0;
912 root.flags = static_cast<FlutterSemanticsFlag>(
913 FlutterSemanticsFlag::kFlutterSemanticsFlagHasCheckedState |
914 FlutterSemanticsFlag::kFlutterSemanticsFlagIsChecked);
915 bridge->AddFlutterSemanticsNodeUpdate(root);
916
917 bridge->CommitUpdates();
918
919 {
920 auto root_node = bridge->GetFlutterPlatformNodeDelegateFromID(0).lock();
921 EXPECT_EQ(root_node->GetData().role, ax::mojom::Role::kCheckBox);
922 EXPECT_EQ(root_node->GetData().GetCheckedState(),
923 ax::mojom::CheckedState::kTrue);
924
925 // Get the IAccessible for the root node.
926 IAccessible* native_view = root_node->GetNativeViewAccessible();
927 ASSERT_TRUE(native_view != nullptr);
928
929 // Look up against the node itself (not one of its children).
930 VARIANT varchild = {};
931 varchild.vt = VT_I4;
932
933 // Verify the checkbox is checked.
934 varchild.lVal = CHILDID_SELF;
935 VARIANT native_state = {};
936 ASSERT_TRUE(SUCCEEDED(native_view->get_accState(varchild, &native_state)));
937 EXPECT_TRUE(native_state.lVal & STATE_SYSTEM_CHECKED);
938
939 // Perform similar tests for UIA value;
940 IRawElementProviderSimple* uia_node;
941 native_view->QueryInterface(IID_PPV_ARGS(&uia_node));
942 ASSERT_TRUE(SUCCEEDED(uia_node->GetPropertyValue(
943 UIA_ToggleToggleStatePropertyId, &native_state)));
944 EXPECT_EQ(native_state.lVal, ToggleState_On);
945
946 ASSERT_TRUE(SUCCEEDED(uia_node->GetPropertyValue(
947 UIA_AriaPropertiesPropertyId, &native_state)));
948 EXPECT_NE(std::wcsstr(native_state.bstrVal, L"checked=true"), nullptr);
949 }
950
951 // Test unchecked too.
952 root.flags = static_cast<FlutterSemanticsFlag>(
953 FlutterSemanticsFlag::kFlutterSemanticsFlagHasCheckedState);
954 bridge->AddFlutterSemanticsNodeUpdate(root);
955 bridge->CommitUpdates();
956
957 {
958 auto root_node = bridge->GetFlutterPlatformNodeDelegateFromID(0).lock();
959 EXPECT_EQ(root_node->GetData().role, ax::mojom::Role::kCheckBox);
960 EXPECT_EQ(root_node->GetData().GetCheckedState(),
961 ax::mojom::CheckedState::kFalse);
962
963 // Get the IAccessible for the root node.
964 IAccessible* native_view = root_node->GetNativeViewAccessible();
965 ASSERT_TRUE(native_view != nullptr);
966
967 // Look up against the node itself (not one of its children).
968 VARIANT varchild = {};
969 varchild.vt = VT_I4;
970
971 // Verify the checkbox is unchecked.
972 varchild.lVal = CHILDID_SELF;
973 VARIANT native_state = {};
974 ASSERT_TRUE(SUCCEEDED(native_view->get_accState(varchild, &native_state)));
975 EXPECT_FALSE(native_state.lVal & STATE_SYSTEM_CHECKED);
976
977 // Perform similar tests for UIA value;
978 IRawElementProviderSimple* uia_node;
979 native_view->QueryInterface(IID_PPV_ARGS(&uia_node));
980 ASSERT_TRUE(SUCCEEDED(uia_node->GetPropertyValue(
981 UIA_ToggleToggleStatePropertyId, &native_state)));
982 EXPECT_EQ(native_state.lVal, ToggleState_Off);
983
984 ASSERT_TRUE(SUCCEEDED(uia_node->GetPropertyValue(
985 UIA_AriaPropertiesPropertyId, &native_state)));
986 EXPECT_NE(std::wcsstr(native_state.bstrVal, L"checked=false"), nullptr);
987 }
988
989 // Now check mixed state.
990 root.flags = static_cast<FlutterSemanticsFlag>(
991 FlutterSemanticsFlag::kFlutterSemanticsFlagHasCheckedState |
992 FlutterSemanticsFlag::kFlutterSemanticsFlagIsCheckStateMixed);
993 bridge->AddFlutterSemanticsNodeUpdate(root);
994 bridge->CommitUpdates();
995
996 {
997 auto root_node = bridge->GetFlutterPlatformNodeDelegateFromID(0).lock();
998 EXPECT_EQ(root_node->GetData().role, ax::mojom::Role::kCheckBox);
999 EXPECT_EQ(root_node->GetData().GetCheckedState(),
1000 ax::mojom::CheckedState::kMixed);
1001
1002 // Get the IAccessible for the root node.
1003 IAccessible* native_view = root_node->GetNativeViewAccessible();
1004 ASSERT_TRUE(native_view != nullptr);
1005
1006 // Look up against the node itself (not one of its children).
1007 VARIANT varchild = {};
1008 varchild.vt = VT_I4;
1009
1010 // Verify the checkbox is mixed.
1011 varchild.lVal = CHILDID_SELF;
1012 VARIANT native_state = {};
1013 ASSERT_TRUE(SUCCEEDED(native_view->get_accState(varchild, &native_state)));
1014 EXPECT_TRUE(native_state.lVal & STATE_SYSTEM_MIXED);
1015
1016 // Perform similar tests for UIA value;
1017 IRawElementProviderSimple* uia_node;
1018 native_view->QueryInterface(IID_PPV_ARGS(&uia_node));
1019 ASSERT_TRUE(SUCCEEDED(uia_node->GetPropertyValue(
1020 UIA_ToggleToggleStatePropertyId, &native_state)));
1021 EXPECT_EQ(native_state.lVal, ToggleState_Indeterminate);
1022
1023 ASSERT_TRUE(SUCCEEDED(uia_node->GetPropertyValue(
1024 UIA_AriaPropertiesPropertyId, &native_state)));
1025 EXPECT_NE(std::wcsstr(native_state.bstrVal, L"checked=mixed"), nullptr);
1026 }
1027 }

## ◆ TEST() [65/166]

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

Definition at line 1281 of file flutter_windows_view_unittests.cc.

1281 {
1282 std::unique_ptr<MockFlutterWindowsEngine> engine =
1283 std::make_unique<MockFlutterWindowsEngine>();
1284 auto window_binding_handler =
1285 std::make_unique<NiceMock<MockWindowBindingHandler>>();
1286 auto windows_proc_table = std::make_shared<MockWindowsProcTable>();
1287 std::unique_ptr<MockAngleSurfaceManager> surface_manager =
1288 std::make_unique<MockAngleSurfaceManager>();
1289
1290 EXPECT_CALL(*engine.get(), running).WillRepeatedly(Return(true));
1291 EXPECT_CALL(*windows_proc_table.get(), DwmIsCompositionEnabled)
1292 .WillOnce(Return(true));
1293
1294 EngineModifier modifier(engine.get());
1295 FlutterWindowsView view(std::move(window_binding_handler),
1296 std::move(windows_proc_table));
1297
1298 InSequence s;
1299 EXPECT_CALL(*surface_manager.get(), CreateSurface(_, _, _))
1300 .Times(1)
1301 .WillOnce(Return(true));
1302 EXPECT_CALL(*engine.get(), PostRasterThreadTask)
1303 .WillOnce([](fml::closure callback) {
1304 callback();
1305 return true;
1306 });
1307 EXPECT_CALL(*surface_manager.get(), SetVSyncEnabled(false)).Times(1);
1308 EXPECT_CALL(*surface_manager.get(), ClearCurrent).Times(0);
1309
1310 EXPECT_CALL(*engine.get(), Stop).Times(1);
1311 EXPECT_CALL(*surface_manager.get(), DestroySurface).Times(1);
1312
1313 modifier.SetSurfaceManager(std::move(surface_manager));
1314 view.SetEngine(engine.get());
1315
1316 view.CreateRenderSurface();
1317 }

References callback, flutter::FlutterWindowsView::CreateRenderSurface(), and flutter::FlutterWindowsView::SetEngine().

## ◆ TEST() [66/166]

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

Definition at line 1208 of file flutter_windows_view_unittests.cc.

1208 {
1209 std::unique_ptr<MockFlutterWindowsEngine> engine =
1210 std::make_unique<MockFlutterWindowsEngine>();
1211 auto window_binding_handler =
1212 std::make_unique<NiceMock<MockWindowBindingHandler>>();
1213 auto windows_proc_table = std::make_shared<MockWindowsProcTable>();
1214 std::unique_ptr<MockAngleSurfaceManager> surface_manager =
1215 std::make_unique<MockAngleSurfaceManager>();
1216
1217 EXPECT_CALL(*engine.get(), running).WillRepeatedly(Return(false));
1218 EXPECT_CALL(*engine.get(), PostRasterThreadTask).Times(0);
1219
1220 EXPECT_CALL(*windows_proc_table.get(), DwmIsCompositionEnabled)
1221 .WillOnce(Return(true));
1222
1223 EngineModifier modifier(engine.get());
1224 FlutterWindowsView view(std::move(window_binding_handler),
1225 std::move(windows_proc_table));
1226
1227 InSequence s;
1228 EXPECT_CALL(*surface_manager.get(), CreateSurface(_, _, _))
1229 .Times(1)
1230 .WillOnce(Return(true));
1231 EXPECT_CALL(*surface_manager.get(), SetVSyncEnabled(false)).Times(1);
1232 EXPECT_CALL(*surface_manager.get(), ClearCurrent).WillOnce(Return(true));
1233
1234 EXPECT_CALL(*engine.get(), Stop).Times(1);
1235 EXPECT_CALL(*surface_manager.get(), DestroySurface).Times(1);
1236
1237 modifier.SetSurfaceManager(std::move(surface_manager));
1238 view.SetEngine(engine.get());
1239
1240 view.CreateRenderSurface();
1241 }

References flutter::FlutterWindowsView::CreateRenderSurface(), and flutter::FlutterWindowsView::SetEngine().

## ◆ TEST() [67/166]

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

Definition at line 271 of file flutter_windows_view_unittests.cc.

271 {
272 std::unique_ptr<FlutterWindowsEngine> engine = GetTestEngine();
273 EngineModifier modifier(engine.get());
274
275 bool semantics_enabled = false;
276 modifier.embedder_api().UpdateSemanticsEnabled = MOCK_ENGINE_PROC(
277 UpdateSemanticsEnabled,
278 [&semantics_enabled](FLUTTER_API_SYMBOL(FlutterEngine) engine,
279 bool enabled) {
280 semantics_enabled = enabled;
281 return kSuccess;
282 });
283
284 auto window_binding_handler =
285 std::make_unique<NiceMock<MockWindowBindingHandler>>();
286 FlutterWindowsView view(std::move(window_binding_handler));
287 view.SetEngine(engine.get());
288
289 view.OnUpdateSemanticsEnabled(true);
290 EXPECT_TRUE(semantics_enabled);
291 }

## ◆ TEST() [68/166]

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

Definition at line 1321 of file flutter_windows_view_unittests.cc.

1321 {
1322 std::unique_ptr<MockFlutterWindowsEngine> engine =
1323 std::make_unique<MockFlutterWindowsEngine>();
1324 auto window_binding_handler =
1325 std::make_unique<NiceMock<MockWindowBindingHandler>>();
1326 auto windows_proc_table = std::make_shared<MockWindowsProcTable>();
1327 std::unique_ptr<MockAngleSurfaceManager> surface_manager =
1328 std::make_unique<MockAngleSurfaceManager>();
1329
1330 EXPECT_CALL(*engine.get(), running).WillRepeatedly(Return(true));
1331
1332 EXPECT_CALL(*windows_proc_table.get(), DwmIsCompositionEnabled)
1333 .WillOnce(Return(false));
1334
1335 EngineModifier modifier(engine.get());
1336 FlutterWindowsView view(std::move(window_binding_handler),
1337 std::move(windows_proc_table));
1338
1339 InSequence s;
1340 EXPECT_CALL(*surface_manager.get(), CreateSurface(_, _, _))
1341 .Times(1)
1342 .WillOnce(Return(true));
1343 EXPECT_CALL(*engine.get(), PostRasterThreadTask)
1344 .WillOnce([](fml::closure callback) {
1345 callback();
1346 return true;
1347 });
1348 EXPECT_CALL(*surface_manager.get(), SetVSyncEnabled(true)).Times(1);
1349 EXPECT_CALL(*surface_manager.get(), ClearCurrent).Times(0);
1350
1351 EXPECT_CALL(*engine.get(), Stop).Times(1);
1352 EXPECT_CALL(*surface_manager.get(), DestroySurface).Times(1);
1353
1354 modifier.SetSurfaceManager(std::move(surface_manager));
1355 view.SetEngine(engine.get());
1356
1357 view.CreateRenderSurface();
1358 }

References callback, flutter::FlutterWindowsView::CreateRenderSurface(), and flutter::FlutterWindowsView::SetEngine().

## ◆ TEST() [69/166]

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

Definition at line 1245 of file flutter_windows_view_unittests.cc.

1245 {
1246 std::unique_ptr<MockFlutterWindowsEngine> engine =
1247 std::make_unique<MockFlutterWindowsEngine>();
1248 auto window_binding_handler =
1249 std::make_unique<NiceMock<MockWindowBindingHandler>>();
1250 auto windows_proc_table = std::make_shared<MockWindowsProcTable>();
1251 std::unique_ptr<MockAngleSurfaceManager> surface_manager =
1252 std::make_unique<MockAngleSurfaceManager>();
1253
1254 EXPECT_CALL(*engine.get(), running).WillRepeatedly(Return(false));
1255 EXPECT_CALL(*engine.get(), PostRasterThreadTask).Times(0);
1256 EXPECT_CALL(*windows_proc_table.get(), DwmIsCompositionEnabled)
1257 .WillOnce(Return(false));
1258
1259 EngineModifier modifier(engine.get());
1260 FlutterWindowsView view(std::move(window_binding_handler),
1261 std::move(windows_proc_table));
1262
1263 InSequence s;
1264 EXPECT_CALL(*surface_manager.get(), CreateSurface(_, _, _))
1265 .Times(1)
1266 .WillOnce(Return(true));
1267 EXPECT_CALL(*surface_manager.get(), SetVSyncEnabled(true)).Times(1);
1268 EXPECT_CALL(*surface_manager.get(), ClearCurrent).WillOnce(Return(true));
1269
1270 EXPECT_CALL(*engine.get(), Stop).Times(1);
1271 EXPECT_CALL(*surface_manager.get(), DestroySurface).Times(1);
1272
1273 modifier.SetSurfaceManager(std::move(surface_manager));
1274 view.SetEngine(engine.get());
1275
1276 view.CreateRenderSurface();
1277 }

References flutter::FlutterWindowsView::CreateRenderSurface(), and flutter::FlutterWindowsView::SetEngine().

## ◆ TEST() [70/166]

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

Definition at line 251 of file flutter_windows_view_unittests.cc.

251 {
252 std::unique_ptr<FlutterWindowsEngine> engine = GetTestEngine();
253
254 test_response = false;
255
256 auto window_binding_handler =
257 std::make_unique<NiceMock<MockWindowBindingHandler>>();
258 FlutterWindowsView view(std::move(window_binding_handler));
259 view.SetEngine(engine.get());
260
261 view.OnKey(kVirtualKeyA, kScanCodeKeyA, WM_KEYDOWN, 'a', false, false,
262 [](bool handled) {});
263
264 EXPECT_EQ(key_event_logs.size(), 2);
265 EXPECT_EQ(key_event_logs[0], kKeyEventFromEmbedder);
266 EXPECT_EQ(key_event_logs[1], kKeyEventFromChannel);
267
268 key_event_logs.clear();
269 }

References kScanCodeKeyA, and kVirtualKeyA.

## ◆ TEST() [71/166]

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

Definition at line 590 of file flutter_windows_view_unittests.cc.

590 {
591 std::unique_ptr<FlutterWindowsEngine> engine = GetTestEngine();
592 EngineModifier modifier(engine.get());
593 modifier.embedder_api().UpdateSemanticsEnabled =
594 [](FLUTTER_API_SYMBOL(FlutterEngine) engine, bool enabled) {
595 return kSuccess;
596 };
597
598 auto window_binding_handler =
599 std::make_unique<NiceMock<MockWindowBindingHandler>>();
600 FlutterWindowsView view(std::move(window_binding_handler));
601 view.SetEngine(engine.get());
602
603 // Enable semantics to instantiate accessibility bridge.
604 view.OnUpdateSemanticsEnabled(true);
605
606 auto bridge = view.accessibility_bridge().lock();
607 ASSERT_TRUE(bridge);
608
609 // Add root node.
610 FlutterSemanticsNode2 node1{sizeof(FlutterSemanticsNode2), 1};
611 std::vector<int32_t> node1_children{2};
612 node1.child_count = node1_children.size();
613 node1.children_in_traversal_order = node1_children.data();
614 node1.children_in_hit_test_order = node1_children.data();
615
616 FlutterSemanticsNode2 node2{sizeof(FlutterSemanticsNode2), 2};
617 node2.label = "prefecture";
618 node2.value = "Kyoto";
619
620 bridge->AddFlutterSemanticsNodeUpdate(node1);
621 bridge->AddFlutterSemanticsNodeUpdate(node2);
622 bridge->CommitUpdates();
623
624 // Look up the root windows node delegate.
625 auto root_delegate = bridge->GetFlutterPlatformNodeDelegateFromID(1).lock();
626 ASSERT_TRUE(root_delegate);
627 EXPECT_EQ(root_delegate->GetChildCount(), 1);
628
629 // Look up the child node delegate
630 auto child_delegate = bridge->GetFlutterPlatformNodeDelegateFromID(2).lock();
631 ASSERT_TRUE(child_delegate);
632 EXPECT_EQ(child_delegate->GetChildCount(), 0);
633
634 // Ensure a node with ID 0 does not exist.
635 auto fake_delegate = bridge->GetFlutterPlatformNodeDelegateFromID(0).lock();
636 ASSERT_FALSE(fake_delegate);
637
638 // Get the root's native IAccessible object.
639 IAccessible* node1_accessible = root_delegate->GetNativeViewAccessible();
640 ASSERT_TRUE(node1_accessible != nullptr);
641
642 // Property lookups will be made against this node itself.
643 VARIANT varchild{};
644 varchild.vt = VT_I4;
645 varchild.lVal = CHILDID_SELF;
646
647 // Verify node type is a group.
648 VARIANT varrole{};
649 varrole.vt = VT_I4;
650 ASSERT_EQ(node1_accessible->get_accRole(varchild, &varrole), S_OK);
651 EXPECT_EQ(varrole.lVal, ROLE_SYSTEM_GROUPING);
652
653 // Verify child count.
654 long node1_child_count = 0;
655 ASSERT_EQ(node1_accessible->get_accChildCount(&node1_child_count), S_OK);
656 EXPECT_EQ(node1_child_count, 1);
657
658 {
659 // Look up first child of node1 (node0), a static text node.
660 varchild.lVal = 1;
661 IDispatch* node2_dispatch = nullptr;
662 ASSERT_EQ(node1_accessible->get_accChild(varchild, &node2_dispatch), S_OK);
663 ASSERT_TRUE(node2_dispatch != nullptr);
664 IAccessible* node2_accessible = nullptr;
665 ASSERT_EQ(node2_dispatch->QueryInterface(
666 IID_IAccessible, reinterpret_cast<void**>(&node2_accessible)),
667 S_OK);
668 ASSERT_TRUE(node2_accessible != nullptr);
669
670 // Verify node name matches our label.
671 varchild.lVal = CHILDID_SELF;
672 BSTR bname = nullptr;
673 ASSERT_EQ(node2_accessible->get_accName(varchild, &bname), S_OK);
674 std::string name(_com_util::ConvertBSTRToString(bname));
675 EXPECT_EQ(name, "prefecture");
676
677 // Verify node value matches.
678 BSTR bvalue = nullptr;
679 ASSERT_EQ(node2_accessible->get_accValue(varchild, &bvalue), S_OK);
680 std::string value(_com_util::ConvertBSTRToString(bvalue));
681 EXPECT_EQ(value, "Kyoto");
682
683 // Verify node type is static text.
684 VARIANT varrole{};
685 varrole.vt = VT_I4;
686 ASSERT_EQ(node2_accessible->get_accRole(varchild, &varrole), S_OK);
687 EXPECT_EQ(varrole.lVal, ROLE_SYSTEM_STATICTEXT);
688
689 // Verify the parent node is the root.
690 IDispatch* parent_dispatch;
691 node2_accessible->get_accParent(&parent_dispatch);
692 IAccessible* parent_accessible;
693 ASSERT_EQ(
694 parent_dispatch->QueryInterface(
695 IID_IAccessible, reinterpret_cast<void**>(&parent_accessible)),
696 S_OK);
697 EXPECT_EQ(parent_accessible, node1_accessible);
698 }
699 }

## ◆ TEST() [72/166]

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

Definition at line 231 of file flutter_windows_view_unittests.cc.

231 {
232 std::unique_ptr<MockFlutterWindowsEngine> engine =
233 std::make_unique<MockFlutterWindowsEngine>();
234 auto window_binding_handler =
235 std::make_unique<NiceMock<MockWindowBindingHandler>>();
236 std::unique_ptr<MockAngleSurfaceManager> surface_manager =
237 std::make_unique<MockAngleSurfaceManager>();
238
239 EngineModifier modifier(engine.get());
240 FlutterWindowsView view(std::move(window_binding_handler));
241
242 // The engine must be stopped before the surface can be destroyed.
243 InSequence s;
244 EXPECT_CALL(*engine.get(), Stop).Times(1);
245 EXPECT_CALL(*surface_manager.get(), DestroySurface).Times(1);
246
247 modifier.SetSurfaceManager(std::move(surface_manager));
248 view.SetEngine(engine.get());
249 }

References flutter::FlutterWindowsView::SetEngine().

## ◆ TEST() [73/166]

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

Definition at line 127 of file flutter_windows_view_unittests.cc.

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

## ◆ TEST() [74/166]

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

Definition at line 1030 of file flutter_windows_view_unittests.cc.

1030 {
1031 std::unique_ptr<FlutterWindowsEngine> engine = GetTestEngine();
1032 EngineModifier modifier(engine.get());
1033 modifier.embedder_api().UpdateSemanticsEnabled =
1034 [](FLUTTER_API_SYMBOL(FlutterEngine) engine, bool enabled) {
1035 return kSuccess;
1036 };
1037
1038 auto window_binding_handler =
1039 std::make_unique<NiceMock<MockWindowBindingHandler>>();
1040 FlutterWindowsView view(std::move(window_binding_handler));
1041 view.SetEngine(engine.get());
1042
1043 // Enable semantics to instantiate accessibility bridge.
1044 view.OnUpdateSemanticsEnabled(true);
1045
1046 auto bridge = view.accessibility_bridge().lock();
1047 ASSERT_TRUE(bridge);
1048
1049 FlutterSemanticsNode2 root{sizeof(FlutterSemanticsNode2), 0};
1050 root.id = 0;
1051 root.label = "root";
1052 root.hint = "";
1053 root.value = "";
1054 root.increased_value = "";
1055 root.decreased_value = "";
1056 root.child_count = 0;
1057 root.custom_accessibility_actions_count = 0;
1058 root.flags = static_cast<FlutterSemanticsFlag>(
1059 FlutterSemanticsFlag::kFlutterSemanticsFlagHasToggledState |
1060 FlutterSemanticsFlag::kFlutterSemanticsFlagIsToggled);
1061 bridge->AddFlutterSemanticsNodeUpdate(root);
1062
1063 bridge->CommitUpdates();
1064
1065 {
1066 auto root_node = bridge->GetFlutterPlatformNodeDelegateFromID(0).lock();
1067 EXPECT_EQ(root_node->GetData().role, ax::mojom::Role::kSwitch);
1068 EXPECT_EQ(root_node->GetData().GetCheckedState(),
1069 ax::mojom::CheckedState::kTrue);
1070
1071 // Get the IAccessible for the root node.
1072 IAccessible* native_view = root_node->GetNativeViewAccessible();
1073 ASSERT_TRUE(native_view != nullptr);
1074
1075 // Look up against the node itself (not one of its children).
1076 VARIANT varchild = {};
1077 varchild.vt = VT_I4;
1078
1079 varchild.lVal = CHILDID_SELF;
1080 VARIANT varrole = {};
1081
1082 // Verify the role of the switch is CHECKBUTTON
1083 ASSERT_EQ(native_view->get_accRole(varchild, &varrole), S_OK);
1084 ASSERT_EQ(varrole.lVal, ROLE_SYSTEM_CHECKBUTTON);
1085
1086 // Verify the switch is pressed.
1087 VARIANT native_state = {};
1088 ASSERT_TRUE(SUCCEEDED(native_view->get_accState(varchild, &native_state)));
1089 EXPECT_TRUE(native_state.lVal & STATE_SYSTEM_PRESSED);
1090 EXPECT_TRUE(native_state.lVal & STATE_SYSTEM_CHECKED);
1091
1092 // Test similarly on UIA node.
1093 IRawElementProviderSimple* uia_node;
1094 native_view->QueryInterface(IID_PPV_ARGS(&uia_node));
1095 ASSERT_EQ(uia_node->GetPropertyValue(UIA_ControlTypePropertyId, &varrole),
1096 S_OK);
1097 EXPECT_EQ(varrole.lVal, UIA_ButtonControlTypeId);
1098 ASSERT_EQ(uia_node->GetPropertyValue(UIA_ToggleToggleStatePropertyId,
1099 &native_state),
1100 S_OK);
1101 EXPECT_EQ(native_state.lVal, ToggleState_On);
1102 ASSERT_EQ(
1103 uia_node->GetPropertyValue(UIA_AriaPropertiesPropertyId, &native_state),
1104 S_OK);
1105 EXPECT_NE(std::wcsstr(native_state.bstrVal, L"pressed=true"), nullptr);
1106 }
1107
1108 // Test unpressed too.
1109 root.flags = static_cast<FlutterSemanticsFlag>(
1110 FlutterSemanticsFlag::kFlutterSemanticsFlagHasToggledState);
1111 bridge->AddFlutterSemanticsNodeUpdate(root);
1112 bridge->CommitUpdates();
1113
1114 {
1115 auto root_node = bridge->GetFlutterPlatformNodeDelegateFromID(0).lock();
1116 EXPECT_EQ(root_node->GetData().role, ax::mojom::Role::kSwitch);
1117 EXPECT_EQ(root_node->GetData().GetCheckedState(),
1118 ax::mojom::CheckedState::kFalse);
1119
1120 // Get the IAccessible for the root node.
1121 IAccessible* native_view = root_node->GetNativeViewAccessible();
1122 ASSERT_TRUE(native_view != nullptr);
1123
1124 // Look up against the node itself (not one of its children).
1125 VARIANT varchild = {};
1126 varchild.vt = VT_I4;
1127
1128 // Verify the switch is not pressed.
1129 varchild.lVal = CHILDID_SELF;
1130 VARIANT native_state = {};
1131 ASSERT_TRUE(SUCCEEDED(native_view->get_accState(varchild, &native_state)));
1132 EXPECT_FALSE(native_state.lVal & STATE_SYSTEM_PRESSED);
1133 EXPECT_FALSE(native_state.lVal & STATE_SYSTEM_CHECKED);
1134
1135 // Test similarly on UIA node.
1136 IRawElementProviderSimple* uia_node;
1137 native_view->QueryInterface(IID_PPV_ARGS(&uia_node));
1138 ASSERT_EQ(uia_node->GetPropertyValue(UIA_ToggleToggleStatePropertyId,
1139 &native_state),
1140 S_OK);
1141 EXPECT_EQ(native_state.lVal, ToggleState_Off);
1142 ASSERT_EQ(
1143 uia_node->GetPropertyValue(UIA_AriaPropertiesPropertyId, &native_state),
1144 S_OK);
1145 EXPECT_NE(std::wcsstr(native_state.bstrVal, L"pressed=false"), nullptr);
1146 }
1147 }

## ◆ TEST() [75/166]

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

Definition at line 1149 of file flutter_windows_view_unittests.cc.

1149 {
1150 std::unique_ptr<FlutterWindowsEngine> engine = GetTestEngine();
1151 EngineModifier modifier(engine.get());
1152 modifier.embedder_api().UpdateSemanticsEnabled =
1153 [](FLUTTER_API_SYMBOL(FlutterEngine) engine, bool enabled) {
1154 return kSuccess;
1155 };
1156
1157 auto window_binding_handler =
1158 std::make_unique<NiceMock<MockWindowBindingHandler>>();
1159 FlutterWindowsView view(std::move(window_binding_handler));
1160 view.SetEngine(engine.get());
1161
1162 // Enable semantics to instantiate accessibility bridge.
1163 view.OnUpdateSemanticsEnabled(true);
1164
1165 auto bridge = view.accessibility_bridge().lock();
1166 ASSERT_TRUE(bridge);
1167
1168 FlutterSemanticsNode2 root{sizeof(FlutterSemanticsNode2), 0};
1169 root.id = 0;
1170 root.label = "root";
1171 root.hint = "";
1172 root.value = "";
1173 root.increased_value = "";
1174 root.decreased_value = "";
1175 root.tooltip = "tooltip";
1176 root.child_count = 0;
1177 root.custom_accessibility_actions_count = 0;
1178 root.flags = static_cast<FlutterSemanticsFlag>(
1179 FlutterSemanticsFlag::kFlutterSemanticsFlagIsTextField);
1180 bridge->AddFlutterSemanticsNodeUpdate(root);
1181
1182 bridge->CommitUpdates();
1183 auto root_node = bridge->GetFlutterPlatformNodeDelegateFromID(0).lock();
1184 std::string tooltip = root_node->GetData().GetStringAttribute(
1185 ax::mojom::StringAttribute::kTooltip);
1186 EXPECT_EQ(tooltip, "tooltip");
1187
1188 // Check that MSAA name contains the tooltip.
1189 IAccessible* native_view = bridge->GetFlutterPlatformNodeDelegateFromID(0)
1190 .lock()
1191 ->GetNativeViewAccessible();
1192 VARIANT varchild = {.vt = VT_I4, .lVal = CHILDID_SELF};
1193 BSTR bname;
1194 ASSERT_EQ(native_view->get_accName(varchild, &bname), S_OK);
1195 EXPECT_NE(std::wcsstr(bname, L"tooltip"), nullptr);
1196
1197 // Check that UIA help text is equal to the tooltip.
1198 IRawElementProviderSimple* uia_node;
1199 native_view->QueryInterface(IID_PPV_ARGS(&uia_node));
1200 VARIANT varname{};
1201 ASSERT_EQ(uia_node->GetPropertyValue(UIA_HelpTextPropertyId, &varname), S_OK);
1202 std::string uia_tooltip = _com_util::ConvertBSTRToString(varname.bstrVal);
1203 EXPECT_EQ(uia_tooltip, "tooltip");
1204 }

## ◆ TEST() [76/166]

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

Definition at line 1363 of file flutter_windows_view_unittests.cc.

1363 {
1364 std::unique_ptr<MockFlutterWindowsEngine> engine =
1365 std::make_unique<MockFlutterWindowsEngine>();
1366 auto window_binding_handler =
1367 std::make_unique<NiceMock<MockWindowBindingHandler>>();
1368 auto windows_proc_table = std::make_shared<MockWindowsProcTable>();
1369 std::unique_ptr<MockAngleSurfaceManager> surface_manager =
1370 std::make_unique<MockAngleSurfaceManager>();
1371
1372 EXPECT_CALL(*engine.get(), running).WillRepeatedly(Return(true));
1373
1374 EXPECT_CALL(*engine.get(), PostRasterThreadTask)
1375 .WillRepeatedly([](fml::closure callback) {
1376 callback();
1377 return true;
1378 });
1379
1380 EXPECT_CALL(*windows_proc_table.get(), DwmIsCompositionEnabled)
1381 .WillOnce(Return(false))
1382 .WillOnce(Return(true));
1383
1384 EXPECT_CALL(*surface_manager.get(), ClearCurrent).Times(0);
1385
1386 EngineModifier modifier(engine.get());
1387 FlutterWindowsView view(std::move(window_binding_handler),
1388 std::move(windows_proc_table));
1389
1390 InSequence s;
1391 EXPECT_CALL(*surface_manager.get(), SetVSyncEnabled(true)).Times(1);
1392 EXPECT_CALL(*surface_manager.get(), SetVSyncEnabled(false)).Times(1);
1393
1394 EXPECT_CALL(*engine.get(), Stop).Times(1);
1395 EXPECT_CALL(*surface_manager.get(), DestroySurface).Times(1);
1396
1397 modifier.SetSurfaceManager(std::move(surface_manager));
1398 view.SetEngine(engine.get());
1399
1400 view.GetEngine()->OnDwmCompositionChanged();
1401 view.GetEngine()->OnDwmCompositionChanged();
1402 }

References callback, flutter::FlutterWindowsView::GetEngine(), flutter::FlutterWindowsEngine::OnDwmCompositionChanged(), and flutter::FlutterWindowsView::SetEngine().

## ◆ TEST() [77/166]

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

Definition at line 860 of file flutter_windows_view_unittests.cc.

860 {
861 std::unique_ptr<FlutterWindowsEngine> engine = GetTestEngine();
862 EngineModifier modifier(engine.get());
863
864 FlutterWindowsView view(std::make_unique<flutter::FlutterWindow>(100, 100));
865 view.SetEngine(engine.get());
866
867 bool schedule_frame_called = false;
868 modifier.embedder_api().ScheduleFrame =
869 MOCK_ENGINE_PROC(ScheduleFrame, ([&schedule_frame_called](auto engine) {
870 schedule_frame_called = true;
871 return kSuccess;
872 }));
873
874 view.OnWindowRepaint();
875 EXPECT_TRUE(schedule_frame_called);
876 }

References flutter::FlutterWindowsView::OnWindowRepaint(), and flutter::FlutterWindowsView::SetEngine().

## ◆ TEST() [78/166]

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

Definition at line 812 of file flutter_windows_view_unittests.cc.

812 {
813 std::unique_ptr<FlutterWindowsEngine> engine = GetTestEngine();
814 EngineModifier modifier(engine.get());
815
816 auto window_binding_handler =
817 std::make_unique<NiceMock<MockWindowBindingHandler>>();
818 auto windows_proc_table = std::make_shared<MockWindowsProcTable>();
819 std::unique_ptr<MockAngleSurfaceManager> surface_manager =
820 std::make_unique<MockAngleSurfaceManager>();
821
822 EXPECT_CALL(*windows_proc_table.get(), DwmIsCompositionEnabled)
823 .WillOnce(Return(true));
824 EXPECT_CALL(
825 *surface_manager.get(),
826 ResizeSurface(_, /*width=*/500, /*height=*/500, /*enable_vsync=*/false))
827 .Times(1);
828 EXPECT_CALL(*surface_manager.get(), DestroySurface).Times(1);
829
830 FlutterWindowsView view(std::move(window_binding_handler),
831 std::move(windows_proc_table));
832 modifier.SetSurfaceManager(std::move(surface_manager));
833 view.SetEngine(engine.get());
834
835 fml::AutoResetWaitableEvent metrics_sent_latch;
836 modifier.embedder_api().SendWindowMetricsEvent = MOCK_ENGINE_PROC(
837 SendWindowMetricsEvent,
838 ([&metrics_sent_latch](auto engine,
839 const FlutterWindowMetricsEvent* event) {
840 metrics_sent_latch.Signal();
841 return kSuccess;
842 }));
843
844 fml::AutoResetWaitableEvent resized_latch;
845 std::thread([&resized_latch, &view]() {
846 // Start the window resize. This sends the new window metrics
847 // and then blocks until another thread completes the window resize.
848 view.OnWindowSizeChanged(500, 500);
849 resized_latch.Signal();
850 }).detach();
851
852 // Wait until the platform thread has started the window resize.
853 metrics_sent_latch.Wait();
854
855 // Complete the window resize by requesting a buffer with the new window size.
856 view.GetFrameBufferId(500, 500);
857 resized_latch.Wait();
858 }

References flutter::FlutterWindowsView::GetFrameBufferId(), flutter::FlutterWindowsView::OnWindowSizeChanged(), and flutter::FlutterWindowsView::SetEngine().

## ◆ TEST() [79/166]

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

Definition at line 304 of file flutter_window_unittests.cc.

304 {
305 MockFlutterWindow win32window;
306
307 EXPECT_EQ(win32window.GetNativeViewAccessible(), nullptr);
308 }

## ◆ TEST() [80/166]

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

Definition at line 312 of file flutter_window_unittests.cc.

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

References message.

## ◆ TEST() [81/166]

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

Definition at line 374 of file flutter_window_unittests.cc.

374 {
375 MockFlutterWindow win32window;
376 EXPECT_CALL(win32window, GetWindowHandle)
377 .WillRepeatedly(Return(reinterpret_cast<HWND>(1)));
378 EXPECT_CALL(win32window, OnWindowStateEvent)
379 .WillRepeatedly([&](WindowStateEvent event) {
380 win32window.FlutterWindow::OnWindowStateEvent(event);
381 });
382 EXPECT_CALL(win32window, OnResize).Times(1);
383
384 // Restore
385 win32window.InjectWindowMessage(WM_SIZE, 0, MAKEWORD(1, 1));
386
387 // Focus
388 win32window.InjectWindowMessage(WM_SETFOCUS, 0, 0);
389
390 MockWindowBindingHandlerDelegate delegate;
391 bool focused = false;
392 bool restored = false;
393 EXPECT_CALL(delegate, OnWindowStateEvent)
394 .WillRepeatedly([&](HWND hwnd, WindowStateEvent event) {
395 if (event == WindowStateEvent::kFocus) {
396 focused = true;
397 } else if (event == WindowStateEvent::kShow) {
398 restored = true;
399 }
400 });
401
402 win32window.SetView(&delegate);
403 EXPECT_TRUE(focused);
404 EXPECT_TRUE(restored);
405 }

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

## ◆ TEST() [82/166]

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

Definition at line 113 of file flutter_window_unittests.cc.

113 {
114 FlutterWindowTest window(800, 600);
115 ASSERT_TRUE(TRUE);
116 }

## ◆ TEST() [83/166]

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

Definition at line 342 of file flutter_window_unittests.cc.

342 {
343 MockFlutterWindow win32window;
344 EXPECT_CALL(win32window, GetWindowHandle)
345 .WillRepeatedly(Return(reinterpret_cast<HWND>(1)));
346 MockWindowBindingHandlerDelegate delegate;
347
348 WindowStateEvent last_event;
349 EXPECT_CALL(delegate, OnWindowStateEvent)
350 .WillRepeatedly([&last_event](HWND hwnd, WindowStateEvent event) {
351 last_event = event;
352 });
353 EXPECT_CALL(win32window, OnWindowStateEvent)
354 .WillRepeatedly([&](WindowStateEvent event) {
355 win32window.FlutterWindow::OnWindowStateEvent(event);
356 });
357 EXPECT_CALL(win32window, OnResize).Times(AnyNumber());
358
359 win32window.SetView(&delegate);
360
361 win32window.InjectWindowMessage(WM_SIZE, 0, 0);
362 EXPECT_EQ(last_event, WindowStateEvent::kHide);
363
364 win32window.InjectWindowMessage(WM_SIZE, 0, MAKEWORD(1, 1));
365 EXPECT_EQ(last_event, WindowStateEvent::kShow);
366
367 win32window.InjectWindowMessage(WM_SETFOCUS, 0, 0);
368 EXPECT_EQ(last_event, WindowStateEvent::kFocus);
369
370 win32window.InjectWindowMessage(WM_KILLFOCUS, 0, 0);
371 EXPECT_EQ(last_event, WindowStateEvent::kUnfocus);
372 }

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

## ◆ TEST() [84/166]

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

Definition at line 118 of file flutter_window_unittests.cc.

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

References flutter::FlutterWindow::OnBitmapSurfaceUpdated().

## ◆ TEST() [85/166]

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

Definition at line 148 of file flutter_window_unittests.cc.

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

## ◆ TEST() [86/166]

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

Definition at line 135 of file flutter_window_unittests.cc.

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

## ◆ TEST() [87/166]

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

Definition at line 159 of file flutter_window_unittests.cc.

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

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

## ◆ TEST() [88/166]

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

Definition at line 260 of file flutter_window_unittests.cc.

260 {
261 MockFlutterWindow win32window;
262 MockWindowBindingHandlerDelegate delegate;
263 EXPECT_CALL(win32window, OnWindowStateEvent).Times(AnyNumber());
264 win32window.SetView(&delegate);
265
266 ON_CALL(win32window, GetScrollOffsetMultiplier())
267 .WillByDefault(Return(120.0f));
268 EXPECT_CALL(win32window, GetScrollOffsetMultiplier()).Times(1);
269
270 EXPECT_CALL(delegate,
271 OnScroll(_, _, 0, 0, 120.0f, kFlutterPointerDeviceKindMouse,
272 kDefaultPointerDeviceId))
273 .Times(1);
274
275 win32window.OnScroll(0.0f, 0.0f, kFlutterPointerDeviceKindMouse,
276 kDefaultPointerDeviceId);
277 }

## ◆ TEST() [89/166]

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

Definition at line 290 of file flutter_window_unittests.cc.

290 {
291 MockFlutterWindow win32window;
292 MockWindowBindingHandlerDelegate delegate;
293 EXPECT_CALL(win32window, OnWindowStateEvent).Times(AnyNumber());
294 win32window.SetView(&delegate);
295
296 EXPECT_CALL(delegate, OnHighContrastChanged).Times(1);
297
298 win32window.InjectWindowMessage(WM_THEMECHANGED, 0, 0);
299 }

## ◆ TEST() [90/166]

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

Definition at line 279 of file flutter_window_unittests.cc.

279 {
280 MockFlutterWindow win32window;
281 MockWindowBindingHandlerDelegate delegate;
282 EXPECT_CALL(win32window, OnWindowStateEvent).Times(AnyNumber());
283 win32window.SetView(&delegate);
284
285 EXPECT_CALL(delegate, OnWindowRepaint()).Times(1);
286
287 win32window.InjectWindowMessage(WM_PAINT, 0, 0);
288 }

## ◆ TEST() [91/166]

flutter::testing::TEST | ( | FlutterWindowTest | ,
|  | PosthumousWindowMessage |
| ) |  |

Definition at line 407 of file flutter_window_unittests.cc.

407 {
408 MockWindowBindingHandlerDelegate delegate;
409 int msg_count = 0;
410 HWND hwnd;
411 EXPECT_CALL(delegate, OnWindowStateEvent)
412 .WillRepeatedly([&](HWND hwnd, WindowStateEvent event) { msg_count++; });
413
414 {
415 MockFlutterWindow win32window(false);
416 EXPECT_CALL(win32window, GetWindowHandle).WillRepeatedly([&]() {
417 return win32window.FlutterWindow::GetWindowHandle();
418 });
419 EXPECT_CALL(win32window, OnWindowStateEvent)
420 .WillRepeatedly([&](WindowStateEvent event) {
421 win32window.FlutterWindow::OnWindowStateEvent(event);
422 });
423 EXPECT_CALL(win32window, OnResize).Times(AnyNumber());
424 win32window.SetView(&delegate);
425 win32window.InitializeChild("Title", 1, 1);
426 hwnd = win32window.GetWindowHandle();
427 SendMessage(hwnd, WM_SIZE, 0, MAKEWORD(1, 1));
428 SendMessage(hwnd, WM_SETFOCUS, 0, 0);
429
430 // By setting this to zero before exiting the scope that contains
431 // win32window, and then checking its value afterwards, enforce that the
432 // window receive and process messages from its destructor without
433 // accessing out-of-bounds memory.
434 msg_count = 0;
435 }
436 EXPECT_GE(msg_count, 1);
437 }

## ◆ TEST() [92/166]

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 }

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

## ◆ TEST() [93/166]

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

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

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

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 }

References callback, kScanCodeKeyA, kVirtualKeyA, and user_data.

## ◆ TEST() [97/166]

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

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

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 }

References flutter::ConvertChar32ToUtf8().

## ◆ TEST() [100/166]

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 }

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

## ◆ TEST() [101/166]

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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 }

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

## ◆ TEST() [116/166]

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

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 }

References hook_history, and message.

## ◆ TEST() [118/166]

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

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 }

References flutter::EncodeUtf16().

## ◆ TEST() [120/166]

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

Definition at line 23 of file window_unittests.cc.

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

## ◆ TEST() [121/166]

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

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

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

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

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 }

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

## ◆ TEST() [126/166]

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

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

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

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

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

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

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

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

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

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 }

References type.

## ◆ TEST() [136/166]

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

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

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

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

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

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

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

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

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

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

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

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 }

References flutter::GetPreferredLanguageInfo().

## ◆ TEST() [148/166]

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 }

References flutter::GetPreferredLanguages().

## ◆ TEST() [149/166]

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 }

References flutter::GetUserTimeFormat().

## ◆ TEST() [150/166]

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 }

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

## ◆ TEST() [151/166]

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

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

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

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

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

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 }

References flutter::Prefer24HourTime().

## ◆ TEST() [157/166]

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

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

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

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

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

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

Definition at line 128 of file window_proc_delegate_manager_unittests.cc.

128 {
129 WindowProcDelegateManager manager;
130
131 bool called_a = false;
132 TestWindowProcDelegate delegate_a =
133 [&called_a](HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam) {
134 called_a = true;
135 return std::optional<LRESULT>(1);
136 };
137 bool called_b = false;
138 TestWindowProcDelegate delegate_b =
139 [&called_b](HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam) {
140 called_b = true;
141 return std::optional<LRESULT>(1);
142 };
143 manager.RegisterTopLevelWindowProcDelegate(TestWindowProcCallback,
144 &delegate_a);
145 manager.RegisterTopLevelWindowProcDelegate(TestWindowProcCallback2,
146 &delegate_b);
147 auto result = manager.OnTopLevelWindowProc(nullptr, 0, 0, 0);
148
149 EXPECT_TRUE(result);
150 // Exactly one of the handlers should be called since each will claim to have
151 // handled the message. Which one is unspecified, since the calling order is
152 // unspecified.
153 EXPECT_TRUE(called_a || called_b);
154 EXPECT_NE(called_a, called_b);
155 }

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

## ◆ TEST() [163/166]

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

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

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

Definition at line 157 of file window_proc_delegate_manager_unittests.cc.

157 {
158 WindowProcDelegateManager manager;
159
160 bool called = false;
161 TestWindowProcDelegate delegate = [&called](HWND hwnd, UINT message,
162 WPARAM wparam, LPARAM lparam) {
163 called = true;
164 return std::optional<LRESULT>();
165 };
166 manager.RegisterTopLevelWindowProcDelegate(TestWindowProcCallback, &delegate);
167 manager.UnregisterTopLevelWindowProcDelegate(TestWindowProcCallback);
168 auto result = manager.OnTopLevelWindowProc(nullptr, 0, 0, 0);
169
170 EXPECT_FALSE(result);
171 EXPECT_FALSE(called);
172 }

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

## ◆ TEST() [166/166]

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

Definition at line 27 of file flutter_windows_unittests.cc.

27 {
28 FlutterDesktopEngineProperties properties = {};
29 properties.assets_path = L"";
30 properties.icu_data_path = L"icudtl.dat";
31 auto engine = FlutterDesktopEngineCreate(&properties);
32 ASSERT_NE(engine, nullptr);
33 auto texture_registrar = FlutterDesktopEngineGetTextureRegistrar(engine);
34 EXPECT_NE(texture_registrar, nullptr);
35 FlutterDesktopEngineDestroy(engine);
36 }

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

## ◆ TEST_F() [1/119]

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

Definition at line 94 of file cursor_handler_unittests.cc.

94 {
95 UseEngineWithView();
96
97 TestBinaryMessenger messenger;
98 CursorHandler cursor_handler(&messenger, engine());
99
100 EXPECT_CALL(*window(), UpdateFlutterCursor("click")).Times(1);
101
102 bool success = false;
103 MethodResultFunctions<> result_handler(
104 [&success](const EncodableValue* result) {
105 success = true;
106 EXPECT_EQ(result, nullptr);
107 },
108 nullptr, nullptr);
109
110 SimulateCursorMessage(&messenger, kActivateSystemCursorMethod,
111 std::make_unique<EncodableValue>(EncodableMap{
112 {EncodableValue("device"), EncodableValue(0)},
113 {EncodableValue("kind"), EncodableValue("click")},
114 }),
115 &result_handler);
116
117 EXPECT_TRUE(success);
118 }

References kActivateSystemCursorMethod.

## ◆ TEST_F() [2/119]

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

Definition at line 120 of file cursor_handler_unittests.cc.

120 {
121 UseHeadlessEngine();
122
123 TestBinaryMessenger messenger;
124 CursorHandler cursor_handler(&messenger, engine());
125
126 bool error = false;
127 MethodResultFunctions<> result_handler(
128 nullptr,
129 [&error](const std::string& error_code, const std::string& error_message,
130 const EncodableValue* value) {
131 error = true;
132 EXPECT_EQ(error_message,
133 "Cursor is not available in Windows headless mode");
134 },
135 nullptr);
136
137 SimulateCursorMessage(&messenger, kActivateSystemCursorMethod,
138 std::make_unique<EncodableValue>(EncodableMap{
139 {EncodableValue("device"), EncodableValue(0)},
140 {EncodableValue("kind"), EncodableValue("click")},
141 }),
142 &result_handler);
143
144 EXPECT_TRUE(error);
145 }

References kActivateSystemCursorMethod.

## ◆ TEST_F() [3/119]

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

Definition at line 147 of file cursor_handler_unittests.cc.

147 {
148 UseEngineWithView();
149
150 TestBinaryMessenger messenger;
151 CursorHandler cursor_handler(&messenger, engine());
152
153 // Create a 4x4 raw BGRA test cursor buffer.
154 std::vector<uint8_t> buffer(4 * 4 * 4, 0);
155
156 bool success = false;
157 MethodResultFunctions<> result_handler(
158 [&success](const EncodableValue* result) {
159 success = true;
160 EXPECT_EQ(std::get<std::string>(*result), "hello");
161 },
162 nullptr, nullptr);
163
164 SimulateCursorMessage(&messenger, kCreateCustomCursorMethod,
165 std::make_unique<EncodableValue>(EncodableMap{
166 {EncodableValue("name"), EncodableValue("hello")},
167 {EncodableValue("buffer"), EncodableValue(buffer)},
168 {EncodableValue("width"), EncodableValue(4)},
169 {EncodableValue("height"), EncodableValue(4)},
170 {EncodableValue("hotX"), EncodableValue(0.0)},
171 {EncodableValue("hotY"), EncodableValue(0.0)},
172 }),
173 &result_handler);
174
175 EXPECT_TRUE(success);
176 }

References kCreateCustomCursorMethod.

## ◆ TEST_F() [4/119]

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

Definition at line 288 of file cursor_handler_unittests.cc.

288 {
289 UseEngineWithView();
290
291 TestBinaryMessenger messenger;
292 CursorHandler cursor_handler(&messenger, engine());
293
294 // Create a 4x4 raw BGRA test cursor buffer.
295 std::vector<uint8_t> buffer(4 * 4 * 4, 0);
296
297 bool success = false;
298 MethodResultFunctions<> create_result_handler(nullptr, nullptr, nullptr);
299 MethodResultFunctions<> delete_result_handler(
300 [&success](const EncodableValue* result) {
301 success = true;
302 EXPECT_EQ(result, nullptr);
303 },
304 nullptr, nullptr);
305
306 SimulateCursorMessage(&messenger, kCreateCustomCursorMethod,
307 std::make_unique<EncodableValue>(EncodableMap{
308 {EncodableValue("name"), EncodableValue("hello")},
309 {EncodableValue("buffer"), EncodableValue(buffer)},
310 {EncodableValue("width"), EncodableValue(4)},
311 {EncodableValue("height"), EncodableValue(4)},
312 {EncodableValue("hotX"), EncodableValue(0.0)},
313 {EncodableValue("hotY"), EncodableValue(0.0)},
314 }),
315 &create_result_handler);
316
317 SimulateCursorMessage(&messenger, kDeleteCustomCursorMethod,
318 std::make_unique<EncodableValue>(EncodableMap{
319 {EncodableValue("name"), EncodableValue("hello")},
320 }),
321 &delete_result_handler);
322
323 EXPECT_TRUE(success);
324 }

References kCreateCustomCursorMethod, and kDeleteCustomCursorMethod.

## ◆ TEST_F() [5/119]

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

Definition at line 326 of file cursor_handler_unittests.cc.

326 {
327 UseEngineWithView();
328
329 TestBinaryMessenger messenger;
330 CursorHandler cursor_handler(&messenger, engine());
331
332 bool success = false;
333 MethodResultFunctions<> result_handler(
334 [&success](const EncodableValue* result) {
335 success = true;
336 EXPECT_EQ(result, nullptr);
337 },
338 nullptr, nullptr);
339
340 SimulateCursorMessage(&messenger, kDeleteCustomCursorMethod,
341 std::make_unique<EncodableValue>(EncodableMap{
342 {EncodableValue("name"), EncodableValue("fake")},
343 }),
344 &result_handler);
345
346 EXPECT_TRUE(success);
347 }

References kDeleteCustomCursorMethod.

## ◆ TEST_F() [6/119]

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

Definition at line 178 of file cursor_handler_unittests.cc.

178 {
179 UseEngineWithView();
180
181 TestBinaryMessenger messenger;
182 CursorHandler cursor_handler(&messenger, engine());
183
184 // Create a 4x4 raw BGRA test cursor buffer.
185 std::vector<uint8_t> buffer(4 * 4 * 4, 0);
186
187 bool success = false;
188 MethodResultFunctions<> create_result_handler(nullptr, nullptr, nullptr);
189 MethodResultFunctions<> set_result_handler(
190 [&success](const EncodableValue* result) {
191 success = true;
192 EXPECT_EQ(result, nullptr);
193 },
194 nullptr, nullptr);
195
196 EXPECT_CALL(*window(), SetFlutterCursor(/*cursor=*/NotNull())).Times(1);
197
198 SimulateCursorMessage(&messenger, kCreateCustomCursorMethod,
199 std::make_unique<EncodableValue>(EncodableMap{
200 {EncodableValue("name"), EncodableValue("hello")},
201 {EncodableValue("buffer"), EncodableValue(buffer)},
202 {EncodableValue("width"), EncodableValue(4)},
203 {EncodableValue("height"), EncodableValue(4)},
204 {EncodableValue("hotX"), EncodableValue(0.0)},
205 {EncodableValue("hotY"), EncodableValue(0.0)},
206 }),
207 &create_result_handler);
208
209 SimulateCursorMessage(&messenger, kSetCustomCursorMethod,
210 std::make_unique<EncodableValue>(EncodableMap{
211 {EncodableValue("name"), EncodableValue("hello")},
212 }),
213 &set_result_handler);
214
215 EXPECT_TRUE(success);
216 }

References kCreateCustomCursorMethod, and kSetCustomCursorMethod.

## ◆ TEST_F() [7/119]

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

Definition at line 218 of file cursor_handler_unittests.cc.

218 {
219 UseHeadlessEngine();
220
221 TestBinaryMessenger messenger;
222 CursorHandler cursor_handler(&messenger, engine());
223
224 // Create a 4x4 raw BGRA test cursor buffer.
225 std::vector<uint8_t> buffer(4 * 4 * 4, 0);
226
227 bool error = false;
228 MethodResultFunctions<> create_result_handler(nullptr, nullptr, nullptr);
229 MethodResultFunctions<> set_result_handler(
230 nullptr,
231 [&error](const std::string& error_code, const std::string& error_message,
232 const EncodableValue* value) {
233 error = true;
234 EXPECT_EQ(error_message,
235 "Cursor is not available in Windows headless mode");
236 },
237 nullptr);
238
239 SimulateCursorMessage(&messenger, kCreateCustomCursorMethod,
240 std::make_unique<EncodableValue>(EncodableMap{
241 {EncodableValue("name"), EncodableValue("hello")},
242 {EncodableValue("buffer"), EncodableValue(buffer)},
243 {EncodableValue("width"), EncodableValue(4)},
244 {EncodableValue("height"), EncodableValue(4)},
245 {EncodableValue("hotX"), EncodableValue(0.0)},
246 {EncodableValue("hotY"), EncodableValue(0.0)},
247 }),
248 &create_result_handler);
249
250 SimulateCursorMessage(&messenger, kSetCustomCursorMethod,
251 std::make_unique<EncodableValue>(EncodableMap{
252 {EncodableValue("name"), EncodableValue("hello")},
253 }),
254 &set_result_handler);
255
256 EXPECT_TRUE(error);
257 }

References kCreateCustomCursorMethod, and kSetCustomCursorMethod.

## ◆ TEST_F() [8/119]

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

Definition at line 259 of file cursor_handler_unittests.cc.

259 {
260 UseEngineWithView();
261
262 TestBinaryMessenger messenger;
263 CursorHandler cursor_handler(&messenger, engine());
264
265 bool error = false;
266 MethodResultFunctions<> result_handler(
267 nullptr,
268 [&error](const std::string& error_code, const std::string& error_message,
269 const EncodableValue* value) {
270 error = true;
271 EXPECT_EQ(
272 error_message,
273 "The custom cursor identified by the argument key cannot be found");
274 },
275 nullptr);
276
277 EXPECT_CALL(*window(), SetFlutterCursor).Times(0);
278
279 SimulateCursorMessage(&messenger, kSetCustomCursorMethod,
280 std::make_unique<EncodableValue>(EncodableMap{
281 {EncodableValue("name"), EncodableValue("hello")},
282 }),
283 &result_handler);
284
285 EXPECT_TRUE(error);
286 }

References kSetCustomCursorMethod.

## ◆ TEST_F() [9/119]

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

Definition at line 493 of file flutter_windows_engine_unittests.cc.

493 {
494 FlutterWindowsEngineBuilder builder{GetContext()};
495 std::unique_ptr<FlutterWindowsEngine> engine = builder.Build();
496 EngineModifier modifier(engine.get());
497
498 MockEmbedderApiForKeyboard(modifier,
499 std::make_shared<MockKeyResponseController>());
500
501 engine->Run();
502
503 // Verify that destruction handlers don't overwrite each other.
504 int result1 = 0;
505 int result2 = 0;
506 engine->AddPluginRegistrarDestructionCallback(
507 [](FlutterDesktopPluginRegistrarRef ref) {
508 auto result = reinterpret_cast<int*>(ref);
509 *result = 1;
510 },
511 reinterpret_cast<FlutterDesktopPluginRegistrarRef>(&result1));
512 engine->AddPluginRegistrarDestructionCallback(
513 [](FlutterDesktopPluginRegistrarRef ref) {
514 auto result = reinterpret_cast<int*>(ref);
515 *result = 2;
516 },
517 reinterpret_cast<FlutterDesktopPluginRegistrarRef>(&result2));
518
519 engine->Stop();
520 EXPECT_EQ(result1, 1);
521 EXPECT_EQ(result2, 2);
522 }

## ◆ TEST_F() [10/119]

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

Definition at line 635 of file flutter_windows_engine_unittests.cc.

635 {
636 FlutterWindowsEngineBuilder builder{GetContext()};
637 builder.SetDartEntrypoint("alertPlatformChannel");
638
639 auto engine = builder.Build();
640 auto window_binding_handler =
641 std::make_unique<::testing::NiceMock<MockWindowBindingHandler>>();
642 ui::AXPlatformNodeDelegateBase parent_delegate;
643 AlertPlatformNodeDelegate delegate(parent_delegate);
644 EXPECT_CALL(*window_binding_handler, GetAlertDelegate)
645 .WillRepeatedly(Return(&delegate));
646 MockFlutterWindowsView view(std::move(window_binding_handler));
647 view.SetEngine(engine.get());
648
649 EngineModifier modifier(engine.get());
650 modifier.embedder_api().RunsAOTCompiledDartCode = []() { return false; };
651
652 auto binary_messenger =
653 std::make_unique<BinaryMessengerImpl>(engine->messenger());
654 binary_messenger->SetMessageHandler(
655 "semantics", [&engine](const uint8_t* message, size_t message_size,
656 BinaryReply reply) {
657 engine->UpdateSemanticsEnabled(true);
658 char response[] = "";
659 reply(reinterpret_cast<uint8_t*>(response), 0);
660 });
661
662 bool did_call = false;
663 EXPECT_CALL(view, NotifyWinEventWrapper)
664 .WillOnce([&did_call](ui::AXPlatformNodeWin* node,
665 ax::mojom::Event event) { did_call = true; });
666
667 engine->UpdateSemanticsEnabled(true);
668 engine->Run();
669
670 // Rely on timeout mechanism in CI.
671 while (!did_call) {
672 engine->task_runner()->ProcessTasks();
673 }
674 }

References message.

## ◆ TEST_F() [11/119]

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

Definition at line 921 of file flutter_windows_engine_unittests.cc.

921 {
922 FlutterWindowsEngineBuilder builder{GetContext()};
923
924 auto engine = builder.Build();
925 auto window_binding_handler =
926 std::make_unique<::testing::NiceMock<MockWindowBindingHandler>>();
927 MockFlutterWindowsView view(std::move(window_binding_handler));
928 view.SetEngine(engine.get());
929
930 EngineModifier modifier(engine.get());
931 modifier.embedder_api().RunsAOTCompiledDartCode = []() { return false; };
932 auto handler = std::make_unique<MockWindowsLifecycleManager>(engine.get());
933 EXPECT_CALL(*handler, IsLastWindowOfProcess).WillOnce(Return(false));
934 modifier.SetLifecycleManager(std::move(handler));
935 engine->lifecycle_manager()->BeginProcessingExit();
936
937 engine->lifecycle_manager()->ExternalWindowMessage(0, WM_CLOSE, 0, 0);
938 }

## ◆ TEST_F() [12/119]

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

Definition at line 940 of file flutter_windows_engine_unittests.cc.

940 {
941 FlutterWindowsEngineBuilder builder{GetContext()};
942
943 auto engine = builder.Build();
944 auto window_binding_handler =
945 std::make_unique<::testing::NiceMock<MockWindowBindingHandler>>();
946 MockFlutterWindowsView view(std::move(window_binding_handler));
947 view.SetEngine(engine.get());
948
949 EngineModifier modifier(engine.get());
950 modifier.embedder_api().RunsAOTCompiledDartCode = []() { return false; };
951 auto handler = std::make_unique<MockWindowsLifecycleManager>(engine.get());
952 EXPECT_CALL(*handler, SetLifecycleState(AppLifecycleState::kResumed))
953 .Times(1);
954 modifier.SetLifecycleManager(std::move(handler));
955 engine->Run();
956 }

References flutter::kResumed.

## ◆ TEST_F() [13/119]

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

Definition at line 1146 of file flutter_windows_engine_unittests.cc.

1146 {
1147 FlutterWindowsEngineBuilder builder{GetContext()};
1148 builder.SetDartEntrypoint("enableLifecycleToFrom");
1149
1150 auto engine = builder.Build();
1151 auto window_binding_handler =
1152 std::make_unique<::testing::NiceMock<MockWindowBindingHandler>>();
1153 MockFlutterWindowsView view(std::move(window_binding_handler));
1154 view.SetEngine(engine.get());
1155
1156 EngineModifier modifier(engine.get());
1157 modifier.embedder_api().RunsAOTCompiledDartCode = []() { return false; };
1158
1159 bool lifecycle_began = false;
1160 auto handler = std::make_unique<MockWindowsLifecycleManager>(engine.get());
1161 EXPECT_CALL(*handler, SetLifecycleState).Times(1);
1162 handler->begin_processing_callback = [&]() { lifecycle_began = true; };
1163 modifier.SetLifecycleManager(std::move(handler));
1164
1165 engine->Run();
1166
1167 while (!lifecycle_began) {
1168 engine->task_runner()->ProcessTasks();
1169 }
1170 }

## ◆ TEST_F() [14/119]

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

Definition at line 150 of file flutter_windows_engine_unittests.cc.

150 {
151 FlutterWindowsEngineBuilder builder{GetContext()};
152 std::unique_ptr<FlutterWindowsEngine> engine = builder.Build();
153 EngineModifier modifier(engine.get());
154 bool on_vsync_called = false;
155
156 modifier.embedder_api().GetCurrentTime =
157 MOCK_ENGINE_PROC(GetCurrentTime, ([]() -> uint64_t { return 1; }));
158 modifier.embedder_api().OnVsync = MOCK_ENGINE_PROC(
159 OnVsync,
160 ([&on_vsync_called, engine_instance = engine.get()](
161 FLUTTER_API_SYMBOL(FlutterEngine) engine, intptr_t baton,
162 uint64_t frame_start_time_nanos, uint64_t frame_target_time_nanos) {
163 EXPECT_EQ(baton, 1);
164 EXPECT_EQ(frame_start_time_nanos, 16600000);
165 EXPECT_EQ(frame_target_time_nanos, 33200000);
166 on_vsync_called = true;
167 return kSuccess;
168 }));
169 modifier.SetStartTime(0);
170 modifier.SetFrameInterval(16600000);
171
172 engine->OnVsync(1);
173
174 EXPECT_TRUE(on_vsync_called);
175 }

## ◆ TEST_F() [15/119]

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

Definition at line 447 of file flutter_windows_engine_unittests.cc.

447 {
448 FlutterWindowsEngineBuilder builder{GetContext()};
449 std::unique_ptr<FlutterWindowsEngine> engine = builder.Build();
450 EngineModifier modifier(engine.get());
451
452 bool called = false;
453 std::string message = "Hello";
454 modifier.embedder_api().DispatchSemanticsAction = MOCK_ENGINE_PROC(
455 DispatchSemanticsAction,
456 ([&called, &message](auto engine, auto target, auto action, auto data,
457 auto data_length) {
458 called = true;
459 EXPECT_EQ(target, 42);
460 EXPECT_EQ(action, kFlutterSemanticsActionDismiss);
461 EXPECT_EQ(memcmp(data, message.c_str(), message.size()), 0);
462 EXPECT_EQ(data_length, message.size());
463 return kSuccess;
464 }));
465
466 auto data = fml::MallocMapping::Copy(message.c_str(), message.size());
467 engine->DispatchSemanticsAction(42, kFlutterSemanticsActionDismiss,
468 std::move(data));
469 EXPECT_TRUE(called);
470 }

References action, and message.

## ◆ TEST_F() [16/119]

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

Definition at line 901 of file flutter_windows_engine_unittests.cc.

901 {
902 FlutterWindowsEngineBuilder builder{GetContext()};
903
904 auto engine = builder.Build();
905 auto window_binding_handler =
906 std::make_unique<::testing::NiceMock<MockWindowBindingHandler>>();
907 MockFlutterWindowsView view(std::move(window_binding_handler));
908 view.SetEngine(engine.get());
909
910 EngineModifier modifier(engine.get());
911 modifier.embedder_api().RunsAOTCompiledDartCode = []() { return false; };
912 auto handler = std::make_unique<MockWindowsLifecycleManager>(engine.get());
913 EXPECT_CALL(*handler, IsLastWindowOfProcess).WillOnce(Return(false));
914 modifier.SetLifecycleManager(std::move(handler));
915 engine->lifecycle_manager()->BeginProcessingExit();
916
917 engine->window_proc_delegate_manager()->OnTopLevelWindowProc(0, WM_CLOSE, 0,
918 0);
919 }

## ◆ TEST_F() [17/119]

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

Definition at line 1045 of file flutter_windows_engine_unittests.cc.

1045 {
1046 FlutterWindowsEngineBuilder builder{GetContext()};
1047 builder.SetDartEntrypoint("enableLifecycleTest");
1048 bool finished = false;
1049
1050 auto engine = builder.Build();
1051 auto window_binding_handler =
1052 std::make_unique<::testing::NiceMock<MockWindowBindingHandler>>();
1053 MockFlutterWindowsView view(std::move(window_binding_handler));
1054 view.SetEngine(engine.get());
1055
1056 EngineModifier modifier(engine.get());
1057 modifier.embedder_api().RunsAOTCompiledDartCode = []() { return false; };
1058 auto handler = std::make_unique<MockWindowsLifecycleManager>(engine.get());
1059 EXPECT_CALL(*handler, SetLifecycleState)
1060 .WillRepeatedly([handler_ptr = handler.get()](AppLifecycleState state) {
1061 handler_ptr->WindowsLifecycleManager::SetLifecycleState(state);
1062 });
1063 modifier.SetLifecycleManager(std::move(handler));
1064
1065 auto binary_messenger =
1066 std::make_unique<BinaryMessengerImpl>(engine->messenger());
1067 // Mark the test only as completed on receiving an inactive state message.
1068 binary_messenger->SetMessageHandler(
1069 "flutter/unittest", [&finished](const uint8_t* message,
1070 size_t message_size, BinaryReply reply) {
1071 std::string contents(message, message + message_size);
1072 EXPECT_NE(contents.find("AppLifecycleState.inactive"),
1073 std::string::npos);
1074 finished = true;
1075 char response[] = "";
1076 reply(reinterpret_cast<uint8_t*>(response), 0);
1077 });
1078
1079 engine->Run();
1080
1081 // Test that setting the state before enabling lifecycle does nothing.
1082 HWND hwnd = reinterpret_cast<HWND>(1);
1083 view.OnWindowStateEvent(hwnd, WindowStateEvent::kShow);
1084 view.OnWindowStateEvent(hwnd, WindowStateEvent::kHide);
1085 EXPECT_FALSE(finished);
1086
1087 // Test that we can set the state afterwards.
1088
1089 engine->lifecycle_manager()->BeginProcessingLifecycle();
1090 view.OnWindowStateEvent(hwnd, WindowStateEvent::kShow);
1091
1092 while (!finished) {
1093 engine->task_runner()->ProcessTasks();
1094 }
1095 }

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

## ◆ TEST_F() [18/119]

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

Definition at line 987 of file flutter_windows_engine_unittests.cc.

987 {
988 FlutterWindowsEngineBuilder builder{GetContext()};
989
990 auto engine = builder.Build();
991 auto window_binding_handler =
992 std::make_unique<::testing::NiceMock<MockWindowBindingHandler>>();
993 MockFlutterWindowsView view(std::move(window_binding_handler));
994 view.SetEngine(engine.get());
995
996 EngineModifier modifier(engine.get());
997 modifier.embedder_api().RunsAOTCompiledDartCode = []() { return false; };
998 // Sets lifecycle state to resumed.
999 engine->Run();
1000
1001 // Ensure HWND(1) is in the set of visible windows before hiding it.
1002 engine->ProcessExternalWindowMessage(reinterpret_cast<HWND>(1), WM_SHOWWINDOW,
1003 TRUE, NULL);
1004 engine->ProcessExternalWindowMessage(reinterpret_cast<HWND>(1), WM_SHOWWINDOW,
1005 FALSE, NULL);
1006
1007 EXPECT_EQ(engine->lifecycle_manager()->GetLifecycleState(),
1008 AppLifecycleState::kHidden);
1009 }

References flutter::kHidden.

## ◆ TEST_F() [19/119]

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

Definition at line 556 of file flutter_windows_engine_unittests.cc.

556 {
557 FlutterWindowsEngineBuilder builder{GetContext()};
558 std::unique_ptr<FlutterWindowsEngine> engine = builder.Build();
559 EXPECT_EQ(engine->GetExecutableName(), "flutter_windows_unittests.exe");
560 }

## ◆ TEST_F() [20/119]

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

Definition at line 1011 of file flutter_windows_engine_unittests.cc.

1011 {
1012 FlutterWindowsEngineBuilder builder{GetContext()};
1013 HWND outer = reinterpret_cast<HWND>(1);
1014 HWND inner = reinterpret_cast<HWND>(2);
1015
1016 auto engine = builder.Build();
1017 auto window_binding_handler =
1018 std::make_unique<::testing::NiceMock<MockWindowBindingHandler>>();
1019 MockFlutterWindowsView view(std::move(window_binding_handler));
1020 ON_CALL(view, GetWindowHandle).WillByDefault([=]() { return inner; });
1021 view.SetEngine(engine.get());
1022
1023 EngineModifier modifier(engine.get());
1024 modifier.embedder_api().RunsAOTCompiledDartCode = []() { return false; };
1025 // Sets lifecycle state to resumed.
1026 engine->Run();
1027
1028 // Show both top-level and Flutter window.
1029 engine->window_proc_delegate_manager()->OnTopLevelWindowProc(
1030 outer, WM_SHOWWINDOW, TRUE, NULL);
1031 view.OnWindowStateEvent(inner, WindowStateEvent::kShow);
1032 view.OnWindowStateEvent(inner, WindowStateEvent::kFocus);
1033
1034 EXPECT_EQ(engine->lifecycle_manager()->GetLifecycleState(),
1035 AppLifecycleState::kResumed);
1036
1037 // Hide Flutter window, but not top level window.
1038 view.OnWindowStateEvent(inner, WindowStateEvent::kHide);
1039
1040 // The top-level window is still visible, so we ought not enter hidden state.
1041 EXPECT_EQ(engine->lifecycle_manager()->GetLifecycleState(),
1042 AppLifecycleState::kInactive);
1043 }

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

## ◆ TEST_F() [21/119]

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

Definition at line 882 of file flutter_windows_engine_unittests.cc.

882 {
883 FlutterWindowsEngineBuilder builder{GetContext()};
884
885 auto engine = builder.Build();
886 auto window_binding_handler =
887 std::make_unique<::testing::NiceMock<MockWindowBindingHandler>>();
888 MockFlutterWindowsView view(std::move(window_binding_handler));
889 view.SetEngine(engine.get());
890
891 EngineModifier modifier(engine.get());
892 modifier.embedder_api().RunsAOTCompiledDartCode = []() { return false; };
893 auto handler = std::make_unique<MockWindowsLifecycleManager>(engine.get());
894 EXPECT_CALL(*handler, IsLastWindowOfProcess).Times(0);
895 modifier.SetLifecycleManager(std::move(handler));
896
897 engine->window_proc_delegate_manager()->OnTopLevelWindowProc(0, WM_CLOSE, 0,
898 0);
899 }

## ◆ TEST_F() [22/119]

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

Definition at line 1097 of file flutter_windows_engine_unittests.cc.

1097 {
1098 FlutterWindowsEngineBuilder builder{GetContext()};
1099 builder.SetDartEntrypoint("enableLifecycleToFrom");
1100 bool enabled_lifecycle = false;
1101 bool dart_responded = false;
1102
1103 auto engine = builder.Build();
1104 auto window_binding_handler =
1105 std::make_unique<::testing::NiceMock<MockWindowBindingHandler>>();
1106 MockFlutterWindowsView view(std::move(window_binding_handler));
1107 view.SetEngine(engine.get());
1108
1109 EngineModifier modifier(engine.get());
1110 modifier.embedder_api().RunsAOTCompiledDartCode = []() { return false; };
1111 auto handler = std::make_unique<MockWindowsLifecycleManager>(engine.get());
1112 EXPECT_CALL(*handler, SetLifecycleState)
1113 .WillRepeatedly([handler_ptr = handler.get()](AppLifecycleState state) {
1114 handler_ptr->WindowsLifecycleManager::SetLifecycleState(state);
1115 });
1116 handler->begin_processing_callback = [&]() { enabled_lifecycle = true; };
1117 modifier.SetLifecycleManager(std::move(handler));
1118
1119 auto binary_messenger =
1120 std::make_unique<BinaryMessengerImpl>(engine->messenger());
1121 binary_messenger->SetMessageHandler(
1122 "flutter/unittest",
1123 [&](const uint8_t* message, size_t message_size, BinaryReply reply) {
1124 std::string contents(message, message + message_size);
1125 EXPECT_NE(contents.find("AppLifecycleState."), std::string::npos);
1126 dart_responded = true;
1127 char response[] = "";
1128 reply(reinterpret_cast<uint8_t*>(response), 0);
1129 });
1130
1131 engine->Run();
1132
1133 while (!enabled_lifecycle) {
1134 engine->task_runner()->ProcessTasks();
1135 }
1136
1137 HWND hwnd = reinterpret_cast<HWND>(1);
1138 view.OnWindowStateEvent(hwnd, WindowStateEvent::kShow);
1139 view.OnWindowStateEvent(hwnd, WindowStateEvent::kHide);
1140
1141 while (!dart_responded) {
1142 engine->task_runner()->ProcessTasks();
1143 }
1144 }

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

## ◆ TEST_F() [23/119]

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

Definition at line 958 of file flutter_windows_engine_unittests.cc.

958 {
959 FlutterWindowsEngineBuilder builder{GetContext()};
960
961 auto engine = builder.Build();
962 auto window_binding_handler =
963 std::make_unique<::testing::NiceMock<MockWindowBindingHandler>>();
964 MockFlutterWindowsView view(std::move(window_binding_handler));
965 view.SetEngine(engine.get());
966
967 EngineModifier modifier(engine.get());
968 modifier.embedder_api().RunsAOTCompiledDartCode = []() { return false; };
969 engine->Run();
970
971 engine->window_proc_delegate_manager()->OnTopLevelWindowProc(
972 (HWND)1, WM_SIZE, SIZE_RESTORED, 0);
973 EXPECT_EQ(engine->lifecycle_manager()->GetLifecycleState(),
974 AppLifecycleState::kResumed);
975
976 engine->window_proc_delegate_manager()->OnTopLevelWindowProc(
977 (HWND)1, WM_SIZE, SIZE_MINIMIZED, 0);
978 EXPECT_EQ(engine->lifecycle_manager()->GetLifecycleState(),
979 AppLifecycleState::kHidden);
980
981 engine->window_proc_delegate_manager()->OnTopLevelWindowProc(
982 (HWND)1, WM_SIZE, SIZE_RESTORED, 0);
983 EXPECT_EQ(engine->lifecycle_manager()->GetLifecycleState(),
984 AppLifecycleState::kInactive);
985 }

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

## ◆ TEST_F() [24/119]

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

Definition at line 337 of file flutter_windows_engine_unittests.cc.

337 {
338 FlutterWindowsEngineBuilder builder{GetContext()};
339 builder.SetDartEntrypoint("hiPlatformChannels");
340
341 std::unique_ptr<FlutterWindowsEngine> engine = builder.Build();
342
343 EngineModifier modifier(engine.get());
344 modifier.embedder_api().RunsAOTCompiledDartCode = []() { return false; };
345
346 auto binary_messenger =
347 std::make_unique<BinaryMessengerImpl>(engine->messenger());
348
349 engine->Run();
350 bool did_call_callback = false;
351 bool did_call_reply = false;
352 bool did_call_dart_reply = false;
353 std::string channel = "hi";
354 std::unique_ptr<std::thread> reply_thread;
355 binary_messenger->SetMessageHandler(
356 channel,
357 [&did_call_callback, &did_call_dart_reply, &reply_thread](
358 const uint8_t* message, size_t message_size, BinaryReply reply) {
359 if (message_size == 5) {
360 EXPECT_EQ(message[0], static_cast<uint8_t>('h'));
361 reply_thread.reset(new std::thread([reply = std::move(reply)]() {
362 char response[] = {'b', 'y', 'e'};
363 reply(reinterpret_cast<uint8_t*>(response), 3);
364 }));
365 did_call_callback = true;
366 } else {
367 EXPECT_EQ(message_size, 3);
368 EXPECT_EQ(message[0], static_cast<uint8_t>('b'));
369 did_call_dart_reply = true;
370 }
371 });
372 char payload[] = {'h', 'e', 'l', 'l', 'o'};
373 binary_messenger->Send(
374 channel, reinterpret_cast<uint8_t*>(payload), 5,
375 [&did_call_reply](const uint8_t* reply, size_t reply_size) {
376 EXPECT_EQ(reply_size, 5);
377 EXPECT_EQ(reply[0], static_cast<uint8_t>('h'));
378 did_call_reply = true;
379 });
380 // Rely on timeout mechanism in CI.
381 while (!did_call_callback || !did_call_reply || !did_call_dart_reply) {
382 engine->task_runner()->ProcessTasks();
383 }
384 ASSERT_TRUE(reply_thread);
385 reply_thread->join();
386 }

References message.

## ◆ TEST_F() [25/119]

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

Definition at line 292 of file flutter_windows_engine_unittests.cc.

292 {
293 FlutterWindowsEngineBuilder builder{GetContext()};
294 builder.SetDartEntrypoint("hiPlatformChannels");
295
296 std::unique_ptr<FlutterWindowsEngine> engine = builder.Build();
297 EngineModifier modifier(engine.get());
298 modifier.embedder_api().RunsAOTCompiledDartCode = []() { return false; };
299
300 auto binary_messenger =
301 std::make_unique<BinaryMessengerImpl>(engine->messenger());
302
303 engine->Run();
304 bool did_call_callback = false;
305 bool did_call_reply = false;
306 bool did_call_dart_reply = false;
307 std::string channel = "hi";
308 binary_messenger->SetMessageHandler(
309 channel,
310 [&did_call_callback, &did_call_dart_reply](
311 const uint8_t* message, size_t message_size, BinaryReply reply) {
312 if (message_size == 5) {
313 EXPECT_EQ(message[0], static_cast<uint8_t>('h'));
314 char response[] = {'b', 'y', 'e'};
315 reply(reinterpret_cast<uint8_t*>(response), 3);
316 did_call_callback = true;
317 } else {
318 EXPECT_EQ(message_size, 3);
319 EXPECT_EQ(message[0], static_cast<uint8_t>('b'));
320 did_call_dart_reply = true;
321 }
322 });
323 char payload[] = {'h', 'e', 'l', 'l', 'o'};
324 binary_messenger->Send(
325 channel, reinterpret_cast<uint8_t*>(payload), 5,
326 [&did_call_reply](const uint8_t* reply, size_t reply_size) {
327 EXPECT_EQ(reply_size, 5);
328 EXPECT_EQ(reply[0], static_cast<uint8_t>('h'));
329 did_call_reply = true;
330 });
331 // Rely on timeout mechanism in CI.
332 while (!did_call_callback || !did_call_reply || !did_call_dart_reply) {
333 engine->task_runner()->ProcessTasks();
334 }
335 }

References message.

## ◆ TEST_F() [26/119]

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

Definition at line 602 of file flutter_windows_engine_unittests.cc.

602 {
603 FlutterWindowsEngineBuilder builder{GetContext()};
604 std::unique_ptr<FlutterWindowsEngine> engine = builder.Build();
605 EngineModifier modifier(engine.get());
606
607 modifier.embedder_api().PostRenderThreadTask = MOCK_ENGINE_PROC(
608 PostRenderThreadTask, ([](auto engine, auto callback, auto context) {
609 callback(context);
610 return kSuccess;
611 }));
612
613 bool called = false;
614 engine->PostRasterThreadTask([&called]() { called = true; });
615
616 EXPECT_TRUE(called);
617 }

References callback.

## ◆ TEST_F() [27/119]

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

Definition at line 34 of file flutter_windows_engine_unittests.cc.

34 {
35 FlutterWindowsEngineBuilder builder{GetContext()};
36 builder.AddDartEntrypointArgument("arg1");
37 builder.AddDartEntrypointArgument("arg2");
38
39 std::unique_ptr<FlutterWindowsEngine> engine = builder.Build();
40 EngineModifier modifier(engine.get());
41
42 // The engine should be run with expected configuration values.
43 bool run_called = false;
44 modifier.embedder_api().Run = MOCK_ENGINE_PROC(
45 Run, ([&run_called, engine_instance = engine.get()](
46 size_t version, const FlutterRendererConfig* config,
47 const FlutterProjectArgs* args, void* user_data,
48 FLUTTER_API_SYMBOL(FlutterEngine) * engine_out) {
49 run_called = true;
50 *engine_out = reinterpret_cast<FLUTTER_API_SYMBOL(FlutterEngine)>(1);
51
52 EXPECT_EQ(version, FLUTTER_ENGINE_VERSION);
53 EXPECT_NE(config, nullptr);
54 // We have an AngleSurfaceManager, so this should be using OpenGL.
55 EXPECT_EQ(config->type, kOpenGL);
56 EXPECT_EQ(user_data, engine_instance);
57 // Spot-check arguments.
58 EXPECT_NE(args->assets_path, nullptr);
59 EXPECT_NE(args->icu_data_path, nullptr);
60 EXPECT_EQ(args->dart_entrypoint_argc, 2U);
61 EXPECT_EQ(strcmp(args->dart_entrypoint_argv[0], "arg1"), 0);
62 EXPECT_EQ(strcmp(args->dart_entrypoint_argv[1], "arg2"), 0);
63 EXPECT_NE(args->platform_message_callback, nullptr);
64 EXPECT_NE(args->custom_task_runners, nullptr);
65 EXPECT_NE(args->custom_task_runners->thread_priority_setter, nullptr);
66 EXPECT_EQ(args->custom_dart_entrypoint, nullptr);
67 EXPECT_NE(args->vsync_callback, nullptr);
68 EXPECT_EQ(args->update_semantics_callback, nullptr);
69 EXPECT_NE(args->update_semantics_callback2, nullptr);
70 EXPECT_EQ(args->update_semantics_node_callback, nullptr);
71 EXPECT_EQ(args->update_semantics_custom_action_callback, nullptr);
72
73 args->custom_task_runners->thread_priority_setter(
74 FlutterThreadPriority::kRaster);
75 EXPECT_EQ(GetThreadPriority(GetCurrentThread()),
76 THREAD_PRIORITY_ABOVE_NORMAL);
77 return kSuccess;
78 }));
79 // Accessibility updates must do nothing when the embedder engine is mocked
80 modifier.embedder_api().UpdateAccessibilityFeatures = MOCK_ENGINE_PROC(
81 UpdateAccessibilityFeatures,
82 [](FLUTTER_API_SYMBOL(FlutterEngine) engine,
83 FlutterAccessibilityFeature flags) { return kSuccess; });
84
85 // It should send locale info.
86 bool update_locales_called = false;
87 modifier.embedder_api().UpdateLocales = MOCK_ENGINE_PROC(
88 UpdateLocales,
89 ([&update_locales_called](auto engine, const FlutterLocale** locales,
90 size_t locales_count) {
91 update_locales_called = true;
92
93 EXPECT_GT(locales_count, 0);
94 EXPECT_NE(locales, nullptr);
95
96 return kSuccess;
97 }));
98
99 // And it should send initial settings info.
100 bool settings_message_sent = false;
101 modifier.embedder_api().SendPlatformMessage = MOCK_ENGINE_PROC(
102 SendPlatformMessage,
103 ([&settings_message_sent](auto engine, auto message) {
104 if (std::string(message->channel) == std::string("flutter/settings")) {
105 settings_message_sent = true;
106 }
107
108 return kSuccess;
109 }));
110
111 // And it should send display info.
112 bool notify_display_update_called = false;
113 modifier.SetFrameInterval(16600000); // 60 fps.
114 modifier.embedder_api().NotifyDisplayUpdate = MOCK_ENGINE_PROC(
115 NotifyDisplayUpdate,
116 ([&notify_display_update_called, engine_instance = engine.get()](
117 FLUTTER_API_SYMBOL(FlutterEngine) raw_engine,
118 const FlutterEngineDisplaysUpdateType update_type,
119 const FlutterEngineDisplay* embedder_displays,
120 size_t display_count) {
121 EXPECT_EQ(update_type, kFlutterEngineDisplaysUpdateTypeStartup);
122 EXPECT_EQ(display_count, 1);
123
124 FlutterEngineDisplay display = embedder_displays[0];
125
126 EXPECT_EQ(display.display_id, 0);
127 EXPECT_EQ(display.single_display, true);
128 EXPECT_EQ(std::floor(display.refresh_rate), 60.0);
129
130 notify_display_update_called = true;
131 return kSuccess;
132 }));
133
134 // Set the AngleSurfaceManager to !nullptr to test ANGLE rendering.
135 modifier.SetSurfaceManager(std::make_unique<MockAngleSurfaceManager>());
136
137 engine->Run();
138
139 EXPECT_TRUE(run_called);
140 EXPECT_TRUE(update_locales_called);
141 EXPECT_TRUE(settings_message_sent);
142 EXPECT_TRUE(notify_display_update_called);
143
144 // Ensure that deallocation doesn't call the actual Shutdown with the bogus
145 // engine pointer that the overridden Run returned.
146 modifier.embedder_api().Shutdown = [](auto engine) { return kSuccess; };
147 modifier.ReleaseSurfaceManager();
148 }

References message, flutter::FlutterEngine::Run(), and user_data.

## ◆ TEST_F() [28/119]

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

Definition at line 230 of file flutter_windows_engine_unittests.cc.

230 {
231 FlutterWindowsEngineBuilder builder{GetContext()};
232 builder.SetSwitches({"--enable-impeller=true"});
233 std::unique_ptr<FlutterWindowsEngine> engine = builder.Build();
234 EngineModifier modifier(engine.get());
235
236 modifier.embedder_api().NotifyDisplayUpdate =
237 MOCK_ENGINE_PROC(NotifyDisplayUpdate,
238 ([engine_instance = engine.get()](
239 FLUTTER_API_SYMBOL(FlutterEngine) raw_engine,
240 const FlutterEngineDisplaysUpdateType update_type,
241 const FlutterEngineDisplay* embedder_displays,
242 size_t display_count) { return kSuccess; }));
243
244 // Accessibility updates must do nothing when the embedder engine is mocked
245 modifier.embedder_api().UpdateAccessibilityFeatures = MOCK_ENGINE_PROC(
246 UpdateAccessibilityFeatures,
247 [](FLUTTER_API_SYMBOL(FlutterEngine) engine,
248 FlutterAccessibilityFeature flags) { return kSuccess; });
249
250 // Stub out UpdateLocales and SendPlatformMessage as we don't have a fully
251 // initialized engine instance.
252 modifier.embedder_api().UpdateLocales = MOCK_ENGINE_PROC(
253 UpdateLocales, ([](auto engine, const FlutterLocale** locales,
254 size_t locales_count) { return kSuccess; }));
255 modifier.embedder_api().SendPlatformMessage =
256 MOCK_ENGINE_PROC(SendPlatformMessage,
257 ([](auto engine, auto message) { return kSuccess; }));
258
259 // Set the AngleSurfaceManager to nullptr to test software fallback path.
260 modifier.SetSurfaceManager(nullptr);
261
262 EXPECT_FALSE(engine->Run());
263 }

References message, and flutter::FlutterEngine::Run().

## ◆ TEST_F() [29/119]

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

Definition at line 177 of file flutter_windows_engine_unittests.cc.

177 {
178 FlutterWindowsEngineBuilder builder{GetContext()};
179 std::unique_ptr<FlutterWindowsEngine> engine = builder.Build();
180 EngineModifier modifier(engine.get());
181
182 modifier.embedder_api().NotifyDisplayUpdate =
183 MOCK_ENGINE_PROC(NotifyDisplayUpdate,
184 ([engine_instance = engine.get()](
185 FLUTTER_API_SYMBOL(FlutterEngine) raw_engine,
186 const FlutterEngineDisplaysUpdateType update_type,
187 const FlutterEngineDisplay* embedder_displays,
188 size_t display_count) { return kSuccess; }));
189
190 // The engine should be run with expected configuration values.
191 bool run_called = false;
192 modifier.embedder_api().Run = MOCK_ENGINE_PROC(
193 Run, ([&run_called, engine_instance = engine.get()](
194 size_t version, const FlutterRendererConfig* config,
195 const FlutterProjectArgs* args, void* user_data,
196 FLUTTER_API_SYMBOL(FlutterEngine) * engine_out) {
197 run_called = true;
198 *engine_out = reinterpret_cast<FLUTTER_API_SYMBOL(FlutterEngine)>(1);
199 // We don't have an AngleSurfaceManager, so we should be using software.
200 EXPECT_EQ(config->type, kSoftware);
201 return kSuccess;
202 }));
203 // Accessibility updates must do nothing when the embedder engine is mocked
204 modifier.embedder_api().UpdateAccessibilityFeatures = MOCK_ENGINE_PROC(
205 UpdateAccessibilityFeatures,
206 [](FLUTTER_API_SYMBOL(FlutterEngine) engine,
207 FlutterAccessibilityFeature flags) { return kSuccess; });
208
209 // Stub out UpdateLocales and SendPlatformMessage as we don't have a fully
210 // initialized engine instance.
211 modifier.embedder_api().UpdateLocales = MOCK_ENGINE_PROC(
212 UpdateLocales, ([](auto engine, const FlutterLocale** locales,
213 size_t locales_count) { return kSuccess; }));
214 modifier.embedder_api().SendPlatformMessage =
215 MOCK_ENGINE_PROC(SendPlatformMessage,
216 ([](auto engine, auto message) { return kSuccess; }));
217
218 // Set the AngleSurfaceManager to nullptr to test software fallback path.
219 modifier.SetSurfaceManager(nullptr);
220
221 engine->Run();
222
223 EXPECT_TRUE(run_called);
224
225 // Ensure that deallocation doesn't call the actual Shutdown with the bogus
226 // engine pointer that the overridden Run returned.
227 modifier.embedder_api().Shutdown = [](auto engine) { return kSuccess; };
228 }

References message, flutter::FlutterEngine::Run(), and user_data.

## ◆ TEST_F() [30/119]

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

Definition at line 524 of file flutter_windows_engine_unittests.cc.

524 {
525 FlutterWindowsEngineBuilder builder{GetContext()};
526 std::unique_ptr<FlutterWindowsEngine> engine = builder.Build();
527 EngineModifier modifier(engine.get());
528
529 bool called = false;
530 modifier.embedder_api().ScheduleFrame =
531 MOCK_ENGINE_PROC(ScheduleFrame, ([&called](auto engine) {
532 called = true;
533 return kSuccess;
534 }));
535
536 engine->ScheduleFrame();
537 EXPECT_TRUE(called);
538 }

## ◆ TEST_F() [31/119]

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

Definition at line 265 of file flutter_windows_engine_unittests.cc.

265 {
266 FlutterWindowsEngineBuilder builder{GetContext()};
267 std::unique_ptr<FlutterWindowsEngine> engine = builder.Build();
268 EngineModifier modifier(engine.get());
269
270 const char* channel = "test";
271 const std::vector<uint8_t> test_message = {1, 2, 3, 4};
272
273 // Without a response, SendPlatformMessage should be a simple pass-through.
274 bool called = false;
275 modifier.embedder_api().SendPlatformMessage = MOCK_ENGINE_PROC(
276 SendPlatformMessage, ([&called, test_message](auto engine, auto message) {
277 called = true;
278 EXPECT_STREQ(message->channel, "test");
279 EXPECT_EQ(message->message_size, test_message.size());
280 EXPECT_EQ(memcmp(message->message, test_message.data(),
281 message->message_size),
282 0);
283 EXPECT_EQ(message->response_handle, nullptr);
284 return kSuccess;
285 }));
286
287 engine->SendPlatformMessage(channel, test_message.data(), test_message.size(),
288 nullptr, nullptr);
289 EXPECT_TRUE(called);
290 }

References message.

## ◆ TEST_F() [32/119]

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

Definition at line 388 of file flutter_windows_engine_unittests.cc.

388 {
389 FlutterWindowsEngineBuilder builder{GetContext()};
390 std::unique_ptr<FlutterWindowsEngine> engine = builder.Build();
391 EngineModifier modifier(engine.get());
392
393 const char* channel = "test";
394 const std::vector<uint8_t> test_message = {1, 2, 3, 4};
395 auto* dummy_response_handle =
396 reinterpret_cast<FlutterPlatformMessageResponseHandle*>(5);
397 const FlutterDesktopBinaryReply reply_handler = [](auto... args) {};
398 void* reply_user_data = reinterpret_cast<void*>(6);
399
400 // When a response is requested, a handle should be created, passed as part
401 // of the message, and then released.
402 bool create_response_handle_called = false;
403 modifier.embedder_api().PlatformMessageCreateResponseHandle =
404 MOCK_ENGINE_PROC(
405 PlatformMessageCreateResponseHandle,
406 ([&create_response_handle_called, &reply_handler, reply_user_data,
407 dummy_response_handle](auto engine, auto reply, auto user_data,
408 auto response_handle) {
409 create_response_handle_called = true;
410 EXPECT_EQ(reply, reply_handler);
411 EXPECT_EQ(user_data, reply_user_data);
412 EXPECT_NE(response_handle, nullptr);
413 *response_handle = dummy_response_handle;
414 return kSuccess;
415 }));
416 bool release_response_handle_called = false;
417 modifier.embedder_api().PlatformMessageReleaseResponseHandle =
418 MOCK_ENGINE_PROC(
419 PlatformMessageReleaseResponseHandle,
420 ([&release_response_handle_called, dummy_response_handle](
421 auto engine, auto response_handle) {
422 release_response_handle_called = true;
423 EXPECT_EQ(response_handle, dummy_response_handle);
424 return kSuccess;
425 }));
426 bool send_message_called = false;
427 modifier.embedder_api().SendPlatformMessage = MOCK_ENGINE_PROC(
428 SendPlatformMessage, ([&send_message_called, test_message,
429 dummy_response_handle](auto engine, auto message) {
430 send_message_called = true;
431 EXPECT_STREQ(message->channel, "test");
432 EXPECT_EQ(message->message_size, test_message.size());
433 EXPECT_EQ(memcmp(message->message, test_message.data(),
434 message->message_size),
435 0);
436 EXPECT_EQ(message->response_handle, dummy_response_handle);
437 return kSuccess;
438 }));
439
440 engine->SendPlatformMessage(channel, test_message.data(), test_message.size(),
441 reply_handler, reply_user_data);
442 EXPECT_TRUE(create_response_handle_called);
443 EXPECT_TRUE(release_response_handle_called);
444 EXPECT_TRUE(send_message_called);
445 }

References message, and user_data.

## ◆ TEST_F() [33/119]

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

Definition at line 540 of file flutter_windows_engine_unittests.cc.

540 {
541 FlutterWindowsEngineBuilder builder{GetContext()};
542 std::unique_ptr<FlutterWindowsEngine> engine = builder.Build();
543 EngineModifier modifier(engine.get());
544
545 bool called = false;
546 modifier.embedder_api().SetNextFrameCallback = MOCK_ENGINE_PROC(
547 SetNextFrameCallback, ([&called](auto engine, auto callback, auto data) {
548 called = true;
549 return kSuccess;
550 }));
551
552 engine->SetNextFrameCallback([]() {});
553 EXPECT_TRUE(called);
554 }

References callback.

## ◆ TEST_F() [34/119]

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

Definition at line 472 of file flutter_windows_engine_unittests.cc.

472 {
473 WindowsPlatformThreadPrioritySetter(FlutterThreadPriority::kBackground);
474 EXPECT_EQ(GetThreadPriority(GetCurrentThread()),
475 THREAD_PRIORITY_BELOW_NORMAL);
476
477 WindowsPlatformThreadPrioritySetter(FlutterThreadPriority::kDisplay);
478 EXPECT_EQ(GetThreadPriority(GetCurrentThread()),
479 THREAD_PRIORITY_ABOVE_NORMAL);
480
481 WindowsPlatformThreadPrioritySetter(FlutterThreadPriority::kRaster);
482 EXPECT_EQ(GetThreadPriority(GetCurrentThread()),
483 THREAD_PRIORITY_ABOVE_NORMAL);
484
485 // FlutterThreadPriority::kNormal does not change thread priority, reset to 0
486 // here.
487 SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_NORMAL);
488
489 WindowsPlatformThreadPrioritySetter(FlutterThreadPriority::kNormal);
490 EXPECT_EQ(GetThreadPriority(GetCurrentThread()), THREAD_PRIORITY_NORMAL);
491 }

References flutter::WindowsPlatformThreadPrioritySetter().

## ◆ TEST_F() [35/119]

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

Definition at line 701 of file flutter_windows_engine_unittests.cc.

701 {
702 FlutterWindowsEngineBuilder builder{GetContext()};
703 builder.SetDartEntrypoint("exitTestExit");
704 bool finished = false;
705
706 auto engine = builder.Build();
707 auto window_binding_handler =
708 std::make_unique<::testing::NiceMock<MockWindowBindingHandler>>();
709 MockFlutterWindowsView view(std::move(window_binding_handler));
710 view.SetEngine(engine.get());
711
712 EngineModifier modifier(engine.get());
713 modifier.embedder_api().RunsAOTCompiledDartCode = []() { return false; };
714 auto handler = std::make_unique<MockWindowsLifecycleManager>(engine.get());
715 EXPECT_CALL(*handler, SetLifecycleState(AppLifecycleState::kResumed));
716 EXPECT_CALL(*handler, Quit)
717 .WillOnce([&finished](std::optional<HWND> hwnd,
718 std::optional<WPARAM> wparam,
719 std::optional<LPARAM> lparam,
720 UINT exit_code) { finished = exit_code == 0; });
721 EXPECT_CALL(*handler, IsLastWindowOfProcess).WillRepeatedly(Return(true));
722 modifier.SetLifecycleManager(std::move(handler));
723
724 engine->lifecycle_manager()->BeginProcessingExit();
725
726 engine->Run();
727
728 engine->window_proc_delegate_manager()->OnTopLevelWindowProc(0, WM_CLOSE, 0,
729 0);
730
731 // The test will only succeed when this while loop exits. Otherwise it will
732 // timeout.
733 while (!finished) {
734 engine->task_runner()->ProcessTasks();
735 }
736 }

References flutter::kResumed.

## ◆ TEST_F() [36/119]

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

Definition at line 738 of file flutter_windows_engine_unittests.cc.

738 {
739 FlutterWindowsEngineBuilder builder{GetContext()};
740 builder.SetDartEntrypoint("exitTestCancel");
741 bool did_call = false;
742
743 auto engine = builder.Build();
744 auto window_binding_handler =
745 std::make_unique<::testing::NiceMock<MockWindowBindingHandler>>();
746 MockFlutterWindowsView view(std::move(window_binding_handler));
747 view.SetEngine(engine.get());
748
749 EngineModifier modifier(engine.get());
750 modifier.embedder_api().RunsAOTCompiledDartCode = []() { return false; };
751 auto handler = std::make_unique<MockWindowsLifecycleManager>(engine.get());
752 EXPECT_CALL(*handler, SetLifecycleState(AppLifecycleState::kResumed));
753 EXPECT_CALL(*handler, IsLastWindowOfProcess).WillRepeatedly(Return(true));
754 EXPECT_CALL(*handler, Quit).Times(0);
755 modifier.SetLifecycleManager(std::move(handler));
756 engine->lifecycle_manager()->BeginProcessingExit();
757
758 auto binary_messenger =
759 std::make_unique<BinaryMessengerImpl>(engine->messenger());
760 binary_messenger->SetMessageHandler(
761 "flutter/platform", [&did_call](const uint8_t* message,
762 size_t message_size, BinaryReply reply) {
763 std::string contents(message, message + message_size);
764 EXPECT_NE(contents.find("\"method\":\"System.exitApplication\""),
765 std::string::npos);
766 EXPECT_NE(contents.find("\"type\":\"required\""), std::string::npos);
767 EXPECT_NE(contents.find("\"exitCode\":0"), std::string::npos);
768 did_call = true;
769 char response[] = "";
770 reply(reinterpret_cast<uint8_t*>(response), 0);
771 });
772
773 engine->Run();
774
775 engine->window_proc_delegate_manager()->OnTopLevelWindowProc(0, WM_CLOSE, 0,
776 0);
777
778 while (!did_call) {
779 engine->task_runner()->ProcessTasks();
780 }
781 }

References flutter::kResumed, and message.

## ◆ TEST_F() [37/119]

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

Definition at line 848 of file flutter_windows_engine_unittests.cc.

848 {
849 FlutterWindowsEngineBuilder builder{GetContext()};
850 builder.SetDartEntrypoint("exitTestExit");
851 bool finished = false;
852
853 auto engine = builder.Build();
854 auto window_binding_handler =
855 std::make_unique<::testing::NiceMock<MockWindowBindingHandler>>();
856 MockFlutterWindowsView view(std::move(window_binding_handler));
857 view.SetEngine(engine.get());
858
859 EngineModifier modifier(engine.get());
860 modifier.embedder_api().RunsAOTCompiledDartCode = []() { return false; };
861 auto handler = std::make_unique<MockWindowsLifecycleManager>(engine.get());
862 EXPECT_CALL(*handler, SetLifecycleState(AppLifecycleState::kResumed));
863 EXPECT_CALL(*handler, IsLastWindowOfProcess).WillOnce([&finished]() {
864 finished = true;
865 return false;
866 });
867 // Quit should not be called when there is more than one window.
868 EXPECT_CALL(*handler, Quit).Times(0);
869 modifier.SetLifecycleManager(std::move(handler));
870 engine->lifecycle_manager()->BeginProcessingExit();
871
872 engine->Run();
873
874 engine->window_proc_delegate_manager()->OnTopLevelWindowProc(0, WM_CLOSE, 0,
875 0);
876
877 while (!finished) {
878 engine->task_runner()->ProcessTasks();
879 }
880 }

References flutter::kResumed.

## ◆ TEST_F() [38/119]

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

Definition at line 786 of file flutter_windows_engine_unittests.cc.

786 {
787 FlutterWindowsEngineBuilder builder{GetContext()};
788 builder.SetDartEntrypoint("exitTestExit");
789 bool second_close = false;
790
791 auto engine = builder.Build();
792 auto window_binding_handler =
793 std::make_unique<::testing::NiceMock<MockWindowBindingHandler>>();
794 MockFlutterWindowsView view(std::move(window_binding_handler));
795 view.SetEngine(engine.get());
796
797 EngineModifier modifier(engine.get());
798 modifier.embedder_api().RunsAOTCompiledDartCode = []() { return false; };
799 auto handler = std::make_unique<MockWindowsLifecycleManager>(engine.get());
800 EXPECT_CALL(*handler, SetLifecycleState(AppLifecycleState::kResumed));
801 // TODO(loicsharma): These should be `EXPECT_CALL`s
802 // https://github.com/flutter/flutter/issues/137963
803 ON_CALL(*handler, IsLastWindowOfProcess).WillByDefault(Return(true));
804 ON_CALL(*handler, Quit)
805 .WillByDefault([handler_ptr = handler.get()](
806 std::optional<HWND> hwnd, std::optional<WPARAM> wparam,
807 std::optional<LPARAM> lparam, UINT exit_code) {
808 handler_ptr->WindowsLifecycleManager::Quit(hwnd, wparam, lparam,
809 exit_code);
810 });
811 ON_CALL(*handler, DispatchMessage)
812 .WillByDefault(
813 [&engine](HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) {
814 engine->window_proc_delegate_manager()->OnTopLevelWindowProc(
815 hwnd, msg, wparam, lparam);
816 });
817 modifier.SetLifecycleManager(std::move(handler));
818 engine->lifecycle_manager()->BeginProcessingExit();
819
820 engine->Run();
821
822 // This delegate will be registered after the lifecycle manager, so it will be
823 // called only when a message is not consumed by the lifecycle manager. This
824 // should be called on the second, synthesized WM_CLOSE message that the
825 // lifecycle manager posts.
826 engine->window_proc_delegate_manager()->RegisterTopLevelWindowProcDelegate(
827 [](HWND hwnd, UINT message, WPARAM wpar, LPARAM lpar, void* user_data,
828 LRESULT* result) {
829 switch (message) {
830 case WM_CLOSE: {
831 bool* called = reinterpret_cast<bool*>(user_data);
832 *called = true;
833 return true;
834 }
835 }
836 return false;
837 },
838 reinterpret_cast<void*>(&second_close));
839
840 engine->window_proc_delegate_manager()->OnTopLevelWindowProc(0, WM_CLOSE, 0,
841 0);
842
843 while (!second_close) {
844 engine->task_runner()->ProcessTasks();
845 }
846 }

References flutter::kResumed, message, and user_data.

## ◆ TEST_F() [39/119]

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

Definition at line 564 of file flutter_windows_engine_unittests.cc.

564 {
565 auto windows_proc_table = std::make_shared<MockWindowsProcTable>();
566 EXPECT_CALL(*windows_proc_table, GetHighContrastEnabled)
567 .WillOnce(Return(true))
568 .WillOnce(Return(false));
569
570 FlutterWindowsEngineBuilder builder{GetContext()};
571 builder.SetWindowsProcTable(windows_proc_table);
572 std::unique_ptr<FlutterWindowsEngine> engine = builder.Build();
573 EngineModifier modifier(engine.get());
574
575 std::optional<FlutterAccessibilityFeature> engine_flags;
576 modifier.embedder_api().UpdateAccessibilityFeatures = MOCK_ENGINE_PROC(
577 UpdateAccessibilityFeatures, ([&engine_flags](auto engine, auto flags) {
578 engine_flags = flags;
579 return kSuccess;
580 }));
581
582 // 1: High contrast is enabled.
583 engine->UpdateHighContrastMode();
584
585 EXPECT_TRUE(engine->high_contrast_enabled());
586 EXPECT_TRUE(engine_flags.has_value());
587 EXPECT_TRUE(
588 engine_flags.value() &
589 FlutterAccessibilityFeature::kFlutterAccessibilityFeatureHighContrast);
590
591 // 2: High contrast is disabled.
592 engine_flags.reset();
593 engine->UpdateHighContrastMode();
594
595 EXPECT_FALSE(engine->high_contrast_enabled());
596 EXPECT_TRUE(engine_flags.has_value());
597 EXPECT_FALSE(
598 engine_flags.value() &
599 FlutterAccessibilityFeature::kFlutterAccessibilityFeatureHighContrast);
600 }

## ◆ TEST_F() [40/119]

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

Definition at line 1231 of file keyboard_unittests.cc.

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

References EXPECT_CALL_IS_EVENT, and EXPECT_CALL_IS_TEXT.

## ◆ TEST_F() [41/119]

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

Definition at line 1318 of file keyboard_unittests.cc.

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

References EXPECT_CALL_IS_EVENT.

## ◆ TEST_F() [42/119]

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

Definition at line 828 of file keyboard_unittests.cc.

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

References EXPECT_CALL_IS_EVENT.

## ◆ TEST_F() [43/119]

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

Definition at line 861 of file keyboard_unittests.cc.

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

References EXPECT_CALL_IS_EVENT.

## ◆ TEST_F() [44/119]

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

Definition at line 622 of file keyboard_unittests.cc.

622 {
623 KeyboardTester tester{GetContext()};
624 tester.Responding(true);
625
626 // US Keyboard layout
627
628 // Press ArrowLeft
629 tester.InjectKeyboardChanges(std::vector<KeyboardChange>{
630 WmKeyDownInfo{VK_LEFT, kScanCodeArrowLeft, kExtended, kWasUp}.Build(
631 kWmResultZero)});
632
633 EXPECT_EQ(tester.key_calls.size(), 1);
634 EXPECT_CALL_IS_EVENT(tester.key_calls[0], kFlutterKeyEventTypeDown,
635 kPhysicalArrowLeft, kLogicalArrowLeft, "",
636 kNotSynthesized);
637 tester.clear_key_calls();
638 EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 0);
639
640 // Release ArrowLeft
641 tester.InjectKeyboardChanges(std::vector<KeyboardChange>{
642 WmKeyUpInfo{VK_LEFT, kScanCodeArrowLeft, kExtended}.Build(
643 kWmResultZero)});
644
645 EXPECT_EQ(tester.key_calls.size(), 1);
646 EXPECT_CALL_IS_EVENT(tester.key_calls[0], kFlutterKeyEventTypeUp,
647 kPhysicalArrowLeft, kLogicalArrowLeft, "",
648 kNotSynthesized);
649 tester.clear_key_calls();
650 EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 0);
651 }

References EXPECT_CALL_IS_EVENT.

## ◆ TEST_F() [45/119]

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

Definition at line 653 of file keyboard_unittests.cc.

653 {
654 KeyboardTester tester{GetContext()};
655 tester.Responding(false);
656
657 // US Keyboard layout
658
659 // Press ArrowLeft
660 tester.InjectKeyboardChanges(std::vector<KeyboardChange>{
661 WmKeyDownInfo{VK_LEFT, kScanCodeArrowLeft, kExtended, kWasUp}.Build(
662 kWmResultZero)});
663
664 EXPECT_EQ(tester.key_calls.size(), 1);
665 EXPECT_CALL_IS_EVENT(tester.key_calls[0], kFlutterKeyEventTypeDown,
666 kPhysicalArrowLeft, kLogicalArrowLeft, "",
667 kNotSynthesized);
668 tester.clear_key_calls();
669 EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 1);
670
671 // Release ArrowLeft
672 tester.InjectKeyboardChanges(std::vector<KeyboardChange>{
673 WmKeyUpInfo{VK_LEFT, kScanCodeArrowLeft, kExtended}.Build(
674 kWmResultZero)});
675
676 EXPECT_EQ(tester.key_calls.size(), 1);
677 EXPECT_CALL_IS_EVENT(tester.key_calls[0], kFlutterKeyEventTypeUp,
678 kPhysicalArrowLeft, kLogicalArrowLeft, "",
679 kNotSynthesized);
680 tester.clear_key_calls();
681 EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 1);
682 }

References EXPECT_CALL_IS_EVENT.

## ◆ TEST_F() [46/119]

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

Definition at line 1141 of file keyboard_unittests.cc.

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

References EXPECT_CALL_IS_EVENT.

## ◆ TEST_F() [47/119]

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

Definition at line 1083 of file keyboard_unittests.cc.

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

References EXPECT_CALL_IS_EVENT, kScanCodeKeyA, and kVirtualKeyA.

## ◆ TEST_F() [48/119]

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

Definition at line 762 of file keyboard_unittests.cc.

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

References EXPECT_CALL_IS_EVENT.

## ◆ TEST_F() [49/119]

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

Definition at line 795 of file keyboard_unittests.cc.

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

References EXPECT_CALL_IS_EVENT.

## ◆ TEST_F() [50/119]

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

Definition at line 1421 of file keyboard_unittests.cc.

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

References EXPECT_CALL_IS_EVENT, and EXPECT_CALL_IS_TEXT.

## ◆ TEST_F() [51/119]

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

Definition at line 1565 of file keyboard_unittests.cc.

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

References EXPECT_CALL_IS_EVENT, and EXPECT_CALL_IS_TEXT.

## ◆ TEST_F() [52/119]

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

Definition at line 1634 of file keyboard_unittests.cc.

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

References callback, EXPECT_CALL_IS_EVENT, and EXPECT_CALL_IS_TEXT.

## ◆ TEST_F() [53/119]

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

Definition at line 1484 of file keyboard_unittests.cc.

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

References EXPECT_CALL_IS_EVENT, EXPECT_CALL_IS_TEXT, and flutter::kScanCodeShiftLeft.

## ◆ TEST_F() [54/119]

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

Definition at line 1198 of file keyboard_unittests.cc.

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

References EXPECT_CALL_IS_EVENT, and EXPECT_CALL_IS_TEXT.

## ◆ TEST_F() [55/119]

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

Definition at line 2457 of file keyboard_unittests.cc.

2457 {
2458 KeyboardTester tester{GetContext()};
2459 tester.Responding(false);
2460
2461 tester.InjectKeyboardChanges(std::vector<KeyboardChange>{
2462 WmKeyDownInfo{VK_CAPITAL, 0, kNotExtended}.Build(),
2463 WmKeyUpInfo{VK_CAPITAL, 0, kNotExtended}.Build()});
2464
2465 tester.clear_key_calls();
2466 }

## ◆ TEST_F() [56/119]

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

Definition at line 1983 of file keyboard_unittests.cc.

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

References EXPECT_CALL_IS_EVENT.

## ◆ TEST_F() [57/119]

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

Definition at line 559 of file keyboard_unittests.cc.

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

References EXPECT_CALL_IS_EVENT, kScanCodeKeyA, and kVirtualKeyA.

## ◆ TEST_F() [58/119]

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

Definition at line 590 of file keyboard_unittests.cc.

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

References EXPECT_CALL_IS_EVENT, EXPECT_CALL_IS_TEXT, kScanCodeKeyA, and kVirtualKeyA.

## ◆ TEST_F() [59/119]

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

Definition at line 896 of file keyboard_unittests.cc.

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

References EXPECT_CALL_IS_EVENT.

## ◆ TEST_F() [60/119]

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

Definition at line 928 of file keyboard_unittests.cc.

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

References EXPECT_CALL_IS_EVENT.

## ◆ TEST_F() [61/119]

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

Definition at line 1718 of file keyboard_unittests.cc.

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

References EXPECT_CALL_IS_EVENT, and EXPECT_CALL_IS_TEXT.

## ◆ TEST_F() [62/119]

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

Definition at line 962 of file keyboard_unittests.cc.

962 {
963 KeyboardTester tester{GetContext()};
964 tester.Responding(true);
965
966 // Press A
967 tester.InjectKeyboardChanges(std::vector<KeyboardChange>{
968 WmKeyDownInfo{kVirtualKeyA, kScanCodeKeyA, kNotExtended, kWasUp}.Build(
969 kWmResultZero),
970 WmCharInfo{'a', kScanCodeKeyA, kNotExtended, kWasUp}.Build(
971 kWmResultZero)});
972
973 // Hold A
974 tester.InjectKeyboardChanges(std::vector<KeyboardChange>{
975 WmKeyDownInfo{kVirtualKeyA, kScanCodeKeyA, kNotExtended, kWasDown}.Build(
976 kWmResultZero),
977 WmCharInfo{'a', kScanCodeKeyA, kNotExtended, kWasDown}.Build(
978 kWmResultZero)});
979
980 EXPECT_EQ(tester.key_calls.size(), 2);
981 EXPECT_CALL_IS_EVENT(tester.key_calls[0], kFlutterKeyEventTypeDown,
982 kPhysicalKeyA, kLogicalKeyA, "a", kNotSynthesized);
983 EXPECT_CALL_IS_EVENT(tester.key_calls[1], kFlutterKeyEventTypeRepeat,
984 kPhysicalKeyA, kLogicalKeyA, "a", kNotSynthesized);
985 EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 0);
986 }

References EXPECT_CALL_IS_EVENT, kScanCodeKeyA, and kVirtualKeyA.

## ◆ TEST_F() [63/119]

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

Definition at line 991 of file keyboard_unittests.cc.

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

References EXPECT_CALL_IS_EVENT, kScanCodeKeyA, and kVirtualKeyA.

## ◆ TEST_F() [64/119]

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

Definition at line 1023 of file keyboard_unittests.cc.

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

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

## ◆ TEST_F() [65/119]

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

Definition at line 684 of file keyboard_unittests.cc.

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

References EXPECT_CALL_IS_EVENT, and flutter::kScanCodeShiftLeft.

## ◆ TEST_F() [66/119]

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

Definition at line 729 of file keyboard_unittests.cc.

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

References EXPECT_CALL_IS_EVENT, and flutter::kScanCodeShiftRight.

## ◆ TEST_F() [67/119]

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

Definition at line 2050 of file keyboard_unittests.cc.

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

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

## ◆ TEST_F() [68/119]

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

Definition at line 2113 of file keyboard_unittests.cc.

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

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

## ◆ TEST_F() [69/119]

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

Definition at line 1755 of file keyboard_unittests.cc.

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

References EXPECT_CALL_IS_EVENT.

## ◆ TEST_F() [70/119]

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

Definition at line 2189 of file keyboard_unittests.cc.

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

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

## ◆ TEST_F() [71/119]

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

Definition at line 2011 of file keyboard_unittests.cc.

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

References EXPECT_CALL_IS_EVENT, and flutter::kScanCodeShiftLeft.

## ◆ TEST_F() [72/119]

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

Definition at line 2257 of file keyboard_unittests.cc.

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

References EXPECT_CALL_IS_EVENT, EXPECT_CALL_IS_TEXT, kScanCodeKeyA, and kVirtualKeyA.

## ◆ TEST_F() [73/119]

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

Definition at line 2447 of file keyboard_unittests.cc.

2447 {
2448 VietnameseTelexAddDiacriticWithSlowResponse(GetContext(), false);
2449 }

References VietnameseTelexAddDiacriticWithSlowResponse().

## ◆ TEST_F() [74/119]

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

Definition at line 2451 of file keyboard_unittests.cc.

2451 {
2452 VietnameseTelexAddDiacriticWithSlowResponse(GetContext(), true);
2453 }

References VietnameseTelexAddDiacriticWithSlowResponse().

## ◆ TEST_F() [75/119]

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

Definition at line 263 of file platform_handler_unittests.cc.

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

References kErrorSuccess.

## ◆ TEST_F() [76/119]

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

Definition at line 332 of file platform_handler_unittests.cc.

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

References kAccessDeniedErrorCode.

## ◆ TEST_F() [77/119]

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

Definition at line 305 of file platform_handler_unittests.cc.

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

## ◆ TEST_F() [78/119]

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

Definition at line 352 of file platform_handler_unittests.cc.

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

## ◆ TEST_F() [79/119]

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

Definition at line 317 of file platform_handler_unittests.cc.

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

## ◆ TEST_F() [80/119]

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

Definition at line 284 of file platform_handler_unittests.cc.

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

References kErrorSuccess.

## ◆ TEST_F() [81/119]

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

Definition at line 372 of file platform_handler_unittests.cc.

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

References kErrorSuccess.

## ◆ TEST_F() [82/119]

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

Definition at line 437 of file platform_handler_unittests.cc.

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

## ◆ TEST_F() [83/119]

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

Definition at line 457 of file platform_handler_unittests.cc.

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

References kErrorSuccess.

## ◆ TEST_F() [84/119]

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

Definition at line 423 of file platform_handler_unittests.cc.

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

## ◆ TEST_F() [85/119]

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

Definition at line 399 of file platform_handler_unittests.cc.

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

## ◆ TEST_F() [86/119]

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

Definition at line 411 of file platform_handler_unittests.cc.

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

## ◆ TEST_F() [87/119]

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

Definition at line 168 of file platform_handler_unittests.cc.

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

References kErrorSuccess.

## ◆ TEST_F() [88/119]

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

Definition at line 192 of file platform_handler_unittests.cc.

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

## ◆ TEST_F() [89/119]

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

Definition at line 239 of file platform_handler_unittests.cc.

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

References kErrorSuccess.

## ◆ TEST_F() [90/119]

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

Definition at line 219 of file platform_handler_unittests.cc.

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

## ◆ TEST_F() [91/119]

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

Definition at line 205 of file platform_handler_unittests.cc.

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

## ◆ TEST_F() [92/119]

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

Definition at line 480 of file platform_handler_unittests.cc.

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

## ◆ TEST_F() [93/119]

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

Definition at line 520 of file platform_handler_unittests.cc.

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

References message.

## ◆ TEST_F() [94/119]

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

Definition at line 541 of file platform_handler_unittests.cc.

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

References message.

## ◆ TEST_F() [95/119]

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

Definition at line 498 of file platform_handler_unittests.cc.

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

References message.

## ◆ TEST_F() [96/119]

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

Definition at line 203 of file text_input_plugin_unittest.cc.

203 {
204 UseHeadlessEngine();
205
206 TestBinaryMessenger messenger([](const std::string& channel,
207 const uint8_t* message, size_t message_size,
208 BinaryReply reply) {});
209
210 std::string reply;
211 BinaryReply reply_handler = [&reply](const uint8_t* reply_bytes,
212 size_t reply_size) {
213 reply = std::string(reinterpret_cast<const char*>(reply_bytes), reply_size);
214 };
215
216 TextInputPlugin handler(&messenger, engine());
217
218 auto& codec = JsonMethodCodec::GetInstance();
219 auto message = codec.EncodeMethodCall({"TextInput.clearClient", nullptr});
220 messenger.SimulateEngineMessage(kChannelName, message->data(),
221 message->size(), reply_handler);
222
223 EXPECT_EQ(reply,
224 "[\"Internal Consistency Error\",\"Text input is not available in "
225 "Windows headless mode\",null]");
226 }

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

## ◆ TEST_F() [97/119]

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

Definition at line 184 of file text_input_plugin_unittest.cc.

184 {
185 UseEngineWithView();
186
187 TestBinaryMessenger messenger([](const std::string& channel,
188 const uint8_t* message, size_t message_size,
189 BinaryReply reply) {});
190 BinaryReply reply_handler = [](const uint8_t* reply, size_t reply_size) {};
191
192 TextInputPlugin handler(&messenger, engine());
193
194 EXPECT_CALL(*view(), OnResetImeComposing());
195
196 auto& codec = JsonMethodCodec::GetInstance();
197 auto message = codec.EncodeMethodCall({"TextInput.clearClient", nullptr});
198 messenger.SimulateEngineMessage(kChannelName, message->data(),
199 message->size(), reply_handler);
200 }

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

## ◆ TEST_F() [98/119]

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

Definition at line 449 of file text_input_plugin_unittest.cc.

449 {
450 UseEngineWithView();
451
452 int selection_base = -1;
453 TestBinaryMessenger messenger([&](const std::string& channel,
454 const uint8_t* message, size_t size,
455 BinaryReply reply) {
456 auto method = JsonMethodCodec::GetInstance().DecodeMethodCall(
457 std::vector<uint8_t>(message, message + size));
458 if (method->method_name() == kUpdateEditingStateMethod) {
459 const auto& args = *method->arguments();
460 const auto& editing_state = args[1];
461 auto base = editing_state.FindMember(kSelectionBaseKey);
462 auto extent = editing_state.FindMember(kSelectionExtentKey);
463 ASSERT_NE(base, editing_state.MemberEnd());
464 ASSERT_TRUE(base->value.IsInt());
465 ASSERT_NE(extent, editing_state.MemberEnd());
466 ASSERT_TRUE(extent->value.IsInt());
467 selection_base = base->value.GetInt();
468 EXPECT_EQ(extent->value.GetInt(), selection_base);
469 }
470 });
471
472 TextInputPlugin plugin(&messenger, engine());
473
474 auto args = std::make_unique<rapidjson::Document>(rapidjson::kArrayType);
475 auto& allocator = args->GetAllocator();
476 args->PushBack(123, allocator); // client_id
477 rapidjson::Value client_config(rapidjson::kObjectType);
478 args->PushBack(client_config, allocator);
479 auto encoded = JsonMethodCodec::GetInstance().EncodeMethodCall(
480 MethodCall<rapidjson::Document>(kSetClientMethod, std::move(args)));
481 EXPECT_TRUE(messenger.SimulateEngineMessage(
482 kChannelName, encoded->data(), encoded->size(),
483 [](const uint8_t* reply, size_t reply_size) {}));
484
485 plugin.ComposeBeginHook();
486 EXPECT_EQ(selection_base, 0);
487 plugin.ComposeChangeHook(u"abc", 3);
488 EXPECT_EQ(selection_base, 3);
489
490 plugin.ComposeCommitHook();
491 plugin.ComposeEndHook();
492 EXPECT_EQ(selection_base, 3);
493
494 plugin.ComposeBeginHook();
495 plugin.ComposeChangeHook(u"1", 1);
496 EXPECT_EQ(selection_base, 4);
497
498 plugin.ComposeChangeHook(u"12", 2);
499 EXPECT_EQ(selection_base, 5);
500
501 plugin.ComposeChangeHook(u"12", 1);
502 EXPECT_EQ(selection_base, 4);
503
504 plugin.ComposeChangeHook(u"12", 2);
505 EXPECT_EQ(selection_base, 5);
506 }

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

## ◆ TEST_F() [99/119]

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

Definition at line 579 of file text_input_plugin_unittest.cc.

579 {
580 UseHeadlessEngine();
581
582 TestBinaryMessenger messenger([](const std::string& channel,
583 const uint8_t* message, size_t message_size,
584 BinaryReply reply) {});
585
586 std::string reply;
587 BinaryReply reply_handler = [&reply](const uint8_t* reply_bytes,
588 size_t reply_size) {
589 reply = std::string(reinterpret_cast<const char*>(reply_bytes), reply_size);
590 };
591
592 TextInputPlugin handler(&messenger, engine());
593
594 auto& codec = JsonMethodCodec::GetInstance();
595
596 auto arguments =
597 std::make_unique<rapidjson::Document>(rapidjson::kObjectType);
598 auto& allocator = arguments->GetAllocator();
599
600 arguments->AddMember("x", 0, allocator);
601 arguments->AddMember("y", 0, allocator);
602 arguments->AddMember("width", 0, allocator);
603 arguments->AddMember("height", 0, allocator);
604
605 auto message = codec.EncodeMethodCall(
606 {"TextInput.setMarkedTextRect", std::move(arguments)});
607 messenger.SimulateEngineMessage(kChannelName, message->data(),
608 message->size(), reply_handler);
609
610 EXPECT_EQ(reply,
611 "[\"Internal Consistency Error\",\"Text input is not available in "
612 "Windows headless mode\",null]");
613 }

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

## ◆ TEST_F() [100/119]

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

Definition at line 391 of file text_input_plugin_unittest.cc.

391 {
392 UseEngineWithView();
393
394 auto handled_message = CreateResponse(true);
395 auto unhandled_message = CreateResponse(false);
396 int received_scancode = 0;
397
398 TestBinaryMessenger messenger(
399 [&received_scancode, &handled_message, &unhandled_message](
400 const std::string& channel, const uint8_t* message,
401 size_t message_size, BinaryReply reply) {});
402
403 int redispatch_scancode = 0;
404 TextInputPlugin handler(&messenger, engine());
405
406 auto args = std::make_unique<rapidjson::Document>(rapidjson::kArrayType);
407 auto& allocator = args->GetAllocator();
408 args->PushBack(123, allocator); // client_id
409
410 rapidjson::Value client_config(rapidjson::kObjectType);
411 client_config.AddMember(kEnableDeltaModel, true, allocator);
412
413 args->PushBack(client_config, allocator);
414 auto encoded = JsonMethodCodec::GetInstance().EncodeMethodCall(
415 MethodCall<rapidjson::Document>(kSetClientMethod, std::move(args)));
416
417 EXPECT_TRUE(messenger.SimulateEngineMessage(
418 kChannelName, encoded->data(), encoded->size(),
419 [](const uint8_t* reply, size_t reply_size) {}));
420
421 handler.KeyboardHook(VK_RETURN, 100, WM_KEYDOWN, '\n', false, false);
422 handler.ComposeBeginHook();
423 std::u16string text;
424 text.push_back('\n');
425 handler.ComposeChangeHook(text, 1);
426 handler.ComposeEndHook();
427
428 handler.KeyboardHook(0x4E, 100, WM_KEYDOWN, 'n', false, false);
429 handler.ComposeBeginHook();
430 std::u16string textN;
431 text.push_back('n');
432 handler.ComposeChangeHook(textN, 1);
433 handler.KeyboardHook(0x49, 100, WM_KEYDOWN, 'i', false, false);
434 std::u16string textNi;
435 text.push_back('n');
436 text.push_back('i');
437 handler.ComposeChangeHook(textNi, 2);
438 handler.KeyboardHook(VK_RETURN, 100, WM_KEYDOWN, '\n', false, false);
439 std::u16string textChineseCharacter;
440 text.push_back(u'\u4F60');
441 handler.ComposeChangeHook(textChineseCharacter, 1);
442 handler.ComposeCommitHook();
443 handler.ComposeEndHook();
444
445 // Passes if it did not crash
446 }

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, message, and text.

## ◆ TEST_F() [101/119]

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

Definition at line 159 of file text_input_plugin_unittest.cc.

159 {
160 UseEngineWithView();
161
162 auto handled_message = CreateResponse(true);
163 auto unhandled_message = CreateResponse(false);
164 int received_scancode = 0;
165
166 TestBinaryMessenger messenger(
167 [&received_scancode, &handled_message, &unhandled_message](
168 const std::string& channel, const uint8_t* message,
169 size_t message_size, BinaryReply reply) {});
170
171 int redispatch_scancode = 0;
172 TextInputPlugin handler(&messenger, engine());
173
174 handler.KeyboardHook(VK_RETURN, 100, WM_KEYDOWN, '\n', false, false);
175 handler.ComposeBeginHook();
176 std::u16string text;
177 text.push_back('\n');
178 handler.ComposeChangeHook(text, 1);
179 handler.ComposeEndHook();
180
181 // Passes if it did not crash
182 }

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

## ◆ TEST_F() [102/119]

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

Definition at line 508 of file text_input_plugin_unittest.cc.

508 {
509 UseEngineWithView();
510
511 // A position of `EditableText`.
512 double view_x = 100;
513 double view_y = 200;
514
515 // A position and size of marked text, in `EditableText` local coordinates.
516 double ime_x = 3;
517 double ime_y = 4;
518 double ime_width = 50;
519 double ime_height = 60;
520
521 // Transformation matrix.
522 std::array<std::array<double, 4>, 4> editabletext_transform = {
523 1.0, 0.0, 0.0, view_x, //
524 0.0, 1.0, 0.0, view_y, //
525 0.0, 0.0, 0.0, 0.0, //
526 0.0, 0.0, 0.0, 1.0};
527
528 TestBinaryMessenger messenger([](const std::string& channel,
529 const uint8_t* message, size_t message_size,
530 BinaryReply reply) {});
531 BinaryReply reply_handler = [](const uint8_t* reply, size_t reply_size) {};
532
533 TextInputPlugin handler(&messenger, engine());
534
535 auto& codec = JsonMethodCodec::GetInstance();
536
537 EXPECT_CALL(*view(), OnCursorRectUpdated(Rect{{view_x, view_y}, {0, 0}}));
538
539 {
540 auto arguments =
541 std::make_unique<rapidjson::Document>(rapidjson::kObjectType);
542 auto& allocator = arguments->GetAllocator();
543
544 rapidjson::Value transoform(rapidjson::kArrayType);
545 for (int i = 0; i < 4 * 4; i++) {
546 // Pack 2-dimensional array by column-major order.
547 transoform.PushBack(editabletext_transform[i % 4][i / 4], allocator);
548 }
549
550 arguments->AddMember("transform", transoform, allocator);
551
552 auto message = codec.EncodeMethodCall(
553 {"TextInput.setEditableSizeAndTransform", std::move(arguments)});
554 messenger.SimulateEngineMessage(kChannelName, message->data(),
555 message->size(), reply_handler);
556 }
557
558 EXPECT_CALL(*view(),
559 OnCursorRectUpdated(Rect{{view_x + ime_x, view_y + ime_y},
560 {ime_width, ime_height}}));
561
562 {
563 auto arguments =
564 std::make_unique<rapidjson::Document>(rapidjson::kObjectType);
565 auto& allocator = arguments->GetAllocator();
566
567 arguments->AddMember("x", ime_x, allocator);
568 arguments->AddMember("y", ime_y, allocator);
569 arguments->AddMember("width", ime_width, allocator);
570 arguments->AddMember("height", ime_height, allocator);
571
572 auto message = codec.EncodeMethodCall(
573 {"TextInput.setMarkedTextRect", std::move(arguments)});
574 messenger.SimulateEngineMessage(kChannelName, message->data(),
575 message->size(), reply_handler);
576 }
577 }

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

## ◆ TEST_F() [103/119]

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

Definition at line 230 of file text_input_plugin_unittest.cc.

230 {
231 UseEngineWithView();
232
233 bool sent_message = false;
234 TestBinaryMessenger messenger(
235 [&sent_message](const std::string& channel, const uint8_t* message,
236 size_t message_size,
237 BinaryReply reply) { sent_message = true; });
238 BinaryReply reply_handler = [](const uint8_t* reply, size_t reply_size) {};
239
240 TextInputPlugin handler(&messenger, engine());
241
242 auto& codec = JsonMethodCodec::GetInstance();
243
244 // Call TextInput.setClient to initialize the TextInputModel.
245 auto arguments = std::make_unique<rapidjson::Document>(rapidjson::kArrayType);
246 auto& allocator = arguments->GetAllocator();
247 arguments->PushBack(kDefaultClientId, allocator);
248 rapidjson::Value config(rapidjson::kObjectType);
249 config.AddMember("inputAction", "done", allocator);
250 config.AddMember("inputType", "text", allocator);
251 config.AddMember(kEnableDeltaModel, false, allocator);
252 arguments->PushBack(config, allocator);
253 auto message =
254 codec.EncodeMethodCall({"TextInput.setClient", std::move(arguments)});
255 messenger.SimulateEngineMessage("flutter/textinput", message->data(),
256 message->size(), reply_handler);
257
258 // ComposeBeginHook should send state update.
259 sent_message = false;
260 handler.ComposeBeginHook();
261 EXPECT_TRUE(sent_message);
262
263 // ComposeChangeHook should send state update.
264 sent_message = false;
265 handler.ComposeChangeHook(u"4", 1);
266 EXPECT_TRUE(sent_message);
267
268 // ComposeCommitHook should NOT send state update.
269 //
270 // Commit messages are always immediately followed by a change message or an
271 // end message, both of which will send an update. Sending intermediate state
272 // with a collapsed composing region will trigger the framework to assume
273 // composing has ended, which is not the case until a WM_IME_ENDCOMPOSING
274 // event is received in the main event loop, which will trigger a call to
275 // ComposeEndHook.
276 sent_message = false;
277 handler.ComposeCommitHook();
278 EXPECT_FALSE(sent_message);
279
280 // ComposeEndHook should send state update.
281 sent_message = false;
282 handler.ComposeEndHook();
283 EXPECT_TRUE(sent_message);
284 }

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

## ◆ TEST_F() [104/119]

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

Definition at line 286 of file text_input_plugin_unittest.cc.

286 {
287 UseEngineWithView();
288
289 // Store messages as std::string for convenience.
290 std::vector<std::string> messages;
291
292 TestBinaryMessenger messenger(
293 [&messages](const std::string& channel, const uint8_t* message,
294 size_t message_size, BinaryReply reply) {
295 std::string last_message(reinterpret_cast<const char*>(message),
296 message_size);
297 messages.push_back(last_message);
298 });
299 BinaryReply reply_handler = [](const uint8_t* reply, size_t reply_size) {};
300
301 TextInputPlugin handler(&messenger, engine());
302
303 auto& codec = JsonMethodCodec::GetInstance();
304
305 // Call TextInput.setClient to initialize the TextInputModel.
306 auto set_client_arguments =
307 EncodedClientConfig("TextInputType.multiline", "TextInputAction.newline");
308 auto message = codec.EncodeMethodCall(
309 {"TextInput.setClient", std::move(set_client_arguments)});
310 messenger.SimulateEngineMessage("flutter/textinput", message->data(),
311 message->size(), reply_handler);
312
313 // Simulate a key down event for '\n'.
314 handler.KeyboardHook(VK_RETURN, 100, WM_KEYDOWN, '\n', false, false);
315
316 // Two messages are expected, the first is TextInput.updateEditingState and
317 // the second is TextInputClient.performAction.
318 EXPECT_EQ(messages.size(), 2);
319
320 // Editing state should have been updated.
321 auto encoded_arguments = EncodedEditingState("\n", TextRange(1));
322 auto update_state_message = codec.EncodeMethodCall(
323 {kUpdateEditingStateMethod, std::move(encoded_arguments)});
324
325 EXPECT_TRUE(std::equal(update_state_message->begin(),
326 update_state_message->end(),
327 messages.front().begin()));
328
329 // TextInputClient.performAction should have been called.
330 auto arguments = std::make_unique<rapidjson::Document>(rapidjson::kArrayType);
331 auto& allocator = arguments->GetAllocator();
332 arguments->PushBack(kDefaultClientId, allocator);
333 arguments->PushBack(
334 rapidjson::Value("TextInputAction.newline", allocator).Move(), allocator);
335 auto invoke_action_message = codec.EncodeMethodCall(
336 {"TextInputClient.performAction", std::move(arguments)});
337
338 EXPECT_TRUE(std::equal(invoke_action_message->begin(),
339 invoke_action_message->end(),
340 messages.back().begin()));
341 }

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

## ◆ TEST_F() [105/119]

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

Definition at line 344 of file text_input_plugin_unittest.cc.

344 {
345 UseEngineWithView();
346
347 std::vector<std::vector<uint8_t>> messages;
348
349 TestBinaryMessenger messenger(
350 [&messages](const std::string& channel, const uint8_t* message,
351 size_t message_size, BinaryReply reply) {
352 int length = static_cast<int>(message_size);
353 std::vector<uint8_t> last_message(length);
354 memcpy(&last_message[0], &message[0], length * sizeof(uint8_t));
355 messages.push_back(last_message);
356 });
357 BinaryReply reply_handler = [](const uint8_t* reply, size_t reply_size) {};
358
359 TextInputPlugin handler(&messenger, engine());
360
361 auto& codec = JsonMethodCodec::GetInstance();
362
363 // Call TextInput.setClient to initialize the TextInputModel.
364 auto set_client_arguments =
365 EncodedClientConfig("TextInputType.multiline", "TextInputAction.send");
366 auto message = codec.EncodeMethodCall(
367 {"TextInput.setClient", std::move(set_client_arguments)});
368 messenger.SimulateEngineMessage("flutter/textinput", message->data(),
369 message->size(), reply_handler);
370
371 // Simulate a key down event for '\n'.
372 handler.KeyboardHook(VK_RETURN, 100, WM_KEYDOWN, '\n', false, false);
373
374 // Only a call to TextInputClient.performAction is expected.
375 EXPECT_EQ(messages.size(), 1);
376
377 // TextInputClient.performAction should have been called.
378 auto arguments = std::make_unique<rapidjson::Document>(rapidjson::kArrayType);
379 auto& allocator = arguments->GetAllocator();
380 arguments->PushBack(kDefaultClientId, allocator);
381 arguments->PushBack(
382 rapidjson::Value("TextInputAction.send", allocator).Move(), allocator);
383 auto invoke_action_message = codec.EncodeMethodCall(
384 {"TextInputClient.performAction", std::move(arguments)});
385
386 EXPECT_TRUE(std::equal(invoke_action_message->begin(),
387 invoke_action_message->end(),
388 messages.front().begin()));
389 }

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

## ◆ TEST_F() [106/119]

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

Definition at line 15 of file windows_lifecycle_manager_unittests.cc.

15 {
16 WindowsLifecycleManager manager(nullptr);
17 HWND win1 = reinterpret_cast<HWND>(1);
18 HWND win2 = reinterpret_cast<HWND>(2);
19
20 // Hidden to inactive upon window shown.
21 manager.SetLifecycleState(AppLifecycleState::kHidden);
22 manager.OnWindowStateEvent(win1, WindowStateEvent::kShow);
23 EXPECT_EQ(manager.GetLifecycleState(), AppLifecycleState::kInactive);
24
25 // Showing a second window does not change state.
26 manager.OnWindowStateEvent(win2, WindowStateEvent::kShow);
27 EXPECT_EQ(manager.GetLifecycleState(), AppLifecycleState::kInactive);
28
29 // Inactive to resumed upon window focus.
30 manager.OnWindowStateEvent(win2, WindowStateEvent::kFocus);
31 EXPECT_EQ(manager.GetLifecycleState(), AppLifecycleState::kResumed);
32
33 // Showing a second window does not change state.
34 manager.OnWindowStateEvent(win1, WindowStateEvent::kFocus);
35 EXPECT_EQ(manager.GetLifecycleState(), AppLifecycleState::kResumed);
36
37 // Unfocusing one window does not change state while another is focused.
38 manager.OnWindowStateEvent(win1, WindowStateEvent::kUnfocus);
39 EXPECT_EQ(manager.GetLifecycleState(), AppLifecycleState::kResumed);
40
41 // Unfocusing final remaining focused window transitions to inactive.
42 manager.OnWindowStateEvent(win2, WindowStateEvent::kUnfocus);
43 EXPECT_EQ(manager.GetLifecycleState(), AppLifecycleState::kInactive);
44
45 // Hiding one of two visible windows does not change state.
46 manager.OnWindowStateEvent(win2, WindowStateEvent::kHide);
47 EXPECT_EQ(manager.GetLifecycleState(), AppLifecycleState::kInactive);
48
49 // Hiding only visible window transitions to hidden.
50 manager.OnWindowStateEvent(win1, WindowStateEvent::kHide);
51 EXPECT_EQ(manager.GetLifecycleState(), AppLifecycleState::kHidden);
52
53 // Transition directly from resumed to hidden when the window is hidden.
54 manager.OnWindowStateEvent(win1, WindowStateEvent::kShow);
55 manager.OnWindowStateEvent(win1, WindowStateEvent::kFocus);
56 manager.OnWindowStateEvent(win1, WindowStateEvent::kHide);
57 EXPECT_EQ(manager.GetLifecycleState(), AppLifecycleState::kHidden);
58 }

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

## ◆ TEST_F() [107/119]

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

Definition at line 285 of file flutter_windows_unittests.cc.

285 {
286 auto& context = GetContext();
287 WindowsConfigBuilder builder(context);
288 ViewControllerPtr controller{builder.Run()};
289 ASSERT_NE(controller, nullptr);
290 auto view = FlutterDesktopViewControllerGetView(controller.get());
291
292 Microsoft::WRL::ComPtr<IDXGIAdapter> dxgi_adapter;
293 dxgi_adapter = FlutterDesktopViewGetGraphicsAdapter(view);
294 ASSERT_NE(dxgi_adapter, nullptr);
295 DXGI_ADAPTER_DESC desc{};
296 ASSERT_TRUE(SUCCEEDED(dxgi_adapter->GetDesc(&desc)));
297 }

References FlutterDesktopViewControllerGetView(), and FlutterDesktopViewGetGraphicsAdapter().

## ◆ TEST_F() [108/119]

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

Definition at line 124 of file flutter_windows_unittests.cc.

124 {
125 auto& context = GetContext();
126 WindowsConfigBuilder builder(context);
127 builder.SetDartEntrypoint("customEntrypoint");
128 EnginePtr engine{builder.InitializeEngine()};
129 ASSERT_NE(engine, nullptr);
130
131 ASSERT_FALSE(FlutterDesktopEngineRun(engine.get(), "conflictingEntrypoint"));
132 }

References FlutterDesktopEngineRun().

## ◆ TEST_F() [109/119]

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

Definition at line 66 of file flutter_windows_unittests.cc.

66 {
67 auto& context = GetContext();
68 WindowsConfigBuilder builder(context);
69 builder.SetDartEntrypoint("customEntrypoint");
70 ViewControllerPtr controller{builder.Run()};
71 ASSERT_NE(controller, nullptr);
72 }

## ◆ TEST_F() [110/119]

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

Definition at line 79 of file flutter_windows_unittests.cc.

79 {
80 auto& context = GetContext();
81 WindowsConfigBuilder builder(context);
82 EnginePtr engine{builder.InitializeEngine()};
83 ASSERT_NE(engine, nullptr);
84
85 ASSERT_TRUE(FlutterDesktopEngineRun(engine.get(), "customEntrypoint"));
86 }

References FlutterDesktopEngineRun().

## ◆ TEST_F() [111/119]

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

Definition at line 89 of file flutter_windows_unittests.cc.

89 {
90 auto& context = GetContext();
91 WindowsConfigBuilder builder(context);
92 EnginePtr engine{builder.InitializeEngine()};
93 ASSERT_NE(engine, nullptr);
94
95 ASSERT_TRUE(FlutterDesktopEngineRun(engine.get(), nullptr));
96 }

References FlutterDesktopEngineRun().

## ◆ TEST_F() [112/119]

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

Definition at line 39 of file flutter_windows_unittests.cc.

39 {
40 auto& context = GetContext();
41 WindowsConfigBuilder builder(context);
42 ViewControllerPtr controller{builder.Run()};
43 ASSERT_NE(controller, nullptr);
44 }

## ◆ TEST_F() [113/119]

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

Definition at line 47 of file flutter_windows_unittests.cc.

47 {
48 // Replace stdout & stderr stream buffers with our own.
49 StreamCapture stdout_capture(&std::cout);
50 StreamCapture stderr_capture(&std::cerr);
51
52 auto& context = GetContext();
53 WindowsConfigBuilder builder(context);
54 ViewControllerPtr controller{builder.Run()};
55 ASSERT_NE(controller, nullptr);
56
57 stdout_capture.Stop();
58 stderr_capture.Stop();
59
60 // Verify stdout & stderr have no output.
61 EXPECT_TRUE(stdout_capture.GetOutput().empty());
62 EXPECT_TRUE(stderr_capture.GetOutput().empty());
63 }

## ◆ TEST_F() [114/119]

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

Definition at line 99 of file flutter_windows_unittests.cc.

99 {
100 auto& context = GetContext();
101 WindowsConfigBuilder builder(context);
102 EnginePtr engine{builder.InitializeEngine()};
103 EngineModifier modifier{
104 reinterpret_cast<FlutterWindowsEngine*>(engine.get())};
105
106 auto called = false;
107 modifier.embedder_api().UpdateAccessibilityFeatures = MOCK_ENGINE_PROC(
108 UpdateAccessibilityFeatures, ([&called](auto engine, auto flags) {
109 called = true;
110 return kSuccess;
111 }));
112
113 ViewControllerPtr controller{
114 FlutterDesktopViewControllerCreate(0, 0, engine.release())};
115
116 ASSERT_TRUE(called);
117 }

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

## ◆ TEST_F() [115/119]

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

Definition at line 232 of file flutter_windows_unittests.cc.

232 {
233 struct Captures {
234 fml::AutoResetWaitableEvent frame_scheduled_latch;
235 fml::AutoResetWaitableEvent frame_drawn_latch;
236 std::thread::id thread_id;
237 };
238 Captures captures;
239
240 CreateNewThread("test_platform_thread")->PostTask([&]() {
241 captures.thread_id = std::this_thread::get_id();
242
243 auto& context = GetContext();
244 WindowsConfigBuilder builder(context);
245 builder.SetDartEntrypoint("drawHelloWorld");
246
247 auto native_entry = CREATE_NATIVE_ENTRY([&](Dart_NativeArguments args) {
248 ASSERT_FALSE(captures.frame_drawn_latch.IsSignaledForTest());
249 captures.frame_scheduled_latch.Signal();
250 });
251 context.AddNativeFunction("NotifyFirstFrameScheduled", native_entry);
252
253 ViewControllerPtr controller{builder.Run()};
254 ASSERT_NE(controller, nullptr);
255
256 auto engine = FlutterDesktopViewControllerGetEngine(controller.get());
257
258 FlutterDesktopEngineSetNextFrameCallback(
259 engine,
260 [](void* user_data) {
261 auto captures = static_cast<Captures*>(user_data);
262
263 ASSERT_TRUE(captures->frame_scheduled_latch.IsSignaledForTest());
264
265 // Callback should execute on platform thread.
266 ASSERT_EQ(std::this_thread::get_id(), captures->thread_id);
267
268 // Signal the test passed and end the Windows message loop.
269 captures->frame_drawn_latch.Signal();
270 ::PostQuitMessage(0);
271 },
272 &captures);
273
274 // Pump messages for the Windows platform task runner.
275 ::MSG msg;
276 while (::GetMessage(&msg, nullptr, 0, 0)) {
277 ::TranslateMessage(&msg);
278 ::DispatchMessage(&msg);
279 }
280 });
281
282 captures.frame_drawn_latch.Wait();
283 }

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

## ◆ TEST_F() [116/119]

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

Definition at line 177 of file flutter_windows_unittests.cc.

177 {
178 auto& context = GetContext();
179 WindowsConfigBuilder builder(context);
180 builder.SetDartEntrypoint("readPlatformExecutable");
181
182 std::string executable_name;
183 fml::AutoResetWaitableEvent latch;
184 auto native_entry = CREATE_NATIVE_ENTRY([&](Dart_NativeArguments args) {
185 auto handle = Dart_GetNativeArgument(args, 0);
186 ASSERT_FALSE(Dart_IsError(handle));
187 executable_name = tonic::DartConverter<std::string>::FromDart(handle);
188 latch.Signal();
189 });
190 context.AddNativeFunction("SignalStringValue", native_entry);
191
192 ViewControllerPtr controller{builder.Run()};
193 ASSERT_NE(controller, nullptr);
194
195 // Wait until signalStringValue has been called.
196 latch.Wait();
197 EXPECT_EQ(executable_name, "flutter_windows_unittests.exe");
198 }

## ◆ TEST_F() [117/119]

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

Definition at line 135 of file flutter_windows_unittests.cc.

135 {
136 auto& context = GetContext();
137 WindowsConfigBuilder builder(context);
138 builder.SetDartEntrypoint("verifyNativeFunction");
139
140 fml::AutoResetWaitableEvent latch;
141 auto native_entry =
142 CREATE_NATIVE_ENTRY([&](Dart_NativeArguments args) { latch.Signal(); });
143 context.AddNativeFunction("Signal", native_entry);
144
145 ViewControllerPtr controller{builder.Run()};
146 ASSERT_NE(controller, nullptr);
147
148 // Wait until signal has been called.
149 latch.Wait();
150 }

## ◆ TEST_F() [118/119]

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

Definition at line 154 of file flutter_windows_unittests.cc.

154 {
155 auto& context = GetContext();
156 WindowsConfigBuilder builder(context);
157 builder.SetDartEntrypoint("verifyNativeFunctionWithParameters");
158
159 bool bool_value = false;
160 fml::AutoResetWaitableEvent latch;
161 auto native_entry = CREATE_NATIVE_ENTRY([&](Dart_NativeArguments args) {
162 auto handle = Dart_GetNativeBooleanArgument(args, 0, &bool_value);
163 ASSERT_FALSE(Dart_IsError(handle));
164 latch.Signal();
165 });
166 context.AddNativeFunction("SignalBoolValue", native_entry);
167
168 ViewControllerPtr controller{builder.Run()};
169 ASSERT_NE(controller, nullptr);
170
171 // Wait until signalBoolValue has been called.
172 latch.Wait();
173 EXPECT_TRUE(bool_value);
174 }

## ◆ TEST_F() [119/119]

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

Definition at line 202 of file flutter_windows_unittests.cc.

202 {
203 auto& context = GetContext();
204 WindowsConfigBuilder builder(context);
205 builder.SetDartEntrypoint("verifyNativeFunctionWithReturn");
206
207 bool bool_value_to_return = true;
208 fml::CountDownLatch latch(2);
209 auto bool_return_entry = CREATE_NATIVE_ENTRY([&](Dart_NativeArguments args) {
210 Dart_SetBooleanReturnValue(args, bool_value_to_return);
211 latch.CountDown();
212 });
213 context.AddNativeFunction("SignalBoolReturn", bool_return_entry);
214
215 bool bool_value_passed = false;
216 auto bool_pass_entry = CREATE_NATIVE_ENTRY([&](Dart_NativeArguments args) {
217 auto handle = Dart_GetNativeBooleanArgument(args, 0, &bool_value_passed);
218 ASSERT_FALSE(Dart_IsError(handle));
219 latch.CountDown();
220 });
221 context.AddNativeFunction("SignalBoolValue", bool_pass_entry);
222
223 ViewControllerPtr controller{builder.Run()};
224 ASSERT_NE(controller, nullptr);
225
226 // Wait until signalBoolReturn and signalBoolValue have been called.
227 latch.Wait();
228 EXPECT_TRUE(bool_value_passed);
229 }

## ◆ VietnameseTelexAddDiacriticWithSlowResponse()

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

Definition at line 2340 of file keyboard_unittests.cc.

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

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

Referenced by TEST_F().

## Variable Documentation

## ◆ kScanCodeKeyA

constexpr uint64_t flutter::testing::kScanCodeKeyA = 0x1e
| constexpr

Definition at line 38 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 39 of file flutter_windows_view_unittests.cc.

Referenced by TEST(), TEST_F(), and VietnameseTelexAddDiacriticWithSlowResponse().

flutter::testing::VietnameseTelexAddDiacriticWithSlowResponse
void VietnameseTelexAddDiacriticWithSlowResponse(WindowsTestContext &context, bool backspace_response)
Definition: keyboard_unittests.cc:2340
flutter::testing::CreateSemanticsNode
FlutterSemanticsNode2 CreateSemanticsNode(int32_t id, const char *label, const std::vector< int32_t > *children=nullptr)
Definition: accessibility_bridge_unittests.cc:18
flutter::WindowStateEvent
WindowStateEvent
An event representing a change in window state that may update the.
Definition: windows_lifecycle_manager.h:24
FlutterDesktopViewControllerGetView
FlutterDesktopViewRef FlutterDesktopViewControllerGetView(FlutterDesktopViewControllerRef ref)
Definition: flutter_windows.cc:120
FlutterDesktopEngineGetTextureRegistrar
FlutterDesktopTextureRegistrarRef FlutterDesktopEngineGetTextureRegistrar(FlutterDesktopEngineRef engine)
Definition: flutter_windows.cc:200
hook_history
std::list< KeyboardHookCall > * hook_history
Definition: keyboard_key_handler_unittests.cc:171
scancode
int scancode
Definition: keyboard_key_handler_unittests.cc:115
user_data
void * user_data
Definition: keyboard_key_embedder_handler_unittests.cc:48
FlutterDesktopEngineProperties
Definition: flutter_windows.h:36
kFlutterDesktopGpuSurfaceTexture
@ kFlutterDesktopGpuSurfaceTexture
Definition: flutter_texture_registrar.h:28
was_down
bool was_down
Definition: keyboard_key_handler_unittests.cc:119
extended
bool extended
Definition: keyboard_key_handler_unittests.cc:118
flutter::GetPreferredLanguageInfo
std::vector< LanguageInfo > GetPreferredLanguageInfo(const WindowsProcTable &windows_proc_table)
Definition: system_utils.cc:15
FlutterDesktopBinaryReply
void(* FlutterDesktopBinaryReply)(const uint8_t *data, size_t data_size, void *user_data)
Definition: flutter_messenger.h:26
flutter::GetDpiForMonitor
UINT GetDpiForMonitor(HMONITOR monitor)
Definition: dpi_utils.cc:134
user_data
void * user_data
Definition: flutter_windows_view_unittests.cc:49
FlutterDesktopPixelBuffer
Definition: flutter_texture_registrar.h:56
kDeleteCustomCursorMethod
static constexpr char kDeleteCustomCursorMethod[]
Definition: cursor_handler.cc:42
character
char32_t character
Definition: keyboard_key_handler_unittests.cc:117
kUpdateEditingStateMethod
static constexpr char kUpdateEditingStateMethod[]
Definition: text_input_plugin.cc:28
FlutterDesktopEngineProperties::dart_entrypoint_argv
const char ** dart_entrypoint_argv
Definition: flutter_windows.h:66
flutter::EncodeUtf16
std::u16string EncodeUtf16(char32_t character)
Definition: keyboard_utils.cc:11
EXPECT_CALL_IS_EVENT
#define EXPECT_CALL_IS_EVENT(_key_call,...)
Definition: keyboard_unittests.cc:547
FlutterDesktopPixelBufferTextureConfig::user_data
void * user_data
Definition: flutter_texture_registrar.h:134
FlutterDesktopGpuSurfaceDescriptor::visible_width
size_t visible_width
Definition: flutter_texture_registrar.h:93
kSetCustomCursorMethod
static constexpr char kSetCustomCursorMethod[]
Definition: cursor_handler.cc:38
EXPECT_CALL_IS_TEXT
#define EXPECT_CALL_IS_TEXT(_key_call, u16_string)
Definition: keyboard_unittests.cc:551
flutter::kScanCodeShiftLeft
constexpr int kScanCodeShiftLeft
Definition: keyboard_utils.h:16
FlutterDesktopEngineProperties::icu_data_path
const wchar_t * icu_data_path
Definition: flutter_windows.h:45
flutter::GetDpiForHWND
UINT GetDpiForHWND(HWND hwnd)
Definition: dpi_utils.cc:130
flutter::GetUserTimeFormat
std::wstring GetUserTimeFormat()
Definition: system_utils.cc:101
user_data
void * user_data
Definition: keyboard_key_handler_unittests.cc:56
FlutterDesktopGpuSurfaceTextureConfig::user_data
void * user_data
Definition: flutter_texture_registrar.h:148
flutter::Prefer24HourTime
bool Prefer24HourTime(std::wstring time_format)
Definition: system_utils.cc:113
FlutterDesktopPixelBufferTextureConfig::callback
FlutterDesktopPixelBufferTextureCallback callback
Definition: flutter_texture_registrar.h:132
kEnableDeltaModel
static constexpr char kEnableDeltaModel[]
Definition: text_input_plugin.cc:39
FlutterDesktopTextureType
FlutterDesktopTextureType
Definition: flutter_texture_registrar.h:24
FlutterDesktopGpuSurfaceDescriptor::release_callback
void(* release_callback)(void *release_context)
Definition: flutter_texture_registrar.h:100
kSelectionExtentKey
static constexpr char kSelectionExtentKey[]
Definition: text_input_plugin.cc:48
kActivateSystemCursorMethod
static constexpr char kActivateSystemCursorMethod[]
Definition: cursor_handler.cc:15
flutter::ParseLanguageName
LanguageInfo ParseLanguageName(std::wstring language_name)
Definition: system_utils.cc:71
text
std::u16string text
Definition: keyboard_unittests.cc:332
FlutterDesktopTextureInfo::type
FlutterDesktopTextureType type
Definition: flutter_texture_registrar.h:152
FlutterDesktopGpuSurfaceDescriptor::visible_height
size_t visible_height
Definition: flutter_texture_registrar.h:96
FlutterDesktopGpuSurfaceDescriptor::release_context
void * release_context
Definition: flutter_texture_registrar.h:102
flutter::testing::kScanCodeKeyA
constexpr uint64_t kScanCodeKeyA
Definition: flutter_windows_view_unittests.cc:38
FlutterDesktopGpuSurfaceTextureConfig::struct_size
size_t struct_size
Definition: flutter_texture_registrar.h:141
FlutterDesktopTextureInfo::pixel_buffer_config
FlutterDesktopPixelBufferTextureConfig pixel_buffer_config
Definition: flutter_texture_registrar.h:154
FlutterDesktopGpuSurfaceDescriptor::height
size_t height
Definition: flutter_texture_registrar.h:90
flutter::BinaryReply
std::function< void(const uint8_t *reply, size_t reply_size)> BinaryReply
Definition: binary_messenger.h:17
FlutterDesktopGpuSurfaceTextureConfig::type
FlutterDesktopGpuSurfaceType type
Definition: flutter_texture_registrar.h:144
FlutterDesktopTextureInfo
Definition: flutter_texture_registrar.h:151
type
enum flutter::testing::@69::KeyboardChange::Type type
flutter::ConvertChar32ToUtf8
std::string ConvertChar32ToUtf8(char32_t ch)
Definition: keyboard_key_embedder_handler.cc:38
FlutterDesktopGpuSurfaceTextureConfig::callback
FlutterDesktopGpuSurfaceTextureCallback callback
Definition: flutter_texture_registrar.h:146
kErrorSuccess
static constexpr int kErrorSuccess
Definition: platform_handler.cc:45
FlutterDesktopPixelBuffer::release_context
void * release_context
Definition: flutter_texture_registrar.h:66
kSelectionBaseKey
static constexpr char kSelectionBaseKey[]
Definition: text_input_plugin.cc:47
content
union flutter::testing::@69::KeyboardChange::@0 content
FlutterDesktopGpuSurfaceDescriptor
Definition: flutter_texture_registrar.h:70
EXPECT_CALL_IS_TEXT_METHOD_CALL
#define EXPECT_CALL_IS_TEXT_METHOD_CALL(_key_call, json_string)
Definition: keyboard_unittests.cc:555
flutter::kShift
constexpr int kShift
Definition: keyboard_utils.h:14
kFlutterDesktopGpuSurfaceTypeD3d11Texture2D
@ kFlutterDesktopGpuSurfaceTypeD3d11Texture2D
Definition: flutter_texture_registrar.h:40
FlutterDesktopTextureInfo::gpu_surface_config
FlutterDesktopGpuSurfaceTextureConfig gpu_surface_config
Definition: flutter_texture_registrar.h:155
FlutterDesktopPixelBuffer::buffer
const uint8_t * buffer
Definition: flutter_texture_registrar.h:58
kCreateCustomCursorMethod
static constexpr char kCreateCustomCursorMethod[]
Definition: cursor_handler.cc:20
kFlutterDesktopGpuSurfaceTypeDxgiSharedHandle
@ kFlutterDesktopGpuSurfaceTypeDxgiSharedHandle
Definition: flutter_texture_registrar.h:38
kSetClientMethod
static constexpr char kSetClientMethod[]
Definition: text_input_plugin.cc:19
kChannelName
static constexpr char kChannelName[]
Definition: cursor_handler.cc:13
callback
FlutterKeyEventCallback callback
Definition: keyboard_key_handler_unittests.cc:55
FlutterDesktopEngineDestroy
bool FlutterDesktopEngineDestroy(FlutterDesktopEngineRef engine_ref)
Definition: flutter_windows.cc:157
flutter::kScanCodeControlLeft
constexpr int kScanCodeControlLeft
Definition: keyboard_utils.h:19
FlutterDesktopEngineCreate
FlutterDesktopEngineRef FlutterDesktopEngineCreate(const FlutterDesktopEngineProperties *engine_properties)
Definition: flutter_windows.cc:150
FlutterDesktopViewControllerGetEngine
FlutterDesktopEngineRef FlutterDesktopViewControllerGetEngine(FlutterDesktopViewControllerRef ref)
Definition: flutter_windows.cc:114
FlutterDesktopGpuSurfaceDescriptor::handle
void * handle
Definition: flutter_texture_registrar.h:86
callback
FlutterKeyEventCallback callback
Definition: keyboard_key_embedder_handler_unittests.cc:47
FlutterDesktopGpuSurfaceTextureConfig
Definition: flutter_texture_registrar.h:138
FlutterDesktopEngineProperties::dart_entrypoint_argc
int dart_entrypoint_argc
Definition: flutter_windows.h:62
FlutterDesktopPixelBuffer::width
size_t width
Definition: flutter_texture_registrar.h:60
message
Win32Message message
Definition: keyboard_unittests.cc:137
action
int action
Definition: keyboard_key_handler_unittests.cc:116
flutter::kScanCodeControlRight
constexpr int kScanCodeControlRight
Definition: keyboard_utils.h:20
flutter::AppLifecycleState
AppLifecycleState
Definition: app_lifecycle_state.h:32
FlutterDesktopEngineSetNextFrameCallback
void FlutterDesktopEngineSetNextFrameCallback(FlutterDesktopEngineRef engine, VoidCallback callback, void *user_data)
Definition: flutter_windows.cc:206
kAccessDeniedErrorCode
static constexpr int kAccessDeniedErrorCode
Definition: platform_handler.cc:44
flutter::kControl
constexpr int kControl
Definition: keyboard_utils.h:15
flutter::kScanCodeShiftRight
constexpr int kScanCodeShiftRight
Definition: keyboard_utils.h:17
FlutterDesktopPixelBuffer::release_callback
void(* release_callback)(void *release_context)
Definition: flutter_texture_registrar.h:64
FlutterDesktopGpuSurfaceDescriptor::struct_size
size_t struct_size
Definition: flutter_texture_registrar.h:73
FlutterDesktopViewGetGraphicsAdapter
IDXGIAdapter * FlutterDesktopViewGetGraphicsAdapter(FlutterDesktopViewRef view)
Definition: flutter_windows.cc:217
flutter::EncodableMap
std::map< EncodableValue, EncodableValue > EncodableMap
Definition: encodable_value.h:95
FlutterDesktopEngineProperties::assets_path
const wchar_t * assets_path
Definition: flutter_windows.h:40
key
int key
Definition: keyboard_key_handler_unittests.cc:114
texture_id
int64_t texture_id
Definition: texture_registrar_unittests.cc:24
FlutterDesktopGpuSurfaceDescriptor::width
size_t width
Definition: flutter_texture_registrar.h:88
FlutterDesktopPluginRegistrar
Definition: window_state.h:23
FlutterDesktopEngineRun
bool FlutterDesktopEngineRun(FlutterDesktopEngineRef engine, const char *entry_point)
Definition: flutter_windows.cc:167
kFlutterDesktopPixelBufferTexture
@ kFlutterDesktopPixelBufferTexture
Definition: flutter_texture_registrar.h:26
flutter::testing::kVirtualKeyA
constexpr uint64_t kVirtualKeyA
Definition: flutter_windows_view_unittests.cc:39
FlutterDesktopPixelBuffer::height
size_t height
Definition: flutter_texture_registrar.h:62
flutter::WindowsPlatformThreadPrioritySetter
static void WindowsPlatformThreadPrioritySetter(FlutterThreadPriority priority)
Definition: flutter_windows_engine.h:48
flutter::GetPreferredLanguages
std::vector< std::wstring > GetPreferredLanguages(const WindowsProcTable &windows_proc_table)
Definition: system_utils.cc:45
FlutterDesktopViewControllerCreate
FlutterDesktopViewControllerRef FlutterDesktopViewControllerCreate(int width, int height, FlutterDesktopEngineRef engine_ref)
Definition: flutter_windows.cc:75
callback
FlutterDesktopBinaryReply callback
Definition: flutter_windows_view_unittests.cc:48
node_delegate
std::shared_ptr< FlutterPlatformNodeDelegateWindows > node_delegate
Definition: accessibility_bridge_windows_unittests.cc:32