tor-browser

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

file_speech_cancel.html (3908B)


      1 <!DOCTYPE HTML>
      2 <html>
      3 <!--
      4 https://bugzilla.mozilla.org/show_bug.cgi?id=1150315
      5 -->
      6 <head>
      7  <meta charset="utf-8">
      8  <title>Test for Bug 1150315: Check that successive cancel/speak calls work</title>
      9  <script type="application/javascript">
     10    window.SimpleTest = parent.SimpleTest;
     11    window.info = parent.info;
     12    window.is = parent.is;
     13    window.isnot = parent.isnot;
     14    window.ok = parent.ok;
     15  </script>
     16  <script type="application/javascript" src="common.js"></script>
     17 </head>
     18 <body>
     19 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1150315">Mozilla Bug 1150315</a>
     20 <p id="display"></p>
     21 <div id="content" style="display: none">
     22 
     23 </div>
     24 <pre id="test">
     25 <script type="application/javascript">
     26 
     27 /** Test for Bug 1150315 */
     28 
     29 function testFunc(done_cb) {
     30  var gotEndEvent = false;
     31  // A long utterance that we will interrupt.
     32  var utterance = new SpeechSynthesisUtterance("Donec ac nunc feugiat, posuere " +
     33    "mauris id, pharetra velit. Donec fermentum orci nunc, sit amet maximus" +
     34    "dui tincidunt ut. Sed ultricies ac nisi a laoreet. Proin interdum," +
     35    "libero maximus hendrerit posuere, lorem risus egestas nisl, a" +
     36    "ultricies massa justo eu nisi. Duis mattis nibh a ligula tincidunt" +
     37    "tincidunt non eu erat. Sed bibendum varius vulputate. Cras leo magna," +
     38    "ornare ac posuere vel, luctus id metus. Mauris nec quam ac augue" +
     39    "consectetur bibendum. Integer a commodo tortor. Duis semper dolor eu" +
     40    "facilisis facilisis. Etiam venenatis turpis est, quis tincidunt velit" +
     41    "suscipit a. Cras semper orci in sapien rhoncus bibendum. Suspendisse" +
     42    "eu ex lobortis, finibus enim in, condimentum quam. Maecenas eget dui" +
     43    "ipsum. Aliquam tortor leo, interdum eget congue ut, tempor id elit.");
     44  utterance.addEventListener('start', function(e) {
     45    ok(true, 'start utterance 1');
     46    speechSynthesis.cancel();
     47    info('cancel!');
     48    speechSynthesis.speak(utterance2);
     49    info('speak??');
     50  });
     51 
     52  var utterance2 = new SpeechSynthesisUtterance("Proin ornare neque vitae " +
     53    "risus mattis rutrum. Suspendisse a velit ut est convallis aliquet." +
     54    "Nullam ante elit, malesuada vel luctus rutrum, ultricies nec libero." +
     55    "Praesent eu iaculis orci. Sed nisl diam, sodales ac purus et," +
     56    "volutpat interdum tortor. Nullam aliquam porta elit et maximus. Cras" +
     57    "risus lectus, elementum vel sodales vel, ultricies eget lectus." +
     58    "Curabitur velit lacus, mollis vel finibus et, molestie sit amet" +
     59    "sapien. Proin vitae dolor ac augue posuere efficitur ac scelerisque" +
     60    "diam. Nulla sed odio elit.");
     61  utterance2.addEventListener('start', function() {
     62    info('start');
     63    speechSynthesis.cancel();
     64    speechSynthesis.speak(utterance3);
     65  });
     66  utterance2.addEventListener('end', function(e) {
     67    gotEndEvent = true;
     68  });
     69 
     70  var utterance3 = new SpeechSynthesisUtterance("Hello, world 3!");
     71  utterance3.addEventListener('start', function() {
     72    ok(gotEndEvent, "didn't get start event for this utterance");
     73  });
     74  utterance3.addEventListener('end', done_cb);
     75 
     76  // Speak/cancel while paused (Bug 1187105)
     77  speechSynthesis.pause();
     78  speechSynthesis.speak(new SpeechSynthesisUtterance("hello."));
     79  ok(speechSynthesis.pending, "paused speechSynthesis has an utterance queued.");
     80  speechSynthesis.cancel();
     81  ok(!speechSynthesis.pending, "paused speechSynthesis has no utterance queued.");
     82  speechSynthesis.resume();
     83 
     84  speechSynthesis.speak(utterance);
     85  ok(!speechSynthesis.speaking, "speechSynthesis is not speaking yet.");
     86  ok(speechSynthesis.pending, "speechSynthesis has an utterance queued.");
     87 }
     88 
     89 // Run test with no global queue, and then run it with a global queue.
     90 testFunc(function() {
     91  SpecialPowers.pushPrefEnv(
     92    { set: [['media.webspeech.synth.force_global_queue', true]] }, function() {
     93      testFunc(SimpleTest.finish)
     94    });
     95 });
     96 
     97 </script>
     98 </pre>
     99 </body>
    100 </html>