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

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

Issue 14273018: Use the browser UI thread for audio on OSX. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix test failures. Created 7 years, 6 months 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/basictypes.h"
6 #include "base/bind.h" 6 #include "base/bind.h"
7 #include "base/environment.h"
8 #include "base/logging.h" 7 #include "base/logging.h"
9 #include "base/memory/ref_counted.h"
10 #include "base/memory/scoped_ptr.h" 8 #include "base/memory/scoped_ptr.h"
11 #include "base/message_loop.h" 9 #include "base/message_loop_proxy.h"
12 #include "base/synchronization/waitable_event.h" 10 #include "base/synchronization/waitable_event.h"
13 #include "media/audio/audio_output_controller.h" 11 #include "media/audio/audio_output_controller.h"
14 #include "media/audio/audio_parameters.h" 12 #include "media/audio/audio_parameters.h"
15 #include "media/base/audio_bus.h" 13 #include "media/base/audio_bus.h"
16 #include "testing/gmock/include/gmock/gmock.h" 14 #include "testing/gmock/include/gmock/gmock.h"
17 #include "testing/gtest/include/gtest/gtest.h" 15 #include "testing/gtest/include/gtest/gtest.h"
18 16
19 using ::testing::_; 17 using ::testing::_;
20 using ::testing::AtLeast; 18 using ::testing::AtLeast;
21 using ::testing::DoAll; 19 using ::testing::DoAll;
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after
215 .WillOnce(SignalEvent(&play_event_)); 213 .WillOnce(SignalEvent(&play_event_));
216 } 214 }
217 215
218 EXPECT_CALL(mock_stream_, Close()); 216 EXPECT_CALL(mock_stream_, Close());
219 217
220 controller_->StopDiverting(); 218 controller_->StopDiverting();
221 } 219 }
222 220
223 void Close() { 221 void Close() {
224 EXPECT_CALL(mock_sync_reader_, Close()); 222 EXPECT_CALL(mock_sync_reader_, Close());
223 base::WaitableEvent close_event(true, false);
224 base::Closure closed_cb = base::Bind(
225 &base::WaitableEvent::Signal, base::Unretained(&close_event));
225 226
226 controller_->Close(base::MessageLoop::QuitClosure()); 227 audio_manager_->GetMessageLoop()->PostTask(
227 base::MessageLoop::current()->Run(); 228 FROM_HERE,
229 base::Bind(&AudioOutputController::Close, controller_, closed_cb));
230 close_event.Wait();
228 } 231 }
229 232
230 // These help make test sequences more readable. 233 // These help make test sequences more readable.
231 void DivertNeverPlaying() { Divert(false, 0); } 234 void DivertNeverPlaying() { Divert(false, 0); }
232 void DivertWillEventuallyBeTwicePlayed() { Divert(false, 2); } 235 void DivertWillEventuallyBeTwicePlayed() { Divert(false, 2); }
233 void DivertWhilePlaying() { Divert(true, 1); } 236 void DivertWhilePlaying() { Divert(true, 1); }
234 void RevertWasNotPlaying() { Revert(false); } 237 void RevertWasNotPlaying() { Revert(false); }
235 void RevertWhilePlaying() { Revert(true); } 238 void RevertWhilePlaying() { Revert(true); }
236 239
237 // These synchronize the main thread with key events taking place on other 240 // These synchronize the main thread with key events taking place on other
238 // threads. 241 // threads.
239 void WaitForCreate() { create_event_.Wait(); } 242 void WaitForCreate() { create_event_.Wait(); }
240 void WaitForPlay() { play_event_.Wait(); } 243 void WaitForPlay() { play_event_.Wait(); }
241 void WaitForReads() { 244 void WaitForReads() {
242 // Note: Arbitrarily chosen, but more iterations causes tests to take 245 // Note: Arbitrarily chosen, but more iterations causes tests to take
243 // significantly more time. 246 // significantly more time.
244 static const int kNumIterations = 3; 247 static const int kNumIterations = 3;
245 for (int i = 0; i < kNumIterations; ++i) { 248 for (int i = 0; i < kNumIterations; ++i) {
246 read_event_.Wait(); 249 read_event_.Wait();
247 } 250 }
248 } 251 }
249 void WaitForPause() { pause_event_.Wait(); } 252 void WaitForPause() { pause_event_.Wait(); }
250 253
251 private: 254 private:
252 base::MessageLoopForIO message_loop_;
253 scoped_ptr<AudioManager> audio_manager_; 255 scoped_ptr<AudioManager> audio_manager_;
254 MockAudioOutputControllerEventHandler mock_event_handler_; 256 MockAudioOutputControllerEventHandler mock_event_handler_;
255 MockAudioOutputControllerSyncReader mock_sync_reader_; 257 MockAudioOutputControllerSyncReader mock_sync_reader_;
256 MockAudioOutputStream mock_stream_; 258 MockAudioOutputStream mock_stream_;
257 base::WaitableEvent create_event_; 259 base::WaitableEvent create_event_;
258 base::WaitableEvent play_event_; 260 base::WaitableEvent play_event_;
259 base::WaitableEvent read_event_; 261 base::WaitableEvent read_event_;
260 base::WaitableEvent pause_event_; 262 base::WaitableEvent pause_event_;
261 AudioParameters params_; 263 AudioParameters params_;
262 scoped_refptr<AudioOutputController> controller_; 264 scoped_refptr<AudioOutputController> controller_;
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
374 376
375 TEST_F(AudioOutputControllerTest, DivertRevertClose) { 377 TEST_F(AudioOutputControllerTest, DivertRevertClose) {
376 Create(kSamplesPerPacket); 378 Create(kSamplesPerPacket);
377 WaitForCreate(); 379 WaitForCreate();
378 DivertNeverPlaying(); 380 DivertNeverPlaying();
379 RevertWasNotPlaying(); 381 RevertWasNotPlaying();
380 Close(); 382 Close();
381 } 383 }
382 384
383 } // namespace media 385 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698