From 2134c852b4bae9d6dbcee78d4ccdde2247cdf256 Mon Sep 17 00:00:00 2001 From: Michael Goderbauer Date: Thu, 1 Feb 2024 13:51:51 -0800 Subject: [PATCH] Re-add tests deleted on accident (flutter/engine#50223) This re-adds the tests from https://github.com/flutter/engine/pull/41998/files that were accidentally deleted in https://github.com/flutter/engine/pull/42418/files#diff-2cce780ae0f93b9230cbf44030048dbf9ef4c6e0fdb959a47cae440fac0350faL808, probably because of a bad merge. --- .../framework/Source/FlutterEngineTest.mm | 51 +++++++++++++++++++ 1 file changed, 51 insertions(+) diff --git a/engine/src/flutter/shell/platform/darwin/macos/framework/Source/FlutterEngineTest.mm b/engine/src/flutter/shell/platform/darwin/macos/framework/Source/FlutterEngineTest.mm index 264ef06d162..bc17ce01c2a 100644 --- a/engine/src/flutter/shell/platform/darwin/macos/framework/Source/FlutterEngineTest.mm +++ b/engine/src/flutter/shell/platform/darwin/macos/framework/Source/FlutterEngineTest.mm @@ -1097,6 +1097,57 @@ TEST_F(FlutterEngineTest, UnregistersPluginsOnEngineDestruction) { [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)