| OLD | NEW |
| 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/prefs/pref_service.h" |
| 8 #include "base/strings/utf_string_conversions.h" | 8 #include "base/strings/utf_string_conversions.h" |
| 9 #include "chrome/browser/content_settings/host_content_settings_map_factory.h" |
| 9 #include "chrome/browser/content_settings/tab_specific_content_settings.h" | 10 #include "chrome/browser/content_settings/tab_specific_content_settings.h" |
| 10 #include "chrome/browser/custom_handlers/protocol_handler_registry.h" | 11 #include "chrome/browser/custom_handlers/protocol_handler_registry.h" |
| 11 #include "chrome/browser/infobars/infobar_service.h" | 12 #include "chrome/browser/infobars/infobar_service.h" |
| 12 #include "chrome/browser/media/media_capture_devices_dispatcher.h" | 13 #include "chrome/browser/media/media_capture_devices_dispatcher.h" |
| 13 #include "chrome/browser/media/media_stream_capture_indicator.h" | 14 #include "chrome/browser/media/media_stream_capture_indicator.h" |
| 14 #include "chrome/browser/profiles/profile.h" | 15 #include "chrome/browser/profiles/profile.h" |
| 15 #include "chrome/browser/ui/content_settings/content_setting_bubble_model.h" | 16 #include "chrome/browser/ui/content_settings/content_setting_bubble_model.h" |
| 16 #include "chrome/common/chrome_switches.h" | 17 #include "chrome/common/chrome_switches.h" |
| 17 #include "chrome/common/pref_names.h" | 18 #include "chrome/common/pref_names.h" |
| 18 #include "chrome/grit/generated_resources.h" | 19 #include "chrome/grit/generated_resources.h" |
| (...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 173 TEST_F(ContentSettingBubbleModelTest, BlockedMediastreamMicAndCamera) { | 174 TEST_F(ContentSettingBubbleModelTest, BlockedMediastreamMicAndCamera) { |
| 174 // Required to break dependency on BrowserMainLoop. | 175 // Required to break dependency on BrowserMainLoop. |
| 175 MediaCaptureDevicesDispatcher::GetInstance()-> | 176 MediaCaptureDevicesDispatcher::GetInstance()-> |
| 176 DisableDeviceEnumerationForTesting(); | 177 DisableDeviceEnumerationForTesting(); |
| 177 | 178 |
| 178 WebContentsTester::For(web_contents())-> | 179 WebContentsTester::For(web_contents())-> |
| 179 NavigateAndCommit(GURL("https://www.example.com")); | 180 NavigateAndCommit(GURL("https://www.example.com")); |
| 180 GURL url = web_contents()->GetURL(); | 181 GURL url = web_contents()->GetURL(); |
| 181 | 182 |
| 182 HostContentSettingsMap* host_content_settings_map = | 183 HostContentSettingsMap* host_content_settings_map = |
| 183 profile()->GetHostContentSettingsMap(); | 184 HostContentSettingsMapFactory::GetForProfile(profile()); |
| 184 ContentSettingsPattern primary_pattern = | 185 ContentSettingsPattern primary_pattern = |
| 185 ContentSettingsPattern::FromURL(url); | 186 ContentSettingsPattern::FromURL(url); |
| 186 ContentSetting setting = CONTENT_SETTING_BLOCK; | 187 ContentSetting setting = CONTENT_SETTING_BLOCK; |
| 187 host_content_settings_map->SetContentSetting( | 188 host_content_settings_map->SetContentSetting( |
| 188 primary_pattern, | 189 primary_pattern, |
| 189 ContentSettingsPattern::Wildcard(), | 190 ContentSettingsPattern::Wildcard(), |
| 190 CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC, | 191 CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC, |
| 191 std::string(), | 192 std::string(), |
| 192 setting); | 193 setting); |
| 193 host_content_settings_map->SetContentSetting( | 194 host_content_settings_map->SetContentSetting( |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 264 TEST_F(ContentSettingBubbleModelTest, MediastreamContentBubble) { | 265 TEST_F(ContentSettingBubbleModelTest, MediastreamContentBubble) { |
| 265 // Required to break dependency on BrowserMainLoop. | 266 // Required to break dependency on BrowserMainLoop. |
| 266 MediaCaptureDevicesDispatcher::GetInstance()-> | 267 MediaCaptureDevicesDispatcher::GetInstance()-> |
| 267 DisableDeviceEnumerationForTesting(); | 268 DisableDeviceEnumerationForTesting(); |
| 268 | 269 |
| 269 WebContentsTester::For(web_contents())-> | 270 WebContentsTester::For(web_contents())-> |
| 270 NavigateAndCommit(GURL("https://www.example.com")); | 271 NavigateAndCommit(GURL("https://www.example.com")); |
| 271 GURL url = web_contents()->GetURL(); | 272 GURL url = web_contents()->GetURL(); |
| 272 | 273 |
| 273 HostContentSettingsMap* host_content_settings_map = | 274 HostContentSettingsMap* host_content_settings_map = |
| 274 profile()->GetHostContentSettingsMap(); | 275 HostContentSettingsMapFactory::GetForProfile(profile()); |
| 275 ContentSettingsPattern primary_pattern = | 276 ContentSettingsPattern primary_pattern = |
| 276 ContentSettingsPattern::FromURL(url); | 277 ContentSettingsPattern::FromURL(url); |
| 277 ContentSetting setting = CONTENT_SETTING_BLOCK; | 278 ContentSetting setting = CONTENT_SETTING_BLOCK; |
| 278 host_content_settings_map->SetContentSetting( | 279 host_content_settings_map->SetContentSetting( |
| 279 primary_pattern, | 280 primary_pattern, |
| 280 ContentSettingsPattern::Wildcard(), | 281 ContentSettingsPattern::Wildcard(), |
| 281 CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC, | 282 CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC, |
| 282 std::string(), | 283 std::string(), |
| 283 setting); | 284 setting); |
| 284 | 285 |
| (...skipping 530 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 815 NavigateAndCommit(page_url); | 816 NavigateAndCommit(page_url); |
| 816 TabSpecificContentSettings* content_settings = | 817 TabSpecificContentSettings* content_settings = |
| 817 TabSpecificContentSettings::FromWebContents(web_contents()); | 818 TabSpecificContentSettings::FromWebContents(web_contents()); |
| 818 | 819 |
| 819 // One permitted frame, but not in the content map: requires reload. | 820 // One permitted frame, but not in the content map: requires reload. |
| 820 content_settings->OnGeolocationPermissionSet(frame1_url, true); | 821 content_settings->OnGeolocationPermissionSet(frame1_url, true); |
| 821 CheckGeolocationBubble(1, false, true); | 822 CheckGeolocationBubble(1, false, true); |
| 822 | 823 |
| 823 // Add it to the content map, should now have a clear link. | 824 // Add it to the content map, should now have a clear link. |
| 824 HostContentSettingsMap* setting_map = | 825 HostContentSettingsMap* setting_map = |
| 825 profile()->GetHostContentSettingsMap(); | 826 HostContentSettingsMapFactory::GetForProfile(profile()); |
| 826 setting_map->SetContentSetting( | 827 setting_map->SetContentSetting( |
| 827 ContentSettingsPattern::FromURLNoWildcard(frame1_url), | 828 ContentSettingsPattern::FromURLNoWildcard(frame1_url), |
| 828 ContentSettingsPattern::FromURLNoWildcard(page_url), | 829 ContentSettingsPattern::FromURLNoWildcard(page_url), |
| 829 CONTENT_SETTINGS_TYPE_GEOLOCATION, | 830 CONTENT_SETTINGS_TYPE_GEOLOCATION, |
| 830 std::string(), | 831 std::string(), |
| 831 CONTENT_SETTING_ALLOW); | 832 CONTENT_SETTING_ALLOW); |
| 832 CheckGeolocationBubble(1, true, false); | 833 CheckGeolocationBubble(1, true, false); |
| 833 | 834 |
| 834 // Change the default to allow: no message needed. | 835 // Change the default to allow: no message needed. |
| 835 profile()->GetHostContentSettingsMap()->SetDefaultContentSetting( | 836 setting_map->SetDefaultContentSetting(CONTENT_SETTINGS_TYPE_GEOLOCATION, |
| 836 CONTENT_SETTINGS_TYPE_GEOLOCATION, CONTENT_SETTING_ALLOW); | 837 CONTENT_SETTING_ALLOW); |
| 837 CheckGeolocationBubble(1, false, false); | 838 CheckGeolocationBubble(1, false, false); |
| 838 | 839 |
| 839 // Second frame denied, but not stored in the content map: requires reload. | 840 // Second frame denied, but not stored in the content map: requires reload. |
| 840 content_settings->OnGeolocationPermissionSet(frame2_url, false); | 841 content_settings->OnGeolocationPermissionSet(frame2_url, false); |
| 841 CheckGeolocationBubble(2, false, true); | 842 CheckGeolocationBubble(2, false, true); |
| 842 | 843 |
| 843 // Change the default to block: offer a clear link for the persisted frame 1. | 844 // Change the default to block: offer a clear link for the persisted frame 1. |
| 844 profile()->GetHostContentSettingsMap()->SetDefaultContentSetting( | 845 setting_map->SetDefaultContentSetting(CONTENT_SETTINGS_TYPE_GEOLOCATION, |
| 845 CONTENT_SETTINGS_TYPE_GEOLOCATION, CONTENT_SETTING_BLOCK); | 846 CONTENT_SETTING_BLOCK); |
| 846 CheckGeolocationBubble(2, true, false); | 847 CheckGeolocationBubble(2, true, false); |
| 847 } | 848 } |
| 848 | 849 |
| 849 TEST_F(ContentSettingBubbleModelTest, FileURL) { | 850 TEST_F(ContentSettingBubbleModelTest, FileURL) { |
| 850 std::string file_url("file:///tmp/test.html"); | 851 std::string file_url("file:///tmp/test.html"); |
| 851 NavigateAndCommit(GURL(file_url)); | 852 NavigateAndCommit(GURL(file_url)); |
| 852 TabSpecificContentSettings::FromWebContents(web_contents())->OnContentBlocked( | 853 TabSpecificContentSettings::FromWebContents(web_contents())->OnContentBlocked( |
| 853 CONTENT_SETTINGS_TYPE_IMAGES); | 854 CONTENT_SETTINGS_TYPE_IMAGES); |
| 854 scoped_ptr<ContentSettingBubbleModel> content_setting_bubble_model( | 855 scoped_ptr<ContentSettingBubbleModel> content_setting_bubble_model( |
| 855 ContentSettingBubbleModel::CreateContentSettingBubbleModel( | 856 ContentSettingBubbleModel::CreateContentSettingBubbleModel( |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 965 { | 966 { |
| 966 ProtocolHandler handler = registry.GetHandlerFor("mailto"); | 967 ProtocolHandler handler = registry.GetHandlerFor("mailto"); |
| 967 ASSERT_FALSE(handler.IsEmpty()); | 968 ASSERT_FALSE(handler.IsEmpty()); |
| 968 EXPECT_EQ(CONTENT_SETTING_ALLOW, | 969 EXPECT_EQ(CONTENT_SETTING_ALLOW, |
| 969 content_settings->pending_protocol_handler_setting()); | 970 content_settings->pending_protocol_handler_setting()); |
| 970 EXPECT_FALSE(registry.IsIgnored(test_handler)); | 971 EXPECT_FALSE(registry.IsIgnored(test_handler)); |
| 971 } | 972 } |
| 972 | 973 |
| 973 registry.Shutdown(); | 974 registry.Shutdown(); |
| 974 } | 975 } |
| OLD | NEW |