@@ -2066,5 +2066,74 @@ TEST_F(ShellTest, DiscardLayerTreeOnResize) {
20662066 DestroyShell (std::move (shell));
20672067}
20682068
2069+ TEST_F (ShellTest, IgnoresInvalidMetrics) {
2070+ fml::AutoResetWaitableEvent latch;
2071+ double last_device_pixel_ratio;
2072+ double last_width;
2073+ double last_height;
2074+ auto native_report_device_pixel_ratio = [&](Dart_NativeArguments args) {
2075+ auto dpr_handle = Dart_GetNativeArgument (args, 0 );
2076+ ASSERT_TRUE (Dart_IsDouble (dpr_handle));
2077+ Dart_DoubleValue (dpr_handle, &last_device_pixel_ratio);
2078+ ASSERT_FALSE (last_device_pixel_ratio == 0.0 );
2079+
2080+ auto width_handle = Dart_GetNativeArgument (args, 1 );
2081+ ASSERT_TRUE (Dart_IsDouble (width_handle));
2082+ Dart_DoubleValue (width_handle, &last_width);
2083+ ASSERT_FALSE (last_width == 0.0 );
2084+
2085+ auto height_handle = Dart_GetNativeArgument (args, 2 );
2086+ ASSERT_TRUE (Dart_IsDouble (height_handle));
2087+ Dart_DoubleValue (height_handle, &last_height);
2088+ ASSERT_FALSE (last_height == 0.0 );
2089+
2090+ latch.Signal ();
2091+ };
2092+
2093+ Settings settings = CreateSettingsForFixture ();
2094+ auto task_runner = CreateNewThread ();
2095+ TaskRunners task_runners (" test" , task_runner, task_runner, task_runner,
2096+ task_runner);
2097+
2098+ AddNativeCallback (" ReportMetrics" ,
2099+ CREATE_NATIVE_ENTRY (native_report_device_pixel_ratio));
2100+
2101+ std::unique_ptr<Shell> shell =
2102+ CreateShell (std::move (settings), std::move (task_runners));
2103+
2104+ auto configuration = RunConfiguration::InferFromSettings (settings);
2105+ configuration.SetEntrypoint (" reportMetrics" );
2106+
2107+ RunEngine (shell.get (), std::move (configuration));
2108+
2109+ task_runner->PostTask ([&]() {
2110+ shell->GetPlatformView ()->SetViewportMetrics ({0.0 , 400 , 200 });
2111+ task_runner->PostTask ([&]() {
2112+ shell->GetPlatformView ()->SetViewportMetrics ({0.8 , 0.0 , 200 });
2113+ task_runner->PostTask ([&]() {
2114+ shell->GetPlatformView ()->SetViewportMetrics ({0.8 , 400 , 0.0 });
2115+ task_runner->PostTask ([&]() {
2116+ shell->GetPlatformView ()->SetViewportMetrics ({0.8 , 400 , 200.0 });
2117+ });
2118+ });
2119+ });
2120+ });
2121+ latch.Wait ();
2122+ ASSERT_EQ (last_device_pixel_ratio, 0.8 );
2123+ ASSERT_EQ (last_width, 400.0 );
2124+ ASSERT_EQ (last_height, 200.0 );
2125+ latch.Reset ();
2126+
2127+ task_runner->PostTask ([&]() {
2128+ shell->GetPlatformView ()->SetViewportMetrics ({1.2 , 600 , 300 });
2129+ });
2130+ latch.Wait ();
2131+ ASSERT_EQ (last_device_pixel_ratio, 1.2 );
2132+ ASSERT_EQ (last_width, 600.0 );
2133+ ASSERT_EQ (last_height, 300.0 );
2134+
2135+ DestroyShell (std::move (shell), std::move (task_runners));
2136+ }
2137+
20692138} // namespace testing
20702139} // namespace flutter
0 commit comments