Bug 1254378 - Update synth tests and introduce no voiceschanged test. r=smaug
authorEitan Isaacson <eitan@monotonous.org>
Thu, 24 Mar 2016 16:43:04 -0700
changeset 291061 f7a5b2b77a7787af1d12eb027e84038da6228aa0
parent 291060 70ead871eea8cbc07577cfceb86458bd5a16d478
child 291062 f2c661c123c089b02b6b542bbf95bb624bcafc22
push id74438
push usereisaacson@mozilla.com
push dateFri, 01 Apr 2016 00:05:56 +0000
treeherdermozilla-inbound@f2c661c123c0 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssmaug
bugs1254378
milestone48.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1254378 - Update synth tests and introduce no voiceschanged test. r=smaug MozReview-Commit-ID: 6O9bBFGgFFq
dom/media/webspeech/synth/moz.build
dom/media/webspeech/synth/test/FakeSynthModule.cpp
dom/media/webspeech/synth/test/common.js
dom/media/webspeech/synth/test/nsFakeSynthServices.cpp
dom/media/webspeech/synth/test/startup/file_voiceschanged.html
dom/media/webspeech/synth/test/startup/mochitest.ini
dom/media/webspeech/synth/test/startup/test_voiceschanged.html
dom/media/webspeech/synth/test/test_bfcache.html
dom/media/webspeech/synth/test/test_global_queue.html
dom/media/webspeech/synth/test/test_global_queue_cancel.html
dom/media/webspeech/synth/test/test_global_queue_pause.html
dom/media/webspeech/synth/test/test_indirect_service_events.html
dom/media/webspeech/synth/test/test_speech_cancel.html
dom/media/webspeech/synth/test/test_speech_error.html
dom/media/webspeech/synth/test/test_speech_queue.html
dom/media/webspeech/synth/test/test_speech_simple.html
--- a/dom/media/webspeech/synth/moz.build
+++ b/dom/media/webspeech/synth/moz.build
@@ -1,16 +1,17 @@
 # vim: set filetype=python:
 # This Source Code Form is subject to the terms of the Mozilla Public
 # License, v. 2.0. If a copy of the MPL was not distributed with this
 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
 
 if CONFIG['MOZ_WEBSPEECH']:
     MOCHITEST_MANIFESTS += [
         'test/mochitest.ini',
+        'test/startup/mochitest.ini',
     ]
 
     XPIDL_MODULE = 'dom_webspeechsynth'
 
     XPIDL_SOURCES += [
         'nsISpeechService.idl',
         'nsISynthVoiceRegistry.idl'
     ]
--- a/dom/media/webspeech/synth/test/FakeSynthModule.cpp
+++ b/dom/media/webspeech/synth/test/FakeSynthModule.cpp
@@ -27,17 +27,17 @@ static const mozilla::Module::CIDEntry k
 };
 
 static const mozilla::Module::ContractIDEntry kContracts[] = {
   { FAKESYNTHSERVICE_CONTRACTID, &kFAKESYNTHSERVICE_CID },
   { nullptr }
 };
 
 static const mozilla::Module::CategoryEntry kCategories[] = {
-  { "profile-after-change", "Fake Speech Synth", FAKESYNTHSERVICE_CONTRACTID },
+  { "speech-synth-started", "Fake Speech Synth", FAKESYNTHSERVICE_CONTRACTID },
   { nullptr }
 };
 
 static void
 UnloadFakeSynthmodule()
 {
   nsFakeSynthServices::Shutdown();
 }
