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

Side by Side Diff: chrome/browser/permissions/permission_decision_auto_blocker_unittest.cc

Issue 2651123002: Migrate content setting PROMPT_NO_DECISION_COUNT to PERMISSION_AUTOBLOCKER_DATA (Closed)
Patch Set: . Created 3 years, 11 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/permissions/permission_decision_auto_blocker.h" 5 #include "chrome/browser/permissions/permission_decision_auto_blocker.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/test/scoped_feature_list.h" 8 #include "base/test/scoped_feature_list.h"
9 #include "base/time/time.h" 9 #include "base/time/time.h"
10 #include "chrome/browser/content_settings/host_content_settings_map_factory.h" 10 #include "chrome/browser/content_settings/host_content_settings_map_factory.h"
11 #include "chrome/browser/permissions/permission_util.h"
11 #include "chrome/common/chrome_features.h" 12 #include "chrome/common/chrome_features.h"
12 #include "chrome/test/base/chrome_render_view_host_test_harness.h" 13 #include "chrome/test/base/chrome_render_view_host_test_harness.h"
13 #include "chrome/test/base/testing_profile.h" 14 #include "chrome/test/base/testing_profile.h"
15 #include "components/content_settings/core/browser/host_content_settings_map.h"
14 #include "components/safe_browsing_db/test_database_manager.h" 16 #include "components/safe_browsing_db/test_database_manager.h"
15 #include "content/public/browser/permission_type.h" 17 #include "content/public/browser/permission_type.h"
16 18
17 namespace { 19 namespace {
18 20
19 bool FilterGoogle(const GURL& url) { 21 bool FilterGoogle(const GURL& url) {
20 return url == "https://www.google.com/"; 22 return url == "https://www.google.com/";
21 } 23 }
22 24
23 bool FilterAll(const GURL& url) { 25 bool FilterAll(const GURL& url) {
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
70 // Manually placing an origin, permission pair under embargo for blacklisting. 72 // Manually placing an origin, permission pair under embargo for blacklisting.
71 // To embargo on dismissals, RecordDismissAndEmbargo can be used. 73 // To embargo on dismissals, RecordDismissAndEmbargo can be used.
72 void PlaceUnderBlacklistEmbargo(content::PermissionType permission, 74 void PlaceUnderBlacklistEmbargo(content::PermissionType permission,
73 const GURL& url, 75 const GURL& url,
74 HostContentSettingsMap* map, 76 HostContentSettingsMap* map,
75 base::Time current_time) { 77 base::Time current_time) {
76 PermissionDecisionAutoBlocker::PlaceUnderEmbargo( 78 PermissionDecisionAutoBlocker::PlaceUnderEmbargo(
77 permission, url, map, current_time, 79 permission, url, map, current_time,
78 PermissionDecisionAutoBlocker::kPermissionBlacklistEmbargoKey); 80 PermissionDecisionAutoBlocker::kPermissionBlacklistEmbargoKey);
79 } 81 }
82
83 const char* GetDismissKey() {
84 return PermissionDecisionAutoBlocker::kPromptDismissCountKey;
85 }
86
87 const char* GetIgnoreKey() {
88 return PermissionDecisionAutoBlocker::kPromptIgnoreCountKey;
89 }
80 }; 90 };
81 91
82 TEST_F(PermissionDecisionAutoBlockerUnitTest, RemoveCountsByUrl) { 92 TEST_F(PermissionDecisionAutoBlockerUnitTest, RemoveCountsByUrl) {
83 GURL url1("https://www.google.com"); 93 GURL url1("https://www.google.com");
84 GURL url2("https://www.example.com"); 94 GURL url2("https://www.example.com");
85 base::test::ScopedFeatureList feature_list; 95 base::test::ScopedFeatureList feature_list;
86 feature_list.InitAndEnableFeature(features::kBlockPromptsIfDismissedOften); 96 feature_list.InitAndEnableFeature(features::kBlockPromptsIfDismissedOften);
87 97
88 // Record some dismissals. 98 // Record some dismissals.
89 EXPECT_FALSE(RecordDismissAndEmbargo( 99 EXPECT_FALSE(RecordDismissAndEmbargo(
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after
288 time_now += base::TimeDelta::FromDays(3); 298 time_now += base::TimeDelta::FromDays(3);
289 EXPECT_FALSE(PermissionDecisionAutoBlocker::IsUnderEmbargo( 299 EXPECT_FALSE(PermissionDecisionAutoBlocker::IsUnderEmbargo(
290 content::PermissionType::GEOLOCATION, profile(), url, 300 content::PermissionType::GEOLOCATION, profile(), url,
291 time_now + base::TimeDelta::FromDays(5))); 301 time_now + base::TimeDelta::FromDays(5)));
292 302
293 // Check that dismissal embargo is still set, even though the blacklisting 303 // Check that dismissal embargo is still set, even though the blacklisting
294 // embargo has expired. 304 // embargo has expired.
295 EXPECT_TRUE(PermissionDecisionAutoBlocker::IsUnderEmbargo( 305 EXPECT_TRUE(PermissionDecisionAutoBlocker::IsUnderEmbargo(
296 content::PermissionType::GEOLOCATION, profile(), url, time_now)); 306 content::PermissionType::GEOLOCATION, profile(), url, time_now));
297 } 307 }
308
309 // TODO(raymes): See crbug.com/681709. Remove after M60.
310 TEST_F(PermissionDecisionAutoBlockerUnitTest,
311 MigrateNoDecisionCountToPermissionAutoblockerData) {
dominickn 2017/01/25 06:02:33 Sp: AutoBlocker
312 GURL url("https://www.google.com");
313 auto* map = HostContentSettingsMapFactory::GetForProfile(profile());
314
315 // Write to the old content setting.
316 base::DictionaryValue permissions_dict;
317 permissions_dict.SetInteger(GetDismissKey(), 100);
318 permissions_dict.SetInteger(GetIgnoreKey(), 50);
319
320 base::DictionaryValue origin_dict;
321 origin_dict.Set(
322 PermissionUtil::GetPermissionString(content::PermissionType::GEOLOCATION),
323 permissions_dict.CreateDeepCopy());
324 map->SetWebsiteSettingDefaultScope(
325 url, GURL(), CONTENT_SETTINGS_TYPE_PROMPT_NO_DECISION_COUNT,
326 std::string(), origin_dict.CreateDeepCopy());
327
328 // Nothing should be migrated yet, so the current values should be 0.
329 EXPECT_EQ(0, PermissionDecisionAutoBlocker::GetDismissCount(
330 url, content::PermissionType::GEOLOCATION, profile()));
331 EXPECT_EQ(0, PermissionDecisionAutoBlocker::GetIgnoreCount(
332 url, content::PermissionType::GEOLOCATION, profile()));
333
334 // Trigger pref migration which happens at the creation of the
335 // HostContentSetitngsMap.
dominickn 2017/01/25 06:02:33 sp. SettingsMap
336 {
337 scoped_refptr<HostContentSettingsMap> temp_map(new HostContentSettingsMap(
338 profile()->GetPrefs(), false /* is_incognito_profile */,
339 false /* is_guest_profile */));
340 temp_map->ShutdownOnUIThread();
341 }
342
343 // The values should now be migrated.
344 EXPECT_EQ(100, PermissionDecisionAutoBlocker::GetDismissCount(
345 url, content::PermissionType::GEOLOCATION, profile()));
346 EXPECT_EQ(50, PermissionDecisionAutoBlocker::GetIgnoreCount(
347 url, content::PermissionType::GEOLOCATION, profile()));
348
349 // The old pref should be deleted.
350 std::unique_ptr<base::DictionaryValue> old_dict =
351 base::DictionaryValue::From(map->GetWebsiteSetting(
352 url, GURL(), CONTENT_SETTINGS_TYPE_PROMPT_NO_DECISION_COUNT,
353 std::string(), nullptr));
354 EXPECT_EQ(nullptr, old_dict);
355 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698