| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 <stddef.h> | 5 #include <stddef.h> |
| 6 #include <stdint.h> | 6 #include <stdint.h> |
| 7 #include <string.h> | 7 #include <string.h> |
| 8 | 8 |
| 9 #include <list> | 9 #include <list> |
| 10 #include <memory> | 10 #include <memory> |
| (...skipping 10 matching lines...) Expand all Loading... |
| 21 #include "content/public/browser/browser_thread.h" | 21 #include "content/public/browser/browser_thread.h" |
| 22 #include "content/public/browser/notification_types.h" | 22 #include "content/public/browser/notification_types.h" |
| 23 #include "content/public/browser/web_contents.h" | 23 #include "content/public/browser/web_contents.h" |
| 24 #include "content/public/test/browser_test_utils.h" | 24 #include "content/public/test/browser_test_utils.h" |
| 25 #include "content/public/test/content_browser_test.h" | 25 #include "content/public/test/content_browser_test.h" |
| 26 #include "content/public/test/content_browser_test_utils.h" | 26 #include "content/public/test/content_browser_test_utils.h" |
| 27 #include "content/public/test/test_utils.h" | 27 #include "content/public/test/test_utils.h" |
| 28 #include "content/shell/browser/shell.h" | 28 #include "content/shell/browser/shell.h" |
| 29 #include "content/test/mock_google_streaming_server.h" | 29 #include "content/test/mock_google_streaming_server.h" |
| 30 #include "media/audio/audio_system_impl.h" | 30 #include "media/audio/audio_system_impl.h" |
| 31 #include "media/audio/audio_thread_impl.h" |
| 31 #include "media/audio/mock_audio_manager.h" | 32 #include "media/audio/mock_audio_manager.h" |
| 32 #include "media/audio/test_audio_input_controller_factory.h" | 33 #include "media/audio/test_audio_input_controller_factory.h" |
| 33 #include "testing/gtest/include/gtest/gtest.h" | 34 #include "testing/gtest/include/gtest/gtest.h" |
| 34 | 35 |
| 35 using base::RunLoop; | 36 using base::RunLoop; |
| 36 | 37 |
| 37 namespace content { | 38 namespace content { |
| 38 | 39 |
| 39 class SpeechRecognitionBrowserTest : | 40 class SpeechRecognitionBrowserTest : |
| 40 public ContentBrowserTest, | 41 public ContentBrowserTest, |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 115 test_audio_input_controller_factory_.set_delegate(this); | 116 test_audio_input_controller_factory_.set_delegate(this); |
| 116 media::AudioInputController::set_factory_for_testing( | 117 media::AudioInputController::set_factory_for_testing( |
| 117 &test_audio_input_controller_factory_); | 118 &test_audio_input_controller_factory_); |
| 118 mock_streaming_server_.reset(new MockGoogleStreamingServer(this)); | 119 mock_streaming_server_.reset(new MockGoogleStreamingServer(this)); |
| 119 streaming_server_state_ = kIdle; | 120 streaming_server_state_ = kIdle; |
| 120 | 121 |
| 121 ASSERT_TRUE(SpeechRecognitionManagerImpl::GetInstance()); | 122 ASSERT_TRUE(SpeechRecognitionManagerImpl::GetInstance()); |
| 122 media::AudioManager::StartHangMonitorIfNeeded( | 123 media::AudioManager::StartHangMonitorIfNeeded( |
| 123 BrowserThread::GetTaskRunnerForThread(BrowserThread::IO)); | 124 BrowserThread::GetTaskRunnerForThread(BrowserThread::IO)); |
| 124 audio_manager_.reset(new media::MockAudioManager( | 125 audio_manager_.reset(new media::MockAudioManager( |
| 125 BrowserThread::GetTaskRunnerForThread(BrowserThread::IO))); | 126 base::MakeUnique<media::AudioThreadImpl>())); |
| 126 audio_manager_->SetInputStreamParameters( | 127 audio_manager_->SetInputStreamParameters( |
| 127 media::AudioParameters::UnavailableDeviceParams()); | 128 media::AudioParameters::UnavailableDeviceParams()); |
| 128 audio_system_ = media::AudioSystemImpl::Create(audio_manager_.get()); | 129 audio_system_ = media::AudioSystemImpl::Create(audio_manager_.get()); |
| 129 SpeechRecognizerImpl::SetAudioEnvironmentForTesting(audio_system_.get(), | 130 SpeechRecognizerImpl::SetAudioEnvironmentForTesting(audio_system_.get(), |
| 130 audio_manager_.get()); | 131 audio_manager_.get()); |
| 131 } | 132 } |
| 132 | 133 |
| 133 void TearDownOnMainThread() override { | 134 void TearDownOnMainThread() override { |
| 134 SpeechRecognizerImpl::SetAudioEnvironmentForTesting(nullptr, nullptr); | 135 SpeechRecognizerImpl::SetAudioEnvironmentForTesting(nullptr, nullptr); |
| 135 | 136 |
| 136 // Deleting AudioManager on audio thread, | 137 audio_manager_->Shutdown(); |
| 137 audio_system_.reset(); | |
| 138 audio_manager_.reset(); | |
| 139 | 138 |
| 140 test_audio_input_controller_factory_.set_delegate(nullptr); | 139 test_audio_input_controller_factory_.set_delegate(nullptr); |
| 141 mock_streaming_server_.reset(); | 140 mock_streaming_server_.reset(); |
| 142 } | 141 } |
| 143 | 142 |
| 144 private: | 143 private: |
| 145 static void FeedSingleBufferToAudioController( | 144 static void FeedSingleBufferToAudioController( |
| 146 scoped_refptr<media::TestAudioInputController> controller, | 145 scoped_refptr<media::TestAudioInputController> controller, |
| 147 size_t buffer_size, | 146 size_t buffer_size, |
| 148 bool fill_with_noise) { | 147 bool fill_with_noise) { |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 188 } | 187 } |
| 189 } | 188 } |
| 190 | 189 |
| 191 SpeechRecognitionResult GetGoodSpeechResult() { | 190 SpeechRecognitionResult GetGoodSpeechResult() { |
| 192 SpeechRecognitionResult result; | 191 SpeechRecognitionResult result; |
| 193 result.hypotheses.push_back(SpeechRecognitionHypothesis( | 192 result.hypotheses.push_back(SpeechRecognitionHypothesis( |
| 194 base::UTF8ToUTF16("Pictures of the moon"), 1.0F)); | 193 base::UTF8ToUTF16("Pictures of the moon"), 1.0F)); |
| 195 return result; | 194 return result; |
| 196 } | 195 } |
| 197 | 196 |
| 198 media::MockAudioManager::UniquePtr audio_manager_; | 197 std::unique_ptr<media::MockAudioManager> audio_manager_; |
| 199 std::unique_ptr<media::AudioSystem> audio_system_; | 198 std::unique_ptr<media::AudioSystem> audio_system_; |
| 200 StreamingServerState streaming_server_state_; | 199 StreamingServerState streaming_server_state_; |
| 201 std::unique_ptr<MockGoogleStreamingServer> mock_streaming_server_; | 200 std::unique_ptr<MockGoogleStreamingServer> mock_streaming_server_; |
| 202 media::TestAudioInputControllerFactory test_audio_input_controller_factory_; | 201 media::TestAudioInputControllerFactory test_audio_input_controller_factory_; |
| 203 }; | 202 }; |
| 204 | 203 |
| 205 // Simply loads the test page and checks if it was able to create a Speech | 204 // Simply loads the test page and checks if it was able to create a Speech |
| 206 // Recognition object in JavaScript, to make sure the Web Speech API is enabled. | 205 // Recognition object in JavaScript, to make sure the Web Speech API is enabled. |
| 207 // Flaky on all platforms. http://crbug.com/396414. | 206 // Flaky on all platforms. http://crbug.com/396414. |
| 208 IN_PROC_BROWSER_TEST_F(SpeechRecognitionBrowserTest, DISABLED_Precheck) { | 207 IN_PROC_BROWSER_TEST_F(SpeechRecognitionBrowserTest, DISABLED_Precheck) { |
| 209 NavigateToURLBlockUntilNavigationsComplete( | 208 NavigateToURLBlockUntilNavigationsComplete( |
| 210 shell(), GetTestUrlFromFragment("precheck"), 2); | 209 shell(), GetTestUrlFromFragment("precheck"), 2); |
| 211 | 210 |
| 212 EXPECT_EQ(kIdle, streaming_server_state()); | 211 EXPECT_EQ(kIdle, streaming_server_state()); |
| 213 EXPECT_EQ("success", GetPageFragment()); | 212 EXPECT_EQ("success", GetPageFragment()); |
| 214 } | 213 } |
| 215 | 214 |
| 216 IN_PROC_BROWSER_TEST_F(SpeechRecognitionBrowserTest, OneShotRecognition) { | 215 IN_PROC_BROWSER_TEST_F(SpeechRecognitionBrowserTest, OneShotRecognition) { |
| 217 NavigateToURLBlockUntilNavigationsComplete( | 216 NavigateToURLBlockUntilNavigationsComplete( |
| 218 shell(), GetTestUrlFromFragment("oneshot"), 2); | 217 shell(), GetTestUrlFromFragment("oneshot"), 2); |
| 219 | 218 |
| 220 EXPECT_EQ(kClientDisconnected, streaming_server_state()); | 219 EXPECT_EQ(kClientDisconnected, streaming_server_state()); |
| 221 EXPECT_EQ("goodresult1", GetPageFragment()); | 220 EXPECT_EQ("goodresult1", GetPageFragment()); |
| 222 } | 221 } |
| 223 | 222 |
| 224 } // namespace content | 223 } // namespace content |
| OLD | NEW |