| 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 VideoCaptureManager. | 5 // Unit test for VideoCaptureManager. |
| 6 | 6 |
| 7 #include "content/browser/renderer_host/media/video_capture_manager.h" | 7 #include "content/browser/renderer_host/media/video_capture_manager.h" |
| 8 | 8 |
| 9 #include <stdint.h> | 9 #include <stdint.h> |
| 10 | 10 |
| (...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 139 class MockMediaStreamProviderListener : public MediaStreamProviderListener { | 139 class MockMediaStreamProviderListener : public MediaStreamProviderListener { |
| 140 public: | 140 public: |
| 141 MockMediaStreamProviderListener() {} | 141 MockMediaStreamProviderListener() {} |
| 142 ~MockMediaStreamProviderListener() {} | 142 ~MockMediaStreamProviderListener() {} |
| 143 | 143 |
| 144 MOCK_METHOD2(Opened, void(MediaStreamType, int)); | 144 MOCK_METHOD2(Opened, void(MediaStreamType, int)); |
| 145 MOCK_METHOD2(Closed, void(MediaStreamType, int)); | 145 MOCK_METHOD2(Closed, void(MediaStreamType, int)); |
| 146 MOCK_METHOD2(Aborted, void(MediaStreamType, int)); | 146 MOCK_METHOD2(Aborted, void(MediaStreamType, int)); |
| 147 }; // class MockMediaStreamProviderListener | 147 }; // class MockMediaStreamProviderListener |
| 148 | 148 |
| 149 // Needed as an input argument to StartCaptureForClient(). | 149 // Needed as an input argument to ConnectClient(). |
| 150 class MockFrameObserver : public VideoCaptureControllerEventHandler { | 150 class MockFrameObserver : public VideoCaptureControllerEventHandler { |
| 151 public: | 151 public: |
| 152 MOCK_METHOD1(OnError, void(VideoCaptureControllerID id)); | 152 MOCK_METHOD1(OnError, void(VideoCaptureControllerID id)); |
| 153 MOCK_METHOD1(OnStarted, void(VideoCaptureControllerID id)); | 153 MOCK_METHOD1(OnStarted, void(VideoCaptureControllerID id)); |
| 154 MOCK_METHOD1(OnStartedUsingGpuDecode, void(VideoCaptureControllerID id)); | 154 MOCK_METHOD1(OnStartedUsingGpuDecode, void(VideoCaptureControllerID id)); |
| 155 | 155 |
| 156 void OnBufferCreated(VideoCaptureControllerID id, | 156 void OnBufferCreated(VideoCaptureControllerID id, |
| 157 mojo::ScopedSharedBufferHandle handle, | 157 mojo::ScopedSharedBufferHandle handle, |
| 158 int length, int buffer_id) override {} | 158 int length, int buffer_id) override {} |
| 159 void OnBufferDestroyed(VideoCaptureControllerID id, int buffer_id) override {} | 159 void OnBufferDestroyed(VideoCaptureControllerID id, int buffer_id) override {} |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 230 ASSERT_FALSE(controller); | 230 ASSERT_FALSE(controller); |
| 231 } | 231 } |
| 232 } | 232 } |
| 233 | 233 |
| 234 VideoCaptureControllerID StartClient(int session_id, bool expect_success) { | 234 VideoCaptureControllerID StartClient(int session_id, bool expect_success) { |
| 235 media::VideoCaptureParams params; | 235 media::VideoCaptureParams params; |
| 236 params.requested_format = media::VideoCaptureFormat( | 236 params.requested_format = media::VideoCaptureFormat( |
| 237 gfx::Size(320, 240), 30, media::PIXEL_FORMAT_I420); | 237 gfx::Size(320, 240), 30, media::PIXEL_FORMAT_I420); |
| 238 | 238 |
| 239 VideoCaptureControllerID client_id(next_client_id_++); | 239 VideoCaptureControllerID client_id(next_client_id_++); |
| 240 vcm_->StartCaptureForClient( | 240 vcm_->ConnectClient( |
| 241 session_id, | 241 session_id, params, client_id, frame_observer_.get(), |
| 242 params, | |
| 243 client_id, | |
| 244 frame_observer_.get(), | |
| 245 base::Bind(&VideoCaptureManagerTest::OnGotControllerCallback, | 242 base::Bind(&VideoCaptureManagerTest::OnGotControllerCallback, |
| 246 base::Unretained(this), | 243 base::Unretained(this), client_id, expect_success)); |
| 247 client_id, | |
| 248 expect_success)); | |
| 249 base::RunLoop().RunUntilIdle(); | 244 base::RunLoop().RunUntilIdle(); |
| 250 return client_id; | 245 return client_id; |
| 251 } | 246 } |
| 252 | 247 |
| 253 void StopClient(VideoCaptureControllerID client_id) { | 248 void StopClient(VideoCaptureControllerID client_id) { |
| 254 ASSERT_TRUE(1 == controllers_.count(client_id)); | 249 ASSERT_TRUE(1 == controllers_.count(client_id)); |
| 255 vcm_->StopCaptureForClient(controllers_[client_id], client_id, | 250 vcm_->DisconnectClient(controllers_[client_id], client_id, |
| 256 frame_observer_.get(), false); | 251 frame_observer_.get(), false); |
| 257 controllers_.erase(client_id); | 252 controllers_.erase(client_id); |
| 258 } | 253 } |
| 259 | 254 |
| 260 void ResumeClient(int session_id, int client_id) { | 255 void ResumeClient(int session_id, int client_id) { |
| 261 ASSERT_EQ(1u, controllers_.count(client_id)); | 256 ASSERT_EQ(1u, controllers_.count(client_id)); |
| 262 media::VideoCaptureParams params; | 257 media::VideoCaptureParams params; |
| 263 params.requested_format = media::VideoCaptureFormat( | 258 params.requested_format = media::VideoCaptureFormat( |
| 264 gfx::Size(320, 240), 30, media::PIXEL_FORMAT_I420); | 259 gfx::Size(320, 240), 30, media::PIXEL_FORMAT_I420); |
| 265 vcm_->ResumeCaptureForClient( | 260 vcm_->ResumeCaptureForClient( |
| 266 session_id, | 261 session_id, |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 343 EXPECT_CALL(*listener_, Opened(MEDIA_DEVICE_VIDEO_CAPTURE, _)); | 338 EXPECT_CALL(*listener_, Opened(MEDIA_DEVICE_VIDEO_CAPTURE, _)); |
| 344 EXPECT_CALL(*frame_observer_, OnStarted(_)); | 339 EXPECT_CALL(*frame_observer_, OnStarted(_)); |
| 345 EXPECT_CALL(*listener_, Aborted(MEDIA_DEVICE_VIDEO_CAPTURE, _)); | 340 EXPECT_CALL(*listener_, Aborted(MEDIA_DEVICE_VIDEO_CAPTURE, _)); |
| 346 | 341 |
| 347 int video_session_id = vcm_->Open(devices_.front().device); | 342 int video_session_id = vcm_->Open(devices_.front().device); |
| 348 VideoCaptureControllerID client_id = StartClient(video_session_id, true); | 343 VideoCaptureControllerID client_id = StartClient(video_session_id, true); |
| 349 | 344 |
| 350 // Wait for device opened. | 345 // Wait for device opened. |
| 351 base::RunLoop().RunUntilIdle(); | 346 base::RunLoop().RunUntilIdle(); |
| 352 | 347 |
| 353 vcm_->StopCaptureForClient(controllers_[client_id], client_id, | 348 vcm_->DisconnectClient(controllers_[client_id], client_id, |
| 354 frame_observer_.get(), true); | 349 frame_observer_.get(), true); |
| 355 | 350 |
| 356 // Wait to check callbacks before removing the listener. | 351 // Wait to check callbacks before removing the listener. |
| 357 base::RunLoop().RunUntilIdle(); | 352 base::RunLoop().RunUntilIdle(); |
| 358 vcm_->UnregisterListener(listener_.get()); | 353 vcm_->UnregisterListener(listener_.get()); |
| 359 } | 354 } |
| 360 | 355 |
| 361 TEST_F(VideoCaptureManagerTest, AddObserver) { | 356 TEST_F(VideoCaptureManagerTest, AddObserver) { |
| 362 InSequence s; | 357 InSequence s; |
| 363 MockVideoCaptureObserver observer; | 358 MockVideoCaptureObserver observer; |
| 364 vcm_->AddVideoCaptureObserver(&observer); | 359 vcm_->AddVideoCaptureObserver(&observer); |
| (...skipping 425 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 790 // Wait to check callbacks before removing the listener. | 785 // Wait to check callbacks before removing the listener. |
| 791 base::RunLoop().RunUntilIdle(); | 786 base::RunLoop().RunUntilIdle(); |
| 792 vcm_->UnregisterListener(listener_.get()); | 787 vcm_->UnregisterListener(listener_.get()); |
| 793 } | 788 } |
| 794 #endif | 789 #endif |
| 795 | 790 |
| 796 // TODO(mcasas): Add a test to check consolidation of the supported formats | 791 // TODO(mcasas): Add a test to check consolidation of the supported formats |
| 797 // provided by the device when http://crbug.com/323913 is closed. | 792 // provided by the device when http://crbug.com/323913 is closed. |
| 798 | 793 |
| 799 } // namespace content | 794 } // namespace content |
| OLD | NEW |