--- a/dom/media/webspeech/synth/test/common.js
+++ b/dom/media/webspeech/synth/test/common.js
@@ -53,17 +53,38 @@ function synthTestQueue(aTestArgs, aEndF
 
 function loadFrame(frameId) {
   return new Promise(function(resolve, reject) {
     var frame = document.getElementById(frameId);
     frame.addEventListener('load', function (e) {
       frame.contentWindow.document.title = frameId;
       resolve(frame);
     });
-    frame1.src = 'data:text/html,' + encodeURI('<html><head></head><body></body></html>');
+    frame.src = 'data:text/html,' + encodeURI('<html><head></head><body></body></html>');
+  });
+}
+
+function waitForVoices(win) {
+  return new Promise(resolve => {
+    function resolver() {
+      if (win.speechSynthesis.getVoices().length) {
+        win.speechSynthesis.removeEventListener('voiceschanged', resolver);
+        resolve();
+      }
+    }
+
+    win.speechSynthesis.addEventListener('voiceschanged', resolver);
+    resolver();
+  });
+}
+
+function loadSpeechTest(fileName, prefs, frameId="testFrame") {
+  loadFrame(frameId).then(frame => {
+    waitForVoices(frame.contentWindow).then(
+      () => document.getElementById("testFrame").src = fileName);
   });
 }
 
 function testSynthState(win, expectedState) {
   for (var attr in expectedState) {
     is(win.speechSynthesis[attr], expectedState[attr],
       win.document.title + ": '" + attr + '" does not match');
   }
--- a/dom/media/webspeech/synth/test/nsFakeSynthServices.cpp
+++ b/dom/media/webspeech/synth/test/nsFakeSynthServices.cpp
@@ -313,28 +313,30 @@ nsFakeSynthServices::nsFakeSynthServices
 
 nsFakeSynthServices::~nsFakeSynthServices()
 {
 }
 
 static void
 AddVoices(nsISpeechService* aService, const VoiceDetails* aVoices, uint32_t aLength)
 {
-  nsSynthVoiceRegistry* registry = nsSynthVoiceRegistry::GetInstance();
+  RefPtr<nsSynthVoiceRegistry> registry = nsSynthVoiceRegistry::GetInstance();
   for (uint32_t i = 0; i < aLength; i++) {
     NS_ConvertUTF8toUTF16 name(aVoices[i].name);
     NS_ConvertUTF8toUTF16 uri(aVoices[i].uri);
     NS_ConvertUTF8toUTF16 lang(aVoices[i].lang);
     // These services can handle more than one utterance at a time and have
     // several speaking simultaniously. So, aQueuesUtterances == false
     registry->AddVoice(aService, uri, name, lang, true, false);
     if (aVoices[i].defaultVoice) {
       registry->SetDefaultVoice(uri, true);
     }
   }
+
+  registry->NotifyVoicesChanged();
 }
 
 void
 nsFakeSynthServices::Init()
 {
   mDirectService = new FakeDirectAudioSynth();
   AddVoices(mDirectService, sDirectVoices, ArrayLength(sDirectVoices));
 
@@ -344,22 +346,22 @@ nsFakeSynthServices::Init()
 
 // nsIObserver
 
 NS_IMETHODIMP
 nsFakeSynthServices::Observe(nsISupports* aSubject, const char* aTopic,
                              const char16_t* aData)
 {
   MOZ_ASSERT(NS_IsMainThread());
-  if(NS_WARN_IF(!(!strcmp(aTopic, "profile-after-change")))) {
+  if(NS_WARN_IF(!(!strcmp(aTopic, "speech-synth-started")))) {
     return NS_ERROR_UNEXPECTED;
   }
 
   if (Preferences::GetBool("media.webspeech.synth.test")) {
-    Init();
+    NS_DispatchToMainThread(NS_NewRunnableMethod(this, &nsFakeSynthServices::Init));
   }
 
   return NS_OK;
 }
 
 // static methods
 
 nsFakeSynthServices*
new file mode 100644
--- /dev/null
+++ b/dom/media/webspeech/synth/test/startup/file_voiceschanged.html
@@ -0,0 +1,32 @@
+<!DOCTYPE HTML>
+<html>
+<!--
+https://bugzilla.mozilla.org/show_bug.cgi?id=1254378
+-->
+<head>
+  <meta charset="utf-8">
+  <title>Test for Bug 1254378: Web Speech API check all classes are present</title>
+  <script type="application/javascript">
+    window.SimpleTest = parent.SimpleTest;
+    window.is = parent.is;
+    window.isnot = parent.isnot;
+    window.ok = parent.ok;
+  </script>
+</head>
+<body>
+<script type="application/javascript">
+
+/** Test for Bug 1254378 **/
+
+function onVoicesChanged() {
+  isnot(speechSynthesis.getVoices().length, 0, "Voices added");
+  speechSynthesis.removeEventListener("voiceschanged", onVoicesChanged);
+  SimpleTest.finish();
+}
+
+speechSynthesis.addEventListener("voiceschanged", onVoicesChanged);
+
+is(speechSynthesis.getVoices().length, 0, "No voices added initially");
+</script>
+</body>
+</html>
new file mode 100644
--- /dev/null
+++ b/dom/media/webspeech/synth/test/startup/mochitest.ini
@@ -0,0 +1,7 @@
+[DEFAULT]
+tags=msg
+subsuite = media
+support-files =
+  file_voiceschanged.html
+
+[test_voiceschanged.html]
new file mode 100644
--- /dev/null
+++ b/dom/media/webspeech/synth/test/startup/test_voiceschanged.html
@@ -0,0 +1,32 @@
+<!DOCTYPE HTML>
+<html>
+<!--
+https://bugzilla.mozilla.org/show_bug.cgi?id=1254378
+-->
+<head>
+  <meta charset="utf-8">
+  <title>Test for Bug 1254378: Emit onvoiceschanged when voices first added</title>
+  <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
+  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
+</head>
+<body>
+<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1254378">Mozilla Bug 1254378</a>
+<p id="display"></p>
+<iframe id="testFrame"></iframe>
+<div id="content" style="display: none">
+  
+</div>
+<pre id="test">
+<script type="application/javascript">
+
+/** Test for Bug 1254378 **/
+
+SimpleTest.waitForExplicitFinish();
+
+SpecialPowers.pushPrefEnv({ set: [['media.webspeech.synth.enabled', true]] },
+                          function() { document.getElementById("testFrame").src = "file_voiceschanged.html"; });
+
+</script>
+</pre>
+</body>
+</html>
--- a/dom/media/webspeech/synth/test/test_bfcache.html
+++ b/dom/media/webspeech/synth/test/test_bfcache.html
@@ -25,23 +25,21 @@ https://bugzilla.mozilla.org/show_bug.cg
 SimpleTest.waitForExplicitFinish();
 
 var iframe;
 
 function onDone() {
   SimpleTest.finish();
 }
 
-function doTest() {
-  iframe = document.getElementById("testFrame");
-  iframe.src = "file_bfcache_frame.html";
-}
-
 SpecialPowers.pushPrefEnv({ set: [
   ['media.webspeech.synth.enabled', true],
   ['media.webspeech.synth.force_global_queue', true],
   ['browser.sessionhistory.cache_subframes', true],
-  ['browser.sessionhistory.max_total_viewers', 10]] }, doTest());
+  ['browser.sessionhistory.max_total_viewers', 10]] },
+  function() {
+    loadSpeechTest("file_bfcache_frame.html");
+  });
 
 </script>
 </pre>
 </body>
 </html>
--- a/dom/media/webspeech/synth/test/test_global_queue.html
+++ b/dom/media/webspeech/synth/test/test_global_queue.html
@@ -19,16 +19,17 @@ https://bugzilla.mozilla.org/show_bug.cg
 </div>
 <pre id="test">
 <script type="application/javascript">
 
 /** Test for Bug 525444 **/
 
 SimpleTest.waitForExplicitFinish();
 
-SpecialPowers.pushPrefEnv({ set: [['media.webspeech.synth.enabled', true],
-                                  ['media.webspeech.synth.force_global_queue', true]] },
-                          function() { document.getElementById("testFrame").src = "file_global_queue.html"; });
+SpecialPowers.pushPrefEnv(
+  { set: [['media.webspeech.synth.enabled', true],
+          ['media.webspeech.synth.force_global_queue', true]] },
+  function() { loadSpeechTest("file_global_queue.html"); });
 
 </script>
 </pre>
 </body>
 </html>
\ No newline at end of file
--- a/dom/media/webspeech/synth/test/test_global_queue_cancel.html
+++ b/dom/media/webspeech/synth/test/test_global_queue_cancel.html
@@ -19,16 +19,17 @@ https://bugzilla.mozilla.org/show_bug.cg
 </div>
 <pre id="test">
 <script type="application/javascript">
 
 /** Test for Bug 525444 **/
 
 SimpleTest.waitForExplicitFinish();
 
-SpecialPowers.pushPrefEnv({ set: [['media.webspeech.synth.enabled', true],
-                                  ['media.webspeech.synth.force_global_queue', true]] },
-                          function() { document.getElementById("testFrame").src = "file_global_queue_cancel.html"; });
+SpecialPowers.pushPrefEnv(
+  { set: [['media.webspeech.synth.enabled', true],
+          ['media.webspeech.synth.force_global_queue', true]] },
+  function() { loadSpeechTest("file_global_queue_cancel.html"); });
 
 </script>
 </pre>
 </body>
 </html>
\ No newline at end of file
--- a/dom/media/webspeech/synth/test/test_global_queue_pause.html
+++ b/dom/media/webspeech/synth/test/test_global_queue_pause.html
@@ -19,16 +19,17 @@ https://bugzilla.mozilla.org/show_bug.cg
 </div>
 <pre id="test">
 <script type="application/javascript">
 
 /** Test for Bug 525444 **/
 
 SimpleTest.waitForExplicitFinish();
 
-SpecialPowers.pushPrefEnv({ set: [['media.webspeech.synth.enabled', true],
-                                  ['media.webspeech.synth.force_global_queue', true]] },
-                          function() { document.getElementById("testFrame").src = "file_global_queue_pause.html"; });
+SpecialPowers.pushPrefEnv(
+  { set: [['media.webspeech.synth.enabled', true],
+          ['media.webspeech.synth.force_global_queue', true]] },
+  function() { loadSpeechTest("file_global_queue_pause.html"); });
 
 </script>
 </pre>
 </body>
 </html>
\ No newline at end of file
--- a/dom/media/webspeech/synth/test/test_indirect_service_events.html
+++ b/dom/media/webspeech/synth/test/test_indirect_service_events.html
@@ -22,15 +22,15 @@ https://bugzilla.mozilla.org/show_bug.cg
 
 /** Test for Bug 1155034 **/
 
 SimpleTest.waitForExplicitFinish();
 
 SpecialPowers.pushPrefEnv(
   { set: [['media.webspeech.synth.enabled', true],
           ['media.webspeech.synth.force_global_queue', false]] },
-  function() { document.getElementById("testFrame").src = "file_indirect_service_events.html"; });
+  function() { loadSpeechTest("file_indirect_service_events.html"); });
 
 
 </script>
 </pre>
 </body>
 </html>
