From e8632a1eebd28e4fc18ae31fa9d50473b807b8ee Mon Sep 17 00:00:00 2001 From: Michael Goderbauer Date: Wed, 31 Jan 2024 16:12:06 -0800 Subject: [PATCH] Re-add tests deleted on accident --- .../framework/Source/FlutterEngineTest.mm | 51 +++++++++++++++++++ 1 file changed, 51 insertions(+) diff --git a/shell/platform/darwin/macos/framework/Source/FlutterEngineTest.mm b/shell/platform/darwin/macos/framework/Source/FlutterEngineTest.mm index 264ef06d162a5..bc17ce01c2a02 100644 --- a/shell/platform/darwin/macos/framework/Source/FlutterEngineTest.mm +++ b/shell/platform/darwin/macos/framework/Source/FlutterEngineTest.mm @@ -1097,6 +1097,57 @@ + (void)registerWithRegistrar:(id)registrar { [NSApplication sharedApplication].delegate = previousDelegate; } +TEST_F(FlutterEngineTest, RunWithEntrypointUpdatesDisplayConfig) { + BOOL updated = NO; + FlutterEngine* engine = GetFlutterEngine(); + auto original_update_displays = engine.embedderAPI.NotifyDisplayUpdate; + engine.embedderAPI.NotifyDisplayUpdate = MOCK_ENGINE_PROC( + NotifyDisplayUpdate, ([&updated, &original_update_displays]( + auto engine, auto update_type, auto* displays, auto display_count) { + updated = YES; + return original_update_displays(engine, update_type, displays, display_count); + })); + + EXPECT_TRUE([engine runWithEntrypoint:@"main"]); + EXPECT_TRUE(updated); + + updated = NO; + [[NSNotificationCenter defaultCenter] + postNotificationName:NSApplicationDidChangeScreenParametersNotification + object:nil]; + EXPECT_TRUE(updated); +} + +TEST_F(FlutterEngineTest, NotificationsUpdateDisplays) { + BOOL updated = NO; + FlutterEngine* engine = GetFlutterEngine(); + auto original_set_viewport_metrics = engine.embedderAPI.SendWindowMetricsEvent; + engine.embedderAPI.SendWindowMetricsEvent = MOCK_ENGINE_PROC( + SendWindowMetricsEvent, + ([&updated, &original_set_viewport_metrics](auto engine, auto* window_metrics) { + updated = YES; + return original_set_viewport_metrics(engine, window_metrics); + })); + + EXPECT_TRUE([engine runWithEntrypoint:@"main"]); + + updated = NO; + [[NSNotificationCenter defaultCenter] postNotificationName:NSWindowDidChangeScreenNotification + object:nil]; + // No VC. + EXPECT_FALSE(updated); + + FlutterViewController* viewController = [[FlutterViewController alloc] initWithEngine:engine + nibName:nil + bundle:nil]; + [viewController loadView]; + viewController.flutterView.frame = CGRectMake(0, 0, 800, 600); + + [[NSNotificationCenter defaultCenter] postNotificationName:NSWindowDidChangeScreenNotification + object:nil]; + EXPECT_TRUE(updated); +} + } // namespace flutter::testing // NOLINTEND(clang-analyzer-core.StackAddressEscape)