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

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 MessageLoop message_loop_;
95 BrowserThread ui_thread_;
96 };
97
98 TEST_F(PolicyProviderTest, Default) {
99 TestingProfile profile;
100 TestingPrefService* prefs = profile.GetTestingPrefService();
101
102 ListValue* value = new ListValue();
103 value->Append(Value::CreateStringValue("[*.]google.com"));
104 prefs->SetManagedPref(prefs::kManagedImagesBlockedForUrls,
105 value);
106
107 PolicyProvider provider(static_cast<Profile*>(&profile));
108
109 ContentSettingsPattern yt_url_pattern("www.youtube.com");
110 GURL youtube_url("http://www.youtube.com");
111 GURL google_url("http://mail.google.com");
112
113 EXPECT_EQ(CONTENT_SETTING_DEFAULT,
114 provider.GetContentSetting(
115 youtube_url, youtube_url, CONTENT_SETTINGS_TYPE_COOKIES, ""));
116 EXPECT_EQ(CONTENT_SETTING_BLOCK,
117 provider.GetContentSetting(
118 google_url, google_url, CONTENT_SETTINGS_TYPE_IMAGES, ""));
119
120 provider.SetContentSetting(
121 yt_url_pattern,
122 yt_url_pattern,
123 CONTENT_SETTINGS_TYPE_COOKIES,
124 "",
125 CONTENT_SETTING_BLOCK);
126 EXPECT_EQ(CONTENT_SETTING_DEFAULT,
127 provider.GetContentSetting(
128 youtube_url, youtube_url, CONTENT_SETTINGS_TYPE_COOKIES, ""));
129 }
130
131 TEST_F(PolicyProviderTest, ResourceIdentifier) {
132 CommandLine* cmd = CommandLine::ForCurrentProcess();
133 AutoReset<CommandLine> auto_reset(cmd, *cmd);
134 cmd->AppendSwitch(switches::kEnableResourceContentSettings);
135
136 TestingProfile profile;
137 TestingPrefService* prefs = profile.GetTestingPrefService();
138
139 ListValue* value = new ListValue();
140 value->Append(Value::CreateStringValue("[*.]google.com"));
141 prefs->SetManagedPref(prefs::kManagedPluginsAllowedForUrls,
142 value);
143
144 PolicyProvider provider(static_cast<Profile*>(&profile));
145
146 GURL youtube_url("http://www.youtube.com");
147 GURL google_url("http://mail.google.com");
148
149 EXPECT_EQ(CONTENT_SETTING_DEFAULT,
150 provider.GetContentSetting(
151 youtube_url,
152 youtube_url,
153 CONTENT_SETTINGS_TYPE_PLUGINS,
154 "someplugin"));
155
156 // There is no policy support for resource content settings until the feature
157 // is enabled by default. Resource identifiers are simply ignored by the
158 // PolicyProvider.
159 EXPECT_EQ(CONTENT_SETTING_ALLOW,
160 provider.GetContentSetting(
161 google_url,
162 google_url,
163 CONTENT_SETTINGS_TYPE_PLUGINS,
164 ""));
165
166 EXPECT_EQ(CONTENT_SETTING_ALLOW,
167 provider.GetContentSetting(
168 google_url,
169 google_url,
170 CONTENT_SETTINGS_TYPE_PLUGINS,
171 "someplugin"));
172
173 EXPECT_EQ(CONTENT_SETTING_ALLOW,
174 provider.GetContentSetting(
175 google_url,
176 google_url,
177 CONTENT_SETTINGS_TYPE_PLUGINS,
178 "anotherplugin"));
179 }
180
84 } // namespace content_settings 181 } // namespace content_settings
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698