Commit bf4fc2ca authored by yuli@chromium.org's avatar yuli@chromium.org

Fix CaptureMjpeg test fails on devices that cannot capture MJPEG.

BUG=335764
TEST=build and run the test on snow

Review URL: https://codereview.chromium.org/227613005

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@262966 0039d316-1c4b-4281-b951-d872f2087c98
parent 34e9bb5f
...@@ -128,6 +128,32 @@ class VideoCaptureDeviceTest : public testing::Test { ...@@ -128,6 +128,32 @@ class VideoCaptureDeviceTest : public testing::Test {
const VideoCaptureFormat& last_format() const { return last_format_; } const VideoCaptureFormat& last_format() const { return last_format_; }
scoped_ptr<VideoCaptureDevice::Name> GetFirstDeviceNameSupportingPixelFormat(
const VideoPixelFormat& pixel_format) {
VideoCaptureDevice::GetDeviceNames(&names_);
if (!names_.size()) {
DVLOG(1) << "No camera available.";
return scoped_ptr<VideoCaptureDevice::Name>();
}
VideoCaptureDevice::Names::iterator names_iterator;
for (names_iterator = names_.begin(); names_iterator != names_.end();
++names_iterator) {
VideoCaptureFormats supported_formats;
VideoCaptureDevice::GetDeviceSupportedFormats(*names_iterator,
&supported_formats);
VideoCaptureFormats::iterator formats_iterator;
for (formats_iterator = supported_formats.begin();
formats_iterator != supported_formats.end(); ++formats_iterator) {
if (formats_iterator->pixel_format == pixel_format) {
return scoped_ptr<VideoCaptureDevice::Name>(
new VideoCaptureDevice::Name(*names_iterator));
}
}
}
DVLOG(1) << "No camera can capture the format: " << pixel_format;
return scoped_ptr<VideoCaptureDevice::Name>();
}
#if defined(OS_WIN) #if defined(OS_WIN)
base::win::ScopedCOMInitializer initialize_com_; base::win::ScopedCOMInitializer initialize_com_;
#endif #endif
...@@ -161,7 +187,7 @@ TEST_F(VideoCaptureDeviceTest, CaptureVGA) { ...@@ -161,7 +187,7 @@ TEST_F(VideoCaptureDeviceTest, CaptureVGA) {
scoped_ptr<VideoCaptureDevice> device( scoped_ptr<VideoCaptureDevice> device(
VideoCaptureDevice::Create(names_.front())); VideoCaptureDevice::Create(names_.front()));
ASSERT_FALSE(device.get() == NULL); ASSERT_TRUE(device);
DVLOG(1) << names_.front().id(); DVLOG(1) << names_.front().id();
EXPECT_CALL(*client_, OnErr()) EXPECT_CALL(*client_, OnErr())
...@@ -189,7 +215,7 @@ TEST_F(VideoCaptureDeviceTest, Capture720p) { ...@@ -189,7 +215,7 @@ TEST_F(VideoCaptureDeviceTest, Capture720p) {
scoped_ptr<VideoCaptureDevice> device( scoped_ptr<VideoCaptureDevice> device(
VideoCaptureDevice::Create(names_.front())); VideoCaptureDevice::Create(names_.front()));
ASSERT_FALSE(device.get() == NULL); ASSERT_TRUE(device);
EXPECT_CALL(*client_, OnErr()) EXPECT_CALL(*client_, OnErr())
.Times(0); .Times(0);
...@@ -213,7 +239,7 @@ TEST_F(VideoCaptureDeviceTest, MAYBE_AllocateBadSize) { ...@@ -213,7 +239,7 @@ TEST_F(VideoCaptureDeviceTest, MAYBE_AllocateBadSize) {
} }
scoped_ptr<VideoCaptureDevice> device( scoped_ptr<VideoCaptureDevice> device(
VideoCaptureDevice::Create(names_.front())); VideoCaptureDevice::Create(names_.front()));
ASSERT_TRUE(device.get() != NULL); ASSERT_TRUE(device);
EXPECT_CALL(*client_, OnErr()) EXPECT_CALL(*client_, OnErr())
.Times(0); .Times(0);
...@@ -284,7 +310,7 @@ TEST_F(VideoCaptureDeviceTest, DeAllocateCameraWhileRunning) { ...@@ -284,7 +310,7 @@ TEST_F(VideoCaptureDeviceTest, DeAllocateCameraWhileRunning) {
} }
scoped_ptr<VideoCaptureDevice> device( scoped_ptr<VideoCaptureDevice> device(
VideoCaptureDevice::Create(names_.front())); VideoCaptureDevice::Create(names_.front()));
ASSERT_TRUE(device.get() != NULL); ASSERT_TRUE(device);
EXPECT_CALL(*client_, OnErr()) EXPECT_CALL(*client_, OnErr())
.Times(0); .Times(0);
...@@ -312,7 +338,7 @@ TEST_F(VideoCaptureDeviceTest, FakeCapture) { ...@@ -312,7 +338,7 @@ TEST_F(VideoCaptureDeviceTest, FakeCapture) {
scoped_ptr<VideoCaptureDevice> device( scoped_ptr<VideoCaptureDevice> device(
FakeVideoCaptureDevice::Create(names.front())); FakeVideoCaptureDevice::Create(names.front()));
ASSERT_TRUE(device.get() != NULL); ASSERT_TRUE(device);
EXPECT_CALL(*client_, OnErr()) EXPECT_CALL(*client_, OnErr())
.Times(0); .Times(0);
...@@ -332,14 +358,14 @@ TEST_F(VideoCaptureDeviceTest, FakeCapture) { ...@@ -332,14 +358,14 @@ TEST_F(VideoCaptureDeviceTest, FakeCapture) {
// Start the camera in 720p to capture MJPEG instead of a raw format. // Start the camera in 720p to capture MJPEG instead of a raw format.
TEST_F(VideoCaptureDeviceTest, MAYBE_CaptureMjpeg) { TEST_F(VideoCaptureDeviceTest, MAYBE_CaptureMjpeg) {
VideoCaptureDevice::GetDeviceNames(&names_); scoped_ptr<VideoCaptureDevice::Name> name =
if (!names_.size()) { GetFirstDeviceNameSupportingPixelFormat(PIXEL_FORMAT_MJPEG);
DVLOG(1) << "No camera available. Exiting test."; if (!name) {
DVLOG(1) << "No camera supports MJPEG format. Exiting test.";
return; return;
} }
scoped_ptr<VideoCaptureDevice> device( scoped_ptr<VideoCaptureDevice> device(VideoCaptureDevice::Create(*name));
VideoCaptureDevice::Create(names_.front())); ASSERT_TRUE(device);
ASSERT_TRUE(device.get() != NULL);
EXPECT_CALL(*client_, OnErr()) EXPECT_CALL(*client_, OnErr())
.Times(0); .Times(0);
...@@ -359,19 +385,13 @@ TEST_F(VideoCaptureDeviceTest, MAYBE_CaptureMjpeg) { ...@@ -359,19 +385,13 @@ TEST_F(VideoCaptureDeviceTest, MAYBE_CaptureMjpeg) {
} }
TEST_F(VideoCaptureDeviceTest, GetDeviceSupportedFormats) { TEST_F(VideoCaptureDeviceTest, GetDeviceSupportedFormats) {
VideoCaptureDevice::GetDeviceNames(&names_); // Use PIXEL_FORMAT_MAX to iterate all device names for testing
if (!names_.size()) { // GetDeviceSupportedFormats().
DVLOG(1) << "No camera available. Exiting test."; scoped_ptr<VideoCaptureDevice::Name> name =
return; GetFirstDeviceNameSupportingPixelFormat(PIXEL_FORMAT_MAX);
} // Verify no camera returned for PIXEL_FORMAT_MAX. Nothing else to test here
VideoCaptureFormats supported_formats; // since we cannot forecast the hardware capabilities.
VideoCaptureDevice::Names::iterator names_iterator; ASSERT_FALSE(name);
for (names_iterator = names_.begin(); names_iterator != names_.end();
++names_iterator) {
VideoCaptureDevice::GetDeviceSupportedFormats(*names_iterator,
&supported_formats);
// Nothing to test here since we cannot forecast the hardware capabilities.
}
} }
TEST_F(VideoCaptureDeviceTest, FakeCaptureVariableResolution) { TEST_F(VideoCaptureDeviceTest, FakeCaptureVariableResolution) {
...@@ -388,7 +408,7 @@ TEST_F(VideoCaptureDeviceTest, FakeCaptureVariableResolution) { ...@@ -388,7 +408,7 @@ TEST_F(VideoCaptureDeviceTest, FakeCaptureVariableResolution) {
scoped_ptr<VideoCaptureDevice> device( scoped_ptr<VideoCaptureDevice> device(
FakeVideoCaptureDevice::Create(names.front())); FakeVideoCaptureDevice::Create(names.front()));
ASSERT_TRUE(device.get() != NULL); ASSERT_TRUE(device);
EXPECT_CALL(*client_, OnErr()) EXPECT_CALL(*client_, OnErr())
.Times(0); .Times(0);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment