blob: f7436e42ce4c2e580e9bb7e95962fb4ba8d98405 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
|
<!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-synthesis.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) => {
switch(method) {
case 'speak': {
const utter = new SpeechSynthesisUtterance('1');
// https://wicg.github.io/speech-api/#tts-methods
// This tests that speak() is completed after prerendering activation.
utter.onend = () => { resolve(); }
speechSynthesis.speak(utter);
break;
}
case 'cancel': {
const utter = new SpeechSynthesisUtterance('1');
// https://wicg.github.io/speech-api/#speechsynthesiserrorevent-attributes
// A cancel method call causes 'canceled' or 'interrupted'.
// This tests if one of them happens after prerendering activation.
utter.onerror = (e) => {
if (e.error == 'canceled' || e.error == 'interrupted')
resolve();
}
speechSynthesis.speak(utter);
speechSynthesis.cancel();
break;
}
case 'pause': {
const utter = new SpeechSynthesisUtterance('1');
utter.onpause = () => { resolve(); }
speechSynthesis.speak(utter);
speechSynthesis.pause();
// To reset the current status for the next test, it calls cancel().
speechSynthesis.cancel();
break;
}
case 'resume': {
const utter = new SpeechSynthesisUtterance('1');
utter.onresume = () => { resolve(); }
speechSynthesis.speak(utter);
speechSynthesis.pause();
speechSynthesis.resume();
break;
}
}
});
prerenderEventCollector.start(promise, `speechSynthesis.${method}`);
}
</script>
|