| OLD | NEW |
| 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 "content/renderer/media/webrtc/media_stream_video_webrtc_sink.h" | 5 #include "content/renderer/media/webrtc/media_stream_video_webrtc_sink.h" |
| 6 | 6 |
| 7 #include "base/test/scoped_feature_list.h" |
| 7 #include "content/child/child_process.h" | 8 #include "content/child/child_process.h" |
| 9 #include "content/public/common/content_features.h" |
| 8 #include "content/renderer/media/mock_constraint_factory.h" | 10 #include "content/renderer/media/mock_constraint_factory.h" |
| 9 #include "content/renderer/media/mock_media_stream_registry.h" | 11 #include "content/renderer/media/mock_media_stream_registry.h" |
| 12 #include "content/renderer/media/video_track_adapter.h" |
| 10 #include "content/renderer/media/webrtc/mock_peer_connection_dependency_factory.
h" | 13 #include "content/renderer/media/webrtc/mock_peer_connection_dependency_factory.
h" |
| 11 #include "testing/gtest/include/gtest/gtest.h" | 14 #include "testing/gtest/include/gtest/gtest.h" |
| 12 | 15 |
| 13 namespace content { | 16 namespace content { |
| 14 namespace { | 17 namespace { |
| 15 | 18 |
| 16 class MediaStreamVideoWebRtcSinkTest : public ::testing::Test { | 19 class MediaStreamVideoWebRtcSinkTest : public ::testing::Test { |
| 17 public: | 20 public: |
| 18 MediaStreamVideoWebRtcSinkTest() {} | 21 MediaStreamVideoWebRtcSinkTest() {} |
| 19 | 22 |
| 23 void SetVideoTrack() { |
| 24 registry_.Init("stream URL"); |
| 25 registry_.AddVideoTrack("test video track"); |
| 26 blink::WebVector<blink::WebMediaStreamTrack> video_tracks; |
| 27 registry_.test_stream().videoTracks(video_tracks); |
| 28 track_ = video_tracks[0]; |
| 29 // TODO(hta): Verify that track_ is valid. When constraints produce |
| 30 // no valid format, using the track will cause a crash. |
| 31 } |
| 32 |
| 20 void SetVideoTrack(blink::WebMediaConstraints constraints) { | 33 void SetVideoTrack(blink::WebMediaConstraints constraints) { |
| 21 registry_.Init("stream URL"); | 34 registry_.Init("stream URL"); |
| 22 registry_.AddVideoTrack("test video track", constraints); | 35 registry_.AddVideoTrack("test video track", constraints); |
| 23 blink::WebVector<blink::WebMediaStreamTrack> video_tracks; | 36 blink::WebVector<blink::WebMediaStreamTrack> video_tracks; |
| 24 registry_.test_stream().videoTracks(video_tracks); | 37 registry_.test_stream().videoTracks(video_tracks); |
| 25 track_ = video_tracks[0]; | 38 track_ = video_tracks[0]; |
| 26 // TODO(hta): Verify that track_ is valid. When constraints produce | 39 // TODO(hta): Verify that track_ is valid. When constraints produce |
| 27 // no valid format, using the track will cause a crash. | 40 // no valid format, using the track will cause a crash. |
| 28 } | 41 } |
| 29 | 42 |
| 43 void SetVideoTrack(const base::Optional<bool>& noise_reduction) { |
| 44 registry_.Init("stream URL"); |
| 45 registry_.AddVideoTrack("test video track", VideoTrackAdapterSettings(), |
| 46 noise_reduction, false, 0.0); |
| 47 blink::WebVector<blink::WebMediaStreamTrack> video_tracks; |
| 48 registry_.test_stream().videoTracks(video_tracks); |
| 49 track_ = video_tracks[0]; |
| 50 // TODO(hta): Verify that track_ is valid. When constraints produce |
| 51 // no valid format, using the track will cause a crash. |
| 52 } |
| 53 |
| 30 protected: | 54 protected: |
| 31 blink::WebMediaStreamTrack track_; | 55 blink::WebMediaStreamTrack track_; |
| 32 MockPeerConnectionDependencyFactory dependency_factory_; | 56 MockPeerConnectionDependencyFactory dependency_factory_; |
| 33 | 57 |
| 34 private: | 58 private: |
| 35 MockMediaStreamRegistry registry_; | 59 MockMediaStreamRegistry registry_; |
| 36 // A ChildProcess and a MessageLoopForUI are both needed to fool the Tracks | 60 // A ChildProcess and a MessageLoopForUI are both needed to fool the Tracks |
| 37 // and Sources in |registry_| into believing they are on the right threads. | 61 // and Sources in |registry_| into believing they are on the right threads. |
| 38 base::MessageLoopForUI message_loop_; | 62 base::MessageLoopForUI message_loop_; |
| 39 const ChildProcess child_process_; | 63 const ChildProcess child_process_; |
| 40 }; | 64 }; |
| 41 | 65 |
| 42 TEST_F(MediaStreamVideoWebRtcSinkTest, NoiseReductionDefaultsToNotSet) { | 66 TEST_F(MediaStreamVideoWebRtcSinkTest, NoiseReductionDefaultsToNotSet) { |
| 67 base::test::ScopedFeatureList scoped_feature_list; |
| 68 scoped_feature_list.InitAndEnableFeature( |
| 69 features::kMediaStreamOldVideoConstraints); |
| 43 blink::WebMediaConstraints constraints; | 70 blink::WebMediaConstraints constraints; |
| 44 constraints.initialize(); | 71 constraints.initialize(); |
| 45 SetVideoTrack(constraints); | 72 SetVideoTrack(constraints); |
| 46 MediaStreamVideoWebRtcSink my_sink(track_, &dependency_factory_); | 73 MediaStreamVideoWebRtcSink my_sink(track_, &dependency_factory_); |
| 47 EXPECT_TRUE(my_sink.webrtc_video_track()); | 74 EXPECT_TRUE(my_sink.webrtc_video_track()); |
| 48 EXPECT_FALSE(my_sink.SourceNeedsDenoisingForTesting()); | 75 EXPECT_FALSE(my_sink.SourceNeedsDenoisingForTesting()); |
| 49 } | 76 } |
| 50 | 77 |
| 78 TEST_F(MediaStreamVideoWebRtcSinkTest, NoiseReductionDefaultsToNotSetNew) { |
| 79 base::test::ScopedFeatureList scoped_feature_list; |
| 80 scoped_feature_list.InitAndDisableFeature( |
| 81 features::kMediaStreamOldVideoConstraints); |
| 82 SetVideoTrack(); |
| 83 MediaStreamVideoWebRtcSink my_sink(track_, &dependency_factory_); |
| 84 EXPECT_TRUE(my_sink.webrtc_video_track()); |
| 85 EXPECT_FALSE(my_sink.SourceNeedsDenoisingForTesting()); |
| 86 } |
| 87 |
| 51 TEST_F(MediaStreamVideoWebRtcSinkTest, NoiseReductionConstraintPassThrough) { | 88 TEST_F(MediaStreamVideoWebRtcSinkTest, NoiseReductionConstraintPassThrough) { |
| 89 base::test::ScopedFeatureList scoped_feature_list; |
| 90 scoped_feature_list.InitAndEnableFeature( |
| 91 features::kMediaStreamOldVideoConstraints); |
| 52 MockConstraintFactory factory; | 92 MockConstraintFactory factory; |
| 53 factory.basic().googNoiseReduction.setExact(true); | 93 factory.basic().googNoiseReduction.setExact(true); |
| 54 SetVideoTrack(factory.CreateWebMediaConstraints()); | 94 SetVideoTrack(factory.CreateWebMediaConstraints()); |
| 55 MediaStreamVideoWebRtcSink my_sink(track_, &dependency_factory_); | 95 MediaStreamVideoWebRtcSink my_sink(track_, &dependency_factory_); |
| 56 EXPECT_TRUE(my_sink.SourceNeedsDenoisingForTesting()); | 96 EXPECT_TRUE(my_sink.SourceNeedsDenoisingForTesting()); |
| 57 EXPECT_TRUE(*(my_sink.SourceNeedsDenoisingForTesting())); | 97 EXPECT_TRUE(*(my_sink.SourceNeedsDenoisingForTesting())); |
| 58 } | 98 } |
| 59 | 99 |
| 100 TEST_F(MediaStreamVideoWebRtcSinkTest, NoiseReductionConstraintPassThroughNew) { |
| 101 base::test::ScopedFeatureList scoped_feature_list; |
| 102 scoped_feature_list.InitAndDisableFeature( |
| 103 features::kMediaStreamOldVideoConstraints); |
| 104 SetVideoTrack(base::Optional<bool>(true)); |
| 105 MediaStreamVideoWebRtcSink my_sink(track_, &dependency_factory_); |
| 106 EXPECT_TRUE(my_sink.SourceNeedsDenoisingForTesting()); |
| 107 EXPECT_TRUE(*(my_sink.SourceNeedsDenoisingForTesting())); |
| 108 } |
| 109 |
| 60 } // namespace | 110 } // namespace |
| 61 } // namespace content | 111 } // namespace content |
| OLD | NEW |