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/env_var.h" | 5 #include "base/env_var.h" |
6 #include "base/basictypes.h" | 6 #include "base/basictypes.h" |
7 #include "base/waitable_event.h" | 7 #include "base/waitable_event.h" |
8 #include "media/audio/audio_controller.h" | 8 #include "media/audio/audio_controller.h" |
9 #include "testing/gmock/include/gmock/gmock.h" | 9 #include "testing/gmock/include/gmock/gmock.h" |
10 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
64 return true; | 64 return true; |
65 return false; | 65 return false; |
66 } | 66 } |
67 | 67 |
68 ACTION_P3(SignalEvent, event, count, limit) { | 68 ACTION_P3(SignalEvent, event, count, limit) { |
69 if (++*count >= limit) { | 69 if (++*count >= limit) { |
70 event->Signal(); | 70 event->Signal(); |
71 } | 71 } |
72 } | 72 } |
73 | 73 |
| 74 TEST(AudioControllerTest, CreateAndClose) { |
| 75 if (!HasAudioDevices() || IsRunningHeadless()) |
| 76 return; |
| 77 |
| 78 MockAudioControllerEventHandler event_handler; |
| 79 scoped_refptr<AudioController> controller = AudioController::Create( |
| 80 &event_handler, AudioManager::AUDIO_PCM_LINEAR, kChannels, |
| 81 kSampleRate, kBitsPerSample, kHardwareBufferSize, kBufferCapacity); |
| 82 ASSERT_TRUE(controller.get()); |
| 83 |
| 84 // Close the controller immediately. |
| 85 controller->Close(); |
| 86 |
| 87 // TODO(hclam): Make sure releasing the reference to this |
| 88 // object actually destruct it. |
| 89 controller = NULL; |
| 90 } |
| 91 |
74 TEST(AudioControllerTest, PlayAndClose) { | 92 TEST(AudioControllerTest, PlayAndClose) { |
75 if (!HasAudioDevices() || IsRunningHeadless()) | 93 if (!HasAudioDevices() || IsRunningHeadless()) |
76 return; | 94 return; |
77 | 95 |
78 MockAudioControllerEventHandler event_handler; | 96 MockAudioControllerEventHandler event_handler; |
79 base::WaitableEvent event(false, false); | 97 base::WaitableEvent event(false, false); |
80 int count = 0; | 98 int count = 0; |
81 | 99 |
82 // If OnCreated is called then signal the event. | 100 // If OnCreated is called then signal the event. |
83 EXPECT_CALL(event_handler, OnCreated(NotNull())) | 101 EXPECT_CALL(event_handler, OnCreated(NotNull())) |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
177 scoped_refptr<AudioController> controller = AudioController::Create( | 195 scoped_refptr<AudioController> controller = AudioController::Create( |
178 &event_handler, AudioManager::AUDIO_PCM_LINEAR, kChannels, | 196 &event_handler, AudioManager::AUDIO_PCM_LINEAR, kChannels, |
179 kSampleRate, kBitsPerSample, kHardwareBufferSize * 1000, | 197 kSampleRate, kBitsPerSample, kHardwareBufferSize * 1000, |
180 kBufferCapacity); | 198 kBufferCapacity); |
181 | 199 |
182 // Use assert because we don't stop the device and assume we can't | 200 // Use assert because we don't stop the device and assume we can't |
183 // create one. | 201 // create one. |
184 ASSERT_FALSE(controller); | 202 ASSERT_FALSE(controller); |
185 } | 203 } |
186 | 204 |
| 205 TEST(AudioControllerTest, CloseTwice) { |
| 206 if (!HasAudioDevices() || IsRunningHeadless()) |
| 207 return; |
| 208 |
| 209 MockAudioControllerEventHandler event_handler; |
| 210 scoped_refptr<AudioController> controller = AudioController::Create( |
| 211 &event_handler, AudioManager::AUDIO_PCM_LINEAR, kChannels, |
| 212 kSampleRate, kBitsPerSample, kHardwareBufferSize, kBufferCapacity); |
| 213 ASSERT_TRUE(controller.get()); |
| 214 |
| 215 // Close the controller immediately. |
| 216 controller->Close(); |
| 217 controller->Close(); |
| 218 |
| 219 // TODO(hclam): Make sure releasing the reference to this |
| 220 // object actually destruct it. |
| 221 controller = NULL; |
| 222 } |
| 223 |
187 } // namespace media | 224 } // namespace media |
OLD | NEW |