OLD | NEW |
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 "base/basictypes.h" | 5 #include "base/basictypes.h" |
6 #include "base/synchronization/waitable_event.h" | 6 #include "base/synchronization/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 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
85 AudioParameters params(AudioParameters::AUDIO_MOCK, kChannelLayout, | 85 AudioParameters params(AudioParameters::AUDIO_MOCK, kChannelLayout, |
86 kSampleRate, kBitsPerSample, kSamplesPerPacket); | 86 kSampleRate, kBitsPerSample, kSamplesPerPacket); |
87 scoped_refptr<AudioInputController> controller = | 87 scoped_refptr<AudioInputController> controller = |
88 AudioInputController::Create(&event_handler, params); | 88 AudioInputController::Create(&event_handler, params); |
89 ASSERT_TRUE(controller.get()); | 89 ASSERT_TRUE(controller.get()); |
90 | 90 |
91 // Wait for OnCreated() to be called. | 91 // Wait for OnCreated() to be called. |
92 event.Wait(); | 92 event.Wait(); |
93 event.Reset(); | 93 event.Reset(); |
94 | 94 |
95 // Play and then wait for the event to be signaled. | 95 // Record and then wait for the event to be signaled. |
96 controller->Record(); | 96 controller->Record(); |
97 event.Wait(); | 97 event.Wait(); |
98 | 98 |
99 controller->Close(); | 99 controller->Close(); |
100 } | 100 } |
101 | 101 |
| 102 // Test that the AudioInputController reports an error when the input stream |
| 103 // stops without an OnClose callback. |
| 104 TEST(AudioInputControllerTest, RecordAndError) { |
| 105 MockAudioInputControllerEventHandler event_handler; |
| 106 base::WaitableEvent event(false, false); |
| 107 int count = 0; |
| 108 |
| 109 // If OnCreated is called then signal the event. |
| 110 EXPECT_CALL(event_handler, OnCreated(NotNull())) |
| 111 .WillOnce(InvokeWithoutArgs(&event, &base::WaitableEvent::Signal)); |
| 112 |
| 113 // OnRecording() will be called only once. |
| 114 EXPECT_CALL(event_handler, OnRecording(NotNull())) |
| 115 .Times(Exactly(1)); |
| 116 |
| 117 // If OnData is called enough then signal the event. |
| 118 EXPECT_CALL(event_handler, OnData(NotNull(), NotNull(), _)) |
| 119 .Times(AtLeast(10)) |
| 120 .WillRepeatedly(CheckCountAndSignalEvent(&count, 10, &event)); |
| 121 |
| 122 // OnError will be called after the data stream stops. |
| 123 EXPECT_CALL(event_handler, OnError(NotNull(), 0)) |
| 124 .WillOnce(InvokeWithoutArgs(&event, &base::WaitableEvent::Signal)); |
| 125 |
| 126 AudioParameters params(AudioParameters::AUDIO_MOCK, kChannelLayout, |
| 127 kSampleRate, kBitsPerSample, kSamplesPerPacket); |
| 128 scoped_refptr<AudioInputController> controller = |
| 129 AudioInputController::Create(&event_handler, params); |
| 130 ASSERT_TRUE(controller.get()); |
| 131 |
| 132 // Wait for OnCreated() to be called. |
| 133 event.Wait(); |
| 134 event.Reset(); |
| 135 |
| 136 // Record and then wait for the event to be signaled. |
| 137 controller->Record(); |
| 138 event.Wait(); |
| 139 event.Reset(); |
| 140 |
| 141 // Wait for the stream to be stopped. |
| 142 AudioInputStream* stream = controller->stream(); |
| 143 stream->Stop(); |
| 144 event.Wait(); |
| 145 |
| 146 controller->Close(); |
| 147 } |
| 148 |
102 // Test that AudioInputController rejects insanely large packet sizes. | 149 // Test that AudioInputController rejects insanely large packet sizes. |
103 TEST(AudioInputControllerTest, SamplesPerPacketTooLarge) { | 150 TEST(AudioInputControllerTest, SamplesPerPacketTooLarge) { |
104 // Create an audio device with a very large packet size. | 151 // Create an audio device with a very large packet size. |
105 MockAudioInputControllerEventHandler event_handler; | 152 MockAudioInputControllerEventHandler event_handler; |
106 | 153 |
107 AudioParameters params(AudioParameters::AUDIO_MOCK, kChannelLayout, | 154 AudioParameters params(AudioParameters::AUDIO_MOCK, kChannelLayout, |
108 kSampleRate, kBitsPerSample, kSamplesPerPacket * 1000); | 155 kSampleRate, kBitsPerSample, kSamplesPerPacket * 1000); |
109 scoped_refptr<AudioInputController> controller = AudioInputController::Create( | 156 scoped_refptr<AudioInputController> controller = AudioInputController::Create( |
110 &event_handler, params); | 157 &event_handler, params); |
111 ASSERT_FALSE(controller); | 158 ASSERT_FALSE(controller); |
112 } | 159 } |
113 | 160 |
114 // Test calling AudioInputController::Close multiple times. | 161 // Test calling AudioInputController::Close multiple times. |
115 TEST(AudioInputControllerTest, CloseTwice) { | 162 TEST(AudioInputControllerTest, CloseTwice) { |
116 MockAudioInputControllerEventHandler event_handler; | 163 MockAudioInputControllerEventHandler event_handler; |
117 EXPECT_CALL(event_handler, OnCreated(NotNull())); | 164 EXPECT_CALL(event_handler, OnCreated(NotNull())); |
118 AudioParameters params(AudioParameters::AUDIO_MOCK, kChannelLayout, | 165 AudioParameters params(AudioParameters::AUDIO_MOCK, kChannelLayout, |
119 kSampleRate, kBitsPerSample, kSamplesPerPacket); | 166 kSampleRate, kBitsPerSample, kSamplesPerPacket); |
120 scoped_refptr<AudioInputController> controller = | 167 scoped_refptr<AudioInputController> controller = |
121 AudioInputController::Create(&event_handler, params); | 168 AudioInputController::Create(&event_handler, params); |
122 ASSERT_TRUE(controller.get()); | 169 ASSERT_TRUE(controller.get()); |
123 | 170 |
124 controller->Close(); | 171 controller->Close(); |
125 controller->Close(); | 172 controller->Close(); |
126 } | 173 } |
127 | 174 |
128 } // namespace media | 175 } // namespace media |
OLD | NEW |