tor-browser

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

file_indirect_service_events.html (3144B)


      1 <!DOCTYPE HTML>
      2 <html>
      3 <!--
      4 https://bugzilla.mozilla.org/show_bug.cgi?id=1155034
      5 -->
      6 <head>
      7  <meta charset="utf-8">
      8  <title>Test for Bug 1155034: Check that indirect audio services dispatch their own events</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=1155034">Mozilla Bug 1155034</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 1155034 */
     28 
     29 function testFunc(done_cb) {
     30  function test_with_events() {
     31    info('test_with_events');
     32    var utterance = new SpeechSynthesisUtterance("never end, callback events");
     33    utterance.lang = 'it-IT-noend';
     34 
     35    utterance.addEventListener('start', function(e) {
     36      info('start test_with_events');
     37      speechSynthesis.pause();
     38    // Wait to see if we get some bad events we didn't expect.
     39    });
     40 
     41    utterance.addEventListener('pause', function(e) {
     42      is(e.charIndex, 1, 'pause event charIndex matches service arguments');
     43      is(e.elapsedTime, 1.5, 'pause event elapsedTime matches service arguments');
     44      speechSynthesis.resume();
     45    });
     46 
     47    utterance.addEventListener('resume', function(e) {
     48      is(e.charIndex, 1, 'resume event charIndex matches service arguments');
     49      is(e.elapsedTime, 1.5, 'resume event elapsedTime matches service arguments');
     50      speechSynthesis.cancel();
     51    });
     52 
     53    utterance.addEventListener('end', function(e) {
     54      is(e.charIndex, 1, 'resume event charIndex matches service arguments');
     55      is(e.elapsedTime, 1.5, 'end event elapsedTime matches service arguments');
     56      test_no_events();
     57    });
     58 
     59    info('start speak');
     60    speechSynthesis.speak(utterance);
     61  }
     62 
     63  function forbiddenEvent(e) {
     64    ok(false, 'no "' + e.type + '" event was explicitly dispatched from the service')
     65  }
     66 
     67  function test_no_events() {
     68    info('test_no_events');
     69    var utterance = new SpeechSynthesisUtterance("never end");
     70    utterance.lang = "it-IT-noevents-noend";
     71    utterance.addEventListener('start', function(e) {
     72      speechSynthesis.pause();
     73      // Wait to see if we get some bad events we didn't expect.
     74      setTimeout(function() {
     75        ok(true, 'didn\'t get any unwanted events');
     76        utterance.removeEventListener('end', forbiddenEvent);
     77        SpecialPowers.wrap(speechSynthesis).forceEnd();
     78        done_cb();
     79      }, 1000);
     80    });
     81 
     82    utterance.addEventListener('pause', forbiddenEvent);
     83    utterance.addEventListener('end', forbiddenEvent);
     84 
     85    speechSynthesis.speak(utterance);
     86  }
     87 
     88  test_with_events();
     89 }
     90 
     91 // Run test with no global queue, and then run it with a global queue.
     92 testFunc(function() {
     93  SpecialPowers.pushPrefEnv(
     94    { set: [['media.webspeech.synth.force_global_queue', true]] }, function() {
     95      testFunc(SimpleTest.finish)
     96    });
     97 });
     98 
     99 </script>
    100 </pre>
    101 </body>
    102 </html>