| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 // Unit test for VideoCaptureController. | 5 // Unit test for VideoCaptureController. |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/memory/ref_counted.h" | 10 #include "base/memory/ref_counted.h" |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 93 | 93 |
| 94 scoped_refptr<VideoCaptureController> controller_; | 94 scoped_refptr<VideoCaptureController> controller_; |
| 95 MessageLoop* message_loop_; | 95 MessageLoop* message_loop_; |
| 96 VideoCaptureControllerID controller_id_; | 96 VideoCaptureControllerID controller_id_; |
| 97 base::ProcessHandle process_handle_; | 97 base::ProcessHandle process_handle_; |
| 98 }; | 98 }; |
| 99 | 99 |
| 100 class MockVideoCaptureManager | 100 class MockVideoCaptureManager |
| 101 : public media_stream::VideoCaptureManager { | 101 : public media_stream::VideoCaptureManager { |
| 102 public: | 102 public: |
| 103 MockVideoCaptureManager() | 103 MockVideoCaptureManager(scoped_refptr<base::MessageLoopProxy> message_loop) |
| 104 : video_session_id_(kStartOpenSessionId) {} | 104 : media_stream::VideoCaptureManager(message_loop), |
| 105 video_session_id_(kStartOpenSessionId) {} |
| 105 | 106 |
| 106 void Init() { | 107 void Init() { |
| 107 device_name_.unique_id = "/dev/video0"; | 108 device_name_.unique_id = "/dev/video0"; |
| 108 device_name_.device_name = "fake_device_0"; | 109 device_name_.device_name = "fake_device_0"; |
| 109 | 110 |
| 110 video_capture_device_.reset( | 111 video_capture_device_.reset( |
| 111 media::FakeVideoCaptureDevice::Create(device_name_)); | 112 media::FakeVideoCaptureDevice::Create(device_name_)); |
| 112 ASSERT_TRUE(video_capture_device_.get() != NULL); | 113 ASSERT_TRUE(video_capture_device_.get() != NULL); |
| 113 } | 114 } |
| 114 | 115 |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 151 virtual ~VideoCaptureControllerTest() {} | 152 virtual ~VideoCaptureControllerTest() {} |
| 152 | 153 |
| 153 protected: | 154 protected: |
| 154 virtual void SetUp() { | 155 virtual void SetUp() { |
| 155 message_loop_.reset(new MessageLoop(MessageLoop::TYPE_IO)); | 156 message_loop_.reset(new MessageLoop(MessageLoop::TYPE_IO)); |
| 156 file_thread_.reset(new BrowserThreadImpl(BrowserThread::FILE, | 157 file_thread_.reset(new BrowserThreadImpl(BrowserThread::FILE, |
| 157 message_loop_.get())); | 158 message_loop_.get())); |
| 158 io_thread_.reset(new BrowserThreadImpl(BrowserThread::IO, | 159 io_thread_.reset(new BrowserThreadImpl(BrowserThread::IO, |
| 159 message_loop_.get())); | 160 message_loop_.get())); |
| 160 | 161 |
| 161 vcm_ = new MockVideoCaptureManager(); | 162 device_thread_.reset(new base::Thread("VideoCaptureControllerTestThread")); |
| 163 CHECK(device_thread_->Start()); |
| 164 |
| 165 vcm_ = new MockVideoCaptureManager(device_thread_->message_loop_proxy()); |
| 162 vcm_->Init(); | 166 vcm_->Init(); |
| 163 controller_ = new VideoCaptureController(vcm_); | 167 controller_ = new VideoCaptureController(vcm_); |
| 164 controller_handler_.reset( | 168 controller_handler_.reset( |
| 165 new MockVideoCaptureControllerEventHandler(controller_.get(), | 169 new MockVideoCaptureControllerEventHandler(controller_.get(), |
| 166 message_loop_.get())); | 170 message_loop_.get())); |
| 167 } | 171 } |
| 168 | 172 |
| 169 virtual void TearDown() { | 173 virtual void TearDown() { |
| 174 device_thread_->Stop(); |
| 170 } | 175 } |
| 171 | 176 |
| 172 scoped_ptr<MessageLoop> message_loop_; | 177 scoped_ptr<MessageLoop> message_loop_; |
| 173 scoped_ptr<BrowserThreadImpl> file_thread_; | 178 scoped_ptr<BrowserThreadImpl> file_thread_; |
| 174 scoped_ptr<BrowserThreadImpl> io_thread_; | 179 scoped_ptr<BrowserThreadImpl> io_thread_; |
| 180 scoped_ptr<base::Thread> device_thread_; |
| 175 scoped_refptr<MockVideoCaptureManager> vcm_; | 181 scoped_refptr<MockVideoCaptureManager> vcm_; |
| 176 scoped_ptr<MockVideoCaptureControllerEventHandler> controller_handler_; | 182 scoped_ptr<MockVideoCaptureControllerEventHandler> controller_handler_; |
| 177 scoped_refptr<VideoCaptureController> controller_; | 183 scoped_refptr<VideoCaptureController> controller_; |
| 178 | 184 |
| 179 private: | 185 private: |
| 180 DISALLOW_COPY_AND_ASSIGN(VideoCaptureControllerTest); | 186 DISALLOW_COPY_AND_ASSIGN(VideoCaptureControllerTest); |
| 181 }; | 187 }; |
| 182 | 188 |
| 183 // Try to start and stop capture. | 189 // Try to start and stop capture. |
| 184 TEST_F(VideoCaptureControllerTest, StartAndStop) { | 190 TEST_F(VideoCaptureControllerTest, StartAndStop) { |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 262 message_loop_->PostDelayedTask( | 268 message_loop_->PostDelayedTask( |
| 263 FROM_HERE, MessageLoop::QuitClosure(), base::TimeDelta::FromSeconds(1)); | 269 FROM_HERE, MessageLoop::QuitClosure(), base::TimeDelta::FromSeconds(1)); |
| 264 message_loop_->Run(); | 270 message_loop_->Run(); |
| 265 | 271 |
| 266 EXPECT_CALL(*vcm_, | 272 EXPECT_CALL(*vcm_, |
| 267 StopCapture(vcm_->video_session_id_)) | 273 StopCapture(vcm_->video_session_id_)) |
| 268 .Times(1); | 274 .Times(1); |
| 269 controller_->StopCapture(controller_handler_->controller_id_, | 275 controller_->StopCapture(controller_handler_->controller_id_, |
| 270 controller_handler_.get()); | 276 controller_handler_.get()); |
| 271 } | 277 } |
| OLD | NEW |