summaryrefslogtreecommitdiffstats
path: root/dom/media/webspeech/synth/test/file_speech_cancel.html
blob: 2ab0e1d0a87fc021d97ef8161acd8b63493a8704 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
<!DOCTYPE HTML>
<html>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=1150315
-->
<head>
  <meta charset="utf-8">
  <title>Test for Bug 1150315: Check that successive cancel/speak calls work</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;
  </script>
  <script type="application/javascript" src="common.js"></script>
</head>
<body>
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1150315">Mozilla Bug 1150315</a>
<p id="display"></p>
<div id="content" style="display: none">

</div>
<pre id="test">
<script type="application/javascript">

/** Test for Bug 1150315 **/

function testFunc(done_cb) {
  var gotEndEvent = false;
  // A long utterance that we will interrupt.
  var utterance = new SpeechSynthesisUtterance("Donec ac nunc feugiat, posuere " +
    "mauris id, pharetra velit. Donec fermentum orci nunc, sit amet maximus" +
    "dui tincidunt ut. Sed ultricies ac nisi a laoreet. Proin interdum," +
    "libero maximus hendrerit posuere, lorem risus egestas nisl, a" +
    "ultricies massa justo eu nisi. Duis mattis nibh a ligula tincidunt" +
    "tincidunt non eu erat. Sed bibendum varius vulputate. Cras leo magna," +
    "ornare ac posuere vel, luctus id metus. Mauris nec quam ac augue" +
    "consectetur bibendum. Integer a commodo tortor. Duis semper dolor eu" +
    "facilisis facilisis. Etiam venenatis turpis est, quis tincidunt velit" +
    "suscipit a. Cras semper orci in sapien rhoncus bibendum. Suspendisse" +
    "eu ex lobortis, finibus enim in, condimentum quam. Maecenas eget dui" +
    "ipsum. Aliquam tortor leo, interdum eget congue ut, tempor id elit.");
  utterance.addEventListener('start', function(e) {
    ok(true, 'start utterance 1');
    speechSynthesis.cancel();
    info('cancel!');
    speechSynthesis.speak(utterance2);
    info('speak??');
  });

  var utterance2 = new SpeechSynthesisUtterance("Proin ornare neque vitae " +
    "risus mattis rutrum. Suspendisse a velit ut est convallis aliquet." +
    "Nullam ante elit, malesuada vel luctus rutrum, ultricies nec libero." +
    "Praesent eu iaculis orci. Sed nisl diam, sodales ac purus et," +
    "volutpat interdum tortor. Nullam aliquam porta elit et maximus. Cras" +
    "risus lectus, elementum vel sodales vel, ultricies eget lectus." +
    "Curabitur velit lacus, mollis vel finibus et, molestie sit amet" +
    "sapien. Proin vitae dolor ac augue posuere efficitur ac scelerisque" +
    "diam. Nulla sed odio elit.");
  utterance2.addEventListener('start', function() {
    info('start');
    speechSynthesis.cancel();
    speechSynthesis.speak(utterance3);
  });
  utterance2.addEventListener('end', function(e) {
    gotEndEvent = true;
  });

  var utterance3 = new SpeechSynthesisUtterance("Hello, world 3!");
  utterance3.addEventListener('start', function() {
    ok(gotEndEvent, "didn't get start event for this utterance");
  });
  utterance3.addEventListener('end', done_cb);

  // Speak/cancel while paused (Bug 1187105)
  speechSynthesis.pause();
  speechSynthesis.speak(new SpeechSynthesisUtterance("hello."));
  ok(speechSynthesis.pending, "paused speechSynthesis has an utterance queued.");
  speechSynthesis.cancel();
  ok(!speechSynthesis.pending, "paused speechSynthesis has no utterance queued.");
  speechSynthesis.resume();

  speechSynthesis.speak(utterance);
  ok(!speechSynthesis.speaking, "speechSynthesis is not speaking yet.");
  ok(speechSynthesis.pending, "speechSynthesis has an utterance queued.");
}

// Run test with no global queue, and then run it with a global queue.
testFunc(function() {
  SpecialPowers.pushPrefEnv(
    { set: [['media.webspeech.synth.force_global_queue', true]] }, function() {
      testFunc(SimpleTest.finish)
    });
});

</script>
</pre>
</body>
</html>