From 4868038829d097b09c46b247e1dccf2230c42fe0 Mon Sep 17 00:00:00 2001 From: Tong Mu Date: Mon, 23 Oct 2023 15:45:43 -0700 Subject: [PATCH] Fix test and change dummy view ID --- shell/common/shell_test.cc | 8 ++++++-- shell/common/shell_test.h | 13 +++++++++---- shell/common/shell_unittests.cc | 2 +- 3 files changed, 16 insertions(+), 7 deletions(-) diff --git a/shell/common/shell_test.cc b/shell/common/shell_test.cc index bd952747ca58f..b298e84b335af 100644 --- a/shell/common/shell_test.cc +++ b/shell/common/shell_test.cc @@ -21,6 +21,10 @@ namespace flutter { namespace testing { constexpr int64_t kImplicitViewId = 0; +// Use a very large number that is not implicit view, so that if people +// accidentally used PumpOneFrame(shell) while rendering some content +// into the implicit view, their content wouldn't be skipped. +constexpr int64_t kDummyView = 0xdeadbeef; FrameContent ViewContent::NoViews() { return std::map(); @@ -28,7 +32,7 @@ FrameContent ViewContent::NoViews() { FrameContent ViewContent::DummyView(double width, double height) { FrameContent result; - result[kImplicitViewId] = ViewContent{ + result[kDummyView] = ViewContent{ .viewport_metrics = {1.0, width, height, 22, 0}, .builder = {}, }; @@ -37,7 +41,7 @@ FrameContent ViewContent::DummyView(double width, double height) { FrameContent ViewContent::DummyView(flutter::ViewportMetrics viewport_metrics) { FrameContent result; - result[kImplicitViewId] = ViewContent{ + result[kDummyView] = ViewContent{ .viewport_metrics = std::move(viewport_metrics), .builder = {}, }; diff --git a/shell/common/shell_test.h b/shell/common/shell_test.h index c11ad1174dc88..6ff9418c663e9 100644 --- a/shell/common/shell_test.h +++ b/shell/common/shell_test.h @@ -46,12 +46,11 @@ struct ViewContent { // to schedule the frame while the frame content is defined by other means. static FrameContent NoViews(); - // Build a frame with a single implicit view with the specific size and no - // content. + // Build a frame with a single view with the specific size and no content. static FrameContent DummyView(double width = 1, double height = 1); - // Build a frame with a single implicit view with the specific viewport - // metrics and no content. + // Build a frame with a single view with the specific viewport metrics and no + // content. static FrameContent DummyView(flutter::ViewportMetrics viewport_metrics); // Build a frame with a single implicit view with the specific size and @@ -108,6 +107,12 @@ class ShellTest : public FixtureTest { static void SetViewportMetrics(Shell* shell, double width, double height); static void NotifyIdle(Shell* shell, fml::TimeDelta deadline); + // By default PumpOneFrame renders dummy content into a dummy view that is + // not view ID. If the test case provide its own content, such as calling + // FlutterView.render in a Dart callback, you should probably pump a frame + // with no extra content using: + // + // PumpOneFrame(shell, FrameContent::NoViews()) static void PumpOneFrame(Shell* shell); static void PumpOneFrame(Shell* shell, FrameContent frame_content); static void DispatchFakePointerData(Shell* shell); diff --git a/shell/common/shell_unittests.cc b/shell/common/shell_unittests.cc index 83c8bd3488c50..b337fc136b782 100644 --- a/shell/common/shell_unittests.cc +++ b/shell/common/shell_unittests.cc @@ -2750,7 +2750,7 @@ TEST_F(ShellTest, OnServiceProtocolRenderFrameWithRasterStatsDisableImpeller) { configuration.SetEntrypoint("scene_with_red_box"); RunEngine(shell.get(), std::move(configuration)); - PumpOneFrame(shell.get()); + PumpOneFrame(shell.get(), ViewContent::NoViews()); ServiceProtocol::Handler::ServiceProtocolMap empty_params; rapidjson::Document document;