| 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 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 52 MOCK_METHOD0(IsSpeaking, bool(void)); | 52 MOCK_METHOD0(IsSpeaking, bool(void)); |
| 53 | 53 |
| 54 void SetErrorToEpicFail() { | 54 void SetErrorToEpicFail() { |
| 55 set_error("epic fail"); | 55 set_error("epic fail"); |
| 56 } | 56 } |
| 57 | 57 |
| 58 void SendEndEvent(int utterance_id, | 58 void SendEndEvent(int utterance_id, |
| 59 const std::string& utterance, | 59 const std::string& utterance, |
| 60 const std::string& lang, | 60 const std::string& lang, |
| 61 const UtteranceContinuousParameters& params) { | 61 const UtteranceContinuousParameters& params) { |
| 62 MessageLoop::current()->PostDelayedTask( | 62 base::MessageLoop::current()->PostDelayedTask( |
| 63 FROM_HERE, base::Bind( | 63 FROM_HERE, |
| 64 &MockTtsPlatformImpl::SendEvent, | 64 base::Bind(&MockTtsPlatformImpl::SendEvent, |
| 65 ptr_factory_.GetWeakPtr(), | 65 ptr_factory_.GetWeakPtr(), |
| 66 false, utterance_id, TTS_EVENT_END, utterance.size(), | 66 false, |
| 67 std::string()), | 67 utterance_id, |
| 68 TTS_EVENT_END, |
| 69 utterance.size(), |
| 70 std::string()), |
| 68 base::TimeDelta()); | 71 base::TimeDelta()); |
| 69 } | 72 } |
| 70 | 73 |
| 71 void SendEndEventWhenQueueNotEmpty( | 74 void SendEndEventWhenQueueNotEmpty( |
| 72 int utterance_id, | 75 int utterance_id, |
| 73 const std::string& utterance, | 76 const std::string& utterance, |
| 74 const std::string& lang, | 77 const std::string& lang, |
| 75 const UtteranceContinuousParameters& params) { | 78 const UtteranceContinuousParameters& params) { |
| 76 MessageLoop::current()->PostDelayedTask( | 79 base::MessageLoop::current()->PostDelayedTask( |
| 77 FROM_HERE, base::Bind( | 80 FROM_HERE, |
| 78 &MockTtsPlatformImpl::SendEvent, | 81 base::Bind(&MockTtsPlatformImpl::SendEvent, |
| 79 ptr_factory_.GetWeakPtr(), | 82 ptr_factory_.GetWeakPtr(), |
| 80 true, utterance_id, TTS_EVENT_END, utterance.size(), std::string()), | 83 true, |
| 84 utterance_id, |
| 85 TTS_EVENT_END, |
| 86 utterance.size(), |
| 87 std::string()), |
| 81 base::TimeDelta()); | 88 base::TimeDelta()); |
| 82 } | 89 } |
| 83 | 90 |
| 84 void SendWordEvents(int utterance_id, | 91 void SendWordEvents(int utterance_id, |
| 85 const std::string& utterance, | 92 const std::string& utterance, |
| 86 const std::string& lang, | 93 const std::string& lang, |
| 87 const UtteranceContinuousParameters& params) { | 94 const UtteranceContinuousParameters& params) { |
| 88 for (int i = 0; i < static_cast<int>(utterance.size()); i++) { | 95 for (int i = 0; i < static_cast<int>(utterance.size()); i++) { |
| 89 if (i == 0 || utterance[i - 1] == ' ') { | 96 if (i == 0 || utterance[i - 1] == ' ') { |
| 90 MessageLoop::current()->PostDelayedTask( | 97 base::MessageLoop::current()->PostDelayedTask( |
| 91 FROM_HERE, base::Bind( | 98 FROM_HERE, |
| 92 &MockTtsPlatformImpl::SendEvent, | 99 base::Bind(&MockTtsPlatformImpl::SendEvent, |
| 93 ptr_factory_.GetWeakPtr(), | 100 ptr_factory_.GetWeakPtr(), |
| 94 false, utterance_id, TTS_EVENT_WORD, i, | 101 false, |
| 95 std::string()), | 102 utterance_id, |
| 103 TTS_EVENT_WORD, |
| 104 i, |
| 105 std::string()), |
| 96 base::TimeDelta()); | 106 base::TimeDelta()); |
| 97 } | 107 } |
| 98 } | 108 } |
| 99 } | 109 } |
| 100 | 110 |
| 101 void SendEvent(bool wait_for_non_empty_queue, | 111 void SendEvent(bool wait_for_non_empty_queue, |
| 102 int utterance_id, | 112 int utterance_id, |
| 103 TtsEventType event_type, | 113 TtsEventType event_type, |
| 104 int char_index, | 114 int char_index, |
| 105 const std::string& message) { | 115 const std::string& message) { |
| 106 TtsController* controller = TtsController::GetInstance(); | 116 TtsController* controller = TtsController::GetInstance(); |
| 107 if (wait_for_non_empty_queue && controller->QueueSize() == 0) { | 117 if (wait_for_non_empty_queue && controller->QueueSize() == 0) { |
| 108 MessageLoop::current()->PostDelayedTask( | 118 base::MessageLoop::current()->PostDelayedTask( |
| 109 FROM_HERE, base::Bind( | 119 FROM_HERE, |
| 110 &MockTtsPlatformImpl::SendEvent, | 120 base::Bind(&MockTtsPlatformImpl::SendEvent, |
| 111 ptr_factory_.GetWeakPtr(), | 121 ptr_factory_.GetWeakPtr(), |
| 112 true, utterance_id, event_type, char_index, message), | 122 true, |
| 123 utterance_id, |
| 124 event_type, |
| 125 char_index, |
| 126 message), |
| 113 base::TimeDelta::FromMilliseconds(100)); | 127 base::TimeDelta::FromMilliseconds(100)); |
| 114 return; | 128 return; |
| 115 } | 129 } |
| 116 | 130 |
| 117 controller->OnTtsEvent(utterance_id, event_type, char_index, message); | 131 controller->OnTtsEvent(utterance_id, event_type, char_index, message); |
| 118 } | 132 } |
| 119 | 133 |
| 120 private: | 134 private: |
| 121 base::WeakPtrFactory<MockTtsPlatformImpl> ptr_factory_; | 135 base::WeakPtrFactory<MockTtsPlatformImpl> ptr_factory_; |
| 122 }; | 136 }; |
| (...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 322 EXPECT_CALL(mock_platform_impl_, StopSpeaking()) | 336 EXPECT_CALL(mock_platform_impl_, StopSpeaking()) |
| 323 .WillRepeatedly(Return(true)); | 337 .WillRepeatedly(Return(true)); |
| 324 | 338 |
| 325 ASSERT_TRUE(RunExtensionTest("tts_engine/lang_matching")) << message_; | 339 ASSERT_TRUE(RunExtensionTest("tts_engine/lang_matching")) << message_; |
| 326 } | 340 } |
| 327 | 341 |
| 328 // http://crbug.com/122474 | 342 // http://crbug.com/122474 |
| 329 IN_PROC_BROWSER_TEST_F(TtsApiTest, EngineApi) { | 343 IN_PROC_BROWSER_TEST_F(TtsApiTest, EngineApi) { |
| 330 ASSERT_TRUE(RunExtensionTest("tts_engine/engine_api")) << message_; | 344 ASSERT_TRUE(RunExtensionTest("tts_engine/engine_api")) << message_; |
| 331 } | 345 } |
| OLD | NEW |