Commit 6b6ff172 authored by dmazzoni@chromium.org's avatar dmazzoni@chromium.org

Ignore accessibility events fired on objects that aren't in the tree.

BUG=371039

Review URL: https://codereview.chromium.org/275503002

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@271251 0039d316-1c4b-4281-b951-d872f2087c98
parent 6762c8bc
...@@ -49,6 +49,7 @@ RendererAccessibilityTest.EditableTextModeFocusEvents ...@@ -49,6 +49,7 @@ RendererAccessibilityTest.EditableTextModeFocusEvents
DumpAccessibilityTreeTest.AccessibilityDialog DumpAccessibilityTreeTest.AccessibilityDialog
DumpAccessibilityTreeTest.AccessibilityModalDialogClosed DumpAccessibilityTreeTest.AccessibilityModalDialogClosed
DumpAccessibilityTreeTest.AccessibilityModalDialogInIframeOpened DumpAccessibilityTreeTest.AccessibilityModalDialogInIframeOpened
RendererAccessibilityTest.EventOnObjectNotInTree
# http://crbug.com/187500 # http://crbug.com/187500
RenderViewImplTest.* RenderViewImplTest.*
......
...@@ -100,6 +100,16 @@ BlinkAXTreeSource::BlinkAXTreeSource(RenderViewImpl* render_view) ...@@ -100,6 +100,16 @@ BlinkAXTreeSource::BlinkAXTreeSource(RenderViewImpl* render_view)
BlinkAXTreeSource::~BlinkAXTreeSource() { BlinkAXTreeSource::~BlinkAXTreeSource() {
} }
bool BlinkAXTreeSource::IsInTree(blink::WebAXObject node) const {
const blink::WebAXObject& root = GetRoot();
while (IsValid(node)) {
if (node.equals(root))
return true;
node = GetParent(node);
}
return false;
}
blink::WebAXObject BlinkAXTreeSource::GetRoot() const { blink::WebAXObject BlinkAXTreeSource::GetRoot() const {
return GetMainDocument().accessibilityObject(); return GetMainDocument().accessibilityObject();
} }
......
...@@ -19,6 +19,9 @@ class BlinkAXTreeSource ...@@ -19,6 +19,9 @@ class BlinkAXTreeSource
BlinkAXTreeSource(RenderViewImpl* render_view); BlinkAXTreeSource(RenderViewImpl* render_view);
virtual ~BlinkAXTreeSource(); virtual ~BlinkAXTreeSource();
// Walks up the ancestor chain to see if this is a descendant of the root.
bool IsInTree(blink::WebAXObject node) const;
// AXTreeSource implementation. // AXTreeSource implementation.
virtual blink::WebAXObject GetRoot() const OVERRIDE; virtual blink::WebAXObject GetRoot() const OVERRIDE;
virtual blink::WebAXObject GetFromId(int32 id) const OVERRIDE; virtual blink::WebAXObject GetFromId(int32 id) const OVERRIDE;
......
...@@ -516,4 +516,38 @@ TEST_F(RendererAccessibilityTest, DetachAccessibilityObject) { ...@@ -516,4 +516,38 @@ TEST_F(RendererAccessibilityTest, DetachAccessibilityObject) {
// so we don't have a test expectation for it. // so we don't have a test expectation for it.
} }
TEST_F(RendererAccessibilityTest, EventOnObjectNotInTree) {
// Test RendererAccessibilityComplete and make sure it doesn't send anything
// if we get a notification from Blink for an object that isn't in the
// tree, like the scroll area that's the parent of the main document,
// which we don't expose.
std::string html = "<body><input></body>";
LoadHTML(html.c_str());
scoped_ptr<TestRendererAccessibilityComplete> accessibility(
new TestRendererAccessibilityComplete(view()));
accessibility->SendPendingAccessibilityEvents();
EXPECT_EQ(3, CountAccessibilityNodesSentToBrowser());
WebDocument document = view()->GetWebView()->mainFrame()->document();
WebAXObject root_obj = document.accessibilityObject();
WebAXObject scroll_area = root_obj.parentObject();
EXPECT_EQ(blink::WebAXRoleScrollArea, scroll_area.role());
// Try to fire a message on the scroll area, and assert that we just
// ignore it.
sink_->ClearMessages();
accessibility->HandleAXEvent(scroll_area,
ui::AX_EVENT_VALUE_CHANGED);
accessibility->SendPendingAccessibilityEvents();
const IPC::Message* message =
sink_->GetUniqueMessageMatching(AccessibilityHostMsg_Events::ID);
ASSERT_TRUE(message);
Tuple1<std::vector<AccessibilityHostMsg_EventParams> > param;
AccessibilityHostMsg_Events::Read(message, &param);
ASSERT_EQ(0U, param.a.size());
}
} // namespace content } // namespace content
...@@ -184,8 +184,14 @@ void RendererAccessibilityComplete::SendPendingAccessibilityEvents() { ...@@ -184,8 +184,14 @@ void RendererAccessibilityComplete::SendPendingAccessibilityEvents() {
WebAXObject obj = document.accessibilityObjectFromID( WebAXObject obj = document.accessibilityObjectFromID(
event.id); event.id);
// Make sure the object still exists.
if (!obj.updateBackingStoreAndCheckValidity()) if (!obj.updateBackingStoreAndCheckValidity())
continue; continue;
// Make sure it's a descendant of our root node - exceptions include the
// scroll area that's the parent of the main document (we ignore it), and
// possibly nodes attached to a different document.
if (!tree_source_.IsInTree(obj))
continue;
// When we get a "selected children changed" event, Blink // When we get a "selected children changed" event, Blink
// doesn't also send us events for each child that changed // doesn't also send us events for each child that changed
......
...@@ -72,16 +72,6 @@ class CONTENT_EXPORT RendererAccessibilityComplete ...@@ -72,16 +72,6 @@ class CONTENT_EXPORT RendererAccessibilityComplete
void OnSetTextSelection(int acc_obj_id, int start_offset, int end_offset); void OnSetTextSelection(int acc_obj_id, int start_offset, int end_offset);
void OnFatalError(); void OnFatalError();
// Checks if a Blink accessibility object is an editable text node.
bool IsEditableText(const blink::WebAXObject& node);
// Recursively explore the tree of Blink accessibility objects rooted
// at |src|, and for each editable text node encountered, add a
// corresponding WebAccessibility node as a child of |dst|.
void RecursiveAddEditableTextNodesToTree(
const blink::WebAXObject& src,
ui::AXNodeData* dst);
// So we can queue up tasks to be executed later. // So we can queue up tasks to be executed later.
base::WeakPtrFactory<RendererAccessibilityComplete> weak_factory_; base::WeakPtrFactory<RendererAccessibilityComplete> weak_factory_;
......
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