| OLD | NEW |
| 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/extensions/extensions_service_unittest.h" | 5 #include "chrome/browser/extensions/extensions_service_unittest.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 65 // Extension ids used during testing. | 65 // Extension ids used during testing. |
| 66 const char* const all_zero = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"; | 66 const char* const all_zero = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"; |
| 67 const char* const zero_n_one = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaab"; | 67 const char* const zero_n_one = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaab"; |
| 68 const char* const good0 = "behllobkkfkfnphdnhnkndlbkcpglgmj"; | 68 const char* const good0 = "behllobkkfkfnphdnhnkndlbkcpglgmj"; |
| 69 const char* const good1 = "hpiknbiabeeppbpihjehijgoemciehgk"; | 69 const char* const good1 = "hpiknbiabeeppbpihjehijgoemciehgk"; |
| 70 const char* const good2 = "bjafgdebaacbbbecmhlhpofkepfkgcpa"; | 70 const char* const good2 = "bjafgdebaacbbbecmhlhpofkepfkgcpa"; |
| 71 const char* const good_crx = "ldnnhddmnhbkjipkidpdiheffobcpfmf"; | 71 const char* const good_crx = "ldnnhddmnhbkjipkidpdiheffobcpfmf"; |
| 72 const char* const page_action = "obcimlgaoabeegjmmpldobjndiealpln"; | 72 const char* const page_action = "obcimlgaoabeegjmmpldobjndiealpln"; |
| 73 const char* const theme_crx = "iamefpfkojoapidjnbafmgkgncegbkad"; | 73 const char* const theme_crx = "iamefpfkojoapidjnbafmgkgncegbkad"; |
| 74 const char* const theme2_crx = "pjpgmfcmabopnnfonnhmdjglfpjjfkbf"; | 74 const char* const theme2_crx = "pjpgmfcmabopnnfonnhmdjglfpjjfkbf"; |
| 75 const char* const permissions_crx = "eagpmdpfmaekmmcejjbmjoecnejeiiin"; |
| 75 | 76 |
| 76 struct ExtensionsOrder { | 77 struct ExtensionsOrder { |
| 77 bool operator()(const Extension* a, const Extension* b) { | 78 bool operator()(const Extension* a, const Extension* b) { |
| 78 return a->name() < b->name(); | 79 return a->name() < b->name(); |
| 79 } | 80 } |
| 80 }; | 81 }; |
| 81 | 82 |
| 82 static std::vector<std::string> GetErrors() { | 83 static std::vector<std::string> GetErrors() { |
| 83 const std::vector<std::string>* errors = | 84 const std::vector<std::string>* errors = |
| 84 ExtensionErrorReporter::GetInstance()->GetErrors(); | 85 ExtensionErrorReporter::GetInstance()->GetErrors(); |
| 85 std::vector<std::string> ret_val; | 86 std::vector<std::string> ret_val; |
| 86 | 87 |
| 87 for (std::vector<std::string>::const_iterator iter = errors->begin(); | 88 for (std::vector<std::string>::const_iterator iter = errors->begin(); |
| 88 iter != errors->end(); ++iter) { | 89 iter != errors->end(); ++iter) { |
| 89 if (iter->find(".svn") == std::string::npos) { | 90 if (iter->find(".svn") == std::string::npos) { |
| 90 ret_val.push_back(*iter); | 91 ret_val.push_back(*iter); |
| 91 } | 92 } |
| 92 } | 93 } |
| 93 | 94 |
| 94 // The tests rely on the errors being in a certain order, which can vary | 95 // The tests rely on the errors being in a certain order, which can vary |
| 95 // depending on how filesystem iteration works. | 96 // depending on how filesystem iteration works. |
| 96 std::stable_sort(ret_val.begin(), ret_val.end()); | 97 std::stable_sort(ret_val.begin(), ret_val.end()); |
| 97 | 98 |
| 98 return ret_val; | 99 return ret_val; |
| 99 } | 100 } |
| 100 | 101 |
| 102 static void AddPattern(ExtensionExtent* extent, const std::string& pattern) { |
| 103 int schemes = URLPattern::SCHEME_ALL; |
| 104 extent->AddPattern(URLPattern(schemes, pattern)); |
| 105 } |
| 106 |
| 107 static void AssertEqualExtents(ExtensionExtent* extent1, |
| 108 ExtensionExtent* extent2) { |
| 109 std::vector<URLPattern> patterns1 = extent1->patterns(); |
| 110 std::vector<URLPattern> patterns2 = extent2->patterns(); |
| 111 std::set<std::string> strings1; |
| 112 EXPECT_EQ(patterns1.size(), patterns2.size()); |
| 113 |
| 114 for (size_t i = 0; i < patterns1.size(); ++i) |
| 115 strings1.insert(patterns1.at(i).GetAsString()); |
| 116 |
| 117 std::set<std::string> strings2; |
| 118 for (size_t i = 0; i < patterns2.size(); ++i) |
| 119 strings2.insert(patterns2.at(i).GetAsString()); |
| 120 |
| 121 EXPECT_EQ(strings1, strings2); |
| 122 } |
| 123 |
| 101 } // namespace | 124 } // namespace |
| 102 | 125 |
| 103 class MockExtensionProvider : public ExternalExtensionProvider { | 126 class MockExtensionProvider : public ExternalExtensionProvider { |
| 104 public: | 127 public: |
| 105 explicit MockExtensionProvider(Extension::Location location) | 128 explicit MockExtensionProvider(Extension::Location location) |
| 106 : location_(location), visit_count_(0) {} | 129 : location_(location), visit_count_(0) {} |
| 107 virtual ~MockExtensionProvider() {} | 130 virtual ~MockExtensionProvider() {} |
| 108 | 131 |
| 109 void UpdateOrAddExtension(const std::string& id, | 132 void UpdateOrAddExtension(const std::string& id, |
| 110 const std::string& version, | 133 const std::string& version, |
| (...skipping 340 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 451 | 474 |
| 452 void AddMockExternalProvider(ExternalExtensionProvider* provider) { | 475 void AddMockExternalProvider(ExternalExtensionProvider* provider) { |
| 453 service_->AddProviderForTesting(provider); | 476 service_->AddProviderForTesting(provider); |
| 454 } | 477 } |
| 455 | 478 |
| 456 protected: | 479 protected: |
| 457 void TestExternalProvider(MockExtensionProvider* provider, | 480 void TestExternalProvider(MockExtensionProvider* provider, |
| 458 Extension::Location location); | 481 Extension::Location location); |
| 459 | 482 |
| 460 void PackAndInstallExtension(const FilePath& dir_path, | 483 void PackAndInstallExtension(const FilePath& dir_path, |
| 484 const FilePath& pem_path, |
| 461 bool should_succeed) { | 485 bool should_succeed) { |
| 462 FilePath crx_path; | 486 FilePath crx_path; |
| 463 ASSERT_TRUE(PathService::Get(base::DIR_TEMP, &crx_path)); | 487 ASSERT_TRUE(PathService::Get(base::DIR_TEMP, &crx_path)); |
| 464 crx_path = crx_path.AppendASCII("temp.crx"); | 488 crx_path = crx_path.AppendASCII("temp.crx"); |
| 465 FilePath pem_path = crx_path.DirName().AppendASCII("temp.pem"); | 489 |
| 490 FilePath pem_output_path; |
| 491 if (pem_path.value().empty()) { |
| 492 pem_output_path = crx_path.DirName().AppendASCII("temp.pem"); |
| 493 ASSERT_TRUE(file_util::Delete(pem_output_path, false)); |
| 494 } else { |
| 495 ASSERT_TRUE(file_util::PathExists(pem_path)); |
| 496 } |
| 466 | 497 |
| 467 ASSERT_TRUE(file_util::Delete(crx_path, false)); | 498 ASSERT_TRUE(file_util::Delete(crx_path, false)); |
| 468 ASSERT_TRUE(file_util::Delete(pem_path, false)); | 499 |
| 469 scoped_ptr<ExtensionCreator> creator(new ExtensionCreator()); | 500 scoped_ptr<ExtensionCreator> creator(new ExtensionCreator()); |
| 470 ASSERT_TRUE(creator->Run(dir_path, crx_path, FilePath(), pem_path)); | 501 ASSERT_TRUE(creator->Run(dir_path, |
| 502 crx_path, |
| 503 pem_path, |
| 504 pem_output_path)); |
| 505 |
| 471 ASSERT_TRUE(file_util::PathExists(crx_path)); | 506 ASSERT_TRUE(file_util::PathExists(crx_path)); |
| 472 | 507 |
| 473 InstallExtension(crx_path, should_succeed); | 508 InstallExtension(crx_path, should_succeed); |
| 474 } | 509 } |
| 475 | 510 |
| 511 void PackAndInstallExtension(const FilePath& dir_path, |
| 512 bool should_succeed) { |
| 513 PackAndInstallExtension(dir_path, FilePath(), should_succeed); |
| 514 } |
| 515 |
| 476 void InstallExtension(const FilePath& path, | 516 void InstallExtension(const FilePath& path, |
| 477 bool should_succeed) { | 517 bool should_succeed) { |
| 478 ASSERT_TRUE(file_util::PathExists(path)); | 518 ASSERT_TRUE(file_util::PathExists(path)); |
| 479 service_->InstallExtension(path); | 519 service_->InstallExtension(path); |
| 480 loop_.RunAllPending(); | 520 loop_.RunAllPending(); |
| 481 std::vector<std::string> errors = GetErrors(); | 521 std::vector<std::string> errors = GetErrors(); |
| 482 if (should_succeed) { | 522 if (should_succeed) { |
| 483 ++total_successes_; | 523 ++total_successes_; |
| 484 | 524 |
| 485 EXPECT_TRUE(installed_) << path.value(); | 525 EXPECT_TRUE(installed_) << path.value(); |
| (...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 647 ASSERT_TRUE(dict != NULL) << msg; | 687 ASSERT_TRUE(dict != NULL) << msg; |
| 648 DictionaryValue* pref = NULL; | 688 DictionaryValue* pref = NULL; |
| 649 std::string manifest_path = extension_id + ".manifest"; | 689 std::string manifest_path = extension_id + ".manifest"; |
| 650 ASSERT_TRUE(dict->GetDictionary(manifest_path, &pref)) << msg; | 690 ASSERT_TRUE(dict->GetDictionary(manifest_path, &pref)) << msg; |
| 651 EXPECT_TRUE(pref != NULL) << msg; | 691 EXPECT_TRUE(pref != NULL) << msg; |
| 652 std::string val; | 692 std::string val; |
| 653 ASSERT_TRUE(pref->GetString(pref_path, &val)) << msg; | 693 ASSERT_TRUE(pref->GetString(pref_path, &val)) << msg; |
| 654 EXPECT_EQ(expected_val, val) << msg; | 694 EXPECT_EQ(expected_val, val) << msg; |
| 655 } | 695 } |
| 656 | 696 |
| 697 void SetPref(const std::string& extension_id, |
| 698 const std::string& pref_path, |
| 699 Value* value, |
| 700 const std::string& msg) { |
| 701 const DictionaryValue* dict = |
| 702 profile_->GetPrefs()->GetMutableDictionary("extensions.settings"); |
| 703 ASSERT_TRUE(dict != NULL) << msg; |
| 704 DictionaryValue* pref = NULL; |
| 705 ASSERT_TRUE(dict->GetDictionary(extension_id, &pref)) << msg; |
| 706 EXPECT_TRUE(pref != NULL) << msg; |
| 707 pref->Set(pref_path, value); |
| 708 } |
| 709 |
| 657 void SetPrefInteg(const std::string& extension_id, | 710 void SetPrefInteg(const std::string& extension_id, |
| 658 const std::string& pref_path, | 711 const std::string& pref_path, |
| 659 int value) { | 712 int value) { |
| 660 std::string msg = " while setting: "; | 713 std::string msg = " while setting: "; |
| 661 msg += extension_id; | 714 msg += extension_id; |
| 662 msg += " "; | 715 msg += " "; |
| 663 msg += pref_path; | 716 msg += pref_path; |
| 664 msg += " = "; | 717 msg += " = "; |
| 665 msg += base::IntToString(value); | 718 msg += base::IntToString(value); |
| 666 | 719 |
| 720 SetPref(extension_id, pref_path, Value::CreateIntegerValue(value), msg); |
| 721 } |
| 722 |
| 723 void SetPrefBool(const std::string& extension_id, |
| 724 const std::string& pref_path, |
| 725 bool value) { |
| 726 std::string msg = " while setting: "; |
| 727 msg += extension_id + " " + pref_path; |
| 728 msg += " = "; |
| 729 msg += (value ? "true" : "false"); |
| 730 |
| 731 SetPref(extension_id, pref_path, Value::CreateBooleanValue(value), msg); |
| 732 } |
| 733 |
| 734 void ClearPref(const std::string& extension_id, |
| 735 const std::string& pref_path) { |
| 736 std::string msg = " while clearing: "; |
| 737 msg += extension_id + " " + pref_path; |
| 738 |
| 667 const DictionaryValue* dict = | 739 const DictionaryValue* dict = |
| 668 profile_->GetPrefs()->GetMutableDictionary("extensions.settings"); | 740 profile_->GetPrefs()->GetMutableDictionary("extensions.settings"); |
| 669 ASSERT_TRUE(dict != NULL) << msg; | 741 ASSERT_TRUE(dict != NULL) << msg; |
| 670 DictionaryValue* pref = NULL; | 742 DictionaryValue* pref = NULL; |
| 671 ASSERT_TRUE(dict->GetDictionary(extension_id, &pref)) << msg; | 743 ASSERT_TRUE(dict->GetDictionary(extension_id, &pref)) << msg; |
| 672 EXPECT_TRUE(pref != NULL) << msg; | 744 EXPECT_TRUE(pref != NULL) << msg; |
| 673 pref->SetInteger(pref_path, value); | 745 pref->Remove(pref_path, NULL); |
| 746 } |
| 747 |
| 748 void SetPrefStringSet(const std::string& extension_id, |
| 749 const std::string& pref_path, |
| 750 const std::set<std::string>& value) { |
| 751 std::string msg = " while setting: "; |
| 752 msg += extension_id + " " + pref_path; |
| 753 |
| 754 ListValue* list_value = new ListValue(); |
| 755 for (std::set<std::string>::const_iterator iter = value.begin(); |
| 756 iter != value.end(); ++iter) |
| 757 list_value->Append(Value::CreateStringValue(*iter)); |
| 758 |
| 759 SetPref(extension_id, pref_path, list_value, msg); |
| 674 } | 760 } |
| 675 | 761 |
| 676 protected: | 762 protected: |
| 677 ExtensionList loaded_; | 763 ExtensionList loaded_; |
| 678 std::string unloaded_id_; | 764 std::string unloaded_id_; |
| 679 const Extension* installed_; | 765 const Extension* installed_; |
| 680 | 766 |
| 681 private: | 767 private: |
| 682 NotificationRegistrar registrar_; | 768 NotificationRegistrar registrar_; |
| 683 }; | 769 }; |
| (...skipping 318 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1002 EXPECT_EQ(0u, errors.size()) << "There were errors: " | 1088 EXPECT_EQ(0u, errors.size()) << "There were errors: " |
| 1003 << JoinString(errors, ','); | 1089 << JoinString(errors, ','); |
| 1004 EXPECT_TRUE(service_->GetExtensionById(loaded_[0]->id(), false)) << | 1090 EXPECT_TRUE(service_->GetExtensionById(loaded_[0]->id(), false)) << |
| 1005 path.value(); | 1091 path.value(); |
| 1006 | 1092 |
| 1007 installed_ = NULL; | 1093 installed_ = NULL; |
| 1008 loaded_.clear(); | 1094 loaded_.clear(); |
| 1009 ExtensionErrorReporter::GetInstance()->ClearErrors(); | 1095 ExtensionErrorReporter::GetInstance()->ClearErrors(); |
| 1010 } | 1096 } |
| 1011 | 1097 |
| 1098 // This tests that the granted permissions preferences are correctly set when |
| 1099 // installing an extension. |
| 1100 TEST_F(ExtensionsServiceTest, GrantedPermissions) { |
| 1101 InitializeEmptyExtensionsService(); |
| 1102 FilePath path; |
| 1103 FilePath pem_path; |
| 1104 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &path)); |
| 1105 path = path.AppendASCII("extensions") |
| 1106 .AppendASCII("permissions"); |
| 1107 |
| 1108 pem_path = path.AppendASCII("unknown.pem"); |
| 1109 path = path.AppendASCII("unknown"); |
| 1110 |
| 1111 ASSERT_TRUE(file_util::PathExists(pem_path)); |
| 1112 ASSERT_TRUE(file_util::PathExists(path)); |
| 1113 |
| 1114 ExtensionPrefs* prefs = service_->extension_prefs(); |
| 1115 |
| 1116 std::set<std::string> expected_api_perms; |
| 1117 std::set<std::string> known_api_perms; |
| 1118 ExtensionExtent expected_host_perms; |
| 1119 ExtensionExtent known_host_perms; |
| 1120 |
| 1121 // Make sure there aren't any granted permissions before the |
| 1122 // extension is installed. |
| 1123 EXPECT_FALSE(prefs->GetGrantedPermissions( |
| 1124 permissions_crx, &known_api_perms, &known_host_perms)); |
| 1125 EXPECT_TRUE(known_api_perms.empty()); |
| 1126 EXPECT_TRUE(known_host_perms.is_empty()); |
| 1127 |
| 1128 PackAndInstallExtension(path, pem_path, true); |
| 1129 |
| 1130 EXPECT_EQ(0u, GetErrors().size()); |
| 1131 EXPECT_EQ(1u, service_->extensions()->size()); |
| 1132 std::string extension_id = service_->extensions()->at(0)->id(); |
| 1133 EXPECT_EQ(permissions_crx, extension_id); |
| 1134 |
| 1135 |
| 1136 // Verify that the valid API permissions have been recognized. |
| 1137 expected_api_perms.insert("tabs"); |
| 1138 |
| 1139 AddPattern(&expected_host_perms, "http://*.google.com/*"); |
| 1140 AddPattern(&expected_host_perms, "https://*.google.com/*"); |
| 1141 AddPattern(&expected_host_perms, "http://www.example.com/*"); |
| 1142 |
| 1143 EXPECT_TRUE(prefs->GetGrantedPermissions(extension_id, |
| 1144 &known_api_perms, |
| 1145 &known_host_perms)); |
| 1146 |
| 1147 EXPECT_EQ(expected_api_perms, known_api_perms); |
| 1148 AssertEqualExtents(&expected_host_perms, &known_host_perms); |
| 1149 } |
| 1150 |
| 1151 // Tests that the extension is disabled when permissions are missing from |
| 1152 // the extension's granted permissions preferences. (This simulates updating |
| 1153 // the browser to a version which recognizes more permissions). |
| 1154 TEST_F(ExtensionsServiceTest, GrantedAPIPermissions) { |
| 1155 InitializeEmptyExtensionsService(); |
| 1156 |
| 1157 FilePath path; |
| 1158 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &path)); |
| 1159 path = path.AppendASCII("extensions") |
| 1160 .AppendASCII("permissions") |
| 1161 .AppendASCII("unknown"); |
| 1162 |
| 1163 ASSERT_TRUE(file_util::PathExists(path)); |
| 1164 |
| 1165 PackAndInstallExtension(path, true); |
| 1166 |
| 1167 EXPECT_EQ(0u, GetErrors().size()); |
| 1168 EXPECT_EQ(1u, service_->extensions()->size()); |
| 1169 const Extension* extension = service_->extensions()->at(0); |
| 1170 std::string extension_id = extension->id(); |
| 1171 |
| 1172 ExtensionPrefs* prefs = service_->extension_prefs(); |
| 1173 |
| 1174 std::set<std::string> expected_api_permissions; |
| 1175 ExtensionExtent expected_host_permissions; |
| 1176 |
| 1177 expected_api_permissions.insert("tabs"); |
| 1178 AddPattern(&expected_host_permissions, "http://*.google.com/*"); |
| 1179 AddPattern(&expected_host_permissions, "https://*.google.com/*"); |
| 1180 AddPattern(&expected_host_permissions, "http://www.example.com/*"); |
| 1181 |
| 1182 std::set<std::string> api_permissions; |
| 1183 std::set<std::string> host_permissions; |
| 1184 |
| 1185 // Test that the extension is disabled when an API permission is missing from |
| 1186 // the extension's granted api permissions preference. (This simulates |
| 1187 // updating the browser to a version which recognizes a new API permission). |
| 1188 host_permissions.insert("http://*.google.com/*"); |
| 1189 host_permissions.insert("https://*.google.com/*"); |
| 1190 host_permissions.insert("http://www.example.com/*"); |
| 1191 |
| 1192 SetPrefBool(extension_id, "granted_permissions.initialized", true); |
| 1193 SetPrefStringSet(extension_id, "granted_permissions.api", api_permissions); |
| 1194 SetPrefStringSet(extension_id, "granted_permissions.host", host_permissions); |
| 1195 |
| 1196 service_->ReloadExtensions(); |
| 1197 |
| 1198 ASSERT_TRUE(prefs->GetExtensionState(extension_id) == Extension::DISABLED); |
| 1199 ASSERT_TRUE(prefs->DidExtensionEscalatePermissions(extension_id)); |
| 1200 |
| 1201 // Now grant and re-enable the extension, making sure the prefs are updated. |
| 1202 service_->GrantPermissionsAndEnableExtension(extension); |
| 1203 |
| 1204 ASSERT_TRUE(prefs->GetExtensionState(extension_id) == Extension::ENABLED); |
| 1205 ASSERT_FALSE(prefs->DidExtensionEscalatePermissions(extension_id)); |
| 1206 |
| 1207 std::set<std::string> current_api_permissions; |
| 1208 ExtensionExtent current_host_permissions; |
| 1209 |
| 1210 ASSERT_TRUE(prefs->GetGrantedPermissions( |
| 1211 extension_id, ¤t_api_permissions, ¤t_host_permissions)); |
| 1212 |
| 1213 ASSERT_EQ(expected_api_permissions, current_api_permissions); |
| 1214 AssertEqualExtents(&expected_host_permissions, ¤t_host_permissions); |
| 1215 |
| 1216 // Tests that the extension is disabled when a host permission is missing from |
| 1217 // the extension's granted host permissions preference. (This simulates |
| 1218 // updating the browser to a version which recognizes additional host |
| 1219 // permissions). |
| 1220 api_permissions.clear(); |
| 1221 host_permissions.clear(); |
| 1222 current_api_permissions.clear(); |
| 1223 current_host_permissions.ClearPaths(); |
| 1224 |
| 1225 api_permissions.insert("tabs"); |
| 1226 host_permissions.insert("http://*.google.com/*"); |
| 1227 host_permissions.insert("https://*.google.com/*"); |
| 1228 |
| 1229 SetPrefBool(extension_id, "granted_permissions.initialized", true); |
| 1230 SetPrefStringSet(extension_id, "granted_permissions.api", api_permissions); |
| 1231 SetPrefStringSet(extension_id, "granted_permissions.host", host_permissions); |
| 1232 |
| 1233 service_->ReloadExtensions(); |
| 1234 |
| 1235 ASSERT_TRUE(prefs->GetExtensionState(extension_id) == Extension::DISABLED); |
| 1236 ASSERT_TRUE(prefs->DidExtensionEscalatePermissions(extension_id)); |
| 1237 |
| 1238 // Now grant and re-enable the extension, making sure the prefs are updated. |
| 1239 service_->GrantPermissionsAndEnableExtension(extension); |
| 1240 |
| 1241 ASSERT_TRUE(prefs->GetExtensionState(extension_id) == Extension::ENABLED); |
| 1242 ASSERT_FALSE(prefs->DidExtensionEscalatePermissions(extension_id)); |
| 1243 |
| 1244 ASSERT_TRUE(prefs->GetGrantedPermissions( |
| 1245 extension_id, ¤t_api_permissions, ¤t_host_permissions)); |
| 1246 |
| 1247 ASSERT_EQ(expected_api_permissions, current_api_permissions); |
| 1248 AssertEqualExtents(&expected_host_permissions, ¤t_host_permissions); |
| 1249 |
| 1250 // Tests that the granted permissions preferences are initialized when |
| 1251 // migrating from the old pref schema. |
| 1252 current_api_permissions.clear(); |
| 1253 current_host_permissions.ClearPaths(); |
| 1254 |
| 1255 ClearPref(extension_id, "granted_permissions"); |
| 1256 |
| 1257 service_->ReloadExtensions(); |
| 1258 |
| 1259 ASSERT_TRUE(prefs->GetExtensionState(extension_id) == Extension::ENABLED); |
| 1260 ASSERT_FALSE(prefs->DidExtensionEscalatePermissions(extension_id)); |
| 1261 |
| 1262 ASSERT_TRUE(prefs->GetGrantedPermissions( |
| 1263 extension_id, ¤t_api_permissions, ¤t_host_permissions)); |
| 1264 |
| 1265 ASSERT_EQ(expected_api_permissions, current_api_permissions); |
| 1266 AssertEqualExtents(&expected_host_permissions, ¤t_host_permissions); |
| 1267 } |
| 1268 |
| 1012 // Test Packaging and installing an extension. | 1269 // Test Packaging and installing an extension. |
| 1013 TEST_F(ExtensionsServiceTest, PackExtension) { | 1270 TEST_F(ExtensionsServiceTest, PackExtension) { |
| 1014 InitializeEmptyExtensionsService(); | 1271 InitializeEmptyExtensionsService(); |
| 1015 FilePath extensions_path; | 1272 FilePath extensions_path; |
| 1016 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &extensions_path)); | 1273 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &extensions_path)); |
| 1017 extensions_path = extensions_path.AppendASCII("extensions"); | 1274 extensions_path = extensions_path.AppendASCII("extensions"); |
| 1018 FilePath input_directory = extensions_path | 1275 FilePath input_directory = extensions_path |
| 1019 .AppendASCII("good") | 1276 .AppendASCII("good") |
| 1020 .AppendASCII("Extensions") | 1277 .AppendASCII("Extensions") |
| 1021 .AppendASCII("behllobkkfkfnphdnhnkndlbkcpglgmj") | 1278 .AppendASCII("behllobkkfkfnphdnhnkndlbkcpglgmj") |
| (...skipping 1730 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2752 // Component extensions shouldn't get recourded in the prefs. | 3009 // Component extensions shouldn't get recourded in the prefs. |
| 2753 ValidatePrefKeyCount(0); | 3010 ValidatePrefKeyCount(0); |
| 2754 | 3011 |
| 2755 // Reload all extensions, and make sure it comes back. | 3012 // Reload all extensions, and make sure it comes back. |
| 2756 std::string extension_id = service_->extensions()->at(0)->id(); | 3013 std::string extension_id = service_->extensions()->at(0)->id(); |
| 2757 loaded_.clear(); | 3014 loaded_.clear(); |
| 2758 service_->ReloadExtensions(); | 3015 service_->ReloadExtensions(); |
| 2759 ASSERT_EQ(1u, service_->extensions()->size()); | 3016 ASSERT_EQ(1u, service_->extensions()->size()); |
| 2760 EXPECT_EQ(extension_id, service_->extensions()->at(0)->id()); | 3017 EXPECT_EQ(extension_id, service_->extensions()->at(0)->id()); |
| 2761 } | 3018 } |
| OLD | NEW |