Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit eead7b0

Browse files
a-wallena-wallen
and
a-wallen
authored
Place native callback registration before running engine (#37600)
Co-authored-by: a-wallen <[email protected]>
1 parent 7a4b112 commit eead7b0

File tree

1 file changed

+35
-28
lines changed

1 file changed

+35
-28
lines changed

shell/platform/darwin/macos/framework/Source/FlutterEngineTest.mm

Lines changed: 35 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,9 @@ @interface FlutterEngine (Test)
3939
}
4040

4141
TEST_F(FlutterEngineTest, HasNonNullExecutableName) {
42-
// Launch the test entrypoint.
4342
FlutterEngine* engine = GetFlutterEngine();
4443
std::string executable_name = [[engine executableName] UTF8String];
4544
ASSERT_FALSE(executable_name.empty());
46-
EXPECT_TRUE([engine runWithEntrypoint:@"executableNameNotNull"]);
4745

4846
// Block until notified by the Dart test of the value of Platform.executable.
4947
fml::AutoResetWaitableEvent latch;
@@ -53,6 +51,10 @@ @interface FlutterEngine (Test)
5351
EXPECT_EQ(executable_name, dart_string);
5452
latch.Signal();
5553
}));
54+
55+
// Launch the test entrypoint.
56+
EXPECT_TRUE([engine runWithEntrypoint:@"executableNameNotNull"]);
57+
5658
latch.Wait();
5759
}
5860

@@ -76,6 +78,11 @@ @interface FlutterEngine (Test)
7678
}
7779

7880
TEST_F(FlutterEngineTest, CanLogToStdout) {
81+
// Block until completion of print statement.
82+
fml::AutoResetWaitableEvent latch;
83+
AddNativeCallback("SignalNativeTest",
84+
CREATE_NATIVE_ENTRY([&](Dart_NativeArguments args) { latch.Signal(); }));
85+
7986
// Replace stdout stream buffer with our own.
8087
std::stringstream buffer;
8188
std::streambuf* old_buffer = std::cout.rdbuf();
@@ -86,10 +93,6 @@ @interface FlutterEngine (Test)
8693
EXPECT_TRUE([engine runWithEntrypoint:@"canLogToStdout"]);
8794
EXPECT_TRUE(engine.running);
8895

89-
// Block until completion of print statement.
90-
fml::AutoResetWaitableEvent latch;
91-
AddNativeCallback("SignalNativeTest",
92-
CREATE_NATIVE_ENTRY([&](Dart_NativeArguments args) { latch.Signal(); }));
9396
latch.Wait();
9497

9598
// Restore old stdout stream buffer.
@@ -101,19 +104,7 @@ @interface FlutterEngine (Test)
101104
}
102105

103106
TEST_F(FlutterEngineTest, BackgroundIsBlack) {
104-
// Launch the test entrypoint.
105107
FlutterEngine* engine = GetFlutterEngine();
106-
EXPECT_TRUE([engine runWithEntrypoint:@"backgroundTest"]);
107-
EXPECT_TRUE(engine.running);
108-
109-
NSString* fixtures = @(flutter::testing::GetFixturesPath());
110-
FlutterDartProject* project = [[FlutterDartProject alloc]
111-
initWithAssetsPath:fixtures
112-
ICUDataPath:[fixtures stringByAppendingString:@"/icudtl.dat"]];
113-
FlutterViewController* viewController = [[FlutterViewController alloc] initWithProject:project];
114-
[viewController loadView];
115-
viewController.flutterView.frame = CGRectMake(0, 0, 800, 600);
116-
[engine setViewController:viewController];
117108

118109
// Latch to ensure the entire layer tree has been generated and presented.
119110
fml::AutoResetWaitableEvent latch;
@@ -127,12 +118,8 @@ @interface FlutterEngine (Test)
127118
}
128119
latch.Signal();
129120
}));
130-
latch.Wait();
131-
}
132121

133-
TEST_F(FlutterEngineTest, CanOverrideBackgroundColor) {
134122
// Launch the test entrypoint.
135-
FlutterEngine* engine = GetFlutterEngine();
136123
EXPECT_TRUE([engine runWithEntrypoint:@"backgroundTest"]);
137124
EXPECT_TRUE(engine.running);
138125

@@ -144,7 +131,12 @@ @interface FlutterEngine (Test)
144131
[viewController loadView];
145132
viewController.flutterView.frame = CGRectMake(0, 0, 800, 600);
146133
[engine setViewController:viewController];
147-
viewController.flutterView.backgroundColor = [NSColor whiteColor];
134+
135+
latch.Wait();
136+
}
137+
138+
TEST_F(FlutterEngineTest, CanOverrideBackgroundColor) {
139+
FlutterEngine* engine = GetFlutterEngine();
148140

149141
// Latch to ensure the entire layer tree has been generated and presented.
150142
fml::AutoResetWaitableEvent latch;
@@ -158,6 +150,21 @@ @interface FlutterEngine (Test)
158150
}
159151
latch.Signal();
160152
}));
153+
154+
// Launch the test entrypoint.
155+
EXPECT_TRUE([engine runWithEntrypoint:@"backgroundTest"]);
156+
EXPECT_TRUE(engine.running);
157+
158+
NSString* fixtures = @(flutter::testing::GetFixturesPath());
159+
FlutterDartProject* project = [[FlutterDartProject alloc]
160+
initWithAssetsPath:fixtures
161+
ICUDataPath:[fixtures stringByAppendingString:@"/icudtl.dat"]];
162+
FlutterViewController* viewController = [[FlutterViewController alloc] initWithProject:project];
163+
[viewController loadView];
164+
viewController.flutterView.frame = CGRectMake(0, 0, 800, 600);
165+
[engine setViewController:viewController];
166+
viewController.flutterView.backgroundColor = [NSColor whiteColor];
167+
161168
latch.Wait();
162169
}
163170

@@ -425,17 +432,17 @@ @interface FlutterEngine (Test)
425432
}
426433

427434
TEST_F(FlutterEngineTest, NativeCallbacks) {
428-
FlutterEngine* engine = GetFlutterEngine();
429-
EXPECT_TRUE([engine runWithEntrypoint:@"nativeCallback"]);
430-
EXPECT_TRUE(engine.running);
431-
432435
fml::AutoResetWaitableEvent latch;
433436
bool latch_called = false;
434-
435437
AddNativeCallback("SignalNativeTest", CREATE_NATIVE_ENTRY([&](Dart_NativeArguments args) {
436438
latch_called = true;
437439
latch.Signal();
438440
}));
441+
442+
FlutterEngine* engine = GetFlutterEngine();
443+
EXPECT_TRUE([engine runWithEntrypoint:@"nativeCallback"]);
444+
EXPECT_TRUE(engine.running);
445+
439446
latch.Wait();
440447
ASSERT_TRUE(latch_called);
441448
}

0 commit comments

Comments
 (0)