This source file includes following definitions.
- create
- m_speakingErrorOccurredTimer
- speakingFinished
- speakingErrorOccurred
- initializeVoiceList
- speak
- cancel
- pause
- resume
#include "config.h"
#include "modules/speech/testing/PlatformSpeechSynthesizerMock.h"
#include "platform/speech/PlatformSpeechSynthesisUtterance.h"
namespace WebCore {
PassOwnPtr<PlatformSpeechSynthesizerMock> PlatformSpeechSynthesizerMock::create(PlatformSpeechSynthesizerClient* client)
{
OwnPtr<PlatformSpeechSynthesizerMock> synthesizer = adoptPtr(new PlatformSpeechSynthesizerMock(client));
synthesizer->initializeVoiceList();
client->voicesDidChange();
return synthesizer.release();
}
PlatformSpeechSynthesizerMock::PlatformSpeechSynthesizerMock(PlatformSpeechSynthesizerClient* client)
: PlatformSpeechSynthesizer(client)
, m_speakingFinishedTimer(this, &PlatformSpeechSynthesizerMock::speakingFinished)
, m_speakingErrorOccurredTimer(this, &PlatformSpeechSynthesizerMock::speakingErrorOccurred)
{
}
PlatformSpeechSynthesizerMock::~PlatformSpeechSynthesizerMock()
{
m_speakingFinishedTimer.stop();
m_speakingErrorOccurredTimer.stop();
}
void PlatformSpeechSynthesizerMock::speakingFinished(Timer<PlatformSpeechSynthesizerMock>*)
{
ASSERT(m_utterance.get());
client()->didFinishSpeaking(m_utterance);
m_utterance = nullptr;
}
void PlatformSpeechSynthesizerMock::speakingErrorOccurred(Timer<PlatformSpeechSynthesizerMock>*)
{
ASSERT(m_utterance.get());
client()->speakingErrorOccurred(m_utterance);
m_utterance = nullptr;
}
void PlatformSpeechSynthesizerMock::initializeVoiceList()
{
m_voiceList.clear();
m_voiceList.append(PlatformSpeechSynthesisVoice::create(String("mock.voice.bruce"), String("bruce"), String("en-US"), true, true));
m_voiceList.append(PlatformSpeechSynthesisVoice::create(String("mock.voice.clark"), String("clark"), String("en-US"), true, false));
m_voiceList.append(PlatformSpeechSynthesisVoice::create(String("mock.voice.logan"), String("logan"), String("fr-CA"), true, true));
}
void PlatformSpeechSynthesizerMock::speak(PassRefPtr<PlatformSpeechSynthesisUtterance> utterance)
{
ASSERT(!m_utterance);
m_utterance = utterance;
client()->didStartSpeaking(m_utterance);
client()->boundaryEventOccurred(m_utterance, SpeechWordBoundary, 0);
client()->boundaryEventOccurred(m_utterance, SpeechSentenceBoundary, m_utterance->text().length());
m_speakingFinishedTimer.startOneShot(.1, FROM_HERE);
}
void PlatformSpeechSynthesizerMock::cancel()
{
if (!m_utterance)
return;
m_speakingFinishedTimer.stop();
m_speakingErrorOccurredTimer.startOneShot(.1, FROM_HERE);
}
void PlatformSpeechSynthesizerMock::pause()
{
client()->didPauseSpeaking(m_utterance);
}
void PlatformSpeechSynthesizerMock::resume()
{
client()->didResumeSpeaking(m_utterance);
}
}