OLD | NEW |
---|---|
(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 "testing/gmock/include/gmock/gmock.h" | |
10 | |
11 using testing::Exactly; | |
12 using testing::_; | |
13 | |
14 namespace video_capture { | |
15 | |
16 class MockClient : public base::RefCountedThreadSafe<MockClient> { | |
17 public: | |
18 void HandleEnumerateDeviceDescriptorsCallback( | |
19 base::RunLoop* loop, | |
20 std::vector<mojom::VideoCaptureDeviceDescriptorPtr> descriptors) { | |
21 OnEnumerateDeviceDescriptorsCallback(descriptors); | |
22 loop->Quit(); | |
23 } | |
24 | |
25 MOCK_METHOD1(OnEnumerateDeviceDescriptorsCallback, | |
26 void(const std::vector<mojom::VideoCaptureDeviceDescriptorPtr>& | |
27 descriptors)); | |
28 | |
29 private: | |
30 friend class base::RefCountedThreadSafe<MockClient>; | |
31 ~MockClient() {} | |
32 }; | |
33 | |
34 class VideoCaptureServiceTest : public shell::test::ServiceTest { | |
35 public: | |
36 VideoCaptureServiceTest() | |
37 : shell::test::ServiceTest("exe:video_capture_unittests") {} | |
38 ~VideoCaptureServiceTest() override {} | |
39 | |
40 void SetUp() override { | |
41 ServiceTest::SetUp(); | |
42 connector()->ConnectToInterface("mojo:video_capture", &factory_); | |
43 client_ = new MockClient(); | |
44 } | |
45 | |
46 protected: | |
47 mojom::VideoCaptureDeviceFactoryPtr factory_; | |
48 scoped_refptr<MockClient> client_; | |
mcasas
2016/08/10 15:50:54
In unittests we usually don't bother having this r
chfremer
2016/08/10 17:07:27
Done.
| |
49 }; | |
50 | |
51 TEST_F(VideoCaptureServiceTest, EnumerateDeviceDescriptorsCallbackArrives) { | |
52 EXPECT_CALL(*client_, OnEnumerateDeviceDescriptorsCallback(_)) | |
53 .Times(Exactly(1)); | |
54 | |
55 base::RunLoop wait_loop; | |
56 factory_->EnumerateDeviceDescriptors( | |
57 base::Bind(&MockClient::HandleEnumerateDeviceDescriptorsCallback, client_, | |
58 &wait_loop)); | |
mcasas
2016/08/10 15:50:54
Instead of passing |wait_loop| here, consider what
chfremer
2016/08/10 17:07:27
Done.
| |
59 wait_loop.Run(); | |
60 } | |
61 | |
62 } // namespace video_capture | |
OLD | NEW |