| OLD | NEW |
| 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 "content/browser/renderer_host/media/audio_renderer_host.h" | 5 #include "content/browser/renderer_host/media/audio_renderer_host.h" |
| 6 | 6 |
| 7 #include <stdint.h> | 7 #include <stdint.h> |
| 8 | 8 |
| 9 #include <memory> | 9 #include <memory> |
| 10 | 10 |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 59 private: | 59 private: |
| 60 DISALLOW_COPY_AND_ASSIGN(MockAudioMirroringManager); | 60 DISALLOW_COPY_AND_ASSIGN(MockAudioMirroringManager); |
| 61 }; | 61 }; |
| 62 | 62 |
| 63 class MockAudioRendererHost : public AudioRendererHost { | 63 class MockAudioRendererHost : public AudioRendererHost { |
| 64 public: | 64 public: |
| 65 MockAudioRendererHost(media::AudioManager* audio_manager, | 65 MockAudioRendererHost(media::AudioManager* audio_manager, |
| 66 AudioMirroringManager* mirroring_manager, | 66 AudioMirroringManager* mirroring_manager, |
| 67 MediaInternals* media_internals, | 67 MediaInternals* media_internals, |
| 68 MediaStreamManager* media_stream_manager, | 68 MediaStreamManager* media_stream_manager, |
| 69 const std::string& salt) | 69 const ResourceContext::SaltCallback& salt_callback) |
| 70 : AudioRendererHost(kRenderProcessId, | 70 : AudioRendererHost(kRenderProcessId, |
| 71 audio_manager, | 71 audio_manager, |
| 72 mirroring_manager, | 72 mirroring_manager, |
| 73 media_internals, | 73 media_internals, |
| 74 media_stream_manager, | 74 media_stream_manager, |
| 75 salt), | 75 salt_callback), |
| 76 shared_memory_length_(0) {} | 76 shared_memory_length_(0) {} |
| 77 | 77 |
| 78 // A list of mock methods. | 78 // A list of mock methods. |
| 79 MOCK_METHOD4(OnDeviceAuthorized, | 79 MOCK_METHOD4(OnDeviceAuthorized, |
| 80 void(int stream_id, | 80 void(int stream_id, |
| 81 media::OutputDeviceStatus device_status, | 81 media::OutputDeviceStatus device_status, |
| 82 const media::AudioParameters& output_params, | 82 const media::AudioParameters& output_params, |
| 83 const std::string& matched_device_id)); | 83 const std::string& matched_device_id)); |
| 84 MOCK_METHOD2(OnStreamCreated, void(int stream_id, int length)); | 84 MOCK_METHOD2(OnStreamCreated, void(int stream_id, int length)); |
| 85 MOCK_METHOD1(OnStreamPlaying, void(int stream_id)); | 85 MOCK_METHOD1(OnStreamPlaying, void(int stream_id)); |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 163 } | 163 } |
| 164 | 164 |
| 165 std::unique_ptr<base::SharedMemory> shared_memory_; | 165 std::unique_ptr<base::SharedMemory> shared_memory_; |
| 166 std::unique_ptr<base::SyncSocket> sync_socket_; | 166 std::unique_ptr<base::SyncSocket> sync_socket_; |
| 167 uint32_t shared_memory_length_; | 167 uint32_t shared_memory_length_; |
| 168 | 168 |
| 169 DISALLOW_COPY_AND_ASSIGN(MockAudioRendererHost); | 169 DISALLOW_COPY_AND_ASSIGN(MockAudioRendererHost); |
| 170 }; | 170 }; |
| 171 | 171 |
| 172 namespace { | 172 namespace { |
| 173 std::string ReturnMockSalt() { |
| 174 return std::string(); |
| 175 } |
| 176 |
| 177 ResourceContext::SaltCallback GetMockSaltCallback() { |
| 178 return base::Bind(&ReturnMockSalt); |
| 179 } |
| 173 | 180 |
| 174 void WaitForEnumeration(base::RunLoop* loop, | 181 void WaitForEnumeration(base::RunLoop* loop, |
| 175 const AudioOutputDeviceEnumeration& e) { | 182 const AudioOutputDeviceEnumeration& e) { |
| 176 loop->Quit(); | 183 loop->Quit(); |
| 177 } | 184 } |
| 178 | |
| 179 } // namespace | 185 } // namespace |
| 180 | 186 |
| 181 class AudioRendererHostTest : public testing::Test { | 187 class AudioRendererHostTest : public testing::Test { |
| 182 public: | 188 public: |
| 183 AudioRendererHostTest() { | 189 AudioRendererHostTest() { |
| 184 audio_manager_ = media::AudioManager::CreateForTesting( | 190 audio_manager_ = media::AudioManager::CreateForTesting( |
| 185 base::ThreadTaskRunnerHandle::Get()); | 191 base::ThreadTaskRunnerHandle::Get()); |
| 186 base::CommandLine::ForCurrentProcess()->AppendSwitch( | 192 base::CommandLine::ForCurrentProcess()->AppendSwitch( |
| 187 switches::kUseFakeDeviceForMediaStream); | 193 switches::kUseFakeDeviceForMediaStream); |
| 188 media_stream_manager_.reset(new MediaStreamManager(audio_manager_.get())); | 194 media_stream_manager_.reset(new MediaStreamManager(audio_manager_.get())); |
| 189 | 195 |
| 190 // Enable caching to make enumerations run in a single thread | 196 // Enable caching to make enumerations run in a single thread |
| 191 media_stream_manager_->audio_output_device_enumerator()->SetCachePolicy( | 197 media_stream_manager_->audio_output_device_enumerator()->SetCachePolicy( |
| 192 AudioOutputDeviceEnumerator::CACHE_POLICY_MANUAL_INVALIDATION); | 198 AudioOutputDeviceEnumerator::CACHE_POLICY_MANUAL_INVALIDATION); |
| 193 base::RunLoop().RunUntilIdle(); | 199 base::RunLoop().RunUntilIdle(); |
| 194 base::RunLoop run_loop; | 200 base::RunLoop run_loop; |
| 195 media_stream_manager_->audio_output_device_enumerator()->Enumerate( | 201 media_stream_manager_->audio_output_device_enumerator()->Enumerate( |
| 196 base::Bind(&WaitForEnumeration, &run_loop)); | 202 base::Bind(&WaitForEnumeration, &run_loop)); |
| 197 run_loop.Run(); | 203 run_loop.Run(); |
| 198 | 204 |
| 199 host_ = | 205 host_ = new MockAudioRendererHost(audio_manager_.get(), &mirroring_manager_, |
| 200 new MockAudioRendererHost(audio_manager_.get(), &mirroring_manager_, | 206 MediaInternals::GetInstance(), |
| 201 MediaInternals::GetInstance(), | 207 media_stream_manager_.get(), |
| 202 media_stream_manager_.get(), std::string()); | 208 GetMockSaltCallback()); |
| 203 | 209 |
| 204 // Simulate IPC channel connected. | 210 // Simulate IPC channel connected. |
| 205 host_->set_peer_process_for_testing(base::Process::Current()); | 211 host_->set_peer_process_for_testing(base::Process::Current()); |
| 206 } | 212 } |
| 207 | 213 |
| 208 ~AudioRendererHostTest() override { | 214 ~AudioRendererHostTest() override { |
| 209 // Simulate closing the IPC channel and give the audio thread time to close | 215 // Simulate closing the IPC channel and give the audio thread time to close |
| 210 // the underlying streams. | 216 // the underlying streams. |
| 211 host_->OnChannelClosing(); | 217 host_->OnChannelClosing(); |
| 212 SyncWithAudioThread(); | 218 SyncWithAudioThread(); |
| (...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 401 } | 407 } |
| 402 | 408 |
| 403 TEST_F(AudioRendererHostTest, CreateInvalidDevice) { | 409 TEST_F(AudioRendererHostTest, CreateInvalidDevice) { |
| 404 Create(false, kInvalidDeviceId, url::Origin(GURL(kSecurityOrigin))); | 410 Create(false, kInvalidDeviceId, url::Origin(GURL(kSecurityOrigin))); |
| 405 Close(); | 411 Close(); |
| 406 } | 412 } |
| 407 | 413 |
| 408 // TODO(hclam): Add tests for data conversation in low latency mode. | 414 // TODO(hclam): Add tests for data conversation in low latency mode. |
| 409 | 415 |
| 410 } // namespace content | 416 } // namespace content |
| OLD | NEW |