chromium/content/browser/webrtc/webrtc_image_capture_browsertest.cc

// 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

// 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
#define MAYBE_ManipulateZoom
#else
#define MAYBE_ManipulatePan
#define MAYBE_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
#else
#define MAYBE_ManipulateExposureTime
#endif

#if BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS)
// See crbug/986470
#define MAYBE_GetPhotoSettings
#define MAYBE_GetTrackSettings
#else
#define MAYBE_GetPhotoSettings
#define MAYBE_GetTrackSettings
#endif

// These tests are flaky on all platforms: https://crbug.com/1515035,
// https://crbug.com/1187247
#define MAYBE_GrabFrame

namespace {

static const char kImageCaptureHtmlFile[] =;

enum class TargetCamera {};

enum class TargetVideoCaptureImplementation {};
const TargetVideoCaptureImplementation
    kTargetVideoCaptureImplementationsForFakeDevice[] =;

}  // 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 {};

// 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>> {};

// TODO(crbug.com/41478485): Flaky on Linux.
#if BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS)
#define MAYBE_GetPhotoCapabilities
#else
#define MAYBE_GetPhotoCapabilities
#endif
IN_PROC_BROWSER_TEST_P(WebRtcImageCaptureSucceedsBrowserTest,
                       MAYBE_GetPhotoCapabilities) {}

IN_PROC_BROWSER_TEST_P(WebRtcImageCaptureSucceedsBrowserTest,
                       MAYBE_GetPhotoSettings) {}

// TODO(crbug.com/40754212): Flaky on Linux/Windows.
#if BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_WIN)
#define MAYBE_TakePhoto
#else
#define MAYBE_TakePhoto
#endif
IN_PROC_BROWSER_TEST_P(WebRtcImageCaptureSucceedsBrowserTest, MAYBE_TakePhoto) {}

IN_PROC_BROWSER_TEST_P(WebRtcImageCaptureSucceedsBrowserTest, MAYBE_GrabFrame) {}

// Flaky. crbug.com/998116
#if BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS)
#define MAYBE_GetTrackCapabilities
#else
#define MAYBE_GetTrackCapabilities
#endif
IN_PROC_BROWSER_TEST_P(WebRtcImageCaptureSucceedsBrowserTest,
                       MAYBE_GetTrackCapabilities) {}

IN_PROC_BROWSER_TEST_P(WebRtcImageCaptureSucceedsBrowserTest,
                       MAYBE_GetTrackSettings) {}

IN_PROC_BROWSER_TEST_P(WebRtcImageCaptureSucceedsBrowserTest,
                       MAYBE_ManipulatePan) {}

// 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
#else
#define MAYBE_ManipulateTilt
#endif
IN_PROC_BROWSER_TEST_P(WebRtcImageCaptureSucceedsBrowserTest,
                       MAYBE_ManipulateTilt) {}

IN_PROC_BROWSER_TEST_P(WebRtcImageCaptureSucceedsBrowserTest,
                       MAYBE_ManipulateZoom) {}

IN_PROC_BROWSER_TEST_P(WebRtcImageCaptureSucceedsBrowserTest,
                       MAYBE_ManipulateExposureTime) {}

IN_PROC_BROWSER_TEST_P(WebRtcImageCaptureSucceedsBrowserTest,
                       MAYBE_ManipulateFocusDistance) {}

INSTANTIATE_TEST_SUITE_P();

// 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[] =;

INSTANTIATE_TEST_SUITE_P();
#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 {};

struct GetPhotoStateFailsConfigTraits {};

WebRtcImageCaptureGetPhotoStateFailsBrowserTest;

IN_PROC_BROWSER_TEST_F(WebRtcImageCaptureGetPhotoStateFailsBrowserTest,
                       GetCapabilities) {}

IN_PROC_BROWSER_TEST_F(WebRtcImageCaptureGetPhotoStateFailsBrowserTest,
                       TakePhoto) {}

IN_PROC_BROWSER_TEST_F(WebRtcImageCaptureGetPhotoStateFailsBrowserTest,
                       MAYBE_GrabFrame) {}

struct SetPhotoOptionsFailsConfigTraits {};

WebRtcImageCaptureSetPhotoOptionsFailsBrowserTest;

IN_PROC_BROWSER_TEST_F(WebRtcImageCaptureSetPhotoOptionsFailsBrowserTest,
                       TakePhoto) {}

IN_PROC_BROWSER_TEST_F(WebRtcImageCaptureSetPhotoOptionsFailsBrowserTest,
                       MAYBE_GrabFrame) {}

struct TakePhotoFailsConfigTraits {};

WebRtcImageCaptureTakePhotoFailsBrowserTest;

IN_PROC_BROWSER_TEST_F(WebRtcImageCaptureTakePhotoFailsBrowserTest, TakePhoto) {}

IN_PROC_BROWSER_TEST_F(WebRtcImageCaptureTakePhotoFailsBrowserTest,
                       MAYBE_GrabFrame) {}

}  // namespace content