Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(82)

Side by Side Diff: content/renderer/media/webrtc/media_stream_video_webrtc_sink_unittest.cc

Issue 2846933002: Use ScopedTaskEnvironment instead of MessageLoopForUI in content tests. (Closed)
Patch Set: self-review Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 "base/test/scoped_task_environment.h"
8 #include "content/child/child_process.h" 9 #include "content/child/child_process.h"
9 #include "content/public/common/content_features.h" 10 #include "content/public/common/content_features.h"
10 #include "content/renderer/media/mock_constraint_factory.h" 11 #include "content/renderer/media/mock_constraint_factory.h"
11 #include "content/renderer/media/mock_media_stream_registry.h" 12 #include "content/renderer/media/mock_media_stream_registry.h"
12 #include "content/renderer/media/video_track_adapter.h" 13 #include "content/renderer/media/video_track_adapter.h"
13 #include "content/renderer/media/webrtc/mock_peer_connection_dependency_factory. h" 14 #include "content/renderer/media/webrtc/mock_peer_connection_dependency_factory. h"
14 #include "testing/gtest/include/gtest/gtest.h" 15 #include "testing/gtest/include/gtest/gtest.h"
15 16
16 namespace content { 17 namespace content {
17 namespace { 18 namespace {
18 19
19 class MediaStreamVideoWebRtcSinkTest : public ::testing::Test { 20 class MediaStreamVideoWebRtcSinkTest : public ::testing::Test {
20 public: 21 public:
21 MediaStreamVideoWebRtcSinkTest() { 22 MediaStreamVideoWebRtcSinkTest()
23 : scoped_task_environment_(
24 base::test::ScopedTaskEnvironment::MainThreadType::UI) {
22 scoped_feature_list_.InitAndDisableFeature( 25 scoped_feature_list_.InitAndDisableFeature(
23 features::kMediaStreamOldVideoConstraints); 26 features::kMediaStreamOldVideoConstraints);
24 } 27 }
25 28
26 void SetVideoTrack() { 29 void SetVideoTrack() {
27 registry_.Init("stream URL"); 30 registry_.Init("stream URL");
28 registry_.AddVideoTrack("test video track"); 31 registry_.AddVideoTrack("test video track");
29 blink::WebVector<blink::WebMediaStreamTrack> video_tracks; 32 blink::WebVector<blink::WebMediaStreamTrack> video_tracks;
30 registry_.test_stream().VideoTracks(video_tracks); 33 registry_.test_stream().VideoTracks(video_tracks);
31 track_ = video_tracks[0]; 34 track_ = video_tracks[0];
(...skipping 23 matching lines...) Expand all
55 } 58 }
56 59
57 protected: 60 protected:
58 blink::WebMediaStreamTrack track_; 61 blink::WebMediaStreamTrack track_;
59 MockPeerConnectionDependencyFactory dependency_factory_; 62 MockPeerConnectionDependencyFactory dependency_factory_;
60 63
61 private: 64 private:
62 MockMediaStreamRegistry registry_; 65 MockMediaStreamRegistry registry_;
63 // A ChildProcess and a MessageLoopForUI are both needed to fool the Tracks 66 // A ChildProcess and a MessageLoopForUI are both needed to fool the Tracks
64 // and Sources in |registry_| into believing they are on the right threads. 67 // and Sources in |registry_| into believing they are on the right threads.
65 base::MessageLoopForUI message_loop_; 68 base::test::ScopedTaskEnvironment scoped_task_environment_;
66 const ChildProcess child_process_; 69 const ChildProcess child_process_;
67 base::test::ScopedFeatureList scoped_feature_list_; 70 base::test::ScopedFeatureList scoped_feature_list_;
68 }; 71 };
69 72
70 TEST_F(MediaStreamVideoWebRtcSinkTest, NoiseReductionDefaultsToNotSet) { 73 TEST_F(MediaStreamVideoWebRtcSinkTest, NoiseReductionDefaultsToNotSet) {
71 SetVideoTrack(); 74 SetVideoTrack();
72 MediaStreamVideoWebRtcSink my_sink(track_, &dependency_factory_); 75 MediaStreamVideoWebRtcSink my_sink(track_, &dependency_factory_);
73 EXPECT_TRUE(my_sink.webrtc_video_track()); 76 EXPECT_TRUE(my_sink.webrtc_video_track());
74 EXPECT_FALSE(my_sink.SourceNeedsDenoisingForTesting()); 77 EXPECT_FALSE(my_sink.SourceNeedsDenoisingForTesting());
75 } 78 }
76 79
77 // TODO(guidou): Remove this test. http://crbug.com/706408 80 // TODO(guidou): Remove this test. http://crbug.com/706408
78 TEST_F(MediaStreamVideoWebRtcSinkTest, NoiseReductionConstraintPassThrough) { 81 TEST_F(MediaStreamVideoWebRtcSinkTest, NoiseReductionConstraintPassThrough) {
79 SetVideoTrack(base::Optional<bool>(true)); 82 SetVideoTrack(base::Optional<bool>(true));
80 MediaStreamVideoWebRtcSink my_sink(track_, &dependency_factory_); 83 MediaStreamVideoWebRtcSink my_sink(track_, &dependency_factory_);
81 EXPECT_TRUE(my_sink.SourceNeedsDenoisingForTesting()); 84 EXPECT_TRUE(my_sink.SourceNeedsDenoisingForTesting());
82 EXPECT_TRUE(*(my_sink.SourceNeedsDenoisingForTesting())); 85 EXPECT_TRUE(*(my_sink.SourceNeedsDenoisingForTesting()));
83 } 86 }
84 87
85 // TODO(guidou): Remove this test. http://crbug.com/706408 88 // TODO(guidou): Remove this test. http://crbug.com/706408
86 class MediaStreamVideoWebRtcSinkOldConstraintsTest : public ::testing::Test { 89 class MediaStreamVideoWebRtcSinkOldConstraintsTest : public ::testing::Test {
87 public: 90 public:
88 MediaStreamVideoWebRtcSinkOldConstraintsTest() { 91 MediaStreamVideoWebRtcSinkOldConstraintsTest()
92 : scoped_task_environment_(
93 base::test::ScopedTaskEnvironment::MainThreadType::UI) {
89 scoped_feature_list_.InitAndEnableFeature( 94 scoped_feature_list_.InitAndEnableFeature(
90 features::kMediaStreamOldVideoConstraints); 95 features::kMediaStreamOldVideoConstraints);
91 } 96 }
92 97
93 void SetVideoTrack() { 98 void SetVideoTrack() {
94 registry_.Init("stream URL"); 99 registry_.Init("stream URL");
95 registry_.AddVideoTrack("test video track"); 100 registry_.AddVideoTrack("test video track");
96 blink::WebVector<blink::WebMediaStreamTrack> video_tracks; 101 blink::WebVector<blink::WebMediaStreamTrack> video_tracks;
97 registry_.test_stream().VideoTracks(video_tracks); 102 registry_.test_stream().VideoTracks(video_tracks);
98 track_ = video_tracks[0]; 103 track_ = video_tracks[0];
(...skipping 23 matching lines...) Expand all
122 } 127 }
123 128
124 protected: 129 protected:
125 blink::WebMediaStreamTrack track_; 130 blink::WebMediaStreamTrack track_;
126 MockPeerConnectionDependencyFactory dependency_factory_; 131 MockPeerConnectionDependencyFactory dependency_factory_;
127 132
128 private: 133 private:
129 MockMediaStreamRegistry registry_; 134 MockMediaStreamRegistry registry_;
130 // A ChildProcess and a MessageLoopForUI are both needed to fool the Tracks 135 // 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. 136 // and Sources in |registry_| into believing they are on the right threads.
132 base::MessageLoopForUI message_loop_; 137 base::test::ScopedTaskEnvironment scoped_task_environment_;
133 const ChildProcess child_process_; 138 const ChildProcess child_process_;
134 base::test::ScopedFeatureList scoped_feature_list_; 139 base::test::ScopedFeatureList scoped_feature_list_;
135 }; 140 };
136 141
137 TEST_F(MediaStreamVideoWebRtcSinkOldConstraintsTest, 142 TEST_F(MediaStreamVideoWebRtcSinkOldConstraintsTest,
138 NoiseReductionDefaultsToNotSet) { 143 NoiseReductionDefaultsToNotSet) {
139 blink::WebMediaConstraints constraints; 144 blink::WebMediaConstraints constraints;
140 constraints.Initialize(); 145 constraints.Initialize();
141 SetVideoTrack(constraints); 146 SetVideoTrack(constraints);
142 MediaStreamVideoWebRtcSink my_sink(track_, &dependency_factory_); 147 MediaStreamVideoWebRtcSink my_sink(track_, &dependency_factory_);
143 EXPECT_TRUE(my_sink.webrtc_video_track()); 148 EXPECT_TRUE(my_sink.webrtc_video_track());
144 EXPECT_FALSE(my_sink.SourceNeedsDenoisingForTesting()); 149 EXPECT_FALSE(my_sink.SourceNeedsDenoisingForTesting());
145 } 150 }
146 151
147 TEST_F(MediaStreamVideoWebRtcSinkOldConstraintsTest, 152 TEST_F(MediaStreamVideoWebRtcSinkOldConstraintsTest,
148 NoiseReductionConstraintPassThrough) { 153 NoiseReductionConstraintPassThrough) {
149 MockConstraintFactory factory; 154 MockConstraintFactory factory;
150 factory.basic().goog_noise_reduction.SetExact(true); 155 factory.basic().goog_noise_reduction.SetExact(true);
151 SetVideoTrack(factory.CreateWebMediaConstraints()); 156 SetVideoTrack(factory.CreateWebMediaConstraints());
152 MediaStreamVideoWebRtcSink my_sink(track_, &dependency_factory_); 157 MediaStreamVideoWebRtcSink my_sink(track_, &dependency_factory_);
153 EXPECT_TRUE(my_sink.SourceNeedsDenoisingForTesting()); 158 EXPECT_TRUE(my_sink.SourceNeedsDenoisingForTesting());
154 EXPECT_TRUE(*(my_sink.SourceNeedsDenoisingForTesting())); 159 EXPECT_TRUE(*(my_sink.SourceNeedsDenoisingForTesting()));
155 } 160 }
156 161
157 } // namespace 162 } // namespace
158 } // namespace content 163 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698