| 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 } | 23 } const kTestParameters[] = {{true}}; |
| 24 #if defined(OS_ANDROID) | |
| 25 const kTestParameters[] = {{true}, {false}}; | |
| 26 #else | |
| 27 const kTestParameters[] = {{true}}; | |
| 28 #endif | |
| 29 | 24 |
| 30 } // namespace | 25 } // namespace |
| 31 | 26 |
| 32 namespace content { | 27 namespace content { |
| 33 | 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 |
| 34 // 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 |
| 35 // for capturing still images out of a MediaStreamTrack. Is a | 38 // for capturing still images out of a MediaStreamTrack. Is a |
| 36 // WebRtcWebcamBrowserTest to be able to use a physical camera. | 39 // WebRtcWebcamBrowserTest to be able to use a physical camera. |
| 37 class WebRtcImageCaptureBrowserTest | 40 class MAYBE_WebRtcImageCaptureBrowserTest |
| 38 : public WebRtcWebcamBrowserTest, | 41 : public WebRtcWebcamBrowserTest, |
| 39 public testing::WithParamInterface<struct TargetCamera> { | 42 public testing::WithParamInterface<struct TargetCamera> { |
| 40 public: | 43 public: |
| 41 WebRtcImageCaptureBrowserTest() = default; | 44 MAYBE_WebRtcImageCaptureBrowserTest() = default; |
| 42 ~WebRtcImageCaptureBrowserTest() override = default; | 45 ~MAYBE_WebRtcImageCaptureBrowserTest() override = default; |
| 43 | 46 |
| 44 void SetUpCommandLine(base::CommandLine* command_line) override { | 47 void SetUpCommandLine(base::CommandLine* command_line) override { |
| 45 WebRtcWebcamBrowserTest::SetUpCommandLine(command_line); | 48 WebRtcWebcamBrowserTest::SetUpCommandLine(command_line); |
| 46 | 49 |
| 47 ASSERT_FALSE(base::CommandLine::ForCurrentProcess()->HasSwitch( | 50 ASSERT_FALSE(base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 48 switches::kUseFakeDeviceForMediaStream)); | 51 switches::kUseFakeDeviceForMediaStream)); |
| 49 if (GetParam().use_fake) { | 52 if (GetParam().use_fake) { |
| 50 base::CommandLine::ForCurrentProcess()->AppendSwitch( | 53 base::CommandLine::ForCurrentProcess()->AppendSwitch( |
| 51 switches::kUseFakeDeviceForMediaStream); | 54 switches::kUseFakeDeviceForMediaStream); |
| 52 ASSERT_TRUE(base::CommandLine::ForCurrentProcess()->HasSwitch( | 55 ASSERT_TRUE(base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 53 switches::kUseFakeDeviceForMediaStream)); | 56 switches::kUseFakeDeviceForMediaStream)); |
| 54 } | 57 } |
| 55 | 58 |
| 56 // Enables promised-based navigator.mediaDevices.getUserMedia(); | 59 // Enables promised-based navigator.mediaDevices.getUserMedia(); |
| 57 // TODO(mcasas): remove after https://crbug.com/503227 is closed. | 60 // TODO(mcasas): remove after https://crbug.com/503227 is closed. |
| 58 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII( | 61 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII( |
| 59 switches::kEnableBlinkFeatures, "GetUserMedia"); | 62 switches::kEnableBlinkFeatures, "GetUserMedia"); |
| 60 | 63 |
| 61 // Specific flag to enable ImageCapture API. | 64 // Specific flag to enable ImageCapture API. |
| 62 // TODO(mcasas): remove after https://crbug.com/603328 is closed. | 65 // TODO(mcasas): remove after https://crbug.com/603328 is closed. |
| 63 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII( | 66 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII( |
| 64 switches::kEnableBlinkFeatures, "ImageCapture"); | 67 switches::kEnableBlinkFeatures, "ImageCapture"); |
| 65 } | 68 } |
| 66 | 69 |
| 67 private: | 70 private: |
| 68 DISALLOW_COPY_AND_ASSIGN(WebRtcImageCaptureBrowserTest); | 71 DISALLOW_COPY_AND_ASSIGN(MAYBE_WebRtcImageCaptureBrowserTest); |
| 69 }; | 72 }; |
| 70 | 73 |
| 71 #if defined(OS_WIN) | 74 IN_PROC_BROWSER_TEST_P(MAYBE_WebRtcImageCaptureBrowserTest, |
| 72 // This test is flaky on WebRTC Windows bots: https://crbug.com/633242. | 75 CreateAndGetCapabilities) { |
| 73 #define MAYBE_CreateAndGetCapabilities DISABLED_CreateAndGetCapabilities | |
| 74 #else | |
| 75 #define MAYBE_CreateAndGetCapabilities CreateAndGetCapabilities | |
| 76 #endif | |
| 77 IN_PROC_BROWSER_TEST_P(WebRtcImageCaptureBrowserTest, | |
| 78 MAYBE_CreateAndGetCapabilities) { | |
| 79 ASSERT_TRUE(embedded_test_server()->Start()); | 76 ASSERT_TRUE(embedded_test_server()->Start()); |
| 80 GURL url(embedded_test_server()->GetURL(kImageCaptureHtmlFile)); | 77 GURL url(embedded_test_server()->GetURL(kImageCaptureHtmlFile)); |
| 81 NavigateToURL(shell(), url); | 78 NavigateToURL(shell(), url); |
| 82 | 79 |
| 83 std::string result; | 80 std::string result; |
| 84 ASSERT_TRUE(ExecuteScriptAndExtractString( | 81 ASSERT_TRUE(ExecuteScriptAndExtractString( |
| 85 shell(), "testCreateAndGetCapabilities()", &result)); | 82 shell(), "testCreateAndGetCapabilities()", &result)); |
| 86 if (result == "OK") | 83 if (result == "OK") |
| 87 return; | 84 return; |
| 88 FAIL(); | 85 FAIL(); |
| 89 } | 86 } |
| 90 | 87 |
| 91 #if defined(OS_WIN) | |
| 92 // This test is flaky on WebRTC Windows bots: https://crbug.com/633242. | |
| 93 #define MAYBE_CreateAndTakePhoto DISABLED_CreateAndTakePhoto | |
| 94 #else | |
| 95 #define MAYBE_CreateAndTakePhoto CreateAndTakePhoto | |
| 96 #endif | |
| 97 IN_PROC_BROWSER_TEST_P(WebRtcImageCaptureBrowserTest, | |
| 98 MAYBE_CreateAndTakePhoto) { | |
| 99 ASSERT_TRUE(embedded_test_server()->Start()); | |
| 100 GURL url(embedded_test_server()->GetURL(kImageCaptureHtmlFile)); | |
| 101 NavigateToURL(shell(), url); | |
| 102 | |
| 103 std::string result; | |
| 104 ASSERT_TRUE(ExecuteScriptAndExtractString(shell(), "testCreateAndTakePhoto()", | |
| 105 &result)); | |
| 106 if (result == "OK") | |
| 107 return; | |
| 108 FAIL(); | |
| 109 } | |
| 110 | |
| 111 INSTANTIATE_TEST_CASE_P(, | 88 INSTANTIATE_TEST_CASE_P(, |
| 112 WebRtcImageCaptureBrowserTest, | 89 MAYBE_WebRtcImageCaptureBrowserTest, |
| 113 testing::ValuesIn(kTestParameters)); | 90 testing::ValuesIn(kTestParameters)); |
| 114 | 91 |
| 115 } // namespace content | 92 } // namespace content |
| OLD | NEW |