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

Side by Side Diff: chrome/browser/ui/content_settings/content_setting_bubble_model_unittest.cc

Issue 678023002: TabSpecificContentSettings no longer knows about MediaStreamDeviceController (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Remaining style nits addressed Created 6 years, 1 month 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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/auto_reset.h" 5 #include "base/auto_reset.h"
6 #include "base/command_line.h" 6 #include "base/command_line.h"
7 #include "base/prefs/pref_service.h"
7 #include "base/strings/utf_string_conversions.h" 8 #include "base/strings/utf_string_conversions.h"
8 #include "chrome/browser/content_settings/tab_specific_content_settings.h" 9 #include "chrome/browser/content_settings/tab_specific_content_settings.h"
9 #include "chrome/browser/custom_handlers/protocol_handler_registry.h" 10 #include "chrome/browser/custom_handlers/protocol_handler_registry.h"
10 #include "chrome/browser/infobars/infobar_service.h" 11 #include "chrome/browser/infobars/infobar_service.h"
11 #include "chrome/browser/media/media_capture_devices_dispatcher.h" 12 #include "chrome/browser/media/media_capture_devices_dispatcher.h"
12 #include "chrome/browser/media/media_stream_capture_indicator.h" 13 #include "chrome/browser/media/media_stream_capture_indicator.h"
13 #include "chrome/browser/profiles/profile.h" 14 #include "chrome/browser/profiles/profile.h"
14 #include "chrome/browser/ui/content_settings/content_setting_bubble_model.h" 15 #include "chrome/browser/ui/content_settings/content_setting_bubble_model.h"
15 #include "chrome/common/chrome_switches.h" 16 #include "chrome/common/chrome_switches.h"
17 #include "chrome/common/pref_names.h"
16 #include "chrome/grit/generated_resources.h" 18 #include "chrome/grit/generated_resources.h"
17 #include "chrome/test/base/chrome_render_view_host_test_harness.h" 19 #include "chrome/test/base/chrome_render_view_host_test_harness.h"
18 #include "chrome/test/base/testing_profile.h" 20 #include "chrome/test/base/testing_profile.h"
19 #include "components/content_settings/core/browser/host_content_settings_map.h" 21 #include "components/content_settings/core/browser/host_content_settings_map.h"
20 #include "components/content_settings/core/common/content_settings.h" 22 #include "components/content_settings/core/common/content_settings.h"
21 #include "components/infobars/core/infobar_delegate.h" 23 #include "components/infobars/core/infobar_delegate.h"
22 #include "content/public/browser/web_contents.h" 24 #include "content/public/browser/web_contents.h"
23 #include "content/public/test/web_contents_tester.h" 25 #include "content/public/test/web_contents_tester.h"
24 #include "testing/gtest/include/gtest/gtest.h" 26 #include "testing/gtest/include/gtest/gtest.h"
25 #include "ui/base/l10n/l10n_util.h" 27 #include "ui/base/l10n/l10n_util.h"
(...skipping 19 matching lines...) Expand all
45 content_setting_bubble_model->bubble_content(); 47 content_setting_bubble_model->bubble_content();
46 EXPECT_TRUE(bubble_content.title.empty()); 48 EXPECT_TRUE(bubble_content.title.empty());
47 EXPECT_TRUE(bubble_content.radio_group.radio_items.empty()); 49 EXPECT_TRUE(bubble_content.radio_group.radio_items.empty());
48 EXPECT_TRUE(bubble_content.popup_items.empty()); 50 EXPECT_TRUE(bubble_content.popup_items.empty());
49 EXPECT_EQ(expected_domains, bubble_content.domain_lists.size()); 51 EXPECT_EQ(expected_domains, bubble_content.domain_lists.size());
50 EXPECT_NE(expect_clear_link || expect_reload_hint, 52 EXPECT_NE(expect_clear_link || expect_reload_hint,
51 bubble_content.custom_link.empty()); 53 bubble_content.custom_link.empty());
52 EXPECT_EQ(expect_clear_link, bubble_content.custom_link_enabled); 54 EXPECT_EQ(expect_clear_link, bubble_content.custom_link_enabled);
53 EXPECT_FALSE(bubble_content.manage_link.empty()); 55 EXPECT_FALSE(bubble_content.manage_link.empty());
54 } 56 }
57
58 std::string GetDefaultAudioDevice() {
59 PrefService* prefs = profile()->GetPrefs();
60 return prefs->GetString(prefs::kDefaultAudioCaptureDevice);
61 }
62
63 std::string GetDefaultVideoDevice() {
64 PrefService* prefs = profile()->GetPrefs();
65 return prefs->GetString(prefs::kDefaultVideoCaptureDevice);
66 }
55 }; 67 };
56 68
57 TEST_F(ContentSettingBubbleModelTest, ImageRadios) { 69 TEST_F(ContentSettingBubbleModelTest, ImageRadios) {
58 TabSpecificContentSettings* content_settings = 70 TabSpecificContentSettings* content_settings =
59 TabSpecificContentSettings::FromWebContents(web_contents()); 71 TabSpecificContentSettings::FromWebContents(web_contents());
60 content_settings->OnContentBlocked(CONTENT_SETTINGS_TYPE_IMAGES); 72 content_settings->OnContentBlocked(CONTENT_SETTINGS_TYPE_IMAGES);
61 73
62 scoped_ptr<ContentSettingBubbleModel> content_setting_bubble_model( 74 scoped_ptr<ContentSettingBubbleModel> content_setting_bubble_model(
63 ContentSettingBubbleModel::CreateContentSettingBubbleModel( 75 ContentSettingBubbleModel::CreateContentSettingBubbleModel(
64 NULL, web_contents(), profile(), 76 NULL, web_contents(), profile(),
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
112 124
113 TEST_F(ContentSettingBubbleModelTest, MediastreamMicAndCamera) { 125 TEST_F(ContentSettingBubbleModelTest, MediastreamMicAndCamera) {
114 // Required to break dependency on BrowserMainLoop. 126 // Required to break dependency on BrowserMainLoop.
115 MediaCaptureDevicesDispatcher::GetInstance()-> 127 MediaCaptureDevicesDispatcher::GetInstance()->
116 DisableDeviceEnumerationForTesting(); 128 DisableDeviceEnumerationForTesting();
117 129
118 TabSpecificContentSettings* content_settings = 130 TabSpecificContentSettings* content_settings =
119 TabSpecificContentSettings::FromWebContents(web_contents()); 131 TabSpecificContentSettings::FromWebContents(web_contents());
120 std::string request_host = "google.com"; 132 std::string request_host = "google.com";
121 GURL security_origin("http://" + request_host); 133 GURL security_origin("http://" + request_host);
122 MediaStreamDevicesController::MediaStreamTypeSettingsMap 134 TabSpecificContentSettings::MicrophoneCameraState microphone_camera_state =
123 request_permissions; 135 TabSpecificContentSettings::MICROPHONE_ACCESSED |
124 request_permissions[content::MEDIA_DEVICE_AUDIO_CAPTURE].permission = 136 TabSpecificContentSettings::CAMERA_ACCESSED;
125 MediaStreamDevicesController::MEDIA_ALLOWED;
126 request_permissions[content::MEDIA_DEVICE_VIDEO_CAPTURE].permission =
127 MediaStreamDevicesController::MEDIA_ALLOWED;
128 content_settings->OnMediaStreamPermissionSet(security_origin, 137 content_settings->OnMediaStreamPermissionSet(security_origin,
129 request_permissions); 138 microphone_camera_state,
139 GetDefaultAudioDevice(),
140 GetDefaultVideoDevice(),
141 std::string(),
142 std::string());
130 143
131 scoped_ptr<ContentSettingBubbleModel> content_setting_bubble_model( 144 scoped_ptr<ContentSettingBubbleModel> content_setting_bubble_model(
132 ContentSettingBubbleModel::CreateContentSettingBubbleModel( 145 ContentSettingBubbleModel::CreateContentSettingBubbleModel(
133 NULL, web_contents(), profile(), 146 NULL, web_contents(), profile(),
134 CONTENT_SETTINGS_TYPE_MEDIASTREAM)); 147 CONTENT_SETTINGS_TYPE_MEDIASTREAM));
135 const ContentSettingBubbleModel::BubbleContent& bubble_content = 148 const ContentSettingBubbleModel::BubbleContent& bubble_content =
136 content_setting_bubble_model->bubble_content(); 149 content_setting_bubble_model->bubble_content();
137 EXPECT_EQ(bubble_content.title, 150 EXPECT_EQ(bubble_content.title,
138 l10n_util::GetStringUTF8(IDS_MICROPHONE_CAMERA_ALLOWED)); 151 l10n_util::GetStringUTF8(IDS_MICROPHONE_CAMERA_ALLOWED));
139 EXPECT_EQ(2U, bubble_content.radio_group.radio_items.size()); 152 EXPECT_EQ(2U, bubble_content.radio_group.radio_items.size());
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
173 setting); 186 setting);
174 host_content_settings_map->SetContentSetting( 187 host_content_settings_map->SetContentSetting(
175 primary_pattern, 188 primary_pattern,
176 ContentSettingsPattern::Wildcard(), 189 ContentSettingsPattern::Wildcard(),
177 CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA, 190 CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA,
178 std::string(), 191 std::string(),
179 setting); 192 setting);
180 193
181 TabSpecificContentSettings* content_settings = 194 TabSpecificContentSettings* content_settings =
182 TabSpecificContentSettings::FromWebContents(web_contents()); 195 TabSpecificContentSettings::FromWebContents(web_contents());
183 MediaStreamDevicesController::MediaStreamTypeSettingsMap 196 TabSpecificContentSettings::MicrophoneCameraState microphone_camera_state =
184 request_permissions; 197 TabSpecificContentSettings::MICROPHONE_ACCESSED |
185 request_permissions[content::MEDIA_DEVICE_AUDIO_CAPTURE].permission = 198 TabSpecificContentSettings::MICROPHONE_BLOCKED |
186 MediaStreamDevicesController::MEDIA_BLOCKED_BY_USER; 199 TabSpecificContentSettings::CAMERA_ACCESSED |
187 request_permissions[content::MEDIA_DEVICE_VIDEO_CAPTURE].permission = 200 TabSpecificContentSettings::CAMERA_BLOCKED;
188 MediaStreamDevicesController::MEDIA_BLOCKED_BY_USER; 201 content_settings->OnMediaStreamPermissionSet(url,
189 content_settings->OnMediaStreamPermissionSet(url, request_permissions); 202 microphone_camera_state,
203 GetDefaultAudioDevice(),
204 GetDefaultVideoDevice(),
205 std::string(),
206 std::string());
190 { 207 {
191 scoped_ptr<ContentSettingBubbleModel> content_setting_bubble_model( 208 scoped_ptr<ContentSettingBubbleModel> content_setting_bubble_model(
192 ContentSettingBubbleModel::CreateContentSettingBubbleModel( 209 ContentSettingBubbleModel::CreateContentSettingBubbleModel(
193 NULL, web_contents(), profile(), 210 NULL, web_contents(), profile(),
194 CONTENT_SETTINGS_TYPE_MEDIASTREAM)); 211 CONTENT_SETTINGS_TYPE_MEDIASTREAM));
195 const ContentSettingBubbleModel::BubbleContent& bubble_content = 212 const ContentSettingBubbleModel::BubbleContent& bubble_content =
196 content_setting_bubble_model->bubble_content(); 213 content_setting_bubble_model->bubble_content();
197 // Test if the correct radio item is selected for the blocked mediastream 214 // Test if the correct radio item is selected for the blocked mediastream
198 // setting. 215 // setting.
199 EXPECT_EQ(1, bubble_content.radio_group.default_item); 216 EXPECT_EQ(1, bubble_content.radio_group.default_item);
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
254 ContentSetting setting = CONTENT_SETTING_BLOCK; 271 ContentSetting setting = CONTENT_SETTING_BLOCK;
255 host_content_settings_map->SetContentSetting( 272 host_content_settings_map->SetContentSetting(
256 primary_pattern, 273 primary_pattern,
257 ContentSettingsPattern::Wildcard(), 274 ContentSettingsPattern::Wildcard(),
258 CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC, 275 CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC,
259 std::string(), 276 std::string(),
260 setting); 277 setting);
261 278
262 TabSpecificContentSettings* content_settings = 279 TabSpecificContentSettings* content_settings =
263 TabSpecificContentSettings::FromWebContents(web_contents()); 280 TabSpecificContentSettings::FromWebContents(web_contents());
264 MediaStreamDevicesController::MediaStreamTypeSettingsMap 281 TabSpecificContentSettings::MicrophoneCameraState microphone_camera_state =
265 request_permissions; 282 TabSpecificContentSettings::MICROPHONE_ACCESSED |
266 request_permissions[content::MEDIA_DEVICE_AUDIO_CAPTURE].permission = 283 TabSpecificContentSettings::MICROPHONE_BLOCKED;
267 MediaStreamDevicesController::MEDIA_BLOCKED_BY_USER; 284 content_settings->OnMediaStreamPermissionSet(url,
268 content_settings->OnMediaStreamPermissionSet(url, request_permissions); 285 microphone_camera_state,
286 GetDefaultAudioDevice(),
287 std::string(),
288 std::string(),
289 std::string());
269 { 290 {
270 scoped_ptr<ContentSettingBubbleModel> content_setting_bubble_model( 291 scoped_ptr<ContentSettingBubbleModel> content_setting_bubble_model(
271 ContentSettingBubbleModel::CreateContentSettingBubbleModel( 292 ContentSettingBubbleModel::CreateContentSettingBubbleModel(
272 NULL, web_contents(), profile(), 293 NULL, web_contents(), profile(),
273 CONTENT_SETTINGS_TYPE_MEDIASTREAM)); 294 CONTENT_SETTINGS_TYPE_MEDIASTREAM));
274 const ContentSettingBubbleModel::BubbleContent& bubble_content = 295 const ContentSettingBubbleModel::BubbleContent& bubble_content =
275 content_setting_bubble_model->bubble_content(); 296 content_setting_bubble_model->bubble_content();
276 // Test if the correct radio item is selected for the blocked mediastream 297 // Test if the correct radio item is selected for the blocked mediastream
277 // setting. 298 // setting.
278 EXPECT_EQ(1, bubble_content.radio_group.default_item); 299 EXPECT_EQ(1, bubble_content.radio_group.default_item);
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
344 content::MediaStreamDevice fake_audio_device3( 365 content::MediaStreamDevice fake_audio_device3(
345 content::MEDIA_DEVICE_AUDIO_CAPTURE, "fake_dev3", "Fake Audio Device 3"); 366 content::MEDIA_DEVICE_AUDIO_CAPTURE, "fake_dev3", "Fake Audio Device 3");
346 audio_devices.push_back(fake_audio_device1); 367 audio_devices.push_back(fake_audio_device1);
347 audio_devices.push_back(fake_audio_device2); 368 audio_devices.push_back(fake_audio_device2);
348 audio_devices.push_back(fake_audio_device3); 369 audio_devices.push_back(fake_audio_device3);
349 MediaCaptureDevicesDispatcher::GetInstance()->SetTestAudioCaptureDevices( 370 MediaCaptureDevicesDispatcher::GetInstance()->SetTestAudioCaptureDevices(
350 audio_devices); 371 audio_devices);
351 372
352 TabSpecificContentSettings* content_settings = 373 TabSpecificContentSettings* content_settings =
353 TabSpecificContentSettings::FromWebContents(web_contents()); 374 TabSpecificContentSettings::FromWebContents(web_contents());
354 MediaStreamDevicesController::MediaStreamTypeSettingsMap 375 TabSpecificContentSettings::MicrophoneCameraState microphone_camera_state =
355 request_permissions; 376 TabSpecificContentSettings::MICROPHONE_ACCESSED |
356 request_permissions[content::MEDIA_DEVICE_AUDIO_CAPTURE].permission = 377 TabSpecificContentSettings::MICROPHONE_BLOCKED;
357 MediaStreamDevicesController::MEDIA_BLOCKED_BY_USER; 378 content_settings->OnMediaStreamPermissionSet(url,
358 content_settings->OnMediaStreamPermissionSet(url, request_permissions); 379 microphone_camera_state,
380 GetDefaultAudioDevice(),
381 std::string(),
382 std::string(),
383 std::string());
359 { 384 {
360 scoped_ptr<ContentSettingBubbleModel> content_setting_bubble_model( 385 scoped_ptr<ContentSettingBubbleModel> content_setting_bubble_model(
361 ContentSettingBubbleModel::CreateContentSettingBubbleModel( 386 ContentSettingBubbleModel::CreateContentSettingBubbleModel(
362 NULL, web_contents(), profile(), 387 NULL, web_contents(), profile(),
363 CONTENT_SETTINGS_TYPE_MEDIASTREAM)); 388 CONTENT_SETTINGS_TYPE_MEDIASTREAM));
364 const ContentSettingBubbleModel::BubbleContent& bubble_content = 389 const ContentSettingBubbleModel::BubbleContent& bubble_content =
365 content_setting_bubble_model->bubble_content(); 390 content_setting_bubble_model->bubble_content();
366 EXPECT_TRUE(bubble_content.custom_link.empty()); 391 EXPECT_TRUE(bubble_content.custom_link.empty());
367 392
368 EXPECT_EQ(1U, bubble_content.media_menus.size()); 393 EXPECT_EQ(1U, bubble_content.media_menus.size());
(...skipping 29 matching lines...) Expand all
398 EXPECT_TRUE(bubble_content.custom_link.empty()); 423 EXPECT_TRUE(bubble_content.custom_link.empty());
399 } 424 }
400 425
401 // Simulate that an audio stream is being captured. 426 // Simulate that an audio stream is being captured.
402 scoped_refptr<MediaStreamCaptureIndicator> indicator = 427 scoped_refptr<MediaStreamCaptureIndicator> indicator =
403 MediaCaptureDevicesDispatcher::GetInstance()-> 428 MediaCaptureDevicesDispatcher::GetInstance()->
404 GetMediaStreamCaptureIndicator(); 429 GetMediaStreamCaptureIndicator();
405 scoped_ptr<content::MediaStreamUI> media_stream_ui = 430 scoped_ptr<content::MediaStreamUI> media_stream_ui =
406 indicator->RegisterMediaStream(web_contents(), audio_devices); 431 indicator->RegisterMediaStream(web_contents(), audio_devices);
407 media_stream_ui->OnStarted(base::Closure()); 432 media_stream_ui->OnStarted(base::Closure());
408 request_permissions[content::MEDIA_DEVICE_AUDIO_CAPTURE].permission = 433 microphone_camera_state &= ~TabSpecificContentSettings::MICROPHONE_BLOCKED;
409 MediaStreamDevicesController::MEDIA_ALLOWED; 434 content_settings->OnMediaStreamPermissionSet(url,
410 content_settings->OnMediaStreamPermissionSet(url, request_permissions); 435 microphone_camera_state,
436 GetDefaultAudioDevice(),
437 std::string(),
438 std::string(),
439 std::string());
411 440
412 { 441 {
413 scoped_ptr<ContentSettingBubbleModel> content_setting_bubble_model( 442 scoped_ptr<ContentSettingBubbleModel> content_setting_bubble_model(
414 ContentSettingBubbleModel::CreateContentSettingBubbleModel( 443 ContentSettingBubbleModel::CreateContentSettingBubbleModel(
415 NULL, web_contents(), profile(), 444 NULL, web_contents(), profile(),
416 CONTENT_SETTINGS_TYPE_MEDIASTREAM)); 445 CONTENT_SETTINGS_TYPE_MEDIASTREAM));
417 const ContentSettingBubbleModel::BubbleContent& bubble_content = 446 const ContentSettingBubbleModel::BubbleContent& bubble_content =
418 content_setting_bubble_model->bubble_content(); 447 content_setting_bubble_model->bubble_content();
419 // Settings not changed yet, so the "settings changed" message should not be 448 // Settings not changed yet, so the "settings changed" message should not be
420 // shown. 449 // shown.
(...skipping 19 matching lines...) Expand all
440 CONTENT_SETTINGS_TYPE_MEDIASTREAM)); 469 CONTENT_SETTINGS_TYPE_MEDIASTREAM));
441 const ContentSettingBubbleModel::BubbleContent& bubble_content = 470 const ContentSettingBubbleModel::BubbleContent& bubble_content =
442 content_setting_bubble_model->bubble_content(); 471 content_setting_bubble_model->bubble_content();
443 // Test that the reload hint is displayed. 472 // Test that the reload hint is displayed.
444 EXPECT_FALSE(bubble_content.custom_link_enabled); 473 EXPECT_FALSE(bubble_content.custom_link_enabled);
445 EXPECT_EQ(bubble_content.custom_link, l10n_util::GetStringUTF8( 474 EXPECT_EQ(bubble_content.custom_link, l10n_util::GetStringUTF8(
446 IDS_MEDIASTREAM_SETTING_CHANGED_MESSAGE)); 475 IDS_MEDIASTREAM_SETTING_CHANGED_MESSAGE));
447 } 476 }
448 477
449 // Simulate that yet another audio stream capture request was initiated. 478 // Simulate that yet another audio stream capture request was initiated.
450 request_permissions[content::MEDIA_DEVICE_AUDIO_CAPTURE].permission = 479 microphone_camera_state |= TabSpecificContentSettings::MICROPHONE_BLOCKED;
451 MediaStreamDevicesController::MEDIA_BLOCKED_BY_USER; 480 content_settings->OnMediaStreamPermissionSet(url,
452 content_settings->OnMediaStreamPermissionSet(url, request_permissions); 481 microphone_camera_state,
482 GetDefaultAudioDevice(),
483 std::string(),
484 std::string(),
485 std::string());
453 486
454 { 487 {
455 scoped_ptr<ContentSettingBubbleModel> content_setting_bubble_model( 488 scoped_ptr<ContentSettingBubbleModel> content_setting_bubble_model(
456 ContentSettingBubbleModel::CreateContentSettingBubbleModel( 489 ContentSettingBubbleModel::CreateContentSettingBubbleModel(
457 NULL, web_contents(), profile(), 490 NULL, web_contents(), profile(),
458 CONTENT_SETTINGS_TYPE_MEDIASTREAM)); 491 CONTENT_SETTINGS_TYPE_MEDIASTREAM));
459 const ContentSettingBubbleModel::BubbleContent& bubble_content = 492 const ContentSettingBubbleModel::BubbleContent& bubble_content =
460 content_setting_bubble_model->bubble_content(); 493 content_setting_bubble_model->bubble_content();
461 // Test that the reload hint is not displayed any more, because this is a 494 // Test that the reload hint is not displayed any more, because this is a
462 // new permission request. 495 // new permission request.
(...skipping 12 matching lines...) Expand all
475 508
476 TEST_F(ContentSettingBubbleModelTest, MediastreamMic) { 509 TEST_F(ContentSettingBubbleModelTest, MediastreamMic) {
477 // Required to break dependency on BrowserMainLoop. 510 // Required to break dependency on BrowserMainLoop.
478 MediaCaptureDevicesDispatcher::GetInstance()-> 511 MediaCaptureDevicesDispatcher::GetInstance()->
479 DisableDeviceEnumerationForTesting(); 512 DisableDeviceEnumerationForTesting();
480 513
481 TabSpecificContentSettings* content_settings = 514 TabSpecificContentSettings* content_settings =
482 TabSpecificContentSettings::FromWebContents(web_contents()); 515 TabSpecificContentSettings::FromWebContents(web_contents());
483 std::string request_host = "google.com"; 516 std::string request_host = "google.com";
484 GURL security_origin("http://" + request_host); 517 GURL security_origin("http://" + request_host);
485 MediaStreamDevicesController::MediaStreamTypeSettingsMap 518 TabSpecificContentSettings::MicrophoneCameraState microphone_camera_state =
486 request_permissions; 519 TabSpecificContentSettings::MICROPHONE_ACCESSED;
487 request_permissions[content::MEDIA_DEVICE_AUDIO_CAPTURE].permission =
488 MediaStreamDevicesController::MEDIA_ALLOWED;
489 content_settings->OnMediaStreamPermissionSet(security_origin, 520 content_settings->OnMediaStreamPermissionSet(security_origin,
490 request_permissions); 521 microphone_camera_state,
522 GetDefaultAudioDevice(),
523 std::string(),
524 std::string(),
525 std::string());
491 526
492 scoped_ptr<ContentSettingBubbleModel> content_setting_bubble_model( 527 scoped_ptr<ContentSettingBubbleModel> content_setting_bubble_model(
493 ContentSettingBubbleModel::CreateContentSettingBubbleModel( 528 ContentSettingBubbleModel::CreateContentSettingBubbleModel(
494 NULL, web_contents(), profile(), 529 NULL, web_contents(), profile(),
495 CONTENT_SETTINGS_TYPE_MEDIASTREAM)); 530 CONTENT_SETTINGS_TYPE_MEDIASTREAM));
496 const ContentSettingBubbleModel::BubbleContent& bubble_content = 531 const ContentSettingBubbleModel::BubbleContent& bubble_content =
497 content_setting_bubble_model->bubble_content(); 532 content_setting_bubble_model->bubble_content();
498 EXPECT_EQ(bubble_content.title, 533 EXPECT_EQ(bubble_content.title,
499 l10n_util::GetStringUTF8(IDS_MICROPHONE_ACCESSED)); 534 l10n_util::GetStringUTF8(IDS_MICROPHONE_ACCESSED));
500 EXPECT_EQ(2U, bubble_content.radio_group.radio_items.size()); 535 EXPECT_EQ(2U, bubble_content.radio_group.radio_items.size());
501 EXPECT_EQ(bubble_content.radio_group.radio_items[0], 536 EXPECT_EQ(bubble_content.radio_group.radio_items[0],
502 l10n_util::GetStringFUTF8( 537 l10n_util::GetStringFUTF8(
503 IDS_ALLOWED_MEDIASTREAM_MIC_NO_ACTION, 538 IDS_ALLOWED_MEDIASTREAM_MIC_NO_ACTION,
504 base::UTF8ToUTF16(request_host))); 539 base::UTF8ToUTF16(request_host)));
505 EXPECT_EQ(bubble_content.radio_group.radio_items[1], 540 EXPECT_EQ(bubble_content.radio_group.radio_items[1],
506 l10n_util::GetStringUTF8( 541 l10n_util::GetStringUTF8(
507 IDS_ALLOWED_MEDIASTREAM_MIC_BLOCK)); 542 IDS_ALLOWED_MEDIASTREAM_MIC_BLOCK));
508 EXPECT_EQ(0, bubble_content.radio_group.default_item); 543 EXPECT_EQ(0, bubble_content.radio_group.default_item);
509 EXPECT_TRUE(bubble_content.custom_link.empty()); 544 EXPECT_TRUE(bubble_content.custom_link.empty());
510 EXPECT_FALSE(bubble_content.custom_link_enabled); 545 EXPECT_FALSE(bubble_content.custom_link_enabled);
511 EXPECT_FALSE(bubble_content.manage_link.empty()); 546 EXPECT_FALSE(bubble_content.manage_link.empty());
512 EXPECT_EQ(1U, bubble_content.media_menus.size()); 547 EXPECT_EQ(1U, bubble_content.media_menus.size());
513 EXPECT_EQ(content::MEDIA_DEVICE_AUDIO_CAPTURE, 548 EXPECT_EQ(content::MEDIA_DEVICE_AUDIO_CAPTURE,
514 bubble_content.media_menus.begin()->first); 549 bubble_content.media_menus.begin()->first);
515 550
516 // Change the microphone access. 551 // Change the microphone access.
517 request_permissions[content::MEDIA_DEVICE_AUDIO_CAPTURE].permission = 552 microphone_camera_state |= TabSpecificContentSettings::MICROPHONE_BLOCKED;
518 MediaStreamDevicesController::MEDIA_BLOCKED_BY_USER;
519 content_settings->OnMediaStreamPermissionSet(security_origin, 553 content_settings->OnMediaStreamPermissionSet(security_origin,
520 request_permissions); 554 microphone_camera_state,
555 GetDefaultAudioDevice(),
556 std::string(),
557 std::string(),
558 std::string());
521 content_setting_bubble_model.reset( 559 content_setting_bubble_model.reset(
522 ContentSettingBubbleModel::CreateContentSettingBubbleModel( 560 ContentSettingBubbleModel::CreateContentSettingBubbleModel(
523 NULL, web_contents(), profile(), 561 NULL, web_contents(), profile(),
524 CONTENT_SETTINGS_TYPE_MEDIASTREAM)); 562 CONTENT_SETTINGS_TYPE_MEDIASTREAM));
525 const ContentSettingBubbleModel::BubbleContent& new_bubble_content = 563 const ContentSettingBubbleModel::BubbleContent& new_bubble_content =
526 content_setting_bubble_model->bubble_content(); 564 content_setting_bubble_model->bubble_content();
527 EXPECT_EQ(new_bubble_content.title, 565 EXPECT_EQ(new_bubble_content.title,
528 l10n_util::GetStringUTF8(IDS_MICROPHONE_BLOCKED)); 566 l10n_util::GetStringUTF8(IDS_MICROPHONE_BLOCKED));
529 EXPECT_EQ(2U, new_bubble_content.radio_group.radio_items.size()); 567 EXPECT_EQ(2U, new_bubble_content.radio_group.radio_items.size());
530 EXPECT_EQ(new_bubble_content.radio_group.radio_items[0], 568 EXPECT_EQ(new_bubble_content.radio_group.radio_items[0],
(...skipping 14 matching lines...) Expand all
545 583
546 TEST_F(ContentSettingBubbleModelTest, MediastreamCamera) { 584 TEST_F(ContentSettingBubbleModelTest, MediastreamCamera) {
547 // Required to break dependency on BrowserMainLoop. 585 // Required to break dependency on BrowserMainLoop.
548 MediaCaptureDevicesDispatcher::GetInstance()-> 586 MediaCaptureDevicesDispatcher::GetInstance()->
549 DisableDeviceEnumerationForTesting(); 587 DisableDeviceEnumerationForTesting();
550 588
551 TabSpecificContentSettings* content_settings = 589 TabSpecificContentSettings* content_settings =
552 TabSpecificContentSettings::FromWebContents(web_contents()); 590 TabSpecificContentSettings::FromWebContents(web_contents());
553 std::string request_host = "google.com"; 591 std::string request_host = "google.com";
554 GURL security_origin("http://" + request_host); 592 GURL security_origin("http://" + request_host);
555 MediaStreamDevicesController::MediaStreamTypeSettingsMap 593 TabSpecificContentSettings::MicrophoneCameraState microphone_camera_state =
556 request_permissions; 594 TabSpecificContentSettings::CAMERA_ACCESSED;
557 request_permissions[content::MEDIA_DEVICE_VIDEO_CAPTURE].permission =
558 MediaStreamDevicesController::MEDIA_ALLOWED;
559 content_settings->OnMediaStreamPermissionSet(security_origin, 595 content_settings->OnMediaStreamPermissionSet(security_origin,
560 request_permissions); 596 microphone_camera_state,
597 std::string(),
598 GetDefaultVideoDevice(),
599 std::string(),
600 std::string());
561 601
562 scoped_ptr<ContentSettingBubbleModel> content_setting_bubble_model( 602 scoped_ptr<ContentSettingBubbleModel> content_setting_bubble_model(
563 ContentSettingBubbleModel::CreateContentSettingBubbleModel( 603 ContentSettingBubbleModel::CreateContentSettingBubbleModel(
564 NULL, web_contents(), profile(), 604 NULL, web_contents(), profile(),
565 CONTENT_SETTINGS_TYPE_MEDIASTREAM)); 605 CONTENT_SETTINGS_TYPE_MEDIASTREAM));
566 const ContentSettingBubbleModel::BubbleContent& bubble_content = 606 const ContentSettingBubbleModel::BubbleContent& bubble_content =
567 content_setting_bubble_model->bubble_content(); 607 content_setting_bubble_model->bubble_content();
568 EXPECT_EQ(bubble_content.title, 608 EXPECT_EQ(bubble_content.title,
569 l10n_util::GetStringUTF8(IDS_CAMERA_ACCESSED)); 609 l10n_util::GetStringUTF8(IDS_CAMERA_ACCESSED));
570 EXPECT_EQ(2U, bubble_content.radio_group.radio_items.size()); 610 EXPECT_EQ(2U, bubble_content.radio_group.radio_items.size());
571 EXPECT_EQ(bubble_content.radio_group.radio_items[0], 611 EXPECT_EQ(bubble_content.radio_group.radio_items[0],
572 l10n_util::GetStringFUTF8( 612 l10n_util::GetStringFUTF8(
573 IDS_ALLOWED_MEDIASTREAM_CAMERA_NO_ACTION, 613 IDS_ALLOWED_MEDIASTREAM_CAMERA_NO_ACTION,
574 base::UTF8ToUTF16(request_host))); 614 base::UTF8ToUTF16(request_host)));
575 EXPECT_EQ(bubble_content.radio_group.radio_items[1], 615 EXPECT_EQ(bubble_content.radio_group.radio_items[1],
576 l10n_util::GetStringUTF8( 616 l10n_util::GetStringUTF8(
577 IDS_ALLOWED_MEDIASTREAM_CAMERA_BLOCK)); 617 IDS_ALLOWED_MEDIASTREAM_CAMERA_BLOCK));
578 EXPECT_EQ(0, bubble_content.radio_group.default_item); 618 EXPECT_EQ(0, bubble_content.radio_group.default_item);
579 EXPECT_TRUE(bubble_content.custom_link.empty()); 619 EXPECT_TRUE(bubble_content.custom_link.empty());
580 EXPECT_FALSE(bubble_content.custom_link_enabled); 620 EXPECT_FALSE(bubble_content.custom_link_enabled);
581 EXPECT_FALSE(bubble_content.manage_link.empty()); 621 EXPECT_FALSE(bubble_content.manage_link.empty());
582 EXPECT_EQ(1U, bubble_content.media_menus.size()); 622 EXPECT_EQ(1U, bubble_content.media_menus.size());
583 EXPECT_EQ(content::MEDIA_DEVICE_VIDEO_CAPTURE, 623 EXPECT_EQ(content::MEDIA_DEVICE_VIDEO_CAPTURE,
584 bubble_content.media_menus.begin()->first); 624 bubble_content.media_menus.begin()->first);
585 625
586 // Change the camera access. 626 // Change the camera access.
587 request_permissions[content::MEDIA_DEVICE_VIDEO_CAPTURE].permission = 627 microphone_camera_state |= TabSpecificContentSettings::CAMERA_BLOCKED;
588 MediaStreamDevicesController::MEDIA_BLOCKED_BY_USER;
589 content_settings->OnMediaStreamPermissionSet(security_origin, 628 content_settings->OnMediaStreamPermissionSet(security_origin,
590 request_permissions); 629 microphone_camera_state,
630 std::string(),
631 GetDefaultVideoDevice(),
632 std::string(),
633 std::string());
591 content_setting_bubble_model.reset( 634 content_setting_bubble_model.reset(
592 ContentSettingBubbleModel::CreateContentSettingBubbleModel( 635 ContentSettingBubbleModel::CreateContentSettingBubbleModel(
593 NULL, web_contents(), profile(), 636 NULL, web_contents(), profile(),
594 CONTENT_SETTINGS_TYPE_MEDIASTREAM)); 637 CONTENT_SETTINGS_TYPE_MEDIASTREAM));
595 const ContentSettingBubbleModel::BubbleContent& new_bubble_content = 638 const ContentSettingBubbleModel::BubbleContent& new_bubble_content =
596 content_setting_bubble_model->bubble_content(); 639 content_setting_bubble_model->bubble_content();
597 EXPECT_EQ(new_bubble_content.title, 640 EXPECT_EQ(new_bubble_content.title,
598 l10n_util::GetStringUTF8(IDS_CAMERA_BLOCKED)); 641 l10n_util::GetStringUTF8(IDS_CAMERA_BLOCKED));
599 EXPECT_EQ(2U, new_bubble_content.radio_group.radio_items.size()); 642 EXPECT_EQ(2U, new_bubble_content.radio_group.radio_items.size());
600 EXPECT_EQ(new_bubble_content.radio_group.radio_items[0], 643 EXPECT_EQ(new_bubble_content.radio_group.radio_items[0],
(...skipping 16 matching lines...) Expand all
617 // Required to break dependency on BrowserMainLoop. 660 // Required to break dependency on BrowserMainLoop.
618 MediaCaptureDevicesDispatcher::GetInstance()-> 661 MediaCaptureDevicesDispatcher::GetInstance()->
619 DisableDeviceEnumerationForTesting(); 662 DisableDeviceEnumerationForTesting();
620 663
621 TabSpecificContentSettings* content_settings = 664 TabSpecificContentSettings* content_settings =
622 TabSpecificContentSettings::FromWebContents(web_contents()); 665 TabSpecificContentSettings::FromWebContents(web_contents());
623 std::string request_host = "google.com"; 666 std::string request_host = "google.com";
624 GURL security_origin("http://" + request_host); 667 GURL security_origin("http://" + request_host);
625 668
626 // Firstly, add microphone access. 669 // Firstly, add microphone access.
627 MediaStreamDevicesController::MediaStreamTypeSettingsMap 670 TabSpecificContentSettings::MicrophoneCameraState microphone_camera_state =
628 request_permissions; 671 TabSpecificContentSettings::MICROPHONE_ACCESSED;
629 request_permissions[content::MEDIA_DEVICE_AUDIO_CAPTURE].permission =
630 MediaStreamDevicesController::MEDIA_ALLOWED;
631 content_settings->OnMediaStreamPermissionSet(security_origin, 672 content_settings->OnMediaStreamPermissionSet(security_origin,
632 request_permissions); 673 microphone_camera_state,
674 GetDefaultAudioDevice(),
675 std::string(),
676 std::string(),
677 std::string());
633 678
634 scoped_ptr<ContentSettingBubbleModel> content_setting_bubble_model( 679 scoped_ptr<ContentSettingBubbleModel> content_setting_bubble_model(
635 ContentSettingBubbleModel::CreateContentSettingBubbleModel( 680 ContentSettingBubbleModel::CreateContentSettingBubbleModel(
636 NULL, web_contents(), profile(), 681 NULL, web_contents(), profile(),
637 CONTENT_SETTINGS_TYPE_MEDIASTREAM)); 682 CONTENT_SETTINGS_TYPE_MEDIASTREAM));
638 const ContentSettingBubbleModel::BubbleContent& bubble_content = 683 const ContentSettingBubbleModel::BubbleContent& bubble_content =
639 content_setting_bubble_model->bubble_content(); 684 content_setting_bubble_model->bubble_content();
640 EXPECT_EQ(bubble_content.title, 685 EXPECT_EQ(bubble_content.title,
641 l10n_util::GetStringUTF8(IDS_MICROPHONE_ACCESSED)); 686 l10n_util::GetStringUTF8(IDS_MICROPHONE_ACCESSED));
642 EXPECT_EQ(2U, bubble_content.radio_group.radio_items.size()); 687 EXPECT_EQ(2U, bubble_content.radio_group.radio_items.size());
643 EXPECT_EQ(bubble_content.radio_group.radio_items[0], 688 EXPECT_EQ(bubble_content.radio_group.radio_items[0],
644 l10n_util::GetStringFUTF8( 689 l10n_util::GetStringFUTF8(
645 IDS_ALLOWED_MEDIASTREAM_MIC_NO_ACTION, 690 IDS_ALLOWED_MEDIASTREAM_MIC_NO_ACTION,
646 base::UTF8ToUTF16(request_host))); 691 base::UTF8ToUTF16(request_host)));
647 EXPECT_EQ(bubble_content.radio_group.radio_items[1], 692 EXPECT_EQ(bubble_content.radio_group.radio_items[1],
648 l10n_util::GetStringUTF8( 693 l10n_util::GetStringUTF8(
649 IDS_ALLOWED_MEDIASTREAM_MIC_BLOCK)); 694 IDS_ALLOWED_MEDIASTREAM_MIC_BLOCK));
650 EXPECT_EQ(0, bubble_content.radio_group.default_item); 695 EXPECT_EQ(0, bubble_content.radio_group.default_item);
651 EXPECT_EQ(1U, bubble_content.media_menus.size()); 696 EXPECT_EQ(1U, bubble_content.media_menus.size());
652 EXPECT_EQ(content::MEDIA_DEVICE_AUDIO_CAPTURE, 697 EXPECT_EQ(content::MEDIA_DEVICE_AUDIO_CAPTURE,
653 bubble_content.media_menus.begin()->first); 698 bubble_content.media_menus.begin()->first);
654 699
655 // Then add camera access. 700 // Then add camera access.
656 request_permissions[content::MEDIA_DEVICE_VIDEO_CAPTURE].permission = 701 microphone_camera_state |= TabSpecificContentSettings::CAMERA_ACCESSED;
657 MediaStreamDevicesController::MEDIA_ALLOWED;
658 content_settings->OnMediaStreamPermissionSet(security_origin, 702 content_settings->OnMediaStreamPermissionSet(security_origin,
659 request_permissions); 703 microphone_camera_state,
704 GetDefaultAudioDevice(),
705 GetDefaultVideoDevice(),
706 std::string(),
707 std::string());
660 708
661 content_setting_bubble_model.reset( 709 content_setting_bubble_model.reset(
662 ContentSettingBubbleModel::CreateContentSettingBubbleModel( 710 ContentSettingBubbleModel::CreateContentSettingBubbleModel(
663 NULL, web_contents(), profile(), 711 NULL, web_contents(), profile(),
664 CONTENT_SETTINGS_TYPE_MEDIASTREAM)); 712 CONTENT_SETTINGS_TYPE_MEDIASTREAM));
665 const ContentSettingBubbleModel::BubbleContent& new_bubble_content = 713 const ContentSettingBubbleModel::BubbleContent& new_bubble_content =
666 content_setting_bubble_model->bubble_content(); 714 content_setting_bubble_model->bubble_content();
667 EXPECT_EQ(new_bubble_content.title, 715 EXPECT_EQ(new_bubble_content.title,
668 l10n_util::GetStringUTF8(IDS_MICROPHONE_CAMERA_ALLOWED)); 716 l10n_util::GetStringUTF8(IDS_MICROPHONE_CAMERA_ALLOWED));
669 EXPECT_EQ(2U, new_bubble_content.radio_group.radio_items.size()); 717 EXPECT_EQ(2U, new_bubble_content.radio_group.radio_items.size());
(...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after
895 { 943 {
896 ProtocolHandler handler = registry.GetHandlerFor("mailto"); 944 ProtocolHandler handler = registry.GetHandlerFor("mailto");
897 ASSERT_FALSE(handler.IsEmpty()); 945 ASSERT_FALSE(handler.IsEmpty());
898 EXPECT_EQ(CONTENT_SETTING_ALLOW, 946 EXPECT_EQ(CONTENT_SETTING_ALLOW,
899 content_settings->pending_protocol_handler_setting()); 947 content_settings->pending_protocol_handler_setting());
900 EXPECT_FALSE(registry.IsIgnored(test_handler)); 948 EXPECT_FALSE(registry.IsIgnored(test_handler));
901 } 949 }
902 950
903 registry.Shutdown(); 951 registry.Shutdown();
904 } 952 }
OLDNEW
« no previous file with comments | « chrome/browser/media/media_stream_devices_controller_browsertest.cc ('k') | chrome/chrome_tests.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698