tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

test_call_start_from_end_handler.html (2847B)


      1 <!DOCTYPE HTML>
      2 <html>
      3 <!--
      4 https://bugzilla.mozilla.org/show_bug.cgi?id=650295
      5 -->
      6 <head>
      7  <meta charset="utf-8">
      8  <title>Test for Bug 650295 -- Restart recognition from end handler</title>
      9  <script src="/tests/SimpleTest/SimpleTest.js"></script>
     10  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
     11  <script type="application/javascript" src="head.js"></script>
     12 </head>
     13 <body>
     14 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=650295">Mozilla Bug 650295</a>
     15 <p id="display"></p>
     16 <div id="content" style="display: none">
     17 
     18 </div>
     19 <pre id="test">
     20 <script type="text/javascript">
     21  SimpleTest.waitForExplicitFinish();
     22 
     23  function createAudioStream() {
     24    var audioTag = document.createElement("audio");
     25    audioTag.src = DEFAULT_AUDIO_SAMPLE_FILE;
     26 
     27    var stream = audioTag.mozCaptureStreamUntilEnded();
     28    audioTag.play();
     29 
     30    return stream;
     31  }
     32 
     33  var done = false;
     34  function endHandler(evt, sr) {
     35    if (done) {
     36      SimpleTest.finish();
     37      return;
     38    }
     39 
     40    try {
     41      var stream = createAudioStream();
     42      sr.start(stream); // shouldn't fail
     43    } catch (err) {
     44      ok(false, "Failed to start() from end() callback");
     45    }
     46 
     47    // calling start() may cause some callbacks to fire, but we're
     48    // no longer interested in them, except for onend, which is where
     49    // we'll conclude the test.
     50    sr.onstart = null;
     51    sr.onaudiostart = null;
     52    sr.onspeechstart = null;
     53    sr.onspeechend = null;
     54    sr.onaudioend = null;
     55    sr.onresult = null;
     56 
     57    // FIXME(ggp) the state transition caused by start() is async,
     58    // but abort() is sync (see bug 1055093). until we normalize
     59    // state transitions, we need to setTimeout here to make sure
     60    // abort() finds the speech recognition object in the correct
     61    // state (namely, STATE_STARTING).
     62    setTimeout(function() {
     63      sr.abort();
     64      done = true;
     65    });
     66 
     67    info("Successfully start() from end() callback");
     68  }
     69 
     70  function expectExceptionHandler(evt, sr) {
     71    try {
     72      sr.start(createAudioStream());
     73    } catch (err) {
     74      is(err.name, "InvalidStateError");
     75      return;
     76    }
     77 
     78    ok(false, "Calling start() didn't raise InvalidStateError");
     79  }
     80 
     81  performTest({
     82    eventsToRequest: [
     83      'EVENT_RECOGNITIONSERVICE_FINAL_RESULT'
     84    ],
     85    expectedEvents: {
     86      'start': expectExceptionHandler,
     87      'audiostart': expectExceptionHandler,
     88      'speechstart': expectExceptionHandler,
     89      'speechend': expectExceptionHandler,
     90      'audioend': expectExceptionHandler,
     91      'result': buildResultCallback("Mock final result"),
     92      'end': endHandler,
     93    },
     94    prefs: [["media.webspeech.test.fake_fsm_events", true],
     95            ["media.webspeech.test.fake_recognition_service", true],
     96            ["media.webspeech.recognition.timeout", 100000]]
     97  });
     98 
     99 </script>
    100 </pre>
    101 </body>
    102 </html>