Chromium Code Reviews| 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 351 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 373 | 372 |
| 374 private: | 373 private: |
| 375 ExtensionService* service_; | 374 ExtensionService* service_; |
| 376 scoped_refptr<ChromeAppCacheService> appcache_service_; | 375 scoped_refptr<ChromeAppCacheService> appcache_service_; |
| 377 scoped_refptr<fileapi::FileSystemContext> file_system_context_; | 376 scoped_refptr<fileapi::FileSystemContext> file_system_context_; |
| 378 }; | 377 }; |
| 379 | 378 |
| 380 // Our message loop may be used in tests which require it to be an IO loop. | 379 // Our message loop may be used in tests which require it to be an IO loop. |
| 381 ExtensionServiceTestBase::ExtensionServiceTestBase() | 380 ExtensionServiceTestBase::ExtensionServiceTestBase() |
| 382 : service_(NULL), | 381 : service_(NULL), |
| 383 total_successes_(0), | 382 expected_extensions_count_(0), |
| 384 loop_(MessageLoop::TYPE_IO), | 383 loop_(MessageLoop::TYPE_IO), |
| 385 ui_thread_(BrowserThread::UI, &loop_), | 384 ui_thread_(BrowserThread::UI, &loop_), |
| 386 db_thread_(BrowserThread::DB, &loop_), | 385 db_thread_(BrowserThread::DB, &loop_), |
| 387 webkit_thread_(BrowserThread::WEBKIT, &loop_), | 386 webkit_thread_(BrowserThread::WEBKIT, &loop_), |
| 388 file_thread_(BrowserThread::FILE, &loop_), | 387 file_thread_(BrowserThread::FILE, &loop_), |
| 389 io_thread_(BrowserThread::IO, &loop_) { | 388 io_thread_(BrowserThread::IO, &loop_) { |
| 390 FilePath test_data_dir; | 389 FilePath test_data_dir; |
| 391 if (!PathService::Get(chrome::DIR_TEST_DATA, &test_data_dir)) { | 390 if (!PathService::Get(chrome::DIR_TEST_DATA, &test_data_dir)) { |
| 392 ADD_FAILURE(); | 391 ADD_FAILURE(); |
| 393 return; | 392 return; |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 425 service_->set_show_extensions_prompts(false); | 424 service_->set_show_extensions_prompts(false); |
| 426 profile->set_extensions_service(service_); | 425 profile->set_extensions_service(service_); |
| 427 | 426 |
| 428 // When we start up, we want to make sure there is no external provider, | 427 // When we start up, we want to make sure there is no external provider, |
| 429 // since the ExtensionService on Windows will use the Registry as a default | 428 // since the ExtensionService on Windows will use the Registry as a default |
| 430 // provider and if there is something already registered there then it will | 429 // provider and if there is something already registered there then it will |
| 431 // interfere with the tests. Those tests that need an external provider | 430 // interfere with the tests. Those tests that need an external provider |
| 432 // will register one specifically. | 431 // will register one specifically. |
| 433 service_->ClearProvidersForTesting(); | 432 service_->ClearProvidersForTesting(); |
| 434 | 433 |
| 435 total_successes_ = 0; | 434 expected_extensions_count_ = 0; |
| 436 } | 435 } |
| 437 | 436 |
| 438 void ExtensionServiceTestBase::InitializeInstalledExtensionService( | 437 void ExtensionServiceTestBase::InitializeInstalledExtensionService( |
| 439 const FilePath& prefs_file, const FilePath& source_install_dir) { | 438 const FilePath& prefs_file, const FilePath& source_install_dir) { |
| 440 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); | 439 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); |
| 441 FilePath path_ = temp_dir_.path(); | 440 FilePath path_ = temp_dir_.path(); |
| 442 path_ = path_.Append(FILE_PATH_LITERAL("TestingExtensionsPath")); | 441 path_ = path_.Append(FILE_PATH_LITERAL("TestingExtensionsPath")); |
| 443 file_util::Delete(path_, true); | 442 file_util::Delete(path_, true); |
| 444 file_util::CreateDirectory(path_); | 443 file_util::CreateDirectory(path_); |
| 445 FilePath temp_prefs = path_.Append(FILE_PATH_LITERAL("Preferences")); | 444 FilePath temp_prefs = path_.Append(FILE_PATH_LITERAL("Preferences")); |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 547 } | 546 } |
| 548 | 547 |
| 549 void AddMockExternalProvider(ExternalExtensionProviderInterface* provider) { | 548 void AddMockExternalProvider(ExternalExtensionProviderInterface* provider) { |
| 550 service_->AddProviderForTesting(provider); | 549 service_->AddProviderForTesting(provider); |
| 551 } | 550 } |
| 552 | 551 |
| 553 protected: | 552 protected: |
| 554 void TestExternalProvider(MockExtensionProvider* provider, | 553 void TestExternalProvider(MockExtensionProvider* provider, |
| 555 Extension::Location location); | 554 Extension::Location location); |
| 556 | 555 |
| 557 void PackAndInstallCrx(const FilePath& dir_path, | 556 void PackCrx(const FilePath& dir_path, |
|
Aaron Boodman
2011/11/20 21:39:43
As long as you're in here, can you fix the capital
Yoyo Zhou
2011/11/21 23:14:52
Why is CRX better? It looks like neither capitaliz
Aaron Boodman
2011/11/22 10:02:59
I did a search a few weeks back of things like "Ur
Yoyo Zhou
2011/11/22 19:40:55
Ok, I'll keep that in mind. Changed.
| |
| 558 const FilePath& pem_path, | 557 const FilePath& pem_path, |
| 559 bool should_succeed) { | 558 const FilePath& crx_path) { |
| 560 FilePath crx_path; | |
| 561 ScopedTempDir temp_dir; | |
| 562 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); | |
| 563 crx_path = temp_dir_.path().AppendASCII("temp.crx"); | |
| 564 | |
| 565 // Use the existing pem key, if provided. | 559 // Use the existing pem key, if provided. |
| 566 FilePath pem_output_path; | 560 FilePath pem_output_path; |
| 567 if (pem_path.value().empty()) { | 561 if (pem_path.value().empty()) { |
| 568 pem_output_path = crx_path.DirName().AppendASCII("temp.pem"); | 562 pem_output_path = crx_path.DirName().AppendASCII("temp.pem"); |
| 569 ASSERT_TRUE(file_util::Delete(pem_output_path, false)); | |
|
Aaron Boodman
2011/11/20 21:39:43
Why remove this?
Yoyo Zhou
2011/11/21 23:14:52
If you look carefully at the code above,
crx_path
| |
| 570 } else { | 563 } else { |
| 571 ASSERT_TRUE(file_util::PathExists(pem_path)); | 564 ASSERT_TRUE(file_util::PathExists(pem_path)); |
| 572 } | 565 } |
| 573 | 566 |
| 574 ASSERT_TRUE(file_util::Delete(crx_path, false)); | 567 ASSERT_TRUE(file_util::Delete(crx_path, false)); |
| 575 | 568 |
| 576 scoped_ptr<ExtensionCreator> creator(new ExtensionCreator()); | 569 scoped_ptr<ExtensionCreator> creator(new ExtensionCreator()); |
| 577 ASSERT_TRUE(creator->Run(dir_path, | 570 ASSERT_TRUE(creator->Run(dir_path, |
| 578 crx_path, | 571 crx_path, |
| 579 pem_path, | 572 pem_path, |
| 580 pem_output_path)); | 573 pem_output_path)); |
| 581 | 574 |
| 582 ASSERT_TRUE(file_util::PathExists(crx_path)); | 575 ASSERT_TRUE(file_util::PathExists(crx_path)); |
| 583 InstallCrx(crx_path, should_succeed); | |
| 584 } | 576 } |
| 585 | 577 |
| 586 void PackAndInstallCrx(const FilePath& dir_path, | 578 const Extension* PackAndInstallCrx(const FilePath& dir_path, |
| 587 bool should_succeed) { | 579 const FilePath& pem_path, |
| 588 PackAndInstallCrx(dir_path, FilePath(), should_succeed); | 580 bool should_succeed) { |
| 581 FilePath crx_path; | |
| 582 ScopedTempDir temp_dir; | |
| 583 EXPECT_TRUE(temp_dir.CreateUniqueTempDir()); | |
| 584 crx_path = temp_dir.path().AppendASCII("temp.crx"); | |
| 585 | |
| 586 PackCrx(dir_path, pem_path, crx_path); | |
| 587 return InstallCrx(crx_path, should_succeed); | |
| 588 } | |
| 589 | |
| 590 const Extension* PackAndInstallCrx(const FilePath& dir_path, | |
| 591 bool should_succeed) { | |
| 592 return PackAndInstallCrx(dir_path, FilePath(), should_succeed); | |
| 589 } | 593 } |
| 590 | 594 |
| 591 // Create a CrxInstaller and start installation. To allow the install | 595 // Create a CrxInstaller and start installation. To allow the install |
| 592 // to happen, use loop_.RunAllPending();. Most tests will not use this | 596 // to happen, use loop_.RunAllPending();. Most tests will not use this |
| 593 // method directly. Instead, use InstallCrx(), which waits for | 597 // method directly. Instead, use InstallCrx(), which waits for |
| 594 // the crx to be installed and does extra error checking. | 598 // the crx to be installed and does extra error checking. |
| 595 void StartCrxInstall(const FilePath& crx_path) { | 599 void StartCrxInstall(const FilePath& crx_path) { |
| 596 StartCrxInstall(crx_path, false); | 600 StartCrxInstall(crx_path, false); |
| 597 } | 601 } |
| 598 | 602 |
| 599 void StartCrxInstall(const FilePath& crx_path, bool from_webstore) { | 603 void StartCrxInstall(const FilePath& crx_path, bool from_webstore) { |
| 600 ASSERT_TRUE(file_util::PathExists(crx_path)) | 604 ASSERT_TRUE(file_util::PathExists(crx_path)) |
| 601 << "Path does not exist: "<< crx_path.value().c_str(); | 605 << "Path does not exist: "<< crx_path.value().c_str(); |
| 602 scoped_refptr<CrxInstaller> installer(CrxInstaller::Create(service_, NULL)); | 606 scoped_refptr<CrxInstaller> installer(CrxInstaller::Create(service_, NULL)); |
| 603 installer->set_allow_silent_install(true); | 607 installer->set_allow_silent_install(true); |
| 604 installer->set_is_gallery_install(from_webstore); | 608 installer->set_is_gallery_install(from_webstore); |
| 605 installer->InstallCrx(crx_path); | 609 installer->InstallCrx(crx_path); |
| 606 } | 610 } |
| 607 | 611 |
| 608 void InstallCrx(const FilePath& path, | 612 const Extension* InstallCrx(const FilePath& path, |
| 609 bool should_succeed) { | 613 bool should_succeed) { |
| 610 StartCrxInstall(path); | 614 StartCrxInstall(path); |
| 611 WaitForCrxInstall(path, should_succeed); | 615 return WaitForCrxInstall(path, should_succeed); |
| 612 } | 616 } |
| 613 | 617 |
| 614 void InstallCrxWithLocation(const FilePath& crx_path, | 618 const Extension* InstallCrxFromWebStore(const FilePath& path, |
| 615 Extension::Location install_location, | 619 bool should_succeed) { |
| 616 bool should_succeed) { | 620 StartCrxInstall(path, true); |
| 617 ASSERT_TRUE(file_util::PathExists(crx_path)) | 621 return WaitForCrxInstall(path, should_succeed); |
| 622 } | |
| 623 | |
| 624 const Extension* InstallCrxWithLocation(const FilePath& crx_path, | |
| 625 Extension::Location install_location, | |
| 626 bool should_succeed) { | |
| 627 EXPECT_TRUE(file_util::PathExists(crx_path)) | |
| 618 << "Path does not exist: "<< crx_path.value().c_str(); | 628 << "Path does not exist: "<< crx_path.value().c_str(); |
| 619 // no client (silent install) | 629 // no client (silent install) |
| 620 scoped_refptr<CrxInstaller> installer(CrxInstaller::Create(service_, NULL)); | 630 scoped_refptr<CrxInstaller> installer(CrxInstaller::Create(service_, NULL)); |
| 621 | 631 |
| 622 installer->set_install_source(install_location); | 632 installer->set_install_source(install_location); |
| 623 installer->InstallCrx(crx_path); | 633 installer->InstallCrx(crx_path); |
| 624 | 634 |
| 625 WaitForCrxInstall(crx_path, should_succeed); | 635 return WaitForCrxInstall(crx_path, should_succeed); |
| 626 } | 636 } |
| 627 | 637 |
| 628 // Wait for a CrxInstaller to finish. Used by InstallCrx. | 638 // Wait for a CrxInstaller to finish. Used by InstallCrx. |
| 629 void WaitForCrxInstall(const FilePath& path, | 639 // Returns the ID of the extension if the install succeeded, NULL otherwise. |
|
Aaron Boodman
2011/11/20 21:39:43
Comment is incorrect.
Yoyo Zhou
2011/11/21 23:14:52
Oops, fixed.
| |
| 630 bool should_succeed) { | 640 const Extension* WaitForCrxInstall(const FilePath& path, |
| 641 bool should_succeed) { | |
| 631 loop_.RunAllPending(); | 642 loop_.RunAllPending(); |
| 632 std::vector<std::string> errors = GetErrors(); | 643 std::vector<std::string> errors = GetErrors(); |
| 644 const Extension* extension = NULL; | |
| 633 if (should_succeed) { | 645 if (should_succeed) { |
| 634 ++total_successes_; | 646 ++expected_extensions_count_; |
| 635 | 647 |
| 636 EXPECT_TRUE(installed_) << path.value(); | 648 EXPECT_TRUE(installed_) << path.value(); |
| 637 | 649 |
| 638 ASSERT_EQ(1u, loaded_.size()) << path.value(); | 650 EXPECT_EQ(1u, loaded_.size()) << path.value(); |
| 639 EXPECT_EQ(0u, errors.size()) << path.value(); | 651 EXPECT_EQ(0u, errors.size()) << path.value(); |
| 640 EXPECT_EQ(total_successes_, service_->extensions()->size()) << | 652 EXPECT_EQ(expected_extensions_count_, service_->extensions()->size()) << |
| 641 path.value(); | 653 path.value(); |
| 642 EXPECT_TRUE(service_->GetExtensionById(loaded_[0]->id(), false)) << | 654 extension = loaded_[0]; |
| 655 EXPECT_TRUE(service_->GetExtensionById(extension->id(), false)) << | |
| 643 path.value(); | 656 path.value(); |
| 644 for (std::vector<std::string>::iterator err = errors.begin(); | 657 for (std::vector<std::string>::iterator err = errors.begin(); |
| 645 err != errors.end(); ++err) { | 658 err != errors.end(); ++err) { |
| 646 LOG(ERROR) << *err; | 659 LOG(ERROR) << *err; |
| 647 } | 660 } |
| 648 } else { | 661 } else { |
| 649 EXPECT_FALSE(installed_) << path.value(); | 662 EXPECT_FALSE(installed_) << path.value(); |
| 650 EXPECT_EQ(0u, loaded_.size()) << path.value(); | 663 EXPECT_EQ(0u, loaded_.size()) << path.value(); |
| 651 EXPECT_EQ(1u, errors.size()) << path.value(); | 664 EXPECT_EQ(1u, errors.size()) << path.value(); |
| 652 } | 665 } |
| 653 | 666 |
| 654 installed_ = NULL; | 667 installed_ = NULL; |
| 655 loaded_.clear(); | 668 loaded_.clear(); |
| 656 ExtensionErrorReporter::GetInstance()->ClearErrors(); | 669 ExtensionErrorReporter::GetInstance()->ClearErrors(); |
| 670 return extension; | |
| 657 } | 671 } |
| 658 | 672 |
| 659 enum UpdateState { | 673 enum UpdateState { |
| 660 FAILED_SILENTLY, | 674 FAILED_SILENTLY, |
| 661 FAILED, | 675 FAILED, |
| 662 UPDATED, | 676 UPDATED, |
| 663 INSTALLED, | 677 INSTALLED, |
| 664 ENABLED | 678 ENABLED |
| 665 }; | 679 }; |
| 666 | 680 |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 739 size_t pref_key_count = GetPrefKeyCount(); | 753 size_t pref_key_count = GetPrefKeyCount(); |
| 740 EXPECT_GT(pref_key_count, 0u); | 754 EXPECT_GT(pref_key_count, 0u); |
| 741 ValidateIntegerPref(id, "state", Extension::ENABLED); | 755 ValidateIntegerPref(id, "state", Extension::ENABLED); |
| 742 | 756 |
| 743 // Uninstall it. | 757 // Uninstall it. |
| 744 if (use_helper) { | 758 if (use_helper) { |
| 745 EXPECT_TRUE(ExtensionService::UninstallExtensionHelper(service_, id)); | 759 EXPECT_TRUE(ExtensionService::UninstallExtensionHelper(service_, id)); |
| 746 } else { | 760 } else { |
| 747 EXPECT_TRUE(service_->UninstallExtension(id, false, NULL)); | 761 EXPECT_TRUE(service_->UninstallExtension(id, false, NULL)); |
| 748 } | 762 } |
| 749 total_successes_ = 0; | 763 expected_extensions_count_ = 0; |
|
Aaron Boodman
2011/11/20 21:39:43
Seems like maybe this isn't needed anymore? It's o
Yoyo Zhou
2011/11/21 23:14:52
Well, if we ever have a test that uninstalls an ex
Aaron Boodman
2011/11/22 10:02:59
Fair enough.
| |
| 750 | 764 |
| 751 // We should get an unload notification. | 765 // We should get an unload notification. |
| 752 EXPECT_FALSE(unloaded_id_.empty()); | 766 EXPECT_FALSE(unloaded_id_.empty()); |
| 753 EXPECT_EQ(id, unloaded_id_); | 767 EXPECT_EQ(id, unloaded_id_); |
| 754 | 768 |
| 755 // Verify uninstalled state. | 769 // Verify uninstalled state. |
| 756 size_t new_pref_key_count = GetPrefKeyCount(); | 770 size_t new_pref_key_count = GetPrefKeyCount(); |
| 757 if (new_pref_key_count == pref_key_count) { | 771 if (new_pref_key_count == pref_key_count) { |
| 758 ValidateIntegerPref(id, "location", | 772 ValidateIntegerPref(id, "location", |
| 759 Extension::EXTERNAL_EXTENSION_UNINSTALLED); | 773 Extension::EXTERNAL_EXTENSION_UNINSTALLED); |
| (...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 977 ASSERT_TRUE(file_util::PathExists(private_key_path)); | 991 ASSERT_TRUE(file_util::PathExists(private_key_path)); |
| 978 } | 992 } |
| 979 | 993 |
| 980 // The tests are designed so that we never expect to see a packing error. | 994 // The tests are designed so that we never expect to see a packing error. |
| 981 void PackExtensionTestClient::OnPackFailure(const std::string& error_message) { | 995 void PackExtensionTestClient::OnPackFailure(const std::string& error_message) { |
| 982 FAIL() << "Packing should not fail."; | 996 FAIL() << "Packing should not fail."; |
| 983 } | 997 } |
| 984 | 998 |
| 985 // Test loading good extensions from the profile directory. | 999 // Test loading good extensions from the profile directory. |
| 986 TEST_F(ExtensionServiceTest, LoadAllExtensionsFromDirectorySuccess) { | 1000 TEST_F(ExtensionServiceTest, LoadAllExtensionsFromDirectorySuccess) { |
| 987 base::ShadowingAtExitManager at_exit_manager; | |
| 988 PluginService::GetInstance()->Init(); | 1001 PluginService::GetInstance()->Init(); |
| 989 | 1002 |
| 990 // Initialize the test dir with a good Preferences/extensions. | 1003 // Initialize the test dir with a good Preferences/extensions. |
| 991 FilePath source_install_dir = data_dir_ | 1004 FilePath source_install_dir = data_dir_ |
| 992 .AppendASCII("good") | 1005 .AppendASCII("good") |
| 993 .AppendASCII("Extensions"); | 1006 .AppendASCII("Extensions"); |
| 994 FilePath pref_path = source_install_dir | 1007 FilePath pref_path = source_install_dir |
| 995 .DirName() | 1008 .DirName() |
| 996 .AppendASCII("Preferences"); | 1009 .AppendASCII("Preferences"); |
| 997 InitializeInstalledExtensionService(pref_path, source_install_dir); | 1010 InitializeInstalledExtensionService(pref_path, source_install_dir); |
| 998 | 1011 |
| 999 service_->Init(); | 1012 service_->Init(); |
| 1013 loop_.RunAllPending(); | |
|
Aaron Boodman
2011/11/20 21:39:43
Why is this important?
Yoyo Zhou
2011/11/21 23:14:52
Not sure, it seems like the other tests that initi
Aaron Boodman
2011/11/22 10:02:59
In the old days ExtensionService startup was async
| |
| 1000 | 1014 |
| 1001 uint32 expected_num_extensions = 3u; | 1015 uint32 expected_num_extensions = 3u; |
| 1002 ASSERT_EQ(expected_num_extensions, loaded_.size()); | 1016 ASSERT_EQ(expected_num_extensions, loaded_.size()); |
| 1003 | 1017 |
| 1004 EXPECT_EQ(std::string(good0), loaded_[0]->id()); | 1018 EXPECT_EQ(std::string(good0), loaded_[0]->id()); |
| 1005 EXPECT_EQ(std::string("My extension 1"), | 1019 EXPECT_EQ(std::string("My extension 1"), |
| 1006 loaded_[0]->name()); | 1020 loaded_[0]->name()); |
| 1007 EXPECT_EQ(std::string("The first extension that I made."), | 1021 EXPECT_EQ(std::string("The first extension that I made."), |
| 1008 loaded_[0]->description()); | 1022 loaded_[0]->description()); |
| 1009 EXPECT_EQ(Extension::INTERNAL, loaded_[0]->location()); | 1023 EXPECT_EQ(Extension::INTERNAL, loaded_[0]->location()); |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1117 extension_manifest_errors::kMissingFile)) << GetErrors()[2]; | 1131 extension_manifest_errors::kMissingFile)) << GetErrors()[2]; |
| 1118 | 1132 |
| 1119 EXPECT_TRUE(MatchPattern(GetErrors()[3], | 1133 EXPECT_TRUE(MatchPattern(GetErrors()[3], |
| 1120 std::string("Could not load extension from '*'. ") + | 1134 std::string("Could not load extension from '*'. ") + |
| 1121 extension_manifest_errors::kManifestUnreadable)) << GetErrors()[3]; | 1135 extension_manifest_errors::kManifestUnreadable)) << GetErrors()[3]; |
| 1122 }; | 1136 }; |
| 1123 | 1137 |
| 1124 // Test that partially deleted extensions are cleaned up during startup | 1138 // Test that partially deleted extensions are cleaned up during startup |
| 1125 // Test loading bad extensions from the profile directory. | 1139 // Test loading bad extensions from the profile directory. |
| 1126 TEST_F(ExtensionServiceTest, CleanupOnStartup) { | 1140 TEST_F(ExtensionServiceTest, CleanupOnStartup) { |
| 1127 base::ShadowingAtExitManager at_exit_manager; | |
| 1128 PluginService::GetInstance()->Init(); | 1141 PluginService::GetInstance()->Init(); |
| 1129 | 1142 |
| 1130 FilePath source_install_dir = data_dir_ | 1143 FilePath source_install_dir = data_dir_ |
| 1131 .AppendASCII("good") | 1144 .AppendASCII("good") |
| 1132 .AppendASCII("Extensions"); | 1145 .AppendASCII("Extensions"); |
| 1133 FilePath pref_path = source_install_dir | 1146 FilePath pref_path = source_install_dir |
| 1134 .DirName() | 1147 .DirName() |
| 1135 .AppendASCII("Preferences"); | 1148 .AppendASCII("Preferences"); |
| 1136 | 1149 |
| 1137 InitializeInstalledExtensionService(pref_path, source_install_dir); | 1150 InitializeInstalledExtensionService(pref_path, source_install_dir); |
| (...skipping 287 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1425 | 1438 |
| 1426 ExtensionAPIPermissionSet expected_api_perms; | 1439 ExtensionAPIPermissionSet expected_api_perms; |
| 1427 URLPatternSet expected_host_perms; | 1440 URLPatternSet expected_host_perms; |
| 1428 | 1441 |
| 1429 // Make sure there aren't any granted permissions before the | 1442 // Make sure there aren't any granted permissions before the |
| 1430 // extension is installed. | 1443 // extension is installed. |
| 1431 scoped_refptr<ExtensionPermissionSet> known_perms( | 1444 scoped_refptr<ExtensionPermissionSet> known_perms( |
| 1432 prefs->GetGrantedPermissions(permissions_crx)); | 1445 prefs->GetGrantedPermissions(permissions_crx)); |
| 1433 EXPECT_FALSE(known_perms.get()); | 1446 EXPECT_FALSE(known_perms.get()); |
| 1434 | 1447 |
| 1435 PackAndInstallCrx(path, pem_path, true); | 1448 const Extension* extension = PackAndInstallCrx(path, pem_path, true); |
| 1436 | 1449 |
| 1437 EXPECT_EQ(0u, GetErrors().size()); | 1450 EXPECT_EQ(0u, GetErrors().size()); |
| 1438 ASSERT_EQ(1u, service_->extensions()->size()); | 1451 ASSERT_EQ(1u, service_->extensions()->size()); |
| 1439 std::string extension_id = service_->extensions()->at(0)->id(); | 1452 EXPECT_EQ(permissions_crx, extension->id()); |
| 1440 EXPECT_EQ(permissions_crx, extension_id); | |
| 1441 | 1453 |
| 1442 // Verify that the valid API permissions have been recognized. | 1454 // Verify that the valid API permissions have been recognized. |
| 1443 expected_api_perms.insert(ExtensionAPIPermission::kTab); | 1455 expected_api_perms.insert(ExtensionAPIPermission::kTab); |
| 1444 | 1456 |
| 1445 AddPattern(&expected_host_perms, "http://*.google.com/*"); | 1457 AddPattern(&expected_host_perms, "http://*.google.com/*"); |
| 1446 AddPattern(&expected_host_perms, "https://*.google.com/*"); | 1458 AddPattern(&expected_host_perms, "https://*.google.com/*"); |
| 1447 AddPattern(&expected_host_perms, "http://*.google.com.hk/*"); | 1459 AddPattern(&expected_host_perms, "http://*.google.com.hk/*"); |
| 1448 AddPattern(&expected_host_perms, "http://www.example.com/*"); | 1460 AddPattern(&expected_host_perms, "http://www.example.com/*"); |
| 1449 | 1461 |
| 1450 known_perms = prefs->GetGrantedPermissions(extension_id); | 1462 known_perms = prefs->GetGrantedPermissions(extension->id()); |
| 1451 EXPECT_TRUE(known_perms.get()); | 1463 EXPECT_TRUE(known_perms.get()); |
| 1452 EXPECT_FALSE(known_perms->IsEmpty()); | 1464 EXPECT_FALSE(known_perms->IsEmpty()); |
| 1453 EXPECT_EQ(expected_api_perms, known_perms->apis()); | 1465 EXPECT_EQ(expected_api_perms, known_perms->apis()); |
| 1454 EXPECT_FALSE(known_perms->HasEffectiveFullAccess()); | 1466 EXPECT_FALSE(known_perms->HasEffectiveFullAccess()); |
| 1455 EXPECT_EQ(expected_host_perms, known_perms->effective_hosts()); | 1467 EXPECT_EQ(expected_host_perms, known_perms->effective_hosts()); |
| 1456 } | 1468 } |
| 1457 | 1469 |
| 1458 #if !defined(OS_CHROMEOS) | 1470 #if !defined(OS_CHROMEOS) |
| 1459 // Tests that the granted permissions full_access bit gets set correctly when | 1471 // Tests that the granted permissions full_access bit gets set correctly when |
| 1460 // an extension contains an NPAPI plugin. Don't run this test on Chrome OS | 1472 // an extension contains an NPAPI plugin. Don't run this test on Chrome OS |
| 1461 // since they don't support plugins. | 1473 // since they don't support plugins. |
| 1462 TEST_F(ExtensionServiceTest, GrantedFullAccessPermissions) { | 1474 TEST_F(ExtensionServiceTest, GrantedFullAccessPermissions) { |
| 1463 base::ShadowingAtExitManager at_exit_manager; | |
| 1464 PluginService::GetInstance()->Init(); | 1475 PluginService::GetInstance()->Init(); |
| 1465 | 1476 |
| 1466 InitializeEmptyExtensionService(); | 1477 InitializeEmptyExtensionService(); |
| 1467 | 1478 |
| 1468 FilePath path = data_dir_ | 1479 FilePath path = data_dir_ |
| 1469 .AppendASCII("good") | 1480 .AppendASCII("good") |
| 1470 .AppendASCII("Extensions") | 1481 .AppendASCII("Extensions") |
| 1471 .AppendASCII(good1) | 1482 .AppendASCII(good1) |
| 1472 .AppendASCII("2"); | 1483 .AppendASCII("2"); |
| 1473 | 1484 |
| 1474 ASSERT_TRUE(file_util::PathExists(path)); | 1485 ASSERT_TRUE(file_util::PathExists(path)); |
| 1475 PackAndInstallCrx(path, true); | 1486 const Extension* extension = PackAndInstallCrx(path, true); |
| 1476 EXPECT_EQ(0u, GetErrors().size()); | 1487 EXPECT_EQ(0u, GetErrors().size()); |
| 1477 EXPECT_EQ(1u, service_->extensions()->size()); | 1488 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(); | 1489 ExtensionPrefs* prefs = service_->extension_prefs(); |
| 1481 | 1490 |
| 1482 scoped_refptr<ExtensionPermissionSet> permissions( | 1491 scoped_refptr<ExtensionPermissionSet> permissions( |
| 1483 prefs->GetGrantedPermissions(extension_id)); | 1492 prefs->GetGrantedPermissions(extension->id())); |
| 1484 EXPECT_FALSE(permissions->IsEmpty()); | 1493 EXPECT_FALSE(permissions->IsEmpty()); |
| 1485 EXPECT_TRUE(permissions->HasEffectiveFullAccess()); | 1494 EXPECT_TRUE(permissions->HasEffectiveFullAccess()); |
| 1486 EXPECT_FALSE(permissions->apis().empty()); | 1495 EXPECT_FALSE(permissions->apis().empty()); |
| 1487 EXPECT_TRUE(permissions->HasAPIPermission(ExtensionAPIPermission::kPlugin)); | 1496 EXPECT_TRUE(permissions->HasAPIPermission(ExtensionAPIPermission::kPlugin)); |
| 1488 | 1497 |
| 1489 // Full access implies full host access too... | 1498 // Full access implies full host access too... |
| 1490 EXPECT_TRUE(permissions->HasEffectiveAccessToAllHosts()); | 1499 EXPECT_TRUE(permissions->HasEffectiveAccessToAllHosts()); |
| 1491 } | 1500 } |
| 1492 #endif | 1501 #endif |
| 1493 | 1502 |
| 1494 // Tests that the extension is disabled when permissions are missing from | 1503 // Tests that the extension is disabled when permissions are missing from |
| 1495 // the extension's granted permissions preferences. (This simulates updating | 1504 // the extension's granted permissions preferences. (This simulates updating |
| 1496 // the browser to a version which recognizes more permissions). | 1505 // the browser to a version which recognizes more permissions). |
| 1497 TEST_F(ExtensionServiceTest, GrantedAPIAndHostPermissions) { | 1506 TEST_F(ExtensionServiceTest, GrantedAPIAndHostPermissions) { |
| 1498 InitializeEmptyExtensionService(); | 1507 InitializeEmptyExtensionService(); |
| 1499 | 1508 |
| 1500 FilePath path = data_dir_ | 1509 FilePath path = data_dir_ |
| 1501 .AppendASCII("permissions") | 1510 .AppendASCII("permissions") |
| 1502 .AppendASCII("unknown"); | 1511 .AppendASCII("unknown"); |
| 1503 | 1512 |
| 1504 ASSERT_TRUE(file_util::PathExists(path)); | 1513 ASSERT_TRUE(file_util::PathExists(path)); |
| 1505 | 1514 |
| 1506 PackAndInstallCrx(path, true); | 1515 const Extension* extension = PackAndInstallCrx(path, true); |
| 1507 | 1516 |
| 1508 EXPECT_EQ(0u, GetErrors().size()); | 1517 EXPECT_EQ(0u, GetErrors().size()); |
| 1509 EXPECT_EQ(1u, service_->extensions()->size()); | 1518 EXPECT_EQ(1u, service_->extensions()->size()); |
| 1510 const Extension* extension = service_->extensions()->at(0); | |
| 1511 std::string extension_id = extension->id(); | 1519 std::string extension_id = extension->id(); |
| 1512 | 1520 |
| 1513 ExtensionPrefs* prefs = service_->extension_prefs(); | 1521 ExtensionPrefs* prefs = service_->extension_prefs(); |
| 1514 | 1522 |
| 1515 ExtensionAPIPermissionSet expected_api_permissions; | 1523 ExtensionAPIPermissionSet expected_api_permissions; |
| 1516 URLPatternSet expected_host_permissions; | 1524 URLPatternSet expected_host_permissions; |
| 1517 | 1525 |
| 1518 expected_api_permissions.insert(ExtensionAPIPermission::kTab); | 1526 expected_api_permissions.insert(ExtensionAPIPermission::kTab); |
| 1519 AddPattern(&expected_host_permissions, "http://*.google.com/*"); | 1527 AddPattern(&expected_host_permissions, "http://*.google.com/*"); |
| 1520 AddPattern(&expected_host_permissions, "https://*.google.com/*"); | 1528 AddPattern(&expected_host_permissions, "https://*.google.com/*"); |
| 1521 AddPattern(&expected_host_permissions, "http://*.google.com.hk/*"); | 1529 AddPattern(&expected_host_permissions, "http://*.google.com.hk/*"); |
| 1522 AddPattern(&expected_host_permissions, "http://www.example.com/*"); | 1530 AddPattern(&expected_host_permissions, "http://www.example.com/*"); |
| 1523 | 1531 |
| 1524 std::set<std::string> host_permissions; | 1532 std::set<std::string> host_permissions; |
| 1525 | 1533 |
| 1526 // Test that the extension is disabled when an API permission is missing from | 1534 // Test that the extension is disabled when an API permission is missing from |
| 1527 // the extension's granted api permissions preference. (This simulates | 1535 // the extension's granted api permissions preference. (This simulates |
| 1528 // updating the browser to a version which recognizes a new API permission). | 1536 // updating the browser to a version which recognizes a new API permission). |
| 1529 SetPref(extension_id, "granted_permissions.api", | 1537 SetPref(extension_id, "granted_permissions.api", |
| 1530 new ListValue(), "granted_permissions.api"); | 1538 new ListValue(), "granted_permissions.api"); |
| 1531 service_->ReloadExtensions(); | 1539 service_->ReloadExtensions(); |
| 1532 | 1540 |
| 1533 EXPECT_EQ(1u, service_->disabled_extensions()->size()); | 1541 EXPECT_EQ(1u, service_->disabled_extensions()->size()); |
| 1534 extension = service_->disabled_extensions()->at(0); | 1542 extension = *service_->disabled_extensions()->begin(); |
| 1535 | 1543 |
| 1536 ASSERT_TRUE(prefs->IsExtensionDisabled(extension_id)); | 1544 ASSERT_TRUE(prefs->IsExtensionDisabled(extension_id)); |
| 1537 ASSERT_FALSE(service_->IsExtensionEnabled(extension_id)); | 1545 ASSERT_FALSE(service_->IsExtensionEnabled(extension_id)); |
| 1538 ASSERT_TRUE(prefs->DidExtensionEscalatePermissions(extension_id)); | 1546 ASSERT_TRUE(prefs->DidExtensionEscalatePermissions(extension_id)); |
| 1539 | 1547 |
| 1540 // Now grant and re-enable the extension, making sure the prefs are updated. | 1548 // Now grant and re-enable the extension, making sure the prefs are updated. |
| 1541 service_->GrantPermissionsAndEnableExtension(extension); | 1549 service_->GrantPermissionsAndEnableExtension(extension); |
| 1542 | 1550 |
| 1543 ASSERT_FALSE(prefs->IsExtensionDisabled(extension_id)); | 1551 ASSERT_FALSE(prefs->IsExtensionDisabled(extension_id)); |
| 1544 ASSERT_TRUE(service_->IsExtensionEnabled(extension_id)); | 1552 ASSERT_TRUE(service_->IsExtensionEnabled(extension_id)); |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 1567 api_permissions->Append( | 1575 api_permissions->Append( |
| 1568 Value::CreateIntegerValue(ExtensionAPIPermission::kTab)); | 1576 Value::CreateIntegerValue(ExtensionAPIPermission::kTab)); |
| 1569 SetPref(extension_id, "granted_permissions.api", | 1577 SetPref(extension_id, "granted_permissions.api", |
| 1570 api_permissions, "granted_permissions.api"); | 1578 api_permissions, "granted_permissions.api"); |
| 1571 SetPrefStringSet( | 1579 SetPrefStringSet( |
| 1572 extension_id, "granted_permissions.scriptable_host", host_permissions); | 1580 extension_id, "granted_permissions.scriptable_host", host_permissions); |
| 1573 | 1581 |
| 1574 service_->ReloadExtensions(); | 1582 service_->ReloadExtensions(); |
| 1575 | 1583 |
| 1576 EXPECT_EQ(1u, service_->disabled_extensions()->size()); | 1584 EXPECT_EQ(1u, service_->disabled_extensions()->size()); |
| 1577 extension = service_->disabled_extensions()->at(0); | 1585 extension = *service_->disabled_extensions()->begin(); |
| 1578 | 1586 |
| 1579 ASSERT_TRUE(prefs->IsExtensionDisabled(extension_id)); | 1587 ASSERT_TRUE(prefs->IsExtensionDisabled(extension_id)); |
| 1580 ASSERT_FALSE(service_->IsExtensionEnabled(extension_id)); | 1588 ASSERT_FALSE(service_->IsExtensionEnabled(extension_id)); |
| 1581 ASSERT_TRUE(prefs->DidExtensionEscalatePermissions(extension_id)); | 1589 ASSERT_TRUE(prefs->DidExtensionEscalatePermissions(extension_id)); |
| 1582 | 1590 |
| 1583 // Now grant and re-enable the extension, making sure the prefs are updated. | 1591 // Now grant and re-enable the extension, making sure the prefs are updated. |
| 1584 service_->GrantPermissionsAndEnableExtension(extension); | 1592 service_->GrantPermissionsAndEnableExtension(extension); |
| 1585 | 1593 |
| 1586 ASSERT_TRUE(service_->IsExtensionEnabled(extension_id)); | 1594 ASSERT_TRUE(service_->IsExtensionEnabled(extension_id)); |
| 1587 ASSERT_FALSE(prefs->DidExtensionEscalatePermissions(extension_id)); | 1595 ASSERT_FALSE(prefs->DidExtensionEscalatePermissions(extension_id)); |
| (...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1777 // Load. | 1785 // Load. |
| 1778 InitializeEmptyExtensionService(); | 1786 InitializeEmptyExtensionService(); |
| 1779 FilePath extension_path = data_dir_ | 1787 FilePath extension_path = data_dir_ |
| 1780 .AppendASCII("theme_i18n"); | 1788 .AppendASCII("theme_i18n"); |
| 1781 | 1789 |
| 1782 extensions::UnpackedInstaller::Create(service_)->Load(extension_path); | 1790 extensions::UnpackedInstaller::Create(service_)->Load(extension_path); |
| 1783 loop_.RunAllPending(); | 1791 loop_.RunAllPending(); |
| 1784 EXPECT_EQ(0u, GetErrors().size()); | 1792 EXPECT_EQ(0u, GetErrors().size()); |
| 1785 ASSERT_EQ(1u, loaded_.size()); | 1793 ASSERT_EQ(1u, loaded_.size()); |
| 1786 EXPECT_EQ(1u, service_->extensions()->size()); | 1794 EXPECT_EQ(1u, service_->extensions()->size()); |
| 1787 EXPECT_EQ("name", service_->extensions()->at(0)->name()); | 1795 const Extension* theme = *service_->extensions()->begin(); |
| 1788 EXPECT_EQ("description", service_->extensions()->at(0)->description()); | 1796 EXPECT_EQ("name", theme->name()); |
| 1797 EXPECT_EQ("description", theme->description()); | |
| 1789 } | 1798 } |
| 1790 | 1799 |
| 1791 TEST_F(ExtensionServiceTest, InstallLocalizedTheme) { | 1800 TEST_F(ExtensionServiceTest, InstallLocalizedTheme) { |
| 1792 InitializeEmptyExtensionService(); | 1801 InitializeEmptyExtensionService(); |
| 1793 FilePath theme_path = data_dir_ | 1802 FilePath theme_path = data_dir_ |
| 1794 .AppendASCII("theme_i18n"); | 1803 .AppendASCII("theme_i18n"); |
| 1795 | 1804 |
| 1796 PackAndInstallCrx(theme_path, true); | 1805 const Extension* theme = PackAndInstallCrx(theme_path, true); |
| 1797 | 1806 |
| 1798 EXPECT_EQ(0u, GetErrors().size()); | 1807 EXPECT_EQ(0u, GetErrors().size()); |
| 1799 EXPECT_EQ(1u, service_->extensions()->size()); | 1808 EXPECT_EQ(1u, service_->extensions()->size()); |
| 1800 EXPECT_EQ("name", service_->extensions()->at(0)->name()); | 1809 EXPECT_EQ("name", theme->name()); |
| 1801 EXPECT_EQ("description", service_->extensions()->at(0)->description()); | 1810 EXPECT_EQ("description", theme->description()); |
| 1802 } | 1811 } |
| 1803 | 1812 |
| 1804 TEST_F(ExtensionServiceTest, InstallApps) { | 1813 TEST_F(ExtensionServiceTest, InstallApps) { |
| 1805 InitializeEmptyExtensionService(); | 1814 InitializeEmptyExtensionService(); |
| 1806 | 1815 |
| 1807 // An empty app. | 1816 // An empty app. |
| 1808 PackAndInstallCrx(data_dir_.AppendASCII("app1"), true); | 1817 const Extension* app = PackAndInstallCrx(data_dir_.AppendASCII("app1"), true); |
| 1809 int pref_count = 0; | 1818 int pref_count = 0; |
| 1810 ValidatePrefKeyCount(++pref_count); | 1819 ValidatePrefKeyCount(++pref_count); |
| 1811 ASSERT_EQ(1u, service_->extensions()->size()); | 1820 ASSERT_EQ(1u, service_->extensions()->size()); |
| 1812 std::string id = service_->extensions()->at(0)->id(); | 1821 ValidateIntegerPref(app->id(), "state", Extension::ENABLED); |
| 1813 ValidateIntegerPref(id, "state", Extension::ENABLED); | 1822 ValidateIntegerPref(app->id(), "location", Extension::INTERNAL); |
| 1814 ValidateIntegerPref(id, "location", Extension::INTERNAL); | |
| 1815 | 1823 |
| 1816 // Another app with non-overlapping extent. Should succeed. | 1824 // Another app with non-overlapping extent. Should succeed. |
| 1817 PackAndInstallCrx(data_dir_.AppendASCII("app2"), true); | 1825 PackAndInstallCrx(data_dir_.AppendASCII("app2"), true); |
| 1818 ValidatePrefKeyCount(++pref_count); | 1826 ValidatePrefKeyCount(++pref_count); |
| 1819 | 1827 |
| 1820 // A third app whose extent overlaps the first. Should fail. | 1828 // A third app whose extent overlaps the first. Should fail. |
| 1821 PackAndInstallCrx(data_dir_.AppendASCII("app3"), false); | 1829 PackAndInstallCrx(data_dir_.AppendASCII("app3"), false); |
| 1822 ValidatePrefKeyCount(pref_count); | 1830 ValidatePrefKeyCount(pref_count); |
| 1823 } | 1831 } |
| 1824 | 1832 |
| 1825 // Tests that file access is OFF by default. | 1833 // Tests that file access is OFF by default. |
| 1826 TEST_F(ExtensionServiceTest, DefaultFileAccess) { | 1834 TEST_F(ExtensionServiceTest, DefaultFileAccess) { |
| 1827 InitializeEmptyExtensionService(); | 1835 InitializeEmptyExtensionService(); |
| 1828 PackAndInstallCrx(data_dir_.AppendASCII("permissions").AppendASCII("files"), | 1836 const Extension* extension = |
| 1829 true); | 1837 PackAndInstallCrx(data_dir_ |
| 1830 | 1838 .AppendASCII("permissions") |
| 1839 .AppendASCII("files"), | |
| 1840 true); | |
| 1831 EXPECT_EQ(0u, GetErrors().size()); | 1841 EXPECT_EQ(0u, GetErrors().size()); |
| 1832 EXPECT_EQ(1u, service_->extensions()->size()); | 1842 EXPECT_EQ(1u, service_->extensions()->size()); |
| 1833 std::string id = service_->extensions()->at(0)->id(); | 1843 EXPECT_FALSE(service_->extension_prefs()->AllowFileAccess(extension->id())); |
| 1834 EXPECT_FALSE(service_->extension_prefs()->AllowFileAccess(id)); | |
| 1835 } | 1844 } |
| 1836 | 1845 |
| 1837 TEST_F(ExtensionServiceTest, UpdateApps) { | 1846 TEST_F(ExtensionServiceTest, UpdateApps) { |
| 1838 InitializeEmptyExtensionService(); | 1847 InitializeEmptyExtensionService(); |
| 1839 FilePath extensions_path = data_dir_.AppendASCII("app_update"); | 1848 FilePath extensions_path = data_dir_.AppendASCII("app_update"); |
| 1840 | 1849 |
| 1841 // First install v1 of a hosted app. | 1850 // First install v1 of a hosted app. |
| 1842 InstallCrx(extensions_path.AppendASCII("v1.crx"), true); | 1851 const Extension* extension = |
| 1852 InstallCrx(extensions_path.AppendASCII("v1.crx"), true); | |
| 1843 ASSERT_EQ(1u, service_->extensions()->size()); | 1853 ASSERT_EQ(1u, service_->extensions()->size()); |
| 1844 std::string id = service_->extensions()->at(0)->id(); | 1854 std::string id = extension->id(); |
| 1845 ASSERT_EQ(std::string("1"), | 1855 ASSERT_EQ(std::string("1"), extension->version()->GetString()); |
| 1846 service_->extensions()->at(0)->version()->GetString()); | |
| 1847 | 1856 |
| 1848 // Now try updating to v2. | 1857 // Now try updating to v2. |
| 1849 UpdateExtension(id, | 1858 UpdateExtension(id, |
| 1850 extensions_path.AppendASCII("v2.crx"), | 1859 extensions_path.AppendASCII("v2.crx"), |
| 1851 ENABLED); | 1860 ENABLED); |
| 1852 ASSERT_EQ(std::string("2"), | 1861 ASSERT_EQ(std::string("2"), |
| 1853 service_->extensions()->at(0)->version()->GetString()); | 1862 service_->GetExtensionById(id, false)->version()->GetString()); |
| 1854 } | 1863 } |
| 1855 | 1864 |
| 1856 TEST_F(ExtensionServiceTest, InstallAppsWithUnlimtedStorage) { | 1865 TEST_F(ExtensionServiceTest, InstallAppsWithUnlimitedStorage) { |
| 1857 InitializeEmptyExtensionService(); | 1866 InitializeEmptyExtensionService(); |
| 1858 InitializeRequestContext(); | 1867 InitializeRequestContext(); |
| 1859 EXPECT_TRUE(service_->extensions()->empty()); | 1868 EXPECT_TRUE(service_->extensions()->empty()); |
| 1860 | 1869 |
| 1861 int pref_count = 0; | 1870 int pref_count = 0; |
| 1862 | 1871 |
| 1863 // Install app1 with unlimited storage. | 1872 // Install app1 with unlimited storage. |
| 1864 PackAndInstallCrx(data_dir_.AppendASCII("app1"), true); | 1873 const Extension* extension = |
| 1874 PackAndInstallCrx(data_dir_.AppendASCII("app1"), true); | |
| 1865 ValidatePrefKeyCount(++pref_count); | 1875 ValidatePrefKeyCount(++pref_count); |
| 1866 ASSERT_EQ(1u, service_->extensions()->size()); | 1876 ASSERT_EQ(1u, service_->extensions()->size()); |
| 1867 const Extension* extension = service_->extensions()->at(0); | |
| 1868 const std::string id1 = extension->id(); | 1877 const std::string id1 = extension->id(); |
| 1869 EXPECT_TRUE(extension->HasAPIPermission( | 1878 EXPECT_TRUE(extension->HasAPIPermission( |
| 1870 ExtensionAPIPermission::kUnlimitedStorage)); | 1879 ExtensionAPIPermission::kUnlimitedStorage)); |
| 1871 EXPECT_TRUE(extension->web_extent().MatchesURL( | 1880 EXPECT_TRUE(extension->web_extent().MatchesURL( |
| 1872 extension->GetFullLaunchURL())); | 1881 extension->GetFullLaunchURL())); |
| 1873 const GURL origin1(extension->GetFullLaunchURL().GetOrigin()); | 1882 const GURL origin1(extension->GetFullLaunchURL().GetOrigin()); |
| 1874 EXPECT_TRUE(profile_->GetExtensionSpecialStoragePolicy()-> | 1883 EXPECT_TRUE(profile_->GetExtensionSpecialStoragePolicy()-> |
| 1875 IsStorageUnlimited(origin1)); | 1884 IsStorageUnlimited(origin1)); |
| 1876 | 1885 |
| 1877 // Install app2 from the same origin with unlimited storage. | 1886 // Install app2 from the same origin with unlimited storage. |
| 1878 PackAndInstallCrx(data_dir_.AppendASCII("app2"), true); | 1887 extension = PackAndInstallCrx(data_dir_.AppendASCII("app2"), true); |
| 1879 ValidatePrefKeyCount(++pref_count); | 1888 ValidatePrefKeyCount(++pref_count); |
| 1880 ASSERT_EQ(2u, service_->extensions()->size()); | 1889 ASSERT_EQ(2u, service_->extensions()->size()); |
| 1881 extension = service_->extensions()->at(1); | |
| 1882 const std::string id2 = extension->id(); | 1890 const std::string id2 = extension->id(); |
| 1883 EXPECT_TRUE(extension->HasAPIPermission( | 1891 EXPECT_TRUE(extension->HasAPIPermission( |
| 1884 ExtensionAPIPermission::kUnlimitedStorage)); | 1892 ExtensionAPIPermission::kUnlimitedStorage)); |
| 1885 EXPECT_TRUE(extension->web_extent().MatchesURL( | 1893 EXPECT_TRUE(extension->web_extent().MatchesURL( |
| 1886 extension->GetFullLaunchURL())); | 1894 extension->GetFullLaunchURL())); |
| 1887 const GURL origin2(extension->GetFullLaunchURL().GetOrigin()); | 1895 const GURL origin2(extension->GetFullLaunchURL().GetOrigin()); |
| 1888 EXPECT_EQ(origin1, origin2); | 1896 EXPECT_EQ(origin1, origin2); |
| 1889 EXPECT_TRUE(profile_->GetExtensionSpecialStoragePolicy()-> | 1897 EXPECT_TRUE(profile_->GetExtensionSpecialStoragePolicy()-> |
| 1890 IsStorageUnlimited(origin2)); | 1898 IsStorageUnlimited(origin2)); |
| 1891 | 1899 |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 1905 IsStorageUnlimited(origin2)); | 1913 IsStorageUnlimited(origin2)); |
| 1906 } | 1914 } |
| 1907 | 1915 |
| 1908 TEST_F(ExtensionServiceTest, InstallAppsAndCheckStorageProtection) { | 1916 TEST_F(ExtensionServiceTest, InstallAppsAndCheckStorageProtection) { |
| 1909 InitializeEmptyExtensionService(); | 1917 InitializeEmptyExtensionService(); |
| 1910 InitializeRequestContext(); | 1918 InitializeRequestContext(); |
| 1911 EXPECT_TRUE(service_->extensions()->empty()); | 1919 EXPECT_TRUE(service_->extensions()->empty()); |
| 1912 | 1920 |
| 1913 int pref_count = 0; | 1921 int pref_count = 0; |
| 1914 | 1922 |
| 1915 PackAndInstallCrx(data_dir_.AppendASCII("app1"), true); | 1923 const Extension* extension = |
| 1924 PackAndInstallCrx(data_dir_.AppendASCII("app1"), true); | |
| 1916 ValidatePrefKeyCount(++pref_count); | 1925 ValidatePrefKeyCount(++pref_count); |
| 1917 ASSERT_EQ(1u, service_->extensions()->size()); | 1926 ASSERT_EQ(1u, service_->extensions()->size()); |
| 1918 const Extension* extension = service_->extensions()->at(0); | |
| 1919 EXPECT_TRUE(extension->is_app()); | 1927 EXPECT_TRUE(extension->is_app()); |
| 1920 const std::string id1 = extension->id(); | 1928 const std::string id1 = extension->id(); |
| 1921 const GURL origin1(extension->GetFullLaunchURL().GetOrigin()); | 1929 const GURL origin1(extension->GetFullLaunchURL().GetOrigin()); |
| 1922 EXPECT_TRUE(profile_->GetExtensionSpecialStoragePolicy()-> | 1930 EXPECT_TRUE(profile_->GetExtensionSpecialStoragePolicy()-> |
| 1923 IsStorageProtected(origin1)); | 1931 IsStorageProtected(origin1)); |
| 1924 | 1932 |
| 1925 // App 4 has a different origin (maps.google.com). | 1933 // App 4 has a different origin (maps.google.com). |
| 1926 PackAndInstallCrx(data_dir_.AppendASCII("app4"), true); | 1934 extension = PackAndInstallCrx(data_dir_.AppendASCII("app4"), true); |
| 1927 ValidatePrefKeyCount(++pref_count); | 1935 ValidatePrefKeyCount(++pref_count); |
| 1928 ASSERT_EQ(2u, service_->extensions()->size()); | 1936 ASSERT_EQ(2u, service_->extensions()->size()); |
| 1929 extension = service_->extensions()->at(1); | |
| 1930 const std::string id2 = extension->id(); | 1937 const std::string id2 = extension->id(); |
| 1931 const GURL origin2(extension->GetFullLaunchURL().GetOrigin()); | 1938 const GURL origin2(extension->GetFullLaunchURL().GetOrigin()); |
| 1932 ASSERT_NE(origin1, origin2); | 1939 ASSERT_NE(origin1, origin2); |
| 1933 EXPECT_TRUE(profile_->GetExtensionSpecialStoragePolicy()-> | 1940 EXPECT_TRUE(profile_->GetExtensionSpecialStoragePolicy()-> |
| 1934 IsStorageProtected(origin2)); | 1941 IsStorageProtected(origin2)); |
| 1935 | 1942 |
| 1936 UninstallExtension(id1, false); | 1943 UninstallExtension(id1, false); |
| 1937 EXPECT_EQ(1u, service_->extensions()->size()); | 1944 EXPECT_EQ(1u, service_->extensions()->size()); |
| 1938 | 1945 |
| 1939 UninstallExtension(id2, false); | 1946 UninstallExtension(id2, false); |
| 1940 | 1947 |
| 1941 EXPECT_TRUE(service_->extensions()->empty()); | 1948 EXPECT_TRUE(service_->extensions()->empty()); |
| 1942 EXPECT_FALSE(profile_->GetExtensionSpecialStoragePolicy()-> | 1949 EXPECT_FALSE(profile_->GetExtensionSpecialStoragePolicy()-> |
| 1943 IsStorageProtected(origin1)); | 1950 IsStorageProtected(origin1)); |
| 1944 EXPECT_FALSE(profile_->GetExtensionSpecialStoragePolicy()-> | 1951 EXPECT_FALSE(profile_->GetExtensionSpecialStoragePolicy()-> |
| 1945 IsStorageProtected(origin2)); | 1952 IsStorageProtected(origin2)); |
| 1946 } | 1953 } |
| 1947 | 1954 |
| 1948 // Test that when an extension version is reinstalled, nothing happens. | 1955 // Test that when an extension version is reinstalled, nothing happens. |
| 1949 TEST_F(ExtensionServiceTest, Reinstall) { | 1956 TEST_F(ExtensionServiceTest, Reinstall) { |
| 1950 InitializeEmptyExtensionService(); | 1957 InitializeEmptyExtensionService(); |
| 1951 | 1958 |
| 1952 // A simple extension that should install without error. | 1959 // A simple extension that should install without error. |
| 1953 FilePath path = data_dir_.AppendASCII("good.crx"); | 1960 FilePath path = data_dir_.AppendASCII("good.crx"); |
| 1954 StartCrxInstall(path); | 1961 InstallCrx(path, true); |
| 1955 loop_.RunAllPending(); | |
| 1956 | 1962 |
| 1957 ASSERT_TRUE(installed_); | |
| 1958 ASSERT_EQ(1u, loaded_.size()); | |
| 1959 ASSERT_EQ(0u, GetErrors().size()); | |
| 1960 ValidatePrefKeyCount(1); | 1963 ValidatePrefKeyCount(1); |
| 1961 ValidateIntegerPref(good_crx, "state", Extension::ENABLED); | 1964 ValidateIntegerPref(good_crx, "state", Extension::ENABLED); |
| 1962 ValidateIntegerPref(good_crx, "location", Extension::INTERNAL); | 1965 ValidateIntegerPref(good_crx, "location", Extension::INTERNAL); |
| 1963 | 1966 |
| 1964 installed_ = NULL; | 1967 // Reinstall the same version, it should overwrite the previous one. |
| 1965 loaded_.clear(); | 1968 expected_extensions_count_--; |
| 1966 ExtensionErrorReporter::GetInstance()->ClearErrors(); | 1969 InstallCrx(path, true); |
| 1967 | 1970 |
| 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); | 1971 ValidatePrefKeyCount(1); |
| 1976 ValidateIntegerPref(good_crx, "state", Extension::ENABLED); | 1972 ValidateIntegerPref(good_crx, "state", Extension::ENABLED); |
| 1977 ValidateIntegerPref(good_crx, "location", Extension::INTERNAL); | 1973 ValidateIntegerPref(good_crx, "location", Extension::INTERNAL); |
| 1978 } | 1974 } |
| 1979 | 1975 |
| 1980 // Test that we can determine if extensions came from the | 1976 // Test that we can determine if extensions came from the |
| 1981 // Chrome web store. | 1977 // Chrome web store. |
| 1982 TEST_F(ExtensionServiceTest, FromWebStore) { | 1978 TEST_F(ExtensionServiceTest, FromWebStore) { |
| 1983 InitializeEmptyExtensionService(); | 1979 InitializeEmptyExtensionService(); |
| 1984 | 1980 |
| 1985 // A simple extension that should install without error. | 1981 // A simple extension that should install without error. |
| 1986 FilePath path = data_dir_.AppendASCII("good.crx"); | 1982 FilePath path = data_dir_.AppendASCII("good.crx"); |
| 1987 StartCrxInstall(path, false); // Not from web store. | 1983 const Extension* extension = InstallCrx(path, true); // Not from web store. |
| 1988 loop_.RunAllPending(); | 1984 std::string id = extension->id(); |
| 1989 | 1985 |
| 1990 ASSERT_TRUE(installed_); | |
| 1991 ASSERT_EQ(1u, loaded_.size()); | |
| 1992 ASSERT_EQ(0u, GetErrors().size()); | |
| 1993 ValidatePrefKeyCount(1); | 1986 ValidatePrefKeyCount(1); |
| 1994 ValidateBooleanPref(good_crx, "from_webstore", false); | 1987 ValidateBooleanPref(good_crx, "from_webstore", false); |
| 1995 | |
| 1996 const Extension* extension = service_->extensions()->at(0); | |
| 1997 ASSERT_FALSE(extension->from_webstore()); | 1988 ASSERT_FALSE(extension->from_webstore()); |
| 1998 | 1989 |
| 1999 installed_ = NULL; | 1990 // Test install from web store. |
| 2000 loaded_.clear(); | 1991 expected_extensions_count_--; |
| 2001 ExtensionErrorReporter::GetInstance()->ClearErrors(); | 1992 InstallCrxFromWebStore(path, true); // From web store. |
| 2002 | 1993 |
| 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); | 1994 ValidatePrefKeyCount(1); |
| 2011 ValidateBooleanPref(good_crx, "from_webstore", true); | 1995 ValidateBooleanPref(good_crx, "from_webstore", true); |
| 2012 | 1996 |
| 2013 // Reload so extension gets reinitialized with new value. | 1997 // Reload so extension gets reinitialized with new value. |
| 2014 service_->ReloadExtensions(); | 1998 service_->ReloadExtensions(); |
| 2015 extension = service_->extensions()->at(0); | 1999 extension = service_->GetExtensionById(id, false); |
| 2016 ASSERT_TRUE(extension->from_webstore()); | 2000 ASSERT_TRUE(extension->from_webstore()); |
| 2017 | 2001 |
| 2018 // Upgrade to version 2.0 | 2002 // Upgrade to version 2.0 |
| 2019 path = data_dir_.AppendASCII("good2.crx"); | 2003 path = data_dir_.AppendASCII("good2.crx"); |
| 2020 UpdateExtension(good_crx, path, ENABLED); | 2004 UpdateExtension(good_crx, path, ENABLED); |
| 2021 ValidatePrefKeyCount(1); | 2005 ValidatePrefKeyCount(1); |
| 2022 ValidateBooleanPref(good_crx, "from_webstore", true); | 2006 ValidateBooleanPref(good_crx, "from_webstore", true); |
| 2023 } | 2007 } |
| 2024 | 2008 |
| 2025 // Test upgrading a signed extension. | 2009 // Test upgrading a signed extension. |
| 2026 TEST_F(ExtensionServiceTest, UpgradeSignedGood) { | 2010 TEST_F(ExtensionServiceTest, UpgradeSignedGood) { |
| 2027 InitializeEmptyExtensionService(); | 2011 InitializeEmptyExtensionService(); |
| 2028 | 2012 |
| 2029 FilePath path = data_dir_.AppendASCII("good.crx"); | 2013 FilePath path = data_dir_.AppendASCII("good.crx"); |
| 2030 StartCrxInstall(path); | 2014 const Extension* extension = InstallCrx(path, true); |
| 2031 loop_.RunAllPending(); | 2015 std::string id = extension->id(); |
| 2032 | 2016 |
| 2033 ASSERT_TRUE(installed_); | 2017 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()); | 2018 ASSERT_EQ(0u, GetErrors().size()); |
| 2037 | 2019 |
| 2038 // Upgrade to version 2.0 | 2020 // Upgrade to version 1.0.0.1 |
| 2039 path = data_dir_.AppendASCII("good2.crx"); | 2021 path = data_dir_.AppendASCII("good2.crx"); |
| 2040 StartCrxInstall(path); | 2022 expected_extensions_count_--; |
|
Aaron Boodman
2011/11/20 21:39:43
A little weird to directly modify the count in all
Yoyo Zhou
2011/11/21 23:14:52
Yeah, I was looking at doing a similar thing to ex
| |
| 2041 loop_.RunAllPending(); | 2023 InstallCrx(path, true); |
| 2024 extension = service_->GetExtensionById(id, false); | |
| 2042 | 2025 |
| 2043 ASSERT_TRUE(installed_); | 2026 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()); | 2027 ASSERT_EQ(0u, GetErrors().size()); |
| 2047 } | 2028 } |
| 2048 | 2029 |
| 2049 // Test upgrading a signed extension with a bad signature. | 2030 // Test upgrading a signed extension with a bad signature. |
| 2050 TEST_F(ExtensionServiceTest, UpgradeSignedBad) { | 2031 TEST_F(ExtensionServiceTest, UpgradeSignedBad) { |
| 2051 InitializeEmptyExtensionService(); | 2032 InitializeEmptyExtensionService(); |
| 2052 | 2033 |
| 2053 FilePath path = data_dir_.AppendASCII("good.crx"); | 2034 FilePath path = data_dir_.AppendASCII("good.crx"); |
| 2054 StartCrxInstall(path); | 2035 InstallCrx(path, true); |
| 2055 loop_.RunAllPending(); | |
| 2056 | |
| 2057 ASSERT_TRUE(installed_); | |
| 2058 ASSERT_EQ(1u, loaded_.size()); | |
| 2059 ASSERT_EQ(0u, GetErrors().size()); | |
| 2060 installed_ = NULL; | |
| 2061 | 2036 |
| 2062 // Try upgrading with a bad signature. This should fail during the unpack, | 2037 // Try upgrading with a bad signature. This should fail during the unpack, |
| 2063 // because the key will not match the signature. | 2038 // because the key will not match the signature. |
| 2064 path = data_dir_.AppendASCII("bad_signature.crx"); | 2039 path = data_dir_.AppendASCII("bad_signature.crx"); |
| 2065 StartCrxInstall(path); | 2040 InstallCrx(path, false); |
| 2066 loop_.RunAllPending(); | |
| 2067 | |
| 2068 ASSERT_FALSE(installed_); | |
| 2069 ASSERT_EQ(1u, loaded_.size()); | |
| 2070 ASSERT_EQ(1u, GetErrors().size()); | |
| 2071 } | 2041 } |
| 2072 | 2042 |
| 2073 // Test a normal update via the UpdateExtension API | 2043 // Test a normal update via the UpdateExtension API |
| 2074 TEST_F(ExtensionServiceTest, UpdateExtension) { | 2044 TEST_F(ExtensionServiceTest, UpdateExtension) { |
| 2075 InitializeEmptyExtensionService(); | 2045 InitializeEmptyExtensionService(); |
| 2076 | 2046 |
| 2077 FilePath path = data_dir_.AppendASCII("good.crx"); | 2047 FilePath path = data_dir_.AppendASCII("good.crx"); |
| 2078 | 2048 |
| 2079 InstallCrx(path, true); | 2049 const Extension* good = InstallCrx(path, true); |
| 2080 const Extension* good = service_->extensions()->at(0); | |
| 2081 ASSERT_EQ("1.0.0.0", good->VersionString()); | 2050 ASSERT_EQ("1.0.0.0", good->VersionString()); |
| 2082 ASSERT_EQ(good_crx, good->id()); | 2051 ASSERT_EQ(good_crx, good->id()); |
| 2083 | 2052 |
| 2084 path = data_dir_.AppendASCII("good2.crx"); | 2053 path = data_dir_.AppendASCII("good2.crx"); |
| 2085 UpdateExtension(good_crx, path, ENABLED); | 2054 UpdateExtension(good_crx, path, ENABLED); |
| 2086 ASSERT_EQ("1.0.0.1", loaded_[0]->version()->GetString()); | 2055 ASSERT_EQ("1.0.0.1", |
| 2056 service_->GetExtensionById(good_crx, false)-> | |
| 2057 version()->GetString()); | |
| 2087 } | 2058 } |
| 2088 | 2059 |
| 2089 // Test updating a not-already-installed extension - this should fail | 2060 // Test updating a not-already-installed extension - this should fail |
| 2090 TEST_F(ExtensionServiceTest, UpdateNotInstalledExtension) { | 2061 TEST_F(ExtensionServiceTest, UpdateNotInstalledExtension) { |
| 2091 InitializeEmptyExtensionService(); | 2062 InitializeEmptyExtensionService(); |
| 2092 | 2063 |
| 2093 FilePath path = data_dir_.AppendASCII("good.crx"); | 2064 FilePath path = data_dir_.AppendASCII("good.crx"); |
| 2094 UpdateExtension(good_crx, path, UPDATED); | 2065 UpdateExtension(good_crx, path, UPDATED); |
| 2095 loop_.RunAllPending(); | 2066 loop_.RunAllPending(); |
| 2096 | 2067 |
| 2097 ASSERT_EQ(0u, service_->extensions()->size()); | 2068 ASSERT_EQ(0u, service_->extensions()->size()); |
| 2098 ASSERT_FALSE(installed_); | 2069 ASSERT_FALSE(installed_); |
| 2099 ASSERT_EQ(0u, loaded_.size()); | 2070 ASSERT_EQ(0u, loaded_.size()); |
| 2100 } | 2071 } |
| 2101 | 2072 |
| 2102 // Makes sure you can't downgrade an extension via UpdateExtension | 2073 // Makes sure you can't downgrade an extension via UpdateExtension |
| 2103 TEST_F(ExtensionServiceTest, UpdateWillNotDowngrade) { | 2074 TEST_F(ExtensionServiceTest, UpdateWillNotDowngrade) { |
| 2104 InitializeEmptyExtensionService(); | 2075 InitializeEmptyExtensionService(); |
| 2105 | 2076 |
| 2106 FilePath path = data_dir_.AppendASCII("good2.crx"); | 2077 FilePath path = data_dir_.AppendASCII("good2.crx"); |
| 2107 | 2078 |
| 2108 InstallCrx(path, true); | 2079 const Extension* good = InstallCrx(path, true); |
| 2109 const Extension* good = service_->extensions()->at(0); | |
| 2110 ASSERT_EQ("1.0.0.1", good->VersionString()); | 2080 ASSERT_EQ("1.0.0.1", good->VersionString()); |
| 2111 ASSERT_EQ(good_crx, good->id()); | 2081 ASSERT_EQ(good_crx, good->id()); |
| 2112 | 2082 |
| 2113 // Change path from good2.crx -> good.crx | 2083 // Change path from good2.crx -> good.crx |
| 2114 path = data_dir_.AppendASCII("good.crx"); | 2084 path = data_dir_.AppendASCII("good.crx"); |
| 2115 UpdateExtension(good_crx, path, FAILED); | 2085 UpdateExtension(good_crx, path, FAILED); |
| 2116 ASSERT_EQ("1.0.0.1", service_->extensions()->at(0)->VersionString()); | 2086 ASSERT_EQ("1.0.0.1", |
| 2087 service_->GetExtensionById(good_crx, false)-> | |
| 2088 version()->GetString()); | |
| 2117 } | 2089 } |
| 2118 | 2090 |
| 2119 // Make sure calling update with an identical version does nothing | 2091 // Make sure calling update with an identical version does nothing |
| 2120 TEST_F(ExtensionServiceTest, UpdateToSameVersionIsNoop) { | 2092 TEST_F(ExtensionServiceTest, UpdateToSameVersionIsNoop) { |
| 2121 InitializeEmptyExtensionService(); | 2093 InitializeEmptyExtensionService(); |
| 2122 | 2094 |
| 2123 FilePath path = data_dir_.AppendASCII("good.crx"); | 2095 FilePath path = data_dir_.AppendASCII("good.crx"); |
| 2124 | 2096 |
| 2125 InstallCrx(path, true); | 2097 const Extension* good = InstallCrx(path, true); |
| 2126 const Extension* good = service_->extensions()->at(0); | |
| 2127 ASSERT_EQ(good_crx, good->id()); | 2098 ASSERT_EQ(good_crx, good->id()); |
| 2128 UpdateExtension(good_crx, path, FAILED_SILENTLY); | 2099 UpdateExtension(good_crx, path, FAILED_SILENTLY); |
| 2129 } | 2100 } |
| 2130 | 2101 |
| 2131 // Tests that updating an extension does not clobber old state. | 2102 // Tests that updating an extension does not clobber old state. |
| 2132 TEST_F(ExtensionServiceTest, UpdateExtensionPreservesState) { | 2103 TEST_F(ExtensionServiceTest, UpdateExtensionPreservesState) { |
| 2133 InitializeEmptyExtensionService(); | 2104 InitializeEmptyExtensionService(); |
| 2134 | 2105 |
| 2135 FilePath path = data_dir_.AppendASCII("good.crx"); | 2106 FilePath path = data_dir_.AppendASCII("good.crx"); |
| 2136 | 2107 |
| 2137 InstallCrx(path, true); | 2108 const Extension* good = InstallCrx(path, true); |
| 2138 const Extension* good = service_->extensions()->at(0); | |
| 2139 ASSERT_EQ("1.0.0.0", good->VersionString()); | 2109 ASSERT_EQ("1.0.0.0", good->VersionString()); |
| 2140 ASSERT_EQ(good_crx, good->id()); | 2110 ASSERT_EQ(good_crx, good->id()); |
| 2141 | 2111 |
| 2142 // Disable it and allow it to run in incognito. These settings should carry | 2112 // Disable it and allow it to run in incognito. These settings should carry |
| 2143 // over to the updated version. | 2113 // over to the updated version. |
| 2144 service_->DisableExtension(good->id()); | 2114 service_->DisableExtension(good->id()); |
| 2145 service_->SetIsIncognitoEnabled(good->id(), true); | 2115 service_->SetIsIncognitoEnabled(good->id(), true); |
| 2146 | 2116 |
| 2147 path = data_dir_.AppendASCII("good2.crx"); | 2117 path = data_dir_.AppendASCII("good2.crx"); |
| 2148 UpdateExtension(good_crx, path, INSTALLED); | 2118 UpdateExtension(good_crx, path, INSTALLED); |
| 2149 ASSERT_EQ(1u, service_->disabled_extensions()->size()); | 2119 ASSERT_EQ(1u, service_->disabled_extensions()->size()); |
| 2150 const Extension* good2 = service_->disabled_extensions()->at(0); | 2120 const Extension* good2 = service_->GetExtensionById(good_crx, true); |
| 2151 ASSERT_EQ("1.0.0.1", good2->version()->GetString()); | 2121 ASSERT_EQ("1.0.0.1", good2->version()->GetString()); |
| 2152 EXPECT_TRUE(service_->IsIncognitoEnabled(good2->id())); | 2122 EXPECT_TRUE(service_->IsIncognitoEnabled(good2->id())); |
| 2153 } | 2123 } |
| 2154 | 2124 |
| 2155 // Tests that updating preserves extension location. | 2125 // Tests that updating preserves extension location. |
| 2156 TEST_F(ExtensionServiceTest, UpdateExtensionPreservesLocation) { | 2126 TEST_F(ExtensionServiceTest, UpdateExtensionPreservesLocation) { |
| 2157 InitializeEmptyExtensionService(); | 2127 InitializeEmptyExtensionService(); |
| 2158 | 2128 |
| 2159 FilePath path = data_dir_.AppendASCII("good.crx"); | 2129 FilePath path = data_dir_.AppendASCII("good.crx"); |
| 2160 | 2130 |
| 2161 InstallCrx(path, true); | 2131 const Extension* good = InstallCrx(path, true); |
| 2162 const Extension* good = service_->extensions()->at(0); | |
| 2163 | 2132 |
| 2164 ASSERT_EQ("1.0.0.0", good->VersionString()); | 2133 ASSERT_EQ("1.0.0.0", good->VersionString()); |
| 2165 ASSERT_EQ(good_crx, good->id()); | 2134 ASSERT_EQ(good_crx, good->id()); |
| 2166 | 2135 |
| 2167 // Simulate non-internal location. | 2136 // Simulate non-internal location. |
| 2168 const_cast<Extension*>(good)->location_ = Extension::EXTERNAL_PREF; | 2137 const_cast<Extension*>(good)->location_ = Extension::EXTERNAL_PREF; |
| 2169 | 2138 |
| 2170 path = data_dir_.AppendASCII("good2.crx"); | 2139 path = data_dir_.AppendASCII("good2.crx"); |
| 2171 UpdateExtension(good_crx, path, ENABLED); | 2140 UpdateExtension(good_crx, path, ENABLED); |
| 2172 const Extension* good2 = service_->extensions()->at(0); | 2141 const Extension* good2 = service_->GetExtensionById(good_crx, false); |
| 2173 ASSERT_EQ("1.0.0.1", good2->version()->GetString()); | 2142 ASSERT_EQ("1.0.0.1", good2->version()->GetString()); |
| 2174 EXPECT_EQ(good2->location(), Extension::EXTERNAL_PREF); | 2143 EXPECT_EQ(good2->location(), Extension::EXTERNAL_PREF); |
| 2175 } | 2144 } |
| 2176 | 2145 |
| 2177 // Makes sure that LOAD extension types can downgrade. | 2146 // Makes sure that LOAD extension types can downgrade. |
| 2178 TEST_F(ExtensionServiceTest, LoadExtensionsCanDowngrade) { | 2147 TEST_F(ExtensionServiceTest, LoadExtensionsCanDowngrade) { |
| 2179 InitializeEmptyExtensionService(); | 2148 InitializeEmptyExtensionService(); |
| 2180 | 2149 |
| 2181 ScopedTempDir temp; | 2150 ScopedTempDir temp; |
| 2182 ASSERT_TRUE(temp.CreateUniqueTempDir()); | 2151 ASSERT_TRUE(temp.CreateUniqueTempDir()); |
| (...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2421 | 2390 |
| 2422 EXPECT_FALSE(service_->pending_extension_manager()->IsIdPending(kGoodId)); | 2391 EXPECT_FALSE(service_->pending_extension_manager()->IsIdPending(kGoodId)); |
| 2423 } | 2392 } |
| 2424 | 2393 |
| 2425 // Test updating a pending extension for one that is already | 2394 // Test updating a pending extension for one that is already |
| 2426 // installed. | 2395 // installed. |
| 2427 TEST_F(ExtensionServiceTest, UpdatePendingExtensionAlreadyInstalled) { | 2396 TEST_F(ExtensionServiceTest, UpdatePendingExtensionAlreadyInstalled) { |
| 2428 InitializeEmptyExtensionService(); | 2397 InitializeEmptyExtensionService(); |
| 2429 | 2398 |
| 2430 FilePath path = data_dir_.AppendASCII("good.crx"); | 2399 FilePath path = data_dir_.AppendASCII("good.crx"); |
| 2431 InstallCrx(path, true); | 2400 const Extension* good = InstallCrx(path, true); |
| 2432 ASSERT_EQ(1u, service_->extensions()->size()); | 2401 ASSERT_EQ(1u, service_->extensions()->size()); |
| 2433 const Extension* good = service_->extensions()->at(0); | |
| 2434 | 2402 |
| 2435 EXPECT_FALSE(good->is_theme()); | 2403 EXPECT_FALSE(good->is_theme()); |
| 2436 | 2404 |
| 2437 // Use AddExtensionImpl() as AddFrom*() would balk. | 2405 // Use AddExtensionImpl() as AddFrom*() would balk. |
| 2438 service_->pending_extension_manager()->AddExtensionImpl( | 2406 service_->pending_extension_manager()->AddExtensionImpl( |
| 2439 good->id(), good->update_url(), &IsExtension, | 2407 good->id(), good->update_url(), &IsExtension, |
| 2440 kGoodIsFromSync, kGoodInstallSilently, Extension::INTERNAL); | 2408 kGoodIsFromSync, kGoodInstallSilently, Extension::INTERNAL); |
| 2441 UpdateExtension(good->id(), path, ENABLED); | 2409 UpdateExtension(good->id(), path, ENABLED); |
| 2442 | 2410 |
| 2443 EXPECT_FALSE(service_->pending_extension_manager()->IsIdPending(kGoodId)); | 2411 EXPECT_FALSE(service_->pending_extension_manager()->IsIdPending(kGoodId)); |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 2471 ValidateBooleanPref(good2, "blacklist", true); | 2439 ValidateBooleanPref(good2, "blacklist", true); |
| 2472 EXPECT_FALSE(IsPrefExist("invalid_id", "blacklist")); | 2440 EXPECT_FALSE(IsPrefExist("invalid_id", "blacklist")); |
| 2473 } | 2441 } |
| 2474 | 2442 |
| 2475 // Unload installed extension from blacklist. | 2443 // Unload installed extension from blacklist. |
| 2476 TEST_F(ExtensionServiceTest, UnloadBlacklistedExtension) { | 2444 TEST_F(ExtensionServiceTest, UnloadBlacklistedExtension) { |
| 2477 InitializeEmptyExtensionService(); | 2445 InitializeEmptyExtensionService(); |
| 2478 | 2446 |
| 2479 FilePath path = data_dir_.AppendASCII("good.crx"); | 2447 FilePath path = data_dir_.AppendASCII("good.crx"); |
| 2480 | 2448 |
| 2481 InstallCrx(path, true); | 2449 const Extension* good = InstallCrx(path, true); |
| 2482 const Extension* good = service_->extensions()->at(0); | |
| 2483 EXPECT_EQ(good_crx, good->id()); | 2450 EXPECT_EQ(good_crx, good->id()); |
| 2484 UpdateExtension(good_crx, path, FAILED_SILENTLY); | 2451 UpdateExtension(good_crx, path, FAILED_SILENTLY); |
| 2485 | 2452 |
| 2486 std::vector<std::string> blacklist; | 2453 std::vector<std::string> blacklist; |
| 2487 blacklist.push_back(good_crx); | 2454 blacklist.push_back(good_crx); |
| 2488 service_->UpdateExtensionBlacklist(blacklist); | 2455 service_->UpdateExtensionBlacklist(blacklist); |
| 2489 // Make sure pref is updated | 2456 // Make sure pref is updated |
| 2490 loop_.RunAllPending(); | 2457 loop_.RunAllPending(); |
| 2491 | 2458 |
| 2492 // Now, the good_crx is blacklisted. | 2459 // Now, the good_crx is blacklisted. |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 2509 blacklist.push_back(good_crx); | 2476 blacklist.push_back(good_crx); |
| 2510 service_->UpdateExtensionBlacklist(blacklist); | 2477 service_->UpdateExtensionBlacklist(blacklist); |
| 2511 // Make sure pref is updated | 2478 // Make sure pref is updated |
| 2512 loop_.RunAllPending(); | 2479 loop_.RunAllPending(); |
| 2513 | 2480 |
| 2514 // Now, the good_crx is blacklisted. | 2481 // Now, the good_crx is blacklisted. |
| 2515 ValidateBooleanPref(good_crx, "blacklist", true); | 2482 ValidateBooleanPref(good_crx, "blacklist", true); |
| 2516 | 2483 |
| 2517 // We can not install good_crx. | 2484 // We can not install good_crx. |
| 2518 FilePath path = data_dir_.AppendASCII("good.crx"); | 2485 FilePath path = data_dir_.AppendASCII("good.crx"); |
| 2519 StartCrxInstall(path); | 2486 InstallCrx(path, false); |
| 2520 loop_.RunAllPending(); | |
| 2521 EXPECT_EQ(0u, service_->extensions()->size()); | 2487 EXPECT_EQ(0u, service_->extensions()->size()); |
| 2522 ValidateBooleanPref(good_crx, "blacklist", true); | 2488 ValidateBooleanPref(good_crx, "blacklist", true); |
| 2523 } | 2489 } |
| 2524 | 2490 |
| 2525 // Test loading extensions from the profile directory, except | 2491 // Test loading extensions from the profile directory, except |
| 2526 // blacklisted ones. | 2492 // blacklisted ones. |
| 2527 TEST_F(ExtensionServiceTest, WillNotLoadBlacklistedExtensionsFromDirectory) { | 2493 TEST_F(ExtensionServiceTest, WillNotLoadBlacklistedExtensionsFromDirectory) { |
| 2528 // Initialize the test dir with a good Preferences/extensions. | 2494 // Initialize the test dir with a good Preferences/extensions. |
| 2529 FilePath source_install_dir = data_dir_ | 2495 FilePath source_install_dir = data_dir_ |
| 2530 .AppendASCII("good") | 2496 .AppendASCII("good") |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 2547 service_->Init(); | 2513 service_->Init(); |
| 2548 loop_.RunAllPending(); | 2514 loop_.RunAllPending(); |
| 2549 | 2515 |
| 2550 std::vector<std::string> errors = GetErrors(); | 2516 std::vector<std::string> errors = GetErrors(); |
| 2551 for (std::vector<std::string>::iterator err = errors.begin(); | 2517 for (std::vector<std::string>::iterator err = errors.begin(); |
| 2552 err != errors.end(); ++err) { | 2518 err != errors.end(); ++err) { |
| 2553 LOG(ERROR) << *err; | 2519 LOG(ERROR) << *err; |
| 2554 } | 2520 } |
| 2555 ASSERT_EQ(2u, loaded_.size()); | 2521 ASSERT_EQ(2u, loaded_.size()); |
| 2556 | 2522 |
| 2557 EXPECT_NE(std::string(good1), loaded_[0]->id()); | 2523 EXPECT_FALSE(service_->GetExtensionById(good1, true)); |
| 2558 EXPECT_NE(std::string(good1), loaded_[1]->id()); | |
| 2559 } | 2524 } |
| 2560 | 2525 |
| 2561 // Will not install extension blacklisted by policy. | 2526 // Will not install extension blacklisted by policy. |
| 2562 TEST_F(ExtensionServiceTest, BlacklistedByPolicyWillNotInstall) { | 2527 TEST_F(ExtensionServiceTest, BlacklistedByPolicyWillNotInstall) { |
| 2563 InitializeEmptyExtensionService(); | 2528 InitializeEmptyExtensionService(); |
| 2564 | 2529 |
| 2565 // Blacklist everything. | 2530 // Blacklist everything. |
| 2566 { | 2531 { |
| 2567 ListPrefUpdate update(profile_->GetPrefs(), | 2532 ListPrefUpdate update(profile_->GetPrefs(), |
| 2568 prefs::kExtensionInstallDenyList); | 2533 prefs::kExtensionInstallDenyList); |
| 2569 ListValue* blacklist = update.Get(); | 2534 ListValue* blacklist = update.Get(); |
| 2570 blacklist->Append(Value::CreateStringValue("*")); | 2535 blacklist->Append(Value::CreateStringValue("*")); |
| 2571 } | 2536 } |
| 2572 | 2537 |
| 2573 // Blacklist prevents us from installing good_crx. | 2538 // Blacklist prevents us from installing good_crx. |
| 2574 FilePath path = data_dir_.AppendASCII("good.crx"); | 2539 FilePath path = data_dir_.AppendASCII("good.crx"); |
| 2575 StartCrxInstall(path); | 2540 InstallCrx(path, false); |
| 2576 loop_.RunAllPending(); | |
| 2577 EXPECT_EQ(0u, service_->extensions()->size()); | 2541 EXPECT_EQ(0u, service_->extensions()->size()); |
| 2578 | 2542 |
| 2579 // Now whitelist this particular extension. | 2543 // Now whitelist this particular extension. |
| 2580 { | 2544 { |
| 2581 ListPrefUpdate update(profile_->GetPrefs(), | 2545 ListPrefUpdate update(profile_->GetPrefs(), |
| 2582 prefs::kExtensionInstallAllowList); | 2546 prefs::kExtensionInstallAllowList); |
| 2583 ListValue* whitelist = update.Get(); | 2547 ListValue* whitelist = update.Get(); |
| 2584 whitelist->Append(Value::CreateStringValue(good_crx)); | 2548 whitelist->Append(Value::CreateStringValue(good_crx)); |
| 2585 } | 2549 } |
| 2586 | 2550 |
| 2587 | |
| 2588 // Ensure we can now install good_crx. | 2551 // Ensure we can now install good_crx. |
| 2589 StartCrxInstall(path); | 2552 InstallCrx(path, true); |
| 2590 loop_.RunAllPending(); | |
| 2591 EXPECT_EQ(1u, service_->extensions()->size()); | 2553 EXPECT_EQ(1u, service_->extensions()->size()); |
| 2592 } | 2554 } |
| 2593 | 2555 |
| 2594 // Extension blacklisted by policy get unloaded after installing. | 2556 // Extension blacklisted by policy get unloaded after installing. |
| 2595 TEST_F(ExtensionServiceTest, BlacklistedByPolicyRemovedIfRunning) { | 2557 TEST_F(ExtensionServiceTest, BlacklistedByPolicyRemovedIfRunning) { |
| 2596 InitializeEmptyExtensionService(); | 2558 InitializeEmptyExtensionService(); |
| 2597 | 2559 |
| 2598 // Install good_crx. | 2560 // Install good_crx. |
| 2599 FilePath path = data_dir_.AppendASCII("good.crx"); | 2561 FilePath path = data_dir_.AppendASCII("good.crx"); |
| 2600 StartCrxInstall(path); | 2562 InstallCrx(path, true); |
| 2601 loop_.RunAllPending(); | |
| 2602 EXPECT_EQ(1u, service_->extensions()->size()); | 2563 EXPECT_EQ(1u, service_->extensions()->size()); |
| 2603 | 2564 |
| 2604 { // Scope for pref update notification. | 2565 { // Scope for pref update notification. |
| 2605 PrefService* prefs = profile_->GetPrefs(); | 2566 PrefService* prefs = profile_->GetPrefs(); |
| 2606 ListPrefUpdate update(prefs, prefs::kExtensionInstallDenyList); | 2567 ListPrefUpdate update(prefs, prefs::kExtensionInstallDenyList); |
| 2607 ListValue* blacklist = update.Get(); | 2568 ListValue* blacklist = update.Get(); |
| 2608 ASSERT_TRUE(blacklist != NULL); | 2569 ASSERT_TRUE(blacklist != NULL); |
| 2609 | 2570 |
| 2610 // Blacklist this extension. | 2571 // Blacklist this extension. |
| 2611 blacklist->Append(Value::CreateStringValue(good_crx)); | 2572 blacklist->Append(Value::CreateStringValue(good_crx)); |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 2636 .AppendASCII(good0) | 2597 .AppendASCII(good0) |
| 2637 .AppendASCII("1.0.0.0"); | 2598 .AppendASCII("1.0.0.0"); |
| 2638 std::string manifest; | 2599 std::string manifest; |
| 2639 ASSERT_TRUE(file_util::ReadFileToString( | 2600 ASSERT_TRUE(file_util::ReadFileToString( |
| 2640 path.Append(Extension::kManifestFilename), &manifest)); | 2601 path.Append(Extension::kManifestFilename), &manifest)); |
| 2641 service_->component_loader()->Add(manifest, path); | 2602 service_->component_loader()->Add(manifest, path); |
| 2642 service_->Init(); | 2603 service_->Init(); |
| 2643 | 2604 |
| 2644 // Extension should be installed despite blacklist. | 2605 // Extension should be installed despite blacklist. |
| 2645 ASSERT_EQ(1u, service_->extensions()->size()); | 2606 ASSERT_EQ(1u, service_->extensions()->size()); |
| 2646 EXPECT_EQ(good0, service_->extensions()->at(0)->id()); | 2607 EXPECT_TRUE(service_->GetExtensionById(good0, false)); |
| 2647 | 2608 |
| 2648 // Poke external providers and make sure the extension is still present. | 2609 // Poke external providers and make sure the extension is still present. |
| 2649 service_->CheckForExternalUpdates(); | 2610 service_->CheckForExternalUpdates(); |
| 2650 ASSERT_EQ(1u, service_->extensions()->size()); | 2611 ASSERT_EQ(1u, service_->extensions()->size()); |
| 2651 EXPECT_EQ(good0, service_->extensions()->at(0)->id()); | 2612 EXPECT_TRUE(service_->GetExtensionById(good0, false)); |
| 2652 | 2613 |
| 2653 // Extension should not be uninstalled on blacklist changes. | 2614 // Extension should not be uninstalled on blacklist changes. |
| 2654 { | 2615 { |
| 2655 ListPrefUpdate update(profile_->GetPrefs(), | 2616 ListPrefUpdate update(profile_->GetPrefs(), |
| 2656 prefs::kExtensionInstallDenyList); | 2617 prefs::kExtensionInstallDenyList); |
| 2657 ListValue* blacklist = update.Get(); | 2618 ListValue* blacklist = update.Get(); |
| 2658 blacklist->Append(Value::CreateStringValue(good0)); | 2619 blacklist->Append(Value::CreateStringValue(good0)); |
| 2659 } | 2620 } |
| 2660 loop_.RunAllPending(); | 2621 loop_.RunAllPending(); |
| 2661 ASSERT_EQ(1u, service_->extensions()->size()); | 2622 ASSERT_EQ(1u, service_->extensions()->size()); |
| 2662 EXPECT_EQ(good0, service_->extensions()->at(0)->id()); | 2623 EXPECT_TRUE(service_->GetExtensionById(good0, false)); |
| 2663 } | 2624 } |
| 2664 | 2625 |
| 2665 // Tests that policy-installed extensions are not blacklisted by policy. | 2626 // Tests that policy-installed extensions are not blacklisted by policy. |
| 2666 TEST_F(ExtensionServiceTest, PolicyInstalledExtensionsWhitelisted) { | 2627 TEST_F(ExtensionServiceTest, PolicyInstalledExtensionsWhitelisted) { |
| 2667 InitializeEmptyExtensionService(); | 2628 InitializeEmptyExtensionService(); |
| 2668 | 2629 |
| 2669 // Blacklist everything. | 2630 // Blacklist everything. |
| 2670 { | 2631 { |
| 2671 ListPrefUpdate update(profile_->GetPrefs(), | 2632 ListPrefUpdate update(profile_->GetPrefs(), |
| 2672 prefs::kExtensionInstallDenyList); | 2633 prefs::kExtensionInstallDenyList); |
| 2673 ListValue* blacklist = update.Get(); | 2634 ListValue* blacklist = update.Get(); |
| 2674 blacklist->Append(Value::CreateStringValue("*")); | 2635 blacklist->Append(Value::CreateStringValue("*")); |
| 2675 } | 2636 } |
| 2676 | 2637 |
| 2677 // Have policy force-install an extension. | 2638 // Have policy force-install an extension. |
| 2678 MockExtensionProvider* provider = | 2639 MockExtensionProvider* provider = |
| 2679 new MockExtensionProvider(service_, | 2640 new MockExtensionProvider(service_, |
| 2680 Extension::EXTERNAL_POLICY_DOWNLOAD); | 2641 Extension::EXTERNAL_POLICY_DOWNLOAD); |
| 2681 AddMockExternalProvider(provider); | 2642 AddMockExternalProvider(provider); |
| 2682 provider->UpdateOrAddExtension(good_crx, "1.0.0.0", | 2643 provider->UpdateOrAddExtension(good_crx, "1.0.0.0", |
| 2683 data_dir_.AppendASCII("good.crx")); | 2644 data_dir_.AppendASCII("good.crx")); |
| 2684 | 2645 |
| 2685 // Reloading extensions should find our externally registered extension | 2646 // Reloading extensions should find our externally registered extension |
| 2686 // and install it. | 2647 // and install it. |
| 2687 service_->CheckForExternalUpdates(); | 2648 service_->CheckForExternalUpdates(); |
| 2688 loop_.RunAllPending(); | 2649 loop_.RunAllPending(); |
| 2689 | 2650 |
| 2690 // Extension should be installed despite blacklist. | 2651 // Extension should be installed despite blacklist. |
| 2691 ASSERT_EQ(1u, service_->extensions()->size()); | 2652 ASSERT_EQ(1u, service_->extensions()->size()); |
| 2692 EXPECT_EQ(good_crx, service_->extensions()->at(0)->id()); | 2653 EXPECT_TRUE(service_->GetExtensionById(good_crx, false)); |
| 2693 | 2654 |
| 2694 // Blacklist update should not uninstall the extension. | 2655 // Blacklist update should not uninstall the extension. |
| 2695 { | 2656 { |
| 2696 ListPrefUpdate update(profile_->GetPrefs(), | 2657 ListPrefUpdate update(profile_->GetPrefs(), |
| 2697 prefs::kExtensionInstallDenyList); | 2658 prefs::kExtensionInstallDenyList); |
| 2698 ListValue* blacklist = update.Get(); | 2659 ListValue* blacklist = update.Get(); |
| 2699 blacklist->Append(Value::CreateStringValue(good0)); | 2660 blacklist->Append(Value::CreateStringValue(good0)); |
| 2700 } | 2661 } |
| 2701 loop_.RunAllPending(); | 2662 loop_.RunAllPending(); |
| 2702 ASSERT_EQ(1u, service_->extensions()->size()); | 2663 ASSERT_EQ(1u, service_->extensions()->size()); |
| 2703 EXPECT_EQ(good_crx, service_->extensions()->at(0)->id()); | 2664 EXPECT_TRUE(service_->GetExtensionById(good_crx, false)); |
| 2704 } | 2665 } |
| 2705 | 2666 |
| 2706 // Tests disabling extensions | 2667 // Tests disabling extensions |
| 2707 TEST_F(ExtensionServiceTest, DisableExtension) { | 2668 TEST_F(ExtensionServiceTest, DisableExtension) { |
| 2708 InitializeEmptyExtensionService(); | 2669 InitializeEmptyExtensionService(); |
| 2709 | 2670 |
| 2710 InstallCrx(data_dir_.AppendASCII("good.crx"), true); | 2671 InstallCrx(data_dir_.AppendASCII("good.crx"), true); |
| 2711 EXPECT_FALSE(service_->extensions()->empty()); | 2672 EXPECT_FALSE(service_->extensions()->empty()); |
| 2712 EXPECT_TRUE(service_->GetExtensionById(good_crx, true) != NULL); | 2673 EXPECT_TRUE(service_->GetExtensionById(good_crx, true)); |
| 2713 EXPECT_TRUE(service_->GetExtensionById(good_crx, false) != NULL); | 2674 EXPECT_TRUE(service_->GetExtensionById(good_crx, false)); |
| 2714 EXPECT_TRUE(service_->disabled_extensions()->empty()); | 2675 EXPECT_TRUE(service_->disabled_extensions()->empty()); |
| 2715 | 2676 |
| 2716 // Disable it. | 2677 // Disable it. |
| 2717 service_->DisableExtension(good_crx); | 2678 service_->DisableExtension(good_crx); |
| 2718 | 2679 |
| 2719 EXPECT_TRUE(service_->extensions()->empty()); | 2680 EXPECT_TRUE(service_->extensions()->empty()); |
| 2720 EXPECT_TRUE(service_->GetExtensionById(good_crx, true) != NULL); | 2681 EXPECT_TRUE(service_->GetExtensionById(good_crx, true)); |
| 2721 EXPECT_FALSE(service_->GetExtensionById(good_crx, false) != NULL); | 2682 EXPECT_FALSE(service_->GetExtensionById(good_crx, false)); |
| 2722 EXPECT_FALSE(service_->disabled_extensions()->empty()); | 2683 EXPECT_FALSE(service_->disabled_extensions()->empty()); |
| 2723 } | 2684 } |
| 2724 | 2685 |
| 2725 TEST_F(ExtensionServiceTest, DisableTerminatedExtension) { | 2686 TEST_F(ExtensionServiceTest, DisableTerminatedExtension) { |
| 2726 InitializeEmptyExtensionService(); | 2687 InitializeEmptyExtensionService(); |
| 2727 | 2688 |
| 2728 InstallCrx(data_dir_.AppendASCII("good.crx"), true); | 2689 InstallCrx(data_dir_.AppendASCII("good.crx"), true); |
| 2729 TerminateExtension(good_crx); | 2690 TerminateExtension(good_crx); |
| 2730 EXPECT_TRUE(service_->GetTerminatedExtension(good_crx)); | 2691 EXPECT_TRUE(service_->GetTerminatedExtension(good_crx)); |
| 2731 | 2692 |
| 2732 // Disable it. | 2693 // Disable it. |
| 2733 service_->DisableExtension(good_crx); | 2694 service_->DisableExtension(good_crx); |
| 2734 | 2695 |
| 2735 EXPECT_FALSE(service_->GetTerminatedExtension(good_crx)); | 2696 EXPECT_FALSE(service_->GetTerminatedExtension(good_crx)); |
| 2736 EXPECT_TRUE(service_->GetExtensionById(good_crx, true) != NULL); | 2697 EXPECT_TRUE(service_->GetExtensionById(good_crx, true)); |
| 2737 EXPECT_FALSE(service_->disabled_extensions()->empty()); | 2698 EXPECT_FALSE(service_->disabled_extensions()->empty()); |
| 2738 } | 2699 } |
| 2739 | 2700 |
| 2740 // Tests disabling all extensions (simulating --disable-extensions flag). | 2701 // Tests disabling all extensions (simulating --disable-extensions flag). |
| 2741 TEST_F(ExtensionServiceTest, DisableAllExtensions) { | 2702 TEST_F(ExtensionServiceTest, DisableAllExtensions) { |
| 2742 InitializeEmptyExtensionService(); | 2703 InitializeEmptyExtensionService(); |
| 2743 | 2704 |
| 2744 | |
| 2745 FilePath path = data_dir_.AppendASCII("good.crx"); | 2705 FilePath path = data_dir_.AppendASCII("good.crx"); |
| 2746 InstallCrx(path, true); | 2706 InstallCrx(path, true); |
| 2747 | 2707 |
| 2748 EXPECT_EQ(1u, service_->extensions()->size()); | 2708 EXPECT_EQ(1u, service_->extensions()->size()); |
| 2749 EXPECT_EQ(0u, service_->disabled_extensions()->size()); | 2709 EXPECT_EQ(0u, service_->disabled_extensions()->size()); |
| 2750 | 2710 |
| 2751 // Disable extensions. | 2711 // Disable extensions. |
| 2752 service_->set_extensions_enabled(false); | 2712 service_->set_extensions_enabled(false); |
| 2753 service_->ReloadExtensions(); | 2713 service_->ReloadExtensions(); |
| 2754 | 2714 |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 2765 EXPECT_EQ(0u, service_->disabled_extensions()->size()); | 2725 EXPECT_EQ(0u, service_->disabled_extensions()->size()); |
| 2766 | 2726 |
| 2767 // And then re-enable the extensions. | 2727 // And then re-enable the extensions. |
| 2768 service_->set_extensions_enabled(true); | 2728 service_->set_extensions_enabled(true); |
| 2769 service_->ReloadExtensions(); | 2729 service_->ReloadExtensions(); |
| 2770 | 2730 |
| 2771 EXPECT_EQ(1u, service_->extensions()->size()); | 2731 EXPECT_EQ(1u, service_->extensions()->size()); |
| 2772 EXPECT_EQ(0u, service_->disabled_extensions()->size()); | 2732 EXPECT_EQ(0u, service_->disabled_extensions()->size()); |
| 2773 } | 2733 } |
| 2774 | 2734 |
| 2775 // Tests reloading extensions | 2735 // Tests reloading extensions. |
| 2776 TEST_F(ExtensionServiceTest, ReloadExtensions) { | 2736 TEST_F(ExtensionServiceTest, ReloadExtensions) { |
| 2777 InitializeEmptyExtensionService(); | 2737 InitializeEmptyExtensionService(); |
| 2778 | 2738 |
| 2779 // Simple extension that should install without error. | 2739 // Simple extension that should install without error. |
| 2780 FilePath path = data_dir_.AppendASCII("good.crx"); | 2740 FilePath path = data_dir_.AppendASCII("good.crx"); |
| 2781 InstallCrx(path, true); | 2741 InstallCrx(path, true); |
| 2782 const char* extension_id = good_crx; | 2742 const char* extension_id = good_crx; |
| 2783 service_->DisableExtension(extension_id); | 2743 service_->DisableExtension(extension_id); |
| 2784 | 2744 |
| 2785 EXPECT_EQ(0u, service_->extensions()->size()); | 2745 EXPECT_EQ(0u, service_->extensions()->size()); |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2866 }; | 2826 }; |
| 2867 | 2827 |
| 2868 // Verifies extension state is removed upon uninstall. | 2828 // Verifies extension state is removed upon uninstall. |
| 2869 TEST_F(ExtensionServiceTest, ClearExtensionData) { | 2829 TEST_F(ExtensionServiceTest, ClearExtensionData) { |
| 2870 InitializeEmptyExtensionService(); | 2830 InitializeEmptyExtensionService(); |
| 2871 ExtensionCookieCallback callback; | 2831 ExtensionCookieCallback callback; |
| 2872 | 2832 |
| 2873 // Load a test extension. | 2833 // Load a test extension. |
| 2874 FilePath path = data_dir_; | 2834 FilePath path = data_dir_; |
| 2875 path = path.AppendASCII("good.crx"); | 2835 path = path.AppendASCII("good.crx"); |
| 2876 InstallCrx(path, true); | 2836 const Extension* extension = InstallCrx(path, true); |
| 2877 const Extension* extension = service_->GetExtensionById(good_crx, false); | |
| 2878 ASSERT_TRUE(extension); | 2837 ASSERT_TRUE(extension); |
| 2879 GURL ext_url(extension->url()); | 2838 GURL ext_url(extension->url()); |
| 2880 string16 origin_id = | 2839 string16 origin_id = |
| 2881 webkit_database::DatabaseUtil::GetOriginIdentifier(ext_url); | 2840 webkit_database::DatabaseUtil::GetOriginIdentifier(ext_url); |
| 2882 | 2841 |
| 2883 // Set a cookie for the extension. | 2842 // Set a cookie for the extension. |
| 2884 net::CookieMonster* cookie_monster = | 2843 net::CookieMonster* cookie_monster = |
| 2885 profile_->GetRequestContextForExtensions()->GetURLRequestContext()-> | 2844 profile_->GetRequestContextForExtensions()->GetURLRequestContext()-> |
| 2886 cookie_store()->GetCookieMonster(); | 2845 cookie_store()->GetCookieMonster(); |
| 2887 ASSERT_TRUE(cookie_monster); | 2846 ASSERT_TRUE(cookie_monster); |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2955 | 2914 |
| 2956 // Verifies app state is removed upon uninstall. | 2915 // Verifies app state is removed upon uninstall. |
| 2957 TEST_F(ExtensionServiceTest, ClearAppData) { | 2916 TEST_F(ExtensionServiceTest, ClearAppData) { |
| 2958 InitializeEmptyExtensionService(); | 2917 InitializeEmptyExtensionService(); |
| 2959 InitializeRequestContext(); | 2918 InitializeRequestContext(); |
| 2960 ExtensionCookieCallback callback; | 2919 ExtensionCookieCallback callback; |
| 2961 | 2920 |
| 2962 int pref_count = 0; | 2921 int pref_count = 0; |
| 2963 | 2922 |
| 2964 // Install app1 with unlimited storage. | 2923 // Install app1 with unlimited storage. |
| 2965 PackAndInstallCrx(data_dir_.AppendASCII("app1"), true); | 2924 const Extension* extension = |
| 2925 PackAndInstallCrx(data_dir_.AppendASCII("app1"), true); | |
| 2966 ValidatePrefKeyCount(++pref_count); | 2926 ValidatePrefKeyCount(++pref_count); |
| 2967 ASSERT_EQ(1u, service_->extensions()->size()); | 2927 ASSERT_EQ(1u, service_->extensions()->size()); |
| 2968 const Extension* extension = service_->extensions()->at(0); | |
| 2969 const std::string id1 = extension->id(); | 2928 const std::string id1 = extension->id(); |
| 2970 EXPECT_TRUE(extension->HasAPIPermission( | 2929 EXPECT_TRUE(extension->HasAPIPermission( |
| 2971 ExtensionAPIPermission::kUnlimitedStorage)); | 2930 ExtensionAPIPermission::kUnlimitedStorage)); |
| 2972 const GURL origin1(extension->GetFullLaunchURL().GetOrigin()); | 2931 const GURL origin1(extension->GetFullLaunchURL().GetOrigin()); |
| 2973 EXPECT_TRUE(profile_->GetExtensionSpecialStoragePolicy()-> | 2932 EXPECT_TRUE(profile_->GetExtensionSpecialStoragePolicy()-> |
| 2974 IsStorageUnlimited(origin1)); | 2933 IsStorageUnlimited(origin1)); |
| 2975 string16 origin_id = | 2934 string16 origin_id = |
| 2976 webkit_database::DatabaseUtil::GetOriginIdentifier(origin1); | 2935 webkit_database::DatabaseUtil::GetOriginIdentifier(origin1); |
| 2977 | 2936 |
| 2978 // Install app2 from the same origin with unlimited storage. | 2937 // Install app2 from the same origin with unlimited storage. |
| 2979 PackAndInstallCrx(data_dir_.AppendASCII("app2"), true); | 2938 extension = PackAndInstallCrx(data_dir_.AppendASCII("app2"), true); |
| 2980 ValidatePrefKeyCount(++pref_count); | 2939 ValidatePrefKeyCount(++pref_count); |
| 2981 ASSERT_EQ(2u, service_->extensions()->size()); | 2940 ASSERT_EQ(2u, service_->extensions()->size()); |
| 2982 extension = service_->extensions()->at(1); | |
| 2983 const std::string id2 = extension->id(); | 2941 const std::string id2 = extension->id(); |
| 2984 EXPECT_TRUE(extension->HasAPIPermission( | 2942 EXPECT_TRUE(extension->HasAPIPermission( |
| 2985 ExtensionAPIPermission::kUnlimitedStorage)); | 2943 ExtensionAPIPermission::kUnlimitedStorage)); |
| 2986 EXPECT_TRUE(extension->web_extent().MatchesURL( | 2944 EXPECT_TRUE(extension->web_extent().MatchesURL( |
| 2987 extension->GetFullLaunchURL())); | 2945 extension->GetFullLaunchURL())); |
| 2988 const GURL origin2(extension->GetFullLaunchURL().GetOrigin()); | 2946 const GURL origin2(extension->GetFullLaunchURL().GetOrigin()); |
| 2989 EXPECT_EQ(origin1, origin2); | 2947 EXPECT_EQ(origin1, origin2); |
| 2990 EXPECT_TRUE(profile_->GetExtensionSpecialStoragePolicy()-> | 2948 EXPECT_TRUE(profile_->GetExtensionSpecialStoragePolicy()-> |
| 2991 IsStorageUnlimited(origin2)); | 2949 IsStorageUnlimited(origin2)); |
| 2992 | 2950 |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3117 EXPECT_EQ(id, unloaded_id_); | 3075 EXPECT_EQ(id, unloaded_id_); |
| 3118 ASSERT_EQ(0u, loaded_.size()); | 3076 ASSERT_EQ(0u, loaded_.size()); |
| 3119 EXPECT_EQ(0u, service_->extensions()->size()); | 3077 EXPECT_EQ(0u, service_->extensions()->size()); |
| 3120 } | 3078 } |
| 3121 | 3079 |
| 3122 // Tests that we generate IDs when they are not specified in the manifest for | 3080 // Tests that we generate IDs when they are not specified in the manifest for |
| 3123 // --load-extension. | 3081 // --load-extension. |
| 3124 TEST_F(ExtensionServiceTest, GenerateID) { | 3082 TEST_F(ExtensionServiceTest, GenerateID) { |
| 3125 InitializeEmptyExtensionService(); | 3083 InitializeEmptyExtensionService(); |
| 3126 | 3084 |
| 3127 | |
| 3128 FilePath no_id_ext = data_dir_.AppendASCII("no_id"); | 3085 FilePath no_id_ext = data_dir_.AppendASCII("no_id"); |
| 3129 extensions::UnpackedInstaller::Create(service_)->Load(no_id_ext); | 3086 extensions::UnpackedInstaller::Create(service_)->Load(no_id_ext); |
| 3130 loop_.RunAllPending(); | 3087 loop_.RunAllPending(); |
| 3131 EXPECT_EQ(0u, GetErrors().size()); | 3088 EXPECT_EQ(0u, GetErrors().size()); |
| 3132 ASSERT_EQ(1u, loaded_.size()); | 3089 ASSERT_EQ(1u, loaded_.size()); |
| 3133 ASSERT_TRUE(Extension::IdIsValid(loaded_[0]->id())); | 3090 ASSERT_TRUE(Extension::IdIsValid(loaded_[0]->id())); |
| 3134 EXPECT_EQ(loaded_[0]->location(), Extension::LOAD); | 3091 EXPECT_EQ(loaded_[0]->location(), Extension::LOAD); |
| 3135 | 3092 |
| 3136 ValidatePrefKeyCount(1); | 3093 ValidatePrefKeyCount(1); |
| 3137 | 3094 |
| (...skipping 621 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3759 | 3716 |
| 3760 EXPECT_EQ(0u, GetErrors().size()); | 3717 EXPECT_EQ(0u, GetErrors().size()); |
| 3761 ASSERT_EQ(1u, loaded_.size()); | 3718 ASSERT_EQ(1u, loaded_.size()); |
| 3762 EXPECT_EQ(Extension::COMPONENT, loaded_[0]->location()); | 3719 EXPECT_EQ(Extension::COMPONENT, loaded_[0]->location()); |
| 3763 EXPECT_EQ(1u, service_->extensions()->size()); | 3720 EXPECT_EQ(1u, service_->extensions()->size()); |
| 3764 | 3721 |
| 3765 // Component extensions shouldn't get recorded in the prefs. | 3722 // Component extensions shouldn't get recorded in the prefs. |
| 3766 ValidatePrefKeyCount(0); | 3723 ValidatePrefKeyCount(0); |
| 3767 | 3724 |
| 3768 // Reload all extensions, and make sure it comes back. | 3725 // Reload all extensions, and make sure it comes back. |
| 3769 std::string extension_id = service_->extensions()->at(0)->id(); | 3726 std::string extension_id = (*service_->extensions()->begin())->id(); |
| 3770 loaded_.clear(); | 3727 loaded_.clear(); |
| 3771 service_->ReloadExtensions(); | 3728 service_->ReloadExtensions(); |
| 3772 ASSERT_EQ(1u, service_->extensions()->size()); | 3729 ASSERT_EQ(1u, service_->extensions()->size()); |
| 3773 EXPECT_EQ(extension_id, service_->extensions()->at(0)->id()); | 3730 EXPECT_EQ(extension_id, (*service_->extensions()->begin())->id()); |
| 3774 } | 3731 } |
| 3775 | 3732 |
| 3776 namespace { | 3733 namespace { |
| 3777 class TestSyncProcessorStub : public SyncChangeProcessor { | 3734 class TestSyncProcessorStub : public SyncChangeProcessor { |
| 3778 virtual SyncError ProcessSyncChanges( | 3735 virtual SyncError ProcessSyncChanges( |
| 3779 const tracked_objects::Location& from_here, | 3736 const tracked_objects::Location& from_here, |
| 3780 const SyncChangeList& change_list) OVERRIDE { | 3737 const SyncChangeList& change_list) OVERRIDE { |
| 3781 return SyncError(); | 3738 return SyncError(); |
| 3782 } | 3739 } |
| 3783 }; | 3740 }; |
| (...skipping 553 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 4337 ASSERT_FALSE(AddPendingSyncInstall()); | 4294 ASSERT_FALSE(AddPendingSyncInstall()); |
| 4338 | 4295 |
| 4339 // Wait for the external source to install. | 4296 // Wait for the external source to install. |
| 4340 WaitForCrxInstall(crx_path_, true); | 4297 WaitForCrxInstall(crx_path_, true); |
| 4341 ASSERT_TRUE(IsCrxInstalled()); | 4298 ASSERT_TRUE(IsCrxInstalled()); |
| 4342 | 4299 |
| 4343 // Now that the extension is installed, sync request should fail | 4300 // Now that the extension is installed, sync request should fail |
| 4344 // because the extension is already installed. | 4301 // because the extension is already installed. |
| 4345 ASSERT_FALSE(AddPendingSyncInstall()); | 4302 ASSERT_FALSE(AddPendingSyncInstall()); |
| 4346 } | 4303 } |
| OLD | NEW |