| 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 | 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, InitialAccessibilityFeatures)
| 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, 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, DisablesVSync)
| TEST (FlutterWindowsViewTest, EnablesVSync)
| 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 (TextInputPluginTest, TextMethodsWorksWithEmptyModel)
| TEST (TextInputPluginTest, ClearClientResetsComposing)
| TEST (TextInputPluginTest, VerifyComposingSendStateUpdate)
| TEST (TextInputPluginTest, VerifyInputActionNewlineInsertNewLine)
| TEST (TextInputPluginTest, VerifyInputActionSendDoesNotInsertNewLine)
| TEST (TextInputPluginTest, TextEditingWorksWithDeltaModel)
| TEST (TextInputPluginTest, CompositionCursorPos)
| TEST (TextInputPluginTest, TransformCursorRect)
| 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, ToggleHasToggleButtonRole)
| 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/173]

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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::kToggleButton);
269 }

References CreateSemanticsNode().

## ◆ TEST() [15/173]

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

Definition at line 263 of file accessibility_bridge_windows_unittests.cc.

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

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

## ◆ TEST() [16/173]

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

Definition at line 233 of file accessibility_bridge_windows_unittests.cc.

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

## ◆ TEST() [17/173]

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

Definition at line 249 of file accessibility_bridge_windows_unittests.cc.

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

## ◆ TEST() [18/173]

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

Definition at line 289 of file accessibility_bridge_windows_unittests.cc.

289 {
290 ExpectWinEventFromAXEvent(0, ui::AXEventGenerator::Event::ALERT,
291 ax::mojom::Event::kAlert);
292 }

## ◆ TEST() [19/173]

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

Definition at line 294 of file accessibility_bridge_windows_unittests.cc.

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

## ◆ TEST() [20/173]

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

Definition at line 299 of file accessibility_bridge_windows_unittests.cc.

299 {
300 auto window_binding_handler =
301 std::make_unique<::testing::NiceMock<MockWindowBindingHandler>>();
302 FlutterWindowsViewSpy view(std::move(window_binding_handler));
303 view.SetEngine(GetTestEngine());
304 view.OnUpdateSemanticsEnabled(true);
305
306 auto bridge = GetAccessibilityBridgeSpy(view);
307 PopulateAXTree(bridge);
308
309 bridge->ResetRecords();
310 bridge->OnAccessibilityEvent({AXNodeFromID(bridge, 1),
311 {ui::AXEventGenerator::Event::FOCUS_CHANGED,
312 ax::mojom::EventFrom::kNone,
313 {}}});
314 ASSERT_EQ(bridge->dispatched_events().size(), 1);
315 EXPECT_EQ(bridge->dispatched_events()[0].event_type,
316 ax::mojom::Event::kFocus);
317
318 ASSERT_EQ(bridge->focused_nodes().size(), 1);
319 EXPECT_EQ(bridge->focused_nodes()[0], 1);
320 }

## ◆ TEST() [21/173]

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

Definition at line 322 of file accessibility_bridge_windows_unittests.cc.

322 {
323 // Static test nodes with no text, hint, or scrollability are ignored.
324 ExpectWinEventFromAXEvent(4, ui::AXEventGenerator::Event::IGNORED_CHANGED,
325 ax::mojom::Event::kHide);
326 }

## ◆ TEST() [22/173]

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

Definition at line 344 of file accessibility_bridge_windows_unittests.cc.

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

## ◆ TEST() [23/173]

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

Definition at line 328 of file accessibility_bridge_windows_unittests.cc.

328 {
329 ExpectWinEventFromAXEvent(
330 1, ui::AXEventGenerator::Event::IMAGE_ANNOTATION_CHANGED,
331 ax::mojom::Event::kTextChanged);
332 }

## ◆ TEST() [24/173]

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

Definition at line 334 of file accessibility_bridge_windows_unittests.cc.

334 {
335 ExpectWinEventFromAXEvent(1, ui::AXEventGenerator::Event::LIVE_REGION_CHANGED,
336 ax::mojom::Event::kLiveRegionChanged);
337 }

## ◆ TEST() [25/173]

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

Definition at line 339 of file accessibility_bridge_windows_unittests.cc.

339 {
340 ExpectWinEventFromAXEvent(1, ui::AXEventGenerator::Event::NAME_CHANGED,
341 ax::mojom::Event::kTextChanged);
342 }

## ◆ TEST() [26/173]

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

Definition at line 356 of file accessibility_bridge_windows_unittests.cc.

356 {
357 ExpectWinEventFromAXEvent(1, ui::AXEventGenerator::Event::SELECTED_CHANGED,
358 ax::mojom::Event::kValueChanged);
359 }

## ◆ TEST() [27/173]

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

Definition at line 361 of file accessibility_bridge_windows_unittests.cc.

361 {
362 ExpectWinEventFromAXEvent(
363 2, ui::AXEventGenerator::Event::SELECTED_CHILDREN_CHANGED,
364 ax::mojom::Event::kSelectedChildrenChanged);
365 }

## ◆ TEST() [28/173]

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

Definition at line 377 of file accessibility_bridge_windows_unittests.cc.

377 {
378 ExpectWinEventFromAXEvent(
379 1, ui::AXEventGenerator::Event::WIN_IACCESSIBLE_STATE_CHANGED,
380 ax::mojom::Event::kStateChanged);
381 }

## ◆ TEST() [29/173]

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

Definition at line 367 of file accessibility_bridge_windows_unittests.cc.

367 {
368 ExpectWinEventFromAXEvent(0, ui::AXEventGenerator::Event::SUBTREE_CREATED,
369 ax::mojom::Event::kShow);
370 }

## ◆ TEST() [30/173]

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

Definition at line 372 of file accessibility_bridge_windows_unittests.cc.

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

## ◆ TEST() [31/173]

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

Definition at line 350 of file accessibility_bridge_windows_unittests.cc.

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

## ◆ TEST() [32/173]

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

Definition at line 383 of file accessibility_bridge_windows_unittests.cc.

383 {
384 ExpectWinEventFromAXEventOnFocusNode(
385 1, ui::AXEventGenerator::Event::DOCUMENT_SELECTION_CHANGED,
386 ax::mojom::Event::kDocumentSelectionChanged, 2);
387 }

## ◆ TEST() [33/173]

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Definition at line 63 of file flutter_windows_texture_registrar_unittests.cc.

63 {
64 std::unique_ptr<FlutterWindowsEngine> engine = GetTestEngine();
65 std::unique_ptr<MockGlFunctions> gl = std::make_unique<MockGlFunctions>();
66 FlutterWindowsTextureRegistrar registrar(engine.get(), gl->gl_procs());
67
68 EXPECT_TRUE(true);
69 }

## ◆ TEST() [54/173]

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

Definition at line 247 of file flutter_windows_texture_registrar_unittests.cc.

247 {
248 std::unique_ptr<FlutterWindowsEngine> engine = GetTestEngine();
249 std::unique_ptr<MockGlFunctions> gl = std::make_unique<MockGlFunctions>();
250 FlutterWindowsTextureRegistrar registrar(engine.get(), gl->gl_procs());
251
252 UINT width = 100;
253 UINT height = 100;
254 auto d3d_texture = CreateD3dTexture(engine.get(), width, height);
255 EXPECT_TRUE(d3d_texture);
256
257 bool release_callback_called = false;
258 FlutterDesktopGpuSurfaceDescriptor surface_descriptor = {};
259 surface_descriptor.struct_size = sizeof(FlutterDesktopGpuSurfaceDescriptor);
260 surface_descriptor.handle = d3d_texture.Get();
261 surface_descriptor.width = surface_descriptor.visible_width = width;
262 surface_descriptor.height = surface_descriptor.visible_height = height;
263 surface_descriptor.release_context = &release_callback_called;
264 surface_descriptor.release_callback = [](void* release_context) {
265 bool* called = reinterpret_cast<bool*>(release_context);
266 *called = true;
267 };
268
269 FlutterDesktopTextureInfo texture_info = {};
270 texture_info.type = kFlutterDesktopGpuSurfaceTexture;
271 texture_info.gpu_surface_config.struct_size =
272 sizeof(FlutterDesktopGpuSurfaceTextureConfig);
273 texture_info.gpu_surface_config.type =
274 kFlutterDesktopGpuSurfaceTypeD3d11Texture2D;
275 texture_info.gpu_surface_config.user_data = &surface_descriptor;
276 texture_info.gpu_surface_config.callback =
277 [](size_t width, size_t height,
278 void* user_data) -> const FlutterDesktopGpuSurfaceDescriptor* {
279 return reinterpret_cast<const FlutterDesktopGpuSurfaceDescriptor*>(
280 user_data);
281 };
282
283 FlutterOpenGLTexture flutter_texture = {};
284 auto texture_id = registrar.RegisterTexture(&texture_info);
285 EXPECT_NE(texture_id, -1);
286
287 auto result =
288 registrar.PopulateTexture(texture_id, 640, 480, &flutter_texture);
289 EXPECT_TRUE(result);
290 EXPECT_EQ(flutter_texture.width, width);
291 EXPECT_EQ(flutter_texture.height, height);
292 EXPECT_EQ(flutter_texture.target, GL_TEXTURE_2D);
293 EXPECT_TRUE(release_callback_called);
294 }

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

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

Definition at line 192 of file flutter_windows_texture_registrar_unittests.cc.

192 {
193 std::unique_ptr<FlutterWindowsEngine> engine = GetTestEngine();
194 std::unique_ptr<MockGlFunctions> gl = std::make_unique<MockGlFunctions>();
195 FlutterWindowsTextureRegistrar registrar(engine.get(), gl->gl_procs());
196
197 UINT width = 100;
198 UINT height = 100;
199 auto d3d_texture = CreateD3dTexture(engine.get(), width, height);
200 EXPECT_TRUE(d3d_texture);
201
202 ComPtr<IDXGIResource> shared_resource;
203 EXPECT_TRUE(SUCCEEDED(d3d_texture.As(&shared_resource)));
204
205 HANDLE shared_handle;
206 EXPECT_TRUE(SUCCEEDED(shared_resource->GetSharedHandle(&shared_handle)));
207
208 bool release_callback_called = false;
209 FlutterDesktopGpuSurfaceDescriptor surface_descriptor = {};
210 surface_descriptor.struct_size = sizeof(FlutterDesktopGpuSurfaceDescriptor);
211 surface_descriptor.handle = shared_handle;
212 surface_descriptor.width = surface_descriptor.visible_width = width;
213 surface_descriptor.height = surface_descriptor.visible_height = height;
214 surface_descriptor.release_context = &release_callback_called;
215 surface_descriptor.release_callback = [](void* release_context) {
216 bool* called = reinterpret_cast<bool*>(release_context);
217 *called = true;
218 };
219
220 FlutterDesktopTextureInfo texture_info = {};
221 texture_info.type = kFlutterDesktopGpuSurfaceTexture;
222 texture_info.gpu_surface_config.struct_size =
223 sizeof(FlutterDesktopGpuSurfaceTextureConfig);
224 texture_info.gpu_surface_config.type =
225 kFlutterDesktopGpuSurfaceTypeDxgiSharedHandle;
226 texture_info.gpu_surface_config.user_data = &surface_descriptor;
227 texture_info.gpu_surface_config.callback =
228 [](size_t width, size_t height,
229 void* user_data) -> const FlutterDesktopGpuSurfaceDescriptor* {
230 return reinterpret_cast<const FlutterDesktopGpuSurfaceDescriptor*>(
231 user_data);
232 };
233
234 FlutterOpenGLTexture flutter_texture = {};
235 auto texture_id = registrar.RegisterTexture(&texture_info);
236 EXPECT_NE(texture_id, -1);
237
238 auto result =
239 registrar.PopulateTexture(texture_id, 640, 480, &flutter_texture);
240 EXPECT_TRUE(result);
241 EXPECT_EQ(flutter_texture.width, width);
242 EXPECT_EQ(flutter_texture.height, height);
243 EXPECT_EQ(flutter_texture.target, GL_TEXTURE_2D);
244 EXPECT_TRUE(release_callback_called);
245 }

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

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

Definition at line 296 of file flutter_windows_texture_registrar_unittests.cc.

296 {
297 std::unique_ptr<FlutterWindowsEngine> engine = GetTestEngine();
298 std::unique_ptr<MockGlFunctions> gl = std::make_unique<MockGlFunctions>();
299
300 FlutterWindowsTextureRegistrar registrar(engine.get(), gl->gl_procs());
301
302 auto result = registrar.PopulateTexture(1, 640, 480, nullptr);
303 EXPECT_FALSE(result);
304 }

References flutter::FlutterWindowsTextureRegistrar::PopulateTexture().

## ◆ TEST() [57/173]

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

Definition at line 150 of file flutter_windows_texture_registrar_unittests.cc.

