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 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
44 | 44 |
45 private: | 45 private: |
46 DISALLOW_COPY_AND_ASSIGN(MockAudioOutputControllerEventHandler); | 46 DISALLOW_COPY_AND_ASSIGN(MockAudioOutputControllerEventHandler); |
47 }; | 47 }; |
48 | 48 |
49 class MockAudioOutputControllerSyncReader | 49 class MockAudioOutputControllerSyncReader |
50 : public AudioOutputController::SyncReader { | 50 : public AudioOutputController::SyncReader { |
51 public: | 51 public: |
52 MockAudioOutputControllerSyncReader() {} | 52 MockAudioOutputControllerSyncReader() {} |
53 | 53 |
54 MOCK_METHOD1(UpdatePendingBytes, void(uint32 bytes)); | 54 MOCK_METHOD2(UpdatePendingBytes, |
| 55 void(uint32_t bytes, uint32_t frames_skipped)); |
55 MOCK_METHOD1(Read, void(AudioBus* dest)); | 56 MOCK_METHOD1(Read, void(AudioBus* dest)); |
56 MOCK_METHOD0(Close, void()); | 57 MOCK_METHOD0(Close, void()); |
57 | 58 |
58 private: | 59 private: |
59 DISALLOW_COPY_AND_ASSIGN(MockAudioOutputControllerSyncReader); | 60 DISALLOW_COPY_AND_ASSIGN(MockAudioOutputControllerSyncReader); |
60 }; | 61 }; |
61 | 62 |
62 class MockAudioOutputStream : public AudioOutputStream { | 63 class MockAudioOutputStream : public AudioOutputStream { |
63 public: | 64 public: |
64 MOCK_METHOD0(Open, bool()); | 65 MOCK_METHOD0(Open, bool()); |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
125 EXPECT_EQ(params_.IsValid(), controller_.get() != NULL); | 126 EXPECT_EQ(params_.IsValid(), controller_.get() != NULL); |
126 } | 127 } |
127 | 128 |
128 void Play() { | 129 void Play() { |
129 // Expect the event handler to receive one OnPlaying() call. | 130 // Expect the event handler to receive one OnPlaying() call. |
130 EXPECT_CALL(mock_event_handler_, OnPlaying()) | 131 EXPECT_CALL(mock_event_handler_, OnPlaying()) |
131 .WillOnce(SignalEvent(&play_event_)); | 132 .WillOnce(SignalEvent(&play_event_)); |
132 | 133 |
133 // During playback, the mock pretends to provide audio data rendered and | 134 // During playback, the mock pretends to provide audio data rendered and |
134 // sent from the render process. | 135 // sent from the render process. |
135 EXPECT_CALL(mock_sync_reader_, UpdatePendingBytes(_)) | 136 EXPECT_CALL(mock_sync_reader_, UpdatePendingBytes(_, _)).Times(AtLeast(1)); |
136 .Times(AtLeast(1)); | |
137 EXPECT_CALL(mock_sync_reader_, Read(_)) | 137 EXPECT_CALL(mock_sync_reader_, Read(_)) |
138 .WillRepeatedly(DoAll(PopulateBuffer(), | 138 .WillRepeatedly(DoAll(PopulateBuffer(), |
139 SignalEvent(&read_event_))); | 139 SignalEvent(&read_event_))); |
140 controller_->Play(); | 140 controller_->Play(); |
141 } | 141 } |
142 | 142 |
143 void Pause() { | 143 void Pause() { |
144 // Expect the event handler to receive one OnPaused() call. | 144 // Expect the event handler to receive one OnPaused() call. |
145 EXPECT_CALL(mock_event_handler_, OnPaused()) | 145 EXPECT_CALL(mock_event_handler_, OnPaused()) |
146 .WillOnce(SignalEvent(&pause_event_)); | 146 .WillOnce(SignalEvent(&pause_event_)); |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
183 .Times(num_times_to_be_started); | 183 .Times(num_times_to_be_started); |
184 } | 184 } |
185 | 185 |
186 controller_->StartDiverting(&mock_stream_); | 186 controller_->StartDiverting(&mock_stream_); |
187 } | 187 } |
188 | 188 |
189 void ReadDivertedAudioData() { | 189 void ReadDivertedAudioData() { |
190 scoped_ptr<AudioBus> dest = AudioBus::Create(params_); | 190 scoped_ptr<AudioBus> dest = AudioBus::Create(params_); |
191 ASSERT_TRUE(mock_stream_.callback()); | 191 ASSERT_TRUE(mock_stream_.callback()); |
192 const int frames_read = | 192 const int frames_read = |
193 mock_stream_.callback()->OnMoreData(dest.get(), 0); | 193 mock_stream_.callback()->OnMoreData(dest.get(), 0, 0); |
194 EXPECT_LT(0, frames_read); | 194 EXPECT_LT(0, frames_read); |
195 EXPECT_EQ(kBufferNonZeroData, dest->channel(0)[0]); | 195 EXPECT_EQ(kBufferNonZeroData, dest->channel(0)[0]); |
196 } | 196 } |
197 | 197 |
198 void Revert(bool was_playing) { | 198 void Revert(bool was_playing) { |
199 if (was_playing) { | 199 if (was_playing) { |
200 // Expect the handler to receive one OnPlaying() call as a result of the | 200 // Expect the handler to receive one OnPlaying() call as a result of the |
201 // stream switching back. | 201 // stream switching back. |
202 EXPECT_CALL(mock_event_handler_, OnPlaying()) | 202 EXPECT_CALL(mock_event_handler_, OnPlaying()) |
203 .WillOnce(SignalEvent(&play_event_)); | 203 .WillOnce(SignalEvent(&play_event_)); |
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
403 | 403 |
404 TEST_F(AudioOutputControllerTest, DivertRevertClose) { | 404 TEST_F(AudioOutputControllerTest, DivertRevertClose) { |
405 Create(kSamplesPerPacket); | 405 Create(kSamplesPerPacket); |
406 WaitForCreate(); | 406 WaitForCreate(); |
407 DivertNeverPlaying(); | 407 DivertNeverPlaying(); |
408 RevertWasNotPlaying(); | 408 RevertWasNotPlaying(); |
409 Close(); | 409 Close(); |
410 } | 410 } |
411 | 411 |
412 } // namespace media | 412 } // namespace media |
OLD | NEW |