| Index: content/renderer/media/media_stream_video_source_unittest.cc
|
| diff --git a/content/renderer/media/media_stream_video_source_unittest.cc b/content/renderer/media/media_stream_video_source_unittest.cc
|
| index ec595fe1e090c958430ea949aa3cd05f81a66d28..5a360caef0736e3db0d074b531775be5ae9e6c8a 100644
|
| --- a/content/renderer/media/media_stream_video_source_unittest.cc
|
| +++ b/content/renderer/media/media_stream_video_source_unittest.cc
|
| @@ -9,6 +9,7 @@
|
| #include "base/strings/utf_string_conversions.h"
|
| #include "content/renderer/media/media_stream_video_source.h"
|
| #include "content/renderer/media/media_stream_video_track.h"
|
| +#include "content/renderer/media/mock_media_constraint_factory.h"
|
| #include "content/renderer/media/mock_media_stream_dependency_factory.h"
|
| #include "content/renderer/media/mock_media_stream_video_source.h"
|
| #include "media/base/video_frame.h"
|
| @@ -16,42 +17,6 @@
|
|
|
| namespace content {
|
|
|
| -class ConstraintsFactory {
|
| - public:
|
| - void AddMandatory(const std::string& key, int value) {
|
| - mandatory_.push_back(blink::WebMediaConstraint(base::UTF8ToUTF16(key),
|
| - base::IntToString16(value)));
|
| - }
|
| - void AddMandatory(const std::string& key, double value) {
|
| - mandatory_.push_back(blink::WebMediaConstraint(
|
| - base::UTF8ToUTF16(key),
|
| - base::UTF8ToUTF16(base::DoubleToString(value))));
|
| - }
|
| -
|
| - void AddOptional(const std::string& key, int value) {
|
| - optional_.push_back(blink::WebMediaConstraint(base::UTF8ToUTF16(key),
|
| - base::IntToString16(value)));
|
| - }
|
| -
|
| - void AddOptional(const std::string& key, double value) {
|
| - optional_.push_back(blink::WebMediaConstraint(
|
| - base::UTF8ToUTF16(key),
|
| - base::UTF8ToUTF16(base::DoubleToString(value))));
|
| - }
|
| -
|
| - blink::WebMediaConstraints CreateConstraints() {
|
| - blink::WebVector<blink::WebMediaConstraint> mandatory(mandatory_);
|
| - blink::WebVector<blink::WebMediaConstraint> optional(optional_);
|
| - blink::WebMediaConstraints constraints;
|
| - constraints.initialize(optional, mandatory);
|
| - return constraints;
|
| - }
|
| -
|
| - private:
|
| - std::vector<blink::WebMediaConstraint> mandatory_;
|
| - std::vector<blink::WebMediaConstraint> optional_;
|
| -};
|
| -
|
| class MediaStreamVideoSourceTest
|
| : public ::testing::Test {
|
| public:
|
| @@ -224,47 +189,47 @@ TEST_F(MediaStreamVideoSourceTest, AddTwoTracksBeforeGetSupportedFormats) {
|
| // Test that the capture output is CIF if we set max constraints to CIF.
|
| // and the capture device support CIF.
|
| TEST_F(MediaStreamVideoSourceTest, MandatoryConstraintCif5Fps) {
|
| - ConstraintsFactory factory;
|
| + MockMediaConstraintFactory factory;
|
| factory.AddMandatory(MediaStreamVideoSource::kMaxWidth, 352);
|
| factory.AddMandatory(MediaStreamVideoSource::kMaxHeight, 288);
|
| factory.AddMandatory(MediaStreamVideoSource::kMaxFrameRate, 5);
|
|
|
| - CreateTrackAndStartSource(factory.CreateConstraints(), 352, 288, 5);
|
| + CreateTrackAndStartSource(factory.CreateWebMediaConstraints(), 352, 288, 5);
|
| }
|
|
|
| // Test that the capture output is 720P if the camera support it and the
|
| // optional constraint is set to 720P.
|
| TEST_F(MediaStreamVideoSourceTest, MandatoryMinVgaOptional720P) {
|
| - ConstraintsFactory factory;
|
| + MockMediaConstraintFactory factory;
|
| factory.AddMandatory(MediaStreamVideoSource::kMinWidth, 640);
|
| factory.AddMandatory(MediaStreamVideoSource::kMinHeight, 480);
|
| factory.AddOptional(MediaStreamVideoSource::kMinWidth, 1280);
|
| factory.AddOptional(MediaStreamVideoSource::kMinAspectRatio,
|
| 1280.0 / 720);
|
|
|
| - CreateTrackAndStartSource(factory.CreateConstraints(), 1280, 720, 30);
|
| + CreateTrackAndStartSource(factory.CreateWebMediaConstraints(), 1280, 720, 30);
|
| }
|
|
|
| // Test that the capture output have aspect ratio 4:3 if a mandatory constraint
|
| // require it even if an optional constraint request a higher resolution
|
| // that don't have this aspect ratio.
|
| TEST_F(MediaStreamVideoSourceTest, MandatoryAspectRatio4To3) {
|
| - ConstraintsFactory factory;
|
| + MockMediaConstraintFactory factory;
|
| factory.AddMandatory(MediaStreamVideoSource::kMinWidth, 640);
|
| factory.AddMandatory(MediaStreamVideoSource::kMinHeight, 480);
|
| factory.AddMandatory(MediaStreamVideoSource::kMaxAspectRatio,
|
| 640.0 / 480);
|
| factory.AddOptional(MediaStreamVideoSource::kMinWidth, 1280);
|
|
|
| - CreateTrackAndStartSource(factory.CreateConstraints(), 640, 480, 30);
|
| + CreateTrackAndStartSource(factory.CreateWebMediaConstraints(), 640, 480, 30);
|
| }
|
|
|
| // Test that AddTrack fail if the mandatory aspect ratio
|
| // is set higher than supported.
|
| TEST_F(MediaStreamVideoSourceTest, MandatoryAspectRatioTooHigh) {
|
| - ConstraintsFactory factory;
|
| + MockMediaConstraintFactory factory;
|
| factory.AddMandatory(MediaStreamVideoSource::kMinAspectRatio, 2);
|
| - CreateTrack("123", factory.CreateConstraints());
|
| + CreateTrack("123", factory.CreateWebMediaConstraints());
|
| mock_source()->CompleteGetSupportedFormats();
|
| EXPECT_EQ(1, NumberOfFailedConstraintsCallbacks());
|
| }
|
| @@ -272,9 +237,9 @@ TEST_F(MediaStreamVideoSourceTest, MandatoryAspectRatioTooHigh) {
|
| // Test that the source ignores an optional aspect ratio that is higher than
|
| // supported.
|
| TEST_F(MediaStreamVideoSourceTest, OptionalAspectRatioTooHigh) {
|
| - ConstraintsFactory factory;
|
| + MockMediaConstraintFactory factory;
|
| factory.AddOptional(MediaStreamVideoSource::kMinAspectRatio, 2);
|
| - CreateTrack("123", factory.CreateConstraints());
|
| + CreateTrack("123", factory.CreateWebMediaConstraints());
|
| mock_source()->CompleteGetSupportedFormats();
|
|
|
| const media::VideoCaptureParams& params = mock_source()->start_params();
|
| @@ -304,19 +269,19 @@ TEST_F(MediaStreamVideoSourceTest, DefaultCapability) {
|
| }
|
|
|
| TEST_F(MediaStreamVideoSourceTest, InvalidMandatoryConstraint) {
|
| - ConstraintsFactory factory;
|
| + MockMediaConstraintFactory factory;
|
| factory.AddMandatory("weird key", 640);
|
| - CreateTrack("123", factory.CreateConstraints());
|
| + CreateTrack("123", factory.CreateWebMediaConstraints());
|
| mock_source()->CompleteGetSupportedFormats();
|
| EXPECT_EQ(1, NumberOfFailedConstraintsCallbacks());
|
| }
|
|
|
| // Test that the source ignores an unknown optional constraint.
|
| TEST_F(MediaStreamVideoSourceTest, InvalidOptionalConstraint) {
|
| - ConstraintsFactory factory;
|
| + MockMediaConstraintFactory factory;
|
| factory.AddOptional("weird key", 640);
|
|
|
| - CreateTrackAndStartSource(factory.CreateConstraints(),
|
| + CreateTrackAndStartSource(factory.CreateWebMediaConstraints(),
|
| MediaStreamVideoSource::kDefaultWidth,
|
| MediaStreamVideoSource::kDefaultHeight,
|
| 30);
|
| @@ -329,31 +294,31 @@ TEST_F(MediaStreamVideoSourceTest, ScreencastResolutionWithConstraint) {
|
| formats.push_back(media::VideoCaptureFormat(
|
| gfx::Size(480, 270), 30, media::PIXEL_FORMAT_I420));
|
| mock_source()->SetSupportedFormats(formats);
|
| - ConstraintsFactory factory;
|
| + MockMediaConstraintFactory factory;
|
| factory.AddMandatory(MediaStreamVideoSource::kMaxWidth, 480);
|
| factory.AddMandatory(MediaStreamVideoSource::kMaxHeight, 270);
|
|
|
| - CreateTrackAndStartSource(factory.CreateConstraints(), 480, 270, 30);
|
| + CreateTrackAndStartSource(factory.CreateWebMediaConstraints(), 480, 270, 30);
|
| EXPECT_EQ(480, mock_source()->max_requested_height());
|
| EXPECT_EQ(270, mock_source()->max_requested_width());
|
| }
|
|
|
| // Test that optional constraints are applied in order.
|
| TEST_F(MediaStreamVideoSourceTest, OptionalConstraints) {
|
| - ConstraintsFactory factory;
|
| + MockMediaConstraintFactory factory;
|
| // Min width of 2056 pixels can not be fulfilled.
|
| factory.AddOptional(MediaStreamVideoSource::kMinWidth, 2056);
|
| factory.AddOptional(MediaStreamVideoSource::kMinWidth, 641);
|
| // Since min width is set to 641 pixels, max width 640 can not be fulfilled.
|
| factory.AddOptional(MediaStreamVideoSource::kMaxWidth, 640);
|
| - CreateTrackAndStartSource(factory.CreateConstraints(), 1280, 720, 30);
|
| + CreateTrackAndStartSource(factory.CreateWebMediaConstraints(), 1280, 720, 30);
|
| }
|
|
|
| // Test that the webrtc video adapter can be created and that it received
|
| // video frames if the source deliver video frames.
|
| TEST_F(MediaStreamVideoSourceTest, AdapterReceiveVideoFrame) {
|
| - ConstraintsFactory factory;
|
| - CreateTrackAndStartSource(factory.CreateConstraints(),
|
| + MockMediaConstraintFactory factory;
|
| + CreateTrackAndStartSource(factory.CreateWebMediaConstraints(),
|
| MediaStreamVideoSource::kDefaultWidth,
|
| MediaStreamVideoSource::kDefaultHeight,
|
| MediaStreamVideoSource::kDefaultFrameRate);
|
| @@ -377,44 +342,45 @@ TEST_F(MediaStreamVideoSourceTest, AdapterReceiveVideoFrame) {
|
| // Test that the source crops to the requested max width and
|
| // height even though the camera delivers a larger frame.
|
| TEST_F(MediaStreamVideoSourceTest, DeliverCroppedVideoFrameOptional640360) {
|
| - ConstraintsFactory factory;
|
| + MockMediaConstraintFactory factory;
|
| factory.AddOptional(MediaStreamVideoSource::kMaxWidth, 640);
|
| factory.AddOptional(MediaStreamVideoSource::kMaxHeight, 360);
|
| - TestSourceCropFrame(640, 480, factory.CreateConstraints(), 640, 360);
|
| + TestSourceCropFrame(640, 480, factory.CreateWebMediaConstraints(), 640, 360);
|
| }
|
|
|
| TEST_F(MediaStreamVideoSourceTest, DeliverCroppedVideoFrameMandatory640360) {
|
| - ConstraintsFactory factory;
|
| + MockMediaConstraintFactory factory;
|
| factory.AddMandatory(MediaStreamVideoSource::kMaxWidth, 640);
|
| factory.AddMandatory(MediaStreamVideoSource::kMaxHeight, 360);
|
| - TestSourceCropFrame(640, 480, factory.CreateConstraints(), 640, 360);
|
| + TestSourceCropFrame(640, 480, factory.CreateWebMediaConstraints(), 640, 360);
|
| }
|
|
|
| TEST_F(MediaStreamVideoSourceTest, DeliverCroppedVideoFrameMandatory732489) {
|
| - ConstraintsFactory factory;
|
| + MockMediaConstraintFactory factory;
|
| factory.AddMandatory(MediaStreamVideoSource::kMaxWidth, 732);
|
| factory.AddMandatory(MediaStreamVideoSource::kMaxHeight, 489);
|
| factory.AddMandatory(MediaStreamVideoSource::kMinWidth, 732);
|
| factory.AddMandatory(MediaStreamVideoSource::kMinWidth, 489);
|
| - TestSourceCropFrame(1280, 720, factory.CreateConstraints(), 732, 489);
|
| + TestSourceCropFrame(1280, 720, factory.CreateWebMediaConstraints(), 732, 489);
|
| }
|
|
|
| // Test that the source crops to the requested max width and
|
| // height even though the requested frame has odd size.
|
| TEST_F(MediaStreamVideoSourceTest, DeliverCroppedVideoFrame637359) {
|
| - ConstraintsFactory factory;
|
| + MockMediaConstraintFactory factory;
|
| factory.AddOptional(MediaStreamVideoSource::kMaxWidth, 637);
|
| factory.AddOptional(MediaStreamVideoSource::kMaxHeight, 359);
|
| - TestSourceCropFrame(640, 480, factory.CreateConstraints(), 637, 359);
|
| + TestSourceCropFrame(640, 480, factory.CreateWebMediaConstraints(), 637, 359);
|
| }
|
|
|
| TEST_F(MediaStreamVideoSourceTest, DeliverSmallerSizeWhenTooLargeMax) {
|
| - ConstraintsFactory factory;
|
| + MockMediaConstraintFactory factory;
|
| factory.AddOptional(MediaStreamVideoSource::kMaxWidth, 1920);
|
| factory.AddOptional(MediaStreamVideoSource::kMaxHeight, 1080);
|
| factory.AddOptional(MediaStreamVideoSource::kMinWidth, 1280);
|
| factory.AddOptional(MediaStreamVideoSource::kMinHeight, 720);
|
| - TestSourceCropFrame(1280, 720, factory.CreateConstraints(), 1280, 720);
|
| + TestSourceCropFrame(1280, 720, factory.CreateWebMediaConstraints(),
|
| + 1280, 720);
|
| }
|
|
|
| } // namespace content
|
|
|