OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/bind.h" | 6 #include "base/bind.h" |
7 #include "base/environment.h" | 7 #include "base/environment.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "base/memory/ref_counted.h" | 9 #include "base/memory/ref_counted.h" |
10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
46 private: | 46 private: |
47 DISALLOW_COPY_AND_ASSIGN(MockAudioOutputControllerEventHandler); | 47 DISALLOW_COPY_AND_ASSIGN(MockAudioOutputControllerEventHandler); |
48 }; | 48 }; |
49 | 49 |
50 class MockAudioOutputControllerSyncReader | 50 class MockAudioOutputControllerSyncReader |
51 : public AudioOutputController::SyncReader { | 51 : public AudioOutputController::SyncReader { |
52 public: | 52 public: |
53 MockAudioOutputControllerSyncReader() {} | 53 MockAudioOutputControllerSyncReader() {} |
54 | 54 |
55 MOCK_METHOD1(UpdatePendingBytes, void(uint32 bytes)); | 55 MOCK_METHOD1(UpdatePendingBytes, void(uint32 bytes)); |
56 MOCK_METHOD3(Read, int(bool block, const AudioBus* source, AudioBus* dest)); | 56 MOCK_METHOD2(Read, void(const AudioBus* source, AudioBus* dest)); |
57 MOCK_METHOD0(Close, void()); | 57 MOCK_METHOD0(Close, void()); |
58 | 58 |
59 private: | 59 private: |
60 DISALLOW_COPY_AND_ASSIGN(MockAudioOutputControllerSyncReader); | 60 DISALLOW_COPY_AND_ASSIGN(MockAudioOutputControllerSyncReader); |
61 }; | 61 }; |
62 | 62 |
63 class MockAudioOutputStream : public AudioOutputStream { | 63 class MockAudioOutputStream : public AudioOutputStream { |
64 public: | 64 public: |
65 MOCK_METHOD0(Open, bool()); | 65 MOCK_METHOD0(Open, bool()); |
66 MOCK_METHOD1(Start, void(AudioSourceCallback* callback)); | 66 MOCK_METHOD1(Start, void(AudioSourceCallback* callback)); |
67 MOCK_METHOD0(Stop, void()); | 67 MOCK_METHOD0(Stop, void()); |
68 MOCK_METHOD1(SetVolume, void(double volume)); | 68 MOCK_METHOD1(SetVolume, void(double volume)); |
69 MOCK_METHOD1(GetVolume, void(double* volume)); | 69 MOCK_METHOD1(GetVolume, void(double* volume)); |
70 MOCK_METHOD0(Close, void()); | 70 MOCK_METHOD0(Close, void()); |
71 | 71 |
72 // Set/get the callback passed to Start(). | 72 // Set/get the callback passed to Start(). |
73 AudioSourceCallback* callback() const { return callback_; } | 73 AudioSourceCallback* callback() const { return callback_; } |
74 void SetCallback(AudioSourceCallback* asc) { callback_ = asc; } | 74 void SetCallback(AudioSourceCallback* asc) { callback_ = asc; } |
75 | 75 |
76 private: | 76 private: |
77 AudioSourceCallback* callback_; | 77 AudioSourceCallback* callback_; |
78 }; | 78 }; |
79 | 79 |
80 ACTION_P(SignalEvent, event) { | 80 ACTION_P(SignalEvent, event) { |
81 event->Signal(); | 81 event->Signal(); |
82 } | 82 } |
83 | 83 |
84 static const float kBufferNonZeroData = 1.0f; | 84 static const float kBufferNonZeroData = 1.0f; |
85 ACTION(PopulateBuffer) { | 85 ACTION(PopulateBuffer) { |
86 arg2->Zero(); | 86 arg1->Zero(); |
87 // Note: To confirm the buffer will be populated in these tests, it's | 87 // Note: To confirm the buffer will be populated in these tests, it's |
88 // sufficient that only the first float in channel 0 is set to the value. | 88 // sufficient that only the first float in channel 0 is set to the value. |
89 arg2->channel(0)[0] = kBufferNonZeroData; | 89 arg1->channel(0)[0] = kBufferNonZeroData; |
90 } | 90 } |
91 | 91 |
92 class AudioOutputControllerTest : public testing::Test { | 92 class AudioOutputControllerTest : public testing::Test { |
93 public: | 93 public: |
94 AudioOutputControllerTest() | 94 AudioOutputControllerTest() |
95 : audio_manager_(AudioManager::Create()), | 95 : audio_manager_(AudioManager::Create()), |
96 create_event_(false, false), | 96 create_event_(false, false), |
97 play_event_(false, false), | 97 play_event_(false, false), |
98 read_event_(false, false), | 98 read_event_(false, false), |
99 pause_event_(false, false) { | 99 pause_event_(false, false) { |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
134 .WillOnce(SignalEvent(&play_event_)); | 134 .WillOnce(SignalEvent(&play_event_)); |
135 #if defined(AUDIO_POWER_MONITORING) | 135 #if defined(AUDIO_POWER_MONITORING) |
136 EXPECT_CALL(mock_event_handler_, OnPowerMeasured(_, false)) | 136 EXPECT_CALL(mock_event_handler_, OnPowerMeasured(_, false)) |
137 .Times(AtLeast(1)); | 137 .Times(AtLeast(1)); |
138 #endif | 138 #endif |
139 | 139 |
140 // During playback, the mock pretends to provide audio data rendered and | 140 // During playback, the mock pretends to provide audio data rendered and |
141 // sent from the render process. | 141 // sent from the render process. |
142 EXPECT_CALL(mock_sync_reader_, UpdatePendingBytes(_)) | 142 EXPECT_CALL(mock_sync_reader_, UpdatePendingBytes(_)) |
143 .Times(AtLeast(1)); | 143 .Times(AtLeast(1)); |
144 EXPECT_CALL(mock_sync_reader_, Read(_, _, _)) | 144 EXPECT_CALL(mock_sync_reader_, Read(_, _)) |
145 .WillRepeatedly(DoAll(PopulateBuffer(), | 145 .WillRepeatedly(DoAll(PopulateBuffer(), |
146 SignalEvent(&read_event_), | 146 SignalEvent(&read_event_))); |
147 Return(params_.frames_per_buffer()))); | |
148 controller_->Play(); | 147 controller_->Play(); |
149 } | 148 } |
150 | 149 |
151 void Pause() { | 150 void Pause() { |
152 // Expect the event handler to receive one OnPaused() call. | 151 // Expect the event handler to receive one OnPaused() call. |
153 EXPECT_CALL(mock_event_handler_, OnPaused()) | 152 EXPECT_CALL(mock_event_handler_, OnPaused()) |
154 .WillOnce(SignalEvent(&pause_event_)); | 153 .WillOnce(SignalEvent(&pause_event_)); |
155 | 154 |
156 controller_->Pause(); | 155 controller_->Pause(); |
157 } | 156 } |
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
370 | 369 |
371 TEST_F(AudioOutputControllerTest, DivertRevertClose) { | 370 TEST_F(AudioOutputControllerTest, DivertRevertClose) { |
372 Create(kSamplesPerPacket); | 371 Create(kSamplesPerPacket); |
373 WaitForCreate(); | 372 WaitForCreate(); |
374 DivertNeverPlaying(); | 373 DivertNeverPlaying(); |
375 RevertWasNotPlaying(); | 374 RevertWasNotPlaying(); |
376 Close(); | 375 Close(); |
377 } | 376 } |
378 | 377 |
379 } // namespace media | 378 } // namespace media |
OLD | NEW |