| 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/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 105 VideoCaptureController* controller_; | 105 VideoCaptureController* controller_; |
| 106 }; | 106 }; |
| 107 | 107 |
| 108 // Test class. | 108 // Test class. |
| 109 class VideoCaptureControllerTest : public testing::Test { | 109 class VideoCaptureControllerTest : public testing::Test { |
| 110 public: | 110 public: |
| 111 VideoCaptureControllerTest() {} | 111 VideoCaptureControllerTest() {} |
| 112 virtual ~VideoCaptureControllerTest() {} | 112 virtual ~VideoCaptureControllerTest() {} |
| 113 | 113 |
| 114 protected: | 114 protected: |
| 115 static const int kPoolSize = 3; | 115 static const int kPoolSize = 5; |
| 116 | 116 |
| 117 virtual void SetUp() OVERRIDE { | 117 virtual void SetUp() OVERRIDE { |
| 118 controller_.reset(new VideoCaptureController()); | 118 controller_.reset(new VideoCaptureController()); |
| 119 device_ = controller_->NewDeviceClient().Pass(); | 119 device_ = controller_->NewDeviceClient().Pass(); |
| 120 client_a_.reset(new MockVideoCaptureControllerEventHandler( | 120 client_a_.reset(new MockVideoCaptureControllerEventHandler( |
| 121 controller_.get())); | 121 controller_.get())); |
| 122 client_b_.reset(new MockVideoCaptureControllerEventHandler( | 122 client_b_.reset(new MockVideoCaptureControllerEventHandler( |
| 123 controller_.get())); | 123 controller_.get())); |
| 124 } | 124 } |
| 125 | 125 |
| (...skipping 261 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 387 Mock::VerifyAndClearExpectations(client_b_.get()); | 387 Mock::VerifyAndClearExpectations(client_b_.get()); |
| 388 | 388 |
| 389 // Add a fourth client now that some buffers have come through. | 389 // Add a fourth client now that some buffers have come through. |
| 390 controller_->AddClient(client_b_route_2, | 390 controller_->AddClient(client_b_route_2, |
| 391 client_b_.get(), | 391 client_b_.get(), |
| 392 base::kNullProcessHandle, | 392 base::kNullProcessHandle, |
| 393 1, | 393 1, |
| 394 session_1); | 394 session_1); |
| 395 Mock::VerifyAndClearExpectations(client_b_.get()); | 395 Mock::VerifyAndClearExpectations(client_b_.get()); |
| 396 | 396 |
| 397 // Third, fourth, and fifth buffers. Pretend they all arrive at the same time. | 397 // Third through seventh buffers. Pretend they all arrive at the same time. |
| 398 for (int i = 0; i < kPoolSize; i++) { | 398 for (int i = 0; i < kPoolSize; i++) { |
| 399 buffer = device_->ReserveOutputBuffer(media::VideoFrame::I420, | 399 buffer = device_->ReserveOutputBuffer(media::VideoFrame::I420, |
| 400 capture_resolution); | 400 capture_resolution); |
| 401 ASSERT_TRUE(buffer); | 401 ASSERT_TRUE(buffer); |
| 402 memset(buffer->data(), buffer_no++, buffer->size()); | 402 memset(buffer->data(), buffer_no++, buffer->size()); |
| 403 device_->OnIncomingCapturedVideoFrame( | 403 device_->OnIncomingCapturedVideoFrame( |
| 404 buffer, | 404 buffer, |
| 405 media::VideoCaptureFormat(capture_resolution, | 405 media::VideoCaptureFormat(capture_resolution, |
| 406 device_format.frame_rate, | 406 device_format.frame_rate, |
| 407 media::PIXEL_FORMAT_I420), | 407 media::PIXEL_FORMAT_I420), |
| 408 WrapI420Buffer(buffer, capture_resolution), | 408 WrapI420Buffer(buffer, capture_resolution), |
| 409 base::TimeTicks()); | 409 base::TimeTicks()); |
| 410 buffer = NULL; | 410 buffer = NULL; |
| 411 } | 411 } |
| 412 // ReserveOutputBuffer ought to fail now, because the pool is depleted. | 412 // ReserveOutputBuffer ought to fail now, because the pool is depleted. |
| 413 ASSERT_FALSE(device_->ReserveOutputBuffer(media::VideoFrame::I420, | 413 ASSERT_FALSE(device_->ReserveOutputBuffer(media::VideoFrame::I420, |
| 414 capture_resolution)); | 414 capture_resolution)); |
| 415 | 415 |
| 416 // The new client needs to be told of 3 buffers; the old clients only 2. | 416 // The new client needs to be told of 5 buffers; the old clients only 4. |
| 417 EXPECT_CALL(*client_b_, DoBufferCreated(client_b_route_2)).Times(kPoolSize); | 417 EXPECT_CALL(*client_b_, DoBufferCreated(client_b_route_2)).Times(kPoolSize); |
| 418 EXPECT_CALL(*client_b_, DoBufferReady(client_b_route_2)).Times(kPoolSize); | 418 EXPECT_CALL(*client_b_, DoBufferReady(client_b_route_2)).Times(kPoolSize); |
| 419 EXPECT_CALL(*client_a_, DoBufferCreated(client_a_route_1)) | 419 EXPECT_CALL(*client_a_, DoBufferCreated(client_a_route_1)) |
| 420 .Times(kPoolSize - 1); | 420 .Times(kPoolSize - 1); |
| 421 EXPECT_CALL(*client_a_, DoBufferReady(client_a_route_1)).Times(kPoolSize); | 421 EXPECT_CALL(*client_a_, DoBufferReady(client_a_route_1)).Times(kPoolSize); |
| 422 EXPECT_CALL(*client_a_, DoBufferCreated(client_a_route_2)) | 422 EXPECT_CALL(*client_a_, DoBufferCreated(client_a_route_2)) |
| 423 .Times(kPoolSize - 1); | 423 .Times(kPoolSize - 1); |
| 424 EXPECT_CALL(*client_a_, DoBufferReady(client_a_route_2)).Times(kPoolSize); | 424 EXPECT_CALL(*client_a_, DoBufferReady(client_a_route_2)).Times(kPoolSize); |
| 425 EXPECT_CALL(*client_b_, DoBufferCreated(client_b_route_1)) | 425 EXPECT_CALL(*client_b_, DoBufferCreated(client_b_route_1)) |
| 426 .Times(kPoolSize - 1); | 426 .Times(kPoolSize - 1); |
| (...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 634 | 634 |
| 635 // Second client connects after the error state. It also should get told of | 635 // Second client connects after the error state. It also should get told of |
| 636 // the error. | 636 // the error. |
| 637 EXPECT_CALL(*client_b_, DoError(route_id)).Times(1); | 637 EXPECT_CALL(*client_b_, DoError(route_id)).Times(1); |
| 638 controller_->AddClient( | 638 controller_->AddClient( |
| 639 route_id, client_b_.get(), base::kNullProcessHandle, 200, session_200); | 639 route_id, client_b_.get(), base::kNullProcessHandle, 200, session_200); |
| 640 Mock::VerifyAndClearExpectations(client_b_.get()); | 640 Mock::VerifyAndClearExpectations(client_b_.get()); |
| 641 } | 641 } |
| 642 | 642 |
| 643 } // namespace content | 643 } // namespace content |
| OLD | NEW |