| OLD | NEW |
| 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 <string> | 5 #include <string> |
| 6 #include <vector> | 6 #include <vector> |
| 7 | 7 |
| 8 #include "base/bind.h" | 8 #include "base/bind.h" |
| 9 #include "base/message_loop/message_loop.h" | |
| 10 #include "base/run_loop.h" | 9 #include "base/run_loop.h" |
| 11 #include "base/strings/string_number_conversions.h" | 10 #include "base/strings/string_number_conversions.h" |
| 12 #include "base/strings/utf_string_conversions.h" | 11 #include "base/strings/utf_string_conversions.h" |
| 13 #include "base/test/scoped_feature_list.h" | 12 #include "base/test/scoped_feature_list.h" |
| 13 #include "base/test/scoped_task_environment.h" |
| 14 #include "content/child/child_process.h" | 14 #include "content/child/child_process.h" |
| 15 #include "content/public/common/content_features.h" | 15 #include "content/public/common/content_features.h" |
| 16 #include "content/renderer/media/media_stream_video_source.h" | 16 #include "content/renderer/media/media_stream_video_source.h" |
| 17 #include "content/renderer/media/media_stream_video_track.h" | 17 #include "content/renderer/media/media_stream_video_track.h" |
| 18 #include "content/renderer/media/mock_constraint_factory.h" | 18 #include "content/renderer/media/mock_constraint_factory.h" |
| 19 #include "content/renderer/media/mock_media_stream_video_sink.h" | 19 #include "content/renderer/media/mock_media_stream_video_sink.h" |
| 20 #include "content/renderer/media/mock_media_stream_video_source.h" | 20 #include "content/renderer/media/mock_media_stream_video_source.h" |
| 21 #include "content/renderer/media/video_track_adapter.h" | 21 #include "content/renderer/media/video_track_adapter.h" |
| 22 #include "media/base/limits.h" | 22 #include "media/base/limits.h" |
| 23 #include "media/base/video_frame.h" | 23 #include "media/base/video_frame.h" |
| 24 #include "testing/gtest/include/gtest/gtest.h" | 24 #include "testing/gtest/include/gtest/gtest.h" |
| 25 #include "third_party/WebKit/public/web/WebHeap.h" | 25 #include "third_party/WebKit/public/web/WebHeap.h" |
| 26 | 26 |
| 27 using ::testing::_; | 27 using ::testing::_; |
| 28 using ::testing::DoAll; | 28 using ::testing::DoAll; |
| 29 using ::testing::SaveArg; | 29 using ::testing::SaveArg; |
| 30 | 30 |
| 31 namespace content { | 31 namespace content { |
| 32 | 32 |
| 33 ACTION_P(RunClosure, closure) { | 33 ACTION_P(RunClosure, closure) { |
| 34 closure.Run(); | 34 closure.Run(); |
| 35 } | 35 } |
| 36 | 36 |
| 37 class MediaStreamVideoSourceTest : public ::testing::Test { | 37 class MediaStreamVideoSourceTest : public ::testing::Test { |
| 38 public: | 38 public: |
| 39 MediaStreamVideoSourceTest() | 39 MediaStreamVideoSourceTest() |
| 40 : child_process_(new ChildProcess()), | 40 : scoped_task_environment_( |
| 41 base::test::ScopedTaskEnvironment::MainThreadType::UI), |
| 42 child_process_(new ChildProcess()), |
| 41 number_of_successful_constraints_applied_(0), | 43 number_of_successful_constraints_applied_(0), |
| 42 number_of_failed_constraints_applied_(0), | 44 number_of_failed_constraints_applied_(0), |
| 43 result_(MEDIA_DEVICE_OK), | 45 result_(MEDIA_DEVICE_OK), |
| 44 result_name_(""), | 46 result_name_(""), |
| 45 mock_source_(new MockMediaStreamVideoSource( | 47 mock_source_(new MockMediaStreamVideoSource( |
| 46 media::VideoCaptureFormat(gfx::Size(1280, 720), | 48 media::VideoCaptureFormat(gfx::Size(1280, 720), |
| 47 1000.0, | 49 1000.0, |
| 48 media::PIXEL_FORMAT_I420), | 50 media::PIXEL_FORMAT_I420), |
| 49 false)) { | 51 false)) { |
| 50 scoped_feature_list_.InitAndDisableFeature( | 52 scoped_feature_list_.InitAndDisableFeature( |
| (...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 235 result_name_ = result_name; | 237 result_name_ = result_name; |
| 236 ++number_of_failed_constraints_applied_; | 238 ++number_of_failed_constraints_applied_; |
| 237 } | 239 } |
| 238 | 240 |
| 239 if (!track_to_release_.IsNull()) { | 241 if (!track_to_release_.IsNull()) { |
| 240 mock_source_ = nullptr; | 242 mock_source_ = nullptr; |
| 241 webkit_source_.Reset(); | 243 webkit_source_.Reset(); |
| 242 track_to_release_.Reset(); | 244 track_to_release_.Reset(); |
| 243 } | 245 } |
| 244 } | 246 } |
| 245 const base::MessageLoopForUI message_loop_; | 247 const base::test::ScopedTaskEnvironment scoped_task_environment_; |
| 246 const std::unique_ptr<ChildProcess> child_process_; | 248 const std::unique_ptr<ChildProcess> child_process_; |
| 247 blink::WebMediaStreamTrack track_to_release_; | 249 blink::WebMediaStreamTrack track_to_release_; |
| 248 int number_of_successful_constraints_applied_; | 250 int number_of_successful_constraints_applied_; |
| 249 int number_of_failed_constraints_applied_; | 251 int number_of_failed_constraints_applied_; |
| 250 content::MediaStreamRequestResult result_; | 252 content::MediaStreamRequestResult result_; |
| 251 blink::WebString result_name_; | 253 blink::WebString result_name_; |
| 252 blink::WebMediaStreamSource webkit_source_; | 254 blink::WebMediaStreamSource webkit_source_; |
| 253 // |mock_source_| is owned by |webkit_source_|. | 255 // |mock_source_| is owned by |webkit_source_|. |
| 254 MockMediaStreamVideoSource* mock_source_; | 256 MockMediaStreamVideoSource* mock_source_; |
| 255 base::test::ScopedFeatureList scoped_feature_list_; | 257 base::test::ScopedFeatureList scoped_feature_list_; |
| (...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 373 EXPECT_EQ(muted_state, false); | 375 EXPECT_EQ(muted_state, false); |
| 374 EXPECT_EQ(track.Source().GetReadyState(), | 376 EXPECT_EQ(track.Source().GetReadyState(), |
| 375 blink::WebMediaStreamSource::kReadyStateLive); | 377 blink::WebMediaStreamSource::kReadyStateLive); |
| 376 | 378 |
| 377 sink.DisconnectFromTrack(); | 379 sink.DisconnectFromTrack(); |
| 378 } | 380 } |
| 379 | 381 |
| 380 class MediaStreamVideoSourceOldConstraintsTest : public ::testing::Test { | 382 class MediaStreamVideoSourceOldConstraintsTest : public ::testing::Test { |
| 381 public: | 383 public: |
| 382 MediaStreamVideoSourceOldConstraintsTest() | 384 MediaStreamVideoSourceOldConstraintsTest() |
| 383 : child_process_(new ChildProcess()), | 385 : scoped_task_environment_( |
| 386 base::test::ScopedTaskEnvironment::MainThreadType::UI), |
| 387 child_process_(new ChildProcess()), |
| 384 number_of_successful_constraints_applied_(0), | 388 number_of_successful_constraints_applied_(0), |
| 385 number_of_failed_constraints_applied_(0), | 389 number_of_failed_constraints_applied_(0), |
| 386 result_(MEDIA_DEVICE_OK), | 390 result_(MEDIA_DEVICE_OK), |
| 387 result_name_(""), | 391 result_name_(""), |
| 388 mock_source_(new MockMediaStreamVideoSource(true)) { | 392 mock_source_(new MockMediaStreamVideoSource(true)) { |
| 389 scoped_feature_list_.InitAndEnableFeature( | 393 scoped_feature_list_.InitAndEnableFeature( |
| 390 features::kMediaStreamOldVideoConstraints); | 394 features::kMediaStreamOldVideoConstraints); |
| 391 | 395 |
| 392 media::VideoCaptureFormats formats; | 396 media::VideoCaptureFormats formats; |
| 393 formats.push_back(media::VideoCaptureFormat( | 397 formats.push_back(media::VideoCaptureFormat( |
| (...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 575 result_name_ = result_name; | 579 result_name_ = result_name; |
| 576 ++number_of_failed_constraints_applied_; | 580 ++number_of_failed_constraints_applied_; |
| 577 } | 581 } |
| 578 | 582 |
| 579 if (!track_to_release_.IsNull()) { | 583 if (!track_to_release_.IsNull()) { |
| 580 mock_source_ = nullptr; | 584 mock_source_ = nullptr; |
| 581 webkit_source_.Reset(); | 585 webkit_source_.Reset(); |
| 582 track_to_release_.Reset(); | 586 track_to_release_.Reset(); |
| 583 } | 587 } |
| 584 } | 588 } |
| 585 const base::MessageLoopForUI message_loop_; | 589 const base::test::ScopedTaskEnvironment scoped_task_environment_; |
| 586 const std::unique_ptr<ChildProcess> child_process_; | 590 const std::unique_ptr<ChildProcess> child_process_; |
| 587 blink::WebMediaStreamTrack track_to_release_; | 591 blink::WebMediaStreamTrack track_to_release_; |
| 588 int number_of_successful_constraints_applied_; | 592 int number_of_successful_constraints_applied_; |
| 589 int number_of_failed_constraints_applied_; | 593 int number_of_failed_constraints_applied_; |
| 590 content::MediaStreamRequestResult result_; | 594 content::MediaStreamRequestResult result_; |
| 591 blink::WebString result_name_; | 595 blink::WebString result_name_; |
| 592 blink::WebMediaStreamSource webkit_source_; | 596 blink::WebMediaStreamSource webkit_source_; |
| 593 // |mock_source_| is owned by |webkit_source_|. | 597 // |mock_source_| is owned by |webkit_source_|. |
| 594 MockMediaStreamVideoSource* mock_source_; | 598 MockMediaStreamVideoSource* mock_source_; |
| 595 base::test::ScopedFeatureList scoped_feature_list_; | 599 base::test::ScopedFeatureList scoped_feature_list_; |
| (...skipping 619 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1215 InvalidMandatoryAspectRatioFails) { | 1219 InvalidMandatoryAspectRatioFails) { |
| 1216 MockConstraintFactory factory; | 1220 MockConstraintFactory factory; |
| 1217 factory.basic().aspect_ratio.SetMax(0.0); | 1221 factory.basic().aspect_ratio.SetMax(0.0); |
| 1218 blink::WebMediaStreamTrack track = | 1222 blink::WebMediaStreamTrack track = |
| 1219 CreateTrack("123", factory.CreateWebMediaConstraints()); | 1223 CreateTrack("123", factory.CreateWebMediaConstraints()); |
| 1220 mock_source()->CompleteGetSupportedFormats(); | 1224 mock_source()->CompleteGetSupportedFormats(); |
| 1221 EXPECT_EQ(1, NumberOfFailedConstraintsCallbacks()); | 1225 EXPECT_EQ(1, NumberOfFailedConstraintsCallbacks()); |
| 1222 } | 1226 } |
| 1223 | 1227 |
| 1224 } // namespace content | 1228 } // namespace content |
| OLD | NEW |