Commit 6626c4c1 authored by dmazzoni's avatar dmazzoni Committed by Commit bot

ChromeVox should not speak live regions that aren't in the document.

The underlying issue is that by the time we get around to processing a live
region node from a mutation observer, the node may no longer be part of
the DOM, in which case we should treat it as invisible.

To fix it, fix cvox.DomUtil.hasInvisibleAncestor_ so that it returns
true (invisible) if passed an element that's not actually part of the
document.

BUG=408821

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

Cr-Commit-Position: refs/heads/master@{#292847}
parent d90378f3
......@@ -193,7 +193,8 @@ cvox.DomUtil.computeIsVisible_ = function(
/**
* Checks the ancestor chain for the given node for invisibility. If an
* ancestor is invisible and this cannot be overriden by a descendant,
* we return true.
* we return true. If the element is not a descendant of the document
* element it will return true (invisible).
* @param {Node} node The node to check the ancestor chain for.
* @return {boolean} True if a descendant is invisible.
* @private
......@@ -205,8 +206,15 @@ cvox.DomUtil.hasInvisibleAncestor_ = function(node) {
if (cvox.DomUtil.isInvisibleStyle(style, true)) {
return true;
}
// Once we reach the document element and we haven't found anything
// invisible yet, we're done. If we exit the while loop and never found
// the document element, the element wasn't part of the DOM and thus it's
// invisible.
if (ancestor == document.documentElement) {
return false;
}
}
return false;
return true;
};
......
......@@ -141,6 +141,12 @@ TEST_F('CvoxDomUtilUnitTest', 'IsVisible', function() {
node = $('nested_visibility_hide');
assertEquals(false,
cvox.DomUtil.isVisible(node, {checkDescendants: false}));
// Test that an element not part of the DOM is treated as invisible.
var div = document.createElement('div');
assertEquals(false, cvox.DomUtil.isVisible(div));
document.body.appendChild(div);
assertEquals(true, cvox.DomUtil.isVisible(div));
});
/** Test determining if a node is a leaf node or not. @export */
......
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