150 {
151 std::unique_ptr<FlutterWindowsEngine> engine = GetTestEngine();
152 std::unique_ptr<MockGlFunctions> gl = std::make_unique<MockGlFunctions>();
153 FlutterWindowsTextureRegistrar registrar(engine.get(), gl->gl_procs());
154
155 bool release_callback_called = false;
156 size_t width = 100;
157 size_t height = 100;
158 std::unique_ptr<uint8_t[]> pixels =
159 std::make_unique<uint8_t[]>(width * height * 4);
160 FlutterDesktopPixelBuffer pixel_buffer = {};
161 pixel_buffer.width = width;
162 pixel_buffer.height = height;
163 pixel_buffer.buffer = pixels.get();
164 pixel_buffer.release_context = &release_callback_called;
165 pixel_buffer.release_callback = [](void* release_context) {
166 bool* called = reinterpret_cast<bool*>(release_context);
167 *called = true;
168 };
169
170 FlutterDesktopTextureInfo texture_info = {};
171 texture_info.type = kFlutterDesktopPixelBufferTexture;
172 texture_info.pixel_buffer_config.user_data = &pixel_buffer;
173 texture_info.pixel_buffer_config.callback =
174 [](size_t width, size_t height,
175 void* user_data) -> const FlutterDesktopPixelBuffer* {
176 return reinterpret_cast<const FlutterDesktopPixelBuffer*>(user_data);
177 };
178
179 FlutterOpenGLTexture flutter_texture = {};
180 auto texture_id = registrar.RegisterTexture(&texture_info);
181 EXPECT_NE(texture_id, -1);
182
183 auto result =
184 registrar.PopulateTexture(texture_id, 640, 480, &flutter_texture);
185 EXPECT_TRUE(result);
186 EXPECT_EQ(flutter_texture.width, width);
187 EXPECT_EQ(flutter_texture.height, height);
188 EXPECT_EQ(flutter_texture.target, GL_TEXTURE_2D);
189 EXPECT_TRUE(release_callback_called);
190 }

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

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

Definition at line 136 of file flutter_windows_texture_registrar_unittests.cc.

136 {
137 std::unique_ptr<FlutterWindowsEngine> engine = GetTestEngine();
138 std::unique_ptr<MockGlFunctions> gl = std::make_unique<MockGlFunctions>();
139
140 FlutterWindowsTextureRegistrar registrar(engine.get(), gl->gl_procs());
141
142 FlutterDesktopTextureInfo texture_info = {};
143 texture_info.type = static_cast<FlutterDesktopTextureType>(1234);
144
145 auto texture_id = registrar.RegisterTexture(&texture_info);
146
147 EXPECT_EQ(texture_id, -1);
148 }

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

## ◆ TEST() [59/173]

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

Definition at line 71 of file flutter_windows_texture_registrar_unittests.cc.

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

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

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

Definition at line 306 of file flutter_windows_texture_registrar_unittests.cc.

307 {
308 std::unique_ptr<FlutterWindowsEngine> engine = GetTestEngine();
309 std::unique_ptr<MockGlFunctions> gl = std::make_unique<MockGlFunctions>();
310
311 FlutterWindowsTextureRegistrar registrar(engine.get(), gl->gl_procs());
312
313 fml::AutoResetWaitableEvent latch;
314 registrar.UnregisterTexture(1234, [&]() { latch.Signal(); });
315 latch.Wait();
316 }

References flutter::FlutterWindowsTextureRegistrar::UnregisterTexture().

## ◆ TEST() [61/173]

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

Definition at line 735 of file flutter_windows_view_unittests.cc.

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

## ◆ TEST() [62/173]

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

Definition at line 310 of file flutter_windows_view_unittests.cc.

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

References node_delegate.

## ◆ TEST() [63/173]

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

Definition at line 409 of file flutter_windows_view_unittests.cc.

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

References node_delegate.

## ◆ TEST() [64/173]

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

Definition at line 900 of file flutter_windows_view_unittests.cc.

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

## ◆ TEST() [65/173]

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

Definition at line 1221 of file flutter_windows_view_unittests.cc.

1221 {
1222 std::unique_ptr<MockFlutterWindowsEngine> engine =
1223 std::make_unique<MockFlutterWindowsEngine>();
1224 auto window_binding_handler =
1225 std::make_unique<NiceMock<MockWindowBindingHandler>>();
1226 std::unique_ptr<MockAngleSurfaceManager> surface_manager =
1227 std::make_unique<MockAngleSurfaceManager>();
1228
1229 EXPECT_CALL(*window_binding_handler.get(), NeedsVSync)
1230 .WillOnce(Return(false));
1231
1232 EngineModifier modifier(engine.get());
1233 FlutterWindowsView view(std::move(window_binding_handler));
1234
1235 InSequence s;
1236 EXPECT_CALL(*surface_manager.get(),
1237 CreateSurface(_, _, _, /*vsync_enabled=*/false))
1238 .Times(1)
1239 .WillOnce(Return(true));
1240
1241 EXPECT_CALL(*engine.get(), Stop).Times(1);
1242 EXPECT_CALL(*surface_manager.get(), DestroySurface).Times(1);
1243
1244 modifier.SetSurfaceManager(surface_manager.release());
1245 view.SetEngine(std::move(engine));
1246
1247 view.CreateRenderSurface();
1248 }

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

## ◆ TEST() [66/173]

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

Definition at line 288 of file flutter_windows_view_unittests.cc.

