Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(9)

Side by Side Diff: content/browser/webrtc/webrtc_image_capture_browsertest.cc

Issue 2418923003: ImageCapture: avoid several grabFrame()s in flight, beef up content_browsertests (Closed)
Patch Set: xianglu@ comments Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | content/renderer/media/image_capture_frame_grabber.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 {
22
23 #if defined(OS_WIN)
24 // These tests are flaky on WebRTC Windows bots: https://crbug.com/633242.
25 #define MAYBE_CreateAndGetCapabilities DISABLED_CreateAndGetCapabilities
26 #define MAYBE_CreateAndTakePhoto DISABLED_CreateAndTakePhoto
27 #define MAYBE_CreateAndGrabFrame DISABLED_CreateAndGrabFrame
28 #else
29 #define MAYBE_CreateAndGetCapabilities CreateAndGetCapabilities
30 #define MAYBE_CreateAndTakePhoto CreateAndTakePhoto
31 #define MAYBE_CreateAndGrabFrame CreateAndGrabFrame
32 #endif
33
21 namespace { 34 namespace {
22 35
23 static const char kImageCaptureHtmlFile[] = "/media/image_capture_test.html"; 36 static const char kImageCaptureHtmlFile[] = "/media/image_capture_test.html";
24 37
25 // 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
26 // platforms where the ImageCaptureCode is landed, https://crbug.com/518807. 39 // platforms where the ImageCaptureCode is landed, https://crbug.com/518807.
27 // TODO(mcasas): enable in Android when takePhoto() can be specified a (small) 40 // TODO(mcasas): enable in Android when takePhoto() can be specified a (small)
28 // capture resolution preventing the test from timeout https://crbug.com/634811. 41 // capture resolution preventing the test from timeout https://crbug.com/634811.
29 static struct TargetCamera { 42 static struct TargetCamera {
30 bool use_fake; 43 bool use_fake;
31 } const kTestParameters[] = {{true}}; 44 } const kTestParameters[] = {{true}};
32 45
33 } // namespace 46 } // namespace
34 47
35 namespace content {
36
37 // This class is the content_browsertests for Image Capture API, which allows 48 // This class is the content_browsertests for Image Capture API, which allows
38 // for capturing still images out of a MediaStreamTrack. Is a 49 // for capturing still images out of a MediaStreamTrack. Is a
39 // WebRtcWebcamBrowserTest to be able to use a physical camera. 50 // WebRtcWebcamBrowserTest to be able to use a physical camera.
40 class WebRtcImageCaptureBrowserTest 51 class WebRtcImageCaptureBrowserTest
41 : public WebRtcWebcamBrowserTest, 52 : public WebRtcWebcamBrowserTest,
42 public testing::WithParamInterface<struct TargetCamera> { 53 public testing::WithParamInterface<struct TargetCamera> {
43 public: 54 public:
44 WebRtcImageCaptureBrowserTest() = default; 55 WebRtcImageCaptureBrowserTest() = default;
45 ~WebRtcImageCaptureBrowserTest() override = default; 56 ~WebRtcImageCaptureBrowserTest() override = default;
46 57
(...skipping 13 matching lines...) Expand all
60 // TODO(mcasas): remove after https://crbug.com/503227 is closed. 71 // TODO(mcasas): remove after https://crbug.com/503227 is closed.
61 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII( 72 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII(
62 switches::kEnableBlinkFeatures, "GetUserMedia"); 73 switches::kEnableBlinkFeatures, "GetUserMedia");
63 74
64 // Specific flag to enable ImageCapture API. 75 // Specific flag to enable ImageCapture API.
65 // TODO(mcasas): remove after https://crbug.com/603328 is closed. 76 // TODO(mcasas): remove after https://crbug.com/603328 is closed.
66 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII( 77 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII(
67 switches::kEnableBlinkFeatures, "ImageCapture"); 78 switches::kEnableBlinkFeatures, "ImageCapture");
68 } 79 }
69 80
81 void SetUp() override {
82 ASSERT_TRUE(embedded_test_server()->InitializeAndListen());
83 WebRtcWebcamBrowserTest::SetUp();
84 }
85
86 // 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.
88 bool RunImageCaptureTestCase(const std::string& command) {
89 #if defined(OS_ANDROID)
90 // TODO(mcasas): fails on Lollipop devices: https://crbug.com/634811
91 if (base::android::BuildInfo::GetInstance()->sdk_int() <
92 base::android::SDK_VERSION_MARSHMALLOW) {
93 return true;
94 }
95 #endif
96
97 GURL url(embedded_test_server()->GetURL(kImageCaptureHtmlFile));
98 NavigateToURL(shell(), url);
99
100 if (!IsWebcamAvailableOnSystem(shell()->web_contents())) {
101 DVLOG(1) << "No video device; skipping test...";
102 return true;
103 }
104
105 std::string result;
106 if (!ExecuteScriptAndExtractString(shell(), command, &result))
107 return false;
108 return result == "OK";
109 }
110
70 private: 111 private:
71 DISALLOW_COPY_AND_ASSIGN(WebRtcImageCaptureBrowserTest); 112 DISALLOW_COPY_AND_ASSIGN(WebRtcImageCaptureBrowserTest);
72 }; 113 };
73 114
74 #if defined(OS_WIN)
75 // This test is flaky on WebRTC Windows bots: https://crbug.com/633242.
76 #define MAYBE_CreateAndGetCapabilities DISABLED_CreateAndGetCapabilities
77 #else
78 #define MAYBE_CreateAndGetCapabilities CreateAndGetCapabilities
79 #endif
80 IN_PROC_BROWSER_TEST_P(WebRtcImageCaptureBrowserTest, 115 IN_PROC_BROWSER_TEST_P(WebRtcImageCaptureBrowserTest,
81 MAYBE_CreateAndGetCapabilities) { 116 MAYBE_CreateAndGetCapabilities) {
82 #if defined(OS_ANDROID) 117 embedded_test_server()->StartAcceptingConnections();
83 // TODO(mcasas): fails on Lollipop devices: https://crbug.com/634811 118 ASSERT_TRUE(RunImageCaptureTestCase("testCreateAndGetCapabilities()"));
84 if (base::android::BuildInfo::GetInstance()->sdk_int() <
85 base::android::SDK_VERSION_MARSHMALLOW) {
86 return;
87 }
88 #endif
89
90 ASSERT_TRUE(embedded_test_server()->Start());
91 GURL url(embedded_test_server()->GetURL(kImageCaptureHtmlFile));
92 NavigateToURL(shell(), url);
93
94 if (!IsWebcamAvailableOnSystem(shell()->web_contents())) {
95 DVLOG(1) << "No video device; skipping test...";
96 return;
97 }
98
99 std::string result;
100 ASSERT_TRUE(ExecuteScriptAndExtractString(
101 shell(), "testCreateAndGetCapabilities()", &result));
102 if (result == "OK")
103 return;
104 FAIL();
105 } 119 }
106 120
107 #if defined(OS_WIN)
108 // This test is flaky on WebRTC Windows bots: https://crbug.com/633242.
109 #define MAYBE_CreateAndTakePhoto DISABLED_CreateAndTakePhoto
110 #else
111 #define MAYBE_CreateAndTakePhoto CreateAndTakePhoto
112 #endif
113 IN_PROC_BROWSER_TEST_P(WebRtcImageCaptureBrowserTest, 121 IN_PROC_BROWSER_TEST_P(WebRtcImageCaptureBrowserTest,
114 MAYBE_CreateAndTakePhoto) { 122 MAYBE_CreateAndTakePhoto) {
115 #if defined(OS_ANDROID) 123 embedded_test_server()->StartAcceptingConnections();
116 // TODO(mcasas): fails on Lollipop devices: https://crbug.com/634811 124 ASSERT_TRUE(RunImageCaptureTestCase("testCreateAndTakePhoto()"));
117 if (base::android::BuildInfo::GetInstance()->sdk_int() < 125 }
118 base::android::SDK_VERSION_MARSHMALLOW) {
119 return;
120 }
121 #endif
122 126
123 ASSERT_TRUE(embedded_test_server()->Start()); 127 IN_PROC_BROWSER_TEST_P(WebRtcImageCaptureBrowserTest,
124 GURL url(embedded_test_server()->GetURL(kImageCaptureHtmlFile)); 128 MAYBE_CreateAndGrabFrame) {
125 NavigateToURL(shell(), url); 129 embedded_test_server()->StartAcceptingConnections();
126 130 ASSERT_TRUE(RunImageCaptureTestCase("testCreateAndGrabFrame()"));
127 if (!IsWebcamAvailableOnSystem(shell()->web_contents())) {
128 DVLOG(1) << "No video device; skipping test...";
129 return;
130 }
131
132 std::string result;
133 ASSERT_TRUE(ExecuteScriptAndExtractString(shell(), "testCreateAndTakePhoto()",
134 &result));
135 if (result == "OK")
136 return;
137 FAIL();
138 } 131 }
139 132
140 INSTANTIATE_TEST_CASE_P(, 133 INSTANTIATE_TEST_CASE_P(,
141 WebRtcImageCaptureBrowserTest, 134 WebRtcImageCaptureBrowserTest,
142 testing::ValuesIn(kTestParameters)); 135 testing::ValuesIn(kTestParameters));
143 136
144 } // namespace content 137 } // namespace content
OLDNEW
« no previous file with comments | « no previous file | content/renderer/media/image_capture_frame_grabber.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698