tor-browser

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

speech-synthesis.https.html (2377B)


      1 <!DOCTYPE html>
      2 <script src="/resources/testharness.js"></script>
      3 <script src="/resources/testharnessreport.js"></script>
      4 <script src="/speculation-rules/prerender/resources/utils.js"></script>
      5 <script src="/speculation-rules/prerender/resources/deferred-promise-utils.js"></script>
      6 <script src="webspeech.js"></script>
      7 
      8 <script>
      9 const params = new URLSearchParams(location.search);
     10 
     11 // The main test page (restriction-speech-synthesis.https.html) loads the
     12 // initiator page, then the initiator page will prerender itself with the
     13 // `prerendering` parameter.
     14 const isPrerendering = params.has('prerendering');
     15 
     16 if (!isPrerendering) {
     17  loadInitiatorPage();
     18 } else {
     19  const method = params.get('method');
     20  const prerenderEventCollector = new PrerenderEventCollector();
     21  const promise = new Promise((resolve, reject) => {
     22    switch(method) {
     23      case 'speak': {
     24        const utter = new SpeechSynthesisUtterance('1');
     25        // https://wicg.github.io/speech-api/#tts-methods
     26        // This tests that speak() is completed after prerendering activation.
     27        utter.onend = () => { resolve(); }
     28        speechSynthesis.speak(utter);
     29        break;
     30      }
     31      case 'cancel': {
     32        const utter = new SpeechSynthesisUtterance('1');
     33        // https://wicg.github.io/speech-api/#speechsynthesiserrorevent-attributes
     34        // A cancel method call causes 'canceled' or 'interrupted'.
     35        // This tests if one of them happens after prerendering activation.
     36        utter.onerror = (e) => {
     37          if (e.error == 'canceled' || e.error == 'interrupted')
     38            resolve();
     39        }
     40        speechSynthesis.speak(utter);
     41        speechSynthesis.cancel();
     42        break;
     43      }
     44      case 'pause': {
     45        const utter = new SpeechSynthesisUtterance('1');
     46        utter.onpause = () => { resolve(); }
     47        speechSynthesis.speak(utter);
     48        speechSynthesis.pause();
     49        // To reset the current status for the next test, it calls cancel().
     50        speechSynthesis.cancel();
     51        break;
     52      }
     53      case 'resume': {
     54        const utter = new SpeechSynthesisUtterance('1');
     55        utter.onresume = () => { resolve(); }
     56        speechSynthesis.speak(utter);
     57        speechSynthesis.pause();
     58        speechSynthesis.resume();
     59        break;
     60      }
     61    }
     62  });
     63  prerenderEventCollector.start(promise, `speechSynthesis.${method}`);
     64 }
     65 </script>