OLD | NEW |
---|---|
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/media_devices_dispatcher_host.h" | 5 #include "content/browser/renderer_host/media/media_devices_dispatcher_host.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <memory> | 9 #include <memory> |
10 #include <queue> | 10 #include <queue> |
(...skipping 18 matching lines...) Expand all Loading... | |
29 #include "media/audio/mock_audio_manager.h" | 29 #include "media/audio/mock_audio_manager.h" |
30 #include "media/base/media_switches.h" | 30 #include "media/base/media_switches.h" |
31 #include "media/capture/video/fake_video_capture_device_factory.h" | 31 #include "media/capture/video/fake_video_capture_device_factory.h" |
32 #include "mojo/public/cpp/bindings/binding.h" | 32 #include "mojo/public/cpp/bindings/binding.h" |
33 #include "testing/gmock/include/gmock/gmock.h" | 33 #include "testing/gmock/include/gmock/gmock.h" |
34 #include "testing/gtest/include/gtest/gtest.h" | 34 #include "testing/gtest/include/gtest/gtest.h" |
35 #include "url/origin.h" | 35 #include "url/origin.h" |
36 | 36 |
37 using testing::_; | 37 using testing::_; |
38 using testing::SaveArg; | 38 using testing::SaveArg; |
39 using testing::InvokeWithoutArgs; | |
39 | 40 |
40 namespace content { | 41 namespace content { |
41 | 42 |
42 namespace { | 43 namespace { |
43 | 44 |
44 const int kProcessId = 5; | 45 const int kProcessId = 5; |
45 const int kRenderId = 6; | 46 const int kRenderId = 6; |
46 const size_t kNumFakeVideoDevices = 3; | 47 const size_t kNumFakeVideoDevices = 3; |
47 const char kDefaultVideoDeviceID[] = "/dev/video2"; | 48 const char kDefaultVideoDeviceID[] = "/dev/video2"; |
48 | 49 |
(...skipping 298 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
347 | 348 |
348 TEST_F(MediaDevicesDispatcherHostTest, EnumerateAllDevicesUniqueOrigin) { | 349 TEST_F(MediaDevicesDispatcherHostTest, EnumerateAllDevicesUniqueOrigin) { |
349 EXPECT_CALL(*this, UniqueOriginCallback(testing::_)).Times(0); | 350 EXPECT_CALL(*this, UniqueOriginCallback(testing::_)).Times(0); |
350 host_->EnumerateDevices( | 351 host_->EnumerateDevices( |
351 true, true, true, url::Origin(), | 352 true, true, true, url::Origin(), |
352 base::Bind(&MediaDevicesDispatcherHostTest::UniqueOriginCallback, | 353 base::Bind(&MediaDevicesDispatcherHostTest::UniqueOriginCallback, |
353 base::Unretained(this))); | 354 base::Unretained(this))); |
354 base::RunLoop().RunUntilIdle(); | 355 base::RunLoop().RunUntilIdle(); |
355 | 356 |
356 // Verify that the callback for a valid origin does get called. | 357 // Verify that the callback for a valid origin does get called. |
357 EXPECT_CALL(*this, ValidOriginCallback(testing::_)); | 358 base::RunLoop run_loop; |
359 EXPECT_CALL(*this, ValidOriginCallback(testing::_)) | |
360 .WillOnce(InvokeWithoutArgs([&run_loop]() { run_loop.Quit(); })); | |
gab
2017/04/06 17:09:09
Bind run_loop.QuitClosure() instead of this lambda
chfremer
2017/04/06 17:19:11
I prefer the lambda, because it works with the gmo
gab
2017/04/06 17:20:24
Hmmm that's unfortunate, but yeah okay.
| |
358 host_->EnumerateDevices( | 361 host_->EnumerateDevices( |
359 true, true, true, url::Origin(GURL("http://localhost")), | 362 true, true, true, url::Origin(GURL("http://localhost")), |
360 base::Bind(&MediaDevicesDispatcherHostTest::ValidOriginCallback, | 363 base::Bind(&MediaDevicesDispatcherHostTest::ValidOriginCallback, |
361 base::Unretained(this))); | 364 base::Unretained(this))); |
362 base::RunLoop().RunUntilIdle(); | 365 run_loop.Run(); |
363 #if defined(OS_WIN) | |
364 // On Windows, the underlying MediaStreamManager uses a separate thread for | |
365 // video capture which must be flushed to guarantee that the callback bound to | |
366 // EnumerateDevices above is invoked before the end of this test's body. | |
367 media_stream_manager_->FlushVideoCaptureThreadForTesting(); | |
368 base::RunLoop().RunUntilIdle(); | |
369 #endif | |
370 } | 366 } |
371 | 367 |
372 TEST_F(MediaDevicesDispatcherHostTest, GetVideoInputCapabilities) { | 368 TEST_F(MediaDevicesDispatcherHostTest, GetVideoInputCapabilities) { |
373 EXPECT_CALL(*this, MockVideoInputCapabilitiesCallback()); | 369 base::RunLoop run_loop; |
370 EXPECT_CALL(*this, MockVideoInputCapabilitiesCallback()) | |
371 .WillOnce(InvokeWithoutArgs([&run_loop]() { run_loop.Quit(); })); | |
374 host_->GetVideoInputCapabilities( | 372 host_->GetVideoInputCapabilities( |
375 origin_, | 373 origin_, |
376 base::Bind( | 374 base::Bind( |
377 &MediaDevicesDispatcherHostTest::VideoInputCapabilitiesCallback, | 375 &MediaDevicesDispatcherHostTest::VideoInputCapabilitiesCallback, |
378 base::Unretained(this))); | 376 base::Unretained(this))); |
379 base::RunLoop().RunUntilIdle(); | 377 run_loop.Run(); |
380 | |
381 #if defined(OS_WIN) | |
382 // On Windows, the underlying MediaStreamManager uses a separate thread for | |
383 // video capture which must be flushed to guarantee that the callback bound to | |
384 // GetVIdeoInputCapabilities above is invoked before the end of this test's | |
385 // body. | |
386 media_stream_manager_->FlushVideoCaptureThreadForTesting(); | |
387 base::RunLoop().RunUntilIdle(); | |
388 #endif | |
389 } | 378 } |
390 | 379 |
391 }; // namespace content | 380 }; // namespace content |
OLD | NEW |