| 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 <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/auto_reset.h" | 9 #include "base/auto_reset.h" |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| (...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 148 | 148 |
| 149 protected: | 149 protected: |
| 150 // TODO(markusheintz): Check if it's possible to derive the provider class | 150 // TODO(markusheintz): Check if it's possible to derive the provider class |
| 151 // from NonThreadSafe and to use native thread identifiers instead of | 151 // from NonThreadSafe and to use native thread identifiers instead of |
| 152 // BrowserThread IDs. Then we could get rid of the message_loop and ui_thread | 152 // BrowserThread IDs. Then we could get rid of the message_loop and ui_thread |
| 153 // fields. | 153 // fields. |
| 154 MessageLoop message_loop_; | 154 MessageLoop message_loop_; |
| 155 BrowserThread ui_thread_; | 155 BrowserThread ui_thread_; |
| 156 }; | 156 }; |
| 157 | 157 |
| 158 TEST_F(PolicyProviderTest, Default) { | 158 TEST_F(PolicyProviderTest, GettingManagedContentSettings) { |
| 159 TestingProfile profile; | 159 TestingProfile profile; |
| 160 TestingPrefService* prefs = profile.GetTestingPrefService(); | 160 TestingPrefService* prefs = profile.GetTestingPrefService(); |
| 161 | 161 |
| 162 ListValue* value = new ListValue(); | 162 ListValue* value = new ListValue(); |
| 163 value->Append(Value::CreateStringValue("[*.]google.com")); | 163 value->Append(Value::CreateStringValue("[*.]google.com")); |
| 164 prefs->SetManagedPref(prefs::kManagedImagesBlockedForUrls, | 164 prefs->SetManagedPref(prefs::kManagedImagesBlockedForUrls, |
| 165 value); | 165 value); |
| 166 | 166 |
| 167 PolicyProvider provider(prefs, NULL); | 167 PolicyProvider provider(prefs, NULL); |
| 168 | 168 |
| 169 ContentSettingsPattern yt_url_pattern = | 169 ContentSettingsPattern yt_url_pattern = |
| 170 ContentSettingsPattern::FromString("www.youtube.com"); | 170 ContentSettingsPattern::FromString("www.youtube.com"); |
| 171 GURL youtube_url("http://www.youtube.com"); | 171 GURL youtube_url("http://www.youtube.com"); |
| 172 GURL google_url("http://mail.google.com"); | 172 GURL google_url("http://mail.google.com"); |
| 173 | 173 |
| 174 EXPECT_EQ(CONTENT_SETTING_DEFAULT, | 174 EXPECT_EQ(CONTENT_SETTING_DEFAULT, |
| 175 provider.GetContentSetting( | 175 provider.GetContentSetting( |
| 176 youtube_url, youtube_url, CONTENT_SETTINGS_TYPE_COOKIES, "")); | 176 youtube_url, youtube_url, CONTENT_SETTINGS_TYPE_COOKIES, "")); |
| 177 EXPECT_EQ(NULL, |
| 178 provider.GetContentSettingValue( |
| 179 youtube_url, youtube_url, CONTENT_SETTINGS_TYPE_COOKIES, "")); |
| 180 |
| 177 EXPECT_EQ(CONTENT_SETTING_BLOCK, | 181 EXPECT_EQ(CONTENT_SETTING_BLOCK, |
| 178 provider.GetContentSetting( | 182 provider.GetContentSetting( |
| 179 google_url, google_url, CONTENT_SETTINGS_TYPE_IMAGES, "")); | 183 google_url, google_url, CONTENT_SETTINGS_TYPE_IMAGES, "")); |
| 184 scoped_ptr<Value> value_ptr(provider.GetContentSettingValue( |
| 185 google_url, google_url, CONTENT_SETTINGS_TYPE_IMAGES, "")); |
| 186 int int_value = -1; |
| 187 value_ptr->GetAsInteger(&int_value); |
| 188 EXPECT_EQ(CONTENT_SETTING_BLOCK, IntToContentSetting(int_value)); |
| 180 | 189 |
| 190 // The PolicyProvider does not allow setting content settings as they are |
| 191 // enforced via policies and not set by the user or extension. So a call to |
| 192 // SetContentSetting does nothing. |
| 181 provider.SetContentSetting( | 193 provider.SetContentSetting( |
| 182 yt_url_pattern, | 194 yt_url_pattern, |
| 183 yt_url_pattern, | 195 yt_url_pattern, |
| 184 CONTENT_SETTINGS_TYPE_COOKIES, | 196 CONTENT_SETTINGS_TYPE_COOKIES, |
| 185 "", | 197 "", |
| 186 CONTENT_SETTING_BLOCK); | 198 CONTENT_SETTING_BLOCK); |
| 187 EXPECT_EQ(CONTENT_SETTING_DEFAULT, | 199 EXPECT_EQ(CONTENT_SETTING_DEFAULT, |
| 188 provider.GetContentSetting( | 200 provider.GetContentSetting( |
| 189 youtube_url, youtube_url, CONTENT_SETTINGS_TYPE_COOKIES, "")); | 201 youtube_url, youtube_url, CONTENT_SETTINGS_TYPE_COOKIES, "")); |
| 190 | 202 |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 266 EXPECT_EQ(CONTENT_SETTING_ALLOW, | 278 EXPECT_EQ(CONTENT_SETTING_ALLOW, |
| 267 provider.GetContentSetting( | 279 provider.GetContentSetting( |
| 268 google_url, | 280 google_url, |
| 269 google_url, | 281 google_url, |
| 270 CONTENT_SETTINGS_TYPE_AUTO_SELECT_CERTIFICATE, | 282 CONTENT_SETTINGS_TYPE_AUTO_SELECT_CERTIFICATE, |
| 271 std::string())); | 283 std::string())); |
| 272 | 284 |
| 273 provider.ShutdownOnUIThread(); | 285 provider.ShutdownOnUIThread(); |
| 274 } | 286 } |
| 275 } // namespace content_settings | 287 } // namespace content_settings |
| OLD | NEW |