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

Side by Side Diff: chrome/browser/media/webrtc/media_stream_devices_controller_browsertest.cc

Issue 2706813004: Move logic to show permission prompts into MediaStreamDevicesController (Closed)
Patch Set: Move logic to show permission prompts into MediaStreamDevicesController Created 3 years, 10 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 <string> 5 #include <string>
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/metrics/field_trial.h" 8 #include "base/metrics/field_trial.h"
9 #include "chrome/browser/content_settings/host_content_settings_map_factory.h" 9 #include "chrome/browser/content_settings/host_content_settings_map_factory.h"
10 #include "chrome/browser/content_settings/tab_specific_content_settings.h" 10 #include "chrome/browser/content_settings/tab_specific_content_settings.h"
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
69 return TabSpecificContentSettings::FromWebContents(GetWebContents()); 69 return TabSpecificContentSettings::FromWebContents(GetWebContents());
70 } 70 }
71 71
72 const std::string& example_audio_id() const { return example_audio_id_; } 72 const std::string& example_audio_id() const { return example_audio_id_; }
73 const std::string& example_video_id() const { return example_video_id_; } 73 const std::string& example_video_id() const { return example_video_id_; }
74 74
75 content::MediaStreamRequestResult media_stream_result() const { 75 content::MediaStreamRequestResult media_stream_result() const {
76 return media_stream_result_; 76 return media_stream_result_;
77 } 77 }
78 78
79 std::unique_ptr<MediaStreamDevicesController>
80 CreateMediaStreamDevicesController(
81 content::WebContents* web_contents,
82 const content::MediaStreamRequest& request,
83 const content::MediaResponseCallback& callback) {
84 return base::WrapUnique(
85 new MediaStreamDevicesController(web_contents, request, callback));
86 }
87
88 bool IsAskingForAudio(const MediaStreamDevicesController* controller) {
89 return controller->IsAskingForAudio();
90 }
91
92 bool IsAskingForVideo(const MediaStreamDevicesController* controller) {
93 return controller->IsAskingForVideo();
94 }
95
96 void PermissionGranted(MediaStreamDevicesController* controller) {
97 return controller->PermissionGranted();
98 }
99
100 void PermissionDenied(MediaStreamDevicesController* controller) {
101 return controller->PermissionDenied();
102 }
103
79 // Sets the device policy-controlled |access| for |example_url_| to be for the 104 // Sets the device policy-controlled |access| for |example_url_| to be for the
80 // selected |device_type|. 105 // selected |device_type|.
81 void SetDevicePolicy(DeviceType device_type, Access access) { 106 void SetDevicePolicy(DeviceType device_type, Access access) {
82 PrefService* prefs = Profile::FromBrowserContext( 107 PrefService* prefs = Profile::FromBrowserContext(
83 GetWebContents()->GetBrowserContext())->GetPrefs(); 108 GetWebContents()->GetBrowserContext())->GetPrefs();
84 const char* policy_name = NULL; 109 const char* policy_name = NULL;
85 switch (device_type) { 110 switch (device_type) {
86 case DEVICE_TYPE_AUDIO: 111 case DEVICE_TYPE_AUDIO:
87 policy_name = prefs::kAudioCaptureAllowed; 112 policy_name = prefs::kAudioCaptureAllowed;
88 break; 113 break;
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
183 const std::string example_video_id_; 208 const std::string example_video_id_;
184 209
185 content::MediaStreamDevices media_stream_devices_; 210 content::MediaStreamDevices media_stream_devices_;
186 content::MediaStreamRequestResult media_stream_result_; 211 content::MediaStreamRequestResult media_stream_result_;
187 }; 212 };
188 213
189 // Request and allow microphone access. 214 // Request and allow microphone access.
190 IN_PROC_BROWSER_TEST_F(MediaStreamDevicesControllerTest, RequestAndAllowMic) { 215 IN_PROC_BROWSER_TEST_F(MediaStreamDevicesControllerTest, RequestAndAllowMic) {
191 InitWithUrl(GURL("https://www.example.com")); 216 InitWithUrl(GURL("https://www.example.com"));
192 SetDevicePolicy(DEVICE_TYPE_AUDIO, ACCESS_ALLOWED); 217 SetDevicePolicy(DEVICE_TYPE_AUDIO, ACCESS_ALLOWED);
193 MediaStreamDevicesController controller( 218 std::unique_ptr<MediaStreamDevicesController> controller(
194 GetWebContents(), CreateRequest(example_audio_id(), std::string()), 219 CreateMediaStreamDevicesController(
195 base::Bind(&MediaStreamDevicesControllerTest::OnMediaStreamResponse, 220 GetWebContents(), CreateRequest(example_audio_id(), std::string()),
196 base::Unretained(this))); 221 base::Bind(&MediaStreamDevicesControllerTest::OnMediaStreamResponse,
197 NotifyTabSpecificContentSettings(&controller); 222 base::Unretained(this))));
223 NotifyTabSpecificContentSettings(controller.get());
198 224
199 EXPECT_TRUE(GetContentSettings()->IsContentAllowed( 225 EXPECT_TRUE(GetContentSettings()->IsContentAllowed(
200 CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC)); 226 CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC));
201 EXPECT_FALSE(GetContentSettings()->IsContentBlocked( 227 EXPECT_FALSE(GetContentSettings()->IsContentBlocked(
202 CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC)); 228 CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC));
203 EXPECT_EQ(TabSpecificContentSettings::MICROPHONE_ACCESSED, 229 EXPECT_EQ(TabSpecificContentSettings::MICROPHONE_ACCESSED,
204 GetContentSettings()->GetMicrophoneCameraState()); 230 GetContentSettings()->GetMicrophoneCameraState());
205 EXPECT_EQ(example_audio_id(), 231 EXPECT_EQ(example_audio_id(),
206 GetContentSettings()->media_stream_requested_audio_device()); 232 GetContentSettings()->media_stream_requested_audio_device());
207 EXPECT_EQ(example_audio_id(), 233 EXPECT_EQ(example_audio_id(),
208 GetContentSettings()->media_stream_selected_audio_device()); 234 GetContentSettings()->media_stream_selected_audio_device());
209 EXPECT_EQ(std::string(), 235 EXPECT_EQ(std::string(),
210 GetContentSettings()->media_stream_requested_video_device()); 236 GetContentSettings()->media_stream_requested_video_device());
211 EXPECT_EQ(std::string(), 237 EXPECT_EQ(std::string(),
212 GetContentSettings()->media_stream_selected_video_device()); 238 GetContentSettings()->media_stream_selected_video_device());
213 } 239 }
214 240
215 // Request and allow camera access. 241 // Request and allow camera access.
216 IN_PROC_BROWSER_TEST_F(MediaStreamDevicesControllerTest, RequestAndAllowCam) { 242 IN_PROC_BROWSER_TEST_F(MediaStreamDevicesControllerTest, RequestAndAllowCam) {
217 InitWithUrl(GURL("https://www.example.com")); 243 InitWithUrl(GURL("https://www.example.com"));
218 SetDevicePolicy(DEVICE_TYPE_VIDEO, ACCESS_ALLOWED); 244 SetDevicePolicy(DEVICE_TYPE_VIDEO, ACCESS_ALLOWED);
219 MediaStreamDevicesController controller( 245 std::unique_ptr<MediaStreamDevicesController> controller(
220 GetWebContents(), CreateRequest(std::string(), example_video_id()), 246 CreateMediaStreamDevicesController(
221 base::Bind(&MediaStreamDevicesControllerTest::OnMediaStreamResponse, 247 GetWebContents(), CreateRequest(std::string(), example_video_id()),
222 base::Unretained(this))); 248 base::Bind(&MediaStreamDevicesControllerTest::OnMediaStreamResponse,
223 NotifyTabSpecificContentSettings(&controller); 249 base::Unretained(this))));
250 NotifyTabSpecificContentSettings(controller.get());
224 251
225 EXPECT_TRUE(GetContentSettings()->IsContentAllowed( 252 EXPECT_TRUE(GetContentSettings()->IsContentAllowed(
226 CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA)); 253 CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA));
227 EXPECT_FALSE(GetContentSettings()->IsContentBlocked( 254 EXPECT_FALSE(GetContentSettings()->IsContentBlocked(
228 CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA)); 255 CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA));
229 EXPECT_EQ(TabSpecificContentSettings::CAMERA_ACCESSED, 256 EXPECT_EQ(TabSpecificContentSettings::CAMERA_ACCESSED,
230 GetContentSettings()->GetMicrophoneCameraState()); 257 GetContentSettings()->GetMicrophoneCameraState());
231 EXPECT_EQ(std::string(), 258 EXPECT_EQ(std::string(),
232 GetContentSettings()->media_stream_requested_audio_device()); 259 GetContentSettings()->media_stream_requested_audio_device());
233 EXPECT_EQ(std::string(), 260 EXPECT_EQ(std::string(),
234 GetContentSettings()->media_stream_selected_audio_device()); 261 GetContentSettings()->media_stream_selected_audio_device());
235 EXPECT_EQ(example_video_id(), 262 EXPECT_EQ(example_video_id(),
236 GetContentSettings()->media_stream_requested_video_device()); 263 GetContentSettings()->media_stream_requested_video_device());
237 EXPECT_EQ(example_video_id(), 264 EXPECT_EQ(example_video_id(),
238 GetContentSettings()->media_stream_selected_video_device()); 265 GetContentSettings()->media_stream_selected_video_device());
239 } 266 }
240 267
241 // Request and block microphone access. 268 // Request and block microphone access.
242 IN_PROC_BROWSER_TEST_F(MediaStreamDevicesControllerTest, RequestAndBlockMic) { 269 IN_PROC_BROWSER_TEST_F(MediaStreamDevicesControllerTest, RequestAndBlockMic) {
243 InitWithUrl(GURL("https://www.example.com")); 270 InitWithUrl(GURL("https://www.example.com"));
244 SetDevicePolicy(DEVICE_TYPE_AUDIO, ACCESS_DENIED); 271 SetDevicePolicy(DEVICE_TYPE_AUDIO, ACCESS_DENIED);
245 MediaStreamDevicesController controller( 272 std::unique_ptr<MediaStreamDevicesController> controller(
246 GetWebContents(), CreateRequest(example_audio_id(), std::string()), 273 CreateMediaStreamDevicesController(
247 base::Bind(&MediaStreamDevicesControllerTest::OnMediaStreamResponse, 274 GetWebContents(), CreateRequest(example_audio_id(), std::string()),
248 base::Unretained(this))); 275 base::Bind(&MediaStreamDevicesControllerTest::OnMediaStreamResponse,
249 NotifyTabSpecificContentSettings(&controller); 276 base::Unretained(this))));
277 NotifyTabSpecificContentSettings(controller.get());
250 278
251 EXPECT_FALSE(GetContentSettings()->IsContentAllowed( 279 EXPECT_FALSE(GetContentSettings()->IsContentAllowed(
252 CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC)); 280 CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC));
253 EXPECT_TRUE(GetContentSettings()->IsContentBlocked( 281 EXPECT_TRUE(GetContentSettings()->IsContentBlocked(
254 CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC)); 282 CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC));
255 EXPECT_EQ(TabSpecificContentSettings::MICROPHONE_ACCESSED | 283 EXPECT_EQ(TabSpecificContentSettings::MICROPHONE_ACCESSED |
256 TabSpecificContentSettings::MICROPHONE_BLOCKED, 284 TabSpecificContentSettings::MICROPHONE_BLOCKED,
257 GetContentSettings()->GetMicrophoneCameraState()); 285 GetContentSettings()->GetMicrophoneCameraState());
258 EXPECT_EQ(example_audio_id(), 286 EXPECT_EQ(example_audio_id(),
259 GetContentSettings()->media_stream_requested_audio_device()); 287 GetContentSettings()->media_stream_requested_audio_device());
260 EXPECT_EQ(example_audio_id(), 288 EXPECT_EQ(example_audio_id(),
261 GetContentSettings()->media_stream_selected_audio_device()); 289 GetContentSettings()->media_stream_selected_audio_device());
262 EXPECT_EQ(std::string(), 290 EXPECT_EQ(std::string(),
263 GetContentSettings()->media_stream_requested_video_device()); 291 GetContentSettings()->media_stream_requested_video_device());
264 EXPECT_EQ(std::string(), 292 EXPECT_EQ(std::string(),
265 GetContentSettings()->media_stream_selected_video_device()); 293 GetContentSettings()->media_stream_selected_video_device());
266 } 294 }
267 295
268 // Request and block camera access. 296 // Request and block camera access.
269 IN_PROC_BROWSER_TEST_F(MediaStreamDevicesControllerTest, RequestAndBlockCam) { 297 IN_PROC_BROWSER_TEST_F(MediaStreamDevicesControllerTest, RequestAndBlockCam) {
270 InitWithUrl(GURL("https://www.example.com")); 298 InitWithUrl(GURL("https://www.example.com"));
271 SetDevicePolicy(DEVICE_TYPE_VIDEO, ACCESS_DENIED); 299 SetDevicePolicy(DEVICE_TYPE_VIDEO, ACCESS_DENIED);
272 MediaStreamDevicesController controller( 300 std::unique_ptr<MediaStreamDevicesController> controller(
273 GetWebContents(), CreateRequest(std::string(), example_video_id()), 301 CreateMediaStreamDevicesController(
274 base::Bind(&MediaStreamDevicesControllerTest::OnMediaStreamResponse, 302 GetWebContents(), CreateRequest(std::string(), example_video_id()),
275 base::Unretained(this))); 303 base::Bind(&MediaStreamDevicesControllerTest::OnMediaStreamResponse,
276 NotifyTabSpecificContentSettings(&controller); 304 base::Unretained(this))));
305 NotifyTabSpecificContentSettings(controller.get());
277 306
278 EXPECT_FALSE(GetContentSettings()->IsContentAllowed( 307 EXPECT_FALSE(GetContentSettings()->IsContentAllowed(
279 CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA)); 308 CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA));
280 EXPECT_TRUE(GetContentSettings()->IsContentBlocked( 309 EXPECT_TRUE(GetContentSettings()->IsContentBlocked(
281 CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA)); 310 CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA));
282 EXPECT_EQ(TabSpecificContentSettings::CAMERA_ACCESSED | 311 EXPECT_EQ(TabSpecificContentSettings::CAMERA_ACCESSED |
283 TabSpecificContentSettings::CAMERA_BLOCKED, 312 TabSpecificContentSettings::CAMERA_BLOCKED,
284 GetContentSettings()->GetMicrophoneCameraState()); 313 GetContentSettings()->GetMicrophoneCameraState());
285 EXPECT_EQ(std::string(), 314 EXPECT_EQ(std::string(),
286 GetContentSettings()->media_stream_requested_audio_device()); 315 GetContentSettings()->media_stream_requested_audio_device());
287 EXPECT_EQ(std::string(), 316 EXPECT_EQ(std::string(),
288 GetContentSettings()->media_stream_selected_audio_device()); 317 GetContentSettings()->media_stream_selected_audio_device());
289 EXPECT_EQ(example_video_id(), 318 EXPECT_EQ(example_video_id(),
290 GetContentSettings()->media_stream_requested_video_device()); 319 GetContentSettings()->media_stream_requested_video_device());
291 EXPECT_EQ(example_video_id(), 320 EXPECT_EQ(example_video_id(),
292 GetContentSettings()->media_stream_selected_video_device()); 321 GetContentSettings()->media_stream_selected_video_device());
293 } 322 }
294 323
295 // Request and allow microphone and camera access. 324 // Request and allow microphone and camera access.
296 IN_PROC_BROWSER_TEST_F(MediaStreamDevicesControllerTest, 325 IN_PROC_BROWSER_TEST_F(MediaStreamDevicesControllerTest,
297 RequestAndAllowMicCam) { 326 RequestAndAllowMicCam) {
298 InitWithUrl(GURL("https://www.example.com")); 327 InitWithUrl(GURL("https://www.example.com"));
299 SetDevicePolicy(DEVICE_TYPE_AUDIO, ACCESS_ALLOWED); 328 SetDevicePolicy(DEVICE_TYPE_AUDIO, ACCESS_ALLOWED);
300 SetDevicePolicy(DEVICE_TYPE_VIDEO, ACCESS_ALLOWED); 329 SetDevicePolicy(DEVICE_TYPE_VIDEO, ACCESS_ALLOWED);
301 MediaStreamDevicesController controller( 330 std::unique_ptr<MediaStreamDevicesController> controller(
302 GetWebContents(), CreateRequest(example_audio_id(), example_video_id()), 331 CreateMediaStreamDevicesController(
303 base::Bind(&MediaStreamDevicesControllerTest::OnMediaStreamResponse, 332 GetWebContents(),
304 base::Unretained(this))); 333 CreateRequest(example_audio_id(), example_video_id()),
305 NotifyTabSpecificContentSettings(&controller); 334 base::Bind(&MediaStreamDevicesControllerTest::OnMediaStreamResponse,
335 base::Unretained(this))));
336 NotifyTabSpecificContentSettings(controller.get());
306 337
307 EXPECT_TRUE(GetContentSettings()->IsContentAllowed( 338 EXPECT_TRUE(GetContentSettings()->IsContentAllowed(
308 CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC)); 339 CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC));
309 EXPECT_FALSE(GetContentSettings()->IsContentBlocked( 340 EXPECT_FALSE(GetContentSettings()->IsContentBlocked(
310 CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC)); 341 CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC));
311 EXPECT_TRUE(GetContentSettings()->IsContentAllowed( 342 EXPECT_TRUE(GetContentSettings()->IsContentAllowed(
312 CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA)); 343 CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA));
313 EXPECT_FALSE(GetContentSettings()->IsContentBlocked( 344 EXPECT_FALSE(GetContentSettings()->IsContentBlocked(
314 CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA)); 345 CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA));
315 EXPECT_EQ(TabSpecificContentSettings::MICROPHONE_ACCESSED | 346 EXPECT_EQ(TabSpecificContentSettings::MICROPHONE_ACCESSED |
316 TabSpecificContentSettings::CAMERA_ACCESSED, 347 TabSpecificContentSettings::CAMERA_ACCESSED,
317 GetContentSettings()->GetMicrophoneCameraState()); 348 GetContentSettings()->GetMicrophoneCameraState());
318 EXPECT_EQ(example_audio_id(), 349 EXPECT_EQ(example_audio_id(),
319 GetContentSettings()->media_stream_requested_audio_device()); 350 GetContentSettings()->media_stream_requested_audio_device());
320 EXPECT_EQ(example_audio_id(), 351 EXPECT_EQ(example_audio_id(),
321 GetContentSettings()->media_stream_selected_audio_device()); 352 GetContentSettings()->media_stream_selected_audio_device());
322 EXPECT_EQ(example_video_id(), 353 EXPECT_EQ(example_video_id(),
323 GetContentSettings()->media_stream_requested_video_device()); 354 GetContentSettings()->media_stream_requested_video_device());
324 EXPECT_EQ(example_video_id(), 355 EXPECT_EQ(example_video_id(),
325 GetContentSettings()->media_stream_selected_video_device()); 356 GetContentSettings()->media_stream_selected_video_device());
326 } 357 }
327 358
328 // Request and block microphone and camera access. 359 // Request and block microphone and camera access.
329 IN_PROC_BROWSER_TEST_F(MediaStreamDevicesControllerTest, 360 IN_PROC_BROWSER_TEST_F(MediaStreamDevicesControllerTest,
330 RequestAndBlockMicCam) { 361 RequestAndBlockMicCam) {
331 InitWithUrl(GURL("https://www.example.com")); 362 InitWithUrl(GURL("https://www.example.com"));
332 SetDevicePolicy(DEVICE_TYPE_AUDIO, ACCESS_DENIED); 363 SetDevicePolicy(DEVICE_TYPE_AUDIO, ACCESS_DENIED);
333 SetDevicePolicy(DEVICE_TYPE_VIDEO, ACCESS_DENIED); 364 SetDevicePolicy(DEVICE_TYPE_VIDEO, ACCESS_DENIED);
334 MediaStreamDevicesController controller( 365 std::unique_ptr<MediaStreamDevicesController> controller(
335 GetWebContents(), CreateRequest(example_audio_id(), example_video_id()), 366 CreateMediaStreamDevicesController(
336 base::Bind(&MediaStreamDevicesControllerTest::OnMediaStreamResponse, 367 GetWebContents(),
337 base::Unretained(this))); 368 CreateRequest(example_audio_id(), example_video_id()),
338 NotifyTabSpecificContentSettings(&controller); 369 base::Bind(&MediaStreamDevicesControllerTest::OnMediaStreamResponse,
370 base::Unretained(this))));
371 NotifyTabSpecificContentSettings(controller.get());
339 372
340 EXPECT_FALSE(GetContentSettings()->IsContentAllowed( 373 EXPECT_FALSE(GetContentSettings()->IsContentAllowed(
341 CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC)); 374 CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC));
342 EXPECT_TRUE(GetContentSettings()->IsContentBlocked( 375 EXPECT_TRUE(GetContentSettings()->IsContentBlocked(
343 CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC)); 376 CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC));
344 EXPECT_FALSE(GetContentSettings()->IsContentAllowed( 377 EXPECT_FALSE(GetContentSettings()->IsContentAllowed(
345 CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA)); 378 CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA));
346 EXPECT_TRUE(GetContentSettings()->IsContentBlocked( 379 EXPECT_TRUE(GetContentSettings()->IsContentBlocked(
347 CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA)); 380 CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA));
348 EXPECT_EQ(TabSpecificContentSettings::MICROPHONE_ACCESSED | 381 EXPECT_EQ(TabSpecificContentSettings::MICROPHONE_ACCESSED |
(...skipping 10 matching lines...) Expand all
359 EXPECT_EQ(example_video_id(), 392 EXPECT_EQ(example_video_id(),
360 GetContentSettings()->media_stream_selected_video_device()); 393 GetContentSettings()->media_stream_selected_video_device());
361 } 394 }
362 395
363 // Request microphone and camera access. Allow microphone, block camera. 396 // Request microphone and camera access. Allow microphone, block camera.
364 IN_PROC_BROWSER_TEST_F(MediaStreamDevicesControllerTest, 397 IN_PROC_BROWSER_TEST_F(MediaStreamDevicesControllerTest,
365 RequestMicCamBlockCam) { 398 RequestMicCamBlockCam) {
366 InitWithUrl(GURL("https://www.example.com")); 399 InitWithUrl(GURL("https://www.example.com"));
367 SetDevicePolicy(DEVICE_TYPE_AUDIO, ACCESS_ALLOWED); 400 SetDevicePolicy(DEVICE_TYPE_AUDIO, ACCESS_ALLOWED);
368 SetDevicePolicy(DEVICE_TYPE_VIDEO, ACCESS_DENIED); 401 SetDevicePolicy(DEVICE_TYPE_VIDEO, ACCESS_DENIED);
369 MediaStreamDevicesController controller( 402 std::unique_ptr<MediaStreamDevicesController> controller(
370 GetWebContents(), CreateRequest(example_audio_id(), example_video_id()), 403 CreateMediaStreamDevicesController(
371 base::Bind(&MediaStreamDevicesControllerTest::OnMediaStreamResponse, 404 GetWebContents(),
372 base::Unretained(this))); 405 CreateRequest(example_audio_id(), example_video_id()),
373 NotifyTabSpecificContentSettings(&controller); 406 base::Bind(&MediaStreamDevicesControllerTest::OnMediaStreamResponse,
407 base::Unretained(this))));
408 NotifyTabSpecificContentSettings(controller.get());
374 409
375 EXPECT_TRUE(GetContentSettings()->IsContentAllowed( 410 EXPECT_TRUE(GetContentSettings()->IsContentAllowed(
376 CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC)); 411 CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC));
377 EXPECT_FALSE(GetContentSettings()->IsContentBlocked( 412 EXPECT_FALSE(GetContentSettings()->IsContentBlocked(
378 CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC)); 413 CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC));
379 EXPECT_FALSE(GetContentSettings()->IsContentAllowed( 414 EXPECT_FALSE(GetContentSettings()->IsContentAllowed(
380 CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA)); 415 CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA));
381 EXPECT_TRUE(GetContentSettings()->IsContentBlocked( 416 EXPECT_TRUE(GetContentSettings()->IsContentBlocked(
382 CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA)); 417 CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA));
383 EXPECT_EQ(TabSpecificContentSettings::MICROPHONE_ACCESSED | 418 EXPECT_EQ(TabSpecificContentSettings::MICROPHONE_ACCESSED |
384 TabSpecificContentSettings::CAMERA_ACCESSED | 419 TabSpecificContentSettings::CAMERA_ACCESSED |
385 TabSpecificContentSettings::CAMERA_BLOCKED, 420 TabSpecificContentSettings::CAMERA_BLOCKED,
386 GetContentSettings()->GetMicrophoneCameraState()); 421 GetContentSettings()->GetMicrophoneCameraState());
387 EXPECT_EQ(example_audio_id(), 422 EXPECT_EQ(example_audio_id(),
388 GetContentSettings()->media_stream_requested_audio_device()); 423 GetContentSettings()->media_stream_requested_audio_device());
389 EXPECT_EQ(example_audio_id(), 424 EXPECT_EQ(example_audio_id(),
390 GetContentSettings()->media_stream_selected_audio_device()); 425 GetContentSettings()->media_stream_selected_audio_device());
391 EXPECT_EQ(example_video_id(), 426 EXPECT_EQ(example_video_id(),
392 GetContentSettings()->media_stream_requested_video_device()); 427 GetContentSettings()->media_stream_requested_video_device());
393 EXPECT_EQ(example_video_id(), 428 EXPECT_EQ(example_video_id(),
394 GetContentSettings()->media_stream_selected_video_device()); 429 GetContentSettings()->media_stream_selected_video_device());
395 } 430 }
396 431
397 // Request microphone and camera access. Block microphone, allow camera. 432 // Request microphone and camera access. Block microphone, allow camera.
398 IN_PROC_BROWSER_TEST_F(MediaStreamDevicesControllerTest, 433 IN_PROC_BROWSER_TEST_F(MediaStreamDevicesControllerTest,
399 RequestMicCamBlockMic) { 434 RequestMicCamBlockMic) {
400 InitWithUrl(GURL("https://www.example.com")); 435 InitWithUrl(GURL("https://www.example.com"));
401 SetDevicePolicy(DEVICE_TYPE_AUDIO, ACCESS_DENIED); 436 SetDevicePolicy(DEVICE_TYPE_AUDIO, ACCESS_DENIED);
402 SetDevicePolicy(DEVICE_TYPE_VIDEO, ACCESS_ALLOWED); 437 SetDevicePolicy(DEVICE_TYPE_VIDEO, ACCESS_ALLOWED);
403 MediaStreamDevicesController controller( 438 std::unique_ptr<MediaStreamDevicesController> controller(
404 GetWebContents(), CreateRequest(example_audio_id(), example_video_id()), 439 CreateMediaStreamDevicesController(
405 base::Bind(&MediaStreamDevicesControllerTest::OnMediaStreamResponse, 440 GetWebContents(),
406 base::Unretained(this))); 441 CreateRequest(example_audio_id(), example_video_id()),
407 NotifyTabSpecificContentSettings(&controller); 442 base::Bind(&MediaStreamDevicesControllerTest::OnMediaStreamResponse,
443 base::Unretained(this))));
444 NotifyTabSpecificContentSettings(controller.get());
408 445
409 EXPECT_FALSE(GetContentSettings()->IsContentAllowed( 446 EXPECT_FALSE(GetContentSettings()->IsContentAllowed(
410 CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC)); 447 CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC));
411 EXPECT_TRUE(GetContentSettings()->IsContentBlocked( 448 EXPECT_TRUE(GetContentSettings()->IsContentBlocked(
412 CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC)); 449 CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC));
413 EXPECT_TRUE(GetContentSettings()->IsContentAllowed( 450 EXPECT_TRUE(GetContentSettings()->IsContentAllowed(
414 CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA)); 451 CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA));
415 EXPECT_FALSE(GetContentSettings()->IsContentBlocked( 452 EXPECT_FALSE(GetContentSettings()->IsContentBlocked(
416 CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA)); 453 CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA));
417 EXPECT_EQ(TabSpecificContentSettings::MICROPHONE_ACCESSED | 454 EXPECT_EQ(TabSpecificContentSettings::MICROPHONE_ACCESSED |
(...skipping 10 matching lines...) Expand all
428 GetContentSettings()->media_stream_selected_video_device()); 465 GetContentSettings()->media_stream_selected_video_device());
429 } 466 }
430 467
431 // Request microphone access. Requesting camera should not change microphone 468 // Request microphone access. Requesting camera should not change microphone
432 // state. 469 // state.
433 IN_PROC_BROWSER_TEST_F(MediaStreamDevicesControllerTest, 470 IN_PROC_BROWSER_TEST_F(MediaStreamDevicesControllerTest,
434 RequestCamDoesNotChangeMic) { 471 RequestCamDoesNotChangeMic) {
435 InitWithUrl(GURL("https://www.example.com")); 472 InitWithUrl(GURL("https://www.example.com"));
436 // Request mic and deny. 473 // Request mic and deny.
437 SetDevicePolicy(DEVICE_TYPE_AUDIO, ACCESS_DENIED); 474 SetDevicePolicy(DEVICE_TYPE_AUDIO, ACCESS_DENIED);
438 MediaStreamDevicesController mic_controller( 475 std::unique_ptr<MediaStreamDevicesController> mic_controller(
439 GetWebContents(), CreateRequest(example_audio_id(), std::string()), 476 CreateMediaStreamDevicesController(
440 base::Bind(&MediaStreamDevicesControllerTest::OnMediaStreamResponse, 477 GetWebContents(), CreateRequest(example_audio_id(), std::string()),
441 base::Unretained(this))); 478 base::Bind(&MediaStreamDevicesControllerTest::OnMediaStreamResponse,
442 NotifyTabSpecificContentSettings(&mic_controller); 479 base::Unretained(this))));
480 NotifyTabSpecificContentSettings(mic_controller.get());
443 EXPECT_FALSE(GetContentSettings()->IsContentAllowed( 481 EXPECT_FALSE(GetContentSettings()->IsContentAllowed(
444 CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC)); 482 CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC));
445 EXPECT_TRUE(GetContentSettings()->IsContentBlocked( 483 EXPECT_TRUE(GetContentSettings()->IsContentBlocked(
446 CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC)); 484 CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC));
447 EXPECT_EQ(example_audio_id(), 485 EXPECT_EQ(example_audio_id(),
448 GetContentSettings()->media_stream_requested_audio_device()); 486 GetContentSettings()->media_stream_requested_audio_device());
449 EXPECT_EQ(example_audio_id(), 487 EXPECT_EQ(example_audio_id(),
450 GetContentSettings()->media_stream_selected_audio_device()); 488 GetContentSettings()->media_stream_selected_audio_device());
451 489
452 // Request cam and allow 490 // Request cam and allow
453 SetDevicePolicy(DEVICE_TYPE_VIDEO, ACCESS_ALLOWED); 491 SetDevicePolicy(DEVICE_TYPE_VIDEO, ACCESS_ALLOWED);
454 MediaStreamDevicesController cam_controller( 492 std::unique_ptr<MediaStreamDevicesController> cam_controller(
455 GetWebContents(), CreateRequest(std::string(), example_video_id()), 493 CreateMediaStreamDevicesController(
456 base::Bind(&MediaStreamDevicesControllerTest::OnMediaStreamResponse, 494 GetWebContents(), CreateRequest(std::string(), example_video_id()),
457 base::Unretained(this))); 495 base::Bind(&MediaStreamDevicesControllerTest::OnMediaStreamResponse,
458 NotifyTabSpecificContentSettings(&cam_controller); 496 base::Unretained(this))));
497 NotifyTabSpecificContentSettings(cam_controller.get());
459 EXPECT_TRUE(GetContentSettings()->IsContentAllowed( 498 EXPECT_TRUE(GetContentSettings()->IsContentAllowed(
460 CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA)); 499 CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA));
461 EXPECT_FALSE(GetContentSettings()->IsContentBlocked( 500 EXPECT_FALSE(GetContentSettings()->IsContentBlocked(
462 CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA)); 501 CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA));
463 EXPECT_EQ(example_video_id(), 502 EXPECT_EQ(example_video_id(),
464 GetContentSettings()->media_stream_requested_video_device()); 503 GetContentSettings()->media_stream_requested_video_device());
465 EXPECT_EQ(example_video_id(), 504 EXPECT_EQ(example_video_id(),
466 GetContentSettings()->media_stream_selected_video_device()); 505 GetContentSettings()->media_stream_selected_video_device());
467 506
468 // Mic state should not have changed. 507 // Mic state should not have changed.
469 EXPECT_FALSE(GetContentSettings()->IsContentAllowed( 508 EXPECT_FALSE(GetContentSettings()->IsContentAllowed(
470 CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC)); 509 CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC));
471 EXPECT_TRUE(GetContentSettings()->IsContentBlocked( 510 EXPECT_TRUE(GetContentSettings()->IsContentBlocked(
472 CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC)); 511 CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC));
473 EXPECT_EQ(example_audio_id(), 512 EXPECT_EQ(example_audio_id(),
474 GetContentSettings()->media_stream_requested_audio_device()); 513 GetContentSettings()->media_stream_requested_audio_device());
475 EXPECT_EQ(example_audio_id(), 514 EXPECT_EQ(example_audio_id(),
476 GetContentSettings()->media_stream_selected_audio_device()); 515 GetContentSettings()->media_stream_selected_audio_device());
477 } 516 }
478 517
479 // Denying mic access after camera access should still show the camera as state. 518 // Denying mic access after camera access should still show the camera as state.
480 IN_PROC_BROWSER_TEST_F(MediaStreamDevicesControllerTest, 519 IN_PROC_BROWSER_TEST_F(MediaStreamDevicesControllerTest,
481 DenyMicDoesNotChangeCam) { 520 DenyMicDoesNotChangeCam) {
482 InitWithUrl(GURL("https://www.example.com")); 521 InitWithUrl(GURL("https://www.example.com"));
483 // Request cam and allow 522 // Request cam and allow
484 SetDevicePolicy(DEVICE_TYPE_VIDEO, ACCESS_ALLOWED); 523 SetDevicePolicy(DEVICE_TYPE_VIDEO, ACCESS_ALLOWED);
485 MediaStreamDevicesController cam_controller( 524 std::unique_ptr<MediaStreamDevicesController> cam_controller(
486 GetWebContents(), CreateRequest(std::string(), example_video_id()), 525 CreateMediaStreamDevicesController(
487 base::Bind(&MediaStreamDevicesControllerTest::OnMediaStreamResponse, 526 GetWebContents(), CreateRequest(std::string(), example_video_id()),
488 base::Unretained(this))); 527 base::Bind(&MediaStreamDevicesControllerTest::OnMediaStreamResponse,
489 NotifyTabSpecificContentSettings(&cam_controller); 528 base::Unretained(this))));
529 NotifyTabSpecificContentSettings(cam_controller.get());
490 EXPECT_TRUE(GetContentSettings()->IsContentAllowed( 530 EXPECT_TRUE(GetContentSettings()->IsContentAllowed(
491 CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA)); 531 CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA));
492 EXPECT_FALSE(GetContentSettings()->IsContentBlocked( 532 EXPECT_FALSE(GetContentSettings()->IsContentBlocked(
493 CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA)); 533 CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA));
494 EXPECT_EQ(example_video_id(), 534 EXPECT_EQ(example_video_id(),
495 GetContentSettings()->media_stream_requested_video_device()); 535 GetContentSettings()->media_stream_requested_video_device());
496 EXPECT_EQ(example_video_id(), 536 EXPECT_EQ(example_video_id(),
497 GetContentSettings()->media_stream_selected_video_device()); 537 GetContentSettings()->media_stream_selected_video_device());
498 EXPECT_EQ(TabSpecificContentSettings::CAMERA_ACCESSED, 538 EXPECT_EQ(TabSpecificContentSettings::CAMERA_ACCESSED,
499 GetContentSettings()->GetMicrophoneCameraState()); 539 GetContentSettings()->GetMicrophoneCameraState());
500 540
501 // Simulate that an a video stream is now being captured. 541 // Simulate that an a video stream is now being captured.
502 content::MediaStreamDevice fake_video_device( 542 content::MediaStreamDevice fake_video_device(
503 content::MEDIA_DEVICE_VIDEO_CAPTURE, example_video_id(), 543 content::MEDIA_DEVICE_VIDEO_CAPTURE, example_video_id(),
504 example_video_id()); 544 example_video_id());
505 content::MediaStreamDevices video_devices(1, fake_video_device); 545 content::MediaStreamDevices video_devices(1, fake_video_device);
506 MediaCaptureDevicesDispatcher* dispatcher = 546 MediaCaptureDevicesDispatcher* dispatcher =
507 MediaCaptureDevicesDispatcher::GetInstance(); 547 MediaCaptureDevicesDispatcher::GetInstance();
508 dispatcher->SetTestVideoCaptureDevices(video_devices); 548 dispatcher->SetTestVideoCaptureDevices(video_devices);
509 std::unique_ptr<content::MediaStreamUI> video_stream_ui = 549 std::unique_ptr<content::MediaStreamUI> video_stream_ui =
510 dispatcher->GetMediaStreamCaptureIndicator()->RegisterMediaStream( 550 dispatcher->GetMediaStreamCaptureIndicator()->RegisterMediaStream(
511 GetWebContents(), video_devices); 551 GetWebContents(), video_devices);
512 video_stream_ui->OnStarted(base::Closure()); 552 video_stream_ui->OnStarted(base::Closure());
513 553
514 // Request mic and deny. 554 // Request mic and deny.
515 SetDevicePolicy(DEVICE_TYPE_AUDIO, ACCESS_DENIED); 555 SetDevicePolicy(DEVICE_TYPE_AUDIO, ACCESS_DENIED);
516 MediaStreamDevicesController mic_controller( 556 std::unique_ptr<MediaStreamDevicesController> mic_controller(
517 GetWebContents(), CreateRequest(example_audio_id(), std::string()), 557 CreateMediaStreamDevicesController(
518 base::Bind(&MediaStreamDevicesControllerTest::OnMediaStreamResponse, 558 GetWebContents(), CreateRequest(example_audio_id(), std::string()),
519 base::Unretained(this))); 559 base::Bind(&MediaStreamDevicesControllerTest::OnMediaStreamResponse,
520 NotifyTabSpecificContentSettings(&mic_controller); 560 base::Unretained(this))));
561 NotifyTabSpecificContentSettings(mic_controller.get());
521 EXPECT_FALSE(GetContentSettings()->IsContentAllowed( 562 EXPECT_FALSE(GetContentSettings()->IsContentAllowed(
522 CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC)); 563 CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC));
523 EXPECT_TRUE(GetContentSettings()->IsContentBlocked( 564 EXPECT_TRUE(GetContentSettings()->IsContentBlocked(
524 CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC)); 565 CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC));
525 EXPECT_EQ(example_audio_id(), 566 EXPECT_EQ(example_audio_id(),
526 GetContentSettings()->media_stream_requested_audio_device()); 567 GetContentSettings()->media_stream_requested_audio_device());
527 EXPECT_EQ(example_audio_id(), 568 EXPECT_EQ(example_audio_id(),
528 GetContentSettings()->media_stream_selected_audio_device()); 569 GetContentSettings()->media_stream_selected_audio_device());
529 570
530 // Cam should still be included in the state. 571 // Cam should still be included in the state.
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
606 647
607 {CONTENT_SETTING_ASK, CONTENT_SETTING_ALLOW, false}, 648 {CONTENT_SETTING_ASK, CONTENT_SETTING_ALLOW, false},
608 {CONTENT_SETTING_ASK, CONTENT_SETTING_ALLOW, true}, 649 {CONTENT_SETTING_ASK, CONTENT_SETTING_ALLOW, true},
609 650
610 {CONTENT_SETTING_ASK, CONTENT_SETTING_BLOCK, false}, 651 {CONTENT_SETTING_ASK, CONTENT_SETTING_BLOCK, false},
611 {CONTENT_SETTING_ASK, CONTENT_SETTING_BLOCK, true}, 652 {CONTENT_SETTING_ASK, CONTENT_SETTING_BLOCK, true},
612 }; 653 };
613 654
614 for (auto& test : tests) { 655 for (auto& test : tests) {
615 SetContentSettings(test.mic, test.cam); 656 SetContentSettings(test.mic, test.cam);
616 MediaStreamDevicesController controller( 657 std::unique_ptr<MediaStreamDevicesController> controller(
617 GetWebContents(), CreateRequest(example_audio_id(), example_video_id()), 658 CreateMediaStreamDevicesController(
618 base::Bind(&MediaStreamDevicesControllerTest::OnMediaStreamResponse, 659 GetWebContents(),
619 base::Unretained(this))); 660 CreateRequest(example_audio_id(), example_video_id()),
661 base::Bind(&MediaStreamDevicesControllerTest::OnMediaStreamResponse,
662 base::Unretained(this))));
620 663
621 // Check that the infobar is requesting the expected cam/mic values. 664 // Check that the infobar is requesting the expected cam/mic values.
622 ASSERT_EQ(test.ExpectMicInfobar(), controller.IsAskingForAudio()); 665 ASSERT_EQ(test.ExpectMicInfobar(), IsAskingForAudio(controller.get()));
623 ASSERT_EQ(test.ExpectCamInfobar(), controller.IsAskingForVideo()); 666 ASSERT_EQ(test.ExpectCamInfobar(), IsAskingForVideo(controller.get()));
624 667
625 // Accept or deny the infobar if it's showing. 668 // Accept or deny the infobar if it's showing.
626 if (test.ExpectMicInfobar() || test.ExpectCamInfobar()) { 669 if (test.ExpectMicInfobar() || test.ExpectCamInfobar()) {
627 if (test.accept_infobar) 670 if (test.accept_infobar)
628 controller.PermissionGranted(); 671 PermissionGranted(controller.get());
629 else 672 else
630 controller.PermissionDenied(); 673 PermissionDenied(controller.get());
631 } 674 }
632 675
633 // Check the media stream result is expected and the devices returned are 676 // Check the media stream result is expected and the devices returned are
634 // expected; 677 // expected;
635 ASSERT_EQ(test.ExpectedMediaStreamResult(), media_stream_result()); 678 ASSERT_EQ(test.ExpectedMediaStreamResult(), media_stream_result());
636 ASSERT_EQ(CheckDevicesListContains(content::MEDIA_DEVICE_AUDIO_CAPTURE), 679 ASSERT_EQ(CheckDevicesListContains(content::MEDIA_DEVICE_AUDIO_CAPTURE),
637 test.ExpectMicAllowed()); 680 test.ExpectMicAllowed());
638 ASSERT_EQ(CheckDevicesListContains(content::MEDIA_DEVICE_VIDEO_CAPTURE), 681 ASSERT_EQ(CheckDevicesListContains(content::MEDIA_DEVICE_VIDEO_CAPTURE),
639 test.ExpectCamAllowed()); 682 test.ExpectCamAllowed());
640 } 683 }
641 } 684 }
642 685
643 // Request and allow camera access on WebUI pages without prompting. 686 // Request and allow camera access on WebUI pages without prompting.
644 IN_PROC_BROWSER_TEST_F(MediaStreamDevicesControllerTest, 687 IN_PROC_BROWSER_TEST_F(MediaStreamDevicesControllerTest,
645 WebUIRequestAndAllowCam) { 688 WebUIRequestAndAllowCam) {
646 InitWithUrl(GURL("chrome://test-page")); 689 InitWithUrl(GURL("chrome://test-page"));
647 MediaStreamDevicesController controller( 690 std::unique_ptr<MediaStreamDevicesController> controller(
648 GetWebContents(), CreateRequest(std::string(), example_video_id()), 691 CreateMediaStreamDevicesController(
649 base::Bind(&MediaStreamDevicesControllerTest::OnMediaStreamResponse, 692 GetWebContents(), CreateRequest(std::string(), example_video_id()),
650 base::Unretained(this))); 693 base::Bind(&MediaStreamDevicesControllerTest::OnMediaStreamResponse,
694 base::Unretained(this))));
651 695
652 ASSERT_FALSE(controller.IsAskingForAudio()); 696 ASSERT_FALSE(IsAskingForAudio(controller.get()));
653 ASSERT_FALSE(controller.IsAskingForVideo()); 697 ASSERT_FALSE(IsAskingForVideo(controller.get()));
654 698
655 ASSERT_EQ(content::MEDIA_DEVICE_OK, media_stream_result()); 699 ASSERT_EQ(content::MEDIA_DEVICE_OK, media_stream_result());
656 ASSERT_FALSE(CheckDevicesListContains(content::MEDIA_DEVICE_AUDIO_CAPTURE)); 700 ASSERT_FALSE(CheckDevicesListContains(content::MEDIA_DEVICE_AUDIO_CAPTURE));
657 ASSERT_TRUE(CheckDevicesListContains(content::MEDIA_DEVICE_VIDEO_CAPTURE)); 701 ASSERT_TRUE(CheckDevicesListContains(content::MEDIA_DEVICE_VIDEO_CAPTURE));
658 } 702 }
659 703
660 IN_PROC_BROWSER_TEST_F(MediaStreamDevicesControllerTest, 704 IN_PROC_BROWSER_TEST_F(MediaStreamDevicesControllerTest,
661 ExtensionRequestMicCam) { 705 ExtensionRequestMicCam) {
662 InitWithUrl(GURL("chrome-extension://test-page")); 706 InitWithUrl(GURL("chrome-extension://test-page"));
663 // Test that a prompt is required. 707 // Test that a prompt is required.
664 MediaStreamDevicesController controller( 708 std::unique_ptr<MediaStreamDevicesController> controller(
665 GetWebContents(), CreateRequest(example_audio_id(), example_video_id()), 709 CreateMediaStreamDevicesController(
666 base::Bind(&MediaStreamDevicesControllerTest::OnMediaStreamResponse, 710 GetWebContents(),
667 base::Unretained(this))); 711 CreateRequest(example_audio_id(), example_video_id()),
668 ASSERT_TRUE(controller.IsAskingForAudio()); 712 base::Bind(&MediaStreamDevicesControllerTest::OnMediaStreamResponse,
669 ASSERT_TRUE(controller.IsAskingForVideo()); 713 base::Unretained(this))));
714 ASSERT_TRUE(IsAskingForAudio(controller.get()));
715 ASSERT_TRUE(IsAskingForVideo(controller.get()));
670 716
671 // Accept the prompt. 717 // Accept the prompt.
672 controller.PermissionGranted(); 718 PermissionGranted(controller.get());
673 ASSERT_EQ(content::MEDIA_DEVICE_OK, media_stream_result()); 719 ASSERT_EQ(content::MEDIA_DEVICE_OK, media_stream_result());
674 ASSERT_TRUE(CheckDevicesListContains(content::MEDIA_DEVICE_AUDIO_CAPTURE)); 720 ASSERT_TRUE(CheckDevicesListContains(content::MEDIA_DEVICE_AUDIO_CAPTURE));
675 ASSERT_TRUE(CheckDevicesListContains(content::MEDIA_DEVICE_VIDEO_CAPTURE)); 721 ASSERT_TRUE(CheckDevicesListContains(content::MEDIA_DEVICE_VIDEO_CAPTURE));
676 722
677 // Check that re-requesting allows without prompting. 723 // Check that re-requesting allows without prompting.
678 MediaStreamDevicesController controller2( 724 std::unique_ptr<MediaStreamDevicesController> controller2(
679 GetWebContents(), CreateRequest(example_audio_id(), example_video_id()), 725 CreateMediaStreamDevicesController(
680 base::Bind(&MediaStreamDevicesControllerTest::OnMediaStreamResponse, 726 GetWebContents(),
681 base::Unretained(this))); 727 CreateRequest(example_audio_id(), example_video_id()),
682 ASSERT_FALSE(controller2.IsAskingForAudio()); 728 base::Bind(&MediaStreamDevicesControllerTest::OnMediaStreamResponse,
683 ASSERT_FALSE(controller2.IsAskingForVideo()); 729 base::Unretained(this))));
730 ASSERT_FALSE(IsAskingForAudio(controller2.get()));
731 ASSERT_FALSE(IsAskingForVideo(controller2.get()));
684 732
685 ASSERT_EQ(content::MEDIA_DEVICE_OK, media_stream_result()); 733 ASSERT_EQ(content::MEDIA_DEVICE_OK, media_stream_result());
686 ASSERT_TRUE(CheckDevicesListContains(content::MEDIA_DEVICE_AUDIO_CAPTURE)); 734 ASSERT_TRUE(CheckDevicesListContains(content::MEDIA_DEVICE_AUDIO_CAPTURE));
687 ASSERT_TRUE(CheckDevicesListContains(content::MEDIA_DEVICE_VIDEO_CAPTURE)); 735 ASSERT_TRUE(CheckDevicesListContains(content::MEDIA_DEVICE_VIDEO_CAPTURE));
688 } 736 }
689 737
690 // For Pepper request from insecure origin, even if it's ALLOW, it won't be 738 // For Pepper request from insecure origin, even if it's ALLOW, it won't be
691 // changed to ASK. 739 // changed to ASK.
692 IN_PROC_BROWSER_TEST_F(MediaStreamDevicesControllerTest, 740 IN_PROC_BROWSER_TEST_F(MediaStreamDevicesControllerTest,
693 PepperRequestInsecure) { 741 PepperRequestInsecure) {
694 InitWithUrl(GURL("http://www.example.com")); 742 InitWithUrl(GURL("http://www.example.com"));
695 SetContentSettings(CONTENT_SETTING_ALLOW, CONTENT_SETTING_ALLOW); 743 SetContentSettings(CONTENT_SETTING_ALLOW, CONTENT_SETTING_ALLOW);
696 744
697 MediaStreamDevicesController controller( 745 std::unique_ptr<MediaStreamDevicesController> controller(
698 GetWebContents(), 746 CreateMediaStreamDevicesController(
699 CreateRequestWithType(example_audio_id(), std::string(), 747 GetWebContents(),
700 content::MEDIA_OPEN_DEVICE_PEPPER_ONLY), 748 CreateRequestWithType(example_audio_id(), std::string(),
701 base::Bind(&MediaStreamDevicesControllerTest::OnMediaStreamResponse, 749 content::MEDIA_OPEN_DEVICE_PEPPER_ONLY),
702 base::Unretained(this))); 750 base::Bind(&MediaStreamDevicesControllerTest::OnMediaStreamResponse,
703 ASSERT_FALSE(controller.IsAskingForAudio()); 751 base::Unretained(this))));
704 ASSERT_FALSE(controller.IsAskingForVideo()); 752 ASSERT_FALSE(IsAskingForAudio(controller.get()));
753 ASSERT_FALSE(IsAskingForVideo(controller.get()));
705 } 754 }
706 755
707 // Request and block microphone and camera access with kill switch. 756 // Request and block microphone and camera access with kill switch.
708 IN_PROC_BROWSER_TEST_F(MediaStreamDevicesControllerTest, 757 IN_PROC_BROWSER_TEST_F(MediaStreamDevicesControllerTest,
709 RequestAndKillSwitchMicCam) { 758 RequestAndKillSwitchMicCam) {
710 std::map<std::string, std::string> params; 759 std::map<std::string, std::string> params;
711 params[PermissionUtil::GetPermissionString( 760 params[PermissionUtil::GetPermissionString(
712 CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC)] = 761 CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC)] =
713 PermissionContextBase::kPermissionsKillSwitchBlockedValue; 762 PermissionContextBase::kPermissionsKillSwitchBlockedValue;
714 params[PermissionUtil::GetPermissionString( 763 params[PermissionUtil::GetPermissionString(
715 CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA)] = 764 CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA)] =
716 PermissionContextBase::kPermissionsKillSwitchBlockedValue; 765 PermissionContextBase::kPermissionsKillSwitchBlockedValue;
717 variations::AssociateVariationParams( 766 variations::AssociateVariationParams(
718 PermissionContextBase::kPermissionsKillSwitchFieldStudy, 767 PermissionContextBase::kPermissionsKillSwitchFieldStudy,
719 "TestGroup", params); 768 "TestGroup", params);
720 base::FieldTrialList::CreateFieldTrial( 769 base::FieldTrialList::CreateFieldTrial(
721 PermissionContextBase::kPermissionsKillSwitchFieldStudy, 770 PermissionContextBase::kPermissionsKillSwitchFieldStudy,
722 "TestGroup"); 771 "TestGroup");
723 InitWithUrl(GURL("https://www.example.com")); 772 InitWithUrl(GURL("https://www.example.com"));
724 SetDevicePolicy(DEVICE_TYPE_AUDIO, ACCESS_ALLOWED); 773 SetDevicePolicy(DEVICE_TYPE_AUDIO, ACCESS_ALLOWED);
725 SetDevicePolicy(DEVICE_TYPE_VIDEO, ACCESS_ALLOWED); 774 SetDevicePolicy(DEVICE_TYPE_VIDEO, ACCESS_ALLOWED);
726 MediaStreamDevicesController controller( 775 std::unique_ptr<MediaStreamDevicesController> controller(
727 GetWebContents(), CreateRequest(example_audio_id(), example_video_id()), 776 CreateMediaStreamDevicesController(
728 base::Bind(&MediaStreamDevicesControllerTest::OnMediaStreamResponse, 777 GetWebContents(),
729 base::Unretained(this))); 778 CreateRequest(example_audio_id(), example_video_id()),
779 base::Bind(&MediaStreamDevicesControllerTest::OnMediaStreamResponse,
780 base::Unretained(this))));
730 781
731 EXPECT_FALSE(controller.IsAllowedForAudio()); 782 EXPECT_FALSE(IsAskingForAudio(controller.get()));
732 EXPECT_FALSE(controller.IsAllowedForVideo()); 783 EXPECT_FALSE(IsAskingForVideo(controller.get()));
733 EXPECT_FALSE(controller.IsAskingForAudio()); 784
734 EXPECT_FALSE(controller.IsAskingForVideo()); 785 ASSERT_EQ(content::MEDIA_DEVICE_KILL_SWITCH_ON, media_stream_result());
786 ASSERT_FALSE(CheckDevicesListContains(content::MEDIA_DEVICE_AUDIO_CAPTURE));
787 ASSERT_FALSE(CheckDevicesListContains(content::MEDIA_DEVICE_VIDEO_CAPTURE));
735 } 788 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698