Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(88)

Side by Side Diff: services/video_capture/service_unittest.cc

Issue 2244763002: Video Capture Mojo (1.4a.a): Add service configurator interface (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@MakeService
Patch Set: Split out rename to separate CL Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 "base/memory/ref_counted.h" 5 #include "base/memory/ref_counted.h"
6 #include "base/run_loop.h" 6 #include "base/run_loop.h"
7 #include "services/shell/public/cpp/service_test.h" 7 #include "services/shell/public/cpp/service_test.h"
8 #include "services/video_capture/public/interfaces/fake_video_capture_device_fac tory_configurator.mojom.h"
8 #include "services/video_capture/public/interfaces/video_capture_device_factory. mojom.h" 9 #include "services/video_capture/public/interfaces/video_capture_device_factory. mojom.h"
10 #include "services/video_capture/public/interfaces/video_capture_device_factory. mojom.h"
11 #include "services/video_capture/public/interfaces/video_capture_service.mojom.h "
9 #include "testing/gmock/include/gmock/gmock.h" 12 #include "testing/gmock/include/gmock/gmock.h"
10 13
11 using testing::Exactly; 14 using testing::Exactly;
12 using testing::_; 15 using testing::_;
16 using testing::Invoke;
17 using testing::InvokeWithoutArgs;
13 18
14 namespace video_capture { 19 namespace video_capture {
15 20
16 ACTION_P(RunClosure, closure) { 21 class MockDeviceDescriptorReceiver {
17 closure.Run();
18 }
19
20 class MockClient {
21 public: 22 public:
22 // Use forwarding method to work around gmock not supporting move-only types. 23 // Use forwarding method to work around gmock not supporting move-only types.
23 void HandleEnumerateDeviceDescriptorsCallback( 24 void HandleEnumerateDeviceDescriptorsCallback(
24 std::vector<mojom::VideoCaptureDeviceDescriptorPtr> descriptors) { 25 std::vector<mojom::VideoCaptureDeviceDescriptorPtr> descriptors) {
25 OnEnumerateDeviceDescriptorsCallback(descriptors); 26 OnEnumerateDeviceDescriptorsCallback(descriptors);
26 } 27 }
27 28
28 MOCK_METHOD1( 29 MOCK_METHOD1(
29 OnEnumerateDeviceDescriptorsCallback, 30 OnEnumerateDeviceDescriptorsCallback,
30 void(const std::vector<mojom::VideoCaptureDeviceDescriptorPtr>&)); 31 void(const std::vector<mojom::VideoCaptureDeviceDescriptorPtr>&));
31 }; 32 };
32 33
34 void HandleAddFakeVideoCaptureDeviceCallback(
35 base::RunLoop* loop,
36 mojom::VideoCaptureDeviceDescriptorPtr* out_descriptor,
37 mojom::VideoCaptureDeviceDescriptorPtr in_descriptor) {
38 *out_descriptor = std::move(in_descriptor);
39 loop->Quit();
40 }
41
33 class VideoCaptureServiceTest : public shell::test::ServiceTest { 42 class VideoCaptureServiceTest : public shell::test::ServiceTest {
34 public: 43 public:
35 VideoCaptureServiceTest() 44 VideoCaptureServiceTest()
36 : shell::test::ServiceTest("exe:video_capture_unittests") {} 45 : shell::test::ServiceTest("exe:video_capture_unittests") {}
37 ~VideoCaptureServiceTest() override {} 46 ~VideoCaptureServiceTest() override {}
38 47
39 void SetUp() override { 48 void SetUp() override {
40 ServiceTest::SetUp(); 49 ServiceTest::SetUp();
41 connector()->ConnectToInterface("mojo:video_capture", &factory_); 50 connector()->ConnectToInterface("mojo:video_capture", &service_);
51 service_->ConnectToFakeDeviceFactory(mojo::GetProxy(&factory_));
52 service_->ConnectToFakeDeviceFactoryConfigurator(
53 mojo::GetProxy(&configurator_));
42 } 54 }
43 55
44 protected: 56 protected:
57 mojom::VideoCaptureDeviceDescriptorPtr AddFakeCaptureDevice() {
58 mojom::VideoCaptureDeviceDescriptorPtr fake_device_descriptor;
59 base::RunLoop wait_loop;
60 configurator_->AddFakeVideoCaptureDevice(
61 base::Bind(HandleAddFakeVideoCaptureDeviceCallback, &wait_loop,
62 &fake_device_descriptor));
63 wait_loop.Run();
64 return fake_device_descriptor;
65 }
66
67 mojom::VideoCaptureServicePtr service_;
68 mojom::FakeVideoCaptureDeviceFactoryConfiguratorPtr configurator_;
45 mojom::VideoCaptureDeviceFactoryPtr factory_; 69 mojom::VideoCaptureDeviceFactoryPtr factory_;
46 MockClient client_; 70 MockDeviceDescriptorReceiver descriptor_receiver_;
47 }; 71 };
48 72
49 // Tests that an answer arrives from the service when calling 73 // Tests that an answer arrives from the service when calling
50 // EnumerateDeviceDescriptors(). 74 // EnumerateDeviceDescriptors().
51 TEST_F(VideoCaptureServiceTest, EnumerateDeviceDescriptorsCallbackArrives) { 75 TEST_F(VideoCaptureServiceTest, EnumerateDeviceDescriptorsCallbackArrives) {
52 base::RunLoop wait_loop; 76 base::RunLoop wait_loop;
53 EXPECT_CALL(client_, OnEnumerateDeviceDescriptorsCallback(_)) 77 EXPECT_CALL(descriptor_receiver_, OnEnumerateDeviceDescriptorsCallback(_))
54 .Times(Exactly(1)) 78 .Times(Exactly(1))
55 .WillOnce(RunClosure(wait_loop.QuitClosure())); 79 .WillOnce(InvokeWithoutArgs([&wait_loop]() { wait_loop.Quit(); }));
80 ;
56 81
57 factory_->EnumerateDeviceDescriptors( 82 factory_->EnumerateDeviceDescriptors(base::Bind(
58 base::Bind(&MockClient::HandleEnumerateDeviceDescriptorsCallback, 83 &MockDeviceDescriptorReceiver::HandleEnumerateDeviceDescriptorsCallback,
59 base::Unretained(&client_))); 84 base::Unretained(&descriptor_receiver_)));
60 wait_loop.Run(); 85 wait_loop.Run();
61 } 86 }
62 87
88 TEST_F(VideoCaptureServiceTest, FakeCaptureDeviceGetsEnumerated) {
89 auto fake_device_descriptor = AddFakeCaptureDevice();
90
91 base::RunLoop wait_loop;
92 EXPECT_CALL(descriptor_receiver_, OnEnumerateDeviceDescriptorsCallback(_))
93 .Times(Exactly(1))
94 .WillOnce(Invoke([&fake_device_descriptor, &wait_loop](
95 const std::vector<mojom::VideoCaptureDeviceDescriptorPtr>&
96 descriptors) {
97 bool fake_device_found = false;
98 for (const auto& descriptor : descriptors) {
99 if (descriptor->device_id == fake_device_descriptor->device_id) {
100 fake_device_found = true;
101 break;
102 }
103 }
104 ASSERT_TRUE(fake_device_found);
105 wait_loop.Quit();
106 }));
107
108 factory_->EnumerateDeviceDescriptors(base::Bind(
109 &MockDeviceDescriptorReceiver::HandleEnumerateDeviceDescriptorsCallback,
110 base::Unretained(&descriptor_receiver_)));
111 wait_loop.Run();
112 }
113
63 } // namespace video_capture 114 } // namespace video_capture
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698