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

Side by Side Diff: content/browser/speech/speech_recognizer_impl_unittest.cc

Issue 1806313003: Pass task runners to AudioManager constructor. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: DCHECK -> CHECK Created 4 years, 8 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
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 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 7
8 #include <vector> 8 #include <vector>
9 9
10 #include "content/browser/browser_thread_impl.h"
11 #include "content/browser/speech/google_one_shot_remote_engine.h" 10 #include "content/browser/speech/google_one_shot_remote_engine.h"
12 #include "content/browser/speech/speech_recognizer_impl.h" 11 #include "content/browser/speech/speech_recognizer_impl.h"
13 #include "content/public/browser/speech_recognition_event_listener.h" 12 #include "content/public/browser/speech_recognition_event_listener.h"
13 #include "content/public/test/test_browser_thread_bundle.h"
14 #include "media/audio/audio_manager_base.h" 14 #include "media/audio/audio_manager_base.h"
15 #include "media/audio/fake_audio_input_stream.h" 15 #include "media/audio/fake_audio_input_stream.h"
16 #include "media/audio/fake_audio_output_stream.h" 16 #include "media/audio/fake_audio_output_stream.h"
17 #include "media/audio/mock_audio_manager.h" 17 #include "media/audio/mock_audio_manager.h"
18 #include "media/audio/test_audio_input_controller_factory.h" 18 #include "media/audio/test_audio_input_controller_factory.h"
19 #include "media/base/audio_bus.h" 19 #include "media/base/audio_bus.h"
20 #include "net/base/net_errors.h" 20 #include "net/base/net_errors.h"
21 #include "net/url_request/test_url_fetcher_factory.h" 21 #include "net/url_request/test_url_fetcher_factory.h"
22 #include "net/url_request/url_request_status.h" 22 #include "net/url_request/url_request_status.h"
23 #include "testing/gtest/include/gtest/gtest.h" 23 #include "testing/gtest/include/gtest/gtest.h"
24 24
25 using media::AudioInputController; 25 using media::AudioInputController;
26 using media::AudioInputStream; 26 using media::AudioInputStream;
27 using media::AudioManager;
28 using media::AudioOutputStream; 27 using media::AudioOutputStream;
29 using media::AudioParameters; 28 using media::AudioParameters;
30 using media::TestAudioInputController; 29 using media::TestAudioInputController;
31 using media::TestAudioInputControllerFactory; 30 using media::TestAudioInputControllerFactory;
32 31
33 namespace content { 32 namespace content {
34 33
35 class SpeechRecognizerImplTest : public SpeechRecognitionEventListener, 34 class SpeechRecognizerImplTest : public SpeechRecognitionEventListener,
36 public testing::Test { 35 public testing::Test {
37 public: 36 public:
38 SpeechRecognizerImplTest() 37 SpeechRecognizerImplTest()
39 : io_thread_(BrowserThread::IO, &message_loop_), 38 : recognition_started_(false),
40 recognition_started_(false),
41 recognition_ended_(false), 39 recognition_ended_(false),
42 result_received_(false), 40 result_received_(false),
43 audio_started_(false), 41 audio_started_(false),
44 audio_ended_(false), 42 audio_ended_(false),
45 sound_started_(false), 43 sound_started_(false),
46 sound_ended_(false), 44 sound_ended_(false),
47 error_(SPEECH_RECOGNITION_ERROR_NONE), 45 error_(SPEECH_RECOGNITION_ERROR_NONE),
48 volume_(-1.0f) { 46 volume_(-1.0f) {
49 // SpeechRecognizer takes ownership of sr_engine. 47 // SpeechRecognizer takes ownership of sr_engine.
50 SpeechRecognitionEngine* sr_engine = 48 SpeechRecognitionEngine* sr_engine =
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
175 int value = 0; 173 int value = 0;
176 int factor = 175; 174 int factor = 175;
177 for (size_t i = 0; i < audio_packet_.size(); ++i) { 175 for (size_t i = 0; i < audio_packet_.size(); ++i) {
178 value += factor; 176 value += factor;
179 audio_packet_[i] = value % 100; 177 audio_packet_[i] = value % 100;
180 } 178 }
181 CopyPacketToAudioBus(); 179 CopyPacketToAudioBus();
182 } 180 }
183 181
184 protected: 182 protected:
185 base::MessageLoopForIO message_loop_; 183 TestBrowserThreadBundle thread_bundle_;
186 BrowserThreadImpl io_thread_;
187 scoped_refptr<SpeechRecognizerImpl> recognizer_; 184 scoped_refptr<SpeechRecognizerImpl> recognizer_;
188 std::unique_ptr<AudioManager> audio_manager_; 185 media::ScopedAudioManagerPtr audio_manager_;
189 bool recognition_started_; 186 bool recognition_started_;
190 bool recognition_ended_; 187 bool recognition_ended_;
191 bool result_received_; 188 bool result_received_;
192 bool audio_started_; 189 bool audio_started_;
193 bool audio_ended_; 190 bool audio_ended_;
194 bool sound_started_; 191 bool sound_started_;
195 bool sound_ended_; 192 bool sound_ended_;
196 SpeechRecognitionErrorCode error_; 193 SpeechRecognitionErrorCode error_;
197 net::TestURLFetcherFactory url_fetcher_factory_; 194 net::TestURLFetcherFactory url_fetcher_factory_;
198 TestAudioInputControllerFactory audio_input_controller_factory_; 195 TestAudioInputControllerFactory audio_input_controller_factory_;
(...skipping 296 matching lines...) Expand 10 before | Expand all | Expand 10 after
495 492
496 EXPECT_EQ(SPEECH_RECOGNITION_ERROR_NONE, error_); 493 EXPECT_EQ(SPEECH_RECOGNITION_ERROR_NONE, error_);
497 EXPECT_FALSE(audio_ended_); 494 EXPECT_FALSE(audio_ended_);
498 EXPECT_FALSE(recognition_ended_); 495 EXPECT_FALSE(recognition_ended_);
499 recognizer_->AbortRecognition(); 496 recognizer_->AbortRecognition();
500 base::MessageLoop::current()->RunUntilIdle(); 497 base::MessageLoop::current()->RunUntilIdle();
501 CheckFinalEventsConsistency(); 498 CheckFinalEventsConsistency();
502 } 499 }
503 500
504 } // namespace content 501 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698