Commit 023ea721 authored by Sharon Yang's avatar Sharon Yang Committed by Commit Bot

[fucshia] Remove pending_accessibility_action_callbacks_ map

* Handle OnAccessibilityActionRequestedCallback once action has been
  dispatched
* Remove map because guarantees aren't provided for if actions will
  return.

Test: AccessibilityBridgeTest.PerformDefaultAction
Bug: 1111141
Change-Id: Ib8242be381f0336d312b9e205abe173636cf956e
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2328052Reviewed-by: default avatarKevin Marshall <kmarshall@chromium.org>
Commit-Queue: Sharon Yang <yangsharon@chromium.org>
Cr-Commit-Position: refs/heads/master@{#795251}
parent 1c26b3cb
...@@ -26,20 +26,20 @@ AccessibilityBridge::AccessibilityBridge( ...@@ -26,20 +26,20 @@ AccessibilityBridge::AccessibilityBridge(
fuchsia::accessibility::semantics::SemanticsManagerPtr semantics_manager, fuchsia::accessibility::semantics::SemanticsManagerPtr semantics_manager,
fuchsia::ui::views::ViewRef view_ref, fuchsia::ui::views::ViewRef view_ref,
content::WebContents* web_contents, content::WebContents* web_contents,
base::OnceCallback<void(zx_status_t)> on_disconnect_callback) base::OnceCallback<void(zx_status_t)> on_error_callback)
: binding_(this), web_contents_(web_contents) { : binding_(this),
web_contents_(web_contents),
on_error_callback_(std::move(on_error_callback)) {
DCHECK(web_contents_); DCHECK(web_contents_);
Observe(web_contents_); Observe(web_contents_);
tree_.AddObserver(this); tree_.AddObserver(this);
semantics_manager->RegisterViewForSemantics( semantics_manager->RegisterViewForSemantics(
std::move(view_ref), binding_.NewBinding(), tree_ptr_.NewRequest()); std::move(view_ref), binding_.NewBinding(), tree_ptr_.NewRequest());
tree_ptr_.set_error_handler( tree_ptr_.set_error_handler([this](zx_status_t status) mutable {
[disconnect_callback = ZX_LOG(ERROR, status) << "SemanticTree disconnected";
std::move(on_disconnect_callback)](zx_status_t status) mutable { std::move(on_error_callback_).Run(ZX_ERR_INTERNAL);
ZX_LOG(ERROR, status) << "SemanticTree disconnected"; });
std::move(disconnect_callback).Run(ZX_ERR_INTERNAL);
});
} }
AccessibilityBridge::~AccessibilityBridge() { AccessibilityBridge::~AccessibilityBridge() {
...@@ -50,11 +50,6 @@ AccessibilityBridge::~AccessibilityBridge() { ...@@ -50,11 +50,6 @@ AccessibilityBridge::~AccessibilityBridge() {
hit.set_node_id(kSemanticNodeRootId); hit.set_node_id(kSemanticNodeRootId);
callback.second(std::move(hit)); callback.second(std::move(hit));
} }
pending_hit_test_callbacks_.clear();
for (auto& callback : pending_accessibility_action_callbacks_)
callback.second(false);
pending_accessibility_action_callbacks_.clear();
} }
void AccessibilityBridge::TryCommit() { void AccessibilityBridge::TryCommit() {
...@@ -131,7 +126,12 @@ void AccessibilityBridge::AccessibilityEventReceived( ...@@ -131,7 +126,12 @@ void AccessibilityBridge::AccessibilityEventReceived(
const content::AXEventNotificationDetails& details) { const content::AXEventNotificationDetails& details) {
// Updates to AXTree must be applied first. // Updates to AXTree must be applied first.
for (const ui::AXTreeUpdate& update : details.updates) { for (const ui::AXTreeUpdate& update : details.updates) {
tree_.Unserialize(update); if (!tree_.Unserialize(update)) {
// If this fails, it is a fatal error that will cause the current Frame to
// be destroyed.
std::move(on_error_callback_).Run(ZX_ERR_INTERNAL);
return;
}
} }
// Events to fire after tree has been updated. // Events to fire after tree has been updated.
...@@ -147,13 +147,6 @@ void AccessibilityBridge::AccessibilityEventReceived( ...@@ -147,13 +147,6 @@ void AccessibilityBridge::AccessibilityEventReceived(
pending_hit_test_callbacks_.erase(event.action_request_id); pending_hit_test_callbacks_.erase(event.action_request_id);
} }
} }
// Run callbacks associated with other accessibility events.
if (pending_accessibility_action_callbacks_.find(event.id) !=
pending_accessibility_action_callbacks_.end()) {
pending_accessibility_action_callbacks_[event.id](true);
pending_accessibility_action_callbacks_.erase(event.id);
}
} }
} }
...@@ -169,15 +162,9 @@ void AccessibilityBridge::OnAccessibilityActionRequested( ...@@ -169,15 +162,9 @@ void AccessibilityBridge::OnAccessibilityActionRequested(
} }
action_data.target_node_id = node_id; action_data.target_node_id = node_id;
pending_accessibility_action_callbacks_[node_id] = std::move(callback);
// Allow tests to bypass action handling to simulate the case that actions
// aren't handled in tests.
if (!handle_actions_for_test_) {
return;
}
web_contents_->GetMainFrame()->AccessibilityPerformAction(action_data); web_contents_->GetMainFrame()->AccessibilityPerformAction(action_data);
callback(true);
} }
void AccessibilityBridge::HitTest(fuchsia::math::PointF local_point, void AccessibilityBridge::HitTest(fuchsia::math::PointF local_point,
......
...@@ -43,16 +43,12 @@ class WEB_ENGINE_EXPORT AccessibilityBridge ...@@ -43,16 +43,12 @@ class WEB_ENGINE_EXPORT AccessibilityBridge
fuchsia::accessibility::semantics::SemanticsManagerPtr semantics_manager, fuchsia::accessibility::semantics::SemanticsManagerPtr semantics_manager,
fuchsia::ui::views::ViewRef view_ref, fuchsia::ui::views::ViewRef view_ref,
content::WebContents* web_contents, content::WebContents* web_contents,
base::OnceCallback<void(zx_status_t)> on_disconnect_callback); base::OnceCallback<void(zx_status_t)> on_error_callback);
~AccessibilityBridge() final; ~AccessibilityBridge() final;
AccessibilityBridge(const AccessibilityBridge&) = delete; AccessibilityBridge(const AccessibilityBridge&) = delete;
AccessibilityBridge& operator=(const AccessibilityBridge&) = delete; AccessibilityBridge& operator=(const AccessibilityBridge&) = delete;
void set_handle_actions_for_test(bool handle) {
handle_actions_for_test_ = handle;
}
private: private:
FRIEND_TEST_ALL_PREFIXES(AccessibilityBridgeTest, OnSemanticsModeChanged); FRIEND_TEST_ALL_PREFIXES(AccessibilityBridgeTest, OnSemanticsModeChanged);
...@@ -127,15 +123,12 @@ class WEB_ENGINE_EXPORT AccessibilityBridge ...@@ -127,15 +123,12 @@ class WEB_ENGINE_EXPORT AccessibilityBridge
// These are keyed by the request_id field of ui::AXActionData. // These are keyed by the request_id field of ui::AXActionData.
base::flat_map<int, HitTestCallback> pending_hit_test_callbacks_; base::flat_map<int, HitTestCallback> pending_hit_test_callbacks_;
// Maintain a map of callbacks for accessibility actions. Entries are keyed by // Run in the case of an internal error that cannot be recovered from. This
// node id the action is performed on. // will cause the frame |this| is owned by to be torn down.
base::flat_map<int, OnAccessibilityActionRequestedCallback> base::OnceCallback<void(zx_status_t)> on_error_callback_;
pending_accessibility_action_callbacks_;
// The root id of |tree_|. // The root id of |tree_|.
int32_t root_id_ = 0; int32_t root_id_ = 0;
bool handle_actions_for_test_ = true;
}; };
#endif // FUCHSIA_ENGINE_BROWSER_ACCESSIBILITY_BRIDGE_H_ #endif // FUCHSIA_ENGINE_BROWSER_ACCESSIBILITY_BRIDGE_H_
...@@ -231,16 +231,6 @@ IN_PROC_BROWSER_TEST_F(AccessibilityBridgeTest, PerformDefaultAction) { ...@@ -231,16 +231,6 @@ IN_PROC_BROWSER_TEST_F(AccessibilityBridgeTest, PerformDefaultAction) {
semantics_manager_.RequestAccessibilityAction( semantics_manager_.RequestAccessibilityAction(
button2->node_id(), fuchsia::accessibility::semantics::Action::DEFAULT); button2->node_id(), fuchsia::accessibility::semantics::Action::DEFAULT);
semantics_manager_.RunUntilNumActionsHandledEquals(2); semantics_manager_.RunUntilNumActionsHandledEquals(2);
// Handle the case that actions are still in flight when AccessibilityBridge
// gets torn down. The corresponding callbacks should still be run.
frame_impl_->set_handle_actions_for_test(false);
semantics_manager_.RequestAccessibilityAction(
button3->node_id(), fuchsia::accessibility::semantics::Action::DEFAULT);
frame_ptr_.Unbind();
base::RunLoop().RunUntilIdle();
EXPECT_EQ(2, semantics_manager_.num_actions_handled());
EXPECT_EQ(1, semantics_manager_.num_actions_unhandled());
} }
IN_PROC_BROWSER_TEST_F(AccessibilityBridgeTest, PerformUnsupportedAction) { IN_PROC_BROWSER_TEST_F(AccessibilityBridgeTest, PerformUnsupportedAction) {
......
...@@ -83,9 +83,6 @@ class FrameImpl : public fuchsia::web::Frame, ...@@ -83,9 +83,6 @@ class FrameImpl : public fuchsia::web::Frame,
semantics_manager) { semantics_manager) {
semantics_manager_for_test_ = std::move(semantics_manager); semantics_manager_for_test_ = std::move(semantics_manager);
} }
void set_handle_actions_for_test(bool handle) {
accessibility_bridge_->set_handle_actions_for_test(handle);
}
CastStreamingSessionClient* cast_streaming_session_client_for_test() { CastStreamingSessionClient* cast_streaming_session_client_for_test() {
return cast_streaming_session_client_.get(); return cast_streaming_session_client_.get();
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment