forked from firka/flutter
[fuchsia][scenic] Reset the state of a PointerInjectorEndpoint on (flutter/engine#35241)
channel closure. This CL resets the state including cleaning up the buffers whenever a fuchsia.ui.pointerinjector.Device channel closes due to some error. Test: flutter_runner_tests
This commit is contained in:
@@ -305,4 +305,10 @@ void PointerInjectorDelegate::PointerInjectorEndpoint::RegisterInjector(
|
||||
registered_ = true;
|
||||
}
|
||||
|
||||
void PointerInjectorDelegate::PointerInjectorEndpoint::Reset() {
|
||||
injection_in_flight_ = false;
|
||||
registered_ = false;
|
||||
injector_events_ = {};
|
||||
}
|
||||
|
||||
} // namespace flutter_runner
|
||||
|
||||
@@ -106,7 +106,11 @@ class PointerInjectorDelegate {
|
||||
if (!weak) {
|
||||
return;
|
||||
}
|
||||
weak->registered_ = false;
|
||||
|
||||
// Clear all the stale pointer events in |injector_events_| and
|
||||
// reset the state of |weak| so that any future calls do not inject
|
||||
// any stale pointer events.
|
||||
weak->Reset();
|
||||
});
|
||||
}
|
||||
|
||||
@@ -129,6 +133,12 @@ class PointerInjectorDelegate {
|
||||
|
||||
void EnqueueEvent(fuchsia::ui::pointerinjector::Event event);
|
||||
|
||||
// Resets |registered_|, |injection_in_flight_| and |injector_events_| so
|
||||
// that |device_| can be re-registered and future calls to
|
||||
// |fuchsia.ui.pointerinjector.Device.Inject| do not include any stale
|
||||
// pointer events.
|
||||
void Reset();
|
||||
|
||||
// Set to true if there is a |fuchsia.ui.pointerinjector.Device.Inject| call
|
||||
// in progress. If true, the |fuchsia.ui.pointerinjector.Event| is buffered
|
||||
// in |injector_events_|.
|
||||
|
||||
@@ -681,6 +681,72 @@ TEST_P(PointerInjectorDelegateTest, ViewsGetPointerEventsInFIFO) {
|
||||
}
|
||||
}
|
||||
|
||||
TEST_P(PointerInjectorDelegateTest, DeviceRetriesRegisterWhenClosed) {
|
||||
const uint64_t view_id = 1;
|
||||
const int pointer_id = 1;
|
||||
auto view_ref_pair = scenic::ViewRefPair::New();
|
||||
|
||||
auto response = FakePlatformMessageResponse::Create();
|
||||
auto response_2 = FakePlatformMessageResponse::Create();
|
||||
|
||||
std::optional<fuv_ViewRef> view_ref_clone;
|
||||
std::optional<fuv_ViewRef> view_ref_clone_2;
|
||||
|
||||
// Create the view.
|
||||
if (!is_flatland_) {
|
||||
CreateView(view_id);
|
||||
fuv_ViewRef temp_ref;
|
||||
fuv_ViewRef temp_ref_2;
|
||||
fidl::Clone(view_ref_pair.view_ref, &temp_ref);
|
||||
fidl::Clone(view_ref_pair.view_ref, &temp_ref_2);
|
||||
view_ref_clone = std::move(temp_ref);
|
||||
view_ref_clone_2 = std::move(temp_ref_2);
|
||||
} else {
|
||||
fuv_ViewRef view_ref;
|
||||
fidl::Clone(view_ref_pair.view_ref, &view_ref);
|
||||
CreateView(view_id, std::move(view_ref));
|
||||
}
|
||||
|
||||
EXPECT_TRUE(pointer_injector_delegate_->HandlePlatformMessage(
|
||||
PlatformMessageBuilder()
|
||||
.SetViewId(view_id)
|
||||
.SetPointerId(pointer_id)
|
||||
.SetViewRefMaybe(std::move(view_ref_clone))
|
||||
.Build(),
|
||||
response));
|
||||
|
||||
response->ExpectCompleted("[0]");
|
||||
|
||||
// The mock Pointerinjector registry server receives a pointer event from
|
||||
// |f.u.p.Device.Inject| call for the view.
|
||||
RunLoopUntil([this] { return registry_->num_events_received() == 1; });
|
||||
|
||||
// The mock Pointerinjector registry server receives a
|
||||
// |f.u.p.Registry.Register| call for the view.
|
||||
ASSERT_TRUE(registry_->num_register_calls() == 1);
|
||||
|
||||
// Close the device channel.
|
||||
registry_->ClearBindings();
|
||||
RunLoopUntilIdle();
|
||||
|
||||
EXPECT_TRUE(pointer_injector_delegate_->HandlePlatformMessage(
|
||||
PlatformMessageBuilder()
|
||||
.SetViewId(view_id)
|
||||
.SetPointerId(pointer_id)
|
||||
.SetViewRefMaybe(std::move(view_ref_clone_2))
|
||||
.Build(),
|
||||
response_2));
|
||||
|
||||
response_2->ExpectCompleted("[0]");
|
||||
|
||||
// The mock Pointerinjector registry server receives a pointer event from
|
||||
// |f.u.p.Device.Inject| call for the view.
|
||||
RunLoopUntil([this] { return registry_->num_events_received() == 2; });
|
||||
|
||||
// The device tries to register again as the channel got closed.
|
||||
ASSERT_TRUE(registry_->num_register_calls() == 2);
|
||||
}
|
||||
|
||||
INSTANTIATE_TEST_SUITE_P(PointerInjectorDelegateParameterizedTest,
|
||||
PointerInjectorDelegateTest,
|
||||
::testing::Bool());
|
||||
|
||||
@@ -51,6 +51,8 @@ class MockInjectorRegistry : public fuchsia::ui::pointerinjector::Registry,
|
||||
callback();
|
||||
}
|
||||
|
||||
void ClearBindings() { bindings_.clear(); }
|
||||
|
||||
// Returns the |fuchsia::ui::pointerinjector::Config| received in the last
|
||||
// |Register(...)| call.
|
||||
const fuchsia::ui::pointerinjector::Config& config() const { return config_; }
|
||||
|
||||
Reference in New Issue
Block a user