Delete legacy focus platform message request handlers. (flutter/engine#27057)
Delete the following platform message request handlers: - `HostView.getCurrentFocusState` - `HostView.getNextFocusState` - `View.requestFocus` See https://fxbug.dev/79740.
This commit is contained in:
@@ -101,23 +101,4 @@ bool FocusDelegate::RequestFocus(
|
||||
return true;
|
||||
}
|
||||
|
||||
bool FocusDelegate::CompleteCurrentFocusState(
|
||||
fml::RefPtr<flutter::PlatformMessageResponse> response) {
|
||||
std::string result(is_focused_ ? "[true]" : "[false]");
|
||||
response->Complete(std::make_unique<fml::DataMapping>(
|
||||
std::vector<uint8_t>(result.begin(), result.end())));
|
||||
return true;
|
||||
}
|
||||
|
||||
bool FocusDelegate::CompleteNextFocusState(
|
||||
fml::RefPtr<flutter::PlatformMessageResponse> response) {
|
||||
if (next_focus_request_) {
|
||||
FML_LOG(ERROR) << "An outstanding PlatformMessageResponse already exists "
|
||||
"for the next focus state!";
|
||||
return false;
|
||||
}
|
||||
next_focus_request_ = std::move(response);
|
||||
return true;
|
||||
}
|
||||
|
||||
} // namespace flutter_runner
|
||||
|
||||
@@ -45,27 +45,6 @@ class FocusDelegate {
|
||||
rapidjson::Value request,
|
||||
fml::RefPtr<flutter::PlatformMessageResponse> response);
|
||||
|
||||
/// Completes the platform message request with the FocusDelegate's most
|
||||
/// recent focus state.
|
||||
// TODO(fxbug.dev/79740): Delete after soft transition.
|
||||
bool CompleteCurrentFocusState(
|
||||
fml::RefPtr<flutter::PlatformMessageResponse> response);
|
||||
|
||||
/// Completes the platform message request with the FocusDelegate's next focus
|
||||
/// state.
|
||||
///
|
||||
/// Only one outstanding request may exist at a time. Any others will be
|
||||
/// completed empty.
|
||||
// TODO(fxbug.dev/79740): Delete after soft transition.
|
||||
bool CompleteNextFocusState(
|
||||
fml::RefPtr<flutter::PlatformMessageResponse> response);
|
||||
|
||||
/// Completes a platform message request by attempting to give focus for a
|
||||
/// given viewRef.
|
||||
// TODO(fxbug.dev/79740): Make private after soft transition.
|
||||
bool RequestFocus(rapidjson::Value request,
|
||||
fml::RefPtr<flutter::PlatformMessageResponse> response);
|
||||
|
||||
private:
|
||||
fuchsia::ui::views::ViewRefFocusedPtr view_ref_focused_;
|
||||
fuchsia::ui::views::FocuserPtr focuser_;
|
||||
@@ -77,6 +56,11 @@ class FocusDelegate {
|
||||
void Complete(fml::RefPtr<flutter::PlatformMessageResponse> response,
|
||||
std::string value);
|
||||
|
||||
/// Completes a platform message request by attempting to give focus for a
|
||||
/// given viewRef.
|
||||
bool RequestFocus(rapidjson::Value request,
|
||||
fml::RefPtr<flutter::PlatformMessageResponse> response);
|
||||
|
||||
FML_DISALLOW_COPY_AND_ASSIGN(FocusDelegate);
|
||||
};
|
||||
|
||||
|
||||
@@ -183,118 +183,4 @@ TEST_F(FocusDelegateTest, RequestFocusFailTest) {
|
||||
EXPECT_TRUE(focuser->request_focus_called());
|
||||
}
|
||||
|
||||
// Tests that WatchLoop() should callback and complete PlatformMessageResponses
|
||||
// correctly, given a series of vrf invocations.
|
||||
// TODO(fxbug.dev/79740): Delete after soft transition.
|
||||
TEST_F(FocusDelegateTest, DeprecatedWatchCallbackSeries) {
|
||||
std::vector<bool> vrf_states{false, true, true, false,
|
||||
true, false, true, true};
|
||||
std::size_t vrf_index = 0;
|
||||
std::size_t callback_index = 0;
|
||||
focus_delegate->WatchLoop([&](bool focus_state) {
|
||||
// Make sure the focus state that FocusDelegate gives us is consistent with
|
||||
// what was fired from the vrf.
|
||||
EXPECT_EQ(vrf_states[callback_index], focus_state);
|
||||
|
||||
// CompleteCurrentFocusState should complete with the current (up to date)
|
||||
// focus state.
|
||||
auto response = FakePlatformMessageResponse::Create();
|
||||
EXPECT_TRUE(focus_delegate->CompleteCurrentFocusState(response));
|
||||
response->ExpectCompleted(focus_state ? "[true]" : "[false]");
|
||||
|
||||
// Ensure this callback always happens in lockstep with
|
||||
// vrf->ScheduleCallback.
|
||||
EXPECT_EQ(vrf_index, callback_index++);
|
||||
});
|
||||
|
||||
// Subsequent WatchLoop calls should not be respected.
|
||||
focus_delegate->WatchLoop([](bool _) {
|
||||
ADD_FAILURE() << "Subsequent WatchLoops should not be respected!";
|
||||
});
|
||||
|
||||
do {
|
||||
// Ensure the next focus state is handled correctly.
|
||||
auto response1 = FakePlatformMessageResponse::Create();
|
||||
EXPECT_TRUE(focus_delegate->CompleteNextFocusState(response1));
|
||||
|
||||
// Since there's already an outstanding PlatformMessageResponse, this one
|
||||
// should be completed empty.
|
||||
auto response = FakePlatformMessageResponse::Create();
|
||||
EXPECT_FALSE(focus_delegate->CompleteNextFocusState(response));
|
||||
|
||||
// Post watch events and trigger the next vrf event.
|
||||
RunLoopUntilIdle();
|
||||
vrf->ScheduleCallback(vrf_states[vrf_index]);
|
||||
RunLoopUntilIdle();
|
||||
|
||||
// Next focus state should be completed by now.
|
||||
response1->ExpectCompleted(vrf_states[vrf_index] ? "[true]" : "[false]");
|
||||
|
||||
// Check CompleteCurrentFocusState again, and increment vrf_index, since we
|
||||
// move on to the next focus state.
|
||||
response = FakePlatformMessageResponse::Create();
|
||||
EXPECT_TRUE(focus_delegate->CompleteCurrentFocusState(response));
|
||||
response->ExpectCompleted(vrf_states[vrf_index++] ? "[true]" : "[false]");
|
||||
|
||||
// vrf->times_watched should always be 1 more than the amount of vrf events
|
||||
// emitted.
|
||||
EXPECT_EQ(vrf_index + 1, vrf->times_watched);
|
||||
} while (vrf_index < vrf_states.size());
|
||||
}
|
||||
|
||||
// Tests that RequestFocus() completes the platform message's response with a
|
||||
// non-error status code.
|
||||
// TODO(fxbug.dev/79740): Delete after soft transition.
|
||||
TEST_F(FocusDelegateTest, DeprecatedRequestFocusTest) {
|
||||
// This "Mock" ViewRef serves as the target for the RequestFocus operation.
|
||||
auto mock_view_ref_pair = scenic::ViewRefPair::New();
|
||||
// Create the platform message request.
|
||||
std::ostringstream message;
|
||||
message << "{"
|
||||
<< " \"method\":\"View.requestFocus\","
|
||||
<< " \"args\": {"
|
||||
<< " \"viewRef\":"
|
||||
<< mock_view_ref_pair.view_ref.reference.get() << " }"
|
||||
<< "}";
|
||||
|
||||
// Dispatch the plaform message request with an expected completion response.
|
||||
auto response = FakePlatformMessageResponse::Create();
|
||||
focus_delegate->RequestFocus(ParsePlatformMessage(message.str()), response);
|
||||
RunLoopUntilIdle();
|
||||
|
||||
response->ExpectCompleted("[0]");
|
||||
EXPECT_TRUE(focuser->request_focus_called());
|
||||
}
|
||||
|
||||
// Tests that RequestFocus() completes the platform message's response with a
|
||||
// Error::DENIED status code.
|
||||
// TODO(fxbug.dev/79740): Delete after soft transition.
|
||||
TEST_F(FocusDelegateTest, DeprecatedRequestFocusFailTest) {
|
||||
// This "Mock" ViewRef serves as the target for the RequestFocus operation.
|
||||
auto mock_view_ref_pair = scenic::ViewRefPair::New();
|
||||
// We're testing the focus failure case.
|
||||
focuser->fail_request_focus();
|
||||
// Create the platform message request.
|
||||
std::ostringstream message;
|
||||
message << "{"
|
||||
<< " \"method\":\"View.requestFocus\","
|
||||
<< " \"args\": {"
|
||||
<< " \"viewRef\":"
|
||||
<< mock_view_ref_pair.view_ref.reference.get() << " }"
|
||||
<< "}";
|
||||
|
||||
// Dispatch the plaform message request with an expected completion response.
|
||||
auto response = FakePlatformMessageResponse::Create();
|
||||
focus_delegate->RequestFocus(ParsePlatformMessage(message.str()), response);
|
||||
RunLoopUntilIdle();
|
||||
|
||||
response->ExpectCompleted(
|
||||
"[" +
|
||||
std::to_string(
|
||||
static_cast<std::underlying_type_t<fuchsia::ui::views::Error>>(
|
||||
fuchsia::ui::views::Error::DENIED)) +
|
||||
"]");
|
||||
EXPECT_TRUE(focuser->request_focus_called());
|
||||
}
|
||||
|
||||
} // namespace flutter_runner::testing
|
||||
|
||||
@@ -1062,12 +1062,6 @@ bool PlatformView::HandleFlutterPlatformViewsChannelPlatformMessage(
|
||||
on_destroy_view_callback_(view_id_raw, std::move(on_view_unbound));
|
||||
} else if (method.rfind("View.focus", 0) == 0) {
|
||||
return focus_delegate_->HandlePlatformMessage(root, message->response());
|
||||
} else if (method == "HostView.getCurrentFocusState") {
|
||||
return focus_delegate_->CompleteCurrentFocusState(message->response());
|
||||
} else if (method == "HostView.getNextFocusState") {
|
||||
return focus_delegate_->CompleteNextFocusState(message->response());
|
||||
} else if (method == "View.requestFocus") {
|
||||
return focus_delegate_->RequestFocus(root, message->response());
|
||||
} else {
|
||||
FML_DLOG(ERROR) << "Unknown " << message->channel() << " method " << method;
|
||||
}
|
||||
|
||||
@@ -1176,173 +1176,6 @@ TEST_F(PlatformViewTests, RequestFocusFailTest) {
|
||||
EXPECT_TRUE(focuser.request_focus_called());
|
||||
}
|
||||
|
||||
// This test makes sure that the PlatformView forwards messages on the
|
||||
// "flutter/platform_views" channel for GetCurrentFocusState and
|
||||
// GetNextFocusState.
|
||||
// TODO(fxbug.dev/79740): Delete after soft transition.
|
||||
TEST_F(PlatformViewTests, DeprecatedGetFocusStatesTest) {
|
||||
sys::testing::ServiceDirectoryProvider services_provider(dispatcher());
|
||||
MockPlatformViewDelegate delegate;
|
||||
flutter::TaskRunners task_runners =
|
||||
flutter::TaskRunners("test_runners", nullptr, nullptr, nullptr, nullptr);
|
||||
|
||||
FakeViewRefFocused vrf;
|
||||
fidl::BindingSet<fuchsia::ui::views::ViewRefFocused> vrf_bindings;
|
||||
auto vrf_handle = vrf_bindings.AddBinding(&vrf);
|
||||
|
||||
flutter_runner::PlatformView platform_view =
|
||||
PlatformViewBuilder(delegate, std::move(task_runners),
|
||||
services_provider.service_directory())
|
||||
.SetViewRefFocused(std::move(vrf_handle))
|
||||
.Build();
|
||||
|
||||
// Cast platform_view to its base view so we can have access to the public
|
||||
// "HandlePlatformMessage" function.
|
||||
auto base_view = static_cast<flutter::PlatformView*>(&platform_view);
|
||||
EXPECT_TRUE(base_view);
|
||||
|
||||
std::vector<bool> vrf_states{false, true, true, false,
|
||||
true, false, true, true};
|
||||
|
||||
for (std::size_t i = 0; i < vrf_states.size(); ++i) {
|
||||
// HostView.getNextFocusState should complete with the next focus state.
|
||||
auto response1 = FakePlatformMessageResponse::Create();
|
||||
base_view->HandlePlatformMessage(
|
||||
response1->WithMessage("flutter/platform_views",
|
||||
"{\"method\":\"HostView.getNextFocusState\"}"));
|
||||
// Duplicate HostView.getNextFocusState requests should complete empty.
|
||||
auto response2 = FakePlatformMessageResponse::Create();
|
||||
base_view->HandlePlatformMessage(
|
||||
response2->WithMessage("flutter/platform_views",
|
||||
"{\"method\":\"HostView.getNextFocusState\"}"));
|
||||
|
||||
// Post watch events and make sure the hanging get is invoked each time.
|
||||
RunLoopUntilIdle();
|
||||
EXPECT_EQ(vrf.times_watched, i + 1);
|
||||
|
||||
// Dispatch the next vrf event.
|
||||
vrf.ScheduleCallback(vrf_states[i]);
|
||||
RunLoopUntilIdle();
|
||||
|
||||
// Make sure HostView.getCurrentFocusState completes with the current focus
|
||||
// state.
|
||||
auto response3 = FakePlatformMessageResponse::Create();
|
||||
base_view->HandlePlatformMessage(response3->WithMessage(
|
||||
"flutter/platform_views",
|
||||
"{\"method\":\"HostView.getCurrentFocusState\"}"));
|
||||
// Duplicate HostView.getCurrentFocusState are allowed.
|
||||
auto response4 = FakePlatformMessageResponse::Create();
|
||||
base_view->HandlePlatformMessage(response4->WithMessage(
|
||||
"flutter/platform_views",
|
||||
"{\"method\":\"HostView.getCurrentFocusState\"}"));
|
||||
|
||||
// Run event loop and check our results.
|
||||
RunLoopUntilIdle();
|
||||
response1->ExpectCompleted(vrf_states[i] ? "[true]" : "[false]");
|
||||
response2->ExpectCompleted("");
|
||||
response3->ExpectCompleted(vrf_states[i] ? "[true]" : "[false]");
|
||||
response4->ExpectCompleted(vrf_states[i] ? "[true]" : "[false]");
|
||||
}
|
||||
}
|
||||
|
||||
// This test makes sure that the PlatformView forwards messages on the
|
||||
// "flutter/platform_views" channel for RequestFocus.
|
||||
// TODO(fxbug.dev/79740): Delete after soft transition.
|
||||
TEST_F(PlatformViewTests, DeprecatedRequestFocusTest) {
|
||||
sys::testing::ServiceDirectoryProvider services_provider(dispatcher());
|
||||
MockPlatformViewDelegate delegate;
|
||||
flutter::TaskRunners task_runners =
|
||||
flutter::TaskRunners("test_runners", nullptr, nullptr, nullptr, nullptr);
|
||||
|
||||
FakeFocuser focuser;
|
||||
fidl::BindingSet<fuchsia::ui::views::Focuser> focuser_bindings;
|
||||
auto focuser_handle = focuser_bindings.AddBinding(&focuser);
|
||||
|
||||
flutter_runner::PlatformView platform_view =
|
||||
PlatformViewBuilder(delegate, std::move(task_runners),
|
||||
services_provider.service_directory())
|
||||
.SetFocuser(std::move(focuser_handle))
|
||||
.Build();
|
||||
|
||||
// Cast platform_view to its base view so we can have access to the public
|
||||
// "HandlePlatformMessage" function.
|
||||
auto base_view = static_cast<flutter::PlatformView*>(&platform_view);
|
||||
EXPECT_TRUE(base_view);
|
||||
|
||||
// This "Mock" ViewRef serves as the target for the RequestFocus operation.
|
||||
auto mock_view_ref_pair = scenic::ViewRefPair::New();
|
||||
|
||||
// JSON for the message to be passed into the PlatformView.
|
||||
std::ostringstream message;
|
||||
message << "{"
|
||||
<< " \"method\":\"View.requestFocus\","
|
||||
<< " \"args\": {"
|
||||
<< " \"viewRef\":"
|
||||
<< mock_view_ref_pair.view_ref.reference.get() << " }"
|
||||
<< "}";
|
||||
|
||||
// Dispatch the plaform message request.
|
||||
auto response = FakePlatformMessageResponse::Create();
|
||||
base_view->HandlePlatformMessage(
|
||||
response->WithMessage("flutter/platform_views", message.str()));
|
||||
RunLoopUntilIdle();
|
||||
|
||||
response->ExpectCompleted("[0]");
|
||||
EXPECT_TRUE(focuser.request_focus_called());
|
||||
}
|
||||
|
||||
// This test makes sure that the PlatformView correctly replies with an error
|
||||
// response when a RequestFocus call fails.
|
||||
// TODO(fxbug.dev/79740): Delete after soft transition.
|
||||
TEST_F(PlatformViewTests, DeprecatedRequestFocusFailTest) {
|
||||
sys::testing::ServiceDirectoryProvider services_provider(dispatcher());
|
||||
MockPlatformViewDelegate delegate;
|
||||
flutter::TaskRunners task_runners =
|
||||
flutter::TaskRunners("test_runners", nullptr, nullptr, nullptr, nullptr);
|
||||
|
||||
FakeFocuser focuser;
|
||||
focuser.fail_request_focus();
|
||||
fidl::BindingSet<fuchsia::ui::views::Focuser> focuser_bindings;
|
||||
auto focuser_handle = focuser_bindings.AddBinding(&focuser);
|
||||
|
||||
flutter_runner::PlatformView platform_view =
|
||||
PlatformViewBuilder(delegate, std::move(task_runners),
|
||||
services_provider.service_directory())
|
||||
.SetFocuser(std::move(focuser_handle))
|
||||
.Build();
|
||||
|
||||
// Cast platform_view to its base view so we can have access to the public
|
||||
// "HandlePlatformMessage" function.
|
||||
auto base_view = static_cast<flutter::PlatformView*>(&platform_view);
|
||||
EXPECT_TRUE(base_view);
|
||||
|
||||
// This "Mock" ViewRef serves as the target for the RequestFocus operation.
|
||||
auto mock_view_ref_pair = scenic::ViewRefPair::New();
|
||||
|
||||
// JSON for the message to be passed into the PlatformView.
|
||||
std::ostringstream message;
|
||||
message << "{"
|
||||
<< " \"method\":\"View.requestFocus\","
|
||||
<< " \"args\": {"
|
||||
<< " \"viewRef\":"
|
||||
<< mock_view_ref_pair.view_ref.reference.get() << " }"
|
||||
<< "}";
|
||||
|
||||
// Dispatch the plaform message request.
|
||||
auto response = FakePlatformMessageResponse::Create();
|
||||
base_view->HandlePlatformMessage(
|
||||
response->WithMessage("flutter/platform_views", message.str()));
|
||||
RunLoopUntilIdle();
|
||||
|
||||
response->ExpectCompleted(
|
||||
"[" +
|
||||
std::to_string(
|
||||
static_cast<std::underlying_type_t<fuchsia::ui::views::Error>>(
|
||||
fuchsia::ui::views::Error::DENIED)) +
|
||||
"]");
|
||||
EXPECT_TRUE(focuser.request_focus_called());
|
||||
}
|
||||
|
||||
struct EventFlow {
|
||||
fuchsia::ui::input3::KeyEvent event;
|
||||
fuchsia::ui::input3::KeyEventStatus expected_key_event_status;
|
||||
|
||||
Reference in New Issue
Block a user