chromium/third_party/blink/web_tests/fast/speechsynthesis/speech-synthesis-utterance-voice.html

<!DOCTYPE html>
<title>SpeechSynthesisUtterance voice attribute</title>
<script src="../../resources/testharness.js"></script>
<script src="../../resources/testharnessreport.js"></script>
<script>
test(() => {
  const u = new SpeechSynthesisUtterance();
  assert_equals(u.voice, null);
}, 'initial state');

test(() => {
  const u = new SpeechSynthesisUtterance();
  u.voice = null;
  assert_equals(u.voice, null);
  u.voice = undefined;
  assert_equals(u.voice, null);
}, 'setting to null/undefined');

test(() => {
  const u = new SpeechSynthesisUtterance();
  for (const value of [{}, "", window]) {
    assert_throws_js(TypeError, () => { u.voice = value; } );
    assert_equals(u.voice, null);
  }
}, 'setting to non-SpeechSynthesisVoice values');

async_test((test) => {
  internals.enableMockSpeechSynthesizer(window);
  speechSynthesis.onvoiceschanged = function() {
    const u = new SpeechSynthesisUtterance();
    const voice = speechSynthesis.getVoices()[0];
    // TODO(foolip): This should test instanceof SpeechSynthesisVoice when that
    // interface is exposed.
    assert_equals(typeof voice, "object");
    u.voice = voice;
    assert_equals(u.voice, voice);
    test.done();
  };
}, 'setting to SpeechSynthesisVoice');
</script>