Bug 1052775 - Abort speech recognition after test_call_start_from_end_handler. r=smaug
authorGuilherme Goncalves <guilherme.p.gonc@gmail.com>
Mon, 18 Aug 2014 10:25:00 -0400
changeset 200389 1e3273854ca703c72ad102cf25acf5f6ad935d5c
parent 200388 1ba16df879d8b2e135af791c164ada475e004f8e
child 200390 9f6ea1c97cc6b701275403669634073952dedde2
push id27342
push userryanvm@gmail.com
push dateTue, 19 Aug 2014 20:23:11 +0000
treeherdermozilla-central@149d3ce6e020 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssmaug
bugs1052775
milestone34.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 1052775 - Abort speech recognition after test_call_start_from_end_handler. r=smaug
content/media/webspeech/recognition/SpeechRecognition.cpp
content/media/webspeech/recognition/test/test_call_start_from_end_handler.html
--- a/content/media/webspeech/recognition/SpeechRecognition.cpp
+++ b/content/media/webspeech/recognition/SpeechRecognition.cpp
@@ -485,23 +485,21 @@ SpeechRecognition::NotifyFinalResult(Spe
 void
 SpeechRecognition::DoNothing(SpeechEvent* aEvent)
 {
 }
 
 void
 SpeechRecognition::AbortSilently(SpeechEvent* aEvent)
 {
-  bool stopRecording = StateBetween(STATE_ESTIMATING, STATE_RECOGNIZING);
-
   if (mRecognitionService) {
     mRecognitionService->Abort();
   }
 
-  if (stopRecording) {
+  if (mDOMStream) {
     StopRecording();
   }
 
   ResetAndEnd();
 }
 
 void
 SpeechRecognition::AbortError(SpeechEvent* aEvent)
--- a/content/media/webspeech/recognition/test/test_call_start_from_end_handler.html
+++ b/content/media/webspeech/recognition/test/test_call_start_from_end_handler.html
@@ -25,23 +25,50 @@ https://bugzilla.mozilla.org/show_bug.cg
     audioTag.src = DEFAULT_AUDIO_SAMPLE_FILE;
 
     var stream = audioTag.mozCaptureStreamUntilEnded();
     audioTag.play();
 
     return stream;
   }
 
+  var done = false;
   function endHandler(evt, sr) {
+    if (done) {
+      SimpleTest.finish();
+      return;
+    }
+
     try {
-      sr.start(createAudioStream()); // shouldn't fail
+      var stream = createAudioStream();
+      sr.start(stream); // shouldn't fail
     } catch (err) {
       ok(false, "Failed to start() from end() callback");
     }
 
+    // calling start() may cause some callbacks to fire, but we're
+    // no longer interested in them, except for onend, which is where
+    // we'll conclude the test.
+    sr.onstart = null;
+    sr.onaudiostart = null;
+    sr.onspeechstart = null;
+    sr.onspeechend = null;
+    sr.onaudioend = null;
+    sr.onresult = null;
+
+    // FIXME(ggp) the state transition caused by start() is async,
+    // but abort() is sync (see bug 1055093). until we normalize
+    // state transitions, we need to setTimeout here to make sure
+    // abort() finds the speech recognition object in the correct
+    // state (namely, STATE_STARTING).
+    setTimeout(function() {
+      sr.abort();
+      done = true;
+    });
+
     info("Successfully start() from end() callback");
   }
 
   function expectExceptionHandler(evt, sr) {
     try {
       sr.start(createAudioStream());
     } catch (err) {
       is(err.name, "InvalidStateError");
@@ -59,16 +86,15 @@ https://bugzilla.mozilla.org/show_bug.cg
       'start': expectExceptionHandler,
       'audiostart': expectExceptionHandler,
       'speechstart': expectExceptionHandler,
       'speechend': expectExceptionHandler,
       'audioend': expectExceptionHandler,
       'result': buildResultCallback("Mock final result"),
       'end': endHandler,
     },
-    doneFunc: SimpleTest.finish,
     prefs: [["media.webspeech.test.fake_fsm_events", true], ["media.webspeech.test.fake_recognition_service", true]]
   });
 
 </script>
 </pre>
 </body>
 </html>