Skip to content

Commit

Permalink
Generate TTS_EVENT_PAUSE and TTS_EVENT_RESUME events for web tests
Browse files Browse the repository at this point in the history
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}
  • Loading branch information
jkim-julie authored and Chromium LUCI CQ committed Nov 4, 2022
1 parent f67784b commit ac38936
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 2 deletions.
14 changes: 12 additions & 2 deletions content/web_test/browser/web_test_tts_platform.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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,
Expand All @@ -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,
Expand Down
4 changes: 4 additions & 0 deletions content/web_test/browser/web_test_tts_platform.h
Original file line number Diff line number Diff line change
Expand Up @@ -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>;
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,23 @@
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}`);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,5 +55,7 @@

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>

0 comments on commit ac38936

Please sign in to comment.