tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

idlharness.https.window.js (1653B)


      1 // META: script=/resources/WebIDLParser.js
      2 // META: script=/resources/idlharness.js
      3 // META: timeout=long
      4 
      5 'use strict';
      6 
      7 // https://w3c.github.io/speech-api/#dom-speechsynthesis-getvoices can
      8 // return an empty list and a voiceschanged event is fired if the list of
      9 // voices is determined asynchronously.
     10 function getVoices() {
     11  return new Promise(resolve => {
     12    const voices = speechSynthesis.getVoices();
     13    if (voices.length) {
     14        resolve(voices);
     15    } else {
     16        // wait for voiceschanged event
     17        speechSynthesis.addEventListener('voiceschanged', () => {
     18          resolve(speechSynthesis.getVoices());
     19        }, { once: true });
     20      }
     21  });
     22 }
     23 
     24 idl_test(
     25  ['speech-api'],
     26  ['dom', 'html'],
     27  (idl_array, t) => {
     28    idl_array.add_objects({
     29      SpeechGrammar: ['new SpeechGrammar()'],
     30      SpeechGrammarList: ['new SpeechGrammarList()'],
     31      SpeechRecognition: ['new SpeechRecognition()'],
     32      // TODO: SpeechRecognitionAlternative
     33      // TODO: SpeechRecognitionErrorEvent
     34      // TODO: SpeechRecognitionEvent
     35      // TODO: SpeechRecognitionResult
     36      // TODO: SpeechRecognitionResultList
     37      SpeechSynthesis: ['speechSynthesis'],
     38      // TODO: SpeechSynthesisErrorEvent
     39      // TODO: SpeechSynthesisEvent
     40      SpeechSynthesisUtterance: ['new SpeechSynthesisUtterance()'],
     41      SpeechSynthesisVoice: ['voice'],
     42      Window: ['self'],
     43    });
     44 
     45    const awaitVoice = getVoices().then(voices => self.voice = voices[0]);
     46    const timeout = new Promise((_, reject) => {
     47      t.step_timeout(() => reject('Timed out waiting for voice'), 3000);
     48    });
     49    return Promise.race([awaitVoice, timeout]);
     50  }
     51 );