Index: services/video_capture/service_unittest.cc |
diff --git a/services/video_capture/service_unittest.cc b/services/video_capture/service_unittest.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..9542b348796b8a984faea0bf470f3c52a45c275f |
--- /dev/null |
+++ b/services/video_capture/service_unittest.cc |
@@ -0,0 +1,62 @@ |
+// Copyright 2016 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#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/video_capture_device_factory.mojom.h" |
+#include "testing/gmock/include/gmock/gmock.h" |
+ |
+using testing::Exactly; |
+using testing::_; |
+ |
+namespace video_capture { |
+ |
+class MockClient : public base::RefCountedThreadSafe<MockClient> { |
+ public: |
+ void HandleEnumerateDeviceDescriptorsCallback( |
+ base::RunLoop* loop, |
+ std::vector<mojom::VideoCaptureDeviceDescriptorPtr> descriptors) { |
+ OnEnumerateDeviceDescriptorsCallback(descriptors); |
+ loop->Quit(); |
+ } |
+ |
+ MOCK_METHOD1(OnEnumerateDeviceDescriptorsCallback, |
+ void(const std::vector<mojom::VideoCaptureDeviceDescriptorPtr>& |
+ descriptors)); |
+ |
+ private: |
+ friend class base::RefCountedThreadSafe<MockClient>; |
+ ~MockClient() {} |
+}; |
+ |
+class VideoCaptureServiceTest : public shell::test::ServiceTest { |
+ public: |
+ VideoCaptureServiceTest() |
+ : shell::test::ServiceTest("exe:video_capture_unittests") {} |
+ ~VideoCaptureServiceTest() override {} |
+ |
+ void SetUp() override { |
+ ServiceTest::SetUp(); |
+ connector()->ConnectToInterface("mojo:video_capture", &factory_); |
+ client_ = new MockClient(); |
+ } |
+ |
+ protected: |
+ mojom::VideoCaptureDeviceFactoryPtr factory_; |
+ 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.
|
+}; |
+ |
+TEST_F(VideoCaptureServiceTest, EnumerateDeviceDescriptorsCallbackArrives) { |
+ EXPECT_CALL(*client_, OnEnumerateDeviceDescriptorsCallback(_)) |
+ .Times(Exactly(1)); |
+ |
+ base::RunLoop wait_loop; |
+ factory_->EnumerateDeviceDescriptors( |
+ base::Bind(&MockClient::HandleEnumerateDeviceDescriptorsCallback, client_, |
+ &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.
|
+ wait_loop.Run(); |
+} |
+ |
+} // namespace video_capture |