OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/memory/scoped_ptr.h" | 6 #include "base/memory/scoped_ptr.h" |
7 #include "base/message_loop/message_loop.h" | 7 #include "base/message_loop/message_loop.h" |
8 #include "base/run_loop.h" | 8 #include "base/run_loop.h" |
9 #include "base/synchronization/waitable_event.h" | 9 #include "base/synchronization/waitable_event.h" |
10 #include "media/audio/audio_io.h" | 10 #include "media/audio/audio_io.h" |
11 #include "media/audio/audio_manager.h" | 11 #include "media/audio/audio_manager.h" |
| 12 #include "media/audio/audio_unittest_util.h" |
12 #include "media/audio/mock_audio_source_callback.h" | 13 #include "media/audio/mock_audio_source_callback.h" |
13 #include "testing/gmock/include/gmock/gmock.h" | 14 #include "testing/gmock/include/gmock/gmock.h" |
14 #include "testing/gtest/include/gtest/gtest.h" | 15 #include "testing/gtest/include/gtest/gtest.h" |
15 | 16 |
16 using testing::_; | 17 using testing::_; |
17 using testing::DoAll; | 18 using testing::DoAll; |
18 using testing::Return; | 19 using testing::Return; |
19 | 20 |
20 // TODO(crogers): Most of these tests can be made platform agnostic. | 21 // TODO(crogers): Most of these tests can be made platform agnostic. |
21 // http://crbug.com/223242 | 22 // http://crbug.com/223242 |
(...skipping 17 matching lines...) Expand all Loading... |
39 base::RunLoop().RunUntilIdle(); | 40 base::RunLoop().RunUntilIdle(); |
40 } | 41 } |
41 | 42 |
42 ~AUHALStreamTest() override { base::RunLoop().RunUntilIdle(); } | 43 ~AUHALStreamTest() override { base::RunLoop().RunUntilIdle(); } |
43 | 44 |
44 AudioOutputStream* Create() { | 45 AudioOutputStream* Create() { |
45 return manager_->MakeAudioOutputStream( | 46 return manager_->MakeAudioOutputStream( |
46 manager_->GetDefaultOutputStreamParameters(), ""); | 47 manager_->GetDefaultOutputStreamParameters(), ""); |
47 } | 48 } |
48 | 49 |
49 bool CanRunAudioTests() { | 50 bool OutputDevicesAvailable() { |
50 return manager_->HasAudioOutputDevices(); | 51 return manager_->HasAudioOutputDevices(); |
51 } | 52 } |
52 | 53 |
53 protected: | 54 protected: |
54 base::MessageLoop message_loop_; | 55 base::MessageLoop message_loop_; |
55 scoped_ptr<AudioManager> manager_; | 56 scoped_ptr<AudioManager> manager_; |
56 MockAudioSourceCallback source_; | 57 MockAudioSourceCallback source_; |
57 | 58 |
58 private: | 59 private: |
59 DISALLOW_COPY_AND_ASSIGN(AUHALStreamTest); | 60 DISALLOW_COPY_AND_ASSIGN(AUHALStreamTest); |
60 }; | 61 }; |
61 | 62 |
62 TEST_F(AUHALStreamTest, HardwareSampleRate) { | 63 TEST_F(AUHALStreamTest, HardwareSampleRate) { |
63 if (!CanRunAudioTests()) | 64 ABORT_AUDIO_TEST_IF_NOT(OutputDevicesAvailable()); |
64 return; | |
65 const AudioParameters preferred_params = | 65 const AudioParameters preferred_params = |
66 manager_->GetDefaultOutputStreamParameters(); | 66 manager_->GetDefaultOutputStreamParameters(); |
67 EXPECT_GE(preferred_params.sample_rate(), 16000); | 67 EXPECT_GE(preferred_params.sample_rate(), 16000); |
68 EXPECT_LE(preferred_params.sample_rate(), 192000); | 68 EXPECT_LE(preferred_params.sample_rate(), 192000); |
69 } | 69 } |
70 | 70 |
71 TEST_F(AUHALStreamTest, CreateClose) { | 71 TEST_F(AUHALStreamTest, CreateClose) { |
72 if (!CanRunAudioTests()) | 72 ABORT_AUDIO_TEST_IF_NOT(OutputDevicesAvailable()); |
73 return; | |
74 Create()->Close(); | 73 Create()->Close(); |
75 } | 74 } |
76 | 75 |
77 TEST_F(AUHALStreamTest, CreateOpenClose) { | 76 TEST_F(AUHALStreamTest, CreateOpenClose) { |
78 if (!CanRunAudioTests()) | 77 ABORT_AUDIO_TEST_IF_NOT(OutputDevicesAvailable()); |
79 return; | |
80 AudioOutputStream* stream = Create(); | 78 AudioOutputStream* stream = Create(); |
81 EXPECT_TRUE(stream->Open()); | 79 EXPECT_TRUE(stream->Open()); |
82 stream->Close(); | 80 stream->Close(); |
83 } | 81 } |
84 | 82 |
85 TEST_F(AUHALStreamTest, CreateOpenStartStopClose) { | 83 TEST_F(AUHALStreamTest, CreateOpenStartStopClose) { |
86 if (!CanRunAudioTests()) | 84 ABORT_AUDIO_TEST_IF_NOT(OutputDevicesAvailable()); |
87 return; | |
88 | 85 |
89 AudioOutputStream* stream = Create(); | 86 AudioOutputStream* stream = Create(); |
90 EXPECT_TRUE(stream->Open()); | 87 EXPECT_TRUE(stream->Open()); |
91 | 88 |
92 // Wait for the first data callback from the OS. | 89 // Wait for the first data callback from the OS. |
93 base::WaitableEvent event(false, false); | 90 base::WaitableEvent event(false, false); |
94 EXPECT_CALL(source_, OnMoreData(_, _)) | 91 EXPECT_CALL(source_, OnMoreData(_, _)) |
95 .WillOnce(DoAll(ZeroBuffer(), SignalEvent(&event), Return(0))); | 92 .WillOnce(DoAll(ZeroBuffer(), SignalEvent(&event), Return(0))); |
96 EXPECT_CALL(source_, OnError(_)).Times(0); | 93 EXPECT_CALL(source_, OnError(_)).Times(0); |
97 stream->Start(&source_); | 94 stream->Start(&source_); |
98 event.Wait(); | 95 event.Wait(); |
99 | 96 |
100 stream->Stop(); | 97 stream->Stop(); |
101 stream->Close(); | 98 stream->Close(); |
102 } | 99 } |
103 | 100 |
104 } // namespace media | 101 } // namespace media |
OLD | NEW |