Chromium Code Reviews| Index: content/browser/webrtc/webrtc_image_capture_browsertest.cc |
| diff --git a/content/browser/webrtc/webrtc_image_capture_browsertest.cc b/content/browser/webrtc/webrtc_image_capture_browsertest.cc |
| index 13603b7976c0b5afc425999a4e595cf09a1b4d19..945e6081e7510ffe4e742fd9f27b51bf3e33f13e 100644 |
| --- a/content/browser/webrtc/webrtc_image_capture_browsertest.cc |
| +++ b/content/browser/webrtc/webrtc_image_capture_browsertest.cc |
| @@ -18,6 +18,19 @@ |
| #include "base/android/build_info.h" |
| #endif |
| +namespace content { |
| + |
| +#if defined(OS_WIN) |
| +// These tests are flaky on WebRTC Windows bots: https://crbug.com/633242. |
| +#define MAYBE_CreateAndGetCapabilities DISABLED_CreateAndGetCapabilities |
| +#define MAYBE_CreateAndTakePhoto DISABLED_CreateAndTakePhoto |
| +#define MAYBE_CreateAndGrabFrame DISABLED_CreateAndGrabFrame |
| +#else |
| +#define MAYBE_CreateAndGetCapabilities CreateAndGetCapabilities |
| +#define MAYBE_CreateAndTakePhoto CreateAndTakePhoto |
| +#define MAYBE_CreateAndGrabFrame CreateAndGrabFrame |
| +#endif |
| + |
| namespace { |
| static const char kImageCaptureHtmlFile[] = "/media/image_capture_test.html"; |
| @@ -32,8 +45,6 @@ static struct TargetCamera { |
| } // namespace |
| -namespace content { |
| - |
| // This class is the content_browsertests for Image Capture API, which allows |
| // for capturing still images out of a MediaStreamTrack. Is a |
| // WebRtcWebcamBrowserTest to be able to use a physical camera. |
| @@ -67,72 +78,60 @@ class WebRtcImageCaptureBrowserTest |
| switches::kEnableBlinkFeatures, "ImageCapture"); |
| } |
| - private: |
| - DISALLOW_COPY_AND_ASSIGN(WebRtcImageCaptureBrowserTest); |
| -}; |
| + void SetUp() override { |
| + ASSERT_TRUE(embedded_test_server()->InitializeAndListen()); |
| + WebRtcWebcamBrowserTest::SetUp(); |
| + } |
| -#if defined(OS_WIN) |
| -// This test is flaky on WebRTC Windows bots: https://crbug.com/633242. |
| -#define MAYBE_CreateAndGetCapabilities DISABLED_CreateAndGetCapabilities |
| -#else |
| -#define MAYBE_CreateAndGetCapabilities CreateAndGetCapabilities |
| -#endif |
| -IN_PROC_BROWSER_TEST_P(WebRtcImageCaptureBrowserTest, |
| - MAYBE_CreateAndGetCapabilities) { |
| + // Tries to run a |command| JS test, returning true if the test can be safely |
| + // skipped or it works as intended, or false otherwise. |
| + bool RunImageCaptureTestCase(const std::string& command) { |
| #if defined(OS_ANDROID) |
| - // TODO(mcasas): fails on Lollipop devices: https://crbug.com/634811 |
| - if (base::android::BuildInfo::GetInstance()->sdk_int() < |
| - base::android::SDK_VERSION_MARSHMALLOW) { |
| - return; |
| - } |
| + // TODO(mcasas): fails on Lollipop devices: https://crbug.com/634811 |
| + if (base::android::BuildInfo::GetInstance()->sdk_int() < |
| + base::android::SDK_VERSION_MARSHMALLOW) { |
| + return true; |
| + } |
| #endif |
| - ASSERT_TRUE(embedded_test_server()->Start()); |
| - GURL url(embedded_test_server()->GetURL(kImageCaptureHtmlFile)); |
| - NavigateToURL(shell(), url); |
| + GURL url(embedded_test_server()->GetURL(kImageCaptureHtmlFile)); |
| + NavigateToURL(shell(), url); |
| - if (!IsWebcamAvailableOnSystem(shell()->web_contents())) { |
| - DVLOG(1) << "No video device; skipping test..."; |
| - return; |
| + if (!IsWebcamAvailableOnSystem(shell()->web_contents())) { |
| + DVLOG(1) << "No video device; skipping test..."; |
| + return true; |
| + } |
| + |
| + std::string result; |
| + if (!ExecuteScriptAndExtractString(shell(), command, &result)) |
| + return false; |
| + return result == "OK"; |
| } |
| - std::string result; |
| - ASSERT_TRUE(ExecuteScriptAndExtractString( |
| - shell(), "testCreateAndGetCapabilities()", &result)); |
| - if (result == "OK") |
| + private: |
| + DISALLOW_COPY_AND_ASSIGN(WebRtcImageCaptureBrowserTest); |
| +}; |
| + |
| +IN_PROC_BROWSER_TEST_P(WebRtcImageCaptureBrowserTest, |
| + MAYBE_CreateAndGetCapabilities) { |
| + embedded_test_server()->StartAcceptingConnections(); |
| + if (RunImageCaptureTestCase("testCreateAndGetCapabilities()")) |
|
xianglu
2016/10/14 22:34:52
Consider using ASSERT_TRUE(), which can save two l
|
| return; |
| FAIL(); |
| } |
| -#if defined(OS_WIN) |
| -// This test is flaky on WebRTC Windows bots: https://crbug.com/633242. |
| -#define MAYBE_CreateAndTakePhoto DISABLED_CreateAndTakePhoto |
| -#else |
| -#define MAYBE_CreateAndTakePhoto CreateAndTakePhoto |
| -#endif |
| IN_PROC_BROWSER_TEST_P(WebRtcImageCaptureBrowserTest, |
| MAYBE_CreateAndTakePhoto) { |
| -#if defined(OS_ANDROID) |
| - // TODO(mcasas): fails on Lollipop devices: https://crbug.com/634811 |
| - if (base::android::BuildInfo::GetInstance()->sdk_int() < |
| - base::android::SDK_VERSION_MARSHMALLOW) { |
| - return; |
| - } |
| -#endif |
| - |
| - ASSERT_TRUE(embedded_test_server()->Start()); |
| - GURL url(embedded_test_server()->GetURL(kImageCaptureHtmlFile)); |
| - NavigateToURL(shell(), url); |
| - |
| - if (!IsWebcamAvailableOnSystem(shell()->web_contents())) { |
| - DVLOG(1) << "No video device; skipping test..."; |
| + embedded_test_server()->StartAcceptingConnections(); |
| + if (RunImageCaptureTestCase("testCreateAndTakePhoto()")) |
| return; |
| - } |
| + FAIL(); |
| +} |
| - std::string result; |
| - ASSERT_TRUE(ExecuteScriptAndExtractString(shell(), "testCreateAndTakePhoto()", |
| - &result)); |
| - if (result == "OK") |
| +IN_PROC_BROWSER_TEST_P(WebRtcImageCaptureBrowserTest, |
| + MAYBE_CreateAndGrabFrame) { |
| + embedded_test_server()->StartAcceptingConnections(); |
| + if (RunImageCaptureTestCase("testCreateAndGrabFrame()")) |
| return; |
| FAIL(); |
| } |