Generate TTS_EVENT_PAUSE and TTS_EVENT_RESUME events for web tests
This CL generates TTS_EVENT_PAUSE and TTS_EVENT_RESUME in WebTestTtsPlatform to get events in web tests. It modifies 'restriction-speech-synthesis.html' to test pause() and resume() in prerendering. Bug: 1365948 Change-Id: Ic9491a14c4343e88bb197db062bf4dfee2bd212e Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3981368 Reviewed-by: Hiroki Nakagawa <nhiroki@chromium.org> Reviewed-by: Evan Liu <evliu@google.com> Reviewed-by: Mike West <mkwst@chromium.org> Commit-Queue: Julie Jeongeun Kim <jkim@igalia.com> Cr-Commit-Position: refs/heads/main@{#1067415}
This commit is contained in:

committed by
Chromium LUCI CQ

parent
f67784b82f
commit
ac38936dfd
content/web_test/browser
third_party/blink/web_tests/external/wpt/speculation-rules/prerender
@ -34,6 +34,7 @@ void WebTestTtsPlatform::Speak(
|
||||
OnSpeakFinishedCallback on_speak_finished) {
|
||||
content::TtsController* controller = content::TtsController::GetInstance();
|
||||
int len = static_cast<int>(utterance.size());
|
||||
utterance_id_ = utterance_id;
|
||||
controller->OnTtsEvent(utterance_id, content::TTS_EVENT_START, 0, len,
|
||||
std::string());
|
||||
base::SequencedTaskRunner::GetCurrentDefault()->PostTask(
|
||||
@ -46,6 +47,7 @@ void WebTestTtsPlatform::SimulateEndEvent(
|
||||
int utterance_id,
|
||||
int len,
|
||||
OnSpeakFinishedCallback on_speak_finished) {
|
||||
utterance_id_ = kInvalidUtteranceId;
|
||||
std::move(on_speak_finished).Run(true);
|
||||
content::TtsController* controller = content::TtsController::GetInstance();
|
||||
controller->OnTtsEvent(utterance_id, content::TTS_EVENT_END, len, 0,
|
||||
@ -63,9 +65,17 @@ bool WebTestTtsPlatform::IsSpeaking() {
|
||||
void WebTestTtsPlatform::GetVoices(
|
||||
std::vector<content::VoiceData>* out_voices) {}
|
||||
|
||||
void WebTestTtsPlatform::Pause() {}
|
||||
void WebTestTtsPlatform::Pause() {
|
||||
content::TtsController* controller = content::TtsController::GetInstance();
|
||||
controller->OnTtsEvent(utterance_id_, content::TTS_EVENT_PAUSE, 0, 0,
|
||||
std::string());
|
||||
}
|
||||
|
||||
void WebTestTtsPlatform::Resume() {}
|
||||
void WebTestTtsPlatform::Resume() {
|
||||
content::TtsController* controller = content::TtsController::GetInstance();
|
||||
controller->OnTtsEvent(utterance_id_, content::TTS_EVENT_RESUME, 0, 0,
|
||||
std::string());
|
||||
}
|
||||
|
||||
void WebTestTtsPlatform::WillSpeakUtteranceWithVoice(
|
||||
content::TtsUtterance* utterance,
|
||||
|
@ -47,12 +47,16 @@ class WebTestTtsPlatform : public content::TtsPlatform {
|
||||
content::ExternalPlatformDelegate* GetExternalPlatformDelegate() override;
|
||||
|
||||
private:
|
||||
static const int kInvalidUtteranceId = -1;
|
||||
|
||||
WebTestTtsPlatform();
|
||||
virtual ~WebTestTtsPlatform();
|
||||
void SimulateEndEvent(int utterance_id,
|
||||
int len,
|
||||
OnSpeakFinishedCallback on_speak_finished);
|
||||
|
||||
int utterance_id_ = kInvalidUtteranceId;
|
||||
|
||||
friend struct base::DefaultSingletonTraits<WebTestTtsPlatform>;
|
||||
};
|
||||
|
||||
|
17
third_party/blink/web_tests/external/wpt/speculation-rules/prerender/resources/speech-synthesis.https.html
vendored
17
third_party/blink/web_tests/external/wpt/speculation-rules/prerender/resources/speech-synthesis.https.html
vendored
@ -41,6 +41,23 @@ if (!isPrerendering) {
|
||||
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}`);
|
||||
|
@ -55,5 +55,7 @@ function RunTest(method, 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`);
|
||||
RunTest('pause', `speechSynthesis.pause() should be deferred until the prerendered page is activated`);
|
||||
RunTest('resume', `speechSynthesis.resume() should be deferred until the prerendered page is activated`);
|
||||
</script>
|
||||
</body>
|
||||
|
Reference in New Issue
Block a user