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

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

Issue 6542048: Add content_settings::PolicyProvider and a set of new policies to managed content settings. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: " Created 9 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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"
8 #include "base/command_line.h"
7 #include "chrome/browser/browser_thread.h" 9 #include "chrome/browser/browser_thread.h"
8 #include "chrome/browser/content_settings/stub_settings_observer.h" 10 #include "chrome/browser/content_settings/stub_settings_observer.h"
9 #include "chrome/browser/prefs/pref_service.h" 11 #include "chrome/browser/prefs/pref_service.h"
12 #include "chrome/common/chrome_switches.h"
10 #include "chrome/common/pref_names.h" 13 #include "chrome/common/pref_names.h"
11 #include "chrome/common/url_constants.h" 14 #include "chrome/common/url_constants.h"
12 #include "chrome/test/testing_browser_process_test.h" 15 #include "chrome/test/testing_browser_process_test.h"
13 #include "chrome/test/testing_pref_service.h" 16 #include "chrome/test/testing_pref_service.h"
14 #include "chrome/test/testing_profile.h" 17 #include "chrome/test/testing_profile.h"
15 #include "testing/gtest/include/gtest/gtest.h" 18 #include "testing/gtest/include/gtest/gtest.h"
16 19 #include "googleurl/src/gurl.h"
17 20
18 namespace content_settings { 21 namespace content_settings {
19 22
20 class PolicyDefaultProviderTest : public TestingBrowserProcessTest { 23 class PolicyDefaultProviderTest : public TestingBrowserProcessTest {
21 public: 24 public:
22 PolicyDefaultProviderTest() 25 PolicyDefaultProviderTest()
23 : ui_thread_(BrowserThread::UI, &message_loop_) { 26 : ui_thread_(BrowserThread::UI, &message_loop_) {
24 } 27 }
25 28
26 protected: 29 protected:
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
74 // Remove the managed default-content-setting. 77 // Remove the managed default-content-setting.
75 prefs->RemoveManagedPref(prefs::kManagedDefaultImagesSetting); 78 prefs->RemoveManagedPref(prefs::kManagedDefaultImagesSetting);
76 EXPECT_EQ(profile.GetHostContentSettingsMap(), observer.last_notifier); 79 EXPECT_EQ(profile.GetHostContentSettingsMap(), observer.last_notifier);
77 EXPECT_EQ(CONTENT_SETTINGS_TYPE_DEFAULT, observer.last_type); 80 EXPECT_EQ(CONTENT_SETTINGS_TYPE_DEFAULT, observer.last_type);
78 EXPECT_EQ(ContentSettingsPattern(), observer.last_pattern); 81 EXPECT_EQ(ContentSettingsPattern(), observer.last_pattern);
79 EXPECT_TRUE(observer.last_update_all); 82 EXPECT_TRUE(observer.last_update_all);
80 EXPECT_TRUE(observer.last_update_all_types); 83 EXPECT_TRUE(observer.last_update_all_types);
81 EXPECT_EQ(2, observer.counter); 84 EXPECT_EQ(2, observer.counter);
82 } 85 }
83 86
87 class PolicyProviderTest : public testing::Test {
88 public:
89 PolicyProviderTest()
90 : ui_thread_(BrowserThread::UI, &message_loop_) {
91 }
92
93 protected:
94 // TODO(markusheintz): Check if it's possible to derive the provider class
95 // from NonThreadSafe and to use native thread identifiers instead of
96 // BrowserThread IDs. Then we could get rid of the message_loop and ui_thread
97 // fields.
98 MessageLoop message_loop_;
99 BrowserThread ui_thread_;
100 };
101
102 TEST_F(PolicyProviderTest, Default) {
103 TestingProfile profile;
104 TestingPrefService* prefs = profile.GetTestingPrefService();
105
106 ListValue* value = new ListValue();
107 value->Append(Value::CreateStringValue("[*.]google.com"));
108 prefs->SetManagedPref(prefs::kManagedImagesBlockedForUrls,
109 value);
110
111 PolicyProvider provider(static_cast<Profile*>(&profile));
112
113 ContentSettingsPattern yt_url_pattern("www.youtube.com");
114 GURL youtube_url("http://www.youtube.com");
115 GURL google_url("http://mail.google.com");
116
117 EXPECT_EQ(CONTENT_SETTING_DEFAULT,
118 provider.GetContentSetting(
119 youtube_url, youtube_url, CONTENT_SETTINGS_TYPE_COOKIES, ""));
120 EXPECT_EQ(CONTENT_SETTING_BLOCK,
121 provider.GetContentSetting(
122 google_url, google_url, CONTENT_SETTINGS_TYPE_IMAGES, ""));
123
124 provider.SetContentSetting(
125 yt_url_pattern,
126 yt_url_pattern,
127 CONTENT_SETTINGS_TYPE_COOKIES,
128 "",
129 CONTENT_SETTING_BLOCK);
130 EXPECT_EQ(CONTENT_SETTING_DEFAULT,
131 provider.GetContentSetting(
132 youtube_url, youtube_url, CONTENT_SETTINGS_TYPE_COOKIES, ""));
133 }
134
135 TEST_F(PolicyProviderTest, ResourceIdentifier) {
136 CommandLine* cmd = CommandLine::ForCurrentProcess();
137 AutoReset<CommandLine> auto_reset(cmd, *cmd);
138 cmd->AppendSwitch(switches::kEnableResourceContentSettings);
139
140 TestingProfile profile;
141 TestingPrefService* prefs = profile.GetTestingPrefService();
142
143 ListValue* value = new ListValue();
144 value->Append(Value::CreateStringValue("[*.]google.com"));
145 prefs->SetManagedPref(prefs::kManagedPluginsAllowedForUrls,
146 value);
147
148 PolicyProvider provider(static_cast<Profile*>(&profile));
149
150 GURL youtube_url("http://www.youtube.com");
151 GURL google_url("http://mail.google.com");
152
153 EXPECT_EQ(CONTENT_SETTING_DEFAULT,
154 provider.GetContentSetting(
155 youtube_url,
156 youtube_url,
157 CONTENT_SETTINGS_TYPE_PLUGINS,
158 "someplugin"));
159
160 // There is no policy support for resource content settings until the feature
161 // is enabled by default. Resource identifiers are simply ignored by the
162 // PolicyProvider.
163 EXPECT_EQ(CONTENT_SETTING_ALLOW,
164 provider.GetContentSetting(
165 google_url,
166 google_url,
167 CONTENT_SETTINGS_TYPE_PLUGINS,
168 ""));
169
170 EXPECT_EQ(CONTENT_SETTING_ALLOW,
171 provider.GetContentSetting(
172 google_url,
173 google_url,
174 CONTENT_SETTINGS_TYPE_PLUGINS,
175 "someplugin"));
176
177 EXPECT_EQ(CONTENT_SETTING_ALLOW,
178 provider.GetContentSetting(
179 google_url,
180 google_url,
181 CONTENT_SETTINGS_TYPE_PLUGINS,
182 "anotherplugin"));
183 }
184
84 } // namespace content_settings 185 } // namespace content_settings
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698