Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(30)

Side by Side Diff: media/audio/audio_output_controller_unittest.cc

Issue 11413078: Tab Audio Capture: Browser-side connect/disconnect functionality. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Simplify! Created 8 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/bind.h" 6 #include "base/bind.h"
6 #include "base/environment.h" 7 #include "base/environment.h"
7 #include "base/basictypes.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "base/memory/ref_counted.h"
10 #include "base/memory/scoped_ptr.h"
9 #include "base/message_loop.h" 11 #include "base/message_loop.h"
10 #include "base/synchronization/waitable_event.h" 12 #include "base/synchronization/waitable_event.h"
11 #include "media/audio/audio_output_controller.h" 13 #include "media/audio/audio_output_controller.h"
14 #include "media/audio/audio_parameters.h"
15 #include "media/base/audio_bus.h"
12 #include "testing/gmock/include/gmock/gmock.h" 16 #include "testing/gmock/include/gmock/gmock.h"
13 #include "testing/gtest/include/gtest/gtest.h" 17 #include "testing/gtest/include/gtest/gtest.h"
14 18
15 // TODO(vrk): These tests need to be rewritten! (crbug.com/112500)
16
17 using ::testing::_; 19 using ::testing::_;
18 using ::testing::AtLeast; 20 using ::testing::AtLeast;
19 using ::testing::DoAll; 21 using ::testing::DoAll;
20 using ::testing::Exactly; 22 using ::testing::Invoke;
21 using ::testing::InvokeWithoutArgs;
22 using ::testing::NotNull; 23 using ::testing::NotNull;
23 using ::testing::Return; 24 using ::testing::Return;
24 25
25 namespace media { 26 namespace media {
26 27
27 static const int kSampleRate = AudioParameters::kAudioCDSampleRate; 28 static const int kSampleRate = AudioParameters::kAudioCDSampleRate;
28 static const int kBitsPerSample = 16; 29 static const int kBitsPerSample = 16;
29 static const ChannelLayout kChannelLayout = CHANNEL_LAYOUT_STEREO; 30 static const ChannelLayout kChannelLayout = CHANNEL_LAYOUT_STEREO;
30 static const int kSamplesPerPacket = kSampleRate / 10; 31 static const int kSamplesPerPacket = kSampleRate / 100;
31 static const int kHardwareBufferSize = kSamplesPerPacket * 32 static const int kHardwareBufferSize = kSamplesPerPacket *
32 ChannelLayoutToChannelCount(kChannelLayout) * kBitsPerSample / 8; 33 ChannelLayoutToChannelCount(kChannelLayout) * kBitsPerSample / 8;
34 static const double kTestVolume = 0.25;
33 35
34 class MockAudioOutputControllerEventHandler 36 class MockAudioOutputControllerEventHandler
35 : public AudioOutputController::EventHandler { 37 : public AudioOutputController::EventHandler {
36 public: 38 public:
37 MockAudioOutputControllerEventHandler() {} 39 MockAudioOutputControllerEventHandler() {}
38 40
39 MOCK_METHOD1(OnCreated, void(AudioOutputController* controller)); 41 MOCK_METHOD1(OnCreated, void(AudioOutputController* controller));
40 MOCK_METHOD1(OnPlaying, void(AudioOutputController* controller)); 42 MOCK_METHOD1(OnPlaying, void(AudioOutputController* controller));
41 MOCK_METHOD1(OnPaused, void(AudioOutputController* controller)); 43 MOCK_METHOD1(OnPaused, void(AudioOutputController* controller));
42 MOCK_METHOD2(OnError, void(AudioOutputController* controller, 44 MOCK_METHOD2(OnError, void(AudioOutputController* controller,
(...skipping 10 matching lines...) Expand all
53 55
54 MOCK_METHOD1(UpdatePendingBytes, void(uint32 bytes)); 56 MOCK_METHOD1(UpdatePendingBytes, void(uint32 bytes));
55 MOCK_METHOD2(Read, int(AudioBus* source, AudioBus* dest)); 57 MOCK_METHOD2(Read, int(AudioBus* source, AudioBus* dest));
56 MOCK_METHOD0(Close, void()); 58 MOCK_METHOD0(Close, void());
57 MOCK_METHOD0(DataReady, bool()); 59 MOCK_METHOD0(DataReady, bool());
58 60
59 private: 61 private:
60 DISALLOW_COPY_AND_ASSIGN(MockAudioOutputControllerSyncReader); 62 DISALLOW_COPY_AND_ASSIGN(MockAudioOutputControllerSyncReader);
61 }; 63 };
62 64
65 class MockAudioOutputStream : public AudioOutputStream {
66 public:
67 MOCK_METHOD0(Open, bool());
68 MOCK_METHOD1(Start, void(AudioSourceCallback* callback));
69 MOCK_METHOD0(Stop, void());
70 MOCK_METHOD1(SetVolume, void(double volume));
71 MOCK_METHOD1(GetVolume, void(double* volume));
72 MOCK_METHOD0(Close, void());
73
74 // Set/get the callback passed to Start().
75 AudioSourceCallback* callback() const { return callback_; }
76 void SetCallback(AudioSourceCallback* asc) { callback_ = asc; }
77
78 private:
79 AudioSourceCallback* callback_;
80 };
81
63 ACTION_P(SignalEvent, event) { 82 ACTION_P(SignalEvent, event) {
64 event->Signal(); 83 event->Signal();
65 } 84 }
66 85
67 // Custom action to clear a memory buffer. 86 static const float kBufferNonZeroData = 1.0f;
68 ACTION(ClearBuffer) { 87 ACTION(PopulateBuffer) {
69 arg1->Zero(); 88 arg1->Zero();
70 } 89 // Note: To confirm the buffer will be populated in these tests, it's
71 90 // sufficient that only the first float in channel 0 is set to the value.
72 // Closes AudioOutputController synchronously. 91 arg1->channel(0)[0] = kBufferNonZeroData;
73 static void CloseAudioController(AudioOutputController* controller) {
74 controller->Close(MessageLoop::QuitClosure());
75 MessageLoop::current()->Run();
76 } 92 }
77 93
78 class AudioOutputControllerTest : public testing::Test { 94 class AudioOutputControllerTest : public testing::Test {
79 public: 95 public:
80 AudioOutputControllerTest() {} 96 AudioOutputControllerTest()
81 virtual ~AudioOutputControllerTest() {} 97 : audio_manager_(AudioManager::Create()),
98 create_event_(false, false),
99 play_event_(false, false),
100 read_event_(false, false),
101 pause_event_(false, false) {
102 }
103
104 virtual ~AudioOutputControllerTest() {
105 }
82 106
83 protected: 107 protected:
108 // Returns true if a controller was successfully created.
109 bool Create(int samples_per_packet) {
110 EXPECT_FALSE(create_event_.IsSignaled());
111 EXPECT_FALSE(play_event_.IsSignaled());
112 EXPECT_FALSE(read_event_.IsSignaled());
113 EXPECT_FALSE(pause_event_.IsSignaled());
114
115 params_ = AudioParameters(
116 AudioParameters::AUDIO_FAKE, kChannelLayout,
117 kSampleRate, kBitsPerSample, samples_per_packet);
118 controller_ = AudioOutputController::Create(
119 audio_manager_.get(), &mock_event_handler_, params_,
120 &mock_sync_reader_);
121
122 if (controller_) {
123 controller_->SetVolume(kTestVolume);
124 EXPECT_CALL(mock_event_handler_, OnCreated(NotNull()))
125 .WillOnce(SignalEvent(&create_event_));
126 }
127
128 return controller_ != NULL;
129 }
130
131 void Play() {
132 // Expect the event handler to receive one OnPlaying() call.
133 EXPECT_CALL(mock_event_handler_, OnPlaying(NotNull()))
134 .WillOnce(SignalEvent(&play_event_));
135
136 // During playback, the mock pretends to provide audio data rendered and
137 // sent from the render process.
138 EXPECT_CALL(mock_sync_reader_, UpdatePendingBytes(_))
139 .Times(AtLeast(2));
140 EXPECT_CALL(mock_sync_reader_, Read(_, _))
141 .WillRepeatedly(DoAll(PopulateBuffer(),
142 SignalEvent(&read_event_),
143 Return(params_.frames_per_buffer())));
144 EXPECT_CALL(mock_sync_reader_, DataReady())
145 .WillRepeatedly(Return(true));
146
147 controller_->Play();
148 }
149
150 void Pause() {
151 // Expect the event handler to receive one OnPaused() call.
152 EXPECT_CALL(mock_event_handler_, OnPaused(NotNull()))
153 .WillOnce(SignalEvent(&pause_event_));
154
155 controller_->Pause();
156 }
157
158 void ChangeDevice() {
159 // Expect the event handler to receive one OnPaying() call and no OnPaused()
160 // call.
161 EXPECT_CALL(mock_event_handler_, OnPlaying(NotNull()))
162 .WillOnce(SignalEvent(&play_event_));
163 EXPECT_CALL(mock_event_handler_, OnPaused(NotNull()))
164 .Times(0);
165
166 // Simulate a device change event to AudioOutputController from the
167 // AudioManager.
168 audio_manager_->GetMessageLoop()->PostTask(
169 FROM_HERE,
170 base::Bind(&AudioOutputController::OnDeviceChange, controller_));
171 }
172
173 void Divert(bool was_playing, bool will_be_playing) {
174 if (was_playing) {
175 // Expect the handler to receive one OnPlaying() call as a result of the
176 // stream switching.
177 EXPECT_CALL(mock_event_handler_, OnPlaying(NotNull()))
178 .WillOnce(SignalEvent(&play_event_));
179 }
180
181 EXPECT_CALL(mock_stream_, Open())
182 .WillOnce(Return(true));
183 EXPECT_CALL(mock_stream_, SetVolume(kTestVolume));
184 if (will_be_playing) {
185 EXPECT_CALL(mock_stream_, Start(NotNull()))
186 .Times(AtLeast(1))
187 .WillRepeatedly(
188 Invoke(&mock_stream_, &MockAudioOutputStream::SetCallback));
189 }
190 // Always expect a Stop() call--even without a Start() call--since
191 // AudioOutputController likes to play it safe and Stop() before any
192 // Close().
193 EXPECT_CALL(mock_stream_, Stop())
194 .Times(AtLeast(1));
195
196 controller_->DivertToStream(&mock_stream_);
197 }
198
199 void ReadDivertedAudioData() {
200 scoped_ptr<AudioBus> dest = AudioBus::Create(params_);
201 ASSERT_TRUE(!!mock_stream_.callback());
202 const int frames_read =
203 mock_stream_.callback()->OnMoreData(dest.get(), AudioBuffersState());
204 EXPECT_LT(0, frames_read);
205 EXPECT_EQ(kBufferNonZeroData, dest->channel(0)[0]);
206 }
207
208 void Revert(bool was_playing) {
209 if (was_playing) {
210 // Expect the handler to receive one OnPlaying() call as a result of the
211 // stream switching back.
212 EXPECT_CALL(mock_event_handler_, OnPlaying(NotNull()))
213 .WillOnce(SignalEvent(&play_event_));
214 }
215
216 EXPECT_CALL(mock_stream_, Close());
217
218 controller_->RevertDiversion();
219 }
220
221 void Close() {
222 EXPECT_CALL(mock_sync_reader_, Close());
223
224 controller_->Close(MessageLoop::QuitClosure());
225 MessageLoop::current()->Run();
226 }
227
228 // These help make test sequences more readable.
229 void DivertNeverPlaying() { Divert(false, false); }
230 void DivertWillEventuallyBePlaying() { Divert(false, true); }
231 void DivertWhilePlaying() { Divert(true, true); }
232 void RevertWasNotPlaying() { Revert(false); }
233 void RevertWhilePlaying() { Revert(true); }
234
235 // These synchronize the main thread with key events taking place on other
236 // threads.
237 void WaitForCreate() { create_event_.Wait(); }
238 void WaitForPlay() { play_event_.Wait(); }
239 void WaitForReads() {
240 // Note: Arbitrarily chosen, but more iterations causes tests to take
241 // significantly more time.
242 static const int kNumIterations = 3;
243 for (int i = 0; i < kNumIterations; ++i) {
244 read_event_.Wait();
245 }
246 }
247 void WaitForPause() { pause_event_.Wait(); }
248
249 private:
84 MessageLoopForIO message_loop_; 250 MessageLoopForIO message_loop_;
85 251 scoped_ptr<AudioManager> audio_manager_;
86 private: 252 MockAudioOutputControllerEventHandler mock_event_handler_;
253 MockAudioOutputControllerSyncReader mock_sync_reader_;
254 MockAudioOutputStream mock_stream_;
255 base::WaitableEvent create_event_;
256 base::WaitableEvent play_event_;
257 base::WaitableEvent read_event_;
258 base::WaitableEvent pause_event_;
259 AudioParameters params_;
260 scoped_refptr<AudioOutputController> controller_;
261
87 DISALLOW_COPY_AND_ASSIGN(AudioOutputControllerTest); 262 DISALLOW_COPY_AND_ASSIGN(AudioOutputControllerTest);
88 }; 263 };
89 264
90 TEST_F(AudioOutputControllerTest, CreateAndClose) { 265 TEST_F(AudioOutputControllerTest, CreateAndClose) {
91 scoped_ptr<AudioManager> audio_manager(AudioManager::Create()); 266 ASSERT_TRUE(Create(kSamplesPerPacket));
92 if (!audio_manager->HasAudioOutputDevices()) 267 Close();
93 return; 268 }
94 269
95 MockAudioOutputControllerEventHandler event_handler; 270 TEST_F(AudioOutputControllerTest, HardwareBufferTooLarge) {
96 271 EXPECT_FALSE(Create(kSamplesPerPacket * 1000));
97 EXPECT_CALL(event_handler, OnCreated(NotNull())) 272 }
98 .Times(1); 273
99 274 TEST_F(AudioOutputControllerTest, PlayAndClose) {
100 MockAudioOutputControllerSyncReader sync_reader; 275 ASSERT_TRUE(Create(kSamplesPerPacket));
101 EXPECT_CALL(sync_reader, Close()); 276 WaitForCreate();
102 277 Play();
103 AudioParameters params(AudioParameters::AUDIO_PCM_LINEAR, kChannelLayout, 278 WaitForPlay();
104 kSampleRate, kBitsPerSample, kSamplesPerPacket); 279 WaitForReads();
105 scoped_refptr<AudioOutputController> controller = 280 Close();
106 AudioOutputController::Create(
107 audio_manager.get(), &event_handler, params, &sync_reader);
108 ASSERT_TRUE(controller.get());
109
110 // Close the controller immediately.
111 CloseAudioController(controller);
112 } 281 }
113 282
114 TEST_F(AudioOutputControllerTest, PlayPauseClose) { 283 TEST_F(AudioOutputControllerTest, PlayPauseClose) {
115 scoped_ptr<AudioManager> audio_manager(AudioManager::Create()); 284 ASSERT_TRUE(Create(kSamplesPerPacket));
116 if (!audio_manager->HasAudioOutputDevices()) 285 WaitForCreate();
117 return; 286 Play();
118 287 WaitForPlay();
119 MockAudioOutputControllerEventHandler event_handler; 288 WaitForReads();
120 base::WaitableEvent event(false, false); 289 Pause();
121 base::WaitableEvent pause_event(false, false); 290 WaitForPause();
122 291 Close();
123 // If OnCreated is called then signal the event.
124 EXPECT_CALL(event_handler, OnCreated(NotNull()))
125 .WillOnce(InvokeWithoutArgs(&event, &base::WaitableEvent::Signal));
126
127 // OnPlaying() will be called only once.
128 EXPECT_CALL(event_handler, OnPlaying(NotNull()));
129
130 MockAudioOutputControllerSyncReader sync_reader;
131 EXPECT_CALL(sync_reader, UpdatePendingBytes(_))
132 .Times(AtLeast(2));
133 EXPECT_CALL(sync_reader, Read(_, _))
134 .WillRepeatedly(DoAll(ClearBuffer(), SignalEvent(&event),
135 Return(4)));
136 EXPECT_CALL(sync_reader, DataReady())
137 .WillRepeatedly(Return(true));
138 EXPECT_CALL(event_handler, OnPaused(NotNull()))
139 .WillOnce(InvokeWithoutArgs(&pause_event, &base::WaitableEvent::Signal));
140 EXPECT_CALL(sync_reader, Close());
141
142 AudioParameters params(AudioParameters::AUDIO_PCM_LINEAR, kChannelLayout,
143 kSampleRate, kBitsPerSample, kSamplesPerPacket);
144 scoped_refptr<AudioOutputController> controller =
145 AudioOutputController::Create(
146 audio_manager.get(), &event_handler, params, &sync_reader);
147 ASSERT_TRUE(controller.get());
148
149 // Wait for OnCreated() to be called.
150 event.Wait();
151
152 ASSERT_FALSE(pause_event.IsSignaled());
153 controller->Play();
154 controller->Pause();
155 pause_event.Wait();
156
157 // Now stop the controller.
158 CloseAudioController(controller);
159 }
160
161 TEST_F(AudioOutputControllerTest, HardwareBufferTooLarge) {
162 scoped_ptr<AudioManager> audio_manager(AudioManager::Create());
163 if (!audio_manager->HasAudioOutputDevices())
164 return;
165
166 // Create an audio device with a very large hardware buffer size.
167 MockAudioOutputControllerEventHandler event_handler;
168
169 MockAudioOutputControllerSyncReader sync_reader;
170 AudioParameters params(AudioParameters::AUDIO_PCM_LINEAR, kChannelLayout,
171 kSampleRate, kBitsPerSample,
172 kSamplesPerPacket * 1000);
173 scoped_refptr<AudioOutputController> controller =
174 AudioOutputController::Create(
175 audio_manager.get(), &event_handler, params, &sync_reader);
176
177 // Use assert because we don't stop the device and assume we can't
178 // create one.
179 ASSERT_FALSE(controller);
180 } 292 }
181 293
182 TEST_F(AudioOutputControllerTest, PlayPausePlayClose) { 294 TEST_F(AudioOutputControllerTest, PlayPausePlayClose) {
183 scoped_ptr<AudioManager> audio_manager(AudioManager::Create()); 295 ASSERT_TRUE(Create(kSamplesPerPacket));
184 if (!audio_manager->HasAudioOutputDevices()) 296 WaitForCreate();
185 return; 297 Play();
186 298 WaitForPlay();
187 MockAudioOutputControllerEventHandler event_handler; 299 WaitForReads();
188 base::WaitableEvent event(false, false); 300 Pause();
189 EXPECT_CALL(event_handler, OnCreated(NotNull())) 301 WaitForPause();
190 .WillOnce(InvokeWithoutArgs(&event, &base::WaitableEvent::Signal)); 302 Play();
191 303 WaitForPlay();
192 // OnPlaying() will be called only once. 304 Close();
193 base::WaitableEvent play_event(false, false); 305 }
194 EXPECT_CALL(event_handler, OnPlaying(NotNull())) 306
195 .WillOnce(InvokeWithoutArgs(&play_event, &base::WaitableEvent::Signal)); 307 TEST_F(AudioOutputControllerTest, PlayDeviceChangeClose) {
196 308 ASSERT_TRUE(Create(kSamplesPerPacket));
197 // OnPaused() should never be called since the pause during kStarting is 309 WaitForCreate();
198 // dropped when the second play comes in. 310 Play();
199 EXPECT_CALL(event_handler, OnPaused(NotNull())) 311 WaitForPlay();
200 .Times(0); 312 WaitForReads();
201 313 ChangeDevice();
202 MockAudioOutputControllerSyncReader sync_reader; 314 WaitForPlay();
203 EXPECT_CALL(sync_reader, UpdatePendingBytes(_)) 315 WaitForReads();
204 .Times(AtLeast(1)); 316 Close();
205 EXPECT_CALL(sync_reader, Read(_, _)) 317 }
206 .WillRepeatedly(DoAll(ClearBuffer(), SignalEvent(&event), Return(4))); 318
207 EXPECT_CALL(sync_reader, DataReady()) 319 TEST_F(AudioOutputControllerTest, PlayDivertRevertClose) {
208 .WillRepeatedly(Return(true)); 320 ASSERT_TRUE(Create(kSamplesPerPacket));
209 EXPECT_CALL(sync_reader, Close()); 321 WaitForCreate();
210 322 Play();
211 AudioParameters params(AudioParameters::AUDIO_PCM_LINEAR, kChannelLayout, 323 WaitForPlay();
212 kSampleRate, kBitsPerSample, kSamplesPerPacket); 324 WaitForReads();
213 scoped_refptr<AudioOutputController> controller = 325 DivertWhilePlaying();
214 AudioOutputController::Create( 326 WaitForPlay();
215 audio_manager.get(), &event_handler, params, &sync_reader); 327 ReadDivertedAudioData();
216 ASSERT_TRUE(controller.get()); 328 RevertWhilePlaying();
217 329 WaitForPlay();
218 // Wait for OnCreated() to be called. 330 WaitForReads();
219 event.Wait(); 331 Close();
220 332 }
221 ASSERT_FALSE(play_event.IsSignaled()); 333
222 controller->Play(); 334 TEST_F(AudioOutputControllerTest, PlayDivertRevertDivertRevertClose) {
223 controller->Pause(); 335 ASSERT_TRUE(Create(kSamplesPerPacket));
224 controller->Play(); 336 WaitForCreate();
225 play_event.Wait(); 337 Play();
226 338 WaitForPlay();
227 // Now stop the controller. 339 WaitForReads();
228 CloseAudioController(controller); 340 DivertWhilePlaying();
229 } 341 WaitForPlay();
230 342 ReadDivertedAudioData();
231 // Ensure state change events are handled. 343 RevertWhilePlaying();
232 TEST_F(AudioOutputControllerTest, PlayStateChangeClose) { 344 WaitForPlay();
233 scoped_ptr<AudioManager> audio_manager(AudioManager::Create()); 345 WaitForReads();
234 if (!audio_manager->HasAudioOutputDevices()) 346 DivertWhilePlaying();
235 return; 347 WaitForPlay();
236 348 ReadDivertedAudioData();
237 MockAudioOutputControllerEventHandler event_handler; 349 RevertWhilePlaying();
238 base::WaitableEvent event(false, false); 350 WaitForPlay();
239 EXPECT_CALL(event_handler, OnCreated(NotNull())) 351 WaitForReads();
240 .WillOnce(InvokeWithoutArgs(&event, &base::WaitableEvent::Signal)); 352 Close();
241 353 }
242 // OnPlaying() will be called once normally and once after being recreated. 354
243 base::WaitableEvent play_event(false, false); 355 TEST_F(AudioOutputControllerTest, DivertPlayPausePlayRevertClose) {
244 EXPECT_CALL(event_handler, OnPlaying(NotNull())) 356 ASSERT_TRUE(Create(kSamplesPerPacket));
245 .Times(2) 357 WaitForCreate();
246 .WillRepeatedly(InvokeWithoutArgs( 358 DivertWillEventuallyBePlaying();
247 &play_event, &base::WaitableEvent::Signal)); 359 Play();
248 360 WaitForPlay();
249 // OnPaused() should not be called during the state change event. 361 ReadDivertedAudioData();
250 EXPECT_CALL(event_handler, OnPaused(NotNull())) 362 Pause();
251 .Times(0); 363 WaitForPause();
252 364 Play();
253 MockAudioOutputControllerSyncReader sync_reader; 365 WaitForPlay();
254 EXPECT_CALL(sync_reader, UpdatePendingBytes(_)) 366 ReadDivertedAudioData();
255 .Times(AtLeast(1)); 367 RevertWhilePlaying();
256 EXPECT_CALL(sync_reader, Read(_, _)) 368 WaitForPlay();
257 .WillRepeatedly(DoAll(ClearBuffer(), SignalEvent(&event), Return(4))); 369 WaitForReads();
258 EXPECT_CALL(sync_reader, DataReady()) 370 Close();
259 .WillRepeatedly(Return(true)); 371 }
260 EXPECT_CALL(sync_reader, Close()); 372
261 373 TEST_F(AudioOutputControllerTest, DivertRevertClose) {
262 AudioParameters params(AudioParameters::AUDIO_PCM_LINEAR, kChannelLayout, 374 ASSERT_TRUE(Create(kSamplesPerPacket));
263 kSampleRate, kBitsPerSample, kSamplesPerPacket); 375 WaitForCreate();
264 scoped_refptr<AudioOutputController> controller = 376 DivertNeverPlaying();
265 AudioOutputController::Create( 377 RevertWasNotPlaying();
266 audio_manager.get(), &event_handler, params, &sync_reader); 378 Close();
267 ASSERT_TRUE(controller.get());
268
269 // Wait for OnCreated() to be called.
270 event.Wait();
271
272 ASSERT_FALSE(play_event.IsSignaled());
273 controller->Play();
274 play_event.Wait();
275
276 // Force a state change and wait for the stream to come back to playing state.
277 play_event.Reset();
278 audio_manager->GetMessageLoop()->PostTask(FROM_HERE,
279 base::Bind(&AudioOutputController::OnDeviceChange, controller));
280 play_event.Wait();
281
282 // Now stop the controller.
283 CloseAudioController(controller);
284 } 379 }
285 380
286 } // namespace media 381 } // namespace media
OLDNEW
« media/audio/audio_output_controller.cc ('K') | « media/audio/audio_output_controller.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698