Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion shell/platform/fuchsia/flutter/platform_view.cc
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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