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, HasTopLevelWindows) {
88 bool has_top_level_windows =
90 EXPECT_FALSE(has_top_level_windows);
93 engine_id(), regular_creation_request());
94 has_top_level_windows =
96 EXPECT_TRUE(has_top_level_windows);
99TEST_F(WindowManagerTest, CreateRegularWindow) {
104 engine_id(), regular_creation_request());
108TEST_F(WindowManagerTest, GetWindowHandle) {
113 engine_id(), regular_creation_request());
114 const HWND window_handle =
117 EXPECT_NE(window_handle,
nullptr);
120TEST_F(WindowManagerTest, GetWindowSize) {
125 engine_id(), regular_creation_request());
126 const HWND window_handle =
133 EXPECT_EQ(
size.width,
134 regular_creation_request()->preferred_size.preferred_view_width);
135 EXPECT_EQ(
size.height,
136 regular_creation_request()->preferred_size.preferred_view_height);
139TEST_F(WindowManagerTest, SetWindowSize) {
144 engine_id(), regular_creation_request());
145 const HWND window_handle =
152 .preferred_view_width = 640,
153 .preferred_view_height = 480,
160 EXPECT_EQ(actual_size.
width, 640);
161 EXPECT_EQ(actual_size.
height, 480);
164TEST_F(WindowManagerTest, CanConstrainByMinimiumSize) {
169 engine_id(), regular_creation_request());
170 const HWND window_handle =
174 .view_min_width = 900,
175 .view_min_height = 700,
176 .view_max_width = 10000,
177 .view_max_height = 10000};
183 EXPECT_EQ(actual_size.
width, 900);
184 EXPECT_EQ(actual_size.
height, 700);
187TEST_F(WindowManagerTest, CanConstrainByMaximumSize) {
192 engine_id(), regular_creation_request());
193 const HWND window_handle =
198 .view_min_height = 0,
199 .view_max_width = 500,
200 .view_max_height = 500};
206 EXPECT_EQ(actual_size.
width, 500);
207 EXPECT_EQ(actual_size.
height, 500);
210TEST_F(WindowManagerTest, CanFullscreenWindow) {
215 engine_id(), regular_creation_request());
216 const HWND window_handle =
223 int screen_width = GetSystemMetrics(SM_CXSCREEN);
224 int screen_height = GetSystemMetrics(SM_CYSCREEN);
227 EXPECT_EQ(actual_size.
width, screen_width);
228 EXPECT_EQ(actual_size.
height, screen_height);
233TEST_F(WindowManagerTest, CanUnfullscreenWindow) {
238 engine_id(), regular_creation_request());
239 const HWND window_handle =
246 request.fullscreen =
false;
251 EXPECT_EQ(actual_size.
width, 800);
252 EXPECT_EQ(actual_size.
height, 600);
257TEST_F(WindowManagerTest, CanSetWindowSizeWhileFullscreen) {
262 engine_id(), regular_creation_request());
263 const HWND window_handle =
273 .preferred_view_width = 500,
274 .preferred_view_height = 500,
279 request.fullscreen =
false;
284 EXPECT_EQ(actual_size.
width, 500);
285 EXPECT_EQ(actual_size.
height, 500);
288TEST_F(WindowManagerTest, CanSetWindowConstraintsWhileFullscreen) {
293 engine_id(), regular_creation_request());
294 const HWND window_handle =
303 .view_min_height = 0,
304 .view_max_width = 500,
305 .view_max_height = 500};
309 request.fullscreen =
false;
314 EXPECT_EQ(actual_size.
width, 500);
315 EXPECT_EQ(actual_size.
height, 500);
318TEST_F(WindowManagerTest, CreateModelessDialogWindow) {
322 .preferred_view_width = 800,
323 .preferred_view_height = 600},
324 .preferred_constraints = {.has_view_constraints =
false},
325 .title = L
"Hello World",
326 .parent_or_null =
nullptr};
329 engine_id(), &creation_request);
333TEST_F(WindowManagerTest, CreateModalDialogWindow) {
336 const int64_t parent_view_id =
338 engine_id(), regular_creation_request());
339 const HWND parent_window_handle =
341 engine_id(), parent_view_id);
347 .preferred_view_width = 800,
348 .preferred_view_height = 600,
350 .preferred_constraints = {.has_view_constraints =
false},
351 .title = L
"Hello World",
352 .parent_or_null = parent_window_handle};
356 engine_id(), &creation_request);
359 const HWND window_handle =
364 parent_window_handle);
367TEST_F(WindowManagerTest, DialogCanNeverBeFullscreen) {
372 .preferred_view_width = 800,
373 .preferred_view_height = 600},
374 .preferred_constraints = {.has_view_constraints =
false},
375 .title = L
"Hello World",
376 .parent_or_null =
nullptr};
380 engine_id(), &creation_request);
381 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)
bool InternalFlutterWindows_WindowManager_HasTopLevelWindows(int64_t engine_id)
HWND InternalFlutterWindows_WindowManager_GetTopLevelWindowHandle(int64_t engine_id, FlutterViewId view_id)