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

Unified Diff: content/browser/speech/speech_recognizer_unittest.cc

Issue 6597071: Add a noise indicator to the speech bubble volume indicator. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 9 years, 10 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 side-by-side diff with in-line comments
Download patch
Index: content/browser/speech/speech_recognizer_unittest.cc
diff --git a/content/browser/speech/speech_recognizer_unittest.cc b/content/browser/speech/speech_recognizer_unittest.cc
index 836539686a8a90901ff13d14d0f3e1605bf36e8f..1871383faa710ebc902c989b1443780c949f724c 100644
--- a/content/browser/speech/speech_recognizer_unittest.cc
+++ b/content/browser/speech/speech_recognizer_unittest.cc
@@ -4,6 +4,7 @@
#include <vector>
+#include "base/rand_util.h"
#include "chrome/common/net/test_url_fetcher_factory.h"
#include "content/browser/browser_thread.h"
#include "content/browser/speech/speech_recognizer.h"
@@ -62,8 +63,9 @@ class SpeechRecognizerTest : public SpeechRecognizerDelegate,
error_ = error;
}
- virtual void SetInputVolume(int caller_id, float volume) {
+ virtual void SetInputVolume(int caller_id, float volume, float noise_volume) {
volume_ = volume;
+ noise_volume_ = noise_volume;
}
// testing::Test methods.
@@ -83,6 +85,11 @@ class SpeechRecognizerTest : public SpeechRecognizerDelegate,
audio_packet_[i] = static_cast<uint8>(i);
}
+ void FillPacketWithNoise() {
+ for (size_t i = 0; i < audio_packet_.size(); ++i)
+ audio_packet_[i] = static_cast<uint8>(base::RandInt(0, 50));
Satish 2011/03/01 16:44:17 Please ignore this part, I should be hardcoding th
bulach 2011/03/01 17:39:04 yay for deterministic tests! :)
+ }
+
protected:
MessageLoopForIO message_loop_;
BrowserThread io_thread_;
@@ -95,6 +102,7 @@ class SpeechRecognizerTest : public SpeechRecognizerDelegate,
TestAudioInputControllerFactory audio_input_controller_factory_;
std::vector<uint8> audio_packet_;
float volume_;
+ float noise_volume_;
};
TEST_F(SpeechRecognizerTest, StopNoData) {
@@ -272,6 +280,7 @@ TEST_F(SpeechRecognizerTest, SetInputVolumeCallback) {
// Feed some samples to begin with for the endpointer to do noise estimation.
int num_packets = SpeechRecognizer::kEndpointerEstimationTimeMs /
SpeechRecognizer::kAudioPacketIntervalMs;
+ FillPacketWithNoise();
for (int i = 0; i < num_packets; ++i) {
controller->event_handler()->OnData(controller, &audio_packet_[0],
audio_packet_.size());
@@ -289,7 +298,8 @@ TEST_F(SpeechRecognizerTest, SetInputVolumeCallback) {
controller->event_handler()->OnData(controller, &audio_packet_[0],
audio_packet_.size());
MessageLoop::current()->RunAllPending();
- EXPECT_FLOAT_EQ(0.9f, volume_);
+ EXPECT_FLOAT_EQ(0.81907868f, volume_);
+ EXPECT_FLOAT_EQ(0.36962864f, noise_volume_);
hans 2011/03/01 17:25:25 maybe make these magic numbers into constant varia
EXPECT_EQ(SpeechRecognizer::RECOGNIZER_NO_ERROR, error_);
EXPECT_FALSE(recording_complete_);
« content/browser/speech/speech_recognizer.cc ('K') | « content/browser/speech/speech_recognizer.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698