OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/message_loop.h" | 5 #include "base/message_loop.h" |
6 #include "content/renderer/media/video_capture_impl.h" | 6 #include "content/renderer/media/video_capture_impl.h" |
7 #include "testing/gmock/include/gmock/gmock.h" | 7 #include "testing/gmock/include/gmock/gmock.h" |
8 #include "testing/gtest/include/gtest/gtest.h" | 8 #include "testing/gtest/include/gtest/gtest.h" |
9 | 9 |
10 using ::testing::_; | 10 using ::testing::_; |
11 using ::testing::Return; | 11 using ::testing::Return; |
12 | 12 |
13 #define DEFAULT_CAPABILITY {176, 144, 30, 0, media::VideoFrame::I420, \ | 13 #define DEFAULT_CAPABILITY {176, 144, 30, 0, media::VideoFrame::I420, \ |
14 false, false } | 14 false, false } |
15 | 15 |
16 ACTION_P(DeleteMessage, return_value) { | 16 ACTION(DeleteMessage) { |
17 delete arg0; | 17 delete arg0; |
18 return return_value; | |
19 } | 18 } |
20 | 19 |
21 class MockVideoCaptureMessageFilter : public VideoCaptureMessageFilter { | 20 class MockVideoCaptureMessageFilter : public VideoCaptureMessageFilter { |
22 public: | 21 public: |
23 MockVideoCaptureMessageFilter() : VideoCaptureMessageFilter(1) {} | 22 MockVideoCaptureMessageFilter() : VideoCaptureMessageFilter(1) {} |
24 virtual ~MockVideoCaptureMessageFilter() {} | 23 virtual ~MockVideoCaptureMessageFilter() {} |
25 | 24 |
26 // Filter implementation. | 25 // Filter implementation. |
27 MOCK_METHOD1(Send, bool(IPC::Message* message)); | 26 MOCK_METHOD1(Send, bool(IPC::Message* message)); |
28 MOCK_METHOD0(ReadyToSend, bool()); | |
29 | 27 |
30 private: | 28 private: |
31 DISALLOW_COPY_AND_ASSIGN(MockVideoCaptureMessageFilter); | 29 DISALLOW_COPY_AND_ASSIGN(MockVideoCaptureMessageFilter); |
32 }; | 30 }; |
33 | 31 |
34 class MockVideoCaptureClient : public media::VideoCapture::EventHandler { | 32 class MockVideoCaptureClient : public media::VideoCapture::EventHandler { |
35 public: | 33 public: |
36 MockVideoCaptureClient() {} | 34 MockVideoCaptureClient() {} |
37 virtual ~MockVideoCaptureClient() {} | 35 virtual ~MockVideoCaptureClient() {} |
38 | 36 |
39 // Filter implementation. | 37 // Filter implementation. |
40 MOCK_METHOD1(OnStarted, void(media::VideoCapture* capture)); | 38 MOCK_METHOD1(OnStarted, void(media::VideoCapture* capture)); |
41 MOCK_METHOD1(OnStopped, void(media::VideoCapture* capture)); | 39 MOCK_METHOD1(OnStopped, void(media::VideoCapture* capture)); |
42 MOCK_METHOD1(OnPaused, void(media::VideoCapture* capture)); | 40 MOCK_METHOD1(OnPaused, void(media::VideoCapture* capture)); |
43 MOCK_METHOD2(OnError, void(media::VideoCapture* capture, int error_code)); | 41 MOCK_METHOD2(OnError, void(media::VideoCapture* capture, int error_code)); |
44 MOCK_METHOD2(OnBufferReady, | 42 MOCK_METHOD2(OnBufferReady, |
45 void(media::VideoCapture* capture, | 43 void(media::VideoCapture* capture, |
46 scoped_refptr<media::VideoCapture::VideoFrameBuffer> buf)); | 44 scoped_refptr<media::VideoCapture::VideoFrameBuffer> buf)); |
47 MOCK_METHOD2(OnDeviceInfoReceived, | 45 MOCK_METHOD2(OnDeviceInfoReceived, |
48 void(media::VideoCapture* capture, | 46 void(media::VideoCapture* capture, |
49 const media::VideoCaptureParams& device_info)); | 47 const media::VideoCaptureParams& device_info)); |
50 | 48 |
51 private: | 49 private: |
52 DISALLOW_COPY_AND_ASSIGN(MockVideoCaptureClient); | 50 DISALLOW_COPY_AND_ASSIGN(MockVideoCaptureClient); |
53 }; | 51 }; |
54 | 52 |
55 class VideoCaptureImplTest : public ::testing::Test { | 53 class VideoCaptureImplTest : public ::testing::Test { |
56 public: | 54 public: |
| 55 class MockVideoCaptureImpl : public VideoCaptureImpl { |
| 56 public: |
| 57 MockVideoCaptureImpl(const media::VideoCaptureSessionId id, |
| 58 scoped_refptr<base::MessageLoopProxy> ml_proxy, |
| 59 VideoCaptureMessageFilter* filter) |
| 60 : VideoCaptureImpl(id, ml_proxy, filter) { |
| 61 } |
| 62 virtual ~MockVideoCaptureImpl() {} |
| 63 |
| 64 MOCK_METHOD1(Send, void(IPC::Message* message)); |
| 65 }; |
| 66 |
57 VideoCaptureImplTest() { | 67 VideoCaptureImplTest() { |
58 message_loop_.reset(new MessageLoop(MessageLoop::TYPE_IO)); | 68 message_loop_.reset(new MessageLoop(MessageLoop::TYPE_IO)); |
59 message_loop_proxy_ = | 69 message_loop_proxy_ = |
60 base::MessageLoopProxy::CreateForCurrentThread().get(); | 70 base::MessageLoopProxy::CreateForCurrentThread().get(); |
61 | 71 |
62 message_filter_ = new MockVideoCaptureMessageFilter; | 72 message_filter_ = new MockVideoCaptureMessageFilter; |
63 session_id_ = 1; | 73 session_id_ = 1; |
64 | 74 |
65 video_capture_impl_ = new VideoCaptureImpl(session_id_, message_loop_proxy_, | 75 video_capture_impl_ = new MockVideoCaptureImpl(session_id_, |
66 message_filter_); | 76 message_loop_proxy_, |
| 77 message_filter_); |
67 | 78 |
68 video_capture_impl_->device_id_ = 2; | 79 video_capture_impl_->device_id_ = 2; |
69 } | 80 } |
70 | 81 |
71 virtual ~VideoCaptureImplTest() { | 82 virtual ~VideoCaptureImplTest() { |
72 delete video_capture_impl_; | 83 delete video_capture_impl_; |
73 } | 84 } |
74 | 85 |
75 protected: | 86 protected: |
76 scoped_ptr<MessageLoop> message_loop_; | 87 scoped_ptr<MessageLoop> message_loop_; |
77 scoped_refptr<base::MessageLoopProxy> message_loop_proxy_; | 88 scoped_refptr<base::MessageLoopProxy> message_loop_proxy_; |
78 scoped_refptr<MockVideoCaptureMessageFilter> message_filter_; | 89 scoped_refptr<MockVideoCaptureMessageFilter> message_filter_; |
79 media::VideoCaptureSessionId session_id_; | 90 media::VideoCaptureSessionId session_id_; |
80 VideoCaptureImpl* video_capture_impl_; | 91 MockVideoCaptureImpl* video_capture_impl_; |
81 | 92 |
82 private: | 93 private: |
83 DISALLOW_COPY_AND_ASSIGN(VideoCaptureImplTest); | 94 DISALLOW_COPY_AND_ASSIGN(VideoCaptureImplTest); |
84 }; | 95 }; |
85 | 96 |
86 TEST_F(VideoCaptureImplTest, Simple) { | 97 TEST_F(VideoCaptureImplTest, Simple) { |
87 // Execute SetCapture() and StopCapture(). | 98 // Execute SetCapture() and StopCapture(). |
88 | 99 |
89 scoped_ptr<MockVideoCaptureClient> client(new MockVideoCaptureClient); | 100 scoped_ptr<MockVideoCaptureClient> client(new MockVideoCaptureClient); |
90 media::VideoCapture::VideoCaptureCapability capability = DEFAULT_CAPABILITY; | 101 media::VideoCapture::VideoCaptureCapability capability = DEFAULT_CAPABILITY; |
91 | 102 |
92 EXPECT_CALL(*message_filter_, Send(_)) | 103 EXPECT_CALL(*video_capture_impl_, Send(_)) |
93 .WillRepeatedly(DeleteMessage(true)); | 104 .WillRepeatedly(DeleteMessage()); |
94 | |
95 EXPECT_CALL(*message_filter_, ReadyToSend()) | |
96 .WillRepeatedly(Return(true)); | |
97 | 105 |
98 EXPECT_CALL(*client, OnStarted(_)) | 106 EXPECT_CALL(*client, OnStarted(_)) |
99 .WillOnce(Return()); | 107 .WillOnce(Return()); |
100 | 108 |
101 video_capture_impl_->StartCapture(client.get(), capability); | 109 video_capture_impl_->StartCapture(client.get(), capability); |
102 | 110 |
103 EXPECT_CALL(*client, OnStopped(_)) | 111 EXPECT_CALL(*client, OnStopped(_)) |
104 .WillOnce(Return()); | 112 .WillOnce(Return()); |
105 | 113 |
106 video_capture_impl_->StopCapture(client.get()); | 114 video_capture_impl_->StopCapture(client.get()); |
107 } | 115 } |
OLD | NEW |