| 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 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 46 | 46 |
| 47 // These mock methods are delegated to by our fake implementation of | 47 // These mock methods are delegated to by our fake implementation of |
| 48 // VideoCaptureControllerEventHandler, to be used in EXPECT_CALL(). | 48 // VideoCaptureControllerEventHandler, to be used in EXPECT_CALL(). |
| 49 MOCK_METHOD1(DoBufferCreated, void(const VideoCaptureControllerID&)); | 49 MOCK_METHOD1(DoBufferCreated, void(const VideoCaptureControllerID&)); |
| 50 MOCK_METHOD1(DoBufferDestroyed, void(const VideoCaptureControllerID&)); | 50 MOCK_METHOD1(DoBufferDestroyed, void(const VideoCaptureControllerID&)); |
| 51 MOCK_METHOD1(DoBufferReady, void(const VideoCaptureControllerID&)); | 51 MOCK_METHOD1(DoBufferReady, void(const VideoCaptureControllerID&)); |
| 52 MOCK_METHOD1(DoMailboxBufferReady, void(const VideoCaptureControllerID&)); | 52 MOCK_METHOD1(DoMailboxBufferReady, void(const VideoCaptureControllerID&)); |
| 53 MOCK_METHOD1(DoEnded, void(const VideoCaptureControllerID&)); | 53 MOCK_METHOD1(DoEnded, void(const VideoCaptureControllerID&)); |
| 54 MOCK_METHOD1(DoError, void(const VideoCaptureControllerID&)); | 54 MOCK_METHOD1(DoError, void(const VideoCaptureControllerID&)); |
| 55 | 55 |
| 56 virtual void OnError(const VideoCaptureControllerID& id) OVERRIDE { | 56 virtual void OnError(const VideoCaptureControllerID& id) override { |
| 57 DoError(id); | 57 DoError(id); |
| 58 } | 58 } |
| 59 virtual void OnBufferCreated(const VideoCaptureControllerID& id, | 59 virtual void OnBufferCreated(const VideoCaptureControllerID& id, |
| 60 base::SharedMemoryHandle handle, | 60 base::SharedMemoryHandle handle, |
| 61 int length, int buffer_id) OVERRIDE { | 61 int length, int buffer_id) override { |
| 62 DoBufferCreated(id); | 62 DoBufferCreated(id); |
| 63 } | 63 } |
| 64 virtual void OnBufferDestroyed(const VideoCaptureControllerID& id, | 64 virtual void OnBufferDestroyed(const VideoCaptureControllerID& id, |
| 65 int buffer_id) OVERRIDE { | 65 int buffer_id) override { |
| 66 DoBufferDestroyed(id); | 66 DoBufferDestroyed(id); |
| 67 } | 67 } |
| 68 virtual void OnBufferReady(const VideoCaptureControllerID& id, | 68 virtual void OnBufferReady(const VideoCaptureControllerID& id, |
| 69 int buffer_id, | 69 int buffer_id, |
| 70 const media::VideoCaptureFormat& format, | 70 const media::VideoCaptureFormat& format, |
| 71 const gfx::Rect& visible_rect, | 71 const gfx::Rect& visible_rect, |
| 72 base::TimeTicks timestamp) OVERRIDE { | 72 base::TimeTicks timestamp) override { |
| 73 DoBufferReady(id); | 73 DoBufferReady(id); |
| 74 base::MessageLoop::current()->PostTask( | 74 base::MessageLoop::current()->PostTask( |
| 75 FROM_HERE, | 75 FROM_HERE, |
| 76 base::Bind(&VideoCaptureController::ReturnBuffer, | 76 base::Bind(&VideoCaptureController::ReturnBuffer, |
| 77 base::Unretained(controller_), | 77 base::Unretained(controller_), |
| 78 id, | 78 id, |
| 79 this, | 79 this, |
| 80 buffer_id, | 80 buffer_id, |
| 81 0)); | 81 0)); |
| 82 } | 82 } |
| 83 virtual void OnMailboxBufferReady(const VideoCaptureControllerID& id, | 83 virtual void OnMailboxBufferReady(const VideoCaptureControllerID& id, |
| 84 int buffer_id, | 84 int buffer_id, |
| 85 const gpu::MailboxHolder& mailbox_holder, | 85 const gpu::MailboxHolder& mailbox_holder, |
| 86 const media::VideoCaptureFormat& format, | 86 const media::VideoCaptureFormat& format, |
| 87 base::TimeTicks timestamp) OVERRIDE { | 87 base::TimeTicks timestamp) override { |
| 88 DoMailboxBufferReady(id); | 88 DoMailboxBufferReady(id); |
| 89 base::MessageLoop::current()->PostTask( | 89 base::MessageLoop::current()->PostTask( |
| 90 FROM_HERE, | 90 FROM_HERE, |
| 91 base::Bind(&VideoCaptureController::ReturnBuffer, | 91 base::Bind(&VideoCaptureController::ReturnBuffer, |
| 92 base::Unretained(controller_), | 92 base::Unretained(controller_), |
| 93 id, | 93 id, |
| 94 this, | 94 this, |
| 95 buffer_id, | 95 buffer_id, |
| 96 mailbox_holder.sync_point)); | 96 mailbox_holder.sync_point)); |
| 97 } | 97 } |
| 98 virtual void OnEnded(const VideoCaptureControllerID& id) OVERRIDE { | 98 virtual void OnEnded(const VideoCaptureControllerID& id) override { |
| 99 DoEnded(id); | 99 DoEnded(id); |
| 100 // OnEnded() must respond by (eventually) unregistering the client. | 100 // OnEnded() must respond by (eventually) unregistering the client. |
| 101 base::MessageLoop::current()->PostTask(FROM_HERE, | 101 base::MessageLoop::current()->PostTask(FROM_HERE, |
| 102 base::Bind(base::IgnoreResult(&VideoCaptureController::RemoveClient), | 102 base::Bind(base::IgnoreResult(&VideoCaptureController::RemoveClient), |
| 103 base::Unretained(controller_), id, this)); | 103 base::Unretained(controller_), id, this)); |
| 104 } | 104 } |
| 105 | 105 |
| 106 VideoCaptureController* controller_; | 106 VideoCaptureController* controller_; |
| 107 }; | 107 }; |
| 108 | 108 |
| 109 // Test class. | 109 // Test class. |
| 110 class VideoCaptureControllerTest : public testing::Test { | 110 class VideoCaptureControllerTest : public testing::Test { |
| 111 public: | 111 public: |
| 112 VideoCaptureControllerTest() {} | 112 VideoCaptureControllerTest() {} |
| 113 virtual ~VideoCaptureControllerTest() {} | 113 virtual ~VideoCaptureControllerTest() {} |
| 114 | 114 |
| 115 protected: | 115 protected: |
| 116 static const int kPoolSize = 3; | 116 static const int kPoolSize = 3; |
| 117 | 117 |
| 118 virtual void SetUp() OVERRIDE { | 118 virtual void SetUp() override { |
| 119 controller_.reset(new VideoCaptureController(kPoolSize)); | 119 controller_.reset(new VideoCaptureController(kPoolSize)); |
| 120 device_ = controller_->NewDeviceClient().Pass(); | 120 device_ = controller_->NewDeviceClient().Pass(); |
| 121 client_a_.reset(new MockVideoCaptureControllerEventHandler( | 121 client_a_.reset(new MockVideoCaptureControllerEventHandler( |
| 122 controller_.get())); | 122 controller_.get())); |
| 123 client_b_.reset(new MockVideoCaptureControllerEventHandler( | 123 client_b_.reset(new MockVideoCaptureControllerEventHandler( |
| 124 controller_.get())); | 124 controller_.get())); |
| 125 } | 125 } |
| 126 | 126 |
| 127 virtual void TearDown() OVERRIDE { | 127 virtual void TearDown() override { |
| 128 base::RunLoop().RunUntilIdle(); | 128 base::RunLoop().RunUntilIdle(); |
| 129 } | 129 } |
| 130 | 130 |
| 131 scoped_refptr<media::VideoFrame> WrapI420Buffer( | 131 scoped_refptr<media::VideoFrame> WrapI420Buffer( |
| 132 const scoped_refptr<media::VideoCaptureDevice::Client::Buffer>& buffer, | 132 const scoped_refptr<media::VideoCaptureDevice::Client::Buffer>& buffer, |
| 133 gfx::Size dimensions) { | 133 gfx::Size dimensions) { |
| 134 return media::VideoFrame::WrapExternalPackedMemory( | 134 return media::VideoFrame::WrapExternalPackedMemory( |
| 135 media::VideoFrame::I420, | 135 media::VideoFrame::I420, |
| 136 dimensions, | 136 dimensions, |
| 137 gfx::Rect(dimensions), | 137 gfx::Rect(dimensions), |
| (...skipping 497 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 635 | 635 |
| 636 // Second client connects after the error state. It also should get told of | 636 // Second client connects after the error state. It also should get told of |
| 637 // the error. | 637 // the error. |
| 638 EXPECT_CALL(*client_b_, DoError(route_id)).Times(1); | 638 EXPECT_CALL(*client_b_, DoError(route_id)).Times(1); |
| 639 controller_->AddClient( | 639 controller_->AddClient( |
| 640 route_id, client_b_.get(), base::kNullProcessHandle, 200, session_200); | 640 route_id, client_b_.get(), base::kNullProcessHandle, 200, session_200); |
| 641 Mock::VerifyAndClearExpectations(client_b_.get()); | 641 Mock::VerifyAndClearExpectations(client_b_.get()); |
| 642 } | 642 } |
| 643 | 643 |
| 644 } // namespace content | 644 } // namespace content |
| OLD | NEW |