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

Side by Side Diff: content/renderer/media/media_stream_video_capturer_source_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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/media_stream_video_capturer_source.h" 5 #include "content/renderer/media/media_stream_video_capturer_source.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/callback_helpers.h" 10 #include "base/callback_helpers.h"
11 #include "base/location.h" 11 #include "base/location.h"
12 #include "base/run_loop.h" 12 #include "base/run_loop.h"
13 #include "base/single_thread_task_runner.h" 13 #include "base/single_thread_task_runner.h"
14 #include "base/strings/utf_string_conversions.h" 14 #include "base/strings/utf_string_conversions.h"
15 #include "base/test/scoped_feature_list.h" 15 #include "base/test/scoped_feature_list.h"
16 #include "base/test/scoped_task_environment.h"
16 #include "content/child/child_process.h" 17 #include "content/child/child_process.h"
17 #include "content/public/common/content_features.h" 18 #include "content/public/common/content_features.h"
18 #include "content/public/renderer/media_stream_video_sink.h" 19 #include "content/public/renderer/media_stream_video_sink.h"
19 #include "content/renderer/media/media_stream_video_track.h" 20 #include "content/renderer/media/media_stream_video_track.h"
20 #include "content/renderer/media/mock_constraint_factory.h" 21 #include "content/renderer/media/mock_constraint_factory.h"
21 #include "content/renderer/media/video_track_adapter.h" 22 #include "content/renderer/media/video_track_adapter.h"
22 #include "media/base/bind_to_current_loop.h" 23 #include "media/base/bind_to_current_loop.h"
23 #include "testing/gmock/include/gmock/gmock.h" 24 #include "testing/gmock/include/gmock/gmock.h"
24 #include "testing/gtest/include/gtest/gtest.h" 25 #include "testing/gtest/include/gtest/gtest.h"
25 #include "third_party/WebKit/public/web/WebHeap.h" 26 #include "third_party/WebKit/public/web/WebHeap.h"
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
97 base::TimeTicks* const capture_time_; 98 base::TimeTicks* const capture_time_;
98 media::VideoFrameMetadata* const metadata_; 99 media::VideoFrameMetadata* const metadata_;
99 base::Closure got_frame_cb_; 100 base::Closure got_frame_cb_;
100 }; 101 };
101 102
102 } // namespace 103 } // namespace
103 104
104 class MediaStreamVideoCapturerSourceTest : public testing::Test { 105 class MediaStreamVideoCapturerSourceTest : public testing::Test {
105 public: 106 public:
106 MediaStreamVideoCapturerSourceTest() 107 MediaStreamVideoCapturerSourceTest()
107 : child_process_(new ChildProcess()), 108 : scoped_task_environment_(
109 base::test::ScopedTaskEnvironment::MainThreadType::UI),
110 child_process_(new ChildProcess()),
108 source_(nullptr), 111 source_(nullptr),
109 delegate_(nullptr), 112 delegate_(nullptr),
110 source_stopped_(false) { 113 source_stopped_(false) {
111 scoped_feature_list_.InitAndDisableFeature( 114 scoped_feature_list_.InitAndDisableFeature(
112 features::kMediaStreamOldVideoConstraints); 115 features::kMediaStreamOldVideoConstraints);
113 } 116 }
114 117
115 void TearDown() override { 118 void TearDown() override {
116 webkit_source_.Reset(); 119 webkit_source_.Reset();
117 blink::WebHeap::CollectAllGarbageForTesting(); 120 blink::WebHeap::CollectAllGarbageForTesting();
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
174 } 177 }
175 void OnStarted(bool result) { source_->OnRunStateChanged(result); } 178 void OnStarted(bool result) { source_->OnRunStateChanged(result); }
176 179
177 protected: 180 protected:
178 void OnConstraintsApplied(MediaStreamSource* source, 181 void OnConstraintsApplied(MediaStreamSource* source,
179 MediaStreamRequestResult result, 182 MediaStreamRequestResult result,
180 const blink::WebString& result_name) {} 183 const blink::WebString& result_name) {}
181 184
182 // A ChildProcess and a MessageLoopForUI are both needed to fool the Tracks 185 // A ChildProcess and a MessageLoopForUI are both needed to fool the Tracks
183 // and Sources below into believing they are on the right threads. 186 // and Sources below into believing they are on the right threads.
184 base::MessageLoopForUI message_loop_; 187 base::test::ScopedTaskEnvironment scoped_task_environment_;
185 std::unique_ptr<ChildProcess> child_process_; 188 std::unique_ptr<ChildProcess> child_process_;
186 189
187 blink::WebMediaStreamSource webkit_source_; 190 blink::WebMediaStreamSource webkit_source_;
188 MediaStreamVideoCapturerSource* source_; // owned by |webkit_source_|. 191 MediaStreamVideoCapturerSource* source_; // owned by |webkit_source_|.
189 MockVideoCapturerSource* delegate_; // owned by |source|. 192 MockVideoCapturerSource* delegate_; // owned by |source|.
190 blink::WebString webkit_source_id_; 193 blink::WebString webkit_source_id_;
191 bool source_stopped_; 194 bool source_stopped_;
192 MockConstraintFactory constraint_factory_; 195 MockConstraintFactory constraint_factory_;
193 base::test::ScopedFeatureList scoped_feature_list_; 196 base::test::ScopedFeatureList scoped_feature_list_;
194 }; 197 };
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
280 EXPECT_EQ(reference_capture_time, capture_time); 283 EXPECT_EQ(reference_capture_time, capture_time);
281 double metadata_value; 284 double metadata_value;
282 EXPECT_TRUE(metadata.GetDouble(media::VideoFrameMetadata::FRAME_RATE, 285 EXPECT_TRUE(metadata.GetDouble(media::VideoFrameMetadata::FRAME_RATE,
283 &metadata_value)); 286 &metadata_value));
284 EXPECT_EQ(30.0, metadata_value); 287 EXPECT_EQ(30.0, metadata_value);
285 } 288 }
286 289
287 class MediaStreamVideoCapturerSourceOldConstraintsTest : public testing::Test { 290 class MediaStreamVideoCapturerSourceOldConstraintsTest : public testing::Test {
288 public: 291 public:
289 MediaStreamVideoCapturerSourceOldConstraintsTest() 292 MediaStreamVideoCapturerSourceOldConstraintsTest()
290 : child_process_(new ChildProcess()), 293 : scoped_task_environment_(
294 base::test::ScopedTaskEnvironment::MainThreadType::UI),
295 child_process_(new ChildProcess()),
291 source_(nullptr), 296 source_(nullptr),
292 delegate_(nullptr), 297 delegate_(nullptr),
293 source_stopped_(false) { 298 source_stopped_(false) {
294 scoped_feature_list_.InitAndEnableFeature( 299 scoped_feature_list_.InitAndEnableFeature(
295 features::kMediaStreamOldVideoConstraints); 300 features::kMediaStreamOldVideoConstraints);
296 } 301 }
297 302
298 void TearDown() override { 303 void TearDown() override {
299 webkit_source_.Reset(); 304 webkit_source_.Reset();
300 blink::WebHeap::CollectAllGarbageForTesting(); 305 blink::WebHeap::CollectAllGarbageForTesting();
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
360 } 365 }
361 void OnStarted(bool result) { source_->OnRunStateChanged(result); } 366 void OnStarted(bool result) { source_->OnRunStateChanged(result); }
362 367
363 protected: 368 protected:
364 void OnConstraintsApplied(MediaStreamSource* source, 369 void OnConstraintsApplied(MediaStreamSource* source,
365 MediaStreamRequestResult result, 370 MediaStreamRequestResult result,
366 const blink::WebString& result_name) {} 371 const blink::WebString& result_name) {}
367 372
368 // A ChildProcess and a MessageLoopForUI are both needed to fool the Tracks 373 // A ChildProcess and a MessageLoopForUI are both needed to fool the Tracks
369 // and Sources below into believing they are on the right threads. 374 // and Sources below into believing they are on the right threads.
370 base::MessageLoopForUI message_loop_; 375 base::test::ScopedTaskEnvironment scoped_task_environment_;
371 std::unique_ptr<ChildProcess> child_process_; 376 std::unique_ptr<ChildProcess> child_process_;
372 377
373 blink::WebMediaStreamSource webkit_source_; 378 blink::WebMediaStreamSource webkit_source_;
374 MediaStreamVideoCapturerSource* source_; // owned by |webkit_source_|. 379 MediaStreamVideoCapturerSource* source_; // owned by |webkit_source_|.
375 MockVideoCapturerSource* delegate_; // owned by |source|. 380 MockVideoCapturerSource* delegate_; // owned by |source|.
376 blink::WebString webkit_source_id_; 381 blink::WebString webkit_source_id_;
377 bool source_stopped_; 382 bool source_stopped_;
378 MockConstraintFactory constraint_factory_; 383 MockConstraintFactory constraint_factory_;
379 base::test::ScopedFeatureList scoped_feature_list_; 384 base::test::ScopedFeatureList scoped_feature_list_;
380 }; 385 };
(...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after
611 run_loop.Run(); 616 run_loop.Run();
612 fake_sink.DisconnectFromTrack(); 617 fake_sink.DisconnectFromTrack();
613 EXPECT_EQ(reference_capture_time, capture_time); 618 EXPECT_EQ(reference_capture_time, capture_time);
614 double metadata_value; 619 double metadata_value;
615 EXPECT_TRUE(metadata.GetDouble(media::VideoFrameMetadata::FRAME_RATE, 620 EXPECT_TRUE(metadata.GetDouble(media::VideoFrameMetadata::FRAME_RATE,
616 &metadata_value)); 621 &metadata_value));
617 EXPECT_EQ(30.0, metadata_value); 622 EXPECT_EQ(30.0, metadata_value);
618 } 623 }
619 624
620 } // namespace content 625 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698