SpeechSynthesisErrorEvent-constructor.html (2891B)
1 <!DOCTYPE html> 2 <meta charset="utf-8"> 3 <script src="/resources/testharness.js"></script> 4 <script src="/resources/testharnessreport.js"></script> 5 <script> 6 /* 7 [Exposed=Window, 8 Constructor(DOMString type, SpeechSynthesisErrorEventInit eventInitDict)] 9 interface SpeechSynthesisErrorEvent : SpeechSynthesisErrorEvent { 10 readonly attribute SpeechSynthesisErrorCode error; 11 }; 12 */ 13 test(() => { 14 assert_throws_js(TypeError, () => { 15 new SpeechSynthesisErrorEvent(); 16 }); 17 }, "SpeechSynthesisErrorEvent with no arguments throws TypeError"); 18 19 test(() => { 20 assert_throws_js(TypeError, () => { 21 new SpeechSynthesisErrorEvent("type"); 22 }); 23 }, "SpeechSynthesisErrorEvent with no eventInitDict throws TypeError"); 24 25 test(() => { 26 assert_throws_js(TypeError, () => { 27 new SpeechSynthesisErrorEvent("type", {}); 28 }); 29 }, `SpeechSynthesisErrorEvent with empty eventInitDict throws TypeError (requires 30 utterance and error)`); 31 32 test(() => { 33 assert_throws_js(TypeError, () => { 34 new SpeechSynthesisErrorEvent("type", {error:"not-allowed"}); 35 }); 36 }, `SpeechSynthesisErrorEvent with eventInitDict without utterance throws 37 TypeError`); 38 39 test(() => { 40 assert_throws_js(TypeError, () => { 41 new SpeechSynthesisErrorEvent("type", {utterance: new SpeechSynthesisUtterance()}); 42 }); 43 }, `SpeechSynthesisErrorEvent with eventInitDict without error throws 44 TypeError`); 45 46 test(() => { 47 const utterance = new SpeechSynthesisUtterance("foo"); 48 const event = new SpeechSynthesisErrorEvent("type", {utterance: utterance, error:"not-allowed"}); 49 assert_equals(event.utterance, utterance); 50 assert_equals(event.error, "not-allowed"); 51 assert_equals(event.charIndex, 0); 52 assert_equals(event.elapsedTime, 0); 53 assert_equals(event.name, ""); 54 }, "SpeechSynthesisErrorEvent with eventInitDict having utterance and error"); 55 56 test(() => { 57 const utterance = new SpeechSynthesisUtterance("foo"); 58 const event = new SpeechSynthesisErrorEvent("type", { 59 utterance: utterance, 60 charIndex: 5, 61 elapsedTime: 100, 62 name: "foo", 63 error: "synthesis-failed" 64 }); 65 assert_equals(event.bubbles, false); 66 assert_equals(event.cancelable, false); 67 assert_equals(event.type, "type"); 68 assert_equals(event.utterance, utterance); 69 assert_equals(event.charIndex, 5); 70 assert_equals(event.elapsedTime, 100); 71 assert_equals(event.name, "foo"); 72 assert_equals(event.error, "synthesis-failed"); 73 }, "SpeechSynthesisErrorEvent with custom eventInitDict"); 74 75 test(() => { 76 function createEventFunc(error) { 77 return () => { 78 new SpeechSynthesisErrorEvent("type", { 79 utterance: new SpeechSynthesisUtterance(), 80 error: error 81 }); 82 }; 83 }; 84 assert_throws_js(TypeError, createEventFunc("")); 85 assert_throws_js(TypeError, createEventFunc("foo")); 86 assert_throws_js(TypeError, createEventFunc("bar")); 87 }, "SpeechSynthesisErrorEvent with wrong error enum"); 88 </script>