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

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

Issue 2238083004: Video Capture Mojo (1.4b): Implement ability to use fake device instance (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@FillServicePart1
Patch Set: Fix control reached end of non-void function. Created 4 years, 3 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
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "base/memory/ref_counted.h"
6 #include "base/run_loop.h"
7 #include "services/shell/public/cpp/service_test.h"
8 #include "services/video_capture/public/interfaces/video_capture_device_factory. mojom.h"
9 #include "services/video_capture/public/interfaces/video_capture_service.mojom.h "
10 #include "testing/gmock/include/gmock/gmock.h"
11
12 using testing::Exactly;
13 using testing::_;
14 using testing::Invoke;
15 using testing::InvokeWithoutArgs;
16
17 namespace video_capture {
18
19 class MockDeviceDescriptorReceiver {
20 public:
21 // Use forwarding method to work around gmock not supporting move-only types.
22 void HandleEnumerateDeviceDescriptorsCallback(
23 std::vector<mojom::VideoCaptureDeviceDescriptorPtr> descriptors) {
24 OnEnumerateDeviceDescriptorsCallback(descriptors);
25 }
26
27 MOCK_METHOD1(
28 OnEnumerateDeviceDescriptorsCallback,
29 void(const std::vector<mojom::VideoCaptureDeviceDescriptorPtr>&));
30 };
31
32 class VideoCaptureServiceTest : public shell::test::ServiceTest {
33 public:
34 VideoCaptureServiceTest()
35 : shell::test::ServiceTest("exe:video_capture_unittests") {}
36 ~VideoCaptureServiceTest() override {}
37
38 void SetUp() override {
39 ServiceTest::SetUp();
40 connector()->ConnectToInterface("mojo:video_capture", &service_);
41 service_->ConnectToFakeDeviceFactory(mojo::GetProxy(&factory_));
42 }
43
44 protected:
45 mojom::VideoCaptureServicePtr service_;
46 mojom::VideoCaptureDeviceFactoryPtr factory_;
47 MockDeviceDescriptorReceiver descriptor_receiver_;
48 };
49
50 // Tests that an answer arrives from the service when calling
51 // EnumerateDeviceDescriptors().
52 TEST_F(VideoCaptureServiceTest, EnumerateDeviceDescriptorsCallbackArrives) {
53 base::RunLoop wait_loop;
54 EXPECT_CALL(descriptor_receiver_, OnEnumerateDeviceDescriptorsCallback(_))
55 .Times(Exactly(1))
56 .WillOnce(InvokeWithoutArgs([&wait_loop]() { wait_loop.Quit(); }));
57
58 factory_->EnumerateDeviceDescriptors(base::Bind(
59 &MockDeviceDescriptorReceiver::HandleEnumerateDeviceDescriptorsCallback,
60 base::Unretained(&descriptor_receiver_)));
61 wait_loop.Run();
62 }
63
64 TEST_F(VideoCaptureServiceTest, FakeDeviceFactoryEnumeratesOneDevice) {
65 base::RunLoop wait_loop;
66 size_t num_devices_enumerated = 0;
67 EXPECT_CALL(descriptor_receiver_, OnEnumerateDeviceDescriptorsCallback(_))
68 .Times(Exactly(1))
69 .WillOnce(Invoke([&wait_loop, &num_devices_enumerated](
70 const std::vector<mojom::VideoCaptureDeviceDescriptorPtr>&
71 descriptors) {
72 num_devices_enumerated = descriptors.size();
73 wait_loop.Quit();
74 }));
75
76 factory_->EnumerateDeviceDescriptors(base::Bind(
77 &MockDeviceDescriptorReceiver::HandleEnumerateDeviceDescriptorsCallback,
78 base::Unretained(&descriptor_receiver_)));
79 wait_loop.Run();
80 ASSERT_EQ(1u, num_devices_enumerated);
81 }
82
83 } // namespace video_capture
OLDNEW
« no previous file with comments | « services/video_capture/mock_video_capture_device_client.cc ('k') | services/video_capture/video_capture_device_factory_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698