Commit 2b824e8a authored by Akihiro Ota's avatar Akihiro Ota Committed by Commit Bot

ChromeVox Tutorial: Restart nudges when range changes.

This change fixes an issue where ChromeVox would interrupt itself when
reading text content. The cause for this is that we previously restarted
the nudge timer when a focus event fired. This works for buttons, but
focus events do not fire when range moves between text content.
Instead of restarting nudges when a focus event fires, do so when the
current ChromeVox range changes.

A test is also included to confirm behavior.

Bug: 1141643
Change-Id: I8245e98b40398a1964bf33b1a14e16ff7e6889a9
AX-Relnotes: N/A
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2503635Reviewed-by: default avatarDavid Tseng <dtseng@chromium.org>
Commit-Queue: Akihiro Ota <akihiroota@chromium.org>
Cr-Commit-Position: refs/heads/master@{#822877}
parent 2f43b9fc
......@@ -474,7 +474,6 @@ Polymer({
// Executes once all lessons have been added to the dom.
this.show();
});
this.$.tutorial.addEventListener('focus', this.onFocus.bind(this), true);
this.addEventListener('startpractice', (evt) => {
this.isPracticeAreaActive = true;
this.startNudges(NudgeType.PRACTICE_AREA);
......@@ -870,7 +869,6 @@ Polymer({
}
},
/** @private */
restartNudges() {
this.stopNudges();
this.setNudgeInterval();
......@@ -907,20 +905,6 @@ Polymer({
new CustomEvent('requestfullydescribe', {composed: true}));
},
/**
* @param {Event} evt
* @private
*/
onFocus(evt) {
// Restart nudges whenever focus changes. Skip this for the practice area
// so nudges are given in regular intervals.
if (this.isPracticeAreaActive) {
return;
}
this.restartNudges();
},
/** @return {!TutorialLesson} */
getCurrentLesson() {
return this.includedLessons[this.activeLessonIndex];
......
......@@ -191,6 +191,10 @@ Panel = class {
/** @private {boolean} */
Panel.iTutorialReadyForTesting_ = false;
const background = chrome.extension.getBackgroundPage()['ChromeVoxState'];
Panel.observer_ = new Panel.PanelStateObserver();
background.addObserver(Panel.observer_);
}
/**
......@@ -1331,6 +1335,22 @@ Panel = class {
}
};
/**
* An observer that reacts to ChromeVox range changes.
* @implements {ChromeVoxStateObserver}
*/
Panel.PanelStateObserver = class {
constructor() {}
onCurrentRangeChanged(range) {
if (Panel.mode_ === Panel.Mode.FULLSCREEN_I_TUTORIAL) {
if (Panel.iTutorial && Panel.iTutorial.restartNudges) {
Panel.iTutorial.restartNudges();
}
}
}
};
/**
* @enum {string}
*/
......@@ -1372,6 +1392,11 @@ Panel.ACTION_TO_MSG_ID = {
*/
Panel.lastMenu_ = '';
/**
* @private {ChromeVoxStateObserver}
*/
Panel.observer_ = null;
window.addEventListener('load', function() {
Panel.init();
......
......@@ -557,3 +557,46 @@ TEST_F('ChromeVoxTutorialTest', 'QuickOrientationLessonTest', function() {
.replay();
});
});
// Tests that tutorial nudges are restarted whenever the current range changes.
TEST_F('ChromeVoxTutorialTest', 'RestartNudges', function() {
this.runWithLoadedTree(this.simpleDoc, async function(root) {
await this.launchAndWaitForTutorial();
const tutorial = this.getPanel().iTutorial;
let restart = false;
// Swap in below function to track when nudges get restarted.
tutorial.restartNudges = () => {
restart = true;
};
const waitForRestartNudges = async () => {
return new Promise(resolve => {
let intervalId;
const nudgesRestarted = () => {
return restart;
};
if (nudgesRestarted()) {
resolve();
} else {
intervalId = setInterval(() => {
if (nudgesRestarted()) {
clearInterval(intervalId);
resolve();
}
}, 500);
}
});
};
restart = false;
CommandHandler.onCommand('nextObject');
await waitForRestartNudges();
// Show a lesson.
tutorial.curriculum = 'essential_keys';
tutorial.showLesson(0);
restart = false;
CommandHandler.onCommand('nextObject');
await waitForRestartNudges();
restart = false;
CommandHandler.onCommand('nextObject');
await waitForRestartNudges();
});
});
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