Chromium Code Reviews| 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 "build/build_config.h" | 6 #include "build/build_config.h" |
| 7 #include "content/browser/webrtc/webrtc_webcam_browsertest.h" | 7 #include "content/browser/webrtc/webrtc_webcam_browsertest.h" |
| 8 #include "content/public/common/content_switches.h" | 8 #include "content/public/common/content_switches.h" |
| 9 #include "content/public/test/browser_test_utils.h" | 9 #include "content/public/test/browser_test_utils.h" |
| 10 #include "content/public/test/content_browser_test.h" | 10 #include "content/public/test/content_browser_test.h" |
| 11 #include "content/public/test/content_browser_test_utils.h" | 11 #include "content/public/test/content_browser_test_utils.h" |
| 12 #include "content/public/test/test_utils.h" | 12 #include "content/public/test/test_utils.h" |
| 13 #include "content/shell/browser/shell.h" | 13 #include "content/shell/browser/shell.h" |
| 14 #include "media/base/media_switches.h" | 14 #include "media/base/media_switches.h" |
| 15 #include "net/test/embedded_test_server/embedded_test_server.h" | 15 #include "net/test/embedded_test_server/embedded_test_server.h" |
| 16 | 16 |
| 17 #if defined(OS_ANDROID) | 17 #if defined(OS_ANDROID) |
| 18 #include "base/android/build_info.h" | 18 #include "base/android/build_info.h" |
| 19 #endif | 19 #endif |
| 20 | 20 |
| 21 namespace content { | 21 namespace content { |
| 22 | 22 |
| 23 #if defined(OS_WIN) | 23 #if defined(OS_WIN) |
| 24 // These tests are flaky on WebRTC Windows bots: https://crbug.com/633242. | 24 // These tests are flaky on WebRTC Windows bots: https://crbug.com/633242. |
| 25 #define MAYBE_CreateAndGetCapabilities DISABLED_CreateAndGetCapabilities | 25 #define MAYBE_GetCapabilities DISABLED_GetCapabilities |
| 26 #define MAYBE_CreateAndTakePhoto DISABLED_CreateAndTakePhoto | 26 #define MAYBE_TakePhoto DISABLED_TakePhoto |
| 27 #define MAYBE_CreateAndGrabFrame DISABLED_CreateAndGrabFrame | 27 #define MAYBE_GrabFrame DISABLED_GrabFrame |
| 28 #else | 28 #else |
| 29 #define MAYBE_CreateAndGetCapabilities CreateAndGetCapabilities | 29 #define MAYBE_GetCapabilities GetCapabilities |
| 30 #define MAYBE_CreateAndTakePhoto CreateAndTakePhoto | 30 #define MAYBE_TakePhoto TakePhoto |
| 31 #define MAYBE_CreateAndGrabFrame CreateAndGrabFrame | 31 #define MAYBE_GrabFrame GrabFrame |
| 32 #endif | 32 #endif |
| 33 | 33 |
| 34 namespace { | 34 namespace { |
| 35 | 35 |
| 36 static const char kImageCaptureHtmlFile[] = "/media/image_capture_test.html"; | 36 static const char kImageCaptureHtmlFile[] = "/media/image_capture_test.html"; |
| 37 | 37 |
| 38 // TODO(mcasas): enable real-camera tests by disabling the Fake Device for | 38 // TODO(mcasas): enable real-camera tests by disabling the Fake Device for |
| 39 // platforms where the ImageCaptureCode is landed, https://crbug.com/518807. | 39 // platforms where the ImageCaptureCode is landed, https://crbug.com/656810 |
| 40 // TODO(mcasas): enable in Android when takePhoto() can be specified a (small) | |
| 41 // capture resolution preventing the test from timeout https://crbug.com/634811. | |
| 42 static struct TargetCamera { | 40 static struct TargetCamera { |
| 43 bool use_fake; | 41 bool use_fake; |
| 44 } const kTestParameters[] = {{true}}; | 42 } const kTestParameters[] = {{true}}; |
| 45 | 43 |
| 46 } // namespace | 44 } // namespace |
| 47 | 45 |
| 48 // This class is the content_browsertests for Image Capture API, which allows | 46 // This class is the content_browsertests for Image Capture API, which allows |
| 49 // for capturing still images out of a MediaStreamTrack. Is a | 47 // for capturing still images out of a MediaStreamTrack. Is a |
| 50 // WebRtcWebcamBrowserTest to be able to use a physical camera. | 48 // WebRtcWebcamBrowserTest to be able to use a physical camera. |
| 51 class WebRtcImageCaptureBrowserTest | 49 class WebRtcImageCaptureBrowserTest |
| 52 : public WebRtcWebcamBrowserTest, | 50 : public WebRtcWebcamBrowserTest, |
| 53 public testing::WithParamInterface<struct TargetCamera> { | 51 public testing::WithParamInterface<struct TargetCamera> { |
| 54 public: | 52 public: |
| 55 WebRtcImageCaptureBrowserTest() = default; | 53 WebRtcImageCaptureBrowserTest() = default; |
| 56 ~WebRtcImageCaptureBrowserTest() override = default; | 54 ~WebRtcImageCaptureBrowserTest() override = default; |
| 57 | 55 |
| 58 void SetUpCommandLine(base::CommandLine* command_line) override { | 56 void SetUpCommandLine(base::CommandLine* command_line) override { |
| 59 WebRtcWebcamBrowserTest::SetUpCommandLine(command_line); | 57 WebRtcWebcamBrowserTest::SetUpCommandLine(command_line); |
| 60 | 58 |
| 61 ASSERT_FALSE(base::CommandLine::ForCurrentProcess()->HasSwitch( | 59 ASSERT_FALSE(base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 62 switches::kUseFakeDeviceForMediaStream)); | 60 switches::kUseFakeDeviceForMediaStream)); |
| 63 if (GetParam().use_fake) { | 61 if (GetParam().use_fake) { |
| 64 base::CommandLine::ForCurrentProcess()->AppendSwitch( | 62 base::CommandLine::ForCurrentProcess()->AppendSwitch( |
| 65 switches::kUseFakeDeviceForMediaStream); | 63 switches::kUseFakeDeviceForMediaStream); |
| 66 ASSERT_TRUE(base::CommandLine::ForCurrentProcess()->HasSwitch( | 64 ASSERT_TRUE(base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 67 switches::kUseFakeDeviceForMediaStream)); | 65 switches::kUseFakeDeviceForMediaStream)); |
| 68 } | 66 } |
| 69 | 67 |
| 70 // Enables promised-based navigator.mediaDevices.getUserMedia(); | 68 // "GetUserMedia": enables navigator.mediaDevices.getUserMedia(); |
| 71 // TODO(mcasas): remove after https://crbug.com/503227 is closed. | 69 // TODO(mcasas): remove GetUserMedia after https://crbug.com/503227. |
| 70 // "ImageCapture": enables the ImageCapture API. | |
| 71 // TODO(mcasas): remove ImageCapture after https://crbug.com/603328. | |
| 72 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII( | 72 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII( |
| 73 switches::kEnableBlinkFeatures, "GetUserMedia"); | 73 switches::kEnableBlinkFeatures, "GetUserMedia,ImageCapture"); |
| 74 | |
| 75 // Specific flag to enable ImageCapture API. | |
| 76 // TODO(mcasas): remove after https://crbug.com/603328 is closed. | |
| 77 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII( | |
| 78 switches::kEnableBlinkFeatures, "ImageCapture"); | |
| 79 } | 74 } |
| 80 | 75 |
| 81 void SetUp() override { | 76 void SetUp() override { |
| 82 ASSERT_TRUE(embedded_test_server()->InitializeAndListen()); | 77 ASSERT_TRUE(embedded_test_server()->InitializeAndListen()); |
| 83 WebRtcWebcamBrowserTest::SetUp(); | 78 WebRtcWebcamBrowserTest::SetUp(); |
| 84 } | 79 } |
| 85 | 80 |
| 86 // Tries to run a |command| JS test, returning true if the test can be safely | 81 // Tries to run a |command| JS test, returning true if the test can be safely |
| 87 // skipped or it works as intended, or false otherwise. | 82 // skipped or it works as intended, or false otherwise. |
| 88 bool RunImageCaptureTestCase(const std::string& command) { | 83 bool RunImageCaptureTestCase(const std::string& command) { |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 105 std::string result; | 100 std::string result; |
| 106 if (!ExecuteScriptAndExtractString(shell(), command, &result)) | 101 if (!ExecuteScriptAndExtractString(shell(), command, &result)) |
| 107 return false; | 102 return false; |
| 108 return result == "OK"; | 103 return result == "OK"; |
| 109 } | 104 } |
| 110 | 105 |
| 111 private: | 106 private: |
| 112 DISALLOW_COPY_AND_ASSIGN(WebRtcImageCaptureBrowserTest); | 107 DISALLOW_COPY_AND_ASSIGN(WebRtcImageCaptureBrowserTest); |
| 113 }; | 108 }; |
| 114 | 109 |
| 115 IN_PROC_BROWSER_TEST_P(WebRtcImageCaptureBrowserTest, | 110 IN_PROC_BROWSER_TEST_P(WebRtcImageCaptureBrowserTest, MAYBE_GetCapabilities) { |
| 116 MAYBE_CreateAndGetCapabilities) { | |
| 117 embedded_test_server()->StartAcceptingConnections(); | 111 embedded_test_server()->StartAcceptingConnections(); |
| 118 ASSERT_TRUE(RunImageCaptureTestCase("testCreateAndGetCapabilities()")); | 112 ASSERT_TRUE(RunImageCaptureTestCase("testCreateAndGetCapabilities()")); |
|
ncarter (slow)
2016/10/17 23:20:13
Do you want to rename the js methods too?
mcasas
2016/10/17 23:22:05
Nah, I like the test cases to be called after what
| |
| 119 } | 113 } |
| 120 | 114 |
| 121 IN_PROC_BROWSER_TEST_P(WebRtcImageCaptureBrowserTest, | 115 IN_PROC_BROWSER_TEST_P(WebRtcImageCaptureBrowserTest, MAYBE_TakePhoto) { |
| 122 MAYBE_CreateAndTakePhoto) { | |
| 123 embedded_test_server()->StartAcceptingConnections(); | 116 embedded_test_server()->StartAcceptingConnections(); |
| 124 ASSERT_TRUE(RunImageCaptureTestCase("testCreateAndTakePhoto()")); | 117 ASSERT_TRUE(RunImageCaptureTestCase("testCreateAndTakePhoto()")); |
| 125 } | 118 } |
| 126 | 119 |
| 127 IN_PROC_BROWSER_TEST_P(WebRtcImageCaptureBrowserTest, | 120 IN_PROC_BROWSER_TEST_P(WebRtcImageCaptureBrowserTest, MAYBE_GrabFrame) { |
| 128 MAYBE_CreateAndGrabFrame) { | |
| 129 embedded_test_server()->StartAcceptingConnections(); | 121 embedded_test_server()->StartAcceptingConnections(); |
| 130 ASSERT_TRUE(RunImageCaptureTestCase("testCreateAndGrabFrame()")); | 122 ASSERT_TRUE(RunImageCaptureTestCase("testCreateAndGrabFrame()")); |
| 131 } | 123 } |
| 132 | 124 |
| 133 INSTANTIATE_TEST_CASE_P(, | 125 INSTANTIATE_TEST_CASE_P(, |
| 134 WebRtcImageCaptureBrowserTest, | 126 WebRtcImageCaptureBrowserTest, |
| 135 testing::ValuesIn(kTestParameters)); | 127 testing::ValuesIn(kTestParameters)); |
| 136 | 128 |
| 137 } // namespace content | 129 } // namespace content |
| OLD | NEW |