diff --git a/toolkit/components/narrate/Narrator.jsm b/toolkit/components/narrate/Narrator.jsm index cfeb660fabe4..c2c22e15117b 100644 --- a/toolkit/components/narrate/Narrator.jsm +++ b/toolkit/components/narrate/Narrator.jsm @@ -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); } }); diff --git a/toolkit/components/narrate/test/browser_narrate.js b/toolkit/components/narrate/test/browser_narrate.js index 7f4332d04d80..a568dd62ce58 100644 --- a/toolkit/components/narrate/test/browser_narrate.js +++ b/toolkit/components/narrate/test/browser_narrate.js @@ -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);