288 {
289 std::unique_ptr<FlutterWindowsEngine> engine = GetTestEngine();
290 EngineModifier modifier(engine.get());
291
292 bool semantics_enabled = false;
293 modifier.embedder_api().UpdateSemanticsEnabled = MOCK_ENGINE_PROC(
294 UpdateSemanticsEnabled,
295 [&semantics_enabled](FLUTTER_API_SYMBOL(FlutterEngine) engine,
296 bool enabled) {
297 semantics_enabled = 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(std::move(engine));
305
306 view.OnUpdateSemanticsEnabled(true);
307 EXPECT_TRUE(semantics_enabled);
308 }

## ◆ TEST() [67/173]

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

Definition at line 1251 of file flutter_windows_view_unittests.cc.

1251 {
1252 std::unique_ptr<MockFlutterWindowsEngine> engine =
1253 std::make_unique<MockFlutterWindowsEngine>();
1254 auto window_binding_handler =
1255 std::make_unique<NiceMock<MockWindowBindingHandler>>();
1256 std::unique_ptr<MockAngleSurfaceManager> surface_manager =
1257 std::make_unique<MockAngleSurfaceManager>();
1258
1259 EXPECT_CALL(*window_binding_handler.get(), NeedsVSync).WillOnce(Return(true));
1260
1261 EngineModifier modifier(engine.get());
1262 FlutterWindowsView view(std::move(window_binding_handler));
1263
1264 InSequence s;
1265 EXPECT_CALL(*surface_manager.get(),
1266 CreateSurface(_, _, _, /*vsync_enabled=*/true))
1267 .Times(1)
1268 .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(surface_manager.release());
1274 view.SetEngine(std::move(engine));
1275
1276 view.CreateRenderSurface();
1277 }

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

## ◆ TEST() [68/173]

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

Definition at line 268 of file flutter_windows_view_unittests.cc.

268 {
269 std::unique_ptr<FlutterWindowsEngine> engine = GetTestEngine();
270
271 test_response = false;
272
273 auto window_binding_handler =
274 std::make_unique<NiceMock<MockWindowBindingHandler>>();
275 FlutterWindowsView view(std::move(window_binding_handler));
276 view.SetEngine(std::move(engine));
277
278 view.OnKey(kVirtualKeyA, kScanCodeKeyA, WM_KEYDOWN, 'a', false, false,
279 [](bool handled) {});
280
281 EXPECT_EQ(key_event_logs.size(), 2);
282 EXPECT_EQ(key_event_logs[0], kKeyEventFromEmbedder);
283 EXPECT_EQ(key_event_logs[1], kKeyEventFromChannel);
284
285 key_event_logs.clear();
286 }

References kScanCodeKeyA, and kVirtualKeyA.

## ◆ TEST() [69/173]

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

Definition at line 607 of file flutter_windows_view_unittests.cc.

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

## ◆ TEST() [70/173]

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

Definition at line 248 of file flutter_windows_view_unittests.cc.

248 {
249 std::unique_ptr<MockFlutterWindowsEngine> engine =
250 std::make_unique<MockFlutterWindowsEngine>();
251 auto window_binding_handler =
252 std::make_unique<NiceMock<MockWindowBindingHandler>>();
253 std::unique_ptr<MockAngleSurfaceManager> surface_manager =
254 std::make_unique<MockAngleSurfaceManager>();
255
256 EngineModifier modifier(engine.get());
257 FlutterWindowsView view(std::move(window_binding_handler));
258
259 // The engine must be stopped before the surface can be destroyed.
260 InSequence s;
261 EXPECT_CALL(*engine.get(), Stop).Times(1);
262 EXPECT_CALL(*surface_manager.get(), DestroySurface).Times(1);
263
264 modifier.SetSurfaceManager(surface_manager.release());
265 view.SetEngine(std::move(engine));
266 }

References flutter::FlutterWindowsView::SetEngine().

## ◆ TEST() [71/173]

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

Definition at line 144 of file flutter_windows_view_unittests.cc.

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

## ◆ TEST() [72/173]

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

Definition at line 1046 of file flutter_windows_view_unittests.cc.

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

## ◆ TEST() [73/173]

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

Definition at line 1163 of file flutter_windows_view_unittests.cc.

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

## ◆ TEST() [74/173]

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

Definition at line 1282 of file flutter_windows_view_unittests.cc.

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

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

## ◆ TEST() [75/173]

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

Definition at line 875 of file flutter_windows_view_unittests.cc.

875 {
876 std::unique_ptr<FlutterWindowsEngine> engine = GetTestEngine();
877 EngineModifier modifier(engine.get());
878
879 FlutterWindowsView view(std::make_unique<flutter::FlutterWindow>(100, 100));
880 view.SetEngine(std::move(engine));
881 view.CreateRenderSurface();
882
883 bool schedule_frame_called = false;
884 modifier.embedder_api().ScheduleFrame =
885 MOCK_ENGINE_PROC(ScheduleFrame, ([&schedule_frame_called](auto engine) {
886 schedule_frame_called = true;
887 return kSuccess;
888 }));
889
890 view.OnWindowRepaint();
891 EXPECT_TRUE(schedule_frame_called);
892 }

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

## ◆ TEST() [76/173]

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

Definition at line 829 of file flutter_windows_view_unittests.cc.

829 {
830 std::unique_ptr<FlutterWindowsEngine> engine = GetTestEngine();
831 EngineModifier modifier(engine.get());
832
833 auto window_binding_handler =
834 std::make_unique<NiceMock<MockWindowBindingHandler>>();
835 std::unique_ptr<MockAngleSurfaceManager> surface_manager =
836 std::make_unique<MockAngleSurfaceManager>();
837
838 EXPECT_CALL(*window_binding_handler.get(), NeedsVSync)
839 .WillOnce(Return(false));
840 EXPECT_CALL(
841 *surface_manager.get(),
842 ResizeSurface(_, /*width=*/500, /*height=*/500, /*enable_vsync=*/false))
843 .Times(1);
844 EXPECT_CALL(*surface_manager.get(), DestroySurface).Times(1);
845
846 FlutterWindowsView view(std::move(window_binding_handler));
847 modifier.SetSurfaceManager(surface_manager.release());
848 view.SetEngine(std::move(engine));
849
850 fml::AutoResetWaitableEvent metrics_sent_latch;
851 modifier.embedder_api().SendWindowMetricsEvent = MOCK_ENGINE_PROC(
852 SendWindowMetricsEvent,
853 ([&metrics_sent_latch](auto engine,
854 const FlutterWindowMetricsEvent* event) {
855 metrics_sent_latch.Signal();
856 return kSuccess;
857 }));
858
859 fml::AutoResetWaitableEvent resized_latch;
860 std::thread([&resized_latch, &view]() {
861 // Start the window resize. This sends the new window metrics
862 // and then blocks until another thread completes the window resize.
863 view.OnWindowSizeChanged(500, 500);
864 resized_latch.Signal();
865 }).detach();
866
867 // Wait until the platform thread has started the window resize.
868 metrics_sent_latch.Wait();
869
870 // Complete the window resize by requesting a buffer with the new window size.
871 view.GetFrameBufferId(500, 500);
872 resized_latch.Wait();
873 }

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

## ◆ TEST() [77/173]

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

Definition at line 302 of file flutter_window_unittests.cc.

302 {
303 MockFlutterWindow win32window;
304
305 EXPECT_EQ(win32window.GetNativeViewAccessible(), nullptr);
306 }

## ◆ TEST() [78/173]

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

Definition at line 321 of file flutter_window_unittests.cc.

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

References message.

## ◆ TEST() [79/173]

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

Definition at line 382 of file flutter_window_unittests.cc.

382 {
383 MockFlutterWindow win32window;
384 ON_CALL(win32window, GetPlatformWindow).WillByDefault([]() {
385 return reinterpret_cast<HWND>(1);
386 });
387 ON_CALL(win32window, OnWindowStateEvent)
388 .WillByDefault([&](WindowStateEvent event) {
389 win32window.FlutterWindow::OnWindowStateEvent(event);
390 });
391
392 // Restore
393 win32window.InjectWindowMessage(WM_SIZE, 0, MAKEWORD(1, 1));
394
395 // Focus
396 win32window.InjectWindowMessage(WM_SETFOCUS, 0, 0);
397
398 MockWindowBindingHandlerDelegate delegate;
399 bool focused = false;
400 bool restored = false;
401 ON_CALL(delegate, OnWindowStateEvent)
402 .WillByDefault([&](HWND hwnd, WindowStateEvent event) {
403 if (event == WindowStateEvent::kFocus) {
404 focused = true;
405 } else if (event == WindowStateEvent::kShow) {
406 restored = true;
407 }
408 });
409
410 win32window.SetView(&delegate);
411 EXPECT_TRUE(focused);
412 EXPECT_TRUE(restored);
413 }

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

## ◆ TEST() [80/173]

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

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

Definition at line 308 of file flutter_window_unittests.cc.

308 {
309 MockFlutterWindow win32window;
310 MockWindowBindingHandlerDelegate delegate;
311 win32window.SetView(&delegate);
312
313 ON_CALL(win32window, GetHighContrastEnabled()).WillByDefault(Return(true));
314 EXPECT_CALL(delegate, UpdateHighContrastEnabled(true)).Times(1);
315
316 win32window.SendInitialAccessibilityFeatures();
317 }

## ◆ TEST() [82/173]

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

Definition at line 351 of file flutter_window_unittests.cc.

351 {
352 MockFlutterWindow win32window;
353 ON_CALL(win32window, GetPlatformWindow).WillByDefault([]() {
354 return reinterpret_cast<HWND>(1);
355 });
356 MockWindowBindingHandlerDelegate delegate;
357 win32window.SetView(&delegate);
358
359 WindowStateEvent last_event;
360 ON_CALL(delegate, OnWindowStateEvent)
361 .WillByDefault([&last_event](HWND hwnd, WindowStateEvent event) {
362 last_event = event;
363 });
364 ON_CALL(win32window, OnWindowStateEvent)
365 .WillByDefault([&](WindowStateEvent event) {
366 win32window.FlutterWindow::OnWindowStateEvent(event);
367 });
368
369 win32window.InjectWindowMessage(WM_SIZE, 0, 0);
370 EXPECT_EQ(last_event, WindowStateEvent::kHide);
371
372 win32window.InjectWindowMessage(WM_SIZE, 0, MAKEWORD(1, 1));
373 EXPECT_EQ(last_event, WindowStateEvent::kShow);
374
375 win32window.InjectWindowMessage(WM_SETFOCUS, 0, 0);
376 EXPECT_EQ(last_event, WindowStateEvent::kFocus);
377
378 win32window.InjectWindowMessage(WM_KILLFOCUS, 0, 0);
379 EXPECT_EQ(last_event, WindowStateEvent::kUnfocus);
380 }

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

## ◆ TEST() [83/173]

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

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

Definition at line 149 of file flutter_window_unittests.cc.

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

## ◆ TEST() [85/173]

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

Definition at line 135 of file flutter_window_unittests.cc.

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

## ◆ TEST() [86/173]

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

Definition at line 161 of file flutter_window_unittests.cc.

161 {
162 FlutterWindow win32window(100, 100);
163 MockWindowBindingHandlerDelegate delegate;
164 win32window.SetView(&delegate);
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() [87/173]

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

Definition at line 260 of file flutter_window_unittests.cc.

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

## ◆ TEST() [88/173]

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

Definition at line 288 of file flutter_window_unittests.cc.

288 {
289 MockFlutterWindow win32window;
290 MockWindowBindingHandlerDelegate delegate;
291 win32window.SetView(&delegate);
292
293 ON_CALL(win32window, GetHighContrastEnabled()).WillByDefault(Return(true));
294 EXPECT_CALL(delegate, UpdateHighContrastEnabled(true)).Times(1);
295
296 win32window.InjectWindowMessage(WM_THEMECHANGED, 0, 0);
297 }

## ◆ TEST() [89/173]

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

Definition at line 278 of file flutter_window_unittests.cc.

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

## ◆ TEST() [90/173]

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

Definition at line 415 of file flutter_window_unittests.cc.

415 {
416 MockWindowBindingHandlerDelegate delegate;
417 int msg_count = 0;
418 HWND hwnd;
419 ON_CALL(delegate, OnWindowStateEvent)
420 .WillByDefault([&](HWND hwnd, WindowStateEvent event) { msg_count++; });
421
422 {
423 MockFlutterWindow win32window(false);
424 ON_CALL(win32window, GetPlatformWindow).WillByDefault([&]() {
425 return win32window.FlutterWindow::GetPlatformWindow();
426 });
427 ON_CALL(win32window, OnWindowStateEvent)
428 .WillByDefault([&](WindowStateEvent event) {
429 win32window.FlutterWindow::OnWindowStateEvent(event);
430 });
431 win32window.SetView(&delegate);
432 win32window.InitializeChild("Title", 1, 1);
433 hwnd = win32window.GetPlatformWindow();
434 SendMessage(hwnd, WM_SIZE, 0, MAKEWORD(1, 1));
435 SendMessage(hwnd, WM_SETFOCUS, 0, 0);
436
437 // By setting this to zero before exiting the scope that contains
438 // win32window, and then checking its value afterwards, enforce that the
439 // window receive and process messages from its destructor without
440 // accessing out-of-bounds memory.
441 msg_count = 0;
442 }
443 EXPECT_GE(msg_count, 1);
444 }

## ◆ TEST() [91/173]

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Definition at line 23 of file window_unittests.cc.

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

## ◆ TEST() [120/173]

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Definition at line 26 of file system_utils_unittests.cc.

26 {
27 MockWindowsProcTable proc_table;
28 ON_CALL(proc_table, GetThreadPreferredUILanguages)
29 .WillByDefault(
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() [148/173]

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

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

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

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

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

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

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

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

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

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

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

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

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

Definition at line 138 of file text_input_plugin_unittest.cc.

138 {
139 TestBinaryMessenger messenger([](const std::string& channel,
140 const uint8_t* message, size_t message_size,
141 BinaryReply reply) {});
142 BinaryReply reply_handler = [](const uint8_t* reply, size_t reply_size) {};
143
144 MockTextInputPluginDelegate delegate;
145 TextInputPlugin handler(&messenger, &delegate);
146
147 EXPECT_CALL(delegate, OnResetImeComposing());
148
149 auto& codec = JsonMethodCodec::GetInstance();
150 auto message = codec.EncodeMethodCall({"TextInput.clearClient", nullptr});
151 messenger.SimulateEngineMessage(kChannelName, message->data(),
152 message->size(), reply_handler);
153 }

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

## ◆ TEST() [161/173]

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

Definition at line 372 of file text_input_plugin_unittest.cc.

372 {
373 int selection_base = -1;
374 TestBinaryMessenger messenger([&](const std::string& channel,
375 const uint8_t* message, size_t size,
376 BinaryReply reply) {
377 auto method = JsonMethodCodec::GetInstance().DecodeMethodCall(
378 std::vector<uint8_t>(message, message + size));
379 if (method->method_name() == kUpdateEditingStateMethod) {
380 const auto& args = *method->arguments();
381 const auto& editing_state = args[1];
382 auto base = editing_state.FindMember(kSelectionBaseKey);
383 auto extent = editing_state.FindMember(kSelectionExtentKey);
384 ASSERT_NE(base, editing_state.MemberEnd());
385 ASSERT_TRUE(base->value.IsInt());
386 ASSERT_NE(extent, editing_state.MemberEnd());
387 ASSERT_TRUE(extent->value.IsInt());
388 selection_base = base->value.GetInt();
389 EXPECT_EQ(extent->value.GetInt(), selection_base);
390 }
391 });
392 MockTextInputPluginDelegate delegate;
393
394 TextInputPlugin plugin(&messenger, &delegate);
395
396 auto args = std::make_unique<rapidjson::Document>(rapidjson::kArrayType);
397 auto& allocator = args->GetAllocator();
398 args->PushBack(123, allocator); // client_id
399 rapidjson::Value client_config(rapidjson::kObjectType);
400 args->PushBack(client_config, allocator);
401 auto encoded = JsonMethodCodec::GetInstance().EncodeMethodCall(
402 MethodCall<rapidjson::Document>(kSetClientMethod, std::move(args)));
403 EXPECT_TRUE(messenger.SimulateEngineMessage(
404 kChannelName, encoded->data(), encoded->size(),
405 [](const uint8_t* reply, size_t reply_size) {}));
406
407 plugin.ComposeBeginHook();
408 EXPECT_EQ(selection_base, 0);
409 plugin.ComposeChangeHook(u"abc", 3);
410 EXPECT_EQ(selection_base, 3);
411
412 plugin.ComposeCommitHook();
413 plugin.ComposeEndHook();
414 EXPECT_EQ(selection_base, 3);
415
416 plugin.ComposeBeginHook();
417 plugin.ComposeChangeHook(u"1", 1);
418 EXPECT_EQ(selection_base, 4);
419
420 plugin.ComposeChangeHook(u"12", 2);
421 EXPECT_EQ(selection_base, 5);
422
423 plugin.ComposeChangeHook(u"12", 1);
424 EXPECT_EQ(selection_base, 4);
425
426 plugin.ComposeChangeHook(u"12", 2);
427 EXPECT_EQ(selection_base, 5);
428 }

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

## ◆ TEST() [162/173]

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

Definition at line 315 of file text_input_plugin_unittest.cc.

315 {
316 auto handled_message = CreateResponse(true);
317 auto unhandled_message = CreateResponse(false);
318 int received_scancode = 0;
319
320 TestBinaryMessenger messenger(
321 [&received_scancode, &handled_message, &unhandled_message](
322 const std::string& channel, const uint8_t* message,
323 size_t message_size, BinaryReply reply) {});
324 MockTextInputPluginDelegate delegate;
325
326 int redispatch_scancode = 0;
327 TextInputPlugin handler(&messenger, &delegate);
328
329 auto args = std::make_unique<rapidjson::Document>(rapidjson::kArrayType);
330 auto& allocator = args->GetAllocator();
331 args->PushBack(123, allocator); // client_id
332
333 rapidjson::Value client_config(rapidjson::kObjectType);
334 client_config.AddMember(kEnableDeltaModel, true, allocator);
335
336 args->PushBack(client_config, allocator);
337 auto encoded = JsonMethodCodec::GetInstance().EncodeMethodCall(
338 MethodCall<rapidjson::Document>(kSetClientMethod, std::move(args)));
339
340 EXPECT_TRUE(messenger.SimulateEngineMessage(
341 kChannelName, encoded->data(), encoded->size(),
342 [](const uint8_t* reply, size_t reply_size) {}));
343
344 handler.KeyboardHook(VK_RETURN, 100, WM_KEYDOWN, '\n', false, false);
345 handler.ComposeBeginHook();
346 std::u16string text;
347 text.push_back('\n');
348 handler.ComposeChangeHook(text, 1);
349 handler.ComposeEndHook();
350
351 handler.KeyboardHook(0x4E, 100, WM_KEYDOWN, 'n', false, false);
352 handler.ComposeBeginHook();
353 std::u16string textN;
354 text.push_back('n');
355 handler.ComposeChangeHook(textN, 1);
356 handler.KeyboardHook(0x49, 100, WM_KEYDOWN, 'i', false, false);
357 std::u16string textNi;
358 text.push_back('n');
359 text.push_back('i');
360 handler.ComposeChangeHook(textNi, 2);
361 handler.KeyboardHook(VK_RETURN, 100, WM_KEYDOWN, '\n', false, false);
362 std::u16string textChineseCharacter;
363 text.push_back(u'\u4F60');
364 handler.ComposeChangeHook(textChineseCharacter, 1);
365 handler.ComposeCommitHook();
366 handler.ComposeEndHook();
367
368 // Passes if it did not crash
369 }

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

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

Definition at line 114 of file text_input_plugin_unittest.cc.

114 {
115 auto handled_message = CreateResponse(true);
116 auto unhandled_message = CreateResponse(false);
117 int received_scancode = 0;
118
119 TestBinaryMessenger messenger(
120 [&received_scancode, &handled_message, &unhandled_message](
121 const std::string& channel, const uint8_t* message,
122 size_t message_size, BinaryReply reply) {});
123 MockTextInputPluginDelegate delegate;
124
125 int redispatch_scancode = 0;
126 TextInputPlugin handler(&messenger, &delegate);
127
128 handler.KeyboardHook(VK_RETURN, 100, WM_KEYDOWN, '\n', false, false);
129 handler.ComposeBeginHook();
130 std::u16string text;
131 text.push_back('\n');
132 handler.ComposeChangeHook(text, 1);
133 handler.ComposeEndHook();
134
135 // Passes if it did not crash
136 }

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

## ◆ TEST() [164/173]

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

Definition at line 430 of file text_input_plugin_unittest.cc.

430 {
431 // A position of `EditableText`.
432 double view_x = 100;
433 double view_y = 200;
434
435 // A position and size of marked text, in `EditableText` local coordinates.
436 double ime_x = 3;
437 double ime_y = 4;
438 double ime_width = 50;
439 double ime_height = 60;
440
441 // Transformation matrix.
442 std::array<std::array<double, 4>, 4> editabletext_transform = {
443 1.0, 0.0, 0.0, view_x, //
444 0.0, 1.0, 0.0, view_y, //
445 0.0, 0.0, 0.0, 0.0, //
446 0.0, 0.0, 0.0, 1.0};
447
448 TestBinaryMessenger messenger([](const std::string& channel,
449 const uint8_t* message, size_t message_size,
450 BinaryReply reply) {});
451 BinaryReply reply_handler = [](const uint8_t* reply, size_t reply_size) {};
452
453 MockTextInputPluginDelegate delegate;
454 TextInputPlugin handler(&messenger, &delegate);
455
456 auto& codec = JsonMethodCodec::GetInstance();
457
458 EXPECT_CALL(delegate, OnCursorRectUpdated(Rect{{view_x, view_y}, {0, 0}}));
459
460 {
461 auto arguments =
462 std::make_unique<rapidjson::Document>(rapidjson::kObjectType);
463 auto& allocator = arguments->GetAllocator();
464
465 rapidjson::Value transoform(rapidjson::kArrayType);
466 for (int i = 0; i < 4 * 4; i++) {
467 // Pack 2-dimensional array by column-major order.
468 transoform.PushBack(editabletext_transform[i % 4][i / 4], allocator);
469 }
470
471 arguments->AddMember("transform", transoform, allocator);
472
473 auto message = codec.EncodeMethodCall(
474 {"TextInput.setEditableSizeAndTransform", std::move(arguments)});
475 messenger.SimulateEngineMessage(kChannelName, message->data(),
476 message->size(), reply_handler);
477 }
478
479 EXPECT_CALL(delegate,
480 OnCursorRectUpdated(Rect{{view_x + ime_x, view_y + ime_y},
481 {ime_width, ime_height}}));
482
483 {
484 auto arguments =
485 std::make_unique<rapidjson::Document>(rapidjson::kObjectType);
486 auto& allocator = arguments->GetAllocator();
487
488 arguments->AddMember("x", ime_x, allocator);
489 arguments->AddMember("y", ime_y, allocator);
490 arguments->AddMember("width", ime_width, allocator);
491 arguments->AddMember("height", ime_height, allocator);
492
493 auto message = codec.EncodeMethodCall(
494 {"TextInput.setMarkedTextRect", std::move(arguments)});
495 messenger.SimulateEngineMessage(kChannelName, message->data(),
496 message->size(), reply_handler);
497 }
498 }

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

## ◆ TEST() [165/173]

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

Definition at line 157 of file text_input_plugin_unittest.cc.

157 {
158 bool sent_message = false;
159 TestBinaryMessenger messenger(
160 [&sent_message](const std::string& channel, const uint8_t* message,
161 size_t message_size,
162 BinaryReply reply) { sent_message = true; });
163 BinaryReply reply_handler = [](const uint8_t* reply, size_t reply_size) {};
164
165 MockTextInputPluginDelegate delegate;
166 TextInputPlugin handler(&messenger, &delegate);
167
168 auto& codec = JsonMethodCodec::GetInstance();
169
170 // Call TextInput.setClient to initialize the TextInputModel.
171 auto arguments = std::make_unique<rapidjson::Document>(rapidjson::kArrayType);
172 auto& allocator = arguments->GetAllocator();
173 arguments->PushBack(kDefaultClientId, allocator);
174 rapidjson::Value config(rapidjson::kObjectType);
175 config.AddMember("inputAction", "done", allocator);
176 config.AddMember("inputType", "text", allocator);
177 config.AddMember(kEnableDeltaModel, false, allocator);
178 arguments->PushBack(config, allocator);
179 auto message =
180 codec.EncodeMethodCall({"TextInput.setClient", std::move(arguments)});
181 messenger.SimulateEngineMessage("flutter/textinput", message->data(),
182 message->size(), reply_handler);
183
184 // ComposeBeginHook should send state update.
185 sent_message = false;
186 handler.ComposeBeginHook();
187 EXPECT_TRUE(sent_message);
188
189 // ComposeChangeHook should send state update.
190 sent_message = false;
191 handler.ComposeChangeHook(u"4", 1);
192 EXPECT_TRUE(sent_message);
193
194 // ComposeCommitHook should NOT send state update.
195 //
196 // Commit messages are always immediately followed by a change message or an
197 // end message, both of which will send an update. Sending intermediate state
198 // with a collapsed composing region will trigger the framework to assume
199 // composing has ended, which is not the case until a WM_IME_ENDCOMPOSING
200 // event is received in the main event loop, which will trigger a call to
201 // ComposeEndHook.
202 sent_message = false;
203 handler.ComposeCommitHook();
204 EXPECT_FALSE(sent_message);
205
206 // ComposeEndHook should send state update.
207 sent_message = false;
208 handler.ComposeEndHook();
209 EXPECT_TRUE(sent_message);
210 }

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

## ◆ TEST() [166/173]

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

Definition at line 212 of file text_input_plugin_unittest.cc.

212 {
213 // Store messages as std::string for convenience.
214 std::vector<std::string> messages;
215
216 TestBinaryMessenger messenger(
217 [&messages](const std::string& channel, const uint8_t* message,
218 size_t message_size, BinaryReply reply) {
219 std::string last_message(reinterpret_cast<const char*>(message),
220 message_size);
221 messages.push_back(last_message);
222 });
223 BinaryReply reply_handler = [](const uint8_t* reply, size_t reply_size) {};
224
225 MockTextInputPluginDelegate delegate;
226 TextInputPlugin handler(&messenger, &delegate);
227
228 auto& codec = JsonMethodCodec::GetInstance();
229
230 // Call TextInput.setClient to initialize the TextInputModel.
231 auto set_client_arguments =
232 EncodedClientConfig("TextInputType.multiline", "TextInputAction.newline");
233 auto message = codec.EncodeMethodCall(
234 {"TextInput.setClient", std::move(set_client_arguments)});
235 messenger.SimulateEngineMessage("flutter/textinput", message->data(),
236 message->size(), reply_handler);
237
238 // Simulate a key down event for '\n'.
239 handler.KeyboardHook(VK_RETURN, 100, WM_KEYDOWN, '\n', false, false);
240
241 // Two messages are expected, the first is TextInput.updateEditingState and
242 // the second is TextInputClient.performAction.
243 EXPECT_EQ(messages.size(), 2);
244
245 // Editing state should have been updated.
246 auto encoded_arguments = EncodedEditingState("\n", TextRange(1));
247 auto update_state_message = codec.EncodeMethodCall(
248 {kUpdateEditingStateMethod, std::move(encoded_arguments)});
249
250 EXPECT_TRUE(std::equal(update_state_message->begin(),
251 update_state_message->end(),
252 messages.front().begin()));
253
254 // TextInputClient.performAction should have been called.
255 auto arguments = std::make_unique<rapidjson::Document>(rapidjson::kArrayType);
256 auto& allocator = arguments->GetAllocator();
257 arguments->PushBack(kDefaultClientId, allocator);
258 arguments->PushBack(
259 rapidjson::Value("TextInputAction.newline", allocator).Move(), allocator);
260 auto invoke_action_message = codec.EncodeMethodCall(
261 {"TextInputClient.performAction", std::move(arguments)});
262
263 EXPECT_TRUE(std::equal(invoke_action_message->begin(),
264 invoke_action_message->end(),
265 messages.back().begin()));
266 }

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

## ◆ TEST() [167/173]

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

Definition at line 269 of file text_input_plugin_unittest.cc.

269 {
270 std::vector<std::vector<uint8_t>> messages;
271
272 TestBinaryMessenger messenger(
273 [&messages](const std::string& channel, const uint8_t* message,
274 size_t message_size, BinaryReply reply) {
275 int length = static_cast<int>(message_size);
276 std::vector<uint8_t> last_message(length);
277 memcpy(&last_message[0], &message[0], length * sizeof(uint8_t));
278 messages.push_back(last_message);
279 });
280 BinaryReply reply_handler = [](const uint8_t* reply, size_t reply_size) {};
281
282 MockTextInputPluginDelegate delegate;
283 TextInputPlugin handler(&messenger, &delegate);
284
285 auto& codec = JsonMethodCodec::GetInstance();
286
287 // Call TextInput.setClient to initialize the TextInputModel.
288 auto set_client_arguments =
289 EncodedClientConfig("TextInputType.multiline", "TextInputAction.send");
290 auto message = codec.EncodeMethodCall(
291 {"TextInput.setClient", std::move(set_client_arguments)});
292 messenger.SimulateEngineMessage("flutter/textinput", message->data(),
293 message->size(), reply_handler);
294
295 // Simulate a key down event for '\n'.
296 handler.KeyboardHook(VK_RETURN, 100, WM_KEYDOWN, '\n', false, false);
297
298 // Only a call to TextInputClient.performAction is expected.
299 EXPECT_EQ(messages.size(), 1);
300
301 // TextInputClient.performAction should have been called.
302 auto arguments = std::make_unique<rapidjson::Document>(rapidjson::kArrayType);
303 auto& allocator = arguments->GetAllocator();
304 arguments->PushBack(kDefaultClientId, allocator);
305 arguments->PushBack(
306 rapidjson::Value("TextInputAction.send", allocator).Move(), allocator);
307 auto invoke_action_message = codec.EncodeMethodCall(
308 {"TextInputClient.performAction", std::move(arguments)});
309
310 EXPECT_TRUE(std::equal(invoke_action_message->begin(),
311 invoke_action_message->end(),
312 messages.front().begin()));
313 }

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

## ◆ TEST() [168/173]

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

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

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

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

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

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

Definition at line 24 of file flutter_windows_unittests.cc.

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

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

## ◆ TEST_F() [1/108]

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

Definition at line 95 of file cursor_handler_unittests.cc.

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

References kActivateSystemCursorMethod.

## ◆ TEST_F() [2/108]

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

Definition at line 121 of file cursor_handler_unittests.cc.

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

References kActivateSystemCursorMethod.

## ◆ TEST_F() [3/108]

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

Definition at line 148 of file cursor_handler_unittests.cc.

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

References kCreateCustomCursorMethod.

## ◆ TEST_F() [4/108]

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

Definition at line 289 of file cursor_handler_unittests.cc.

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

References kCreateCustomCursorMethod, and kDeleteCustomCursorMethod.

## ◆ TEST_F() [5/108]

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

Definition at line 327 of file cursor_handler_unittests.cc.

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

References kDeleteCustomCursorMethod.

## ◆ TEST_F() [6/108]

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

Definition at line 179 of file cursor_handler_unittests.cc.

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

References kCreateCustomCursorMethod, and kSetCustomCursorMethod.

## ◆ TEST_F() [7/108]

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

Definition at line 219 of file cursor_handler_unittests.cc.

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

References kCreateCustomCursorMethod, and kSetCustomCursorMethod.

## ◆ TEST_F() [8/108]

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

Definition at line 260 of file cursor_handler_unittests.cc.

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

References kSetCustomCursorMethod.

## ◆ TEST_F() [9/108]

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

Definition at line 489 of file flutter_windows_engine_unittests.cc.

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

## ◆ TEST_F() [10/108]

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

Definition at line 619 of file flutter_windows_engine_unittests.cc.

619 {
620 FlutterWindowsEngineBuilder builder{GetContext()};
621 builder.SetDartEntrypoint("alertPlatformChannel");
622
623 auto window_binding_handler =
624 std::make_unique<::testing::NiceMock<MockWindowBindingHandler>>();
625 ui::AXPlatformNodeDelegateBase parent_delegate;
626 AlertPlatformNodeDelegate delegate(parent_delegate);
627 ON_CALL(*window_binding_handler, GetAlertDelegate).WillByDefault([&delegate] {
628 return &delegate;
629 });
630 MockFlutterWindowsView view(std::move(window_binding_handler));
631 view.SetEngine(builder.Build());
632 FlutterWindowsEngine* engine = view.GetEngine();
633
634 EngineModifier modifier(engine);
635 modifier.embedder_api().RunsAOTCompiledDartCode = []() { return false; };
636
637 auto binary_messenger =
638 std::make_unique<BinaryMessengerImpl>(engine->messenger());
639 binary_messenger->SetMessageHandler(
640 "semantics", [&engine](const uint8_t* message, size_t message_size,
641 BinaryReply reply) {
642 engine->UpdateSemanticsEnabled(true);
643 char response[] = "";
644 reply(reinterpret_cast<uint8_t*>(response), 0);
645 });
646
647 bool did_call = false;
648 ON_CALL(view, NotifyWinEventWrapper)
649 .WillByDefault([&did_call](ui::AXPlatformNodeWin* node,
650 ax::mojom::Event event) { did_call = true; });
651
652 engine->UpdateSemanticsEnabled(true);
653 engine->Run();
654
655 // Rely on timeout mechanism in CI.
656 while (!did_call) {
657 engine->task_runner()->ProcessTasks();
658 }
659 }

References message, flutter::FlutterWindowsEngine::messenger(), flutter::TaskRunner::ProcessTasks(), flutter::FlutterWindowsEngine::Run(), flutter::FlutterWindowsEngine::task_runner(), and flutter::FlutterWindowsEngine::UpdateSemanticsEnabled().

## ◆ TEST_F() [11/108]

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

Definition at line 912 of file flutter_windows_engine_unittests.cc.

912 {
913 FlutterWindowsEngineBuilder builder{GetContext()};
914
915 auto window_binding_handler =
916 std::make_unique<::testing::NiceMock<MockWindowBindingHandler>>();
917 MockFlutterWindowsView view(std::move(window_binding_handler));
918 view.SetEngine(builder.Build());
919 FlutterWindowsEngine* engine = view.GetEngine();
920
921 EngineModifier modifier(engine);
922 modifier.embedder_api().RunsAOTCompiledDartCode = []() { return false; };
923 auto handler = std::make_unique<MockWindowsLifecycleManager>(engine);
924 ON_CALL(*handler, IsLastWindowOfProcess).WillByDefault([]() {
925 return false;
926 });
927 EXPECT_CALL(*handler, IsLastWindowOfProcess).Times(1);
928 modifier.SetLifecycleManager(std::move(handler));
929 engine->lifecycle_manager()->BeginProcessingExit();
930
931 engine->lifecycle_manager()->ExternalWindowMessage(0, WM_CLOSE, 0, 0);
932 }

References flutter::WindowsLifecycleManager::BeginProcessingExit(), flutter::WindowsLifecycleManager::ExternalWindowMessage(), and flutter::FlutterWindowsEngine::lifecycle_manager().

## ◆ TEST_F() [12/108]

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

Definition at line 934 of file flutter_windows_engine_unittests.cc.

934 {
935 FlutterWindowsEngineBuilder builder{GetContext()};
936
937 auto window_binding_handler =
938 std::make_unique<::testing::NiceMock<MockWindowBindingHandler>>();
939 MockFlutterWindowsView view(std::move(window_binding_handler));
940 view.SetEngine(builder.Build());
941 FlutterWindowsEngine* engine = view.GetEngine();
942
943 EngineModifier modifier(engine);
944 modifier.embedder_api().RunsAOTCompiledDartCode = []() { return false; };
945 auto handler = std::make_unique<MockWindowsLifecycleManager>(engine);
946 EXPECT_CALL(*handler, SetLifecycleState(AppLifecycleState::kResumed))
947 .Times(1);
948 modifier.SetLifecycleManager(std::move(handler));
949 engine->Run();
950 }

References flutter::kResumed, and flutter::FlutterWindowsEngine::Run().

## ◆ TEST_F() [13/108]

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

Definition at line 1140 of file flutter_windows_engine_unittests.cc.

1140 {
1141 FlutterWindowsEngineBuilder builder{GetContext()};
1142 builder.SetDartEntrypoint("enableLifecycleToFrom");
1143
1144 auto window_binding_handler =
1145 std::make_unique<::testing::NiceMock<MockWindowBindingHandler>>();
1146 MockFlutterWindowsView view(std::move(window_binding_handler));
1147 view.SetEngine(builder.Build());
1148 FlutterWindowsEngine* engine = view.GetEngine();
1149 EngineModifier modifier(engine);
1150 modifier.embedder_api().RunsAOTCompiledDartCode = []() { return false; };
1151
1152 bool lifecycle_began = false;
1153 auto handler = std::make_unique<MockWindowsLifecycleManager>(engine);
1154 handler->begin_processing_callback = [&]() { lifecycle_began = true; };
1155 modifier.SetLifecycleManager(std::move(handler));
1156
1157 engine->Run();
1158
1159 while (!lifecycle_began) {
1160 engine->task_runner()->ProcessTasks();
1161 }
1162 }

References flutter::TaskRunner::ProcessTasks(), flutter::FlutterWindowsEngine::Run(), and flutter::FlutterWindowsEngine::task_runner().

## ◆ TEST_F() [14/108]

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

Definition at line 146 of file flutter_windows_engine_unittests.cc.

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

## ◆ TEST_F() [15/108]

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

Definition at line 443 of file flutter_windows_engine_unittests.cc.

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

References action, and message.

## ◆ TEST_F() [16/108]

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

Definition at line 889 of file flutter_windows_engine_unittests.cc.

889 {
890 FlutterWindowsEngineBuilder builder{GetContext()};
891
892 auto window_binding_handler =
893 std::make_unique<::testing::NiceMock<MockWindowBindingHandler>>();
894 MockFlutterWindowsView view(std::move(window_binding_handler));
895 view.SetEngine(builder.Build());
896 FlutterWindowsEngine* engine = view.GetEngine();
897
898 EngineModifier modifier(engine);
899 modifier.embedder_api().RunsAOTCompiledDartCode = []() { return false; };
900 auto handler = std::make_unique<MockWindowsLifecycleManager>(engine);
901 ON_CALL(*handler, IsLastWindowOfProcess).WillByDefault([]() {
902 return false;
903 });
904 EXPECT_CALL(*handler, IsLastWindowOfProcess).Times(1);
905 modifier.SetLifecycleManager(std::move(handler));
906 engine->lifecycle_manager()->BeginProcessingExit();
907
908 engine->window_proc_delegate_manager()->OnTopLevelWindowProc(0, WM_CLOSE, 0,
909 0);
910 }

References flutter::WindowsLifecycleManager::BeginProcessingExit(), flutter::FlutterWindowsEngine::lifecycle_manager(), flutter::WindowProcDelegateManager::OnTopLevelWindowProc(), and flutter::FlutterWindowsEngine::window_proc_delegate_manager().

## ◆ TEST_F() [17/108]

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

Definition at line 1039 of file flutter_windows_engine_unittests.cc.

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

References flutter::WindowsLifecycleManager::BeginProcessingLifecycle(), flutter::kHide, flutter::kShow, flutter::FlutterWindowsEngine::lifecycle_manager(), message, flutter::FlutterWindowsEngine::messenger(), flutter::TaskRunner::ProcessTasks(), flutter::FlutterWindowsEngine::Run(), and flutter::FlutterWindowsEngine::task_runner().

## ◆ TEST_F() [18/108]

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

Definition at line 981 of file flutter_windows_engine_unittests.cc.

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

References flutter::WindowsLifecycleManager::GetLifecycleState(), flutter::kHidden, flutter::FlutterWindowsEngine::lifecycle_manager(), flutter::FlutterWindowsEngine::ProcessExternalWindowMessage(), and flutter::FlutterWindowsEngine::Run().

## ◆ TEST_F() [19/108]

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

Definition at line 552 of file flutter_windows_engine_unittests.cc.

552 {
553 FlutterWindowsEngineBuilder builder{GetContext()};
554 std::unique_ptr<FlutterWindowsEngine> engine = builder.Build();
555 EXPECT_EQ(engine->GetExecutableName(), "flutter_windows_unittests.exe");
556 }

## ◆ TEST_F() [20/108]

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

Definition at line 1005 of file flutter_windows_engine_unittests.cc.

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

References flutter::WindowsLifecycleManager::GetLifecycleState(), flutter::kFocus, flutter::kHide, flutter::kInactive, flutter::kResumed, flutter::kShow, flutter::FlutterWindowsEngine::lifecycle_manager(), flutter::WindowProcDelegateManager::OnTopLevelWindowProc(), flutter::FlutterWindowsEngine::Run(), and flutter::FlutterWindowsEngine::window_proc_delegate_manager().

## ◆ TEST_F() [21/108]

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

Definition at line 870 of file flutter_windows_engine_unittests.cc.

870 {
871 FlutterWindowsEngineBuilder builder{GetContext()};
872
873 auto window_binding_handler =
874 std::make_unique<::testing::NiceMock<MockWindowBindingHandler>>();
875 MockFlutterWindowsView view(std::move(window_binding_handler));
876 view.SetEngine(builder.Build());
877 FlutterWindowsEngine* engine = view.GetEngine();
878
879 EngineModifier modifier(engine);
880 modifier.embedder_api().RunsAOTCompiledDartCode = []() { return false; };
881 auto handler = std::make_unique<MockWindowsLifecycleManager>(engine);
882 EXPECT_CALL(*handler, IsLastWindowOfProcess).Times(0);
883 modifier.SetLifecycleManager(std::move(handler));
884
885 engine->window_proc_delegate_manager()->OnTopLevelWindowProc(0, WM_CLOSE, 0,
886 0);
887 }

References flutter::WindowProcDelegateManager::OnTopLevelWindowProc(), and flutter::FlutterWindowsEngine::window_proc_delegate_manager().

## ◆ TEST_F() [22/108]

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

Definition at line 1091 of file flutter_windows_engine_unittests.cc.

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

References flutter::kHide, flutter::kShow, message, flutter::FlutterWindowsEngine::messenger(), flutter::TaskRunner::ProcessTasks(), flutter::FlutterWindowsEngine::Run(), and flutter::FlutterWindowsEngine::task_runner().

## ◆ TEST_F() [23/108]

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

Definition at line 952 of file flutter_windows_engine_unittests.cc.

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

References flutter::WindowsLifecycleManager::GetLifecycleState(), flutter::kHidden, flutter::kInactive, flutter::kResumed, flutter::FlutterWindowsEngine::lifecycle_manager(), flutter::WindowProcDelegateManager::OnTopLevelWindowProc(), flutter::FlutterWindowsEngine::Run(), and flutter::FlutterWindowsEngine::window_proc_delegate_manager().

## ◆ TEST_F() [24/108]

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

Definition at line 333 of file flutter_windows_engine_unittests.cc.

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

References message.

## ◆ TEST_F() [25/108]

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

Definition at line 288 of file flutter_windows_engine_unittests.cc.

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

References message.

## ◆ TEST_F() [26/108]

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

Definition at line 586 of file flutter_windows_engine_unittests.cc.

586 {
587 FlutterWindowsEngineBuilder builder{GetContext()};
588 std::unique_ptr<FlutterWindowsEngine> engine = builder.Build();
589 EngineModifier modifier(engine.get());
590
591 modifier.embedder_api().PostRenderThreadTask = MOCK_ENGINE_PROC(
592 PostRenderThreadTask, ([](auto engine, auto callback, auto context) {
593 callback(context);
594 return kSuccess;
595 }));
596
597 bool called = false;
598 engine->PostRasterThreadTask([&called]() { called = true; });
599
600 EXPECT_TRUE(called);
601 }

References callback.

## ◆ TEST_F() [27/108]

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

Definition at line 30 of file flutter_windows_engine_unittests.cc.

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

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

## ◆ TEST_F() [28/108]

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

Definition at line 226 of file flutter_windows_engine_unittests.cc.

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

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

## ◆ TEST_F() [29/108]

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

Definition at line 173 of file flutter_windows_engine_unittests.cc.

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

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

## ◆ TEST_F() [30/108]

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

Definition at line 520 of file flutter_windows_engine_unittests.cc.

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

## ◆ TEST_F() [31/108]

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

Definition at line 261 of file flutter_windows_engine_unittests.cc.

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

References message.

## ◆ TEST_F() [32/108]

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

Definition at line 384 of file flutter_windows_engine_unittests.cc.

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

References message, and user_data.

## ◆ TEST_F() [33/108]

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

Definition at line 536 of file flutter_windows_engine_unittests.cc.

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

References callback.

## ◆ TEST_F() [34/108]

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

Definition at line 468 of file flutter_windows_engine_unittests.cc.

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

References flutter::WindowsPlatformThreadPrioritySetter().

## ◆ TEST_F() [35/108]

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

Definition at line 686 of file flutter_windows_engine_unittests.cc.

686 {
687 FlutterWindowsEngineBuilder builder{GetContext()};
688 builder.SetDartEntrypoint("exitTestExit");
689 bool finished = false;
690
691 auto window_binding_handler =
692 std::make_unique<::testing::NiceMock<MockWindowBindingHandler>>();
693 MockFlutterWindowsView view(std::move(window_binding_handler));
694 view.SetEngine(builder.Build());
695 FlutterWindowsEngine* engine = view.GetEngine();
696
697 EngineModifier modifier(engine);
698 modifier.embedder_api().RunsAOTCompiledDartCode = []() { return false; };
699 auto handler = std::make_unique<MockWindowsLifecycleManager>(engine);
700 ON_CALL(*handler, Quit)
701 .WillByDefault(
702 [&finished](std::optional<HWND> hwnd, std::optional<WPARAM> wparam,
703 std::optional<LPARAM> lparam,
704 UINT exit_code) { finished = exit_code == 0; });
705 ON_CALL(*handler, IsLastWindowOfProcess).WillByDefault([]() { return true; });
706 EXPECT_CALL(*handler, Quit).Times(1);
707 modifier.SetLifecycleManager(std::move(handler));
708
709 engine->lifecycle_manager()->BeginProcessingExit();
710
711 engine->Run();
712
713 engine->window_proc_delegate_manager()->OnTopLevelWindowProc(0, WM_CLOSE, 0,
714 0);
715
716 // The test will only succeed when this while loop exits. Otherwise it will
717 // timeout.
718 while (!finished) {
719 engine->task_runner()->ProcessTasks();
720 }
721 }

References flutter::WindowsLifecycleManager::BeginProcessingExit(), flutter::FlutterWindowsEngine::lifecycle_manager(), flutter::WindowProcDelegateManager::OnTopLevelWindowProc(), flutter::TaskRunner::ProcessTasks(), flutter::FlutterWindowsEngine::Run(), flutter::FlutterWindowsEngine::task_runner(), and flutter::FlutterWindowsEngine::window_proc_delegate_manager().

## ◆ TEST_F() [36/108]

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

Definition at line 723 of file flutter_windows_engine_unittests.cc.

723 {
724 FlutterWindowsEngineBuilder builder{GetContext()};
725 builder.SetDartEntrypoint("exitTestCancel");
726 bool finished = false;
727 bool did_call = false;
728
729 auto window_binding_handler =
730 std::make_unique<::testing::NiceMock<MockWindowBindingHandler>>();
731 MockFlutterWindowsView view(std::move(window_binding_handler));
732 view.SetEngine(builder.Build());
733 FlutterWindowsEngine* engine = view.GetEngine();
734
735 EngineModifier modifier(engine);
736 modifier.embedder_api().RunsAOTCompiledDartCode = []() { return false; };
737 auto handler = std::make_unique<MockWindowsLifecycleManager>(engine);
738 ON_CALL(*handler, Quit)
739 .WillByDefault([&finished](std::optional<HWND> hwnd,
740 std::optional<WPARAM> wparam,
741 std::optional<LPARAM> lparam,
742 UINT exit_code) { finished = true; });
743 ON_CALL(*handler, IsLastWindowOfProcess).WillByDefault([]() { return true; });
744 EXPECT_CALL(*handler, Quit).Times(0);
745 modifier.SetLifecycleManager(std::move(handler));
746 engine->lifecycle_manager()->BeginProcessingExit();
747
748 auto binary_messenger =
749 std::make_unique<BinaryMessengerImpl>(engine->messenger());
750 binary_messenger->SetMessageHandler(
751 "flutter/platform", [&did_call](const uint8_t* message,
752 size_t message_size, BinaryReply reply) {
753 std::string contents(message, message + message_size);
754 EXPECT_NE(contents.find("\"method\":\"System.exitApplication\""),
755 std::string::npos);
756 EXPECT_NE(contents.find("\"type\":\"required\""), std::string::npos);
757 EXPECT_NE(contents.find("\"exitCode\":0"), std::string::npos);
758 did_call = true;
759 char response[] = "";
760 reply(reinterpret_cast<uint8_t*>(response), 0);
761 });
762
763 engine->Run();
764
765 engine->window_proc_delegate_manager()->OnTopLevelWindowProc(0, WM_CLOSE, 0,
766 0);
767
768 while (!did_call) {
769 engine->task_runner()->ProcessTasks();
770 }
771
772 EXPECT_FALSE(finished);
773 }

References flutter::WindowsLifecycleManager::BeginProcessingExit(), flutter::FlutterWindowsEngine::lifecycle_manager(), message, flutter::FlutterWindowsEngine::messenger(), flutter::WindowProcDelegateManager::OnTopLevelWindowProc(), flutter::TaskRunner::ProcessTasks(), flutter::FlutterWindowsEngine::Run(), flutter::FlutterWindowsEngine::task_runner(), and flutter::FlutterWindowsEngine::window_proc_delegate_manager().

## ◆ TEST_F() [37/108]

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

Definition at line 837 of file flutter_windows_engine_unittests.cc.

837 {
838 FlutterWindowsEngineBuilder builder{GetContext()};
839 builder.SetDartEntrypoint("exitTestExit");
840 bool finished = false;
841
842 auto window_binding_handler =
843 std::make_unique<::testing::NiceMock<MockWindowBindingHandler>>();
844 MockFlutterWindowsView view(std::move(window_binding_handler));
845 view.SetEngine(builder.Build());
846 FlutterWindowsEngine* engine = view.GetEngine();
847
848 EngineModifier modifier(engine);
849 modifier.embedder_api().RunsAOTCompiledDartCode = []() { return false; };
850 auto handler = std::make_unique<MockWindowsLifecycleManager>(engine);
851 ON_CALL(*handler, IsLastWindowOfProcess).WillByDefault([&finished]() {
852 finished = true;
853 return false;
854 });
855 // Quit should not be called when there is more than one window.
856 EXPECT_CALL(*handler, Quit).Times(0);
857 modifier.SetLifecycleManager(std::move(handler));
858 engine->lifecycle_manager()->BeginProcessingExit();
859
860 engine->Run();
861
862 engine->window_proc_delegate_manager()->OnTopLevelWindowProc(0, WM_CLOSE, 0,
863 0);
864
865 while (!finished) {
866 engine->task_runner()->ProcessTasks();
867 }
868 }

References flutter::WindowsLifecycleManager::BeginProcessingExit(), flutter::FlutterWindowsEngine::lifecycle_manager(), flutter::WindowProcDelegateManager::OnTopLevelWindowProc(), flutter::TaskRunner::ProcessTasks(), flutter::FlutterWindowsEngine::Run(), flutter::FlutterWindowsEngine::task_runner(), and flutter::FlutterWindowsEngine::window_proc_delegate_manager().

## ◆ TEST_F() [38/108]

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

Definition at line 775 of file flutter_windows_engine_unittests.cc.

775 {
776 FlutterWindowsEngineBuilder builder{GetContext()};
777 builder.SetDartEntrypoint("exitTestExit");
778 bool second_close = false;
779
780 auto window_binding_handler =
781 std::make_unique<::testing::NiceMock<MockWindowBindingHandler>>();
782 MockFlutterWindowsView view(std::move(window_binding_handler));
783 view.SetEngine(builder.Build());
784 FlutterWindowsEngine* engine = view.GetEngine();
785
786 EngineModifier modifier(engine);
787 modifier.embedder_api().RunsAOTCompiledDartCode = []() { return false; };
788 auto handler = std::make_unique<MockWindowsLifecycleManager>(engine);
789 auto& handler_obj = *handler;
790 ON_CALL(handler_obj, IsLastWindowOfProcess).WillByDefault([]() {
791 return true;
792 });
793 ON_CALL(handler_obj, Quit)
794 .WillByDefault(
795 [&handler_obj](std::optional<HWND> hwnd, std::optional<WPARAM> wparam,
796 std::optional<LPARAM> lparam, UINT exit_code) {
797 handler_obj.WindowsLifecycleManager::Quit(hwnd, wparam, lparam,
798 exit_code);
799 });
800 ON_CALL(handler_obj, DispatchMessage)
801 .WillByDefault(
802 [&engine](HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) {
803 engine->window_proc_delegate_manager()->OnTopLevelWindowProc(
804 hwnd, msg, wparam, lparam);
805 });
806 modifier.SetLifecycleManager(std::move(handler));
807 engine->lifecycle_manager()->BeginProcessingExit();
808
809 engine->Run();
810
811 // This delegate will be registered after the lifecycle manager, so it will be
812 // called only when a message is not consumed by the lifecycle manager. This
813 // should be called on the second, synthesized WM_CLOSE message that the
814 // lifecycle manager posts.
815 engine->window_proc_delegate_manager()->RegisterTopLevelWindowProcDelegate(
816 [](HWND hwnd, UINT message, WPARAM wpar, LPARAM lpar, void* user_data,
817 LRESULT* result) {
818 switch (message) {
819 case WM_CLOSE: {
820 bool* called = reinterpret_cast<bool*>(user_data);
821 *called = true;
822 return true;
823 }
824 }
825 return false;
826 },
827 reinterpret_cast<void*>(&second_close));
828
829 engine->window_proc_delegate_manager()->OnTopLevelWindowProc(0, WM_CLOSE, 0,
830 0);
831
832 while (!second_close) {
833 engine->task_runner()->ProcessTasks();
834 }
835 }

References flutter::WindowsLifecycleManager::BeginProcessingExit(), flutter::FlutterWindowsEngine::lifecycle_manager(), message, flutter::WindowProcDelegateManager::OnTopLevelWindowProc(), flutter::TaskRunner::ProcessTasks(), flutter::WindowProcDelegateManager::RegisterTopLevelWindowProcDelegate(), flutter::FlutterWindowsEngine::Run(), flutter::FlutterWindowsEngine::task_runner(), user_data, and flutter::FlutterWindowsEngine::window_proc_delegate_manager().

## ◆ TEST_F() [39/108]

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

Definition at line 560 of file flutter_windows_engine_unittests.cc.

560 {
561 FlutterWindowsEngineBuilder builder{GetContext()};
562 std::unique_ptr<FlutterWindowsEngine> engine = builder.Build();
563 EngineModifier modifier(engine.get());
564
565 bool called = false;
566 modifier.embedder_api().UpdateAccessibilityFeatures = MOCK_ENGINE_PROC(
567 UpdateAccessibilityFeatures, ([&called](auto engine, auto flags) {
568 called = true;
569 return kSuccess;
570 }));
571
572 engine->UpdateHighContrastEnabled(true);
573 EXPECT_TRUE(
574 engine->EnabledAccessibilityFeatures() &
575 FlutterAccessibilityFeature::kFlutterAccessibilityFeatureHighContrast);
576 EXPECT_TRUE(engine->high_contrast_enabled());
577 EXPECT_TRUE(called);
578
579 engine->UpdateHighContrastEnabled(false);
580 EXPECT_FALSE(
581 engine->EnabledAccessibilityFeatures() &
582 FlutterAccessibilityFeature::kFlutterAccessibilityFeatureHighContrast);
583 EXPECT_FALSE(engine->high_contrast_enabled());
584 }

## ◆ TEST_F() [40/108]

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

Definition at line 1221 of file keyboard_unittests.cc.

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

References EXPECT_CALL_IS_EVENT, and EXPECT_CALL_IS_TEXT.

## ◆ TEST_F() [41/108]

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

Definition at line 1307 of file keyboard_unittests.cc.

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

References EXPECT_CALL_IS_EVENT.

## ◆ TEST_F() [42/108]

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

Definition at line 822 of file keyboard_unittests.cc.

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

References EXPECT_CALL_IS_EVENT.

## ◆ TEST_F() [43/108]

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

Definition at line 855 of file keyboard_unittests.cc.

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

References EXPECT_CALL_IS_EVENT.

## ◆ TEST_F() [44/108]

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

Definition at line 619 of file keyboard_unittests.cc.

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

References EXPECT_CALL_IS_EVENT.

## ◆ TEST_F() [45/108]

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

Definition at line 649 of file keyboard_unittests.cc.

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

References EXPECT_CALL_IS_EVENT.

## ◆ TEST_F() [46/108]

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

Definition at line 1131 of file keyboard_unittests.cc.

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

References EXPECT_CALL_IS_EVENT.

## ◆ TEST_F() [47/108]

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

Definition at line 1073 of file keyboard_unittests.cc.

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

References EXPECT_CALL_IS_EVENT, kScanCodeKeyA, and kVirtualKeyA.

## ◆ TEST_F() [48/108]

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

Definition at line 756 of file keyboard_unittests.cc.

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

References EXPECT_CALL_IS_EVENT.

## ◆ TEST_F() [49/108]

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

Definition at line 789 of file keyboard_unittests.cc.

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

References EXPECT_CALL_IS_EVENT.

## ◆ TEST_F() [50/108]

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

Definition at line 1408 of file keyboard_unittests.cc.

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

References EXPECT_CALL_IS_EVENT, and EXPECT_CALL_IS_TEXT.

## ◆ TEST_F() [51/108]

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

Definition at line 1551 of file keyboard_unittests.cc.

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

References EXPECT_CALL_IS_EVENT, and EXPECT_CALL_IS_TEXT.

## ◆ TEST_F() [52/108]

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

Definition at line 1620 of file keyboard_unittests.cc.

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

References callback, EXPECT_CALL_IS_EVENT, and EXPECT_CALL_IS_TEXT.

## ◆ TEST_F() [53/108]

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

Definition at line 1471 of file keyboard_unittests.cc.

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

References EXPECT_CALL_IS_EVENT, EXPECT_CALL_IS_TEXT, and flutter::kScanCodeShiftLeft.

## ◆ TEST_F() [54/108]

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

Definition at line 1188 of file keyboard_unittests.cc.

1188 {
1189 KeyboardTester tester{GetContext()};
1190 tester.Responding(false);
1191
1192 tester.SetLayout(LayoutFrench);
1193
1194 // Press 1
1195 tester.InjectKeyboardChanges(std::vector<KeyboardChange>{
1196 WmKeyDownInfo{kVirtualDigit1, kScanCodeDigit1, kNotExtended, kWasUp}
1197 .Build(kWmResultZero),
1198 WmCharInfo{'&', kScanCodeDigit1, kNotExtended, kWasUp}.Build(
1199 kWmResultZero)});
1200
1201 EXPECT_EQ(key_calls.size(), 2);
1202 EXPECT_CALL_IS_EVENT(key_calls[0], kFlutterKeyEventTypeDown, kPhysicalDigit1,
1203 kLogicalDigit1, "&", kNotSynthesized);
1204 EXPECT_CALL_IS_TEXT(key_calls[1], u"&");
1205 clear_key_calls();
1206 EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 2);
1207
1208 // Release 1
1209 tester.InjectKeyboardChanges(std::vector<KeyboardChange>{
1210 WmKeyUpInfo{kVirtualDigit1, kScanCodeDigit1, kNotExtended}.Build(
1211 kWmResultZero)});
1212
1213 EXPECT_EQ(key_calls.size(), 1);
1214 EXPECT_CALL_IS_EVENT(key_calls[0], kFlutterKeyEventTypeUp, kPhysicalDigit1,
1215 kLogicalDigit1, "", kNotSynthesized);
1216 clear_key_calls();
1217 EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 1);
1218 }

References EXPECT_CALL_IS_EVENT, and EXPECT_CALL_IS_TEXT.

## ◆ TEST_F() [55/108]

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

Definition at line 2438 of file keyboard_unittests.cc.

2438 {
2439 KeyboardTester tester{GetContext()};
2440 tester.Responding(false);
2441
2442 tester.InjectKeyboardChanges(std::vector<KeyboardChange>{
2443 WmKeyDownInfo{VK_CAPITAL, 0, kNotExtended}.Build(),
2444 WmKeyUpInfo{VK_CAPITAL, 0, kNotExtended}.Build()});
2445
2446 clear_key_calls();
2447 }

## ◆ TEST_F() [56/108]

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

Definition at line 1967 of file keyboard_unittests.cc.

1967 {
1968 KeyboardTester tester{GetContext()};
1969 tester.Responding(false);
1970
1971 // US Keyboard layout.
1972
1973 // There should be preceding key events to make the keyboard into IME mode.
1974 // Omit them in this test since they are not relavent.
1975
1976 // Press CtrlRight in IME mode.
1977 tester.InjectKeyboardChanges(std::vector<KeyboardChange>{
1978 KeyStateChange{VK_RCONTROL, true, false},
1979 WmKeyDownInfo{VK_PROCESSKEY, kScanCodeControl, kExtended, kWasUp}.Build(
1980 kWmResultZero)});
1981
1982 EXPECT_EQ(key_calls.size(), 1);
1983 EXPECT_CALL_IS_EVENT(key_calls[0], kFlutterKeyEventTypeDown, 0, 0, "",
1984 kNotSynthesized);
1985 clear_key_calls();
1986 EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 0);
1987 }

References EXPECT_CALL_IS_EVENT.

## ◆ TEST_F() [57/108]

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

Definition at line 556 of file keyboard_unittests.cc.

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

References EXPECT_CALL_IS_EVENT, kScanCodeKeyA, and kVirtualKeyA.

## ◆ TEST_F() [58/108]

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

Definition at line 587 of file keyboard_unittests.cc.

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

References EXPECT_CALL_IS_EVENT, EXPECT_CALL_IS_TEXT, kScanCodeKeyA, and kVirtualKeyA.

## ◆ TEST_F() [59/108]

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

Definition at line 889 of file keyboard_unittests.cc.

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

References EXPECT_CALL_IS_EVENT.

## ◆ TEST_F() [60/108]

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

Definition at line 920 of file keyboard_unittests.cc.

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

References EXPECT_CALL_IS_EVENT.

## ◆ TEST_F() [61/108]

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

Definition at line 1702 of file keyboard_unittests.cc.

1702 {
1703 KeyboardTester tester{GetContext()};
1704 tester.Responding(false);
1705
1706 // Gothic Keyboard layout. (We need a layout that yields non-BMP characters
1707 // without IME, which is actually very rare.)
1708
1709 // Press key W of a US keyboard, which should yield character '𐍅'.
1710 tester.InjectKeyboardChanges(std::vector<KeyboardChange>{
1711 WmKeyDownInfo{kVirtualKeyW, kScanCodeKeyW, kNotExtended, kWasUp}.Build(
1712 kWmResultZero),
1713 WmCharInfo{0xd800, kScanCodeKeyW, kNotExtended, kWasUp}.Build(
1714 kWmResultZero),
1715 WmCharInfo{0xdf45, kScanCodeKeyW, kNotExtended, kWasUp}.Build(
1716 kWmResultZero)});
1717
1718 const char* st = key_calls[0].key_event.character;
1719
1720 EXPECT_EQ(key_calls.size(), 2);
1721 EXPECT_CALL_IS_EVENT(key_calls[0], kFlutterKeyEventTypeDown, kPhysicalKeyW,
1722 kLogicalKeyW, "𐍅", kNotSynthesized);
1723 EXPECT_CALL_IS_TEXT(key_calls[1], u"𐍅");
1724 clear_key_calls();
1725 EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 3);
1726
1727 // Release W
1728 tester.InjectKeyboardChanges(std::vector<KeyboardChange>{
1729 WmKeyUpInfo{kVirtualKeyW, kScanCodeKeyW, kNotExtended}.Build(
1730 kWmResultZero)});
1731
1732 EXPECT_EQ(key_calls.size(), 1);
1733 EXPECT_CALL_IS_EVENT(key_calls[0], kFlutterKeyEventTypeUp, kPhysicalKeyW,
1734 kLogicalKeyW, "", kNotSynthesized);
1735 clear_key_calls();
1736 EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 1);
1737 }

