| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/bind.h" | 5 #include "base/bind.h" |
| 6 #include "base/callback.h" | 6 #include "base/callback.h" |
| 7 #include "base/macros.h" | 7 #include "base/macros.h" |
| 8 #include "base/memory/ref_counted.h" | 8 #include "base/memory/ref_counted.h" |
| 9 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
| 10 #include "base/run_loop.h" | 10 #include "base/run_loop.h" |
| (...skipping 14 matching lines...) Expand all Loading... |
| 25 | 25 |
| 26 ACTION_P(RunClosure, closure) { | 26 ACTION_P(RunClosure, closure) { |
| 27 closure.Run(); | 27 closure.Run(); |
| 28 } | 28 } |
| 29 | 29 |
| 30 class MockVideoCaptureImpl : public VideoCaptureImpl { | 30 class MockVideoCaptureImpl : public VideoCaptureImpl { |
| 31 public: | 31 public: |
| 32 MockVideoCaptureImpl(media::VideoCaptureSessionId session_id, | 32 MockVideoCaptureImpl(media::VideoCaptureSessionId session_id, |
| 33 VideoCaptureMessageFilter* filter, | 33 VideoCaptureMessageFilter* filter, |
| 34 base::Closure destruct_callback) | 34 base::Closure destruct_callback) |
| 35 : VideoCaptureImpl(session_id, filter), | 35 : VideoCaptureImpl(session_id, |
| 36 destruct_callback_(destruct_callback) { | 36 filter, |
| 37 } | 37 ChildProcess::current()->io_task_runner()), |
| 38 destruct_callback_(destruct_callback) {} |
| 38 | 39 |
| 39 ~MockVideoCaptureImpl() override { destruct_callback_.Run(); } | 40 ~MockVideoCaptureImpl() override { destruct_callback_.Run(); } |
| 40 | 41 |
| 41 private: | 42 private: |
| 42 base::Closure destruct_callback_; | 43 const base::Closure destruct_callback_; |
| 43 | 44 |
| 44 DISALLOW_COPY_AND_ASSIGN(MockVideoCaptureImpl); | 45 DISALLOW_COPY_AND_ASSIGN(MockVideoCaptureImpl); |
| 45 }; | 46 }; |
| 46 | 47 |
| 47 class MockVideoCaptureImplManager : public VideoCaptureImplManager { | 48 class MockVideoCaptureImplManager : public VideoCaptureImplManager { |
| 48 public: | 49 public: |
| 49 explicit MockVideoCaptureImplManager( | 50 explicit MockVideoCaptureImplManager( |
| 50 base::Closure destruct_video_capture_callback) | 51 base::Closure destruct_video_capture_callback) |
| 51 : destruct_video_capture_callback_( | 52 : destruct_video_capture_callback_( |
| 52 destruct_video_capture_callback) {} | 53 destruct_video_capture_callback) {} |
| 53 ~MockVideoCaptureImplManager() override {} | 54 ~MockVideoCaptureImplManager() override {} |
| 54 | 55 |
| 55 protected: | 56 protected: |
| 56 VideoCaptureImpl* CreateVideoCaptureImplForTesting( | 57 VideoCaptureImpl* CreateVideoCaptureImplForTesting( |
| 57 media::VideoCaptureSessionId id, | 58 media::VideoCaptureSessionId id, |
| 58 VideoCaptureMessageFilter* filter) const override { | 59 VideoCaptureMessageFilter* filter) const override { |
| 59 return new MockVideoCaptureImpl(id, | 60 return new MockVideoCaptureImpl(id, |
| 60 filter, | 61 filter, |
| 61 destruct_video_capture_callback_); | 62 destruct_video_capture_callback_); |
| 62 } | 63 } |
| 63 | 64 |
| 64 private: | 65 private: |
| 65 base::Closure destruct_video_capture_callback_; | 66 const base::Closure destruct_video_capture_callback_; |
| 66 | 67 |
| 67 DISALLOW_COPY_AND_ASSIGN(MockVideoCaptureImplManager); | 68 DISALLOW_COPY_AND_ASSIGN(MockVideoCaptureImplManager); |
| 68 }; | 69 }; |
| 69 | 70 |
| 70 class VideoCaptureImplManagerTest : public ::testing::Test { | 71 class VideoCaptureImplManagerTest : public ::testing::Test { |
| 71 public: | 72 public: |
| 72 VideoCaptureImplManagerTest() | 73 VideoCaptureImplManagerTest() |
| 73 : manager_(new MockVideoCaptureImplManager( | 74 : child_process_(new ChildProcess()), |
| 74 BindToCurrentLoop(cleanup_run_loop_.QuitClosure()))) { | 75 manager_(new MockVideoCaptureImplManager( |
| 76 BindToCurrentLoop(cleanup_run_loop_.QuitClosure()))) { |
| 75 params_.requested_format = media::VideoCaptureFormat( | 77 params_.requested_format = media::VideoCaptureFormat( |
| 76 gfx::Size(176, 144), 30, media::PIXEL_FORMAT_I420); | 78 gfx::Size(176, 144), 30, media::PIXEL_FORMAT_I420); |
| 77 child_process_.reset(new ChildProcess()); | 79 ; |
| 78 } | 80 } |
| 79 | 81 |
| 80 void FakeChannelSetup() { | 82 void FakeChannelSetup() { |
| 81 scoped_refptr<base::SingleThreadTaskRunner> task_runner = | 83 scoped_refptr<base::SingleThreadTaskRunner> task_runner = |
| 82 child_process_->io_task_runner(); | 84 child_process_->io_task_runner(); |
| 83 if (!task_runner->BelongsToCurrentThread()) { | 85 if (!task_runner->BelongsToCurrentThread()) { |
| 84 task_runner->PostTask( | 86 task_runner->PostTask( |
| 85 FROM_HERE, base::Bind(&VideoCaptureImplManagerTest::FakeChannelSetup, | 87 FROM_HERE, base::Bind(&VideoCaptureImplManagerTest::FakeChannelSetup, |
| 86 base::Unretained(this))); | 88 base::Unretained(this))); |
| 87 return; | 89 return; |
| (...skipping 22 matching lines...) Expand all Loading... |
| 110 } | 112 } |
| 111 | 113 |
| 112 base::Closure StartCapture(const media::VideoCaptureParams& params) { | 114 base::Closure StartCapture(const media::VideoCaptureParams& params) { |
| 113 return manager_->StartCapture( | 115 return manager_->StartCapture( |
| 114 0, params, base::Bind(&VideoCaptureImplManagerTest::OnStateUpdate, | 116 0, params, base::Bind(&VideoCaptureImplManagerTest::OnStateUpdate, |
| 115 base::Unretained(this)), | 117 base::Unretained(this)), |
| 116 base::Bind(&VideoCaptureImplManagerTest::OnFrameReady, | 118 base::Bind(&VideoCaptureImplManagerTest::OnFrameReady, |
| 117 base::Unretained(this))); | 119 base::Unretained(this))); |
| 118 } | 120 } |
| 119 | 121 |
| 120 base::MessageLoop message_loop_; | 122 const base::MessageLoop message_loop_; |
| 121 std::unique_ptr<ChildProcess> child_process_; | 123 const std::unique_ptr<ChildProcess> child_process_; |
| 122 media::VideoCaptureParams params_; | 124 media::VideoCaptureParams params_; |
| 123 base::RunLoop cleanup_run_loop_; | 125 base::RunLoop cleanup_run_loop_; |
| 124 std::unique_ptr<MockVideoCaptureImplManager> manager_; | 126 std::unique_ptr<MockVideoCaptureImplManager> manager_; |
| 125 | 127 |
| 126 private: | 128 private: |
| 127 DISALLOW_COPY_AND_ASSIGN(VideoCaptureImplManagerTest); | 129 DISALLOW_COPY_AND_ASSIGN(VideoCaptureImplManagerTest); |
| 128 }; | 130 }; |
| 129 | 131 |
| 130 // Multiple clients with the same session id. There is only one | 132 // Multiple clients with the same session id. There is only one |
| 131 // media::VideoCapture object. | 133 // media::VideoCapture object. |
| (...skipping 27 matching lines...) Expand all Loading... |
| 159 cleanup_run_loop_.Run(); | 161 cleanup_run_loop_.Run(); |
| 160 } | 162 } |
| 161 | 163 |
| 162 TEST_F(VideoCaptureImplManagerTest, NoLeak) { | 164 TEST_F(VideoCaptureImplManagerTest, NoLeak) { |
| 163 manager_->UseDevice(0).Reset(); | 165 manager_->UseDevice(0).Reset(); |
| 164 manager_.reset(); | 166 manager_.reset(); |
| 165 cleanup_run_loop_.Run(); | 167 cleanup_run_loop_.Run(); |
| 166 } | 168 } |
| 167 | 169 |
| 168 } // namespace content | 170 } // namespace content |
| OLD | NEW |