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

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

Issue 8818012: Remove the AudioManager singleton. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Set svn eol properties for a couple of files Created 9 years 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 <vector> 5 #include <vector>
6 6
7 #include "content/browser/browser_thread_impl.h" 7 #include "content/browser/browser_thread_impl.h"
8 #include "content/browser/speech/speech_recognizer.h" 8 #include "content/browser/speech/speech_recognizer.h"
9 #include "content/test/test_url_fetcher_factory.h" 9 #include "content/test/test_url_fetcher_factory.h"
10 #include "media/audio/audio_manager.h"
10 #include "media/audio/test_audio_input_controller_factory.h" 11 #include "media/audio/test_audio_input_controller_factory.h"
11 #include "net/base/net_errors.h" 12 #include "net/base/net_errors.h"
12 #include "net/url_request/url_request_status.h" 13 #include "net/url_request/url_request_status.h"
13 #include "testing/gtest/include/gtest/gtest.h" 14 #include "testing/gtest/include/gtest/gtest.h"
14 15
15 using content::BrowserThread; 16 using content::BrowserThread;
16 using content::BrowserThreadImpl; 17 using content::BrowserThreadImpl;
17 using media::AudioInputController; 18 using media::AudioInputController;
18 using media::TestAudioInputController; 19 using media::TestAudioInputController;
19 using media::TestAudioInputControllerFactory; 20 using media::TestAudioInputControllerFactory;
20 21
21 namespace speech_input { 22 namespace speech_input {
22 23
23 class SpeechRecognizerTest : public SpeechRecognizerDelegate, 24 class SpeechRecognizerTest : public SpeechRecognizerDelegate,
24 public testing::Test { 25 public testing::Test {
25 public: 26 public:
26 SpeechRecognizerTest() 27 SpeechRecognizerTest()
27 : io_thread_(BrowserThread::IO, &message_loop_), 28 : io_thread_(BrowserThread::IO, &message_loop_),
28 ALLOW_THIS_IN_INITIALIZER_LIST( 29 audio_manager_(AudioManager::Create()),
29 recognizer_(new SpeechRecognizer(this, 1, std::string(),
30 std::string(), NULL, false,
31 std::string(), std::string()))),
32 recording_complete_(false), 30 recording_complete_(false),
33 recognition_complete_(false), 31 recognition_complete_(false),
34 result_received_(false), 32 result_received_(false),
35 audio_received_(false), 33 audio_received_(false),
36 error_(content::SPEECH_INPUT_ERROR_NONE), 34 error_(content::SPEECH_INPUT_ERROR_NONE),
37 volume_(-1.0f) { 35 volume_(-1.0f) {
36 recognizer_ = new SpeechRecognizer(this, 1, std::string(), std::string(),
37 NULL, audio_manager_, false,
38 std::string(), std::string());
38 int audio_packet_length_bytes = 39 int audio_packet_length_bytes =
39 (SpeechRecognizer::kAudioSampleRate * 40 (SpeechRecognizer::kAudioSampleRate *
40 SpeechRecognizer::kAudioPacketIntervalMs * 41 SpeechRecognizer::kAudioPacketIntervalMs *
41 ChannelLayoutToChannelCount(SpeechRecognizer::kChannelLayout) * 42 ChannelLayoutToChannelCount(SpeechRecognizer::kChannelLayout) *
42 SpeechRecognizer::kNumBitsPerAudioSample) / (8 * 1000); 43 SpeechRecognizer::kNumBitsPerAudioSample) / (8 * 1000);
43 audio_packet_.resize(audio_packet_length_bytes); 44 audio_packet_.resize(audio_packet_length_bytes);
44 } 45 }
45 46
46 // SpeechRecognizer::Delegate methods. 47 // SpeechRecognizer::Delegate methods.
47 virtual void SetRecognitionResult( 48 virtual void SetRecognitionResult(
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
104 for (size_t i = 0; i < audio_packet_.size(); ++i) { 105 for (size_t i = 0; i < audio_packet_.size(); ++i) {
105 value += factor; 106 value += factor;
106 audio_packet_[i] = value % 100; 107 audio_packet_[i] = value % 100;
107 } 108 }
108 } 109 }
109 110
110 protected: 111 protected:
111 MessageLoopForIO message_loop_; 112 MessageLoopForIO message_loop_;
112 BrowserThreadImpl io_thread_; 113 BrowserThreadImpl io_thread_;
113 scoped_refptr<SpeechRecognizer> recognizer_; 114 scoped_refptr<SpeechRecognizer> recognizer_;
115 scoped_refptr<AudioManager> audio_manager_;
114 bool recording_complete_; 116 bool recording_complete_;
115 bool recognition_complete_; 117 bool recognition_complete_;
116 bool result_received_; 118 bool result_received_;
117 bool audio_received_; 119 bool audio_received_;
118 content::SpeechInputError error_; 120 content::SpeechInputError error_;
119 TestURLFetcherFactory url_fetcher_factory_; 121 TestURLFetcherFactory url_fetcher_factory_;
120 TestAudioInputControllerFactory audio_input_controller_factory_; 122 TestAudioInputControllerFactory audio_input_controller_factory_;
121 std::vector<uint8> audio_packet_; 123 std::vector<uint8> audio_packet_;
122 float volume_; 124 float volume_;
123 float noise_volume_; 125 float noise_volume_;
(...skipping 287 matching lines...) Expand 10 before | Expand all | Expand 10 after
411 EXPECT_FLOAT_EQ(0.89926866f, volume_); 413 EXPECT_FLOAT_EQ(0.89926866f, volume_);
412 EXPECT_FLOAT_EQ(0.75071919f, noise_volume_); 414 EXPECT_FLOAT_EQ(0.75071919f, noise_volume_);
413 415
414 EXPECT_EQ(content::SPEECH_INPUT_ERROR_NONE, error_); 416 EXPECT_EQ(content::SPEECH_INPUT_ERROR_NONE, error_);
415 EXPECT_FALSE(recording_complete_); 417 EXPECT_FALSE(recording_complete_);
416 EXPECT_FALSE(recognition_complete_); 418 EXPECT_FALSE(recognition_complete_);
417 recognizer_->CancelRecognition(); 419 recognizer_->CancelRecognition();
418 } 420 }
419 421
420 } // namespace speech_input 422 } // namespace speech_input
OLDNEW
« no previous file with comments | « content/browser/speech/speech_recognizer.cc ('k') | content/renderer/media/webrtc_audio_device_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698