Bug 1310448 - Wait for narrate button to appear before starting tests. r?Gijs draft
authorEitan Isaacson <eitan@monotonous.org>
Mon, 17 Oct 2016 12:17:39 -0700
changeset 426083 261fbb5c161aa1569a6f84d7d859f5712cd1e4b5
parent 425306 cb2dd5a34dd7b374500fedd72fe19df13c9a7a4d
child 534089 ce1bb07bcf927f01773b5b7e6b56aa5bcb6c4a6e
push id32613
push userbmo:eitan@monotonous.org
push dateMon, 17 Oct 2016 19:21:09 +0000
reviewersGijs
bugs1310448
milestone52.0a1
Bug 1310448 - Wait for narrate button to appear before starting tests. r?Gijs MozReview-Commit-ID: 8MPzdZvAT1
toolkit/components/narrate/test/NarrateTestUtils.jsm
toolkit/components/narrate/test/browser_narrate.js
toolkit/components/narrate/test/browser_narrate_language.js
toolkit/components/narrate/test/browser_voiceselect.js
toolkit/components/narrate/test/browser_word_highlight.js
--- a/toolkit/components/narrate/test/NarrateTestUtils.jsm
+++ b/toolkit/components/narrate/test/NarrateTestUtils.jsm
@@ -103,22 +103,20 @@ this.NarrateTestUtils = {
       if (window.document.body.classList.contains("loaded")) {
         resolve();
       } else {
         Services.obs.addObserver(observeReady, "AboutReader:Ready", false);
       }
     });
   },
 
