| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 "base/basictypes.h" | 5 #include "base/basictypes.h" |
| 6 #include "base/waitable_event.h" | 6 #include "base/waitable_event.h" |
| 7 #include "media/audio/audio_input_controller.h" | 7 #include "media/audio/audio_input_controller.h" |
| 8 #include "testing/gmock/include/gmock/gmock.h" | 8 #include "testing/gmock/include/gmock/gmock.h" |
| 9 #include "testing/gtest/include/gtest/gtest.h" | 9 #include "testing/gtest/include/gtest/gtest.h" |
| 10 | 10 |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 48 }; | 48 }; |
| 49 | 49 |
| 50 TEST(AudioInputControllerTest, CreateAndClose) { | 50 TEST(AudioInputControllerTest, CreateAndClose) { |
| 51 MockAudioInputControllerEventHandler event_handler; | 51 MockAudioInputControllerEventHandler event_handler; |
| 52 base::WaitableEvent event(false, false); | 52 base::WaitableEvent event(false, false); |
| 53 // If OnCreated is called then signal the event. | 53 // If OnCreated is called then signal the event. |
| 54 EXPECT_CALL(event_handler, OnCreated(NotNull())) | 54 EXPECT_CALL(event_handler, OnCreated(NotNull())) |
| 55 .WillOnce(InvokeWithoutArgs(&event, &base::WaitableEvent::Signal)); | 55 .WillOnce(InvokeWithoutArgs(&event, &base::WaitableEvent::Signal)); |
| 56 | 56 |
| 57 AudioParameters params(AudioParameters::AUDIO_MOCK, kChannels, | 57 AudioParameters params(AudioParameters::AUDIO_MOCK, kChannels, |
| 58 kSampleRate, kBitsPerSample); | 58 kSampleRate, kBitsPerSample, kSamplesPerPacket); |
| 59 scoped_refptr<AudioInputController> controller = | 59 scoped_refptr<AudioInputController> controller = |
| 60 AudioInputController::Create(&event_handler, params, kSamplesPerPacket); | 60 AudioInputController::Create(&event_handler, params); |
| 61 ASSERT_TRUE(controller.get()); | 61 ASSERT_TRUE(controller.get()); |
| 62 | 62 |
| 63 // Wait for OnCreated() to be called. | 63 // Wait for OnCreated() to be called. |
| 64 event.Wait(); | 64 event.Wait(); |
| 65 | 65 |
| 66 controller->Close(); | 66 controller->Close(); |
| 67 } | 67 } |
| 68 | 68 |
| 69 // Test a normal call sequence of create, record and close. | 69 // Test a normal call sequence of create, record and close. |
| 70 TEST(AudioInputControllerTest, RecordAndClose) { | 70 TEST(AudioInputControllerTest, RecordAndClose) { |
| 71 MockAudioInputControllerEventHandler event_handler; | 71 MockAudioInputControllerEventHandler event_handler; |
| 72 base::WaitableEvent event(false, false); | 72 base::WaitableEvent event(false, false); |
| 73 int count = 0; | 73 int count = 0; |
| 74 | 74 |
| 75 // If OnCreated is called then signal the event. | 75 // If OnCreated is called then signal the event. |
| 76 EXPECT_CALL(event_handler, OnCreated(NotNull())) | 76 EXPECT_CALL(event_handler, OnCreated(NotNull())) |
| 77 .WillOnce(InvokeWithoutArgs(&event, &base::WaitableEvent::Signal)); | 77 .WillOnce(InvokeWithoutArgs(&event, &base::WaitableEvent::Signal)); |
| 78 | 78 |
| 79 // OnRecording() will be called only once. | 79 // OnRecording() will be called only once. |
| 80 EXPECT_CALL(event_handler, OnRecording(NotNull())) | 80 EXPECT_CALL(event_handler, OnRecording(NotNull())) |
| 81 .Times(Exactly(1)); | 81 .Times(Exactly(1)); |
| 82 | 82 |
| 83 // If OnData is called enough then signal the event. | 83 // If OnData is called enough then signal the event. |
| 84 EXPECT_CALL(event_handler, OnData(NotNull(), NotNull(), _)) | 84 EXPECT_CALL(event_handler, OnData(NotNull(), NotNull(), _)) |
| 85 .Times(AtLeast(10)) | 85 .Times(AtLeast(10)) |
| 86 .WillRepeatedly(CheckCountAndSignalEvent(&count, 10, &event)); | 86 .WillRepeatedly(CheckCountAndSignalEvent(&count, 10, &event)); |
| 87 | 87 |
| 88 AudioParameters params(AudioParameters::AUDIO_MOCK, kChannels, | 88 AudioParameters params(AudioParameters::AUDIO_MOCK, kChannels, |
| 89 kSampleRate, kBitsPerSample); | 89 kSampleRate, kBitsPerSample, kSamplesPerPacket); |
| 90 scoped_refptr<AudioInputController> controller = | 90 scoped_refptr<AudioInputController> controller = |
| 91 AudioInputController::Create(&event_handler, params, kSamplesPerPacket); | 91 AudioInputController::Create(&event_handler, params); |
| 92 ASSERT_TRUE(controller.get()); | 92 ASSERT_TRUE(controller.get()); |
| 93 | 93 |
| 94 // Wait for OnCreated() to be called. | 94 // Wait for OnCreated() to be called. |
| 95 event.Wait(); | 95 event.Wait(); |
| 96 event.Reset(); | 96 event.Reset(); |
| 97 | 97 |
| 98 // Play and then wait for the event to be signaled. | 98 // Play and then wait for the event to be signaled. |
| 99 controller->Record(); | 99 controller->Record(); |
| 100 event.Wait(); | 100 event.Wait(); |
| 101 | 101 |
| 102 controller->Close(); | 102 controller->Close(); |
| 103 } | 103 } |
| 104 | 104 |
| 105 // Test that AudioInputController rejects insanely large packet sizes. | 105 // Test that AudioInputController rejects insanely large packet sizes. |
| 106 TEST(AudioInputControllerTest, SamplesPerPacketTooLarge) { | 106 TEST(AudioInputControllerTest, SamplesPerPacketTooLarge) { |
| 107 // Create an audio device with a very large packet size. | 107 // Create an audio device with a very large packet size. |
| 108 MockAudioInputControllerEventHandler event_handler; | 108 MockAudioInputControllerEventHandler event_handler; |
| 109 | 109 |
| 110 AudioParameters params(AudioParameters::AUDIO_MOCK, kChannels, | 110 AudioParameters params(AudioParameters::AUDIO_MOCK, kChannels, |
| 111 kSampleRate, kBitsPerSample); | 111 kSampleRate, kBitsPerSample, kSamplesPerPacket * 1000); |
| 112 scoped_refptr<AudioInputController> controller = AudioInputController::Create( | 112 scoped_refptr<AudioInputController> controller = AudioInputController::Create( |
| 113 &event_handler, params, kSamplesPerPacket * 1000); | 113 &event_handler, params); |
| 114 ASSERT_FALSE(controller); | 114 ASSERT_FALSE(controller); |
| 115 } | 115 } |
| 116 | 116 |
| 117 // Test calling AudioInputController::Close multiple times. | 117 // Test calling AudioInputController::Close multiple times. |
| 118 TEST(AudioInputControllerTest, CloseTwice) { | 118 TEST(AudioInputControllerTest, CloseTwice) { |
| 119 MockAudioInputControllerEventHandler event_handler; | 119 MockAudioInputControllerEventHandler event_handler; |
| 120 EXPECT_CALL(event_handler, OnCreated(NotNull())); | 120 EXPECT_CALL(event_handler, OnCreated(NotNull())); |
| 121 AudioParameters params(AudioParameters::AUDIO_MOCK, kChannels, | 121 AudioParameters params(AudioParameters::AUDIO_MOCK, kChannels, |
| 122 kSampleRate, kBitsPerSample); | 122 kSampleRate, kBitsPerSample, kSamplesPerPacket); |
| 123 scoped_refptr<AudioInputController> controller = | 123 scoped_refptr<AudioInputController> controller = |
| 124 AudioInputController::Create(&event_handler, params, kSamplesPerPacket); | 124 AudioInputController::Create(&event_handler, params); |
| 125 ASSERT_TRUE(controller.get()); | 125 ASSERT_TRUE(controller.get()); |
| 126 | 126 |
| 127 controller->Close(); | 127 controller->Close(); |
| 128 controller->Close(); | 128 controller->Close(); |
| 129 } | 129 } |
| 130 | 130 |
| 131 } // namespace media | 131 } // namespace media |
| OLD | NEW |