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

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

Issue 11298006: Browser-wide audio mirroring for TabCapture API (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Adress nits 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/bind.h" 5 #include "base/bind.h"
6 #include "base/environment.h" 6 #include "base/environment.h"
7 #include "base/basictypes.h" 7 #include "base/basictypes.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "base/message_loop.h" 9 #include "base/message_loop.h"
10 #include "base/synchronization/waitable_event.h" 10 #include "base/synchronization/waitable_event.h"
11 #include "media/audio/audio_output_controller.h" 11 #include "media/audio/audio_output_controller.h"
12 #include "media/audio/virtual_audio_input_stream.h"
12 #include "testing/gmock/include/gmock/gmock.h" 13 #include "testing/gmock/include/gmock/gmock.h"
13 #include "testing/gtest/include/gtest/gtest.h" 14 #include "testing/gtest/include/gtest/gtest.h"
14 15
15 // TODO(vrk): These tests need to be rewritten! (crbug.com/112500) 16 // TODO(vrk): These tests need to be rewritten! (crbug.com/112500)
16 17
17 using ::testing::_; 18 using ::testing::_;
18 using ::testing::AtLeast; 19 using ::testing::AtLeast;
19 using ::testing::DoAll; 20 using ::testing::DoAll;
20 using ::testing::Exactly; 21 using ::testing::Exactly;
21 using ::testing::InvokeWithoutArgs; 22 using ::testing::InvokeWithoutArgs;
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
70 } 71 }
71 72
72 // Closes AudioOutputController synchronously. 73 // Closes AudioOutputController synchronously.
73 static void CloseAudioController(AudioOutputController* controller) { 74 static void CloseAudioController(AudioOutputController* controller) {
74 controller->Close(MessageLoop::QuitClosure()); 75 controller->Close(MessageLoop::QuitClosure());
75 MessageLoop::current()->Run(); 76 MessageLoop::current()->Run();
76 } 77 }
77 78
78 class AudioOutputControllerTest : public testing::Test { 79 class AudioOutputControllerTest : public testing::Test {
79 public: 80 public:
80 AudioOutputControllerTest() {} 81 AudioOutputControllerTest() : done_(false, false) {}
81 virtual ~AudioOutputControllerTest() {} 82 virtual ~AudioOutputControllerTest() {}
82 83
84 void EndTestVirtualAudioTest(int callbacks) {
85 stream_->Stop();
86 stream_->Close();
87
88 done_.Signal();
89 }
90
83 protected: 91 protected:
92 AudioInputStream* stream_;
84 MessageLoopForIO message_loop_; 93 MessageLoopForIO message_loop_;
94 base::WaitableEvent done_;
85 95
86 private: 96 private:
87 DISALLOW_COPY_AND_ASSIGN(AudioOutputControllerTest); 97 DISALLOW_COPY_AND_ASSIGN(AudioOutputControllerTest);
88 }; 98 };
89 99
90 TEST_F(AudioOutputControllerTest, CreateAndClose) { 100 TEST_F(AudioOutputControllerTest, CreateAndClose) {
91 scoped_ptr<AudioManager> audio_manager(AudioManager::Create()); 101 scoped_ptr<AudioManager> audio_manager(AudioManager::Create());
92 if (!audio_manager->HasAudioOutputDevices()) 102 if (!audio_manager->HasAudioOutputDevices())
93 return; 103 return;
94 104
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after
276 // Force a state change and wait for the stream to come back to playing state. 286 // Force a state change and wait for the stream to come back to playing state.
277 play_event.Reset(); 287 play_event.Reset();
278 audio_manager->GetMessageLoop()->PostTask(FROM_HERE, 288 audio_manager->GetMessageLoop()->PostTask(FROM_HERE,
279 base::Bind(&AudioOutputController::OnDeviceChange, controller)); 289 base::Bind(&AudioOutputController::OnDeviceChange, controller));
280 play_event.Wait(); 290 play_event.Wait();
281 291
282 // Now stop the controller. 292 // Now stop the controller.
283 CloseAudioController(controller); 293 CloseAudioController(controller);
284 } 294 }
285 295
296 // Tests that we detach an existing audio stream and re-attach them as virtual
297 // output streams when a VirtualAudioInputStream is created.
298 TEST_F(AudioOutputControllerTest, VirtualStreamsTriggerDeviceChange) {
299 scoped_ptr<AudioManager> audio_manager(AudioManager::Create());
300 if (!audio_manager->HasAudioOutputDevices())
301 return;
302
303 MockAudioOutputControllerEventHandler event_handler;
304 base::WaitableEvent event(false, false);
305 EXPECT_CALL(event_handler, OnCreated(NotNull()))
306 .WillOnce(InvokeWithoutArgs(&event, &base::WaitableEvent::Signal));
307
308 // OnPlaying() will be called once normally and once after being recreated.
309 base::WaitableEvent play_event(false, false);
310 EXPECT_CALL(event_handler, OnPlaying(NotNull()))
311 .Times(2)
312 .WillRepeatedly(InvokeWithoutArgs(
313 &play_event, &base::WaitableEvent::Signal));
314
315 // OnPaused() should not be called during the state change event.
316 EXPECT_CALL(event_handler, OnPaused(NotNull()))
317 .Times(0);
318
319 MockAudioOutputControllerSyncReader sync_reader;
320 EXPECT_CALL(sync_reader, UpdatePendingBytes(_))
321 .Times(AtLeast(1));
322 EXPECT_CALL(sync_reader, Read(_, _))
323 .WillRepeatedly(DoAll(ClearBuffer(), SignalEvent(&event), Return(4)));
324 EXPECT_CALL(sync_reader, DataReady())
325 .WillRepeatedly(Return(true));
326 EXPECT_CALL(sync_reader, Close());
327
328 AudioParameters params(AudioParameters::AUDIO_PCM_LINEAR, kChannelLayout,
329 kSampleRate, kBitsPerSample, kSamplesPerPacket);
330 scoped_refptr<AudioOutputController> controller =
331 AudioOutputController::Create(
332 audio_manager.get(), &event_handler, params, &sync_reader);
333 ASSERT_TRUE(controller.get());
334
335 // Wait for OnCreated() to be called.
336 event.Wait();
337
338 ASSERT_FALSE(play_event.IsSignaled());
339 controller->Play();
340 play_event.Wait();
341
342 play_event.Reset();
343
344 // Create a new VirtualAudioInputStream and expect another play event and
345 // the existing output stream to be recreated as a VirtualAudiOutputStream and
346 // attached.
347 stream_ = audio_manager->MakeAudioInputStream(
348 AudioParameters(AudioParameters::AUDIO_MIRROR_BROWSER,
349 CHANNEL_LAYOUT_MONO, 8000, 8, 128), "1");
350
351 play_event.Wait();
352 EXPECT_EQ(1u,
353 static_cast<VirtualAudioInputStream*>(stream_)->converters_.size());
354
355 int callbacks = 0;
356 audio_manager->GetMessageLoop()->PostTask(FROM_HERE, base::Bind(
357 &AudioOutputControllerTest::EndTestVirtualAudioTest,
358 base::Unretained(this),
359 callbacks));
360 done_.Wait();
361
362 // Now stop the controller.
363 CloseAudioController(controller);
364 }
365
286 } // namespace media 366 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698