chromium/third_party/blink/renderer/modules/imagecapture/image_capture_test.cc

// Copyright 2023 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifdef UNSAFE_BUFFERS_BUILD
// TODO(crbug.com/351564777): Remove this and convert code to safer constructs.
#pragma allow_unsafe_buffers
#endif

#include "third_party/blink/renderer/modules/imagecapture/image_capture.h"

#include "base/time/time.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/blink/public/web/web_heap.h"
#include "third_party/blink/renderer/bindings/core/v8/script_function.h"
#include "third_party/blink/renderer/bindings/core/v8/script_promise_resolver.h"
#include "third_party/blink/renderer/bindings/core/v8/script_promise_tester.h"
#include "third_party/blink/renderer/bindings/core/v8/v8_binding_for_testing.h"
#include "third_party/blink/renderer/bindings/core/v8/v8_union_string_stringsequence.h"
#include "third_party/blink/renderer/bindings/modules/v8/v8_constrain_boolean_parameters.h"
#include "third_party/blink/renderer/bindings/modules/v8/v8_constrain_dom_string_parameters.h"
#include "third_party/blink/renderer/bindings/modules/v8/v8_constrain_double_range.h"
#include "third_party/blink/renderer/bindings/modules/v8/v8_constrain_point_2d_parameters.h"
#include "third_party/blink/renderer/bindings/modules/v8/v8_media_settings_range.h"
#include "third_party/blink/renderer/bindings/modules/v8/v8_point_2d.h"
#include "third_party/blink/renderer/bindings/modules/v8/v8_union_boolean_constrainbooleanparameters.h"
#include "third_party/blink/renderer/bindings/modules/v8/v8_union_boolean_constraindoublerange_double.h"
#include "third_party/blink/renderer/bindings/modules/v8/v8_union_constraindomstringparameters_string_stringsequence.h"
#include "third_party/blink/renderer/bindings/modules/v8/v8_union_constraindoublerange_double.h"
#include "third_party/blink/renderer/bindings/modules/v8/v8_union_constrainpoint2dparameters_point2dsequence.h"
#include "third_party/blink/renderer/core/frame/local_frame.h"
#include "third_party/blink/renderer/core/page/page.h"
#include "third_party/blink/renderer/modules/imagecapture/image_capture.h"
#include "third_party/blink/renderer/modules/mediastream/media_stream_video_capturer_source.h"
#include "third_party/blink/renderer/modules/mediastream/media_stream_video_track.h"
#include "third_party/blink/renderer/modules/mediastream/mock_media_stream_track.h"
#include "third_party/blink/renderer/modules/mediastream/mock_video_capturer_source.h"
#include "third_party/blink/renderer/platform/bindings/script_state.h"
#include "third_party/blink/renderer/platform/testing/io_task_runner_testing_platform_support.h"
#include "third_party/blink/renderer/platform/testing/task_environment.h"

