Commit f83fa468 authored by dtseng's avatar dtseng Committed by Commit bot

Always enqueue live regions from background tabs

In the case where a very lengthy live region fires on a foreground tab, and a background live region fires, don't interrupt the first live region.

Also, note that a background webView does lose focus state (even when focus goes to a new window).

BUG=619280
CQ_INCLUDE_TRYBOTS=master.tryserver.chromium.linux:closure_compilation

Review-Url: https://codereview.chromium.org/2388193003
Cr-Commit-Position: refs/heads/master@{#422609}
parent 4030de34
......@@ -240,27 +240,6 @@ AutomationUtil.isInSameTree = function(a, b) {
(a.root.role == b.root.role && a.root.role == RoleType.rootWebArea);
};
/**
* Determines whether the two given nodes come from the same webpage.
* @param {AutomationNode} a
* @param {AutomationNode} b
* @return {boolean}
*/
AutomationUtil.isInSameWebpage = function(a, b) {
if (!a || !b)
return false;
a = a.root;
while (a && a.parent && AutomationUtil.isInSameTree(a.parent, a))
a = a.parent.root;
b = b.root;
while (b && b.parent && AutomationUtil.isInSameTree(b.parent, b))
b = b.parent.root;
return a == b;
};
/**
* Determines whether or not a node is or is the descendant of another node.
* @param {!AutomationNode} node
......
......@@ -137,62 +137,6 @@ TEST_F('AutomationUtilE2ETest', 'GetDirection', function() {
});
});
TEST_F('AutomationUtilE2ETest', 'IsInSameWebpage', function() {
this.runWithLoadedTree(this.basicDoc, function(root) {
this.runWithLoadedTree(this.secondDoc, function(root2) {
chrome.automation.getDesktop(this.newCallback(function(desktop) {
assertTrue(AutomationUtil.isInSameWebpage(root, root));
assertTrue(AutomationUtil.isInSameWebpage(root.firstChild, root));
assertTrue(AutomationUtil.isInSameWebpage(root, root.firstChild));
assertTrue(AutomationUtil.isInSameWebpage(root2, root2));
assertTrue(AutomationUtil.isInSameWebpage(root2.firstChild, root2));
assertTrue(AutomationUtil.isInSameWebpage(root2, root2.firstChild));
assertFalse(AutomationUtil.isInSameWebpage(root, root2));
assertFalse(AutomationUtil.isInSameWebpage(root.firstChild, root2));
assertFalse(AutomationUtil.isInSameWebpage(root2.firstChild));
assertFalse(AutomationUtil.isInSameWebpage(
root.firstChild, root2.firstChild));
assertFalse(AutomationUtil.isInSameWebpage(root, desktop));
assertFalse(AutomationUtil.isInSameWebpage(root2, desktop));
}.bind(this)));
}.bind(this));
}.bind(this));
});
TEST_F('AutomationUtilE2ETest', 'IsInSameWebpageIframe', function() {
// Wait for load complete on both outer frame and iframe.
var outerFrame;
var innerFrame;
var desktop;
var onSuccess = this.newCallback(function() {
assertTrue(AutomationUtil.isInSameWebpage(outerFrame, innerFrame));
assertFalse(AutomationUtil.isInSameWebpage(outerFrame, desktop));
assertFalse(AutomationUtil.isInSameWebpage(innerFrame, desktop));
assertFalse(AutomationUtil.isInSameWebpage(outerFrame.parent, innerFrame));
}.bind(this));
chrome.automation.getDesktop(function(r) {
desktop = r;
this.runWithTab(this.iframeDoc, function(newTabUrl) {
var listener = function(evt) {
if (evt.target.docUrl == newTabUrl)
outerFrame = evt.target;
if (evt.target.docUrl.indexOf('data:text/html') == 0)
innerFrame = evt.target;
if (outerFrame && innerFrame) {
desktop.removeEventListener('loadComplete', listener, true);
onSuccess();
}
}.bind(this);
desktop.addEventListener('loadComplete', listener, true);
}.bind(this));
}.bind(this));
});
TEST_F('AutomationUtilE2ETest', 'VisitContainer', function() {
this.runWithLoadedTree(toolbarDoc, function(r) {
var pred = function(n) { return n.role != 'rootWebArea'; };
......
......@@ -12,6 +12,7 @@ goog.require('ChromeVoxState');
goog.scope(function() {
var AutomationNode = chrome.automation.AutomationNode;
var RoleType = chrome.automation.RoleType;
var TreeChange = chrome.automation.TreeChange;
/**
......@@ -87,8 +88,11 @@ LiveRegions.prototype = {
if (!currentRange)
return;
var webView = AutomationUtil.getTopLevelRoot(node);
webView = webView ? webView.parent : null;
if (!LiveRegions.announceLiveRegionsFromBackgroundTabs_ &&
!AutomationUtil.isInSameWebpage(node, currentRange.start.node)) {
currentRange.start.node.role != RoleType.desktop &&
(!webView || !webView.state.focused)) {
return;
}
......@@ -140,11 +144,17 @@ LiveRegions.prototype = {
if (!output.hasSpeech)
return;
// Queue live regions coming from background tabs.
var webView = AutomationUtil.getTopLevelRoot(node);
webView = webView ? webView.parent : null;
var forceQueueForBackgroundedLiveRegion =
!webView || !webView.state.focused;
// Enqueue live region updates that were received at approximately
// the same time, otherwise flush previous live region updates.
var queueTime = LiveRegions.LIVE_REGION_QUEUE_TIME_MS;
var delta = currentTime - this.lastLiveRegionTime_;
if (delta > queueTime)
if (delta > queueTime && !forceQueueForBackgroundedLiveRegion)
output.withQueueMode(cvox.QueueMode.CATEGORY_FLUSH);
else
output.withQueueMode(cvox.QueueMode.QUEUE);
......
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