Bug 863813 - Only call the done function once per test, failure or success. r=smaug
authorGuilherme Gonçalves <ggp@mozilla.com>
Wed, 24 Apr 2013 10:33:26 -0700
changeset 140725 c0b61756db382f57bc00d255ceeb2d9c42bd3022
parent 140724 d558c2172bcd44fed576892c3fcce5447cd0c6d7
child 140726 36c5e72589bc8382722807f3da67a22c29f8b21b
push id2579
push userakeybl@mozilla.com
push dateMon, 24 Jun 2013 18:52:47 +0000
treeherdermozilla-beta@b69b7de8a05a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssmaug
bugs863813
milestone23.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 863813 - Only call the done function once per test, failure or success. r=smaug
content/media/webspeech/recognition/test/head.js
--- a/content/media/webspeech/recognition/test/head.js
+++ b/content/media/webspeech/recognition/test/head.js
@@ -38,33 +38,38 @@ function EventManager(sr) {
   ];
 
   var eventDependencies = {
     "speechend": "speechstart",
     "soundent": "soundstart",
     "audioend": "audiostart"
   };
 
+  var isDone = false;
+
   // AUDIO_DATA events are asynchronous,
   // so we queue events requested while they are being
   // issued to make them seem synchronous
   var isSendingAudioData = false;
   var queuedEventRequests = [];
 
   // register default handlers
   for (var i = 0; i < allEvents.length; i++) {
     (function (eventName) {
       sr["on" + eventName] = function (evt) {
         var message = "unexpected event: " + eventName;
         if (eventName == "error") {
           message += " -- " + evt.message;
         }
 
         ok(false, message);
-        if (self.done) self.done();
+        if (self.doneFunc && !isDone) {
+          isDone = true;
+          self.doneFunc();
+        }
       };
     })(allEvents[i]);
   }
 
   self.expect = function EventManager_expect(eventName, cb) {
     nEventsExpected++;
 
     sr["on" + eventName] = function(evt) {
@@ -73,18 +78,20 @@ function EventManager(sr) {
 
       var dep = eventDependencies[eventName];
       if (dep) {
         ok(self.eventsReceived.indexOf(dep) >= 0,
            eventName + " must come after " + dep);
       }
 
       cb && cb(evt, sr);
-      if (self.done && nEventsExpected === self.eventsReceived.length) {
-        self.done();
+      if (self.doneFunc && !isDone &&
+          nEventsExpected === self.eventsReceived.length) {
+        isDone = true;
+        self.doneFunc();
       }
     }
   }
 
   self.requestFSMEvent = function EventManager_requestFSMEvent(eventName) {
     if (isSendingAudioData) {
       info("Queuing event " + eventName + " until we're done sending audio data");
       queuedEventRequests.push(eventName);
@@ -145,17 +152,17 @@ function performTest(options) {
     var sr = new SpeechRecognition();
     var em = new EventManager(sr);
 
     for (var eventName in options.expectedEvents) {
       var cb = options.expectedEvents[eventName];
       em.expect(eventName, cb);
     }
 
-    em.done = function() {
+    em.doneFunc = function() {
       em.requestTestEnd();
       options.doneFunc();
     }
 
     em.audioSampleFile = DEFAULT_AUDIO_SAMPLE_FILE;
     if (options.audioSampleFile) {
       em.audioSampleFile = options.audioSampleFile;
     }