@@ -4771,6 +4771,63 @@ TEST_F(ShellTest, CanRemoveViewBeforeLaunchingIsolate) {
47714771 DestroyShell (std::move (shell), task_runners);
47724772}
47734773
4774+ // Ensure pending "add views" failures are properly flushed when the Dart
4775+ // isolate is launched.
4776+ TEST_F (ShellTest, IgnoresBadAddViewsBeforeLaunchingIsolate) {
4777+ ASSERT_FALSE (DartVMRef::IsInstanceRunning ());
4778+ Settings settings = CreateSettingsForFixture ();
4779+ ThreadHost thread_host (ThreadHost::ThreadHostConfig (
4780+ " io.flutter.test." + GetCurrentTestName () + " ." ,
4781+ ThreadHost::Type::kPlatform | ThreadHost::Type::kRaster |
4782+ ThreadHost::Type::kIo | ThreadHost::Type::kUi ));
4783+ TaskRunners task_runners (" test" , thread_host.platform_thread ->GetTaskRunner (),
4784+ thread_host.raster_thread ->GetTaskRunner (),
4785+ thread_host.ui_thread ->GetTaskRunner (),
4786+ thread_host.io_thread ->GetTaskRunner ());
4787+ std::unique_ptr<Shell> shell = CreateShell (settings, task_runners);
4788+ ASSERT_TRUE (shell);
4789+
4790+ PostSync (shell->GetTaskRunners ().GetPlatformTaskRunner (), [&shell] {
4791+ auto platform_view = shell->GetPlatformView ();
4792+
4793+ // Add the same view twice. The second time should fail.
4794+ shell->AddView (123 , ViewportMetrics{1 , 100 , 1 , 0 , 0 },
4795+ [](bool added) { ASSERT_TRUE (added); });
4796+
4797+ shell->AddView (123 , ViewportMetrics{1 , 200 , 1 , 0 , 0 },
4798+ [](bool added) { ASSERT_FALSE (added); });
4799+
4800+ // Add another view. Previous failures should not affect this.
4801+ shell->AddView (456 , ViewportMetrics{1 , 300 , 1 , 0 , 0 },
4802+ [](bool added) { ASSERT_TRUE (added); });
4803+ });
4804+
4805+ bool first_report = true ;
4806+ std::map<int64_t , int64_t > view_widths;
4807+ fml::AutoResetWaitableEvent report_latch;
4808+ AddNativeCallback (" NativeReportViewWidthsCallback" ,
4809+ CREATE_NATIVE_ENTRY ([&](Dart_NativeArguments args) {
4810+ EXPECT_TRUE (first_report);
4811+ first_report = false ;
4812+ ParseViewWidthsCallback (args, &view_widths);
4813+ report_latch.Signal ();
4814+ }));
4815+
4816+ PlatformViewNotifyCreated (shell.get ());
4817+ auto configuration = RunConfiguration::InferFromSettings (settings);
4818+ configuration.SetEntrypoint (" testReportViewWidths" );
4819+ RunEngine (shell.get (), std::move (configuration));
4820+
4821+ report_latch.Wait ();
4822+ EXPECT_EQ (view_widths.size (), 3u );
4823+ EXPECT_EQ (view_widths[0 ], 0 );
4824+ EXPECT_EQ (view_widths[123 ], 100 );
4825+ EXPECT_EQ (view_widths[456 ], 300 );
4826+
4827+ PlatformViewNotifyDestroyed (shell.get ());
4828+ DestroyShell (std::move (shell), task_runners);
4829+ }
4830+
47744831TEST_F (ShellTest, RuntimeStageBackendDefaultsToSkSLWithoutImpeller) {
47754832 ASSERT_FALSE (DartVMRef::IsInstanceRunning ());
47764833 Settings settings = CreateSettingsForFixture ();
0 commit comments