dom/media/webspeech/synth/test/file_global_queue_pause.html
author Robert Longson <longsonr@gmail.com>
Sat, 04 Feb 2023 15:41:48 +0000
changeset 651752 40237e7707f1928c84d09cdd2f1fd018a74ea784
parent 395510 8b191f1e28a8f72fd49da6db0930c1baa40d4647
permissions -rw-r--r--
Bug 1814872 - Fix degenerate radial gradient handling r=emilio This is a change from SVG 1.1 where we only had to check for r=0 because fr did not exist. The SVG 2 behaviour was clarified in https://github.com/w3c/svgwg/issues/648 Differential Revision: https://phabricator.services.mozilla.com/D168783

<!DOCTYPE HTML>
<html>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=1188099
-->
<head>
  <meta charset="utf-8">
  <title>Test for Bug 1188099: Calling pause() should work correctly with global queue</title>
  <script type="application/javascript">
    window.SimpleTest = parent.SimpleTest;
    window.info = parent.info;
    window.is = parent.is;
    window.isnot = parent.isnot;
    window.ok = parent.ok;
    window.todo = parent.todo;
  </script>
  <script type="application/javascript" src="common.js"></script>
</head>
<body>
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1188099">Mozilla Bug 1188099</a>
<iframe id="frame1"></iframe>
<iframe id="frame2"></iframe>
<div id="content" style="display: none">

</div>
<pre id="test">
<script type="application/javascript">
  Promise.all([loadFrame('frame1'), loadFrame('frame2')]).then(function ([frame1, frame2]) {
    var win1 = frame1.contentWindow;
    var win2 = frame2.contentWindow;

    var utterance1 = new win1.SpeechSynthesisUtterance("Speak utterance 1.");
    utterance1.lang = 'it-IT-noend';
    var utterance2 = new win2.SpeechSynthesisUtterance("Speak utterance 2.");
    var utterance3 = new win1.SpeechSynthesisUtterance("Speak utterance 3.");
    var utterance4 = new win2.SpeechSynthesisUtterance("Speak utterance 4.");
    var eventOrder = ['start1', 'pause1', 'resume1', 'end1', 'start2', 'end2',
      'start4', 'end4', 'start3', 'end3'];

    utterance1.addEventListener('start', function(e) {
      is(eventOrder.shift(), 'start1', 'start1');
      win1.speechSynthesis.pause();
    });
    utterance1.addEventListener('pause', function(e) {
      var expectedEvent = eventOrder.shift()
      is(expectedEvent, 'pause1', 'pause1');
      testSynthState(win1, { speaking: true, pending: false, paused: true});
      testSynthState(win2, { speaking: true, pending: true, paused: false});

      if (expectedEvent == 'pause1') {
        win1.speechSynthesis.resume();
      }
    });
    utterance1.addEventListener('resume', function(e) {
      is(eventOrder.shift(), 'resume1', 'resume1');
      testSynthState(win1, { speaking: true, pending: false, paused: false});
      testSynthState(win2, { speaking: true, pending: true, paused: false});

      win2.speechSynthesis.pause();

      testSynthState(win1, { speaking: true, pending: false, paused: false});
      testSynthState(win2, { speaking: true, pending: true, paused: true });

      // We now make the utterance end.
      SpecialPowers.wrap(win1.speechSynthesis).forceEnd();
    });
    utterance1.addEventListener('end', function(e) {
      is(eventOrder.shift(), 'end1', 'end1');
      testSynthState(win1, { speaking: false, pending: false, paused: false});
      testSynthState(win2, { speaking: false, pending: true, paused: true});

      win2.speechSynthesis.resume();
    });

    utterance2.addEventListener('start', function(e) {
      is(eventOrder.shift(), 'start2', 'start2');
      testSynthState(win1, { speaking: true, pending: false, paused: false});
      testSynthState(win2, { speaking: true, pending: false, paused: false});
    });
    utterance2.addEventListener('end', function(e) {
      is(eventOrder.shift(), 'end2', 'end2');
      testSynthState(win1, { speaking: false, pending: false, paused: false});
      testSynthState(win2, { speaking: false, pending: false, paused: false});

      win1.speechSynthesis.pause();

      testSynthState(win1, { speaking: false, pending: false, paused: true});
      testSynthState(win2, { speaking: false, pending: false, paused: false});

      win1.speechSynthesis.speak(utterance3);
      win2.speechSynthesis.speak(utterance4);

      testSynthState(win1, { speaking: false, pending: true, paused: true});
      testSynthState(win2, { speaking: false, pending: true, paused: false});
    });

    utterance4.addEventListener('start', function(e) {
      is(eventOrder.shift(), 'start4', 'start4');
      testSynthState(win1, { speaking: true, pending: true, paused: true});
      testSynthState(win2, { speaking: true, pending: false, paused: false});

      win1.speechSynthesis.resume();
    });
    utterance4.addEventListener('end', function(e) {
      is(eventOrder.shift(), 'end4', 'end4');
      testSynthState(win1, { speaking: false, pending: true, paused: false});
      testSynthState(win2, { speaking: false, pending: false, paused: false});
    });

    utterance3.addEventListener('start', function(e) {
      is(eventOrder.shift(), 'start3', 'start3');
      testSynthState(win1, { speaking: true, pending: false, paused: false});
      testSynthState(win2, { speaking: true, pending: false, paused: false});
    });

    utterance3.addEventListener('end', function(e) {
      is(eventOrder.shift(), 'end3', 'end3');
      testSynthState(win1, { speaking: false, pending: false, paused: false});
      testSynthState(win2, { speaking: false, pending: false, paused: false});

      SimpleTest.finish();
    });

    win1.speechSynthesis.speak(utterance1);
    win2.speechSynthesis.speak(utterance2);
  });
</script>
</pre>
</body>
</html>