13 #import "flutter/testing/testing.h"
14 #import "third_party/googletest/googletest/include/gtest/gtest.h"
38 CFRunLoopRunInMode(kCFRunLoopDefaultMode, 0.1,
false);
52 FML_LOG(ERROR) <<
"Isolate is not set.";
67 [engine.windowController fixMoveRunLoopModeIfNeeded];
71 __block BOOL signalled = NO;
72 CFRunLoopPerformBlock(CFRunLoopGetCurrent(), kCFRunLoopCommonModes, ^{
75 CFRunLoopRunInMode(CFSTR(
"_NSMoveTimerRunLoopMode"), 1.0, YES);
76 EXPECT_TRUE(signalled);
82 .size = {.width = 800, .height = 600},
84 .on_should_close = [] {},
85 .on_will_close = [] {},
86 .notify_listeners = [] {},
90 int64_t engineId =
reinterpret_cast<int64_t
>(engine);
98 EXPECT_NE(viewController, nil);
99 CGSize size = viewController.view.frame.size;
100 EXPECT_EQ(size.width, 800);
101 EXPECT_EQ(size.height, 600);
108 int64_t engineId =
reinterpret_cast<int64_t
>(engine);
112 .size = {.width = 800, .height = 600},
114 .on_should_close = [] {},
115 .on_will_close = [] {},
116 .notify_listeners = [] {},
119 EXPECT_EQ(parentViewId, 1);
125 rect->
left = parent_rect.left + 10;
126 rect->
top = parent_rect.top + 10;
139 .parent_view_id = parentViewId,
140 .on_should_close = [] {},
141 .on_will_close = [] {},
142 .notify_listeners = [] {},
143 .on_get_window_position = position_callback,
146 const int64_t tooltipViewId =
148 EXPECT_NE(tooltipViewId, 0);
154 int64_t engineId =
reinterpret_cast<int64_t
>(engine);
158 .size = {.width = 800, .height = 600},
160 .on_should_close = [] {},
161 .on_will_close = [] {},
162 .notify_listeners = [] {},
165 EXPECT_EQ(parentViewId, 1);
171 rect->
left = parent_rect.left + 10;
172 rect->
top = parent_rect.top + 10;
185 .parent_view_id = parentViewId,
186 .on_should_close = [] {},
187 .on_will_close = [] {},
188 .notify_listeners = [] {},
189 .on_get_window_position = position_callback,
192 const int64_t tooltipViewId =
194 EXPECT_NE(tooltipViewId, 0);
200 .size = {.width = 800, .height = 600},
202 .on_should_close = [] {},
203 .on_will_close = [] {},
204 .notify_listeners = [] {},
209 NSString* fixtures = @(flutter::testing::GetFixturesPath());
210 NSLog(
@"Fixtures path: %@", fixtures);
212 initWithAssetsPath:fixtures
213 ICUDataPath:[fixtures stringByAppendingString:
@"/icudtl.dat"]];
215 static std::optional<flutter::Isolate> isolate;
216 isolate = std::nullopt;
221 allowHeadlessExecution:YES];
223 [engine runWithEntrypoint:
@"testWindowControllerRetainCycle"];
225 CFRunLoopRunInMode(kCFRunLoopDefaultMode, 1,
false);
227 int64_t engineId =
reinterpret_cast<int64_t
>(engine);
230 FML_DCHECK(isolate.has_value());
234 EXPECT_EQ(handle, 1);
237 CFRunLoopRunInMode(kCFRunLoopDefaultMode, 1,
false);
239 [engine.windowController closeAllWindows];
240 [engine shutDownEngine];
242 EXPECT_EQ(weakEngine, nil);
248 .size = {.width = 800, .height = 600},
250 .on_should_close = [] {},
251 .on_will_close = [] {},
252 .notify_listeners = [] {},
256 int64_t engine_id =
reinterpret_cast<int64_t
>(engine);
263 viewController = [engine viewControllerForIdentifier:handle];
264 EXPECT_EQ(viewController, nil);
270 .size = {.width = 800, .height = 600},
272 .on_should_close = [] {},
273 .on_will_close = [] {},
274 .notify_listeners = [] {},
278 int64_t engine_id =
reinterpret_cast<int64_t
>(engine);
285 EXPECT_EQ(window_handle, (__bridge
void*)viewController.view.window);
291 .size = {.width = 800, .height = 600},
293 .on_should_close = [] {},
294 .on_will_close = [] {},
295 .notify_listeners = [] {},
299 int64_t engine_id =
reinterpret_cast<int64_t
>(engine);
305 NSWindow* window = viewController.view.window;
306 void* windowHandle = (__bridge
void*)window;
308 EXPECT_EQ(window.zoomed, NO);
309 EXPECT_EQ(window.miniaturized, NO);
310 EXPECT_EQ(window.styleMask & NSWindowStyleMaskFullScreen, 0u);
313 CFRunLoopRunInMode(kCFRunLoopDefaultMode, 0.5,
false);
314 EXPECT_EQ(window.zoomed, YES);
317 CFRunLoopRunInMode(kCFRunLoopDefaultMode, 0.5,
false);
318 EXPECT_EQ(window.zoomed, NO);
323 CFRunLoopRunInMode(kCFRunLoopDefaultMode, 0.5,
false);
324 EXPECT_EQ(window.miniaturized, YES);
330 .size = {.width = 800, .height = 600},
332 .on_should_close = [] {},
333 .on_will_close = [] {},
334 .notify_listeners = [] {},
337 int64_t engine_id =
reinterpret_cast<int64_t
>(engine);
350 EXPECT_NE(viewController1, nil);
351 EXPECT_NE(viewController2, nil);
352 EXPECT_NE(viewController3, nil);
355 [engine engineCallbackOnPreEngineRestart];
358 viewController1 = [engine viewControllerForIdentifier:handle1];
359 viewController2 = [engine viewControllerForIdentifier:handle2];
360 viewController3 = [engine viewControllerForIdentifier:handle3];
361 EXPECT_EQ(viewController1, nil);
362 EXPECT_EQ(viewController2, nil);
363 EXPECT_EQ(viewController3, nil);
369 int64_t engineId =
reinterpret_cast<int64_t
>(engine);
374 .size = {.width = 800, .height = 600},
376 .on_should_close = [] {},
377 .on_will_close = [] {},
378 .notify_listeners = [] {},
380 int64_t parentViewId =
382 EXPECT_EQ(parentViewId, 1);
388 rect->
left = parent_rect.left;
389 rect->
top = parent_rect.top;
403 .parent_view_id = parentViewId,
404 .on_should_close = [] {},
405 .on_will_close = [] {},
406 .notify_listeners = [] {},
407 .on_get_window_position = position_callback,
410 const int64_t tooltipViewId =
412 EXPECT_NE(tooltipViewId, 0);
415 FlutterView* flutterView = viewController.flutterView;
419 CFRunLoopRunInMode(kCFRunLoopDefaultMode, 0.1,
false);
421 [flutterView.
contentDelegate viewDidUpdateContents:flutterView withSize:NSMakeSize(1000, 1000)];
426 EXPECT_LE(maxSize.width, 500);
427 EXPECT_LE(maxSize.height, 400);
431 NSWindow* parentWindow = [[NSWindow alloc] initWithContentRect:NSMakeRect(0, 0, 800, 600)
432 styleMask:NSWindowStyleMaskTitled
433 backing:NSBackingStoreBuffered
435 [parentWindow setReleasedWhenClosed:NO];
436 NSWindow* childWindow = [[NSWindow alloc] initWithContentRect:NSMakeRect(0, 0, 100, 100)
437 styleMask:NSWindowStyleMaskBorderless
438 backing:NSBackingStoreBuffered
440 [childWindow setReleasedWhenClosed:NO];
443 [parentWindow setFrame:NSMakeRect(100, 100, 800, 600) display:NO];
444 [childWindow setFrame:NSMakeRect(150, 150, 100, 100) display:NO];
447 [parentWindow addChildWindow:childWindow ordered:NSWindowAbove];
453 NSRect parentContentRect = [parentWindow contentRectForFrameRect:parentWindow.frame];
455 double expectedX = 150 - parentContentRect.origin.x;
456 double expectedY = (parentContentRect.origin.y + parentContentRect.size.height) - (150 + 100);
458 EXPECT_NEAR(offset.
x, expectedX, 0.001);
459 EXPECT_NEAR(offset.
y, expectedY, 0.001);
461 [parentWindow removeChildWindow:childWindow];
463 [parentWindow close];
471 .has_constraints =
true,
479 .on_should_close = [] {},
480 .on_will_close = [] {},
481 .notify_listeners = [] {},
484 std::optional<Isolate> isolate;
486 bool signaled =
false;
487 AddFfiNativeCallback(
"SignalNativeTest", CREATE_FFI_LAMBDA([&](Dart_NativeArguments args) {
492 auto engine = GetFlutterEngine();
493 [engine runWithEntrypoint:
@"testRenderSizedToContentResizable"];
495 auto engineId =
reinterpret_cast<int64_t
>(GetFlutterEngine());
498 CFRunLoopRunInMode(kCFRunLoopDefaultMode, 0.1,
true);
507 auto controller = [engine viewControllerForIdentifier:viewId];
508 auto window = controller.view.window;
509 CFAbsoluteTime startTime = CFAbsoluteTimeGetCurrent();
510 double pixelRatio = [window backingScaleFactor];
511 while (window.frame.size.width != 300 / pixelRatio &&
512 CFAbsoluteTimeGetCurrent() - startTime <
kTestTimeout) {
513 CFRunLoopRunInMode(kCFRunLoopDefaultMode, 0.1,
true);
516 NSRect contentRect = [window contentRectForFrameRect:window.frame];
517 EXPECT_EQ(contentRect.size.width, 300 / pixelRatio);
518 EXPECT_EQ(contentRect.size.height, 300 / pixelRatio);
519 EXPECT_TRUE((window.styleMask & NSWindowStyleMaskResizable) != 0);
521 [engine.windowController closeAllWindows];
522 [engine shutDownEngine];
528 .has_constraints =
true,
536 .on_should_close = [] {},
537 .on_will_close = [] {},
538 .notify_listeners = [] {},
541 std::optional<Isolate> isolate;
543 bool signaled =
false;
544 AddFfiNativeCallback(
"SignalNativeTest", CREATE_FFI_LAMBDA([&](Dart_NativeArguments args) {
549 auto engine = GetFlutterEngine();
550 [engine runWithEntrypoint:
@"testRenderSizedToContent"];
552 auto engineId =
reinterpret_cast<int64_t
>(GetFlutterEngine());
555 CFRunLoopRunInMode(kCFRunLoopDefaultMode, 0.1,
true);
564 auto controller = [engine viewControllerForIdentifier:viewId];
565 auto window = controller.view.window;
567 CFAbsoluteTime startTime = CFAbsoluteTimeGetCurrent();
568 double pixelRatio = [window backingScaleFactor];
569 while (window.frame.size.width != 300 / pixelRatio &&
570 CFAbsoluteTimeGetCurrent() - startTime <
kTestTimeout) {
571 CFRunLoopRunInMode(kCFRunLoopDefaultMode, 0.1,
true);
574 NSRect contentRect = [window contentRectForFrameRect:window.frame];
575 EXPECT_EQ(contentRect.size.width, 300 / pixelRatio);
576 EXPECT_EQ(contentRect.size.height, 300 / pixelRatio);
577 EXPECT_TRUE((window.styleMask & NSWindowStyleMaskResizable) == 0);
581 startTime = CFAbsoluteTimeGetCurrent();
582 while (window.frame.size.width == 300 / pixelRatio &&
583 CFAbsoluteTimeGetCurrent() - startTime <
kTestTimeout) {
584 CFRunLoopRunInMode(kCFRunLoopDefaultMode, 0.1,
true);
587 contentRect = [window contentRectForFrameRect:window.frame];
588 EXPECT_EQ(contentRect.size.width, 200 / pixelRatio);
589 EXPECT_EQ(contentRect.size.height, 200 / pixelRatio);
591 [engine.windowController closeAllWindows];
592 [engine shutDownEngine];
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 AddFfiNativeCallback(const char *name, void *function)
FlutterEngine * GetFlutterEngine()
std::optional< flutter::Isolate > isolate_
FlutterWindowControllerTest()=default
flutter::Isolate & isolate()
CGSize maximumContentSize
id< FlutterViewContentDelegate > contentDelegate
TEST_F(AccessibilityBridgeMacWindowTest, SendsAccessibilityCreateNotificationFlutterViewWindow)
const CFAbsoluteTime kTestTimeout