Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(969)

Side by Side Diff: media/video/capture/video_capture_device_unittest.cc

Issue 8177008: Adding VideoCaptureDevice for Mac. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Test change: PostTask instead of PostDelayedTask. Created 9 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « media/video/capture/mac/video_capture_device_mac_qtkit.mm ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/message_loop.h"
6 #include "base/synchronization/waitable_event.h" 7 #include "base/synchronization/waitable_event.h"
7 #include "base/test/test_timeouts.h" 8 #include "base/test/test_timeouts.h"
8 #include "base/threading/thread.h" 9 #include "base/threading/thread.h"
9 #include "media/video/capture/fake_video_capture_device.h" 10 #include "media/video/capture/fake_video_capture_device.h"
10 #include "media/video/capture/video_capture_device.h" 11 #include "media/video/capture/video_capture_device.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
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 {
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 }
32 48
33 virtual void OnFrameInfo( 49 virtual void OnFrameInfo(
34 const VideoCaptureDevice::Capability& info) OVERRIDE { 50 const VideoCaptureDevice::Capability& info) OVERRIDE {
35 OnFrameInfo(info.width, info.height, info.frame_rate); 51 OnFrameInfo(info.width, info.height, info.frame_rate);
36 } 52 }
37 53
38 virtual void OnIncomingCapturedFrame(const uint8* data, int length, 54 virtual void OnIncomingCapturedFrame(const uint8* data, int length,
39 base::Time timestamp) OVERRIDE { 55 base::Time timestamp) OVERRIDE {
40 wait_event_->Signal(); 56 wait_event_->Signal();
41 } 57 }
42 58
43 private: 59 private:
44 base::WaitableEvent* wait_event_; 60 base::WaitableEvent* wait_event_;
45 }; 61 };
46 62
47 class VideoCaptureDeviceTest : public testing::Test { 63 class VideoCaptureDeviceTest : public testing::Test {
48 public: 64 public:
49 VideoCaptureDeviceTest(): wait_event_(false, false) { } 65 VideoCaptureDeviceTest(): wait_event_(false, false) { }
50 66
67 void PostQuitTask() {
68 loop_->PostTask(FROM_HERE, new MessageLoop::QuitTask);
69 loop_->Run();
70 }
71
51 protected: 72 protected:
52 virtual void SetUp() { 73 virtual void SetUp() {
53 frame_observer_.reset(new MockFrameObserver(&wait_event_)); 74 frame_observer_.reset(new MockFrameObserver(&wait_event_));
75 loop_.reset(new MessageLoopForUI());
54 } 76 }
55 77
56 virtual void TearDown() { 78 virtual void TearDown() {
57 } 79 }
58 80
59 base::WaitableEvent wait_event_; 81 base::WaitableEvent wait_event_;
60 scoped_ptr<MockFrameObserver> frame_observer_; 82 scoped_ptr<MockFrameObserver> frame_observer_;
61 VideoCaptureDevice::Names names_; 83 VideoCaptureDevice::Names names_;
84 scoped_ptr<MessageLoop> loop_;
62 }; 85 };
63 86
64 TEST_F(VideoCaptureDeviceTest, OpenInvalidDevice) { 87 TEST_F(VideoCaptureDeviceTest, OpenInvalidDevice) {
65 VideoCaptureDevice::Name device_name; 88 VideoCaptureDevice::Name device_name;
66 device_name.device_name = "jibberish"; 89 device_name.device_name = "jibberish";
67 device_name.unique_id = "jibberish"; 90 device_name.unique_id = "jibberish";
68 VideoCaptureDevice* device = VideoCaptureDevice::Create(device_name); 91 VideoCaptureDevice* device = VideoCaptureDevice::Create(device_name);
69 EXPECT_TRUE(device == NULL); 92 EXPECT_TRUE(device == NULL);
70 } 93 }
71 94
(...skipping 10 matching lines...) Expand all
82 105
83 // Get info about the new resolution. 106 // Get info about the new resolution.
84 EXPECT_CALL(*frame_observer_, OnFrameInfo(640, 480, 30)) 107 EXPECT_CALL(*frame_observer_, OnFrameInfo(640, 480, 30))
85 .Times(1); 108 .Times(1);
86 109
87 EXPECT_CALL(*frame_observer_, OnErr()) 110 EXPECT_CALL(*frame_observer_, OnErr())
88 .Times(0); 111 .Times(0);
89 112
90 device->Allocate(640, 480, 30, frame_observer_.get()); 113 device->Allocate(640, 480, 30, frame_observer_.get());
91 device->Start(); 114 device->Start();
92 // Wait for 3s or for captured frame. 115 // Get captured video frames.
116 PostQuitTask();
93 EXPECT_TRUE(wait_event_.TimedWait(base::TimeDelta::FromMilliseconds( 117 EXPECT_TRUE(wait_event_.TimedWait(base::TimeDelta::FromMilliseconds(
94 TestTimeouts::action_max_timeout_ms()))); 118 TestTimeouts::action_max_timeout_ms())));
95 device->Stop(); 119 device->Stop();
96 device->DeAllocate(); 120 device->DeAllocate();
97 } 121 }
98 122
99 TEST_F(VideoCaptureDeviceTest, Capture720p) { 123 TEST_F(VideoCaptureDeviceTest, Capture720p) {
100 VideoCaptureDevice::GetDeviceNames(&names_); 124 VideoCaptureDevice::GetDeviceNames(&names_);
101 if (!names_.size()) { 125 if (!names_.size()) {
102 LOG(WARNING) << "No camera available. Exiting test."; 126 LOG(WARNING) << "No camera available. Exiting test.";
103 return; 127 return;
104 } 128 }
105 129
106 scoped_ptr<VideoCaptureDevice> device( 130 scoped_ptr<VideoCaptureDevice> device(
107 VideoCaptureDevice::Create(names_.front())); 131 VideoCaptureDevice::Create(names_.front()));
108 ASSERT_FALSE(device.get() == NULL); 132 ASSERT_FALSE(device.get() == NULL);
109 133
110 // Get info about the new resolution. 134 // Get info about the new resolution.
111 // We don't care about the resulting resolution or frame rate as it might 135 // We don't care about the resulting resolution or frame rate as it might
112 // be different from one machine to the next. 136 // be different from one machine to the next.
113 EXPECT_CALL(*frame_observer_, OnFrameInfo(_, _, _)) 137 EXPECT_CALL(*frame_observer_, OnFrameInfo(_, _, _))
114 .Times(1); 138 .Times(1);
115 139
116 EXPECT_CALL(*frame_observer_, OnErr()) 140 EXPECT_CALL(*frame_observer_, OnErr())
117 .Times(0); 141 .Times(0);
118 142
119 device->Allocate(1280, 720, 30, frame_observer_.get()); 143 device->Allocate(1280, 720, 30, frame_observer_.get());
120 device->Start(); 144 device->Start();
121 // Get captured video frames. 145 // Get captured video frames.
146 PostQuitTask();
122 EXPECT_TRUE(wait_event_.TimedWait(base::TimeDelta::FromMilliseconds( 147 EXPECT_TRUE(wait_event_.TimedWait(base::TimeDelta::FromMilliseconds(
123 TestTimeouts::action_max_timeout_ms()))); 148 TestTimeouts::action_max_timeout_ms())));
124 device->Stop(); 149 device->Stop();
125 device->DeAllocate(); 150 device->DeAllocate();
126 } 151 }
127 152
128 TEST_F(VideoCaptureDeviceTest, AllocateSameCameraTwice) { 153 TEST_F(VideoCaptureDeviceTest, MAYBE_AllocateSameCameraTwice) {
129 VideoCaptureDevice::GetDeviceNames(&names_); 154 VideoCaptureDevice::GetDeviceNames(&names_);
130 if (!names_.size()) { 155 if (!names_.size()) {
131 LOG(WARNING) << "No camera available. Exiting test."; 156 LOG(WARNING) << "No camera available. Exiting test.";
132 return; 157 return;
133 } 158 }
134 scoped_ptr<VideoCaptureDevice> device1( 159 scoped_ptr<VideoCaptureDevice> device1(
135 VideoCaptureDevice::Create(names_.front())); 160 VideoCaptureDevice::Create(names_.front()));
136 ASSERT_TRUE(device1.get() != NULL); 161 ASSERT_TRUE(device1.get() != NULL);
137 162
138 scoped_ptr<VideoCaptureDevice> device2( 163 scoped_ptr<VideoCaptureDevice> device2(
139 VideoCaptureDevice::Create(names_.front())); 164 VideoCaptureDevice::Create(names_.front()));
140 ASSERT_TRUE(device2.get() != NULL); 165 ASSERT_TRUE(device2.get() != NULL);
141 166
142 // 1. Get info about the new resolution on the first allocated camera 167 // 1. Get info about the new resolution on the first allocated camera
143 EXPECT_CALL(*frame_observer_, OnFrameInfo(640, 480, 30)); 168 EXPECT_CALL(*frame_observer_, OnFrameInfo(640, 480, 30));
144 169
145 device1->Allocate(640, 480, 30, frame_observer_.get()); 170 device1->Allocate(640, 480, 30, frame_observer_.get());
146 171
147 // 2. Error when trying to allocate the same camera again. 172 // 2. Error when trying to allocate the same camera again.
148 EXPECT_CALL(*frame_observer_, OnErr()); 173 EXPECT_CALL(*frame_observer_, OnErr());
149 device2->Allocate(640, 480, 30, frame_observer_.get()); 174 device2->Allocate(640, 480, 30, frame_observer_.get());
150 175
151 device1->DeAllocate(); 176 device1->DeAllocate();
152 device2->DeAllocate(); 177 device2->DeAllocate();
153 } 178 }
154 179
155 TEST_F(VideoCaptureDeviceTest, AllocateBadSize) { 180 TEST_F(VideoCaptureDeviceTest, MAYBE_AllocateBadSize) {
156 VideoCaptureDevice::GetDeviceNames(&names_); 181 VideoCaptureDevice::GetDeviceNames(&names_);
157 if (!names_.size()) { 182 if (!names_.size()) {
158 LOG(WARNING) << "No camera available. Exiting test."; 183 LOG(WARNING) << "No camera available. Exiting test.";
159 return; 184 return;
160 } 185 }
161 scoped_ptr<VideoCaptureDevice> device( 186 scoped_ptr<VideoCaptureDevice> device(
162 VideoCaptureDevice::Create(names_.front())); 187 VideoCaptureDevice::Create(names_.front()));
163 ASSERT_TRUE(device.get() != NULL); 188 ASSERT_TRUE(device.get() != NULL);
164 189
165 EXPECT_CALL(*frame_observer_, OnErr()) 190 EXPECT_CALL(*frame_observer_, OnErr())
(...skipping 26 matching lines...) Expand all
192 device->Allocate(640, 480, 30, frame_observer_.get()); 217 device->Allocate(640, 480, 30, frame_observer_.get());
193 device->Start(); 218 device->Start();
194 // Nothing shall happen. 219 // Nothing shall happen.
195 device->Allocate(1280, 1024, 30, frame_observer_.get()); 220 device->Allocate(1280, 1024, 30, frame_observer_.get());
196 device->DeAllocate(); 221 device->DeAllocate();
197 // Allocate new size 320, 240 222 // Allocate new size 320, 240
198 device->Allocate(320, 240, 30, frame_observer_.get()); 223 device->Allocate(320, 240, 30, frame_observer_.get());
199 224
200 device->Start(); 225 device->Start();
201 // Get captured video frames. 226 // Get captured video frames.
227 PostQuitTask();
202 EXPECT_TRUE(wait_event_.TimedWait(base::TimeDelta::FromMilliseconds( 228 EXPECT_TRUE(wait_event_.TimedWait(base::TimeDelta::FromMilliseconds(
203 TestTimeouts::action_max_timeout_ms()))); 229 TestTimeouts::action_max_timeout_ms())));
204 device->Stop(); 230 device->Stop();
205 device->DeAllocate(); 231 device->DeAllocate();
206 } 232 }
207 233
208 TEST_F(VideoCaptureDeviceTest, DeAllocateCameraWhileRunning) { 234 TEST_F(VideoCaptureDeviceTest, DeAllocateCameraWhileRunning) {
209 VideoCaptureDevice::GetDeviceNames(&names_); 235 VideoCaptureDevice::GetDeviceNames(&names_);
210 if (!names_.size()) { 236 if (!names_.size()) {
211 LOG(WARNING) << "No camera available. Exiting test."; 237 LOG(WARNING) << "No camera available. Exiting test.";
212 return; 238 return;
213 } 239 }
214 scoped_ptr<VideoCaptureDevice> device( 240 scoped_ptr<VideoCaptureDevice> device(
215 VideoCaptureDevice::Create(names_.front())); 241 VideoCaptureDevice::Create(names_.front()));
216 ASSERT_TRUE(device.get() != NULL); 242 ASSERT_TRUE(device.get() != NULL);
217 243
218 EXPECT_CALL(*frame_observer_, OnErr()) 244 EXPECT_CALL(*frame_observer_, OnErr())
219 .Times(0); 245 .Times(0);
220 // Get info about the new resolution. 246 // Get info about the new resolution.
221 EXPECT_CALL(*frame_observer_, OnFrameInfo(640, 480, 30)); 247 EXPECT_CALL(*frame_observer_, OnFrameInfo(640, 480, 30));
222 248
223 device->Allocate(640, 480, 30, frame_observer_.get()); 249 device->Allocate(640, 480, 30, frame_observer_.get());
224 250
225 device->Start(); 251 device->Start();
226 // Get captured video frames. 252 // Get captured video frames.
253 PostQuitTask();
227 EXPECT_TRUE(wait_event_.TimedWait(base::TimeDelta::FromMilliseconds( 254 EXPECT_TRUE(wait_event_.TimedWait(base::TimeDelta::FromMilliseconds(
228 TestTimeouts::action_max_timeout_ms()))); 255 TestTimeouts::action_max_timeout_ms())));
229 device->DeAllocate(); 256 device->DeAllocate();
230 } 257 }
231 258
232 TEST_F(VideoCaptureDeviceTest, TestFakeCapture) { 259 TEST_F(VideoCaptureDeviceTest, TestFakeCapture) {
233 VideoCaptureDevice::Names names; 260 VideoCaptureDevice::Names names;
234 261
235 FakeVideoCaptureDevice::GetDeviceNames(&names); 262 FakeVideoCaptureDevice::GetDeviceNames(&names);
236 263
(...skipping 13 matching lines...) Expand all
250 device->Allocate(640, 480, 30, frame_observer_.get()); 277 device->Allocate(640, 480, 30, frame_observer_.get());
251 278
252 device->Start(); 279 device->Start();
253 EXPECT_TRUE(wait_event_.TimedWait(base::TimeDelta::FromMilliseconds( 280 EXPECT_TRUE(wait_event_.TimedWait(base::TimeDelta::FromMilliseconds(
254 TestTimeouts::action_max_timeout_ms()))); 281 TestTimeouts::action_max_timeout_ms())));
255 device->Stop(); 282 device->Stop();
256 device->DeAllocate(); 283 device->DeAllocate();
257 } 284 }
258 285
259 }; // namespace media 286 }; // namespace media
OLDNEW
« no previous file with comments | « media/video/capture/mac/video_capture_device_mac_qtkit.mm ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698