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