OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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_service_unittest.h" | 5 #include "chrome/browser/extensions/extension_service_unittest.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <set> | 8 #include <set> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
94 const char* const theme_crx = "iamefpfkojoapidjnbafmgkgncegbkad"; | 94 const char* const theme_crx = "iamefpfkojoapidjnbafmgkgncegbkad"; |
95 const char* const theme2_crx = "pjpgmfcmabopnnfonnhmdjglfpjjfkbf"; | 95 const char* const theme2_crx = "pjpgmfcmabopnnfonnhmdjglfpjjfkbf"; |
96 const char* const permissions_crx = "eagpmdpfmaekmmcejjbmjoecnejeiiin"; | 96 const char* const permissions_crx = "eagpmdpfmaekmmcejjbmjoecnejeiiin"; |
97 | 97 |
98 struct ExtensionsOrder { | 98 struct ExtensionsOrder { |
99 bool operator()(const Extension* a, const Extension* b) { | 99 bool operator()(const Extension* a, const Extension* b) { |
100 return a->name() < b->name(); | 100 return a->name() < b->name(); |
101 } | 101 } |
102 }; | 102 }; |
103 | 103 |
104 static std::vector<std::string> GetErrors() { | 104 static std::vector<string16> GetErrors() { |
105 const std::vector<std::string>* errors = | 105 const std::vector<string16>* errors = |
106 ExtensionErrorReporter::GetInstance()->GetErrors(); | 106 ExtensionErrorReporter::GetInstance()->GetErrors(); |
107 std::vector<std::string> ret_val; | 107 std::vector<string16> ret_val; |
108 | 108 |
109 for (std::vector<std::string>::const_iterator iter = errors->begin(); | 109 for (std::vector<string16>::const_iterator iter = errors->begin(); |
110 iter != errors->end(); ++iter) { | 110 iter != errors->end(); ++iter) { |
111 if (iter->find(".svn") == std::string::npos) { | 111 std::string utf8_error = UTF16ToUTF8(*iter); |
| 112 if (utf8_error.find(".svn") == std::string::npos) { |
112 ret_val.push_back(*iter); | 113 ret_val.push_back(*iter); |
113 } | 114 } |
114 } | 115 } |
115 | 116 |
116 // The tests rely on the errors being in a certain order, which can vary | 117 // The tests rely on the errors being in a certain order, which can vary |
117 // depending on how filesystem iteration works. | 118 // depending on how filesystem iteration works. |
118 std::stable_sort(ret_val.begin(), ret_val.end()); | 119 std::stable_sort(ret_val.begin(), ret_val.end()); |
119 | 120 |
120 return ret_val; | 121 return ret_val; |
121 } | 122 } |
(...skipping 523 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
645 installer->InstallCrx(crx_path); | 646 installer->InstallCrx(crx_path); |
646 | 647 |
647 return WaitForCrxInstall(crx_path, install_state); | 648 return WaitForCrxInstall(crx_path, install_state); |
648 } | 649 } |
649 | 650 |
650 // Wait for a CrxInstaller to finish. Used by InstallCRX. | 651 // Wait for a CrxInstaller to finish. Used by InstallCRX. |
651 // Returns an Extension pointer if the install succeeded, NULL otherwise. | 652 // Returns an Extension pointer if the install succeeded, NULL otherwise. |
652 const Extension* WaitForCrxInstall(const FilePath& path, | 653 const Extension* WaitForCrxInstall(const FilePath& path, |
653 InstallState install_state) { | 654 InstallState install_state) { |
654 loop_.RunAllPending(); | 655 loop_.RunAllPending(); |
655 std::vector<std::string> errors = GetErrors(); | 656 std::vector<string16> errors = GetErrors(); |
656 const Extension* extension = NULL; | 657 const Extension* extension = NULL; |
657 if (install_state != INSTALL_FAILED) { | 658 if (install_state != INSTALL_FAILED) { |
658 if (install_state == INSTALL_NEW) | 659 if (install_state == INSTALL_NEW) |
659 ++expected_extensions_count_; | 660 ++expected_extensions_count_; |
660 | 661 |
661 EXPECT_TRUE(installed_) << path.value(); | 662 EXPECT_TRUE(installed_) << path.value(); |
662 | 663 |
663 EXPECT_EQ(1u, loaded_.size()) << path.value(); | 664 EXPECT_EQ(1u, loaded_.size()) << path.value(); |
664 EXPECT_EQ(0u, errors.size()) << path.value(); | 665 EXPECT_EQ(0u, errors.size()) << path.value(); |
665 EXPECT_EQ(expected_extensions_count_, service_->extensions()->size()) << | 666 EXPECT_EQ(expected_extensions_count_, service_->extensions()->size()) << |
666 path.value(); | 667 path.value(); |
667 extension = loaded_[0]; | 668 extension = loaded_[0]; |
668 EXPECT_TRUE(service_->GetExtensionById(extension->id(), false)) << | 669 EXPECT_TRUE(service_->GetExtensionById(extension->id(), false)) << |
669 path.value(); | 670 path.value(); |
670 for (std::vector<std::string>::iterator err = errors.begin(); | 671 for (std::vector<string16>::iterator err = errors.begin(); |
671 err != errors.end(); ++err) { | 672 err != errors.end(); ++err) { |
672 LOG(ERROR) << *err; | 673 LOG(ERROR) << *err; |
673 } | 674 } |
674 } else { | 675 } else { |
675 EXPECT_FALSE(installed_) << path.value(); | 676 EXPECT_FALSE(installed_) << path.value(); |
676 EXPECT_EQ(0u, loaded_.size()) << path.value(); | 677 EXPECT_EQ(0u, loaded_.size()) << path.value(); |
677 EXPECT_EQ(1u, errors.size()) << path.value(); | 678 EXPECT_EQ(1u, errors.size()) << path.value(); |
678 } | 679 } |
679 | 680 |
680 installed_ = NULL; | 681 installed_ = NULL; |
(...skipping 22 matching lines...) Expand all Loading... |
703 | 704 |
704 int previous_enabled_extension_count = | 705 int previous_enabled_extension_count = |
705 service_->extensions()->size(); | 706 service_->extensions()->size(); |
706 int previous_installed_extension_count = | 707 int previous_installed_extension_count = |
707 previous_enabled_extension_count + | 708 previous_enabled_extension_count + |
708 service_->disabled_extensions()->size(); | 709 service_->disabled_extensions()->size(); |
709 | 710 |
710 service_->UpdateExtension(id, path, GURL(), NULL); | 711 service_->UpdateExtension(id, path, GURL(), NULL); |
711 loop_.RunAllPending(); | 712 loop_.RunAllPending(); |
712 | 713 |
713 std::vector<std::string> errors = GetErrors(); | 714 std::vector<string16> errors = GetErrors(); |
714 int error_count = errors.size(); | 715 int error_count = errors.size(); |
715 int enabled_extension_count = | 716 int enabled_extension_count = |
716 service_->extensions()->size(); | 717 service_->extensions()->size(); |
717 int installed_extension_count = | 718 int installed_extension_count = |
718 enabled_extension_count + service_->disabled_extensions()->size(); | 719 enabled_extension_count + service_->disabled_extensions()->size(); |
719 | 720 |
720 int expected_error_count = (expected_state == FAILED) ? 1 : 0; | 721 int expected_error_count = (expected_state == FAILED) ? 1 : 0; |
721 EXPECT_EQ(expected_error_count, error_count) << path.value(); | 722 EXPECT_EQ(expected_error_count, error_count) << path.value(); |
722 | 723 |
723 if (expected_state <= FAILED) { | 724 if (expected_state <= FAILED) { |
(...skipping 398 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1122 .DirName() | 1123 .DirName() |
1123 .AppendASCII("Preferences"); | 1124 .AppendASCII("Preferences"); |
1124 | 1125 |
1125 InitializeInstalledExtensionService(pref_path, source_install_dir); | 1126 InitializeInstalledExtensionService(pref_path, source_install_dir); |
1126 | 1127 |
1127 service_->Init(); | 1128 service_->Init(); |
1128 | 1129 |
1129 ASSERT_EQ(4u, GetErrors().size()); | 1130 ASSERT_EQ(4u, GetErrors().size()); |
1130 ASSERT_EQ(0u, loaded_.size()); | 1131 ASSERT_EQ(0u, loaded_.size()); |
1131 | 1132 |
1132 EXPECT_TRUE(MatchPattern(GetErrors()[0], | 1133 EXPECT_TRUE(MatchPattern(UTF16ToUTF8(GetErrors()[0]), |
1133 std::string("Could not load extension from '*'. ") + | 1134 std::string("Could not load extension from '*'. ") + |
1134 extension_manifest_errors::kManifestUnreadable)) << GetErrors()[0]; | 1135 extension_manifest_errors::kManifestUnreadable)) << |
| 1136 UTF16ToUTF8(GetErrors()[0]); |
1135 | 1137 |
1136 EXPECT_TRUE(MatchPattern(GetErrors()[1], | 1138 EXPECT_TRUE(MatchPattern(UTF16ToUTF8(GetErrors()[1]), |
1137 std::string("Could not load extension from '*'. ") + | 1139 std::string("Could not load extension from '*'. ") + |
1138 extension_manifest_errors::kManifestUnreadable)) << GetErrors()[1]; | 1140 extension_manifest_errors::kManifestUnreadable)) << |
| 1141 UTF16ToUTF8(GetErrors()[1]); |
1139 | 1142 |
1140 EXPECT_TRUE(MatchPattern(GetErrors()[2], | 1143 EXPECT_TRUE(MatchPattern(UTF16ToUTF8(GetErrors()[2]), |
1141 std::string("Could not load extension from '*'. ") + | 1144 std::string("Could not load extension from '*'. ") + |
1142 extension_manifest_errors::kMissingFile)) << GetErrors()[2]; | 1145 extension_manifest_errors::kMissingFile)) << |
| 1146 UTF16ToUTF8(GetErrors()[2]); |
1143 | 1147 |
1144 EXPECT_TRUE(MatchPattern(GetErrors()[3], | 1148 EXPECT_TRUE(MatchPattern(UTF16ToUTF8(GetErrors()[3]), |
1145 std::string("Could not load extension from '*'. ") + | 1149 std::string("Could not load extension from '*'. ") + |
1146 extension_manifest_errors::kManifestUnreadable)) << GetErrors()[3]; | 1150 extension_manifest_errors::kManifestUnreadable)) << |
| 1151 UTF16ToUTF8(GetErrors()[3]); |
1147 }; | 1152 }; |
1148 | 1153 |
1149 // Test that partially deleted extensions are cleaned up during startup | 1154 // Test that partially deleted extensions are cleaned up during startup |
1150 // Test loading bad extensions from the profile directory. | 1155 // Test loading bad extensions from the profile directory. |
1151 TEST_F(ExtensionServiceTest, CleanupOnStartup) { | 1156 TEST_F(ExtensionServiceTest, CleanupOnStartup) { |
1152 PluginService::GetInstance()->Init(); | 1157 PluginService::GetInstance()->Init(); |
1153 | 1158 |
1154 FilePath source_install_dir = data_dir_ | 1159 FilePath source_install_dir = data_dir_ |
1155 .AppendASCII("good") | 1160 .AppendASCII("good") |
1156 .AppendASCII("Extensions"); | 1161 .AppendASCII("Extensions"); |
(...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1412 .AppendASCII("user_script_basic.user.js"); | 1417 .AppendASCII("user_script_basic.user.js"); |
1413 | 1418 |
1414 ASSERT_TRUE(file_util::PathExists(path)); | 1419 ASSERT_TRUE(file_util::PathExists(path)); |
1415 scoped_refptr<CrxInstaller> installer(CrxInstaller::Create(service_, NULL)); | 1420 scoped_refptr<CrxInstaller> installer(CrxInstaller::Create(service_, NULL)); |
1416 installer->set_allow_silent_install(true); | 1421 installer->set_allow_silent_install(true); |
1417 installer->InstallUserScript( | 1422 installer->InstallUserScript( |
1418 path, | 1423 path, |
1419 GURL("http://www.aaronboodman.com/scripts/user_script_basic.user.js")); | 1424 GURL("http://www.aaronboodman.com/scripts/user_script_basic.user.js")); |
1420 | 1425 |
1421 loop_.RunAllPending(); | 1426 loop_.RunAllPending(); |
1422 std::vector<std::string> errors = GetErrors(); | 1427 std::vector<string16> errors = GetErrors(); |
1423 EXPECT_TRUE(installed_) << "Nothing was installed."; | 1428 EXPECT_TRUE(installed_) << "Nothing was installed."; |
1424 ASSERT_EQ(1u, loaded_.size()) << "Nothing was loaded."; | 1429 ASSERT_EQ(1u, loaded_.size()) << "Nothing was loaded."; |
1425 EXPECT_EQ(0u, errors.size()) << "There were errors: " | 1430 EXPECT_EQ(0u, errors.size()) << "There were errors: " |
1426 << JoinString(errors, ','); | 1431 << JoinString(errors, ','); |
1427 EXPECT_TRUE(service_->GetExtensionById(loaded_[0]->id(), false)) << | 1432 EXPECT_TRUE(service_->GetExtensionById(loaded_[0]->id(), false)) << |
1428 path.value(); | 1433 path.value(); |
1429 | 1434 |
1430 installed_ = NULL; | 1435 installed_ = NULL; |
1431 loaded_.clear(); | 1436 loaded_.clear(); |
1432 ExtensionErrorReporter::GetInstance()->ClearErrors(); | 1437 ExtensionErrorReporter::GetInstance()->ClearErrors(); |
(...skipping 1083 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2516 blacklist.push_back(good1); | 2521 blacklist.push_back(good1); |
2517 service_->UpdateExtensionBlacklist(blacklist); | 2522 service_->UpdateExtensionBlacklist(blacklist); |
2518 // Make sure pref is updated | 2523 // Make sure pref is updated |
2519 loop_.RunAllPending(); | 2524 loop_.RunAllPending(); |
2520 | 2525 |
2521 ValidateBooleanPref(good1, "blacklist", true); | 2526 ValidateBooleanPref(good1, "blacklist", true); |
2522 | 2527 |
2523 // Load extensions. | 2528 // Load extensions. |
2524 service_->Init(); | 2529 service_->Init(); |
2525 | 2530 |
2526 std::vector<std::string> errors = GetErrors(); | 2531 std::vector<string16> errors = GetErrors(); |
2527 for (std::vector<std::string>::iterator err = errors.begin(); | 2532 for (std::vector<string16>::iterator err = errors.begin(); |
2528 err != errors.end(); ++err) { | 2533 err != errors.end(); ++err) { |
2529 LOG(ERROR) << *err; | 2534 LOG(ERROR) << *err; |
2530 } | 2535 } |
2531 ASSERT_EQ(2u, loaded_.size()); | 2536 ASSERT_EQ(2u, loaded_.size()); |
2532 | 2537 |
2533 EXPECT_FALSE(service_->GetExtensionById(good1, true)); | 2538 EXPECT_FALSE(service_->GetExtensionById(good1, true)); |
2534 } | 2539 } |
2535 | 2540 |
2536 // Will not install extension blacklisted by policy. | 2541 // Will not install extension blacklisted by policy. |
2537 TEST_F(ExtensionServiceTest, BlacklistedByPolicyWillNotInstall) { | 2542 TEST_F(ExtensionServiceTest, BlacklistedByPolicyWillNotInstall) { |
(...skipping 1757 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4295 ASSERT_FALSE(AddPendingSyncInstall()); | 4300 ASSERT_FALSE(AddPendingSyncInstall()); |
4296 | 4301 |
4297 // Wait for the external source to install. | 4302 // Wait for the external source to install. |
4298 WaitForCrxInstall(crx_path_, INSTALL_NEW); | 4303 WaitForCrxInstall(crx_path_, INSTALL_NEW); |
4299 ASSERT_TRUE(IsCrxInstalled()); | 4304 ASSERT_TRUE(IsCrxInstalled()); |
4300 | 4305 |
4301 // Now that the extension is installed, sync request should fail | 4306 // Now that the extension is installed, sync request should fail |
4302 // because the extension is already installed. | 4307 // because the extension is already installed. |
4303 ASSERT_FALSE(AddPendingSyncInstall()); | 4308 ASSERT_FALSE(AddPendingSyncInstall()); |
4304 } | 4309 } |
OLD | NEW |