OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/content_settings/content_settings_policy_provider.h" | 5 #include "chrome/browser/content_settings/content_settings_policy_provider.h" |
6 | 6 |
7 #include "base/auto_reset.h" | 7 #include "base/auto_reset.h" |
8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
9 #include "chrome/browser/content_settings/mock_settings_observer.h" | 9 #include "chrome/browser/content_settings/mock_settings_observer.h" |
10 #include "chrome/browser/prefs/pref_service.h" | 10 #include "chrome/browser/prefs/pref_service.h" |
(...skipping 17 matching lines...) Expand all Loading... |
28 : ui_thread_(BrowserThread::UI, &message_loop_) { | 28 : ui_thread_(BrowserThread::UI, &message_loop_) { |
29 } | 29 } |
30 | 30 |
31 protected: | 31 protected: |
32 MessageLoop message_loop_; | 32 MessageLoop message_loop_; |
33 BrowserThread ui_thread_; | 33 BrowserThread ui_thread_; |
34 }; | 34 }; |
35 | 35 |
36 TEST_F(PolicyDefaultProviderTest, DefaultValues) { | 36 TEST_F(PolicyDefaultProviderTest, DefaultValues) { |
37 TestingProfile profile; | 37 TestingProfile profile; |
38 PolicyDefaultProvider provider(&profile); | |
39 TestingPrefService* prefs = profile.GetTestingPrefService(); | 38 TestingPrefService* prefs = profile.GetTestingPrefService(); |
| 39 PolicyDefaultProvider provider(profile.GetHostContentSettingsMap(), prefs); |
40 | 40 |
41 // By default, policies should be off. | 41 // By default, policies should be off. |
42 ASSERT_FALSE( | 42 ASSERT_FALSE( |
43 provider.DefaultSettingIsManaged(CONTENT_SETTINGS_TYPE_COOKIES)); | 43 provider.DefaultSettingIsManaged(CONTENT_SETTINGS_TYPE_COOKIES)); |
44 | 44 |
45 // Set managed-default-content-setting through the coresponding preferences. | 45 // Set managed-default-content-setting through the coresponding preferences. |
46 prefs->SetManagedPref(prefs::kManagedDefaultCookiesSetting, | 46 prefs->SetManagedPref(prefs::kManagedDefaultCookiesSetting, |
47 Value::CreateIntegerValue(CONTENT_SETTING_BLOCK)); | 47 Value::CreateIntegerValue(CONTENT_SETTING_BLOCK)); |
48 ASSERT_TRUE( | 48 ASSERT_TRUE( |
49 provider.DefaultSettingIsManaged(CONTENT_SETTINGS_TYPE_COOKIES)); | 49 provider.DefaultSettingIsManaged(CONTENT_SETTINGS_TYPE_COOKIES)); |
50 ASSERT_EQ(CONTENT_SETTING_BLOCK, | 50 ASSERT_EQ(CONTENT_SETTING_BLOCK, |
51 provider.ProvideDefaultSetting(CONTENT_SETTINGS_TYPE_COOKIES)); | 51 provider.ProvideDefaultSetting(CONTENT_SETTINGS_TYPE_COOKIES)); |
52 | 52 |
53 // Remove managed-default-content-settings-preferences. | 53 // Remove managed-default-content-settings-preferences. |
54 prefs->RemoveManagedPref(prefs::kManagedDefaultCookiesSetting); | 54 prefs->RemoveManagedPref(prefs::kManagedDefaultCookiesSetting); |
55 ASSERT_FALSE( | 55 ASSERT_FALSE( |
56 provider.DefaultSettingIsManaged(CONTENT_SETTINGS_TYPE_COOKIES)); | 56 provider.DefaultSettingIsManaged(CONTENT_SETTINGS_TYPE_COOKIES)); |
| 57 |
| 58 provider.ShutdownOnUIThread(); |
57 } | 59 } |
58 | 60 |
59 // When a default-content-setting is set to a managed setting a | 61 // When a default-content-setting is set to a managed setting a |
60 // CONTENT_SETTINGS_CHANGED notification should be fired. The same should happen | 62 // CONTENT_SETTINGS_CHANGED notification should be fired. The same should happen |
61 // if the managed setting is removed. | 63 // if the managed setting is removed. |
62 TEST_F(PolicyDefaultProviderTest, ObserveManagedSettingsChange) { | 64 TEST_F(PolicyDefaultProviderTest, ObserveManagedSettingsChange) { |
63 TestingProfile profile; | 65 TestingProfile profile; |
64 MockSettingsObserver observer; | 66 MockSettingsObserver observer; |
65 // Make sure the content settings map exists. | 67 // Make sure the content settings map exists. |
66 profile.GetHostContentSettingsMap(); | 68 profile.GetHostContentSettingsMap(); |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
100 | 102 |
101 TEST_F(PolicyProviderTest, Default) { | 103 TEST_F(PolicyProviderTest, Default) { |
102 TestingProfile profile; | 104 TestingProfile profile; |
103 TestingPrefService* prefs = profile.GetTestingPrefService(); | 105 TestingPrefService* prefs = profile.GetTestingPrefService(); |
104 | 106 |
105 ListValue* value = new ListValue(); | 107 ListValue* value = new ListValue(); |
106 value->Append(Value::CreateStringValue("[*.]google.com")); | 108 value->Append(Value::CreateStringValue("[*.]google.com")); |
107 prefs->SetManagedPref(prefs::kManagedImagesBlockedForUrls, | 109 prefs->SetManagedPref(prefs::kManagedImagesBlockedForUrls, |
108 value); | 110 value); |
109 | 111 |
110 PolicyProvider provider(&profile, NULL); | 112 PolicyProvider provider(profile.GetHostContentSettingsMap(), prefs, NULL); |
111 | 113 |
112 ContentSettingsPattern yt_url_pattern = | 114 ContentSettingsPattern yt_url_pattern = |
113 ContentSettingsPattern::FromString("www.youtube.com"); | 115 ContentSettingsPattern::FromString("www.youtube.com"); |
114 GURL youtube_url("http://www.youtube.com"); | 116 GURL youtube_url("http://www.youtube.com"); |
115 GURL google_url("http://mail.google.com"); | 117 GURL google_url("http://mail.google.com"); |
116 | 118 |
117 EXPECT_EQ(CONTENT_SETTING_DEFAULT, | 119 EXPECT_EQ(CONTENT_SETTING_DEFAULT, |
118 provider.GetContentSetting( | 120 provider.GetContentSetting( |
119 youtube_url, youtube_url, CONTENT_SETTINGS_TYPE_COOKIES, "")); | 121 youtube_url, youtube_url, CONTENT_SETTINGS_TYPE_COOKIES, "")); |
120 EXPECT_EQ(CONTENT_SETTING_BLOCK, | 122 EXPECT_EQ(CONTENT_SETTING_BLOCK, |
121 provider.GetContentSetting( | 123 provider.GetContentSetting( |
122 google_url, google_url, CONTENT_SETTINGS_TYPE_IMAGES, "")); | 124 google_url, google_url, CONTENT_SETTINGS_TYPE_IMAGES, "")); |
123 | 125 |
124 provider.SetContentSetting( | 126 provider.SetContentSetting( |
125 yt_url_pattern, | 127 yt_url_pattern, |
126 yt_url_pattern, | 128 yt_url_pattern, |
127 CONTENT_SETTINGS_TYPE_COOKIES, | 129 CONTENT_SETTINGS_TYPE_COOKIES, |
128 "", | 130 "", |
129 CONTENT_SETTING_BLOCK); | 131 CONTENT_SETTING_BLOCK); |
130 EXPECT_EQ(CONTENT_SETTING_DEFAULT, | 132 EXPECT_EQ(CONTENT_SETTING_DEFAULT, |
131 provider.GetContentSetting( | 133 provider.GetContentSetting( |
132 youtube_url, youtube_url, CONTENT_SETTINGS_TYPE_COOKIES, "")); | 134 youtube_url, youtube_url, CONTENT_SETTINGS_TYPE_COOKIES, "")); |
| 135 |
| 136 provider.ShutdownOnUIThread(); |
133 } | 137 } |
134 | 138 |
135 TEST_F(PolicyProviderTest, ResourceIdentifier) { | 139 TEST_F(PolicyProviderTest, ResourceIdentifier) { |
136 CommandLine* cmd = CommandLine::ForCurrentProcess(); | 140 CommandLine* cmd = CommandLine::ForCurrentProcess(); |
137 AutoReset<CommandLine> auto_reset(cmd, *cmd); | 141 AutoReset<CommandLine> auto_reset(cmd, *cmd); |
138 cmd->AppendSwitch(switches::kEnableResourceContentSettings); | 142 cmd->AppendSwitch(switches::kEnableResourceContentSettings); |
139 | 143 |
140 TestingProfile profile; | 144 TestingProfile profile; |
141 TestingPrefService* prefs = profile.GetTestingPrefService(); | 145 TestingPrefService* prefs = profile.GetTestingPrefService(); |
142 | 146 |
143 ListValue* value = new ListValue(); | 147 ListValue* value = new ListValue(); |
144 value->Append(Value::CreateStringValue("[*.]google.com")); | 148 value->Append(Value::CreateStringValue("[*.]google.com")); |
145 prefs->SetManagedPref(prefs::kManagedPluginsAllowedForUrls, | 149 prefs->SetManagedPref(prefs::kManagedPluginsAllowedForUrls, |
146 value); | 150 value); |
147 | 151 |
148 PolicyProvider provider(&profile, NULL); | 152 PolicyProvider provider(profile.GetHostContentSettingsMap(), prefs, NULL); |
149 | 153 |
150 GURL youtube_url("http://www.youtube.com"); | 154 GURL youtube_url("http://www.youtube.com"); |
151 GURL google_url("http://mail.google.com"); | 155 GURL google_url("http://mail.google.com"); |
152 | 156 |
153 EXPECT_EQ(CONTENT_SETTING_DEFAULT, | 157 EXPECT_EQ(CONTENT_SETTING_DEFAULT, |
154 provider.GetContentSetting( | 158 provider.GetContentSetting( |
155 youtube_url, | 159 youtube_url, |
156 youtube_url, | 160 youtube_url, |
157 CONTENT_SETTINGS_TYPE_PLUGINS, | 161 CONTENT_SETTINGS_TYPE_PLUGINS, |
158 "someplugin")); | 162 "someplugin")); |
159 | 163 |
160 // There is no policy support for resource content settings until the feature | 164 // There is no policy support for resource content settings until the feature |
161 // is enabled by default. Resource identifiers are simply ignored by the | 165 // is enabled by default. Resource identifiers are simply ignored by the |
162 // PolicyProvider. | 166 // PolicyProvider. |
163 EXPECT_EQ(CONTENT_SETTING_ALLOW, | 167 EXPECT_EQ(CONTENT_SETTING_ALLOW, |
164 provider.GetContentSetting( | 168 provider.GetContentSetting( |
165 google_url, | 169 google_url, |
166 google_url, | 170 google_url, |
167 CONTENT_SETTINGS_TYPE_PLUGINS, | 171 CONTENT_SETTINGS_TYPE_PLUGINS, |
168 "")); | 172 "")); |
169 | 173 |
170 EXPECT_EQ(CONTENT_SETTING_DEFAULT, | 174 EXPECT_EQ(CONTENT_SETTING_DEFAULT, |
171 provider.GetContentSetting( | 175 provider.GetContentSetting( |
172 google_url, | 176 google_url, |
173 google_url, | 177 google_url, |
174 CONTENT_SETTINGS_TYPE_PLUGINS, | 178 CONTENT_SETTINGS_TYPE_PLUGINS, |
175 "someplugin")); | 179 "someplugin")); |
| 180 |
| 181 provider.ShutdownOnUIThread(); |
176 } | 182 } |
177 | 183 |
178 } // namespace content_settings | 184 } // namespace content_settings |
OLD | NEW |