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

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

Issue 706623004: Add minimum version to extension management (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@ext-update-url
Patch Set: WIP Created 6 years, 1 month 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 <algorithm> 5 #include <algorithm>
6 #include <string> 6 #include <string>
7 #include <vector> 7 #include <vector>
8 8
9 #include "base/json/json_parser.h" 9 #include "base/json/json_parser.h"
10 #include "base/memory/scoped_ptr.h" 10 #include "base/memory/scoped_ptr.h"
(...skipping 25 matching lines...) Expand all
36 const char kExampleUpdateUrl[] = "http://example.com/update_url"; 36 const char kExampleUpdateUrl[] = "http://example.com/update_url";
37 37
38 const char kNonExistingExtension[] = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"; 38 const char kNonExistingExtension[] = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
39 const char kNonExistingUpdateUrl[] = "http://example.net/update.xml"; 39 const char kNonExistingUpdateUrl[] = "http://example.net/update.xml";
40 40
41 const char kExampleDictPreference[] = 41 const char kExampleDictPreference[] =
42 "{" 42 "{"
43 " \"abcdefghijklmnopabcdefghijklmnop\": {" // kTargetExtension 43 " \"abcdefghijklmnopabcdefghijklmnop\": {" // kTargetExtension
44 " \"installation_mode\": \"allowed\"," 44 " \"installation_mode\": \"allowed\","
45 " \"blocked_permissions\": [\"fileSystem\", \"bookmarks\"]," 45 " \"blocked_permissions\": [\"fileSystem\", \"bookmarks\"],"
46 " \"minimum_version\": \"1.1.0\","
46 " }," 47 " },"
47 " \"bcdefghijklmnopabcdefghijklmnopa\": {" // kTargetExtension2 48 " \"bcdefghijklmnopabcdefghijklmnopa\": {" // kTargetExtension2
48 " \"installation_mode\": \"force_installed\"," 49 " \"installation_mode\": \"force_installed\","
49 " \"update_url\": \"http://example.com/update_url\"," 50 " \"update_url\": \"http://example.com/update_url\","
50 " \"allowed_permissions\": [\"fileSystem\", \"bookmarks\"]," 51 " \"allowed_permissions\": [\"fileSystem\", \"bookmarks\"],"
51 " }," 52 " },"
52 " \"cdefghijklmnopabcdefghijklmnopab\": {" // kTargetExtension3 53 " \"cdefghijklmnopabcdefghijklmnopab\": {" // kTargetExtension3
53 " \"installation_mode\": \"normal_installed\"," 54 " \"installation_mode\": \"normal_installed\","
54 " \"update_url\": \"http://example.com/update_url\"," 55 " \"update_url\": \"http://example.com/update_url\","
55 " \"allowed_permissions\": [\"fileSystem\", \"downloads\"]," 56 " \"allowed_permissions\": [\"fileSystem\", \"downloads\"],"
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
155 &error_msg)); 156 &error_msg));
156 ASSERT_TRUE(parsed && parsed->IsType(base::Value::TYPE_DICTIONARY)) 157 ASSERT_TRUE(parsed && parsed->IsType(base::Value::TYPE_DICTIONARY))
157 << error_msg; 158 << error_msg;
158 SetPref(true, pref_names::kExtensionManagement, parsed.release()); 159 SetPref(true, pref_names::kExtensionManagement, parsed.release());
159 } 160 }
160 161
161 ExtensionManagement::InstallationMode GetInstallationMode( 162 ExtensionManagement::InstallationMode GetInstallationMode(
162 const std::string& id, 163 const std::string& id,
163 const std::string& update_url) { 164 const std::string& update_url) {
164 scoped_refptr<const Extension> extension = 165 scoped_refptr<const Extension> extension =
165 CreateExtensionWithIdAndUpdateUrl(Manifest::UNPACKED, id, update_url); 166 CreateExtension(Manifest::UNPACKED, "0.1", id, update_url);
166 return extension_management_->GetInstallationMode(extension.get()); 167 return extension_management_->GetInstallationMode(extension.get());
167 } 168 }
168 169
169 APIPermissionSet GetBlockedAPIPermissions(const std::string& id, 170 APIPermissionSet GetBlockedAPIPermissions(const std::string& id,
170 const std::string& update_url) { 171 const std::string& update_url) {
171 scoped_refptr<const Extension> extension = 172 scoped_refptr<const Extension> extension =
172 CreateExtensionWithIdAndUpdateUrl(Manifest::UNPACKED, id, update_url); 173 CreateExtension(Manifest::UNPACKED, "0.1", id, update_url);
173 return extension_management_->GetBlockedAPIPermissions(extension.get()); 174 return extension_management_->GetBlockedAPIPermissions(extension.get());
174 } 175 }
175 176
177 bool CheckMinimumVersion(const std::string& id, const std::string& version) {
178 scoped_refptr<const Extension> extension =
179 CreateExtension(Manifest::UNPACKED, version, id, kNonExistingUpdateUrl);
180 return extension_management_->CheckMinimumVersion(extension.get(), nullptr);
pastarmovj 2014/11/11 12:50:54 I would check here that the second parameter is se
binjin 2014/11/11 19:10:37 Done.
181 }
182
176 protected: 183 protected:
177 scoped_ptr<TestingPrefServiceSimple> pref_service_; 184 scoped_ptr<TestingPrefServiceSimple> pref_service_;
178 scoped_ptr<ExtensionManagement> extension_management_; 185 scoped_ptr<ExtensionManagement> extension_management_;
179 186
180 private: 187 private:
181 // Create an extension with specified |location|, |id| and |update_url|. 188 // Create an extension with specified |location|, |version|, |id| and
182 scoped_refptr<const Extension> CreateExtensionWithIdAndUpdateUrl( 189 // |update_url|.
190 scoped_refptr<const Extension> CreateExtension(
183 Manifest::Location location, 191 Manifest::Location location,
192 const std::string& version,
184 const std::string& id, 193 const std::string& id,
185 const std::string& update_url) { 194 const std::string& update_url) {
186 base::DictionaryValue manifest_dict; 195 base::DictionaryValue manifest_dict;
187 manifest_dict.SetString(manifest_keys::kName, "test"); 196 manifest_dict.SetString(manifest_keys::kName, "test");
188 manifest_dict.SetString(manifest_keys::kVersion, "0.1"); 197 manifest_dict.SetString(manifest_keys::kVersion, version);
189 manifest_dict.SetString(manifest_keys::kUpdateURL, update_url); 198 manifest_dict.SetString(manifest_keys::kUpdateURL, update_url);
190 std::string error; 199 std::string error;
191 scoped_refptr<const Extension> extension = 200 scoped_refptr<const Extension> extension =
192 Extension::Create(base::FilePath(), location, manifest_dict, 201 Extension::Create(base::FilePath(), location, manifest_dict,
193 Extension::NO_FLAGS, id, &error); 202 Extension::NO_FLAGS, id, &error);
194 CHECK(extension.get()) << error; 203 CHECK(extension.get()) << error;
195 return extension; 204 return extension;
196 } 205 }
197 }; 206 };
198 207
(...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after
442 api_permission_set.insert(APIPermission::kFileSystem); 451 api_permission_set.insert(APIPermission::kFileSystem);
443 api_permission_set.insert(APIPermission::kHistory); 452 api_permission_set.insert(APIPermission::kHistory);
444 EXPECT_EQ(api_permission_set, 453 EXPECT_EQ(api_permission_set,
445 GetBlockedAPIPermissionsById(kTargetExtension3)); 454 GetBlockedAPIPermissionsById(kTargetExtension3));
446 455
447 api_permission_set.clear(); 456 api_permission_set.clear();
448 api_permission_set.insert(APIPermission::kFileSystem); 457 api_permission_set.insert(APIPermission::kFileSystem);
449 api_permission_set.insert(APIPermission::kBookmark); 458 api_permission_set.insert(APIPermission::kBookmark);
450 EXPECT_EQ(api_permission_set, 459 EXPECT_EQ(api_permission_set,
451 GetBlockedAPIPermissionsByUpdateUrl(kExampleUpdateUrl)); 460 GetBlockedAPIPermissionsByUpdateUrl(kExampleUpdateUrl));
461
462 // Verifies minimum version settings.
463 EXPECT_FALSE(CheckMinimumVersion(kTargetExtension, "1.0.99"));
464 EXPECT_TRUE(CheckMinimumVersion(kTargetExtension, "1.1"));
465 EXPECT_TRUE(CheckMinimumVersion(kTargetExtension, "1.1.0.1"));
452 } 466 }
453 467
454 // Tests the handling of installation mode in case it's specified in both 468 // Tests the handling of installation mode in case it's specified in both
455 // per-extension and per-update-url settings. 469 // per-extension and per-update-url settings.
456 TEST_F(ExtensionManagementServiceTest, InstallationModeConflictHandling) { 470 TEST_F(ExtensionManagementServiceTest, InstallationModeConflictHandling) {
457 SetExampleDictPref(); 471 SetExampleDictPref();
458 472
459 // Per-extension installation mode settings should always override 473 // Per-extension installation mode settings should always override
460 // per-update-url settings. 474 // per-update-url settings.
461 EXPECT_EQ(GetInstallationMode(kTargetExtension, kExampleUpdateUrl), 475 EXPECT_EQ(GetInstallationMode(kTargetExtension, kExampleUpdateUrl),
(...skipping 28 matching lines...) Expand all
490 EXPECT_EQ(api_permission_set, 504 EXPECT_EQ(api_permission_set,
491 GetBlockedAPIPermissions(kTargetExtension2, kExampleUpdateUrl)); 505 GetBlockedAPIPermissions(kTargetExtension2, kExampleUpdateUrl));
492 506
493 api_permission_set = blocked_permissions_for_update_url; 507 api_permission_set = blocked_permissions_for_update_url;
494 api_permission_set.insert(APIPermission::kFileSystem); 508 api_permission_set.insert(APIPermission::kFileSystem);
495 api_permission_set.insert(APIPermission::kHistory); 509 api_permission_set.insert(APIPermission::kHistory);
496 EXPECT_EQ(api_permission_set, 510 EXPECT_EQ(api_permission_set,
497 GetBlockedAPIPermissions(kTargetExtension3, kExampleUpdateUrl)); 511 GetBlockedAPIPermissions(kTargetExtension3, kExampleUpdateUrl));
498 } 512 }
499 513
514 // Tests the minimum version settings of extension management.
515 TEST_F(ExtensionManagementServiceTest, MinimumVersion) {
516 EXPECT_TRUE(CheckMinimumVersion(kTargetExtension, "0.0"));
517 EXPECT_TRUE(CheckMinimumVersion(kTargetExtension, "3.0.0"));
518 EXPECT_TRUE(CheckMinimumVersion(kTargetExtension, "9999.0"));
519
520 {
521 PrefUpdater pref(pref_service_.get());
522 pref.SetMinimumVersion(kTargetExtension, "3.0");
523 }
524
525 EXPECT_FALSE(CheckMinimumVersion(kTargetExtension, "0.0"));
526 EXPECT_FALSE(CheckMinimumVersion(kTargetExtension, "2.99"));
527 EXPECT_TRUE(CheckMinimumVersion(kTargetExtension, "3.0.0"));
528 EXPECT_TRUE(CheckMinimumVersion(kTargetExtension, "3.0.1"));
529 EXPECT_TRUE(CheckMinimumVersion(kTargetExtension, "4.0"));
530 }
531
500 // Tests functionality of new preference as to deprecate legacy 532 // Tests functionality of new preference as to deprecate legacy
501 // ExtensionInstallSources policy. 533 // ExtensionInstallSources policy.
502 TEST_F(ExtensionManagementServiceTest, NewInstallSources) { 534 TEST_F(ExtensionManagementServiceTest, NewInstallSources) {
503 // Set the legacy preference, and verifies that it works. 535 // Set the legacy preference, and verifies that it works.
504 base::ListValue allowed_sites_pref; 536 base::ListValue allowed_sites_pref;
505 allowed_sites_pref.AppendString("https://www.example.com/foo"); 537 allowed_sites_pref.AppendString("https://www.example.com/foo");
506 SetPref( 538 SetPref(
507 true, pref_names::kAllowedInstallSites, allowed_sites_pref.DeepCopy()); 539 true, pref_names::kAllowedInstallSites, allowed_sites_pref.DeepCopy());
508 EXPECT_TRUE(ReadGlobalSettings()->has_restricted_install_sources); 540 EXPECT_TRUE(ReadGlobalSettings()->has_restricted_install_sources);
509 EXPECT_TRUE(ReadGlobalSettings()->install_sources.MatchesURL( 541 EXPECT_TRUE(ReadGlobalSettings()->install_sources.MatchesURL(
(...skipping 321 matching lines...) Expand 10 before | Expand all | Expand 10 after
831 EXPECT_FALSE(error.empty()); 863 EXPECT_FALSE(error.empty());
832 864
833 CreateExtension(Manifest::INTERNAL); 865 CreateExtension(Manifest::INTERNAL);
834 error.clear(); 866 error.clear();
835 EXPECT_FALSE(MustRemainEnabled(extension_.get(), NULL)); 867 EXPECT_FALSE(MustRemainEnabled(extension_.get(), NULL));
836 EXPECT_FALSE(MustRemainEnabled(extension_.get(), &error)); 868 EXPECT_FALSE(MustRemainEnabled(extension_.get(), &error));
837 EXPECT_TRUE(error.empty()); 869 EXPECT_TRUE(error.empty());
838 } 870 }
839 871
840 } // namespace extensions 872 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698