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/bind.h" | 5 #include "base/bind.h" |
6 #include "base/macros.h" | 6 #include "base/macros.h" |
7 #include "base/run_loop.h" | 7 #include "base/run_loop.h" |
8 #include "base/synchronization/waitable_event.h" | 8 #include "base/synchronization/waitable_event.h" |
9 #include "base/test/test_message_loop.h" | 9 #include "base/test/test_message_loop.h" |
10 #include "base/threading/thread_task_runner_handle.h" | 10 #include "base/threading/thread_task_runner_handle.h" |
| 11 #include "media/audio/audio_device_info_accessor_for_tests.h" |
11 #include "media/audio/audio_io.h" | 12 #include "media/audio/audio_io.h" |
12 #include "media/audio/audio_manager.h" | 13 #include "media/audio/audio_manager.h" |
13 #include "media/audio/audio_unittest_util.h" | 14 #include "media/audio/audio_unittest_util.h" |
14 #include "media/audio/mock_audio_source_callback.h" | 15 #include "media/audio/mock_audio_source_callback.h" |
15 #include "testing/gmock/include/gmock/gmock.h" | 16 #include "testing/gmock/include/gmock/gmock.h" |
16 #include "testing/gtest/include/gtest/gtest.h" | 17 #include "testing/gtest/include/gtest/gtest.h" |
17 | 18 |
18 using testing::_; | 19 using testing::_; |
19 using testing::DoAll; | 20 using testing::DoAll; |
20 using testing::Return; | 21 using testing::Return; |
(...skipping 10 matching lines...) Expand all Loading... |
31 ACTION_P3(MaybeSignalEvent, counter, signal_at_count, event) { | 32 ACTION_P3(MaybeSignalEvent, counter, signal_at_count, event) { |
32 if (++(*counter) == signal_at_count) | 33 if (++(*counter) == signal_at_count) |
33 event->Signal(); | 34 event->Signal(); |
34 } | 35 } |
35 | 36 |
36 class AUHALStreamTest : public testing::Test { | 37 class AUHALStreamTest : public testing::Test { |
37 public: | 38 public: |
38 AUHALStreamTest() | 39 AUHALStreamTest() |
39 : message_loop_(base::MessageLoop::TYPE_UI), | 40 : message_loop_(base::MessageLoop::TYPE_UI), |
40 manager_(AudioManager::CreateForTesting( | 41 manager_(AudioManager::CreateForTesting( |
41 base::ThreadTaskRunnerHandle::Get())) { | 42 base::ThreadTaskRunnerHandle::Get())), |
| 43 manager_device_info_(manager_.get()) { |
42 // Wait for the AudioManager to finish any initialization on the audio loop. | 44 // Wait for the AudioManager to finish any initialization on the audio loop. |
43 base::RunLoop().RunUntilIdle(); | 45 base::RunLoop().RunUntilIdle(); |
44 } | 46 } |
45 | 47 |
46 ~AUHALStreamTest() override {} | 48 ~AUHALStreamTest() override {} |
47 | 49 |
48 AudioOutputStream* Create() { | 50 AudioOutputStream* Create() { |
49 return manager_->MakeAudioOutputStream( | 51 return manager_->MakeAudioOutputStream( |
50 manager_->GetDefaultOutputStreamParameters(), "", | 52 manager_device_info_.GetDefaultOutputStreamParameters(), "", |
51 base::Bind(&AUHALStreamTest::OnLogMessage, base::Unretained(this))); | 53 base::Bind(&AUHALStreamTest::OnLogMessage, base::Unretained(this))); |
52 } | 54 } |
53 | 55 |
54 bool OutputDevicesAvailable() { | 56 bool OutputDevicesAvailable() { |
55 return manager_->HasAudioOutputDevices(); | 57 return manager_device_info_.HasAudioOutputDevices(); |
56 } | 58 } |
57 | 59 |
58 void OnLogMessage(const std::string& message) { log_message_ = message; } | 60 void OnLogMessage(const std::string& message) { log_message_ = message; } |
59 | 61 |
60 protected: | 62 protected: |
61 base::TestMessageLoop message_loop_; | 63 base::TestMessageLoop message_loop_; |
62 ScopedAudioManagerPtr manager_; | 64 ScopedAudioManagerPtr manager_; |
| 65 AudioDeviceInfoAccessorForTests manager_device_info_; |
63 MockAudioSourceCallback source_; | 66 MockAudioSourceCallback source_; |
64 std::string log_message_; | 67 std::string log_message_; |
65 | 68 |
66 private: | 69 private: |
67 DISALLOW_COPY_AND_ASSIGN(AUHALStreamTest); | 70 DISALLOW_COPY_AND_ASSIGN(AUHALStreamTest); |
68 }; | 71 }; |
69 | 72 |
70 TEST_F(AUHALStreamTest, HardwareSampleRate) { | 73 TEST_F(AUHALStreamTest, HardwareSampleRate) { |
71 ABORT_AUDIO_TEST_IF_NOT(OutputDevicesAvailable()); | 74 ABORT_AUDIO_TEST_IF_NOT(OutputDevicesAvailable()); |
72 const AudioParameters preferred_params = | 75 const AudioParameters preferred_params = |
73 manager_->GetDefaultOutputStreamParameters(); | 76 manager_device_info_.GetDefaultOutputStreamParameters(); |
74 EXPECT_GE(preferred_params.sample_rate(), 16000); | 77 EXPECT_GE(preferred_params.sample_rate(), 16000); |
75 EXPECT_LE(preferred_params.sample_rate(), 192000); | 78 EXPECT_LE(preferred_params.sample_rate(), 192000); |
76 } | 79 } |
77 | 80 |
78 TEST_F(AUHALStreamTest, CreateClose) { | 81 TEST_F(AUHALStreamTest, CreateClose) { |
79 ABORT_AUDIO_TEST_IF_NOT(OutputDevicesAvailable()); | 82 ABORT_AUDIO_TEST_IF_NOT(OutputDevicesAvailable()); |
80 Create()->Close(); | 83 Create()->Close(); |
81 } | 84 } |
82 | 85 |
83 TEST_F(AUHALStreamTest, CreateOpenClose) { | 86 TEST_F(AUHALStreamTest, CreateOpenClose) { |
(...skipping 24 matching lines...) Expand all Loading... |
108 stream->Start(&source_); | 111 stream->Start(&source_); |
109 event.Wait(); | 112 event.Wait(); |
110 | 113 |
111 stream->Stop(); | 114 stream->Stop(); |
112 stream->Close(); | 115 stream->Close(); |
113 | 116 |
114 EXPECT_FALSE(log_message_.empty()); | 117 EXPECT_FALSE(log_message_.empty()); |
115 } | 118 } |
116 | 119 |
117 } // namespace media | 120 } // namespace media |
OLD | NEW |