From db7a3dc09157e139587c9f23d0d73a83128988cf Mon Sep 17 00:00:00 2001 From: David Worsham Date: Tue, 18 May 2021 09:15:50 -0700 Subject: [PATCH] fuchsia: Fix occlusion_hint handling (#26208) --- .../platform/fuchsia/flutter/platform_view.cc | 2 +- .../fuchsia/flutter/platform_view_unittest.cc | 94 ++++++++++++++++--- 2 files changed, 82 insertions(+), 14 deletions(-) diff --git a/shell/platform/fuchsia/flutter/platform_view.cc b/shell/platform/fuchsia/flutter/platform_view.cc index 5061240162b85..7fe2e22c463a0 100644 --- a/shell/platform/fuchsia/flutter/platform_view.cc +++ b/shell/platform/fuchsia/flutter/platform_view.cc @@ -1011,7 +1011,7 @@ void PlatformView::HandleFlutterPlatformViewsChannelPlatformMessage( } SkRect view_occlusion_hint_raw = SkRect::MakeEmpty(); - auto view_occlusion_hint = args.FindMember(""); + auto view_occlusion_hint = args.FindMember("viewOcclusionHintLTRB"); if (view_occlusion_hint != args.MemberEnd()) { if (view_occlusion_hint->value.IsArray()) { const auto& view_occlusion_hint_array = diff --git a/shell/platform/fuchsia/flutter/platform_view_unittest.cc b/shell/platform/fuchsia/flutter/platform_view_unittest.cc index 63cdec25319a6..64b8e318bf53f 100644 --- a/shell/platform/fuchsia/flutter/platform_view_unittest.cc +++ b/shell/platform/fuchsia/flutter/platform_view_unittest.cc @@ -651,14 +651,17 @@ TEST_F(PlatformViewTests, UpdateViewTest) { flutter::TaskRunners task_runners = flutter::TaskRunners("test_runners", nullptr, nullptr, nullptr, nullptr); - // Test wireframe callback function. If the message sent to the platform - // view was properly handled and parsed, this function should be called, - // setting |wireframe_enabled| to true. - bool update_view_called = false; - auto UpdateViewCallback = [&update_view_called]( + std::optional occlusion_hint_for_test; + std::optional hit_testable_for_test; + std::optional focusable_for_test; + auto UpdateViewCallback = [&occlusion_hint_for_test, &hit_testable_for_test, + &focusable_for_test]( int64_t view_id, SkRect occlusion_hint, - bool hit_testable, - bool focusable) { update_view_called = true; }; + bool hit_testable, bool focusable) { + occlusion_hint_for_test = occlusion_hint; + hit_testable_for_test = hit_testable; + focusable_for_test = focusable; + }; flutter_runner::PlatformView platform_view = PlatformViewBuilder(delegate, std::move(task_runners), @@ -671,8 +674,8 @@ TEST_F(PlatformViewTests, UpdateViewTest) { auto base_view = static_cast(&platform_view); EXPECT_TRUE(base_view); - // JSON for the message to be passed into the PlatformView. - const uint8_t txt[] = + // Send a basic message. + const uint8_t json[] = "{" " \"method\":\"View.update\"," " \"args\": {" @@ -681,16 +684,81 @@ TEST_F(PlatformViewTests, UpdateViewTest) { " \"focusable\":true" " }" "}"; - std::unique_ptr message = std::make_unique( - "flutter/platform_views", fml::MallocMapping::Copy(txt, sizeof(txt)), + "flutter/platform_views", + fml::MallocMapping::Copy(json, sizeof(json)), fml::RefPtr()); base_view->HandlePlatformMessage(std::move(message)); RunLoopUntilIdle(); - - EXPECT_TRUE(update_view_called); + ASSERT_TRUE(occlusion_hint_for_test.has_value()); + ASSERT_TRUE(hit_testable_for_test.has_value()); + ASSERT_TRUE(focusable_for_test.has_value()); + EXPECT_EQ(occlusion_hint_for_test.value(), SkRect::MakeEmpty()); + EXPECT_EQ(hit_testable_for_test.value(), true); + EXPECT_EQ(focusable_for_test.value(), true); + + // Reset for the next message. + occlusion_hint_for_test.reset(); + hit_testable_for_test.reset(); + focusable_for_test.reset(); + + // Send another basic message. + const uint8_t json_false[] = + "{" + " \"method\":\"View.update\"," + " \"args\": {" + " \"viewId\":42," + " \"hitTestable\":false," + " \"focusable\":false" + " }" + "}"; + std::unique_ptr message_false = + std::make_unique( + "flutter/platform_views", + fml::MallocMapping::Copy(json_false, sizeof(json_false)), + fml::RefPtr()); + base_view->HandlePlatformMessage(std::move(message_false)); + RunLoopUntilIdle(); + ASSERT_TRUE(occlusion_hint_for_test.has_value()); + ASSERT_TRUE(hit_testable_for_test.has_value()); + ASSERT_TRUE(focusable_for_test.has_value()); + EXPECT_EQ(occlusion_hint_for_test.value(), SkRect::MakeEmpty()); + EXPECT_EQ(hit_testable_for_test.value(), false); + EXPECT_EQ(focusable_for_test.value(), false); + + // Reset for the next message. + occlusion_hint_for_test.reset(); + hit_testable_for_test.reset(); + focusable_for_test.reset(); + + // Send a message including an occlusion hint. + const uint8_t json_occlusion_hint[] = + "{" + " \"method\":\"View.update\"," + " \"args\": {" + " \"viewId\":42," + " \"hitTestable\":true," + " \"focusable\":true," + " \"viewOcclusionHintLTRB\":[0.1,0.2,0.3,0.4]" + " }" + "}"; + std::unique_ptr message_occlusion_hint = + std::make_unique( + "flutter/platform_views", + fml::MallocMapping::Copy(json_occlusion_hint, + sizeof(json_occlusion_hint)), + fml::RefPtr()); + base_view->HandlePlatformMessage(std::move(message_occlusion_hint)); + RunLoopUntilIdle(); + ASSERT_TRUE(occlusion_hint_for_test.has_value()); + ASSERT_TRUE(hit_testable_for_test.has_value()); + ASSERT_TRUE(focusable_for_test.has_value()); + EXPECT_EQ(occlusion_hint_for_test.value(), + SkRect::MakeLTRB(0.1, 0.2, 0.3, 0.4)); + EXPECT_EQ(hit_testable_for_test.value(), true); + EXPECT_EQ(focusable_for_test.value(), true); } // This test makes sure that the PlatformView forwards messages on the