9 #include "flutter/shell/platform/windows/testing/egl/mock_context.h"
10 #include "flutter/shell/platform/windows/testing/egl/mock_manager.h"
11 #include "flutter/shell/platform/windows/testing/egl/mock_window_surface.h"
12 #include "flutter/shell/platform/windows/testing/engine_modifier.h"
13 #include "flutter/shell/platform/windows/testing/flutter_windows_engine_builder.h"
14 #include "flutter/shell/platform/windows/testing/windows_test.h"
16 #include "gmock/gmock.h"
17 #include "gtest/gtest.h"
24 using ::testing::NiceMock;
25 using ::testing::Return;
31 std::unique_ptr<egl::MockWindowSurface> CreateMockWindowSurface() {
32 auto surface = std::make_unique<NiceMock<egl::MockWindowSurface>>();
33 ON_CALL(*surface, IsValid).WillByDefault(Return(
true));
34 ON_CALL(*surface, MakeCurrent).WillByDefault(Return(
true));
35 ON_CALL(*surface, SetVSyncEnabled).WillByDefault(Return(
true));
36 ON_CALL(*surface, Destroy).WillByDefault(Return(
true));
40 class WindowManagerTest :
public WindowsTest {
42 WindowManagerTest() =
default;
43 virtual ~WindowManagerTest() =
default;
46 void SetUp()
override {
47 auto& context = GetContext();
48 FlutterWindowsEngineBuilder builder(context);
49 ::CoInitializeEx(
nullptr, COINIT_APARTMENTTHREADED);
51 engine_ = builder.Build();
54 engine_->SetRootIsolateCreateCallback(context.GetRootIsolateCallback());
55 ASSERT_TRUE(engine_->Run(
"testWindowController"));
57 bool signalled =
false;
58 context.AddFfiNativeFunction(
"Signal", CREATE_FFI_LAMBDA([&]() {
63 engine_->task_runner()->ProcessTasks();
73 auto egl_manager = std::make_unique<NiceMock<egl::MockManager>>();
74 ON_CALL(*egl_manager, CreateWindowSurface)
76 [](HWND,
size_t,
size_t) {
return CreateMockWindowSurface(); });
77 ON_CALL(*egl_manager, render_context)
78 .WillByDefault(Return(&mock_egl_context_));
79 ON_CALL(mock_egl_context_, ClearCurrent).WillByDefault(Return(
true));
80 ON_CALL(mock_egl_context_, MakeCurrent).WillByDefault(Return(
true));
81 EngineModifier{engine_.get()}.SetEGLManager(std::move(egl_manager));
84 void TearDown()
override { engine_->Stop(); }
86 int64_t engine_id() {
return reinterpret_cast<int64_t
>(engine_.get()); }
88 RegularWindowCreationRequest* regular_creation_request() {
89 return ®ular_creation_request_;
91 FlutterWindowsEngine* engine() {
return engine_.get(); }
95 HWND CreateParentWindow() {
98 engine_id(), regular_creation_request()));
103 static void OffsetPositionCallback(
const WindowSize& child_size,
104 const WindowRect& parent_rect,
105 const WindowRect& display_rect,
106 WindowRect& output_rect) {
107 output_rect.left = parent_rect.left + 20;
108 output_rect.top = parent_rect.top + 30;
109 output_rect.width = child_size.width;
110 output_rect.height = child_size.height;
115 static SatelliteWindowCreationRequest SatelliteCreationRequest(
118 return SatelliteWindowCreationRequest{
119 .preferred_size = {.has_preferred_view_size =
true,
120 .preferred_view_width = 200,
121 .preferred_view_height = 150},
122 .preferred_constraints = {.has_view_constraints =
true,
123 .view_min_width = 100,
124 .view_min_height = 50,
125 .view_max_width = 300,
126 .view_max_height = 200},
128 .get_position_callback = get_position_callback,
129 .title = L
"Satellite",
130 .sized_to_content =
false,
135 std::unique_ptr<FlutterWindowsEngine> engine_;
136 NiceMock<egl::MockContext> mock_egl_context_;
137 std::optional<flutter::Isolate> isolate_;
138 RegularWindowCreationRequest regular_creation_request_{
141 .has_preferred_view_size =
true,
142 .preferred_view_width = 800,
143 .preferred_view_height = 600,
147 FML_DISALLOW_COPY_AND_ASSIGN(WindowManagerTest);
152 TEST_F(WindowManagerTest, WindowingInitialize) {
155 static bool received_message =
false;
160 const int64_t view_id =
162 engine_id(), regular_creation_request());
164 engine_id(), view_id));
166 EXPECT_TRUE(received_message);
169 TEST_F(WindowManagerTest, CreateRegularWindow) {
172 const int64_t view_id =
174 engine_id(), regular_creation_request());
175 EXPECT_EQ(view_id, 1);
178 TEST_F(WindowManagerTest, GetWindowHandle) {
181 const int64_t view_id =
183 engine_id(), regular_creation_request());
184 const HWND window_handle =
187 EXPECT_NE(window_handle,
nullptr);
190 TEST_F(WindowManagerTest, GetWindowSize) {
193 const int64_t view_id =
195 engine_id(), regular_creation_request());
196 const HWND window_handle =
203 EXPECT_EQ(size.
width,
204 regular_creation_request()->preferred_size.preferred_view_width);
206 regular_creation_request()->preferred_size.preferred_view_height);
209 TEST_F(WindowManagerTest, SetWindowSize) {
212 const int64_t view_id =
214 engine_id(), regular_creation_request());
215 const HWND window_handle =
222 .preferred_view_width = 640,
223 .preferred_view_height = 480,
230 EXPECT_EQ(actual_size.
width, 640);
231 EXPECT_EQ(actual_size.
height, 480);
234 TEST_F(WindowManagerTest, CanConstrainByMinimiumSize) {
237 const int64_t view_id =
239 engine_id(), regular_creation_request());
240 const HWND window_handle =
244 .view_min_width = 900,
245 .view_min_height = 700,
246 .view_max_width = 10000,
247 .view_max_height = 10000};
253 EXPECT_EQ(actual_size.
width, 900);
254 EXPECT_EQ(actual_size.
height, 700);
257 TEST_F(WindowManagerTest, CanConstrainByMaximumSize) {
260 const int64_t view_id =
262 engine_id(), regular_creation_request());
263 const HWND window_handle =
268 .view_min_height = 0,
269 .view_max_width = 500,
270 .view_max_height = 500};
276 EXPECT_EQ(actual_size.
width, 500);
277 EXPECT_EQ(actual_size.
height, 500);
280 TEST_F(WindowManagerTest, CanFullscreenWindow) {
283 const int64_t view_id =
285 engine_id(), regular_creation_request());
286 const HWND window_handle =
293 int screen_width = GetSystemMetrics(SM_CXSCREEN);
294 int screen_height = GetSystemMetrics(SM_CYSCREEN);
297 EXPECT_EQ(actual_size.
width, screen_width);
298 EXPECT_EQ(actual_size.
height, screen_height);
303 TEST_F(WindowManagerTest, CanUnfullscreenWindow) {
306 const int64_t view_id =
308 engine_id(), regular_creation_request());
309 const HWND window_handle =
316 request.fullscreen =
false;
321 EXPECT_EQ(actual_size.
width, 800);
322 EXPECT_EQ(actual_size.
height, 600);
327 TEST_F(WindowManagerTest, CanSetWindowSizeWhileFullscreen) {
330 const int64_t view_id =
332 engine_id(), regular_creation_request());
333 const HWND window_handle =
343 .preferred_view_width = 500,
344 .preferred_view_height = 500,
349 request.fullscreen =
false;
354 EXPECT_EQ(actual_size.
width, 500);
355 EXPECT_EQ(actual_size.
height, 500);
358 TEST_F(WindowManagerTest, CanSetWindowConstraintsWhileFullscreen) {
361 const int64_t view_id =
363 engine_id(), regular_creation_request());
364 const HWND window_handle =
373 .view_min_height = 0,
374 .view_max_width = 500,
375 .view_max_height = 500};
379 request.fullscreen =
false;
384 EXPECT_EQ(actual_size.
width, 500);
385 EXPECT_EQ(actual_size.
height, 500);
388 TEST_F(WindowManagerTest, CreateModelessDialogWindow) {
392 .preferred_view_width = 800,
393 .preferred_view_height = 600},
394 .preferred_constraints = {.has_view_constraints =
false},
395 .title = L
"Hello World",
396 .parent_or_null =
nullptr};
397 const int64_t view_id =
399 engine_id(), &creation_request);
400 EXPECT_EQ(view_id, 1);
403 TEST_F(WindowManagerTest, CreateModalDialogWindow) {
406 const int64_t parent_view_id =
408 engine_id(), regular_creation_request());
409 const HWND parent_window_handle =
411 engine_id(), parent_view_id);
417 .preferred_view_width = 800,
418 .preferred_view_height = 600,
420 .preferred_constraints = {.has_view_constraints =
false},
421 .title = L
"Hello World",
422 .parent_or_null = parent_window_handle};
424 const int64_t view_id =
426 engine_id(), &creation_request);
427 EXPECT_EQ(view_id, 2);
429 const HWND window_handle =
434 parent_window_handle);
437 TEST_F(WindowManagerTest, DeactivatedRegularWindowDoesNotReactivateItself) {
443 const int64_t window_view_id =
445 engine_id(), regular_creation_request());
446 const HWND window_handle =
448 engine_id(), window_view_id);
450 const int64_t active_view_id =
452 engine_id(), regular_creation_request());
453 const HWND active_window_handle =
455 engine_id(), active_view_id);
457 SetActiveWindow(active_window_handle);
458 ASSERT_EQ(GetActiveWindow(), active_window_handle);
464 SendMessage(window_handle, WM_ACTIVATE, MAKEWPARAM(WA_INACTIVE, 0), 0);
466 EXPECT_EQ(GetActiveWindow(), active_window_handle);
469 TEST_F(WindowManagerTest, DialogCanNeverBeFullscreen) {
474 .preferred_view_width = 800,
475 .preferred_view_height = 600},
476 .preferred_constraints = {.has_view_constraints =
false},
477 .title = L
"Hello World",
478 .parent_or_null =
nullptr};
480 const int64_t view_id =
482 engine_id(), &creation_request);
483 const HWND window_handle =
493 TEST_F(WindowManagerTest, CreateTooltipWindow) {
496 const int64_t parent_view_id =
498 engine_id(), regular_creation_request());
499 const HWND parent_window_handle =
501 engine_id(), parent_view_id);
503 auto position_callback =
506 rect.left = parent_rect.left + 10;
507 rect.top = parent_rect.top + 10;
508 rect.width = child_size.
width;
509 rect.height = child_size.
height;
514 .view_min_width = 100,
515 .view_min_height = 50,
516 .view_max_width = 300,
517 .view_max_height = 200},
518 .parent = parent_window_handle,
519 .get_position_callback = position_callback};
521 const int64_t tooltip_view_id =
523 engine_id(), &creation_request);
525 EXPECT_NE(tooltip_view_id, -1);
526 HWND tooltip_window_handle =
528 engine_id(), tooltip_view_id);
529 EXPECT_NE(tooltip_window_handle,
nullptr);
532 TEST_F(WindowManagerTest, TooltipWindowHasNoActivateStyle) {
535 const int64_t parent_view_id =
537 engine_id(), regular_creation_request());
538 const HWND parent_window_handle =
540 engine_id(), parent_view_id);
542 auto position_callback =
545 rect.left = parent_rect.left + 10;
546 rect.top = parent_rect.top + 10;
547 rect.width = child_size.
width;
548 rect.height = child_size.
height;
553 .view_min_width = 100,
554 .view_min_height = 50,
555 .view_max_width = 300,
556 .view_max_height = 200},
557 .parent = parent_window_handle,
558 .get_position_callback = position_callback};
560 const int64_t tooltip_view_id =
562 engine_id(), &creation_request);
564 HWND tooltip_window_handle =
566 engine_id(), tooltip_view_id);
568 DWORD ex_style = GetWindowLong(tooltip_window_handle, GWL_EXSTYLE);
569 EXPECT_TRUE(ex_style & WS_EX_NOACTIVATE);
572 TEST_F(WindowManagerTest, TooltipWindowDoesNotStealFocus) {
575 const int64_t parent_view_id =
577 engine_id(), regular_creation_request());
578 const HWND parent_window_handle =
580 engine_id(), parent_view_id);
583 SetFocus(parent_window_handle);
584 HWND focused_before = GetFocus();
586 auto position_callback =
589 rect.left = parent_rect.left + 10;
590 rect.top = parent_rect.top + 10;
591 rect.width = child_size.
width;
592 rect.height = child_size.
height;
597 .view_min_width = 100,
598 .view_min_height = 50,
599 .view_max_width = 300,
600 .view_max_height = 200},
601 .parent = parent_window_handle,
602 .get_position_callback = position_callback};
604 const int64_t tooltip_view_id =
606 engine_id(), &creation_request);
608 HWND tooltip_window_handle =
610 engine_id(), tooltip_view_id);
613 HWND focused_after = GetFocus();
614 EXPECT_EQ(focused_before, focused_after);
615 EXPECT_NE(focused_after, tooltip_window_handle);
618 TEST_F(WindowManagerTest, TooltipWindowReturnsNoActivateOnMouseClick) {
621 const int64_t parent_view_id =
623 engine_id(), regular_creation_request());
624 const HWND parent_window_handle =
626 engine_id(), parent_view_id);
628 auto position_callback =
631 rect.left = parent_rect.left + 10;
632 rect.top = parent_rect.top + 10;
633 rect.width = child_size.
width;
634 rect.height = child_size.
height;
639 .view_min_width = 100,
640 .view_min_height = 50,
641 .view_max_width = 300,
642 .view_max_height = 200},
643 .parent = parent_window_handle,
644 .get_position_callback = position_callback};
646 const int64_t tooltip_view_id =
648 engine_id(), &creation_request);
650 HWND tooltip_window_handle =
652 engine_id(), tooltip_view_id);
655 LRESULT result = SendMessage(tooltip_window_handle, WM_MOUSEACTIVATE,
656 reinterpret_cast<WPARAM
>(parent_window_handle),
657 MAKELPARAM(HTCLIENT, WM_LBUTTONDOWN));
660 EXPECT_EQ(result, MA_NOACTIVATE);
666 DISABLED_TooltipWindowUpdatesPositionOnViewSizeChange) {
669 const int64_t parent_view_id =
671 engine_id(), regular_creation_request());
672 const HWND parent_window_handle =
674 engine_id(), parent_view_id);
677 static int callback_count = 0;
678 static int last_width = 0;
679 static int last_height = 0;
681 auto position_callback =
685 last_width = child_size.
width;
686 last_height = child_size.
height;
688 rect.left = parent_rect.left + callback_count * 5;
689 rect.top = parent_rect.top + callback_count * 5;
690 rect.width = child_size.
width;
691 rect.height = child_size.
height;
696 .view_min_width = 100,
697 .view_min_height = 50,
698 .view_max_width = 300,
699 .view_max_height = 200},
700 .parent = parent_window_handle,
701 .get_position_callback = position_callback};
708 const int64_t tooltip_view_id =
710 engine_id(), &creation_request);
712 HWND tooltip_window_handle =
714 engine_id(), tooltip_view_id);
718 engine()->GetViewFromTopLevelWindow(tooltip_window_handle);
719 ASSERT_NE(view,
nullptr);
723 GetWindowRect(tooltip_window_handle, &initial_rect);
724 int initial_callback_count = callback_count;
731 engine()->task_runner()->ProcessTasks();
734 EXPECT_GT(callback_count, initial_callback_count);
735 EXPECT_EQ(last_width, 150);
736 EXPECT_EQ(last_height, 100);
740 GetWindowRect(tooltip_window_handle, &new_rect);
744 EXPECT_NE(initial_rect.left, new_rect.left);
745 EXPECT_NE(initial_rect.top, new_rect.top);
748 TEST_F(WindowManagerTest, CreatePopupWindow) {
751 const int64_t parent_view_id =
753 engine_id(), regular_creation_request());
754 const HWND parent_window_handle =
756 engine_id(), parent_view_id);
758 auto position_callback =
761 rect.left = parent_rect.left + 10;
762 rect.top = parent_rect.top + 10;
763 rect.width = child_size.
width;
764 rect.height = child_size.
height;
769 .view_min_width = 100,
770 .view_min_height = 50,
771 .view_max_width = 300,
772 .view_max_height = 200},
773 .parent = parent_window_handle,
774 .get_position_callback = position_callback};
776 const int64_t popup_view_id =
780 EXPECT_NE(popup_view_id, -1);
781 HWND popup_window_handle =
783 engine_id(), popup_view_id);
784 EXPECT_NE(popup_window_handle,
nullptr);
787 TEST_F(WindowManagerTest, PopupWindowHasNoActivateStyle) {
790 const int64_t parent_view_id =
792 engine_id(), regular_creation_request());
793 const HWND parent_window_handle =
795 engine_id(), parent_view_id);
797 auto position_callback =
800 rect.left = parent_rect.left + 10;
801 rect.top = parent_rect.top + 10;
802 rect.width = child_size.
width;
803 rect.height = child_size.
height;
808 .view_min_width = 100,
809 .view_min_height = 50,
810 .view_max_width = 300,
811 .view_max_height = 200},
812 .parent = parent_window_handle,
813 .get_position_callback = position_callback};
815 const int64_t popup_view_id =
819 HWND popup_window_handle =
821 engine_id(), popup_view_id);
823 DWORD ex_style = GetWindowLong(popup_window_handle, GWL_EXSTYLE);
824 EXPECT_TRUE(ex_style & WS_EX_NOACTIVATE);
827 TEST_F(WindowManagerTest, PopupWindowDoesNotStealFocus) {
830 const int64_t parent_view_id =
832 engine_id(), regular_creation_request());
833 const HWND parent_window_handle =
835 engine_id(), parent_view_id);
838 SetFocus(parent_window_handle);
839 HWND focused_before = GetFocus();
841 auto position_callback =
844 rect.left = parent_rect.left + 10;
845 rect.top = parent_rect.top + 10;
846 rect.width = child_size.
width;
847 rect.height = child_size.
height;
852 .view_min_width = 100,
853 .view_min_height = 50,
854 .view_max_width = 300,
855 .view_max_height = 200},
856 .parent = parent_window_handle,
857 .get_position_callback = position_callback};
859 const int64_t popup_view_id =
863 HWND popup_window_handle =
865 engine_id(), popup_view_id);
868 HWND focused_after = GetFocus();
869 EXPECT_EQ(focused_before, focused_after);
870 EXPECT_NE(focused_after, popup_window_handle);
875 TEST_F(WindowManagerTest, DISABLED_PopupWindowUpdatesPositionOnViewSizeChange) {
878 const int64_t parent_view_id =
880 engine_id(), regular_creation_request());
881 const HWND parent_window_handle =
883 engine_id(), parent_view_id);
886 static int callback_count = 0;
887 static int last_width = 0;
888 static int last_height = 0;
890 auto position_callback =
894 last_width = child_size.
width;
895 last_height = child_size.
height;
897 rect.left = parent_rect.left + callback_count * 5;
898 rect.top = parent_rect.top + callback_count * 5;
899 rect.width = child_size.
width;
900 rect.height = child_size.
height;
905 .view_min_width = 100,
906 .view_min_height = 50,
907 .view_max_width = 300,
908 .view_max_height = 200},
909 .parent = parent_window_handle,
910 .get_position_callback = position_callback};
917 const int64_t popup_view_id =
921 HWND popup_window_handle =
923 engine_id(), popup_view_id);
927 engine()->GetViewFromTopLevelWindow(popup_window_handle);
928 ASSERT_NE(view,
nullptr);
932 GetWindowRect(popup_window_handle, &initial_rect);
933 int initial_callback_count = callback_count;
940 engine()->task_runner()->ProcessTasks();
943 EXPECT_GT(callback_count, initial_callback_count);
944 EXPECT_EQ(last_width, 150);
945 EXPECT_EQ(last_height, 100);
949 GetWindowRect(popup_window_handle, &new_rect);
953 EXPECT_NE(initial_rect.left, new_rect.left);
954 EXPECT_NE(initial_rect.top, new_rect.top);
957 TEST_F(WindowManagerTest, CreateRegularWindowSizedToContent) {
962 .preferred_constraints = {.has_view_constraints =
false},
963 .title = L
"Sized To Content",
964 .sized_to_content =
true,
967 const int64_t view_id =
969 engine_id(), &creation_request);
970 EXPECT_GE(view_id, 1);
976 DISABLED_RegularWindowSizedToContentResizesToContent) {
981 .preferred_constraints = {.has_view_constraints =
false},
982 .title = L
"Sized To Content",
983 .sized_to_content =
true,
986 const int64_t view_id =
988 engine_id(), &creation_request);
989 const HWND window_handle =
994 ASSERT_NE(view,
nullptr);
997 engine()->task_runner()->ProcessTasks();
1001 EXPECT_EQ(size.
width, 300);
1002 EXPECT_EQ(size.
height, 200);
1006 RegularWindowSizedToContentNonResizableHasNoThickFrame) {
1011 .preferred_constraints = {.has_view_constraints =
false},
1012 .title = L
"Sized To Content Non-Resizable",
1013 .sized_to_content =
true,
1014 .resizable =
false};
1016 const int64_t view_id =
1018 engine_id(), &creation_request);
1019 const HWND window_handle =
1023 const LONG style = GetWindowLong(window_handle, GWL_STYLE);
1024 EXPECT_EQ(style & WS_THICKFRAME, 0L);
1025 EXPECT_EQ(style & WS_MAXIMIZEBOX, 0L);
1028 TEST_F(WindowManagerTest, RegularWindowSizedToContentResizableHasThickFrame) {
1033 .preferred_constraints = {.has_view_constraints =
false},
1034 .title = L
"Sized To Content Resizable",
1035 .sized_to_content =
true,
1038 const int64_t view_id =
1040 engine_id(), &creation_request);
1041 const HWND window_handle =
1045 const LONG style = GetWindowLong(window_handle, GWL_STYLE);
1046 EXPECT_NE(style & WS_THICKFRAME, 0L);
1047 EXPECT_NE(style & WS_MAXIMIZEBOX, 0L);
1054 DISABLED_RegularWindowSizedToContentResizableStopsTrackingAfterFirstFrame) {
1059 .preferred_constraints = {.has_view_constraints =
false},
1060 .title = L
"Sized To Content Resizable",
1061 .sized_to_content =
true,
1064 const int64_t view_id =
1066 engine_id(), &creation_request);
1067 const HWND window_handle =
1072 ASSERT_NE(view,
nullptr);
1075 engine()->task_runner()->ProcessTasks();
1080 TEST_F(WindowManagerTest, CreateModelessDialogSizedToContent) {
1085 .preferred_constraints = {.has_view_constraints =
false},
1086 .title = L
"Modeless Dialog Sized To Content",
1087 .parent_or_null =
nullptr,
1088 .sized_to_content =
true,
1089 .resizable =
false};
1091 const int64_t view_id =
1093 engine_id(), &creation_request);
1094 EXPECT_GE(view_id, 0);
1097 TEST_F(WindowManagerTest, CreateModalDialogSizedToContent) {
1100 const int64_t parent_view_id =
1102 engine_id(), regular_creation_request());
1103 const HWND parent_window_handle =
1105 engine_id(), parent_view_id);
1109 .preferred_constraints = {.has_view_constraints =
false},
1110 .title = L
"Modal Dialog Sized To Content",
1111 .parent_or_null = parent_window_handle,
1112 .sized_to_content =
true,
1113 .resizable =
false};
1115 const int64_t view_id =
1117 engine_id(), &creation_request);
1118 EXPECT_GE(view_id, 0);
1123 TEST_F(WindowManagerTest, DISABLED_DialogWindowSizedToContentResizesToContent) {
1128 .preferred_constraints = {.has_view_constraints =
false},
1129 .title = L
"Dialog Sized To Content",
1130 .parent_or_null =
nullptr,
1131 .sized_to_content =
true,
1132 .resizable =
false};
1134 const int64_t view_id =
1136 engine_id(), &creation_request);
1137 const HWND window_handle =
1142 ASSERT_NE(view,
nullptr);
1145 engine()->task_runner()->ProcessTasks();
1149 EXPECT_EQ(size.
width, 300);
1150 EXPECT_EQ(size.
height, 200);
1154 DialogWindowSizedToContentNonResizableHasNoThickFrame) {
1159 .preferred_constraints = {.has_view_constraints =
false},
1160 .title = L
"Dialog Sized To Content Non-Resizable",
1161 .parent_or_null =
nullptr,
1162 .sized_to_content =
true,
1163 .resizable =
false};
1165 const int64_t view_id =
1167 engine_id(), &creation_request);
1168 const HWND window_handle =
1172 const LONG style = GetWindowLong(window_handle, GWL_STYLE);
1173 EXPECT_EQ(style & WS_THICKFRAME, 0L);
1177 OnPreEngineRestartDestroysWindowsWithoutDispatchingMessages) {
1180 static bool received_message =
false;
1185 const int64_t first_view_id =
1187 engine_id(), regular_creation_request());
1188 const HWND first_window_handle =
1190 engine_id(), first_view_id);
1191 const int64_t second_view_id =
1193 engine_id(), regular_creation_request());
1194 const HWND second_window_handle =
1196 engine_id(), second_view_id);
1198 received_message =
false;
1199 EngineModifier{engine()}.Restart();
1201 EXPECT_FALSE(received_message);
1202 EXPECT_FALSE(IsWindow(first_window_handle));
1203 EXPECT_FALSE(IsWindow(second_window_handle));
1211 TEST_F(WindowManagerTest, OnEngineShutdownDispatchesWmDestroyForPopupWindow) {
1214 static std::vector<UINT> received_messages;
1215 received_messages.clear();
1217 received_messages.push_back(
message->message);
1221 const int64_t parent_view_id =
1223 engine_id(), regular_creation_request());
1224 const HWND parent_window_handle =
1226 engine_id(), parent_view_id);
1228 auto position_callback =
1231 rect.left = parent_rect.left + 10;
1232 rect.top = parent_rect.top + 10;
1233 rect.width = child_size.
width;
1234 rect.height = child_size.
height;
1239 .view_min_width = 100,
1240 .view_min_height = 50,
1241 .view_max_width = 300,
1242 .view_max_height = 200},
1243 .parent = parent_window_handle,
1244 .get_position_callback = position_callback};
1249 received_messages.clear();
1250 engine()->window_manager()->OnEngineShutdown();
1252 EXPECT_NE(std::find(received_messages.begin(), received_messages.end(),
1253 static_cast<UINT
>(WM_DESTROY)),
1254 received_messages.end());
1258 TEST_F(WindowManagerTest, OnEngineShutdownDispatchesWmDestroyForTooltipWindow) {
1261 static std::vector<UINT> received_messages;
1262 received_messages.clear();
1264 received_messages.push_back(
message->message);
1268 const int64_t parent_view_id =
1270 engine_id(), regular_creation_request());
1271 const HWND parent_window_handle =
1273 engine_id(), parent_view_id);
1275 auto position_callback =
1278 rect.left = parent_rect.left + 10;
1279 rect.top = parent_rect.top + 10;
1280 rect.width = child_size.
width;
1281 rect.height = child_size.
height;
1286 .view_min_width = 100,
1287 .view_min_height = 50,
1288 .view_max_width = 300,
1289 .view_max_height = 200},
1290 .parent = parent_window_handle,
1291 .get_position_callback = position_callback};
1296 received_messages.clear();
1297 engine()->window_manager()->OnEngineShutdown();
1299 EXPECT_NE(std::find(received_messages.begin(), received_messages.end(),
1300 static_cast<UINT
>(WM_DESTROY)),
1301 received_messages.end());
1304 TEST_F(WindowManagerTest, CreateSatelliteWindow) {
1307 const HWND parent_window_handle = CreateParentWindow();
1309 SatelliteCreationRequest(parent_window_handle, OffsetPositionCallback);
1311 const int64_t satellite_view_id =
1313 engine_id(), &creation_request);
1315 EXPECT_GE(satellite_view_id, 0);
1316 const HWND satellite_window_handle =
1318 engine_id(), satellite_view_id);
1319 EXPECT_NE(satellite_window_handle,
nullptr);
1322 TEST_F(WindowManagerTest, SatelliteWindowUsesPositionCallbackAfterFirstFrame) {
1325 const HWND parent_window_handle = CreateParentWindow();
1326 SetWindowPos(parent_window_handle,
nullptr, 200, 100, 0, 0,
1327 SWP_NOSIZE | SWP_NOZORDER);
1330 SatelliteCreationRequest(parent_window_handle, OffsetPositionCallback);
1332 const int64_t satellite_view_id =
1334 engine_id(), &creation_request);
1335 const HWND satellite_window_handle =
1337 engine_id(), satellite_view_id);
1340 engine()->GetViewFromTopLevelWindow(satellite_window_handle);
1341 ASSERT_NE(view,
nullptr);
1346 engine()->task_runner()->ProcessTasks();
1350 RECT parent_client_rect;
1351 GetClientRect(parent_window_handle, &parent_client_rect);
1352 POINT parent_top_left = {parent_client_rect.left, parent_client_rect.top};
1353 ClientToScreen(parent_window_handle, &parent_top_left);
1356 RECT satellite_rect;
1357 GetWindowRect(satellite_window_handle, &satellite_rect);
1359 EXPECT_EQ(satellite_rect.left, parent_top_left.x + 20);
1360 EXPECT_EQ(satellite_rect.top, parent_top_left.y + 30);
1363 TEST_F(WindowManagerTest, SatelliteWindowIsHiddenUntilFirstFrame) {
1366 const HWND parent_window_handle = CreateParentWindow();
1368 SatelliteCreationRequest(parent_window_handle, OffsetPositionCallback);
1370 const HWND satellite_window_handle =
1374 engine_id(), &creation_request));
1375 ASSERT_NE(satellite_window_handle,
nullptr);
1379 EXPECT_FALSE(IsWindowVisible(satellite_window_handle));
1382 engine()->GetViewFromTopLevelWindow(satellite_window_handle);
1383 ASSERT_NE(view,
nullptr);
1385 engine()->task_runner()->ProcessTasks();
1387 EXPECT_TRUE(IsWindowVisible(satellite_window_handle));
1390 TEST_F(WindowManagerTest, SatelliteWindowHandlesNullPositionCallback) {
1393 const HWND parent_window_handle = CreateParentWindow();
1395 SatelliteCreationRequest(parent_window_handle,
nullptr);
1397 const int64_t satellite_view_id =
1399 engine_id(), &creation_request);
1401 EXPECT_GE(satellite_view_id, 0);
1403 engine_id(), satellite_view_id),
1407 TEST_F(WindowManagerTest, SatelliteWindowFollowsParentMovement) {
1414 const HWND parent_window_handle = CreateParentWindow();
1415 SetWindowPos(parent_window_handle,
nullptr, 200, 100, 0, 0,
1416 SWP_NOSIZE | SWP_NOZORDER);
1419 SatelliteCreationRequest(parent_window_handle, OffsetPositionCallback);
1420 const HWND satellite_window_handle =
1424 engine_id(), &creation_request));
1426 RECT satellite_rect_before;
1427 GetWindowRect(satellite_window_handle, &satellite_rect_before);
1432 SetWindowPos(parent_window_handle,
nullptr, 250, 200, 0, 0,
1433 SWP_NOSIZE | SWP_NOZORDER);
1435 RECT satellite_rect_after;
1436 GetWindowRect(satellite_window_handle, &satellite_rect_after);
1438 EXPECT_EQ(satellite_rect_after.left, satellite_rect_before.left + 50);
1439 EXPECT_EQ(satellite_rect_after.top, satellite_rect_before.top + 100);
1442 TEST_F(WindowManagerTest, SatelliteWindowDoesNotMoveWhenParentOnlyResizes) {
1449 const HWND parent_window_handle = CreateParentWindow();
1450 SetWindowPos(parent_window_handle,
nullptr, 200, 100, 0, 0,
1451 SWP_NOSIZE | SWP_NOZORDER);
1454 SatelliteCreationRequest(parent_window_handle, OffsetPositionCallback);
1455 const HWND satellite_window_handle =
1459 engine_id(), &creation_request));
1461 RECT satellite_rect_before;
1462 GetWindowRect(satellite_window_handle, &satellite_rect_before);
1464 SetWindowPos(parent_window_handle,
nullptr, 0, 0, 640, 480,
1465 SWP_NOMOVE | SWP_NOZORDER);
1467 RECT satellite_rect_after;
1468 GetWindowRect(satellite_window_handle, &satellite_rect_after);
1470 EXPECT_EQ(satellite_rect_after.left, satellite_rect_before.left);
1471 EXPECT_EQ(satellite_rect_after.top, satellite_rect_before.top);
1474 TEST_F(WindowManagerTest, SatelliteWindowKeepsOffsetAfterBeingMoved) {
1481 const HWND parent_window_handle = CreateParentWindow();
1482 SetWindowPos(parent_window_handle,
nullptr, 200, 100, 0, 0,
1483 SWP_NOSIZE | SWP_NOZORDER);
1486 SatelliteCreationRequest(parent_window_handle, OffsetPositionCallback);
1487 const HWND satellite_window_handle =
1491 engine_id(), &creation_request));
1494 RECT satellite_rect;
1495 GetWindowRect(satellite_window_handle, &satellite_rect);
1496 SetWindowPos(satellite_window_handle,
nullptr, satellite_rect.left + 40,
1497 satellite_rect.top + 60, 0, 0, SWP_NOSIZE | SWP_NOZORDER);
1499 RECT satellite_rect_before;
1500 GetWindowRect(satellite_window_handle, &satellite_rect_before);
1501 ASSERT_EQ(satellite_rect_before.left, satellite_rect.left + 40);
1502 ASSERT_EQ(satellite_rect_before.top, satellite_rect.top + 60);
1505 SetWindowPos(parent_window_handle,
nullptr, 250, 200, 0, 0,
1506 SWP_NOSIZE | SWP_NOZORDER);
1508 RECT satellite_rect_after;
1509 GetWindowRect(satellite_window_handle, &satellite_rect_after);
1510 EXPECT_EQ(satellite_rect_after.left, satellite_rect_before.left + 50);
1511 EXPECT_EQ(satellite_rect_after.top, satellite_rect_before.top + 100);
1514 TEST_F(WindowManagerTest, SatelliteWindowFollowsParentClientArea) {
1521 const HWND parent_window_handle = CreateParentWindow();
1522 SetWindowPos(parent_window_handle,
nullptr, 200, 100, 0, 0,
1523 SWP_NOSIZE | SWP_NOZORDER);
1526 SatelliteCreationRequest(parent_window_handle, OffsetPositionCallback);
1527 const HWND satellite_window_handle =
1531 engine_id(), &creation_request));
1533 POINT parent_client_origin_before = {0, 0};
1534 ClientToScreen(parent_window_handle, &parent_client_origin_before);
1535 RECT satellite_rect_before;
1536 GetWindowRect(satellite_window_handle, &satellite_rect_before);
1541 parent_window_handle, GWL_STYLE,
1542 GetWindowLongPtr(parent_window_handle, GWL_STYLE) & ~WS_CAPTION);
1543 SetWindowPos(parent_window_handle,
nullptr, 0, 0, 0, 0,
1544 SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE |
1547 POINT parent_client_origin_after = {0, 0};
1548 ClientToScreen(parent_window_handle, &parent_client_origin_after);
1549 ASSERT_NE(parent_client_origin_after.y, parent_client_origin_before.y);
1551 RECT satellite_rect_after;
1552 GetWindowRect(satellite_window_handle, &satellite_rect_after);
1553 EXPECT_EQ(satellite_rect_after.left,
1554 satellite_rect_before.left +
1555 (parent_client_origin_after.x - parent_client_origin_before.x));
1556 EXPECT_EQ(satellite_rect_after.top,
1557 satellite_rect_before.top +
1558 (parent_client_origin_after.y - parent_client_origin_before.y));
1561 TEST_F(WindowManagerTest, SatelliteWindowCannotBeMinimized) {
1564 const HWND parent_window_handle = CreateParentWindow();
1566 SatelliteCreationRequest(parent_window_handle, OffsetPositionCallback);
1568 const HWND satellite_window_handle =
1572 engine_id(), &creation_request));
1574 SendMessage(satellite_window_handle, WM_SYSCOMMAND, SC_MINIMIZE, 0);
1576 EXPECT_FALSE(IsIconic(satellite_window_handle));
1579 TEST_F(WindowManagerTest, SatelliteWindowCanReparent) {
1586 const HWND parent1_handle = CreateParentWindow();
1587 SetWindowPos(parent1_handle,
nullptr, 100, 100, 0, 0,
1588 SWP_NOSIZE | SWP_NOZORDER);
1589 const HWND parent2_handle = CreateParentWindow();
1590 SetWindowPos(parent2_handle,
nullptr, 500, 500, 0, 0,
1591 SWP_NOSIZE | SWP_NOZORDER);
1594 SatelliteCreationRequest(parent1_handle, OffsetPositionCallback);
1595 const HWND satellite_handle =
1599 engine_id(), &creation_request));
1601 RECT satellite_rect_before;
1602 GetWindowRect(satellite_handle, &satellite_rect_before);
1608 RECT satellite_rect_after;
1609 GetWindowRect(satellite_handle, &satellite_rect_after);
1610 EXPECT_EQ(satellite_rect_after.left, satellite_rect_before.left);
1611 EXPECT_EQ(satellite_rect_after.top, satellite_rect_before.top);
1615 GetWindowRect(parent2_handle, &parent2_rect);
1616 SetWindowPos(parent2_handle,
nullptr, parent2_rect.left + 30,
1617 parent2_rect.top + 40, 0, 0, SWP_NOSIZE | SWP_NOZORDER);
1619 RECT satellite_rect_moved;
1620 GetWindowRect(satellite_handle, &satellite_rect_moved);
1621 EXPECT_EQ(satellite_rect_moved.left, satellite_rect_after.left + 30);
1622 EXPECT_EQ(satellite_rect_moved.top, satellite_rect_after.top + 40);
1626 GetWindowRect(parent1_handle, &parent1_rect);
1627 SetWindowPos(parent1_handle,
nullptr, parent1_rect.left + 70,
1628 parent1_rect.top + 80, 0, 0, SWP_NOSIZE | SWP_NOZORDER);
1630 RECT satellite_rect_final;
1631 GetWindowRect(satellite_handle, &satellite_rect_final);
1632 EXPECT_EQ(satellite_rect_final.left, satellite_rect_moved.left);
1633 EXPECT_EQ(satellite_rect_final.top, satellite_rect_moved.top);
1636 TEST_F(WindowManagerTest, CreateSatelliteWindowSizedToContent) {
1639 const HWND parent_window_handle = CreateParentWindow();
1640 SetWindowPos(parent_window_handle,
nullptr, 200, 100, 0, 0,
1641 SWP_NOSIZE | SWP_NOZORDER);
1644 SatelliteCreationRequest(parent_window_handle, OffsetPositionCallback);
1648 const int64_t satellite_view_id =
1650 engine_id(), &creation_request);
1651 ASSERT_GE(satellite_view_id, 0);
1652 const HWND satellite_window_handle =
1654 engine_id(), satellite_view_id);
1655 ASSERT_NE(satellite_window_handle,
nullptr);
1658 engine()->GetViewFromTopLevelWindow(satellite_window_handle);
1659 ASSERT_NE(view,
nullptr);
1664 SatelliteWindowSizedToContentUsesPositionCallbackAfterFirstFrame) {
1667 const HWND parent_window_handle = CreateParentWindow();
1668 SetWindowPos(parent_window_handle,
nullptr, 200, 100, 0, 0,
1669 SWP_NOSIZE | SWP_NOZORDER);
1672 SatelliteCreationRequest(parent_window_handle, OffsetPositionCallback);
1676 const HWND satellite_window_handle =
1680 engine_id(), &creation_request));
1681 ASSERT_NE(satellite_window_handle,
nullptr);
1684 engine()->GetViewFromTopLevelWindow(satellite_window_handle);
1685 ASSERT_NE(view,
nullptr);
1690 engine()->task_runner()->ProcessTasks();
1692 RECT parent_client_rect;
1693 GetClientRect(parent_window_handle, &parent_client_rect);
1694 POINT parent_top_left = {parent_client_rect.left, parent_client_rect.top};
1695 ClientToScreen(parent_window_handle, &parent_top_left);
1699 RECT satellite_rect;
1700 GetWindowRect(satellite_window_handle, &satellite_rect);
1701 EXPECT_EQ(satellite_rect.left, parent_top_left.x + 20);
1702 EXPECT_EQ(satellite_rect.top, parent_top_left.y + 30);
1705 TEST_F(WindowManagerTest, SatelliteWindowCannotBeReparentedToItself) {
1712 const HWND parent_window_handle = CreateParentWindow();
1714 SatelliteCreationRequest(parent_window_handle, OffsetPositionCallback);
1715 const HWND satellite_handle =
1719 engine_id(), &creation_request));
1727 GetWindowRect(parent_window_handle, &parent_rect);
1728 RECT satellite_rect_before;
1729 GetWindowRect(satellite_handle, &satellite_rect_before);
1732 SetWindowPos(parent_window_handle,
nullptr, parent_rect.left + 15,
1733 parent_rect.top + 25, 0, 0, SWP_NOSIZE | SWP_NOZORDER);
1735 RECT satellite_rect_after;
1736 GetWindowRect(satellite_handle, &satellite_rect_after);
1737 EXPECT_EQ(satellite_rect_after.left, satellite_rect_before.left + 15);
1738 EXPECT_EQ(satellite_rect_after.top, satellite_rect_before.top + 25);
1741 TEST_F(WindowManagerTest, SatelliteWindowCannotBeReparentedToItsOwnSatellite) {
1748 const HWND parent_window_handle = CreateParentWindow();
1750 SatelliteCreationRequest(parent_window_handle, OffsetPositionCallback);
1751 const HWND outer_handle =
1755 engine_id(), &outer_request));
1758 SatelliteCreationRequest(outer_handle, OffsetPositionCallback);
1759 const HWND inner_handle =
1763 engine_id(), &inner_request));
1771 GetWindowRect(parent_window_handle, &parent_rect);
1772 RECT outer_rect_before;
1773 GetWindowRect(outer_handle, &outer_rect_before);
1774 RECT inner_rect_before;
1775 GetWindowRect(inner_handle, &inner_rect_before);
1778 SetWindowPos(parent_window_handle,
nullptr, parent_rect.left + 10,
1779 parent_rect.top + 20, 0, 0, SWP_NOSIZE | SWP_NOZORDER);
1781 RECT outer_rect_after;
1782 GetWindowRect(outer_handle, &outer_rect_after);
1783 RECT inner_rect_after;
1784 GetWindowRect(inner_handle, &inner_rect_after);
1785 EXPECT_EQ(outer_rect_after.left, outer_rect_before.left + 10);
1786 EXPECT_EQ(outer_rect_after.top, outer_rect_before.top + 20);
1787 EXPECT_EQ(inner_rect_after.left, inner_rect_before.left + 10);
1788 EXPECT_EQ(inner_rect_after.top, inner_rect_before.top + 20);
1791 TEST_F(WindowManagerTest, OnEngineShutdownDispatchesWmDestroyForSatellite) {
1794 static std::vector<UINT> received_messages;
1795 received_messages.clear();
1797 received_messages.push_back(
message->message);
1801 const HWND parent_window_handle = CreateParentWindow();
1803 SatelliteCreationRequest(parent_window_handle, OffsetPositionCallback);
1807 received_messages.clear();
1808 engine()->window_manager()->OnEngineShutdown();
1810 EXPECT_NE(std::find(received_messages.begin(), received_messages.end(),
1811 static_cast<UINT
>(WM_DESTROY)),
1812 received_messages.end());
virtual void OnFramePresented()
bool IsSizedToContent() const
bool OnFrameGenerated(size_t width, size_t height)
HWND GetWindowHandle() const
HostWindow * GetOwnerWindow() const
static HostWindow * GetThisFromHandle(HWND hwnd)
TEST_F(AccessibilityPluginTest, DirectAnnounceCall)
void(* GetWindowPositionCallback)(const WindowSize &child_size, const WindowRect &parent_rect, const WindowRect &display_rect, WindowRect &output_rect)
WindowSizeRequest preferred_size
WindowSizeRequest preferred_size
WindowSizeRequest preferred_size
bool has_view_constraints
bool has_preferred_view_size
void(* on_message)(WindowsMessage *)
void InternalFlutterWindows_WindowManager_Initialize(int64_t engine_id, const flutter::WindowingInitRequest *request)
void InternalFlutterWindows_WindowManager_SetWindowConstraints(HWND hwnd, const flutter::WindowConstraints *constraints)
bool InternalFlutterWindows_WindowManager_GetFullscreen(HWND hwnd)
void InternalFlutterWindows_WindowManager_SetWindowSize(HWND hwnd, const flutter::WindowSizeRequest *size)
FlutterViewId InternalFlutterWindows_WindowManager_CreateRegularWindow(int64_t engine_id, const flutter::RegularWindowCreationRequest *request)
FLUTTER_EXPORT FlutterViewId InternalFlutterWindows_WindowManager_CreateDialogWindow(int64_t engine_id, const flutter::DialogWindowCreationRequest *request)
void InternalFlutterWindows_WindowManager_SetFullscreen(HWND hwnd, const flutter::FullscreenRequest *request)
flutter::ActualWindowSize InternalFlutterWindows_WindowManager_GetWindowContentSize(HWND hwnd)
FLUTTER_EXPORT FlutterViewId InternalFlutterWindows_WindowManager_CreateSatelliteWindow(int64_t engine_id, const flutter::SatelliteWindowCreationRequest *request)
FLUTTER_EXPORT void InternalFlutterWindows_WindowManager_SetSatelliteParent(HWND satellite_hwnd, HWND new_parent)
FLUTTER_EXPORT FlutterViewId InternalFlutterWindows_WindowManager_CreateTooltipWindow(int64_t engine_id, const flutter::TooltipWindowCreationRequest *request)
FLUTTER_EXPORT FlutterViewId InternalFlutterWindows_WindowManager_CreatePopupWindow(int64_t engine_id, const flutter::PopupWindowCreationRequest *request)
HWND InternalFlutterWindows_WindowManager_GetTopLevelWindowHandle(int64_t engine_id, FlutterViewId view_id)