| 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/thread_task_runner_handle.h" | 16 #include "base/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/fake_audio_log_factory.h" | 26 #include "media/audio/fake_audio_log_factory.h" |
| 27 #include "media/base/media_switches.h" | 27 #include "media/base/media_switches.h" |
| 28 #include "testing/gmock/include/gmock/gmock.h" | 28 #include "testing/gmock/include/gmock/gmock.h" |
| 29 #include "testing/gtest/include/gtest/gtest.h" | 29 #include "testing/gtest/include/gtest/gtest.h" |
| 30 #include "url/gurl.h" |
| 31 #include "url/origin.h" |
| 30 | 32 |
| 31 #if defined(USE_ALSA) | 33 #if defined(USE_ALSA) |
| 32 #include "media/audio/alsa/audio_manager_alsa.h" | 34 #include "media/audio/alsa/audio_manager_alsa.h" |
| 33 #elif defined(OS_ANDROID) | 35 #elif defined(OS_ANDROID) |
| 34 #include "media/audio/android/audio_manager_android.h" | 36 #include "media/audio/android/audio_manager_android.h" |
| 35 #elif defined(OS_MACOSX) | 37 #elif defined(OS_MACOSX) |
| 36 #include "media/audio/mac/audio_manager_mac.h" | 38 #include "media/audio/mac/audio_manager_mac.h" |
| 37 #elif defined(OS_WIN) | 39 #elif defined(OS_WIN) |
| 38 #include "media/audio/win/audio_manager_win.h" | 40 #include "media/audio/win/audio_manager_win.h" |
| 39 #else | 41 #else |
| (...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 229 Response(index); | 231 Response(index); |
| 230 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, | 232 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, |
| 231 run_loop_.QuitClosure()); | 233 run_loop_.QuitClosure()); |
| 232 } | 234 } |
| 233 | 235 |
| 234 protected: | 236 protected: |
| 235 std::string MakeMediaAccessRequest(int index) { | 237 std::string MakeMediaAccessRequest(int index) { |
| 236 const int render_process_id = 1; | 238 const int render_process_id = 1; |
| 237 const int render_frame_id = 1; | 239 const int render_frame_id = 1; |
| 238 const int page_request_id = 1; | 240 const int page_request_id = 1; |
| 239 const GURL security_origin; | 241 const url::Origin security_origin; |
| 240 MediaStreamManager::MediaRequestResponseCallback callback = | 242 MediaStreamManager::MediaRequestResponseCallback callback = |
| 241 base::Bind(&MediaStreamManagerTest::ResponseCallback, | 243 base::Bind(&MediaStreamManagerTest::ResponseCallback, |
| 242 base::Unretained(this), index); | 244 base::Unretained(this), index); |
| 243 StreamControls controls(true, true); | 245 StreamControls controls(true, true); |
| 244 return media_stream_manager_->MakeMediaAccessRequest( | 246 return media_stream_manager_->MakeMediaAccessRequest( |
| 245 render_process_id, render_frame_id, page_request_id, controls, | 247 render_process_id, render_frame_id, page_request_id, controls, |
| 246 security_origin, callback); | 248 security_origin, callback); |
| 247 } | 249 } |
| 248 | 250 |
| 249 // media_stream_manager_ needs to outlive thread_bundle_ because it is a | 251 // media_stream_manager_ needs to outlive thread_bundle_ because it is a |
| (...skipping 24 matching lines...) Expand all Loading... |
| 274 } | 276 } |
| 275 | 277 |
| 276 TEST_F(MediaStreamManagerTest, MakeMultipleRequests) { | 278 TEST_F(MediaStreamManagerTest, MakeMultipleRequests) { |
| 277 // First request. | 279 // First request. |
| 278 std::string label1 = MakeMediaAccessRequest(0); | 280 std::string label1 = MakeMediaAccessRequest(0); |
| 279 | 281 |
| 280 // Second request. | 282 // Second request. |
| 281 int render_process_id = 2; | 283 int render_process_id = 2; |
| 282 int render_frame_id = 2; | 284 int render_frame_id = 2; |
| 283 int page_request_id = 2; | 285 int page_request_id = 2; |
| 284 GURL security_origin; | 286 url::Origin security_origin; |
| 285 StreamControls controls(true, true); | 287 StreamControls controls(true, true); |
| 286 MediaStreamManager::MediaRequestResponseCallback callback = | 288 MediaStreamManager::MediaRequestResponseCallback callback = |
| 287 base::Bind(&MediaStreamManagerTest::ResponseCallback, | 289 base::Bind(&MediaStreamManagerTest::ResponseCallback, |
| 288 base::Unretained(this), 1); | 290 base::Unretained(this), 1); |
| 289 std::string label2 = media_stream_manager_->MakeMediaAccessRequest( | 291 std::string label2 = media_stream_manager_->MakeMediaAccessRequest( |
| 290 render_process_id, render_frame_id, page_request_id, controls, | 292 render_process_id, render_frame_id, page_request_id, controls, |
| 291 security_origin, callback); | 293 security_origin, callback); |
| 292 | 294 |
| 293 // Expecting the callbackS from requests will be triggered and quit the test. | 295 // Expecting the callbackS from requests will be triggered and quit the test. |
| 294 // Note, the callbacks might come in a different order depending on the | 296 // Note, the callbacks might come in a different order depending on the |
| 295 // value of labels. | 297 // value of labels. |
| 296 EXPECT_CALL(*this, Response(0)); | 298 EXPECT_CALL(*this, Response(0)); |
| 297 EXPECT_CALL(*this, Response(1)); | 299 EXPECT_CALL(*this, Response(1)); |
| 298 run_loop_.Run(); | 300 run_loop_.Run(); |
| 299 } | 301 } |
| 300 | 302 |
| 301 TEST_F(MediaStreamManagerTest, MakeAndCancelMultipleRequests) { | 303 TEST_F(MediaStreamManagerTest, MakeAndCancelMultipleRequests) { |
| 302 std::string label1 = MakeMediaAccessRequest(0); | 304 std::string label1 = MakeMediaAccessRequest(0); |
| 303 std::string label2 = MakeMediaAccessRequest(1); | 305 std::string label2 = MakeMediaAccessRequest(1); |
| 304 media_stream_manager_->CancelRequest(label1); | 306 media_stream_manager_->CancelRequest(label1); |
| 305 | 307 |
| 306 // Expecting the callback from the second request will be triggered and | 308 // Expecting the callback from the second request will be triggered and |
| 307 // quit the test. | 309 // quit the test. |
| 308 EXPECT_CALL(*this, Response(1)); | 310 EXPECT_CALL(*this, Response(1)); |
| 309 run_loop_.Run(); | 311 run_loop_.Run(); |
| 310 } | 312 } |
| 311 | 313 |
| 312 TEST_F(MediaStreamManagerTest, DeviceID) { | 314 TEST_F(MediaStreamManagerTest, DeviceID) { |
| 313 GURL security_origin("http://localhost"); | 315 url::Origin security_origin(GURL("http://localhost")); |
| 314 const std::string unique_default_id( | 316 const std::string unique_default_id( |
| 315 media::AudioDeviceDescription::kDefaultDeviceId); | 317 media::AudioDeviceDescription::kDefaultDeviceId); |
| 316 const std::string hashed_default_id = | 318 const std::string hashed_default_id = |
| 317 MediaStreamManager::GetHMACForMediaDeviceID( | 319 MediaStreamManager::GetHMACForMediaDeviceID( |
| 318 GetMockSaltCallback(), security_origin, unique_default_id); | 320 GetMockSaltCallback(), security_origin, unique_default_id); |
| 319 EXPECT_TRUE(MediaStreamManager::DoesMediaDeviceIDMatchHMAC( | 321 EXPECT_TRUE(MediaStreamManager::DoesMediaDeviceIDMatchHMAC( |
| 320 GetMockSaltCallback(), security_origin, hashed_default_id, | 322 GetMockSaltCallback(), security_origin, hashed_default_id, |
| 321 unique_default_id)); | 323 unique_default_id)); |
| 322 EXPECT_EQ(unique_default_id, hashed_default_id); | 324 EXPECT_EQ(unique_default_id, hashed_default_id); |
| 323 | 325 |
| (...skipping 23 matching lines...) Expand all Loading... |
| 347 TEST_F(MediaStreamManagerTest, EnumerationOutputDevices) { | 349 TEST_F(MediaStreamManagerTest, EnumerationOutputDevices) { |
| 348 for (size_t num_devices = 0; num_devices < 3; num_devices++) { | 350 for (size_t num_devices = 0; num_devices < 3; num_devices++) { |
| 349 audio_manager_->SetNumAudioOutputDevices(num_devices); | 351 audio_manager_->SetNumAudioOutputDevices(num_devices); |
| 350 base::RunLoop run_loop; | 352 base::RunLoop run_loop; |
| 351 MockMediaStreamRequester requester(media_stream_manager_.get(), &run_loop, | 353 MockMediaStreamRequester requester(media_stream_manager_.get(), &run_loop, |
| 352 num_devices == 0 ? 0 : num_devices + 1, | 354 num_devices == 0 ? 0 : num_devices + 1, |
| 353 nullptr); | 355 nullptr); |
| 354 const int render_process_id = 1; | 356 const int render_process_id = 1; |
| 355 const int render_frame_id = 1; | 357 const int render_frame_id = 1; |
| 356 const int page_request_id = 1; | 358 const int page_request_id = 1; |
| 357 const GURL security_origin("http://localhost"); | 359 const url::Origin security_origin(GURL("http://localhost")); |
| 358 EXPECT_CALL(requester, | 360 EXPECT_CALL(requester, |
| 359 MockDevicesEnumerated(render_frame_id, page_request_id, _, _)); | 361 MockDevicesEnumerated(render_frame_id, page_request_id, _, _)); |
| 360 std::string label = media_stream_manager_->EnumerateDevices( | 362 std::string label = media_stream_manager_->EnumerateDevices( |
| 361 &requester, render_process_id, render_frame_id, GetMockSaltCallback(), | 363 &requester, render_process_id, render_frame_id, GetMockSaltCallback(), |
| 362 page_request_id, MEDIA_DEVICE_AUDIO_OUTPUT, security_origin); | 364 page_request_id, MEDIA_DEVICE_AUDIO_OUTPUT, security_origin); |
| 363 run_loop.Run(); | 365 run_loop.Run(); |
| 364 // CancelRequest is necessary for enumeration requests. | 366 // CancelRequest is necessary for enumeration requests. |
| 365 media_stream_manager_->CancelRequest(label); | 367 media_stream_manager_->CancelRequest(label); |
| 366 } | 368 } |
| 367 } | 369 } |
| 368 | 370 |
| 369 TEST_F(MediaStreamManagerTest, NotifyDeviceChanges) { | 371 TEST_F(MediaStreamManagerTest, NotifyDeviceChanges) { |
| 370 const int render_process_id = 1; | 372 const int render_process_id = 1; |
| 371 const int render_frame_id = 1; | 373 const int render_frame_id = 1; |
| 372 const int page_request_id = 1; | 374 const int page_request_id = 1; |
| 373 const GURL security_origin("http://localhost"); | 375 const url::Origin security_origin(GURL("http://localhost")); |
| 374 | 376 |
| 375 // Check that device change notifications are received | 377 // Check that device change notifications are received |
| 376 { | 378 { |
| 377 // First run an enumeration to warm up the cache | 379 // First run an enumeration to warm up the cache |
| 378 base::RunLoop run_loop_enumeration; | 380 base::RunLoop run_loop_enumeration; |
| 379 base::RunLoop run_loop_device_change; | 381 base::RunLoop run_loop_device_change; |
| 380 MockMediaStreamRequester requester(media_stream_manager_.get(), | 382 MockMediaStreamRequester requester(media_stream_manager_.get(), |
| 381 &run_loop_enumeration, 3, | 383 &run_loop_enumeration, 3, |
| 382 &run_loop_device_change); | 384 &run_loop_device_change); |
| 383 audio_manager_->SetNumAudioInputDevices(2); | 385 audio_manager_->SetNumAudioInputDevices(2); |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 419 MockDevicesEnumerated(render_frame_id, page_request_id, _, _)); | 421 MockDevicesEnumerated(render_frame_id, page_request_id, _, _)); |
| 420 std::string label = media_stream_manager_->EnumerateDevices( | 422 std::string label = media_stream_manager_->EnumerateDevices( |
| 421 &requester, render_process_id, render_frame_id, GetMockSaltCallback(), | 423 &requester, render_process_id, render_frame_id, GetMockSaltCallback(), |
| 422 page_request_id, MEDIA_DEVICE_AUDIO_CAPTURE, security_origin); | 424 page_request_id, MEDIA_DEVICE_AUDIO_CAPTURE, security_origin); |
| 423 run_loop.Run(); | 425 run_loop.Run(); |
| 424 media_stream_manager_->CancelRequest(label); | 426 media_stream_manager_->CancelRequest(label); |
| 425 } | 427 } |
| 426 } | 428 } |
| 427 | 429 |
| 428 } // namespace content | 430 } // namespace content |
| OLD | NEW |