Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2703)

Unified Diff: Source/modules/speech/testing/PlatformSpeechSynthesizerMock.cpp

Issue 884973003: Extend PlatformSpeechSynthesizerMock with an utterance queue. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: minor test tidying Created 5 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « Source/modules/speech/testing/PlatformSpeechSynthesizerMock.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/modules/speech/testing/PlatformSpeechSynthesizerMock.cpp
diff --git a/Source/modules/speech/testing/PlatformSpeechSynthesizerMock.cpp b/Source/modules/speech/testing/PlatformSpeechSynthesizerMock.cpp
index dedde190c390d5ed5c955aaa59d443b8990b53b2..f874cd911aecb2f2ddfda877a1788ae904121497 100644
--- a/Source/modules/speech/testing/PlatformSpeechSynthesizerMock.cpp
+++ b/Source/modules/speech/testing/PlatformSpeechSynthesizerMock.cpp
@@ -41,29 +41,41 @@ PlatformSpeechSynthesizerMock* PlatformSpeechSynthesizerMock::create(PlatformSpe
PlatformSpeechSynthesizerMock::PlatformSpeechSynthesizerMock(PlatformSpeechSynthesizerClient* client)
: PlatformSpeechSynthesizer(client)
- , m_speakingFinishedTimer(this, &PlatformSpeechSynthesizerMock::speakingFinished)
, m_speakingErrorOccurredTimer(this, &PlatformSpeechSynthesizerMock::speakingErrorOccurred)
+ , m_speakingFinishedTimer(this, &PlatformSpeechSynthesizerMock::speakingFinished)
{
}
PlatformSpeechSynthesizerMock::~PlatformSpeechSynthesizerMock()
{
- m_speakingFinishedTimer.stop();
- m_speakingErrorOccurredTimer.stop();
+}
+
+void PlatformSpeechSynthesizerMock::speakingErrorOccurred(Timer<PlatformSpeechSynthesizerMock>*)
+{
+ ASSERT(m_currentUtterance);
+
+ client()->speakingErrorOccurred(m_currentUtterance);
+ speakNext();
}
void PlatformSpeechSynthesizerMock::speakingFinished(Timer<PlatformSpeechSynthesizerMock>*)
{
- ASSERT(m_utterance.get());
- client()->didFinishSpeaking(m_utterance);
- m_utterance = nullptr;
+ ASSERT(m_currentUtterance);
+ client()->didFinishSpeaking(m_currentUtterance);
+ speakNext();
}
-void PlatformSpeechSynthesizerMock::speakingErrorOccurred(Timer<PlatformSpeechSynthesizerMock>*)
+void PlatformSpeechSynthesizerMock::speakNext()
{
- ASSERT(m_utterance.get());
- client()->speakingErrorOccurred(m_utterance);
- m_utterance = nullptr;
+ if (m_speakingErrorOccurredTimer.isActive())
+ return;
+
+ if (m_queuedUtterances.isEmpty()) {
+ m_currentUtterance = nullptr;
+ return;
+ }
+ m_currentUtterance = m_queuedUtterances.takeFirst();
+ speakNow();
}
void PlatformSpeechSynthesizerMock::initializeVoiceList()
@@ -76,13 +88,22 @@ void PlatformSpeechSynthesizerMock::initializeVoiceList()
void PlatformSpeechSynthesizerMock::speak(PlatformSpeechSynthesisUtterance* utterance)
{
- ASSERT(!m_utterance);
- m_utterance = utterance;
- client()->didStartSpeaking(m_utterance);
+ if (!m_currentUtterance) {
+ m_currentUtterance = utterance;
+ speakNow();
+ return;
+ }
+ m_queuedUtterances.append(utterance);
+}
+
+void PlatformSpeechSynthesizerMock::speakNow()
+{
+ ASSERT(m_currentUtterance);
+ client()->didStartSpeaking(m_currentUtterance);
// Fire a fake word and then sentence boundary event.
- client()->boundaryEventOccurred(m_utterance, SpeechWordBoundary, 0);
- client()->boundaryEventOccurred(m_utterance, SpeechSentenceBoundary, m_utterance->text().length());
+ client()->boundaryEventOccurred(m_currentUtterance, SpeechWordBoundary, 0);
+ client()->boundaryEventOccurred(m_currentUtterance, SpeechSentenceBoundary, m_currentUtterance->text().length());
// Give the fake speech job some time so that pause and other functions have time to be called.
m_speakingFinishedTimer.startOneShot(.1, FROM_HERE);
@@ -90,26 +111,30 @@ void PlatformSpeechSynthesizerMock::speak(PlatformSpeechSynthesisUtterance* utte
void PlatformSpeechSynthesizerMock::cancel()
{
- if (!m_utterance)
+ if (!m_currentUtterance)
return;
+ // Per spec, removes all queued utterances.
+ m_queuedUtterances.clear();
+
m_speakingFinishedTimer.stop();
m_speakingErrorOccurredTimer.startOneShot(.1, FROM_HERE);
}
void PlatformSpeechSynthesizerMock::pause()
{
- client()->didPauseSpeaking(m_utterance);
+ client()->didPauseSpeaking(m_currentUtterance);
}
void PlatformSpeechSynthesizerMock::resume()
{
- client()->didResumeSpeaking(m_utterance);
+ client()->didResumeSpeaking(m_currentUtterance);
}
void PlatformSpeechSynthesizerMock::trace(Visitor* visitor)
{
- visitor->trace(m_utterance);
+ visitor->trace(m_currentUtterance);
+ visitor->trace(m_queuedUtterances);
PlatformSpeechSynthesizer::trace(visitor);
}
« no previous file with comments | « Source/modules/speech/testing/PlatformSpeechSynthesizerMock.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698