Chromium Code Reviews| 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/threading/thread.h" | 7 #include "base/threading/thread.h" |
| 8 #include "media/video/capture/fake_video_capture_device.h" | 8 #include "media/video/capture/fake_video_capture_device.h" |
| 9 #include "media/video/capture/video_capture_device.h" | 9 #include "media/video/capture/video_capture_device.h" |
| 10 #include "testing/gmock/include/gmock/gmock.h" | 10 #include "testing/gmock/include/gmock/gmock.h" |
| 11 #include "testing/gtest/include/gtest/gtest.h" | 11 #include "testing/gtest/include/gtest/gtest.h" |
| 12 | 12 |
| 13 using ::testing::_; | 13 using ::testing::_; |
| 14 using ::testing::AnyNumber; | 14 using ::testing::AnyNumber; |
| 15 using ::testing::Return; | 15 using ::testing::Return; |
| 16 using ::testing::AtLeast; | 16 using ::testing::AtLeast; |
| 17 | 17 |
| 18 namespace media { | 18 namespace media { |
| 19 const int kWaitTime = 3000; | 19 const int kWaitTime = 5000; |
|
Paweł Hajdan Jr.
2011/08/26 21:56:18
Why not base/test/test_timeouts?
perkj_chrome
2011/08/29 11:34:14
Done.
| |
| 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 TEST_F(VideoCaptureDeviceTest, DISABLED_CaptureVGA) { |
| 73 VideoCaptureDevice::GetDeviceNames(&names_); | 73 VideoCaptureDevice::GetDeviceNames(&names_); |
| 74 // Make sure there are more than 0 cameras. | 74 // Make sure there are more than 0 cameras. |
| 75 if (!names_.size()) { | 75 if (!names_.size()) { |
| 76 LOG(WARNING) << "No camera available. Exiting test."; | 76 LOG(WARNING) << "No camera available. Exiting test."; |
| 77 return; | 77 return; |
| 78 } | 78 } |
| 79 | 79 |
| 80 scoped_ptr<VideoCaptureDevice> device( | 80 scoped_ptr<VideoCaptureDevice> device( |
| 81 VideoCaptureDevice::Create(names_.front())); | 81 VideoCaptureDevice::Create(names_.front())); |
| 82 ASSERT_FALSE(device.get() == NULL); | 82 ASSERT_FALSE(device.get() == NULL); |
| 83 | 83 |
| 84 // Get info about the new resolution. | 84 // Get info about the new resolution. |
| 85 EXPECT_CALL(*frame_observer_, OnFrameInfo(640, 480, 30)) | 85 EXPECT_CALL(*frame_observer_, OnFrameInfo(640, 480, 30)) |
| 86 .Times(1); | 86 .Times(1); |
| 87 | 87 |
| 88 EXPECT_CALL(*frame_observer_, OnErr()) | 88 EXPECT_CALL(*frame_observer_, OnErr()) |
| 89 .Times(0); | 89 .Times(0); |
| 90 | 90 |
| 91 device->Allocate(640, 480, 30, frame_observer_.get()); | 91 device->Allocate(640, 480, 30, frame_observer_.get()); |
| 92 device->Start(); | 92 device->Start(); |
| 93 // Wait for 3s or for captured frame. | 93 // Wait for 3s or for captured frame. |
| 94 EXPECT_TRUE(wait_event_.TimedWait( | 94 EXPECT_TRUE(wait_event_.TimedWait( |
| 95 base::TimeDelta::FromMilliseconds(kWaitTime))); | 95 base::TimeDelta::FromMilliseconds(kWaitTime))); |
| 96 device->Stop(); | 96 device->Stop(); |
| 97 device->DeAllocate(); | 97 device->DeAllocate(); |
| 98 } | 98 } |
| 99 | 99 |
| 100 TEST_F(VideoCaptureDeviceTest, Capture720p) { | 100 TEST_F(VideoCaptureDeviceTest, DISABLED_Capture720p) { |
| 101 VideoCaptureDevice::GetDeviceNames(&names_); | 101 VideoCaptureDevice::GetDeviceNames(&names_); |
| 102 // Make sure there are more than 0 cameras. | 102 // Make sure there are more than 0 cameras. |
| 103 if (!names_.size()) { | 103 if (!names_.size()) { |
| 104 LOG(WARNING) << "No camera available. Exiting test."; | 104 LOG(WARNING) << "No camera available. Exiting test."; |
| 105 return; | 105 return; |
| 106 } | 106 } |
| 107 | 107 |
| 108 scoped_ptr<VideoCaptureDevice> device( | 108 scoped_ptr<VideoCaptureDevice> device( |
| 109 VideoCaptureDevice::Create(names_.front())); | 109 VideoCaptureDevice::Create(names_.front())); |
| 110 ASSERT_FALSE(device.get() == NULL); | 110 ASSERT_FALSE(device.get() == NULL); |
| 111 | 111 |
| 112 // Get info about the new resolution. | 112 // Get info about the new resolution. |
| 113 // We don't care about the resulting resolution or frame rate as it might | 113 // We don't care about the resulting resolution or frame rate as it might |
| 114 // be different from one machine to the next. | 114 // be different from one machine to the next. |
| 115 EXPECT_CALL(*frame_observer_, OnFrameInfo(_, _, _)) | 115 EXPECT_CALL(*frame_observer_, OnFrameInfo(_, _, _)) |
| 116 .Times(1); | 116 .Times(1); |
| 117 | 117 |
| 118 EXPECT_CALL(*frame_observer_, OnErr()) | 118 EXPECT_CALL(*frame_observer_, OnErr()) |
| 119 .Times(0); | 119 .Times(0); |
| 120 | 120 |
| 121 device->Allocate(1280, 720, 30, frame_observer_.get()); | 121 device->Allocate(1280, 720, 30, frame_observer_.get()); |
| 122 device->Start(); | 122 device->Start(); |
| 123 // Get captured video frames. | 123 // Get captured video frames. |
| 124 EXPECT_TRUE(wait_event_.TimedWait( | 124 EXPECT_TRUE(wait_event_.TimedWait( |
| 125 base::TimeDelta::FromMilliseconds(kWaitTime))); | 125 base::TimeDelta::FromMilliseconds(kWaitTime))); |
| 126 device->Stop(); | 126 device->Stop(); |
| 127 device->DeAllocate(); | 127 device->DeAllocate(); |
| 128 } | 128 } |
| 129 | 129 |
| 130 TEST_F(VideoCaptureDeviceTest, AllocateSameCameraTwice) { | 130 TEST_F(VideoCaptureDeviceTest, DISABLED_AllocateSameCameraTwice) { |
| 131 VideoCaptureDevice::GetDeviceNames(&names_); | 131 VideoCaptureDevice::GetDeviceNames(&names_); |
| 132 if (!names_.size()) { | 132 if (!names_.size()) { |
| 133 LOG(WARNING) << "No camera available. Exiting test."; | 133 LOG(WARNING) << "No camera available. Exiting test."; |
| 134 return; | 134 return; |
| 135 } | 135 } |
| 136 scoped_ptr<VideoCaptureDevice> device1( | 136 scoped_ptr<VideoCaptureDevice> device1( |
| 137 VideoCaptureDevice::Create(names_.front())); | 137 VideoCaptureDevice::Create(names_.front())); |
| 138 ASSERT_TRUE(device1.get() != NULL); | 138 ASSERT_TRUE(device1.get() != NULL); |
| 139 | 139 |
| 140 scoped_ptr<VideoCaptureDevice> device2( | 140 scoped_ptr<VideoCaptureDevice> device2( |
| 141 VideoCaptureDevice::Create(names_.front())); | 141 VideoCaptureDevice::Create(names_.front())); |
| 142 ASSERT_TRUE(device2.get() != NULL); | 142 ASSERT_TRUE(device2.get() != NULL); |
| 143 | 143 |
| 144 // 1. Get info about the new resolution on the first allocated camera | 144 // 1. Get info about the new resolution on the first allocated camera |
| 145 EXPECT_CALL(*frame_observer_, OnFrameInfo(640, 480, 30)); | 145 EXPECT_CALL(*frame_observer_, OnFrameInfo(640, 480, 30)); |
| 146 | 146 |
| 147 device1->Allocate(640, 480, 30, frame_observer_.get()); | 147 device1->Allocate(640, 480, 30, frame_observer_.get()); |
| 148 | 148 |
| 149 // 2. Error when trying to allocate the same camera again. | 149 // 2. Error when trying to allocate the same camera again. |
| 150 EXPECT_CALL(*frame_observer_, OnErr()); | 150 EXPECT_CALL(*frame_observer_, OnErr()); |
| 151 device2->Allocate(640, 480, 30, frame_observer_.get()); | 151 device2->Allocate(640, 480, 30, frame_observer_.get()); |
| 152 | 152 |
| 153 device1->DeAllocate(); | 153 device1->DeAllocate(); |
| 154 device2->DeAllocate(); | 154 device2->DeAllocate(); |
| 155 } | 155 } |
| 156 | 156 |
| 157 TEST_F(VideoCaptureDeviceTest, AllocateBadSize) { | 157 TEST_F(VideoCaptureDeviceTest, DISABLED_AllocateBadSize) { |
| 158 VideoCaptureDevice::GetDeviceNames(&names_); | 158 VideoCaptureDevice::GetDeviceNames(&names_); |
| 159 if (!names_.size()) { | 159 if (!names_.size()) { |
| 160 LOG(WARNING) << "No camera available. Exiting test."; | 160 LOG(WARNING) << "No camera available. Exiting test."; |
| 161 return; | 161 return; |
| 162 } | 162 } |
| 163 scoped_ptr<VideoCaptureDevice> device( | 163 scoped_ptr<VideoCaptureDevice> device( |
| 164 VideoCaptureDevice::Create(names_.front())); | 164 VideoCaptureDevice::Create(names_.front())); |
| 165 ASSERT_TRUE(device.get() != NULL); | 165 ASSERT_TRUE(device.get() != NULL); |
| 166 | 166 |
| 167 EXPECT_CALL(*frame_observer_, OnErr()) | 167 EXPECT_CALL(*frame_observer_, OnErr()) |
| 168 .Times(0); | 168 .Times(0); |
| 169 | 169 |
| 170 // get info about the new resolution | 170 // get info about the new resolution |
| 171 EXPECT_CALL(*frame_observer_, OnFrameInfo(640, 480 , _)) | 171 EXPECT_CALL(*frame_observer_, OnFrameInfo(640, 480 , _)) |
| 172 .Times(AtLeast(1)); | 172 .Times(AtLeast(1)); |
| 173 | 173 |
| 174 device->Allocate(637, 472, 35, frame_observer_.get()); | 174 device->Allocate(637, 472, 35, frame_observer_.get()); |
| 175 device->DeAllocate(); | 175 device->DeAllocate(); |
| 176 } | 176 } |
| 177 | 177 |
| 178 TEST_F(VideoCaptureDeviceTest, ReAllocateCamera) { | 178 TEST_F(VideoCaptureDeviceTest, DISABLED_ReAllocateCamera) { |
| 179 VideoCaptureDevice::GetDeviceNames(&names_); | 179 VideoCaptureDevice::GetDeviceNames(&names_); |
| 180 if (!names_.size()) { | 180 if (!names_.size()) { |
| 181 LOG(WARNING) << "No camera available. Exiting test."; | 181 LOG(WARNING) << "No camera available. Exiting test."; |
| 182 return; | 182 return; |
| 183 } | 183 } |
| 184 scoped_ptr<VideoCaptureDevice> device( | 184 scoped_ptr<VideoCaptureDevice> device( |
| 185 VideoCaptureDevice::Create(names_.front())); | 185 VideoCaptureDevice::Create(names_.front())); |
| 186 ASSERT_TRUE(device.get() != NULL); | 186 ASSERT_TRUE(device.get() != NULL); |
| 187 EXPECT_CALL(*frame_observer_, OnErr()) | 187 EXPECT_CALL(*frame_observer_, OnErr()) |
| 188 .Times(0); | 188 .Times(0); |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 200 device->Allocate(320, 240, 30, frame_observer_.get()); | 200 device->Allocate(320, 240, 30, frame_observer_.get()); |
| 201 | 201 |
| 202 device->Start(); | 202 device->Start(); |
| 203 // Get captured video frames. | 203 // Get captured video frames. |
| 204 EXPECT_TRUE(wait_event_.TimedWait( | 204 EXPECT_TRUE(wait_event_.TimedWait( |
| 205 base::TimeDelta::FromMilliseconds(kWaitTime))); | 205 base::TimeDelta::FromMilliseconds(kWaitTime))); |
| 206 device->Stop(); | 206 device->Stop(); |
| 207 device->DeAllocate(); | 207 device->DeAllocate(); |
| 208 } | 208 } |
| 209 | 209 |
| 210 TEST_F(VideoCaptureDeviceTest, DeAllocateCameraWhileRunning) { | 210 TEST_F(VideoCaptureDeviceTest, DISABLED_DeAllocateCameraWhileRunning) { |
| 211 VideoCaptureDevice::GetDeviceNames(&names_); | 211 VideoCaptureDevice::GetDeviceNames(&names_); |
| 212 if (!names_.size()) { | 212 if (!names_.size()) { |
| 213 LOG(WARNING) << "No camera available. Exiting test."; | 213 LOG(WARNING) << "No camera available. Exiting test."; |
| 214 return; | 214 return; |
| 215 } | 215 } |
| 216 scoped_ptr<VideoCaptureDevice> device( | 216 scoped_ptr<VideoCaptureDevice> device( |
| 217 VideoCaptureDevice::Create(names_.front())); | 217 VideoCaptureDevice::Create(names_.front())); |
| 218 ASSERT_TRUE(device.get() != NULL); | 218 ASSERT_TRUE(device.get() != NULL); |
| 219 | 219 |
| 220 EXPECT_CALL(*frame_observer_, OnErr()) | 220 EXPECT_CALL(*frame_observer_, OnErr()) |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 252 device->Allocate(640, 480, 30, frame_observer_.get()); | 252 device->Allocate(640, 480, 30, frame_observer_.get()); |
| 253 | 253 |
| 254 device->Start(); | 254 device->Start(); |
| 255 EXPECT_TRUE(wait_event_.TimedWait( | 255 EXPECT_TRUE(wait_event_.TimedWait( |
| 256 base::TimeDelta::FromMilliseconds(kWaitTime))); | 256 base::TimeDelta::FromMilliseconds(kWaitTime))); |
| 257 device->Stop(); | 257 device->Stop(); |
| 258 device->DeAllocate(); | 258 device->DeAllocate(); |
| 259 } | 259 } |
| 260 | 260 |
| 261 }; // namespace media | 261 }; // namespace media |
| OLD | NEW |