Index: content/browser/renderer_host/media/audio_stream_registry_impl_unittest.cc |
diff --git a/content/browser/renderer_host/media/audio_stream_registry_impl_unittest.cc b/content/browser/renderer_host/media/audio_stream_registry_impl_unittest.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..54b4c2e83641ea479ad39f21dae1147e297d0ba9 |
--- /dev/null |
+++ b/content/browser/renderer_host/media/audio_stream_registry_impl_unittest.cc |
@@ -0,0 +1,130 @@ |
+// Copyright 2016 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include "content/browser/renderer_host/media/audio_stream_registry_impl.h" |
+ |
+#include "base/run_loop.h" |
+#include "content/public/test/mock_render_process_host.h" |
+#include "content/public/test/test_browser_context.h" |
+#include "content/public/test/test_browser_thread_bundle.h" |
+#include "testing/gmock/include/gmock/gmock.h" |
+#include "testing/gtest/include/gtest/gtest.h" |
+ |
+using testing::StrictMock; |
+using testing::Mock; |
+ |
+namespace content { |
+ |
+namespace { |
+ |
+class MockStream : public AudioStreamRegistry::Stream { |
+ public: |
+ MOCK_METHOD1(EnableDebugRecording, void(const base::FilePath&)); |
+ MOCK_METHOD0(DisableDebugRecording, void()); |
+}; |
+ |
+class MockRenderProcessHostHandler { |
+ public: |
+ MOCK_METHOD0(AudioStateChanged, void()); |
+}; |
+ |
+#if defined(OS_WIN) |
+const wchar_t kBaseFileName[] = L"some_file_name"; |
+#else |
+const char kBaseFileName[] = "some_file_name"; |
+#endif |
+} // namespace |
+ |
+class AudioStreamRegistryImplTest : public testing::Test { |
+ public: |
+ AudioStreamRegistryImplTest() = default; |
+ ~AudioStreamRegistryImplTest() override = default; |
+ |
+ private: |
+ TestBrowserThreadBundle thread_bundle_; |
+}; |
+ |
+TEST_F(AudioStreamRegistryImplTest, RegisterUnregister) { |
+ AudioStreamRegistryImpl registry(0); |
+ StrictMock<MockStream> s; |
+ |
+ EXPECT_FALSE(registry.HasActiveAudio()); |
+ registry.RegisterOutputStream(&s); |
+ EXPECT_FALSE(registry.HasActiveAudio()); |
+ registry.DeregisterOutputStream(&s); |
+ EXPECT_FALSE(registry.HasActiveAudio()); |
+} |
+ |
+TEST_F(AudioStreamRegistryImplTest, RegisterPlayUnregister) { |
+ AudioStreamRegistryImpl registry(0); |
+ StrictMock<MockStream> s; |
+ |
+ registry.RegisterOutputStream(&s); |
+ registry.OutputStreamStateChanged(&s, true); |
+ EXPECT_TRUE(registry.HasActiveAudio()); |
+ registry.OutputStreamStateChanged(&s, false); |
+ EXPECT_FALSE(registry.HasActiveAudio()); |
+ registry.DeregisterOutputStream(&s); |
+ EXPECT_FALSE(registry.HasActiveAudio()); |
+} |
+ |
+TEST_F(AudioStreamRegistryImplTest, DebugRecording) { |
+ base::FilePath path(kBaseFileName); |
+ AudioStreamRegistryImpl registry(0); |
+ StrictMock<MockStream> s1; |
+ StrictMock<MockStream> s2; |
+ StrictMock<MockStream> s3; |
+ |
+ registry.RegisterOutputStream(&s1); |
+ registry.RegisterOutputStream(&s2); |
+ registry.DeregisterOutputStream(&s1); |
+// s1 should not get a call since it's not registered. |
+#if BUILDFLAG(ENABLE_WEBRTC) |
+ { |
+ testing::InSequence s; |
+ EXPECT_CALL(s2, EnableDebugRecording(path)); |
+ EXPECT_CALL(s2, DisableDebugRecording()); |
+ } |
+ { |
+ testing::InSequence s; |
+ EXPECT_CALL(s3, EnableDebugRecording(path)); |
+ EXPECT_CALL(s3, DisableDebugRecording()); |
+ } |
+ registry.EnableDebugRecording(path); |
+#endif // BUILDFLAG(ENABLE_WEBRTC) |
+ registry.RegisterOutputStream(&s3); |
+ registry.DeregisterOutputStream(&s2); |
+#if BUILDFLAG(ENABLE_WEBRTC) |
+ registry.DisableDebugRecording(); |
+#endif // BUILDFLAG(ENABLE_WEBRTC) |
+ EXPECT_TRUE(Mock::VerifyAndClearExpectations(&s2)); |
+ EXPECT_TRUE(Mock::VerifyAndClearExpectations(&s3)); |
+ registry.DeregisterOutputStream(&s3); |
+} |
+ |
+TEST_F(AudioStreamRegistryImplTest, StateChangeNotifiesRenderProcessHost) { |
+ TestBrowserContext context; |
+ MockRenderProcessHost rph(&context); |
+ StrictMock<MockRenderProcessHostHandler> mock; |
+ rph.SetAudioStateChangedCallback( |
+ base::Bind(&MockRenderProcessHostHandler::AudioStateChanged, |
+ base::Unretained(&mock))); |
+ AudioStreamRegistryImpl registry(rph.GetID()); |
+ |
+ StrictMock<MockStream> s1; |
+ registry.RegisterOutputStream(&s1); |
+ base::RunLoop().RunUntilIdle(); |
+ |
+ EXPECT_CALL(mock, AudioStateChanged()); |
+ registry.OutputStreamStateChanged(&s1, true); |
+ base::RunLoop().RunUntilIdle(); |
+ EXPECT_TRUE(Mock::VerifyAndClearExpectations(&mock)); |
+ EXPECT_CALL(mock, AudioStateChanged()); |
+ registry.OutputStreamStateChanged(&s1, false); |
+ base::RunLoop().RunUntilIdle(); |
+ EXPECT_TRUE(Mock::VerifyAndClearExpectations(&mock)); |
+ registry.DeregisterOutputStream(&s1); |
+} |
+ |
+} // namespace content |