13 #import "flutter/testing/testing.h"
14 #import "third_party/googletest/googletest/include/gtest/gtest.h"
29 AddNativeCallback(
"SignalNativeTest", CREATE_NATIVE_ENTRY([&](Dart_NativeArguments args) {
35 CFRunLoopRunInMode(kCFRunLoopDefaultMode, 0.1,
false);
49 FML_LOG(ERROR) <<
"Isolate is not set.";
63 .size = {.width = 800, .height = 600},
64 .on_should_close = [] {},
65 .on_will_close = [] {},
66 .notify_listeners = [] {},
70 int64_t engineId =
reinterpret_cast<int64_t
>(engine);
78 EXPECT_NE(viewController, nil);
79 CGSize size = viewController.view.frame.size;
80 EXPECT_EQ(size.width, 800);
81 EXPECT_EQ(size.height, 600);
88 int64_t engineId =
reinterpret_cast<int64_t
>(engine);
92 .size = {.width = 800, .height = 600},
93 .on_should_close = [] {},
94 .on_will_close = [] {},
95 .notify_listeners = [] {},
98 EXPECT_EQ(parentViewId, 1);
104 rect->
left = parent_rect.left + 10;
105 rect->
top = parent_rect.top + 10;
117 .parent_view_id = parentViewId,
118 .on_should_close = [] {},
119 .on_will_close = [] {},
120 .notify_listeners = [] {},
121 .on_get_window_position = position_callback,
124 const int64_t tooltipViewId =
126 EXPECT_NE(tooltipViewId, 0);
132 int64_t engineId =
reinterpret_cast<int64_t
>(engine);
136 .size = {.width = 800, .height = 600},
137 .on_should_close = [] {},
138 .on_will_close = [] {},
139 .notify_listeners = [] {},
142 EXPECT_EQ(parentViewId, 1);
148 rect->
left = parent_rect.left + 10;
149 rect->
top = parent_rect.top + 10;
161 .parent_view_id = parentViewId,
162 .on_should_close = [] {},
163 .on_will_close = [] {},
164 .notify_listeners = [] {},
165 .on_get_window_position = position_callback,
168 const int64_t tooltipViewId =
170 EXPECT_NE(tooltipViewId, 0);
176 .size = {.width = 800, .height = 600},
177 .on_should_close = [] {},
178 .on_will_close = [] {},
179 .notify_listeners = [] {},
184 NSString* fixtures = @(flutter::testing::GetFixturesPath());
185 NSLog(
@"Fixtures path: %@", fixtures);
187 initWithAssetsPath:fixtures
188 ICUDataPath:[fixtures stringByAppendingString:
@"/icudtl.dat"]];
190 static std::optional<flutter::Isolate> isolate;
191 isolate = std::nullopt;
196 allowHeadlessExecution:YES];
198 [engine runWithEntrypoint:
@"testWindowControllerRetainCycle"];
200 int64_t engineId =
reinterpret_cast<int64_t
>(engine);
203 FML_DCHECK(isolate.has_value());
207 EXPECT_EQ(handle, 1);
210 [engine.windowController closeAllWindows];
211 [engine shutDownEngine];
213 EXPECT_EQ(weakEngine, nil);
219 .size = {.width = 800, .height = 600},
220 .on_should_close = [] {},
221 .on_will_close = [] {},
222 .notify_listeners = [] {},
226 int64_t engine_id =
reinterpret_cast<int64_t
>(engine);
233 viewController = [engine viewControllerForIdentifier:handle];
234 EXPECT_EQ(viewController, nil);
240 .size = {.width = 800, .height = 600},
241 .on_should_close = [] {},
242 .on_will_close = [] {},
243 .notify_listeners = [] {},
247 int64_t engine_id =
reinterpret_cast<int64_t
>(engine);
254 EXPECT_EQ(window_handle, (__bridge
void*)viewController.view.window);
260 .size = {.width = 800, .height = 600},
261 .on_should_close = [] {},
262 .on_will_close = [] {},
263 .notify_listeners = [] {},
267 int64_t engine_id =
reinterpret_cast<int64_t
>(engine);
273 NSWindow* window = viewController.view.window;
274 void* windowHandle = (__bridge
void*)window;
276 EXPECT_EQ(window.zoomed, NO);
277 EXPECT_EQ(window.miniaturized, NO);
278 EXPECT_EQ(window.styleMask & NSWindowStyleMaskFullScreen, 0u);
281 CFRunLoopRunInMode(kCFRunLoopDefaultMode, 0.5,
false);
282 EXPECT_EQ(window.zoomed, YES);
285 CFRunLoopRunInMode(kCFRunLoopDefaultMode, 0.5,
false);
286 EXPECT_EQ(window.zoomed, NO);
291 CFRunLoopRunInMode(kCFRunLoopDefaultMode, 0.5,
false);
292 EXPECT_EQ(window.miniaturized, YES);
298 .size = {.width = 800, .height = 600},
299 .on_should_close = [] {},
300 .on_will_close = [] {},
301 .notify_listeners = [] {},
304 int64_t engine_id =
reinterpret_cast<int64_t
>(engine);
317 EXPECT_NE(viewController1, nil);
318 EXPECT_NE(viewController2, nil);
319 EXPECT_NE(viewController3, nil);
322 [engine engineCallbackOnPreEngineRestart];
325 viewController1 = [engine viewControllerForIdentifier:handle1];
326 viewController2 = [engine viewControllerForIdentifier:handle2];
327 viewController3 = [engine viewControllerForIdentifier:handle3];
328 EXPECT_EQ(viewController1, nil);
329 EXPECT_EQ(viewController2, nil);
330 EXPECT_EQ(viewController3, nil);
336 int64_t engineId =
reinterpret_cast<int64_t
>(engine);
341 .size = {.width = 800, .height = 600},
342 .on_should_close = [] {},
343 .on_will_close = [] {},
344 .notify_listeners = [] {},
346 int64_t parentViewId =
348 EXPECT_EQ(parentViewId, 1);
354 rect->
left = parent_rect.left;
355 rect->
top = parent_rect.top;
369 .parent_view_id = parentViewId,
370 .on_should_close = [] {},
371 .on_will_close = [] {},
372 .notify_listeners = [] {},
373 .on_get_window_position = position_callback,
376 const int64_t tooltipViewId =
378 EXPECT_NE(tooltipViewId, 0);
381 FlutterView* flutterView = viewController.flutterView;
385 CFRunLoopRunInMode(kCFRunLoopDefaultMode, 0.1,
false);
387 [flutterView.
sizingDelegate viewDidUpdateContents:flutterView withSize:NSMakeSize(1000, 1000)];
392 EXPECT_LE(maxSize.width, 500);
393 EXPECT_LE(maxSize.height, 400);
397 NSWindow* parentWindow = [[NSWindow alloc] initWithContentRect:NSMakeRect(0, 0, 800, 600)
398 styleMask:NSWindowStyleMaskTitled
399 backing:NSBackingStoreBuffered
401 [parentWindow setReleasedWhenClosed:NO];
402 NSWindow* childWindow = [[NSWindow alloc] initWithContentRect:NSMakeRect(0, 0, 100, 100)
403 styleMask:NSWindowStyleMaskBorderless
404 backing:NSBackingStoreBuffered
406 [childWindow setReleasedWhenClosed:NO];
409 [parentWindow setFrame:NSMakeRect(100, 100, 800, 600) display:NO];
410 [childWindow setFrame:NSMakeRect(150, 150, 100, 100) display:NO];
413 [parentWindow addChildWindow:childWindow ordered:NSWindowAbove];
419 NSRect parentContentRect = [parentWindow contentRectForFrameRect:parentWindow.frame];
421 double expectedX = 150 - parentContentRect.origin.x;
422 double expectedY = (parentContentRect.origin.y + parentContentRect.size.height) - (150 + 100);
424 EXPECT_NEAR(offset.
x, expectedX, 0.001);
425 EXPECT_NEAR(offset.
y, expectedY, 0.001);
427 [parentWindow removeChildWindow:childWindow];
429 [parentWindow close];
FLUTTER_DARWIN_EXPORT int64_t InternalFlutter_WindowController_CreateRegularWindow(int64_t engine_id, const FlutterWindowCreationRequest *request)
FLUTTER_DARWIN_EXPORT FlutterWindowOffset InternalFlutter_Window_GetOffsetInParent(void *window)
FLUTTER_DARWIN_EXPORT int64_t InternalFlutter_WindowController_CreateTooltipWindow(int64_t engine_id, const FlutterWindowCreationRequest *request)
FLUTTER_DARWIN_EXPORT void InternalFlutter_Window_SetMaximized(void *window, bool maximized)
FLUTTER_DARWIN_EXPORT int64_t InternalFlutter_WindowController_CreatePopupWindow(int64_t engine_id, const FlutterWindowCreationRequest *request)
FLUTTER_DARWIN_EXPORT void InternalFlutter_Window_Destroy(int64_t engine_id, void *window)
FLUTTER_DARWIN_EXPORT void * InternalFlutter_Window_GetHandle(int64_t engine_id, FlutterViewIdentifier view_id)
FLUTTER_DARWIN_EXPORT void InternalFlutter_Window_Minimize(void *window)
void AddNativeCallback(const char *name, Dart_NativeFunction function)
FlutterEngine * GetFlutterEngine()
std::optional< flutter::Isolate > isolate_
FlutterWindowControllerTest()=default
flutter::Isolate & isolate()
CGSize maximumContentSize
id< FlutterViewSizingDelegate > sizingDelegate
TEST_F(AccessibilityBridgeMacWindowTest, SendsAccessibilityCreateNotificationFlutterViewWindow)