References EXPECT_CALL_IS_EVENT, and EXPECT_CALL_IS_TEXT.

## ◆ TEST_F() [62/108]

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

Definition at line 953 of file keyboard_unittests.cc.

953 {
954 KeyboardTester tester{GetContext()};
955 tester.Responding(true);
956
957 // Press A
958 tester.InjectKeyboardChanges(std::vector<KeyboardChange>{
959 WmKeyDownInfo{kVirtualKeyA, kScanCodeKeyA, kNotExtended, kWasUp}.Build(
960 kWmResultZero),
961 WmCharInfo{'a', kScanCodeKeyA, kNotExtended, kWasUp}.Build(
962 kWmResultZero)});
963
964 // Hold A
965 tester.InjectKeyboardChanges(std::vector<KeyboardChange>{
966 WmKeyDownInfo{kVirtualKeyA, kScanCodeKeyA, kNotExtended, kWasDown}.Build(
967 kWmResultZero),
968 WmCharInfo{'a', kScanCodeKeyA, kNotExtended, kWasDown}.Build(
969 kWmResultZero)});
970
971 EXPECT_EQ(key_calls.size(), 2);
972 EXPECT_CALL_IS_EVENT(key_calls[0], kFlutterKeyEventTypeDown, kPhysicalKeyA,
973 kLogicalKeyA, "a", kNotSynthesized);
974 EXPECT_CALL_IS_EVENT(key_calls[1], kFlutterKeyEventTypeRepeat, kPhysicalKeyA,
975 kLogicalKeyA, "a", kNotSynthesized);
976 EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 0);
977 }

