| 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 "testing/gmock/include/gmock/gmock.h" | 11 #include "testing/gmock/include/gmock/gmock.h" |
| 12 #include "testing/gtest/include/gtest/gtest.h" | 12 #include "testing/gtest/include/gtest/gtest.h" |
| 13 | 13 |
| 14 #if defined(OS_MACOSX) |
| 15 // These tests requires a runloop to be created in the test. |
| 16 #define MAYBE_CaptureVGA DISABLED_CaptureVGA |
| 17 #define MAYBE_Capture720p DISABLED_Capture720p |
| 18 #define MAYBE_AllocateSameCameraTwice DISABLED_AllocateSameCameraTwice |
| 19 #define MAYBE_AllocateBadSize DISABLED_AllocateBadSize |
| 20 #define MAYBE_ReAllocateCamera DISABLED_ReAllocateCamera |
| 21 #define MAYBE_DeAllocateCameraWhileRunning DISABLED_DeAllocateCameraWhileRunning |
| 22 #else |
| 23 #define MAYBE_CaptureVGA CaptureVGA |
| 24 #define MAYBE_Capture720p Capture720p |
| 25 #define MAYBE_AllocateSameCameraTwice AllocateSameCameraTwice |
| 26 #define MAYBE_AllocateBadSize AllocateBadSize |
| 27 #define MAYBE_ReAllocateCamera ReAllocateCamera |
| 28 #define MAYBE_DeAllocateCameraWhileRunning DeAllocateCameraWhileRunning |
| 29 #endif |
| 30 |
| 14 using ::testing::_; | 31 using ::testing::_; |
| 15 using ::testing::AnyNumber; | 32 using ::testing::AnyNumber; |
| 16 using ::testing::Return; | 33 using ::testing::Return; |
| 17 using ::testing::AtLeast; | 34 using ::testing::AtLeast; |
| 18 | 35 |
| 19 namespace media { | 36 namespace media { |
| 20 | 37 |
| 21 class MockFrameObserver: public media::VideoCaptureDevice::EventHandler { | 38 class MockFrameObserver: public media::VideoCaptureDevice::EventHandler { |
| 22 public: | 39 public: |
| 23 MOCK_METHOD0(OnErr, void()); | 40 MOCK_METHOD0(OnErr, void()); |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 62 }; | 79 }; |
| 63 | 80 |
| 64 TEST_F(VideoCaptureDeviceTest, OpenInvalidDevice) { | 81 TEST_F(VideoCaptureDeviceTest, OpenInvalidDevice) { |
| 65 VideoCaptureDevice::Name device_name; | 82 VideoCaptureDevice::Name device_name; |
| 66 device_name.device_name = "jibberish"; | 83 device_name.device_name = "jibberish"; |
| 67 device_name.unique_id = "jibberish"; | 84 device_name.unique_id = "jibberish"; |
| 68 VideoCaptureDevice* device = VideoCaptureDevice::Create(device_name); | 85 VideoCaptureDevice* device = VideoCaptureDevice::Create(device_name); |
| 69 EXPECT_TRUE(device == NULL); | 86 EXPECT_TRUE(device == NULL); |
| 70 } | 87 } |
| 71 | 88 |
| 72 TEST_F(VideoCaptureDeviceTest, CaptureVGA) { | 89 TEST_F(VideoCaptureDeviceTest, MAYBE_CaptureVGA) { |
| 73 VideoCaptureDevice::GetDeviceNames(&names_); | 90 VideoCaptureDevice::GetDeviceNames(&names_); |
| 74 if (!names_.size()) { | 91 if (!names_.size()) { |
| 75 LOG(WARNING) << "No camera available. Exiting test."; | 92 LOG(WARNING) << "No camera available. Exiting test."; |
| 76 return; | 93 return; |
| 77 } | 94 } |
| 78 | 95 |
| 79 scoped_ptr<VideoCaptureDevice> device( | 96 scoped_ptr<VideoCaptureDevice> device( |
| 80 VideoCaptureDevice::Create(names_.front())); | 97 VideoCaptureDevice::Create(names_.front())); |
| 81 ASSERT_FALSE(device.get() == NULL); | 98 ASSERT_FALSE(device.get() == NULL); |
| 82 | 99 |
| 83 // Get info about the new resolution. | 100 // Get info about the new resolution. |
| 84 EXPECT_CALL(*frame_observer_, OnFrameInfo(640, 480, 30)) | 101 EXPECT_CALL(*frame_observer_, OnFrameInfo(640, 480, 30)) |
| 85 .Times(1); | 102 .Times(1); |
| 86 | 103 |
| 87 EXPECT_CALL(*frame_observer_, OnErr()) | 104 EXPECT_CALL(*frame_observer_, OnErr()) |
| 88 .Times(0); | 105 .Times(0); |
| 89 | 106 |
| 90 device->Allocate(640, 480, 30, frame_observer_.get()); | 107 device->Allocate(640, 480, 30, frame_observer_.get()); |
| 91 device->Start(); | 108 device->Start(); |
| 92 // Wait for 3s or for captured frame. | 109 // Wait for 3s or for captured frame. |
| 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, MAYBE_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. |
| 122 EXPECT_TRUE(wait_event_.TimedWait(base::TimeDelta::FromMilliseconds( | 139 EXPECT_TRUE(wait_event_.TimedWait(base::TimeDelta::FromMilliseconds( |
| 123 TestTimeouts::action_max_timeout_ms()))); | 140 TestTimeouts::action_max_timeout_ms()))); |
| 124 device->Stop(); | 141 device->Stop(); |
| 125 device->DeAllocate(); | 142 device->DeAllocate(); |
| 126 } | 143 } |
| 127 | 144 |
| 128 TEST_F(VideoCaptureDeviceTest, AllocateSameCameraTwice) { | 145 TEST_F(VideoCaptureDeviceTest, MAYBE_AllocateSameCameraTwice) { |
| 129 VideoCaptureDevice::GetDeviceNames(&names_); | 146 VideoCaptureDevice::GetDeviceNames(&names_); |
| 130 if (!names_.size()) { | 147 if (!names_.size()) { |
| 131 LOG(WARNING) << "No camera available. Exiting test."; | 148 LOG(WARNING) << "No camera available. Exiting test."; |
| 132 return; | 149 return; |
| 133 } | 150 } |
| 134 scoped_ptr<VideoCaptureDevice> device1( | 151 scoped_ptr<VideoCaptureDevice> device1( |
| 135 VideoCaptureDevice::Create(names_.front())); | 152 VideoCaptureDevice::Create(names_.front())); |
| 136 ASSERT_TRUE(device1.get() != NULL); | 153 ASSERT_TRUE(device1.get() != NULL); |
| 137 | 154 |
| 138 scoped_ptr<VideoCaptureDevice> device2( | 155 scoped_ptr<VideoCaptureDevice> device2( |
| 139 VideoCaptureDevice::Create(names_.front())); | 156 VideoCaptureDevice::Create(names_.front())); |
| 140 ASSERT_TRUE(device2.get() != NULL); | 157 ASSERT_TRUE(device2.get() != NULL); |
| 141 | 158 |
| 142 // 1. Get info about the new resolution on the first allocated camera | 159 // 1. Get info about the new resolution on the first allocated camera |
| 143 EXPECT_CALL(*frame_observer_, OnFrameInfo(640, 480, 30)); | 160 EXPECT_CALL(*frame_observer_, OnFrameInfo(640, 480, 30)); |
| 144 | 161 |
| 145 device1->Allocate(640, 480, 30, frame_observer_.get()); | 162 device1->Allocate(640, 480, 30, frame_observer_.get()); |
| 146 | 163 |
| 147 // 2. Error when trying to allocate the same camera again. | 164 // 2. Error when trying to allocate the same camera again. |
| 148 EXPECT_CALL(*frame_observer_, OnErr()); | 165 EXPECT_CALL(*frame_observer_, OnErr()); |
| 149 device2->Allocate(640, 480, 30, frame_observer_.get()); | 166 device2->Allocate(640, 480, 30, frame_observer_.get()); |
| 150 | 167 |
| 151 device1->DeAllocate(); | 168 device1->DeAllocate(); |
| 152 device2->DeAllocate(); | 169 device2->DeAllocate(); |
| 153 } | 170 } |
| 154 | 171 |
| 155 TEST_F(VideoCaptureDeviceTest, AllocateBadSize) { | 172 TEST_F(VideoCaptureDeviceTest, MAYBE_AllocateBadSize) { |
| 156 VideoCaptureDevice::GetDeviceNames(&names_); | 173 VideoCaptureDevice::GetDeviceNames(&names_); |
| 157 if (!names_.size()) { | 174 if (!names_.size()) { |
| 158 LOG(WARNING) << "No camera available. Exiting test."; | 175 LOG(WARNING) << "No camera available. Exiting test."; |
| 159 return; | 176 return; |
| 160 } | 177 } |
| 161 scoped_ptr<VideoCaptureDevice> device( | 178 scoped_ptr<VideoCaptureDevice> device( |
| 162 VideoCaptureDevice::Create(names_.front())); | 179 VideoCaptureDevice::Create(names_.front())); |
| 163 ASSERT_TRUE(device.get() != NULL); | 180 ASSERT_TRUE(device.get() != NULL); |
| 164 | 181 |
| 165 EXPECT_CALL(*frame_observer_, OnErr()) | 182 EXPECT_CALL(*frame_observer_, OnErr()) |
| 166 .Times(0); | 183 .Times(0); |
| 167 | 184 |
| 168 // get info about the new resolution | 185 // get info about the new resolution |
| 169 EXPECT_CALL(*frame_observer_, OnFrameInfo(640, 480 , _)) | 186 EXPECT_CALL(*frame_observer_, OnFrameInfo(640, 480 , _)) |
| 170 .Times(AtLeast(1)); | 187 .Times(AtLeast(1)); |
| 171 | 188 |
| 172 device->Allocate(637, 472, 35, frame_observer_.get()); | 189 device->Allocate(637, 472, 35, frame_observer_.get()); |
| 173 device->DeAllocate(); | 190 device->DeAllocate(); |
| 174 } | 191 } |
| 175 | 192 |
| 176 TEST_F(VideoCaptureDeviceTest, ReAllocateCamera) { | 193 TEST_F(VideoCaptureDeviceTest, MAYBE_ReAllocateCamera) { |
| 177 VideoCaptureDevice::GetDeviceNames(&names_); | 194 VideoCaptureDevice::GetDeviceNames(&names_); |
| 178 if (!names_.size()) { | 195 if (!names_.size()) { |
| 179 LOG(WARNING) << "No camera available. Exiting test."; | 196 LOG(WARNING) << "No camera available. Exiting test."; |
| 180 return; | 197 return; |
| 181 } | 198 } |
| 182 scoped_ptr<VideoCaptureDevice> device( | 199 scoped_ptr<VideoCaptureDevice> device( |
| 183 VideoCaptureDevice::Create(names_.front())); | 200 VideoCaptureDevice::Create(names_.front())); |
| 184 ASSERT_TRUE(device.get() != NULL); | 201 ASSERT_TRUE(device.get() != NULL); |
| 185 EXPECT_CALL(*frame_observer_, OnErr()) | 202 EXPECT_CALL(*frame_observer_, OnErr()) |
| 186 .Times(0); | 203 .Times(0); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 198 device->Allocate(320, 240, 30, frame_observer_.get()); | 215 device->Allocate(320, 240, 30, frame_observer_.get()); |
| 199 | 216 |
| 200 device->Start(); | 217 device->Start(); |
| 201 // Get captured video frames. | 218 // Get captured video frames. |
| 202 EXPECT_TRUE(wait_event_.TimedWait(base::TimeDelta::FromMilliseconds( | 219 EXPECT_TRUE(wait_event_.TimedWait(base::TimeDelta::FromMilliseconds( |
| 203 TestTimeouts::action_max_timeout_ms()))); | 220 TestTimeouts::action_max_timeout_ms()))); |
| 204 device->Stop(); | 221 device->Stop(); |
| 205 device->DeAllocate(); | 222 device->DeAllocate(); |
| 206 } | 223 } |
| 207 | 224 |
| 208 TEST_F(VideoCaptureDeviceTest, DeAllocateCameraWhileRunning) { | 225 TEST_F(VideoCaptureDeviceTest, MAYBE_DeAllocateCameraWhileRunning) { |
| 209 VideoCaptureDevice::GetDeviceNames(&names_); | 226 VideoCaptureDevice::GetDeviceNames(&names_); |
| 210 if (!names_.size()) { | 227 if (!names_.size()) { |
| 211 LOG(WARNING) << "No camera available. Exiting test."; | 228 LOG(WARNING) << "No camera available. Exiting test."; |
| 212 return; | 229 return; |
| 213 } | 230 } |
| 214 scoped_ptr<VideoCaptureDevice> device( | 231 scoped_ptr<VideoCaptureDevice> device( |
| 215 VideoCaptureDevice::Create(names_.front())); | 232 VideoCaptureDevice::Create(names_.front())); |
| 216 ASSERT_TRUE(device.get() != NULL); | 233 ASSERT_TRUE(device.get() != NULL); |
| 217 | 234 |
| 218 EXPECT_CALL(*frame_observer_, OnErr()) | 235 EXPECT_CALL(*frame_observer_, OnErr()) |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 250 device->Allocate(640, 480, 30, frame_observer_.get()); | 267 device->Allocate(640, 480, 30, frame_observer_.get()); |
| 251 | 268 |
| 252 device->Start(); | 269 device->Start(); |
| 253 EXPECT_TRUE(wait_event_.TimedWait(base::TimeDelta::FromMilliseconds( | 270 EXPECT_TRUE(wait_event_.TimedWait(base::TimeDelta::FromMilliseconds( |
| 254 TestTimeouts::action_max_timeout_ms()))); | 271 TestTimeouts::action_max_timeout_ms()))); |
| 255 device->Stop(); | 272 device->Stop(); |
| 256 device->DeAllocate(); | 273 device->DeAllocate(); |
| 257 } | 274 } |
| 258 | 275 |
| 259 }; // namespace media | 276 }; // namespace media |
| OLD | NEW |