OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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 "base/path_service.h" | 5 #include "base/path_service.h" |
6 #include "base/prefs/pref_service.h" | 6 #include "base/prefs/pref_service.h" |
7 #include "base/prefs/scoped_user_pref_update.h" | 7 #include "base/prefs/scoped_user_pref_update.h" |
8 #include "base/strings/utf_string_conversions.h" | 8 #include "base/strings/utf_string_conversions.h" |
9 #include "chrome/browser/chrome_notification_types.h" | 9 #include "chrome/browser/chrome_notification_types.h" |
10 #include "chrome/browser/extensions/extension_service_test_base.h" | 10 #include "chrome/browser/extensions/extension_service_test_base.h" |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
96 } // namespace | 96 } // namespace |
97 | 97 |
98 TEST_F(ManagedUserServiceTest, GetManualExceptionsForHost) { | 98 TEST_F(ManagedUserServiceTest, GetManualExceptionsForHost) { |
99 GURL kExampleFooURL("http://www.example.com/foo"); | 99 GURL kExampleFooURL("http://www.example.com/foo"); |
100 GURL kExampleBarURL("http://www.example.com/bar"); | 100 GURL kExampleBarURL("http://www.example.com/bar"); |
101 GURL kExampleFooNoWWWURL("http://example.com/foo"); | 101 GURL kExampleFooNoWWWURL("http://example.com/foo"); |
102 GURL kBlurpURL("http://blurp.net/bla"); | 102 GURL kBlurpURL("http://blurp.net/bla"); |
103 GURL kMooseURL("http://moose.org/baz"); | 103 GURL kMooseURL("http://moose.org/baz"); |
104 { | 104 { |
105 DictionaryPrefUpdate update(profile_->GetPrefs(), | 105 DictionaryPrefUpdate update(profile_->GetPrefs(), |
106 prefs::kManagedModeManualURLs); | 106 prefs::kSupervisedUserManualURLs); |
107 base::DictionaryValue* dict = update.Get(); | 107 base::DictionaryValue* dict = update.Get(); |
108 dict->SetBooleanWithoutPathExpansion(kExampleFooURL.spec(), true); | 108 dict->SetBooleanWithoutPathExpansion(kExampleFooURL.spec(), true); |
109 dict->SetBooleanWithoutPathExpansion(kExampleBarURL.spec(), false); | 109 dict->SetBooleanWithoutPathExpansion(kExampleBarURL.spec(), false); |
110 dict->SetBooleanWithoutPathExpansion(kExampleFooNoWWWURL.spec(), true); | 110 dict->SetBooleanWithoutPathExpansion(kExampleFooNoWWWURL.spec(), true); |
111 dict->SetBooleanWithoutPathExpansion(kBlurpURL.spec(), true); | 111 dict->SetBooleanWithoutPathExpansion(kBlurpURL.spec(), true); |
112 } | 112 } |
113 | 113 |
114 EXPECT_EQ(ManagedUserService::MANUAL_ALLOW, | 114 EXPECT_EQ(ManagedUserService::MANUAL_ALLOW, |
115 managed_user_service_->GetManualBehaviorForURL(kExampleFooURL)); | 115 managed_user_service_->GetManualBehaviorForURL(kExampleFooURL)); |
116 EXPECT_EQ(ManagedUserService::MANUAL_BLOCK, | 116 EXPECT_EQ(ManagedUserService::MANUAL_BLOCK, |
117 managed_user_service_->GetManualBehaviorForURL(kExampleBarURL)); | 117 managed_user_service_->GetManualBehaviorForURL(kExampleBarURL)); |
118 EXPECT_EQ(ManagedUserService::MANUAL_ALLOW, | 118 EXPECT_EQ(ManagedUserService::MANUAL_ALLOW, |
119 managed_user_service_->GetManualBehaviorForURL( | 119 managed_user_service_->GetManualBehaviorForURL( |
120 kExampleFooNoWWWURL)); | 120 kExampleFooNoWWWURL)); |
121 EXPECT_EQ(ManagedUserService::MANUAL_ALLOW, | 121 EXPECT_EQ(ManagedUserService::MANUAL_ALLOW, |
122 managed_user_service_->GetManualBehaviorForURL(kBlurpURL)); | 122 managed_user_service_->GetManualBehaviorForURL(kBlurpURL)); |
123 EXPECT_EQ(ManagedUserService::MANUAL_NONE, | 123 EXPECT_EQ(ManagedUserService::MANUAL_NONE, |
124 managed_user_service_->GetManualBehaviorForURL(kMooseURL)); | 124 managed_user_service_->GetManualBehaviorForURL(kMooseURL)); |
125 std::vector<GURL> exceptions; | 125 std::vector<GURL> exceptions; |
126 managed_user_service_->GetManualExceptionsForHost("www.example.com", | 126 managed_user_service_->GetManualExceptionsForHost("www.example.com", |
127 &exceptions); | 127 &exceptions); |
128 ASSERT_EQ(2u, exceptions.size()); | 128 ASSERT_EQ(2u, exceptions.size()); |
129 EXPECT_EQ(kExampleBarURL, exceptions[0]); | 129 EXPECT_EQ(kExampleBarURL, exceptions[0]); |
130 EXPECT_EQ(kExampleFooURL, exceptions[1]); | 130 EXPECT_EQ(kExampleFooURL, exceptions[1]); |
131 | 131 |
132 { | 132 { |
133 DictionaryPrefUpdate update(profile_->GetPrefs(), | 133 DictionaryPrefUpdate update(profile_->GetPrefs(), |
134 prefs::kManagedModeManualURLs); | 134 prefs::kSupervisedUserManualURLs); |
135 base::DictionaryValue* dict = update.Get(); | 135 base::DictionaryValue* dict = update.Get(); |
136 for (std::vector<GURL>::iterator it = exceptions.begin(); | 136 for (std::vector<GURL>::iterator it = exceptions.begin(); |
137 it != exceptions.end(); ++it) { | 137 it != exceptions.end(); ++it) { |
138 dict->RemoveWithoutPathExpansion(it->spec(), NULL); | 138 dict->RemoveWithoutPathExpansion(it->spec(), NULL); |
139 } | 139 } |
140 } | 140 } |
141 | 141 |
142 EXPECT_EQ(ManagedUserService::MANUAL_NONE, | 142 EXPECT_EQ(ManagedUserService::MANUAL_NONE, |
143 managed_user_service_->GetManualBehaviorForURL(kExampleFooURL)); | 143 managed_user_service_->GetManualBehaviorForURL(kExampleFooURL)); |
144 EXPECT_EQ(ManagedUserService::MANUAL_NONE, | 144 EXPECT_EQ(ManagedUserService::MANUAL_NONE, |
(...skipping 25 matching lines...) Expand all Loading... |
170 public: | 170 public: |
171 explicit ManagedUserServiceExtensionTestBase(bool is_managed) | 171 explicit ManagedUserServiceExtensionTestBase(bool is_managed) |
172 : is_managed_(is_managed), | 172 : is_managed_(is_managed), |
173 channel_(chrome::VersionInfo::CHANNEL_DEV) {} | 173 channel_(chrome::VersionInfo::CHANNEL_DEV) {} |
174 virtual ~ManagedUserServiceExtensionTestBase() {} | 174 virtual ~ManagedUserServiceExtensionTestBase() {} |
175 | 175 |
176 virtual void SetUp() OVERRIDE { | 176 virtual void SetUp() OVERRIDE { |
177 ExtensionServiceTestBase::SetUp(); | 177 ExtensionServiceTestBase::SetUp(); |
178 ExtensionServiceTestBase::ExtensionServiceInitParams params = | 178 ExtensionServiceTestBase::ExtensionServiceInitParams params = |
179 CreateDefaultInitParams(); | 179 CreateDefaultInitParams(); |
180 params.profile_is_managed = is_managed_; | 180 params.profile_is_supervised = is_managed_; |
181 InitializeExtensionService(params); | 181 InitializeExtensionService(params); |
182 ManagedUserServiceFactory::GetForProfile(profile_.get())->Init(); | 182 ManagedUserServiceFactory::GetForProfile(profile_.get())->Init(); |
183 } | 183 } |
184 | 184 |
185 protected: | 185 protected: |
186 ScopedVector<ManagedModeSiteList> GetActiveSiteLists( | 186 ScopedVector<ManagedModeSiteList> GetActiveSiteLists( |
187 ManagedUserService* managed_user_service) { | 187 ManagedUserService* managed_user_service) { |
188 return managed_user_service->GetActiveSiteLists(); | 188 return managed_user_service->GetActiveSiteLists(); |
189 } | 189 } |
190 | 190 |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
225 : public ManagedUserServiceExtensionTestBase { | 225 : public ManagedUserServiceExtensionTestBase { |
226 public: | 226 public: |
227 ManagedUserServiceExtensionTest() | 227 ManagedUserServiceExtensionTest() |
228 : ManagedUserServiceExtensionTestBase(true) {} | 228 : ManagedUserServiceExtensionTestBase(true) {} |
229 }; | 229 }; |
230 | 230 |
231 TEST_F(ManagedUserServiceExtensionTestUnmanaged, | 231 TEST_F(ManagedUserServiceExtensionTestUnmanaged, |
232 ExtensionManagementPolicyProvider) { | 232 ExtensionManagementPolicyProvider) { |
233 ManagedUserService* managed_user_service = | 233 ManagedUserService* managed_user_service = |
234 ManagedUserServiceFactory::GetForProfile(profile_.get()); | 234 ManagedUserServiceFactory::GetForProfile(profile_.get()); |
235 EXPECT_FALSE(profile_->IsManaged()); | 235 EXPECT_FALSE(profile_->IsSupervised()); |
236 | 236 |
237 scoped_refptr<extensions::Extension> extension = MakeExtension(); | 237 scoped_refptr<extensions::Extension> extension = MakeExtension(); |
238 base::string16 error_1; | 238 base::string16 error_1; |
239 EXPECT_TRUE(managed_user_service->UserMayLoad(extension.get(), &error_1)); | 239 EXPECT_TRUE(managed_user_service->UserMayLoad(extension.get(), &error_1)); |
240 EXPECT_EQ(base::string16(), error_1); | 240 EXPECT_EQ(base::string16(), error_1); |
241 | 241 |
242 base::string16 error_2; | 242 base::string16 error_2; |
243 EXPECT_TRUE( | 243 EXPECT_TRUE( |
244 managed_user_service->UserMayModifySettings(extension.get(), &error_2)); | 244 managed_user_service->UserMayModifySettings(extension.get(), &error_2)); |
245 EXPECT_EQ(base::string16(), error_2); | 245 EXPECT_EQ(base::string16(), error_2); |
246 } | 246 } |
247 | 247 |
248 TEST_F(ManagedUserServiceExtensionTest, ExtensionManagementPolicyProvider) { | 248 TEST_F(ManagedUserServiceExtensionTest, ExtensionManagementPolicyProvider) { |
249 ManagedUserService* managed_user_service = | 249 ManagedUserService* managed_user_service = |
250 ManagedUserServiceFactory::GetForProfile(profile_.get()); | 250 ManagedUserServiceFactory::GetForProfile(profile_.get()); |
251 ManagedModeURLFilterObserver observer( | 251 ManagedModeURLFilterObserver observer( |
252 managed_user_service->GetURLFilterForUIThread()); | 252 managed_user_service->GetURLFilterForUIThread()); |
253 ASSERT_TRUE(profile_->IsManaged()); | 253 ASSERT_TRUE(profile_->IsSupervised()); |
254 // Wait for the initial update to finish (otherwise we'll get leaks). | 254 // Wait for the initial update to finish (otherwise we'll get leaks). |
255 observer.Wait(); | 255 observer.Wait(); |
256 | 256 |
257 // Check that a supervised user can install a theme. | 257 // Check that a supervised user can install a theme. |
258 scoped_refptr<extensions::Extension> theme = MakeThemeExtension(); | 258 scoped_refptr<extensions::Extension> theme = MakeThemeExtension(); |
259 base::string16 error_1; | 259 base::string16 error_1; |
260 EXPECT_TRUE(managed_user_service->UserMayLoad(theme.get(), &error_1)); | 260 EXPECT_TRUE(managed_user_service->UserMayLoad(theme.get(), &error_1)); |
261 EXPECT_TRUE(error_1.empty()); | 261 EXPECT_TRUE(error_1.empty()); |
262 EXPECT_TRUE( | 262 EXPECT_TRUE( |
263 managed_user_service->UserMayModifySettings(theme.get(), &error_1)); | 263 managed_user_service->UserMayModifySettings(theme.get(), &error_1)); |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
298 ManagedModeURLFilter* url_filter = | 298 ManagedModeURLFilter* url_filter = |
299 managed_user_service->GetURLFilterForUIThread(); | 299 managed_user_service->GetURLFilterForUIThread(); |
300 ManagedModeURLFilterObserver observer(url_filter); | 300 ManagedModeURLFilterObserver observer(url_filter); |
301 observer.Wait(); | 301 observer.Wait(); |
302 | 302 |
303 GURL example_url("http://example.com"); | 303 GURL example_url("http://example.com"); |
304 GURL moose_url("http://moose.org"); | 304 GURL moose_url("http://moose.org"); |
305 EXPECT_EQ(ManagedModeURLFilter::ALLOW, | 305 EXPECT_EQ(ManagedModeURLFilter::ALLOW, |
306 url_filter->GetFilteringBehaviorForURL(example_url)); | 306 url_filter->GetFilteringBehaviorForURL(example_url)); |
307 | 307 |
308 profile_->GetPrefs()->SetInteger(prefs::kDefaultManagedModeFilteringBehavior, | 308 profile_->GetPrefs()->SetInteger( |
309 ManagedModeURLFilter::BLOCK); | 309 prefs::kDefaultSupervisedUserFilteringBehavior, |
| 310 ManagedModeURLFilter::BLOCK); |
310 EXPECT_EQ(ManagedModeURLFilter::BLOCK, | 311 EXPECT_EQ(ManagedModeURLFilter::BLOCK, |
311 url_filter->GetFilteringBehaviorForURL(example_url)); | 312 url_filter->GetFilteringBehaviorForURL(example_url)); |
312 | 313 |
313 profile_->GetPrefs()->SetInteger(prefs::kDefaultManagedModeFilteringBehavior, | 314 profile_->GetPrefs()->SetInteger( |
314 ManagedModeURLFilter::WARN); | 315 prefs::kDefaultSupervisedUserFilteringBehavior, |
| 316 ManagedModeURLFilter::WARN); |
315 EXPECT_EQ(ManagedModeURLFilter::WARN, | 317 EXPECT_EQ(ManagedModeURLFilter::WARN, |
316 url_filter->GetFilteringBehaviorForURL(example_url)); | 318 url_filter->GetFilteringBehaviorForURL(example_url)); |
317 | 319 |
318 managed_user_service->set_elevated_for_testing(true); | 320 managed_user_service->set_elevated_for_testing(true); |
319 | 321 |
320 // Load a content pack. | 322 // Load a content pack. |
321 scoped_refptr<extensions::UnpackedInstaller> installer( | 323 scoped_refptr<extensions::UnpackedInstaller> installer( |
322 extensions::UnpackedInstaller::Create(service_)); | 324 extensions::UnpackedInstaller::Create(service_)); |
323 installer->set_prompt_for_plugins(false); | 325 installer->set_prompt_for_plugins(false); |
324 base::FilePath test_data_dir; | 326 base::FilePath test_data_dir; |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
392 site_lists[0]->GetSites(&sites); | 394 site_lists[0]->GetSites(&sites); |
393 ASSERT_EQ(1u, sites.size()); | 395 ASSERT_EQ(1u, sites.size()); |
394 EXPECT_EQ(base::ASCIIToUTF16("Moose"), sites[0].name); | 396 EXPECT_EQ(base::ASCIIToUTF16("Moose"), sites[0].name); |
395 | 397 |
396 EXPECT_EQ(ManagedModeURLFilter::WARN, | 398 EXPECT_EQ(ManagedModeURLFilter::WARN, |
397 url_filter->GetFilteringBehaviorForURL(example_url)); | 399 url_filter->GetFilteringBehaviorForURL(example_url)); |
398 EXPECT_EQ(ManagedModeURLFilter::ALLOW, | 400 EXPECT_EQ(ManagedModeURLFilter::ALLOW, |
399 url_filter->GetFilteringBehaviorForURL(moose_url)); | 401 url_filter->GetFilteringBehaviorForURL(moose_url)); |
400 } | 402 } |
401 #endif // !defined(OS_ANDROID) | 403 #endif // !defined(OS_ANDROID) |
OLD | NEW |