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

Unified Diff: media/audio/audio_power_monitor_unittest.cc

Issue 22339024: Crash fix: Remove MessageLoop from AudioPowerMonitor and instead use MessageLoopProxy in AudioOutpu… (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: boolean style Created 7 years, 4 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
« no previous file with comments | « media/audio/audio_power_monitor.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: media/audio/audio_power_monitor_unittest.cc
diff --git a/media/audio/audio_power_monitor_unittest.cc b/media/audio/audio_power_monitor_unittest.cc
index 938837d972986f7d6eca3dc304d4360d548dd979..1289de0ab476b8572ccca0efde846437d1289562 100644
--- a/media/audio/audio_power_monitor_unittest.cc
+++ b/media/audio/audio_power_monitor_unittest.cc
@@ -6,9 +6,6 @@
#include <limits>
-#include "base/bind.h"
-#include "base/bind_helpers.h"
-#include "base/message_loop/message_loop.h"
#include "base/time/time.h"
#include "media/base/audio_bus.h"
#include "testing/gtest/include/gtest/gtest.h"
@@ -19,7 +16,6 @@ static const int kSampleRate = 48000;
static const int kFramesPerBuffer = 128;
static const int kTimeConstantMillis = 5;
-static const int kMeasurementPeriodMillis = 20;
namespace {
@@ -158,26 +154,22 @@ class MeasurementObserver {
class AudioPowerMonitorTest : public ::testing::TestWithParam<TestScenario> {
public:
AudioPowerMonitorTest()
- : power_monitor_(
- kSampleRate,
- base::TimeDelta::FromMilliseconds(kTimeConstantMillis),
- base::TimeDelta::FromMilliseconds(kMeasurementPeriodMillis),
- &message_loop_,
- base::Bind(&AudioPowerMonitorTest::OnPowerMeasured,
- base::Unretained(this))) {}
+ : power_monitor_(kSampleRate,
+ base::TimeDelta::FromMilliseconds(kTimeConstantMillis)) {
+ }
void FeedAndCheckExpectedPowerIsMeasured(
const AudioBus& bus, float power, bool clipped) {
- // Feed the AudioPowerMonitor. It should post tasks to |message_loop_|.
+ // Feed the AudioPowerMonitor, read measurements from it, and record them in
+ // MeasurementObserver.
static const int kNumFeedIters = 100;
- for (int i = 0; i < kNumFeedIters; ++i)
- power_monitor_.Scan(bus, bus.frames());
-
- // Set up an observer and run all the enqueued tasks.
MeasurementObserver observer(power, clipped);
- current_observer_ = &observer;
- message_loop_.RunUntilIdle();
- current_observer_ = NULL;
+ for (int i = 0; i < kNumFeedIters; ++i) {
+ power_monitor_.Scan(bus, bus.frames());
+ const std::pair<float, bool>& reading =
+ power_monitor_.ReadCurrentPowerAndClip();
+ observer.OnPowerMeasured(reading.first, reading.second);
+ }
// Check that the results recorded by the observer are the same whole-number
// dBFS.
@@ -187,14 +179,7 @@ class AudioPowerMonitorTest : public ::testing::TestWithParam<TestScenario> {
}
private:
- void OnPowerMeasured(float power, bool clipped) {
- CHECK(current_observer_);
- current_observer_->OnPowerMeasured(power, clipped);
- }
-
- base::MessageLoop message_loop_;
AudioPowerMonitor power_monitor_;
- MeasurementObserver* current_observer_;
DISALLOW_COPY_AND_ASSIGN(AudioPowerMonitorTest);
};
@@ -303,7 +288,7 @@ INSTANTIATE_TEST_CASE_P(
TestScenario(kMonoMaxAmplitudeWithClip2, 1, 4,
AudioPowerMonitor::max_power(), true),
TestScenario(kMonoSilentNoise, 1, 2,
- AudioPowerMonitor::zero_power(), true).
+ AudioPowerMonitor::zero_power(), false).
WithABadSample(std::numeric_limits<float>::infinity()),
TestScenario(kMonoHalfMaxAmplitude, 1, 4,
AudioPowerMonitor::zero_power(), false).
« no previous file with comments | « media/audio/audio_power_monitor.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698