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 "base/bind.h" | 5 #include "base/bind.h" |
6 #include "base/callback_helpers.h" | 6 #include "base/callback_helpers.h" |
7 #include "base/message_loop/message_loop.h" | 7 #include "base/message_loop/message_loop.h" |
8 #include "base/run_loop.h" | 8 #include "base/run_loop.h" |
9 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
10 #include "content/child/child_process.h" | 10 #include "content/child/child_process.h" |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
59 source_->SetDeviceInfo(device_info); | 59 source_->SetDeviceInfo(device_info); |
60 | 60 |
61 webkit_source_.initialize(base::UTF8ToUTF16("dummy_source_id"), | 61 webkit_source_.initialize(base::UTF8ToUTF16("dummy_source_id"), |
62 blink::WebMediaStreamSource::TypeVideo, | 62 blink::WebMediaStreamSource::TypeVideo, |
63 base::UTF8ToUTF16("dummy_source_name"), | 63 base::UTF8ToUTF16("dummy_source_name"), |
64 false /* remote */ , true /* readonly */); | 64 false /* remote */ , true /* readonly */); |
65 webkit_source_.setExtraData(source_); | 65 webkit_source_.setExtraData(source_); |
66 webkit_source_id_ = webkit_source_.id(); | 66 webkit_source_id_ = webkit_source_.id(); |
67 } | 67 } |
68 | 68 |
| 69 MockMediaConstraintFactory* constraint_factory() { |
| 70 return &constraint_factory_; |
| 71 } |
| 72 |
69 blink::WebMediaStreamTrack StartSource() { | 73 blink::WebMediaStreamTrack StartSource() { |
70 MockMediaConstraintFactory factory; | |
71 bool enabled = true; | 74 bool enabled = true; |
72 // CreateVideoTrack will trigger OnConstraintsApplied. | 75 // CreateVideoTrack will trigger OnConstraintsApplied. |
73 return MediaStreamVideoTrack::CreateVideoTrack( | 76 return MediaStreamVideoTrack::CreateVideoTrack( |
74 source_, factory.CreateWebMediaConstraints(), | 77 source_, constraint_factory_.CreateWebMediaConstraints(), |
75 base::Bind( | 78 base::Bind( |
76 &MediaStreamVideoCapturerSourceTest::OnConstraintsApplied, | 79 &MediaStreamVideoCapturerSourceTest::OnConstraintsApplied, |
77 base::Unretained(this)), | 80 base::Unretained(this)), |
78 enabled); | 81 enabled); |
79 } | 82 } |
80 | 83 |
81 MockVideoCapturerDelegate& mock_delegate() { | 84 MockVideoCapturerDelegate& mock_delegate() { |
82 return *delegate_; | 85 return *delegate_; |
83 } | 86 } |
84 | 87 |
85 void OnSourceStopped(const blink::WebMediaStreamSource& source) { | 88 void OnSourceStopped(const blink::WebMediaStreamSource& source) { |
86 source_stopped_ = true; | 89 source_stopped_ = true; |
87 EXPECT_EQ(source.id(), webkit_source_id_); | 90 EXPECT_EQ(source.id(), webkit_source_id_); |
88 } | 91 } |
89 | 92 |
90 protected: | 93 protected: |
91 void OnConstraintsApplied(MediaStreamSource* source, | 94 void OnConstraintsApplied(MediaStreamSource* source, |
92 MediaStreamRequestResult result, | 95 MediaStreamRequestResult result, |
93 const blink::WebString& result_name) { | 96 const blink::WebString& result_name) { |
94 } | 97 } |
95 | 98 |
96 base::MessageLoopForUI message_loop_; | 99 base::MessageLoopForUI message_loop_; |
97 scoped_ptr<ChildProcess> child_process_; | 100 scoped_ptr<ChildProcess> child_process_; |
98 blink::WebMediaStreamSource webkit_source_; | 101 blink::WebMediaStreamSource webkit_source_; |
99 MediaStreamVideoCapturerSource* source_; // owned by |webkit_source_|. | 102 MediaStreamVideoCapturerSource* source_; // owned by |webkit_source_|. |
100 MockVideoCapturerDelegate* delegate_; // owned by |source|. | 103 MockVideoCapturerDelegate* delegate_; // owned by |source|. |
101 blink::WebString webkit_source_id_; | 104 blink::WebString webkit_source_id_; |
102 bool source_stopped_; | 105 bool source_stopped_; |
| 106 MockMediaConstraintFactory constraint_factory_; |
103 }; | 107 }; |
104 | 108 |
105 TEST_F(MediaStreamVideoCapturerSourceTest, TabCaptureAllowResolutionChange) { | 109 TEST_F(MediaStreamVideoCapturerSourceTest, TabCaptureFixedResolutionByDefault) { |
106 StreamDeviceInfo device_info; | 110 StreamDeviceInfo device_info; |
107 device_info.device.type = MEDIA_TAB_VIDEO_CAPTURE; | 111 device_info.device.type = MEDIA_TAB_VIDEO_CAPTURE; |
108 InitWithDeviceInfo(device_info); | 112 InitWithDeviceInfo(device_info); |
109 | 113 |
| 114 // No constraints are being provided to the implementation, so expect only |
| 115 // default values. |
| 116 media::VideoCaptureParams expected_params; |
| 117 expected_params.requested_format.frame_size.SetSize( |
| 118 MediaStreamVideoSource::kDefaultWidth, |
| 119 MediaStreamVideoSource::kDefaultHeight); |
| 120 expected_params.requested_format.frame_rate = |
| 121 MediaStreamVideoSource::kDefaultFrameRate; |
| 122 expected_params.requested_format.pixel_format = media::PIXEL_FORMAT_I420; |
| 123 expected_params.resolution_change_policy = |
| 124 media::RESOLUTION_POLICY_FIXED_RESOLUTION; |
| 125 |
110 EXPECT_CALL(mock_delegate(), StartCapture( | 126 EXPECT_CALL(mock_delegate(), StartCapture( |
111 testing::Field(&media::VideoCaptureParams::resolution_change_policy, | 127 expected_params, |
112 media::RESOLUTION_POLICY_DYNAMIC_WITHIN_LIMIT), | |
113 testing::_, | 128 testing::_, |
114 testing::_, | 129 testing::_, |
115 testing::_)).Times(1); | 130 testing::_)).Times(1); |
116 blink::WebMediaStreamTrack track = StartSource(); | 131 blink::WebMediaStreamTrack track = StartSource(); |
117 // When the track goes out of scope, the source will be stopped. | 132 // When the track goes out of scope, the source will be stopped. |
118 EXPECT_CALL(mock_delegate(), StopCapture()); | 133 EXPECT_CALL(mock_delegate(), StopCapture()); |
119 } | 134 } |
120 | 135 |
121 TEST_F(MediaStreamVideoCapturerSourceTest, | 136 TEST_F(MediaStreamVideoCapturerSourceTest, |
122 DesktopCaptureAllowResolutionChange) { | 137 DesktopCaptureAllowAnyResolutionChangeByDefault) { |
123 StreamDeviceInfo device_info; | 138 StreamDeviceInfo device_info; |
124 device_info.device.type = MEDIA_DESKTOP_VIDEO_CAPTURE; | 139 device_info.device.type = MEDIA_DESKTOP_VIDEO_CAPTURE; |
125 InitWithDeviceInfo(device_info); | 140 InitWithDeviceInfo(device_info); |
126 | 141 |
| 142 // No constraints are being provided to the implementation, so expect only |
| 143 // default values. |
| 144 media::VideoCaptureParams expected_params; |
| 145 expected_params.requested_format.frame_size.SetSize( |
| 146 MediaStreamVideoSource::kDefaultWidth, |
| 147 MediaStreamVideoSource::kDefaultHeight); |
| 148 expected_params.requested_format.frame_rate = |
| 149 MediaStreamVideoSource::kDefaultFrameRate; |
| 150 expected_params.requested_format.pixel_format = media::PIXEL_FORMAT_I420; |
| 151 expected_params.resolution_change_policy = |
| 152 media::RESOLUTION_POLICY_ANY_WITHIN_LIMIT; |
| 153 |
127 EXPECT_CALL(mock_delegate(), StartCapture( | 154 EXPECT_CALL(mock_delegate(), StartCapture( |
128 testing::Field(&media::VideoCaptureParams::resolution_change_policy, | 155 expected_params, |
129 media::RESOLUTION_POLICY_DYNAMIC_WITHIN_LIMIT), | |
130 testing::_, | 156 testing::_, |
131 testing::_, | 157 testing::_, |
132 testing::_)).Times(1); | 158 testing::_)).Times(1); |
| 159 blink::WebMediaStreamTrack track = StartSource(); |
| 160 // When the track goes out of scope, the source will be stopped. |
| 161 EXPECT_CALL(mock_delegate(), StopCapture()); |
| 162 } |
| 163 |
| 164 TEST_F(MediaStreamVideoCapturerSourceTest, |
| 165 TabCaptureConstraintsImplyFixedAspectRatio) { |
| 166 StreamDeviceInfo device_info; |
| 167 device_info.device.type = MEDIA_TAB_VIDEO_CAPTURE; |
| 168 InitWithDeviceInfo(device_info); |
| 169 |
| 170 // Specify max and min size constraints that have the same ~16:9 aspect ratio. |
| 171 constraint_factory()->AddMandatory(MediaStreamVideoSource::kMaxWidth, 1920); |
| 172 constraint_factory()->AddMandatory(MediaStreamVideoSource::kMaxHeight, 1080); |
| 173 constraint_factory()->AddMandatory(MediaStreamVideoSource::kMinWidth, 854); |
| 174 constraint_factory()->AddMandatory(MediaStreamVideoSource::kMinHeight, 480); |
| 175 constraint_factory()->AddMandatory(MediaStreamVideoSource::kMaxFrameRate, |
| 176 60.0); |
| 177 |
| 178 media::VideoCaptureParams expected_params; |
| 179 expected_params.requested_format.frame_size.SetSize(1920, 1080); |
| 180 expected_params.requested_format.frame_rate = 60.0; |
| 181 expected_params.requested_format.pixel_format = media::PIXEL_FORMAT_I420; |
| 182 expected_params.resolution_change_policy = |
| 183 media::RESOLUTION_POLICY_FIXED_ASPECT_RATIO; |
| 184 |
| 185 EXPECT_CALL(mock_delegate(), StartCapture( |
| 186 testing::Field(&media::VideoCaptureParams::resolution_change_policy, |
| 187 media::RESOLUTION_POLICY_FIXED_ASPECT_RATIO), |
| 188 testing::_, |
| 189 testing::_, |
| 190 testing::_)).Times(1); |
| 191 blink::WebMediaStreamTrack track = StartSource(); |
| 192 // When the track goes out of scope, the source will be stopped. |
| 193 EXPECT_CALL(mock_delegate(), StopCapture()); |
| 194 } |
| 195 |
| 196 TEST_F(MediaStreamVideoCapturerSourceTest, |
| 197 TabCaptureConstraintsImplyAllowingAnyResolutionChange) { |
| 198 StreamDeviceInfo device_info; |
| 199 device_info.device.type = MEDIA_TAB_VIDEO_CAPTURE; |
| 200 InitWithDeviceInfo(device_info); |
| 201 |
| 202 // Specify max and min size constraints with different aspect ratios. |
| 203 constraint_factory()->AddMandatory(MediaStreamVideoSource::kMaxWidth, 1920); |
| 204 constraint_factory()->AddMandatory(MediaStreamVideoSource::kMaxHeight, 1080); |
| 205 constraint_factory()->AddMandatory(MediaStreamVideoSource::kMinWidth, 0); |
| 206 constraint_factory()->AddMandatory(MediaStreamVideoSource::kMinHeight, 0); |
| 207 constraint_factory()->AddMandatory(MediaStreamVideoSource::kMaxFrameRate, |
| 208 60.0); |
| 209 |
| 210 media::VideoCaptureParams expected_params; |
| 211 expected_params.requested_format.frame_size.SetSize(1920, 1080); |
| 212 expected_params.requested_format.frame_rate = 60.0; |
| 213 expected_params.requested_format.pixel_format = media::PIXEL_FORMAT_I420; |
| 214 expected_params.resolution_change_policy = |
| 215 media::RESOLUTION_POLICY_ANY_WITHIN_LIMIT; |
| 216 |
| 217 EXPECT_CALL(mock_delegate(), StartCapture( |
| 218 expected_params, |
| 219 testing::_, |
| 220 testing::_, |
| 221 testing::_)).Times(1); |
133 blink::WebMediaStreamTrack track = StartSource(); | 222 blink::WebMediaStreamTrack track = StartSource(); |
134 // When the track goes out of scope, the source will be stopped. | 223 // When the track goes out of scope, the source will be stopped. |
135 EXPECT_CALL(mock_delegate(), StopCapture()); | 224 EXPECT_CALL(mock_delegate(), StopCapture()); |
136 } | 225 } |
137 | 226 |
138 TEST_F(MediaStreamVideoCapturerSourceTest, Ended) { | 227 TEST_F(MediaStreamVideoCapturerSourceTest, Ended) { |
139 StreamDeviceInfo device_info; | 228 StreamDeviceInfo device_info; |
140 device_info.device.type = MEDIA_DESKTOP_VIDEO_CAPTURE; | 229 device_info.device.type = MEDIA_DESKTOP_VIDEO_CAPTURE; |
141 scoped_ptr<VideoCapturerDelegate> delegate( | 230 scoped_ptr<VideoCapturerDelegate> delegate( |
142 new VideoCapturerDelegate(device_info)); | 231 new VideoCapturerDelegate(device_info)); |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
237 run_loop.Run(); | 326 run_loop.Run(); |
238 FakeMediaStreamVideoSink::RemoveFromVideoTrack(&fake_sink, track); | 327 FakeMediaStreamVideoSink::RemoveFromVideoTrack(&fake_sink, track); |
239 EXPECT_EQ(reference_capture_time, capture_time); | 328 EXPECT_EQ(reference_capture_time, capture_time); |
240 double metadata_value; | 329 double metadata_value; |
241 EXPECT_TRUE(metadata.GetDouble(media::VideoFrameMetadata::FRAME_RATE, | 330 EXPECT_TRUE(metadata.GetDouble(media::VideoFrameMetadata::FRAME_RATE, |
242 &metadata_value)); | 331 &metadata_value)); |
243 EXPECT_EQ(30.0, metadata_value); | 332 EXPECT_EQ(30.0, metadata_value); |
244 } | 333 } |
245 | 334 |
246 } // namespace content | 335 } // namespace content |
OLD | NEW |