Bug 1298436 - Don't get caught in an endless loop when narrating last paragraph. r=jaws

MozReview-Commit-ID: 7SMh0MGusgM

--HG--
extra : rebase_source : 03f3c0c9d4b3de248f39e7d013e34df0260594a3
This commit is contained in:
Eitan Isaacson 2016-08-27 14:42:51 -07:00
parent ae1f9fd8ec
commit 57a244c4d9
2 changed files with 12 additions and 6 deletions

View File

@ -144,8 +144,8 @@ Narrator.prototype = {
this._win.speechSynthesis.cancel();
let tw = this._treeWalker;
let paragraph = tw.currentNode;
if (!paragraph) {
tw.currentNode = tw.root;
if (paragraph == tw.root) {
this._sendTestEvent("paragraphsdone", {});
return Promise.resolve();
}
@ -193,7 +193,7 @@ Narrator.prototype = {
// User pressed stopped.
resolve();
} else {
tw.nextNode();
tw.currentNode = tw.nextNode() || tw.root;
this._speakInner().then(resolve, reject);
}
});

View File

@ -118,9 +118,15 @@ add_task(function* testNarrate() {
ok(!NarrateTestUtils.isVisible(popup), "popup is dismissed while speaking");
NarrateTestUtils.isStartedState(content, ok);
promiseEvent = ContentTaskUtils.waitForEvent(content, "paragraphend");
$(NarrateTestUtils.STOP).click();
yield promiseEvent;
// Go forward all the way to the end of the article. We should eventually
// stop.
do {
promiseEvent = Promise.race([
ContentTaskUtils.waitForEvent(content, "paragraphstart"),
ContentTaskUtils.waitForEvent(content, "paragraphsdone")]);
$(NarrateTestUtils.FORWARD).click();
} while ((yield promiseEvent).type == "paragraphstart");
yield ContentTaskUtils.waitForCondition(
() => !$(NarrateTestUtils.STOP), "transitioned to stopped state");
NarrateTestUtils.isStoppedState(content, ok);