--- a/dom/media/webspeech/synth/test/test_speech_cancel.html
+++ b/dom/media/webspeech/synth/test/test_speech_cancel.html
@@ -22,14 +22,14 @@ https://bugzilla.mozilla.org/show_bug.cg
 
 /** Test for Bug 1150315 **/
 
 SimpleTest.waitForExplicitFinish();
 
 SpecialPowers.pushPrefEnv(
   { set: [['media.webspeech.synth.enabled', true],
           ['media.webspeech.synth.force_global_queue', false]] },
-  function() { document.getElementById("testFrame").src = "file_speech_cancel.html"; });
+  function() { loadSpeechTest("file_speech_cancel.html"); });
 
 </script>
 </pre>
 </body>
 </html>
--- a/dom/media/webspeech/synth/test/test_speech_error.html
+++ b/dom/media/webspeech/synth/test/test_speech_error.html
@@ -22,14 +22,14 @@ https://bugzilla.mozilla.org/show_bug.cg
 
 /** Test for Bug 1226015 **/
 
 SimpleTest.waitForExplicitFinish();
 
 SpecialPowers.pushPrefEnv(
   { set: [['media.webspeech.synth.enabled', true],
           ['media.webspeech.synth.force_global_queue', false]] },
-  function() { document.getElementById("testFrame").src = "file_speech_error.html"; });
+  function() { loadSpeechTest("file_speech_error.html"); });
 
 </script>
 </pre>
 </body>
 </html>
