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/memory/scoped_ptr.h" | 5 #include "base/memory/scoped_ptr.h" |
6 #include "base/synchronization/waitable_event.h" | 6 #include "base/synchronization/waitable_event.h" |
7 #include "base/test/test_timeouts.h" | 7 #include "base/test/test_timeouts.h" |
8 #include "base/threading/thread.h" | 8 #include "base/threading/thread.h" |
9 #include "media/video/capture/fake_video_capture_device.h" | 9 #include "media/video/capture/fake_video_capture_device.h" |
10 #include "media/video/capture/video_capture_device.h" | 10 #include "media/video/capture/video_capture_device.h" |
11 #include "media/video/capture/video_capture_device_unittest_helper.h" | |
11 #include "testing/gmock/include/gmock/gmock.h" | 12 #include "testing/gmock/include/gmock/gmock.h" |
12 #include "testing/gtest/include/gtest/gtest.h" | 13 #include "testing/gtest/include/gtest/gtest.h" |
13 | 14 |
15 #if defined(OS_MACOSX) | |
16 // The camera is 'locked' by the application once started on MAC OS X, not when | |
dmac
2011/10/14 23:31:35
s/MAC/Mac/
mflodman_chromium_OOO
2011/10/16 21:58:38
Done.
| |
17 // allocated as for Windows and Linux, and this test case will fail. | |
18 #define MAYBE_AllocateSameCameraTwice DISABLED_AllocateSameCameraTwice | |
19 #else | |
20 #define MAYBE_AllocateSameCameraTwice AllocateSameCameraTwice | |
21 #endif | |
22 | |
23 #if defined(OS_MACOSX) | |
24 // Mac/QTKit will always give you the size you ask for and this case will fail. | |
25 #define MAYBE_AllocateBadSize DISABLED_AllocateBadSize | |
26 #else | |
27 #define MAYBE_AllocateBadSize AllocateBadSize | |
28 #endif | |
29 | |
14 using ::testing::_; | 30 using ::testing::_; |
15 using ::testing::AnyNumber; | 31 using ::testing::AnyNumber; |
16 using ::testing::Return; | 32 using ::testing::Return; |
17 using ::testing::AtLeast; | 33 using ::testing::AtLeast; |
18 | 34 |
19 namespace media { | 35 namespace media { |
20 | 36 |
21 class MockFrameObserver: public media::VideoCaptureDevice::EventHandler { | 37 class MockFrameObserver: public media::VideoCaptureDevice::EventHandler { |
dmac
2011/10/14 23:31:35
space between r and :
mflodman_chromium_OOO
2011/10/16 21:58:38
Done.
| |
22 public: | 38 public: |
23 MOCK_METHOD0(OnErr, void()); | 39 MOCK_METHOD0(OnErr, void()); |
24 MOCK_METHOD3(OnFrameInfo, void(int width, int height, int frame_rate)); | 40 MOCK_METHOD3(OnFrameInfo, void(int width, int height, int frame_rate)); |
25 | 41 |
26 explicit MockFrameObserver(base::WaitableEvent* wait_event) | 42 explicit MockFrameObserver(base::WaitableEvent* wait_event) |
27 : wait_event_(wait_event) {} | 43 : wait_event_(wait_event) {} |
28 | 44 |
29 virtual void OnError() OVERRIDE { | 45 virtual void OnError() OVERRIDE { |
30 OnErr(); | 46 OnErr(); |
31 } | 47 } |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
82 | 98 |
83 // Get info about the new resolution. | 99 // Get info about the new resolution. |
84 EXPECT_CALL(*frame_observer_, OnFrameInfo(640, 480, 30)) | 100 EXPECT_CALL(*frame_observer_, OnFrameInfo(640, 480, 30)) |
85 .Times(1); | 101 .Times(1); |
86 | 102 |
87 EXPECT_CALL(*frame_observer_, OnErr()) | 103 EXPECT_CALL(*frame_observer_, OnErr()) |
88 .Times(0); | 104 .Times(0); |
89 | 105 |
90 device->Allocate(640, 480, 30, frame_observer_.get()); | 106 device->Allocate(640, 480, 30, frame_observer_.get()); |
91 device->Start(); | 107 device->Start(); |
92 // Wait for 3s or for captured frame. | 108 // Get captured video frames. |
109 ExecuteRunLoop(); | |
dmac
2011/10/14 23:31:35
Have you considered using a MessageLoop (new Messa
mflodman_chromium_OOO
2011/10/16 21:58:38
I wasn't aware of the MessageLoopForUI, thanks for
| |
93 EXPECT_TRUE(wait_event_.TimedWait(base::TimeDelta::FromMilliseconds( | 110 EXPECT_TRUE(wait_event_.TimedWait(base::TimeDelta::FromMilliseconds( |
94 TestTimeouts::action_max_timeout_ms()))); | 111 TestTimeouts::action_max_timeout_ms()))); |
95 device->Stop(); | 112 device->Stop(); |
96 device->DeAllocate(); | 113 device->DeAllocate(); |
97 } | 114 } |
98 | 115 |
99 TEST_F(VideoCaptureDeviceTest, Capture720p) { | 116 TEST_F(VideoCaptureDeviceTest, Capture720p) { |
100 VideoCaptureDevice::GetDeviceNames(&names_); | 117 VideoCaptureDevice::GetDeviceNames(&names_); |
101 if (!names_.size()) { | 118 if (!names_.size()) { |
102 LOG(WARNING) << "No camera available. Exiting test."; | 119 LOG(WARNING) << "No camera available. Exiting test."; |
103 return; | 120 return; |
104 } | 121 } |
105 | 122 |
106 scoped_ptr<VideoCaptureDevice> device( | 123 scoped_ptr<VideoCaptureDevice> device( |
107 VideoCaptureDevice::Create(names_.front())); | 124 VideoCaptureDevice::Create(names_.front())); |
108 ASSERT_FALSE(device.get() == NULL); | 125 ASSERT_FALSE(device.get() == NULL); |
109 | 126 |
110 // Get info about the new resolution. | 127 // Get info about the new resolution. |
111 // We don't care about the resulting resolution or frame rate as it might | 128 // We don't care about the resulting resolution or frame rate as it might |
112 // be different from one machine to the next. | 129 // be different from one machine to the next. |
113 EXPECT_CALL(*frame_observer_, OnFrameInfo(_, _, _)) | 130 EXPECT_CALL(*frame_observer_, OnFrameInfo(_, _, _)) |
114 .Times(1); | 131 .Times(1); |
115 | 132 |
116 EXPECT_CALL(*frame_observer_, OnErr()) | 133 EXPECT_CALL(*frame_observer_, OnErr()) |
117 .Times(0); | 134 .Times(0); |
118 | 135 |
119 device->Allocate(1280, 720, 30, frame_observer_.get()); | 136 device->Allocate(1280, 720, 30, frame_observer_.get()); |
120 device->Start(); | 137 device->Start(); |
121 // Get captured video frames. | 138 // Get captured video frames. |
139 ExecuteRunLoop(); | |
122 EXPECT_TRUE(wait_event_.TimedWait(base::TimeDelta::FromMilliseconds( | 140 EXPECT_TRUE(wait_event_.TimedWait(base::TimeDelta::FromMilliseconds( |
123 TestTimeouts::action_max_timeout_ms()))); | 141 TestTimeouts::action_max_timeout_ms()))); |
124 device->Stop(); | 142 device->Stop(); |
125 device->DeAllocate(); | 143 device->DeAllocate(); |
126 } | 144 } |
127 | 145 |
128 TEST_F(VideoCaptureDeviceTest, AllocateSameCameraTwice) { | 146 TEST_F(VideoCaptureDeviceTest, MAYBE_AllocateSameCameraTwice) { |
129 VideoCaptureDevice::GetDeviceNames(&names_); | 147 VideoCaptureDevice::GetDeviceNames(&names_); |
130 if (!names_.size()) { | 148 if (!names_.size()) { |
131 LOG(WARNING) << "No camera available. Exiting test."; | 149 LOG(WARNING) << "No camera available. Exiting test."; |
132 return; | 150 return; |
133 } | 151 } |
134 scoped_ptr<VideoCaptureDevice> device1( | 152 scoped_ptr<VideoCaptureDevice> device1( |
135 VideoCaptureDevice::Create(names_.front())); | 153 VideoCaptureDevice::Create(names_.front())); |
136 ASSERT_TRUE(device1.get() != NULL); | 154 ASSERT_TRUE(device1.get() != NULL); |
137 | 155 |
138 scoped_ptr<VideoCaptureDevice> device2( | 156 scoped_ptr<VideoCaptureDevice> device2( |
139 VideoCaptureDevice::Create(names_.front())); | 157 VideoCaptureDevice::Create(names_.front())); |
140 ASSERT_TRUE(device2.get() != NULL); | 158 ASSERT_TRUE(device2.get() != NULL); |
141 | 159 |
142 // 1. Get info about the new resolution on the first allocated camera | 160 // 1. Get info about the new resolution on the first allocated camera |
143 EXPECT_CALL(*frame_observer_, OnFrameInfo(640, 480, 30)); | 161 EXPECT_CALL(*frame_observer_, OnFrameInfo(640, 480, 30)); |
144 | 162 |
145 device1->Allocate(640, 480, 30, frame_observer_.get()); | 163 device1->Allocate(640, 480, 30, frame_observer_.get()); |
146 | 164 |
147 // 2. Error when trying to allocate the same camera again. | 165 // 2. Error when trying to allocate the same camera again. |
148 EXPECT_CALL(*frame_observer_, OnErr()); | 166 EXPECT_CALL(*frame_observer_, OnErr()); |
149 device2->Allocate(640, 480, 30, frame_observer_.get()); | 167 device2->Allocate(640, 480, 30, frame_observer_.get()); |
150 | 168 |
151 device1->DeAllocate(); | 169 device1->DeAllocate(); |
152 device2->DeAllocate(); | 170 device2->DeAllocate(); |
153 } | 171 } |
154 | 172 |
155 TEST_F(VideoCaptureDeviceTest, AllocateBadSize) { | 173 TEST_F(VideoCaptureDeviceTest, MAYBE_AllocateBadSize) { |
156 VideoCaptureDevice::GetDeviceNames(&names_); | 174 VideoCaptureDevice::GetDeviceNames(&names_); |
157 if (!names_.size()) { | 175 if (!names_.size()) { |
158 LOG(WARNING) << "No camera available. Exiting test."; | 176 LOG(WARNING) << "No camera available. Exiting test."; |
159 return; | 177 return; |
160 } | 178 } |
161 scoped_ptr<VideoCaptureDevice> device( | 179 scoped_ptr<VideoCaptureDevice> device( |
162 VideoCaptureDevice::Create(names_.front())); | 180 VideoCaptureDevice::Create(names_.front())); |
163 ASSERT_TRUE(device.get() != NULL); | 181 ASSERT_TRUE(device.get() != NULL); |
164 | 182 |
165 EXPECT_CALL(*frame_observer_, OnErr()) | 183 EXPECT_CALL(*frame_observer_, OnErr()) |
(...skipping 26 matching lines...) Expand all Loading... | |
192 device->Allocate(640, 480, 30, frame_observer_.get()); | 210 device->Allocate(640, 480, 30, frame_observer_.get()); |
193 device->Start(); | 211 device->Start(); |
194 // Nothing shall happen. | 212 // Nothing shall happen. |
195 device->Allocate(1280, 1024, 30, frame_observer_.get()); | 213 device->Allocate(1280, 1024, 30, frame_observer_.get()); |
196 device->DeAllocate(); | 214 device->DeAllocate(); |
197 // Allocate new size 320, 240 | 215 // Allocate new size 320, 240 |
198 device->Allocate(320, 240, 30, frame_observer_.get()); | 216 device->Allocate(320, 240, 30, frame_observer_.get()); |
199 | 217 |
200 device->Start(); | 218 device->Start(); |
201 // Get captured video frames. | 219 // Get captured video frames. |
220 ExecuteRunLoop(); | |
202 EXPECT_TRUE(wait_event_.TimedWait(base::TimeDelta::FromMilliseconds( | 221 EXPECT_TRUE(wait_event_.TimedWait(base::TimeDelta::FromMilliseconds( |
203 TestTimeouts::action_max_timeout_ms()))); | 222 TestTimeouts::action_max_timeout_ms()))); |
204 device->Stop(); | 223 device->Stop(); |
205 device->DeAllocate(); | 224 device->DeAllocate(); |
206 } | 225 } |
207 | 226 |
208 TEST_F(VideoCaptureDeviceTest, DeAllocateCameraWhileRunning) { | 227 TEST_F(VideoCaptureDeviceTest, DeAllocateCameraWhileRunning) { |
209 VideoCaptureDevice::GetDeviceNames(&names_); | 228 VideoCaptureDevice::GetDeviceNames(&names_); |
210 if (!names_.size()) { | 229 if (!names_.size()) { |
211 LOG(WARNING) << "No camera available. Exiting test."; | 230 LOG(WARNING) << "No camera available. Exiting test."; |
212 return; | 231 return; |
213 } | 232 } |
214 scoped_ptr<VideoCaptureDevice> device( | 233 scoped_ptr<VideoCaptureDevice> device( |
215 VideoCaptureDevice::Create(names_.front())); | 234 VideoCaptureDevice::Create(names_.front())); |
216 ASSERT_TRUE(device.get() != NULL); | 235 ASSERT_TRUE(device.get() != NULL); |
217 | 236 |
218 EXPECT_CALL(*frame_observer_, OnErr()) | 237 EXPECT_CALL(*frame_observer_, OnErr()) |
219 .Times(0); | 238 .Times(0); |
220 // Get info about the new resolution. | 239 // Get info about the new resolution. |
221 EXPECT_CALL(*frame_observer_, OnFrameInfo(640, 480, 30)); | 240 EXPECT_CALL(*frame_observer_, OnFrameInfo(640, 480, 30)); |
222 | 241 |
223 device->Allocate(640, 480, 30, frame_observer_.get()); | 242 device->Allocate(640, 480, 30, frame_observer_.get()); |
224 | 243 |
225 device->Start(); | 244 device->Start(); |
226 // Get captured video frames. | 245 // Get captured video frames. |
246 ExecuteRunLoop(); | |
227 EXPECT_TRUE(wait_event_.TimedWait(base::TimeDelta::FromMilliseconds( | 247 EXPECT_TRUE(wait_event_.TimedWait(base::TimeDelta::FromMilliseconds( |
228 TestTimeouts::action_max_timeout_ms()))); | 248 TestTimeouts::action_max_timeout_ms()))); |
229 device->DeAllocate(); | 249 device->DeAllocate(); |
230 } | 250 } |
231 | 251 |
232 TEST_F(VideoCaptureDeviceTest, TestFakeCapture) { | 252 TEST_F(VideoCaptureDeviceTest, TestFakeCapture) { |
233 VideoCaptureDevice::Names names; | 253 VideoCaptureDevice::Names names; |
234 | 254 |
235 FakeVideoCaptureDevice::GetDeviceNames(&names); | 255 FakeVideoCaptureDevice::GetDeviceNames(&names); |
236 | 256 |
(...skipping 13 matching lines...) Expand all Loading... | |
250 device->Allocate(640, 480, 30, frame_observer_.get()); | 270 device->Allocate(640, 480, 30, frame_observer_.get()); |
251 | 271 |
252 device->Start(); | 272 device->Start(); |
253 EXPECT_TRUE(wait_event_.TimedWait(base::TimeDelta::FromMilliseconds( | 273 EXPECT_TRUE(wait_event_.TimedWait(base::TimeDelta::FromMilliseconds( |
254 TestTimeouts::action_max_timeout_ms()))); | 274 TestTimeouts::action_max_timeout_ms()))); |
255 device->Stop(); | 275 device->Stop(); |
256 device->DeAllocate(); | 276 device->DeAllocate(); |
257 } | 277 } |
258 | 278 |
259 }; // namespace media | 279 }; // namespace media |
OLD | NEW |