Skip to content

Commit

Permalink
fuchsia: Fix occlusion_hint handling (#26208)
Browse files Browse the repository at this point in the history
  • Loading branch information
arbreng committed May 18, 2021
1 parent ca89d69 commit db7a3dc
Show file tree
Hide file tree
Showing 2 changed files with 82 additions and 14 deletions.
2 changes: 1 addition & 1 deletion shell/platform/fuchsia/flutter/platform_view.cc
Expand Up @@ -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 =
Expand Down
94 changes: 81 additions & 13 deletions shell/platform/fuchsia/flutter/platform_view_unittest.cc
Expand Up @@ -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<SkRect> occlusion_hint_for_test;
std::optional<bool> hit_testable_for_test;
std::optional<bool> 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),
Expand All @@ -671,8 +674,8 @@ TEST_F(PlatformViewTests, UpdateViewTest) {
auto base_view = static_cast<flutter::PlatformView*>(&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\": {"
Expand All @@ -681,16 +684,81 @@ TEST_F(PlatformViewTests, UpdateViewTest) {
" \"focusable\":true"
" }"
"}";

std::unique_ptr<flutter::PlatformMessage> message =
std::make_unique<flutter::PlatformMessage>(
"flutter/platform_views", fml::MallocMapping::Copy(txt, sizeof(txt)),
"flutter/platform_views",
fml::MallocMapping::Copy(json, sizeof(json)),
fml::RefPtr<flutter::PlatformMessageResponse>());
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<flutter::PlatformMessage> message_false =
std::make_unique<flutter::PlatformMessage>(
"flutter/platform_views",
fml::MallocMapping::Copy(json_false, sizeof(json_false)),
fml::RefPtr<flutter::PlatformMessageResponse>());
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<flutter::PlatformMessage> message_occlusion_hint =
std::make_unique<flutter::PlatformMessage>(
"flutter/platform_views",
fml::MallocMapping::Copy(json_occlusion_hint,
sizeof(json_occlusion_hint)),
fml::RefPtr<flutter::PlatformMessageResponse>());
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
Expand Down

0 comments on commit db7a3dc

Please sign in to comment.