| 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/threading/thread.h" | 8 #include "base/threading/thread.h" |
| 8 #include "media/video/capture/fake_video_capture_device.h" | 9 #include "media/video/capture/fake_video_capture_device.h" |
| 9 #include "media/video/capture/video_capture_device.h" | 10 #include "media/video/capture/video_capture_device.h" |
| 10 #include "testing/gmock/include/gmock/gmock.h" | 11 #include "testing/gmock/include/gmock/gmock.h" |
| 11 #include "testing/gtest/include/gtest/gtest.h" | 12 #include "testing/gtest/include/gtest/gtest.h" |
| 12 | 13 |
| 13 using ::testing::_; | 14 using ::testing::_; |
| 14 using ::testing::AnyNumber; | 15 using ::testing::AnyNumber; |
| 15 using ::testing::Return; | 16 using ::testing::Return; |
| 16 using ::testing::AtLeast; | 17 using ::testing::AtLeast; |
| 17 | 18 |
| 18 namespace media { | 19 namespace media { |
| 19 const int kWaitTime = 3000; | |
| 20 | 20 |
| 21 class MockFrameObserver: public media::VideoCaptureDevice::EventHandler { | 21 class MockFrameObserver: public media::VideoCaptureDevice::EventHandler { |
| 22 public: | 22 public: |
| 23 MOCK_METHOD0(OnErr, void()); | 23 MOCK_METHOD0(OnErr, void()); |
| 24 MOCK_METHOD3(OnFrameInfo, void(int width, int height, int frame_rate)); | 24 MOCK_METHOD3(OnFrameInfo, void(int width, int height, int frame_rate)); |
| 25 | 25 |
| 26 explicit MockFrameObserver(base::WaitableEvent* wait_event) | 26 explicit MockFrameObserver(base::WaitableEvent* wait_event) |
| 27 : wait_event_(wait_event) {} | 27 : wait_event_(wait_event) {} |
| 28 | 28 |
| 29 virtual void OnError() OVERRIDE { | 29 virtual void OnError() OVERRIDE { |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 62 }; | 62 }; |
| 63 | 63 |
| 64 TEST_F(VideoCaptureDeviceTest, OpenInvalidDevice) { | 64 TEST_F(VideoCaptureDeviceTest, OpenInvalidDevice) { |
| 65 VideoCaptureDevice::Name device_name; | 65 VideoCaptureDevice::Name device_name; |
| 66 device_name.device_name = "jibberish"; | 66 device_name.device_name = "jibberish"; |
| 67 device_name.unique_id = "jibberish"; | 67 device_name.unique_id = "jibberish"; |
| 68 VideoCaptureDevice* device = VideoCaptureDevice::Create(device_name); | 68 VideoCaptureDevice* device = VideoCaptureDevice::Create(device_name); |
| 69 EXPECT_TRUE(device == NULL); | 69 EXPECT_TRUE(device == NULL); |
| 70 } | 70 } |
| 71 | 71 |
| 72 TEST_F(VideoCaptureDeviceTest, CaptureVGA) { | 72 // TODO(perkj): This test is disabled due to stability problem with certain |
| 73 // cameras. http://www.crbug.com/94134 |
| 74 TEST_F(VideoCaptureDeviceTest, DISABLED_CaptureVGA) { |
| 73 VideoCaptureDevice::GetDeviceNames(&names_); | 75 VideoCaptureDevice::GetDeviceNames(&names_); |
| 74 // Make sure there are more than 0 cameras. | |
| 75 if (!names_.size()) { | 76 if (!names_.size()) { |
| 76 LOG(WARNING) << "No camera available. Exiting test."; | 77 LOG(WARNING) << "No camera available. Exiting test."; |
| 77 return; | 78 return; |
| 78 } | 79 } |
| 79 | 80 |
| 80 scoped_ptr<VideoCaptureDevice> device( | 81 scoped_ptr<VideoCaptureDevice> device( |
| 81 VideoCaptureDevice::Create(names_.front())); | 82 VideoCaptureDevice::Create(names_.front())); |
| 82 ASSERT_FALSE(device.get() == NULL); | 83 ASSERT_FALSE(device.get() == NULL); |
| 83 | 84 |
| 84 // Get info about the new resolution. | 85 // Get info about the new resolution. |
| 85 EXPECT_CALL(*frame_observer_, OnFrameInfo(640, 480, 30)) | 86 EXPECT_CALL(*frame_observer_, OnFrameInfo(640, 480, 30)) |
| 86 .Times(1); | 87 .Times(1); |
| 87 | 88 |
| 88 EXPECT_CALL(*frame_observer_, OnErr()) | 89 EXPECT_CALL(*frame_observer_, OnErr()) |
| 89 .Times(0); | 90 .Times(0); |
| 90 | 91 |
| 91 device->Allocate(640, 480, 30, frame_observer_.get()); | 92 device->Allocate(640, 480, 30, frame_observer_.get()); |
| 92 device->Start(); | 93 device->Start(); |
| 93 // Wait for 3s or for captured frame. | 94 // Wait for 3s or for captured frame. |
| 94 EXPECT_TRUE(wait_event_.TimedWait( | 95 EXPECT_TRUE(wait_event_.TimedWait(base::TimeDelta::FromMilliseconds( |
| 95 base::TimeDelta::FromMilliseconds(kWaitTime))); | 96 TestTimeouts::action_max_timeout_ms()))); |
| 96 device->Stop(); | 97 device->Stop(); |
| 97 device->DeAllocate(); | 98 device->DeAllocate(); |
| 98 } | 99 } |
| 99 | 100 |
| 100 TEST_F(VideoCaptureDeviceTest, Capture720p) { | 101 // TODO(perkj): This test is disabled due to stability problem with certain |
| 102 // cameras. http://www.crbug.com/94134 |
| 103 TEST_F(VideoCaptureDeviceTest, DISABLED_Capture720p) { |
| 101 VideoCaptureDevice::GetDeviceNames(&names_); | 104 VideoCaptureDevice::GetDeviceNames(&names_); |
| 102 // Make sure there are more than 0 cameras. | |
| 103 if (!names_.size()) { | 105 if (!names_.size()) { |
| 104 LOG(WARNING) << "No camera available. Exiting test."; | 106 LOG(WARNING) << "No camera available. Exiting test."; |
| 105 return; | 107 return; |
| 106 } | 108 } |
| 107 | 109 |
| 108 scoped_ptr<VideoCaptureDevice> device( | 110 scoped_ptr<VideoCaptureDevice> device( |
| 109 VideoCaptureDevice::Create(names_.front())); | 111 VideoCaptureDevice::Create(names_.front())); |
| 110 ASSERT_FALSE(device.get() == NULL); | 112 ASSERT_FALSE(device.get() == NULL); |
| 111 | 113 |
| 112 // Get info about the new resolution. | 114 // Get info about the new resolution. |
| 113 // We don't care about the resulting resolution or frame rate as it might | 115 // We don't care about the resulting resolution or frame rate as it might |
| 114 // be different from one machine to the next. | 116 // be different from one machine to the next. |
| 115 EXPECT_CALL(*frame_observer_, OnFrameInfo(_, _, _)) | 117 EXPECT_CALL(*frame_observer_, OnFrameInfo(_, _, _)) |
| 116 .Times(1); | 118 .Times(1); |
| 117 | 119 |
| 118 EXPECT_CALL(*frame_observer_, OnErr()) | 120 EXPECT_CALL(*frame_observer_, OnErr()) |
| 119 .Times(0); | 121 .Times(0); |
| 120 | 122 |
| 121 device->Allocate(1280, 720, 30, frame_observer_.get()); | 123 device->Allocate(1280, 720, 30, frame_observer_.get()); |
| 122 device->Start(); | 124 device->Start(); |
| 123 // Get captured video frames. | 125 // Get captured video frames. |
| 124 EXPECT_TRUE(wait_event_.TimedWait( | 126 EXPECT_TRUE(wait_event_.TimedWait(base::TimeDelta::FromMilliseconds( |
| 125 base::TimeDelta::FromMilliseconds(kWaitTime))); | 127 TestTimeouts::action_max_timeout_ms()))); |
| 126 device->Stop(); | 128 device->Stop(); |
| 127 device->DeAllocate(); | 129 device->DeAllocate(); |
| 128 } | 130 } |
| 129 | 131 |
| 130 TEST_F(VideoCaptureDeviceTest, AllocateSameCameraTwice) { | 132 // TODO(perkj): This test is disabled due to stability problem with certain |
| 133 // cameras. http://www.crbug.com/94134 |
| 134 TEST_F(VideoCaptureDeviceTest, DISABLED_AllocateSameCameraTwice) { |
| 131 VideoCaptureDevice::GetDeviceNames(&names_); | 135 VideoCaptureDevice::GetDeviceNames(&names_); |
| 132 if (!names_.size()) { | 136 if (!names_.size()) { |
| 133 LOG(WARNING) << "No camera available. Exiting test."; | 137 LOG(WARNING) << "No camera available. Exiting test."; |
| 134 return; | 138 return; |
| 135 } | 139 } |
| 136 scoped_ptr<VideoCaptureDevice> device1( | 140 scoped_ptr<VideoCaptureDevice> device1( |
| 137 VideoCaptureDevice::Create(names_.front())); | 141 VideoCaptureDevice::Create(names_.front())); |
| 138 ASSERT_TRUE(device1.get() != NULL); | 142 ASSERT_TRUE(device1.get() != NULL); |
| 139 | 143 |
| 140 scoped_ptr<VideoCaptureDevice> device2( | 144 scoped_ptr<VideoCaptureDevice> device2( |
| 141 VideoCaptureDevice::Create(names_.front())); | 145 VideoCaptureDevice::Create(names_.front())); |
| 142 ASSERT_TRUE(device2.get() != NULL); | 146 ASSERT_TRUE(device2.get() != NULL); |
| 143 | 147 |
| 144 // 1. Get info about the new resolution on the first allocated camera | 148 // 1. Get info about the new resolution on the first allocated camera |
| 145 EXPECT_CALL(*frame_observer_, OnFrameInfo(640, 480, 30)); | 149 EXPECT_CALL(*frame_observer_, OnFrameInfo(640, 480, 30)); |
| 146 | 150 |
| 147 device1->Allocate(640, 480, 30, frame_observer_.get()); | 151 device1->Allocate(640, 480, 30, frame_observer_.get()); |
| 148 | 152 |
| 149 // 2. Error when trying to allocate the same camera again. | 153 // 2. Error when trying to allocate the same camera again. |
| 150 EXPECT_CALL(*frame_observer_, OnErr()); | 154 EXPECT_CALL(*frame_observer_, OnErr()); |
| 151 device2->Allocate(640, 480, 30, frame_observer_.get()); | 155 device2->Allocate(640, 480, 30, frame_observer_.get()); |
| 152 | 156 |
| 153 device1->DeAllocate(); | 157 device1->DeAllocate(); |
| 154 device2->DeAllocate(); | 158 device2->DeAllocate(); |
| 155 } | 159 } |
| 156 | 160 |
| 157 TEST_F(VideoCaptureDeviceTest, AllocateBadSize) { | 161 // TODO(perkj): This test is disabled due to stability problem with certain |
| 162 // cameras. http://www.crbug.com/94134 |
| 163 TEST_F(VideoCaptureDeviceTest, DISABLED_AllocateBadSize) { |
| 158 VideoCaptureDevice::GetDeviceNames(&names_); | 164 VideoCaptureDevice::GetDeviceNames(&names_); |
| 159 if (!names_.size()) { | 165 if (!names_.size()) { |
| 160 LOG(WARNING) << "No camera available. Exiting test."; | 166 LOG(WARNING) << "No camera available. Exiting test."; |
| 161 return; | 167 return; |
| 162 } | 168 } |
| 163 scoped_ptr<VideoCaptureDevice> device( | 169 scoped_ptr<VideoCaptureDevice> device( |
| 164 VideoCaptureDevice::Create(names_.front())); | 170 VideoCaptureDevice::Create(names_.front())); |
| 165 ASSERT_TRUE(device.get() != NULL); | 171 ASSERT_TRUE(device.get() != NULL); |
| 166 | 172 |
| 167 EXPECT_CALL(*frame_observer_, OnErr()) | 173 EXPECT_CALL(*frame_observer_, OnErr()) |
| 168 .Times(0); | 174 .Times(0); |
| 169 | 175 |
| 170 // get info about the new resolution | 176 // get info about the new resolution |
| 171 EXPECT_CALL(*frame_observer_, OnFrameInfo(640, 480 , _)) | 177 EXPECT_CALL(*frame_observer_, OnFrameInfo(640, 480 , _)) |
| 172 .Times(AtLeast(1)); | 178 .Times(AtLeast(1)); |
| 173 | 179 |
| 174 device->Allocate(637, 472, 35, frame_observer_.get()); | 180 device->Allocate(637, 472, 35, frame_observer_.get()); |
| 175 device->DeAllocate(); | 181 device->DeAllocate(); |
| 176 } | 182 } |
| 177 | 183 |
| 178 TEST_F(VideoCaptureDeviceTest, ReAllocateCamera) { | 184 // TODO(perkj): This test is disabled due to stability problem with certain |
| 185 // cameras. http://www.crbug.com/94134 |
| 186 TEST_F(VideoCaptureDeviceTest, DISABLED_ReAllocateCamera) { |
| 179 VideoCaptureDevice::GetDeviceNames(&names_); | 187 VideoCaptureDevice::GetDeviceNames(&names_); |
| 180 if (!names_.size()) { | 188 if (!names_.size()) { |
| 181 LOG(WARNING) << "No camera available. Exiting test."; | 189 LOG(WARNING) << "No camera available. Exiting test."; |
| 182 return; | 190 return; |
| 183 } | 191 } |
| 184 scoped_ptr<VideoCaptureDevice> device( | 192 scoped_ptr<VideoCaptureDevice> device( |
| 185 VideoCaptureDevice::Create(names_.front())); | 193 VideoCaptureDevice::Create(names_.front())); |
| 186 ASSERT_TRUE(device.get() != NULL); | 194 ASSERT_TRUE(device.get() != NULL); |
| 187 EXPECT_CALL(*frame_observer_, OnErr()) | 195 EXPECT_CALL(*frame_observer_, OnErr()) |
| 188 .Times(0); | 196 .Times(0); |
| 189 // get info about the new resolution | 197 // get info about the new resolution |
| 190 EXPECT_CALL(*frame_observer_, OnFrameInfo(640, 480, _)); | 198 EXPECT_CALL(*frame_observer_, OnFrameInfo(640, 480, _)); |
| 191 | 199 |
| 192 EXPECT_CALL(*frame_observer_, OnFrameInfo(320, 240, _)); | 200 EXPECT_CALL(*frame_observer_, OnFrameInfo(320, 240, _)); |
| 193 | 201 |
| 194 device->Allocate(640, 480, 30, frame_observer_.get()); | 202 device->Allocate(640, 480, 30, frame_observer_.get()); |
| 195 device->Start(); | 203 device->Start(); |
| 196 // Nothing shall happen. | 204 // Nothing shall happen. |
| 197 device->Allocate(1280, 1024, 30, frame_observer_.get()); | 205 device->Allocate(1280, 1024, 30, frame_observer_.get()); |
| 198 device->DeAllocate(); | 206 device->DeAllocate(); |
| 199 // Allocate new size 320, 240 | 207 // Allocate new size 320, 240 |
| 200 device->Allocate(320, 240, 30, frame_observer_.get()); | 208 device->Allocate(320, 240, 30, frame_observer_.get()); |
| 201 | 209 |
| 202 device->Start(); | 210 device->Start(); |
| 203 // Get captured video frames. | 211 // Get captured video frames. |
| 204 EXPECT_TRUE(wait_event_.TimedWait( | 212 EXPECT_TRUE(wait_event_.TimedWait(base::TimeDelta::FromMilliseconds( |
| 205 base::TimeDelta::FromMilliseconds(kWaitTime))); | 213 TestTimeouts::action_max_timeout_ms()))); |
| 206 device->Stop(); | 214 device->Stop(); |
| 207 device->DeAllocate(); | 215 device->DeAllocate(); |
| 208 } | 216 } |
| 209 | 217 |
| 210 TEST_F(VideoCaptureDeviceTest, DeAllocateCameraWhileRunning) { | 218 // TODO(perkj): This test is disabled due to stability problem with certain |
| 219 // cameras. http://www.crbug.com/94134 |
| 220 TEST_F(VideoCaptureDeviceTest, DISABLED_DeAllocateCameraWhileRunning) { |
| 211 VideoCaptureDevice::GetDeviceNames(&names_); | 221 VideoCaptureDevice::GetDeviceNames(&names_); |
| 212 if (!names_.size()) { | 222 if (!names_.size()) { |
| 213 LOG(WARNING) << "No camera available. Exiting test."; | 223 LOG(WARNING) << "No camera available. Exiting test."; |
| 214 return; | 224 return; |
| 215 } | 225 } |
| 216 scoped_ptr<VideoCaptureDevice> device( | 226 scoped_ptr<VideoCaptureDevice> device( |
| 217 VideoCaptureDevice::Create(names_.front())); | 227 VideoCaptureDevice::Create(names_.front())); |
| 218 ASSERT_TRUE(device.get() != NULL); | 228 ASSERT_TRUE(device.get() != NULL); |
| 219 | 229 |
| 220 EXPECT_CALL(*frame_observer_, OnErr()) | 230 EXPECT_CALL(*frame_observer_, OnErr()) |
| 221 .Times(0); | 231 .Times(0); |
| 222 // Get info about the new resolution. | 232 // Get info about the new resolution. |
| 223 EXPECT_CALL(*frame_observer_, OnFrameInfo(640, 480, 30)); | 233 EXPECT_CALL(*frame_observer_, OnFrameInfo(640, 480, 30)); |
| 224 | 234 |
| 225 device->Allocate(640, 480, 30, frame_observer_.get()); | 235 device->Allocate(640, 480, 30, frame_observer_.get()); |
| 226 | 236 |
| 227 device->Start(); | 237 device->Start(); |
| 228 // Get captured video frames. | 238 // Get captured video frames. |
| 229 EXPECT_TRUE(wait_event_.TimedWait( | 239 EXPECT_TRUE(wait_event_.TimedWait(base::TimeDelta::FromMilliseconds( |
| 230 base::TimeDelta::FromMilliseconds(kWaitTime))); | 240 TestTimeouts::action_max_timeout_ms()))); |
| 231 device->DeAllocate(); | 241 device->DeAllocate(); |
| 232 } | 242 } |
| 233 | 243 |
| 234 TEST_F(VideoCaptureDeviceTest, TestFakeCapture) { | 244 TEST_F(VideoCaptureDeviceTest, TestFakeCapture) { |
| 235 VideoCaptureDevice::Names names; | 245 VideoCaptureDevice::Names names; |
| 236 | 246 |
| 237 FakeVideoCaptureDevice::GetDeviceNames(&names); | 247 FakeVideoCaptureDevice::GetDeviceNames(&names); |
| 238 | 248 |
| 239 ASSERT_GT(static_cast<int>(names.size()), 0); | 249 ASSERT_GT(static_cast<int>(names.size()), 0); |
| 240 | 250 |
| 241 scoped_ptr<VideoCaptureDevice> device( | 251 scoped_ptr<VideoCaptureDevice> device( |
| 242 FakeVideoCaptureDevice::Create(names.front())); | 252 FakeVideoCaptureDevice::Create(names.front())); |
| 243 ASSERT_TRUE(device.get() != NULL); | 253 ASSERT_TRUE(device.get() != NULL); |
| 244 | 254 |
| 245 // Get info about the new resolution. | 255 // Get info about the new resolution. |
| 246 EXPECT_CALL(*frame_observer_, OnFrameInfo(640, 480, 30)) | 256 EXPECT_CALL(*frame_observer_, OnFrameInfo(640, 480, 30)) |
| 247 .Times(1); | 257 .Times(1); |
| 248 | 258 |
| 249 EXPECT_CALL(*frame_observer_, OnErr()) | 259 EXPECT_CALL(*frame_observer_, OnErr()) |
| 250 .Times(0); | 260 .Times(0); |
| 251 | 261 |
| 252 device->Allocate(640, 480, 30, frame_observer_.get()); | 262 device->Allocate(640, 480, 30, frame_observer_.get()); |
| 253 | 263 |
| 254 device->Start(); | 264 device->Start(); |
| 255 EXPECT_TRUE(wait_event_.TimedWait( | 265 EXPECT_TRUE(wait_event_.TimedWait(base::TimeDelta::FromMilliseconds( |
| 256 base::TimeDelta::FromMilliseconds(kWaitTime))); | 266 TestTimeouts::action_max_timeout_ms()))); |
| 257 device->Stop(); | 267 device->Stop(); |
| 258 device->DeAllocate(); | 268 device->DeAllocate(); |
| 259 } | 269 } |
| 260 | 270 |
| 261 }; // namespace media | 271 }; // namespace media |
| OLD | NEW |