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

Side by Side Diff: chrome/browser/extensions/extension_management_unittest.cc

Issue 2499493004: Communicate ExtensionSettings policy to renderers (Closed)
Patch Set: Fix effective TLD wildcard bug, move to Leaky LazyInstance in PermissionsData, removed unnecessary … Created 3 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
OLDNEW
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 "chrome/browser/extensions/extension_management.h" 5 #include "chrome/browser/extensions/extension_management.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <memory> 8 #include <memory>
9 #include <string> 9 #include <string>
10 #include <vector> 10 #include <vector>
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
118 if (managed) 118 if (managed)
119 pref_service_->RemoveManagedPref(path); 119 pref_service_->RemoveManagedPref(path);
120 else 120 else
121 pref_service_->RemoveUserPref(path); 121 pref_service_->RemoveUserPref(path);
122 } 122 }
123 123
124 const internal::GlobalSettings* ReadGlobalSettings() { 124 const internal::GlobalSettings* ReadGlobalSettings() {
125 return extension_management_->global_settings_.get(); 125 return extension_management_->global_settings_.get();
126 } 126 }
127 127
128 const URLPatternSet& GetRuntimeBlockedHostsById(const std::string& id) {
129 return GetRuntimeBlockedHosts(id, kNonExistingUpdateUrl);
130 }
131
132 ExtensionManagement::InstallationMode GetInstallationModeById( 128 ExtensionManagement::InstallationMode GetInstallationModeById(
133 const std::string& id) { 129 const std::string& id) {
134 return GetInstallationMode(id, kNonExistingUpdateUrl); 130 return GetInstallationMode(id, kNonExistingUpdateUrl);
135 } 131 }
136 132
137 ExtensionManagement::InstallationMode GetInstallationModeByUpdateUrl( 133 ExtensionManagement::InstallationMode GetInstallationModeByUpdateUrl(
138 const std::string& update_url) { 134 const std::string& update_url) {
139 return GetInstallationMode(kNonExistingExtension, update_url); 135 return GetInstallationMode(kNonExistingExtension, update_url);
140 } 136 }
141 137
(...skipping 30 matching lines...) Expand all
172 // Wrapper of ExtensionManagement::GetInstallationMode, |id| and 168 // Wrapper of ExtensionManagement::GetInstallationMode, |id| and
173 // |update_url| are used to construct an Extension for testing. 169 // |update_url| are used to construct an Extension for testing.
174 ExtensionManagement::InstallationMode GetInstallationMode( 170 ExtensionManagement::InstallationMode GetInstallationMode(
175 const std::string& id, 171 const std::string& id,
176 const std::string& update_url) { 172 const std::string& update_url) {
177 scoped_refptr<const Extension> extension = 173 scoped_refptr<const Extension> extension =
178 CreateExtension(Manifest::UNPACKED, "0.1", id, update_url); 174 CreateExtension(Manifest::UNPACKED, "0.1", id, update_url);
179 return extension_management_->GetInstallationMode(extension.get()); 175 return extension_management_->GetInstallationMode(extension.get());
180 } 176 }
181 177
182 // Wrapper of ExtensionManagement::GetRuntimeBlockedHosts, |id| and 178 // Wrapper of ExtensionManagement::GetRuntimeBlockedHosts, |id| is used
183 // |update_url| are used to construct an Extension for testing. 179 // to construct an Extension for testing.
184 URLPatternSet GetRuntimeBlockedHosts( 180 URLPatternSet GetRuntimeBlockedHosts(const std::string& id) {
185 const std::string& id,
186 const std::string& update_url) {
187 scoped_refptr<const Extension> extension = 181 scoped_refptr<const Extension> extension =
188 CreateExtension(Manifest::UNPACKED, "0.1", id, update_url); 182 CreateExtension(Manifest::UNPACKED, "0.1", id, kNonExistingUpdateUrl);
189 return extension_management_->GetRuntimeBlockedHosts(extension.get()); 183 return extension_management_->GetRuntimeBlockedHosts(extension.get());
190 } 184 }
191 185
192 // Wrapper of ExtensionManagement::GetBlockedAPIPermissions, |id| and 186 // Wrapper of ExtensionManagement::GetBlockedAPIPermissions, |id| and
193 // |update_url| are used to construct an Extension for testing. 187 // |update_url| are used to construct an Extension for testing.
194 APIPermissionSet GetBlockedAPIPermissions(const std::string& id, 188 APIPermissionSet GetBlockedAPIPermissions(const std::string& id,
195 const std::string& update_url) { 189 const std::string& update_url) {
196 scoped_refptr<const Extension> extension = 190 scoped_refptr<const Extension> extension =
197 CreateExtension(Manifest::UNPACKED, "0.1", id, update_url); 191 CreateExtension(Manifest::UNPACKED, "0.1", id, update_url);
198 return extension_management_->GetBlockedAPIPermissions(extension.get()); 192 return extension_management_->GetBlockedAPIPermissions(extension.get());
(...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after
434 EXPECT_EQ(GetInstallationModeById(kTargetExtension2), 428 EXPECT_EQ(GetInstallationModeById(kTargetExtension2),
435 ExtensionManagement::INSTALLATION_FORCED); 429 ExtensionManagement::INSTALLATION_FORCED);
436 CheckAutomaticallyInstalledUpdateUrl(kTargetExtension2, kExampleUpdateUrl); 430 CheckAutomaticallyInstalledUpdateUrl(kTargetExtension2, kExampleUpdateUrl);
437 EXPECT_EQ(GetInstallationModeById(kTargetExtension3), 431 EXPECT_EQ(GetInstallationModeById(kTargetExtension3),
438 ExtensionManagement::INSTALLATION_RECOMMENDED); 432 ExtensionManagement::INSTALLATION_RECOMMENDED);
439 CheckAutomaticallyInstalledUpdateUrl(kTargetExtension3, kExampleUpdateUrl); 433 CheckAutomaticallyInstalledUpdateUrl(kTargetExtension3, kExampleUpdateUrl);
440 EXPECT_EQ(GetInstallationModeById(kNonExistingExtension), 434 EXPECT_EQ(GetInstallationModeById(kNonExistingExtension),
441 ExtensionManagement::INSTALLATION_BLOCKED); 435 ExtensionManagement::INSTALLATION_BLOCKED);
442 EXPECT_EQ(GetInstallationModeByUpdateUrl(kExampleUpdateUrl), 436 EXPECT_EQ(GetInstallationModeByUpdateUrl(kExampleUpdateUrl),
443 ExtensionManagement::INSTALLATION_ALLOWED); 437 ExtensionManagement::INSTALLATION_ALLOWED);
444 EXPECT_TRUE(GetRuntimeBlockedHostsById(kTargetExtension).empty()); 438 EXPECT_TRUE(GetRuntimeBlockedHosts(kTargetExtension).is_empty());
445 EXPECT_TRUE(GetRuntimeBlockedHostsById(kTargetExtension4) 439 EXPECT_TRUE(GetRuntimeBlockedHosts(kTargetExtension4)
446 .MatchesURL(GURL("http://test.foo.com/test"))); 440 .MatchesURL(GURL("http://test.foo.com/test")));
447 EXPECT_TRUE(GetRuntimeBlockedHostsById(kTargetExtension4) 441 EXPECT_TRUE(GetRuntimeBlockedHosts(kTargetExtension4)
448 .MatchesURL(GURL("https://bar.org/test"))); 442 .MatchesURL(GURL("https://bar.org/test")));
449 443
450 // Verifies global settings. 444 // Verifies global settings.
451 EXPECT_TRUE(ReadGlobalSettings()->has_restricted_install_sources); 445 EXPECT_TRUE(ReadGlobalSettings()->has_restricted_install_sources);
452 const URLPatternSet& allowed_sites = ReadGlobalSettings()->install_sources; 446 const URLPatternSet& allowed_sites = ReadGlobalSettings()->install_sources;
453 EXPECT_EQ(allowed_sites.size(), 1u); 447 EXPECT_EQ(allowed_sites.size(), 1u);
454 EXPECT_TRUE(allowed_sites.MatchesURL(GURL("http://foo.com/entry"))); 448 EXPECT_TRUE(allowed_sites.MatchesURL(GURL("http://foo.com/entry")));
455 EXPECT_FALSE(allowed_sites.MatchesURL(GURL("http://bar.com/entry"))); 449 EXPECT_FALSE(allowed_sites.MatchesURL(GURL("http://bar.com/entry")));
456 EXPECT_TRUE(GetRuntimeBlockedHostsById(kNonExistingExtension) 450 EXPECT_TRUE(GetRuntimeBlockedHosts(kNonExistingExtension)
457 .MatchesURL(GURL("http://example.com/default"))); 451 .MatchesURL(GURL("http://example.com/default")));
458 452
459 EXPECT_TRUE(ReadGlobalSettings()->has_restricted_allowed_types); 453 EXPECT_TRUE(ReadGlobalSettings()->has_restricted_allowed_types);
460 const std::vector<Manifest::Type>& allowed_types = 454 const std::vector<Manifest::Type>& allowed_types =
461 ReadGlobalSettings()->allowed_types; 455 ReadGlobalSettings()->allowed_types;
462 EXPECT_EQ(allowed_types.size(), 2u); 456 EXPECT_EQ(allowed_types.size(), 2u);
463 EXPECT_TRUE(std::find(allowed_types.begin(), 457 EXPECT_TRUE(std::find(allowed_types.begin(),
464 allowed_types.end(), 458 allowed_types.end(),
465 Manifest::TYPE_THEME) != allowed_types.end()); 459 Manifest::TYPE_THEME) != allowed_types.end());
466 EXPECT_TRUE(std::find(allowed_types.begin(), 460 EXPECT_TRUE(std::find(allowed_types.begin(),
(...skipping 435 matching lines...) Expand 10 before | Expand all | Expand 10 after
902 EXPECT_FALSE(error.empty()); 896 EXPECT_FALSE(error.empty());
903 897
904 CreateExtension(Manifest::INTERNAL); 898 CreateExtension(Manifest::INTERNAL);
905 error.clear(); 899 error.clear();
906 EXPECT_FALSE(MustRemainEnabled(extension_.get(), NULL)); 900 EXPECT_FALSE(MustRemainEnabled(extension_.get(), NULL));
907 EXPECT_FALSE(MustRemainEnabled(extension_.get(), &error)); 901 EXPECT_FALSE(MustRemainEnabled(extension_.get(), &error));
908 EXPECT_TRUE(error.empty()); 902 EXPECT_TRUE(error.empty());
909 } 903 }
910 904
911 } // namespace extensions 905 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698