8#include "gtest/gtest.h"
15class WindowManagerTest :
public WindowsTest {
17 WindowManagerTest() =
default;
18 virtual ~WindowManagerTest() =
default;
21 void SetUp()
override {
22 auto& context = GetContext();
23 FlutterWindowsEngineBuilder builder(context);
24 ::CoInitializeEx(
nullptr, COINIT_APARTMENTTHREADED);
26 engine_ = builder.Build();
29 engine_->SetRootIsolateCreateCallback(context.GetRootIsolateCallback());
30 ASSERT_TRUE(engine_->Run(
"testWindowController"));
32 bool signalled =
false;
33 context.AddNativeFunction(
39 engine_->task_runner()->ProcessTasks();
43 void TearDown()
override { engine_->Stop(); }
45 int64_t engine_id() {
return reinterpret_cast<int64_t
>(engine_.get()); }
47 RegularWindowCreationRequest* regular_creation_request() {
48 return ®ular_creation_request_;
52 std::unique_ptr<FlutterWindowsEngine> engine_;
53 std::optional<flutter::Isolate> isolate_;
54 RegularWindowCreationRequest regular_creation_request_{
57 .has_preferred_view_size =
true,
58 .preferred_view_width = 800,
59 .preferred_view_height = 600,
68TEST_F(WindowManagerTest, WindowingInitialize) {
71 static bool received_message =
false;
78 engine_id(), regular_creation_request());
82 EXPECT_TRUE(received_message);
85TEST_F(WindowManagerTest, CreateRegularWindow) {
90 engine_id(), regular_creation_request());
94TEST_F(WindowManagerTest, GetWindowHandle) {
99 engine_id(), regular_creation_request());
100 const HWND window_handle =
103 EXPECT_NE(window_handle,
nullptr);
106TEST_F(WindowManagerTest, GetWindowSize) {
111 engine_id(), regular_creation_request());
112 const HWND window_handle =
119 EXPECT_EQ(
size.width,
120 regular_creation_request()->preferred_size.preferred_view_width);
121 EXPECT_EQ(
size.height,
122 regular_creation_request()->preferred_size.preferred_view_height);
125TEST_F(WindowManagerTest, SetWindowSize) {
130 engine_id(), regular_creation_request());
131 const HWND window_handle =
138 .preferred_view_width = 640,
139 .preferred_view_height = 480,
146 EXPECT_EQ(actual_size.
width, 640);
147 EXPECT_EQ(actual_size.
height, 480);
150TEST_F(WindowManagerTest, CanConstrainByMinimiumSize) {
155 engine_id(), regular_creation_request());
156 const HWND window_handle =
160 .view_min_width = 900,
161 .view_min_height = 700,
162 .view_max_width = 10000,
163 .view_max_height = 10000};
169 EXPECT_EQ(actual_size.
width, 900);
170 EXPECT_EQ(actual_size.
height, 700);
173TEST_F(WindowManagerTest, CanConstrainByMaximumSize) {
178 engine_id(), regular_creation_request());
179 const HWND window_handle =
184 .view_min_height = 0,
185 .view_max_width = 500,
186 .view_max_height = 500};
192 EXPECT_EQ(actual_size.
width, 500);
193 EXPECT_EQ(actual_size.
height, 500);
196TEST_F(WindowManagerTest, CanFullscreenWindow) {
201 engine_id(), regular_creation_request());
202 const HWND window_handle =
209 int screen_width = GetSystemMetrics(SM_CXSCREEN);
210 int screen_height = GetSystemMetrics(SM_CYSCREEN);
213 EXPECT_EQ(actual_size.
width, screen_width);
214 EXPECT_EQ(actual_size.
height, screen_height);
219TEST_F(WindowManagerTest, CanUnfullscreenWindow) {
224 engine_id(), regular_creation_request());
225 const HWND window_handle =
232 request.fullscreen =
false;
237 EXPECT_EQ(actual_size.
width, 800);
238 EXPECT_EQ(actual_size.
height, 600);
243TEST_F(WindowManagerTest, CanSetWindowSizeWhileFullscreen) {
248 engine_id(), regular_creation_request());
249 const HWND window_handle =
259 .preferred_view_width = 500,
260 .preferred_view_height = 500,
265 request.fullscreen =
false;
270 EXPECT_EQ(actual_size.
width, 500);
271 EXPECT_EQ(actual_size.
height, 500);
274TEST_F(WindowManagerTest, CanSetWindowConstraintsWhileFullscreen) {
279 engine_id(), regular_creation_request());
280 const HWND window_handle =
289 .view_min_height = 0,
290 .view_max_width = 500,
291 .view_max_height = 500};
295 request.fullscreen =
false;
300 EXPECT_EQ(actual_size.
width, 500);
301 EXPECT_EQ(actual_size.
height, 500);
304TEST_F(WindowManagerTest, CreateModelessDialogWindow) {
308 .preferred_view_width = 800,
309 .preferred_view_height = 600},
310 .preferred_constraints = {.has_view_constraints =
false},
311 .title = L
"Hello World",
312 .parent_or_null =
nullptr};
315 engine_id(), &creation_request);
319TEST_F(WindowManagerTest, CreateModalDialogWindow) {
322 const int64_t parent_view_id =
324 engine_id(), regular_creation_request());
325 const HWND parent_window_handle =
327 engine_id(), parent_view_id);
333 .preferred_view_width = 800,
334 .preferred_view_height = 600,
336 .preferred_constraints = {.has_view_constraints =
false},
337 .title = L
"Hello World",
338 .parent_or_null = parent_window_handle};
342 engine_id(), &creation_request);
345 const HWND window_handle =
350 parent_window_handle);
353TEST_F(WindowManagerTest, DialogCanNeverBeFullscreen) {
358 .preferred_view_width = 800,
359 .preferred_view_height = 600},
360 .preferred_constraints = {.has_view_constraints =
false},
361 .title = L
"Hello World",
362 .parent_or_null =
nullptr};
366 engine_id(), &creation_request);
367 const HWND window_handle =
HWND GetWindowHandle() const
HostWindow * GetOwnerWindow() const
static HostWindow * GetThisFromHandle(HWND hwnd)
G_BEGIN_DECLS G_MODULE_EXPORT FlValue * args
G_BEGIN_DECLS GBytes * message
G_BEGIN_DECLS FlutterViewId view_id
#define FML_DISALLOW_COPY_AND_ASSIGN(TypeName)
TEST_F(DisplayListTest, Defaults)
it will be possible to load the file into Perfetto s trace viewer use test Running tests that layout and measure text will not yield consistent results across various platforms Enabling this option will make font resolution default to the Ahem test font on all disable asset Prevents usage of any non test fonts unless they were explicitly Loaded via prefetched default font Indicates whether the embedding started a prefetch of the default font manager before creating the engine run In non interactive keep the shell running after the Dart script has completed enable serial On low power devices with low core running concurrent GC tasks on threads can cause them to contend with the UI thread which could potentially lead to jank This option turns off all concurrent GC activities domain network JSON encoded network policy per domain This overrides the DisallowInsecureConnections switch Embedder can specify whether to allow or disallow insecure connections at a domain level old gen heap size
WindowSizeRequest preferred_size
bool has_view_constraints
bool has_preferred_view_size
void(* on_message)(WindowsMessage *)
#define CREATE_NATIVE_ENTRY(native_entry)
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)
HWND InternalFlutterWindows_WindowManager_GetTopLevelWindowHandle(int64_t engine_id, FlutterViewId view_id)