OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include <stdint.h> |
| 6 #include <string> |
| 7 |
| 8 #include "base/bind.h" |
| 9 #include "base/command_line.h" |
| 10 #include "content/browser/media/audio_output_impl.h" |
| 11 #include "content/browser/media/audio_output_stream_impl.h" |
| 12 #include "content/browser/media/capture/audio_mirroring_manager.h" |
| 13 #include "content/browser/media/media_internals.h" |
| 14 #include "content/browser/renderer_host/media/media_stream_manager.h" |
| 15 #include "content/public/test/test_browser_thread_bundle.h" |
| 16 #include "media/audio/audio_manager.h" |
| 17 #include "media/base/media_switches.h" |
| 18 #include "media/mojo/interfaces/audio_output.mojom.h" |
| 19 #include "testing/gmock/include/gmock/gmock.h" |
| 20 #include "testing/gtest/include/gtest/gtest.h" |
| 21 |
| 22 using ::testing::_; |
| 23 using ::testing::Return; |
| 24 |
| 25 namespace content { |
| 26 |
| 27 namespace { |
| 28 |
| 29 const int kRenderFrameId1 = 5; |
| 30 const int kStreamId1 = 9; |
| 31 // const int kStreamId2 = 20; |
| 32 |
| 33 // const int kStreamIds[] = {800, 2, 30, 22}; |
| 34 // const unsigned int kStreamIdsSize = 4; |
| 35 const int kRenderProcessId = 1; |
| 36 |
| 37 std::string ReturnMockSalt() { |
| 38 return std::string(); |
| 39 } |
| 40 |
| 41 ResourceContext::SaltCallback GetMockSaltCallback() { |
| 42 return base::Bind(&ReturnMockSalt); |
| 43 } |
| 44 } |
| 45 |
| 46 class MockAudioOutputImpl : public AudioOutputImpl { |
| 47 public: |
| 48 MockAudioOutputImpl(scoped_refptr<AudioRendererHost> audio_renderer_host, |
| 49 int render_frame_id, |
| 50 media::mojom::AudioOutputRequest request) |
| 51 : AudioOutputImpl(audio_renderer_host, |
| 52 render_frame_id, |
| 53 std::move(request)) {} |
| 54 |
| 55 MOCK_METHOD1(RemoveStream, bool(int stream_id)); |
| 56 DISALLOW_COPY_AND_ASSIGN(MockAudioOutputImpl); |
| 57 }; |
| 58 |
| 59 class MockAudioOutputStreamAudioRendererHost : public AudioRendererHost { |
| 60 public: |
| 61 MockAudioOutputStreamAudioRendererHost( |
| 62 int render_process_id, |
| 63 media::AudioManager* audio_manager, |
| 64 AudioMirroringManager* mirroring_manager, |
| 65 MediaInternals* media_internals, |
| 66 MediaStreamManager* media_stream_manager, |
| 67 const ResourceContext::SaltCallback& salt_callback) |
| 68 : AudioRendererHost(render_process_id, |
| 69 audio_manager, |
| 70 mirroring_manager, |
| 71 media_internals, |
| 72 media_stream_manager, |
| 73 salt_callback) {} |
| 74 |
| 75 MOCK_METHOD1(CloseStream, void(int stream_id)); |
| 76 |
| 77 protected: |
| 78 FRIEND_TEST_ALL_PREFIXES(AudioOutputStreamImplTest, Close); |
| 79 friend class AudioOutputStreamImplTest; |
| 80 virtual ~MockAudioOutputStreamAudioRendererHost() {} |
| 81 |
| 82 private: |
| 83 DISALLOW_COPY_AND_ASSIGN(MockAudioOutputStreamAudioRendererHost); |
| 84 }; |
| 85 |
| 86 class AudioOutputStreamImplTest : public ::testing::Test { |
| 87 public: |
| 88 AudioOutputStreamImplTest() { |
| 89 audio_manager_ = media::AudioManager::CreateForTesting( |
| 90 base::ThreadTaskRunnerHandle::Get()); |
| 91 |
| 92 base::CommandLine::ForCurrentProcess()->AppendSwitch( |
| 93 switches::kUseFakeDeviceForMediaStream); |
| 94 media_stream_manager_.reset(new MediaStreamManager(audio_manager_.get())); |
| 95 |
| 96 // Enable caching to make enumerations run in a single thread |
| 97 media_stream_manager_->audio_output_device_enumerator()->SetCachePolicy( |
| 98 AudioOutputDeviceEnumerator::CACHE_POLICY_MANUAL_INVALIDATION); |
| 99 |
| 100 audio_renderer_host_ = (new MockAudioOutputStreamAudioRendererHost( |
| 101 kRenderProcessId, audio_manager_.get(), &mirroring_manager_, |
| 102 MediaInternals::GetInstance(), media_stream_manager_.get(), |
| 103 GetMockSaltCallback())); |
| 104 |
| 105 audio_output_impl_.reset( |
| 106 new MockAudioOutputImpl(audio_renderer_host_, kRenderFrameId1, |
| 107 media::mojom::AudioOutputRequest())); |
| 108 audio_renderer_host_->set_audio_output_impl(kRenderFrameId1, |
| 109 audio_output_impl_.get()); |
| 110 } |
| 111 |
| 112 ~AudioOutputStreamImplTest() override { audio_renderer_host_ = NULL; } |
| 113 |
| 114 protected: |
| 115 // MockAudioOutputStreamAudioRendererHost* audio_renderer_host_; |
| 116 std::unique_ptr<MockAudioOutputImpl> audio_output_impl_; |
| 117 |
| 118 scoped_refptr<MockAudioOutputStreamAudioRendererHost> audio_renderer_host_; |
| 119 |
| 120 private: |
| 121 media::ScopedAudioManagerPtr audio_manager_; |
| 122 std::unique_ptr<MediaStreamManager> media_stream_manager_; |
| 123 TestBrowserThreadBundle thread_bundle_; |
| 124 AudioMirroringManager mirroring_manager_; |
| 125 |
| 126 DISALLOW_COPY_AND_ASSIGN(AudioOutputStreamImplTest); |
| 127 }; |
| 128 |
| 129 TEST_F(AudioOutputStreamImplTest, Close) { |
| 130 media::mojom::AudioOutputStreamPtr stream1 = |
| 131 media::mojom::AudioOutputStreamPtr(); |
| 132 |
| 133 std::unique_ptr<AudioOutputStreamImpl> stream_ptr1( |
| 134 new AudioOutputStreamImpl(mojo::GetProxy(&stream1), kStreamId1, |
| 135 kRenderFrameId1, audio_renderer_host_.get())); |
| 136 |
| 137 EXPECT_CALL(*audio_renderer_host_.get(), CloseStream(kStreamId1)); |
| 138 |
| 139 EXPECT_CALL(*audio_output_impl_, RemoveStream(kStreamId1)).Times(1); |
| 140 stream_ptr1->Close(); |
| 141 } |
| 142 } // namespace content |
OLD | NEW |