Commit 6cf984ef authored by Sara Kato's avatar Sara Kato Committed by Commit Bot

Return early when output only contains "alert".

On an alert event, 2 alert events are sometimes generated. The
first alert events will read "Alert", while the second wil contain
the actual contents of the alert. This CL prevents such "Alert"
messages from being announced.

Such as case is when a notification in chat app is received, ChromeVox will read
"Alert" "Alert <message>". With this CL, ChromeVox will read
"Alert <message>"".

AX-Relnotes: None
Test: ChromeVoxBackgroundTest.Alert[No]Announcement
Test: manual. Confirm "Alert" for chat notification is read once.
Bug: b:162993006
Change-Id: Ibc661dca9df96da937af165099718f710593fac8
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2341231
Commit-Queue: Sara Kato <sarakato@chromium.org>
Auto-Submit: Sara Kato <sarakato@chromium.org>
Reviewed-by: default avatarDavid Tseng <dtseng@chromium.org>
Reviewed-by: default avatarHiroki Sato <hirokisato@chromium.org>
Cr-Commit-Position: refs/heads/master@{#802121}
parent 0c9e14d6
......@@ -2943,3 +2943,51 @@ TEST_F('ChromeVoxBackgroundTest', 'AudioVideo', function() {
.replay();
});
});
TEST_F('ChromeVoxBackgroundTest', 'AlertNoAnnouncement', function() {
const mockFeedback = this.createMockFeedback();
this.runWithLoadedTree(
`
<button></button>
`,
function(root) {
ChromeVoxState.addObserver(new class {
onCurrentRangeChanged(range) {
assertNotReached('Range was changed unexpectedly.');
}
}());
const button = root.find({role: RoleType.BUTTON});
const alertEvt =
new CustomAutomationEvent(EventType.ALERT, button, '', []);
mockFeedback
.call(DesktopAutomationHandler.instance.onAlert.bind(
DesktopAutomationHandler.instance, alertEvt))
.call(() => assertFalse(mockFeedback.utteranceInQueue('Alert')))
.replay();
});
});
TEST_F('ChromeVoxBackgroundTest', 'AlertAnnouncement', function() {
const mockFeedback = this.createMockFeedback();
this.runWithLoadedTree(
`
<button>hello world</button>
`,
function(root) {
ChromeVoxState.addObserver(new class {
onCurrentRangeChanged(range) {
assertNotReached('Range was changed unexpectedly.');
}
}());
const button = root.find({role: RoleType.BUTTON});
const alertEvt =
new CustomAutomationEvent(EventType.ALERT, button, '', []);
mockFeedback
.call(DesktopAutomationHandler.instance.onAlert.bind(
DesktopAutomationHandler.instance, alertEvt))
.expectSpeech('Alert')
.expectSpeech('hello world')
.replay();
});
});
......@@ -152,10 +152,14 @@ DesktopAutomationHandler = class extends BaseAutomationHandler {
const node = evt.target;
const range = cursors.Range.fromNode(node);
new Output()
.withSpeechCategory(TtsCategory.LIVE)
.withSpeechAndBraille(range, null, evt.type)
.go();
const output = new Output()
.withSpeechCategory(TtsCategory.LIVE)
.withSpeechAndBraille(range, null, evt.type);
// A workaround for alert nodes that contain no actual content.
if (output.toString() != (Msgs.getMsg('role_alert'))) {
output.go();
}
}
onBlur(evt) {
......
......@@ -2091,7 +2091,7 @@ Output = class {
*/
toString() {
return this.speechBuffer_.reduce(function(prev, cur) {
if (prev === null) {
if (prev === null || prev == '') {
return cur.toString();
}
prev += ' ' + cur.toString();
......
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