| 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 // Use the existing pem key, if provided. |
| 491 FilePath pem_output_path; |
| 492 if (pem_path.value().empty()) { |
| 493 pem_output_path = crx_path.DirName().AppendASCII("temp.pem"); |
| 494 ASSERT_TRUE(file_util::Delete(pem_output_path, false)); |
| 495 } else { |
| 496 ASSERT_TRUE(file_util::PathExists(pem_path)); |
| 497 } |
| 466 | 498 |
| 467 ASSERT_TRUE(file_util::Delete(crx_path, false)); | 499 ASSERT_TRUE(file_util::Delete(crx_path, false)); |
| 468 ASSERT_TRUE(file_util::Delete(pem_path, false)); | 500 |
| 469 scoped_ptr<ExtensionCreator> creator(new ExtensionCreator()); | 501 scoped_ptr<ExtensionCreator> creator(new ExtensionCreator()); |
| 470 ASSERT_TRUE(creator->Run(dir_path, crx_path, FilePath(), pem_path)); | 502 ASSERT_TRUE(creator->Run(dir_path, |
| 503 crx_path, |
| 504 pem_path, |
| 505 pem_output_path)); |
| 506 |
| 471 ASSERT_TRUE(file_util::PathExists(crx_path)); | 507 ASSERT_TRUE(file_util::PathExists(crx_path)); |
| 472 | 508 |
| 473 InstallExtension(crx_path, should_succeed); | 509 InstallExtension(crx_path, should_succeed); |
| 474 } | 510 } |
| 475 | 511 |
| 512 void PackAndInstallExtension(const FilePath& dir_path, |
| 513 bool should_succeed) { |
| 514 PackAndInstallExtension(dir_path, FilePath(), should_succeed); |
| 515 } |
| 516 |
| 476 void InstallExtension(const FilePath& path, | 517 void InstallExtension(const FilePath& path, |
| 477 bool should_succeed) { | 518 bool should_succeed) { |
| 478 ASSERT_TRUE(file_util::PathExists(path)); | 519 ASSERT_TRUE(file_util::PathExists(path)); |
| 479 service_->InstallExtension(path); | 520 service_->InstallExtension(path); |
| 480 loop_.RunAllPending(); | 521 loop_.RunAllPending(); |
| 481 std::vector<std::string> errors = GetErrors(); | 522 std::vector<std::string> errors = GetErrors(); |
| 482 if (should_succeed) { | 523 if (should_succeed) { |
| 483 ++total_successes_; | 524 ++total_successes_; |
| 484 | 525 |
| 485 EXPECT_TRUE(installed_) << path.value(); | 526 EXPECT_TRUE(installed_) << path.value(); |
| (...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 647 ASSERT_TRUE(dict != NULL) << msg; | 688 ASSERT_TRUE(dict != NULL) << msg; |
| 648 DictionaryValue* pref = NULL; | 689 DictionaryValue* pref = NULL; |
| 649 std::string manifest_path = extension_id + ".manifest"; | 690 std::string manifest_path = extension_id + ".manifest"; |
| 650 ASSERT_TRUE(dict->GetDictionary(manifest_path, &pref)) << msg; | 691 ASSERT_TRUE(dict->GetDictionary(manifest_path, &pref)) << msg; |
| 651 EXPECT_TRUE(pref != NULL) << msg; | 692 EXPECT_TRUE(pref != NULL) << msg; |
| 652 std::string val; | 693 std::string val; |
| 653 ASSERT_TRUE(pref->GetString(pref_path, &val)) << msg; | 694 ASSERT_TRUE(pref->GetString(pref_path, &val)) << msg; |
| 654 EXPECT_EQ(expected_val, val) << msg; | 695 EXPECT_EQ(expected_val, val) << msg; |
| 655 } | 696 } |
| 656 | 697 |
| 698 void SetPref(const std::string& extension_id, |
| 699 const std::string& pref_path, |
| 700 Value* value, |
| 701 const std::string& msg) { |
| 702 const DictionaryValue* dict = |
| 703 profile_->GetPrefs()->GetMutableDictionary("extensions.settings"); |
| 704 ASSERT_TRUE(dict != NULL) << msg; |
| 705 DictionaryValue* pref = NULL; |
| 706 ASSERT_TRUE(dict->GetDictionary(extension_id, &pref)) << msg; |
| 707 EXPECT_TRUE(pref != NULL) << msg; |
| 708 pref->Set(pref_path, value); |
| 709 } |
| 710 |
| 657 void SetPrefInteg(const std::string& extension_id, | 711 void SetPrefInteg(const std::string& extension_id, |
| 658 const std::string& pref_path, | 712 const std::string& pref_path, |
| 659 int value) { | 713 int value) { |
| 660 std::string msg = " while setting: "; | 714 std::string msg = " while setting: "; |
| 661 msg += extension_id; | 715 msg += extension_id; |
| 662 msg += " "; | 716 msg += " "; |
| 663 msg += pref_path; | 717 msg += pref_path; |
| 664 msg += " = "; | 718 msg += " = "; |
| 665 msg += base::IntToString(value); | 719 msg += base::IntToString(value); |
| 666 | 720 |
| 721 SetPref(extension_id, pref_path, Value::CreateIntegerValue(value), msg); |
| 722 } |
| 723 |
| 724 void SetPrefBool(const std::string& extension_id, |
| 725 const std::string& pref_path, |
| 726 bool value) { |
| 727 std::string msg = " while setting: "; |
| 728 msg += extension_id + " " + pref_path; |
| 729 msg += " = "; |
| 730 msg += (value ? "true" : "false"); |
| 731 |
| 732 SetPref(extension_id, pref_path, Value::CreateBooleanValue(value), msg); |
| 733 } |
| 734 |
| 735 void ClearPref(const std::string& extension_id, |
| 736 const std::string& pref_path) { |
| 737 std::string msg = " while clearing: "; |
| 738 msg += extension_id + " " + pref_path; |
| 739 |
| 667 const DictionaryValue* dict = | 740 const DictionaryValue* dict = |
| 668 profile_->GetPrefs()->GetMutableDictionary("extensions.settings"); | 741 profile_->GetPrefs()->GetMutableDictionary("extensions.settings"); |
| 669 ASSERT_TRUE(dict != NULL) << msg; | 742 ASSERT_TRUE(dict != NULL) << msg; |
| 670 DictionaryValue* pref = NULL; | 743 DictionaryValue* pref = NULL; |
| 671 ASSERT_TRUE(dict->GetDictionary(extension_id, &pref)) << msg; | 744 ASSERT_TRUE(dict->GetDictionary(extension_id, &pref)) << msg; |
| 672 EXPECT_TRUE(pref != NULL) << msg; | 745 EXPECT_TRUE(pref != NULL) << msg; |
| 673 pref->SetInteger(pref_path, value); | 746 pref->Remove(pref_path, NULL); |
| 747 } |
| 748 |
| 749 void SetPrefStringSet(const std::string& extension_id, |
| 750 const std::string& pref_path, |
| 751 const std::set<std::string>& value) { |
| 752 std::string msg = " while setting: "; |
| 753 msg += extension_id + " " + pref_path; |
| 754 |
| 755 ListValue* list_value = new ListValue(); |
| 756 for (std::set<std::string>::const_iterator iter = value.begin(); |
| 757 iter != value.end(); ++iter) |
| 758 list_value->Append(Value::CreateStringValue(*iter)); |
| 759 |
| 760 SetPref(extension_id, pref_path, list_value, msg); |
| 674 } | 761 } |
| 675 | 762 |
| 676 protected: | 763 protected: |
| 677 ExtensionList loaded_; | 764 ExtensionList loaded_; |
| 678 std::string unloaded_id_; | 765 std::string unloaded_id_; |
| 679 const Extension* installed_; | 766 const Extension* installed_; |
| 680 | 767 |
| 681 private: | 768 private: |
| 682 NotificationRegistrar registrar_; | 769 NotificationRegistrar registrar_; |
| 683 }; | 770 }; |
| (...skipping 316 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1000 EXPECT_EQ(0u, errors.size()) << "There were errors: " | 1087 EXPECT_EQ(0u, errors.size()) << "There were errors: " |
| 1001 << JoinString(errors, ','); | 1088 << JoinString(errors, ','); |
| 1002 EXPECT_TRUE(service_->GetExtensionById(loaded_[0]->id(), false)) << | 1089 EXPECT_TRUE(service_->GetExtensionById(loaded_[0]->id(), false)) << |
| 1003 path.value(); | 1090 path.value(); |
| 1004 | 1091 |
| 1005 installed_ = NULL; | 1092 installed_ = NULL; |
| 1006 loaded_.clear(); | 1093 loaded_.clear(); |
| 1007 ExtensionErrorReporter::GetInstance()->ClearErrors(); | 1094 ExtensionErrorReporter::GetInstance()->ClearErrors(); |
| 1008 } | 1095 } |
| 1009 | 1096 |
| 1097 // This tests that the granted permissions preferences are correctly set when |
| 1098 // installing an extension. |
| 1099 TEST_F(ExtensionsServiceTest, GrantedPermissions) { |
| 1100 InitializeEmptyExtensionsService(); |
| 1101 FilePath path; |
| 1102 FilePath pem_path; |
| 1103 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &path)); |
| 1104 path = path.AppendASCII("extensions") |
| 1105 .AppendASCII("permissions"); |
| 1106 |
| 1107 pem_path = path.AppendASCII("unknown.pem"); |
| 1108 path = path.AppendASCII("unknown"); |
| 1109 |
| 1110 ASSERT_TRUE(file_util::PathExists(pem_path)); |
| 1111 ASSERT_TRUE(file_util::PathExists(path)); |
| 1112 |
| 1113 ExtensionPrefs* prefs = service_->extension_prefs(); |
| 1114 |
| 1115 std::set<std::string> expected_api_perms; |
| 1116 std::set<std::string> known_api_perms; |
| 1117 bool full_access; |
| 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, &full_access, &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 ASSERT_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 &full_access, |
| 1145 &known_api_perms, |
| 1146 &known_host_perms)); |
| 1147 |
| 1148 EXPECT_EQ(expected_api_perms, known_api_perms); |
| 1149 EXPECT_FALSE(full_access); |
| 1150 AssertEqualExtents(&expected_host_perms, &known_host_perms); |
| 1151 } |
| 1152 |
| 1153 #if !defined(OS_CHROMEOS) |
| 1154 // Tests that the granted permissions full_access bit gets set correctly when |
| 1155 // an extension contains an NPAPI plugin. Don't run this test on Chrome OS |
| 1156 // since they don't support plugins. |
| 1157 TEST_F(ExtensionsServiceTest, GrantedFullAccessPermissions) { |
| 1158 InitializeEmptyExtensionsService(); |
| 1159 |
| 1160 FilePath path; |
| 1161 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &path)); |
| 1162 path = path.AppendASCII("extensions") |
| 1163 .AppendASCII("good") |
| 1164 .AppendASCII("Extensions") |
| 1165 .AppendASCII(good1) |
| 1166 .AppendASCII("2"); |
| 1167 |
| 1168 ASSERT_TRUE(file_util::PathExists(path)); |
| 1169 |
| 1170 PackAndInstallExtension(path, true); |
| 1171 |
| 1172 EXPECT_EQ(0u, GetErrors().size()); |
| 1173 EXPECT_EQ(1u, service_->extensions()->size()); |
| 1174 const Extension* extension = service_->extensions()->at(0); |
| 1175 std::string extension_id = extension->id(); |
| 1176 ExtensionPrefs* prefs = service_->extension_prefs(); |
| 1177 |
| 1178 bool full_access; |
| 1179 std::set<std::string> api_permissions; |
| 1180 ExtensionExtent host_permissions; |
| 1181 EXPECT_TRUE(prefs->GetGrantedPermissions( |
| 1182 extension_id, &full_access, &api_permissions, &host_permissions)); |
| 1183 |
| 1184 EXPECT_TRUE(full_access); |
| 1185 EXPECT_TRUE(api_permissions.empty()); |
| 1186 EXPECT_TRUE(host_permissions.is_empty()); |
| 1187 } |
| 1188 #endif |
| 1189 |
| 1190 // Tests that the extension is disabled when permissions are missing from |
| 1191 // the extension's granted permissions preferences. (This simulates updating |
| 1192 // the browser to a version which recognizes more permissions). |
| 1193 TEST_F(ExtensionsServiceTest, GrantedAPIAndHostPermissions) { |
| 1194 InitializeEmptyExtensionsService(); |
| 1195 |
| 1196 FilePath path; |
| 1197 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &path)); |
| 1198 path = path.AppendASCII("extensions") |
| 1199 .AppendASCII("permissions") |
| 1200 .AppendASCII("unknown"); |
| 1201 |
| 1202 ASSERT_TRUE(file_util::PathExists(path)); |
| 1203 |
| 1204 PackAndInstallExtension(path, true); |
| 1205 |
| 1206 EXPECT_EQ(0u, GetErrors().size()); |
| 1207 EXPECT_EQ(1u, service_->extensions()->size()); |
| 1208 const Extension* extension = service_->extensions()->at(0); |
| 1209 std::string extension_id = extension->id(); |
| 1210 |
| 1211 ExtensionPrefs* prefs = service_->extension_prefs(); |
| 1212 |
| 1213 std::set<std::string> expected_api_permissions; |
| 1214 ExtensionExtent expected_host_permissions; |
| 1215 |
| 1216 expected_api_permissions.insert("tabs"); |
| 1217 AddPattern(&expected_host_permissions, "http://*.google.com/*"); |
| 1218 AddPattern(&expected_host_permissions, "https://*.google.com/*"); |
| 1219 AddPattern(&expected_host_permissions, "http://www.example.com/*"); |
| 1220 |
| 1221 std::set<std::string> api_permissions; |
| 1222 std::set<std::string> host_permissions; |
| 1223 |
| 1224 // Test that the extension is disabled when an API permission is missing from |
| 1225 // the extension's granted api permissions preference. (This simulates |
| 1226 // updating the browser to a version which recognizes a new API permission). |
| 1227 SetPrefStringSet(extension_id, "granted_permissions.api", api_permissions); |
| 1228 |
| 1229 service_->ReloadExtensions(); |
| 1230 |
| 1231 EXPECT_EQ(1u, service_->disabled_extensions()->size()); |
| 1232 extension = service_->disabled_extensions()->at(0); |
| 1233 |
| 1234 ASSERT_TRUE(prefs->GetExtensionState(extension_id) == Extension::DISABLED); |
| 1235 ASSERT_TRUE(prefs->DidExtensionEscalatePermissions(extension_id)); |
| 1236 |
| 1237 // Now grant and re-enable the extension, making sure the prefs are updated. |
| 1238 service_->GrantPermissionsAndEnableExtension(extension); |
| 1239 |
| 1240 ASSERT_TRUE(prefs->GetExtensionState(extension_id) == Extension::ENABLED); |
| 1241 ASSERT_FALSE(prefs->DidExtensionEscalatePermissions(extension_id)); |
| 1242 |
| 1243 std::set<std::string> current_api_permissions; |
| 1244 ExtensionExtent current_host_permissions; |
| 1245 bool current_full_access; |
| 1246 |
| 1247 ASSERT_TRUE(prefs->GetGrantedPermissions(extension_id, |
| 1248 ¤t_full_access, |
| 1249 ¤t_api_permissions, |
| 1250 ¤t_host_permissions)); |
| 1251 |
| 1252 ASSERT_FALSE(current_full_access); |
| 1253 ASSERT_EQ(expected_api_permissions, current_api_permissions); |
| 1254 AssertEqualExtents(&expected_host_permissions, ¤t_host_permissions); |
| 1255 |
| 1256 // Tests that the extension is disabled when a host permission is missing from |
| 1257 // the extension's granted host permissions preference. (This simulates |
| 1258 // updating the browser to a version which recognizes additional host |
| 1259 // permissions). |
| 1260 api_permissions.clear(); |
| 1261 host_permissions.clear(); |
| 1262 current_api_permissions.clear(); |
| 1263 current_host_permissions.ClearPaths(); |
| 1264 |
| 1265 api_permissions.insert("tabs"); |
| 1266 host_permissions.insert("http://*.google.com/*"); |
| 1267 host_permissions.insert("https://*.google.com/*"); |
| 1268 |
| 1269 SetPrefStringSet(extension_id, "granted_permissions.api", api_permissions); |
| 1270 SetPrefStringSet(extension_id, "granted_permissions.host", host_permissions); |
| 1271 |
| 1272 service_->ReloadExtensions(); |
| 1273 |
| 1274 EXPECT_EQ(1u, service_->disabled_extensions()->size()); |
| 1275 extension = service_->disabled_extensions()->at(0); |
| 1276 |
| 1277 ASSERT_TRUE(prefs->GetExtensionState(extension_id) == Extension::DISABLED); |
| 1278 ASSERT_TRUE(prefs->DidExtensionEscalatePermissions(extension_id)); |
| 1279 |
| 1280 // Now grant and re-enable the extension, making sure the prefs are updated. |
| 1281 service_->GrantPermissionsAndEnableExtension(extension); |
| 1282 |
| 1283 ASSERT_TRUE(prefs->GetExtensionState(extension_id) == Extension::ENABLED); |
| 1284 ASSERT_FALSE(prefs->DidExtensionEscalatePermissions(extension_id)); |
| 1285 |
| 1286 ASSERT_TRUE(prefs->GetGrantedPermissions(extension_id, |
| 1287 ¤t_full_access, |
| 1288 ¤t_api_permissions, |
| 1289 ¤t_host_permissions)); |
| 1290 |
| 1291 ASSERT_FALSE(current_full_access); |
| 1292 ASSERT_EQ(expected_api_permissions, current_api_permissions); |
| 1293 AssertEqualExtents(&expected_host_permissions, ¤t_host_permissions); |
| 1294 |
| 1295 // Tests that the granted permissions preferences are initialized when |
| 1296 // migrating from the old pref schema. |
| 1297 current_api_permissions.clear(); |
| 1298 current_host_permissions.ClearPaths(); |
| 1299 |
| 1300 ClearPref(extension_id, "granted_permissions"); |
| 1301 |
| 1302 service_->ReloadExtensions(); |
| 1303 |
| 1304 EXPECT_EQ(1u, service_->extensions()->size()); |
| 1305 extension = service_->extensions()->at(0); |
| 1306 |
| 1307 ASSERT_TRUE(prefs->GetExtensionState(extension_id) == Extension::ENABLED); |
| 1308 ASSERT_FALSE(prefs->DidExtensionEscalatePermissions(extension_id)); |
| 1309 |
| 1310 ASSERT_TRUE(prefs->GetGrantedPermissions(extension_id, |
| 1311 ¤t_full_access, |
| 1312 ¤t_api_permissions, |
| 1313 ¤t_host_permissions)); |
| 1314 |
| 1315 ASSERT_FALSE(current_full_access); |
| 1316 ASSERT_EQ(expected_api_permissions, current_api_permissions); |
| 1317 AssertEqualExtents(&expected_host_permissions, ¤t_host_permissions); |
| 1318 } |
| 1319 |
| 1010 // Test Packaging and installing an extension. | 1320 // Test Packaging and installing an extension. |
| 1011 TEST_F(ExtensionsServiceTest, PackExtension) { | 1321 TEST_F(ExtensionsServiceTest, PackExtension) { |
| 1012 InitializeEmptyExtensionsService(); | 1322 InitializeEmptyExtensionsService(); |
| 1013 FilePath extensions_path; | 1323 FilePath extensions_path; |
| 1014 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &extensions_path)); | 1324 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &extensions_path)); |
| 1015 extensions_path = extensions_path.AppendASCII("extensions"); | 1325 extensions_path = extensions_path.AppendASCII("extensions"); |
| 1016 FilePath input_directory = extensions_path | 1326 FilePath input_directory = extensions_path |
| 1017 .AppendASCII("good") | 1327 .AppendASCII("good") |
| 1018 .AppendASCII("Extensions") | 1328 .AppendASCII("Extensions") |
| 1019 .AppendASCII("behllobkkfkfnphdnhnkndlbkcpglgmj") | 1329 .AppendASCII("behllobkkfkfnphdnhnkndlbkcpglgmj") |
| (...skipping 1767 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2787 // Component extensions shouldn't get recourded in the prefs. | 3097 // Component extensions shouldn't get recourded in the prefs. |
| 2788 ValidatePrefKeyCount(0); | 3098 ValidatePrefKeyCount(0); |
| 2789 | 3099 |
| 2790 // Reload all extensions, and make sure it comes back. | 3100 // Reload all extensions, and make sure it comes back. |
| 2791 std::string extension_id = service_->extensions()->at(0)->id(); | 3101 std::string extension_id = service_->extensions()->at(0)->id(); |
| 2792 loaded_.clear(); | 3102 loaded_.clear(); |
| 2793 service_->ReloadExtensions(); | 3103 service_->ReloadExtensions(); |
| 2794 ASSERT_EQ(1u, service_->extensions()->size()); | 3104 ASSERT_EQ(1u, service_->extensions()->size()); |
| 2795 EXPECT_EQ(extension_id, service_->extensions()->at(0)->id()); | 3105 EXPECT_EQ(extension_id, service_->extensions()->at(0)->id()); |
| 2796 } | 3106 } |
| OLD | NEW |