References EXPECT_CALL_IS_EVENT, kScanCodeKeyA, and kVirtualKeyA.

## ◆ TEST_F() [63/108]

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

Definition at line 982 of file keyboard_unittests.cc.

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

References EXPECT_CALL_IS_EVENT, kScanCodeKeyA, and kVirtualKeyA.

## ◆ TEST_F() [64/108]

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

Definition at line 1014 of file keyboard_unittests.cc.

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

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

## ◆ TEST_F() [65/108]

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

Definition at line 679 of file keyboard_unittests.cc.

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

References EXPECT_CALL_IS_EVENT, and flutter::kScanCodeShiftLeft.

## ◆ TEST_F() [66/108]

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

Definition at line 723 of file keyboard_unittests.cc.

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

References EXPECT_CALL_IS_EVENT, and flutter::kScanCodeShiftRight.

## ◆ TEST_F() [67/108]

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

Definition at line 2033 of file keyboard_unittests.cc.

2033 {
2034 KeyboardTester tester{GetContext()};
2035
2036 std::vector<MockKeyResponseController::ResponseCallback> recorded_callbacks;
2037
2038 // Store callbacks to manually call them.
2039 tester.LateResponding(
2040 [&recorded_callbacks](
2041 const FlutterKeyEvent* event,
2042 MockKeyResponseController::ResponseCallback callback) {
2043 recorded_callbacks.push_back(callback);
2044 });
2045
2046 // Press A
2047 tester.InjectKeyboardChanges(std::vector<KeyboardChange>{
2048 WmKeyDownInfo{kVirtualKeyA, kScanCodeKeyA, kNotExtended, kWasUp}.Build(
2049 kWmResultZero),
2050 WmCharInfo{'a', kScanCodeKeyA, kNotExtended, kWasUp}.Build(
2051 kWmResultZero)});
2052
2053 // Hold A
2054 tester.InjectKeyboardChanges(std::vector<KeyboardChange>{
2055 WmKeyDownInfo{kVirtualKeyA, kScanCodeKeyA, kNotExtended, kWasDown}.Build(
2056 kWmResultZero),
2057 WmCharInfo{'a', kScanCodeKeyA, kNotExtended, kWasDown}.Build(
2058 kWmResultZero)});
2059
2060 EXPECT_EQ(key_calls.size(), 1);
2061 EXPECT_CALL_IS_EVENT(key_calls[0], kFlutterKeyEventTypeDown, kPhysicalKeyA,
2062 kLogicalKeyA, "a", kNotSynthesized);
2063 EXPECT_EQ(recorded_callbacks.size(), 1);
2064 EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 0);
2065
2066 // The first response.
2067 recorded_callbacks.front()(false);
2068
2069 EXPECT_EQ(key_calls.size(), 3);
2070 EXPECT_EQ(recorded_callbacks.size(), 2);
2071 EXPECT_CALL_IS_TEXT(key_calls[1], u"a");
2072 EXPECT_CALL_IS_EVENT(key_calls[2], kFlutterKeyEventTypeRepeat, kPhysicalKeyA,
2073 kLogicalKeyA, "a", kNotSynthesized);
2074 EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 2);
2075
2076 // The second response.
2077 recorded_callbacks.back()(false);
2078
2079 EXPECT_EQ(key_calls.size(), 4);
2080 EXPECT_CALL_IS_TEXT(key_calls[3], u"a");
2081 clear_key_calls();
2082 EXPECT_EQ(tester.RedispatchedMessageCountAndClear(), 2);
2083 }

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

