| 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 |
| 11 #include "base/at_exit.h" | |
| 12 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
| 13 #include "base/bind.h" | 12 #include "base/bind.h" |
| 14 #include "base/command_line.h" | 13 #include "base/command_line.h" |
| 15 #include "base/file_util.h" | 14 #include "base/file_util.h" |
| 16 #include "base/json/json_reader.h" | 15 #include "base/json/json_reader.h" |
| 17 #include "base/json/json_value_serializer.h" | 16 #include "base/json/json_value_serializer.h" |
| 18 #include "base/memory/scoped_ptr.h" | 17 #include "base/memory/scoped_ptr.h" |
| 19 #include "base/message_loop.h" | 18 #include "base/message_loop.h" |
| 20 #include "base/path_service.h" | 19 #include "base/path_service.h" |
| 21 #include "base/scoped_temp_dir.h" | 20 #include "base/scoped_temp_dir.h" |
| (...skipping 353 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 375 private: | 374 private: |
| 376 ExtensionService* service_; | 375 ExtensionService* service_; |
| 377 scoped_refptr<ChromeAppCacheService> appcache_service_; | 376 scoped_refptr<ChromeAppCacheService> appcache_service_; |
| 378 scoped_refptr<fileapi::FileSystemContext> file_system_context_; | 377 scoped_refptr<fileapi::FileSystemContext> file_system_context_; |
| 379 }; | 378 }; |
| 380 | 379 |
| 381 // Our message loop may be used in tests which require it to be an IO loop. | 380 // Our message loop may be used in tests which require it to be an IO loop. |
| 382 ExtensionServiceTestBase::ExtensionServiceTestBase() | 381 ExtensionServiceTestBase::ExtensionServiceTestBase() |
| 383 : loop_(MessageLoop::TYPE_IO), | 382 : loop_(MessageLoop::TYPE_IO), |
| 384 service_(NULL), | 383 service_(NULL), |
| 385 total_successes_(0), | 384 expected_extensions_count_(0), |
| 386 ui_thread_(BrowserThread::UI, &loop_), | 385 ui_thread_(BrowserThread::UI, &loop_), |
| 387 db_thread_(BrowserThread::DB, &loop_), | 386 db_thread_(BrowserThread::DB, &loop_), |
| 388 webkit_thread_(BrowserThread::WEBKIT, &loop_), | 387 webkit_thread_(BrowserThread::WEBKIT, &loop_), |
| 389 file_thread_(BrowserThread::FILE, &loop_), | 388 file_thread_(BrowserThread::FILE, &loop_), |
| 390 io_thread_(BrowserThread::IO, &loop_) { | 389 io_thread_(BrowserThread::IO, &loop_) { |
| 391 FilePath test_data_dir; | 390 FilePath test_data_dir; |
| 392 if (!PathService::Get(chrome::DIR_TEST_DATA, &test_data_dir)) { | 391 if (!PathService::Get(chrome::DIR_TEST_DATA, &test_data_dir)) { |
| 393 ADD_FAILURE(); | 392 ADD_FAILURE(); |
| 394 return; | 393 return; |
| 395 } | 394 } |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 428 service_->set_show_extensions_prompts(false); | 427 service_->set_show_extensions_prompts(false); |
| 429 profile->set_extensions_service(service_); | 428 profile->set_extensions_service(service_); |
| 430 | 429 |
| 431 // When we start up, we want to make sure there is no external provider, | 430 // When we start up, we want to make sure there is no external provider, |
| 432 // since the ExtensionService on Windows will use the Registry as a default | 431 // since the ExtensionService on Windows will use the Registry as a default |
| 433 // provider and if there is something already registered there then it will | 432 // provider and if there is something already registered there then it will |
| 434 // interfere with the tests. Those tests that need an external provider | 433 // interfere with the tests. Those tests that need an external provider |
| 435 // will register one specifically. | 434 // will register one specifically. |
| 436 service_->ClearProvidersForTesting(); | 435 service_->ClearProvidersForTesting(); |
| 437 | 436 |
| 438 total_successes_ = 0; | 437 expected_extensions_count_ = 0; |
| 439 } | 438 } |
| 440 | 439 |
| 441 void ExtensionServiceTestBase::InitializeInstalledExtensionService( | 440 void ExtensionServiceTestBase::InitializeInstalledExtensionService( |
| 442 const FilePath& prefs_file, const FilePath& source_install_dir) { | 441 const FilePath& prefs_file, const FilePath& source_install_dir) { |
| 443 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); | 442 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); |
| 444 FilePath path_ = temp_dir_.path(); | 443 FilePath path_ = temp_dir_.path(); |
| 445 path_ = path_.Append(FILE_PATH_LITERAL("TestingExtensionsPath")); | 444 path_ = path_.Append(FILE_PATH_LITERAL("TestingExtensionsPath")); |
| 446 file_util::Delete(path_, true); | 445 file_util::Delete(path_, true); |
| 447 file_util::CreateDirectory(path_); | 446 file_util::CreateDirectory(path_); |
| 448 FilePath temp_prefs = path_.Append(FILE_PATH_LITERAL("Preferences")); | 447 FilePath temp_prefs = path_.Append(FILE_PATH_LITERAL("Preferences")); |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 550 } | 549 } |
| 551 | 550 |
| 552 void AddMockExternalProvider(ExternalExtensionProviderInterface* provider) { | 551 void AddMockExternalProvider(ExternalExtensionProviderInterface* provider) { |
| 553 service_->AddProviderForTesting(provider); | 552 service_->AddProviderForTesting(provider); |
| 554 } | 553 } |
| 555 | 554 |
| 556 protected: | 555 protected: |
| 557 void TestExternalProvider(MockExtensionProvider* provider, | 556 void TestExternalProvider(MockExtensionProvider* provider, |
| 558 Extension::Location location); | 557 Extension::Location location); |
| 559 | 558 |
| 560 void PackAndInstallCrx(const FilePath& dir_path, | 559 void PackCRX(const FilePath& dir_path, |
| 561 const FilePath& pem_path, | 560 const FilePath& pem_path, |
| 562 bool should_succeed) { | 561 const FilePath& crx_path) { |
| 563 FilePath crx_path; | |
| 564 ScopedTempDir temp_dir; | |
| 565 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); | |
| 566 crx_path = temp_dir_.path().AppendASCII("temp.crx"); | |
| 567 | |
| 568 // Use the existing pem key, if provided. | 562 // Use the existing pem key, if provided. |
| 569 FilePath pem_output_path; | 563 FilePath pem_output_path; |
| 570 if (pem_path.value().empty()) { | 564 if (pem_path.value().empty()) { |
| 571 pem_output_path = crx_path.DirName().AppendASCII("temp.pem"); | 565 pem_output_path = crx_path.DirName().AppendASCII("temp.pem"); |
| 572 ASSERT_TRUE(file_util::Delete(pem_output_path, false)); | |
| 573 } else { | 566 } else { |
| 574 ASSERT_TRUE(file_util::PathExists(pem_path)); | 567 ASSERT_TRUE(file_util::PathExists(pem_path)); |
| 575 } | 568 } |
| 576 | 569 |
| 577 ASSERT_TRUE(file_util::Delete(crx_path, false)); | 570 ASSERT_TRUE(file_util::Delete(crx_path, false)); |
| 578 | 571 |
| 579 scoped_ptr<ExtensionCreator> creator(new ExtensionCreator()); | 572 scoped_ptr<ExtensionCreator> creator(new ExtensionCreator()); |
| 580 ASSERT_TRUE(creator->Run(dir_path, | 573 ASSERT_TRUE(creator->Run(dir_path, |
| 581 crx_path, | 574 crx_path, |
| 582 pem_path, | 575 pem_path, |
| 583 pem_output_path)); | 576 pem_output_path)); |
| 584 | 577 |
| 585 ASSERT_TRUE(file_util::PathExists(crx_path)); | 578 ASSERT_TRUE(file_util::PathExists(crx_path)); |
| 586 InstallCrx(crx_path, should_succeed); | |
| 587 } | |
| 588 | |
| 589 void PackAndInstallCrx(const FilePath& dir_path, | |
| 590 bool should_succeed) { | |
| 591 PackAndInstallCrx(dir_path, FilePath(), should_succeed); | |
| 592 } | 579 } |
| 593 | 580 |
| 594 // Create a CrxInstaller and start installation. To allow the install | 581 // Create a CrxInstaller and start installation. To allow the install |
| 595 // to happen, use loop_.RunAllPending();. Most tests will not use this | 582 // to happen, use loop_.RunAllPending();. Most tests will not use this |
| 596 // method directly. Instead, use InstallCrx(), which waits for | 583 // method directly. Instead, use InstallCrx(), which waits for |
| 597 // the crx to be installed and does extra error checking. | 584 // the crx to be installed and does extra error checking. |
| 598 void StartCrxInstall(const FilePath& crx_path) { | 585 void StartCRXInstall(const FilePath& crx_path) { |
| 599 StartCrxInstall(crx_path, false); | 586 StartCRXInstall(crx_path, false); |
| 600 } | 587 } |
| 601 | 588 |
| 602 void StartCrxInstall(const FilePath& crx_path, bool from_webstore) { | 589 void StartCRXInstall(const FilePath& crx_path, bool from_webstore) { |
| 603 ASSERT_TRUE(file_util::PathExists(crx_path)) | 590 ASSERT_TRUE(file_util::PathExists(crx_path)) |
| 604 << "Path does not exist: "<< crx_path.value().c_str(); | 591 << "Path does not exist: "<< crx_path.value().c_str(); |
| 605 scoped_refptr<CrxInstaller> installer(CrxInstaller::Create(service_, NULL)); | 592 scoped_refptr<CrxInstaller> installer(CrxInstaller::Create(service_, NULL)); |
| 606 installer->set_allow_silent_install(true); | 593 installer->set_allow_silent_install(true); |
| 607 installer->set_is_gallery_install(from_webstore); | 594 installer->set_is_gallery_install(from_webstore); |
| 608 installer->InstallCrx(crx_path); | 595 installer->InstallCrx(crx_path); |
| 609 } | 596 } |
| 610 | 597 |
| 611 void InstallCrx(const FilePath& path, | 598 enum InstallState { |
| 612 bool should_succeed) { | 599 INSTALL_FAILED, |
| 613 StartCrxInstall(path); | 600 INSTALL_UPDATED, |
| 614 WaitForCrxInstall(path, should_succeed); | 601 INSTALL_NEW |
| 602 }; |
| 603 |
| 604 const Extension* PackAndInstallCRX(const FilePath& dir_path, |
| 605 const FilePath& pem_path, |
| 606 InstallState install_state) { |
| 607 FilePath crx_path; |
| 608 ScopedTempDir temp_dir; |
| 609 EXPECT_TRUE(temp_dir.CreateUniqueTempDir()); |
| 610 crx_path = temp_dir.path().AppendASCII("temp.crx"); |
| 611 |
| 612 PackCRX(dir_path, pem_path, crx_path); |
| 613 return InstallCRX(crx_path, install_state); |
| 615 } | 614 } |
| 616 | 615 |
| 617 void InstallCrxWithLocation(const FilePath& crx_path, | 616 const Extension* PackAndInstallCRX(const FilePath& dir_path, |
| 618 Extension::Location install_location, | 617 InstallState install_state) { |
| 619 bool should_succeed) { | 618 return PackAndInstallCRX(dir_path, FilePath(), install_state); |
| 620 ASSERT_TRUE(file_util::PathExists(crx_path)) | 619 } |
| 620 |
| 621 const Extension* InstallCRX(const FilePath& path, |
| 622 InstallState install_state) { |
| 623 StartCRXInstall(path); |
| 624 return WaitForCrxInstall(path, install_state); |
| 625 } |
| 626 |
| 627 const Extension* InstallCRXFromWebStore(const FilePath& path, |
| 628 InstallState install_state) { |
| 629 StartCRXInstall(path, true); |
| 630 return WaitForCrxInstall(path, install_state); |
| 631 } |
| 632 |
| 633 const Extension* InstallCRXWithLocation(const FilePath& crx_path, |
| 634 Extension::Location install_location, |
| 635 InstallState install_state) { |
| 636 EXPECT_TRUE(file_util::PathExists(crx_path)) |
| 621 << "Path does not exist: "<< crx_path.value().c_str(); | 637 << "Path does not exist: "<< crx_path.value().c_str(); |
| 622 // no client (silent install) | 638 // no client (silent install) |
| 623 scoped_refptr<CrxInstaller> installer(CrxInstaller::Create(service_, NULL)); | 639 scoped_refptr<CrxInstaller> installer(CrxInstaller::Create(service_, NULL)); |
| 624 | 640 |
| 625 installer->set_install_source(install_location); | 641 installer->set_install_source(install_location); |
| 626 installer->InstallCrx(crx_path); | 642 installer->InstallCrx(crx_path); |
| 627 | 643 |
| 628 WaitForCrxInstall(crx_path, should_succeed); | 644 return WaitForCrxInstall(crx_path, install_state); |
| 629 } | 645 } |
| 630 | 646 |
| 631 // Wait for a CrxInstaller to finish. Used by InstallCrx. | 647 // Wait for a CrxInstaller to finish. Used by InstallCRX. |
| 632 void WaitForCrxInstall(const FilePath& path, | 648 // Returns an Extension pointer if the install succeeded, NULL otherwise. |
| 633 bool should_succeed) { | 649 const Extension* WaitForCrxInstall(const FilePath& path, |
| 650 InstallState install_state) { |
| 634 loop_.RunAllPending(); | 651 loop_.RunAllPending(); |
| 635 std::vector<std::string> errors = GetErrors(); | 652 std::vector<std::string> errors = GetErrors(); |
| 636 if (should_succeed) { | 653 const Extension* extension = NULL; |
| 637 ++total_successes_; | 654 if (install_state != INSTALL_FAILED) { |
| 655 if (install_state == INSTALL_NEW) |
| 656 ++expected_extensions_count_; |
| 638 | 657 |
| 639 EXPECT_TRUE(installed_) << path.value(); | 658 EXPECT_TRUE(installed_) << path.value(); |
| 640 | 659 |
| 641 ASSERT_EQ(1u, loaded_.size()) << path.value(); | 660 EXPECT_EQ(1u, loaded_.size()) << path.value(); |
| 642 EXPECT_EQ(0u, errors.size()) << path.value(); | 661 EXPECT_EQ(0u, errors.size()) << path.value(); |
| 643 EXPECT_EQ(total_successes_, service_->extensions()->size()) << | 662 EXPECT_EQ(expected_extensions_count_, service_->extensions()->size()) << |
| 644 path.value(); | 663 path.value(); |
| 645 EXPECT_TRUE(service_->GetExtensionById(loaded_[0]->id(), false)) << | 664 extension = loaded_[0]; |
| 665 EXPECT_TRUE(service_->GetExtensionById(extension->id(), false)) << |
| 646 path.value(); | 666 path.value(); |
| 647 for (std::vector<std::string>::iterator err = errors.begin(); | 667 for (std::vector<std::string>::iterator err = errors.begin(); |
| 648 err != errors.end(); ++err) { | 668 err != errors.end(); ++err) { |
| 649 LOG(ERROR) << *err; | 669 LOG(ERROR) << *err; |
| 650 } | 670 } |
| 651 } else { | 671 } else { |
| 652 EXPECT_FALSE(installed_) << path.value(); | 672 EXPECT_FALSE(installed_) << path.value(); |
| 653 EXPECT_EQ(0u, loaded_.size()) << path.value(); | 673 EXPECT_EQ(0u, loaded_.size()) << path.value(); |
| 654 EXPECT_EQ(1u, errors.size()) << path.value(); | 674 EXPECT_EQ(1u, errors.size()) << path.value(); |
| 655 } | 675 } |
| 656 | 676 |
| 657 installed_ = NULL; | 677 installed_ = NULL; |
| 658 loaded_.clear(); | 678 loaded_.clear(); |
| 659 ExtensionErrorReporter::GetInstance()->ClearErrors(); | 679 ExtensionErrorReporter::GetInstance()->ClearErrors(); |
| 680 return extension; |
| 660 } | 681 } |
| 661 | 682 |
| 662 enum UpdateState { | 683 enum UpdateState { |
| 663 FAILED_SILENTLY, | 684 FAILED_SILENTLY, |
| 664 FAILED, | 685 FAILED, |
| 665 UPDATED, | 686 UPDATED, |
| 666 INSTALLED, | 687 INSTALLED, |
| 667 ENABLED | 688 ENABLED |
| 668 }; | 689 }; |
| 669 | 690 |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 742 size_t pref_key_count = GetPrefKeyCount(); | 763 size_t pref_key_count = GetPrefKeyCount(); |
| 743 EXPECT_GT(pref_key_count, 0u); | 764 EXPECT_GT(pref_key_count, 0u); |
| 744 ValidateIntegerPref(id, "state", Extension::ENABLED); | 765 ValidateIntegerPref(id, "state", Extension::ENABLED); |
| 745 | 766 |
| 746 // Uninstall it. | 767 // Uninstall it. |
| 747 if (use_helper) { | 768 if (use_helper) { |
| 748 EXPECT_TRUE(ExtensionService::UninstallExtensionHelper(service_, id)); | 769 EXPECT_TRUE(ExtensionService::UninstallExtensionHelper(service_, id)); |
| 749 } else { | 770 } else { |
| 750 EXPECT_TRUE(service_->UninstallExtension(id, false, NULL)); | 771 EXPECT_TRUE(service_->UninstallExtension(id, false, NULL)); |
| 751 } | 772 } |
| 752 total_successes_ = 0; | 773 --expected_extensions_count_; |
| 753 | 774 |
| 754 // We should get an unload notification. | 775 // We should get an unload notification. |
| 755 EXPECT_FALSE(unloaded_id_.empty()); | 776 EXPECT_FALSE(unloaded_id_.empty()); |
| 756 EXPECT_EQ(id, unloaded_id_); | 777 EXPECT_EQ(id, unloaded_id_); |
| 757 | 778 |
| 758 // Verify uninstalled state. | 779 // Verify uninstalled state. |
| 759 size_t new_pref_key_count = GetPrefKeyCount(); | 780 size_t new_pref_key_count = GetPrefKeyCount(); |
| 760 if (new_pref_key_count == pref_key_count) { | 781 if (new_pref_key_count == pref_key_count) { |
| 761 ValidateIntegerPref(id, "location", | 782 ValidateIntegerPref(id, "location", |
| 762 Extension::EXTERNAL_EXTENSION_UNINSTALLED); | 783 Extension::EXTERNAL_EXTENSION_UNINSTALLED); |
| (...skipping 331 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1094 FilePath source_install_dir = data_dir_ | 1115 FilePath source_install_dir = data_dir_ |
| 1095 .AppendASCII("bad") | 1116 .AppendASCII("bad") |
| 1096 .AppendASCII("Extensions"); | 1117 .AppendASCII("Extensions"); |
| 1097 FilePath pref_path = source_install_dir | 1118 FilePath pref_path = source_install_dir |
| 1098 .DirName() | 1119 .DirName() |
| 1099 .AppendASCII("Preferences"); | 1120 .AppendASCII("Preferences"); |
| 1100 | 1121 |
| 1101 InitializeInstalledExtensionService(pref_path, source_install_dir); | 1122 InitializeInstalledExtensionService(pref_path, source_install_dir); |
| 1102 | 1123 |
| 1103 service_->Init(); | 1124 service_->Init(); |
| 1104 loop_.RunAllPending(); | |
| 1105 | 1125 |
| 1106 ASSERT_EQ(4u, GetErrors().size()); | 1126 ASSERT_EQ(4u, GetErrors().size()); |
| 1107 ASSERT_EQ(0u, loaded_.size()); | 1127 ASSERT_EQ(0u, loaded_.size()); |
| 1108 | 1128 |
| 1109 EXPECT_TRUE(MatchPattern(GetErrors()[0], | 1129 EXPECT_TRUE(MatchPattern(GetErrors()[0], |
| 1110 std::string("Could not load extension from '*'. ") + | 1130 std::string("Could not load extension from '*'. ") + |
| 1111 extension_manifest_errors::kManifestUnreadable)) << GetErrors()[0]; | 1131 extension_manifest_errors::kManifestUnreadable)) << GetErrors()[0]; |
| 1112 | 1132 |
| 1113 EXPECT_TRUE(MatchPattern(GetErrors()[1], | 1133 EXPECT_TRUE(MatchPattern(GetErrors()[1], |
| 1114 std::string("Could not load extension from '*'. ") + | 1134 std::string("Could not load extension from '*'. ") + |
| (...skipping 24 matching lines...) Expand all Loading... |
| 1139 | 1159 |
| 1140 // Simulate that one of them got partially deleted by clearing its pref. | 1160 // Simulate that one of them got partially deleted by clearing its pref. |
| 1141 { | 1161 { |
| 1142 DictionaryPrefUpdate update(profile_->GetPrefs(), "extensions.settings"); | 1162 DictionaryPrefUpdate update(profile_->GetPrefs(), "extensions.settings"); |
| 1143 DictionaryValue* dict = update.Get(); | 1163 DictionaryValue* dict = update.Get(); |
| 1144 ASSERT_TRUE(dict != NULL); | 1164 ASSERT_TRUE(dict != NULL); |
| 1145 dict->Remove("behllobkkfkfnphdnhnkndlbkcpglgmj", NULL); | 1165 dict->Remove("behllobkkfkfnphdnhnkndlbkcpglgmj", NULL); |
| 1146 } | 1166 } |
| 1147 | 1167 |
| 1148 service_->Init(); | 1168 service_->Init(); |
| 1169 // Wait for GarbageCollectExtensions task to complete. |
| 1149 loop_.RunAllPending(); | 1170 loop_.RunAllPending(); |
| 1150 | 1171 |
| 1151 file_util::FileEnumerator dirs(extensions_install_dir_, false, | 1172 file_util::FileEnumerator dirs(extensions_install_dir_, false, |
| 1152 file_util::FileEnumerator::DIRECTORIES); | 1173 file_util::FileEnumerator::DIRECTORIES); |
| 1153 size_t count = 0; | 1174 size_t count = 0; |
| 1154 while (!dirs.Next().empty()) | 1175 while (!dirs.Next().empty()) |
| 1155 count++; | 1176 count++; |
| 1156 | 1177 |
| 1157 // We should have only gotten two extensions now. | 1178 // We should have only gotten two extensions now. |
| 1158 EXPECT_EQ(2u, count); | 1179 EXPECT_EQ(2u, count); |
| 1159 | 1180 |
| 1160 // And extension1 dir should now be toast. | 1181 // And extension1 dir should now be toast. |
| 1161 FilePath extension_dir = extensions_install_dir_ | 1182 FilePath extension_dir = extensions_install_dir_ |
| 1162 .AppendASCII("behllobkkfkfnphdnhnkndlbkcpglgmj"); | 1183 .AppendASCII("behllobkkfkfnphdnhnkndlbkcpglgmj"); |
| 1163 ASSERT_FALSE(file_util::PathExists(extension_dir)); | 1184 ASSERT_FALSE(file_util::PathExists(extension_dir)); |
| 1164 } | 1185 } |
| 1165 | 1186 |
| 1166 // Test installing extensions. This test tries to install few extensions using | 1187 // Test installing extensions. This test tries to install few extensions using |
| 1167 // crx files. If you need to change those crx files, feel free to repackage | 1188 // crx files. If you need to change those crx files, feel free to repackage |
| 1168 // them, throw away the key used and change the id's above. | 1189 // them, throw away the key used and change the id's above. |
| 1169 TEST_F(ExtensionServiceTest, InstallExtension) { | 1190 TEST_F(ExtensionServiceTest, InstallExtension) { |
| 1170 InitializeEmptyExtensionService(); | 1191 InitializeEmptyExtensionService(); |
| 1171 | 1192 |
| 1172 // Extensions not enabled. | 1193 // Extensions not enabled. |
| 1173 set_extensions_enabled(false); | 1194 set_extensions_enabled(false); |
| 1174 FilePath path = data_dir_.AppendASCII("good.crx"); | 1195 FilePath path = data_dir_.AppendASCII("good.crx"); |
| 1175 InstallCrx(path, false); | 1196 InstallCRX(path, INSTALL_FAILED); |
| 1176 set_extensions_enabled(true); | 1197 set_extensions_enabled(true); |
| 1177 | 1198 |
| 1178 ValidatePrefKeyCount(0); | 1199 ValidatePrefKeyCount(0); |
| 1179 | 1200 |
| 1180 // A simple extension that should install without error. | 1201 // A simple extension that should install without error. |
| 1181 path = data_dir_.AppendASCII("good.crx"); | 1202 path = data_dir_.AppendASCII("good.crx"); |
| 1182 InstallCrx(path, true); | 1203 InstallCRX(path, INSTALL_NEW); |
| 1183 // TODO(erikkay): verify the contents of the installed extension. | 1204 // TODO(erikkay): verify the contents of the installed extension. |
| 1184 | 1205 |
| 1185 int pref_count = 0; | 1206 int pref_count = 0; |
| 1186 ValidatePrefKeyCount(++pref_count); | 1207 ValidatePrefKeyCount(++pref_count); |
| 1187 ValidateIntegerPref(good_crx, "state", Extension::ENABLED); | 1208 ValidateIntegerPref(good_crx, "state", Extension::ENABLED); |
| 1188 ValidateIntegerPref(good_crx, "location", Extension::INTERNAL); | 1209 ValidateIntegerPref(good_crx, "location", Extension::INTERNAL); |
| 1189 | 1210 |
| 1190 // An extension with page actions. | 1211 // An extension with page actions. |
| 1191 path = data_dir_.AppendASCII("page_action.crx"); | 1212 path = data_dir_.AppendASCII("page_action.crx"); |
| 1192 InstallCrx(path, true); | 1213 InstallCRX(path, INSTALL_NEW); |
| 1193 ValidatePrefKeyCount(++pref_count); | 1214 ValidatePrefKeyCount(++pref_count); |
| 1194 ValidateIntegerPref(page_action, "state", Extension::ENABLED); | 1215 ValidateIntegerPref(page_action, "state", Extension::ENABLED); |
| 1195 ValidateIntegerPref(page_action, "location", Extension::INTERNAL); | 1216 ValidateIntegerPref(page_action, "location", Extension::INTERNAL); |
| 1196 | 1217 |
| 1197 // Bad signature. | 1218 // Bad signature. |
| 1198 path = data_dir_.AppendASCII("bad_signature.crx"); | 1219 path = data_dir_.AppendASCII("bad_signature.crx"); |
| 1199 InstallCrx(path, false); | 1220 InstallCRX(path, INSTALL_FAILED); |
| 1200 ValidatePrefKeyCount(pref_count); | 1221 ValidatePrefKeyCount(pref_count); |
| 1201 | 1222 |
| 1202 // 0-length extension file. | 1223 // 0-length extension file. |
| 1203 path = data_dir_.AppendASCII("not_an_extension.crx"); | 1224 path = data_dir_.AppendASCII("not_an_extension.crx"); |
| 1204 InstallCrx(path, false); | 1225 InstallCRX(path, INSTALL_FAILED); |
| 1205 ValidatePrefKeyCount(pref_count); | 1226 ValidatePrefKeyCount(pref_count); |
| 1206 | 1227 |
| 1207 // Bad magic number. | 1228 // Bad magic number. |
| 1208 path = data_dir_.AppendASCII("bad_magic.crx"); | 1229 path = data_dir_.AppendASCII("bad_magic.crx"); |
| 1209 InstallCrx(path, false); | 1230 InstallCRX(path, INSTALL_FAILED); |
| 1210 ValidatePrefKeyCount(pref_count); | 1231 ValidatePrefKeyCount(pref_count); |
| 1211 | 1232 |
| 1212 // Extensions cannot have folders or files that have underscores except in | 1233 // Extensions cannot have folders or files that have underscores except in |
| 1213 // certain whitelisted cases (eg _locales). This is an example of a broader | 1234 // certain whitelisted cases (eg _locales). This is an example of a broader |
| 1214 // class of validation that we do to the directory structure of the extension. | 1235 // class of validation that we do to the directory structure of the extension. |
| 1215 // We did not used to handle this correctly for installation. | 1236 // We did not used to handle this correctly for installation. |
| 1216 path = data_dir_.AppendASCII("bad_underscore.crx"); | 1237 path = data_dir_.AppendASCII("bad_underscore.crx"); |
| 1217 InstallCrx(path, false); | 1238 InstallCRX(path, INSTALL_FAILED); |
| 1218 ValidatePrefKeyCount(pref_count); | 1239 ValidatePrefKeyCount(pref_count); |
| 1219 | 1240 |
| 1220 // TODO(erikkay): add more tests for many of the failure cases. | 1241 // TODO(erikkay): add more tests for many of the failure cases. |
| 1221 // TODO(erikkay): add tests for upgrade cases. | 1242 // TODO(erikkay): add tests for upgrade cases. |
| 1222 } | 1243 } |
| 1223 | 1244 |
| 1224 // Tests that flags passed to OnExternalExtensionFileFound() make it to the | 1245 // Tests that flags passed to OnExternalExtensionFileFound() make it to the |
| 1225 // extension object. | 1246 // extension object. |
| 1226 TEST_F(ExtensionServiceTest, InstallingExternalExtensionWithFlags) { | 1247 TEST_F(ExtensionServiceTest, InstallingExternalExtensionWithFlags) { |
| 1227 InitializeEmptyExtensionService(); | 1248 InitializeEmptyExtensionService(); |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1305 // that requires 'experimental' permission. | 1326 // that requires 'experimental' permission. |
| 1306 FilePath pref_path = source_install_dir | 1327 FilePath pref_path = source_install_dir |
| 1307 .DirName() | 1328 .DirName() |
| 1308 .AppendASCII("PreferencesExperimental"); | 1329 .AppendASCII("PreferencesExperimental"); |
| 1309 | 1330 |
| 1310 // Aforementioned extension will not be loaded if | 1331 // Aforementioned extension will not be loaded if |
| 1311 // there is no '--enable-experimental-extension-apis' command line flag. | 1332 // there is no '--enable-experimental-extension-apis' command line flag. |
| 1312 InitializeInstalledExtensionService(pref_path, source_install_dir); | 1333 InitializeInstalledExtensionService(pref_path, source_install_dir); |
| 1313 | 1334 |
| 1314 service_->Init(); | 1335 service_->Init(); |
| 1315 loop_.RunAllPending(); | |
| 1316 | 1336 |
| 1317 // Check and try to uninstall it. | 1337 // Check and try to uninstall it. |
| 1318 // If we don't check whether the extension is loaded before we uninstall it | 1338 // If we don't check whether the extension is loaded before we uninstall it |
| 1319 // in CheckExternalUninstall, a crash will happen here because we will get or | 1339 // in CheckExternalUninstall, a crash will happen here because we will get or |
| 1320 // dereference a NULL pointer (extension) inside UninstallExtension. | 1340 // dereference a NULL pointer (extension) inside UninstallExtension. |
| 1321 MockExtensionProvider provider(NULL, Extension::EXTERNAL_REGISTRY); | 1341 MockExtensionProvider provider(NULL, Extension::EXTERNAL_REGISTRY); |
| 1322 service_->OnExternalProviderReady(&provider); | 1342 service_->OnExternalProviderReady(&provider); |
| 1323 } | 1343 } |
| 1324 | 1344 |
| 1325 // Test that external extensions with incorrect IDs are not installed. | 1345 // Test that external extensions with incorrect IDs are not installed. |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1426 | 1446 |
| 1427 ExtensionAPIPermissionSet expected_api_perms; | 1447 ExtensionAPIPermissionSet expected_api_perms; |
| 1428 URLPatternSet expected_host_perms; | 1448 URLPatternSet expected_host_perms; |
| 1429 | 1449 |
| 1430 // Make sure there aren't any granted permissions before the | 1450 // Make sure there aren't any granted permissions before the |
| 1431 // extension is installed. | 1451 // extension is installed. |
| 1432 scoped_refptr<ExtensionPermissionSet> known_perms( | 1452 scoped_refptr<ExtensionPermissionSet> known_perms( |
| 1433 prefs->GetGrantedPermissions(permissions_crx)); | 1453 prefs->GetGrantedPermissions(permissions_crx)); |
| 1434 EXPECT_FALSE(known_perms.get()); | 1454 EXPECT_FALSE(known_perms.get()); |
| 1435 | 1455 |
| 1436 PackAndInstallCrx(path, pem_path, true); | 1456 const Extension* extension = PackAndInstallCRX(path, pem_path, INSTALL_NEW); |
| 1437 | 1457 |
| 1438 EXPECT_EQ(0u, GetErrors().size()); | 1458 EXPECT_EQ(0u, GetErrors().size()); |
| 1439 ASSERT_EQ(1u, service_->extensions()->size()); | 1459 ASSERT_EQ(1u, service_->extensions()->size()); |
| 1440 std::string extension_id = service_->extensions()->at(0)->id(); | 1460 EXPECT_EQ(permissions_crx, extension->id()); |
| 1441 EXPECT_EQ(permissions_crx, extension_id); | |
| 1442 | 1461 |
| 1443 // Verify that the valid API permissions have been recognized. | 1462 // Verify that the valid API permissions have been recognized. |
| 1444 expected_api_perms.insert(ExtensionAPIPermission::kTab); | 1463 expected_api_perms.insert(ExtensionAPIPermission::kTab); |
| 1445 | 1464 |
| 1446 AddPattern(&expected_host_perms, "http://*.google.com/*"); | 1465 AddPattern(&expected_host_perms, "http://*.google.com/*"); |
| 1447 AddPattern(&expected_host_perms, "https://*.google.com/*"); | 1466 AddPattern(&expected_host_perms, "https://*.google.com/*"); |
| 1448 AddPattern(&expected_host_perms, "http://*.google.com.hk/*"); | 1467 AddPattern(&expected_host_perms, "http://*.google.com.hk/*"); |
| 1449 AddPattern(&expected_host_perms, "http://www.example.com/*"); | 1468 AddPattern(&expected_host_perms, "http://www.example.com/*"); |
| 1450 | 1469 |
| 1451 known_perms = prefs->GetGrantedPermissions(extension_id); | 1470 known_perms = prefs->GetGrantedPermissions(extension->id()); |
| 1452 EXPECT_TRUE(known_perms.get()); | 1471 EXPECT_TRUE(known_perms.get()); |
| 1453 EXPECT_FALSE(known_perms->IsEmpty()); | 1472 EXPECT_FALSE(known_perms->IsEmpty()); |
| 1454 EXPECT_EQ(expected_api_perms, known_perms->apis()); | 1473 EXPECT_EQ(expected_api_perms, known_perms->apis()); |
| 1455 EXPECT_FALSE(known_perms->HasEffectiveFullAccess()); | 1474 EXPECT_FALSE(known_perms->HasEffectiveFullAccess()); |
| 1456 EXPECT_EQ(expected_host_perms, known_perms->effective_hosts()); | 1475 EXPECT_EQ(expected_host_perms, known_perms->effective_hosts()); |
| 1457 } | 1476 } |
| 1458 | 1477 |
| 1459 #if !defined(OS_CHROMEOS) | 1478 #if !defined(OS_CHROMEOS) |
| 1460 // Tests that the granted permissions full_access bit gets set correctly when | 1479 // Tests that the granted permissions full_access bit gets set correctly when |
| 1461 // an extension contains an NPAPI plugin. Don't run this test on Chrome OS | 1480 // an extension contains an NPAPI plugin. Don't run this test on Chrome OS |
| 1462 // since they don't support plugins. | 1481 // since they don't support plugins. |
| 1463 TEST_F(ExtensionServiceTest, GrantedFullAccessPermissions) { | 1482 TEST_F(ExtensionServiceTest, GrantedFullAccessPermissions) { |
| 1464 PluginService::GetInstance()->Init(); | 1483 PluginService::GetInstance()->Init(); |
| 1465 | 1484 |
| 1466 InitializeEmptyExtensionService(); | 1485 InitializeEmptyExtensionService(); |
| 1467 | 1486 |
| 1468 FilePath path = data_dir_ | 1487 FilePath path = data_dir_ |
| 1469 .AppendASCII("good") | 1488 .AppendASCII("good") |
| 1470 .AppendASCII("Extensions") | 1489 .AppendASCII("Extensions") |
| 1471 .AppendASCII(good1) | 1490 .AppendASCII(good1) |
| 1472 .AppendASCII("2"); | 1491 .AppendASCII("2"); |
| 1473 | 1492 |
| 1474 ASSERT_TRUE(file_util::PathExists(path)); | 1493 ASSERT_TRUE(file_util::PathExists(path)); |
| 1475 PackAndInstallCrx(path, true); | 1494 const Extension* extension = PackAndInstallCRX(path, INSTALL_NEW); |
| 1476 EXPECT_EQ(0u, GetErrors().size()); | 1495 EXPECT_EQ(0u, GetErrors().size()); |
| 1477 EXPECT_EQ(1u, service_->extensions()->size()); | 1496 EXPECT_EQ(1u, service_->extensions()->size()); |
| 1478 const Extension* extension = service_->extensions()->at(0); | |
| 1479 std::string extension_id = extension->id(); | |
| 1480 ExtensionPrefs* prefs = service_->extension_prefs(); | 1497 ExtensionPrefs* prefs = service_->extension_prefs(); |
| 1481 | 1498 |
| 1482 scoped_refptr<ExtensionPermissionSet> permissions( | 1499 scoped_refptr<ExtensionPermissionSet> permissions( |
| 1483 prefs->GetGrantedPermissions(extension_id)); | 1500 prefs->GetGrantedPermissions(extension->id())); |
| 1484 EXPECT_FALSE(permissions->IsEmpty()); | 1501 EXPECT_FALSE(permissions->IsEmpty()); |
| 1485 EXPECT_TRUE(permissions->HasEffectiveFullAccess()); | 1502 EXPECT_TRUE(permissions->HasEffectiveFullAccess()); |
| 1486 EXPECT_FALSE(permissions->apis().empty()); | 1503 EXPECT_FALSE(permissions->apis().empty()); |
| 1487 EXPECT_TRUE(permissions->HasAPIPermission(ExtensionAPIPermission::kPlugin)); | 1504 EXPECT_TRUE(permissions->HasAPIPermission(ExtensionAPIPermission::kPlugin)); |
| 1488 | 1505 |
| 1489 // Full access implies full host access too... | 1506 // Full access implies full host access too... |
| 1490 EXPECT_TRUE(permissions->HasEffectiveAccessToAllHosts()); | 1507 EXPECT_TRUE(permissions->HasEffectiveAccessToAllHosts()); |
| 1491 } | 1508 } |
| 1492 #endif | 1509 #endif |
| 1493 | 1510 |
| 1494 // Tests that the extension is disabled when permissions are missing from | 1511 // Tests that the extension is disabled when permissions are missing from |
| 1495 // the extension's granted permissions preferences. (This simulates updating | 1512 // the extension's granted permissions preferences. (This simulates updating |
| 1496 // the browser to a version which recognizes more permissions). | 1513 // the browser to a version which recognizes more permissions). |
| 1497 TEST_F(ExtensionServiceTest, GrantedAPIAndHostPermissions) { | 1514 TEST_F(ExtensionServiceTest, GrantedAPIAndHostPermissions) { |
| 1498 InitializeEmptyExtensionService(); | 1515 InitializeEmptyExtensionService(); |
| 1499 | 1516 |
| 1500 FilePath path = data_dir_ | 1517 FilePath path = data_dir_ |
| 1501 .AppendASCII("permissions") | 1518 .AppendASCII("permissions") |
| 1502 .AppendASCII("unknown"); | 1519 .AppendASCII("unknown"); |
| 1503 | 1520 |
| 1504 ASSERT_TRUE(file_util::PathExists(path)); | 1521 ASSERT_TRUE(file_util::PathExists(path)); |
| 1505 | 1522 |
| 1506 PackAndInstallCrx(path, true); | 1523 const Extension* extension = PackAndInstallCRX(path, INSTALL_NEW); |
| 1507 | 1524 |
| 1508 EXPECT_EQ(0u, GetErrors().size()); | 1525 EXPECT_EQ(0u, GetErrors().size()); |
| 1509 EXPECT_EQ(1u, service_->extensions()->size()); | 1526 EXPECT_EQ(1u, service_->extensions()->size()); |
| 1510 const Extension* extension = service_->extensions()->at(0); | |
| 1511 std::string extension_id = extension->id(); | 1527 std::string extension_id = extension->id(); |
| 1512 | 1528 |
| 1513 ExtensionPrefs* prefs = service_->extension_prefs(); | 1529 ExtensionPrefs* prefs = service_->extension_prefs(); |
| 1514 | 1530 |
| 1515 ExtensionAPIPermissionSet expected_api_permissions; | 1531 ExtensionAPIPermissionSet expected_api_permissions; |
| 1516 URLPatternSet expected_host_permissions; | 1532 URLPatternSet expected_host_permissions; |
| 1517 | 1533 |
| 1518 expected_api_permissions.insert(ExtensionAPIPermission::kTab); | 1534 expected_api_permissions.insert(ExtensionAPIPermission::kTab); |
| 1519 AddPattern(&expected_host_permissions, "http://*.google.com/*"); | 1535 AddPattern(&expected_host_permissions, "http://*.google.com/*"); |
| 1520 AddPattern(&expected_host_permissions, "https://*.google.com/*"); | 1536 AddPattern(&expected_host_permissions, "https://*.google.com/*"); |
| 1521 AddPattern(&expected_host_permissions, "http://*.google.com.hk/*"); | 1537 AddPattern(&expected_host_permissions, "http://*.google.com.hk/*"); |
| 1522 AddPattern(&expected_host_permissions, "http://www.example.com/*"); | 1538 AddPattern(&expected_host_permissions, "http://www.example.com/*"); |
| 1523 | 1539 |
| 1524 std::set<std::string> host_permissions; | 1540 std::set<std::string> host_permissions; |
| 1525 | 1541 |
| 1526 // Test that the extension is disabled when an API permission is missing from | 1542 // Test that the extension is disabled when an API permission is missing from |
| 1527 // the extension's granted api permissions preference. (This simulates | 1543 // the extension's granted api permissions preference. (This simulates |
| 1528 // updating the browser to a version which recognizes a new API permission). | 1544 // updating the browser to a version which recognizes a new API permission). |
| 1529 SetPref(extension_id, "granted_permissions.api", | 1545 SetPref(extension_id, "granted_permissions.api", |
| 1530 new ListValue(), "granted_permissions.api"); | 1546 new ListValue(), "granted_permissions.api"); |
| 1531 service_->ReloadExtensions(); | 1547 service_->ReloadExtensions(); |
| 1532 | 1548 |
| 1533 EXPECT_EQ(1u, service_->disabled_extensions()->size()); | 1549 EXPECT_EQ(1u, service_->disabled_extensions()->size()); |
| 1534 extension = service_->disabled_extensions()->at(0); | 1550 extension = *service_->disabled_extensions()->begin(); |
| 1535 | 1551 |
| 1536 ASSERT_TRUE(prefs->IsExtensionDisabled(extension_id)); | 1552 ASSERT_TRUE(prefs->IsExtensionDisabled(extension_id)); |
| 1537 ASSERT_FALSE(service_->IsExtensionEnabled(extension_id)); | 1553 ASSERT_FALSE(service_->IsExtensionEnabled(extension_id)); |
| 1538 ASSERT_TRUE(prefs->DidExtensionEscalatePermissions(extension_id)); | 1554 ASSERT_TRUE(prefs->DidExtensionEscalatePermissions(extension_id)); |
| 1539 | 1555 |
| 1540 // Now grant and re-enable the extension, making sure the prefs are updated. | 1556 // Now grant and re-enable the extension, making sure the prefs are updated. |
| 1541 service_->GrantPermissionsAndEnableExtension(extension); | 1557 service_->GrantPermissionsAndEnableExtension(extension); |
| 1542 | 1558 |
| 1543 ASSERT_FALSE(prefs->IsExtensionDisabled(extension_id)); | 1559 ASSERT_FALSE(prefs->IsExtensionDisabled(extension_id)); |
| 1544 ASSERT_TRUE(service_->IsExtensionEnabled(extension_id)); | 1560 ASSERT_TRUE(service_->IsExtensionEnabled(extension_id)); |
| (...skipping 22 matching lines...) Expand all Loading... |
| 1567 api_permissions->Append( | 1583 api_permissions->Append( |
| 1568 Value::CreateIntegerValue(ExtensionAPIPermission::kTab)); | 1584 Value::CreateIntegerValue(ExtensionAPIPermission::kTab)); |
| 1569 SetPref(extension_id, "granted_permissions.api", | 1585 SetPref(extension_id, "granted_permissions.api", |
| 1570 api_permissions, "granted_permissions.api"); | 1586 api_permissions, "granted_permissions.api"); |
| 1571 SetPrefStringSet( | 1587 SetPrefStringSet( |
| 1572 extension_id, "granted_permissions.scriptable_host", host_permissions); | 1588 extension_id, "granted_permissions.scriptable_host", host_permissions); |
| 1573 | 1589 |
| 1574 service_->ReloadExtensions(); | 1590 service_->ReloadExtensions(); |
| 1575 | 1591 |
| 1576 EXPECT_EQ(1u, service_->disabled_extensions()->size()); | 1592 EXPECT_EQ(1u, service_->disabled_extensions()->size()); |
| 1577 extension = service_->disabled_extensions()->at(0); | 1593 extension = *service_->disabled_extensions()->begin(); |
| 1578 | 1594 |
| 1579 ASSERT_TRUE(prefs->IsExtensionDisabled(extension_id)); | 1595 ASSERT_TRUE(prefs->IsExtensionDisabled(extension_id)); |
| 1580 ASSERT_FALSE(service_->IsExtensionEnabled(extension_id)); | 1596 ASSERT_FALSE(service_->IsExtensionEnabled(extension_id)); |
| 1581 ASSERT_TRUE(prefs->DidExtensionEscalatePermissions(extension_id)); | 1597 ASSERT_TRUE(prefs->DidExtensionEscalatePermissions(extension_id)); |
| 1582 | 1598 |
| 1583 // Now grant and re-enable the extension, making sure the prefs are updated. | 1599 // Now grant and re-enable the extension, making sure the prefs are updated. |
| 1584 service_->GrantPermissionsAndEnableExtension(extension); | 1600 service_->GrantPermissionsAndEnableExtension(extension); |
| 1585 | 1601 |
| 1586 ASSERT_TRUE(service_->IsExtensionEnabled(extension_id)); | 1602 ASSERT_TRUE(service_->IsExtensionEnabled(extension_id)); |
| 1587 ASSERT_FALSE(prefs->DidExtensionEscalatePermissions(extension_id)); | 1603 ASSERT_FALSE(prefs->DidExtensionEscalatePermissions(extension_id)); |
| (...skipping 20 matching lines...) Expand all Loading... |
| 1608 FilePath output_directory = temp_dir.path(); | 1624 FilePath output_directory = temp_dir.path(); |
| 1609 | 1625 |
| 1610 FilePath crx_path(output_directory.AppendASCII("ex1.crx")); | 1626 FilePath crx_path(output_directory.AppendASCII("ex1.crx")); |
| 1611 FilePath privkey_path(output_directory.AppendASCII("privkey.pem")); | 1627 FilePath privkey_path(output_directory.AppendASCII("privkey.pem")); |
| 1612 | 1628 |
| 1613 scoped_ptr<ExtensionCreator> creator(new ExtensionCreator()); | 1629 scoped_ptr<ExtensionCreator> creator(new ExtensionCreator()); |
| 1614 ASSERT_TRUE(creator->Run(input_directory, crx_path, FilePath(), | 1630 ASSERT_TRUE(creator->Run(input_directory, crx_path, FilePath(), |
| 1615 privkey_path)); | 1631 privkey_path)); |
| 1616 | 1632 |
| 1617 ASSERT_TRUE(file_util::PathExists(privkey_path)); | 1633 ASSERT_TRUE(file_util::PathExists(privkey_path)); |
| 1618 InstallCrx(crx_path, true); | 1634 InstallCRX(crx_path, INSTALL_NEW); |
| 1619 | 1635 |
| 1620 // Try packing with invalid paths. | 1636 // Try packing with invalid paths. |
| 1621 creator.reset(new ExtensionCreator()); | 1637 creator.reset(new ExtensionCreator()); |
| 1622 ASSERT_FALSE(creator->Run(FilePath(), FilePath(), FilePath(), FilePath())); | 1638 ASSERT_FALSE(creator->Run(FilePath(), FilePath(), FilePath(), FilePath())); |
| 1623 | 1639 |
| 1624 // Try packing an empty directory. Should fail because an empty directory is | 1640 // Try packing an empty directory. Should fail because an empty directory is |
| 1625 // not a valid extension. | 1641 // not a valid extension. |
| 1626 ScopedTempDir temp_dir2; | 1642 ScopedTempDir temp_dir2; |
| 1627 ASSERT_TRUE(temp_dir2.CreateUniqueTempDir()); | 1643 ASSERT_TRUE(temp_dir2.CreateUniqueTempDir()); |
| 1628 creator.reset(new ExtensionCreator()); | 1644 creator.reset(new ExtensionCreator()); |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1699 // The packer will post a notification task to the current thread's message | 1715 // The packer will post a notification task to the current thread's message |
| 1700 // loop when it is finished. We manually run the loop here so that we | 1716 // loop when it is finished. We manually run the loop here so that we |
| 1701 // block and catch the notification; otherwise, the process would exit. | 1717 // block and catch the notification; otherwise, the process would exit. |
| 1702 // This call to |Run()| is matched by a call to |Quit()| in the | 1718 // This call to |Run()| is matched by a call to |Quit()| in the |
| 1703 // |PackExtensionTestClient|'s notification handling code. | 1719 // |PackExtensionTestClient|'s notification handling code. |
| 1704 MessageLoop::current()->Run(); | 1720 MessageLoop::current()->Run(); |
| 1705 | 1721 |
| 1706 if (HasFatalFailure()) | 1722 if (HasFatalFailure()) |
| 1707 return; | 1723 return; |
| 1708 | 1724 |
| 1709 InstallCrx(expected_crx_path, true); | 1725 InstallCRX(expected_crx_path, INSTALL_NEW); |
| 1710 } | 1726 } |
| 1711 } | 1727 } |
| 1712 | 1728 |
| 1713 // Test Packaging and installing an extension using an openssl generated key. | 1729 // Test Packaging and installing an extension using an openssl generated key. |
| 1714 // The openssl is generated with the following: | 1730 // The openssl is generated with the following: |
| 1715 // > openssl genrsa -out privkey.pem 1024 | 1731 // > openssl genrsa -out privkey.pem 1024 |
| 1716 // > openssl pkcs8 -topk8 -nocrypt -in privkey.pem -out privkey_asn1.pem | 1732 // > openssl pkcs8 -topk8 -nocrypt -in privkey.pem -out privkey_asn1.pem |
| 1717 // The privkey.pem is a PrivateKey, and the pcks8 -topk8 creates a | 1733 // The privkey.pem is a PrivateKey, and the pcks8 -topk8 creates a |
| 1718 // PrivateKeyInfo ASN.1 structure, we our RSAPrivateKey expects. | 1734 // PrivateKeyInfo ASN.1 structure, we our RSAPrivateKey expects. |
| 1719 TEST_F(ExtensionServiceTest, PackExtensionOpenSSLKey) { | 1735 TEST_F(ExtensionServiceTest, PackExtensionOpenSSLKey) { |
| (...skipping 10 matching lines...) Expand all Loading... |
| 1730 ScopedTempDir temp_dir; | 1746 ScopedTempDir temp_dir; |
| 1731 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); | 1747 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); |
| 1732 FilePath output_directory = temp_dir.path(); | 1748 FilePath output_directory = temp_dir.path(); |
| 1733 | 1749 |
| 1734 FilePath crx_path(output_directory.AppendASCII("ex1.crx")); | 1750 FilePath crx_path(output_directory.AppendASCII("ex1.crx")); |
| 1735 | 1751 |
| 1736 scoped_ptr<ExtensionCreator> creator(new ExtensionCreator()); | 1752 scoped_ptr<ExtensionCreator> creator(new ExtensionCreator()); |
| 1737 ASSERT_TRUE(creator->Run(input_directory, crx_path, privkey_path, | 1753 ASSERT_TRUE(creator->Run(input_directory, crx_path, privkey_path, |
| 1738 FilePath())); | 1754 FilePath())); |
| 1739 | 1755 |
| 1740 InstallCrx(crx_path, true); | 1756 InstallCRX(crx_path, INSTALL_NEW); |
| 1741 } | 1757 } |
| 1742 | 1758 |
| 1743 TEST_F(ExtensionServiceTest, InstallTheme) { | 1759 TEST_F(ExtensionServiceTest, InstallTheme) { |
| 1744 InitializeEmptyExtensionService(); | 1760 InitializeEmptyExtensionService(); |
| 1745 | 1761 |
| 1746 // A theme. | 1762 // A theme. |
| 1747 FilePath path = data_dir_.AppendASCII("theme.crx"); | 1763 FilePath path = data_dir_.AppendASCII("theme.crx"); |
| 1748 InstallCrx(path, true); | 1764 InstallCRX(path, INSTALL_NEW); |
| 1749 int pref_count = 0; | 1765 int pref_count = 0; |
| 1750 ValidatePrefKeyCount(++pref_count); | 1766 ValidatePrefKeyCount(++pref_count); |
| 1751 ValidateIntegerPref(theme_crx, "state", Extension::ENABLED); | 1767 ValidateIntegerPref(theme_crx, "state", Extension::ENABLED); |
| 1752 ValidateIntegerPref(theme_crx, "location", Extension::INTERNAL); | 1768 ValidateIntegerPref(theme_crx, "location", Extension::INTERNAL); |
| 1753 | 1769 |
| 1754 // A theme when extensions are disabled. Themes can be installed, even when | 1770 // A theme when extensions are disabled. Themes can be installed, even when |
| 1755 // extensions are disabled. | 1771 // extensions are disabled. |
| 1756 set_extensions_enabled(false); | 1772 set_extensions_enabled(false); |
| 1757 path = data_dir_.AppendASCII("theme2.crx"); | 1773 path = data_dir_.AppendASCII("theme2.crx"); |
| 1758 InstallCrx(path, true); | 1774 InstallCRX(path, INSTALL_NEW); |
| 1759 ValidatePrefKeyCount(++pref_count); | 1775 ValidatePrefKeyCount(++pref_count); |
| 1760 ValidateIntegerPref(theme2_crx, "state", Extension::ENABLED); | 1776 ValidateIntegerPref(theme2_crx, "state", Extension::ENABLED); |
| 1761 ValidateIntegerPref(theme2_crx, "location", Extension::INTERNAL); | 1777 ValidateIntegerPref(theme2_crx, "location", Extension::INTERNAL); |
| 1762 | 1778 |
| 1763 // A theme with extension elements. Themes cannot have extension elements so | 1779 // A theme with extension elements. Themes cannot have extension elements so |
| 1764 // this test should fail. | 1780 // this test should fail. |
| 1765 set_extensions_enabled(true); | 1781 set_extensions_enabled(true); |
| 1766 path = data_dir_.AppendASCII("theme_with_extension.crx"); | 1782 path = data_dir_.AppendASCII("theme_with_extension.crx"); |
| 1767 InstallCrx(path, false); | 1783 InstallCRX(path, INSTALL_FAILED); |
| 1768 ValidatePrefKeyCount(pref_count); | 1784 ValidatePrefKeyCount(pref_count); |
| 1769 | 1785 |
| 1770 // A theme with image resources missing (misspelt path). | 1786 // A theme with image resources missing (misspelt path). |
| 1771 path = data_dir_.AppendASCII("theme_missing_image.crx"); | 1787 path = data_dir_.AppendASCII("theme_missing_image.crx"); |
| 1772 InstallCrx(path, false); | 1788 InstallCRX(path, INSTALL_FAILED); |
| 1773 ValidatePrefKeyCount(pref_count); | 1789 ValidatePrefKeyCount(pref_count); |
| 1774 } | 1790 } |
| 1775 | 1791 |
| 1776 TEST_F(ExtensionServiceTest, LoadLocalizedTheme) { | 1792 TEST_F(ExtensionServiceTest, LoadLocalizedTheme) { |
| 1777 // Load. | 1793 // Load. |
| 1778 InitializeEmptyExtensionService(); | 1794 InitializeEmptyExtensionService(); |
| 1779 FilePath extension_path = data_dir_ | 1795 FilePath extension_path = data_dir_ |
| 1780 .AppendASCII("theme_i18n"); | 1796 .AppendASCII("theme_i18n"); |
| 1781 | 1797 |
| 1782 extensions::UnpackedInstaller::Create(service_)->Load(extension_path); | 1798 extensions::UnpackedInstaller::Create(service_)->Load(extension_path); |
| 1783 loop_.RunAllPending(); | 1799 loop_.RunAllPending(); |
| 1784 EXPECT_EQ(0u, GetErrors().size()); | 1800 EXPECT_EQ(0u, GetErrors().size()); |
| 1785 ASSERT_EQ(1u, loaded_.size()); | 1801 ASSERT_EQ(1u, loaded_.size()); |
| 1786 EXPECT_EQ(1u, service_->extensions()->size()); | 1802 EXPECT_EQ(1u, service_->extensions()->size()); |
| 1787 EXPECT_EQ("name", service_->extensions()->at(0)->name()); | 1803 const Extension* theme = *service_->extensions()->begin(); |
| 1788 EXPECT_EQ("description", service_->extensions()->at(0)->description()); | 1804 EXPECT_EQ("name", theme->name()); |
| 1805 EXPECT_EQ("description", theme->description()); |
| 1789 } | 1806 } |
| 1790 | 1807 |
| 1791 TEST_F(ExtensionServiceTest, InstallLocalizedTheme) { | 1808 TEST_F(ExtensionServiceTest, InstallLocalizedTheme) { |
| 1792 InitializeEmptyExtensionService(); | 1809 InitializeEmptyExtensionService(); |
| 1793 FilePath theme_path = data_dir_ | 1810 FilePath theme_path = data_dir_ |
| 1794 .AppendASCII("theme_i18n"); | 1811 .AppendASCII("theme_i18n"); |
| 1795 | 1812 |
| 1796 PackAndInstallCrx(theme_path, true); | 1813 const Extension* theme = PackAndInstallCRX(theme_path, INSTALL_NEW); |
| 1797 | 1814 |
| 1798 EXPECT_EQ(0u, GetErrors().size()); | 1815 EXPECT_EQ(0u, GetErrors().size()); |
| 1799 EXPECT_EQ(1u, service_->extensions()->size()); | 1816 EXPECT_EQ(1u, service_->extensions()->size()); |
| 1800 EXPECT_EQ("name", service_->extensions()->at(0)->name()); | 1817 EXPECT_EQ("name", theme->name()); |
| 1801 EXPECT_EQ("description", service_->extensions()->at(0)->description()); | 1818 EXPECT_EQ("description", theme->description()); |
| 1802 } | 1819 } |
| 1803 | 1820 |
| 1804 TEST_F(ExtensionServiceTest, InstallApps) { | 1821 TEST_F(ExtensionServiceTest, InstallApps) { |
| 1805 InitializeEmptyExtensionService(); | 1822 InitializeEmptyExtensionService(); |
| 1806 | 1823 |
| 1807 // An empty app. | 1824 // An empty app. |
| 1808 PackAndInstallCrx(data_dir_.AppendASCII("app1"), true); | 1825 const Extension* app = PackAndInstallCRX(data_dir_.AppendASCII("app1"), |
| 1826 INSTALL_NEW); |
| 1809 int pref_count = 0; | 1827 int pref_count = 0; |
| 1810 ValidatePrefKeyCount(++pref_count); | 1828 ValidatePrefKeyCount(++pref_count); |
| 1811 ASSERT_EQ(1u, service_->extensions()->size()); | 1829 ASSERT_EQ(1u, service_->extensions()->size()); |
| 1812 std::string id = service_->extensions()->at(0)->id(); | 1830 ValidateIntegerPref(app->id(), "state", Extension::ENABLED); |
| 1813 ValidateIntegerPref(id, "state", Extension::ENABLED); | 1831 ValidateIntegerPref(app->id(), "location", Extension::INTERNAL); |
| 1814 ValidateIntegerPref(id, "location", Extension::INTERNAL); | |
| 1815 | 1832 |
| 1816 // Another app with non-overlapping extent. Should succeed. | 1833 // Another app with non-overlapping extent. Should succeed. |
| 1817 PackAndInstallCrx(data_dir_.AppendASCII("app2"), true); | 1834 PackAndInstallCRX(data_dir_.AppendASCII("app2"), INSTALL_NEW); |
| 1818 ValidatePrefKeyCount(++pref_count); | 1835 ValidatePrefKeyCount(++pref_count); |
| 1819 | 1836 |
| 1820 // A third app whose extent overlaps the first. Should fail. | 1837 // A third app whose extent overlaps the first. Should fail. |
| 1821 PackAndInstallCrx(data_dir_.AppendASCII("app3"), false); | 1838 PackAndInstallCRX(data_dir_.AppendASCII("app3"), INSTALL_FAILED); |
| 1822 ValidatePrefKeyCount(pref_count); | 1839 ValidatePrefKeyCount(pref_count); |
| 1823 } | 1840 } |
| 1824 | 1841 |
| 1825 // Tests that file access is OFF by default. | 1842 // Tests that file access is OFF by default. |
| 1826 TEST_F(ExtensionServiceTest, DefaultFileAccess) { | 1843 TEST_F(ExtensionServiceTest, DefaultFileAccess) { |
| 1827 InitializeEmptyExtensionService(); | 1844 InitializeEmptyExtensionService(); |
| 1828 PackAndInstallCrx(data_dir_.AppendASCII("permissions").AppendASCII("files"), | 1845 const Extension* extension = |
| 1829 true); | 1846 PackAndInstallCRX(data_dir_ |
| 1830 | 1847 .AppendASCII("permissions") |
| 1848 .AppendASCII("files"), |
| 1849 INSTALL_NEW); |
| 1831 EXPECT_EQ(0u, GetErrors().size()); | 1850 EXPECT_EQ(0u, GetErrors().size()); |
| 1832 EXPECT_EQ(1u, service_->extensions()->size()); | 1851 EXPECT_EQ(1u, service_->extensions()->size()); |
| 1833 std::string id = service_->extensions()->at(0)->id(); | 1852 EXPECT_FALSE(service_->extension_prefs()->AllowFileAccess(extension->id())); |
| 1834 EXPECT_FALSE(service_->extension_prefs()->AllowFileAccess(id)); | |
| 1835 } | 1853 } |
| 1836 | 1854 |
| 1837 TEST_F(ExtensionServiceTest, UpdateApps) { | 1855 TEST_F(ExtensionServiceTest, UpdateApps) { |
| 1838 InitializeEmptyExtensionService(); | 1856 InitializeEmptyExtensionService(); |
| 1839 FilePath extensions_path = data_dir_.AppendASCII("app_update"); | 1857 FilePath extensions_path = data_dir_.AppendASCII("app_update"); |
| 1840 | 1858 |
| 1841 // First install v1 of a hosted app. | 1859 // First install v1 of a hosted app. |
| 1842 InstallCrx(extensions_path.AppendASCII("v1.crx"), true); | 1860 const Extension* extension = |
| 1861 InstallCRX(extensions_path.AppendASCII("v1.crx"), INSTALL_NEW); |
| 1843 ASSERT_EQ(1u, service_->extensions()->size()); | 1862 ASSERT_EQ(1u, service_->extensions()->size()); |
| 1844 std::string id = service_->extensions()->at(0)->id(); | 1863 std::string id = extension->id(); |
| 1845 ASSERT_EQ(std::string("1"), | 1864 ASSERT_EQ(std::string("1"), extension->version()->GetString()); |
| 1846 service_->extensions()->at(0)->version()->GetString()); | |
| 1847 | 1865 |
| 1848 // Now try updating to v2. | 1866 // Now try updating to v2. |
| 1849 UpdateExtension(id, | 1867 UpdateExtension(id, |
| 1850 extensions_path.AppendASCII("v2.crx"), | 1868 extensions_path.AppendASCII("v2.crx"), |
| 1851 ENABLED); | 1869 ENABLED); |
| 1852 ASSERT_EQ(std::string("2"), | 1870 ASSERT_EQ(std::string("2"), |
| 1853 service_->extensions()->at(0)->version()->GetString()); | 1871 service_->GetExtensionById(id, false)->version()->GetString()); |
| 1854 } | 1872 } |
| 1855 | 1873 |
| 1856 TEST_F(ExtensionServiceTest, InstallAppsWithUnlimtedStorage) { | 1874 TEST_F(ExtensionServiceTest, InstallAppsWithUnlimitedStorage) { |
| 1857 InitializeEmptyExtensionService(); | 1875 InitializeEmptyExtensionService(); |
| 1858 InitializeRequestContext(); | 1876 InitializeRequestContext(); |
| 1859 EXPECT_TRUE(service_->extensions()->empty()); | 1877 EXPECT_TRUE(service_->extensions()->empty()); |
| 1860 | 1878 |
| 1861 int pref_count = 0; | 1879 int pref_count = 0; |
| 1862 | 1880 |
| 1863 // Install app1 with unlimited storage. | 1881 // Install app1 with unlimited storage. |
| 1864 PackAndInstallCrx(data_dir_.AppendASCII("app1"), true); | 1882 const Extension* extension = |
| 1883 PackAndInstallCRX(data_dir_.AppendASCII("app1"), INSTALL_NEW); |
| 1865 ValidatePrefKeyCount(++pref_count); | 1884 ValidatePrefKeyCount(++pref_count); |
| 1866 ASSERT_EQ(1u, service_->extensions()->size()); | 1885 ASSERT_EQ(1u, service_->extensions()->size()); |
| 1867 const Extension* extension = service_->extensions()->at(0); | |
| 1868 const std::string id1 = extension->id(); | 1886 const std::string id1 = extension->id(); |
| 1869 EXPECT_TRUE(extension->HasAPIPermission( | 1887 EXPECT_TRUE(extension->HasAPIPermission( |
| 1870 ExtensionAPIPermission::kUnlimitedStorage)); | 1888 ExtensionAPIPermission::kUnlimitedStorage)); |
| 1871 EXPECT_TRUE(extension->web_extent().MatchesURL( | 1889 EXPECT_TRUE(extension->web_extent().MatchesURL( |
| 1872 extension->GetFullLaunchURL())); | 1890 extension->GetFullLaunchURL())); |
| 1873 const GURL origin1(extension->GetFullLaunchURL().GetOrigin()); | 1891 const GURL origin1(extension->GetFullLaunchURL().GetOrigin()); |
| 1874 EXPECT_TRUE(profile_->GetExtensionSpecialStoragePolicy()-> | 1892 EXPECT_TRUE(profile_->GetExtensionSpecialStoragePolicy()-> |
| 1875 IsStorageUnlimited(origin1)); | 1893 IsStorageUnlimited(origin1)); |
| 1876 | 1894 |
| 1877 // Install app2 from the same origin with unlimited storage. | 1895 // Install app2 from the same origin with unlimited storage. |
| 1878 PackAndInstallCrx(data_dir_.AppendASCII("app2"), true); | 1896 extension = PackAndInstallCRX(data_dir_.AppendASCII("app2"), INSTALL_NEW); |
| 1879 ValidatePrefKeyCount(++pref_count); | 1897 ValidatePrefKeyCount(++pref_count); |
| 1880 ASSERT_EQ(2u, service_->extensions()->size()); | 1898 ASSERT_EQ(2u, service_->extensions()->size()); |
| 1881 extension = service_->extensions()->at(1); | |
| 1882 const std::string id2 = extension->id(); | 1899 const std::string id2 = extension->id(); |
| 1883 EXPECT_TRUE(extension->HasAPIPermission( | 1900 EXPECT_TRUE(extension->HasAPIPermission( |
| 1884 ExtensionAPIPermission::kUnlimitedStorage)); | 1901 ExtensionAPIPermission::kUnlimitedStorage)); |
| 1885 EXPECT_TRUE(extension->web_extent().MatchesURL( | 1902 EXPECT_TRUE(extension->web_extent().MatchesURL( |
| 1886 extension->GetFullLaunchURL())); | 1903 extension->GetFullLaunchURL())); |
| 1887 const GURL origin2(extension->GetFullLaunchURL().GetOrigin()); | 1904 const GURL origin2(extension->GetFullLaunchURL().GetOrigin()); |
| 1888 EXPECT_EQ(origin1, origin2); | 1905 EXPECT_EQ(origin1, origin2); |
| 1889 EXPECT_TRUE(profile_->GetExtensionSpecialStoragePolicy()-> | 1906 EXPECT_TRUE(profile_->GetExtensionSpecialStoragePolicy()-> |
| 1890 IsStorageUnlimited(origin2)); | 1907 IsStorageUnlimited(origin2)); |
| 1891 | 1908 |
| (...skipping 13 matching lines...) Expand all Loading... |
| 1905 IsStorageUnlimited(origin2)); | 1922 IsStorageUnlimited(origin2)); |
| 1906 } | 1923 } |
| 1907 | 1924 |
| 1908 TEST_F(ExtensionServiceTest, InstallAppsAndCheckStorageProtection) { | 1925 TEST_F(ExtensionServiceTest, InstallAppsAndCheckStorageProtection) { |
| 1909 InitializeEmptyExtensionService(); | 1926 InitializeEmptyExtensionService(); |
| 1910 InitializeRequestContext(); | 1927 InitializeRequestContext(); |
| 1911 EXPECT_TRUE(service_->extensions()->empty()); | 1928 EXPECT_TRUE(service_->extensions()->empty()); |
| 1912 | 1929 |
| 1913 int pref_count = 0; | 1930 int pref_count = 0; |
| 1914 | 1931 |
| 1915 PackAndInstallCrx(data_dir_.AppendASCII("app1"), true); | 1932 const Extension* extension = |
| 1933 PackAndInstallCRX(data_dir_.AppendASCII("app1"), INSTALL_NEW); |
| 1916 ValidatePrefKeyCount(++pref_count); | 1934 ValidatePrefKeyCount(++pref_count); |
| 1917 ASSERT_EQ(1u, service_->extensions()->size()); | 1935 ASSERT_EQ(1u, service_->extensions()->size()); |
| 1918 const Extension* extension = service_->extensions()->at(0); | |
| 1919 EXPECT_TRUE(extension->is_app()); | 1936 EXPECT_TRUE(extension->is_app()); |
| 1920 const std::string id1 = extension->id(); | 1937 const std::string id1 = extension->id(); |
| 1921 const GURL origin1(extension->GetFullLaunchURL().GetOrigin()); | 1938 const GURL origin1(extension->GetFullLaunchURL().GetOrigin()); |
| 1922 EXPECT_TRUE(profile_->GetExtensionSpecialStoragePolicy()-> | 1939 EXPECT_TRUE(profile_->GetExtensionSpecialStoragePolicy()-> |
| 1923 IsStorageProtected(origin1)); | 1940 IsStorageProtected(origin1)); |
| 1924 | 1941 |
| 1925 // App 4 has a different origin (maps.google.com). | 1942 // App 4 has a different origin (maps.google.com). |
| 1926 PackAndInstallCrx(data_dir_.AppendASCII("app4"), true); | 1943 extension = PackAndInstallCRX(data_dir_.AppendASCII("app4"), INSTALL_NEW); |
| 1927 ValidatePrefKeyCount(++pref_count); | 1944 ValidatePrefKeyCount(++pref_count); |
| 1928 ASSERT_EQ(2u, service_->extensions()->size()); | 1945 ASSERT_EQ(2u, service_->extensions()->size()); |
| 1929 extension = service_->extensions()->at(1); | |
| 1930 const std::string id2 = extension->id(); | 1946 const std::string id2 = extension->id(); |
| 1931 const GURL origin2(extension->GetFullLaunchURL().GetOrigin()); | 1947 const GURL origin2(extension->GetFullLaunchURL().GetOrigin()); |
| 1932 ASSERT_NE(origin1, origin2); | 1948 ASSERT_NE(origin1, origin2); |
| 1933 EXPECT_TRUE(profile_->GetExtensionSpecialStoragePolicy()-> | 1949 EXPECT_TRUE(profile_->GetExtensionSpecialStoragePolicy()-> |
| 1934 IsStorageProtected(origin2)); | 1950 IsStorageProtected(origin2)); |
| 1935 | 1951 |
| 1936 UninstallExtension(id1, false); | 1952 UninstallExtension(id1, false); |
| 1937 EXPECT_EQ(1u, service_->extensions()->size()); | 1953 EXPECT_EQ(1u, service_->extensions()->size()); |
| 1938 | 1954 |
| 1939 UninstallExtension(id2, false); | 1955 UninstallExtension(id2, false); |
| 1940 | 1956 |
| 1941 EXPECT_TRUE(service_->extensions()->empty()); | 1957 EXPECT_TRUE(service_->extensions()->empty()); |
| 1942 EXPECT_FALSE(profile_->GetExtensionSpecialStoragePolicy()-> | 1958 EXPECT_FALSE(profile_->GetExtensionSpecialStoragePolicy()-> |
| 1943 IsStorageProtected(origin1)); | 1959 IsStorageProtected(origin1)); |
| 1944 EXPECT_FALSE(profile_->GetExtensionSpecialStoragePolicy()-> | 1960 EXPECT_FALSE(profile_->GetExtensionSpecialStoragePolicy()-> |
| 1945 IsStorageProtected(origin2)); | 1961 IsStorageProtected(origin2)); |
| 1946 } | 1962 } |
| 1947 | 1963 |
| 1948 // Test that when an extension version is reinstalled, nothing happens. | 1964 // Test that when an extension version is reinstalled, nothing happens. |
| 1949 TEST_F(ExtensionServiceTest, Reinstall) { | 1965 TEST_F(ExtensionServiceTest, Reinstall) { |
| 1950 InitializeEmptyExtensionService(); | 1966 InitializeEmptyExtensionService(); |
| 1951 | 1967 |
| 1952 // A simple extension that should install without error. | 1968 // A simple extension that should install without error. |
| 1953 FilePath path = data_dir_.AppendASCII("good.crx"); | 1969 FilePath path = data_dir_.AppendASCII("good.crx"); |
| 1954 StartCrxInstall(path); | 1970 InstallCRX(path, INSTALL_NEW); |
| 1955 loop_.RunAllPending(); | |
| 1956 | 1971 |
| 1957 ASSERT_TRUE(installed_); | |
| 1958 ASSERT_EQ(1u, loaded_.size()); | |
| 1959 ASSERT_EQ(0u, GetErrors().size()); | |
| 1960 ValidatePrefKeyCount(1); | 1972 ValidatePrefKeyCount(1); |
| 1961 ValidateIntegerPref(good_crx, "state", Extension::ENABLED); | 1973 ValidateIntegerPref(good_crx, "state", Extension::ENABLED); |
| 1962 ValidateIntegerPref(good_crx, "location", Extension::INTERNAL); | 1974 ValidateIntegerPref(good_crx, "location", Extension::INTERNAL); |
| 1963 | 1975 |
| 1964 installed_ = NULL; | 1976 // Reinstall the same version, it should overwrite the previous one. |
| 1965 loaded_.clear(); | 1977 InstallCRX(path, INSTALL_UPDATED); |
| 1966 ExtensionErrorReporter::GetInstance()->ClearErrors(); | |
| 1967 | 1978 |
| 1968 // Reinstall the same version, it should overwrite the previous one. | |
| 1969 StartCrxInstall(path); | |
| 1970 loop_.RunAllPending(); | |
| 1971 | |
| 1972 ASSERT_TRUE(installed_); | |
| 1973 ASSERT_EQ(1u, loaded_.size()); | |
| 1974 ASSERT_EQ(0u, GetErrors().size()); | |
| 1975 ValidatePrefKeyCount(1); | 1979 ValidatePrefKeyCount(1); |
| 1976 ValidateIntegerPref(good_crx, "state", Extension::ENABLED); | 1980 ValidateIntegerPref(good_crx, "state", Extension::ENABLED); |
| 1977 ValidateIntegerPref(good_crx, "location", Extension::INTERNAL); | 1981 ValidateIntegerPref(good_crx, "location", Extension::INTERNAL); |
| 1978 } | 1982 } |
| 1979 | 1983 |
| 1980 // Test that we can determine if extensions came from the | 1984 // Test that we can determine if extensions came from the |
| 1981 // Chrome web store. | 1985 // Chrome web store. |
| 1982 TEST_F(ExtensionServiceTest, FromWebStore) { | 1986 TEST_F(ExtensionServiceTest, FromWebStore) { |
| 1983 InitializeEmptyExtensionService(); | 1987 InitializeEmptyExtensionService(); |
| 1984 | 1988 |
| 1985 // A simple extension that should install without error. | 1989 // A simple extension that should install without error. |
| 1986 FilePath path = data_dir_.AppendASCII("good.crx"); | 1990 FilePath path = data_dir_.AppendASCII("good.crx"); |
| 1987 StartCrxInstall(path, false); // Not from web store. | 1991 // Not from web store. |
| 1988 loop_.RunAllPending(); | 1992 const Extension* extension = InstallCRX(path, INSTALL_NEW); |
| 1993 std::string id = extension->id(); |
| 1989 | 1994 |
| 1990 ASSERT_TRUE(installed_); | |
| 1991 ASSERT_EQ(1u, loaded_.size()); | |
| 1992 ASSERT_EQ(0u, GetErrors().size()); | |
| 1993 ValidatePrefKeyCount(1); | 1995 ValidatePrefKeyCount(1); |
| 1994 ValidateBooleanPref(good_crx, "from_webstore", false); | 1996 ValidateBooleanPref(good_crx, "from_webstore", false); |
| 1995 | |
| 1996 const Extension* extension = service_->extensions()->at(0); | |
| 1997 ASSERT_FALSE(extension->from_webstore()); | 1997 ASSERT_FALSE(extension->from_webstore()); |
| 1998 | 1998 |
| 1999 installed_ = NULL; | 1999 // Test install from web store. |
| 2000 loaded_.clear(); | 2000 InstallCRXFromWebStore(path, INSTALL_UPDATED); // From web store. |
| 2001 ExtensionErrorReporter::GetInstance()->ClearErrors(); | |
| 2002 | 2001 |
| 2003 // Test install from web store. | |
| 2004 StartCrxInstall(path, true); // From web store. | |
| 2005 loop_.RunAllPending(); | |
| 2006 | |
| 2007 ASSERT_TRUE(installed_); | |
| 2008 ASSERT_EQ(1u, loaded_.size()); | |
| 2009 ASSERT_EQ(0u, GetErrors().size()); | |
| 2010 ValidatePrefKeyCount(1); | 2002 ValidatePrefKeyCount(1); |
| 2011 ValidateBooleanPref(good_crx, "from_webstore", true); | 2003 ValidateBooleanPref(good_crx, "from_webstore", true); |
| 2012 | 2004 |
| 2013 // Reload so extension gets reinitialized with new value. | 2005 // Reload so extension gets reinitialized with new value. |
| 2014 service_->ReloadExtensions(); | 2006 service_->ReloadExtensions(); |
| 2015 extension = service_->extensions()->at(0); | 2007 extension = service_->GetExtensionById(id, false); |
| 2016 ASSERT_TRUE(extension->from_webstore()); | 2008 ASSERT_TRUE(extension->from_webstore()); |
| 2017 | 2009 |
| 2018 // Upgrade to version 2.0 | 2010 // Upgrade to version 2.0 |
| 2019 path = data_dir_.AppendASCII("good2.crx"); | 2011 path = data_dir_.AppendASCII("good2.crx"); |
| 2020 UpdateExtension(good_crx, path, ENABLED); | 2012 UpdateExtension(good_crx, path, ENABLED); |
| 2021 ValidatePrefKeyCount(1); | 2013 ValidatePrefKeyCount(1); |
| 2022 ValidateBooleanPref(good_crx, "from_webstore", true); | 2014 ValidateBooleanPref(good_crx, "from_webstore", true); |
| 2023 } | 2015 } |
| 2024 | 2016 |
| 2025 // Test upgrading a signed extension. | 2017 // Test upgrading a signed extension. |
| 2026 TEST_F(ExtensionServiceTest, UpgradeSignedGood) { | 2018 TEST_F(ExtensionServiceTest, UpgradeSignedGood) { |
| 2027 InitializeEmptyExtensionService(); | 2019 InitializeEmptyExtensionService(); |
| 2028 | 2020 |
| 2029 FilePath path = data_dir_.AppendASCII("good.crx"); | 2021 FilePath path = data_dir_.AppendASCII("good.crx"); |
| 2030 StartCrxInstall(path); | 2022 const Extension* extension = InstallCRX(path, INSTALL_NEW); |
| 2031 loop_.RunAllPending(); | 2023 std::string id = extension->id(); |
| 2032 | 2024 |
| 2033 ASSERT_TRUE(installed_); | 2025 ASSERT_EQ("1.0.0.0", extension->version()->GetString()); |
| 2034 ASSERT_EQ(1u, loaded_.size()); | |
| 2035 ASSERT_EQ("1.0.0.0", loaded_[0]->version()->GetString()); | |
| 2036 ASSERT_EQ(0u, GetErrors().size()); | 2026 ASSERT_EQ(0u, GetErrors().size()); |
| 2037 | 2027 |
| 2038 // Upgrade to version 2.0 | 2028 // Upgrade to version 1.0.0.1 |
| 2039 path = data_dir_.AppendASCII("good2.crx"); | 2029 path = data_dir_.AppendASCII("good2.crx"); |
| 2040 StartCrxInstall(path); | 2030 InstallCRX(path, INSTALL_UPDATED); |
| 2041 loop_.RunAllPending(); | 2031 extension = service_->GetExtensionById(id, false); |
| 2042 | 2032 |
| 2043 ASSERT_TRUE(installed_); | 2033 ASSERT_EQ("1.0.0.1", extension->version()->GetString()); |
| 2044 ASSERT_EQ(1u, loaded_.size()); | |
| 2045 ASSERT_EQ("1.0.0.1", loaded_[0]->version()->GetString()); | |
| 2046 ASSERT_EQ(0u, GetErrors().size()); | 2034 ASSERT_EQ(0u, GetErrors().size()); |
| 2047 } | 2035 } |
| 2048 | 2036 |
| 2049 // Test upgrading a signed extension with a bad signature. | 2037 // Test upgrading a signed extension with a bad signature. |
| 2050 TEST_F(ExtensionServiceTest, UpgradeSignedBad) { | 2038 TEST_F(ExtensionServiceTest, UpgradeSignedBad) { |
| 2051 InitializeEmptyExtensionService(); | 2039 InitializeEmptyExtensionService(); |
| 2052 | 2040 |
| 2053 FilePath path = data_dir_.AppendASCII("good.crx"); | 2041 FilePath path = data_dir_.AppendASCII("good.crx"); |
| 2054 StartCrxInstall(path); | 2042 InstallCRX(path, INSTALL_NEW); |
| 2055 loop_.RunAllPending(); | |
| 2056 | |
| 2057 ASSERT_TRUE(installed_); | |
| 2058 ASSERT_EQ(1u, loaded_.size()); | |
| 2059 ASSERT_EQ(0u, GetErrors().size()); | |
| 2060 installed_ = NULL; | |
| 2061 | 2043 |
| 2062 // Try upgrading with a bad signature. This should fail during the unpack, | 2044 // Try upgrading with a bad signature. This should fail during the unpack, |
| 2063 // because the key will not match the signature. | 2045 // because the key will not match the signature. |
| 2064 path = data_dir_.AppendASCII("bad_signature.crx"); | 2046 path = data_dir_.AppendASCII("bad_signature.crx"); |
| 2065 StartCrxInstall(path); | 2047 InstallCRX(path, INSTALL_FAILED); |
| 2066 loop_.RunAllPending(); | |
| 2067 | |
| 2068 ASSERT_FALSE(installed_); | |
| 2069 ASSERT_EQ(1u, loaded_.size()); | |
| 2070 ASSERT_EQ(1u, GetErrors().size()); | |
| 2071 } | 2048 } |
| 2072 | 2049 |
| 2073 // Test a normal update via the UpdateExtension API | 2050 // Test a normal update via the UpdateExtension API |
| 2074 TEST_F(ExtensionServiceTest, UpdateExtension) { | 2051 TEST_F(ExtensionServiceTest, UpdateExtension) { |
| 2075 InitializeEmptyExtensionService(); | 2052 InitializeEmptyExtensionService(); |
| 2076 | 2053 |
| 2077 FilePath path = data_dir_.AppendASCII("good.crx"); | 2054 FilePath path = data_dir_.AppendASCII("good.crx"); |
| 2078 | 2055 |
| 2079 InstallCrx(path, true); | 2056 const Extension* good = InstallCRX(path, INSTALL_NEW); |
| 2080 const Extension* good = service_->extensions()->at(0); | |
| 2081 ASSERT_EQ("1.0.0.0", good->VersionString()); | 2057 ASSERT_EQ("1.0.0.0", good->VersionString()); |
| 2082 ASSERT_EQ(good_crx, good->id()); | 2058 ASSERT_EQ(good_crx, good->id()); |
| 2083 | 2059 |
| 2084 path = data_dir_.AppendASCII("good2.crx"); | 2060 path = data_dir_.AppendASCII("good2.crx"); |
| 2085 UpdateExtension(good_crx, path, ENABLED); | 2061 UpdateExtension(good_crx, path, ENABLED); |
| 2086 ASSERT_EQ("1.0.0.1", loaded_[0]->version()->GetString()); | 2062 ASSERT_EQ("1.0.0.1", |
| 2063 service_->GetExtensionById(good_crx, false)-> |
| 2064 version()->GetString()); |
| 2087 } | 2065 } |
| 2088 | 2066 |
| 2089 // Test updating a not-already-installed extension - this should fail | 2067 // Test updating a not-already-installed extension - this should fail |
| 2090 TEST_F(ExtensionServiceTest, UpdateNotInstalledExtension) { | 2068 TEST_F(ExtensionServiceTest, UpdateNotInstalledExtension) { |
| 2091 InitializeEmptyExtensionService(); | 2069 InitializeEmptyExtensionService(); |
| 2092 | 2070 |
| 2093 FilePath path = data_dir_.AppendASCII("good.crx"); | 2071 FilePath path = data_dir_.AppendASCII("good.crx"); |
| 2094 UpdateExtension(good_crx, path, UPDATED); | 2072 UpdateExtension(good_crx, path, UPDATED); |
| 2095 loop_.RunAllPending(); | 2073 loop_.RunAllPending(); |
| 2096 | 2074 |
| 2097 ASSERT_EQ(0u, service_->extensions()->size()); | 2075 ASSERT_EQ(0u, service_->extensions()->size()); |
| 2098 ASSERT_FALSE(installed_); | 2076 ASSERT_FALSE(installed_); |
| 2099 ASSERT_EQ(0u, loaded_.size()); | 2077 ASSERT_EQ(0u, loaded_.size()); |
| 2100 } | 2078 } |
| 2101 | 2079 |
| 2102 // Makes sure you can't downgrade an extension via UpdateExtension | 2080 // Makes sure you can't downgrade an extension via UpdateExtension |
| 2103 TEST_F(ExtensionServiceTest, UpdateWillNotDowngrade) { | 2081 TEST_F(ExtensionServiceTest, UpdateWillNotDowngrade) { |
| 2104 InitializeEmptyExtensionService(); | 2082 InitializeEmptyExtensionService(); |
| 2105 | 2083 |
| 2106 FilePath path = data_dir_.AppendASCII("good2.crx"); | 2084 FilePath path = data_dir_.AppendASCII("good2.crx"); |
| 2107 | 2085 |
| 2108 InstallCrx(path, true); | 2086 const Extension* good = InstallCRX(path, INSTALL_NEW); |
| 2109 const Extension* good = service_->extensions()->at(0); | |
| 2110 ASSERT_EQ("1.0.0.1", good->VersionString()); | 2087 ASSERT_EQ("1.0.0.1", good->VersionString()); |
| 2111 ASSERT_EQ(good_crx, good->id()); | 2088 ASSERT_EQ(good_crx, good->id()); |
| 2112 | 2089 |
| 2113 // Change path from good2.crx -> good.crx | 2090 // Change path from good2.crx -> good.crx |
| 2114 path = data_dir_.AppendASCII("good.crx"); | 2091 path = data_dir_.AppendASCII("good.crx"); |
| 2115 UpdateExtension(good_crx, path, FAILED); | 2092 UpdateExtension(good_crx, path, FAILED); |
| 2116 ASSERT_EQ("1.0.0.1", service_->extensions()->at(0)->VersionString()); | 2093 ASSERT_EQ("1.0.0.1", |
| 2094 service_->GetExtensionById(good_crx, false)-> |
| 2095 version()->GetString()); |
| 2117 } | 2096 } |
| 2118 | 2097 |
| 2119 // Make sure calling update with an identical version does nothing | 2098 // Make sure calling update with an identical version does nothing |
| 2120 TEST_F(ExtensionServiceTest, UpdateToSameVersionIsNoop) { | 2099 TEST_F(ExtensionServiceTest, UpdateToSameVersionIsNoop) { |
| 2121 InitializeEmptyExtensionService(); | 2100 InitializeEmptyExtensionService(); |
| 2122 | 2101 |
| 2123 FilePath path = data_dir_.AppendASCII("good.crx"); | 2102 FilePath path = data_dir_.AppendASCII("good.crx"); |
| 2124 | 2103 |
| 2125 InstallCrx(path, true); | 2104 const Extension* good = InstallCRX(path, INSTALL_NEW); |
| 2126 const Extension* good = service_->extensions()->at(0); | |
| 2127 ASSERT_EQ(good_crx, good->id()); | 2105 ASSERT_EQ(good_crx, good->id()); |
| 2128 UpdateExtension(good_crx, path, FAILED_SILENTLY); | 2106 UpdateExtension(good_crx, path, FAILED_SILENTLY); |
| 2129 } | 2107 } |
| 2130 | 2108 |
| 2131 // Tests that updating an extension does not clobber old state. | 2109 // Tests that updating an extension does not clobber old state. |
| 2132 TEST_F(ExtensionServiceTest, UpdateExtensionPreservesState) { | 2110 TEST_F(ExtensionServiceTest, UpdateExtensionPreservesState) { |
| 2133 InitializeEmptyExtensionService(); | 2111 InitializeEmptyExtensionService(); |
| 2134 | 2112 |
| 2135 FilePath path = data_dir_.AppendASCII("good.crx"); | 2113 FilePath path = data_dir_.AppendASCII("good.crx"); |
| 2136 | 2114 |
| 2137 InstallCrx(path, true); | 2115 const Extension* good = InstallCRX(path, INSTALL_NEW); |
| 2138 const Extension* good = service_->extensions()->at(0); | |
| 2139 ASSERT_EQ("1.0.0.0", good->VersionString()); | 2116 ASSERT_EQ("1.0.0.0", good->VersionString()); |
| 2140 ASSERT_EQ(good_crx, good->id()); | 2117 ASSERT_EQ(good_crx, good->id()); |
| 2141 | 2118 |
| 2142 // Disable it and allow it to run in incognito. These settings should carry | 2119 // Disable it and allow it to run in incognito. These settings should carry |
| 2143 // over to the updated version. | 2120 // over to the updated version. |
| 2144 service_->DisableExtension(good->id()); | 2121 service_->DisableExtension(good->id()); |
| 2145 service_->SetIsIncognitoEnabled(good->id(), true); | 2122 service_->SetIsIncognitoEnabled(good->id(), true); |
| 2146 | 2123 |
| 2147 path = data_dir_.AppendASCII("good2.crx"); | 2124 path = data_dir_.AppendASCII("good2.crx"); |
| 2148 UpdateExtension(good_crx, path, INSTALLED); | 2125 UpdateExtension(good_crx, path, INSTALLED); |
| 2149 ASSERT_EQ(1u, service_->disabled_extensions()->size()); | 2126 ASSERT_EQ(1u, service_->disabled_extensions()->size()); |
| 2150 const Extension* good2 = service_->disabled_extensions()->at(0); | 2127 const Extension* good2 = service_->GetExtensionById(good_crx, true); |
| 2151 ASSERT_EQ("1.0.0.1", good2->version()->GetString()); | 2128 ASSERT_EQ("1.0.0.1", good2->version()->GetString()); |
| 2152 EXPECT_TRUE(service_->IsIncognitoEnabled(good2->id())); | 2129 EXPECT_TRUE(service_->IsIncognitoEnabled(good2->id())); |
| 2153 } | 2130 } |
| 2154 | 2131 |
| 2155 // Tests that updating preserves extension location. | 2132 // Tests that updating preserves extension location. |
| 2156 TEST_F(ExtensionServiceTest, UpdateExtensionPreservesLocation) { | 2133 TEST_F(ExtensionServiceTest, UpdateExtensionPreservesLocation) { |
| 2157 InitializeEmptyExtensionService(); | 2134 InitializeEmptyExtensionService(); |
| 2158 | 2135 |
| 2159 FilePath path = data_dir_.AppendASCII("good.crx"); | 2136 FilePath path = data_dir_.AppendASCII("good.crx"); |
| 2160 | 2137 |
| 2161 InstallCrx(path, true); | 2138 const Extension* good = InstallCRX(path, INSTALL_NEW); |
| 2162 const Extension* good = service_->extensions()->at(0); | |
| 2163 | 2139 |
| 2164 ASSERT_EQ("1.0.0.0", good->VersionString()); | 2140 ASSERT_EQ("1.0.0.0", good->VersionString()); |
| 2165 ASSERT_EQ(good_crx, good->id()); | 2141 ASSERT_EQ(good_crx, good->id()); |
| 2166 | 2142 |
| 2167 // Simulate non-internal location. | 2143 // Simulate non-internal location. |
| 2168 const_cast<Extension*>(good)->location_ = Extension::EXTERNAL_PREF; | 2144 const_cast<Extension*>(good)->location_ = Extension::EXTERNAL_PREF; |
| 2169 | 2145 |
| 2170 path = data_dir_.AppendASCII("good2.crx"); | 2146 path = data_dir_.AppendASCII("good2.crx"); |
| 2171 UpdateExtension(good_crx, path, ENABLED); | 2147 UpdateExtension(good_crx, path, ENABLED); |
| 2172 const Extension* good2 = service_->extensions()->at(0); | 2148 const Extension* good2 = service_->GetExtensionById(good_crx, false); |
| 2173 ASSERT_EQ("1.0.0.1", good2->version()->GetString()); | 2149 ASSERT_EQ("1.0.0.1", good2->version()->GetString()); |
| 2174 EXPECT_EQ(good2->location(), Extension::EXTERNAL_PREF); | 2150 EXPECT_EQ(good2->location(), Extension::EXTERNAL_PREF); |
| 2175 } | 2151 } |
| 2176 | 2152 |
| 2177 // Makes sure that LOAD extension types can downgrade. | 2153 // Makes sure that LOAD extension types can downgrade. |
| 2178 TEST_F(ExtensionServiceTest, LoadExtensionsCanDowngrade) { | 2154 TEST_F(ExtensionServiceTest, LoadExtensionsCanDowngrade) { |
| 2179 InitializeEmptyExtensionService(); | 2155 InitializeEmptyExtensionService(); |
| 2180 | 2156 |
| 2181 ScopedTempDir temp; | 2157 ScopedTempDir temp; |
| 2182 ASSERT_TRUE(temp.CreateUniqueTempDir()); | 2158 ASSERT_TRUE(temp.CreateUniqueTempDir()); |
| (...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2421 | 2397 |
| 2422 EXPECT_FALSE(service_->pending_extension_manager()->IsIdPending(kGoodId)); | 2398 EXPECT_FALSE(service_->pending_extension_manager()->IsIdPending(kGoodId)); |
| 2423 } | 2399 } |
| 2424 | 2400 |
| 2425 // Test updating a pending extension for one that is already | 2401 // Test updating a pending extension for one that is already |
| 2426 // installed. | 2402 // installed. |
| 2427 TEST_F(ExtensionServiceTest, UpdatePendingExtensionAlreadyInstalled) { | 2403 TEST_F(ExtensionServiceTest, UpdatePendingExtensionAlreadyInstalled) { |
| 2428 InitializeEmptyExtensionService(); | 2404 InitializeEmptyExtensionService(); |
| 2429 | 2405 |
| 2430 FilePath path = data_dir_.AppendASCII("good.crx"); | 2406 FilePath path = data_dir_.AppendASCII("good.crx"); |
| 2431 InstallCrx(path, true); | 2407 const Extension* good = InstallCRX(path, INSTALL_NEW); |
| 2432 ASSERT_EQ(1u, service_->extensions()->size()); | 2408 ASSERT_EQ(1u, service_->extensions()->size()); |
| 2433 const Extension* good = service_->extensions()->at(0); | |
| 2434 | 2409 |
| 2435 EXPECT_FALSE(good->is_theme()); | 2410 EXPECT_FALSE(good->is_theme()); |
| 2436 | 2411 |
| 2437 // Use AddExtensionImpl() as AddFrom*() would balk. | 2412 // Use AddExtensionImpl() as AddFrom*() would balk. |
| 2438 service_->pending_extension_manager()->AddExtensionImpl( | 2413 service_->pending_extension_manager()->AddExtensionImpl( |
| 2439 good->id(), good->update_url(), &IsExtension, | 2414 good->id(), good->update_url(), &IsExtension, |
| 2440 kGoodIsFromSync, kGoodInstallSilently, Extension::INTERNAL); | 2415 kGoodIsFromSync, kGoodInstallSilently, Extension::INTERNAL); |
| 2441 UpdateExtension(good->id(), path, ENABLED); | 2416 UpdateExtension(good->id(), path, ENABLED); |
| 2442 | 2417 |
| 2443 EXPECT_FALSE(service_->pending_extension_manager()->IsIdPending(kGoodId)); | 2418 EXPECT_FALSE(service_->pending_extension_manager()->IsIdPending(kGoodId)); |
| (...skipping 27 matching lines...) Expand all Loading... |
| 2471 ValidateBooleanPref(good2, "blacklist", true); | 2446 ValidateBooleanPref(good2, "blacklist", true); |
| 2472 EXPECT_FALSE(IsPrefExist("invalid_id", "blacklist")); | 2447 EXPECT_FALSE(IsPrefExist("invalid_id", "blacklist")); |
| 2473 } | 2448 } |
| 2474 | 2449 |
| 2475 // Unload installed extension from blacklist. | 2450 // Unload installed extension from blacklist. |
| 2476 TEST_F(ExtensionServiceTest, UnloadBlacklistedExtension) { | 2451 TEST_F(ExtensionServiceTest, UnloadBlacklistedExtension) { |
| 2477 InitializeEmptyExtensionService(); | 2452 InitializeEmptyExtensionService(); |
| 2478 | 2453 |
| 2479 FilePath path = data_dir_.AppendASCII("good.crx"); | 2454 FilePath path = data_dir_.AppendASCII("good.crx"); |
| 2480 | 2455 |
| 2481 InstallCrx(path, true); | 2456 const Extension* good = InstallCRX(path, INSTALL_NEW); |
| 2482 const Extension* good = service_->extensions()->at(0); | |
| 2483 EXPECT_EQ(good_crx, good->id()); | 2457 EXPECT_EQ(good_crx, good->id()); |
| 2484 UpdateExtension(good_crx, path, FAILED_SILENTLY); | 2458 UpdateExtension(good_crx, path, FAILED_SILENTLY); |
| 2485 | 2459 |
| 2486 std::vector<std::string> blacklist; | 2460 std::vector<std::string> blacklist; |
| 2487 blacklist.push_back(good_crx); | 2461 blacklist.push_back(good_crx); |
| 2488 service_->UpdateExtensionBlacklist(blacklist); | 2462 service_->UpdateExtensionBlacklist(blacklist); |
| 2489 // Make sure pref is updated | 2463 // Make sure pref is updated |
| 2490 loop_.RunAllPending(); | 2464 loop_.RunAllPending(); |
| 2491 | 2465 |
| 2492 // Now, the good_crx is blacklisted. | 2466 // Now, the good_crx is blacklisted. |
| (...skipping 16 matching lines...) Expand all Loading... |
| 2509 blacklist.push_back(good_crx); | 2483 blacklist.push_back(good_crx); |
| 2510 service_->UpdateExtensionBlacklist(blacklist); | 2484 service_->UpdateExtensionBlacklist(blacklist); |
| 2511 // Make sure pref is updated | 2485 // Make sure pref is updated |
| 2512 loop_.RunAllPending(); | 2486 loop_.RunAllPending(); |
| 2513 | 2487 |
| 2514 // Now, the good_crx is blacklisted. | 2488 // Now, the good_crx is blacklisted. |
| 2515 ValidateBooleanPref(good_crx, "blacklist", true); | 2489 ValidateBooleanPref(good_crx, "blacklist", true); |
| 2516 | 2490 |
| 2517 // We can not install good_crx. | 2491 // We can not install good_crx. |
| 2518 FilePath path = data_dir_.AppendASCII("good.crx"); | 2492 FilePath path = data_dir_.AppendASCII("good.crx"); |
| 2519 StartCrxInstall(path); | 2493 InstallCRX(path, INSTALL_FAILED); |
| 2520 loop_.RunAllPending(); | |
| 2521 EXPECT_EQ(0u, service_->extensions()->size()); | 2494 EXPECT_EQ(0u, service_->extensions()->size()); |
| 2522 ValidateBooleanPref(good_crx, "blacklist", true); | 2495 ValidateBooleanPref(good_crx, "blacklist", true); |
| 2523 } | 2496 } |
| 2524 | 2497 |
| 2525 // Test loading extensions from the profile directory, except | 2498 // Test loading extensions from the profile directory, except |
| 2526 // blacklisted ones. | 2499 // blacklisted ones. |
| 2527 TEST_F(ExtensionServiceTest, WillNotLoadBlacklistedExtensionsFromDirectory) { | 2500 TEST_F(ExtensionServiceTest, WillNotLoadBlacklistedExtensionsFromDirectory) { |
| 2528 // Initialize the test dir with a good Preferences/extensions. | 2501 // Initialize the test dir with a good Preferences/extensions. |
| 2529 FilePath source_install_dir = data_dir_ | 2502 FilePath source_install_dir = data_dir_ |
| 2530 .AppendASCII("good") | 2503 .AppendASCII("good") |
| 2531 .AppendASCII("Extensions"); | 2504 .AppendASCII("Extensions"); |
| 2532 FilePath pref_path = source_install_dir | 2505 FilePath pref_path = source_install_dir |
| 2533 .DirName() | 2506 .DirName() |
| 2534 .AppendASCII("Preferences"); | 2507 .AppendASCII("Preferences"); |
| 2535 InitializeInstalledExtensionService(pref_path, source_install_dir); | 2508 InitializeInstalledExtensionService(pref_path, source_install_dir); |
| 2536 | 2509 |
| 2537 // Blacklist good1. | 2510 // Blacklist good1. |
| 2538 std::vector<std::string> blacklist; | 2511 std::vector<std::string> blacklist; |
| 2539 blacklist.push_back(good1); | 2512 blacklist.push_back(good1); |
| 2540 service_->UpdateExtensionBlacklist(blacklist); | 2513 service_->UpdateExtensionBlacklist(blacklist); |
| 2541 // Make sure pref is updated | 2514 // Make sure pref is updated |
| 2542 loop_.RunAllPending(); | 2515 loop_.RunAllPending(); |
| 2543 | 2516 |
| 2544 ValidateBooleanPref(good1, "blacklist", true); | 2517 ValidateBooleanPref(good1, "blacklist", true); |
| 2545 | 2518 |
| 2546 // Load extensions. | 2519 // Load extensions. |
| 2547 service_->Init(); | 2520 service_->Init(); |
| 2548 loop_.RunAllPending(); | |
| 2549 | 2521 |
| 2550 std::vector<std::string> errors = GetErrors(); | 2522 std::vector<std::string> errors = GetErrors(); |
| 2551 for (std::vector<std::string>::iterator err = errors.begin(); | 2523 for (std::vector<std::string>::iterator err = errors.begin(); |
| 2552 err != errors.end(); ++err) { | 2524 err != errors.end(); ++err) { |
| 2553 LOG(ERROR) << *err; | 2525 LOG(ERROR) << *err; |
| 2554 } | 2526 } |
| 2555 ASSERT_EQ(2u, loaded_.size()); | 2527 ASSERT_EQ(2u, loaded_.size()); |
| 2556 | 2528 |
| 2557 EXPECT_NE(std::string(good1), loaded_[0]->id()); | 2529 EXPECT_FALSE(service_->GetExtensionById(good1, true)); |
| 2558 EXPECT_NE(std::string(good1), loaded_[1]->id()); | |
| 2559 } | 2530 } |
| 2560 | 2531 |
| 2561 // Will not install extension blacklisted by policy. | 2532 // Will not install extension blacklisted by policy. |
| 2562 TEST_F(ExtensionServiceTest, BlacklistedByPolicyWillNotInstall) { | 2533 TEST_F(ExtensionServiceTest, BlacklistedByPolicyWillNotInstall) { |
| 2563 InitializeEmptyExtensionService(); | 2534 InitializeEmptyExtensionService(); |
| 2564 | 2535 |
| 2565 // Blacklist everything. | 2536 // Blacklist everything. |
| 2566 { | 2537 { |
| 2567 ListPrefUpdate update(profile_->GetPrefs(), | 2538 ListPrefUpdate update(profile_->GetPrefs(), |
| 2568 prefs::kExtensionInstallDenyList); | 2539 prefs::kExtensionInstallDenyList); |
| 2569 ListValue* blacklist = update.Get(); | 2540 ListValue* blacklist = update.Get(); |
| 2570 blacklist->Append(Value::CreateStringValue("*")); | 2541 blacklist->Append(Value::CreateStringValue("*")); |
| 2571 } | 2542 } |
| 2572 | 2543 |
| 2573 // Blacklist prevents us from installing good_crx. | 2544 // Blacklist prevents us from installing good_crx. |
| 2574 FilePath path = data_dir_.AppendASCII("good.crx"); | 2545 FilePath path = data_dir_.AppendASCII("good.crx"); |
| 2575 StartCrxInstall(path); | 2546 InstallCRX(path, INSTALL_FAILED); |
| 2576 loop_.RunAllPending(); | |
| 2577 EXPECT_EQ(0u, service_->extensions()->size()); | 2547 EXPECT_EQ(0u, service_->extensions()->size()); |
| 2578 | 2548 |
| 2579 // Now whitelist this particular extension. | 2549 // Now whitelist this particular extension. |
| 2580 { | 2550 { |
| 2581 ListPrefUpdate update(profile_->GetPrefs(), | 2551 ListPrefUpdate update(profile_->GetPrefs(), |
| 2582 prefs::kExtensionInstallAllowList); | 2552 prefs::kExtensionInstallAllowList); |
| 2583 ListValue* whitelist = update.Get(); | 2553 ListValue* whitelist = update.Get(); |
| 2584 whitelist->Append(Value::CreateStringValue(good_crx)); | 2554 whitelist->Append(Value::CreateStringValue(good_crx)); |
| 2585 } | 2555 } |
| 2586 | 2556 |
| 2587 | |
| 2588 // Ensure we can now install good_crx. | 2557 // Ensure we can now install good_crx. |
| 2589 StartCrxInstall(path); | 2558 InstallCRX(path, INSTALL_NEW); |
| 2590 loop_.RunAllPending(); | |
| 2591 EXPECT_EQ(1u, service_->extensions()->size()); | 2559 EXPECT_EQ(1u, service_->extensions()->size()); |
| 2592 } | 2560 } |
| 2593 | 2561 |
| 2594 // Extension blacklisted by policy get unloaded after installing. | 2562 // Extension blacklisted by policy get unloaded after installing. |
| 2595 TEST_F(ExtensionServiceTest, BlacklistedByPolicyRemovedIfRunning) { | 2563 TEST_F(ExtensionServiceTest, BlacklistedByPolicyRemovedIfRunning) { |
| 2596 InitializeEmptyExtensionService(); | 2564 InitializeEmptyExtensionService(); |
| 2597 | 2565 |
| 2598 // Install good_crx. | 2566 // Install good_crx. |
| 2599 FilePath path = data_dir_.AppendASCII("good.crx"); | 2567 FilePath path = data_dir_.AppendASCII("good.crx"); |
| 2600 StartCrxInstall(path); | 2568 InstallCRX(path, INSTALL_NEW); |
| 2601 loop_.RunAllPending(); | |
| 2602 EXPECT_EQ(1u, service_->extensions()->size()); | 2569 EXPECT_EQ(1u, service_->extensions()->size()); |
| 2603 | 2570 |
| 2604 { // Scope for pref update notification. | 2571 { // Scope for pref update notification. |
| 2605 PrefService* prefs = profile_->GetPrefs(); | 2572 PrefService* prefs = profile_->GetPrefs(); |
| 2606 ListPrefUpdate update(prefs, prefs::kExtensionInstallDenyList); | 2573 ListPrefUpdate update(prefs, prefs::kExtensionInstallDenyList); |
| 2607 ListValue* blacklist = update.Get(); | 2574 ListValue* blacklist = update.Get(); |
| 2608 ASSERT_TRUE(blacklist != NULL); | 2575 ASSERT_TRUE(blacklist != NULL); |
| 2609 | 2576 |
| 2610 // Blacklist this extension. | 2577 // Blacklist this extension. |
| 2611 blacklist->Append(Value::CreateStringValue(good_crx)); | 2578 blacklist->Append(Value::CreateStringValue(good_crx)); |
| (...skipping 24 matching lines...) Expand all Loading... |
| 2636 .AppendASCII(good0) | 2603 .AppendASCII(good0) |
| 2637 .AppendASCII("1.0.0.0"); | 2604 .AppendASCII("1.0.0.0"); |
| 2638 std::string manifest; | 2605 std::string manifest; |
| 2639 ASSERT_TRUE(file_util::ReadFileToString( | 2606 ASSERT_TRUE(file_util::ReadFileToString( |
| 2640 path.Append(Extension::kManifestFilename), &manifest)); | 2607 path.Append(Extension::kManifestFilename), &manifest)); |
| 2641 service_->component_loader()->Add(manifest, path); | 2608 service_->component_loader()->Add(manifest, path); |
| 2642 service_->Init(); | 2609 service_->Init(); |
| 2643 | 2610 |
| 2644 // Extension should be installed despite blacklist. | 2611 // Extension should be installed despite blacklist. |
| 2645 ASSERT_EQ(1u, service_->extensions()->size()); | 2612 ASSERT_EQ(1u, service_->extensions()->size()); |
| 2646 EXPECT_EQ(good0, service_->extensions()->at(0)->id()); | 2613 EXPECT_TRUE(service_->GetExtensionById(good0, false)); |
| 2647 | 2614 |
| 2648 // Poke external providers and make sure the extension is still present. | 2615 // Poke external providers and make sure the extension is still present. |
| 2649 service_->CheckForExternalUpdates(); | 2616 service_->CheckForExternalUpdates(); |
| 2650 ASSERT_EQ(1u, service_->extensions()->size()); | 2617 ASSERT_EQ(1u, service_->extensions()->size()); |
| 2651 EXPECT_EQ(good0, service_->extensions()->at(0)->id()); | 2618 EXPECT_TRUE(service_->GetExtensionById(good0, false)); |
| 2652 | 2619 |
| 2653 // Extension should not be uninstalled on blacklist changes. | 2620 // Extension should not be uninstalled on blacklist changes. |
| 2654 { | 2621 { |
| 2655 ListPrefUpdate update(profile_->GetPrefs(), | 2622 ListPrefUpdate update(profile_->GetPrefs(), |
| 2656 prefs::kExtensionInstallDenyList); | 2623 prefs::kExtensionInstallDenyList); |
| 2657 ListValue* blacklist = update.Get(); | 2624 ListValue* blacklist = update.Get(); |
| 2658 blacklist->Append(Value::CreateStringValue(good0)); | 2625 blacklist->Append(Value::CreateStringValue(good0)); |
| 2659 } | 2626 } |
| 2660 loop_.RunAllPending(); | 2627 loop_.RunAllPending(); |
| 2661 ASSERT_EQ(1u, service_->extensions()->size()); | 2628 ASSERT_EQ(1u, service_->extensions()->size()); |
| 2662 EXPECT_EQ(good0, service_->extensions()->at(0)->id()); | 2629 EXPECT_TRUE(service_->GetExtensionById(good0, false)); |
| 2663 } | 2630 } |
| 2664 | 2631 |
| 2665 // Tests that policy-installed extensions are not blacklisted by policy. | 2632 // Tests that policy-installed extensions are not blacklisted by policy. |
| 2666 TEST_F(ExtensionServiceTest, PolicyInstalledExtensionsWhitelisted) { | 2633 TEST_F(ExtensionServiceTest, PolicyInstalledExtensionsWhitelisted) { |
| 2667 InitializeEmptyExtensionService(); | 2634 InitializeEmptyExtensionService(); |
| 2668 | 2635 |
| 2669 // Blacklist everything. | 2636 // Blacklist everything. |
| 2670 { | 2637 { |
| 2671 ListPrefUpdate update(profile_->GetPrefs(), | 2638 ListPrefUpdate update(profile_->GetPrefs(), |
| 2672 prefs::kExtensionInstallDenyList); | 2639 prefs::kExtensionInstallDenyList); |
| 2673 ListValue* blacklist = update.Get(); | 2640 ListValue* blacklist = update.Get(); |
| 2674 blacklist->Append(Value::CreateStringValue("*")); | 2641 blacklist->Append(Value::CreateStringValue("*")); |
| 2675 } | 2642 } |
| 2676 | 2643 |
| 2677 // Have policy force-install an extension. | 2644 // Have policy force-install an extension. |
| 2678 MockExtensionProvider* provider = | 2645 MockExtensionProvider* provider = |
| 2679 new MockExtensionProvider(service_, | 2646 new MockExtensionProvider(service_, |
| 2680 Extension::EXTERNAL_POLICY_DOWNLOAD); | 2647 Extension::EXTERNAL_POLICY_DOWNLOAD); |
| 2681 AddMockExternalProvider(provider); | 2648 AddMockExternalProvider(provider); |
| 2682 provider->UpdateOrAddExtension(good_crx, "1.0.0.0", | 2649 provider->UpdateOrAddExtension(good_crx, "1.0.0.0", |
| 2683 data_dir_.AppendASCII("good.crx")); | 2650 data_dir_.AppendASCII("good.crx")); |
| 2684 | 2651 |
| 2685 // Reloading extensions should find our externally registered extension | 2652 // Reloading extensions should find our externally registered extension |
| 2686 // and install it. | 2653 // and install it. |
| 2687 service_->CheckForExternalUpdates(); | 2654 service_->CheckForExternalUpdates(); |
| 2688 loop_.RunAllPending(); | 2655 loop_.RunAllPending(); |
| 2689 | 2656 |
| 2690 // Extension should be installed despite blacklist. | 2657 // Extension should be installed despite blacklist. |
| 2691 ASSERT_EQ(1u, service_->extensions()->size()); | 2658 ASSERT_EQ(1u, service_->extensions()->size()); |
| 2692 EXPECT_EQ(good_crx, service_->extensions()->at(0)->id()); | 2659 EXPECT_TRUE(service_->GetExtensionById(good_crx, false)); |
| 2693 | 2660 |
| 2694 // Blacklist update should not uninstall the extension. | 2661 // Blacklist update should not uninstall the extension. |
| 2695 { | 2662 { |
| 2696 ListPrefUpdate update(profile_->GetPrefs(), | 2663 ListPrefUpdate update(profile_->GetPrefs(), |
| 2697 prefs::kExtensionInstallDenyList); | 2664 prefs::kExtensionInstallDenyList); |
| 2698 ListValue* blacklist = update.Get(); | 2665 ListValue* blacklist = update.Get(); |
| 2699 blacklist->Append(Value::CreateStringValue(good0)); | 2666 blacklist->Append(Value::CreateStringValue(good0)); |
| 2700 } | 2667 } |
| 2701 loop_.RunAllPending(); | 2668 loop_.RunAllPending(); |
| 2702 ASSERT_EQ(1u, service_->extensions()->size()); | 2669 ASSERT_EQ(1u, service_->extensions()->size()); |
| 2703 EXPECT_EQ(good_crx, service_->extensions()->at(0)->id()); | 2670 EXPECT_TRUE(service_->GetExtensionById(good_crx, false)); |
| 2704 } | 2671 } |
| 2705 | 2672 |
| 2706 // Tests disabling extensions | 2673 // Tests disabling extensions |
| 2707 TEST_F(ExtensionServiceTest, DisableExtension) { | 2674 TEST_F(ExtensionServiceTest, DisableExtension) { |
| 2708 InitializeEmptyExtensionService(); | 2675 InitializeEmptyExtensionService(); |
| 2709 | 2676 |
| 2710 InstallCrx(data_dir_.AppendASCII("good.crx"), true); | 2677 InstallCRX(data_dir_.AppendASCII("good.crx"), INSTALL_NEW); |
| 2711 EXPECT_FALSE(service_->extensions()->empty()); | 2678 EXPECT_FALSE(service_->extensions()->empty()); |
| 2712 EXPECT_TRUE(service_->GetExtensionById(good_crx, true) != NULL); | 2679 EXPECT_TRUE(service_->GetExtensionById(good_crx, true)); |
| 2713 EXPECT_TRUE(service_->GetExtensionById(good_crx, false) != NULL); | 2680 EXPECT_TRUE(service_->GetExtensionById(good_crx, false)); |
| 2714 EXPECT_TRUE(service_->disabled_extensions()->empty()); | 2681 EXPECT_TRUE(service_->disabled_extensions()->empty()); |
| 2715 | 2682 |
| 2716 // Disable it. | 2683 // Disable it. |
| 2717 service_->DisableExtension(good_crx); | 2684 service_->DisableExtension(good_crx); |
| 2718 | 2685 |
| 2719 EXPECT_TRUE(service_->extensions()->empty()); | 2686 EXPECT_TRUE(service_->extensions()->empty()); |
| 2720 EXPECT_TRUE(service_->GetExtensionById(good_crx, true) != NULL); | 2687 EXPECT_TRUE(service_->GetExtensionById(good_crx, true)); |
| 2721 EXPECT_FALSE(service_->GetExtensionById(good_crx, false) != NULL); | 2688 EXPECT_FALSE(service_->GetExtensionById(good_crx, false)); |
| 2722 EXPECT_FALSE(service_->disabled_extensions()->empty()); | 2689 EXPECT_FALSE(service_->disabled_extensions()->empty()); |
| 2723 } | 2690 } |
| 2724 | 2691 |
| 2725 TEST_F(ExtensionServiceTest, DisableTerminatedExtension) { | 2692 TEST_F(ExtensionServiceTest, DisableTerminatedExtension) { |
| 2726 InitializeEmptyExtensionService(); | 2693 InitializeEmptyExtensionService(); |
| 2727 | 2694 |
| 2728 InstallCrx(data_dir_.AppendASCII("good.crx"), true); | 2695 InstallCRX(data_dir_.AppendASCII("good.crx"), INSTALL_NEW); |
| 2729 TerminateExtension(good_crx); | 2696 TerminateExtension(good_crx); |
| 2730 EXPECT_TRUE(service_->GetTerminatedExtension(good_crx)); | 2697 EXPECT_TRUE(service_->GetTerminatedExtension(good_crx)); |
| 2731 | 2698 |
| 2732 // Disable it. | 2699 // Disable it. |
| 2733 service_->DisableExtension(good_crx); | 2700 service_->DisableExtension(good_crx); |
| 2734 | 2701 |
| 2735 EXPECT_FALSE(service_->GetTerminatedExtension(good_crx)); | 2702 EXPECT_FALSE(service_->GetTerminatedExtension(good_crx)); |
| 2736 EXPECT_TRUE(service_->GetExtensionById(good_crx, true) != NULL); | 2703 EXPECT_TRUE(service_->GetExtensionById(good_crx, true)); |
| 2737 EXPECT_FALSE(service_->disabled_extensions()->empty()); | 2704 EXPECT_FALSE(service_->disabled_extensions()->empty()); |
| 2738 } | 2705 } |
| 2739 | 2706 |
| 2740 // Tests disabling all extensions (simulating --disable-extensions flag). | 2707 // Tests disabling all extensions (simulating --disable-extensions flag). |
| 2741 TEST_F(ExtensionServiceTest, DisableAllExtensions) { | 2708 TEST_F(ExtensionServiceTest, DisableAllExtensions) { |
| 2742 InitializeEmptyExtensionService(); | 2709 InitializeEmptyExtensionService(); |
| 2743 | 2710 |
| 2744 | |
| 2745 FilePath path = data_dir_.AppendASCII("good.crx"); | 2711 FilePath path = data_dir_.AppendASCII("good.crx"); |
| 2746 InstallCrx(path, true); | 2712 InstallCRX(path, INSTALL_NEW); |
| 2747 | 2713 |
| 2748 EXPECT_EQ(1u, service_->extensions()->size()); | 2714 EXPECT_EQ(1u, service_->extensions()->size()); |
| 2749 EXPECT_EQ(0u, service_->disabled_extensions()->size()); | 2715 EXPECT_EQ(0u, service_->disabled_extensions()->size()); |
| 2750 | 2716 |
| 2751 // Disable extensions. | 2717 // Disable extensions. |
| 2752 service_->set_extensions_enabled(false); | 2718 service_->set_extensions_enabled(false); |
| 2753 service_->ReloadExtensions(); | 2719 service_->ReloadExtensions(); |
| 2754 | 2720 |
| 2755 // There shouldn't be extensions in either list. | 2721 // There shouldn't be extensions in either list. |
| 2756 EXPECT_EQ(0u, service_->extensions()->size()); | 2722 EXPECT_EQ(0u, service_->extensions()->size()); |
| 2757 EXPECT_EQ(0u, service_->disabled_extensions()->size()); | 2723 EXPECT_EQ(0u, service_->disabled_extensions()->size()); |
| 2758 | 2724 |
| 2759 // This shouldn't do anything when all extensions are disabled. | 2725 // This shouldn't do anything when all extensions are disabled. |
| 2760 service_->EnableExtension(good_crx); | 2726 service_->EnableExtension(good_crx); |
| 2761 service_->ReloadExtensions(); | 2727 service_->ReloadExtensions(); |
| 2762 | 2728 |
| 2763 // There still shouldn't be extensions in either list. | 2729 // There still shouldn't be extensions in either list. |
| 2764 EXPECT_EQ(0u, service_->extensions()->size()); | 2730 EXPECT_EQ(0u, service_->extensions()->size()); |
| 2765 EXPECT_EQ(0u, service_->disabled_extensions()->size()); | 2731 EXPECT_EQ(0u, service_->disabled_extensions()->size()); |
| 2766 | 2732 |
| 2767 // And then re-enable the extensions. | 2733 // And then re-enable the extensions. |
| 2768 service_->set_extensions_enabled(true); | 2734 service_->set_extensions_enabled(true); |
| 2769 service_->ReloadExtensions(); | 2735 service_->ReloadExtensions(); |
| 2770 | 2736 |
| 2771 EXPECT_EQ(1u, service_->extensions()->size()); | 2737 EXPECT_EQ(1u, service_->extensions()->size()); |
| 2772 EXPECT_EQ(0u, service_->disabled_extensions()->size()); | 2738 EXPECT_EQ(0u, service_->disabled_extensions()->size()); |
| 2773 } | 2739 } |
| 2774 | 2740 |
| 2775 // Tests reloading extensions | 2741 // Tests reloading extensions. |
| 2776 TEST_F(ExtensionServiceTest, ReloadExtensions) { | 2742 TEST_F(ExtensionServiceTest, ReloadExtensions) { |
| 2777 InitializeEmptyExtensionService(); | 2743 InitializeEmptyExtensionService(); |
| 2778 | 2744 |
| 2779 // Simple extension that should install without error. | 2745 // Simple extension that should install without error. |
| 2780 FilePath path = data_dir_.AppendASCII("good.crx"); | 2746 FilePath path = data_dir_.AppendASCII("good.crx"); |
| 2781 InstallCrx(path, true); | 2747 InstallCRX(path, INSTALL_NEW); |
| 2782 const char* extension_id = good_crx; | 2748 const char* extension_id = good_crx; |
| 2783 service_->DisableExtension(extension_id); | 2749 service_->DisableExtension(extension_id); |
| 2784 | 2750 |
| 2785 EXPECT_EQ(0u, service_->extensions()->size()); | 2751 EXPECT_EQ(0u, service_->extensions()->size()); |
| 2786 EXPECT_EQ(1u, service_->disabled_extensions()->size()); | 2752 EXPECT_EQ(1u, service_->disabled_extensions()->size()); |
| 2787 | 2753 |
| 2788 service_->ReloadExtensions(); | 2754 service_->ReloadExtensions(); |
| 2789 | 2755 |
| 2790 // Extension counts shouldn't change. | 2756 // Extension counts shouldn't change. |
| 2791 EXPECT_EQ(0u, service_->extensions()->size()); | 2757 EXPECT_EQ(0u, service_->extensions()->size()); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 2809 | 2775 |
| 2810 // Tests uninstalling normal extensions. | 2776 // Tests uninstalling normal extensions. |
| 2811 // Occasionally fails on Windows. See http://crbug.com/96296 | 2777 // Occasionally fails on Windows. See http://crbug.com/96296 |
| 2812 #if defined(OS_WIN) | 2778 #if defined(OS_WIN) |
| 2813 #define MAYBE_UninstallExtension FLAKY_UninstallExtension | 2779 #define MAYBE_UninstallExtension FLAKY_UninstallExtension |
| 2814 #else | 2780 #else |
| 2815 #define MAYBE_UninstallExtension UninstallExtension | 2781 #define MAYBE_UninstallExtension UninstallExtension |
| 2816 #endif | 2782 #endif |
| 2817 TEST_F(ExtensionServiceTest, MAYBE_UninstallExtension) { | 2783 TEST_F(ExtensionServiceTest, MAYBE_UninstallExtension) { |
| 2818 InitializeEmptyExtensionService(); | 2784 InitializeEmptyExtensionService(); |
| 2819 InstallCrx(data_dir_.AppendASCII("good.crx"), true); | 2785 InstallCRX(data_dir_.AppendASCII("good.crx"), INSTALL_NEW); |
| 2820 UninstallExtension(good_crx, false); | 2786 UninstallExtension(good_crx, false); |
| 2821 } | 2787 } |
| 2822 | 2788 |
| 2823 TEST_F(ExtensionServiceTest, UninstallTerminatedExtension) { | 2789 TEST_F(ExtensionServiceTest, UninstallTerminatedExtension) { |
| 2824 InitializeEmptyExtensionService(); | 2790 InitializeEmptyExtensionService(); |
| 2825 InstallCrx(data_dir_.AppendASCII("good.crx"), true); | 2791 InstallCRX(data_dir_.AppendASCII("good.crx"), INSTALL_NEW); |
| 2826 TerminateExtension(good_crx); | 2792 TerminateExtension(good_crx); |
| 2827 UninstallExtension(good_crx, false); | 2793 UninstallExtension(good_crx, false); |
| 2828 } | 2794 } |
| 2829 | 2795 |
| 2830 // Tests the uninstaller helper. | 2796 // Tests the uninstaller helper. |
| 2831 TEST_F(ExtensionServiceTest, UninstallExtensionHelper) { | 2797 TEST_F(ExtensionServiceTest, UninstallExtensionHelper) { |
| 2832 InitializeEmptyExtensionService(); | 2798 InitializeEmptyExtensionService(); |
| 2833 InstallCrx(data_dir_.AppendASCII("good.crx"), true); | 2799 InstallCRX(data_dir_.AppendASCII("good.crx"), INSTALL_NEW); |
| 2834 UninstallExtension(good_crx, true); | 2800 UninstallExtension(good_crx, true); |
| 2835 } | 2801 } |
| 2836 | 2802 |
| 2837 TEST_F(ExtensionServiceTest, UninstallExtensionHelperTerminated) { | 2803 TEST_F(ExtensionServiceTest, UninstallExtensionHelperTerminated) { |
| 2838 InitializeEmptyExtensionService(); | 2804 InitializeEmptyExtensionService(); |
| 2839 InstallCrx(data_dir_.AppendASCII("good.crx"), true); | 2805 InstallCRX(data_dir_.AppendASCII("good.crx"), INSTALL_NEW); |
| 2840 TerminateExtension(good_crx); | 2806 TerminateExtension(good_crx); |
| 2841 UninstallExtension(good_crx, true); | 2807 UninstallExtension(good_crx, true); |
| 2842 } | 2808 } |
| 2843 | 2809 |
| 2844 class ExtensionCookieCallback { | 2810 class ExtensionCookieCallback { |
| 2845 public: | 2811 public: |
| 2846 ExtensionCookieCallback() | 2812 ExtensionCookieCallback() |
| 2847 : result_(false), | 2813 : result_(false), |
| 2848 message_loop_factory_(MessageLoop::current()) {} | 2814 message_loop_factory_(MessageLoop::current()) {} |
| 2849 | 2815 |
| (...skipping 16 matching lines...) Expand all Loading... |
| 2866 }; | 2832 }; |
| 2867 | 2833 |
| 2868 // Verifies extension state is removed upon uninstall. | 2834 // Verifies extension state is removed upon uninstall. |
| 2869 TEST_F(ExtensionServiceTest, ClearExtensionData) { | 2835 TEST_F(ExtensionServiceTest, ClearExtensionData) { |
| 2870 InitializeEmptyExtensionService(); | 2836 InitializeEmptyExtensionService(); |
| 2871 ExtensionCookieCallback callback; | 2837 ExtensionCookieCallback callback; |
| 2872 | 2838 |
| 2873 // Load a test extension. | 2839 // Load a test extension. |
| 2874 FilePath path = data_dir_; | 2840 FilePath path = data_dir_; |
| 2875 path = path.AppendASCII("good.crx"); | 2841 path = path.AppendASCII("good.crx"); |
| 2876 InstallCrx(path, true); | 2842 const Extension* extension = InstallCRX(path, INSTALL_NEW); |
| 2877 const Extension* extension = service_->GetExtensionById(good_crx, false); | |
| 2878 ASSERT_TRUE(extension); | 2843 ASSERT_TRUE(extension); |
| 2879 GURL ext_url(extension->url()); | 2844 GURL ext_url(extension->url()); |
| 2880 string16 origin_id = | 2845 string16 origin_id = |
| 2881 webkit_database::DatabaseUtil::GetOriginIdentifier(ext_url); | 2846 webkit_database::DatabaseUtil::GetOriginIdentifier(ext_url); |
| 2882 | 2847 |
| 2883 // Set a cookie for the extension. | 2848 // Set a cookie for the extension. |
| 2884 net::CookieMonster* cookie_monster = | 2849 net::CookieMonster* cookie_monster = |
| 2885 profile_->GetRequestContextForExtensions()->GetURLRequestContext()-> | 2850 profile_->GetRequestContextForExtensions()->GetURLRequestContext()-> |
| 2886 cookie_store()->GetCookieMonster(); | 2851 cookie_store()->GetCookieMonster(); |
| 2887 ASSERT_TRUE(cookie_monster); | 2852 ASSERT_TRUE(cookie_monster); |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2955 | 2920 |
| 2956 // Verifies app state is removed upon uninstall. | 2921 // Verifies app state is removed upon uninstall. |
| 2957 TEST_F(ExtensionServiceTest, ClearAppData) { | 2922 TEST_F(ExtensionServiceTest, ClearAppData) { |
| 2958 InitializeEmptyExtensionService(); | 2923 InitializeEmptyExtensionService(); |
| 2959 InitializeRequestContext(); | 2924 InitializeRequestContext(); |
| 2960 ExtensionCookieCallback callback; | 2925 ExtensionCookieCallback callback; |
| 2961 | 2926 |
| 2962 int pref_count = 0; | 2927 int pref_count = 0; |
| 2963 | 2928 |
| 2964 // Install app1 with unlimited storage. | 2929 // Install app1 with unlimited storage. |
| 2965 PackAndInstallCrx(data_dir_.AppendASCII("app1"), true); | 2930 const Extension* extension = |
| 2931 PackAndInstallCRX(data_dir_.AppendASCII("app1"), INSTALL_NEW); |
| 2966 ValidatePrefKeyCount(++pref_count); | 2932 ValidatePrefKeyCount(++pref_count); |
| 2967 ASSERT_EQ(1u, service_->extensions()->size()); | 2933 ASSERT_EQ(1u, service_->extensions()->size()); |
| 2968 const Extension* extension = service_->extensions()->at(0); | |
| 2969 const std::string id1 = extension->id(); | 2934 const std::string id1 = extension->id(); |
| 2970 EXPECT_TRUE(extension->HasAPIPermission( | 2935 EXPECT_TRUE(extension->HasAPIPermission( |
| 2971 ExtensionAPIPermission::kUnlimitedStorage)); | 2936 ExtensionAPIPermission::kUnlimitedStorage)); |
| 2972 const GURL origin1(extension->GetFullLaunchURL().GetOrigin()); | 2937 const GURL origin1(extension->GetFullLaunchURL().GetOrigin()); |
| 2973 EXPECT_TRUE(profile_->GetExtensionSpecialStoragePolicy()-> | 2938 EXPECT_TRUE(profile_->GetExtensionSpecialStoragePolicy()-> |
| 2974 IsStorageUnlimited(origin1)); | 2939 IsStorageUnlimited(origin1)); |
| 2975 string16 origin_id = | 2940 string16 origin_id = |
| 2976 webkit_database::DatabaseUtil::GetOriginIdentifier(origin1); | 2941 webkit_database::DatabaseUtil::GetOriginIdentifier(origin1); |
| 2977 | 2942 |
| 2978 // Install app2 from the same origin with unlimited storage. | 2943 // Install app2 from the same origin with unlimited storage. |
| 2979 PackAndInstallCrx(data_dir_.AppendASCII("app2"), true); | 2944 extension = PackAndInstallCRX(data_dir_.AppendASCII("app2"), INSTALL_NEW); |
| 2980 ValidatePrefKeyCount(++pref_count); | 2945 ValidatePrefKeyCount(++pref_count); |
| 2981 ASSERT_EQ(2u, service_->extensions()->size()); | 2946 ASSERT_EQ(2u, service_->extensions()->size()); |
| 2982 extension = service_->extensions()->at(1); | |
| 2983 const std::string id2 = extension->id(); | 2947 const std::string id2 = extension->id(); |
| 2984 EXPECT_TRUE(extension->HasAPIPermission( | 2948 EXPECT_TRUE(extension->HasAPIPermission( |
| 2985 ExtensionAPIPermission::kUnlimitedStorage)); | 2949 ExtensionAPIPermission::kUnlimitedStorage)); |
| 2986 EXPECT_TRUE(extension->web_extent().MatchesURL( | 2950 EXPECT_TRUE(extension->web_extent().MatchesURL( |
| 2987 extension->GetFullLaunchURL())); | 2951 extension->GetFullLaunchURL())); |
| 2988 const GURL origin2(extension->GetFullLaunchURL().GetOrigin()); | 2952 const GURL origin2(extension->GetFullLaunchURL().GetOrigin()); |
| 2989 EXPECT_EQ(origin1, origin2); | 2953 EXPECT_EQ(origin1, origin2); |
| 2990 EXPECT_TRUE(profile_->GetExtensionSpecialStoragePolicy()-> | 2954 EXPECT_TRUE(profile_->GetExtensionSpecialStoragePolicy()-> |
| 2991 IsStorageUnlimited(origin2)); | 2955 IsStorageUnlimited(origin2)); |
| 2992 | 2956 |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3117 EXPECT_EQ(id, unloaded_id_); | 3081 EXPECT_EQ(id, unloaded_id_); |
| 3118 ASSERT_EQ(0u, loaded_.size()); | 3082 ASSERT_EQ(0u, loaded_.size()); |
| 3119 EXPECT_EQ(0u, service_->extensions()->size()); | 3083 EXPECT_EQ(0u, service_->extensions()->size()); |
| 3120 } | 3084 } |
| 3121 | 3085 |
| 3122 // Tests that we generate IDs when they are not specified in the manifest for | 3086 // Tests that we generate IDs when they are not specified in the manifest for |
| 3123 // --load-extension. | 3087 // --load-extension. |
| 3124 TEST_F(ExtensionServiceTest, GenerateID) { | 3088 TEST_F(ExtensionServiceTest, GenerateID) { |
| 3125 InitializeEmptyExtensionService(); | 3089 InitializeEmptyExtensionService(); |
| 3126 | 3090 |
| 3127 | |
| 3128 FilePath no_id_ext = data_dir_.AppendASCII("no_id"); | 3091 FilePath no_id_ext = data_dir_.AppendASCII("no_id"); |
| 3129 extensions::UnpackedInstaller::Create(service_)->Load(no_id_ext); | 3092 extensions::UnpackedInstaller::Create(service_)->Load(no_id_ext); |
| 3130 loop_.RunAllPending(); | 3093 loop_.RunAllPending(); |
| 3131 EXPECT_EQ(0u, GetErrors().size()); | 3094 EXPECT_EQ(0u, GetErrors().size()); |
| 3132 ASSERT_EQ(1u, loaded_.size()); | 3095 ASSERT_EQ(1u, loaded_.size()); |
| 3133 ASSERT_TRUE(Extension::IdIsValid(loaded_[0]->id())); | 3096 ASSERT_TRUE(Extension::IdIsValid(loaded_[0]->id())); |
| 3134 EXPECT_EQ(loaded_[0]->location(), Extension::LOAD); | 3097 EXPECT_EQ(loaded_[0]->location(), Extension::LOAD); |
| 3135 | 3098 |
| 3136 ValidatePrefKeyCount(1); | 3099 ValidatePrefKeyCount(1); |
| 3137 | 3100 |
| 3138 std::string previous_id = loaded_[0]->id(); | 3101 std::string previous_id = loaded_[0]->id(); |
| 3139 | 3102 |
| 3140 // If we reload the same path, we should get the same extension ID. | 3103 // If we reload the same path, we should get the same extension ID. |
| 3141 extensions::UnpackedInstaller::Create(service_)->Load(no_id_ext); | 3104 extensions::UnpackedInstaller::Create(service_)->Load(no_id_ext); |
| 3142 loop_.RunAllPending(); | 3105 loop_.RunAllPending(); |
| 3143 ASSERT_EQ(1u, loaded_.size()); | 3106 ASSERT_EQ(1u, loaded_.size()); |
| 3144 ASSERT_EQ(previous_id, loaded_[0]->id()); | 3107 ASSERT_EQ(previous_id, loaded_[0]->id()); |
| 3145 } | 3108 } |
| 3146 | 3109 |
| 3147 void ExtensionServiceTest::TestExternalProvider( | 3110 void ExtensionServiceTest::TestExternalProvider( |
| 3148 MockExtensionProvider* provider, Extension::Location location) { | 3111 MockExtensionProvider* provider, Extension::Location location) { |
| 3149 // Verify that starting with no providers loads no extensions. | 3112 // Verify that starting with no providers loads no extensions. |
| 3150 service_->Init(); | 3113 service_->Init(); |
| 3151 loop_.RunAllPending(); | |
| 3152 ASSERT_EQ(0u, loaded_.size()); | 3114 ASSERT_EQ(0u, loaded_.size()); |
| 3153 | 3115 |
| 3154 provider->set_visit_count(0); | 3116 provider->set_visit_count(0); |
| 3155 | 3117 |
| 3156 // Register a test extension externally using the mock registry provider. | 3118 // Register a test extension externally using the mock registry provider. |
| 3157 FilePath source_path = data_dir_.AppendASCII("good.crx"); | 3119 FilePath source_path = data_dir_.AppendASCII("good.crx"); |
| 3158 | 3120 |
| 3159 // Add the extension. | 3121 // Add the extension. |
| 3160 provider->UpdateOrAddExtension(good_crx, "1.0.0.0", source_path); | 3122 provider->UpdateOrAddExtension(good_crx, "1.0.0.0", source_path); |
| 3161 | 3123 |
| (...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3351 .AppendASCII("Extensions"); | 3313 .AppendASCII("Extensions"); |
| 3352 FilePath pref_path = source_install_dir | 3314 FilePath pref_path = source_install_dir |
| 3353 .DirName() | 3315 .DirName() |
| 3354 .AppendASCII("PreferencesExternal"); | 3316 .AppendASCII("PreferencesExternal"); |
| 3355 | 3317 |
| 3356 // This initializes the extensions service with no ExternalExtensionProviders. | 3318 // This initializes the extensions service with no ExternalExtensionProviders. |
| 3357 InitializeInstalledExtensionService(pref_path, source_install_dir); | 3319 InitializeInstalledExtensionService(pref_path, source_install_dir); |
| 3358 set_extensions_enabled(false); | 3320 set_extensions_enabled(false); |
| 3359 | 3321 |
| 3360 service_->Init(); | 3322 service_->Init(); |
| 3361 loop_.RunAllPending(); | |
| 3362 | 3323 |
| 3363 ASSERT_EQ(0u, GetErrors().size()); | 3324 ASSERT_EQ(0u, GetErrors().size()); |
| 3364 ASSERT_EQ(0u, loaded_.size()); | 3325 ASSERT_EQ(0u, loaded_.size()); |
| 3365 | 3326 |
| 3366 // Verify that it's not the disabled extensions flag causing it not to load. | 3327 // Verify that it's not the disabled extensions flag causing it not to load. |
| 3367 set_extensions_enabled(true); | 3328 set_extensions_enabled(true); |
| 3368 service_->ReloadExtensions(); | 3329 service_->ReloadExtensions(); |
| 3369 loop_.RunAllPending(); | 3330 loop_.RunAllPending(); |
| 3370 | 3331 |
| 3371 ASSERT_EQ(0u, GetErrors().size()); | 3332 ASSERT_EQ(0u, GetErrors().size()); |
| 3372 ASSERT_EQ(0u, loaded_.size()); | 3333 ASSERT_EQ(0u, loaded_.size()); |
| 3373 } | 3334 } |
| 3374 | 3335 |
| 3375 // Test that running multiple update checks simultaneously does not | 3336 // Test that running multiple update checks simultaneously does not |
| 3376 // keep the update from succeeding. | 3337 // keep the update from succeeding. |
| 3377 TEST_F(ExtensionServiceTest, MultipleExternalUpdateCheck) { | 3338 TEST_F(ExtensionServiceTest, MultipleExternalUpdateCheck) { |
| 3378 InitializeEmptyExtensionService(); | 3339 InitializeEmptyExtensionService(); |
| 3379 | 3340 |
| 3380 MockExtensionProvider* provider = | 3341 MockExtensionProvider* provider = |
| 3381 new MockExtensionProvider(service_, Extension::EXTERNAL_PREF); | 3342 new MockExtensionProvider(service_, Extension::EXTERNAL_PREF); |
| 3382 AddMockExternalProvider(provider); | 3343 AddMockExternalProvider(provider); |
| 3383 | 3344 |
| 3384 // Verify that starting with no providers loads no extensions. | 3345 // Verify that starting with no providers loads no extensions. |
| 3385 service_->Init(); | 3346 service_->Init(); |
| 3386 loop_.RunAllPending(); | |
| 3387 ASSERT_EQ(0u, loaded_.size()); | 3347 ASSERT_EQ(0u, loaded_.size()); |
| 3388 | 3348 |
| 3389 // Start two checks for updates. | 3349 // Start two checks for updates. |
| 3390 provider->set_visit_count(0); | 3350 provider->set_visit_count(0); |
| 3391 service_->CheckForExternalUpdates(); | 3351 service_->CheckForExternalUpdates(); |
| 3392 service_->CheckForExternalUpdates(); | 3352 service_->CheckForExternalUpdates(); |
| 3393 loop_.RunAllPending(); | 3353 loop_.RunAllPending(); |
| 3394 | 3354 |
| 3395 // Two calls should cause two checks for external extensions. | 3355 // Two calls should cause two checks for external extensions. |
| 3396 EXPECT_EQ(2, provider->visit_count()); | 3356 EXPECT_EQ(2, provider->visit_count()); |
| (...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3577 | 3537 |
| 3578 // Test loading good extensions from the profile directory. | 3538 // Test loading good extensions from the profile directory. |
| 3579 TEST_F(ExtensionServiceTest, LoadAndRelocalizeExtensions) { | 3539 TEST_F(ExtensionServiceTest, LoadAndRelocalizeExtensions) { |
| 3580 // Initialize the test dir with a good Preferences/extensions. | 3540 // Initialize the test dir with a good Preferences/extensions. |
| 3581 FilePath source_install_dir = data_dir_ | 3541 FilePath source_install_dir = data_dir_ |
| 3582 .AppendASCII("l10n"); | 3542 .AppendASCII("l10n"); |
| 3583 FilePath pref_path = source_install_dir.AppendASCII("Preferences"); | 3543 FilePath pref_path = source_install_dir.AppendASCII("Preferences"); |
| 3584 InitializeInstalledExtensionService(pref_path, source_install_dir); | 3544 InitializeInstalledExtensionService(pref_path, source_install_dir); |
| 3585 | 3545 |
| 3586 service_->Init(); | 3546 service_->Init(); |
| 3587 loop_.RunAllPending(); | |
| 3588 | 3547 |
| 3589 ASSERT_EQ(3u, loaded_.size()); | 3548 ASSERT_EQ(3u, loaded_.size()); |
| 3590 | 3549 |
| 3591 // This was equal to "sr" on load. | 3550 // This was equal to "sr" on load. |
| 3592 ValidateStringPref(loaded_[0]->id(), keys::kCurrentLocale, "en"); | 3551 ValidateStringPref(loaded_[0]->id(), keys::kCurrentLocale, "en"); |
| 3593 | 3552 |
| 3594 // These are untouched by re-localization. | 3553 // These are untouched by re-localization. |
| 3595 ValidateStringPref(loaded_[1]->id(), keys::kCurrentLocale, "en"); | 3554 ValidateStringPref(loaded_[1]->id(), keys::kCurrentLocale, "en"); |
| 3596 EXPECT_FALSE(IsPrefExist(loaded_[1]->id(), keys::kCurrentLocale)); | 3555 EXPECT_FALSE(IsPrefExist(loaded_[1]->id(), keys::kCurrentLocale)); |
| 3597 | 3556 |
| (...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3759 | 3718 |
| 3760 EXPECT_EQ(0u, GetErrors().size()); | 3719 EXPECT_EQ(0u, GetErrors().size()); |
| 3761 ASSERT_EQ(1u, loaded_.size()); | 3720 ASSERT_EQ(1u, loaded_.size()); |
| 3762 EXPECT_EQ(Extension::COMPONENT, loaded_[0]->location()); | 3721 EXPECT_EQ(Extension::COMPONENT, loaded_[0]->location()); |
| 3763 EXPECT_EQ(1u, service_->extensions()->size()); | 3722 EXPECT_EQ(1u, service_->extensions()->size()); |
| 3764 | 3723 |
| 3765 // Component extensions shouldn't get recorded in the prefs. | 3724 // Component extensions shouldn't get recorded in the prefs. |
| 3766 ValidatePrefKeyCount(0); | 3725 ValidatePrefKeyCount(0); |
| 3767 | 3726 |
| 3768 // Reload all extensions, and make sure it comes back. | 3727 // Reload all extensions, and make sure it comes back. |
| 3769 std::string extension_id = service_->extensions()->at(0)->id(); | 3728 std::string extension_id = (*service_->extensions()->begin())->id(); |
| 3770 loaded_.clear(); | 3729 loaded_.clear(); |
| 3771 service_->ReloadExtensions(); | 3730 service_->ReloadExtensions(); |
| 3772 ASSERT_EQ(1u, service_->extensions()->size()); | 3731 ASSERT_EQ(1u, service_->extensions()->size()); |
| 3773 EXPECT_EQ(extension_id, service_->extensions()->at(0)->id()); | 3732 EXPECT_EQ(extension_id, (*service_->extensions()->begin())->id()); |
| 3774 } | 3733 } |
| 3775 | 3734 |
| 3776 namespace { | 3735 namespace { |
| 3777 class TestSyncProcessorStub : public SyncChangeProcessor { | 3736 class TestSyncProcessorStub : public SyncChangeProcessor { |
| 3778 virtual SyncError ProcessSyncChanges( | 3737 virtual SyncError ProcessSyncChanges( |
| 3779 const tracked_objects::Location& from_here, | 3738 const tracked_objects::Location& from_here, |
| 3780 const SyncChangeList& change_list) OVERRIDE { | 3739 const SyncChangeList& change_list) OVERRIDE { |
| 3781 return SyncError(); | 3740 return SyncError(); |
| 3782 } | 3741 } |
| 3783 }; | 3742 }; |
| 3784 } | 3743 } |
| 3785 | 3744 |
| 3786 TEST_F(ExtensionServiceTest, GetSyncData) { | 3745 TEST_F(ExtensionServiceTest, GetSyncData) { |
| 3787 InitializeEmptyExtensionService(); | 3746 InitializeEmptyExtensionService(); |
| 3788 InstallCrx(data_dir_.AppendASCII("good.crx"), true); | 3747 InstallCRX(data_dir_.AppendASCII("good.crx"), INSTALL_NEW); |
| 3789 const Extension* extension = service_->GetInstalledExtension(good_crx); | 3748 const Extension* extension = service_->GetInstalledExtension(good_crx); |
| 3790 ASSERT_TRUE(extension); | 3749 ASSERT_TRUE(extension); |
| 3791 | 3750 |
| 3792 TestSyncProcessorStub processor; | 3751 TestSyncProcessorStub processor; |
| 3793 service_->MergeDataAndStartSyncing(syncable::EXTENSIONS, SyncDataList(), | 3752 service_->MergeDataAndStartSyncing(syncable::EXTENSIONS, SyncDataList(), |
| 3794 &processor); | 3753 &processor); |
| 3795 | 3754 |
| 3796 SyncDataList list = service_->GetAllSyncData(syncable::EXTENSIONS); | 3755 SyncDataList list = service_->GetAllSyncData(syncable::EXTENSIONS); |
| 3797 ASSERT_EQ(list.size(), 1U); | 3756 ASSERT_EQ(list.size(), 1U); |
| 3798 ExtensionSyncData data(list[0]); | 3757 ExtensionSyncData data(list[0]); |
| 3799 EXPECT_EQ(extension->id(), data.id()); | 3758 EXPECT_EQ(extension->id(), data.id()); |
| 3800 EXPECT_FALSE(data.uninstalled()); | 3759 EXPECT_FALSE(data.uninstalled()); |
| 3801 EXPECT_EQ(service_->IsExtensionEnabled(good_crx), data.enabled()); | 3760 EXPECT_EQ(service_->IsExtensionEnabled(good_crx), data.enabled()); |
| 3802 EXPECT_EQ(service_->IsIncognitoEnabled(good_crx), data.incognito_enabled()); | 3761 EXPECT_EQ(service_->IsIncognitoEnabled(good_crx), data.incognito_enabled()); |
| 3803 EXPECT_TRUE(data.version().Equals(*extension->version())); | 3762 EXPECT_TRUE(data.version().Equals(*extension->version())); |
| 3804 EXPECT_EQ(extension->update_url(), data.update_url()); | 3763 EXPECT_EQ(extension->update_url(), data.update_url()); |
| 3805 EXPECT_EQ(extension->name(), data.name()); | 3764 EXPECT_EQ(extension->name(), data.name()); |
| 3806 } | 3765 } |
| 3807 | 3766 |
| 3808 TEST_F(ExtensionServiceTest, GetSyncDataTerminated) { | 3767 TEST_F(ExtensionServiceTest, GetSyncDataTerminated) { |
| 3809 InitializeEmptyExtensionService(); | 3768 InitializeEmptyExtensionService(); |
| 3810 InstallCrx(data_dir_.AppendASCII("good.crx"), true); | 3769 InstallCRX(data_dir_.AppendASCII("good.crx"), INSTALL_NEW); |
| 3811 TerminateExtension(good_crx); | 3770 TerminateExtension(good_crx); |
| 3812 const Extension* extension = service_->GetInstalledExtension(good_crx); | 3771 const Extension* extension = service_->GetInstalledExtension(good_crx); |
| 3813 ASSERT_TRUE(extension); | 3772 ASSERT_TRUE(extension); |
| 3814 | 3773 |
| 3815 TestSyncProcessorStub processor; | 3774 TestSyncProcessorStub processor; |
| 3816 service_->MergeDataAndStartSyncing(syncable::EXTENSIONS, SyncDataList(), | 3775 service_->MergeDataAndStartSyncing(syncable::EXTENSIONS, SyncDataList(), |
| 3817 &processor); | 3776 &processor); |
| 3818 | 3777 |
| 3819 SyncDataList list = service_->GetAllSyncData(syncable::EXTENSIONS); | 3778 SyncDataList list = service_->GetAllSyncData(syncable::EXTENSIONS); |
| 3820 ASSERT_EQ(list.size(), 1U); | 3779 ASSERT_EQ(list.size(), 1U); |
| 3821 ExtensionSyncData data(list[0]); | 3780 ExtensionSyncData data(list[0]); |
| 3822 EXPECT_EQ(extension->id(), data.id()); | 3781 EXPECT_EQ(extension->id(), data.id()); |
| 3823 EXPECT_FALSE(data.uninstalled()); | 3782 EXPECT_FALSE(data.uninstalled()); |
| 3824 EXPECT_EQ(service_->IsExtensionEnabled(good_crx), data.enabled()); | 3783 EXPECT_EQ(service_->IsExtensionEnabled(good_crx), data.enabled()); |
| 3825 EXPECT_EQ(service_->IsIncognitoEnabled(good_crx), data.incognito_enabled()); | 3784 EXPECT_EQ(service_->IsIncognitoEnabled(good_crx), data.incognito_enabled()); |
| 3826 EXPECT_TRUE(data.version().Equals(*extension->version())); | 3785 EXPECT_TRUE(data.version().Equals(*extension->version())); |
| 3827 EXPECT_EQ(extension->update_url(), data.update_url()); | 3786 EXPECT_EQ(extension->update_url(), data.update_url()); |
| 3828 EXPECT_EQ(extension->name(), data.name()); | 3787 EXPECT_EQ(extension->name(), data.name()); |
| 3829 } | 3788 } |
| 3830 | 3789 |
| 3831 TEST_F(ExtensionServiceTest, GetSyncDataFilter) { | 3790 TEST_F(ExtensionServiceTest, GetSyncDataFilter) { |
| 3832 InitializeEmptyExtensionService(); | 3791 InitializeEmptyExtensionService(); |
| 3833 InstallCrx(data_dir_.AppendASCII("good.crx"), true); | 3792 InstallCRX(data_dir_.AppendASCII("good.crx"), INSTALL_NEW); |
| 3834 const Extension* extension = service_->GetInstalledExtension(good_crx); | 3793 const Extension* extension = service_->GetInstalledExtension(good_crx); |
| 3835 ASSERT_TRUE(extension); | 3794 ASSERT_TRUE(extension); |
| 3836 | 3795 |
| 3837 TestSyncProcessorStub processor; | 3796 TestSyncProcessorStub processor; |
| 3838 service_->MergeDataAndStartSyncing(syncable::APPS, SyncDataList(), | 3797 service_->MergeDataAndStartSyncing(syncable::APPS, SyncDataList(), |
| 3839 &processor); | 3798 &processor); |
| 3840 | 3799 |
| 3841 SyncDataList list = service_->GetAllSyncData(syncable::EXTENSIONS); | 3800 SyncDataList list = service_->GetAllSyncData(syncable::EXTENSIONS); |
| 3842 ASSERT_EQ(list.size(), 0U); | 3801 ASSERT_EQ(list.size(), 0U); |
| 3843 } | 3802 } |
| 3844 | 3803 |
| 3845 TEST_F(ExtensionServiceTest, GetSyncDataUserSettings) { | 3804 TEST_F(ExtensionServiceTest, GetSyncDataUserSettings) { |
| 3846 InitializeEmptyExtensionService(); | 3805 InitializeEmptyExtensionService(); |
| 3847 InstallCrx(data_dir_.AppendASCII("good.crx"), true); | 3806 InstallCRX(data_dir_.AppendASCII("good.crx"), INSTALL_NEW); |
| 3848 const Extension* extension = service_->GetInstalledExtension(good_crx); | 3807 const Extension* extension = service_->GetInstalledExtension(good_crx); |
| 3849 ASSERT_TRUE(extension); | 3808 ASSERT_TRUE(extension); |
| 3850 | 3809 |
| 3851 TestSyncProcessorStub processor; | 3810 TestSyncProcessorStub processor; |
| 3852 service_->MergeDataAndStartSyncing(syncable::EXTENSIONS, SyncDataList(), | 3811 service_->MergeDataAndStartSyncing(syncable::EXTENSIONS, SyncDataList(), |
| 3853 &processor); | 3812 &processor); |
| 3854 | 3813 |
| 3855 { | 3814 { |
| 3856 SyncDataList list = service_->GetAllSyncData(syncable::EXTENSIONS); | 3815 SyncDataList list = service_->GetAllSyncData(syncable::EXTENSIONS); |
| 3857 ASSERT_EQ(list.size(), 1U); | 3816 ASSERT_EQ(list.size(), 1U); |
| (...skipping 25 matching lines...) Expand all Loading... |
| 3883 SyncDataList list = service_->GetAllSyncData(syncable::EXTENSIONS); | 3842 SyncDataList list = service_->GetAllSyncData(syncable::EXTENSIONS); |
| 3884 ASSERT_EQ(list.size(), 1U); | 3843 ASSERT_EQ(list.size(), 1U); |
| 3885 ExtensionSyncData data(list[0]); | 3844 ExtensionSyncData data(list[0]); |
| 3886 EXPECT_TRUE(data.enabled()); | 3845 EXPECT_TRUE(data.enabled()); |
| 3887 EXPECT_TRUE(data.incognito_enabled()); | 3846 EXPECT_TRUE(data.incognito_enabled()); |
| 3888 } | 3847 } |
| 3889 } | 3848 } |
| 3890 | 3849 |
| 3891 TEST_F(ExtensionServiceTest, GetSyncDataList) { | 3850 TEST_F(ExtensionServiceTest, GetSyncDataList) { |
| 3892 InitializeEmptyExtensionService(); | 3851 InitializeEmptyExtensionService(); |
| 3893 InstallCrx(data_dir_.AppendASCII("good.crx"), true); | 3852 InstallCRX(data_dir_.AppendASCII("good.crx"), INSTALL_NEW); |
| 3894 InstallCrx(data_dir_.AppendASCII("page_action.crx"), true); | 3853 InstallCRX(data_dir_.AppendASCII("page_action.crx"), INSTALL_NEW); |
| 3895 InstallCrx(data_dir_.AppendASCII("theme.crx"), true); | 3854 InstallCRX(data_dir_.AppendASCII("theme.crx"), INSTALL_NEW); |
| 3896 InstallCrx(data_dir_.AppendASCII("theme2.crx"), true); | 3855 InstallCRX(data_dir_.AppendASCII("theme2.crx"), INSTALL_NEW); |
| 3897 | 3856 |
| 3898 TestSyncProcessorStub processor; | 3857 TestSyncProcessorStub processor; |
| 3899 service_->MergeDataAndStartSyncing(syncable::APPS, SyncDataList(), | 3858 service_->MergeDataAndStartSyncing(syncable::APPS, SyncDataList(), |
| 3900 &processor); | 3859 &processor); |
| 3901 service_->MergeDataAndStartSyncing(syncable::EXTENSIONS, SyncDataList(), | 3860 service_->MergeDataAndStartSyncing(syncable::EXTENSIONS, SyncDataList(), |
| 3902 &processor); | 3861 &processor); |
| 3903 | 3862 |
| 3904 service_->DisableExtension(page_action); | 3863 service_->DisableExtension(page_action); |
| 3905 TerminateExtension(theme2_crx); | 3864 TerminateExtension(theme2_crx); |
| 3906 | 3865 |
| (...skipping 16 matching lines...) Expand all Loading... |
| 3923 SyncChange sync_change(SyncChange::ACTION_DELETE, sync_data); | 3882 SyncChange sync_change(SyncChange::ACTION_DELETE, sync_data); |
| 3924 SyncChangeList list(1); | 3883 SyncChangeList list(1); |
| 3925 list[0] = sync_change; | 3884 list[0] = sync_change; |
| 3926 | 3885 |
| 3927 // Should do nothing. | 3886 // Should do nothing. |
| 3928 service_->ProcessSyncChanges(FROM_HERE, list); | 3887 service_->ProcessSyncChanges(FROM_HERE, list); |
| 3929 EXPECT_FALSE(service_->GetExtensionById(good_crx, true)); | 3888 EXPECT_FALSE(service_->GetExtensionById(good_crx, true)); |
| 3930 | 3889 |
| 3931 // Install the extension. | 3890 // Install the extension. |
| 3932 FilePath extension_path = data_dir_.AppendASCII("good.crx"); | 3891 FilePath extension_path = data_dir_.AppendASCII("good.crx"); |
| 3933 InstallCrx(extension_path, true); | 3892 InstallCRX(extension_path, INSTALL_NEW); |
| 3934 EXPECT_TRUE(service_->GetExtensionById(good_crx, true)); | 3893 EXPECT_TRUE(service_->GetExtensionById(good_crx, true)); |
| 3935 | 3894 |
| 3936 // Should uninstall the extension. | 3895 // Should uninstall the extension. |
| 3937 service_->ProcessSyncChanges(FROM_HERE, list); | 3896 service_->ProcessSyncChanges(FROM_HERE, list); |
| 3938 EXPECT_FALSE(service_->GetExtensionById(good_crx, true)); | 3897 EXPECT_FALSE(service_->GetExtensionById(good_crx, true)); |
| 3939 | 3898 |
| 3940 // Should again do nothing. | 3899 // Should again do nothing. |
| 3941 service_->ProcessSyncChanges(FROM_HERE, list); | 3900 service_->ProcessSyncChanges(FROM_HERE, list); |
| 3942 EXPECT_FALSE(service_->GetExtensionById(good_crx, true)); | 3901 EXPECT_FALSE(service_->GetExtensionById(good_crx, true)); |
| 3943 } | 3902 } |
| 3944 | 3903 |
| 3945 TEST_F(ExtensionServiceTest, ProcessSyncDataWrongType) { | 3904 TEST_F(ExtensionServiceTest, ProcessSyncDataWrongType) { |
| 3946 InitializeEmptyExtensionService(); | 3905 InitializeEmptyExtensionService(); |
| 3947 | 3906 |
| 3948 // Install the extension. | 3907 // Install the extension. |
| 3949 FilePath extension_path = data_dir_.AppendASCII("good.crx"); | 3908 FilePath extension_path = data_dir_.AppendASCII("good.crx"); |
| 3950 InstallCrx(extension_path, true); | 3909 InstallCRX(extension_path, INSTALL_NEW); |
| 3951 EXPECT_TRUE(service_->GetExtensionById(good_crx, true)); | 3910 EXPECT_TRUE(service_->GetExtensionById(good_crx, true)); |
| 3952 | 3911 |
| 3953 sync_pb::EntitySpecifics specifics; | 3912 sync_pb::EntitySpecifics specifics; |
| 3954 sync_pb::AppSpecifics* app_specifics = | 3913 sync_pb::AppSpecifics* app_specifics = |
| 3955 specifics.MutableExtension(sync_pb::app); | 3914 specifics.MutableExtension(sync_pb::app); |
| 3956 sync_pb::ExtensionSpecifics* extension_specifics = | 3915 sync_pb::ExtensionSpecifics* extension_specifics = |
| 3957 app_specifics->mutable_extension(); | 3916 app_specifics->mutable_extension(); |
| 3958 extension_specifics->set_id(good_crx); | 3917 extension_specifics->set_id(good_crx); |
| 3959 extension_specifics->set_version( | 3918 extension_specifics->set_version( |
| 3960 service_->GetInstalledExtension(good_crx)->version()->GetString()); | 3919 service_->GetInstalledExtension(good_crx)->version()->GetString()); |
| (...skipping 23 matching lines...) Expand all Loading... |
| 3984 } | 3943 } |
| 3985 } | 3944 } |
| 3986 | 3945 |
| 3987 TEST_F(ExtensionServiceTest, ProcessSyncDataSettings) { | 3946 TEST_F(ExtensionServiceTest, ProcessSyncDataSettings) { |
| 3988 InitializeEmptyExtensionService(); | 3947 InitializeEmptyExtensionService(); |
| 3989 InitializeExtensionProcessManager(); | 3948 InitializeExtensionProcessManager(); |
| 3990 TestSyncProcessorStub processor; | 3949 TestSyncProcessorStub processor; |
| 3991 service_->MergeDataAndStartSyncing(syncable::EXTENSIONS, SyncDataList(), | 3950 service_->MergeDataAndStartSyncing(syncable::EXTENSIONS, SyncDataList(), |
| 3992 &processor); | 3951 &processor); |
| 3993 | 3952 |
| 3994 InstallCrx(data_dir_.AppendASCII("good.crx"), true); | 3953 InstallCRX(data_dir_.AppendASCII("good.crx"), INSTALL_NEW); |
| 3995 EXPECT_TRUE(service_->IsExtensionEnabled(good_crx)); | 3954 EXPECT_TRUE(service_->IsExtensionEnabled(good_crx)); |
| 3996 EXPECT_FALSE(service_->IsIncognitoEnabled(good_crx)); | 3955 EXPECT_FALSE(service_->IsIncognitoEnabled(good_crx)); |
| 3997 | 3956 |
| 3998 sync_pb::EntitySpecifics specifics; | 3957 sync_pb::EntitySpecifics specifics; |
| 3999 sync_pb::ExtensionSpecifics* ext_specifics = | 3958 sync_pb::ExtensionSpecifics* ext_specifics = |
| 4000 specifics.MutableExtension(sync_pb::extension); | 3959 specifics.MutableExtension(sync_pb::extension); |
| 4001 ext_specifics->set_id(good_crx); | 3960 ext_specifics->set_id(good_crx); |
| 4002 ext_specifics->set_version( | 3961 ext_specifics->set_version( |
| 4003 service_->GetInstalledExtension(good_crx)->version()->GetString()); | 3962 service_->GetInstalledExtension(good_crx)->version()->GetString()); |
| 4004 ext_specifics->set_enabled(false); | 3963 ext_specifics->set_enabled(false); |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4039 | 3998 |
| 4040 EXPECT_FALSE(service_->pending_extension_manager()->IsIdPending(good_crx)); | 3999 EXPECT_FALSE(service_->pending_extension_manager()->IsIdPending(good_crx)); |
| 4041 } | 4000 } |
| 4042 | 4001 |
| 4043 TEST_F(ExtensionServiceTest, ProcessSyncDataTerminatedExtension) { | 4002 TEST_F(ExtensionServiceTest, ProcessSyncDataTerminatedExtension) { |
| 4044 InitializeExtensionServiceWithUpdater(); | 4003 InitializeExtensionServiceWithUpdater(); |
| 4045 TestSyncProcessorStub processor; | 4004 TestSyncProcessorStub processor; |
| 4046 service_->MergeDataAndStartSyncing(syncable::EXTENSIONS, SyncDataList(), | 4005 service_->MergeDataAndStartSyncing(syncable::EXTENSIONS, SyncDataList(), |
| 4047 &processor); | 4006 &processor); |
| 4048 | 4007 |
| 4049 InstallCrx(data_dir_.AppendASCII("good.crx"), true); | 4008 InstallCRX(data_dir_.AppendASCII("good.crx"), INSTALL_NEW); |
| 4050 TerminateExtension(good_crx); | 4009 TerminateExtension(good_crx); |
| 4051 EXPECT_TRUE(service_->IsExtensionEnabled(good_crx)); | 4010 EXPECT_TRUE(service_->IsExtensionEnabled(good_crx)); |
| 4052 EXPECT_FALSE(service_->IsIncognitoEnabled(good_crx)); | 4011 EXPECT_FALSE(service_->IsIncognitoEnabled(good_crx)); |
| 4053 | 4012 |
| 4054 sync_pb::EntitySpecifics specifics; | 4013 sync_pb::EntitySpecifics specifics; |
| 4055 sync_pb::ExtensionSpecifics* ext_specifics = | 4014 sync_pb::ExtensionSpecifics* ext_specifics = |
| 4056 specifics.MutableExtension(sync_pb::extension); | 4015 specifics.MutableExtension(sync_pb::extension); |
| 4057 ext_specifics->set_id(good_crx); | 4016 ext_specifics->set_id(good_crx); |
| 4058 ext_specifics->set_version( | 4017 ext_specifics->set_version( |
| 4059 service_->GetInstalledExtension(good_crx)->version()->GetString()); | 4018 service_->GetInstalledExtension(good_crx)->version()->GetString()); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 4070 | 4029 |
| 4071 EXPECT_FALSE(service_->pending_extension_manager()->IsIdPending(good_crx)); | 4030 EXPECT_FALSE(service_->pending_extension_manager()->IsIdPending(good_crx)); |
| 4072 } | 4031 } |
| 4073 | 4032 |
| 4074 TEST_F(ExtensionServiceTest, ProcessSyncDataVersionCheck) { | 4033 TEST_F(ExtensionServiceTest, ProcessSyncDataVersionCheck) { |
| 4075 InitializeExtensionServiceWithUpdater(); | 4034 InitializeExtensionServiceWithUpdater(); |
| 4076 TestSyncProcessorStub processor; | 4035 TestSyncProcessorStub processor; |
| 4077 service_->MergeDataAndStartSyncing(syncable::EXTENSIONS, SyncDataList(), | 4036 service_->MergeDataAndStartSyncing(syncable::EXTENSIONS, SyncDataList(), |
| 4078 &processor); | 4037 &processor); |
| 4079 | 4038 |
| 4080 InstallCrx(data_dir_.AppendASCII("good.crx"), true); | 4039 InstallCRX(data_dir_.AppendASCII("good.crx"), INSTALL_NEW); |
| 4081 EXPECT_TRUE(service_->IsExtensionEnabled(good_crx)); | 4040 EXPECT_TRUE(service_->IsExtensionEnabled(good_crx)); |
| 4082 EXPECT_FALSE(service_->IsIncognitoEnabled(good_crx)); | 4041 EXPECT_FALSE(service_->IsIncognitoEnabled(good_crx)); |
| 4083 | 4042 |
| 4084 sync_pb::EntitySpecifics specifics; | 4043 sync_pb::EntitySpecifics specifics; |
| 4085 sync_pb::ExtensionSpecifics* ext_specifics = | 4044 sync_pb::ExtensionSpecifics* ext_specifics = |
| 4086 specifics.MutableExtension(sync_pb::extension); | 4045 specifics.MutableExtension(sync_pb::extension); |
| 4087 ext_specifics->set_id(good_crx); | 4046 ext_specifics->set_id(good_crx); |
| 4088 ext_specifics->set_enabled(true); | 4047 ext_specifics->set_enabled(true); |
| 4089 | 4048 |
| 4090 { | 4049 { |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4162 EXPECT_TRUE(info.is_from_sync()); | 4121 EXPECT_TRUE(info.is_from_sync()); |
| 4163 EXPECT_TRUE(info.install_silently()); | 4122 EXPECT_TRUE(info.install_silently()); |
| 4164 EXPECT_EQ(Extension::INTERNAL, info.install_source()); | 4123 EXPECT_EQ(Extension::INTERNAL, info.install_source()); |
| 4165 // TODO(akalin): Figure out a way to test |info.ShouldAllowInstall()|. | 4124 // TODO(akalin): Figure out a way to test |info.ShouldAllowInstall()|. |
| 4166 } | 4125 } |
| 4167 | 4126 |
| 4168 TEST_F(ExtensionServiceTest, HigherPriorityInstall) { | 4127 TEST_F(ExtensionServiceTest, HigherPriorityInstall) { |
| 4169 InitializeEmptyExtensionService(); | 4128 InitializeEmptyExtensionService(); |
| 4170 | 4129 |
| 4171 FilePath path = data_dir_.AppendASCII("good.crx"); | 4130 FilePath path = data_dir_.AppendASCII("good.crx"); |
| 4172 InstallCrx(path, true); | 4131 InstallCRX(path, INSTALL_NEW); |
| 4173 ValidatePrefKeyCount(1u); | 4132 ValidatePrefKeyCount(1u); |
| 4174 ValidateIntegerPref(good_crx, "state", Extension::ENABLED); | 4133 ValidateIntegerPref(good_crx, "state", Extension::ENABLED); |
| 4175 ValidateIntegerPref(good_crx, "location", Extension::INTERNAL); | 4134 ValidateIntegerPref(good_crx, "location", Extension::INTERNAL); |
| 4176 | 4135 |
| 4177 PendingExtensionManager* pending = service_->pending_extension_manager(); | 4136 PendingExtensionManager* pending = service_->pending_extension_manager(); |
| 4178 EXPECT_FALSE(pending->IsIdPending(kGoodId)); | 4137 EXPECT_FALSE(pending->IsIdPending(kGoodId)); |
| 4179 | 4138 |
| 4180 // Skip install when the location is the same. | 4139 // Skip install when the location is the same. |
| 4181 service_->OnExternalExtensionUpdateUrlFound(kGoodId, GURL(kGoodUpdateURL), | 4140 service_->OnExternalExtensionUpdateUrlFound(kGoodId, GURL(kGoodUpdateURL), |
| 4182 Extension::INTERNAL); | 4141 Extension::INTERNAL); |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4287 // Install pending as external prefs json would. | 4246 // Install pending as external prefs json would. |
| 4288 AddPendingExternalPrefFileInstall(); | 4247 AddPendingExternalPrefFileInstall(); |
| 4289 ASSERT_EQ(Extension::EXTERNAL_PREF, GetPendingLocation()); | 4248 ASSERT_EQ(Extension::EXTERNAL_PREF, GetPendingLocation()); |
| 4290 ASSERT_FALSE(IsCrxInstalled()); | 4249 ASSERT_FALSE(IsCrxInstalled()); |
| 4291 | 4250 |
| 4292 // Another request from sync should be ignorred. | 4251 // Another request from sync should be ignorred. |
| 4293 EXPECT_FALSE(AddPendingSyncInstall()); | 4252 EXPECT_FALSE(AddPendingSyncInstall()); |
| 4294 ASSERT_EQ(Extension::EXTERNAL_PREF, GetPendingLocation()); | 4253 ASSERT_EQ(Extension::EXTERNAL_PREF, GetPendingLocation()); |
| 4295 ASSERT_FALSE(IsCrxInstalled()); | 4254 ASSERT_FALSE(IsCrxInstalled()); |
| 4296 | 4255 |
| 4297 WaitForCrxInstall(crx_path_, true); | 4256 WaitForCrxInstall(crx_path_, INSTALL_NEW); |
| 4298 ASSERT_TRUE(IsCrxInstalled()); | 4257 ASSERT_TRUE(IsCrxInstalled()); |
| 4299 } | 4258 } |
| 4300 | 4259 |
| 4301 // Test that an install of an external CRX from an update overrides | 4260 // Test that an install of an external CRX from an update overrides |
| 4302 // an install of the same extension from sync. | 4261 // an install of the same extension from sync. |
| 4303 TEST_F(ExtensionSourcePriorityTest, PendingExternalUrlOverSync) { | 4262 TEST_F(ExtensionSourcePriorityTest, PendingExternalUrlOverSync) { |
| 4304 InitializeEmptyExtensionService(); | 4263 InitializeEmptyExtensionService(); |
| 4305 ASSERT_FALSE(IsCrxInstalled()); | 4264 ASSERT_FALSE(IsCrxInstalled()); |
| 4306 | 4265 |
| 4307 EXPECT_TRUE(AddPendingSyncInstall()); | 4266 EXPECT_TRUE(AddPendingSyncInstall()); |
| (...skipping 22 matching lines...) Expand all Loading... |
| 4330 AddPendingExternalPrefFileInstall(); | 4289 AddPendingExternalPrefFileInstall(); |
| 4331 | 4290 |
| 4332 // Crx installer was made, but has not yet run. | 4291 // Crx installer was made, but has not yet run. |
| 4333 ASSERT_FALSE(IsCrxInstalled()); | 4292 ASSERT_FALSE(IsCrxInstalled()); |
| 4334 | 4293 |
| 4335 // Before the CRX installer runs, Sync requests that the same extension | 4294 // Before the CRX installer runs, Sync requests that the same extension |
| 4336 // be installed. Should fail, because an external source is pending. | 4295 // be installed. Should fail, because an external source is pending. |
| 4337 ASSERT_FALSE(AddPendingSyncInstall()); | 4296 ASSERT_FALSE(AddPendingSyncInstall()); |
| 4338 | 4297 |
| 4339 // Wait for the external source to install. | 4298 // Wait for the external source to install. |
| 4340 WaitForCrxInstall(crx_path_, true); | 4299 WaitForCrxInstall(crx_path_, INSTALL_NEW); |
| 4341 ASSERT_TRUE(IsCrxInstalled()); | 4300 ASSERT_TRUE(IsCrxInstalled()); |
| 4342 | 4301 |
| 4343 // Now that the extension is installed, sync request should fail | 4302 // Now that the extension is installed, sync request should fail |
| 4344 // because the extension is already installed. | 4303 // because the extension is already installed. |
| 4345 ASSERT_FALSE(AddPendingSyncInstall()); | 4304 ASSERT_FALSE(AddPendingSyncInstall()); |
| 4346 } | 4305 } |
| OLD | NEW |