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

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: 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..2d7e5372881101111256ef805730c6296824184c 100644
--- a/Source/modules/speech/testing/PlatformSpeechSynthesizerMock.cpp
+++ b/Source/modules/speech/testing/PlatformSpeechSynthesizerMock.cpp
@@ -41,29 +41,51 @@ 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)
+ , m_speakingNextTimer(this, &PlatformSpeechSynthesizerMock::speakingNext)
haraken 2015/01/31 01:38:03 Why do we need to speakNow here? In the previous c
sof 2015/01/31 06:06:19 I don't understand, the ctor just initializes the
{
}
PlatformSpeechSynthesizerMock::~PlatformSpeechSynthesizerMock()
{
- m_speakingFinishedTimer.stop();
- m_speakingErrorOccurredTimer.stop();
+}
+
+void PlatformSpeechSynthesizerMock::speakingErrorOccurred(Timer<PlatformSpeechSynthesizerMock>*)
+{
+ ASSERT(m_currentUtterance);
+ // Per spec, removes all utterances from the queue.
+ m_queuedUtterances.clear();
+
+ 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::speakingNext(Timer<PlatformSpeechSynthesizerMock>*)
{
- ASSERT(m_utterance.get());
- client()->speakingErrorOccurred(m_utterance);
- m_utterance = nullptr;
+ ASSERT(m_currentUtterance);
+ speakNow();
+}
+
+void PlatformSpeechSynthesizerMock::speakNext()
+{
+ if (m_speakingErrorOccurredTimer.isActive())
+ return;
+
+ if (m_queuedUtterances.isEmpty()) {
+ m_currentUtterance = nullptr;
+ return;
+ }
+ m_currentUtterance = m_queuedUtterances.takeFirst();
+ // Give others a look in before starting with next.
+ m_speakingNextTimer.startOneShot(.2, FROM_HERE);
haraken 2015/01/31 01:38:03 I don't know if .2 is good or not though :)
dmazzoni 2015/01/31 06:51:11 Do we need a delay between the end of one utteranc
sof 2015/01/31 07:24:24 ok, will align with that.
sof 2015/01/31 07:36:19 Done, removing the "next" timer that was previousl
}
void PlatformSpeechSynthesizerMock::initializeVoiceList()
@@ -76,13 +98,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 +121,28 @@ void PlatformSpeechSynthesizerMock::speak(PlatformSpeechSynthesisUtterance* utte
void PlatformSpeechSynthesizerMock::cancel()
dmazzoni 2015/01/31 06:51:11 This should remove all utterances from the queue,
sof 2015/01/31 07:24:24 It should, but doesn't it suffice to do it in spea
dmazzoni 2015/01/31 07:43:30 I don't think that's right. If I call cancel() and
sof 2015/01/31 07:56:50 That makes good sense - switched to that behavior
{
- if (!m_utterance)
+ if (!m_currentUtterance)
return;
m_speakingFinishedTimer.stop();
+ m_speakingNextTimer.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