1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392
|
// Copyright 2016 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "base/command_line.h"
#include "base/test/scoped_feature_list.h"
#include "build/build_config.h"
#include "content/browser/webrtc/webrtc_webcam_browsertest.h"
#include "content/public/common/content_features.h"
#include "content/public/test/browser_test.h"
#include "content/public/test/browser_test_utils.h"
#include "content/public/test/content_browser_test.h"
#include "content/public/test/content_browser_test_utils.h"
#include "content/public/test/test_utils.h"
#include "content/shell/browser/shell.h"
#include "media/base/media_switches.h"
#include "media/capture/video/fake_video_capture_device_factory.h"
#include "net/test/embedded_test_server/embedded_test_server.h"
namespace content {
// Disable FocusDistance test which fails with Logitech cameras.
// TODO(crbug.com/40624855): renable these tests when we have a way to detect
// which device is connected and hence avoid running it if the camera is
// Logitech.
#define MAYBE_ManipulateFocusDistance DISABLED_ManipulateFocusDistance
// TODO(crbug.com/40554182): Re-enable test on Android as soon as the cause for
// the bug is understood and fixed.
// TODO(crbug.com/40754212): Flaky on Linux/Windows.
#if BUILDFLAG(IS_ANDROID) || BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_WIN)
#define MAYBE_ManipulatePan DISABLED_ManipulatePan
#define MAYBE_ManipulateZoom DISABLED_ManipulateZoom
#else
#define MAYBE_ManipulatePan ManipulatePan
#define MAYBE_ManipulateZoom ManipulateZoom
#endif
// TODO(crbug.com/793859, crbug.com/986602): This test is broken on Android
// (see above) and flaky on Linux.
#if BUILDFLAG(IS_ANDROID) || BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS)
#define MAYBE_ManipulateExposureTime DISABLED_ManipulateExposureTime
#else
#define MAYBE_ManipulateExposureTime ManipulateExposureTime
#endif
#if BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS)
// See crbug/986470
#define MAYBE_GetPhotoSettings DISABLED_GetPhotoSettings
#define MAYBE_GetTrackSettings DISABLED_GetTrackSettings
#else
#define MAYBE_GetPhotoSettings GetPhotoSettings
#define MAYBE_GetTrackSettings GetTrackSettings
#endif
// These tests are flaky on all platforms: https://crbug.com/1515035,
// https://crbug.com/1187247
#define MAYBE_GrabFrame DISABLED_GrabFrame
namespace {
static const char kImageCaptureHtmlFile[] = "/media/image_capture_test.html";
enum class TargetCamera { REAL_WEBCAM, FAKE_DEVICE };
enum class TargetVideoCaptureImplementation {
DEFAULT,
#if BUILDFLAG(IS_WIN)
WIN_MEDIA_FOUNDATION
#endif
};
const TargetVideoCaptureImplementation
kTargetVideoCaptureImplementationsForFakeDevice[] = {
TargetVideoCaptureImplementation::DEFAULT};
} // namespace
// 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.
class WebRtcImageCaptureBrowserTestBase
: public UsingRealWebcam_WebRtcWebcamBrowserTest {
public:
WebRtcImageCaptureBrowserTestBase() = default;
WebRtcImageCaptureBrowserTestBase(const WebRtcImageCaptureBrowserTestBase&) =
delete;
WebRtcImageCaptureBrowserTestBase& operator=(
const WebRtcImageCaptureBrowserTestBase&) = delete;
~WebRtcImageCaptureBrowserTestBase() override = default;
void SetUpCommandLine(base::CommandLine* command_line) override {
UsingRealWebcam_WebRtcWebcamBrowserTest::SetUpCommandLine(command_line);
ASSERT_FALSE(
command_line->HasSwitch(switches::kUseFakeDeviceForMediaStream));
}
void SetUp() override {
ASSERT_TRUE(embedded_test_server()->InitializeAndListen());
UsingRealWebcam_WebRtcWebcamBrowserTest::SetUp();
}
// Tries to run a |command| JS test, returning true if the test can be safely
// skipped or it works as intended, or false otherwise.
virtual bool RunImageCaptureTestCase(const std::string& command) {
GURL url(embedded_test_server()->GetURL(kImageCaptureHtmlFile));
EXPECT_TRUE(NavigateToURL(shell(), url));
if (!IsWebcamAvailableOnSystem(shell()->web_contents())) {
DVLOG(1) << "No video device; skipping test...";
return true;
}
LookupAndLogNameAndIdOfFirstCamera();
return ExecJs(shell(), command);
}
};
// Test fixture for setting up a capture device (real or fake) that successfully
// serves all image capture requests.
class WebRtcImageCaptureSucceedsBrowserTest
: public WebRtcImageCaptureBrowserTestBase,
public testing::WithParamInterface<
std::tuple<TargetCamera,
TargetVideoCaptureImplementation>> {
public:
WebRtcImageCaptureSucceedsBrowserTest() {
std::vector<base::test::FeatureRef> features_to_enable;
std::vector<base::test::FeatureRef> features_to_disable;
#if BUILDFLAG(IS_WIN)
if (std::get<1>(GetParam()) ==
TargetVideoCaptureImplementation::WIN_MEDIA_FOUNDATION) {
features_to_enable.push_back(media::kMediaFoundationVideoCapture);
} else {
features_to_disable.push_back(media::kMediaFoundationVideoCapture);
}
#endif
scoped_feature_list_.InitWithFeatures(features_to_enable,
features_to_disable);
}
WebRtcImageCaptureSucceedsBrowserTest(
const WebRtcImageCaptureSucceedsBrowserTest&) = delete;
WebRtcImageCaptureSucceedsBrowserTest& operator=(
const WebRtcImageCaptureSucceedsBrowserTest&) = delete;
~WebRtcImageCaptureSucceedsBrowserTest() override = default;
void SetUpCommandLine(base::CommandLine* command_line) override {
WebRtcImageCaptureBrowserTestBase::SetUpCommandLine(command_line);
if (std::get<0>(GetParam()) == TargetCamera::FAKE_DEVICE) {
base::CommandLine::ForCurrentProcess()->AppendSwitch(
switches::kUseFakeDeviceForMediaStream);
ASSERT_TRUE(base::CommandLine::ForCurrentProcess()->HasSwitch(
switches::kUseFakeDeviceForMediaStream));
}
}
private:
base::test::ScopedFeatureList scoped_feature_list_;
};
// TODO(crbug.com/41478485): Flaky on Linux.
#if BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS)
#define MAYBE_GetPhotoCapabilities DISABLED_GetPhotoCapabilities
#else
#define MAYBE_GetPhotoCapabilities GetPhotoCapabilities
#endif
IN_PROC_BROWSER_TEST_P(WebRtcImageCaptureSucceedsBrowserTest,
MAYBE_GetPhotoCapabilities) {
embedded_test_server()->StartAcceptingConnections();
ASSERT_TRUE(
RunImageCaptureTestCase("testCreateAndGetPhotoCapabilitiesSucceeds()"));
}
IN_PROC_BROWSER_TEST_P(WebRtcImageCaptureSucceedsBrowserTest,
MAYBE_GetPhotoSettings) {
embedded_test_server()->StartAcceptingConnections();
ASSERT_TRUE(
RunImageCaptureTestCase("testCreateAndGetPhotoSettingsSucceeds()"));
}
// TODO(crbug.com/40754212): Flaky on Linux/Windows.
#if BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_WIN)
#define MAYBE_TakePhoto DISABLED_TakePhoto
#else
#define MAYBE_TakePhoto TakePhoto
#endif
IN_PROC_BROWSER_TEST_P(WebRtcImageCaptureSucceedsBrowserTest, MAYBE_TakePhoto) {
embedded_test_server()->StartAcceptingConnections();
ASSERT_TRUE(RunImageCaptureTestCase("testCreateAndTakePhotoSucceeds()"));
}
IN_PROC_BROWSER_TEST_P(WebRtcImageCaptureSucceedsBrowserTest, MAYBE_GrabFrame) {
embedded_test_server()->StartAcceptingConnections();
ASSERT_TRUE(RunImageCaptureTestCase("testCreateAndGrabFrameSucceeds()"));
}
// Flaky. crbug.com/998116
#if BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS)
#define MAYBE_GetTrackCapabilities DISABLED_GetTrackCapabilities
#else
#define MAYBE_GetTrackCapabilities GetTrackCapabilities
#endif
IN_PROC_BROWSER_TEST_P(WebRtcImageCaptureSucceedsBrowserTest,
MAYBE_GetTrackCapabilities) {
embedded_test_server()->StartAcceptingConnections();
ASSERT_TRUE(RunImageCaptureTestCase("testCreateAndGetTrackCapabilities()"));
}
IN_PROC_BROWSER_TEST_P(WebRtcImageCaptureSucceedsBrowserTest,
MAYBE_GetTrackSettings) {
embedded_test_server()->StartAcceptingConnections();
ASSERT_TRUE(RunImageCaptureTestCase("testCreateAndGetTrackSettings()"));
}
IN_PROC_BROWSER_TEST_P(WebRtcImageCaptureSucceedsBrowserTest,
MAYBE_ManipulatePan) {
embedded_test_server()->StartAcceptingConnections();
ASSERT_TRUE(RunImageCaptureTestCase("testManipulatePan()"));
}
// TODO(crbug.com/41478484): Flaky on Linux.
// TODO(crbug.com/40554182): Re-enable test on Android as soon as the cause for
// the bug is understood and fixed.
#if BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS) || BUILDFLAG(IS_ANDROID)
#define MAYBE_ManipulateTilt DISABLED_ManipulateTilt
#else
#define MAYBE_ManipulateTilt ManipulateTilt
#endif
IN_PROC_BROWSER_TEST_P(WebRtcImageCaptureSucceedsBrowserTest,
MAYBE_ManipulateTilt) {
embedded_test_server()->StartAcceptingConnections();
ASSERT_TRUE(RunImageCaptureTestCase("testManipulateTilt()"));
}
IN_PROC_BROWSER_TEST_P(WebRtcImageCaptureSucceedsBrowserTest,
MAYBE_ManipulateZoom) {
embedded_test_server()->StartAcceptingConnections();
ASSERT_TRUE(RunImageCaptureTestCase("testManipulateZoom()"));
}
IN_PROC_BROWSER_TEST_P(WebRtcImageCaptureSucceedsBrowserTest,
MAYBE_ManipulateExposureTime) {
embedded_test_server()->StartAcceptingConnections();
ASSERT_TRUE(RunImageCaptureTestCase("testManipulateExposureTime()"));
}
IN_PROC_BROWSER_TEST_P(WebRtcImageCaptureSucceedsBrowserTest,
MAYBE_ManipulateFocusDistance) {
embedded_test_server()->StartAcceptingConnections();
ASSERT_TRUE(RunImageCaptureTestCase("testManipulateFocusDistance()"));
}
INSTANTIATE_TEST_SUITE_P(
All, // Use no prefix, so that these get picked up when using
// --gtest_filter=WebRtc*
WebRtcImageCaptureSucceedsBrowserTest,
testing::Combine(
testing::Values(TargetCamera::FAKE_DEVICE),
testing::ValuesIn(kTargetVideoCaptureImplementationsForFakeDevice)));
// Tests on real webcam can only run on platforms for which the image capture
// API has already been implemented.
// Note, these tests must be run sequentially, since multiple parallel test runs
// competing for a single physical webcam typically causes failures.
#if BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS) || BUILDFLAG(IS_MAC) || \
BUILDFLAG(IS_ANDROID) || BUILDFLAG(IS_WIN)
const TargetVideoCaptureImplementation
kTargetVideoCaptureImplementationsForRealWebcam[] = {
TargetVideoCaptureImplementation::DEFAULT,
#if BUILDFLAG(IS_WIN)
TargetVideoCaptureImplementation::WIN_MEDIA_FOUNDATION
#endif
};
INSTANTIATE_TEST_SUITE_P(
UsingRealWebcam, // This prefix can be used with --gtest_filter to
// distinguish the tests using a real camera from the ones
// that don't.
WebRtcImageCaptureSucceedsBrowserTest,
testing::Combine(
testing::Values(TargetCamera::REAL_WEBCAM),
testing::ValuesIn(kTargetVideoCaptureImplementationsForRealWebcam)));
#endif
// Test fixture template for setting up a fake device with a custom
// configuration. We are going to use this to set up fake devices that respond
// to invocation of various ImageCapture API calls with a failure response.
template <typename FakeDeviceConfigTraits>
class WebRtcImageCaptureCustomConfigFakeDeviceBrowserTest
: public WebRtcImageCaptureBrowserTestBase {
public:
WebRtcImageCaptureCustomConfigFakeDeviceBrowserTest() = default;
WebRtcImageCaptureCustomConfigFakeDeviceBrowserTest(
const WebRtcImageCaptureCustomConfigFakeDeviceBrowserTest&) = delete;
WebRtcImageCaptureCustomConfigFakeDeviceBrowserTest& operator=(
const WebRtcImageCaptureCustomConfigFakeDeviceBrowserTest&) = delete;
~WebRtcImageCaptureCustomConfigFakeDeviceBrowserTest() override {}
void SetUpCommandLine(base::CommandLine* command_line) override {
WebRtcImageCaptureBrowserTestBase::SetUpCommandLine(command_line);
base::CommandLine::ForCurrentProcess()->AppendSwitchASCII(
switches::kUseFakeDeviceForMediaStream,
std::string("config=") + FakeDeviceConfigTraits::config());
}
};
struct GetPhotoStateFailsConfigTraits {
static std::string config() {
return media::FakeVideoCaptureDeviceFactory::
kDeviceConfigForGetPhotoStateFails;
}
};
using WebRtcImageCaptureGetPhotoStateFailsBrowserTest =
WebRtcImageCaptureCustomConfigFakeDeviceBrowserTest<
GetPhotoStateFailsConfigTraits>;
IN_PROC_BROWSER_TEST_F(WebRtcImageCaptureGetPhotoStateFailsBrowserTest,
GetCapabilities) {
embedded_test_server()->StartAcceptingConnections();
// When the fake device faile, we expect an empty set of capabilities to
// reported back to JS.
ASSERT_TRUE(
RunImageCaptureTestCase("testCreateAndGetPhotoCapabilitiesSucceeds()"));
}
IN_PROC_BROWSER_TEST_F(WebRtcImageCaptureGetPhotoStateFailsBrowserTest,
TakePhoto) {
embedded_test_server()->StartAcceptingConnections();
ASSERT_TRUE(RunImageCaptureTestCase("testCreateAndTakePhotoSucceeds()"));
}
IN_PROC_BROWSER_TEST_F(WebRtcImageCaptureGetPhotoStateFailsBrowserTest,
MAYBE_GrabFrame) {
embedded_test_server()->StartAcceptingConnections();
ASSERT_TRUE(RunImageCaptureTestCase("testCreateAndGrabFrameSucceeds()"));
}
struct SetPhotoOptionsFailsConfigTraits {
static std::string config() {
return media::FakeVideoCaptureDeviceFactory::
kDeviceConfigForSetPhotoOptionsFails;
}
};
using WebRtcImageCaptureSetPhotoOptionsFailsBrowserTest =
WebRtcImageCaptureCustomConfigFakeDeviceBrowserTest<
SetPhotoOptionsFailsConfigTraits>;
IN_PROC_BROWSER_TEST_F(WebRtcImageCaptureSetPhotoOptionsFailsBrowserTest,
TakePhoto) {
embedded_test_server()->StartAcceptingConnections();
ASSERT_TRUE(RunImageCaptureTestCase("testCreateAndTakePhotoIsRejected()"));
}
IN_PROC_BROWSER_TEST_F(WebRtcImageCaptureSetPhotoOptionsFailsBrowserTest,
MAYBE_GrabFrame) {
embedded_test_server()->StartAcceptingConnections();
ASSERT_TRUE(RunImageCaptureTestCase("testCreateAndGrabFrameSucceeds()"));
}
struct TakePhotoFailsConfigTraits {
static std::string config() {
return media::FakeVideoCaptureDeviceFactory::kDeviceConfigForTakePhotoFails;
}
};
using WebRtcImageCaptureTakePhotoFailsBrowserTest =
WebRtcImageCaptureCustomConfigFakeDeviceBrowserTest<
TakePhotoFailsConfigTraits>;
IN_PROC_BROWSER_TEST_F(WebRtcImageCaptureTakePhotoFailsBrowserTest, TakePhoto) {
embedded_test_server()->StartAcceptingConnections();
ASSERT_TRUE(RunImageCaptureTestCase("testCreateAndTakePhotoIsRejected()"));
}
IN_PROC_BROWSER_TEST_F(WebRtcImageCaptureTakePhotoFailsBrowserTest,
MAYBE_GrabFrame) {
embedded_test_server()->StartAcceptingConnections();
ASSERT_TRUE(RunImageCaptureTestCase("testCreateAndGrabFrameSucceeds()"));
}
} // namespace content
|