Chromium Code Reviews| 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 ACTION_P(RunClosure, closure) { | |
| 17 closure.Run(); | |
| 18 } | |
| 19 | |
| 20 class MockClient { | |
| 21 public: | |
| 22 // Use forwarding method to work around gmock not supporting move-only types. | |
| 23 void HandleEnumerateDeviceDescriptorsCallback( | |
| 24 std::vector<mojom::VideoCaptureDeviceDescriptorPtr> descriptors) { | |
| 25 OnEnumerateDeviceDescriptorsCallback(descriptors); | |
| 26 } | |
| 27 | |
| 28 MOCK_METHOD1(OnEnumerateDeviceDescriptorsCallback, | |
| 29 void(const std::vector<mojom::VideoCaptureDeviceDescriptorPtr>& | |
| 30 descriptors)); | |
|
mcasas
2016/08/12 21:45:27
nit: MOCKs don't need to name the parameters.
chfremer
2016/08/12 22:23:24
Done.
| |
| 31 }; | |
| 32 | |
| 33 class VideoCaptureServiceTest : public shell::test::ServiceTest { | |
| 34 public: | |
| 35 VideoCaptureServiceTest() | |
| 36 : shell::test::ServiceTest("exe:video_capture_unittests") {} | |
| 37 ~VideoCaptureServiceTest() override {} | |
| 38 | |
| 39 void SetUp() override { | |
| 40 ServiceTest::SetUp(); | |
| 41 connector()->ConnectToInterface("mojo:video_capture", &factory_); | |
| 42 } | |
| 43 | |
| 44 protected: | |
| 45 mojom::VideoCaptureDeviceFactoryPtr factory_; | |
| 46 MockClient client_; | |
| 47 }; | |
| 48 | |
| 49 TEST_F(VideoCaptureServiceTest, EnumerateDeviceDescriptorsCallbackArrives) { | |
|
mcasas
2016/08/12 21:45:27
nit: write a minimal explanation, like:
// Tests t
chfremer
2016/08/12 22:23:24
Done.
| |
| 50 base::RunLoop wait_loop; | |
| 51 EXPECT_CALL(client_, OnEnumerateDeviceDescriptorsCallback(_)) | |
| 52 .Times(Exactly(1)) | |
| 53 .WillOnce(RunClosure(wait_loop.QuitClosure())); | |
| 54 ; | |
|
mcasas
2016/08/12 21:45:27
nit: remove ;
chfremer
2016/08/12 22:23:24
Done.
| |
| 55 | |
| 56 factory_->EnumerateDeviceDescriptors( | |
| 57 base::Bind(&MockClient::HandleEnumerateDeviceDescriptorsCallback, | |
| 58 base::Unretained(&client_))); | |
| 59 wait_loop.Run(); | |
| 60 } | |
| 61 | |
| 62 } // namespace video_capture | |
| OLD | NEW |