| 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 <stddef.h> | 5 #include <stddef.h> |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| 11 #include "base/location.h" | 11 #include "base/location.h" |
| 12 #include "base/macros.h" | 12 #include "base/macros.h" |
| 13 #include "base/run_loop.h" | 13 #include "base/run_loop.h" |
| 14 #include "base/strings/string_number_conversions.h" | 14 #include "base/strings/string_number_conversions.h" |
| 15 #include "base/strings/string_util.h" | 15 #include "base/strings/string_util.h" |
| 16 #include "base/threading/thread_task_runner_handle.h" | 16 #include "base/threading/thread_task_runner_handle.h" |
| 17 #include "build/build_config.h" | 17 #include "build/build_config.h" |
| 18 #include "content/browser/browser_thread_impl.h" | 18 #include "content/browser/browser_thread_impl.h" |
| 19 #include "content/browser/renderer_host/media/media_stream_manager.h" | 19 #include "content/browser/renderer_host/media/media_stream_manager.h" |
| 20 #include "content/browser/renderer_host/media/media_stream_requester.h" | 20 #include "content/browser/renderer_host/media/media_stream_requester.h" |
| 21 #include "content/browser/renderer_host/media/media_stream_ui_proxy.h" | 21 #include "content/browser/renderer_host/media/media_stream_ui_proxy.h" |
| 22 #include "content/common/media/media_stream_options.h" | 22 #include "content/common/media/media_stream_options.h" |
| 23 #include "content/public/common/content_switches.h" | 23 #include "content/public/common/content_switches.h" |
| 24 #include "content/public/test/test_browser_thread_bundle.h" | 24 #include "content/public/test/test_browser_thread_bundle.h" |
| 25 #include "media/audio/audio_device_description.h" | 25 #include "media/audio/audio_device_description.h" |
| 26 #include "media/audio/audio_system_impl.h" | 26 #include "media/audio/audio_system_impl.h" |
| 27 #include "media/audio/fake_audio_log_factory.h" | 27 #include "media/audio/fake_audio_log_factory.h" |
| 28 #include "media/audio/test_audio_thread.h" |
| 28 #include "media/base/media_switches.h" | 29 #include "media/base/media_switches.h" |
| 29 #include "testing/gmock/include/gmock/gmock.h" | 30 #include "testing/gmock/include/gmock/gmock.h" |
| 30 #include "testing/gtest/include/gtest/gtest.h" | 31 #include "testing/gtest/include/gtest/gtest.h" |
| 31 #include "url/gurl.h" | 32 #include "url/gurl.h" |
| 32 #include "url/origin.h" | 33 #include "url/origin.h" |
| 33 | 34 |
| 34 #if defined(USE_ALSA) | 35 #if defined(USE_ALSA) |
| 35 #include "media/audio/alsa/audio_manager_alsa.h" | 36 #include "media/audio/alsa/audio_manager_alsa.h" |
| 36 #elif defined(OS_ANDROID) | 37 #elif defined(OS_ANDROID) |
| 37 #include "media/audio/android/audio_manager_android.h" | 38 #include "media/audio/android/audio_manager_android.h" |
| (...skipping 23 matching lines...) Expand all Loading... |
| 61 | 62 |
| 62 namespace { | 63 namespace { |
| 63 | 64 |
| 64 const char kMockSalt[] = ""; | 65 const char kMockSalt[] = ""; |
| 65 | 66 |
| 66 // This class mocks the audio manager and overrides some methods to ensure that | 67 // This class mocks the audio manager and overrides some methods to ensure that |
| 67 // we can run our tests on the buildbots. | 68 // we can run our tests on the buildbots. |
| 68 class MockAudioManager : public AudioManagerPlatform { | 69 class MockAudioManager : public AudioManagerPlatform { |
| 69 public: | 70 public: |
| 70 MockAudioManager() | 71 MockAudioManager() |
| 71 : AudioManagerPlatform(base::ThreadTaskRunnerHandle::Get(), | 72 : AudioManagerPlatform(base::MakeUnique<media::TestAudioThread>(), |
| 72 base::ThreadTaskRunnerHandle::Get(), | |
| 73 &fake_audio_log_factory_), | 73 &fake_audio_log_factory_), |
| 74 num_output_devices_(2), | 74 num_output_devices_(2), |
| 75 num_input_devices_(2) {} | 75 num_input_devices_(2) {} |
| 76 ~MockAudioManager() override {} | 76 ~MockAudioManager() override {} |
| 77 | 77 |
| 78 void GetAudioInputDeviceNames( | 78 void GetAudioInputDeviceNames( |
| 79 media::AudioDeviceNames* device_names) override { | 79 media::AudioDeviceNames* device_names) override { |
| 80 DCHECK(device_names->empty()); | 80 DCHECK(device_names->empty()); |
| 81 | 81 |
| 82 // AudioManagers add a default device when there is at least one real device | 82 // AudioManagers add a default device when there is at least one real device |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 166 public: | 166 public: |
| 167 MediaStreamManagerTest() | 167 MediaStreamManagerTest() |
| 168 : thread_bundle_(content::TestBrowserThreadBundle::IO_MAINLOOP) { | 168 : thread_bundle_(content::TestBrowserThreadBundle::IO_MAINLOOP) { |
| 169 audio_manager_.reset(new MockAudioManager()); | 169 audio_manager_.reset(new MockAudioManager()); |
| 170 audio_system_ = media::AudioSystemImpl::Create(audio_manager_.get()); | 170 audio_system_ = media::AudioSystemImpl::Create(audio_manager_.get()); |
| 171 media_stream_manager_ = | 171 media_stream_manager_ = |
| 172 base::MakeUnique<MediaStreamManager>(audio_system_.get()); | 172 base::MakeUnique<MediaStreamManager>(audio_system_.get()); |
| 173 base::RunLoop().RunUntilIdle(); | 173 base::RunLoop().RunUntilIdle(); |
| 174 } | 174 } |
| 175 | 175 |
| 176 ~MediaStreamManagerTest() override {} | 176 ~MediaStreamManagerTest() override { audio_manager_->Shutdown(); } |
| 177 | 177 |
| 178 MOCK_METHOD1(Response, void(int index)); | 178 MOCK_METHOD1(Response, void(int index)); |
| 179 void ResponseCallback(int index, | 179 void ResponseCallback(int index, |
| 180 const MediaStreamDevices& devices, | 180 const MediaStreamDevices& devices, |
| 181 std::unique_ptr<MediaStreamUIProxy> ui_proxy) { | 181 std::unique_ptr<MediaStreamUIProxy> ui_proxy) { |
| 182 Response(index); | 182 Response(index); |
| 183 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, | 183 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, |
| 184 run_loop_.QuitClosure()); | 184 run_loop_.QuitClosure()); |
| 185 } | 185 } |
| 186 | 186 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 197 return media_stream_manager_->MakeMediaAccessRequest( | 197 return media_stream_manager_->MakeMediaAccessRequest( |
| 198 render_process_id, render_frame_id, page_request_id, controls, | 198 render_process_id, render_frame_id, page_request_id, controls, |
| 199 security_origin, callback); | 199 security_origin, callback); |
| 200 } | 200 } |
| 201 | 201 |
| 202 // media_stream_manager_ needs to outlive thread_bundle_ because it is a | 202 // media_stream_manager_ needs to outlive thread_bundle_ because it is a |
| 203 // MessageLoop::DestructionObserver. audio_manager_ needs to outlive | 203 // MessageLoop::DestructionObserver. audio_manager_ needs to outlive |
| 204 // thread_bundle_ because it uses the underlying message loop. | 204 // thread_bundle_ because it uses the underlying message loop. |
| 205 std::unique_ptr<MediaStreamManager> media_stream_manager_; | 205 std::unique_ptr<MediaStreamManager> media_stream_manager_; |
| 206 content::TestBrowserThreadBundle thread_bundle_; | 206 content::TestBrowserThreadBundle thread_bundle_; |
| 207 std::unique_ptr<MockAudioManager, media::AudioManagerDeleter> audio_manager_; | 207 std::unique_ptr<MockAudioManager> audio_manager_; |
| 208 std::unique_ptr<media::AudioSystem> audio_system_; | 208 std::unique_ptr<media::AudioSystem> audio_system_; |
| 209 base::RunLoop run_loop_; | 209 base::RunLoop run_loop_; |
| 210 | 210 |
| 211 private: | 211 private: |
| 212 DISALLOW_COPY_AND_ASSIGN(MediaStreamManagerTest); | 212 DISALLOW_COPY_AND_ASSIGN(MediaStreamManagerTest); |
| 213 }; | 213 }; |
| 214 | 214 |
| 215 TEST_F(MediaStreamManagerTest, MakeMediaAccessRequest) { | 215 TEST_F(MediaStreamManagerTest, MakeMediaAccessRequest) { |
| 216 MakeMediaAccessRequest(0); | 216 MakeMediaAccessRequest(0); |
| 217 | 217 |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 290 unique_other_id); | 290 unique_other_id); |
| 291 EXPECT_TRUE(MediaStreamManager::DoesMediaDeviceIDMatchHMAC( | 291 EXPECT_TRUE(MediaStreamManager::DoesMediaDeviceIDMatchHMAC( |
| 292 kMockSalt, security_origin, hashed_other_id, unique_other_id)); | 292 kMockSalt, security_origin, hashed_other_id, unique_other_id)); |
| 293 EXPECT_NE(unique_other_id, hashed_other_id); | 293 EXPECT_NE(unique_other_id, hashed_other_id); |
| 294 EXPECT_EQ(hashed_other_id.size(), 64U); | 294 EXPECT_EQ(hashed_other_id.size(), 64U); |
| 295 for (const char& c : hashed_other_id) | 295 for (const char& c : hashed_other_id) |
| 296 EXPECT_TRUE(base::IsAsciiDigit(c) || (c >= 'a' && c <= 'f')); | 296 EXPECT_TRUE(base::IsAsciiDigit(c) || (c >= 'a' && c <= 'f')); |
| 297 } | 297 } |
| 298 | 298 |
| 299 } // namespace content | 299 } // namespace content |
| OLD | NEW |