Index: media/video/capture/video_capture_device_unittest.cc |
diff --git a/media/video/capture/video_capture_device_unittest.cc b/media/video/capture/video_capture_device_unittest.cc |
index 7cb40bc27139fc7482867cb60c6ec10e685b0c7a..fc3eb874e2e15fcbda85892a528c64561d0f21be 100644 |
--- a/media/video/capture/video_capture_device_unittest.cc |
+++ b/media/video/capture/video_capture_device_unittest.cc |
@@ -3,6 +3,7 @@ |
// found in the LICENSE file. |
#include "base/memory/scoped_ptr.h" |
+#include "base/message_loop.h" |
#include "base/synchronization/waitable_event.h" |
#include "base/test/test_timeouts.h" |
#include "base/threading/thread.h" |
@@ -11,6 +12,21 @@ |
#include "testing/gmock/include/gmock/gmock.h" |
#include "testing/gtest/include/gtest/gtest.h" |
+#if defined(OS_MACOSX) |
+// The camera is 'locked' by the application once started on Mac OS X, not when |
+// allocated as for Windows and Linux, and this test case will fail. |
+#define MAYBE_AllocateSameCameraTwice DISABLED_AllocateSameCameraTwice |
+#else |
+#define MAYBE_AllocateSameCameraTwice AllocateSameCameraTwice |
+#endif |
+ |
+#if defined(OS_MACOSX) |
+// Mac/QTKit will always give you the size you ask for and this case will fail. |
+#define MAYBE_AllocateBadSize DISABLED_AllocateBadSize |
+#else |
+#define MAYBE_AllocateBadSize AllocateBadSize |
+#endif |
+ |
using ::testing::_; |
using ::testing::AnyNumber; |
using ::testing::Return; |
@@ -18,7 +34,7 @@ using ::testing::AtLeast; |
namespace media { |
-class MockFrameObserver: public media::VideoCaptureDevice::EventHandler { |
+class MockFrameObserver : public media::VideoCaptureDevice::EventHandler { |
public: |
MOCK_METHOD0(OnErr, void()); |
MOCK_METHOD3(OnFrameInfo, void(int width, int height, int frame_rate)); |
@@ -48,9 +64,18 @@ class VideoCaptureDeviceTest : public testing::Test { |
public: |
VideoCaptureDeviceTest(): wait_event_(false, false) { } |
+ void PostQuitTask() { |
+ // Give the camera 5s to start. |
+ const int quit_task_wait_time_ms = 5000; |
dmac
2011/10/17 17:02:29
don't use a fixed constant here. Use one of the va
mflodman_chromium_OOO
2011/10/17 18:40:38
Ok, changed to your original proposal. It will tak
|
+ loop_->PostDelayedTask(FROM_HERE, new MessageLoop::QuitTask, |
+ quit_task_wait_time_ms); |
+ loop_->Run(); |
+ } |
+ |
protected: |
virtual void SetUp() { |
frame_observer_.reset(new MockFrameObserver(&wait_event_)); |
+ loop_.reset(new MessageLoopForUI()); |
} |
virtual void TearDown() { |
@@ -59,6 +84,7 @@ class VideoCaptureDeviceTest : public testing::Test { |
base::WaitableEvent wait_event_; |
scoped_ptr<MockFrameObserver> frame_observer_; |
VideoCaptureDevice::Names names_; |
+ scoped_ptr<MessageLoop> loop_; |
}; |
TEST_F(VideoCaptureDeviceTest, OpenInvalidDevice) { |
@@ -89,7 +115,8 @@ TEST_F(VideoCaptureDeviceTest, CaptureVGA) { |
device->Allocate(640, 480, 30, frame_observer_.get()); |
device->Start(); |
- // Wait for 3s or for captured frame. |
+ // Get captured video frames. |
+ PostQuitTask(); |
EXPECT_TRUE(wait_event_.TimedWait(base::TimeDelta::FromMilliseconds( |
TestTimeouts::action_max_timeout_ms()))); |
device->Stop(); |
@@ -119,13 +146,14 @@ TEST_F(VideoCaptureDeviceTest, Capture720p) { |
device->Allocate(1280, 720, 30, frame_observer_.get()); |
device->Start(); |
// Get captured video frames. |
+ PostQuitTask(); |
EXPECT_TRUE(wait_event_.TimedWait(base::TimeDelta::FromMilliseconds( |
TestTimeouts::action_max_timeout_ms()))); |
device->Stop(); |
device->DeAllocate(); |
} |
-TEST_F(VideoCaptureDeviceTest, AllocateSameCameraTwice) { |
+TEST_F(VideoCaptureDeviceTest, MAYBE_AllocateSameCameraTwice) { |
VideoCaptureDevice::GetDeviceNames(&names_); |
if (!names_.size()) { |
LOG(WARNING) << "No camera available. Exiting test."; |
@@ -152,7 +180,7 @@ TEST_F(VideoCaptureDeviceTest, AllocateSameCameraTwice) { |
device2->DeAllocate(); |
} |
-TEST_F(VideoCaptureDeviceTest, AllocateBadSize) { |
+TEST_F(VideoCaptureDeviceTest, MAYBE_AllocateBadSize) { |
VideoCaptureDevice::GetDeviceNames(&names_); |
if (!names_.size()) { |
LOG(WARNING) << "No camera available. Exiting test."; |
@@ -199,6 +227,7 @@ TEST_F(VideoCaptureDeviceTest, ReAllocateCamera) { |
device->Start(); |
// Get captured video frames. |
+ PostQuitTask(); |
EXPECT_TRUE(wait_event_.TimedWait(base::TimeDelta::FromMilliseconds( |
dmac
2011/10/17 17:02:29
do you need the TimedWait and the PostQuitTask?
mflodman_chromium_OOO
2011/10/17 18:40:38
PostQuitTask is needed since it takes care of the
|
TestTimeouts::action_max_timeout_ms()))); |
device->Stop(); |
@@ -224,6 +253,7 @@ TEST_F(VideoCaptureDeviceTest, DeAllocateCameraWhileRunning) { |
device->Start(); |
// Get captured video frames. |
+ PostQuitTask(); |
EXPECT_TRUE(wait_event_.TimedWait(base::TimeDelta::FromMilliseconds( |
TestTimeouts::action_max_timeout_ms()))); |
device->DeAllocate(); |