From 534a4bfa17319f23e9832cf8e0dd85000458216c Mon Sep 17 00:00:00 2001 From: Harlen Batagelo Date: Wed, 18 Dec 2024 17:39:03 -0300 Subject: [PATCH 1/2] Add tests for popups, dialogs, and satellites --- ...lutter_host_window_controller_unittests.cc | 339 ++++++++++++++++++ shell/platform/windows/windowing_handler.cc | 6 +- .../windows/windowing_handler_unittests.cc | 202 ++++++++++- 3 files changed, 540 insertions(+), 7 deletions(-) diff --git a/shell/platform/windows/flutter_host_window_controller_unittests.cc b/shell/platform/windows/flutter_host_window_controller_unittests.cc index 278545cc8e657..04f175894891a 100644 --- a/shell/platform/windows/flutter_host_window_controller_unittests.cc +++ b/shell/platform/windows/flutter_host_window_controller_unittests.cc @@ -139,6 +139,345 @@ TEST_F(FlutterHostWindowControllerTest, CreateRegularWindow) { EXPECT_EQ(client_rect.bottom - client_rect.top, size.height); } +TEST_F(FlutterHostWindowControllerTest, CreatePopup) { + // Create a top-level window first. + std::optional const parent_result = + host_window_controller()->CreateHostWindow(L"parent", {800, 600}, + WindowArchetype::regular, + std::nullopt, std::nullopt); + ASSERT_NE(parent_result, std::nullopt); + + bool called_onWindowCreated = false; + + // Test messenger with a handler for onWindowCreated. + TestBinaryMessenger messenger([&](const std::string& channel, + const uint8_t* message, size_t size, + BinaryReply reply) { + // Ensure the message is sent on the windowing channel. + ASSERT_EQ(channel, kChannelName); + + // Ensure the decoded method call is valid. + auto const method = StandardMethodCodec::GetInstance().DecodeMethodCall( + std::vector(message, message + size)); + ASSERT_NE(method, nullptr); + + // Handle the onWindowCreated method. + if (method->method_name() == kOnWindowCreatedMethod) { + called_onWindowCreated = true; + + // Validate the method arguments. + auto const& args = *method->arguments(); + ASSERT_TRUE(std::holds_alternative(args)); + auto const& args_map = std::get(args); + + // Ensure the viewId is present and valid. + auto const& it_viewId = args_map.find(EncodableValue(kViewIdKey)); + ASSERT_NE(it_viewId, args_map.end()); + auto const* value_viewId = std::get_if(&it_viewId->second); + ASSERT_NE(value_viewId, nullptr); + EXPECT_GE(*value_viewId, 0); + EXPECT_NE(engine()->view(*value_viewId), nullptr); + + // Ensure the parentViewId is present and valid. + auto const& it_parentViewId = + args_map.find(EncodableValue(kParentViewIdKey)); + ASSERT_NE(it_parentViewId, args_map.end()); + auto const* value_parentViewId = + std::get_if(&it_parentViewId->second); + EXPECT_EQ(*value_parentViewId, parent_result->view_id); + } + }); + + // Define parameters for the popup to be created. + WindowSize const size = {200, 200}; + wchar_t const* const title = L"popup"; + WindowArchetype const archetype = WindowArchetype::popup; + WindowPositioner const positioner = WindowPositioner{ + .anchor_rect = std::optional( + {.top_left = {0, 0}, .size = {size.width, size.height}}), + .parent_anchor = WindowPositioner::Anchor::center, + .child_anchor = WindowPositioner::Anchor::center, + .offset = {0, 0}, + .constraint_adjustment = WindowPositioner::ConstraintAdjustment::none}; + + // Create the windowing handler with the test messenger. + WindowingHandler windowing_handler(&messenger, host_window_controller()); + + // Create popup parented to top-level window. + std::optional const result = + host_window_controller()->CreateHostWindow( + title, size, archetype, positioner, parent_result->view_id); + + // Verify the onWindowCreated callback was invoked. + EXPECT_TRUE(called_onWindowCreated); + + // Validate the returned metadata. + ASSERT_TRUE(result.has_value()); + EXPECT_NE(engine()->view(result->view_id), nullptr); + EXPECT_EQ(result->archetype, archetype); + EXPECT_GE(result->size.width, size.width); + EXPECT_GE(result->size.height, size.height); + EXPECT_EQ(result->parent_id.value(), parent_result->view_id); + + // Verify the popup exists and the view has the expected dimensions. + FlutterHostWindow* const window = + host_window_controller()->GetHostWindow(result->view_id); + ASSERT_NE(window, nullptr); + RECT client_rect; + GetClientRect(window->GetWindowHandle(), &client_rect); + EXPECT_EQ(client_rect.right - client_rect.left, size.width); + EXPECT_EQ(client_rect.bottom - client_rect.top, size.height); +} + +TEST_F(FlutterHostWindowControllerTest, CreateModalDialog) { + // Create a top-level window first. + std::optional const parent_result = + host_window_controller()->CreateHostWindow(L"parent", {800, 600}, + WindowArchetype::regular, + std::nullopt, std::nullopt); + ASSERT_NE(parent_result, std::nullopt); + + bool called_onWindowCreated = false; + + // Test messenger with a handler for onWindowCreated. + TestBinaryMessenger messenger([&](const std::string& channel, + const uint8_t* message, size_t size, + BinaryReply reply) { + // Ensure the message is sent on the windowing channel. + ASSERT_EQ(channel, kChannelName); + + // Ensure the decoded method call is valid. + auto const method = StandardMethodCodec::GetInstance().DecodeMethodCall( + std::vector(message, message + size)); + ASSERT_NE(method, nullptr); + + // Handle the onWindowCreated method. + if (method->method_name() == kOnWindowCreatedMethod) { + called_onWindowCreated = true; + + // Validate the method arguments. + auto const& args = *method->arguments(); + ASSERT_TRUE(std::holds_alternative(args)); + auto const& args_map = std::get(args); + + // Ensure the viewId is present and valid. + auto const& it_viewId = args_map.find(EncodableValue(kViewIdKey)); + ASSERT_NE(it_viewId, args_map.end()); + auto const* value_viewId = std::get_if(&it_viewId->second); + ASSERT_NE(value_viewId, nullptr); + EXPECT_GE(*value_viewId, 0); + EXPECT_NE(engine()->view(*value_viewId), nullptr); + + // Ensure the parentViewId is present and valid. + auto const& it_parentViewId = + args_map.find(EncodableValue(kParentViewIdKey)); + ASSERT_NE(it_parentViewId, args_map.end()); + auto const* value_parentViewId = + std::get_if(&it_parentViewId->second); + EXPECT_EQ(*value_parentViewId, parent_result->view_id); + } + }); + + // Define parameters for the popup to be created. + WindowSize const size = {400, 300}; + wchar_t const* const title = L"modal_dialog"; + WindowArchetype const archetype = WindowArchetype::dialog; + + // Create the windowing handler with the test messenger. + WindowingHandler windowing_handler(&messenger, host_window_controller()); + + // Create dialog parented to top-level window. + std::optional const result = + host_window_controller()->CreateHostWindow( + title, size, archetype, std::nullopt, parent_result->view_id); + + // Verify the onWindowCreated callback was invoked. + EXPECT_TRUE(called_onWindowCreated); + + // Validate the returned metadata. + ASSERT_TRUE(result.has_value()); + EXPECT_NE(engine()->view(result->view_id), nullptr); + EXPECT_EQ(result->archetype, archetype); + EXPECT_GE(result->size.width, size.width); + EXPECT_GE(result->size.height, size.height); + EXPECT_EQ(result->parent_id.value(), parent_result->view_id); + + // Verify the dialog exists and the view has the expected dimensions. + FlutterHostWindow* const window = + host_window_controller()->GetHostWindow(result->view_id); + ASSERT_NE(window, nullptr); + RECT client_rect; + GetClientRect(window->GetWindowHandle(), &client_rect); + EXPECT_EQ(client_rect.right - client_rect.left, size.width); + EXPECT_EQ(client_rect.bottom - client_rect.top, size.height); +} + +TEST_F(FlutterHostWindowControllerTest, CreateModelessDialog) { + bool called_onWindowCreated = false; + + // Test messenger with a handler for onWindowCreated. + TestBinaryMessenger messenger([&](const std::string& channel, + const uint8_t* message, size_t size, + BinaryReply reply) { + // Ensure the message is sent on the windowing channel. + ASSERT_EQ(channel, kChannelName); + + // Ensure the decoded method call is valid. + auto const method = StandardMethodCodec::GetInstance().DecodeMethodCall( + std::vector(message, message + size)); + ASSERT_NE(method, nullptr); + + // Handle the onWindowCreated method. + if (method->method_name() == kOnWindowCreatedMethod) { + called_onWindowCreated = true; + + // Validate the method arguments. + auto const& args = *method->arguments(); + ASSERT_TRUE(std::holds_alternative(args)); + auto const& args_map = std::get(args); + + // Ensure the viewId is present and valid. + auto const& it_viewId = args_map.find(EncodableValue(kViewIdKey)); + ASSERT_NE(it_viewId, args_map.end()); + auto const* value_viewId = std::get_if(&it_viewId->second); + ASSERT_NE(value_viewId, nullptr); + EXPECT_GE(*value_viewId, 0); + EXPECT_NE(engine()->view(*value_viewId), nullptr); + + // Ensure the parentViewId is a std::monostate (indicating no parent). + auto const& it_parentViewId = + args_map.find(EncodableValue(kParentViewIdKey)); + ASSERT_NE(it_parentViewId, args_map.end()); + auto const* value_parentViewId = + std::get_if(&it_parentViewId->second); + EXPECT_NE(value_parentViewId, nullptr); + } + }); + + // Define parameters for the popup to be created. + WindowSize const size = {400, 300}; + wchar_t const* const title = L"modeless_dialog"; + WindowArchetype const archetype = WindowArchetype::dialog; + + // Create the windowing handler with the test messenger. + WindowingHandler windowing_handler(&messenger, host_window_controller()); + + // Create dialog without a parent. + std::optional const result = + host_window_controller()->CreateHostWindow(title, size, archetype, + std::nullopt, std::nullopt); + + // Verify the onWindowCreated callback was invoked. + EXPECT_TRUE(called_onWindowCreated); + + // Validate the returned metadata. + ASSERT_TRUE(result.has_value()); + EXPECT_NE(engine()->view(result->view_id), nullptr); + EXPECT_EQ(result->archetype, archetype); + EXPECT_GE(result->size.width, size.width); + EXPECT_GE(result->size.height, size.height); + EXPECT_FALSE(result->parent_id.has_value()); + + // Verify the dialog exists and the view has the expected dimensions. + FlutterHostWindow* const window = + host_window_controller()->GetHostWindow(result->view_id); + ASSERT_NE(window, nullptr); + RECT client_rect; + GetClientRect(window->GetWindowHandle(), &client_rect); + EXPECT_EQ(client_rect.right - client_rect.left, size.width); + EXPECT_EQ(client_rect.bottom - client_rect.top, size.height); +} + +TEST_F(FlutterHostWindowControllerTest, CreateSatellite) { + // Create a top-level window first. + std::optional const parent_result = + host_window_controller()->CreateHostWindow(L"parent", {800, 600}, + WindowArchetype::regular, + std::nullopt, std::nullopt); + ASSERT_NE(parent_result, std::nullopt); + + bool called_onWindowCreated = false; + + // Test messenger with a handler for onWindowCreated. + TestBinaryMessenger messenger([&](const std::string& channel, + const uint8_t* message, size_t size, + BinaryReply reply) { + // Ensure the message is sent on the windowing channel. + ASSERT_EQ(channel, kChannelName); + + // Ensure the decoded method call is valid. + auto const method = StandardMethodCodec::GetInstance().DecodeMethodCall( + std::vector(message, message + size)); + ASSERT_NE(method, nullptr); + + // Handle the onWindowCreated method. + if (method->method_name() == kOnWindowCreatedMethod) { + called_onWindowCreated = true; + + // Validate the method arguments. + auto const& args = *method->arguments(); + ASSERT_TRUE(std::holds_alternative(args)); + auto const& args_map = std::get(args); + + // Ensure the viewId is present and valid. + auto const& it_viewId = args_map.find(EncodableValue(kViewIdKey)); + ASSERT_NE(it_viewId, args_map.end()); + auto const* value_viewId = std::get_if(&it_viewId->second); + ASSERT_NE(value_viewId, nullptr); + EXPECT_GE(*value_viewId, 0); + EXPECT_NE(engine()->view(*value_viewId), nullptr); + + // Ensure the parentViewId is present and valid. + auto const& it_parentViewId = + args_map.find(EncodableValue(kParentViewIdKey)); + ASSERT_NE(it_parentViewId, args_map.end()); + auto const* value_parentViewId = + std::get_if(&it_parentViewId->second); + EXPECT_EQ(*value_parentViewId, parent_result->view_id); + } + }); + + // Define parameters for the satellite to be created. + WindowSize const size = {200, 300}; + wchar_t const* const title = L"satellite"; + WindowArchetype const archetype = WindowArchetype::satellite; + WindowPositioner const positioner = WindowPositioner{ + .anchor_rect = std::optional( + {.top_left = {0, 0}, .size = {size.width, size.height}}), + .parent_anchor = WindowPositioner::Anchor::center, + .child_anchor = WindowPositioner::Anchor::center, + .offset = {0, 0}, + .constraint_adjustment = WindowPositioner::ConstraintAdjustment::none}; + + // Create the windowing handler with the test messenger. + WindowingHandler windowing_handler(&messenger, host_window_controller()); + + // Create popup parented to top-level window. + std::optional const result = + host_window_controller()->CreateHostWindow( + title, size, archetype, positioner, parent_result->view_id); + + // Verify the onWindowCreated callback was invoked. + EXPECT_TRUE(called_onWindowCreated); + + // Validate the returned metadata. + ASSERT_TRUE(result.has_value()); + EXPECT_NE(engine()->view(result->view_id), nullptr); + EXPECT_EQ(result->archetype, archetype); + EXPECT_GE(result->size.width, size.width); + EXPECT_GE(result->size.height, size.height); + EXPECT_EQ(result->parent_id.value(), parent_result->view_id); + + // Verify the satellite exists and the view has the expected dimensions. + FlutterHostWindow* const window = + host_window_controller()->GetHostWindow(result->view_id); + ASSERT_NE(window, nullptr); + RECT client_rect; + GetClientRect(window->GetWindowHandle(), &client_rect); + EXPECT_EQ(client_rect.right - client_rect.left, size.width); + EXPECT_EQ(client_rect.bottom - client_rect.top, size.height); +} + TEST_F(FlutterHostWindowControllerTest, DestroyWindow) { bool done = false; diff --git a/shell/platform/windows/windowing_handler.cc b/shell/platform/windows/windowing_handler.cc index 0752dd4f2cbb1..25221f406fc6f 100644 --- a/shell/platform/windows/windowing_handler.cc +++ b/shell/platform/windows/windowing_handler.cc @@ -214,6 +214,9 @@ void WindowingHandler::HandleCreateWindow(WindowArchetype archetype, if (!positioner_parent_anchor) { return; } + auto const parent_anchor = + static_cast(positioner_parent_anchor.value()); + auto const positioner_child_anchor = GetSingleValueForKeyOrSendError( kPositionerChildAnchorKey, map, result); if (!positioner_child_anchor) { @@ -235,8 +238,7 @@ void WindowingHandler::HandleCreateWindow(WindowArchetype archetype, } positioner = WindowPositioner{ .anchor_rect = anchor_rect, - .parent_anchor = static_cast( - positioner_parent_anchor.value()), + .parent_anchor = parent_anchor, .child_anchor = child_anchor, .offset = {positioner_offset_list->at(0), positioner_offset_list->at(1)}, diff --git a/shell/platform/windows/windowing_handler_unittests.cc b/shell/platform/windows/windowing_handler_unittests.cc index be2db4ceed3da..6f468dc08280a 100644 --- a/shell/platform/windows/windowing_handler_unittests.cc +++ b/shell/platform/windows/windowing_handler_unittests.cc @@ -20,13 +20,27 @@ namespace { using ::testing::_; using ::testing::Eq; using ::testing::NiceMock; +using ::testing::Optional; using ::testing::Return; using ::testing::StrEq; -static constexpr char kChannelName[] = "flutter/windowing"; +constexpr char kChannelName[] = "flutter/windowing"; -static constexpr char kCreateWindowMethod[] = "createWindow"; -static constexpr char kDestroyWindowMethod[] = "destroyWindow"; +constexpr char kCreateWindowMethod[] = "createWindow"; +constexpr char kCreateDialogMethod[] = "createDialog"; +constexpr char kCreateSatelliteMethod[] = "createSatellite"; +constexpr char kCreatePopupMethod[] = "createPopup"; +constexpr char kDestroyWindowMethod[] = "destroyWindow"; + +constexpr char kAnchorRectKey[] = "anchorRect"; +constexpr char kParentKey[] = "parent"; +constexpr char kPositionerChildAnchorKey[] = "positionerChildAnchor"; +constexpr char kPositionerConstraintAdjustmentKey[] = + "positionerConstraintAdjustment"; +constexpr char kPositionerOffsetKey[] = "positionerOffset"; +constexpr char kPositionerParentAnchorKey[] = "positionerParentAnchor"; +constexpr char kSizeKey[] = "size"; +constexpr char kViewIdKey[] = "viewId"; void SimulateWindowingMessage(TestBinaryMessenger* messenger, const std::string& method_name, @@ -64,6 +78,20 @@ class MockFlutterHostWindowController : public FlutterHostWindowController { FML_DISALLOW_COPY_AND_ASSIGN(MockFlutterHostWindowController); }; +bool operator==(WindowPositioner const& lhs, WindowPositioner const& rhs) { + return lhs.anchor_rect == rhs.anchor_rect && + lhs.parent_anchor == rhs.parent_anchor && + lhs.child_anchor == rhs.child_anchor && lhs.offset == rhs.offset && + lhs.constraint_adjustment == rhs.constraint_adjustment; +} + +MATCHER_P(WindowPositionerEq, expected, "WindowPositioner matches expected") { + return arg.anchor_rect == expected.anchor_rect && + arg.parent_anchor == expected.parent_anchor && + arg.child_anchor == expected.child_anchor && + arg.offset == expected.offset && + arg.constraint_adjustment == expected.constraint_adjustment; +} } // namespace class WindowingHandlerTest : public WindowsTest { @@ -102,7 +130,7 @@ TEST_F(WindowingHandlerTest, HandleCreateRegularWindow) { WindowSize const size = {800, 600}; EncodableMap const arguments = { - {EncodableValue("size"), + {EncodableValue(kSizeKey), EncodableValue(EncodableList{EncodableValue(size.width), EncodableValue(size.height)})}, }; @@ -125,12 +153,176 @@ TEST_F(WindowingHandlerTest, HandleCreateRegularWindow) { EXPECT_TRUE(success); } +TEST_F(WindowingHandlerTest, HandleCreatePopup) { + TestBinaryMessenger messenger; + WindowingHandler windowing_handler(&messenger, controller()); + + WindowSize const size = {200, 200}; + std::optional const parent_view_id = 0; + WindowPositioner const positioner = WindowPositioner{ + .anchor_rect = std::optional( + {.top_left = {0, 0}, .size = {size.width, size.height}}), + .parent_anchor = WindowPositioner::Anchor::center, + .child_anchor = WindowPositioner::Anchor::center, + .offset = {0, 0}, + .constraint_adjustment = WindowPositioner::ConstraintAdjustment::none}; + EncodableMap const arguments = { + {EncodableValue(kSizeKey), + EncodableValue(EncodableList{EncodableValue(size.width), + EncodableValue(size.height)})}, + {EncodableValue(kAnchorRectKey), + EncodableValue( + EncodableList{EncodableValue(positioner.anchor_rect->top_left.x), + EncodableValue(positioner.anchor_rect->top_left.y), + EncodableValue(positioner.anchor_rect->size.width), + EncodableValue(positioner.anchor_rect->size.height)})}, + {EncodableValue(kPositionerParentAnchorKey), + EncodableValue(static_cast(positioner.parent_anchor))}, + {EncodableValue(kPositionerChildAnchorKey), + EncodableValue(static_cast(positioner.child_anchor))}, + {EncodableValue(kPositionerOffsetKey), + EncodableValue(EncodableList{EncodableValue(positioner.offset.x), + EncodableValue(positioner.offset.y)})}, + {EncodableValue(kPositionerConstraintAdjustmentKey), + EncodableValue(static_cast(positioner.constraint_adjustment))}, + {EncodableValue(kParentKey), + EncodableValue(static_cast(parent_view_id.value()))}}; + + bool success = false; + MethodResultFunctions<> result_handler( + [&success](const EncodableValue* result) { success = true; }, nullptr, + nullptr); + + EXPECT_CALL(*controller(), + CreateHostWindow(StrEq(L"popup"), size, WindowArchetype::popup, + Optional(WindowPositionerEq(positioner)), + parent_view_id)) + .Times(1); + + SimulateWindowingMessage(&messenger, kCreatePopupMethod, + std::make_unique(arguments), + &result_handler); + + EXPECT_TRUE(success); +} + +TEST_F(WindowingHandlerTest, HandleCreateModalDialog) { + TestBinaryMessenger messenger; + WindowingHandler windowing_handler(&messenger, controller()); + + WindowSize const size = {400, 300}; + std::optional const parent_view_id = 0; + EncodableMap const arguments = { + {EncodableValue(kSizeKey), + EncodableValue(EncodableList{EncodableValue(size.width), + EncodableValue(size.height)})}, + {EncodableValue(kParentKey), + EncodableValue(static_cast(parent_view_id.value()))}}; + + bool success = false; + MethodResultFunctions<> result_handler( + [&success](const EncodableValue* result) { success = true; }, nullptr, + nullptr); + + EXPECT_CALL(*controller(), + CreateHostWindow(StrEq(L"dialog"), size, WindowArchetype::dialog, + Eq(std::nullopt), parent_view_id)) + .Times(1); + + SimulateWindowingMessage(&messenger, kCreateDialogMethod, + std::make_unique(arguments), + &result_handler); + + EXPECT_TRUE(success); +} + +TEST_F(WindowingHandlerTest, HandleCreateModelessDialog) { + TestBinaryMessenger messenger; + WindowingHandler windowing_handler(&messenger, controller()); + + WindowSize const size = {400, 300}; + EncodableMap const arguments = { + {EncodableValue(kSizeKey), + EncodableValue(EncodableList{EncodableValue(size.width), + EncodableValue(size.height)})}, + {EncodableValue(kParentKey), EncodableValue()}}; + + bool success = false; + MethodResultFunctions<> result_handler( + [&success](const EncodableValue* result) { success = true; }, nullptr, + nullptr); + + EXPECT_CALL(*controller(), + CreateHostWindow(StrEq(L"dialog"), size, WindowArchetype::dialog, + Eq(std::nullopt), Eq(std::nullopt))) + .Times(1); + + SimulateWindowingMessage(&messenger, kCreateDialogMethod, + std::make_unique(arguments), + &result_handler); + + EXPECT_TRUE(success); +} + +TEST_F(WindowingHandlerTest, HandleCreateSatellite) { + TestBinaryMessenger messenger; + WindowingHandler windowing_handler(&messenger, controller()); + + WindowSize const size = {200, 300}; + std::optional const parent_view_id = 0; + WindowPositioner const positioner = WindowPositioner{ + .anchor_rect = std::optional( + {.top_left = {0, 0}, .size = {size.width, size.height}}), + .parent_anchor = WindowPositioner::Anchor::center, + .child_anchor = WindowPositioner::Anchor::center, + .offset = {0, 0}, + .constraint_adjustment = WindowPositioner::ConstraintAdjustment::none}; + EncodableMap const arguments = { + {EncodableValue(kSizeKey), + EncodableValue(EncodableList{EncodableValue(size.width), + EncodableValue(size.height)})}, + {EncodableValue(kAnchorRectKey), + EncodableValue( + EncodableList{EncodableValue(positioner.anchor_rect->top_left.x), + EncodableValue(positioner.anchor_rect->top_left.y), + EncodableValue(positioner.anchor_rect->size.width), + EncodableValue(positioner.anchor_rect->size.height)})}, + {EncodableValue(kPositionerParentAnchorKey), + EncodableValue(static_cast(positioner.parent_anchor))}, + {EncodableValue(kPositionerChildAnchorKey), + EncodableValue(static_cast(positioner.child_anchor))}, + {EncodableValue(kPositionerOffsetKey), + EncodableValue(EncodableList{EncodableValue(positioner.offset.x), + EncodableValue(positioner.offset.y)})}, + {EncodableValue(kPositionerConstraintAdjustmentKey), + EncodableValue(static_cast(positioner.constraint_adjustment))}, + {EncodableValue(kParentKey), + EncodableValue(static_cast(parent_view_id.value()))}}; + + bool success = false; + MethodResultFunctions<> result_handler( + [&success](const EncodableValue* result) { success = true; }, nullptr, + nullptr); + + EXPECT_CALL(*controller(), + CreateHostWindow( + StrEq(L"satellite"), size, WindowArchetype::satellite, + Optional(WindowPositionerEq(positioner)), parent_view_id)) + .Times(1); + + SimulateWindowingMessage(&messenger, kCreateSatelliteMethod, + std::make_unique(arguments), + &result_handler); + + EXPECT_TRUE(success); +} + TEST_F(WindowingHandlerTest, HandleDestroyWindow) { TestBinaryMessenger messenger; WindowingHandler windowing_handler(&messenger, controller()); EncodableMap const arguments = { - {EncodableValue("viewId"), EncodableValue(1)}, + {EncodableValue(kViewIdKey), EncodableValue(1)}, }; bool success = false; From cf7e288622f268a3853a4116f4361cf203db1350 Mon Sep 17 00:00:00 2001 From: Harlen Batagelo Date: Mon, 6 Jan 2025 09:53:50 -0300 Subject: [PATCH 2/2] Remove redundant static keyword --- .../flutter_host_window_controller_unittests.cc | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/shell/platform/windows/flutter_host_window_controller_unittests.cc b/shell/platform/windows/flutter_host_window_controller_unittests.cc index 04f175894891a..fad1a560f7092 100644 --- a/shell/platform/windows/flutter_host_window_controller_unittests.cc +++ b/shell/platform/windows/flutter_host_window_controller_unittests.cc @@ -16,11 +16,11 @@ namespace testing { namespace { -static constexpr char kChannelName[] = "flutter/windowing"; -static constexpr char kOnWindowCreatedMethod[] = "onWindowCreated"; -static constexpr char kOnWindowDestroyedMethod[] = "onWindowDestroyed"; -static constexpr char kViewIdKey[] = "viewId"; -static constexpr char kParentViewIdKey[] = "parentViewId"; +constexpr char kChannelName[] = "flutter/windowing"; +constexpr char kOnWindowCreatedMethod[] = "onWindowCreated"; +constexpr char kOnWindowDestroyedMethod[] = "onWindowDestroyed"; +constexpr char kViewIdKey[] = "viewId"; +constexpr char kParentViewIdKey[] = "parentViewId"; // Process the next Win32 message if there is one. This can be used to // pump the Windows platform thread task runner.