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

Side by Side Diff: chrome/browser/plugins/chrome_plugin_service_filter_unittest.cc

Issue 2735333002: Rename SiteEngagementService::ResetScoreForURL. (Closed)
Patch Set: Created 3 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 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 192 matching lines...) Expand 10 before | Expand all | Expand 10 after
203 map->SetDefaultContentSetting(CONTENT_SETTINGS_TYPE_PLUGINS, 203 map->SetDefaultContentSetting(CONTENT_SETTINGS_TYPE_PLUGINS,
204 CONTENT_SETTING_DETECT_IMPORTANT_CONTENT); 204 CONTENT_SETTING_DETECT_IMPORTANT_CONTENT);
205 205
206 // This should be blocked due to 0 engagement and a detect content setting. 206 // This should be blocked due to 0 engagement and a detect content setting.
207 EXPECT_FALSE(IsPluginAvailable( 207 EXPECT_FALSE(IsPluginAvailable(
208 url, main_frame_origin, profile()->GetResourceContext(), flash_plugin)); 208 url, main_frame_origin, profile()->GetResourceContext(), flash_plugin));
209 histograms.ExpectBucketCount( 209 histograms.ExpectBucketCount(
210 ChromePluginServiceFilter::kEngagementNoSettingHistogram, 0, 1); 210 ChromePluginServiceFilter::kEngagementNoSettingHistogram, 0, 1);
211 211
212 SiteEngagementService* service = SiteEngagementService::Get(profile()); 212 SiteEngagementService* service = SiteEngagementService::Get(profile());
213 service->ResetScoreForURL(url, 10.0); 213 service->ResetBaseScoreForURL(url, 10.0);
214 214
215 // Should still be blocked. 215 // Should still be blocked.
216 EXPECT_FALSE(IsPluginAvailable( 216 EXPECT_FALSE(IsPluginAvailable(
217 url, main_frame_origin, profile()->GetResourceContext(), flash_plugin)); 217 url, main_frame_origin, profile()->GetResourceContext(), flash_plugin));
218 histograms.ExpectBucketCount( 218 histograms.ExpectBucketCount(
219 ChromePluginServiceFilter::kEngagementNoSettingHistogram, 10, 1); 219 ChromePluginServiceFilter::kEngagementNoSettingHistogram, 10, 1);
220 220
221 // Reaching 30.0 engagement should allow Flash. 221 // Reaching 30.0 engagement should allow Flash.
222 service->ResetScoreForURL(url, 30.0); 222 service->ResetBaseScoreForURL(url, 30.0);
223 EXPECT_TRUE(IsPluginAvailable(url, main_frame_origin, 223 EXPECT_TRUE(IsPluginAvailable(url, main_frame_origin,
224 profile()->GetResourceContext(), flash_plugin)); 224 profile()->GetResourceContext(), flash_plugin));
225 225
226 histograms.ExpectBucketCount( 226 histograms.ExpectBucketCount(
227 ChromePluginServiceFilter::kEngagementNoSettingHistogram, 0, 1); 227 ChromePluginServiceFilter::kEngagementNoSettingHistogram, 0, 1);
228 histograms.ExpectBucketCount( 228 histograms.ExpectBucketCount(
229 ChromePluginServiceFilter::kEngagementNoSettingHistogram, 10, 1); 229 ChromePluginServiceFilter::kEngagementNoSettingHistogram, 10, 1);
230 histograms.ExpectBucketCount( 230 histograms.ExpectBucketCount(
231 ChromePluginServiceFilter::kEngagementNoSettingHistogram, 30, 1); 231 ChromePluginServiceFilter::kEngagementNoSettingHistogram, 30, 1);
232 232
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
278 CONTENT_SETTING_DETECT_IMPORTANT_CONTENT); 278 CONTENT_SETTING_DETECT_IMPORTANT_CONTENT);
279 279
280 // This should be blocked due to 0 engagement. 280 // This should be blocked due to 0 engagement.
281 GURL url("http://www.google.com"); 281 GURL url("http://www.google.com");
282 url::Origin main_frame_origin(url); 282 url::Origin main_frame_origin(url);
283 EXPECT_FALSE(IsPluginAvailable( 283 EXPECT_FALSE(IsPluginAvailable(
284 url, main_frame_origin, profile()->GetResourceContext(), flash_plugin)); 284 url, main_frame_origin, profile()->GetResourceContext(), flash_plugin));
285 285
286 // Should still be blocked until engagement reaches 50. 286 // Should still be blocked until engagement reaches 50.
287 SiteEngagementService* service = SiteEngagementService::Get(profile()); 287 SiteEngagementService* service = SiteEngagementService::Get(profile());
288 service->ResetScoreForURL(url, 0.0); 288 service->ResetBaseScoreForURL(url, 0.0);
289 EXPECT_FALSE(IsPluginAvailable( 289 EXPECT_FALSE(IsPluginAvailable(
290 url, main_frame_origin, profile()->GetResourceContext(), flash_plugin)); 290 url, main_frame_origin, profile()->GetResourceContext(), flash_plugin));
291 service->ResetScoreForURL(url, 10.0); 291 service->ResetBaseScoreForURL(url, 10.0);
292 EXPECT_FALSE(IsPluginAvailable( 292 EXPECT_FALSE(IsPluginAvailable(
293 url, main_frame_origin, profile()->GetResourceContext(), flash_plugin)); 293 url, main_frame_origin, profile()->GetResourceContext(), flash_plugin));
294 service->ResetScoreForURL(url, 40.0); 294 service->ResetBaseScoreForURL(url, 40.0);
295 EXPECT_FALSE(IsPluginAvailable( 295 EXPECT_FALSE(IsPluginAvailable(
296 url, main_frame_origin, profile()->GetResourceContext(), flash_plugin)); 296 url, main_frame_origin, profile()->GetResourceContext(), flash_plugin));
297 service->ResetScoreForURL(url, 60.0); 297 service->ResetBaseScoreForURL(url, 60.0);
298 EXPECT_TRUE(IsPluginAvailable(url, main_frame_origin, 298 EXPECT_TRUE(IsPluginAvailable(url, main_frame_origin,
299 profile()->GetResourceContext(), flash_plugin)); 299 profile()->GetResourceContext(), flash_plugin));
300 300
301 histograms.ExpectBucketCount( 301 histograms.ExpectBucketCount(
302 ChromePluginServiceFilter::kEngagementNoSettingHistogram, 0, 2); 302 ChromePluginServiceFilter::kEngagementNoSettingHistogram, 0, 2);
303 histograms.ExpectBucketCount( 303 histograms.ExpectBucketCount(
304 ChromePluginServiceFilter::kEngagementNoSettingHistogram, 10, 1); 304 ChromePluginServiceFilter::kEngagementNoSettingHistogram, 10, 1);
305 histograms.ExpectBucketCount( 305 histograms.ExpectBucketCount(
306 ChromePluginServiceFilter::kEngagementNoSettingHistogram, 40, 1); 306 ChromePluginServiceFilter::kEngagementNoSettingHistogram, 40, 1);
307 histograms.ExpectBucketCount( 307 histograms.ExpectBucketCount(
(...skipping 22 matching lines...) Expand all
330 CONTENT_SETTING_BLOCK); 330 CONTENT_SETTING_BLOCK);
331 331
332 // We should fail the availablity check in incognito. 332 // We should fail the availablity check in incognito.
333 GURL url("http://www.google.com"); 333 GURL url("http://www.google.com");
334 url::Origin main_frame_origin(url); 334 url::Origin main_frame_origin(url);
335 EXPECT_FALSE(IsPluginAvailable( 335 EXPECT_FALSE(IsPluginAvailable(
336 url, main_frame_origin, incognito->GetResourceContext(), flash_plugin)); 336 url, main_frame_origin, incognito->GetResourceContext(), flash_plugin));
337 337
338 // Add sufficient engagement to allow Flash in the original profile. 338 // Add sufficient engagement to allow Flash in the original profile.
339 SiteEngagementService* service = SiteEngagementService::Get(profile()); 339 SiteEngagementService* service = SiteEngagementService::Get(profile());
340 service->ResetScoreForURL(url, 30.0); 340 service->ResetBaseScoreForURL(url, 30.0);
341 341
342 // We should still fail the engagement check due to the block. 342 // We should still fail the engagement check due to the block.
343 EXPECT_FALSE(IsPluginAvailable( 343 EXPECT_FALSE(IsPluginAvailable(
344 url, main_frame_origin, incognito->GetResourceContext(), flash_plugin)); 344 url, main_frame_origin, incognito->GetResourceContext(), flash_plugin));
345 345
346 // Change to detect important content in the original profile. 346 // Change to detect important content in the original profile.
347 map->SetDefaultContentSetting(CONTENT_SETTINGS_TYPE_PLUGINS, 347 map->SetDefaultContentSetting(CONTENT_SETTINGS_TYPE_PLUGINS,
348 CONTENT_SETTING_DETECT_IMPORTANT_CONTENT); 348 CONTENT_SETTING_DETECT_IMPORTANT_CONTENT);
349 349
350 // Ensure we pass the engagement check in the incognito profile (i.e. it falls 350 // Ensure we pass the engagement check in the incognito profile (i.e. it falls
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
390 std::string(), 390 std::string(),
391 CONTENT_SETTING_DETECT_IMPORTANT_CONTENT); 391 CONTENT_SETTING_DETECT_IMPORTANT_CONTENT);
392 392
393 // Now we fail the availability check due to the content setting carrying 393 // Now we fail the availability check due to the content setting carrying
394 // over. 394 // over.
395 EXPECT_FALSE(IsPluginAvailable( 395 EXPECT_FALSE(IsPluginAvailable(
396 url, main_frame_origin, incognito->GetResourceContext(), flash_plugin)); 396 url, main_frame_origin, incognito->GetResourceContext(), flash_plugin));
397 397
398 // Add sufficient engagement to allow Flash in the incognito profile. 398 // Add sufficient engagement to allow Flash in the incognito profile.
399 SiteEngagementService* service = SiteEngagementService::Get(incognito); 399 SiteEngagementService* service = SiteEngagementService::Get(incognito);
400 service->ResetScoreForURL(url, 30.0); 400 service->ResetBaseScoreForURL(url, 30.0);
401 401
402 // Ensure we pass the engagement check in the incognito profile. 402 // Ensure we pass the engagement check in the incognito profile.
403 EXPECT_TRUE(IsPluginAvailable(url, main_frame_origin, 403 EXPECT_TRUE(IsPluginAvailable(url, main_frame_origin,
404 incognito->GetResourceContext(), flash_plugin)); 404 incognito->GetResourceContext(), flash_plugin));
405 } 405 }
406 406
407 TEST_F(ChromePluginServiceFilterTest, ManagedSetting) { 407 TEST_F(ChromePluginServiceFilterTest, ManagedSetting) {
408 content::WebPluginInfo flash_plugin( 408 content::WebPluginInfo flash_plugin(
409 base::ASCIIToUTF16(content::kFlashPluginName), flash_plugin_path_, 409 base::ASCIIToUTF16(content::kFlashPluginName), flash_plugin_path_,
410 base::ASCIIToUTF16("1"), base::ASCIIToUTF16("The Flash plugin.")); 410 base::ASCIIToUTF16("1"), base::ASCIIToUTF16("The Flash plugin."));
(...skipping 10 matching lines...) Expand all
421 sync_preferences::TestingPrefServiceSyncable* prefs = 421 sync_preferences::TestingPrefServiceSyncable* prefs =
422 profile()->GetTestingPrefService(); 422 profile()->GetTestingPrefService();
423 prefs->SetManagedPref(prefs::kManagedDefaultPluginsSetting, 423 prefs->SetManagedPref(prefs::kManagedDefaultPluginsSetting,
424 new base::Value(CONTENT_SETTING_ASK)); 424 new base::Value(CONTENT_SETTING_ASK));
425 425
426 SiteEngagementService* service = SiteEngagementService::Get(profile()); 426 SiteEngagementService* service = SiteEngagementService::Get(profile());
427 GURL url("http://www.google.com"); 427 GURL url("http://www.google.com");
428 url::Origin main_frame_origin(url); 428 url::Origin main_frame_origin(url);
429 NavigateAndCommit(url); 429 NavigateAndCommit(url);
430 430
431 service->ResetScoreForURL(url, 30.0); 431 service->ResetBaseScoreForURL(url, 30.0);
432 // Reaching 30.0 engagement would usually allow Flash, but not for enterprise. 432 // Reaching 30.0 engagement would usually allow Flash, but not for enterprise.
433 service->ResetScoreForURL(url, 0); 433 service->ResetBaseScoreForURL(url, 0);
434 EXPECT_FALSE(IsPluginAvailable( 434 EXPECT_FALSE(IsPluginAvailable(
435 url, main_frame_origin, profile()->GetResourceContext(), flash_plugin)); 435 url, main_frame_origin, profile()->GetResourceContext(), flash_plugin));
436 436
437 // Allow flash temporarily. 437 // Allow flash temporarily.
438 FlashTemporaryPermissionTracker::Get(profile())->FlashEnabledForWebContents( 438 FlashTemporaryPermissionTracker::Get(profile())->FlashEnabledForWebContents(
439 web_contents()); 439 web_contents());
440 EXPECT_TRUE(IsPluginAvailable(url, main_frame_origin, 440 EXPECT_TRUE(IsPluginAvailable(url, main_frame_origin,
441 profile()->GetResourceContext(), flash_plugin)); 441 profile()->GetResourceContext(), flash_plugin));
442 } 442 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698