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