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

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

Issue 183743021: Implement MediaCaptureDevices. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 9 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 (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/strings/utf_string_conversions.h" 7 #include "base/strings/utf_string_conversions.h"
8 #include "chrome/browser/content_settings/host_content_settings_map.h" 8 #include "chrome/browser/content_settings/host_content_settings_map.h"
9 #include "chrome/browser/content_settings/tab_specific_content_settings.h" 9 #include "chrome/browser/content_settings/tab_specific_content_settings.h"
10 #include "chrome/browser/custom_handlers/protocol_handler_registry.h" 10 #include "chrome/browser/custom_handlers/protocol_handler_registry.h"
11 #include "chrome/browser/infobars/infobar_delegate.h" 11 #include "chrome/browser/infobars/infobar_delegate.h"
12 #include "chrome/browser/infobars/infobar_service.h" 12 #include "chrome/browser/infobars/infobar_service.h"
13 #include "chrome/browser/media/media_capture_devices_dispatcher.h"
14 #include "chrome/browser/profiles/profile.h" 13 #include "chrome/browser/profiles/profile.h"
15 #include "chrome/browser/ui/content_settings/content_setting_bubble_model.h" 14 #include "chrome/browser/ui/content_settings/content_setting_bubble_model.h"
16 #include "chrome/common/chrome_switches.h" 15 #include "chrome/common/chrome_switches.h"
17 #include "chrome/common/content_settings.h" 16 #include "chrome/common/content_settings.h"
18 #include "chrome/test/base/chrome_render_view_host_test_harness.h" 17 #include "chrome/test/base/chrome_render_view_host_test_harness.h"
19 #include "chrome/test/base/testing_profile.h" 18 #include "chrome/test/base/testing_profile.h"
19 #include "content/public/browser/media_capture_devices.h"
20 #include "content/public/browser/web_contents.h" 20 #include "content/public/browser/web_contents.h"
21 #include "content/public/test/web_contents_tester.h" 21 #include "content/public/test/web_contents_tester.h"
22 #include "grit/generated_resources.h" 22 #include "grit/generated_resources.h"
23 #include "testing/gtest/include/gtest/gtest.h" 23 #include "testing/gtest/include/gtest/gtest.h"
24 #include "ui/base/l10n/l10n_util.h" 24 #include "ui/base/l10n/l10n_util.h"
25 25
26 using content::WebContentsTester; 26 using content::WebContentsTester;
27 27
28 class ContentSettingBubbleModelTest : public ChromeRenderViewHostTestHarness { 28 class ContentSettingBubbleModelTest : public ChromeRenderViewHostTestHarness {
29 protected: 29 protected:
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
103 ASSERT_EQ(2U, bubble_content_2.radio_group.radio_items.size()); 103 ASSERT_EQ(2U, bubble_content_2.radio_group.radio_items.size());
104 // TODO(bauerb): Update this once the strings have been updated. 104 // TODO(bauerb): Update this once the strings have been updated.
105 EXPECT_EQ(radio1, bubble_content_2.radio_group.radio_items[0]); 105 EXPECT_EQ(radio1, bubble_content_2.radio_group.radio_items[0]);
106 EXPECT_EQ(radio2, bubble_content_2.radio_group.radio_items[1]); 106 EXPECT_EQ(radio2, bubble_content_2.radio_group.radio_items[1]);
107 EXPECT_FALSE(bubble_content_2.custom_link.empty()); 107 EXPECT_FALSE(bubble_content_2.custom_link.empty());
108 EXPECT_TRUE(bubble_content_2.custom_link_enabled); 108 EXPECT_TRUE(bubble_content_2.custom_link_enabled);
109 EXPECT_FALSE(bubble_content_2.manage_link.empty()); 109 EXPECT_FALSE(bubble_content_2.manage_link.empty());
110 } 110 }
111 111
112 TEST_F(ContentSettingBubbleModelTest, MediastreamMicAndCamera) { 112 TEST_F(ContentSettingBubbleModelTest, MediastreamMicAndCamera) {
113 // Required to break dependency on BrowserMainLoop. 113 content::MediaCaptureDevices::GetInstance()->
114 MediaCaptureDevicesDispatcher::GetInstance()->
115 DisableDeviceEnumerationForTesting(); 114 DisableDeviceEnumerationForTesting();
116 115
117 TabSpecificContentSettings* content_settings = 116 TabSpecificContentSettings* content_settings =
118 TabSpecificContentSettings::FromWebContents(web_contents()); 117 TabSpecificContentSettings::FromWebContents(web_contents());
119 std::string request_host = "google.com"; 118 std::string request_host = "google.com";
120 GURL security_origin("http://" + request_host); 119 GURL security_origin("http://" + request_host);
121 MediaStreamDevicesController::MediaStreamTypeSettingsMap 120 MediaStreamDevicesController::MediaStreamTypeSettingsMap
122 request_permissions; 121 request_permissions;
123 request_permissions[content::MEDIA_DEVICE_AUDIO_CAPTURE].permission = 122 request_permissions[content::MEDIA_DEVICE_AUDIO_CAPTURE].permission =
124 MediaStreamDevicesController::MEDIA_ALLOWED; 123 MediaStreamDevicesController::MEDIA_ALLOWED;
(...skipping 19 matching lines...) Expand all
144 l10n_util::GetStringUTF8( 143 l10n_util::GetStringUTF8(
145 IDS_ALLOWED_MEDIASTREAM_MIC_AND_CAMERA_BLOCK)); 144 IDS_ALLOWED_MEDIASTREAM_MIC_AND_CAMERA_BLOCK));
146 EXPECT_EQ(0, bubble_content.radio_group.default_item); 145 EXPECT_EQ(0, bubble_content.radio_group.default_item);
147 EXPECT_TRUE(bubble_content.custom_link.empty()); 146 EXPECT_TRUE(bubble_content.custom_link.empty());
148 EXPECT_FALSE(bubble_content.custom_link_enabled); 147 EXPECT_FALSE(bubble_content.custom_link_enabled);
149 EXPECT_FALSE(bubble_content.manage_link.empty()); 148 EXPECT_FALSE(bubble_content.manage_link.empty());
150 EXPECT_EQ(2U, bubble_content.media_menus.size()); 149 EXPECT_EQ(2U, bubble_content.media_menus.size());
151 } 150 }
152 151
153 TEST_F(ContentSettingBubbleModelTest, BlockedMediastreamMicAndCamera) { 152 TEST_F(ContentSettingBubbleModelTest, BlockedMediastreamMicAndCamera) {
154 // Required to break dependency on BrowserMainLoop. 153 content::MediaCaptureDevices::GetInstance()->
155 MediaCaptureDevicesDispatcher::GetInstance()->
156 DisableDeviceEnumerationForTesting(); 154 DisableDeviceEnumerationForTesting();
157 155
158 WebContentsTester::For(web_contents())-> 156 WebContentsTester::For(web_contents())->
159 NavigateAndCommit(GURL("https://www.example.com")); 157 NavigateAndCommit(GURL("https://www.example.com"));
160 GURL url = web_contents()->GetURL(); 158 GURL url = web_contents()->GetURL();
161 159
162 HostContentSettingsMap* host_content_settings_map = 160 HostContentSettingsMap* host_content_settings_map =
163 profile()->GetHostContentSettingsMap(); 161 profile()->GetHostContentSettingsMap();
164 ContentSettingsPattern primary_pattern = 162 ContentSettingsPattern primary_pattern =
165 ContentSettingsPattern::FromURL(url); 163 ContentSettingsPattern::FromURL(url);
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
233 url, 231 url,
234 CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA, 232 CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA,
235 std::string())); 233 std::string()));
236 234
237 InfoBarService* infobar_service = 235 InfoBarService* infobar_service =
238 InfoBarService::FromWebContents(web_contents()); 236 InfoBarService::FromWebContents(web_contents());
239 infobar_service->RemoveInfoBar(infobar_service->infobar_at(0)); 237 infobar_service->RemoveInfoBar(infobar_service->infobar_at(0));
240 } 238 }
241 239
242 TEST_F(ContentSettingBubbleModelTest, MediastreamMic) { 240 TEST_F(ContentSettingBubbleModelTest, MediastreamMic) {
243 // Required to break dependency on BrowserMainLoop. 241 content::MediaCaptureDevices::GetInstance()->
244 MediaCaptureDevicesDispatcher::GetInstance()->
245 DisableDeviceEnumerationForTesting(); 242 DisableDeviceEnumerationForTesting();
246 243
247 TabSpecificContentSettings* content_settings = 244 TabSpecificContentSettings* content_settings =
248 TabSpecificContentSettings::FromWebContents(web_contents()); 245 TabSpecificContentSettings::FromWebContents(web_contents());
249 std::string request_host = "google.com"; 246 std::string request_host = "google.com";
250 GURL security_origin("http://" + request_host); 247 GURL security_origin("http://" + request_host);
251 MediaStreamDevicesController::MediaStreamTypeSettingsMap 248 MediaStreamDevicesController::MediaStreamTypeSettingsMap
252 request_permissions; 249 request_permissions;
253 request_permissions[content::MEDIA_DEVICE_AUDIO_CAPTURE].permission = 250 request_permissions[content::MEDIA_DEVICE_AUDIO_CAPTURE].permission =
254 MediaStreamDevicesController::MEDIA_ALLOWED; 251 MediaStreamDevicesController::MEDIA_ALLOWED;
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
303 EXPECT_EQ(1, new_bubble_content.radio_group.default_item); 300 EXPECT_EQ(1, new_bubble_content.radio_group.default_item);
304 EXPECT_TRUE(new_bubble_content.custom_link.empty()); 301 EXPECT_TRUE(new_bubble_content.custom_link.empty());
305 EXPECT_FALSE(new_bubble_content.custom_link_enabled); 302 EXPECT_FALSE(new_bubble_content.custom_link_enabled);
306 EXPECT_FALSE(new_bubble_content.manage_link.empty()); 303 EXPECT_FALSE(new_bubble_content.manage_link.empty());
307 EXPECT_EQ(1U, new_bubble_content.media_menus.size()); 304 EXPECT_EQ(1U, new_bubble_content.media_menus.size());
308 EXPECT_EQ(content::MEDIA_DEVICE_AUDIO_CAPTURE, 305 EXPECT_EQ(content::MEDIA_DEVICE_AUDIO_CAPTURE,
309 new_bubble_content.media_menus.begin()->first); 306 new_bubble_content.media_menus.begin()->first);
310 } 307 }
311 308
312 TEST_F(ContentSettingBubbleModelTest, MediastreamCamera) { 309 TEST_F(ContentSettingBubbleModelTest, MediastreamCamera) {
313 // Required to break dependency on BrowserMainLoop. 310 content::MediaCaptureDevices::GetInstance()->
314 MediaCaptureDevicesDispatcher::GetInstance()->
315 DisableDeviceEnumerationForTesting(); 311 DisableDeviceEnumerationForTesting();
316 312
317 TabSpecificContentSettings* content_settings = 313 TabSpecificContentSettings* content_settings =
318 TabSpecificContentSettings::FromWebContents(web_contents()); 314 TabSpecificContentSettings::FromWebContents(web_contents());
319 std::string request_host = "google.com"; 315 std::string request_host = "google.com";
320 GURL security_origin("http://" + request_host); 316 GURL security_origin("http://" + request_host);
321 MediaStreamDevicesController::MediaStreamTypeSettingsMap 317 MediaStreamDevicesController::MediaStreamTypeSettingsMap
322 request_permissions; 318 request_permissions;
323 request_permissions[content::MEDIA_DEVICE_VIDEO_CAPTURE].permission = 319 request_permissions[content::MEDIA_DEVICE_VIDEO_CAPTURE].permission =
324 MediaStreamDevicesController::MEDIA_ALLOWED; 320 MediaStreamDevicesController::MEDIA_ALLOWED;
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
373 EXPECT_EQ(1, new_bubble_content.radio_group.default_item); 369 EXPECT_EQ(1, new_bubble_content.radio_group.default_item);
374 EXPECT_TRUE(new_bubble_content.custom_link.empty()); 370 EXPECT_TRUE(new_bubble_content.custom_link.empty());
375 EXPECT_FALSE(new_bubble_content.custom_link_enabled); 371 EXPECT_FALSE(new_bubble_content.custom_link_enabled);
376 EXPECT_FALSE(new_bubble_content.manage_link.empty()); 372 EXPECT_FALSE(new_bubble_content.manage_link.empty());
377 EXPECT_EQ(1U, new_bubble_content.media_menus.size()); 373 EXPECT_EQ(1U, new_bubble_content.media_menus.size());
378 EXPECT_EQ(content::MEDIA_DEVICE_VIDEO_CAPTURE, 374 EXPECT_EQ(content::MEDIA_DEVICE_VIDEO_CAPTURE,
379 new_bubble_content.media_menus.begin()->first); 375 new_bubble_content.media_menus.begin()->first);
380 } 376 }
381 377
382 TEST_F(ContentSettingBubbleModelTest, AccumulateMediastreamMicAndCamera) { 378 TEST_F(ContentSettingBubbleModelTest, AccumulateMediastreamMicAndCamera) {
383 // Required to break dependency on BrowserMainLoop. 379 content::MediaCaptureDevices::GetInstance()->
384 MediaCaptureDevicesDispatcher::GetInstance()->
385 DisableDeviceEnumerationForTesting(); 380 DisableDeviceEnumerationForTesting();
386 381
387 TabSpecificContentSettings* content_settings = 382 TabSpecificContentSettings* content_settings =
388 TabSpecificContentSettings::FromWebContents(web_contents()); 383 TabSpecificContentSettings::FromWebContents(web_contents());
389 std::string request_host = "google.com"; 384 std::string request_host = "google.com";
390 GURL security_origin("http://" + request_host); 385 GURL security_origin("http://" + request_host);
391 386
392 // Firstly, add microphone access. 387 // Firstly, add microphone access.
393 MediaStreamDevicesController::MediaStreamTypeSettingsMap 388 MediaStreamDevicesController::MediaStreamTypeSettingsMap
394 request_permissions; 389 request_permissions;
(...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after
663 ProtocolHandler handler = registry.GetHandlerFor("mailto"); 658 ProtocolHandler handler = registry.GetHandlerFor("mailto");
664 ASSERT_FALSE(handler.IsEmpty()); 659 ASSERT_FALSE(handler.IsEmpty());
665 EXPECT_EQ(base::ASCIIToUTF16("Handler"), handler.title()); 660 EXPECT_EQ(base::ASCIIToUTF16("Handler"), handler.title());
666 EXPECT_EQ(CONTENT_SETTING_ALLOW, 661 EXPECT_EQ(CONTENT_SETTING_ALLOW,
667 content_settings->pending_protocol_handler_setting()); 662 content_settings->pending_protocol_handler_setting());
668 EXPECT_FALSE(registry.IsIgnored(test_handler)); 663 EXPECT_FALSE(registry.IsIgnored(test_handler));
669 } 664 }
670 665
671 registry.Shutdown(); 666 registry.Shutdown();
672 } 667 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698