## ◆ TEST_F() [68/108]

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

Definition at line 2096 of file keyboard_unittests.cc.

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

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

## ◆ TEST_F() [69/108]

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

Definition at line 1739 of file keyboard_unittests.cc.

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

References EXPECT_CALL_IS_EVENT.

## ◆ TEST_F() [70/108]

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

Definition at line 2172 of file keyboard_unittests.cc.

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

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

## ◆ TEST_F() [71/108]

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

Definition at line 1995 of file keyboard_unittests.cc.

1995 {
1996 KeyboardTester tester{GetContext()};
1997 tester.Responding(true);
1998
1999 // US Keyboard layout.
2000
2001 // Press CtrlRight in IME mode.
2002 tester.InjectKeyboardChanges(std::vector<KeyboardChange>{
2003 KeyStateChange{VK_LSHIFT, true, false},
2004 WmKeyDownInfo{VK_SHIFT, kScanCodeShiftLeft, kNotExtended, kWasUp}.Build(
2005 kWmResultZero),
2006 WmKeyDownInfo{VK_PROCESSKEY, kScanCodeDigit2, kNotExtended, kWasUp}.Build(
2007 kWmResultZero),
2008 KeyStateChange{VK_LSHIFT, false, true},
2009 WmKeyUpInfo{VK_PROCESSKEY, kScanCodeShiftLeft, kNotExtended}.Build(
2010 kWmResultZero),
2011 WmKeyUpInfo{'2', kScanCodeDigit2, kNotExtended, kWasUp}.Build(
2012 kWmResultZero)});
2013
2014 EXPECT_EQ(key_calls.size(), 4);
2015 EXPECT_CALL_IS_EVENT(key_calls[0], kFlutterKeyEventTypeDown,
2016 kPhysicalShiftLeft, kLogicalShiftLeft, "",
2017 kNotSynthesized);
2018 EXPECT_CALL_IS_EVENT(key_calls[1], kFlutterKeyEventTypeDown, 0, 0, "",
2019 kNotSynthesized);
2020 EXPECT_CALL_IS_EVENT(key_calls[2], kFlutterKeyEventTypeUp, kPhysicalShiftLeft,
2021 kLogicalShiftLeft, "", kNotSynthesized);
2022 EXPECT_CALL_IS_EVENT(key_calls[3], kFlutterKeyEventTypeDown, 0, 0, "",
2023 kNotSynthesized);
2024 clear_key_calls();
2025 }

