summaryrefslogtreecommitdiffstats
path: root/dom/media/webspeech/synth/test/file_setup.html
blob: 4c102050522162531ddb7d2a93a1fc460374d0d9 (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
<!DOCTYPE HTML>
<html>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=525444
-->
<head>
  <meta charset="utf-8">
  <title>Test for Bug 525444: Web Speech API check all classes are present</title>
  <script type="application/javascript">
    window.SimpleTest = parent.SimpleTest;
    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=650295">Mozilla Bug 650295</a>
<p id="display"></p>
<div id="content" style="display: none">
  
</div>
<pre id="test">
<script type="application/javascript">

/** Test for Bug 525444 **/

ok(SpeechSynthesis, "SpeechSynthesis exists in global scope");
ok(SpeechSynthesisVoice, "SpeechSynthesisVoice exists in global scope");
ok(SpeechSynthesisErrorEvent, "SpeechSynthesisErrorEvent exists in global scope");
ok(SpeechSynthesisEvent, "SpeechSynthesisEvent exists in global scope");

// SpeechSynthesisUtterance is the only type that has a constructor
//  and writable properties
ok(SpeechSynthesisUtterance, "SpeechSynthesisUtterance exists in global scope");
var ssu = new SpeechSynthesisUtterance("hello world");
is(typeof ssu, "object", "SpeechSynthesisUtterance instance is an object");
is(ssu.text, "hello world", "SpeechSynthesisUtterance.text is correct");
is(ssu.volume, 1, "SpeechSynthesisUtterance.volume default is correct");
is(ssu.rate, 1, "SpeechSynthesisUtterance.rate default is correct");
is(ssu.pitch, 1, "SpeechSynthesisUtterance.pitch default is correct");
ssu.lang = "he-IL";
ssu.volume = 0.5;
ssu.rate = 2.0;
ssu.pitch = 1.5;
is(ssu.lang, "he-IL", "SpeechSynthesisUtterance.lang is correct");
is(ssu.volume, 0.5,  "SpeechSynthesisUtterance.volume is correct");
is(ssu.rate, 2.0,  "SpeechSynthesisUtterance.rate is correct");
is(ssu.pitch, 1.5,  "SpeechSynthesisUtterance.pitch is correct");

// Assign a rate that is out of bounds
ssu.rate = 20;
is(ssu.rate, 10, "SpeechSynthesisUtterance.rate enforces max of 10");
ssu.rate = 0;
is(ssu.rate.toPrecision(1), "0.1", "SpeechSynthesisUtterance.rate enforces min of 0.1");

// Assign a volume which is out of bounds
ssu.volume = 2;
is(ssu.volume, 1, "SpeechSynthesisUtterance.volume enforces max of 1");
ssu.volume = -1;
is(ssu.volume, 0, "SpeechSynthesisUtterance.volume enforces min of 0");

// Assign a pitch which is out of bounds
ssu.pitch = 2.1;
is(ssu.pitch, 2, "SpeechSynthesisUtterance.pitch enforces max of 2");
ssu.pitch = -1;
is(ssu.pitch, 0, "SpeechSynthesisUtterance.pitch enforces min of 0");

// Test for singleton instance hanging off of window.
ok(speechSynthesis, "speechSynthesis exists in global scope");
is(typeof speechSynthesis, "object", "speechSynthesis instance is an object");
is(typeof speechSynthesis.speak, "function", "speechSynthesis.speak is a function");
is(typeof speechSynthesis.cancel, "function", "speechSynthesis.cancel is a function");
is(typeof speechSynthesis.pause, "function", "speechSynthesis.pause is a function");
is(typeof speechSynthesis.resume, "function", "speechSynthesis.resume is a function");
is(typeof speechSynthesis.getVoices, "function", "speechSynthesis.getVoices is a function");

is(typeof speechSynthesis.pending, "boolean", "speechSynthesis.pending is a boolean");
is(typeof speechSynthesis.speaking, "boolean", "speechSynthesis.speaking is a boolean");
is(typeof speechSynthesis.paused, "boolean", "speechSynthesis.paused is a boolean");

var voices1 = speechSynthesis.getVoices();
var voices2 = speechSynthesis.getVoices();

ok(voices1.length == voices2.length, "Voice count matches");

for (var i in voices1) {
  ok(voices1[i] == voices2[i], "Voice instance matches");
}

SimpleTest.finish();
</script>
</pre>
</body>
</html>