Commit c8fb7466 authored by Lei Shi's avatar Lei Shi Committed by Chromium LUCI CQ

Address the issue of invalidated nodes in Select to Speak

When a user resize or change a webpage, the selected inline nodes may be
invalidated. To address this issue, we reuse the prior STS logic, which
converts all selected content into node groups. Then, we send the node
groups to TTS one by one. The only entry point for reading new content
will be startSpeechQueue_, which uses updateNodeGroups_ to convert nodes
into node groups, and start TTS using startCurrentNodeGroup_.

This CL also refactored the names of variables and removed unnecessary
variables. The prior CLs (http://crrev.com/c/2582524,
http://crrev.com/c/2587799, and http://crrev.com/c/2587820) have
modified navigation features so that they do not rely on
navigationState_ anymore.Thus I implement the following rename and
refactor:
1. Rename this.currentNode_ to this.currentNodeGroupItem_ since the
variable is actually for a node group item.
2. Rename this.currentNodeGroupIndex_ to this.currentNodeGroupItemIndex_
since the variable is meant to be the index for node group item.
3. Add this.currentNodeGroups_ and this.currentNodeGroupIndex_, which
are used for tracking the selected node groups and the current speaking
node group.
4. Refactor this.navigationState_.currentCharIndex and
this.navigationState_.isUserSelectContent. to this.currentCharIndex_ and
this.isUserSelectContent_ to keep code concise.

Also, we added a test for the case of invalidated nodes. Test credits to
joelriley@google.com.

Bug: 1160004
Change-Id: I92e0a1acc25265df476ea248be39d05ec06726d6
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2587565
Commit-Queue: Lei Shi <leileilei@google.com>
Reviewed-by: default avatarDavid Tseng <dtseng@chromium.org>
Cr-Commit-Position: refs/heads/master@{#839018}
parent 6de88b2e
......@@ -587,4 +587,54 @@ TEST_F(
this.assertEqualsCollapseWhitespace(
this.mockTts.pendingUtterances()[0], '. Sentence two.');
});
});
\ No newline at end of file
});
TEST_F('SelectToSpeakNavigationControlTest', 'ResizeWhilePlaying', function() {
const longLine =
'Second paragraph is longer than 300 pixels and will wrap when resized';
const bodyHtml = `
<script type="text/javascript">
function doResize() {
document.getElementById('resize').style.width = '100px';
}
</script>
<div id="content">
<p>First paragraph</p>
<p id='resize' style='width:300px; font-size: 1em'>
${longLine}
</p>
</div>
<button onclick="doResize()">Resize</button>
`;
this.runWithLoadedTree(
this.generateHtmlWithSelectedElement('content', bodyHtml), (root) => {
this.triggerReadSelectedText();
// Speaks the first paragraph.
assertTrue(this.mockTts.currentlySpeaking());
assertEquals(this.mockTts.pendingUtterances().length, 1);
this.assertEqualsCollapseWhitespace(
this.mockTts.pendingUtterances()[0], 'First paragraph');
const resizeButton =
root.find({role: 'button', attributes: {name: 'Resize'}});
// Wait for click event, at which point the automation tree should
// be updated from the resize.
resizeButton.addEventListener(
EventType.CLICKED, this.newCallback(() => {
// Trigger next node group by completing first TTS request.
this.mockTts.finishPendingUtterance();
// Should still read second paragraph, even though some nodes
// were invalided from the resize.
assertTrue(this.mockTts.currentlySpeaking());
assertEquals(this.mockTts.pendingUtterances().length, 1);
this.assertEqualsCollapseWhitespace(
this.mockTts.pendingUtterances()[0], longLine);
}));
// Perform resize.
resizeButton.doDefault();
});
});
\ No newline at end of file
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