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

Side by Side Diff: chrome/browser/content_settings/host_content_settings_map_unittest.cc

Issue 1963203002: [Chrome Settings UI] Show overruled User Exceptions as strike-through. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Sync. Created 4 years, 6 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
« no previous file with comments | « no previous file | chrome/browser/resources/options/content_settings.css » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 <memory> 5 #include <memory>
6 #include <string> 6 #include <string>
7 7
8 #include "base/auto_reset.h" 8 #include "base/auto_reset.h"
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/json/json_reader.h" 10 #include "base/json/json_reader.h"
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
74 74
75 void ClearPolicyDefault() { 75 void ClearPolicyDefault() {
76 prefs_->RemoveManagedPref(policy_default_setting_); 76 prefs_->RemoveManagedPref(policy_default_setting_);
77 } 77 }
78 78
79 void SetPolicyDefault(ContentSetting setting) { 79 void SetPolicyDefault(ContentSetting setting) {
80 prefs_->SetManagedPref(policy_default_setting_, 80 prefs_->SetManagedPref(policy_default_setting_,
81 new base::FundamentalValue(setting)); 81 new base::FundamentalValue(setting));
82 } 82 }
83 83
84 bool AreUserExceptionsAllowed() {
85 return host_content_settings_map_->AreUserExceptionsAllowedForType(
86 content_type_);
87 }
88
89 void AddUserException(std::string exception, 84 void AddUserException(std::string exception,
90 ContentSetting content_settings) { 85 ContentSetting content_settings) {
91 ContentSettingsPattern pattern = 86 ContentSettingsPattern pattern =
92 ContentSettingsPattern::FromString(exception); 87 ContentSettingsPattern::FromString(exception);
93 host_content_settings_map_->SetContentSettingCustomScope( 88 host_content_settings_map_->SetContentSettingCustomScope(
94 pattern, pattern, content_type_, std::string(), content_settings); 89 pattern, pattern, content_type_, std::string(), content_settings);
95 } 90 }
96 91
97 // Wrapper to query GetWebsiteSetting(), and only return the source. 92 // Wrapper to query GetWebsiteSetting(), and only return the source.
98 content_settings::SettingSource GetSettingSourceForURL( 93 content_settings::SettingSource GetSettingSourceForURL(
(...skipping 763 matching lines...) Expand 10 before | Expand all | Expand 10 after
862 std::unique_ptr<base::Value> stored_value = 857 std::unique_ptr<base::Value> stored_value =
863 host_content_settings_map->GetWebsiteSetting( 858 host_content_settings_map->GetWebsiteSetting(
864 host, host, CONTENT_SETTINGS_TYPE_USB_CHOOSER_DATA, std::string(), 859 host, host, CONTENT_SETTINGS_TYPE_USB_CHOOSER_DATA, std::string(),
865 nullptr); 860 nullptr);
866 EXPECT_TRUE(stored_value && stored_value->Equals(&test_value)); 861 EXPECT_TRUE(stored_value && stored_value->Equals(&test_value));
867 EXPECT_EQ(nullptr, otr_map->GetWebsiteSetting( 862 EXPECT_EQ(nullptr, otr_map->GetWebsiteSetting(
868 host, host, CONTENT_SETTINGS_TYPE_USB_CHOOSER_DATA, 863 host, host, CONTENT_SETTINGS_TYPE_USB_CHOOSER_DATA,
869 std::string(), nullptr)); 864 std::string(), nullptr));
870 } 865 }
871 866
872 TEST_F(HostContentSettingsMapTest, AreUserExceptionsAllowedForType) {
873 ContentSettingsType kContentTypesToTest[] = {
874 CONTENT_SETTINGS_TYPE_COOKIES,
875 CONTENT_SETTINGS_TYPE_POPUPS,
876 };
877
878 TestingProfile profile;
879
880 for (ContentSettingsType type : kContentTypesToTest) {
881 TesterForType tester(&profile, type);
882
883 // No settings: Yes.
884 tester.ClearPolicyDefault();
885 EXPECT_TRUE(tester.AreUserExceptionsAllowed());
886
887 // Policy enforces default value: No.
888 tester.SetPolicyDefault(CONTENT_SETTING_ALLOW);
889 EXPECT_FALSE(tester.AreUserExceptionsAllowed());
890 tester.SetPolicyDefault(CONTENT_SETTING_BLOCK);
891 EXPECT_FALSE(tester.AreUserExceptionsAllowed());
892
893 // Cleanup for next iteration.
894 tester.ClearPolicyDefault();
895 }
896 }
897
898 TEST_F(HostContentSettingsMapTest, PrefExceptionsOperation) { 867 TEST_F(HostContentSettingsMapTest, PrefExceptionsOperation) {
899 using content_settings::SETTING_SOURCE_POLICY; 868 using content_settings::SETTING_SOURCE_POLICY;
900 using content_settings::SETTING_SOURCE_USER; 869 using content_settings::SETTING_SOURCE_USER;
901 870
902 const char kUrl1[] = "http://user_exception_allow.com"; 871 const char kUrl1[] = "http://user_exception_allow.com";
903 const char kUrl2[] = "http://user_exception_block.com"; 872 const char kUrl2[] = "http://user_exception_block.com";
904 const char kUrl3[] = "http://non_exception.com"; 873 const char kUrl3[] = "http://non_exception.com";
905 874
906 TestingProfile profile; 875 TestingProfile profile;
907 // Arbitrarily using cookies as content type to test. 876 // Arbitrarily using cookies as content type to test.
(...skipping 433 matching lines...) Expand 10 before | Expand all | Expand 10 after
1341 host, host, CONTENT_SETTINGS_TYPE_KEYGEN, std::string())); 1310 host, host, CONTENT_SETTINGS_TYPE_KEYGEN, std::string()));
1342 1311
1343 // After migrating old settings, changes to the setting works. 1312 // After migrating old settings, changes to the setting works.
1344 host_content_settings_map->SetContentSettingDefaultScope( 1313 host_content_settings_map->SetContentSettingDefaultScope(
1345 host, GURL(), CONTENT_SETTINGS_TYPE_KEYGEN, std::string(), 1314 host, GURL(), CONTENT_SETTINGS_TYPE_KEYGEN, std::string(),
1346 CONTENT_SETTING_BLOCK); 1315 CONTENT_SETTING_BLOCK);
1347 EXPECT_EQ(CONTENT_SETTING_BLOCK, 1316 EXPECT_EQ(CONTENT_SETTING_BLOCK,
1348 host_content_settings_map->GetContentSetting( 1317 host_content_settings_map->GetContentSetting(
1349 host, host, CONTENT_SETTINGS_TYPE_KEYGEN, std::string())); 1318 host, host, CONTENT_SETTINGS_TYPE_KEYGEN, std::string()));
1350 } 1319 }
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/resources/options/content_settings.css » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698