-
Notifications
You must be signed in to change notification settings - Fork 6.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduce a new enum type, mojom::SpeechSynthesisEndReason
This CL introduces a new enum type, mojom::SpeechSynthesisEndReason, to explain why an utterance is finished. The enum values are kInterrupted, kCancelled, kErrorOccurred, and kRegularEnd. It's passed by SpeechSynthesisClient::OnFinishedSpeaking() to blink. Particularly, when an utterance is finished by cancel(), JS can know by getting the error codes described in [1]. This CL also adds a test for SpeechSynthesis in prerendering. According to the spec[2], cancel() method call should have [DelayWhilePrerendering]. The test includes speak() and cancel() in prerendering and ensures that they are handled after activation. [1] https://wicg.github.io/speech-api/#speechsynthesiserrorevent-attributes [2] https://wicg.github.io/nav-speculation/prerendering.html#web-speech-patch Bug: 1365948 Change-Id: I6cdbc8c25ecea2f0b91ec154640ab235831bcc5c Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3978652 Reviewed-by: Hiroki Nakagawa <nhiroki@chromium.org> Reviewed-by: Evan Liu <evliu@google.com> Commit-Queue: Julie Jeongeun Kim <jkim@igalia.com> Reviewed-by: Mike West <mkwst@chromium.org> Reviewed-by: David Tseng <dtseng@chromium.org> Cr-Commit-Position: refs/heads/main@{#1067390}
- Loading branch information
1 parent
71181d3
commit f6a5e23
Showing
9 changed files
with
175 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
.../web_tests/external/wpt/speculation-rules/prerender/resources/speech-synthesis.https.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
<!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; | ||
} | ||
} | ||
}); | ||
prerenderEventCollector.start(promise, `speechSynthesis.${method}`); | ||
} | ||
</script> |
59 changes: 59 additions & 0 deletions
59
...link/web_tests/external/wpt/speculation-rules/prerender/restriction-speech-synthesis.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
<!DOCTYPE html> | ||
<title>Access to the speech synthesis is deferred</title> | ||
<meta name="timeout" content="long"> | ||
<script src="/resources/testharness.js"></script> | ||
<script src="/resources/testharnessreport.js"></script> | ||
<script src="/common/utils.js"></script> | ||
<script src="/speculation-rules/prerender/resources/utils.js"></script> | ||
<body> | ||
<script> | ||
|
||
setup(() => assertSpeculationRulesIsSupported()); | ||
|
||
function RunTest(method, description) { | ||
promise_test(async t => { | ||
const uid = token(); | ||
const bc = new PrerenderChannel('test-channel', uid); | ||
t.add_cleanup(_ => bc.close()); | ||
|
||
const gotMessage = new Promise(resolve => { | ||
bc.addEventListener('message', e => { | ||
resolve(e.data); | ||
}, { | ||
once: true | ||
}); | ||
}); | ||
const url = `resources/speech-synthesis.https.html?method=${method}&uid=${uid}`; | ||
window.open(url, '_blank', 'noopener'); | ||
|
||
const result = await gotMessage; | ||
const expected = [ | ||
{ | ||
event: `started waiting speechSynthesis.${method}`, | ||
prerendering: true | ||
}, | ||
{ | ||
event: `prerendering change`, | ||
prerendering: false | ||
}, | ||
{ | ||
event: `finished waiting speechSynthesis.${method}`, | ||
prerendering: false | ||
}, | ||
]; | ||
assert_equals(result.length, expected.length); | ||
for (let i = 0; i < result.length; i++) { | ||
assert_equals(result[i].event, expected[i].event, `event${i}`); | ||
assert_equals(result[i].prerendering, expected[i].prerendering, | ||
`prerendering${i}`); | ||
} | ||
|
||
// Send a close signal to PrerenderEventCollector on the prerendered page. | ||
new PrerenderChannel('close', uid).postMessage(''); | ||
}, description); | ||
} | ||
|
||
RunTest('speak', `speechSynthesis.speak(utterance) should be deferred until the prerendered page is activated`); | ||
RunTest('cancel', `speechSynthesis.cancel() should be deferred until the prerendered page is activated`); | ||
</script> | ||
</body> |