chromium/third_party/blink/web_tests/wpt_internal/prerender/resources/speech-recognition.https.html

<!DOCTYPE html>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/speculation-rules/prerender/resources/utils.js"></script>
<script src="/speculation-rules/prerender/resources/deferred-promise-utils.js"></script>
<script src="webspeech.js"></script>

<script>
const params = new URLSearchParams(location.search);

// The main test page (restriction-speech-recognition.https.html) loads the
// initiator page, then the initiator page will prerender itself with the
// `prerendering` parameter.
const isPrerendering = params.has('prerendering');

if (!isPrerendering) {
  loadInitiatorPage();
} else {
  const method = params.get('method');
  const prerenderEventCollector = new PrerenderEventCollector();
  const promise = new Promise((resolve, reject) => {
    const reco = new webkitSpeechRecognition();
    switch(method) {
      case 'start':
        reco.onstart = () => { resolve(); }
        reco.onerror = (e) => { reject(); }
        reco.start();
        break;
      case 'stop':
        // https://wicg.github.io/speech-api/#dom-speechrecognition-stop
        // If the stop method is called on an object which is already
        // stopped, or being stopped, the user agent must ignore the
        // call. To test stop(), this test starts the recognition first
        // and it's deferred in prerendering. Then, it stops the
        // recognition and it's also deferred in prerendering. Once
        // prerendering is activated, start() and stop() work and
        // an end event should happen.
        reco.onend = () => { resolve(); }
        reco.onerror = (e) => { reject(); }
        reco.start();
        reco.stop();
        break;
      case 'abort':
        // https://wicg.github.io/speech-api/#dom-speechrecognition-abort
        // If the abort method is called on an object which is already
        // stopped or aborting, the user agent must ignore the call.
        // To test abort(), this test starts the recognition first
        // and it's deferred in prerendering. Then, it aborts the
        // recognition and it's also deferred in prerendering. Once
        // prerendering is activated, start() and abort() work and
        // an end event should happen.
        reco.onend = () => { resolve(); }
        reco.start();
        reco.abort();
        break;
    }
  });
  prerenderEventCollector.start(promise, `SpeechRecognition.${method}`);
}
</script>