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 // 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); |
43 blink::WebMediaConstraints constraints; | 72 blink::WebMediaConstraints constraints; |
44 constraints.initialize(); | 73 constraints.initialize(); |
45 SetVideoTrack(constraints); | 74 SetVideoTrack(constraints); |
46 MediaStreamVideoWebRtcSink my_sink(track_, &dependency_factory_); | 75 MediaStreamVideoWebRtcSink my_sink(track_, &dependency_factory_); |
47 EXPECT_TRUE(my_sink.webrtc_video_track()); | 76 EXPECT_TRUE(my_sink.webrtc_video_track()); |
48 EXPECT_FALSE(my_sink.SourceNeedsDenoisingForTesting()); | 77 EXPECT_FALSE(my_sink.SourceNeedsDenoisingForTesting()); |
49 } | 78 } |
50 | 79 |
51 TEST_F(MediaStreamVideoWebRtcSinkTest, NoiseReductionConstraintPassThrough) { | 80 // TODO(guidou): Remove this test. http://crbug.com/706408 |
| 81 TEST_F(MediaStreamVideoWebRtcSinkTest, NoiseReductionDefaultsToNotSet) { |
| 82 base::test::ScopedFeatureList scoped_feature_list; |
| 83 scoped_feature_list.InitAndDisableFeature( |
| 84 features::kMediaStreamOldVideoConstraints); |
| 85 SetVideoTrack(); |
| 86 MediaStreamVideoWebRtcSink my_sink(track_, &dependency_factory_); |
| 87 EXPECT_TRUE(my_sink.webrtc_video_track()); |
| 88 EXPECT_FALSE(my_sink.SourceNeedsDenoisingForTesting()); |
| 89 } |
| 90 |
| 91 // TODO(guidou): Remove this test. http://crbug.com/706408 |
| 92 TEST_F(MediaStreamVideoWebRtcSinkTest, |
| 93 NoiseReductionConstraintPassThroughOldConstraints) { |
| 94 base::test::ScopedFeatureList scoped_feature_list; |
| 95 scoped_feature_list.InitAndEnableFeature( |
| 96 features::kMediaStreamOldVideoConstraints); |
52 MockConstraintFactory factory; | 97 MockConstraintFactory factory; |
53 factory.basic().googNoiseReduction.setExact(true); | 98 factory.basic().googNoiseReduction.setExact(true); |
54 SetVideoTrack(factory.CreateWebMediaConstraints()); | 99 SetVideoTrack(factory.CreateWebMediaConstraints()); |
55 MediaStreamVideoWebRtcSink my_sink(track_, &dependency_factory_); | 100 MediaStreamVideoWebRtcSink my_sink(track_, &dependency_factory_); |
56 EXPECT_TRUE(my_sink.SourceNeedsDenoisingForTesting()); | 101 EXPECT_TRUE(my_sink.SourceNeedsDenoisingForTesting()); |
57 EXPECT_TRUE(*(my_sink.SourceNeedsDenoisingForTesting())); | 102 EXPECT_TRUE(*(my_sink.SourceNeedsDenoisingForTesting())); |
58 } | 103 } |
59 | 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 } |
| 115 |
60 } // namespace | 116 } // namespace |
61 } // namespace content | 117 } // namespace content |
OLD | NEW |