References EXPECT_CALL_IS_EVENT, and flutter::kScanCodeShiftLeft.

## ◆ TEST_F() [72/108]

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

Definition at line 2240 of file keyboard_unittests.cc.

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

References EXPECT_CALL_IS_EVENT, EXPECT_CALL_IS_TEXT, kScanCodeKeyA, and kVirtualKeyA.

## ◆ TEST_F() [73/108]

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

Definition at line 2428 of file keyboard_unittests.cc.

2428 {
2429 VietnameseTelexAddDiacriticWithSlowResponse(GetContext(), false);
2430 }

References VietnameseTelexAddDiacriticWithSlowResponse().

## ◆ TEST_F() [74/108]

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

Definition at line 2432 of file keyboard_unittests.cc.

2432 {
2433 VietnameseTelexAddDiacriticWithSlowResponse(GetContext(), true);
2434 }

References VietnameseTelexAddDiacriticWithSlowResponse().

## ◆ TEST_F() [75/108]

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

Definition at line 263 of file platform_handler_unittests.cc.

263 {
264 use_engine_with_view();
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/108]

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

Definition at line 332 of file platform_handler_unittests.cc.

332 {
333 use_engine_with_view();
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/108]

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

Definition at line 305 of file platform_handler_unittests.cc.

305 {
306 use_engine_with_view();
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/108]

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

Definition at line 352 of file platform_handler_unittests.cc.

352 {
353 use_engine_with_view();
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/108]

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

Definition at line 317 of file platform_handler_unittests.cc.

317 {
318 use_headless_engine();
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/108]

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

Definition at line 284 of file platform_handler_unittests.cc.

284 {
285 use_engine_with_view();
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/108]

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

Definition at line 372 of file platform_handler_unittests.cc.

372 {
373 use_engine_with_view();
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/108]

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

Definition at line 437 of file platform_handler_unittests.cc.

437 {
438 use_engine_with_view();
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/108]

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

Definition at line 457 of file platform_handler_unittests.cc.

457 {
458 use_engine_with_view();
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/108]

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

Definition at line 423 of file platform_handler_unittests.cc.

423 {
424 use_headless_engine();
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/108]

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

Definition at line 399 of file platform_handler_unittests.cc.

399 {
400 use_engine_with_view();
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/108]

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

Definition at line 411 of file platform_handler_unittests.cc.

411 {
412 use_engine_with_view();
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/108]

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

Definition at line 168 of file platform_handler_unittests.cc.

168 {
169 use_engine_with_view();
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/108]

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

Definition at line 192 of file platform_handler_unittests.cc.

192 {
193 use_engine_with_view();
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/108]

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

Definition at line 239 of file platform_handler_unittests.cc.

239 {
240 use_engine_with_view();
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/108]

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

Definition at line 219 of file platform_handler_unittests.cc.

219 {
220 use_engine_with_view();
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/108]

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

Definition at line 205 of file platform_handler_unittests.cc.

205 {
206 use_headless_engine();
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/108]

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

