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 18 matching lines...) Expand all Loading... |
29 #include "components/content_settings/core/browser/host_content_settings_map.h" | 29 #include "components/content_settings/core/browser/host_content_settings_map.h" |
30 #include "components/content_settings/core/common/pref_names.h" | 30 #include "components/content_settings/core/common/pref_names.h" |
31 #include "components/syncable_prefs/testing_pref_service_syncable.h" | 31 #include "components/syncable_prefs/testing_pref_service_syncable.h" |
32 #include "components/variations/variations_associated_data.h" | 32 #include "components/variations/variations_associated_data.h" |
33 #include "content/public/browser/browser_thread.h" | 33 #include "content/public/browser/browser_thread.h" |
34 #include "content/public/browser/plugin_service.h" | 34 #include "content/public/browser/plugin_service.h" |
35 #include "content/public/browser/render_process_host.h" | 35 #include "content/public/browser/render_process_host.h" |
36 #include "content/public/browser/web_contents.h" | 36 #include "content/public/browser/web_contents.h" |
37 #include "content/public/common/content_constants.h" | 37 #include "content/public/common/content_constants.h" |
38 #include "content/public/test/test_utils.h" | 38 #include "content/public/test/test_utils.h" |
| 39 #include "url/origin.h" |
39 | 40 |
40 namespace { | 41 namespace { |
41 | 42 |
42 const char kTrialName[] = "PreferHtmlOverPlugins"; | 43 const char kTrialName[] = "PreferHtmlOverPlugins"; |
43 const char kGroupName[] = "Group1"; | 44 const char kGroupName[] = "Group1"; |
44 | 45 |
45 } // namespace | 46 } // namespace |
46 | 47 |
47 class ChromePluginServiceFilterTest : public ChromeRenderViewHostTestHarness { | 48 class ChromePluginServiceFilterTest : public ChromeRenderViewHostTestHarness { |
48 public: | 49 public: |
49 ChromePluginServiceFilterTest() | 50 ChromePluginServiceFilterTest() |
50 : ChromeRenderViewHostTestHarness(), | 51 : ChromeRenderViewHostTestHarness(), |
51 filter_(nullptr), | 52 filter_(nullptr), |
52 flash_plugin_path_(FILE_PATH_LITERAL("/path/to/flash")) {} | 53 flash_plugin_path_(FILE_PATH_LITERAL("/path/to/flash")) {} |
53 | 54 |
54 bool IsPluginAvailable(const GURL& plugin_content_url, | 55 bool IsPluginAvailable(const GURL& plugin_content_url, |
55 const GURL& main_url, | 56 const url::Origin& main_url, |
56 const void* resource_context, | 57 const void* resource_context, |
57 const content::WebPluginInfo& plugin_info) { | 58 const content::WebPluginInfo& plugin_info) { |
58 bool is_available = false; | 59 bool is_available = false; |
59 | 60 |
60 // ChromePluginServiceFilter::IsPluginAvailable always runs on the IO | 61 // ChromePluginServiceFilter::IsPluginAvailable always runs on the IO |
61 // thread. Use a RunLoop to ensure this method blocks until it posts back. | 62 // thread. Use a RunLoop to ensure this method blocks until it posts back. |
62 base::RunLoop run_loop; | 63 base::RunLoop run_loop; |
63 content::BrowserThread::PostTaskAndReply( | 64 content::BrowserThread::PostTaskAndReply( |
64 content::BrowserThread::IO, FROM_HERE, | 65 content::BrowserThread::IO, FROM_HERE, |
65 base::Bind(&ChromePluginServiceFilterTest::IsPluginAvailableOnIOThread, | 66 base::Bind(&ChromePluginServiceFilterTest::IsPluginAvailableOnIOThread, |
(...skipping 12 matching lines...) Expand all Loading... |
78 // Ensure that the testing profile is registered for creating a PluginPrefs. | 79 // Ensure that the testing profile is registered for creating a PluginPrefs. |
79 PluginPrefs::GetForTestingProfile(profile()); | 80 PluginPrefs::GetForTestingProfile(profile()); |
80 PluginFinder::GetInstance(); | 81 PluginFinder::GetInstance(); |
81 | 82 |
82 filter_ = ChromePluginServiceFilter::GetInstance(); | 83 filter_ = ChromePluginServiceFilter::GetInstance(); |
83 filter_->RegisterResourceContext(profile(), | 84 filter_->RegisterResourceContext(profile(), |
84 profile()->GetResourceContext()); | 85 profile()->GetResourceContext()); |
85 } | 86 } |
86 | 87 |
87 void IsPluginAvailableOnIOThread(const GURL& plugin_content_url, | 88 void IsPluginAvailableOnIOThread(const GURL& plugin_content_url, |
88 const GURL& main_url, | 89 const url::Origin& main_url, |
89 const void* resource_context, | 90 const void* resource_context, |
90 content::WebPluginInfo plugin_info, | 91 content::WebPluginInfo plugin_info, |
91 bool* is_available) { | 92 bool* is_available) { |
92 *is_available = filter_->IsPluginAvailable( | 93 *is_available = filter_->IsPluginAvailable( |
93 web_contents()->GetRenderProcessHost()->GetID(), | 94 web_contents()->GetRenderProcessHost()->GetID(), |
94 web_contents()->GetMainFrame()->GetRoutingID(), resource_context, | 95 web_contents()->GetMainFrame()->GetRoutingID(), resource_context, |
95 plugin_content_url, main_url, &plugin_info); | 96 plugin_content_url, main_url, &plugin_info); |
96 } | 97 } |
97 | 98 |
98 ChromePluginServiceFilter* filter_; | 99 ChromePluginServiceFilter* filter_; |
99 base::FilePath flash_plugin_path_; | 100 base::FilePath flash_plugin_path_; |
100 }; | 101 }; |
101 | 102 |
102 TEST_F(ChromePluginServiceFilterTest, FlashAvailableByDefault) { | 103 TEST_F(ChromePluginServiceFilterTest, FlashAvailableByDefault) { |
103 content::WebPluginInfo flash_plugin( | 104 content::WebPluginInfo flash_plugin( |
104 base::ASCIIToUTF16(content::kFlashPluginName), flash_plugin_path_, | 105 base::ASCIIToUTF16(content::kFlashPluginName), flash_plugin_path_, |
105 base::ASCIIToUTF16("1"), base::ASCIIToUTF16("The Flash plugin.")); | 106 base::ASCIIToUTF16("1"), base::ASCIIToUTF16("The Flash plugin.")); |
106 EXPECT_TRUE(IsPluginAvailable(GURL(), GURL(), profile()->GetResourceContext(), | 107 EXPECT_TRUE(IsPluginAvailable(GURL(), url::Origin(), |
107 flash_plugin)); | 108 profile()->GetResourceContext(), flash_plugin)); |
108 } | 109 } |
109 | 110 |
110 TEST_F(ChromePluginServiceFilterTest, PreferHtmlOverPluginsDefault) { | 111 TEST_F(ChromePluginServiceFilterTest, PreferHtmlOverPluginsDefault) { |
111 content::WebPluginInfo flash_plugin( | 112 content::WebPluginInfo flash_plugin( |
112 base::ASCIIToUTF16(content::kFlashPluginName), flash_plugin_path_, | 113 base::ASCIIToUTF16(content::kFlashPluginName), flash_plugin_path_, |
113 base::ASCIIToUTF16("1"), base::ASCIIToUTF16("The Flash plugin.")); | 114 base::ASCIIToUTF16("1"), base::ASCIIToUTF16("The Flash plugin.")); |
114 | 115 |
115 // Activate PreferHtmlOverPlugins. | 116 // Activate PreferHtmlOverPlugins. |
116 base::test::ScopedFeatureList feature_list; | 117 base::test::ScopedFeatureList feature_list; |
117 feature_list.InitAndEnableFeature(features::kPreferHtmlOverPlugins); | 118 feature_list.InitAndEnableFeature(features::kPreferHtmlOverPlugins); |
118 | 119 |
119 // The default content setting should block Flash, as there should be 0 | 120 // The default content setting should block Flash, as there should be 0 |
120 // engagement. | 121 // engagement. |
121 GURL url("http://www.google.com"); | 122 GURL url("http://www.google.com"); |
122 EXPECT_FALSE(IsPluginAvailable(url, url, profile()->GetResourceContext(), | 123 url::Origin main_frame_origin(url); |
123 flash_plugin)); | 124 EXPECT_FALSE(IsPluginAvailable( |
| 125 url, main_frame_origin, profile()->GetResourceContext(), flash_plugin)); |
124 | 126 |
125 // Block plugins. | 127 // Block plugins. |
126 HostContentSettingsMap* map = | 128 HostContentSettingsMap* map = |
127 HostContentSettingsMapFactory::GetForProfile(profile()); | 129 HostContentSettingsMapFactory::GetForProfile(profile()); |
128 map->SetDefaultContentSetting(CONTENT_SETTINGS_TYPE_PLUGINS, | 130 map->SetDefaultContentSetting(CONTENT_SETTINGS_TYPE_PLUGINS, |
129 CONTENT_SETTING_BLOCK); | 131 CONTENT_SETTING_BLOCK); |
130 | 132 |
131 EXPECT_FALSE(IsPluginAvailable(url, url, profile()->GetResourceContext(), | 133 EXPECT_FALSE(IsPluginAvailable( |
132 flash_plugin)); | 134 url, main_frame_origin, profile()->GetResourceContext(), flash_plugin)); |
133 | 135 |
134 // Allow plugins. | 136 // Allow plugins. |
135 map->SetDefaultContentSetting(CONTENT_SETTINGS_TYPE_PLUGINS, | 137 map->SetDefaultContentSetting(CONTENT_SETTINGS_TYPE_PLUGINS, |
136 CONTENT_SETTING_ALLOW); | 138 CONTENT_SETTING_ALLOW); |
137 | 139 |
138 EXPECT_TRUE(IsPluginAvailable(url, url, profile()->GetResourceContext(), | 140 EXPECT_TRUE(IsPluginAvailable(url, main_frame_origin, |
139 flash_plugin)); | 141 profile()->GetResourceContext(), flash_plugin)); |
140 | 142 |
141 // Detect important content should block on 0 engagement. | 143 // Detect important content should block on 0 engagement. |
142 map->SetDefaultContentSetting(CONTENT_SETTINGS_TYPE_PLUGINS, | 144 map->SetDefaultContentSetting(CONTENT_SETTINGS_TYPE_PLUGINS, |
143 CONTENT_SETTING_DETECT_IMPORTANT_CONTENT); | 145 CONTENT_SETTING_DETECT_IMPORTANT_CONTENT); |
144 | 146 |
145 EXPECT_FALSE(IsPluginAvailable(url, url, profile()->GetResourceContext(), | 147 EXPECT_FALSE(IsPluginAvailable( |
146 flash_plugin)); | 148 url, main_frame_origin, profile()->GetResourceContext(), flash_plugin)); |
147 } | 149 } |
148 | 150 |
149 TEST_F(ChromePluginServiceFilterTest, | 151 TEST_F(ChromePluginServiceFilterTest, |
150 PreferHtmlOverPluginsAllowOrBlockOverrides) { | 152 PreferHtmlOverPluginsAllowOrBlockOverrides) { |
151 content::WebPluginInfo flash_plugin( | 153 content::WebPluginInfo flash_plugin( |
152 base::ASCIIToUTF16(content::kFlashPluginName), flash_plugin_path_, | 154 base::ASCIIToUTF16(content::kFlashPluginName), flash_plugin_path_, |
153 base::ASCIIToUTF16("1"), base::ASCIIToUTF16("The Flash plugin.")); | 155 base::ASCIIToUTF16("1"), base::ASCIIToUTF16("The Flash plugin.")); |
154 | 156 |
155 // Activate PreferHtmlOverPlugins. | 157 // Activate PreferHtmlOverPlugins. |
156 base::test::ScopedFeatureList feature_list; | 158 base::test::ScopedFeatureList feature_list; |
157 feature_list.InitAndEnableFeature(features::kPreferHtmlOverPlugins); | 159 feature_list.InitAndEnableFeature(features::kPreferHtmlOverPlugins); |
158 | 160 |
159 // Allow plugins by default. | 161 // Allow plugins by default. |
160 HostContentSettingsMap* map = | 162 HostContentSettingsMap* map = |
161 HostContentSettingsMapFactory::GetForProfile(profile()); | 163 HostContentSettingsMapFactory::GetForProfile(profile()); |
162 map->SetDefaultContentSetting(CONTENT_SETTINGS_TYPE_PLUGINS, | 164 map->SetDefaultContentSetting(CONTENT_SETTINGS_TYPE_PLUGINS, |
163 CONTENT_SETTING_ALLOW); | 165 CONTENT_SETTING_ALLOW); |
164 | 166 |
165 // This should respect the content setting and be allowed. | 167 // This should respect the content setting and be allowed. |
166 GURL url("http://www.google.com"); | 168 GURL url("http://www.google.com"); |
167 EXPECT_TRUE(IsPluginAvailable(url, url, profile()->GetResourceContext(), | 169 url::Origin main_frame_origin(url); |
168 flash_plugin)); | 170 EXPECT_TRUE(IsPluginAvailable(url, main_frame_origin, |
| 171 profile()->GetResourceContext(), flash_plugin)); |
169 | 172 |
170 map->SetDefaultContentSetting(CONTENT_SETTINGS_TYPE_PLUGINS, | 173 map->SetDefaultContentSetting(CONTENT_SETTINGS_TYPE_PLUGINS, |
171 CONTENT_SETTING_DETECT_IMPORTANT_CONTENT); | 174 CONTENT_SETTING_DETECT_IMPORTANT_CONTENT); |
172 | 175 |
173 // This should be blocked due to 0 engagement and a detect content setting. | 176 // This should be blocked due to 0 engagement and a detect content setting. |
174 EXPECT_FALSE(IsPluginAvailable(url, url, profile()->GetResourceContext(), | 177 EXPECT_FALSE(IsPluginAvailable( |
175 flash_plugin)); | 178 url, main_frame_origin, profile()->GetResourceContext(), flash_plugin)); |
176 | 179 |
177 SiteEngagementService* service = SiteEngagementService::Get(profile()); | 180 SiteEngagementService* service = SiteEngagementService::Get(profile()); |
178 service->ResetScoreForURL(url, 0.5); | 181 service->ResetScoreForURL(url, 0.5); |
179 | 182 |
180 // Should still be blocked. | 183 // Should still be blocked. |
181 EXPECT_FALSE(IsPluginAvailable(url, url, profile()->GetResourceContext(), | 184 EXPECT_FALSE(IsPluginAvailable( |
182 flash_plugin)); | 185 url, main_frame_origin, profile()->GetResourceContext(), flash_plugin)); |
183 | 186 |
184 // Reaching 1.0 engagement should allow Flash. | 187 // Reaching 1.0 engagement should allow Flash. |
185 service->ResetScoreForURL(url, 1.0); | 188 service->ResetScoreForURL(url, 1.0); |
186 EXPECT_TRUE(IsPluginAvailable(url, url, profile()->GetResourceContext(), | 189 EXPECT_TRUE(IsPluginAvailable(url, main_frame_origin, |
187 flash_plugin)); | 190 profile()->GetResourceContext(), flash_plugin)); |
188 | 191 |
189 // Blocked content setting should override engagement | 192 // Blocked content setting should override engagement |
190 map->SetDefaultContentSetting(CONTENT_SETTINGS_TYPE_PLUGINS, | 193 map->SetDefaultContentSetting(CONTENT_SETTINGS_TYPE_PLUGINS, |
191 CONTENT_SETTING_BLOCK); | 194 CONTENT_SETTING_BLOCK); |
192 EXPECT_FALSE(IsPluginAvailable(url, url, profile()->GetResourceContext(), | 195 EXPECT_FALSE(IsPluginAvailable( |
193 flash_plugin)); | 196 url, main_frame_origin, profile()->GetResourceContext(), flash_plugin)); |
194 } | 197 } |
195 | 198 |
196 TEST_F(ChromePluginServiceFilterTest, PreferHtmlOverPluginsCustomEngagement) { | 199 TEST_F(ChromePluginServiceFilterTest, PreferHtmlOverPluginsCustomEngagement) { |
197 content::WebPluginInfo flash_plugin( | 200 content::WebPluginInfo flash_plugin( |
198 base::ASCIIToUTF16(content::kFlashPluginName), flash_plugin_path_, | 201 base::ASCIIToUTF16(content::kFlashPluginName), flash_plugin_path_, |
199 base::ASCIIToUTF16("1"), base::ASCIIToUTF16("The Flash plugin.")); | 202 base::ASCIIToUTF16("1"), base::ASCIIToUTF16("The Flash plugin.")); |
200 | 203 |
201 // Activate PreferHtmlOverPlugins and set a custom variation value in the | 204 // Activate PreferHtmlOverPlugins and set a custom variation value in the |
202 // feature. | 205 // feature. |
203 base::FieldTrialList field_trials_(nullptr); | 206 base::FieldTrialList field_trials_(nullptr); |
(...skipping 20 matching lines...) Expand all Loading... |
224 EXPECT_EQ(params, actualParams); | 227 EXPECT_EQ(params, actualParams); |
225 | 228 |
226 // Set to detect important content by default. | 229 // Set to detect important content by default. |
227 HostContentSettingsMap* map = | 230 HostContentSettingsMap* map = |
228 HostContentSettingsMapFactory::GetForProfile(profile()); | 231 HostContentSettingsMapFactory::GetForProfile(profile()); |
229 map->SetDefaultContentSetting(CONTENT_SETTINGS_TYPE_PLUGINS, | 232 map->SetDefaultContentSetting(CONTENT_SETTINGS_TYPE_PLUGINS, |
230 CONTENT_SETTING_DETECT_IMPORTANT_CONTENT); | 233 CONTENT_SETTING_DETECT_IMPORTANT_CONTENT); |
231 | 234 |
232 // This should be blocked due to 0 engagement. | 235 // This should be blocked due to 0 engagement. |
233 GURL url("http://www.google.com"); | 236 GURL url("http://www.google.com"); |
234 EXPECT_FALSE(IsPluginAvailable(url, url, profile()->GetResourceContext(), | 237 url::Origin main_frame_origin(url); |
235 flash_plugin)); | 238 EXPECT_FALSE(IsPluginAvailable( |
| 239 url, main_frame_origin, profile()->GetResourceContext(), flash_plugin)); |
236 | 240 |
237 // Should still be blocked until engagement reaches 4. | 241 // Should still be blocked until engagement reaches 4. |
238 SiteEngagementService* service = SiteEngagementService::Get(profile()); | 242 SiteEngagementService* service = SiteEngagementService::Get(profile()); |
239 service->ResetScoreForURL(url, 0.5); | 243 service->ResetScoreForURL(url, 0.5); |
240 EXPECT_FALSE(IsPluginAvailable(url, url, profile()->GetResourceContext(), | 244 EXPECT_FALSE(IsPluginAvailable( |
241 flash_plugin)); | 245 url, main_frame_origin, profile()->GetResourceContext(), flash_plugin)); |
242 service->ResetScoreForURL(url, 2.0); | 246 service->ResetScoreForURL(url, 2.0); |
243 EXPECT_FALSE(IsPluginAvailable(url, url, profile()->GetResourceContext(), | 247 EXPECT_FALSE(IsPluginAvailable( |
244 flash_plugin)); | 248 url, main_frame_origin, profile()->GetResourceContext(), flash_plugin)); |
245 service->ResetScoreForURL(url, 3.0); | 249 service->ResetScoreForURL(url, 3.0); |
246 EXPECT_FALSE(IsPluginAvailable(url, url, profile()->GetResourceContext(), | 250 EXPECT_FALSE(IsPluginAvailable( |
247 flash_plugin)); | 251 url, main_frame_origin, profile()->GetResourceContext(), flash_plugin)); |
248 service->ResetScoreForURL(url, 4.0); | 252 service->ResetScoreForURL(url, 4.0); |
249 EXPECT_TRUE(IsPluginAvailable(url, url, profile()->GetResourceContext(), | 253 EXPECT_TRUE(IsPluginAvailable(url, main_frame_origin, |
250 flash_plugin)); | 254 profile()->GetResourceContext(), flash_plugin)); |
251 | 255 |
252 variations::testing::ClearAllVariationParams(); | 256 variations::testing::ClearAllVariationParams(); |
253 } | 257 } |
254 | 258 |
255 TEST_F(ChromePluginServiceFilterTest, | 259 TEST_F(ChromePluginServiceFilterTest, |
256 PreferHtmlOverPluginsIncognitoBlockToDetect) { | 260 PreferHtmlOverPluginsIncognitoBlockToDetect) { |
257 Profile* incognito = profile()->GetOffTheRecordProfile(); | 261 Profile* incognito = profile()->GetOffTheRecordProfile(); |
258 filter_->RegisterResourceContext(incognito, incognito->GetResourceContext()); | 262 filter_->RegisterResourceContext(incognito, incognito->GetResourceContext()); |
259 | 263 |
260 content::WebPluginInfo flash_plugin( | 264 content::WebPluginInfo flash_plugin( |
261 base::ASCIIToUTF16(content::kFlashPluginName), flash_plugin_path_, | 265 base::ASCIIToUTF16(content::kFlashPluginName), flash_plugin_path_, |
262 base::ASCIIToUTF16("1"), base::ASCIIToUTF16("The Flash plugin.")); | 266 base::ASCIIToUTF16("1"), base::ASCIIToUTF16("The Flash plugin.")); |
263 | 267 |
264 // Activate PreferHtmlOverPlugins. | 268 // Activate PreferHtmlOverPlugins. |
265 base::test::ScopedFeatureList feature_list; | 269 base::test::ScopedFeatureList feature_list; |
266 feature_list.InitAndEnableFeature(features::kPreferHtmlOverPlugins); | 270 feature_list.InitAndEnableFeature(features::kPreferHtmlOverPlugins); |
267 | 271 |
268 // Block plugins in the original profile. This should inherit into incognito. | 272 // Block plugins in the original profile. This should inherit into incognito. |
269 HostContentSettingsMap* map = | 273 HostContentSettingsMap* map = |
270 HostContentSettingsMapFactory::GetForProfile(profile()); | 274 HostContentSettingsMapFactory::GetForProfile(profile()); |
271 map->SetDefaultContentSetting(CONTENT_SETTINGS_TYPE_PLUGINS, | 275 map->SetDefaultContentSetting(CONTENT_SETTINGS_TYPE_PLUGINS, |
272 CONTENT_SETTING_BLOCK); | 276 CONTENT_SETTING_BLOCK); |
273 | 277 |
274 // We should fail the availablity check in incognito. | 278 // We should fail the availablity check in incognito. |
275 GURL url("http://www.google.com"); | 279 GURL url("http://www.google.com"); |
276 EXPECT_FALSE(IsPluginAvailable(url, url, incognito->GetResourceContext(), | 280 url::Origin main_frame_origin(url); |
277 flash_plugin)); | 281 EXPECT_FALSE(IsPluginAvailable( |
| 282 url, main_frame_origin, incognito->GetResourceContext(), flash_plugin)); |
278 | 283 |
279 // Add sufficient engagement to allow Flash in the original profile. | 284 // Add sufficient engagement to allow Flash in the original profile. |
280 SiteEngagementService* service = SiteEngagementService::Get(profile()); | 285 SiteEngagementService* service = SiteEngagementService::Get(profile()); |
281 service->ResetScoreForURL(url, 1.0); | 286 service->ResetScoreForURL(url, 1.0); |
282 | 287 |
283 // We should still fail the engagement check due to the block. | 288 // We should still fail the engagement check due to the block. |
284 EXPECT_FALSE(IsPluginAvailable(url, url, incognito->GetResourceContext(), | 289 EXPECT_FALSE(IsPluginAvailable( |
285 flash_plugin)); | 290 url, main_frame_origin, incognito->GetResourceContext(), flash_plugin)); |
286 | 291 |
287 // Change to detect important content in the original profile. | 292 // Change to detect important content in the original profile. |
288 map->SetDefaultContentSetting(CONTENT_SETTINGS_TYPE_PLUGINS, | 293 map->SetDefaultContentSetting(CONTENT_SETTINGS_TYPE_PLUGINS, |
289 CONTENT_SETTING_DETECT_IMPORTANT_CONTENT); | 294 CONTENT_SETTING_DETECT_IMPORTANT_CONTENT); |
290 | 295 |
291 // Ensure we pass the engagement check in the incognito profile (i.e. it falls | 296 // Ensure we pass the engagement check in the incognito profile (i.e. it falls |
292 // back to checking engagement from the original profile when nothing is found | 297 // back to checking engagement from the original profile when nothing is found |
293 // in the incognito profile). | 298 // in the incognito profile). |
294 EXPECT_TRUE(IsPluginAvailable(url, url, incognito->GetResourceContext(), | 299 EXPECT_TRUE(IsPluginAvailable(url, main_frame_origin, |
295 flash_plugin)); | 300 incognito->GetResourceContext(), flash_plugin)); |
296 } | 301 } |
297 | 302 |
298 TEST_F(ChromePluginServiceFilterTest, | 303 TEST_F(ChromePluginServiceFilterTest, |
299 PreferHtmlOverPluginsIncognitoAllowToDetect) { | 304 PreferHtmlOverPluginsIncognitoAllowToDetect) { |
300 Profile* incognito = profile()->GetOffTheRecordProfile(); | 305 Profile* incognito = profile()->GetOffTheRecordProfile(); |
301 filter_->RegisterResourceContext(incognito, incognito->GetResourceContext()); | 306 filter_->RegisterResourceContext(incognito, incognito->GetResourceContext()); |
302 | 307 |
303 content::WebPluginInfo flash_plugin( | 308 content::WebPluginInfo flash_plugin( |
304 base::ASCIIToUTF16(content::kFlashPluginName), flash_plugin_path_, | 309 base::ASCIIToUTF16(content::kFlashPluginName), flash_plugin_path_, |
305 base::ASCIIToUTF16("1"), base::ASCIIToUTF16("The Flash plugin.")); | 310 base::ASCIIToUTF16("1"), base::ASCIIToUTF16("The Flash plugin.")); |
306 | 311 |
307 // Activate PreferHtmlOverPlugins. | 312 // Activate PreferHtmlOverPlugins. |
308 base::test::ScopedFeatureList feature_list; | 313 base::test::ScopedFeatureList feature_list; |
309 feature_list.InitAndEnableFeature(features::kPreferHtmlOverPlugins); | 314 feature_list.InitAndEnableFeature(features::kPreferHtmlOverPlugins); |
310 | 315 |
311 // Allow plugins in the original profile. | 316 // Allow plugins in the original profile. |
312 HostContentSettingsMap* map = | 317 HostContentSettingsMap* map = |
313 HostContentSettingsMapFactory::GetForProfile(profile()); | 318 HostContentSettingsMapFactory::GetForProfile(profile()); |
314 map->SetDefaultContentSetting(CONTENT_SETTINGS_TYPE_PLUGINS, | 319 map->SetDefaultContentSetting(CONTENT_SETTINGS_TYPE_PLUGINS, |
315 CONTENT_SETTING_ALLOW); | 320 CONTENT_SETTING_ALLOW); |
316 | 321 |
317 // We pass the availablity check in incognito based on the original content | 322 // We pass the availablity check in incognito based on the original content |
318 // setting. | 323 // setting. |
319 GURL url("http://www.google.com"); | 324 GURL url("http://www.google.com"); |
320 EXPECT_TRUE(IsPluginAvailable(url, url, incognito->GetResourceContext(), | 325 url::Origin main_frame_origin(url); |
321 flash_plugin)); | 326 EXPECT_TRUE(IsPluginAvailable(url, main_frame_origin, |
| 327 incognito->GetResourceContext(), flash_plugin)); |
322 | 328 |
323 map->SetDefaultContentSetting(CONTENT_SETTINGS_TYPE_PLUGINS, | 329 map->SetDefaultContentSetting(CONTENT_SETTINGS_TYPE_PLUGINS, |
324 CONTENT_SETTING_DETECT_IMPORTANT_CONTENT); | 330 CONTENT_SETTING_DETECT_IMPORTANT_CONTENT); |
325 | 331 |
326 // Now we fail the availability check due to the content setting carrying | 332 // Now we fail the availability check due to the content setting carrying |
327 // over. | 333 // over. |
328 EXPECT_FALSE(IsPluginAvailable(url, url, incognito->GetResourceContext(), | 334 EXPECT_FALSE(IsPluginAvailable( |
329 flash_plugin)); | 335 url, main_frame_origin, incognito->GetResourceContext(), flash_plugin)); |
330 | 336 |
331 // Add sufficient engagement to allow Flash in the incognito profile. | 337 // Add sufficient engagement to allow Flash in the incognito profile. |
332 SiteEngagementService* service = SiteEngagementService::Get(incognito); | 338 SiteEngagementService* service = SiteEngagementService::Get(incognito); |
333 service->ResetScoreForURL(url, 2.0); | 339 service->ResetScoreForURL(url, 2.0); |
334 | 340 |
335 // Ensure we pass the engagement check in the incognito profile. | 341 // Ensure we pass the engagement check in the incognito profile. |
336 EXPECT_TRUE(IsPluginAvailable(url, url, incognito->GetResourceContext(), | 342 EXPECT_TRUE(IsPluginAvailable(url, main_frame_origin, |
337 flash_plugin)); | 343 incognito->GetResourceContext(), flash_plugin)); |
338 } | 344 } |
339 | 345 |
340 TEST_F(ChromePluginServiceFilterTest, BlockIfManagedSetting) { | 346 TEST_F(ChromePluginServiceFilterTest, BlockIfManagedSetting) { |
341 content::WebPluginInfo flash_plugin( | 347 content::WebPluginInfo flash_plugin( |
342 base::ASCIIToUTF16(content::kFlashPluginName), flash_plugin_path_, | 348 base::ASCIIToUTF16(content::kFlashPluginName), flash_plugin_path_, |
343 base::ASCIIToUTF16("1"), base::ASCIIToUTF16("The Flash plugin.")); | 349 base::ASCIIToUTF16("1"), base::ASCIIToUTF16("The Flash plugin.")); |
344 | 350 |
345 // Activate PreferHtmlOverPlugins. | 351 // Activate PreferHtmlOverPlugins. |
346 base::test::ScopedFeatureList feature_list; | 352 base::test::ScopedFeatureList feature_list; |
347 feature_list.InitAndEnableFeature(features::kPreferHtmlOverPlugins); | 353 feature_list.InitAndEnableFeature(features::kPreferHtmlOverPlugins); |
348 | 354 |
349 HostContentSettingsMap* map = | 355 HostContentSettingsMap* map = |
350 HostContentSettingsMapFactory::GetForProfile(profile()); | 356 HostContentSettingsMapFactory::GetForProfile(profile()); |
351 map->SetDefaultContentSetting(CONTENT_SETTINGS_TYPE_PLUGINS, | 357 map->SetDefaultContentSetting(CONTENT_SETTINGS_TYPE_PLUGINS, |
352 CONTENT_SETTING_DETECT_IMPORTANT_CONTENT); | 358 CONTENT_SETTING_DETECT_IMPORTANT_CONTENT); |
353 | 359 |
354 SiteEngagementService* service = SiteEngagementService::Get(profile()); | 360 SiteEngagementService* service = SiteEngagementService::Get(profile()); |
355 // Reaching 1.0 engagement should allow Flash. | 361 // Reaching 1.0 engagement should allow Flash. |
356 GURL url("http://www.google.com"); | 362 GURL url("http://www.google.com"); |
| 363 url::Origin main_frame_origin(url); |
357 service->ResetScoreForURL(url, 1.0); | 364 service->ResetScoreForURL(url, 1.0); |
358 EXPECT_TRUE(IsPluginAvailable(url, url, profile()->GetResourceContext(), | 365 EXPECT_TRUE(IsPluginAvailable(url, main_frame_origin, |
359 flash_plugin)); | 366 profile()->GetResourceContext(), flash_plugin)); |
360 | 367 |
361 // Enterprise ASK setting should block flash from being advertised. | 368 // Enterprise ASK setting should block flash from being advertised. |
362 syncable_prefs::TestingPrefServiceSyncable* prefs = | 369 syncable_prefs::TestingPrefServiceSyncable* prefs = |
363 profile()->GetTestingPrefService(); | 370 profile()->GetTestingPrefService(); |
364 prefs->SetManagedPref(prefs::kManagedDefaultPluginsSetting, | 371 prefs->SetManagedPref(prefs::kManagedDefaultPluginsSetting, |
365 new base::FundamentalValue(CONTENT_SETTING_ASK)); | 372 new base::FundamentalValue(CONTENT_SETTING_ASK)); |
366 EXPECT_FALSE(IsPluginAvailable(url, url, profile()->GetResourceContext(), | 373 EXPECT_FALSE(IsPluginAvailable( |
367 flash_plugin)); | 374 url, main_frame_origin, profile()->GetResourceContext(), flash_plugin)); |
368 } | 375 } |
OLD | NEW |