Bug 1310448 - Wait for narrate button to appear before starting tests. r?Gijs
MozReview-Commit-ID: 8MPzdZvAT1
--- 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");