| 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" | |
| 8 #include "base/test/scoped_task_environment.h" | 7 #include "base/test/scoped_task_environment.h" |
| 9 #include "content/child/child_process.h" | 8 #include "content/child/child_process.h" |
| 10 #include "content/public/common/content_features.h" | |
| 11 #include "content/renderer/media/mock_constraint_factory.h" | 9 #include "content/renderer/media/mock_constraint_factory.h" |
| 12 #include "content/renderer/media/mock_media_stream_registry.h" | 10 #include "content/renderer/media/mock_media_stream_registry.h" |
| 13 #include "content/renderer/media/video_track_adapter.h" | 11 #include "content/renderer/media/video_track_adapter.h" |
| 14 #include "content/renderer/media/webrtc/mock_peer_connection_dependency_factory.
h" | 12 #include "content/renderer/media/webrtc/mock_peer_connection_dependency_factory.
h" |
| 15 #include "testing/gtest/include/gtest/gtest.h" | 13 #include "testing/gtest/include/gtest/gtest.h" |
| 16 | 14 |
| 17 namespace content { | 15 namespace content { |
| 18 namespace { | 16 namespace { |
| 19 | 17 |
| 20 class MediaStreamVideoWebRtcSinkTest : public ::testing::Test { | 18 class MediaStreamVideoWebRtcSinkTest : public ::testing::Test { |
| 21 public: | 19 public: |
| 22 MediaStreamVideoWebRtcSinkTest() | 20 MediaStreamVideoWebRtcSinkTest() |
| 23 : scoped_task_environment_( | 21 : scoped_task_environment_( |
| 24 base::test::ScopedTaskEnvironment::MainThreadType::UI) { | 22 base::test::ScopedTaskEnvironment::MainThreadType::UI) {} |
| 25 scoped_feature_list_.InitAndDisableFeature( | |
| 26 features::kMediaStreamOldVideoConstraints); | |
| 27 } | |
| 28 | 23 |
| 29 void SetVideoTrack() { | 24 void SetVideoTrack() { |
| 30 registry_.Init("stream URL"); | 25 registry_.Init("stream URL"); |
| 31 registry_.AddVideoTrack("test video track"); | 26 registry_.AddVideoTrack("test video track"); |
| 32 blink::WebVector<blink::WebMediaStreamTrack> video_tracks; | 27 blink::WebVector<blink::WebMediaStreamTrack> video_tracks; |
| 33 registry_.test_stream().VideoTracks(video_tracks); | 28 registry_.test_stream().VideoTracks(video_tracks); |
| 34 track_ = video_tracks[0]; | 29 track_ = video_tracks[0]; |
| 35 // TODO(hta): Verify that track_ is valid. When constraints produce | 30 // TODO(hta): Verify that track_ is valid. When constraints produce |
| 36 // no valid format, using the track will cause a crash. | 31 // no valid format, using the track will cause a crash. |
| 37 } | 32 } |
| 38 | 33 |
| 39 void SetVideoTrack(blink::WebMediaConstraints constraints) { | |
| 40 registry_.Init("stream URL"); | |
| 41 registry_.AddVideoTrack("test video track", constraints); | |
| 42 blink::WebVector<blink::WebMediaStreamTrack> video_tracks; | |
| 43 registry_.test_stream().VideoTracks(video_tracks); | |
| 44 track_ = video_tracks[0]; | |
| 45 // TODO(hta): Verify that track_ is valid. When constraints produce | |
| 46 // no valid format, using the track will cause a crash. | |
| 47 } | |
| 48 | |
| 49 void SetVideoTrack(const base::Optional<bool>& noise_reduction) { | 34 void SetVideoTrack(const base::Optional<bool>& noise_reduction) { |
| 50 registry_.Init("stream URL"); | 35 registry_.Init("stream URL"); |
| 51 registry_.AddVideoTrack("test video track", VideoTrackAdapterSettings(), | 36 registry_.AddVideoTrack("test video track", VideoTrackAdapterSettings(), |
| 52 noise_reduction, false, 0.0); | 37 noise_reduction, false, 0.0); |
| 53 blink::WebVector<blink::WebMediaStreamTrack> video_tracks; | 38 blink::WebVector<blink::WebMediaStreamTrack> video_tracks; |
| 54 registry_.test_stream().VideoTracks(video_tracks); | 39 registry_.test_stream().VideoTracks(video_tracks); |
| 55 track_ = video_tracks[0]; | 40 track_ = video_tracks[0]; |
| 56 // TODO(hta): Verify that track_ is valid. When constraints produce | 41 // TODO(hta): Verify that track_ is valid. When constraints produce |
| 57 // no valid format, using the track will cause a crash. | 42 // no valid format, using the track will cause a crash. |
| 58 } | 43 } |
| 59 | 44 |
| 60 protected: | 45 protected: |
| 61 blink::WebMediaStreamTrack track_; | 46 blink::WebMediaStreamTrack track_; |
| 62 MockPeerConnectionDependencyFactory dependency_factory_; | 47 MockPeerConnectionDependencyFactory dependency_factory_; |
| 63 | 48 |
| 64 private: | 49 private: |
| 65 MockMediaStreamRegistry registry_; | 50 MockMediaStreamRegistry registry_; |
| 66 // A ChildProcess and a MessageLoopForUI are both needed to fool the Tracks | 51 // A ChildProcess and a MessageLoopForUI are both needed to fool the Tracks |
| 67 // and Sources in |registry_| into believing they are on the right threads. | 52 // and Sources in |registry_| into believing they are on the right threads. |
| 68 base::test::ScopedTaskEnvironment scoped_task_environment_; | 53 base::test::ScopedTaskEnvironment scoped_task_environment_; |
| 69 const ChildProcess child_process_; | 54 const ChildProcess child_process_; |
| 70 base::test::ScopedFeatureList scoped_feature_list_; | |
| 71 }; | 55 }; |
| 72 | 56 |
| 73 TEST_F(MediaStreamVideoWebRtcSinkTest, NoiseReductionDefaultsToNotSet) { | 57 TEST_F(MediaStreamVideoWebRtcSinkTest, NoiseReductionDefaultsToNotSet) { |
| 74 SetVideoTrack(); | 58 SetVideoTrack(); |
| 75 MediaStreamVideoWebRtcSink my_sink(track_, &dependency_factory_); | 59 MediaStreamVideoWebRtcSink my_sink(track_, &dependency_factory_); |
| 76 EXPECT_TRUE(my_sink.webrtc_video_track()); | 60 EXPECT_TRUE(my_sink.webrtc_video_track()); |
| 77 EXPECT_FALSE(my_sink.SourceNeedsDenoisingForTesting()); | 61 EXPECT_FALSE(my_sink.SourceNeedsDenoisingForTesting()); |
| 78 } | 62 } |
| 79 | 63 |
| 80 // TODO(guidou): Remove this test. http://crbug.com/706408 | 64 // TODO(guidou): Remove this test. http://crbug.com/706408 |
| 81 TEST_F(MediaStreamVideoWebRtcSinkTest, NoiseReductionConstraintPassThrough) { | 65 TEST_F(MediaStreamVideoWebRtcSinkTest, NoiseReductionConstraintPassThrough) { |
| 82 SetVideoTrack(base::Optional<bool>(true)); | 66 SetVideoTrack(base::Optional<bool>(true)); |
| 83 MediaStreamVideoWebRtcSink my_sink(track_, &dependency_factory_); | 67 MediaStreamVideoWebRtcSink my_sink(track_, &dependency_factory_); |
| 84 EXPECT_TRUE(my_sink.SourceNeedsDenoisingForTesting()); | 68 EXPECT_TRUE(my_sink.SourceNeedsDenoisingForTesting()); |
| 85 EXPECT_TRUE(*(my_sink.SourceNeedsDenoisingForTesting())); | 69 EXPECT_TRUE(*(my_sink.SourceNeedsDenoisingForTesting())); |
| 86 } | 70 } |
| 87 | 71 |
| 88 // TODO(guidou): Remove this test. http://crbug.com/706408 | |
| 89 class MediaStreamVideoWebRtcSinkOldConstraintsTest : public ::testing::Test { | |
| 90 public: | |
| 91 MediaStreamVideoWebRtcSinkOldConstraintsTest() | |
| 92 : scoped_task_environment_( | |
| 93 base::test::ScopedTaskEnvironment::MainThreadType::UI) { | |
| 94 scoped_feature_list_.InitAndEnableFeature( | |
| 95 features::kMediaStreamOldVideoConstraints); | |
| 96 } | |
| 97 | |
| 98 void SetVideoTrack() { | |
| 99 registry_.Init("stream URL"); | |
| 100 registry_.AddVideoTrack("test video track"); | |
| 101 blink::WebVector<blink::WebMediaStreamTrack> video_tracks; | |
| 102 registry_.test_stream().VideoTracks(video_tracks); | |
| 103 track_ = video_tracks[0]; | |
| 104 // TODO(hta): Verify that track_ is valid. When constraints produce | |
| 105 // no valid format, using the track will cause a crash. | |
| 106 } | |
| 107 | |
| 108 void SetVideoTrack(blink::WebMediaConstraints constraints) { | |
| 109 registry_.Init("stream URL"); | |
| 110 registry_.AddVideoTrack("test video track", constraints); | |
| 111 blink::WebVector<blink::WebMediaStreamTrack> video_tracks; | |
| 112 registry_.test_stream().VideoTracks(video_tracks); | |
| 113 track_ = video_tracks[0]; | |
| 114 // TODO(hta): Verify that track_ is valid. When constraints produce | |
| 115 // no valid format, using the track will cause a crash. | |
| 116 } | |
| 117 | |
| 118 void SetVideoTrack(const base::Optional<bool>& noise_reduction) { | |
| 119 registry_.Init("stream URL"); | |
| 120 registry_.AddVideoTrack("test video track", VideoTrackAdapterSettings(), | |
| 121 noise_reduction, false, 0.0); | |
| 122 blink::WebVector<blink::WebMediaStreamTrack> video_tracks; | |
| 123 registry_.test_stream().VideoTracks(video_tracks); | |
| 124 track_ = video_tracks[0]; | |
| 125 // TODO(hta): Verify that track_ is valid. When constraints produce | |
| 126 // no valid format, using the track will cause a crash. | |
| 127 } | |
| 128 | |
| 129 protected: | |
| 130 blink::WebMediaStreamTrack track_; | |
| 131 MockPeerConnectionDependencyFactory dependency_factory_; | |
| 132 | |
| 133 private: | |
| 134 MockMediaStreamRegistry registry_; | |
| 135 // A ChildProcess and a MessageLoopForUI are both needed to fool the Tracks | |
| 136 // and Sources in |registry_| into believing they are on the right threads. | |
| 137 base::test::ScopedTaskEnvironment scoped_task_environment_; | |
| 138 const ChildProcess child_process_; | |
| 139 base::test::ScopedFeatureList scoped_feature_list_; | |
| 140 }; | |
| 141 | |
| 142 TEST_F(MediaStreamVideoWebRtcSinkOldConstraintsTest, | |
| 143 NoiseReductionDefaultsToNotSet) { | |
| 144 blink::WebMediaConstraints constraints; | |
| 145 constraints.Initialize(); | |
| 146 SetVideoTrack(constraints); | |
| 147 MediaStreamVideoWebRtcSink my_sink(track_, &dependency_factory_); | |
| 148 EXPECT_TRUE(my_sink.webrtc_video_track()); | |
| 149 EXPECT_FALSE(my_sink.SourceNeedsDenoisingForTesting()); | |
| 150 } | |
| 151 | |
| 152 TEST_F(MediaStreamVideoWebRtcSinkOldConstraintsTest, | |
| 153 NoiseReductionConstraintPassThrough) { | |
| 154 MockConstraintFactory factory; | |
| 155 factory.basic().goog_noise_reduction.SetExact(true); | |
| 156 SetVideoTrack(factory.CreateWebMediaConstraints()); | |
| 157 MediaStreamVideoWebRtcSink my_sink(track_, &dependency_factory_); | |
| 158 EXPECT_TRUE(my_sink.SourceNeedsDenoisingForTesting()); | |
| 159 EXPECT_TRUE(*(my_sink.SourceNeedsDenoisingForTesting())); | |
| 160 } | |
| 161 | |
| 162 } // namespace | 72 } // namespace |
| 163 } // namespace content | 73 } // namespace content |
| OLD | NEW |