-  waitForVoiceOptions: function(window) {
-    let options = window.document.querySelector(this.VOICE_OPTIONS);
+  waitForNarrateToggle: function(window) {
+    let toggle = window.document.querySelector(this.TOGGLE);
     return ContentTaskUtils.waitForCondition(
-      () => {
-        return options.childElementCount > 1;
-      }, "voice select options populated.");
+      () => !toggle.hidden, "");
   },
 
   waitForPrefChange: function(pref) {
     return new Promise(resolve => {
       function observeChange() {
         Services.prefs.removeObserver(pref, observeChange);
         resolve(Preferences.get(pref));
       }
--- a/toolkit/components/narrate/test/browser_narrate.js
+++ b/toolkit/components/narrate/test/browser_narrate.js
@@ -10,26 +10,26 @@ registerCleanupFunction(teardown);
 
 add_task(function* testNarrate() {
   setup();
 
   yield spawnInNewReaderTab(TEST_ARTICLE, function* () {
     let TEST_VOICE = "urn:moz-tts:fake-indirect:teresa";
     let $ = content.document.querySelector.bind(content.document);
 
+    yield NarrateTestUtils.waitForNarrateToggle(content);
+
     let popup = $(NarrateTestUtils.POPUP);
     ok(!NarrateTestUtils.isVisible(popup), "popup is initially hidden");
 
     let toggle = $(NarrateTestUtils.TOGGLE);
     toggle.click();
 
     ok(NarrateTestUtils.isVisible(popup), "popup toggled");
 
-    yield NarrateTestUtils.waitForVoiceOptions(content);
-
     let voiceOptions = $(NarrateTestUtils.VOICE_OPTIONS);
     ok(!NarrateTestUtils.isVisible(voiceOptions),
       "voice options are initially hidden");
 
     $(NarrateTestUtils.VOICE_SELECT).click();
     ok(NarrateTestUtils.isVisible(voiceOptions), "voice options pop up");
 
     let prefChanged = NarrateTestUtils.waitForPrefChange("narrate.voice");
--- a/toolkit/components/narrate/test/browser_narrate_language.js
+++ b/toolkit/components/narrate/test/browser_narrate_language.js
@@ -9,17 +9,17 @@
 registerCleanupFunction(teardown);
 
 add_task(function* testVoiceselectDropdownAutoclose() {
   setup("automatic", true);
 
   yield spawnInNewReaderTab(TEST_ARTICLE, function* () {
     let $ = content.document.querySelector.bind(content.document);
 
-    yield NarrateTestUtils.waitForVoiceOptions(content);
+    yield NarrateTestUtils.waitForNarrateToggle(content);
 
     ok(!!$(".option[data-value='urn:moz-tts:fake-direct:bob']"),
       "Jamaican English voice available");
     ok(!!$(".option[data-value='urn:moz-tts:fake-direct:lenny']"),
       "Canadian English voice available");
     ok(!!$(".option[data-value='urn:moz-tts:fake-direct:amy']"),
       "British English voice available");
 
@@ -41,17 +41,17 @@ add_task(function* testVoiceselectDropdo
 });
 
 add_task(function* testVoiceselectDropdownAutoclose() {
   setup("automatic", true);
 
   yield spawnInNewReaderTab(TEST_ITALIAN_ARTICLE, function* () {
     let $ = content.document.querySelector.bind(content.document);
 
-    yield NarrateTestUtils.waitForVoiceOptions(content);
+    yield NarrateTestUtils.waitForNarrateToggle(content);
 
     ok(!!$(".option[data-value='urn:moz-tts:fake-indirect:zanetta']"),
       "Italian voice available");
     ok(!!$(".option[data-value='urn:moz-tts:fake-indirect:margherita']"),
       "Italian voice available");
 
     ok(!$(".option[data-value='urn:moz-tts:fake-direct:bob']"),
       "Jamaican English voice available");
--- a/toolkit/components/narrate/test/browser_voiceselect.js
+++ b/toolkit/components/narrate/test/browser_voiceselect.js
@@ -9,17 +9,17 @@
 registerCleanupFunction(teardown);
 
 add_task(function* testVoiceselectDropdownAutoclose() {
   setup();
 
   yield spawnInNewReaderTab(TEST_ARTICLE, function* () {
     let $ = content.document.querySelector.bind(content.document);
 
-    yield NarrateTestUtils.waitForVoiceOptions(content);
+    yield NarrateTestUtils.waitForNarrateToggle(content);
 
     $(NarrateTestUtils.TOGGLE).click();
     ok(NarrateTestUtils.isVisible($(NarrateTestUtils.POPUP)),
       "popup is toggled");
 
     ok(!NarrateTestUtils.isVisible($(NarrateTestUtils.VOICE_OPTIONS)),
       "voice options are initially hidden");
 
@@ -44,17 +44,17 @@ add_task(function* testVoiceselectDropdo
 });
 
 add_task(function* testVoiceselectLabelChange() {
   setup();
 
   yield spawnInNewReaderTab(TEST_ARTICLE, function* () {
     let $ = content.document.querySelector.bind(content.document);
 
-    yield NarrateTestUtils.waitForVoiceOptions(content);
+    yield NarrateTestUtils.waitForNarrateToggle(content);
 
     $(NarrateTestUtils.TOGGLE).click();
     ok(NarrateTestUtils.isVisible($(NarrateTestUtils.POPUP)),
       "popup is toggled");
 
     ok(NarrateTestUtils.selectVoice(content, "urn:moz-tts:fake-direct:lenny"),
       "voice selected");
 
@@ -67,17 +67,17 @@ add_task(function* testVoiceselectLabelC
 });
 
 add_task(function* testVoiceselectKeyboard() {
   setup();
 
   yield spawnInNewReaderTab(TEST_ARTICLE, function* () {
     let $ = content.document.querySelector.bind(content.document);
 
-    yield NarrateTestUtils.waitForVoiceOptions(content);
+    yield NarrateTestUtils.waitForNarrateToggle(content);
 
     $(NarrateTestUtils.TOGGLE).click();
     ok(NarrateTestUtils.isVisible($(NarrateTestUtils.POPUP)),
       "popup is toggled");
 
     let eventUtils = NarrateTestUtils.getEventUtils(content);
 
     let firstValue = $(NarrateTestUtils.VOICE_SELECTED).dataset.value;
--- a/toolkit/components/narrate/test/browser_word_highlight.js
+++ b/toolkit/components/narrate/test/browser_word_highlight.js
@@ -9,24 +9,25 @@
 registerCleanupFunction(teardown);
 
 add_task(function* testNarrate() {
   setup("urn:moz-tts:fake-indirect:teresa");
 
   yield spawnInNewReaderTab(TEST_ARTICLE, function* () {
     let $ = content.document.querySelector.bind(content.document);
 
+    yield NarrateTestUtils.waitForNarrateToggle(content);
+
     let popup = $(NarrateTestUtils.POPUP);
     ok(!NarrateTestUtils.isVisible(popup), "popup is initially hidden");
 
     let toggle = $(NarrateTestUtils.TOGGLE);
     toggle.click();
 
     ok(NarrateTestUtils.isVisible(popup), "popup toggled");
-    yield NarrateTestUtils.waitForVoiceOptions(content);
 
     NarrateTestUtils.isStoppedState(content, ok);
 
     let promiseEvent = ContentTaskUtils.waitForEvent(content, "paragraphstart");
     $(NarrateTestUtils.START).click();
     let voice = (yield promiseEvent).detail.voice;
     is(voice, "urn:moz-tts:fake-indirect:teresa", "double-check voice");