OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 <algorithm> | 5 #include <algorithm> |
6 #include <vector> | 6 #include <vector> |
7 | 7 |
8 #include "base/json/json_parser.h" | 8 #include "base/json/json_parser.h" |
9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
10 #include "base/prefs/pref_registry_simple.h" | 10 #include "base/prefs/pref_registry_simple.h" |
11 #include "base/prefs/testing_pref_service.h" | 11 #include "base/prefs/testing_pref_service.h" |
12 #include "base/values.h" | 12 #include "base/values.h" |
13 #include "chrome/browser/extensions/extension_management.h" | 13 #include "chrome/browser/extensions/extension_management.h" |
| 14 #include "chrome/browser/extensions/extension_management_internal.h" |
14 #include "chrome/browser/extensions/extension_management_test_util.h" | 15 #include "chrome/browser/extensions/extension_management_test_util.h" |
15 #include "chrome/browser/extensions/external_policy_loader.h" | 16 #include "chrome/browser/extensions/external_policy_loader.h" |
16 #include "extensions/browser/pref_names.h" | 17 #include "extensions/browser/pref_names.h" |
17 #include "extensions/common/manifest.h" | 18 #include "extensions/common/manifest.h" |
18 #include "extensions/common/manifest_constants.h" | 19 #include "extensions/common/manifest_constants.h" |
19 #include "extensions/common/url_pattern.h" | 20 #include "extensions/common/url_pattern.h" |
20 #include "testing/gtest/include/gtest/gtest.h" | 21 #include "testing/gtest/include/gtest/gtest.h" |
21 #include "url/gurl.h" | 22 #include "url/gurl.h" |
22 | 23 |
23 namespace extensions { | 24 namespace extensions { |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
86 pref_service_->SetUserPref(path, value); | 87 pref_service_->SetUserPref(path, value); |
87 } | 88 } |
88 | 89 |
89 void RemovePref(bool managed, const char* path) { | 90 void RemovePref(bool managed, const char* path) { |
90 if (managed) | 91 if (managed) |
91 pref_service_->RemoveManagedPref(path); | 92 pref_service_->RemoveManagedPref(path); |
92 else | 93 else |
93 pref_service_->RemoveUserPref(path); | 94 pref_service_->RemoveUserPref(path); |
94 } | 95 } |
95 | 96 |
| 97 const internal::IndividualSettings* ReadById(const ExtensionId& id) { |
| 98 return extension_management_->ReadById(id); |
| 99 } |
| 100 |
| 101 const internal::GlobalSettings* ReadGlobalSettings() { |
| 102 return extension_management_->ReadGlobalSettings(); |
| 103 } |
| 104 |
96 void SetExampleDictPref() { | 105 void SetExampleDictPref() { |
97 std::string error_msg; | 106 std::string error_msg; |
98 scoped_ptr<base::Value> parsed(base::JSONReader::ReadAndReturnError( | 107 scoped_ptr<base::Value> parsed(base::JSONReader::ReadAndReturnError( |
99 kExampleDictPreference, | 108 kExampleDictPreference, |
100 base::JSONParserOptions::JSON_ALLOW_TRAILING_COMMAS, | 109 base::JSONParserOptions::JSON_ALLOW_TRAILING_COMMAS, |
101 NULL, | 110 NULL, |
102 &error_msg)); | 111 &error_msg)); |
103 ASSERT_TRUE(parsed && parsed->IsType(base::Value::TYPE_DICTIONARY)) | 112 ASSERT_TRUE(parsed && parsed->IsType(base::Value::TYPE_DICTIONARY)) |
104 << error_msg; | 113 << error_msg; |
105 SetPref(true, pref_names::kExtensionManagement, parsed.release()); | 114 SetPref(true, pref_names::kExtensionManagement, parsed.release()); |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
195 } | 204 } |
196 | 205 |
197 // Verify that preference controlled by legacy ExtensionInstallSources policy is | 206 // Verify that preference controlled by legacy ExtensionInstallSources policy is |
198 // handled well. | 207 // handled well. |
199 TEST_F(ExtensionManagementServiceTest, LegacyInstallSources) { | 208 TEST_F(ExtensionManagementServiceTest, LegacyInstallSources) { |
200 base::ListValue allowed_sites_pref; | 209 base::ListValue allowed_sites_pref; |
201 allowed_sites_pref.AppendString("https://www.example.com/foo"); | 210 allowed_sites_pref.AppendString("https://www.example.com/foo"); |
202 allowed_sites_pref.AppendString("https://corp.mycompany.com/*"); | 211 allowed_sites_pref.AppendString("https://corp.mycompany.com/*"); |
203 SetPref( | 212 SetPref( |
204 true, pref_names::kAllowedInstallSites, allowed_sites_pref.DeepCopy()); | 213 true, pref_names::kAllowedInstallSites, allowed_sites_pref.DeepCopy()); |
205 const URLPatternSet& allowed_sites = | 214 const URLPatternSet& allowed_sites = ReadGlobalSettings()->install_sources; |
206 extension_management_->ReadGlobalSettings().install_sources; | 215 ASSERT_TRUE(ReadGlobalSettings()->has_restricted_install_sources); |
207 ASSERT_TRUE(extension_management_->ReadGlobalSettings() | |
208 .has_restricted_install_sources); | |
209 EXPECT_FALSE(allowed_sites.is_empty()); | 216 EXPECT_FALSE(allowed_sites.is_empty()); |
210 EXPECT_TRUE(allowed_sites.MatchesURL(GURL("https://www.example.com/foo"))); | 217 EXPECT_TRUE(allowed_sites.MatchesURL(GURL("https://www.example.com/foo"))); |
211 EXPECT_FALSE(allowed_sites.MatchesURL(GURL("https://www.example.com/bar"))); | 218 EXPECT_FALSE(allowed_sites.MatchesURL(GURL("https://www.example.com/bar"))); |
212 EXPECT_TRUE( | 219 EXPECT_TRUE( |
213 allowed_sites.MatchesURL(GURL("https://corp.mycompany.com/entry"))); | 220 allowed_sites.MatchesURL(GURL("https://corp.mycompany.com/entry"))); |
214 EXPECT_FALSE( | 221 EXPECT_FALSE( |
215 allowed_sites.MatchesURL(GURL("https://www.mycompany.com/entry"))); | 222 allowed_sites.MatchesURL(GURL("https://www.mycompany.com/entry"))); |
216 } | 223 } |
217 | 224 |
218 // Verify that preference controlled by legacy ExtensionAllowedTypes policy is | 225 // Verify that preference controlled by legacy ExtensionAllowedTypes policy is |
219 // handled well. | 226 // handled well. |
220 TEST_F(ExtensionManagementServiceTest, LegacyAllowedTypes) { | 227 TEST_F(ExtensionManagementServiceTest, LegacyAllowedTypes) { |
221 base::ListValue allowed_types_pref; | 228 base::ListValue allowed_types_pref; |
222 allowed_types_pref.AppendInteger(Manifest::TYPE_THEME); | 229 allowed_types_pref.AppendInteger(Manifest::TYPE_THEME); |
223 allowed_types_pref.AppendInteger(Manifest::TYPE_USER_SCRIPT); | 230 allowed_types_pref.AppendInteger(Manifest::TYPE_USER_SCRIPT); |
224 | 231 |
225 SetPref(true, pref_names::kAllowedTypes, allowed_types_pref.DeepCopy()); | 232 SetPref(true, pref_names::kAllowedTypes, allowed_types_pref.DeepCopy()); |
226 const std::vector<Manifest::Type>& allowed_types = | 233 const std::vector<Manifest::Type>& allowed_types = |
227 extension_management_->ReadGlobalSettings().allowed_types; | 234 ReadGlobalSettings()->allowed_types; |
228 ASSERT_TRUE( | 235 ASSERT_TRUE(ReadGlobalSettings()->has_restricted_allowed_types); |
229 extension_management_->ReadGlobalSettings().has_restricted_allowed_types); | |
230 EXPECT_TRUE(allowed_types.size() == 2); | 236 EXPECT_TRUE(allowed_types.size() == 2); |
231 EXPECT_FALSE(std::find(allowed_types.begin(), | 237 EXPECT_FALSE(std::find(allowed_types.begin(), |
232 allowed_types.end(), | 238 allowed_types.end(), |
233 Manifest::TYPE_EXTENSION) != allowed_types.end()); | 239 Manifest::TYPE_EXTENSION) != allowed_types.end()); |
234 EXPECT_TRUE(std::find(allowed_types.begin(), | 240 EXPECT_TRUE(std::find(allowed_types.begin(), |
235 allowed_types.end(), | 241 allowed_types.end(), |
236 Manifest::TYPE_THEME) != allowed_types.end()); | 242 Manifest::TYPE_THEME) != allowed_types.end()); |
237 EXPECT_TRUE(std::find(allowed_types.begin(), | 243 EXPECT_TRUE(std::find(allowed_types.begin(), |
238 allowed_types.end(), | 244 allowed_types.end(), |
239 Manifest::TYPE_USER_SCRIPT) != allowed_types.end()); | 245 Manifest::TYPE_USER_SCRIPT) != allowed_types.end()); |
240 } | 246 } |
241 | 247 |
242 // Verify that preference controlled by legacy ExtensionInstallBlacklist policy | 248 // Verify that preference controlled by legacy ExtensionInstallBlacklist policy |
243 // is handled well. | 249 // is handled well. |
244 TEST_F(ExtensionManagementServiceTest, LegacyInstallBlacklist) { | 250 TEST_F(ExtensionManagementServiceTest, LegacyInstallBlacklist) { |
245 base::ListValue denied_list_pref; | 251 base::ListValue denied_list_pref; |
246 denied_list_pref.AppendString(kTargetExtension); | 252 denied_list_pref.AppendString(kTargetExtension); |
247 | 253 |
248 SetPref(true, pref_names::kInstallDenyList, denied_list_pref.DeepCopy()); | 254 SetPref(true, pref_names::kInstallDenyList, denied_list_pref.DeepCopy()); |
249 EXPECT_EQ(extension_management_->ReadById(kTargetExtension).installation_mode, | 255 EXPECT_EQ(ReadById(kTargetExtension)->installation_mode, |
250 ExtensionManagement::INSTALLATION_BLOCKED); | 256 ExtensionManagement::INSTALLATION_BLOCKED); |
251 EXPECT_EQ(extension_management_->ReadById(kOtherExtension).installation_mode, | 257 EXPECT_EQ(ReadById(kOtherExtension)->installation_mode, |
252 ExtensionManagement::INSTALLATION_ALLOWED); | 258 ExtensionManagement::INSTALLATION_ALLOWED); |
253 } | 259 } |
254 | 260 |
255 // Verify that preference controlled by legacy ExtensionInstallWhitelist policy | 261 // Verify that preference controlled by legacy ExtensionInstallWhitelist policy |
256 // is handled well. | 262 // is handled well. |
257 TEST_F(ExtensionManagementServiceTest, LegacyInstallWhitelist) { | 263 TEST_F(ExtensionManagementServiceTest, LegacyInstallWhitelist) { |
258 base::ListValue denied_list_pref; | 264 base::ListValue denied_list_pref; |
259 denied_list_pref.AppendString("*"); | 265 denied_list_pref.AppendString("*"); |
260 base::ListValue allowed_list_pref; | 266 base::ListValue allowed_list_pref; |
261 allowed_list_pref.AppendString(kTargetExtension); | 267 allowed_list_pref.AppendString(kTargetExtension); |
262 | 268 |
263 SetPref(true, pref_names::kInstallDenyList, denied_list_pref.DeepCopy()); | 269 SetPref(true, pref_names::kInstallDenyList, denied_list_pref.DeepCopy()); |
264 SetPref(true, pref_names::kInstallAllowList, allowed_list_pref.DeepCopy()); | 270 SetPref(true, pref_names::kInstallAllowList, allowed_list_pref.DeepCopy()); |
265 EXPECT_EQ(extension_management_->ReadById(kTargetExtension).installation_mode, | 271 EXPECT_EQ(ReadById(kTargetExtension)->installation_mode, |
266 ExtensionManagement::INSTALLATION_ALLOWED); | 272 ExtensionManagement::INSTALLATION_ALLOWED); |
267 EXPECT_EQ(extension_management_->ReadById(kOtherExtension).installation_mode, | 273 EXPECT_EQ(ReadById(kOtherExtension)->installation_mode, |
268 ExtensionManagement::INSTALLATION_BLOCKED); | 274 ExtensionManagement::INSTALLATION_BLOCKED); |
269 | 275 |
270 // Verify that install whitelist preference set by user is ignored. | 276 // Verify that install whitelist preference set by user is ignored. |
271 RemovePref(true, pref_names::kInstallAllowList); | 277 RemovePref(true, pref_names::kInstallAllowList); |
272 SetPref(false, pref_names::kInstallAllowList, allowed_list_pref.DeepCopy()); | 278 SetPref(false, pref_names::kInstallAllowList, allowed_list_pref.DeepCopy()); |
273 EXPECT_EQ(extension_management_->ReadById(kTargetExtension).installation_mode, | 279 EXPECT_EQ(ReadById(kTargetExtension)->installation_mode, |
274 ExtensionManagement::INSTALLATION_BLOCKED); | 280 ExtensionManagement::INSTALLATION_BLOCKED); |
275 } | 281 } |
276 | 282 |
277 // Verify that preference controlled by legacy ExtensionInstallForcelist policy | 283 // Verify that preference controlled by legacy ExtensionInstallForcelist policy |
278 // is handled well. | 284 // is handled well. |
279 TEST_F(ExtensionManagementServiceTest, LegacyInstallForcelist) { | 285 TEST_F(ExtensionManagementServiceTest, LegacyInstallForcelist) { |
280 base::DictionaryValue forced_list_pref; | 286 base::DictionaryValue forced_list_pref; |
281 ExternalPolicyLoader::AddExtension( | 287 ExternalPolicyLoader::AddExtension( |
282 &forced_list_pref, kTargetExtension, kExampleUpdateUrl); | 288 &forced_list_pref, kTargetExtension, kExampleUpdateUrl); |
283 | 289 |
284 SetPref(true, pref_names::kInstallForceList, forced_list_pref.DeepCopy()); | 290 SetPref(true, pref_names::kInstallForceList, forced_list_pref.DeepCopy()); |
285 EXPECT_EQ(extension_management_->ReadById(kTargetExtension).installation_mode, | 291 EXPECT_EQ(ReadById(kTargetExtension)->installation_mode, |
286 ExtensionManagement::INSTALLATION_FORCED); | 292 ExtensionManagement::INSTALLATION_FORCED); |
287 EXPECT_EQ(extension_management_->ReadById(kTargetExtension).update_url, | 293 EXPECT_EQ(ReadById(kTargetExtension)->update_url, kExampleUpdateUrl); |
288 kExampleUpdateUrl); | 294 EXPECT_EQ(ReadById(kOtherExtension)->installation_mode, |
289 EXPECT_EQ(extension_management_->ReadById(kOtherExtension).installation_mode, | |
290 ExtensionManagement::INSTALLATION_ALLOWED); | 295 ExtensionManagement::INSTALLATION_ALLOWED); |
291 | 296 |
292 // Verify that install forcelist preference set by user is ignored. | 297 // Verify that install forcelist preference set by user is ignored. |
293 RemovePref(true, pref_names::kInstallForceList); | 298 RemovePref(true, pref_names::kInstallForceList); |
294 SetPref(false, pref_names::kInstallForceList, forced_list_pref.DeepCopy()); | 299 SetPref(false, pref_names::kInstallForceList, forced_list_pref.DeepCopy()); |
295 EXPECT_EQ(extension_management_->ReadById(kTargetExtension).installation_mode, | 300 EXPECT_EQ(ReadById(kTargetExtension)->installation_mode, |
296 ExtensionManagement::INSTALLATION_ALLOWED); | 301 ExtensionManagement::INSTALLATION_ALLOWED); |
297 } | 302 } |
298 | 303 |
299 // Tests parsing of new dictionary preference. | 304 // Tests parsing of new dictionary preference. |
300 TEST_F(ExtensionManagementServiceTest, PreferenceParsing) { | 305 TEST_F(ExtensionManagementServiceTest, PreferenceParsing) { |
301 SetExampleDictPref(); | 306 SetExampleDictPref(); |
302 | 307 |
303 // Verifies the installation mode settings. | 308 // Verifies the installation mode settings. |
304 EXPECT_TRUE(extension_management_->BlacklistedByDefault()); | 309 EXPECT_TRUE(extension_management_->BlacklistedByDefault()); |
305 EXPECT_EQ(extension_management_->ReadById(kTargetExtension).installation_mode, | 310 EXPECT_EQ(ReadById(kTargetExtension)->installation_mode, |
306 ExtensionManagement::INSTALLATION_ALLOWED); | 311 ExtensionManagement::INSTALLATION_ALLOWED); |
307 EXPECT_EQ( | 312 EXPECT_EQ(ReadById(kTargetExtension2)->installation_mode, |
308 extension_management_->ReadById(kTargetExtension2).installation_mode, | 313 ExtensionManagement::INSTALLATION_FORCED); |
309 ExtensionManagement::INSTALLATION_FORCED); | 314 EXPECT_EQ(ReadById(kTargetExtension2)->update_url, kExampleUpdateUrl); |
310 EXPECT_EQ(extension_management_->ReadById(kTargetExtension2).update_url, | 315 EXPECT_EQ(ReadById(kTargetExtension3)->installation_mode, |
311 kExampleUpdateUrl); | 316 ExtensionManagement::INSTALLATION_RECOMMENDED); |
312 EXPECT_EQ( | 317 EXPECT_EQ(ReadById(kTargetExtension3)->update_url, kExampleUpdateUrl); |
313 extension_management_->ReadById(kTargetExtension3).installation_mode, | 318 EXPECT_EQ(ReadById(kOtherExtension)->installation_mode, |
314 ExtensionManagement::INSTALLATION_RECOMMENDED); | |
315 EXPECT_EQ(extension_management_->ReadById(kTargetExtension3).update_url, | |
316 kExampleUpdateUrl); | |
317 EXPECT_EQ(extension_management_->ReadById(kOtherExtension).installation_mode, | |
318 ExtensionManagement::INSTALLATION_BLOCKED); | 319 ExtensionManagement::INSTALLATION_BLOCKED); |
319 | 320 |
320 // Verifies global settings. | 321 // Verifies global settings. |
321 EXPECT_TRUE(extension_management_->ReadGlobalSettings() | 322 EXPECT_TRUE(ReadGlobalSettings()->has_restricted_install_sources); |
322 .has_restricted_install_sources); | 323 const URLPatternSet& allowed_sites = ReadGlobalSettings()->install_sources; |
323 const URLPatternSet& allowed_sites = | |
324 extension_management_->ReadGlobalSettings().install_sources; | |
325 EXPECT_EQ(allowed_sites.size(), 1u); | 324 EXPECT_EQ(allowed_sites.size(), 1u); |
326 EXPECT_TRUE(allowed_sites.MatchesURL(GURL("http://foo.com/entry"))); | 325 EXPECT_TRUE(allowed_sites.MatchesURL(GURL("http://foo.com/entry"))); |
327 EXPECT_FALSE(allowed_sites.MatchesURL(GURL("http://bar.com/entry"))); | 326 EXPECT_FALSE(allowed_sites.MatchesURL(GURL("http://bar.com/entry"))); |
328 | 327 |
329 EXPECT_TRUE( | 328 EXPECT_TRUE(ReadGlobalSettings()->has_restricted_allowed_types); |
330 extension_management_->ReadGlobalSettings().has_restricted_allowed_types); | |
331 const std::vector<Manifest::Type>& allowed_types = | 329 const std::vector<Manifest::Type>& allowed_types = |
332 extension_management_->ReadGlobalSettings().allowed_types; | 330 ReadGlobalSettings()->allowed_types; |
333 EXPECT_EQ(allowed_types.size(), 2u); | 331 EXPECT_EQ(allowed_types.size(), 2u); |
334 EXPECT_TRUE(std::find(allowed_types.begin(), | 332 EXPECT_TRUE(std::find(allowed_types.begin(), |
335 allowed_types.end(), | 333 allowed_types.end(), |
336 Manifest::TYPE_THEME) != allowed_types.end()); | 334 Manifest::TYPE_THEME) != allowed_types.end()); |
337 EXPECT_TRUE(std::find(allowed_types.begin(), | 335 EXPECT_TRUE(std::find(allowed_types.begin(), |
338 allowed_types.end(), | 336 allowed_types.end(), |
339 Manifest::TYPE_USER_SCRIPT) != allowed_types.end()); | 337 Manifest::TYPE_USER_SCRIPT) != allowed_types.end()); |
340 } | 338 } |
341 | 339 |
342 // Tests functionality of new preference as to deprecate legacy | 340 // Tests functionality of new preference as to deprecate legacy |
343 // ExtensionInstallSources policy. | 341 // ExtensionInstallSources policy. |
344 TEST_F(ExtensionManagementServiceTest, NewInstallSources) { | 342 TEST_F(ExtensionManagementServiceTest, NewInstallSources) { |
345 // Set the legacy preference, and verifies that it works. | 343 // Set the legacy preference, and verifies that it works. |
346 base::ListValue allowed_sites_pref; | 344 base::ListValue allowed_sites_pref; |
347 allowed_sites_pref.AppendString("https://www.example.com/foo"); | 345 allowed_sites_pref.AppendString("https://www.example.com/foo"); |
348 SetPref( | 346 SetPref( |
349 true, pref_names::kAllowedInstallSites, allowed_sites_pref.DeepCopy()); | 347 true, pref_names::kAllowedInstallSites, allowed_sites_pref.DeepCopy()); |
350 EXPECT_TRUE(extension_management_->ReadGlobalSettings() | 348 EXPECT_TRUE(ReadGlobalSettings()->has_restricted_install_sources); |
351 .has_restricted_install_sources); | 349 EXPECT_TRUE(ReadGlobalSettings()->install_sources.MatchesURL( |
352 EXPECT_TRUE( | 350 GURL("https://www.example.com/foo"))); |
353 extension_management_->ReadGlobalSettings() | |
354 .install_sources.MatchesURL(GURL("https://www.example.com/foo"))); | |
355 | 351 |
356 // Set the new dictionary preference. | 352 // Set the new dictionary preference. |
357 { | 353 { |
358 PrefUpdater updater(pref_service_.get()); | 354 PrefUpdater updater(pref_service_.get()); |
359 updater.ClearInstallSources(); | 355 updater.ClearInstallSources(); |
360 } | 356 } |
361 // Verifies that the new one overrides the legacy ones. | 357 // Verifies that the new one overrides the legacy ones. |
362 EXPECT_TRUE(extension_management_->ReadGlobalSettings() | 358 EXPECT_TRUE(ReadGlobalSettings()->has_restricted_install_sources); |
363 .has_restricted_install_sources); | 359 EXPECT_FALSE(ReadGlobalSettings()->install_sources.MatchesURL( |
364 EXPECT_FALSE( | 360 GURL("https://www.example.com/foo"))); |
365 extension_management_->ReadGlobalSettings() | |
366 .install_sources.MatchesURL(GURL("https://www.example.com/foo"))); | |
367 | 361 |
368 // Updates the new dictionary preference. | 362 // Updates the new dictionary preference. |
369 { | 363 { |
370 PrefUpdater updater(pref_service_.get()); | 364 PrefUpdater updater(pref_service_.get()); |
371 updater.AddInstallSource("https://corp.mycompany.com/*"); | 365 updater.AddInstallSource("https://corp.mycompany.com/*"); |
372 } | 366 } |
373 EXPECT_TRUE(extension_management_->ReadGlobalSettings() | 367 EXPECT_TRUE(ReadGlobalSettings()->has_restricted_install_sources); |
374 .has_restricted_install_sources); | 368 EXPECT_TRUE(ReadGlobalSettings()->install_sources.MatchesURL( |
375 EXPECT_TRUE(extension_management_->ReadGlobalSettings() | 369 GURL("https://corp.mycompany.com/entry"))); |
376 .install_sources.MatchesURL( | |
377 GURL("https://corp.mycompany.com/entry"))); | |
378 } | 370 } |
379 | 371 |
380 // Tests functionality of new preference as to deprecate legacy | 372 // Tests functionality of new preference as to deprecate legacy |
381 // ExtensionAllowedTypes policy. | 373 // ExtensionAllowedTypes policy. |
382 TEST_F(ExtensionManagementServiceTest, NewAllowedTypes) { | 374 TEST_F(ExtensionManagementServiceTest, NewAllowedTypes) { |
383 // Set the legacy preference, and verifies that it works. | 375 // Set the legacy preference, and verifies that it works. |
384 base::ListValue allowed_types_pref; | 376 base::ListValue allowed_types_pref; |
385 allowed_types_pref.AppendInteger(Manifest::TYPE_USER_SCRIPT); | 377 allowed_types_pref.AppendInteger(Manifest::TYPE_USER_SCRIPT); |
386 SetPref(true, pref_names::kAllowedTypes, allowed_types_pref.DeepCopy()); | 378 SetPref(true, pref_names::kAllowedTypes, allowed_types_pref.DeepCopy()); |
387 EXPECT_TRUE( | 379 EXPECT_TRUE(ReadGlobalSettings()->has_restricted_allowed_types); |
388 extension_management_->ReadGlobalSettings().has_restricted_allowed_types); | 380 EXPECT_EQ(ReadGlobalSettings()->allowed_types.size(), 1u); |
389 EXPECT_EQ(extension_management_->ReadGlobalSettings().allowed_types.size(), | 381 EXPECT_EQ(ReadGlobalSettings()->allowed_types[0], Manifest::TYPE_USER_SCRIPT); |
390 1u); | |
391 EXPECT_EQ(extension_management_->ReadGlobalSettings().allowed_types[0], | |
392 Manifest::TYPE_USER_SCRIPT); | |
393 | 382 |
394 // Set the new dictionary preference. | 383 // Set the new dictionary preference. |
395 { | 384 { |
396 PrefUpdater updater(pref_service_.get()); | 385 PrefUpdater updater(pref_service_.get()); |
397 updater.ClearAllowedTypes(); | 386 updater.ClearAllowedTypes(); |
398 } | 387 } |
399 // Verifies that the new one overrides the legacy ones. | 388 // Verifies that the new one overrides the legacy ones. |
400 EXPECT_TRUE( | 389 EXPECT_TRUE(ReadGlobalSettings()->has_restricted_allowed_types); |
401 extension_management_->ReadGlobalSettings().has_restricted_allowed_types); | 390 EXPECT_EQ(ReadGlobalSettings()->allowed_types.size(), 0u); |
402 EXPECT_EQ(extension_management_->ReadGlobalSettings().allowed_types.size(), | |
403 0u); | |
404 | 391 |
405 // Updates the new dictionary preference. | 392 // Updates the new dictionary preference. |
406 { | 393 { |
407 PrefUpdater updater(pref_service_.get()); | 394 PrefUpdater updater(pref_service_.get()); |
408 updater.AddAllowedType("theme"); | 395 updater.AddAllowedType("theme"); |
409 } | 396 } |
410 EXPECT_TRUE( | 397 EXPECT_TRUE(ReadGlobalSettings()->has_restricted_allowed_types); |
411 extension_management_->ReadGlobalSettings().has_restricted_allowed_types); | 398 EXPECT_EQ(ReadGlobalSettings()->allowed_types.size(), 1u); |
412 EXPECT_EQ(extension_management_->ReadGlobalSettings().allowed_types.size(), | 399 EXPECT_EQ(ReadGlobalSettings()->allowed_types[0], Manifest::TYPE_THEME); |
413 1u); | |
414 EXPECT_EQ(extension_management_->ReadGlobalSettings().allowed_types[0], | |
415 Manifest::TYPE_THEME); | |
416 } | 400 } |
417 | 401 |
418 // Tests functionality of new preference as to deprecate legacy | 402 // Tests functionality of new preference as to deprecate legacy |
419 // ExtensionInstallBlacklist policy. | 403 // ExtensionInstallBlacklist policy. |
420 TEST_F(ExtensionManagementServiceTest, NewInstallBlacklist) { | 404 TEST_F(ExtensionManagementServiceTest, NewInstallBlacklist) { |
421 // Set the new dictionary preference. | 405 // Set the new dictionary preference. |
422 { | 406 { |
423 PrefUpdater updater(pref_service_.get()); | 407 PrefUpdater updater(pref_service_.get()); |
424 updater.SetBlacklistedByDefault(false); // Allowed by default. | 408 updater.SetBlacklistedByDefault(false); // Allowed by default. |
425 updater.SetIndividualExtensionInstallationAllowed(kTargetExtension, false); | 409 updater.SetIndividualExtensionInstallationAllowed(kTargetExtension, false); |
426 updater.ClearPerExtensionSettings(kTargetExtension2); | 410 updater.ClearPerExtensionSettings(kTargetExtension2); |
427 updater.ClearPerExtensionSettings(kOtherExtension); | 411 updater.ClearPerExtensionSettings(kOtherExtension); |
428 } | 412 } |
429 EXPECT_FALSE(extension_management_->BlacklistedByDefault()); | 413 EXPECT_FALSE(extension_management_->BlacklistedByDefault()); |
430 EXPECT_EQ(extension_management_->ReadById(kTargetExtension).installation_mode, | 414 EXPECT_EQ(ReadById(kTargetExtension)->installation_mode, |
431 ExtensionManagement::INSTALLATION_BLOCKED); | 415 ExtensionManagement::INSTALLATION_BLOCKED); |
432 EXPECT_EQ(extension_management_->ReadById(kOtherExtension).installation_mode, | 416 EXPECT_EQ(ReadById(kOtherExtension)->installation_mode, |
433 ExtensionManagement::INSTALLATION_ALLOWED); | 417 ExtensionManagement::INSTALLATION_ALLOWED); |
434 | 418 |
435 // Set legacy preference. | 419 // Set legacy preference. |
436 base::ListValue denied_list_pref; | 420 base::ListValue denied_list_pref; |
437 denied_list_pref.AppendString("*"); | 421 denied_list_pref.AppendString("*"); |
438 denied_list_pref.AppendString(kTargetExtension2); | 422 denied_list_pref.AppendString(kTargetExtension2); |
439 SetPref(true, pref_names::kInstallDenyList, denied_list_pref.DeepCopy()); | 423 SetPref(true, pref_names::kInstallDenyList, denied_list_pref.DeepCopy()); |
440 | 424 |
441 base::ListValue allowed_list_pref; | 425 base::ListValue allowed_list_pref; |
442 allowed_list_pref.AppendString(kTargetExtension); | 426 allowed_list_pref.AppendString(kTargetExtension); |
443 SetPref(true, pref_names::kInstallAllowList, allowed_list_pref.DeepCopy()); | 427 SetPref(true, pref_names::kInstallAllowList, allowed_list_pref.DeepCopy()); |
444 | 428 |
445 // Verifies that the new one have higher priority over the legacy ones. | 429 // Verifies that the new one have higher priority over the legacy ones. |
446 EXPECT_FALSE(extension_management_->BlacklistedByDefault()); | 430 EXPECT_FALSE(extension_management_->BlacklistedByDefault()); |
447 EXPECT_EQ(extension_management_->ReadById(kTargetExtension).installation_mode, | 431 EXPECT_EQ(ReadById(kTargetExtension)->installation_mode, |
448 ExtensionManagement::INSTALLATION_BLOCKED); | 432 ExtensionManagement::INSTALLATION_BLOCKED); |
449 EXPECT_EQ( | 433 EXPECT_EQ(ReadById(kTargetExtension2)->installation_mode, |
450 extension_management_->ReadById(kTargetExtension2).installation_mode, | 434 ExtensionManagement::INSTALLATION_BLOCKED); |
451 ExtensionManagement::INSTALLATION_BLOCKED); | 435 EXPECT_EQ(ReadById(kOtherExtension)->installation_mode, |
452 EXPECT_EQ(extension_management_->ReadById(kOtherExtension).installation_mode, | |
453 ExtensionManagement::INSTALLATION_ALLOWED); | 436 ExtensionManagement::INSTALLATION_ALLOWED); |
454 } | 437 } |
455 | 438 |
456 // Tests functionality of new preference as to deprecate legacy | 439 // Tests functionality of new preference as to deprecate legacy |
457 // ExtensionInstallWhitelist policy. | 440 // ExtensionInstallWhitelist policy. |
458 TEST_F(ExtensionManagementServiceTest, NewInstallWhitelist) { | 441 TEST_F(ExtensionManagementServiceTest, NewInstallWhitelist) { |
459 // Set the new dictionary preference. | 442 // Set the new dictionary preference. |
460 { | 443 { |
461 PrefUpdater updater(pref_service_.get()); | 444 PrefUpdater updater(pref_service_.get()); |
462 updater.SetBlacklistedByDefault(true); // Disallowed by default. | 445 updater.SetBlacklistedByDefault(true); // Disallowed by default. |
463 updater.SetIndividualExtensionInstallationAllowed(kTargetExtension, true); | 446 updater.SetIndividualExtensionInstallationAllowed(kTargetExtension, true); |
464 updater.ClearPerExtensionSettings(kTargetExtension2); | 447 updater.ClearPerExtensionSettings(kTargetExtension2); |
465 updater.ClearPerExtensionSettings(kOtherExtension); | 448 updater.ClearPerExtensionSettings(kOtherExtension); |
466 } | 449 } |
467 EXPECT_TRUE(extension_management_->BlacklistedByDefault()); | 450 EXPECT_TRUE(extension_management_->BlacklistedByDefault()); |
468 EXPECT_EQ(extension_management_->ReadById(kTargetExtension).installation_mode, | 451 EXPECT_EQ(ReadById(kTargetExtension)->installation_mode, |
469 ExtensionManagement::INSTALLATION_ALLOWED); | 452 ExtensionManagement::INSTALLATION_ALLOWED); |
470 EXPECT_EQ(extension_management_->ReadById(kOtherExtension).installation_mode, | 453 EXPECT_EQ(ReadById(kOtherExtension)->installation_mode, |
471 ExtensionManagement::INSTALLATION_BLOCKED); | 454 ExtensionManagement::INSTALLATION_BLOCKED); |
472 | 455 |
473 // Set legacy preference. | 456 // Set legacy preference. |
474 base::ListValue denied_list_pref; | 457 base::ListValue denied_list_pref; |
475 denied_list_pref.AppendString(kTargetExtension); | 458 denied_list_pref.AppendString(kTargetExtension); |
476 SetPref(true, pref_names::kInstallDenyList, denied_list_pref.DeepCopy()); | 459 SetPref(true, pref_names::kInstallDenyList, denied_list_pref.DeepCopy()); |
477 | 460 |
478 base::ListValue allowed_list_pref; | 461 base::ListValue allowed_list_pref; |
479 allowed_list_pref.AppendString(kTargetExtension2); | 462 allowed_list_pref.AppendString(kTargetExtension2); |
480 SetPref(true, pref_names::kInstallAllowList, allowed_list_pref.DeepCopy()); | 463 SetPref(true, pref_names::kInstallAllowList, allowed_list_pref.DeepCopy()); |
481 | 464 |
482 // Verifies that the new one have higher priority over the legacy ones. | 465 // Verifies that the new one have higher priority over the legacy ones. |
483 EXPECT_TRUE(extension_management_->BlacklistedByDefault()); | 466 EXPECT_TRUE(extension_management_->BlacklistedByDefault()); |
484 EXPECT_EQ(extension_management_->ReadById(kTargetExtension).installation_mode, | 467 EXPECT_EQ(ReadById(kTargetExtension)->installation_mode, |
485 ExtensionManagement::INSTALLATION_ALLOWED); | 468 ExtensionManagement::INSTALLATION_ALLOWED); |
486 EXPECT_EQ( | 469 EXPECT_EQ(ReadById(kTargetExtension2)->installation_mode, |
487 extension_management_->ReadById(kTargetExtension2).installation_mode, | 470 ExtensionManagement::INSTALLATION_ALLOWED); |
488 ExtensionManagement::INSTALLATION_ALLOWED); | 471 EXPECT_EQ(ReadById(kOtherExtension)->installation_mode, |
489 EXPECT_EQ(extension_management_->ReadById(kOtherExtension).installation_mode, | |
490 ExtensionManagement::INSTALLATION_BLOCKED); | 472 ExtensionManagement::INSTALLATION_BLOCKED); |
491 } | 473 } |
492 | 474 |
493 // Tests functionality of new preference as to deprecate legacy | 475 // Tests functionality of new preference as to deprecate legacy |
494 // ExtensionInstallForcelist policy. | 476 // ExtensionInstallForcelist policy. |
495 TEST_F(ExtensionManagementServiceTest, NewInstallForcelist) { | 477 TEST_F(ExtensionManagementServiceTest, NewInstallForcelist) { |
496 // Set some legacy preferences, to verify that the new one overrides the | 478 // Set some legacy preferences, to verify that the new one overrides the |
497 // legacy ones. | 479 // legacy ones. |
498 base::ListValue denied_list_pref; | 480 base::ListValue denied_list_pref; |
499 denied_list_pref.AppendString(kTargetExtension); | 481 denied_list_pref.AppendString(kTargetExtension); |
500 SetPref(true, pref_names::kInstallDenyList, denied_list_pref.DeepCopy()); | 482 SetPref(true, pref_names::kInstallDenyList, denied_list_pref.DeepCopy()); |
501 | 483 |
502 // Set the new dictionary preference. | 484 // Set the new dictionary preference. |
503 { | 485 { |
504 PrefUpdater updater(pref_service_.get()); | 486 PrefUpdater updater(pref_service_.get()); |
505 updater.SetIndividualExtensionAutoInstalled( | 487 updater.SetIndividualExtensionAutoInstalled( |
506 kTargetExtension, kExampleUpdateUrl, true); | 488 kTargetExtension, kExampleUpdateUrl, true); |
507 updater.ClearPerExtensionSettings(kOtherExtension); | 489 updater.ClearPerExtensionSettings(kOtherExtension); |
508 } | 490 } |
509 EXPECT_EQ(extension_management_->ReadById(kTargetExtension).installation_mode, | 491 EXPECT_EQ(ReadById(kTargetExtension)->installation_mode, |
510 ExtensionManagement::INSTALLATION_FORCED); | 492 ExtensionManagement::INSTALLATION_FORCED); |
511 EXPECT_EQ(extension_management_->ReadById(kTargetExtension).update_url, | 493 EXPECT_EQ(ReadById(kTargetExtension)->update_url, kExampleUpdateUrl); |
512 kExampleUpdateUrl); | 494 EXPECT_EQ(ReadById(kOtherExtension)->installation_mode, |
513 EXPECT_EQ(extension_management_->ReadById(kOtherExtension).installation_mode, | |
514 ExtensionManagement::INSTALLATION_ALLOWED); | 495 ExtensionManagement::INSTALLATION_ALLOWED); |
515 } | 496 } |
516 | 497 |
517 // Tests the flag value indicating that extensions are blacklisted by default. | 498 // Tests the flag value indicating that extensions are blacklisted by default. |
518 TEST_F(ExtensionAdminPolicyTest, BlacklistedByDefault) { | 499 TEST_F(ExtensionAdminPolicyTest, BlacklistedByDefault) { |
519 EXPECT_FALSE(BlacklistedByDefault(NULL)); | 500 EXPECT_FALSE(BlacklistedByDefault(NULL)); |
520 | 501 |
521 base::ListValue blacklist; | 502 base::ListValue blacklist; |
522 blacklist.Append(new base::StringValue(kOtherExtension)); | 503 blacklist.Append(new base::StringValue(kOtherExtension)); |
523 EXPECT_FALSE(BlacklistedByDefault(&blacklist)); | 504 EXPECT_FALSE(BlacklistedByDefault(&blacklist)); |
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
656 EXPECT_FALSE(error.empty()); | 637 EXPECT_FALSE(error.empty()); |
657 | 638 |
658 CreateExtension(Manifest::INTERNAL); | 639 CreateExtension(Manifest::INTERNAL); |
659 error.clear(); | 640 error.clear(); |
660 EXPECT_FALSE(MustRemainEnabled(extension_.get(), NULL)); | 641 EXPECT_FALSE(MustRemainEnabled(extension_.get(), NULL)); |
661 EXPECT_FALSE(MustRemainEnabled(extension_.get(), &error)); | 642 EXPECT_FALSE(MustRemainEnabled(extension_.get(), &error)); |
662 EXPECT_TRUE(error.empty()); | 643 EXPECT_TRUE(error.empty()); |
663 } | 644 } |
664 | 645 |
665 } // namespace extensions | 646 } // namespace extensions |
OLD | NEW |