Chromium Code Reviews| 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/memory/ref_counted.h" | 7 #include "base/memory/ref_counted.h" |
| 7 #include "base/message_loop/message_loop.h" | 8 #include "base/message_loop/message_loop.h" |
| 8 #include "base/run_loop.h" | 9 #include "base/run_loop.h" |
| 9 #include "content/child/child_process.h" | 10 #include "content/child/child_process.h" |
| 10 #include "content/renderer/media/video_capture_impl.h" | 11 #include "content/renderer/media/video_capture_impl.h" |
| 11 #include "content/renderer/media/video_capture_impl_manager.h" | 12 #include "content/renderer/media/video_capture_impl_manager.h" |
| 12 #include "content/renderer/media/video_capture_message_filter.h" | 13 #include "content/renderer/media/video_capture_message_filter.h" |
| 13 #include "media/base/bind_to_current_loop.h" | 14 #include "media/base/bind_to_current_loop.h" |
| 14 #include "media/video/capture/mock_video_capture_event_handler.h" | 15 #include "media/video/capture/mock_video_capture_event_handler.h" |
| 15 #include "testing/gmock/include/gmock/gmock.h" | 16 #include "testing/gmock/include/gmock/gmock.h" |
| 16 #include "testing/gtest/include/gtest/gtest.h" | 17 #include "testing/gtest/include/gtest/gtest.h" |
| 17 | 18 |
| 18 using ::testing::_; | 19 using ::testing::_; |
| 19 using ::testing::DoAll; | 20 using ::testing::DoAll; |
| 20 using ::testing::SaveArg; | 21 using ::testing::SaveArg; |
| 21 using media::BindToCurrentLoop; | 22 using media::BindToCurrentLoop; |
| 22 using media::MockVideoCaptureEventHandler; | 23 using media::MockVideoCaptureEventHandler; |
| 23 | 24 |
| 24 namespace content { | 25 namespace content { |
| 25 | 26 |
| 26 ACTION_P(RunClosure, closure) { | 27 ACTION_P(RunClosure, closure) { |
| 27 closure.Run(); | 28 closure.Run(); |
| 28 } | 29 } |
| 29 | 30 |
| 30 class MockVideoCaptureImpl : public VideoCaptureImpl { | 31 class MockVideoCaptureImpl : public VideoCaptureImpl { |
| 31 public: | 32 public: |
| 32 MockVideoCaptureImpl(media::VideoCaptureSessionId session_id, | 33 MockVideoCaptureImpl(media::VideoCaptureSessionId session_id, |
| 33 VideoCaptureMessageFilter* filter) | 34 VideoCaptureMessageFilter* filter, |
| 34 : VideoCaptureImpl(session_id, filter) { | 35 base::Closure destruct_callback) |
| 36 : VideoCaptureImpl(session_id, filter), | |
| 37 destruct_callback_(destruct_callback) { | |
| 35 } | 38 } |
| 36 | 39 |
| 37 virtual ~MockVideoCaptureImpl() { | 40 virtual ~MockVideoCaptureImpl() { |
| 38 Destruct(); | 41 destruct_callback_.Run(); |
| 39 } | 42 } |
| 40 | 43 |
| 41 MOCK_METHOD0(Destruct, void()); | 44 private: |
| 45 base::Closure destruct_callback_; | |
| 42 | 46 |
| 43 private: | |
| 44 DISALLOW_COPY_AND_ASSIGN(MockVideoCaptureImpl); | 47 DISALLOW_COPY_AND_ASSIGN(MockVideoCaptureImpl); |
| 45 }; | 48 }; |
| 46 | 49 |
| 47 class MockVideoCaptureImplManager : public VideoCaptureImplManager { | 50 class MockVideoCaptureImplManager : public VideoCaptureImplManager { |
| 48 public: | 51 public: |
| 49 MockVideoCaptureImplManager() {} | 52 MockVideoCaptureImplManager(base::Closure destruct_callback) |
| 53 : destruct_callback_(destruct_callback) {} | |
|
Ami GONE FROM CHROMIUM
2014/01/13 22:15:04
explicit
Ami GONE FROM CHROMIUM
2014/01/13 22:15:04
member & arg names fail to connote that this cb is
| |
| 50 | 54 |
| 51 protected: | 55 protected: |
| 52 virtual VideoCaptureImpl* CreateVideoCaptureImpl( | 56 virtual VideoCaptureImpl* CreateVideoCaptureImpl( |
| 53 media::VideoCaptureSessionId id, | 57 media::VideoCaptureSessionId id, |
| 54 VideoCaptureMessageFilter* filter) const OVERRIDE { | 58 VideoCaptureMessageFilter* filter) const OVERRIDE { |
| 55 return new MockVideoCaptureImpl(id, filter); | 59 return new MockVideoCaptureImpl(id, filter, destruct_callback_); |
| 56 } | 60 } |
| 57 | 61 |
| 58 private: | 62 private: |
| 63 base::Closure destruct_callback_; | |
| 64 | |
| 59 DISALLOW_COPY_AND_ASSIGN(MockVideoCaptureImplManager); | 65 DISALLOW_COPY_AND_ASSIGN(MockVideoCaptureImplManager); |
| 60 }; | 66 }; |
| 61 | 67 |
| 62 class VideoCaptureImplManagerTest : public ::testing::Test { | 68 class VideoCaptureImplManagerTest : public ::testing::Test { |
| 63 public: | 69 public: |
| 64 VideoCaptureImplManagerTest() { | 70 VideoCaptureImplManagerTest() |
| 71 : manager_(BindToCurrentLoop(cleanup_run_loop_.QuitClosure())) { | |
| 65 params_.requested_format = media::VideoCaptureFormat( | 72 params_.requested_format = media::VideoCaptureFormat( |
| 66 gfx::Size(176, 144), 30, media::PIXEL_FORMAT_I420); | 73 gfx::Size(176, 144), 30, media::PIXEL_FORMAT_I420); |
| 67 child_process_.reset(new ChildProcess()); | 74 child_process_.reset(new ChildProcess()); |
| 68 } | 75 } |
| 69 | 76 |
| 70 void FakeChannelSetup() { | 77 void FakeChannelSetup() { |
| 71 scoped_refptr<base::MessageLoopProxy> loop = | 78 scoped_refptr<base::MessageLoopProxy> loop = |
| 72 child_process_->io_message_loop_proxy(); | 79 child_process_->io_message_loop_proxy(); |
| 73 if (!loop->BelongsToCurrentThread()) { | 80 if (!loop->BelongsToCurrentThread()) { |
| 74 loop->PostTask( | 81 loop->PostTask( |
| 75 FROM_HERE, | 82 FROM_HERE, |
| 76 base::Bind( | 83 base::Bind( |
| 77 &VideoCaptureImplManagerTest::FakeChannelSetup, | 84 &VideoCaptureImplManagerTest::FakeChannelSetup, |
| 78 base::Unretained(this))); | 85 base::Unretained(this))); |
| 79 return; | 86 return; |
| 80 } | 87 } |
| 81 manager_.video_capture_message_filter()->OnFilterAdded(NULL); | 88 manager_.video_capture_message_filter()->OnFilterAdded(NULL); |
| 82 } | 89 } |
| 83 | 90 |
| 84 void Quit(base::RunLoop* run_loop) { | |
| 85 message_loop_.PostTask(FROM_HERE, run_loop->QuitClosure()); | |
| 86 } | |
| 87 | |
| 88 protected: | 91 protected: |
| 89 base::MessageLoop message_loop_; | 92 base::MessageLoop message_loop_; |
| 90 scoped_ptr<ChildProcess> child_process_; | 93 scoped_ptr<ChildProcess> child_process_; |
| 91 media::VideoCaptureParams params_; | 94 media::VideoCaptureParams params_; |
| 95 base::RunLoop cleanup_run_loop_; | |
| 92 MockVideoCaptureImplManager manager_; | 96 MockVideoCaptureImplManager manager_; |
| 93 | 97 |
| 94 private: | 98 private: |
| 95 DISALLOW_COPY_AND_ASSIGN(VideoCaptureImplManagerTest); | 99 DISALLOW_COPY_AND_ASSIGN(VideoCaptureImplManagerTest); |
| 96 }; | 100 }; |
| 97 | 101 |
| 98 // Multiple clients with the same session id. There is only one | 102 // Multiple clients with the same session id. There is only one |
| 99 // media::VideoCapture object. | 103 // media::VideoCapture object. |
| 100 TEST_F(VideoCaptureImplManagerTest, MultipleClients) { | 104 TEST_F(VideoCaptureImplManagerTest, MultipleClients) { |
| 101 scoped_ptr<MockVideoCaptureEventHandler> client1( | 105 scoped_ptr<MockVideoCaptureEventHandler> client1( |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 133 | 137 |
| 134 EXPECT_CALL(*client1, OnStopped(_)); | 138 EXPECT_CALL(*client1, OnStopped(_)); |
| 135 EXPECT_CALL(*client1, OnRemoved(_)); | 139 EXPECT_CALL(*client1, OnRemoved(_)); |
| 136 EXPECT_CALL(*client2, OnStopped(_)); | 140 EXPECT_CALL(*client2, OnStopped(_)); |
| 137 EXPECT_CALL(*client2, OnRemoved(_)).WillOnce( | 141 EXPECT_CALL(*client2, OnRemoved(_)).WillOnce( |
| 138 RunClosure(quit_closure)); | 142 RunClosure(quit_closure)); |
| 139 handle1->StopCapture(client1.get()); | 143 handle1->StopCapture(client1.get()); |
| 140 handle2->StopCapture(client2.get()); | 144 handle2->StopCapture(client2.get()); |
| 141 run_loop.Run(); | 145 run_loop.Run(); |
| 142 } | 146 } |
| 147 EXPECT_TRUE(device1 == device2); | |
| 143 | 148 |
| 144 EXPECT_TRUE(device1 == device2); | 149 handle1.reset(); |
| 145 EXPECT_CALL(*static_cast<MockVideoCaptureImpl*>(device1), Destruct()); | 150 handle2.reset(); |
| 151 cleanup_run_loop_.Run(); | |
| 146 } | 152 } |
| 147 | 153 |
| 148 } // namespace content | 154 } // namespace content |
| OLD | NEW |