| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 "chrome/browser/plugins/chrome_plugin_service_filter.h" | 5 #include "chrome/browser/plugins/chrome_plugin_service_filter.h" |
| 6 | 6 |
| 7 #include <map> | 7 #include <map> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 19 matching lines...) Expand all Loading... |
| 30 #include "components/content_settings/core/browser/host_content_settings_map.h" | 30 #include "components/content_settings/core/browser/host_content_settings_map.h" |
| 31 #include "components/content_settings/core/common/pref_names.h" | 31 #include "components/content_settings/core/common/pref_names.h" |
| 32 #include "components/syncable_prefs/testing_pref_service_syncable.h" | 32 #include "components/syncable_prefs/testing_pref_service_syncable.h" |
| 33 #include "components/variations/variations_associated_data.h" | 33 #include "components/variations/variations_associated_data.h" |
| 34 #include "content/public/browser/browser_thread.h" | 34 #include "content/public/browser/browser_thread.h" |
| 35 #include "content/public/browser/plugin_service.h" | 35 #include "content/public/browser/plugin_service.h" |
| 36 #include "content/public/browser/render_process_host.h" | 36 #include "content/public/browser/render_process_host.h" |
| 37 #include "content/public/browser/web_contents.h" | 37 #include "content/public/browser/web_contents.h" |
| 38 #include "content/public/common/content_constants.h" | 38 #include "content/public/common/content_constants.h" |
| 39 #include "content/public/test/test_utils.h" | 39 #include "content/public/test/test_utils.h" |
| 40 #include "url/origin.h" |
| 40 | 41 |
| 41 namespace { | 42 namespace { |
| 42 | 43 |
| 43 const char kTrialName[] = "PreferHtmlOverPlugins"; | 44 const char kTrialName[] = "PreferHtmlOverPlugins"; |
| 44 const char kGroupName[] = "Group1"; | 45 const char kGroupName[] = "Group1"; |
| 45 | 46 |
| 46 } // namespace | 47 } // namespace |
| 47 | 48 |
| 48 class ChromePluginServiceFilterTest : public ChromeRenderViewHostTestHarness { | 49 class ChromePluginServiceFilterTest : public ChromeRenderViewHostTestHarness { |
| 49 public: | 50 public: |
| 50 ChromePluginServiceFilterTest() | 51 ChromePluginServiceFilterTest() |
| 51 : ChromeRenderViewHostTestHarness(), | 52 : ChromeRenderViewHostTestHarness(), |
| 52 filter_(nullptr), | 53 filter_(nullptr), |
| 53 flash_plugin_path_(FILE_PATH_LITERAL("/path/to/flash")) {} | 54 flash_plugin_path_(FILE_PATH_LITERAL("/path/to/flash")) {} |
| 54 | 55 |
| 55 bool IsPluginAvailable(const GURL& plugin_content_url, | 56 bool IsPluginAvailable(const GURL& plugin_content_url, |
| 56 const GURL& main_url, | 57 const url::Origin& main_frame_origin, |
| 57 const void* resource_context, | 58 const void* resource_context, |
| 58 const content::WebPluginInfo& plugin_info) { | 59 const content::WebPluginInfo& plugin_info) { |
| 59 bool is_available = false; | 60 bool is_available = false; |
| 60 | 61 |
| 61 // ChromePluginServiceFilter::IsPluginAvailable always runs on the IO | 62 // ChromePluginServiceFilter::IsPluginAvailable always runs on the IO |
| 62 // thread. Use a RunLoop to ensure this method blocks until it posts back. | 63 // thread. Use a RunLoop to ensure this method blocks until it posts back. |
| 63 base::RunLoop run_loop; | 64 base::RunLoop run_loop; |
| 64 content::BrowserThread::PostTaskAndReply( | 65 content::BrowserThread::PostTaskAndReply( |
| 65 content::BrowserThread::IO, FROM_HERE, | 66 content::BrowserThread::IO, FROM_HERE, |
| 66 base::Bind(&ChromePluginServiceFilterTest::IsPluginAvailableOnIOThread, | 67 base::Bind(&ChromePluginServiceFilterTest::IsPluginAvailableOnIOThread, |
| 67 base::Unretained(this), plugin_content_url, main_url, | 68 base::Unretained(this), plugin_content_url, |
| 68 resource_context, plugin_info, &is_available), | 69 main_frame_origin, resource_context, plugin_info, |
| 70 &is_available), |
| 69 run_loop.QuitClosure()); | 71 run_loop.QuitClosure()); |
| 70 run_loop.Run(); | 72 run_loop.Run(); |
| 71 | 73 |
| 72 return is_available; | 74 return is_available; |
| 73 } | 75 } |
| 74 | 76 |
| 75 protected: | 77 protected: |
| 76 void SetUp() override { | 78 void SetUp() override { |
| 77 ChromeRenderViewHostTestHarness::SetUp(); | 79 ChromeRenderViewHostTestHarness::SetUp(); |
| 78 SiteEngagementScore::SetParamValuesForTesting(); | 80 SiteEngagementScore::SetParamValuesForTesting(); |
| 79 // Ensure that the testing profile is registered for creating a PluginPrefs. | 81 // Ensure that the testing profile is registered for creating a PluginPrefs. |
| 80 PluginPrefs::GetForTestingProfile(profile()); | 82 PluginPrefs::GetForTestingProfile(profile()); |
| 81 PluginFinder::GetInstance(); | 83 PluginFinder::GetInstance(); |
| 82 | 84 |
| 83 filter_ = ChromePluginServiceFilter::GetInstance(); | 85 filter_ = ChromePluginServiceFilter::GetInstance(); |
| 84 filter_->RegisterResourceContext(profile(), | 86 filter_->RegisterResourceContext(profile(), |
| 85 profile()->GetResourceContext()); | 87 profile()->GetResourceContext()); |
| 86 } | 88 } |
| 87 | 89 |
| 88 void IsPluginAvailableOnIOThread(const GURL& plugin_content_url, | 90 void IsPluginAvailableOnIOThread(const GURL& plugin_content_url, |
| 89 const GURL& main_url, | 91 const url::Origin& main_frame_origin, |
| 90 const void* resource_context, | 92 const void* resource_context, |
| 91 content::WebPluginInfo plugin_info, | 93 content::WebPluginInfo plugin_info, |
| 92 bool* is_available) { | 94 bool* is_available) { |
| 93 *is_available = filter_->IsPluginAvailable( | 95 *is_available = filter_->IsPluginAvailable( |
| 94 web_contents()->GetRenderProcessHost()->GetID(), | 96 web_contents()->GetRenderProcessHost()->GetID(), |
| 95 web_contents()->GetMainFrame()->GetRoutingID(), resource_context, | 97 web_contents()->GetMainFrame()->GetRoutingID(), resource_context, |
| 96 plugin_content_url, main_url, &plugin_info); | 98 plugin_content_url, main_frame_origin, &plugin_info); |
| 97 } | 99 } |
| 98 | 100 |
| 99 ChromePluginServiceFilter* filter_; | 101 ChromePluginServiceFilter* filter_; |
| 100 base::FilePath flash_plugin_path_; | 102 base::FilePath flash_plugin_path_; |
| 101 }; | 103 }; |
| 102 | 104 |
| 103 TEST_F(ChromePluginServiceFilterTest, FlashAvailableByDefault) { | 105 TEST_F(ChromePluginServiceFilterTest, FlashAvailableByDefault) { |
| 104 content::WebPluginInfo flash_plugin( | 106 content::WebPluginInfo flash_plugin( |
| 105 base::ASCIIToUTF16(content::kFlashPluginName), flash_plugin_path_, | 107 base::ASCIIToUTF16(content::kFlashPluginName), flash_plugin_path_, |
| 106 base::ASCIIToUTF16("1"), base::ASCIIToUTF16("The Flash plugin.")); | 108 base::ASCIIToUTF16("1"), base::ASCIIToUTF16("The Flash plugin.")); |
| 107 EXPECT_TRUE(IsPluginAvailable(GURL(), GURL(), profile()->GetResourceContext(), | 109 EXPECT_TRUE(IsPluginAvailable(GURL(), url::Origin(), |
| 108 flash_plugin)); | 110 profile()->GetResourceContext(), flash_plugin)); |
| 109 } | 111 } |
| 110 | 112 |
| 111 TEST_F(ChromePluginServiceFilterTest, PreferHtmlOverPluginsDefault) { | 113 TEST_F(ChromePluginServiceFilterTest, PreferHtmlOverPluginsDefault) { |
| 112 content::WebPluginInfo flash_plugin( | 114 content::WebPluginInfo flash_plugin( |
| 113 base::ASCIIToUTF16(content::kFlashPluginName), flash_plugin_path_, | 115 base::ASCIIToUTF16(content::kFlashPluginName), flash_plugin_path_, |
| 114 base::ASCIIToUTF16("1"), base::ASCIIToUTF16("The Flash plugin.")); | 116 base::ASCIIToUTF16("1"), base::ASCIIToUTF16("The Flash plugin.")); |
| 115 base::HistogramTester histograms; | 117 base::HistogramTester histograms; |
| 116 | 118 |
| 117 // Activate PreferHtmlOverPlugins. | 119 // Activate PreferHtmlOverPlugins. |
| 118 base::test::ScopedFeatureList feature_list; | 120 base::test::ScopedFeatureList feature_list; |
| 119 feature_list.InitAndEnableFeature(features::kPreferHtmlOverPlugins); | 121 feature_list.InitAndEnableFeature(features::kPreferHtmlOverPlugins); |
| 120 | 122 |
| 121 // The default content setting should block Flash, as there should be 0 | 123 // The default content setting should block Flash, as there should be 0 |
| 122 // engagement. | 124 // engagement. |
| 123 GURL url("http://www.google.com"); | 125 GURL url("http://www.google.com"); |
| 124 EXPECT_FALSE(IsPluginAvailable(url, url, profile()->GetResourceContext(), | 126 url::Origin main_frame_origin(url); |
| 125 flash_plugin)); | 127 EXPECT_FALSE(IsPluginAvailable( |
| 128 url, main_frame_origin, profile()->GetResourceContext(), flash_plugin)); |
| 126 | 129 |
| 127 histograms.ExpectUniqueSample( | 130 histograms.ExpectUniqueSample( |
| 128 ChromePluginServiceFilter::kEngagementNoSettingHistogram, 0, 1); | 131 ChromePluginServiceFilter::kEngagementNoSettingHistogram, 0, 1); |
| 129 | 132 |
| 130 // Block plugins. | 133 // Block plugins. |
| 131 HostContentSettingsMap* map = | 134 HostContentSettingsMap* map = |
| 132 HostContentSettingsMapFactory::GetForProfile(profile()); | 135 HostContentSettingsMapFactory::GetForProfile(profile()); |
| 133 map->SetDefaultContentSetting(CONTENT_SETTINGS_TYPE_PLUGINS, | 136 map->SetDefaultContentSetting(CONTENT_SETTINGS_TYPE_PLUGINS, |
| 134 CONTENT_SETTING_BLOCK); | 137 CONTENT_SETTING_BLOCK); |
| 135 | 138 |
| 136 EXPECT_FALSE(IsPluginAvailable(url, url, profile()->GetResourceContext(), | 139 EXPECT_FALSE(IsPluginAvailable( |
| 137 flash_plugin)); | 140 url, main_frame_origin, profile()->GetResourceContext(), flash_plugin)); |
| 138 | 141 |
| 139 histograms.ExpectUniqueSample( | 142 histograms.ExpectUniqueSample( |
| 140 ChromePluginServiceFilter::kEngagementNoSettingHistogram, 0, 1); | 143 ChromePluginServiceFilter::kEngagementNoSettingHistogram, 0, 1); |
| 141 histograms.ExpectUniqueSample( | 144 histograms.ExpectUniqueSample( |
| 142 ChromePluginServiceFilter::kEngagementSettingBlockedHistogram, 0, 1); | 145 ChromePluginServiceFilter::kEngagementSettingBlockedHistogram, 0, 1); |
| 143 | 146 |
| 144 // Allow plugins. | 147 // Allow plugins. |
| 145 map->SetDefaultContentSetting(CONTENT_SETTINGS_TYPE_PLUGINS, | 148 map->SetDefaultContentSetting(CONTENT_SETTINGS_TYPE_PLUGINS, |
| 146 CONTENT_SETTING_ALLOW); | 149 CONTENT_SETTING_ALLOW); |
| 147 | 150 |
| 148 EXPECT_TRUE(IsPluginAvailable(url, url, profile()->GetResourceContext(), | 151 EXPECT_TRUE(IsPluginAvailable(url, main_frame_origin, |
| 149 flash_plugin)); | 152 profile()->GetResourceContext(), flash_plugin)); |
| 150 | 153 |
| 151 histograms.ExpectUniqueSample( | 154 histograms.ExpectUniqueSample( |
| 152 ChromePluginServiceFilter::kEngagementNoSettingHistogram, 0, 1); | 155 ChromePluginServiceFilter::kEngagementNoSettingHistogram, 0, 1); |
| 153 histograms.ExpectUniqueSample( | 156 histograms.ExpectUniqueSample( |
| 154 ChromePluginServiceFilter::kEngagementSettingAllowedHistogram, 0, 1); | 157 ChromePluginServiceFilter::kEngagementSettingAllowedHistogram, 0, 1); |
| 155 histograms.ExpectUniqueSample( | 158 histograms.ExpectUniqueSample( |
| 156 ChromePluginServiceFilter::kEngagementSettingBlockedHistogram, 0, 1); | 159 ChromePluginServiceFilter::kEngagementSettingBlockedHistogram, 0, 1); |
| 157 | 160 |
| 158 // Detect important content should block on 0 engagement. | 161 // Detect important content should block on 0 engagement. |
| 159 map->SetDefaultContentSetting(CONTENT_SETTINGS_TYPE_PLUGINS, | 162 map->SetDefaultContentSetting(CONTENT_SETTINGS_TYPE_PLUGINS, |
| 160 CONTENT_SETTING_DETECT_IMPORTANT_CONTENT); | 163 CONTENT_SETTING_DETECT_IMPORTANT_CONTENT); |
| 161 | 164 |
| 162 EXPECT_FALSE(IsPluginAvailable(url, url, profile()->GetResourceContext(), | 165 EXPECT_FALSE(IsPluginAvailable( |
| 163 flash_plugin)); | 166 url, main_frame_origin, profile()->GetResourceContext(), flash_plugin)); |
| 164 | 167 |
| 165 histograms.ExpectUniqueSample( | 168 histograms.ExpectUniqueSample( |
| 166 ChromePluginServiceFilter::kEngagementNoSettingHistogram, 0, 2); | 169 ChromePluginServiceFilter::kEngagementNoSettingHistogram, 0, 2); |
| 167 histograms.ExpectUniqueSample( | 170 histograms.ExpectUniqueSample( |
| 168 ChromePluginServiceFilter::kEngagementSettingAllowedHistogram, 0, 1); | 171 ChromePluginServiceFilter::kEngagementSettingAllowedHistogram, 0, 1); |
| 169 histograms.ExpectUniqueSample( | 172 histograms.ExpectUniqueSample( |
| 170 ChromePluginServiceFilter::kEngagementSettingBlockedHistogram, 0, 1); | 173 ChromePluginServiceFilter::kEngagementSettingBlockedHistogram, 0, 1); |
| 171 } | 174 } |
| 172 | 175 |
| 173 TEST_F(ChromePluginServiceFilterTest, | 176 TEST_F(ChromePluginServiceFilterTest, |
| 174 PreferHtmlOverPluginsAllowOrBlockOverrides) { | 177 PreferHtmlOverPluginsAllowOrBlockOverrides) { |
| 175 content::WebPluginInfo flash_plugin( | 178 content::WebPluginInfo flash_plugin( |
| 176 base::ASCIIToUTF16(content::kFlashPluginName), flash_plugin_path_, | 179 base::ASCIIToUTF16(content::kFlashPluginName), flash_plugin_path_, |
| 177 base::ASCIIToUTF16("1"), base::ASCIIToUTF16("The Flash plugin.")); | 180 base::ASCIIToUTF16("1"), base::ASCIIToUTF16("The Flash plugin.")); |
| 178 base::HistogramTester histograms; | 181 base::HistogramTester histograms; |
| 179 | 182 |
| 180 // Activate PreferHtmlOverPlugins. | 183 // Activate PreferHtmlOverPlugins. |
| 181 base::test::ScopedFeatureList feature_list; | 184 base::test::ScopedFeatureList feature_list; |
| 182 feature_list.InitAndEnableFeature(features::kPreferHtmlOverPlugins); | 185 feature_list.InitAndEnableFeature(features::kPreferHtmlOverPlugins); |
| 183 | 186 |
| 184 // Allow plugins by default. | 187 // Allow plugins by default. |
| 185 HostContentSettingsMap* map = | 188 HostContentSettingsMap* map = |
| 186 HostContentSettingsMapFactory::GetForProfile(profile()); | 189 HostContentSettingsMapFactory::GetForProfile(profile()); |
| 187 map->SetDefaultContentSetting(CONTENT_SETTINGS_TYPE_PLUGINS, | 190 map->SetDefaultContentSetting(CONTENT_SETTINGS_TYPE_PLUGINS, |
| 188 CONTENT_SETTING_ALLOW); | 191 CONTENT_SETTING_ALLOW); |
| 189 | 192 |
| 190 // This should respect the content setting and be allowed. | 193 // This should respect the content setting and be allowed. |
| 191 GURL url("http://www.google.com"); | 194 GURL url("http://www.google.com"); |
| 192 EXPECT_TRUE(IsPluginAvailable(url, url, profile()->GetResourceContext(), | 195 url::Origin main_frame_origin(url); |
| 193 flash_plugin)); | 196 EXPECT_TRUE(IsPluginAvailable(url, main_frame_origin, |
| 197 profile()->GetResourceContext(), flash_plugin)); |
| 194 | 198 |
| 195 histograms.ExpectBucketCount( | 199 histograms.ExpectBucketCount( |
| 196 ChromePluginServiceFilter::kEngagementSettingAllowedHistogram, 0, 1); | 200 ChromePluginServiceFilter::kEngagementSettingAllowedHistogram, 0, 1); |
| 197 | 201 |
| 198 map->SetDefaultContentSetting(CONTENT_SETTINGS_TYPE_PLUGINS, | 202 map->SetDefaultContentSetting(CONTENT_SETTINGS_TYPE_PLUGINS, |
| 199 CONTENT_SETTING_DETECT_IMPORTANT_CONTENT); | 203 CONTENT_SETTING_DETECT_IMPORTANT_CONTENT); |
| 200 | 204 |
| 201 // This should be blocked due to 0 engagement and a detect content setting. | 205 // This should be blocked due to 0 engagement and a detect content setting. |
| 202 EXPECT_FALSE(IsPluginAvailable(url, url, profile()->GetResourceContext(), | 206 EXPECT_FALSE(IsPluginAvailable( |
| 203 flash_plugin)); | 207 url, main_frame_origin, profile()->GetResourceContext(), flash_plugin)); |
| 204 histograms.ExpectBucketCount( | 208 histograms.ExpectBucketCount( |
| 205 ChromePluginServiceFilter::kEngagementNoSettingHistogram, 0, 1); | 209 ChromePluginServiceFilter::kEngagementNoSettingHistogram, 0, 1); |
| 206 | 210 |
| 207 SiteEngagementService* service = SiteEngagementService::Get(profile()); | 211 SiteEngagementService* service = SiteEngagementService::Get(profile()); |
| 208 service->ResetScoreForURL(url, 10.0); | 212 service->ResetScoreForURL(url, 10.0); |
| 209 | 213 |
| 210 // Should still be blocked. | 214 // Should still be blocked. |
| 211 EXPECT_FALSE(IsPluginAvailable(url, url, profile()->GetResourceContext(), | 215 EXPECT_FALSE(IsPluginAvailable( |
| 212 flash_plugin)); | 216 url, main_frame_origin, profile()->GetResourceContext(), flash_plugin)); |
| 213 histograms.ExpectBucketCount( | 217 histograms.ExpectBucketCount( |
| 214 ChromePluginServiceFilter::kEngagementNoSettingHistogram, 10, 1); | 218 ChromePluginServiceFilter::kEngagementNoSettingHistogram, 10, 1); |
| 215 | 219 |
| 216 // Reaching 30.0 engagement should allow Flash. | 220 // Reaching 30.0 engagement should allow Flash. |
| 217 service->ResetScoreForURL(url, 30.0); | 221 service->ResetScoreForURL(url, 30.0); |
| 218 EXPECT_TRUE(IsPluginAvailable(url, url, profile()->GetResourceContext(), | 222 EXPECT_TRUE(IsPluginAvailable(url, main_frame_origin, |
| 219 flash_plugin)); | 223 profile()->GetResourceContext(), flash_plugin)); |
| 220 | 224 |
| 221 histograms.ExpectBucketCount( | 225 histograms.ExpectBucketCount( |
| 222 ChromePluginServiceFilter::kEngagementNoSettingHistogram, 0, 1); | 226 ChromePluginServiceFilter::kEngagementNoSettingHistogram, 0, 1); |
| 223 histograms.ExpectBucketCount( | 227 histograms.ExpectBucketCount( |
| 224 ChromePluginServiceFilter::kEngagementNoSettingHistogram, 10, 1); | 228 ChromePluginServiceFilter::kEngagementNoSettingHistogram, 10, 1); |
| 225 histograms.ExpectBucketCount( | 229 histograms.ExpectBucketCount( |
| 226 ChromePluginServiceFilter::kEngagementNoSettingHistogram, 30, 1); | 230 ChromePluginServiceFilter::kEngagementNoSettingHistogram, 30, 1); |
| 227 | 231 |
| 228 // Blocked content setting should override engagement | 232 // Blocked content setting should override engagement |
| 229 map->SetDefaultContentSetting(CONTENT_SETTINGS_TYPE_PLUGINS, | 233 map->SetDefaultContentSetting(CONTENT_SETTINGS_TYPE_PLUGINS, |
| 230 CONTENT_SETTING_BLOCK); | 234 CONTENT_SETTING_BLOCK); |
| 231 EXPECT_FALSE(IsPluginAvailable(url, url, profile()->GetResourceContext(), | 235 EXPECT_FALSE(IsPluginAvailable( |
| 232 flash_plugin)); | 236 url, main_frame_origin, profile()->GetResourceContext(), flash_plugin)); |
| 233 | 237 |
| 234 histograms.ExpectBucketCount( | 238 histograms.ExpectBucketCount( |
| 235 ChromePluginServiceFilter::kEngagementSettingBlockedHistogram, 30, 1); | 239 ChromePluginServiceFilter::kEngagementSettingBlockedHistogram, 30, 1); |
| 236 } | 240 } |
| 237 | 241 |
| 238 TEST_F(ChromePluginServiceFilterTest, PreferHtmlOverPluginsCustomEngagement) { | 242 TEST_F(ChromePluginServiceFilterTest, PreferHtmlOverPluginsCustomEngagement) { |
| 239 content::WebPluginInfo flash_plugin( | 243 content::WebPluginInfo flash_plugin( |
| 240 base::ASCIIToUTF16(content::kFlashPluginName), flash_plugin_path_, | 244 base::ASCIIToUTF16(content::kFlashPluginName), flash_plugin_path_, |
| 241 base::ASCIIToUTF16("1"), base::ASCIIToUTF16("The Flash plugin.")); | 245 base::ASCIIToUTF16("1"), base::ASCIIToUTF16("The Flash plugin.")); |
| 242 base::HistogramTester histograms; | 246 base::HistogramTester histograms; |
| (...skipping 24 matching lines...) Expand all Loading... |
| 267 EXPECT_EQ(params, actualParams); | 271 EXPECT_EQ(params, actualParams); |
| 268 | 272 |
| 269 // Set to detect important content by default. | 273 // Set to detect important content by default. |
| 270 HostContentSettingsMap* map = | 274 HostContentSettingsMap* map = |
| 271 HostContentSettingsMapFactory::GetForProfile(profile()); | 275 HostContentSettingsMapFactory::GetForProfile(profile()); |
| 272 map->SetDefaultContentSetting(CONTENT_SETTINGS_TYPE_PLUGINS, | 276 map->SetDefaultContentSetting(CONTENT_SETTINGS_TYPE_PLUGINS, |
| 273 CONTENT_SETTING_DETECT_IMPORTANT_CONTENT); | 277 CONTENT_SETTING_DETECT_IMPORTANT_CONTENT); |
| 274 | 278 |
| 275 // This should be blocked due to 0 engagement. | 279 // This should be blocked due to 0 engagement. |
| 276 GURL url("http://www.google.com"); | 280 GURL url("http://www.google.com"); |
| 277 EXPECT_FALSE(IsPluginAvailable(url, url, profile()->GetResourceContext(), | 281 url::Origin main_frame_origin(url); |
| 278 flash_plugin)); | 282 EXPECT_FALSE(IsPluginAvailable( |
| 283 url, main_frame_origin, profile()->GetResourceContext(), flash_plugin)); |
| 279 | 284 |
| 280 // Should still be blocked until engagement reaches 50. | 285 // Should still be blocked until engagement reaches 50. |
| 281 SiteEngagementService* service = SiteEngagementService::Get(profile()); | 286 SiteEngagementService* service = SiteEngagementService::Get(profile()); |
| 282 service->ResetScoreForURL(url, 0.0); | 287 service->ResetScoreForURL(url, 0.0); |
| 283 EXPECT_FALSE(IsPluginAvailable(url, url, profile()->GetResourceContext(), | 288 EXPECT_FALSE(IsPluginAvailable( |
| 284 flash_plugin)); | 289 url, main_frame_origin, profile()->GetResourceContext(), flash_plugin)); |
| 285 service->ResetScoreForURL(url, 10.0); | 290 service->ResetScoreForURL(url, 10.0); |
| 286 EXPECT_FALSE(IsPluginAvailable(url, url, profile()->GetResourceContext(), | 291 EXPECT_FALSE(IsPluginAvailable( |
| 287 flash_plugin)); | 292 url, main_frame_origin, profile()->GetResourceContext(), flash_plugin)); |
| 288 service->ResetScoreForURL(url, 40.0); | 293 service->ResetScoreForURL(url, 40.0); |
| 289 EXPECT_FALSE(IsPluginAvailable(url, url, profile()->GetResourceContext(), | 294 EXPECT_FALSE(IsPluginAvailable( |
| 290 flash_plugin)); | 295 url, main_frame_origin, profile()->GetResourceContext(), flash_plugin)); |
| 291 service->ResetScoreForURL(url, 60.0); | 296 service->ResetScoreForURL(url, 60.0); |
| 292 EXPECT_TRUE(IsPluginAvailable(url, url, profile()->GetResourceContext(), | 297 EXPECT_TRUE(IsPluginAvailable(url, main_frame_origin, |
| 293 flash_plugin)); | 298 profile()->GetResourceContext(), flash_plugin)); |
| 294 | 299 |
| 295 histograms.ExpectBucketCount( | 300 histograms.ExpectBucketCount( |
| 296 ChromePluginServiceFilter::kEngagementNoSettingHistogram, 0, 2); | 301 ChromePluginServiceFilter::kEngagementNoSettingHistogram, 0, 2); |
| 297 histograms.ExpectBucketCount( | 302 histograms.ExpectBucketCount( |
| 298 ChromePluginServiceFilter::kEngagementNoSettingHistogram, 10, 1); | 303 ChromePluginServiceFilter::kEngagementNoSettingHistogram, 10, 1); |
| 299 histograms.ExpectBucketCount( | 304 histograms.ExpectBucketCount( |
| 300 ChromePluginServiceFilter::kEngagementNoSettingHistogram, 40, 1); | 305 ChromePluginServiceFilter::kEngagementNoSettingHistogram, 40, 1); |
| 301 histograms.ExpectBucketCount( | 306 histograms.ExpectBucketCount( |
| 302 ChromePluginServiceFilter::kEngagementNoSettingHistogram, 60, 1); | 307 ChromePluginServiceFilter::kEngagementNoSettingHistogram, 60, 1); |
| 303 | 308 |
| (...skipping 14 matching lines...) Expand all Loading... |
| 318 feature_list.InitAndEnableFeature(features::kPreferHtmlOverPlugins); | 323 feature_list.InitAndEnableFeature(features::kPreferHtmlOverPlugins); |
| 319 | 324 |
| 320 // Block plugins in the original profile. This should inherit into incognito. | 325 // Block plugins in the original profile. This should inherit into incognito. |
| 321 HostContentSettingsMap* map = | 326 HostContentSettingsMap* map = |
| 322 HostContentSettingsMapFactory::GetForProfile(profile()); | 327 HostContentSettingsMapFactory::GetForProfile(profile()); |
| 323 map->SetDefaultContentSetting(CONTENT_SETTINGS_TYPE_PLUGINS, | 328 map->SetDefaultContentSetting(CONTENT_SETTINGS_TYPE_PLUGINS, |
| 324 CONTENT_SETTING_BLOCK); | 329 CONTENT_SETTING_BLOCK); |
| 325 | 330 |
| 326 // We should fail the availablity check in incognito. | 331 // We should fail the availablity check in incognito. |
| 327 GURL url("http://www.google.com"); | 332 GURL url("http://www.google.com"); |
| 328 EXPECT_FALSE(IsPluginAvailable(url, url, incognito->GetResourceContext(), | 333 url::Origin main_frame_origin(url); |
| 329 flash_plugin)); | 334 EXPECT_FALSE(IsPluginAvailable( |
| 335 url, main_frame_origin, incognito->GetResourceContext(), flash_plugin)); |
| 330 | 336 |
| 331 // Add sufficient engagement to allow Flash in the original profile. | 337 // Add sufficient engagement to allow Flash in the original profile. |
| 332 SiteEngagementService* service = SiteEngagementService::Get(profile()); | 338 SiteEngagementService* service = SiteEngagementService::Get(profile()); |
| 333 service->ResetScoreForURL(url, 30.0); | 339 service->ResetScoreForURL(url, 30.0); |
| 334 | 340 |
| 335 // We should still fail the engagement check due to the block. | 341 // We should still fail the engagement check due to the block. |
| 336 EXPECT_FALSE(IsPluginAvailable(url, url, incognito->GetResourceContext(), | 342 EXPECT_FALSE(IsPluginAvailable( |
| 337 flash_plugin)); | 343 url, main_frame_origin, incognito->GetResourceContext(), flash_plugin)); |
| 338 | 344 |
| 339 // Change to detect important content in the original profile. | 345 // Change to detect important content in the original profile. |
| 340 map->SetDefaultContentSetting(CONTENT_SETTINGS_TYPE_PLUGINS, | 346 map->SetDefaultContentSetting(CONTENT_SETTINGS_TYPE_PLUGINS, |
| 341 CONTENT_SETTING_DETECT_IMPORTANT_CONTENT); | 347 CONTENT_SETTING_DETECT_IMPORTANT_CONTENT); |
| 342 | 348 |
| 343 // Ensure we pass the engagement check in the incognito profile (i.e. it falls | 349 // Ensure we pass the engagement check in the incognito profile (i.e. it falls |
| 344 // back to checking engagement from the original profile when nothing is found | 350 // back to checking engagement from the original profile when nothing is found |
| 345 // in the incognito profile). | 351 // in the incognito profile). |
| 346 EXPECT_TRUE(IsPluginAvailable(url, url, incognito->GetResourceContext(), | 352 EXPECT_TRUE(IsPluginAvailable(url, main_frame_origin, |
| 347 flash_plugin)); | 353 incognito->GetResourceContext(), flash_plugin)); |
| 348 } | 354 } |
| 349 | 355 |
| 350 TEST_F(ChromePluginServiceFilterTest, | 356 TEST_F(ChromePluginServiceFilterTest, |
| 351 PreferHtmlOverPluginsIncognitoAllowToDetect) { | 357 PreferHtmlOverPluginsIncognitoAllowToDetect) { |
| 352 Profile* incognito = profile()->GetOffTheRecordProfile(); | 358 Profile* incognito = profile()->GetOffTheRecordProfile(); |
| 353 filter_->RegisterResourceContext(incognito, incognito->GetResourceContext()); | 359 filter_->RegisterResourceContext(incognito, incognito->GetResourceContext()); |
| 354 | 360 |
| 355 content::WebPluginInfo flash_plugin( | 361 content::WebPluginInfo flash_plugin( |
| 356 base::ASCIIToUTF16(content::kFlashPluginName), flash_plugin_path_, | 362 base::ASCIIToUTF16(content::kFlashPluginName), flash_plugin_path_, |
| 357 base::ASCIIToUTF16("1"), base::ASCIIToUTF16("The Flash plugin.")); | 363 base::ASCIIToUTF16("1"), base::ASCIIToUTF16("The Flash plugin.")); |
| 358 | 364 |
| 359 // Activate PreferHtmlOverPlugins. | 365 // Activate PreferHtmlOverPlugins. |
| 360 base::test::ScopedFeatureList feature_list; | 366 base::test::ScopedFeatureList feature_list; |
| 361 feature_list.InitAndEnableFeature(features::kPreferHtmlOverPlugins); | 367 feature_list.InitAndEnableFeature(features::kPreferHtmlOverPlugins); |
| 362 | 368 |
| 363 // Allow plugins in the original profile. | 369 // Allow plugins in the original profile. |
| 364 HostContentSettingsMap* map = | 370 HostContentSettingsMap* map = |
| 365 HostContentSettingsMapFactory::GetForProfile(profile()); | 371 HostContentSettingsMapFactory::GetForProfile(profile()); |
| 366 map->SetDefaultContentSetting(CONTENT_SETTINGS_TYPE_PLUGINS, | 372 map->SetDefaultContentSetting(CONTENT_SETTINGS_TYPE_PLUGINS, |
| 367 CONTENT_SETTING_ALLOW); | 373 CONTENT_SETTING_ALLOW); |
| 368 | 374 |
| 369 // We pass the availablity check in incognito based on the original content | 375 // We pass the availablity check in incognito based on the original content |
| 370 // setting. | 376 // setting. |
| 371 GURL url("http://www.google.com"); | 377 GURL url("http://www.google.com"); |
| 372 EXPECT_TRUE(IsPluginAvailable(url, url, incognito->GetResourceContext(), | 378 url::Origin main_frame_origin(url); |
| 373 flash_plugin)); | 379 EXPECT_TRUE(IsPluginAvailable(url, main_frame_origin, |
| 380 incognito->GetResourceContext(), flash_plugin)); |
| 374 | 381 |
| 375 map->SetDefaultContentSetting(CONTENT_SETTINGS_TYPE_PLUGINS, | 382 map->SetDefaultContentSetting(CONTENT_SETTINGS_TYPE_PLUGINS, |
| 376 CONTENT_SETTING_DETECT_IMPORTANT_CONTENT); | 383 CONTENT_SETTING_DETECT_IMPORTANT_CONTENT); |
| 377 | 384 |
| 378 // Now we fail the availability check due to the content setting carrying | 385 // Now we fail the availability check due to the content setting carrying |
| 379 // over. | 386 // over. |
| 380 EXPECT_FALSE(IsPluginAvailable(url, url, incognito->GetResourceContext(), | 387 EXPECT_FALSE(IsPluginAvailable( |
| 381 flash_plugin)); | 388 url, main_frame_origin, incognito->GetResourceContext(), flash_plugin)); |
| 382 | 389 |
| 383 // Add sufficient engagement to allow Flash in the incognito profile. | 390 // Add sufficient engagement to allow Flash in the incognito profile. |
| 384 SiteEngagementService* service = SiteEngagementService::Get(incognito); | 391 SiteEngagementService* service = SiteEngagementService::Get(incognito); |
| 385 service->ResetScoreForURL(url, 30.0); | 392 service->ResetScoreForURL(url, 30.0); |
| 386 | 393 |
| 387 // Ensure we pass the engagement check in the incognito profile. | 394 // Ensure we pass the engagement check in the incognito profile. |
| 388 EXPECT_TRUE(IsPluginAvailable(url, url, incognito->GetResourceContext(), | 395 EXPECT_TRUE(IsPluginAvailable(url, main_frame_origin, |
| 389 flash_plugin)); | 396 incognito->GetResourceContext(), flash_plugin)); |
| 390 } | 397 } |
| 391 | 398 |
| 392 TEST_F(ChromePluginServiceFilterTest, BlockIfManagedSetting) { | 399 TEST_F(ChromePluginServiceFilterTest, BlockIfManagedSetting) { |
| 393 content::WebPluginInfo flash_plugin( | 400 content::WebPluginInfo flash_plugin( |
| 394 base::ASCIIToUTF16(content::kFlashPluginName), flash_plugin_path_, | 401 base::ASCIIToUTF16(content::kFlashPluginName), flash_plugin_path_, |
| 395 base::ASCIIToUTF16("1"), base::ASCIIToUTF16("The Flash plugin.")); | 402 base::ASCIIToUTF16("1"), base::ASCIIToUTF16("The Flash plugin.")); |
| 396 base::HistogramTester histograms; | 403 base::HistogramTester histograms; |
| 397 | 404 |
| 398 // Activate PreferHtmlOverPlugins. | 405 // Activate PreferHtmlOverPlugins. |
| 399 base::test::ScopedFeatureList feature_list; | 406 base::test::ScopedFeatureList feature_list; |
| 400 feature_list.InitAndEnableFeature(features::kPreferHtmlOverPlugins); | 407 feature_list.InitAndEnableFeature(features::kPreferHtmlOverPlugins); |
| 401 | 408 |
| 402 HostContentSettingsMap* map = | 409 HostContentSettingsMap* map = |
| 403 HostContentSettingsMapFactory::GetForProfile(profile()); | 410 HostContentSettingsMapFactory::GetForProfile(profile()); |
| 404 map->SetDefaultContentSetting(CONTENT_SETTINGS_TYPE_PLUGINS, | 411 map->SetDefaultContentSetting(CONTENT_SETTINGS_TYPE_PLUGINS, |
| 405 CONTENT_SETTING_DETECT_IMPORTANT_CONTENT); | 412 CONTENT_SETTING_DETECT_IMPORTANT_CONTENT); |
| 406 | 413 |
| 407 SiteEngagementService* service = SiteEngagementService::Get(profile()); | 414 SiteEngagementService* service = SiteEngagementService::Get(profile()); |
| 408 // Reaching 30.0 engagement should allow Flash. | 415 // Reaching 30.0 engagement should allow Flash. |
| 409 GURL url("http://www.google.com"); | 416 GURL url("http://www.google.com"); |
| 417 url::Origin main_frame_origin(url); |
| 410 service->ResetScoreForURL(url, 30.0); | 418 service->ResetScoreForURL(url, 30.0); |
| 411 EXPECT_TRUE(IsPluginAvailable(url, url, profile()->GetResourceContext(), | 419 EXPECT_TRUE(IsPluginAvailable(url, main_frame_origin, |
| 412 flash_plugin)); | 420 profile()->GetResourceContext(), flash_plugin)); |
| 413 histograms.ExpectUniqueSample( | 421 histograms.ExpectUniqueSample( |
| 414 ChromePluginServiceFilter::kEngagementNoSettingHistogram, 30, 1); | 422 ChromePluginServiceFilter::kEngagementNoSettingHistogram, 30, 1); |
| 415 | 423 |
| 416 // Enterprise ASK setting should block Flash from being advertised. | 424 // Enterprise ASK setting should block Flash from being advertised. |
| 417 syncable_prefs::TestingPrefServiceSyncable* prefs = | 425 syncable_prefs::TestingPrefServiceSyncable* prefs = |
| 418 profile()->GetTestingPrefService(); | 426 profile()->GetTestingPrefService(); |
| 419 prefs->SetManagedPref(prefs::kManagedDefaultPluginsSetting, | 427 prefs->SetManagedPref(prefs::kManagedDefaultPluginsSetting, |
| 420 new base::FundamentalValue(CONTENT_SETTING_ASK)); | 428 new base::FundamentalValue(CONTENT_SETTING_ASK)); |
| 421 | 429 EXPECT_FALSE(IsPluginAvailable( |
| 422 EXPECT_FALSE(IsPluginAvailable(url, url, profile()->GetResourceContext(), | 430 url, main_frame_origin, profile()->GetResourceContext(), flash_plugin)); |
| 423 flash_plugin)); | |
| 424 histograms.ExpectUniqueSample( | 431 histograms.ExpectUniqueSample( |
| 425 ChromePluginServiceFilter::kEngagementNoSettingHistogram, 30, 2); | 432 ChromePluginServiceFilter::kEngagementNoSettingHistogram, 30, 2); |
| 426 } | 433 } |
| OLD | NEW |