| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/command_line.h" | 5 #include "base/command_line.h" |
| 6 #include "content/browser/webrtc/webrtc_webcam_browsertest.h" | 6 #include "content/browser/webrtc/webrtc_webcam_browsertest.h" |
| 7 #include "content/public/common/content_switches.h" | 7 #include "content/public/common/content_switches.h" |
| 8 #include "content/public/test/browser_test_utils.h" | 8 #include "content/public/test/browser_test_utils.h" |
| 9 #include "content/public/test/content_browser_test.h" | 9 #include "content/public/test/content_browser_test.h" |
| 10 #include "content/public/test/content_browser_test_utils.h" | 10 #include "content/public/test/content_browser_test_utils.h" |
| 11 #include "content/public/test/test_utils.h" | 11 #include "content/public/test/test_utils.h" |
| 12 #include "media/base/media_switches.h" | 12 #include "media/base/media_switches.h" |
| 13 #include "net/test/embedded_test_server/embedded_test_server.h" | 13 #include "net/test/embedded_test_server/embedded_test_server.h" |
| 14 | 14 |
| 15 namespace { | 15 namespace { |
| 16 | 16 |
| 17 static const char kImageCaptureHtmlFile[] = "/media/image_capture_test.html"; | 17 static const char kImageCaptureHtmlFile[] = "/media/image_capture_test.html"; |
| 18 | 18 |
| 19 // TODO(mcasas): enable real-camera tests by disabling the Fake Device for | 19 // TODO(mcasas): enable real-camera tests by disabling the Fake Device for |
| 20 // platforms where the ImageCaptureCode is landed, https://crbug.com/518807. | 20 // platforms where the ImageCaptureCode is landed, https://crbug.com/518807. |
| 21 static struct TargetCamera { | 21 static struct TargetCamera { |
| 22 bool use_fake; | 22 bool use_fake; |
| 23 } const kTestParameters[] = {{true}}; | 23 } const kTestParameters[] = {{true}}; |
| 24 | 24 |
| 25 } // namespace | 25 } // namespace |
| 26 | 26 |
| 27 namespace content { | 27 namespace content { |
| 28 | 28 |
| 29 #if defined(OS_WIN) |
| 30 // This test is flaky on WebRTC Windows bots: https://crbug.com/633242. |
| 31 #define MAYBE_WebRtcImageCaptureBrowserTest \ |
| 32 DISABLED_WebRtcImageCaptureBrowserTest |
| 33 #else |
| 34 #define MAYBE_WebRtcImageCaptureBrowserTest WebRtcImageCaptureBrowserTest |
| 35 #endif |
| 36 |
| 29 // This class is the content_browsertests for Image Capture API, which allows | 37 // This class is the content_browsertests for Image Capture API, which allows |
| 30 // for capturing still images out of a MediaStreamTrack. Is a | 38 // for capturing still images out of a MediaStreamTrack. Is a |
| 31 // WebRtcWebcamBrowserTest to be able to use a physical camera. | 39 // WebRtcWebcamBrowserTest to be able to use a physical camera. |
| 32 class WebRtcImageCaptureBrowserTest | 40 class MAYBE_WebRtcImageCaptureBrowserTest |
| 33 : public WebRtcWebcamBrowserTest, | 41 : public WebRtcWebcamBrowserTest, |
| 34 public testing::WithParamInterface<struct TargetCamera> { | 42 public testing::WithParamInterface<struct TargetCamera> { |
| 35 public: | 43 public: |
| 36 WebRtcImageCaptureBrowserTest() = default; | 44 MAYBE_WebRtcImageCaptureBrowserTest() = default; |
| 37 ~WebRtcImageCaptureBrowserTest() override = default; | 45 ~MAYBE_WebRtcImageCaptureBrowserTest() override = default; |
| 38 | 46 |
| 39 void SetUpCommandLine(base::CommandLine* command_line) override { | 47 void SetUpCommandLine(base::CommandLine* command_line) override { |
| 40 WebRtcWebcamBrowserTest::SetUpCommandLine(command_line); | 48 WebRtcWebcamBrowserTest::SetUpCommandLine(command_line); |
| 41 | 49 |
| 42 ASSERT_FALSE(base::CommandLine::ForCurrentProcess()->HasSwitch( | 50 ASSERT_FALSE(base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 43 switches::kUseFakeDeviceForMediaStream)); | 51 switches::kUseFakeDeviceForMediaStream)); |
| 44 if (GetParam().use_fake) { | 52 if (GetParam().use_fake) { |
| 45 base::CommandLine::ForCurrentProcess()->AppendSwitch( | 53 base::CommandLine::ForCurrentProcess()->AppendSwitch( |
| 46 switches::kUseFakeDeviceForMediaStream); | 54 switches::kUseFakeDeviceForMediaStream); |
| 47 ASSERT_TRUE(base::CommandLine::ForCurrentProcess()->HasSwitch( | 55 ASSERT_TRUE(base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 48 switches::kUseFakeDeviceForMediaStream)); | 56 switches::kUseFakeDeviceForMediaStream)); |
| 49 } | 57 } |
| 50 | 58 |
| 51 // Enables promised-based navigator.mediaDevices.getUserMedia(); | 59 // Enables promised-based navigator.mediaDevices.getUserMedia(); |
| 52 // TODO(mcasas): remove after https://crbug.com/503227 is closed. | 60 // TODO(mcasas): remove after https://crbug.com/503227 is closed. |
| 53 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII( | 61 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII( |
| 54 switches::kEnableBlinkFeatures, "GetUserMedia"); | 62 switches::kEnableBlinkFeatures, "GetUserMedia"); |
| 55 | 63 |
| 56 // Specific flag to enable ImageCapture API. | 64 // Specific flag to enable ImageCapture API. |
| 57 // TODO(mcasas): remove after https://crbug.com/603328 is closed. | 65 // TODO(mcasas): remove after https://crbug.com/603328 is closed. |
| 58 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII( | 66 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII( |
| 59 switches::kEnableBlinkFeatures, "ImageCapture"); | 67 switches::kEnableBlinkFeatures, "ImageCapture"); |
| 60 } | 68 } |
| 61 | 69 |
| 62 private: | 70 private: |
| 63 DISALLOW_COPY_AND_ASSIGN(WebRtcImageCaptureBrowserTest); | 71 DISALLOW_COPY_AND_ASSIGN(MAYBE_WebRtcImageCaptureBrowserTest); |
| 64 }; | 72 }; |
| 65 | 73 |
| 66 IN_PROC_BROWSER_TEST_P(WebRtcImageCaptureBrowserTest, | 74 IN_PROC_BROWSER_TEST_P(MAYBE_WebRtcImageCaptureBrowserTest, |
| 67 CreateAndGetCapabilities) { | 75 CreateAndGetCapabilities) { |
| 68 ASSERT_TRUE(embedded_test_server()->Start()); | 76 ASSERT_TRUE(embedded_test_server()->Start()); |
| 69 GURL url(embedded_test_server()->GetURL(kImageCaptureHtmlFile)); | 77 GURL url(embedded_test_server()->GetURL(kImageCaptureHtmlFile)); |
| 70 NavigateToURL(shell(), url); | 78 NavigateToURL(shell(), url); |
| 71 | 79 |
| 72 std::string result; | 80 std::string result; |
| 73 ASSERT_TRUE(ExecuteScriptAndExtractString( | 81 ASSERT_TRUE(ExecuteScriptAndExtractString( |
| 74 shell(), "testCreateAndGetCapabilities()", &result)); | 82 shell(), "testCreateAndGetCapabilities()", &result)); |
| 75 if (result == "OK") | 83 if (result == "OK") |
| 76 return; | 84 return; |
| 77 FAIL(); | 85 FAIL(); |
| 78 } | 86 } |
| 79 | 87 |
| 80 INSTANTIATE_TEST_CASE_P(, | 88 INSTANTIATE_TEST_CASE_P(, |
| 81 WebRtcImageCaptureBrowserTest, | 89 MAYBE_WebRtcImageCaptureBrowserTest, |
| 82 testing::ValuesIn(kTestParameters)); | 90 testing::ValuesIn(kTestParameters)); |
| 83 | 91 |
| 84 } // namespace content | 92 } // namespace content |
| OLD | NEW |