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" |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
55 | 55 |
56 virtual void TearDown() { | 56 virtual void TearDown() { |
57 } | 57 } |
58 | 58 |
59 base::WaitableEvent wait_event_; | 59 base::WaitableEvent wait_event_; |
60 scoped_ptr<MockFrameObserver> frame_observer_; | 60 scoped_ptr<MockFrameObserver> frame_observer_; |
61 VideoCaptureDevice::Names names_; | 61 VideoCaptureDevice::Names names_; |
62 }; | 62 }; |
63 | 63 |
64 TEST_F(VideoCaptureDeviceTest, OpenInvalidDevice) { | 64 TEST_F(VideoCaptureDeviceTest, OpenInvalidDevice) { |
65 #if defined(OS_MACOSX) | |
scherkus (not reviewing)
2011/10/07 17:17:55
will these tests ever be supported?
if so you sho
mflodman_chromium_OOO
2011/10/10 12:56:52
Thanks, changed!
Yes, the plan is to support them
dmac
2011/10/11 00:25:47
Not to be annoying, but wouldn't it be better to w
| |
66 // Test not supported for Mac. | |
67 return; | |
68 #endif | |
65 VideoCaptureDevice::Name device_name; | 69 VideoCaptureDevice::Name device_name; |
66 device_name.device_name = "jibberish"; | 70 device_name.device_name = "jibberish"; |
67 device_name.unique_id = "jibberish"; | 71 device_name.unique_id = "jibberish"; |
68 VideoCaptureDevice* device = VideoCaptureDevice::Create(device_name); | 72 VideoCaptureDevice* device = VideoCaptureDevice::Create(device_name); |
69 EXPECT_TRUE(device == NULL); | 73 EXPECT_TRUE(device == NULL); |
70 } | 74 } |
71 | 75 |
72 TEST_F(VideoCaptureDeviceTest, CaptureVGA) { | 76 TEST_F(VideoCaptureDeviceTest, CaptureVGA) { |
77 #if defined(OS_MACOSX) | |
78 // Test not supported for Mac. | |
79 return; | |
80 #endif | |
73 VideoCaptureDevice::GetDeviceNames(&names_); | 81 VideoCaptureDevice::GetDeviceNames(&names_); |
74 if (!names_.size()) { | 82 if (!names_.size()) { |
75 LOG(WARNING) << "No camera available. Exiting test."; | 83 LOG(WARNING) << "No camera available. Exiting test."; |
76 return; | 84 return; |
77 } | 85 } |
78 | 86 |
79 scoped_ptr<VideoCaptureDevice> device( | 87 scoped_ptr<VideoCaptureDevice> device( |
80 VideoCaptureDevice::Create(names_.front())); | 88 VideoCaptureDevice::Create(names_.front())); |
81 ASSERT_FALSE(device.get() == NULL); | 89 ASSERT_FALSE(device.get() == NULL); |
82 | 90 |
83 // Get info about the new resolution. | 91 // Get info about the new resolution. |
84 EXPECT_CALL(*frame_observer_, OnFrameInfo(640, 480, 30)) | 92 EXPECT_CALL(*frame_observer_, OnFrameInfo(640, 480, 30)) |
85 .Times(1); | 93 .Times(1); |
86 | 94 |
87 EXPECT_CALL(*frame_observer_, OnErr()) | 95 EXPECT_CALL(*frame_observer_, OnErr()) |
88 .Times(0); | 96 .Times(0); |
89 | 97 |
90 device->Allocate(640, 480, 30, frame_observer_.get()); | 98 device->Allocate(640, 480, 30, frame_observer_.get()); |
91 device->Start(); | 99 device->Start(); |
92 // Wait for 3s or for captured frame. | 100 // Wait for 3s or for captured frame. |
93 EXPECT_TRUE(wait_event_.TimedWait(base::TimeDelta::FromMilliseconds( | 101 EXPECT_TRUE(wait_event_.TimedWait(base::TimeDelta::FromMilliseconds( |
94 TestTimeouts::action_max_timeout_ms()))); | 102 TestTimeouts::action_max_timeout_ms()))); |
95 device->Stop(); | 103 device->Stop(); |
96 device->DeAllocate(); | 104 device->DeAllocate(); |
97 } | 105 } |
98 | 106 |
99 TEST_F(VideoCaptureDeviceTest, Capture720p) { | 107 TEST_F(VideoCaptureDeviceTest, Capture720p) { |
108 #if defined(OS_MACOSX) | |
109 // Test not supported for Mac. | |
110 return; | |
111 #endif | |
100 VideoCaptureDevice::GetDeviceNames(&names_); | 112 VideoCaptureDevice::GetDeviceNames(&names_); |
101 if (!names_.size()) { | 113 if (!names_.size()) { |
102 LOG(WARNING) << "No camera available. Exiting test."; | 114 LOG(WARNING) << "No camera available. Exiting test."; |
103 return; | 115 return; |
104 } | 116 } |
105 | 117 |
106 scoped_ptr<VideoCaptureDevice> device( | 118 scoped_ptr<VideoCaptureDevice> device( |
107 VideoCaptureDevice::Create(names_.front())); | 119 VideoCaptureDevice::Create(names_.front())); |
108 ASSERT_FALSE(device.get() == NULL); | 120 ASSERT_FALSE(device.get() == NULL); |
109 | 121 |
110 // Get info about the new resolution. | 122 // Get info about the new resolution. |
111 // We don't care about the resulting resolution or frame rate as it might | 123 // We don't care about the resulting resolution or frame rate as it might |
112 // be different from one machine to the next. | 124 // be different from one machine to the next. |
113 EXPECT_CALL(*frame_observer_, OnFrameInfo(_, _, _)) | 125 EXPECT_CALL(*frame_observer_, OnFrameInfo(_, _, _)) |
114 .Times(1); | 126 .Times(1); |
115 | 127 |
116 EXPECT_CALL(*frame_observer_, OnErr()) | 128 EXPECT_CALL(*frame_observer_, OnErr()) |
117 .Times(0); | 129 .Times(0); |
118 | 130 |
119 device->Allocate(1280, 720, 30, frame_observer_.get()); | 131 device->Allocate(1280, 720, 30, frame_observer_.get()); |
120 device->Start(); | 132 device->Start(); |
121 // Get captured video frames. | 133 // Get captured video frames. |
122 EXPECT_TRUE(wait_event_.TimedWait(base::TimeDelta::FromMilliseconds( | 134 EXPECT_TRUE(wait_event_.TimedWait(base::TimeDelta::FromMilliseconds( |
123 TestTimeouts::action_max_timeout_ms()))); | 135 TestTimeouts::action_max_timeout_ms()))); |
124 device->Stop(); | 136 device->Stop(); |
125 device->DeAllocate(); | 137 device->DeAllocate(); |
126 } | 138 } |
127 | 139 |
128 TEST_F(VideoCaptureDeviceTest, AllocateSameCameraTwice) { | 140 TEST_F(VideoCaptureDeviceTest, AllocateSameCameraTwice) { |
141 #if defined(OS_MACOSX) | |
142 // Test not supported for Mac. | |
143 return; | |
144 #endif | |
129 VideoCaptureDevice::GetDeviceNames(&names_); | 145 VideoCaptureDevice::GetDeviceNames(&names_); |
130 if (!names_.size()) { | 146 if (!names_.size()) { |
131 LOG(WARNING) << "No camera available. Exiting test."; | 147 LOG(WARNING) << "No camera available. Exiting test."; |
132 return; | 148 return; |
133 } | 149 } |
134 scoped_ptr<VideoCaptureDevice> device1( | 150 scoped_ptr<VideoCaptureDevice> device1( |
135 VideoCaptureDevice::Create(names_.front())); | 151 VideoCaptureDevice::Create(names_.front())); |
136 ASSERT_TRUE(device1.get() != NULL); | 152 ASSERT_TRUE(device1.get() != NULL); |
137 | 153 |
138 scoped_ptr<VideoCaptureDevice> device2( | 154 scoped_ptr<VideoCaptureDevice> device2( |
139 VideoCaptureDevice::Create(names_.front())); | 155 VideoCaptureDevice::Create(names_.front())); |
140 ASSERT_TRUE(device2.get() != NULL); | 156 ASSERT_TRUE(device2.get() != NULL); |
141 | 157 |
142 // 1. Get info about the new resolution on the first allocated camera | 158 // 1. Get info about the new resolution on the first allocated camera |
143 EXPECT_CALL(*frame_observer_, OnFrameInfo(640, 480, 30)); | 159 EXPECT_CALL(*frame_observer_, OnFrameInfo(640, 480, 30)); |
144 | 160 |
145 device1->Allocate(640, 480, 30, frame_observer_.get()); | 161 device1->Allocate(640, 480, 30, frame_observer_.get()); |
146 | 162 |
147 // 2. Error when trying to allocate the same camera again. | 163 // 2. Error when trying to allocate the same camera again. |
148 EXPECT_CALL(*frame_observer_, OnErr()); | 164 EXPECT_CALL(*frame_observer_, OnErr()); |
149 device2->Allocate(640, 480, 30, frame_observer_.get()); | 165 device2->Allocate(640, 480, 30, frame_observer_.get()); |
150 | 166 |
151 device1->DeAllocate(); | 167 device1->DeAllocate(); |
152 device2->DeAllocate(); | 168 device2->DeAllocate(); |
153 } | 169 } |
154 | 170 |
155 TEST_F(VideoCaptureDeviceTest, AllocateBadSize) { | 171 TEST_F(VideoCaptureDeviceTest, AllocateBadSize) { |
172 #if defined(OS_MACOSX) | |
173 // Test not supported for Mac. | |
174 return; | |
175 #endif | |
156 VideoCaptureDevice::GetDeviceNames(&names_); | 176 VideoCaptureDevice::GetDeviceNames(&names_); |
157 if (!names_.size()) { | 177 if (!names_.size()) { |
158 LOG(WARNING) << "No camera available. Exiting test."; | 178 LOG(WARNING) << "No camera available. Exiting test."; |
159 return; | 179 return; |
160 } | 180 } |
161 scoped_ptr<VideoCaptureDevice> device( | 181 scoped_ptr<VideoCaptureDevice> device( |
162 VideoCaptureDevice::Create(names_.front())); | 182 VideoCaptureDevice::Create(names_.front())); |
163 ASSERT_TRUE(device.get() != NULL); | 183 ASSERT_TRUE(device.get() != NULL); |
164 | 184 |
165 EXPECT_CALL(*frame_observer_, OnErr()) | 185 EXPECT_CALL(*frame_observer_, OnErr()) |
166 .Times(0); | 186 .Times(0); |
167 | 187 |
168 // get info about the new resolution | 188 // get info about the new resolution |
169 EXPECT_CALL(*frame_observer_, OnFrameInfo(640, 480 , _)) | 189 EXPECT_CALL(*frame_observer_, OnFrameInfo(640, 480 , _)) |
170 .Times(AtLeast(1)); | 190 .Times(AtLeast(1)); |
171 | 191 |
172 device->Allocate(637, 472, 35, frame_observer_.get()); | 192 device->Allocate(637, 472, 35, frame_observer_.get()); |
173 device->DeAllocate(); | 193 device->DeAllocate(); |
174 } | 194 } |
175 | 195 |
176 TEST_F(VideoCaptureDeviceTest, ReAllocateCamera) { | 196 TEST_F(VideoCaptureDeviceTest, ReAllocateCamera) { |
197 #if defined(OS_MACOSX) | |
198 // Test not supported for Mac. | |
199 return; | |
200 #endif | |
177 VideoCaptureDevice::GetDeviceNames(&names_); | 201 VideoCaptureDevice::GetDeviceNames(&names_); |
178 if (!names_.size()) { | 202 if (!names_.size()) { |
179 LOG(WARNING) << "No camera available. Exiting test."; | 203 LOG(WARNING) << "No camera available. Exiting test."; |
180 return; | 204 return; |
181 } | 205 } |
182 scoped_ptr<VideoCaptureDevice> device( | 206 scoped_ptr<VideoCaptureDevice> device( |
183 VideoCaptureDevice::Create(names_.front())); | 207 VideoCaptureDevice::Create(names_.front())); |
184 ASSERT_TRUE(device.get() != NULL); | 208 ASSERT_TRUE(device.get() != NULL); |
185 EXPECT_CALL(*frame_observer_, OnErr()) | 209 EXPECT_CALL(*frame_observer_, OnErr()) |
186 .Times(0); | 210 .Times(0); |
(...skipping 12 matching lines...) Expand all Loading... | |
199 | 223 |
200 device->Start(); | 224 device->Start(); |
201 // Get captured video frames. | 225 // Get captured video frames. |
202 EXPECT_TRUE(wait_event_.TimedWait(base::TimeDelta::FromMilliseconds( | 226 EXPECT_TRUE(wait_event_.TimedWait(base::TimeDelta::FromMilliseconds( |
203 TestTimeouts::action_max_timeout_ms()))); | 227 TestTimeouts::action_max_timeout_ms()))); |
204 device->Stop(); | 228 device->Stop(); |
205 device->DeAllocate(); | 229 device->DeAllocate(); |
206 } | 230 } |
207 | 231 |
208 TEST_F(VideoCaptureDeviceTest, DeAllocateCameraWhileRunning) { | 232 TEST_F(VideoCaptureDeviceTest, DeAllocateCameraWhileRunning) { |
233 #if defined(OS_MACOSX) | |
234 // Test not supported for Mac. | |
235 return; | |
236 #endif | |
209 VideoCaptureDevice::GetDeviceNames(&names_); | 237 VideoCaptureDevice::GetDeviceNames(&names_); |
210 if (!names_.size()) { | 238 if (!names_.size()) { |
211 LOG(WARNING) << "No camera available. Exiting test."; | 239 LOG(WARNING) << "No camera available. Exiting test."; |
212 return; | 240 return; |
213 } | 241 } |
214 scoped_ptr<VideoCaptureDevice> device( | 242 scoped_ptr<VideoCaptureDevice> device( |
215 VideoCaptureDevice::Create(names_.front())); | 243 VideoCaptureDevice::Create(names_.front())); |
216 ASSERT_TRUE(device.get() != NULL); | 244 ASSERT_TRUE(device.get() != NULL); |
217 | 245 |
218 EXPECT_CALL(*frame_observer_, OnErr()) | 246 EXPECT_CALL(*frame_observer_, OnErr()) |
219 .Times(0); | 247 .Times(0); |
220 // Get info about the new resolution. | 248 // Get info about the new resolution. |
221 EXPECT_CALL(*frame_observer_, OnFrameInfo(640, 480, 30)); | 249 EXPECT_CALL(*frame_observer_, OnFrameInfo(640, 480, 30)); |
222 | 250 |
223 device->Allocate(640, 480, 30, frame_observer_.get()); | 251 device->Allocate(640, 480, 30, frame_observer_.get()); |
224 | 252 |
225 device->Start(); | 253 device->Start(); |
226 // Get captured video frames. | 254 // Get captured video frames. |
227 EXPECT_TRUE(wait_event_.TimedWait(base::TimeDelta::FromMilliseconds( | 255 EXPECT_TRUE(wait_event_.TimedWait(base::TimeDelta::FromMilliseconds( |
228 TestTimeouts::action_max_timeout_ms()))); | 256 TestTimeouts::action_max_timeout_ms()))); |
229 device->DeAllocate(); | 257 device->DeAllocate(); |
230 } | 258 } |
231 | 259 |
232 TEST_F(VideoCaptureDeviceTest, TestFakeCapture) { | 260 TEST_F(VideoCaptureDeviceTest, TestFakeCapture) { |
261 #if defined(OS_MACOSX) | |
262 // Test not supported for Mac. | |
263 return; | |
264 #endif | |
233 VideoCaptureDevice::Names names; | 265 VideoCaptureDevice::Names names; |
234 | 266 |
235 FakeVideoCaptureDevice::GetDeviceNames(&names); | 267 FakeVideoCaptureDevice::GetDeviceNames(&names); |
236 | 268 |
237 ASSERT_GT(static_cast<int>(names.size()), 0); | 269 ASSERT_GT(static_cast<int>(names.size()), 0); |
238 | 270 |
239 scoped_ptr<VideoCaptureDevice> device( | 271 scoped_ptr<VideoCaptureDevice> device( |
240 FakeVideoCaptureDevice::Create(names.front())); | 272 FakeVideoCaptureDevice::Create(names.front())); |
241 ASSERT_TRUE(device.get() != NULL); | 273 ASSERT_TRUE(device.get() != NULL); |
242 | 274 |
243 // Get info about the new resolution. | 275 // Get info about the new resolution. |
244 EXPECT_CALL(*frame_observer_, OnFrameInfo(640, 480, 30)) | 276 EXPECT_CALL(*frame_observer_, OnFrameInfo(640, 480, 30)) |
245 .Times(1); | 277 .Times(1); |
246 | 278 |
247 EXPECT_CALL(*frame_observer_, OnErr()) | 279 EXPECT_CALL(*frame_observer_, OnErr()) |
248 .Times(0); | 280 .Times(0); |
249 | 281 |
250 device->Allocate(640, 480, 30, frame_observer_.get()); | 282 device->Allocate(640, 480, 30, frame_observer_.get()); |
251 | 283 |
252 device->Start(); | 284 device->Start(); |
253 EXPECT_TRUE(wait_event_.TimedWait(base::TimeDelta::FromMilliseconds( | 285 EXPECT_TRUE(wait_event_.TimedWait(base::TimeDelta::FromMilliseconds( |
254 TestTimeouts::action_max_timeout_ms()))); | 286 TestTimeouts::action_max_timeout_ms()))); |
255 device->Stop(); | 287 device->Stop(); |
256 device->DeAllocate(); | 288 device->DeAllocate(); |
257 } | 289 } |
258 | 290 |
259 }; // namespace media | 291 }; // namespace media |
OLD | NEW |