Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 51 additions & 0 deletions shell/platform/darwin/macos/framework/Source/FlutterEngineTest.mm
Original file line number Diff line number Diff line change
Expand Up @@ -1097,6 +1097,57 @@ + (void)registerWithRegistrar:(id<FlutterPluginRegistrar>)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)