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

Unified Diff: media/audio/audio_input_controller_unittest.cc

Issue 2624403002: Refactor AudioInputController and related interfaces. (Closed)
Patch Set: Created 3 years, 11 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: media/audio/audio_input_controller_unittest.cc
diff --git a/media/audio/audio_input_controller_unittest.cc b/media/audio/audio_input_controller_unittest.cc
index 6d44002e817d1fba3b08b5d5051a28017f1f995e..b34eeaff2658e0f4aca6d53c9c80672674bf919b 100644
--- a/media/audio/audio_input_controller_unittest.cc
+++ b/media/audio/audio_input_controller_unittest.cc
@@ -53,8 +53,6 @@ class MockAudioInputControllerEventHandler
MOCK_METHOD1(OnCreated, void(AudioInputController* controller));
MOCK_METHOD2(OnError, void(AudioInputController* controller,
AudioInputController::ErrorCode error_code));
- MOCK_METHOD2(OnData,
- void(AudioInputController* controller, const AudioBus* data));
MOCK_METHOD2(OnLog,
void(AudioInputController* controller,
const std::string& message));
@@ -63,6 +61,18 @@ class MockAudioInputControllerEventHandler
DISALLOW_COPY_AND_ASSIGN(MockAudioInputControllerEventHandler);
};
+class MockSyncWriter : public AudioInputController::SyncWriter {
+ public:
+ MockSyncWriter() {}
+
+ MOCK_METHOD4(Write,
+ void(const AudioBus* data,
+ double volume,
+ bool key_pressed,
+ uint32_t hardware_delay_bytes));
+ MOCK_METHOD0(Close, void());
+};
+
// Test fixture.
class AudioInputControllerTest : public testing::Test {
public:
@@ -90,6 +100,7 @@ TEST_F(AudioInputControllerTest, CreateAndClose) {
base::RunLoop run_loop;
MockAudioInputControllerEventHandler event_handler;
+ MockSyncWriter sync_writer;
// OnCreated() will be posted once.
EXPECT_CALL(event_handler, OnCreated(NotNull()))
@@ -99,7 +110,7 @@ TEST_F(AudioInputControllerTest, CreateAndClose) {
kSampleRate, kBitsPerSample, kSamplesPerPacket);
scoped_refptr<AudioInputController> controller = AudioInputController::Create(
- audio_manager_.get(), &event_handler, params,
+ audio_manager_.get(), &event_handler, &sync_writer, params,
AudioDeviceDescription::kDefaultDeviceId, NULL);
ASSERT_TRUE(controller.get());
@@ -113,30 +124,31 @@ TEST_F(AudioInputControllerTest, CreateAndClose) {
// Test a normal call sequence of create, record and close.
TEST_F(AudioInputControllerTest, RecordAndClose) {
MockAudioInputControllerEventHandler event_handler;
+ MockSyncWriter sync_writer;
int count = 0;
// OnCreated() will be called once.
EXPECT_CALL(event_handler, OnCreated(NotNull()))
.Times(Exactly(1));
- // OnData() shall be called ten times.
- EXPECT_CALL(event_handler, OnData(NotNull(), NotNull()))
+ // Write() should be called ten times.
+ EXPECT_CALL(sync_writer, Write(NotNull(), _, _, _))
.Times(AtLeast(10))
- .WillRepeatedly(CheckCountAndPostQuitTask(
- &count, 10, message_loop_.task_runner()));
+ .WillRepeatedly(
+ CheckCountAndPostQuitTask(&count, 10, message_loop_.task_runner()));
AudioParameters params(AudioParameters::AUDIO_FAKE, kChannelLayout,
kSampleRate, kBitsPerSample, kSamplesPerPacket);
// Creating the AudioInputController should render an OnCreated() call.
scoped_refptr<AudioInputController> controller = AudioInputController::Create(
- audio_manager_.get(), &event_handler, params,
+ audio_manager_.get(), &event_handler, &sync_writer, params,
AudioDeviceDescription::kDefaultDeviceId, NULL);
ASSERT_TRUE(controller.get());
controller->Record();
- // Record and wait until ten OnData() callbacks are received.
+ // Record and wait until ten Write() callbacks are received.
base::RunLoop().Run();
// Close the AudioInputController synchronously.
@@ -147,6 +159,7 @@ TEST_F(AudioInputControllerTest, RecordAndClose) {
TEST_F(AudioInputControllerTest, SamplesPerPacketTooLarge) {
// Create an audio device with a very large packet size.
MockAudioInputControllerEventHandler event_handler;
+ MockSyncWriter sync_writer;
// OnCreated() shall not be called in this test.
EXPECT_CALL(event_handler, OnCreated(NotNull()))
@@ -158,7 +171,7 @@ TEST_F(AudioInputControllerTest, SamplesPerPacketTooLarge) {
kBitsPerSample,
kSamplesPerPacket * 1000);
scoped_refptr<AudioInputController> controller = AudioInputController::Create(
- audio_manager_.get(), &event_handler, params,
+ audio_manager_.get(), &event_handler, &sync_writer, params,
AudioDeviceDescription::kDefaultDeviceId, NULL);
ASSERT_FALSE(controller.get());
}
@@ -166,6 +179,7 @@ TEST_F(AudioInputControllerTest, SamplesPerPacketTooLarge) {
// Test calling AudioInputController::Close multiple times.
TEST_F(AudioInputControllerTest, CloseTwice) {
MockAudioInputControllerEventHandler event_handler;
+ MockSyncWriter sync_writer;
// OnCreated() will be called only once.
EXPECT_CALL(event_handler, OnCreated(NotNull()));
@@ -176,7 +190,7 @@ TEST_F(AudioInputControllerTest, CloseTwice) {
kBitsPerSample,
kSamplesPerPacket);
scoped_refptr<AudioInputController> controller = AudioInputController::Create(
- audio_manager_.get(), &event_handler, params,
+ audio_manager_.get(), &event_handler, &sync_writer, params,
AudioDeviceDescription::kDefaultDeviceId, NULL);
ASSERT_TRUE(controller.get());

Powered by Google App Engine
This is Rietveld 408576698