namespace blink {

namespace {

ExpectHasExposureModeAndFocusMode;
ExpectHasPanTiltZoom;
PopulatePanTiltZoom;

_;
Invoke;
NiceMock;
Return;

constexpr double kExposureCompensationDelta =;
constexpr double kExposureTimeDelta =;
constexpr double kColorTemperatureDelta =;
constexpr double kIsoDelta =;
constexpr double kBrightnessDelta =;
constexpr double kContrastDelta =;
constexpr double kSaturationDelta =;
constexpr double kSharpnessDelta =;
constexpr double kFocusDistanceDelta =;
constexpr double kPanDelta =;
constexpr double kTiltDelta =;
constexpr double kZoomDelta =;

// CaptureErrorFunction implements a javascript function which captures
// name, message and constraint of the exception passed as its argument.
class CaptureErrorFunction final : public ScriptFunction::Callable {};

// These traits and type aliases simplify mapping from bare value types (bool,
// double, sequence, string) to constrain value dictionary types.
template <typename T>
struct ConstrainWithDictionaryTraits;

template <>
struct ConstrainWithDictionaryTraits<bool> {};

template <>
struct ConstrainWithDictionaryTraits<double> {};

template <>
struct ConstrainWithDictionaryTraits<HeapVector<Member<Point2D>>> {};

template <>
struct ConstrainWithDictionaryTraits<String> {};

template <>
struct ConstrainWithDictionaryTraits<Vector<String>> {};

ConstrainWithDictionaryType;

// The `ConstrainDOMStringParameters` dictionary type has `exact` and `ideal`
// members of type `(DOMString or sequence<DOMString>)`.
// https://w3c.github.io/mediacapture-main/#dom-constraindomstringparameters
V8UnionStringOrStringSequence* CreateDictionaryMemberValue(
    const String& value) {}

V8UnionStringOrStringSequence* CreateDictionaryMemberValue(
    const Vector<String>& value) {}

// All the other constrain value dictionary types (ConstrainBooleanParameters,
// ConstrainDoubleRange and ConstrainPoint2DParameters) have `exact` and
// `ideal` members of non-union types.
// https://w3c.github.io/mediacapture-main/#dom-constrainbooleanparameters
// https://w3c.github.io/mediacapture-main/#dom-constraindoublerange
// https://w3c.github.io/mediacapture-main/#dom-constrainpoint2dparameters
template <typename T>
const T& CreateDictionaryMemberValue(const T& value) {}

// This creator creates bare value (bool, double, sequence, string)
// constraints.
struct ConstrainWithBareValueCreator {};

// This creator creates constrain value dictionary constraints without members.
struct ConstrainWithEmptyDictionaryCreator {};

// This creator creates constrain value dictionary constraints with `exact`
// members.
struct ConstrainWithExactDictionaryCreator {};

// This creator creates constrain value dictionary constraints with `ideal`
// members.
struct ConstrainWithIdealDictionaryCreator {};

// This creator creates constrain value dictionary constraints with `max`
// members.
struct ConstrainWithMaxDictionaryCreator {};

// This creator creates constrain value dictionary constraints with `max`
// members for numeric (double) values and empty constrain value dictionary
// constraints for non-numeric (bool, sequence, string) values.
struct ConstrainWithMaxOrEmptyDictionaryCreator {};

// This creator creates constrain value dictionary constraints with `min`
// members.
struct ConstrainWithMinDictionaryCreator {};

// This creator creates constrain value dictionary constraints with `min`
// members for numeric (double) values and empty constrain value dictionary
// constraints for non-numeric (bool, sequence, string) values.
struct ConstrainWithMinOrEmptyDictionaryCreator {};

MediaSettingsRange* CreateMediaSettingsRange(double min,
                                             double max,
                                             double step) {}

MediaSettingsRange* CreateMediaSettingsRange(const char (&str)[3]) {}

Point2D* CreatePoint2D(double x, double y) {}

double RangeMean(const MediaSettingsRange* range) {}

void CheckExactValues(
    const media::mojom::blink::PhotoSettingsPtr& settings,
    const MediaTrackCapabilities* all_capabilities,
    ExpectHasPanTiltZoom expect_has_pan_tilt_zoom = ExpectHasPanTiltZoom(true),
    ExpectHasExposureModeAndFocusMode expect_has_exposure_mode_and_focus_mode =
        ExpectHasExposureModeAndFocusMode(true)) {}

void CheckMaxValues(const media::mojom::blink::PhotoSettingsPtr& settings,
                    const MediaTrackCapabilities* all_capabilities,
                    const MediaTrackSettings* default_settings,
                    ExpectHasPanTiltZoom expect_has_pan_tilt_zoom =
                        ExpectHasPanTiltZoom(true)) {}

void CheckMinValues(const media::mojom::blink::PhotoSettingsPtr& settings,
                    const MediaTrackCapabilities* all_capabilities,
                    const MediaTrackSettings* default_settings,
                    ExpectHasPanTiltZoom expect_has_pan_tilt_zoom =
                        ExpectHasPanTiltZoom(true)) {}

void CheckNoValues(const media::mojom::blink::PhotoSettingsPtr& settings,
                   size_t expected_points_of_interest_size = 0u) {}

template <typename ConstraintCreator>
void PopulateConstraintSet(
    MediaTrackConstraintSet* constraint_set,
    const MediaTrackCapabilities* all_capabilities,
    PopulatePanTiltZoom populate_pan_tilt_zoom = PopulatePanTiltZoom(true)) {}

class MockMediaStreamComponent
    : public GarbageCollected<MockMediaStreamComponent>,
      public MediaStreamComponent {};

}  // namespace

class ImageCaptureTest : public testing::Test {};

class ImageCaptureConstraintTest : public ImageCaptureTest {};

TEST_F(ImageCaptureConstraintTest, ApplyBasicBareValueConstraints) {}

TEST_F(ImageCaptureConstraintTest, ApplyBasicExactConstraints) {}

TEST_F(ImageCaptureConstraintTest, ApplyBasicIdealConstraints) {}

TEST_F(ImageCaptureConstraintTest, ApplyBasicMaxConstraints) {}

TEST_F(ImageCaptureConstraintTest, ApplyBasicMinConstraints) {}

// If an empty list has been given as the value for a constraint, it MUST be
// interpreted as if the constraint were not specified (in other words,
// an empty constraint == no constraint).
// https://w3c.github.io/mediacapture-main/#dfn-selectsettings
TEST_F(ImageCaptureConstraintTest, ApplyBasicNoConstraints) {}

TEST_F(ImageCaptureConstraintTest, ApplyBasicOverconstrainedConstraints) {}

TEST_F(ImageCaptureConstraintTest, ApplyFirstAdvancedBareValueConstraints) {}

TEST_F(ImageCaptureConstraintTest, ApplyFirstAdvancedExactConstraints) {}

TEST_F(ImageCaptureConstraintTest, ApplyFirstAdvancedIdealConstraints) {}

TEST_F(ImageCaptureConstraintTest,
       ApplyFirstAdvancedOverconstrainedConstraints) {}

TEST_F(ImageCaptureConstraintTest, ApplyAdvancedBareValueConstraints) {}

TEST_F(ImageCaptureConstraintTest, ApplyAdvancedExactConstraints) {}

TEST_F(ImageCaptureConstraintTest, ApplyAdvancedIdealConstraints) {}

// If an empty list has been given as the value for a constraint, it MUST be
// interpreted as if the constraint were not specified (in other words,
// an empty constraint == no constraint).
// https://w3c.github.io/mediacapture-main/#dfn-selectsettings
TEST_F(ImageCaptureConstraintTest, ApplyAdvancedNoConstraints) {}

TEST_F(ImageCaptureConstraintTest, ApplyAdvancedOverconstrainedConstraints) {}

// If the visibilityState of the top-level browsing context value is "hidden",
// the `applyConstraints()` algorithm MUST throw a `SecurityError` if `pan`,
// `tilt` or `zoom` dictionary member exists with a value other than `false`.
// https://w3c.github.io/mediacapture-image/#pan
// https://w3c.github.io/mediacapture-image/#tilt
// https://w3c.github.io/mediacapture-image/#zoom
TEST_F(ImageCaptureConstraintTest, ApplySecurityErrorConstraints) {}

TEST_F(ImageCaptureTest, GrabFrameOfLiveTrackIsFulfilled) {}

TEST_F(ImageCaptureTest, GrabFrameOfMutedTrackIsFulfilled) {}

TEST_F(ImageCaptureTest, GrabFrameOfMutedTrackWithoutFramesIsRejected) {}

TEST_F(ImageCaptureTest, GrabFrameOfEndedTrackRejects) {}

TEST_F(ImageCaptureTest, GrabFrameOfDisabledTrackRejects) {}

}  // namespace blink