Definition at line 480 of file platform_handler_unittests.cc.

480 {
481 use_headless_engine();
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/108]

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

Definition at line 520 of file platform_handler_unittests.cc.

520 {
521 use_headless_engine();
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/108]

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

Definition at line 541 of file platform_handler_unittests.cc.

541 {
542 use_headless_engine();
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/108]

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

Definition at line 498 of file platform_handler_unittests.cc.

498 {
499 use_headless_engine();
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/108]

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

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

Definition at line 268 of file flutter_windows_unittests.cc.

268 {
269 auto& context = GetContext();
270 WindowsConfigBuilder builder(context);
271 ViewControllerPtr controller{builder.Run()};
272 ASSERT_NE(controller, nullptr);
273 auto view = FlutterDesktopViewControllerGetView(controller.get());
274
275 Microsoft::WRL::ComPtr<IDXGIAdapter> dxgi_adapter;
276 dxgi_adapter = FlutterDesktopViewGetGraphicsAdapter(view);
277 ASSERT_NE(dxgi_adapter, nullptr);
278 DXGI_ADAPTER_DESC desc{};
279 ASSERT_TRUE(SUCCEEDED(dxgi_adapter->GetDesc(&desc)));
280 }

References FlutterDesktopViewControllerGetView(), and FlutterDesktopViewGetGraphicsAdapter().

## ◆ TEST_F() [98/108]

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

Definition at line 107 of file flutter_windows_unittests.cc.

107 {
108 auto& context = GetContext();
109 WindowsConfigBuilder builder(context);
110 builder.SetDartEntrypoint("customEntrypoint");
111 EnginePtr engine{builder.InitializeEngine()};
112 ASSERT_NE(engine, nullptr);
113
114 ASSERT_FALSE(FlutterDesktopEngineRun(engine.get(), "conflictingEntrypoint"));
115 }

References FlutterDesktopEngineRun().

## ◆ TEST_F() [99/108]

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

Definition at line 70 of file flutter_windows_unittests.cc.

70 {
71 auto& context = GetContext();
72 WindowsConfigBuilder builder(context);
73 builder.SetDartEntrypoint("customEntrypoint");
74 ViewControllerPtr controller{builder.Run()};
75 ASSERT_NE(controller, nullptr);
76 }

## ◆ TEST_F() [100/108]

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

Definition at line 83 of file flutter_windows_unittests.cc.

83 {
84 auto& context = GetContext();
85 WindowsConfigBuilder builder(context);
86 EnginePtr engine{builder.InitializeEngine()};
87 ASSERT_NE(engine, nullptr);
88
89 ASSERT_TRUE(FlutterDesktopEngineRun(engine.get(), "customEntrypoint"));
90 }

References FlutterDesktopEngineRun().

## ◆ TEST_F() [101/108]

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

Definition at line 93 of file flutter_windows_unittests.cc.

93 {
94 auto& context = GetContext();
95 WindowsConfigBuilder builder(context);
96 EnginePtr engine{builder.InitializeEngine()};
97 ASSERT_NE(engine, nullptr);
98
99 ASSERT_TRUE(FlutterDesktopEngineRun(engine.get(), nullptr));
100 }

References FlutterDesktopEngineRun().

## ◆ TEST_F() [102/108]

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

Definition at line 36 of file flutter_windows_unittests.cc.

36 {
37 auto& context = GetContext();
38 WindowsConfigBuilder builder(context);
39 ViewControllerPtr controller{builder.Run()};
40 ASSERT_NE(controller, nullptr);
41 }

## ◆ TEST_F() [103/108]

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

Definition at line 44 of file flutter_windows_unittests.cc.

44 {
45 // Replace stdout & stderr stream buffers with our own.
46 std::stringstream cout_buffer;
47 std::stringstream cerr_buffer;
48 std::streambuf* old_cout_buffer = std::cout.rdbuf();
49 std::streambuf* old_cerr_buffer = std::cerr.rdbuf();
50 std::cout.rdbuf(cout_buffer.rdbuf());
51 std::cerr.rdbuf(cerr_buffer.rdbuf());
52
53 auto& context = GetContext();
54 WindowsConfigBuilder builder(context);
55 ViewControllerPtr controller{builder.Run()};
56 ASSERT_NE(controller, nullptr);
57
58 // Restore original stdout & stderr stream buffer.
59 std::cout.rdbuf(old_cout_buffer);
60 std::cerr.rdbuf(old_cerr_buffer);
61
62 // Verify stdout & stderr have no output.
63 std::string cout = cout_buffer.str();
64 std::string cerr = cerr_buffer.str();
65 EXPECT_TRUE(cout.empty());
66 EXPECT_TRUE(cerr.empty());
67 }

## ◆ TEST_F() [104/108]

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

Definition at line 215 of file flutter_windows_unittests.cc.

215 {
216 struct Captures {
217 fml::AutoResetWaitableEvent frame_scheduled_latch;
218 fml::AutoResetWaitableEvent frame_drawn_latch;
219 std::thread::id thread_id;
220 };
221 Captures captures;
222
223 CreateNewThread("test_platform_thread")->PostTask([&]() {
224 captures.thread_id = std::this_thread::get_id();
225
226 auto& context = GetContext();
227 WindowsConfigBuilder builder(context);
228 builder.SetDartEntrypoint("drawHelloWorld");
229
230 auto native_entry = CREATE_NATIVE_ENTRY([&](Dart_NativeArguments args) {
231 ASSERT_FALSE(captures.frame_drawn_latch.IsSignaledForTest());
232 captures.frame_scheduled_latch.Signal();
233 });
234 context.AddNativeFunction("NotifyFirstFrameScheduled", native_entry);
235
236 ViewControllerPtr controller{builder.Run()};
237 ASSERT_NE(controller, nullptr);
238
239 auto engine = FlutterDesktopViewControllerGetEngine(controller.get());
240
241 FlutterDesktopEngineSetNextFrameCallback(
242 engine,
243 [](void* user_data) {
244 auto captures = static_cast<Captures*>(user_data);
245
246 ASSERT_TRUE(captures->frame_scheduled_latch.IsSignaledForTest());
247
248 // Callback should execute on platform thread.
249 ASSERT_EQ(std::this_thread::get_id(), captures->thread_id);
250
251 // Signal the test passed and end the Windows message loop.
252 captures->frame_drawn_latch.Signal();
253 ::PostQuitMessage(0);
254 },
255 &captures);
256
257 // Pump messages for the Windows platform task runner.
258 ::MSG msg;
259 while (::GetMessage(&msg, nullptr, 0, 0)) {
260 ::TranslateMessage(&msg);
261 ::DispatchMessage(&msg);
262 }
263 });
264
265 captures.frame_drawn_latch.Wait();
266 }

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

## ◆ TEST_F() [105/108]

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

Definition at line 160 of file flutter_windows_unittests.cc.

160 {
161 auto& context = GetContext();
162 WindowsConfigBuilder builder(context);
163 builder.SetDartEntrypoint("readPlatformExecutable");
164
165 std::string executable_name;
166 fml::AutoResetWaitableEvent latch;
167 auto native_entry = CREATE_NATIVE_ENTRY([&](Dart_NativeArguments args) {
168 auto handle = Dart_GetNativeArgument(args, 0);
169 ASSERT_FALSE(Dart_IsError(handle));
170 executable_name = tonic::DartConverter<std::string>::FromDart(handle);
171 latch.Signal();
172 });
173 context.AddNativeFunction("SignalStringValue", native_entry);
174
175 ViewControllerPtr controller{builder.Run()};
176 ASSERT_NE(controller, nullptr);
177
178 // Wait until signalStringValue has been called.
179 latch.Wait();
180 EXPECT_EQ(executable_name, "flutter_windows_unittests.exe");
181 }

## ◆ TEST_F() [106/108]

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

Definition at line 118 of file flutter_windows_unittests.cc.

118 {
119 auto& context = GetContext();
120 WindowsConfigBuilder builder(context);
121 builder.SetDartEntrypoint("verifyNativeFunction");
122
123 fml::AutoResetWaitableEvent latch;
124 auto native_entry =
125 CREATE_NATIVE_ENTRY([&](Dart_NativeArguments args) { latch.Signal(); });
126 context.AddNativeFunction("Signal", native_entry);
127
128 ViewControllerPtr controller{builder.Run()};
129 ASSERT_NE(controller, nullptr);
130
131 // Wait until signal has been called.
132 latch.Wait();
133 }

## ◆ TEST_F() [107/108]

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

Definition at line 137 of file flutter_windows_unittests.cc.

137 {
138 auto& context = GetContext();
139 WindowsConfigBuilder builder(context);
140 builder.SetDartEntrypoint("verifyNativeFunctionWithParameters");
141
142 bool bool_value = false;
143 fml::AutoResetWaitableEvent latch;
144 auto native_entry = CREATE_NATIVE_ENTRY([&](Dart_NativeArguments args) {
145 auto handle = Dart_GetNativeBooleanArgument(args, 0, &bool_value);
146 ASSERT_FALSE(Dart_IsError(handle));
147 latch.Signal();
148 });
149 context.AddNativeFunction("SignalBoolValue", native_entry);
150
151 ViewControllerPtr controller{builder.Run()};
152 ASSERT_NE(controller, nullptr);
153
154 // Wait until signalBoolValue has been called.
155 latch.Wait();
156 EXPECT_TRUE(bool_value);
157 }

## ◆ TEST_F() [108/108]

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

Definition at line 185 of file flutter_windows_unittests.cc.

185 {
186 auto& context = GetContext();
187 WindowsConfigBuilder builder(context);
188 builder.SetDartEntrypoint("verifyNativeFunctionWithReturn");
189
190 bool bool_value_to_return = true;
191 fml::CountDownLatch latch(2);
192 auto bool_return_entry = CREATE_NATIVE_ENTRY([&](Dart_NativeArguments args) {
193 Dart_SetBooleanReturnValue(args, bool_value_to_return);
194 latch.CountDown();
195 });
196 context.AddNativeFunction("SignalBoolReturn", bool_return_entry);
197
198 bool bool_value_passed = false;
199 auto bool_pass_entry = CREATE_NATIVE_ENTRY([&](Dart_NativeArguments args) {
200 auto handle = Dart_GetNativeBooleanArgument(args, 0, &bool_value_passed);
201 ASSERT_FALSE(Dart_IsError(handle));
202 latch.CountDown();
203 });
204 context.AddNativeFunction("SignalBoolValue", bool_pass_entry);
205
206 ViewControllerPtr controller{builder.Run()};
207 ASSERT_NE(controller, nullptr);
208
209 // Wait until signalBoolReturn and signalBoolValue have been called.
210 latch.Wait();
211 EXPECT_TRUE(bool_value_passed);
212 }

## ◆ VietnameseTelexAddDiacriticWithSlowResponse()

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

Definition at line 2322 of file keyboard_unittests.cc.

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

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 36 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 37 of file flutter_windows_view_unittests.cc.

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

FlutterDesktopViewControllerGetView
FlutterDesktopViewRef FlutterDesktopViewControllerGetView(FlutterDesktopViewControllerRef controller)
Definition: flutter_windows.cc:100
flutter::testing::VietnameseTelexAddDiacriticWithSlowResponse
void VietnameseTelexAddDiacriticWithSlowResponse(WindowsTestContext &context, bool backspace_response)
Definition: keyboard_unittests.cc:2322
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
FlutterDesktopEngineGetTextureRegistrar
FlutterDesktopTextureRegistrarRef FlutterDesktopEngineGetTextureRegistrar(FlutterDesktopEngineRef engine)
Definition: flutter_windows.cc:177
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
FlutterDesktopViewControllerGetEngine
FlutterDesktopEngineRef FlutterDesktopViewControllerGetEngine(FlutterDesktopViewControllerRef controller)
Definition: flutter_windows.cc:95
flutter::GetDpiForMonitor
UINT GetDpiForMonitor(HMONITOR monitor)
Definition: dpi_utils.cc:134
user_data
void * user_data
Definition: flutter_windows_view_unittests.cc:47
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:27
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:544
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:548
flutter::kScanCodeShiftLeft
constexpr int kScanCodeShiftLeft
Definition: keyboard_utils.h:16
type
enum flutter::testing::@66::KeyboardChange::Type type
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:38
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:47
content
union flutter::testing::@66::KeyboardChange::@0 content
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:36
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
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:46
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:552
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:18
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:134
flutter::kScanCodeControlLeft
constexpr int kScanCodeControlLeft
Definition: keyboard_utils.h:19
FlutterDesktopEngineCreate
FlutterDesktopEngineRef FlutterDesktopEngineCreate(const FlutterDesktopEngineProperties *engine_properties)
Definition: flutter_windows.cc:127
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:183
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:194
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:31
FlutterDesktopEngineRun
bool FlutterDesktopEngineRun(FlutterDesktopEngineRef engine, const char *entry_point)
Definition: flutter_windows.cc:144
kFlutterDesktopPixelBufferTexture
@ kFlutterDesktopPixelBufferTexture
Definition: flutter_texture_registrar.h:26
flutter::testing::kVirtualKeyA
constexpr uint64_t kVirtualKeyA
Definition: flutter_windows_view_unittests.cc:37
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
callback
FlutterDesktopBinaryReply callback
Definition: flutter_windows_view_unittests.cc:46
node_delegate
std::shared_ptr< FlutterPlatformNodeDelegateWindows > node_delegate
Definition: accessibility_bridge_windows_unittests.cc:32