SpeechSynthesisUtterance-basics.https.html (1433B)
1 <!DOCTYPE html> 2 <title>SpeechSynthesisUtterance basics</title> 3 <script src="/resources/testharness.js"></script> 4 <script src="/resources/testharnessreport.js"></script> 5 <script> 6 const DEFAULTS = { 7 text: '', 8 lang: '', 9 voice: null, 10 volume: 1, 11 rate: 1, 12 pitch: 1, 13 }; 14 15 for (const prop in DEFAULTS) { 16 test(function() { 17 const utt = new SpeechSynthesisUtterance(); 18 assert_equals(utt[prop], DEFAULTS[prop], prop); 19 }, `new SpeechSynthesisUtterance() default ${prop}`); 20 } 21 22 test(function() { 23 const utt = new SpeechSynthesisUtterance("hello"); 24 assert_equals(utt.text, 'hello', 'text'); 25 // check that the other properties retain their defaults 26 for (const prop in DEFAULTS) { 27 if (prop != 'text') { 28 assert_equals(utt[prop], DEFAULTS[prop], prop); 29 } 30 } 31 }, 'new SpeechSynthesisUtterance("hello") text and defaults'); 32 33 test(function() { 34 const utt = new SpeechSynthesisUtterance(null); 35 assert_equals(utt.text, 'null'); 36 }, 'new SpeechSynthesisUtterance(null)'); 37 38 test(function() { 39 const utt = new SpeechSynthesisUtterance(undefined); 40 // See https://github.com/w3c/speech-api/pull/48. 41 assert_equals(utt.text, ''); 42 }, 'new SpeechSynthesisUtterance(undefined)'); 43 44 test(function() { 45 const utt = new SpeechSynthesisUtterance(); 46 utt.text = 'word'; 47 assert_equals(utt.text, 'word'); 48 }, 'SpeechSynthesisUtterance text setter'); 49 50 // TODO: setters https://github.com/w3c/speech-api/issues/29 51 </script>