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

Unified Diff: content/browser/media/audio_output_stream_impl_unittest.cc

Issue 1930393002: Switch stream creation and closing in Chrome audio rendering from IPC to Mojo (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: unique_ptr for Binding Created 4 years, 7 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 side-by-side diff with in-line comments
Download patch
Index: content/browser/media/audio_output_stream_impl_unittest.cc
diff --git a/content/browser/media/audio_output_stream_impl_unittest.cc b/content/browser/media/audio_output_stream_impl_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..5ad6befc54bde49c1321978cbbdd60d2e2600d44
--- /dev/null
+++ b/content/browser/media/audio_output_stream_impl_unittest.cc
@@ -0,0 +1,171 @@
+// Copyright (c) 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 <stdint.h>
+#include <string>
+
+#include "base/bind.h"
+#include "base/command_line.h"
+#include "content/browser/media/audio_output_impl.h"
+#include "content/browser/media/audio_output_stream_impl.h"
+#include "content/browser/media/capture/audio_mirroring_manager.h"
+#include "content/browser/media/media_internals.h"
+#include "content/browser/renderer_host/media/media_stream_manager.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 "media/audio/audio_manager.h"
+#include "media/base/media_switches.h"
+#include "media/mojo/interfaces/audio_output.mojom.h"
+#include "testing/gmock/include/gmock/gmock.h"
+#include "testing/gtest/include/gtest/gtest.h"
+/*
+using ::testing::_;
+using ::testing::Return;
+
+namespace content {
+
+namespace {
+
+const int kRenderProcessId = 1;
+const int kRenderFrameId = 5;
+const int kStreamId1 = 9;
+const int kStreamId2 = 20;
+
+std::string ReturnMockSalt() {
+ return std::string();
+}
+
+ResourceContext::SaltCallback GetMockSaltCallback() {
+ return base::Bind(&ReturnMockSalt);
+}
+}
+
+class MockAudioOutputStreamAudioRendererHost : public AudioRendererHost {
+ public:
+ MockAudioOutputStreamAudioRendererHost(
+ int render_process_id,
+ media::AudioManager* audio_manager,
+ AudioMirroringManager* mirroring_manager,
+ MediaInternals* media_internals,
+ MediaStreamManager* media_stream_manager,
+ const ResourceContext::SaltCallback& salt_callback)
+ : AudioRendererHost(render_process_id,
+ audio_manager,
+ mirroring_manager,
+ media_internals,
+ media_stream_manager,
+ salt_callback) {}
+
+ MOCK_METHOD1(CloseStream, void(int stream_id));
+
+ protected:
+ FRIEND_TEST_ALL_PREFIXES(AudioOutputStreamImplTest, Close);
+ friend class AudioOutputStreamImplTest;
+ ~MockAudioOutputStreamAudioRendererHost() override {}
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(MockAudioOutputStreamAudioRendererHost);
+};
+
+class MockAudioOutputImpl : public AudioOutputImpl {
+ public:
+ MockAudioOutputImpl(content::RenderProcessHost* process,
+ int render_frame_id,
+ media::mojom::AudioOutputRequest request)
+ : AudioOutputImpl(process, render_frame_id, std::move(request)) {}
+ ~MockAudioOutputImpl() {}
+ MOCK_METHOD1(RemoveStream, bool(int stream_id));
+ DISALLOW_COPY_AND_ASSIGN(MockAudioOutputImpl);
+};
+
+class TestRenderProcessHost : public MockRenderProcessHost {
+ public:
+ TestRenderProcessHost(BrowserContext* context)
+ : MockRenderProcessHost(context) {}
+ scoped_refptr<AudioRendererHost> audio_renderer_host() const override {
+ return audio_renderer_host_;
+ }
+ scoped_refptr<AudioRendererHost> audio_renderer_host_;
+};
+
+class AudioOutputStreamImplTest : public ::testing::Test {
+ public:
+ AudioOutputStreamImplTest() {
+ browser_context_.reset(new TestBrowserContext);
+ render_process_host_.reset(
+ new TestRenderProcessHost(browser_context_.get()));
+
+ audio_manager_ = media::AudioManager::CreateForTesting(
+ base::ThreadTaskRunnerHandle::Get());
+
+ base::CommandLine::ForCurrentProcess()->AppendSwitch(
+ switches::kUseFakeDeviceForMediaStream);
+ media_stream_manager_.reset(new MediaStreamManager(audio_manager_.get()));
+
+ // Enable caching to make enumerations run in a single thread
+ media_stream_manager_->audio_output_device_enumerator()->SetCachePolicy(
+ AudioOutputDeviceEnumerator::CACHE_POLICY_MANUAL_INVALIDATION);
+
+ audio_renderer_host_ = (new MockAudioOutputStreamAudioRendererHost(
+ kRenderProcessId, audio_manager_.get(), &mirroring_manager_,
+ MediaInternals::GetInstance(), media_stream_manager_.get(),
+ GetMockSaltCallback()));
+ render_process_host_->audio_renderer_host_ = audio_renderer_host_;
+ audio_output_impl_.reset(
+ new MockAudioOutputImpl(render_process_host_.get(), kRenderFrameId,
+ media::mojom::AudioOutputRequest()));
+ audio_renderer_host_->set_audio_output_impl(kRenderFrameId,
+ audio_output_impl_.get());
+ }
+
+ ~AudioOutputStreamImplTest() override {
+ // Avoid leaking the |audio_renderer_host_|.
+ audio_renderer_host_ = NULL;
+ }
+
+ protected:
+ std::unique_ptr<MockAudioOutputImpl> audio_output_impl_;
+ scoped_refptr<MockAudioOutputStreamAudioRendererHost> audio_renderer_host_;
+
+ private:
+ media::ScopedAudioManagerPtr audio_manager_;
+ std::unique_ptr<BrowserContext> browser_context_;
+ std::unique_ptr<MediaStreamManager> media_stream_manager_;
+ AudioMirroringManager mirroring_manager_;
+ std::unique_ptr<TestRenderProcessHost> render_process_host_;
+ TestBrowserThreadBundle thread_bundle_;
+ DISALLOW_COPY_AND_ASSIGN(AudioOutputStreamImplTest);
+};
+
+TEST_F(AudioOutputStreamImplTest, Close) {
+ media::mojom::AudioOutputStreamPtr stream1 =
+ media::mojom::AudioOutputStreamPtr();
+
+ std::unique_ptr<AudioOutputStreamImpl> stream_ptr1(
+ new AudioOutputStreamImpl(mojo::GetProxy(&stream1), kStreamId1,
+ kRenderFrameId, audio_renderer_host_.get()));
+
+ EXPECT_CALL(*audio_renderer_host_.get(), CloseStream(kStreamId1)).Times(1);
+ ;
+ EXPECT_CALL(*audio_output_impl_, RemoveStream(kStreamId1)).Times(1);
+
+ stream_ptr1->Close();
+
+ media::mojom::AudioOutputStreamPtr stream2 =
+ media::mojom::AudioOutputStreamPtr();
+
+ std::unique_ptr<AudioOutputStreamImpl> stream_ptr2(
+ new AudioOutputStreamImpl(mojo::GetProxy(&stream2), kStreamId2,
+ kRenderFrameId, audio_renderer_host_.get()));
+
+ EXPECT_CALL(*audio_renderer_host_.get(), CloseStream(kStreamId2)).Times(1);
+ ;
+ EXPECT_CALL(*audio_output_impl_, RemoveStream(kStreamId2)).Times(1);
+
+ stream_ptr2->Close();
+}
+
+} // namespace content
+*/
« no previous file with comments | « content/browser/media/audio_output_stream_impl.cc ('k') | content/browser/renderer_host/media/audio_renderer_host.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698