--- a/dom/media/webspeech/synth/test/test_speech_queue.html
+++ b/dom/media/webspeech/synth/test/test_speech_queue.html
@@ -22,14 +22,16 @@ https://bugzilla.mozilla.org/show_bug.cg
 
 /** Test for Bug 525444 **/
 
 SimpleTest.waitForExplicitFinish();
 
 SpecialPowers.pushPrefEnv(
   { set: [['media.webspeech.synth.enabled', true],
           ['media.webspeech.synth.force_global_queue', false]] },
-  function() { document.getElementById("testFrame").src = "file_speech_queue.html"; });
+  function() {
+    loadSpeechTest("file_speech_queue.html");
+  });
 
 </script>
 </pre>
 </body>
 </html>
--- a/dom/media/webspeech/synth/test/test_speech_simple.html
+++ b/dom/media/webspeech/synth/test/test_speech_simple.html
@@ -19,15 +19,16 @@ https://bugzilla.mozilla.org/show_bug.cg
 </div>
 <pre id="test">
 <script type="application/javascript">
 
 /** Test for Bug 525444 **/
 
 SimpleTest.waitForExplicitFinish();
 
-SpecialPowers.pushPrefEnv({ set: [['media.webspeech.synth.enabled', true]] },
-                          function() { document.getElementById("testFrame").src = "file_speech_simple.html"; });
+SpecialPowers.pushPrefEnv(
+  { set: [['media.webspeech.synth.enabled', true]] },
+  function() { loadSpeechTest("file_speech_simple.html"); });
 
 </script>
 </pre>
 </body>
 </html>