OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "base/bind.h" | 5 #include "base/bind.h" |
6 #include "base/command_line.h" | 6 #include "base/command_line.h" |
7 #include "base/memory/weak_ptr.h" | 7 #include "base/memory/weak_ptr.h" |
8 #include "base/message_loop.h" | 8 #include "base/message_loop.h" |
9 #include "chrome/browser/extensions/extension_apitest.h" | 9 #include "chrome/browser/extensions/extension_apitest.h" |
10 #include "chrome/browser/speech/extension_api/tts_extension_api.h" | 10 #include "chrome/browser/speech/extension_api/tts_extension_api.h" |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
51 | 51 |
52 void SetErrorToEpicFail() { | 52 void SetErrorToEpicFail() { |
53 set_error("epic fail"); | 53 set_error("epic fail"); |
54 } | 54 } |
55 | 55 |
56 void SendEndEvent(int utterance_id, | 56 void SendEndEvent(int utterance_id, |
57 const std::string& utterance, | 57 const std::string& utterance, |
58 const std::string& lang, | 58 const std::string& lang, |
59 const VoiceData& voice, | 59 const VoiceData& voice, |
60 const UtteranceContinuousParameters& params) { | 60 const UtteranceContinuousParameters& params) { |
61 MessageLoop::current()->PostDelayedTask( | 61 base::MessageLoop::current()->PostDelayedTask( |
62 FROM_HERE, base::Bind( | 62 FROM_HERE, base::Bind( |
63 &MockTtsPlatformImpl::SendEvent, | 63 &MockTtsPlatformImpl::SendEvent, |
64 ptr_factory_.GetWeakPtr(), | 64 ptr_factory_.GetWeakPtr(), |
65 false, utterance_id, TTS_EVENT_END, utterance.size(), | 65 false, utterance_id, TTS_EVENT_END, utterance.size(), |
66 std::string()), | 66 std::string()), |
67 base::TimeDelta()); | 67 base::TimeDelta()); |
68 } | 68 } |
69 | 69 |
70 void SendEndEventWhenQueueNotEmpty( | 70 void SendEndEventWhenQueueNotEmpty( |
71 int utterance_id, | 71 int utterance_id, |
72 const std::string& utterance, | 72 const std::string& utterance, |
73 const std::string& lang, | 73 const std::string& lang, |
74 const VoiceData& voice, | 74 const VoiceData& voice, |
75 const UtteranceContinuousParameters& params) { | 75 const UtteranceContinuousParameters& params) { |
76 MessageLoop::current()->PostDelayedTask( | 76 base::MessageLoop::current()->PostDelayedTask( |
77 FROM_HERE, base::Bind( | 77 FROM_HERE, base::Bind( |
78 &MockTtsPlatformImpl::SendEvent, | 78 &MockTtsPlatformImpl::SendEvent, |
79 ptr_factory_.GetWeakPtr(), | 79 ptr_factory_.GetWeakPtr(), |
80 true, utterance_id, TTS_EVENT_END, utterance.size(), std::string()), | 80 true, utterance_id, TTS_EVENT_END, utterance.size(), std::string()), |
81 base::TimeDelta()); | 81 base::TimeDelta()); |
82 } | 82 } |
83 | 83 |
84 void SendWordEvents(int utterance_id, | 84 void SendWordEvents(int utterance_id, |
85 const std::string& utterance, | 85 const std::string& utterance, |
86 const std::string& lang, | 86 const std::string& lang, |
87 const VoiceData& voice, | 87 const VoiceData& voice, |
88 const UtteranceContinuousParameters& params) { | 88 const UtteranceContinuousParameters& params) { |
89 for (int i = 0; i < static_cast<int>(utterance.size()); i++) { | 89 for (int i = 0; i < static_cast<int>(utterance.size()); i++) { |
90 if (i == 0 || utterance[i - 1] == ' ') { | 90 if (i == 0 || utterance[i - 1] == ' ') { |
91 MessageLoop::current()->PostDelayedTask( | 91 base::MessageLoop::current()->PostDelayedTask( |
92 FROM_HERE, base::Bind( | 92 FROM_HERE, base::Bind( |
93 &MockTtsPlatformImpl::SendEvent, | 93 &MockTtsPlatformImpl::SendEvent, |
94 ptr_factory_.GetWeakPtr(), | 94 ptr_factory_.GetWeakPtr(), |
95 false, utterance_id, TTS_EVENT_WORD, i, | 95 false, utterance_id, TTS_EVENT_WORD, i, |
96 std::string()), | 96 std::string()), |
97 base::TimeDelta()); | 97 base::TimeDelta()); |
98 } | 98 } |
99 } | 99 } |
100 } | 100 } |
101 | 101 |
102 void SendEvent(bool wait_for_non_empty_queue, | 102 void SendEvent(bool wait_for_non_empty_queue, |
103 int utterance_id, | 103 int utterance_id, |
104 TtsEventType event_type, | 104 TtsEventType event_type, |
105 int char_index, | 105 int char_index, |
106 const std::string& message) { | 106 const std::string& message) { |
107 TtsController* controller = TtsController::GetInstance(); | 107 TtsController* controller = TtsController::GetInstance(); |
108 if (wait_for_non_empty_queue && controller->QueueSize() == 0) { | 108 if (wait_for_non_empty_queue && controller->QueueSize() == 0) { |
109 MessageLoop::current()->PostDelayedTask( | 109 base::MessageLoop::current()->PostDelayedTask( |
110 FROM_HERE, base::Bind( | 110 FROM_HERE, base::Bind( |
111 &MockTtsPlatformImpl::SendEvent, | 111 &MockTtsPlatformImpl::SendEvent, |
112 ptr_factory_.GetWeakPtr(), | 112 ptr_factory_.GetWeakPtr(), |
113 true, utterance_id, event_type, char_index, message), | 113 true, utterance_id, event_type, char_index, message), |
114 base::TimeDelta::FromMilliseconds(100)); | 114 base::TimeDelta::FromMilliseconds(100)); |
115 return; | 115 return; |
116 } | 116 } |
117 | 117 |
118 controller->OnTtsEvent(utterance_id, event_type, char_index, message); | 118 controller->OnTtsEvent(utterance_id, event_type, char_index, message); |
119 } | 119 } |
(...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
325 EXPECT_CALL(mock_platform_impl_, StopSpeaking()) | 325 EXPECT_CALL(mock_platform_impl_, StopSpeaking()) |
326 .WillRepeatedly(Return(true)); | 326 .WillRepeatedly(Return(true)); |
327 | 327 |
328 ASSERT_TRUE(RunExtensionTest("tts_engine/lang_matching")) << message_; | 328 ASSERT_TRUE(RunExtensionTest("tts_engine/lang_matching")) << message_; |
329 } | 329 } |
330 | 330 |
331 // http://crbug.com/122474 | 331 // http://crbug.com/122474 |
332 IN_PROC_BROWSER_TEST_F(TtsApiTest, EngineApi) { | 332 IN_PROC_BROWSER_TEST_F(TtsApiTest, EngineApi) { |
333 ASSERT_TRUE(RunExtensionTest("tts_engine/engine_api")) << message_; | 333 ASSERT_TRUE(RunExtensionTest("tts_engine/engine_api")) << message_; |
334 } | 334 } |
OLD | NEW |