| 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 ResourceContext::SaltCallback& salt_callback) | 69 const std::string& salt) |
| 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_callback), | 75 salt), |
| 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 } | |
| 180 | 173 |
| 181 void WaitForEnumeration(base::RunLoop* loop, | 174 void WaitForEnumeration(base::RunLoop* loop, |
| 182 const AudioOutputDeviceEnumeration& e) { | 175 const AudioOutputDeviceEnumeration& e) { |
| 183 loop->Quit(); | 176 loop->Quit(); |
| 184 } | 177 } |
| 178 |
| 185 } // namespace | 179 } // namespace |
| 186 | 180 |
| 187 class AudioRendererHostTest : public testing::Test { | 181 class AudioRendererHostTest : public testing::Test { |
| 188 public: | 182 public: |
| 189 AudioRendererHostTest() { | 183 AudioRendererHostTest() { |
| 190 audio_manager_ = media::AudioManager::CreateForTesting( | 184 audio_manager_ = media::AudioManager::CreateForTesting( |
| 191 base::ThreadTaskRunnerHandle::Get()); | 185 base::ThreadTaskRunnerHandle::Get()); |
| 192 base::CommandLine::ForCurrentProcess()->AppendSwitch( | 186 base::CommandLine::ForCurrentProcess()->AppendSwitch( |
| 193 switches::kUseFakeDeviceForMediaStream); | 187 switches::kUseFakeDeviceForMediaStream); |
| 194 media_stream_manager_.reset(new MediaStreamManager(audio_manager_.get())); | 188 media_stream_manager_.reset(new MediaStreamManager(audio_manager_.get())); |
| 195 | 189 |
| 196 // Enable caching to make enumerations run in a single thread | 190 // Enable caching to make enumerations run in a single thread |
| 197 media_stream_manager_->audio_output_device_enumerator()->SetCachePolicy( | 191 media_stream_manager_->audio_output_device_enumerator()->SetCachePolicy( |
| 198 AudioOutputDeviceEnumerator::CACHE_POLICY_MANUAL_INVALIDATION); | 192 AudioOutputDeviceEnumerator::CACHE_POLICY_MANUAL_INVALIDATION); |
| 199 base::RunLoop().RunUntilIdle(); | 193 base::RunLoop().RunUntilIdle(); |
| 200 base::RunLoop run_loop; | 194 base::RunLoop run_loop; |
| 201 media_stream_manager_->audio_output_device_enumerator()->Enumerate( | 195 media_stream_manager_->audio_output_device_enumerator()->Enumerate( |
| 202 base::Bind(&WaitForEnumeration, &run_loop)); | 196 base::Bind(&WaitForEnumeration, &run_loop)); |
| 203 run_loop.Run(); | 197 run_loop.Run(); |
| 204 | 198 |
| 205 host_ = new MockAudioRendererHost(audio_manager_.get(), &mirroring_manager_, | 199 host_ = |
| 206 MediaInternals::GetInstance(), | 200 new MockAudioRendererHost(audio_manager_.get(), &mirroring_manager_, |
| 207 media_stream_manager_.get(), | 201 MediaInternals::GetInstance(), |
| 208 GetMockSaltCallback()); | 202 media_stream_manager_.get(), std::string()); |
| 209 | 203 |
| 210 // Simulate IPC channel connected. | 204 // Simulate IPC channel connected. |
| 211 host_->set_peer_process_for_testing(base::Process::Current()); | 205 host_->set_peer_process_for_testing(base::Process::Current()); |
| 212 } | 206 } |
| 213 | 207 |
| 214 ~AudioRendererHostTest() override { | 208 ~AudioRendererHostTest() override { |
| 215 // Simulate closing the IPC channel and give the audio thread time to close | 209 // Simulate closing the IPC channel and give the audio thread time to close |
| 216 // the underlying streams. | 210 // the underlying streams. |
| 217 host_->OnChannelClosing(); | 211 host_->OnChannelClosing(); |
| 218 SyncWithAudioThread(); | 212 SyncWithAudioThread(); |
| (...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 407 } | 401 } |
| 408 | 402 |
| 409 TEST_F(AudioRendererHostTest, CreateInvalidDevice) { | 403 TEST_F(AudioRendererHostTest, CreateInvalidDevice) { |
| 410 Create(false, kInvalidDeviceId, url::Origin(GURL(kSecurityOrigin))); | 404 Create(false, kInvalidDeviceId, url::Origin(GURL(kSecurityOrigin))); |
| 411 Close(); | 405 Close(); |
| 412 } | 406 } |
| 413 | 407 |
| 414 // TODO(hclam): Add tests for data conversation in low latency mode. | 408 // TODO(hclam): Add tests for data conversation in low latency mode. |
| 415 | 409 |
| 416 } // namespace content | 410 } // namespace content |
| OLD | NEW |