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

Side by Side 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, 10 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 unified diff | Download patch
« no previous file with comments | « Source/modules/speech/testing/PlatformSpeechSynthesizerMock.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2013 Apple Computer, Inc. All rights reserved. 2 * Copyright (C) 2013 Apple Computer, Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions 5 * modification, are permitted provided that the following conditions
6 * are met: 6 * are met:
7 * 1. Redistributions of source code must retain the above copyright 7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer. 8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright 9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the 10 * notice, this list of conditions and the following disclaimer in the
(...skipping 23 matching lines...) Expand all
34 PlatformSpeechSynthesizerMock* PlatformSpeechSynthesizerMock::create(PlatformSpe echSynthesizerClient* client) 34 PlatformSpeechSynthesizerMock* PlatformSpeechSynthesizerMock::create(PlatformSpe echSynthesizerClient* client)
35 { 35 {
36 PlatformSpeechSynthesizerMock* synthesizer = new PlatformSpeechSynthesizerMo ck(client); 36 PlatformSpeechSynthesizerMock* synthesizer = new PlatformSpeechSynthesizerMo ck(client);
37 synthesizer->initializeVoiceList(); 37 synthesizer->initializeVoiceList();
38 client->voicesDidChange(); 38 client->voicesDidChange();
39 return synthesizer; 39 return synthesizer;
40 } 40 }
41 41
42 PlatformSpeechSynthesizerMock::PlatformSpeechSynthesizerMock(PlatformSpeechSynth esizerClient* client) 42 PlatformSpeechSynthesizerMock::PlatformSpeechSynthesizerMock(PlatformSpeechSynth esizerClient* client)
43 : PlatformSpeechSynthesizer(client) 43 : PlatformSpeechSynthesizer(client)
44 , m_speakingErrorOccurredTimer(this, &PlatformSpeechSynthesizerMock::speakin gErrorOccurred)
44 , m_speakingFinishedTimer(this, &PlatformSpeechSynthesizerMock::speakingFini shed) 45 , m_speakingFinishedTimer(this, &PlatformSpeechSynthesizerMock::speakingFini shed)
45 , m_speakingErrorOccurredTimer(this, &PlatformSpeechSynthesizerMock::speakin gErrorOccurred)
46 { 46 {
47 } 47 }
48 48
49 PlatformSpeechSynthesizerMock::~PlatformSpeechSynthesizerMock() 49 PlatformSpeechSynthesizerMock::~PlatformSpeechSynthesizerMock()
50 { 50 {
51 m_speakingFinishedTimer.stop(); 51 }
52 m_speakingErrorOccurredTimer.stop(); 52
53 void PlatformSpeechSynthesizerMock::speakingErrorOccurred(Timer<PlatformSpeechSy nthesizerMock>*)
54 {
55 ASSERT(m_currentUtterance);
56
57 client()->speakingErrorOccurred(m_currentUtterance);
58 speakNext();
53 } 59 }
54 60
55 void PlatformSpeechSynthesizerMock::speakingFinished(Timer<PlatformSpeechSynthes izerMock>*) 61 void PlatformSpeechSynthesizerMock::speakingFinished(Timer<PlatformSpeechSynthes izerMock>*)
56 { 62 {
57 ASSERT(m_utterance.get()); 63 ASSERT(m_currentUtterance);
58 client()->didFinishSpeaking(m_utterance); 64 client()->didFinishSpeaking(m_currentUtterance);
59 m_utterance = nullptr; 65 speakNext();
60 } 66 }
61 67
62 void PlatformSpeechSynthesizerMock::speakingErrorOccurred(Timer<PlatformSpeechSy nthesizerMock>*) 68 void PlatformSpeechSynthesizerMock::speakNext()
63 { 69 {
64 ASSERT(m_utterance.get()); 70 if (m_speakingErrorOccurredTimer.isActive())
65 client()->speakingErrorOccurred(m_utterance); 71 return;
66 m_utterance = nullptr; 72
73 if (m_queuedUtterances.isEmpty()) {
74 m_currentUtterance = nullptr;
75 return;
76 }
77 m_currentUtterance = m_queuedUtterances.takeFirst();
78 speakNow();
67 } 79 }
68 80
69 void PlatformSpeechSynthesizerMock::initializeVoiceList() 81 void PlatformSpeechSynthesizerMock::initializeVoiceList()
70 { 82 {
71 m_voiceList.clear(); 83 m_voiceList.clear();
72 m_voiceList.append(PlatformSpeechSynthesisVoice::create(String("mock.voice.b ruce"), String("bruce"), String("en-US"), true, true)); 84 m_voiceList.append(PlatformSpeechSynthesisVoice::create(String("mock.voice.b ruce"), String("bruce"), String("en-US"), true, true));
73 m_voiceList.append(PlatformSpeechSynthesisVoice::create(String("mock.voice.c lark"), String("clark"), String("en-US"), true, false)); 85 m_voiceList.append(PlatformSpeechSynthesisVoice::create(String("mock.voice.c lark"), String("clark"), String("en-US"), true, false));
74 m_voiceList.append(PlatformSpeechSynthesisVoice::create(String("mock.voice.l ogan"), String("logan"), String("fr-CA"), true, true)); 86 m_voiceList.append(PlatformSpeechSynthesisVoice::create(String("mock.voice.l ogan"), String("logan"), String("fr-CA"), true, true));
75 } 87 }
76 88
77 void PlatformSpeechSynthesizerMock::speak(PlatformSpeechSynthesisUtterance* utte rance) 89 void PlatformSpeechSynthesizerMock::speak(PlatformSpeechSynthesisUtterance* utte rance)
78 { 90 {
79 ASSERT(!m_utterance); 91 if (!m_currentUtterance) {
80 m_utterance = utterance; 92 m_currentUtterance = utterance;
81 client()->didStartSpeaking(m_utterance); 93 speakNow();
94 return;
95 }
96 m_queuedUtterances.append(utterance);
97 }
98
99 void PlatformSpeechSynthesizerMock::speakNow()
100 {
101 ASSERT(m_currentUtterance);
102 client()->didStartSpeaking(m_currentUtterance);
82 103
83 // Fire a fake word and then sentence boundary event. 104 // Fire a fake word and then sentence boundary event.
84 client()->boundaryEventOccurred(m_utterance, SpeechWordBoundary, 0); 105 client()->boundaryEventOccurred(m_currentUtterance, SpeechWordBoundary, 0);
85 client()->boundaryEventOccurred(m_utterance, SpeechSentenceBoundary, m_utter ance->text().length()); 106 client()->boundaryEventOccurred(m_currentUtterance, SpeechSentenceBoundary, m_currentUtterance->text().length());
86 107
87 // Give the fake speech job some time so that pause and other functions have time to be called. 108 // Give the fake speech job some time so that pause and other functions have time to be called.
88 m_speakingFinishedTimer.startOneShot(.1, FROM_HERE); 109 m_speakingFinishedTimer.startOneShot(.1, FROM_HERE);
89 } 110 }
90 111
91 void PlatformSpeechSynthesizerMock::cancel() 112 void PlatformSpeechSynthesizerMock::cancel()
92 { 113 {
93 if (!m_utterance) 114 if (!m_currentUtterance)
94 return; 115 return;
95 116
117 // Per spec, removes all queued utterances.
118 m_queuedUtterances.clear();
119
96 m_speakingFinishedTimer.stop(); 120 m_speakingFinishedTimer.stop();
97 m_speakingErrorOccurredTimer.startOneShot(.1, FROM_HERE); 121 m_speakingErrorOccurredTimer.startOneShot(.1, FROM_HERE);
98 } 122 }
99 123
100 void PlatformSpeechSynthesizerMock::pause() 124 void PlatformSpeechSynthesizerMock::pause()
101 { 125 {
102 client()->didPauseSpeaking(m_utterance); 126 client()->didPauseSpeaking(m_currentUtterance);
103 } 127 }
104 128
105 void PlatformSpeechSynthesizerMock::resume() 129 void PlatformSpeechSynthesizerMock::resume()
106 { 130 {
107 client()->didResumeSpeaking(m_utterance); 131 client()->didResumeSpeaking(m_currentUtterance);
108 } 132 }
109 133
110 void PlatformSpeechSynthesizerMock::trace(Visitor* visitor) 134 void PlatformSpeechSynthesizerMock::trace(Visitor* visitor)
111 { 135 {
112 visitor->trace(m_utterance); 136 visitor->trace(m_currentUtterance);
137 visitor->trace(m_queuedUtterances);
113 PlatformSpeechSynthesizer::trace(visitor); 138 PlatformSpeechSynthesizer::trace(visitor);
114 } 139 }
115 140
116 } // namespace blink 141 } // namespace blink
OLDNEW
« 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