Index: services/video_capture/service_unittest.cc |
diff --git a/services/video_capture/service_unittest.cc b/services/video_capture/service_unittest.cc |
index 3a4ab972dbc53247f7c2cb645b6bb02d8dd7f814..592a8c070cfc342c980aca409cc70a5774ceec4c 100644 |
--- a/services/video_capture/service_unittest.cc |
+++ b/services/video_capture/service_unittest.cc |
@@ -5,19 +5,19 @@ |
#include "base/memory/ref_counted.h" |
#include "base/run_loop.h" |
#include "services/shell/public/cpp/service_test.h" |
+#include "services/video_capture/public/interfaces/service_configurator.mojom.h" |
+#include "services/video_capture/public/interfaces/video_capture_device_access.mojom.h" |
#include "services/video_capture/public/interfaces/video_capture_device_factory.mojom.h" |
#include "testing/gmock/include/gmock/gmock.h" |
using testing::Exactly; |
using testing::_; |
+using testing::Invoke; |
+using testing::InvokeWithoutArgs; |
namespace video_capture { |
-ACTION_P(RunClosure, closure) { |
- closure.Run(); |
-} |
- |
-class MockClient { |
+class MockDeviceDescriptorReceiver { |
public: |
// Use forwarding method to work around gmock not supporting move-only types. |
void HandleEnumerateDeviceDescriptorsCallback( |
@@ -30,6 +30,14 @@ class MockClient { |
descriptors)); |
}; |
+void HandleAddFakeVideoCaptureDeviceCallback( |
+ base::RunLoop* loop, |
+ mojom::VideoCaptureDeviceDescriptorPtr* out_descriptor, |
+ mojom::VideoCaptureDeviceDescriptorPtr in_descriptor) { |
+ *out_descriptor = std::move(in_descriptor); |
+ loop->Quit(); |
+} |
+ |
class VideoCaptureServiceTest : public shell::test::ServiceTest { |
public: |
VideoCaptureServiceTest() |
@@ -38,24 +46,61 @@ class VideoCaptureServiceTest : public shell::test::ServiceTest { |
void SetUp() override { |
ServiceTest::SetUp(); |
+ connector()->ConnectToInterface("mojo:video_capture", &configurator_); |
connector()->ConnectToInterface("mojo:video_capture", &factory_); |
} |
protected: |
+ mojom::VideoCaptureDeviceDescriptorPtr AddFakeCaptureDevice() { |
+ mojom::VideoCaptureDeviceDescriptorPtr fake_device_descriptor; |
+ base::RunLoop wait_loop; |
+ configurator_->AddFakeVideoCaptureDevice( |
+ base::Bind(HandleAddFakeVideoCaptureDeviceCallback, &wait_loop, |
+ &fake_device_descriptor)); |
+ wait_loop.Run(); |
+ return fake_device_descriptor; |
+ } |
+ |
+ mojom::ServiceConfiguratorPtr configurator_; |
mojom::VideoCaptureDeviceFactoryPtr factory_; |
- MockClient client_; |
+ MockDeviceDescriptorReceiver descriptor_receiver_; |
}; |
TEST_F(VideoCaptureServiceTest, EnumerateDeviceDescriptorsCallbackArrives) { |
base::RunLoop wait_loop; |
- EXPECT_CALL(client_, OnEnumerateDeviceDescriptorsCallback(_)) |
+ EXPECT_CALL(descriptor_receiver_, OnEnumerateDeviceDescriptorsCallback(_)) |
+ .Times(Exactly(1)) |
+ .WillOnce(InvokeWithoutArgs([&wait_loop]() { wait_loop.Quit(); })); |
+ |
+ factory_->EnumerateDeviceDescriptors(base::Bind( |
+ &MockDeviceDescriptorReceiver::HandleEnumerateDeviceDescriptorsCallback, |
+ base::Unretained(&descriptor_receiver_))); |
+ wait_loop.Run(); |
+} |
+ |
+TEST_F(VideoCaptureServiceTest, FakeCaptureDeviceGetsEnumerated) { |
+ auto fake_device_descriptor = AddFakeCaptureDevice(); |
+ |
+ base::RunLoop wait_loop; |
+ EXPECT_CALL(descriptor_receiver_, OnEnumerateDeviceDescriptorsCallback(_)) |
.Times(Exactly(1)) |
- .WillOnce(RunClosure(wait_loop.QuitClosure())); |
- ; |
+ .WillOnce(Invoke([&fake_device_descriptor, &wait_loop]( |
+ const std::vector<mojom::VideoCaptureDeviceDescriptorPtr>& |
+ descriptors) { |
+ bool fake_device_found = false; |
+ for (const auto& descriptor : descriptors) { |
+ if (descriptor->device_id == fake_device_descriptor->device_id) { |
+ fake_device_found = true; |
+ break; |
+ } |
+ } |
+ ASSERT_TRUE(fake_device_found); |
+ wait_loop.Quit(); |
+ })); |
- factory_->EnumerateDeviceDescriptors( |
- base::Bind(&MockClient::HandleEnumerateDeviceDescriptorsCallback, |
- base::Unretained(&client_))); |
+ factory_->EnumerateDeviceDescriptors(base::Bind( |
+ &MockDeviceDescriptorReceiver::HandleEnumerateDeviceDescriptorsCallback, |
+ base::Unretained(&descriptor_receiver_))); |
wait_loop.Run(); |
} |