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

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

Issue 899923003: Purge AudioOutputDispatcher after close delay if no proxies exist. (Closed) Base URL: http://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix comments. Created 5 years, 10 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
« no previous file with comments | « media/audio/audio_output_dispatcher_impl.cc ('k') | media/audio/audio_output_resampler.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 <string> 5 #include <string>
6 6
7 #include "base/message_loop/message_loop.h" 7 #include "base/message_loop/message_loop.h"
8 #include "base/run_loop.h" 8 #include "base/run_loop.h"
9 #include "media/audio/audio_manager.h" 9 #include "media/audio/audio_manager.h"
10 #include "media/audio/audio_manager_base.h" 10 #include "media/audio/audio_manager_base.h"
(...skipping 656 matching lines...) Expand 10 before | Expand all | Expand 10 after
667 667
668 proxy1->Stop(); 668 proxy1->Stop();
669 CloseAndWaitForCloseTimer(proxy1, &stream1); 669 CloseAndWaitForCloseTimer(proxy1, &stream1);
670 670
671 EXPECT_TRUE(stream1.stop_called()); 671 EXPECT_TRUE(stream1.stop_called());
672 EXPECT_TRUE(stream1.start_called()); 672 EXPECT_TRUE(stream1.start_called());
673 EXPECT_TRUE(stream2.stop_called()); 673 EXPECT_TRUE(stream2.stop_called());
674 EXPECT_TRUE(stream2.start_called()); 674 EXPECT_TRUE(stream2.start_called());
675 } 675 }
676 676
677 // Simulate failures to open both the low latency and the fallback high latency
678 // stream and ensure AudioOutputResampler falls back to a fake stream. Ensure
679 // that after the close delay elapses, opening another stream succeeds with a
680 // non-fake stream.
681 TEST_F(AudioOutputResamplerTest, FallbackRecovery) {
682 MockAudioOutputStream fake_stream(&manager_, params_);
683
684 // Trigger the fallback mechanism until a fake output stream is created.
685 #if defined(OS_WIN)
686 static const int kFallbackCount = 2;
687 #else
688 static const int kFallbackCount = 1;
689 #endif
690 EXPECT_CALL(manager(), MakeAudioOutputStream(_, _))
691 .Times(kFallbackCount)
692 .WillRepeatedly(Return(static_cast<AudioOutputStream*>(NULL)));
693 EXPECT_CALL(manager(),
694 MakeAudioOutputStream(
695 AllOf(testing::Property(&AudioParameters::format,
696 AudioParameters::AUDIO_FAKE),
697 testing::Property(&AudioParameters::sample_rate,
698 params_.sample_rate()),
699 testing::Property(&AudioParameters::frames_per_buffer,
700 params_.frames_per_buffer())),
701 _)).WillOnce(Return(&fake_stream));
702 EXPECT_CALL(fake_stream, Open()).WillOnce(Return(true));
703 AudioOutputProxy* proxy = new AudioOutputProxy(resampler_.get());
704 EXPECT_TRUE(proxy->Open());
705 CloseAndWaitForCloseTimer(proxy, &fake_stream);
706
707 // Once all proxies have been closed, AudioOutputResampler will start the
708 // reinitialization timer and execute it after the close delay elapses.
709 base::RunLoop run_loop;
710 message_loop_.PostDelayedTask(
711 FROM_HERE, run_loop.QuitClosure(),
712 base::TimeDelta::FromMilliseconds(2 * kTestCloseDelayMs));
713 run_loop.Run();
714
715 // Verify a non-fake stream can be created.
716 MockAudioOutputStream real_stream(&manager_, params_);
717 EXPECT_CALL(manager(),
718 MakeAudioOutputStream(
719 testing::Property(&AudioParameters::format,
720 testing::Ne(AudioParameters::AUDIO_FAKE)),
721 _)).WillOnce(Return(&real_stream));
722
723 // Stream1 should be able to successfully open and start.
724 EXPECT_CALL(real_stream, Open()).WillOnce(Return(true));
725 proxy = new AudioOutputProxy(resampler_.get());
726 EXPECT_TRUE(proxy->Open());
727 CloseAndWaitForCloseTimer(proxy, &real_stream);
728 }
729
677 } // namespace media 730 } // namespace media
OLDNEW
« no previous file with comments | « media/audio/audio_output_dispatcher_impl.cc ('k') | media/audio/audio_output_resampler.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698