Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(103)

Side by Side Diff: chrome/browser/extensions/extension_service_unittest.cc

Issue 18119009: Make utility process run in-process when running in single-process mode. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: add comment Created 7 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 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" 11 #include "base/at_exit.h"
12 #include "base/basictypes.h" 12 #include "base/basictypes.h"
13 #include "base/bind.h" 13 #include "base/bind.h"
14 #include "base/command_line.h" 14 #include "base/command_line.h"
15 #include "base/debug/trace_event_impl.h"
15 #include "base/file_util.h" 16 #include "base/file_util.h"
16 #include "base/files/file_enumerator.h" 17 #include "base/files/file_enumerator.h"
17 #include "base/files/scoped_temp_dir.h" 18 #include "base/files/scoped_temp_dir.h"
18 #include "base/json/json_file_value_serializer.h" 19 #include "base/json/json_file_value_serializer.h"
19 #include "base/json/json_reader.h" 20 #include "base/json/json_reader.h"
20 #include "base/json/json_string_value_serializer.h" 21 #include "base/json/json_string_value_serializer.h"
21 #include "base/memory/scoped_ptr.h" 22 #include "base/memory/scoped_ptr.h"
22 #include "base/memory/weak_ptr.h" 23 #include "base/memory/weak_ptr.h"
23 #include "base/message_loop.h" 24 #include "base/message_loop.h"
24 #include "base/path_service.h" 25 #include "base/path_service.h"
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
75 #include "chrome/common/pref_names.h" 76 #include "chrome/common/pref_names.h"
76 #include "chrome/common/url_constants.h" 77 #include "chrome/common/url_constants.h"
77 #include "chrome/test/base/testing_profile.h" 78 #include "chrome/test/base/testing_profile.h"
78 #include "components/user_prefs/pref_registry_syncable.h" 79 #include "components/user_prefs/pref_registry_syncable.h"
79 #include "content/public/browser/dom_storage_context.h" 80 #include "content/public/browser/dom_storage_context.h"
80 #include "content/public/browser/gpu_data_manager.h" 81 #include "content/public/browser/gpu_data_manager.h"
81 #include "content/public/browser/indexed_db_context.h" 82 #include "content/public/browser/indexed_db_context.h"
82 #include "content/public/browser/notification_registrar.h" 83 #include "content/public/browser/notification_registrar.h"
83 #include "content/public/browser/notification_service.h" 84 #include "content/public/browser/notification_service.h"
84 #include "content/public/browser/plugin_service.h" 85 #include "content/public/browser/plugin_service.h"
86 #include "content/public/browser/render_process_host.h"
85 #include "content/public/browser/storage_partition.h" 87 #include "content/public/browser/storage_partition.h"
86 #include "content/public/common/content_constants.h" 88 #include "content/public/common/content_constants.h"
87 #include "content/public/test/test_browser_thread.h" 89 #include "content/public/test/test_browser_thread.h"
90 #include "content/public/test/test_utils.h"
88 #include "extensions/common/constants.h" 91 #include "extensions/common/constants.h"
89 #include "extensions/common/extension_resource.h" 92 #include "extensions/common/extension_resource.h"
90 #include "extensions/common/url_pattern.h" 93 #include "extensions/common/url_pattern.h"
91 #include "googleurl/src/gurl.h" 94 #include "googleurl/src/gurl.h"
92 #include "gpu/config/gpu_info.h" 95 #include "gpu/config/gpu_info.h"
93 #include "grit/browser_resources.h" 96 #include "grit/browser_resources.h"
94 #include "net/cookies/canonical_cookie.h" 97 #include "net/cookies/canonical_cookie.h"
95 #include "net/cookies/cookie_monster.h" 98 #include "net/cookies/cookie_monster.h"
96 #include "net/cookies/cookie_options.h" 99 #include "net/cookies/cookie_options.h"
97 #include "net/url_request/url_request_context.h" 100 #include "net/url_request/url_request_context.h"
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
188 int schemes = URLPattern::SCHEME_ALL; 191 int schemes = URLPattern::SCHEME_ALL;
189 extent->AddPattern(URLPattern(schemes, pattern)); 192 extent->AddPattern(URLPattern(schemes, pattern));
190 } 193 }
191 194
192 base::FilePath GetTemporaryFile() { 195 base::FilePath GetTemporaryFile() {
193 base::FilePath temp_file; 196 base::FilePath temp_file;
194 CHECK(file_util::CreateTemporaryFile(&temp_file)); 197 CHECK(file_util::CreateTemporaryFile(&temp_file));
195 return temp_file; 198 return temp_file;
196 } 199 }
197 200
201
202 bool WaitForCountNotificationsCallback(int *count) {
203 return --(*count) == 0;
204 }
205
198 } // namespace 206 } // namespace
199 207
200 class MockExtensionProvider : public extensions::ExternalProviderInterface { 208 class MockExtensionProvider : public extensions::ExternalProviderInterface {
201 public: 209 public:
202 MockExtensionProvider( 210 MockExtensionProvider(
203 VisitorInterface* visitor, 211 VisitorInterface* visitor,
204 Manifest::Location location) 212 Manifest::Location location)
205 : location_(location), visitor_(visitor), visit_count_(0) { 213 : location_(location), visitor_(visitor), visit_count_(0) {
206 } 214 }
207 215
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after
421 }; 429 };
422 430
423 ExtensionServiceTestBase::ExtensionServiceInitParams:: 431 ExtensionServiceTestBase::ExtensionServiceInitParams::
424 ExtensionServiceInitParams() 432 ExtensionServiceInitParams()
425 : autoupdate_enabled(false), is_first_run(true) { 433 : autoupdate_enabled(false), is_first_run(true) {
426 } 434 }
427 435
428 // Our message loop may be used in tests which require it to be an IO loop. 436 // Our message loop may be used in tests which require it to be an IO loop.
429 ExtensionServiceTestBase::ExtensionServiceTestBase() 437 ExtensionServiceTestBase::ExtensionServiceTestBase()
430 : loop_(base::MessageLoop::TYPE_IO), 438 : loop_(base::MessageLoop::TYPE_IO),
439 at_exit_manager_(new base::ShadowingAtExitManager),
431 service_(NULL), 440 service_(NULL),
432 management_policy_(NULL), 441 management_policy_(NULL),
433 expected_extensions_count_(0), 442 expected_extensions_count_(0),
434 ui_thread_(BrowserThread::UI, &loop_), 443 ui_thread_(BrowserThread::UI, &loop_),
435 db_thread_(BrowserThread::DB, &loop_), 444 db_thread_(BrowserThread::DB, &loop_),
436 webkit_thread_(BrowserThread::WEBKIT_DEPRECATED, &loop_), 445 webkit_thread_(BrowserThread::WEBKIT_DEPRECATED, &loop_),
437 file_thread_(BrowserThread::FILE, &loop_), 446 file_thread_(BrowserThread::FILE, &loop_),
438 file_user_blocking_thread_(BrowserThread::FILE_USER_BLOCKING, &loop_), 447 file_user_blocking_thread_(BrowserThread::FILE_USER_BLOCKING, &loop_),
439 io_thread_(BrowserThread::IO, &loop_) { 448 io_thread_(BrowserThread::IO, &loop_) {
440 base::FilePath test_data_dir; 449 base::FilePath test_data_dir;
441 if (!PathService::Get(chrome::DIR_TEST_DATA, &test_data_dir)) { 450 if (!PathService::Get(chrome::DIR_TEST_DATA, &test_data_dir)) {
442 ADD_FAILURE(); 451 ADD_FAILURE();
443 return; 452 return;
444 } 453 }
445 data_dir_ = test_data_dir.AppendASCII("extensions"); 454 data_dir_ = test_data_dir.AppendASCII("extensions");
446 } 455 }
447 456
448 ExtensionServiceTestBase::~ExtensionServiceTestBase() { 457 ExtensionServiceTestBase::~ExtensionServiceTestBase() {
449 // Drop our reference to ExtensionService and TestingProfile, so that they 458 // Drop our reference to ExtensionService and TestingProfile, so that they
450 // can be destroyed while BrowserThreads and MessageLoop are still around 459 // can be destroyed while BrowserThreads and MessageLoop are still around
451 // (they are used in the destruction process). 460 // (they are used in the destruction process).
452 service_ = NULL; 461 service_ = NULL;
453 base::MessageLoop::current()->RunUntilIdle(); 462 base::MessageLoop::current()->RunUntilIdle();
454 profile_.reset(NULL); 463 profile_.reset(NULL);
455 base::MessageLoop::current()->RunUntilIdle(); 464 base::MessageLoop::current()->RunUntilIdle();
465 at_exit_manager_.reset();
466
467 // This is needed because otherwise the next unit test which creates an
468 // in-process utility thread won't be able to create a TraceLog instance.
469 base::debug::TraceLog::Resurrect();
456 } 470 }
457 471
458 void ExtensionServiceTestBase::InitializeExtensionService( 472 void ExtensionServiceTestBase::InitializeExtensionService(
459 const ExtensionServiceTestBase::ExtensionServiceInitParams& params) { 473 const ExtensionServiceTestBase::ExtensionServiceInitParams& params) {
460 TestingProfile::Builder profile_builder; 474 TestingProfile::Builder profile_builder;
461 // Create a PrefService that only contains user defined preference values. 475 // Create a PrefService that only contains user defined preference values.
462 PrefServiceMockBuilder builder; 476 PrefServiceMockBuilder builder;
463 builder.WithUserFilePrefs(params.pref_file, loop_.message_loop_proxy().get()); 477 builder.WithUserFilePrefs(params.pref_file, loop_.message_loop_proxy().get());
464 scoped_refptr<user_prefs::PrefRegistrySyncable> registry( 478 scoped_refptr<user_prefs::PrefRegistrySyncable> registry(
465 new user_prefs::PrefRegistrySyncable); 479 new user_prefs::PrefRegistrySyncable);
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
570 profile->CreateRequestContext(); 584 profile->CreateRequestContext();
571 } 585 }
572 586
573 // static 587 // static
574 void ExtensionServiceTestBase::SetUpTestCase() { 588 void ExtensionServiceTestBase::SetUpTestCase() {
575 ExtensionErrorReporter::Init(false); // no noisy errors 589 ExtensionErrorReporter::Init(false); // no noisy errors
576 } 590 }
577 591
578 void ExtensionServiceTestBase::SetUp() { 592 void ExtensionServiceTestBase::SetUp() {
579 ExtensionErrorReporter::GetInstance()->ClearErrors(); 593 ExtensionErrorReporter::GetInstance()->ClearErrors();
594 content::RenderProcessHost::SetRunRendererInProcess(true);
595 }
596
597 void ExtensionServiceTestBase::TearDown() {
598 content::RenderProcessHost::SetRunRendererInProcess(false);
580 } 599 }
581 600
582 class ExtensionServiceTest 601 class ExtensionServiceTest
583 : public ExtensionServiceTestBase, public content::NotificationObserver { 602 : public ExtensionServiceTestBase, public content::NotificationObserver {
584 public: 603 public:
585 ExtensionServiceTest() 604 ExtensionServiceTest()
586 : installed_(NULL), 605 : installed_(NULL),
587 was_update_(false), 606 was_update_(false),
588 override_external_install_prompt_( 607 override_external_install_prompt_(
589 FeatureSwitch::prompt_for_external_extensions(), false) { 608 FeatureSwitch::prompt_for_external_extensions(), false) {
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
674 // to happen, use loop_.RunUntilIdle();. Most tests will not use this 693 // to happen, use loop_.RunUntilIdle();. Most tests will not use this
675 // method directly. Instead, use InstallCrx(), which waits for 694 // method directly. Instead, use InstallCrx(), which waits for
676 // the crx to be installed and does extra error checking. 695 // the crx to be installed and does extra error checking.
677 void StartCRXInstall(const base::FilePath& crx_path) { 696 void StartCRXInstall(const base::FilePath& crx_path) {
678 StartCRXInstall(crx_path, Extension::NO_FLAGS); 697 StartCRXInstall(crx_path, Extension::NO_FLAGS);
679 } 698 }
680 699
681 void StartCRXInstall(const base::FilePath& crx_path, int creation_flags) { 700 void StartCRXInstall(const base::FilePath& crx_path, int creation_flags) {
682 ASSERT_TRUE(file_util::PathExists(crx_path)) 701 ASSERT_TRUE(file_util::PathExists(crx_path))
683 << "Path does not exist: "<< crx_path.value().c_str(); 702 << "Path does not exist: "<< crx_path.value().c_str();
703
684 scoped_refptr<CrxInstaller> installer(CrxInstaller::Create(service_, NULL)); 704 scoped_refptr<CrxInstaller> installer(CrxInstaller::Create(service_, NULL));
685 installer->set_creation_flags(creation_flags); 705 installer->set_creation_flags(creation_flags);
686 if (!(creation_flags & Extension::WAS_INSTALLED_BY_DEFAULT)) { 706 if (!(creation_flags & Extension::WAS_INSTALLED_BY_DEFAULT)) {
687 installer->set_allow_silent_install(true); 707 installer->set_allow_silent_install(true);
688 } 708 }
709
710 content::WindowedNotificationObserver windowed_observer(
711 chrome::NOTIFICATION_CRX_INSTALLER_DONE,
712 content::Source<extensions::CrxInstaller>(installer));
713
689 installer->InstallCrx(crx_path); 714 installer->InstallCrx(crx_path);
690 } 715 }
691 716
692 enum InstallState { 717 enum InstallState {
693 INSTALL_FAILED, 718 INSTALL_FAILED,
694 INSTALL_UPDATED, 719 INSTALL_UPDATED,
695 INSTALL_NEW, 720 INSTALL_NEW,
696 INSTALL_WITHOUT_LOAD, 721 INSTALL_WITHOUT_LOAD,
697 }; 722 };
698 723
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
779 804
780 // Wait for a CrxInstaller to finish. Used by InstallCRX. Set the 805 // Wait for a CrxInstaller to finish. Used by InstallCRX. Set the
781 // |install_state| to INSTALL_FAILED if the installation is expected to fail. 806 // |install_state| to INSTALL_FAILED if the installation is expected to fail.
782 // If |install_state| is INSTALL_UPDATED, and |expected_old_name| is 807 // If |install_state| is INSTALL_UPDATED, and |expected_old_name| is
783 // non-empty, expects that the existing extension's title was 808 // non-empty, expects that the existing extension's title was
784 // |expected_old_name|. 809 // |expected_old_name|.
785 // Returns an Extension pointer if the install succeeded, NULL otherwise. 810 // Returns an Extension pointer if the install succeeded, NULL otherwise.
786 const Extension* WaitForCrxInstall(const base::FilePath& path, 811 const Extension* WaitForCrxInstall(const base::FilePath& path,
787 InstallState install_state, 812 InstallState install_state,
788 const std::string& expected_old_name) { 813 const std::string& expected_old_name) {
789 loop_.RunUntilIdle(); 814 content::WindowedNotificationObserver(
815 chrome::NOTIFICATION_CRX_INSTALLER_DONE,
816 content::NotificationService::AllSources()).Wait();
817
790 std::vector<string16> errors = GetErrors(); 818 std::vector<string16> errors = GetErrors();
791 const Extension* extension = NULL; 819 const Extension* extension = NULL;
792 if (install_state != INSTALL_FAILED) { 820 if (install_state != INSTALL_FAILED) {
793 if (install_state == INSTALL_NEW) 821 if (install_state == INSTALL_NEW)
794 ++expected_extensions_count_; 822 ++expected_extensions_count_;
795 823
796 EXPECT_TRUE(installed_) << path.value(); 824 EXPECT_TRUE(installed_) << path.value();
797 // If and only if INSTALL_UPDATED, it should have the is_update flag. 825 // If and only if INSTALL_UPDATED, it should have the is_update flag.
798 EXPECT_EQ(install_state == INSTALL_UPDATED, was_update_) 826 EXPECT_EQ(install_state == INSTALL_UPDATED, was_update_)
799 << path.value(); 827 << path.value();
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
865 base::FilePath path = temp_dir_.path(); 893 base::FilePath path = temp_dir_.path();
866 path = path.Append(in_path.BaseName()); 894 path = path.Append(in_path.BaseName());
867 ASSERT_TRUE(file_util::CopyFile(in_path, path)); 895 ASSERT_TRUE(file_util::CopyFile(in_path, path));
868 896
869 int previous_enabled_extension_count = 897 int previous_enabled_extension_count =
870 service_->extensions()->size(); 898 service_->extensions()->size();
871 int previous_installed_extension_count = 899 int previous_installed_extension_count =
872 previous_enabled_extension_count + 900 previous_enabled_extension_count +
873 service_->disabled_extensions()->size(); 901 service_->disabled_extensions()->size();
874 902
875 service_->UpdateExtension(id, path, GURL(), NULL); 903 extensions::CrxInstaller* installer = NULL;
876 loop_.RunUntilIdle(); 904 service_->UpdateExtension(id, path, GURL(), &installer);
905
906 if (installer) {
907 content::WindowedNotificationObserver(
908 chrome::NOTIFICATION_CRX_INSTALLER_DONE,
909 content::Source<extensions::CrxInstaller>(installer)).Wait();
910 } else {
911 loop_.RunUntilIdle();
912 }
877 913
878 std::vector<string16> errors = GetErrors(); 914 std::vector<string16> errors = GetErrors();
879 int error_count = errors.size(); 915 int error_count = errors.size();
880 int enabled_extension_count = 916 int enabled_extension_count =
881 service_->extensions()->size(); 917 service_->extensions()->size();
882 int installed_extension_count = 918 int installed_extension_count =
883 enabled_extension_count + service_->disabled_extensions()->size(); 919 enabled_extension_count + service_->disabled_extensions()->size();
884 920
885 int expected_error_count = (expected_state == FAILED) ? 1 : 0; 921 int expected_error_count = (expected_state == FAILED) ? 1 : 0;
886 EXPECT_EQ(expected_error_count, error_count) << path.value(); 922 EXPECT_EQ(expected_error_count, error_count) << path.value();
(...skipping 690 matching lines...) Expand 10 before | Expand all | Expand 10 after
1577 TEST_F(ExtensionServiceTest, InstallingExternalExtensionWithFlags) { 1613 TEST_F(ExtensionServiceTest, InstallingExternalExtensionWithFlags) {
1578 const char kPrefFromBookmark[] = "from_bookmark"; 1614 const char kPrefFromBookmark[] = "from_bookmark";
1579 1615
1580 InitializeEmptyExtensionService(); 1616 InitializeEmptyExtensionService();
1581 1617
1582 base::FilePath path = data_dir_.AppendASCII("good.crx"); 1618 base::FilePath path = data_dir_.AppendASCII("good.crx");
1583 set_extensions_enabled(true); 1619 set_extensions_enabled(true);
1584 1620
1585 // Register and install an external extension. 1621 // Register and install an external extension.
1586 Version version("1.0.0.0"); 1622 Version version("1.0.0.0");
1587 service_->OnExternalExtensionFileFound( 1623 if (service_->OnExternalExtensionFileFound(
1588 good_crx, 1624 good_crx,
1589 &version, 1625 &version,
1590 path, 1626 path,
1591 Manifest::EXTERNAL_PREF, 1627 Manifest::EXTERNAL_PREF,
1592 Extension::FROM_BOOKMARK, 1628 Extension::FROM_BOOKMARK,
1593 false /* mark_acknowledged */); 1629 false /* mark_acknowledged */)) {
1594 loop_.RunUntilIdle(); 1630 content::WindowedNotificationObserver(
1631 chrome::NOTIFICATION_CRX_INSTALLER_DONE,
1632 content::NotificationService::AllSources()).Wait();
1633 }
1595 1634
1596 const Extension* extension = service_->GetExtensionById(good_crx, false); 1635 const Extension* extension = service_->GetExtensionById(good_crx, false);
1597 ASSERT_TRUE(extension); 1636 ASSERT_TRUE(extension);
1598 ASSERT_TRUE(extension->from_bookmark()); 1637 ASSERT_TRUE(extension->from_bookmark());
1599 ValidateBooleanPref(good_crx, kPrefFromBookmark, true); 1638 ValidateBooleanPref(good_crx, kPrefFromBookmark, true);
1600 1639
1601 // Upgrade to version 2.0, the flag should be preserved. 1640 // Upgrade to version 2.0, the flag should be preserved.
1602 path = data_dir_.AppendASCII("good2.crx"); 1641 path = data_dir_.AppendASCII("good2.crx");
1603 UpdateExtension(good_crx, path, ENABLED); 1642 UpdateExtension(good_crx, path, ENABLED);
1643
1604 ValidateBooleanPref(good_crx, kPrefFromBookmark, true); 1644 ValidateBooleanPref(good_crx, kPrefFromBookmark, true);
1605 extension = service_->GetExtensionById(good_crx, false); 1645 extension = service_->GetExtensionById(good_crx, false);
1606 ASSERT_TRUE(extension); 1646 ASSERT_TRUE(extension);
1607 ASSERT_TRUE(extension->from_bookmark()); 1647 ASSERT_TRUE(extension->from_bookmark());
1608 } 1648 }
1609 1649
1610 // Test the handling of Extension::EXTERNAL_EXTENSION_UNINSTALLED 1650 // Test the handling of Extension::EXTERNAL_EXTENSION_UNINSTALLED
1611 TEST_F(ExtensionServiceTest, UninstallingExternalExtensions) { 1651 TEST_F(ExtensionServiceTest, UninstallingExternalExtensions) {
1612 InitializeEmptyExtensionService(); 1652 InitializeEmptyExtensionService();
1613 1653
1614 base::FilePath path = data_dir_.AppendASCII("good.crx"); 1654 base::FilePath path = data_dir_.AppendASCII("good.crx");
1615 set_extensions_enabled(true); 1655 set_extensions_enabled(true);
1616 1656
1617 Version version("1.0.0.0"); 1657 Version version("1.0.0.0");
1618 // Install an external extension. 1658 // Install an external extension.
1619 service_->OnExternalExtensionFileFound(good_crx, &version, 1659 if (service_->OnExternalExtensionFileFound(good_crx, &version,
1620 path, Manifest::EXTERNAL_PREF, 1660 path, Manifest::EXTERNAL_PREF,
1621 Extension::NO_FLAGS, false); 1661 Extension::NO_FLAGS, false)) {
1622 loop_.RunUntilIdle(); 1662 content::WindowedNotificationObserver(
1663 chrome::NOTIFICATION_CRX_INSTALLER_DONE,
1664 content::NotificationService::AllSources()).Wait();
1665 }
1666
1623 ASSERT_TRUE(service_->GetExtensionById(good_crx, false)); 1667 ASSERT_TRUE(service_->GetExtensionById(good_crx, false));
1624 1668
1625 // Uninstall it and check that its killbit gets set. 1669 // Uninstall it and check that its killbit gets set.
1626 UninstallExtension(good_crx, false); 1670 UninstallExtension(good_crx, false);
1627 ValidateIntegerPref(good_crx, "location", 1671 ValidateIntegerPref(good_crx, "location",
1628 Extension::EXTERNAL_EXTENSION_UNINSTALLED); 1672 Extension::EXTERNAL_EXTENSION_UNINSTALLED);
1629 1673
1630 // Try to re-install it externally. This should fail because of the killbit. 1674 // Try to re-install it externally. This should fail because of the killbit.
1631 service_->OnExternalExtensionFileFound(good_crx, &version, 1675 service_->OnExternalExtensionFileFound(good_crx, &version,
1632 path, Manifest::EXTERNAL_PREF, 1676 path, Manifest::EXTERNAL_PREF,
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
1695 const std::string wrong_id = all_zero; 1739 const std::string wrong_id = all_zero;
1696 const std::string correct_id = good_crx; 1740 const std::string correct_id = good_crx;
1697 ASSERT_NE(correct_id, wrong_id); 1741 ASSERT_NE(correct_id, wrong_id);
1698 1742
1699 // Install an external extension with an ID from the external 1743 // Install an external extension with an ID from the external
1700 // source that is not equal to the ID in the extension manifest. 1744 // source that is not equal to the ID in the extension manifest.
1701 service_->OnExternalExtensionFileFound( 1745 service_->OnExternalExtensionFileFound(
1702 wrong_id, &version, path, Manifest::EXTERNAL_PREF, 1746 wrong_id, &version, path, Manifest::EXTERNAL_PREF,
1703 Extension::NO_FLAGS, false); 1747 Extension::NO_FLAGS, false);
1704 1748
1705 loop_.RunUntilIdle(); 1749 content::WindowedNotificationObserver(
1750 chrome::NOTIFICATION_CRX_INSTALLER_DONE,
1751 content::NotificationService::AllSources()).Wait();
1706 ASSERT_FALSE(service_->GetExtensionById(good_crx, false)); 1752 ASSERT_FALSE(service_->GetExtensionById(good_crx, false));
1707 1753
1708 // Try again with the right ID. Expect success. 1754 // Try again with the right ID. Expect success.
1709 service_->OnExternalExtensionFileFound( 1755 if (service_->OnExternalExtensionFileFound(
1710 correct_id, &version, path, Manifest::EXTERNAL_PREF, 1756 correct_id, &version, path, Manifest::EXTERNAL_PREF,
1711 Extension::NO_FLAGS, false); 1757 Extension::NO_FLAGS, false)) {
1712 loop_.RunUntilIdle(); 1758 content::WindowedNotificationObserver(
1759 chrome::NOTIFICATION_CRX_INSTALLER_DONE,
1760 content::NotificationService::AllSources()).Wait();
1761 }
1713 ASSERT_TRUE(service_->GetExtensionById(good_crx, false)); 1762 ASSERT_TRUE(service_->GetExtensionById(good_crx, false));
1714 } 1763 }
1715 1764
1716 // Test that external extensions with incorrect versions are not installed. 1765 // Test that external extensions with incorrect versions are not installed.
1717 TEST_F(ExtensionServiceTest, FailOnWrongVersion) { 1766 TEST_F(ExtensionServiceTest, FailOnWrongVersion) {
1718 InitializeEmptyExtensionService(); 1767 InitializeEmptyExtensionService();
1719 base::FilePath path = data_dir_.AppendASCII("good.crx"); 1768 base::FilePath path = data_dir_.AppendASCII("good.crx");
1720 set_extensions_enabled(true); 1769 set_extensions_enabled(true);
1721 1770
1722 // Install an external extension with a version from the external 1771 // Install an external extension with a version from the external
1723 // source that is not equal to the version in the extension manifest. 1772 // source that is not equal to the version in the extension manifest.
1724 Version wrong_version("1.2.3.4"); 1773 Version wrong_version("1.2.3.4");
1725 service_->OnExternalExtensionFileFound( 1774 service_->OnExternalExtensionFileFound(
1726 good_crx, &wrong_version, path, Manifest::EXTERNAL_PREF, 1775 good_crx, &wrong_version, path, Manifest::EXTERNAL_PREF,
1727 Extension::NO_FLAGS, false); 1776 Extension::NO_FLAGS, false);
1728 1777
1729 loop_.RunUntilIdle(); 1778 content::WindowedNotificationObserver(
1779 chrome::NOTIFICATION_CRX_INSTALLER_DONE,
1780 content::NotificationService::AllSources()).Wait();
1730 ASSERT_FALSE(service_->GetExtensionById(good_crx, false)); 1781 ASSERT_FALSE(service_->GetExtensionById(good_crx, false));
1731 1782
1732 // Try again with the right version. Expect success. 1783 // Try again with the right version. Expect success.
1733 service_->pending_extension_manager()->Remove(good_crx); 1784 service_->pending_extension_manager()->Remove(good_crx);
1734 Version correct_version("1.0.0.0"); 1785 Version correct_version("1.0.0.0");
1735 service_->OnExternalExtensionFileFound( 1786 if (service_->OnExternalExtensionFileFound(
1736 good_crx, &correct_version, path, Manifest::EXTERNAL_PREF, 1787 good_crx, &correct_version, path, Manifest::EXTERNAL_PREF,
1737 Extension::NO_FLAGS, false); 1788 Extension::NO_FLAGS, false)) {
1738 loop_.RunUntilIdle(); 1789 content::WindowedNotificationObserver(
1790 chrome::NOTIFICATION_CRX_INSTALLER_DONE,
1791 content::NotificationService::AllSources()).Wait();
1792 }
1739 ASSERT_TRUE(service_->GetExtensionById(good_crx, false)); 1793 ASSERT_TRUE(service_->GetExtensionById(good_crx, false));
1740 } 1794 }
1741 1795
1742 // Install a user script (they get converted automatically to an extension) 1796 // Install a user script (they get converted automatically to an extension)
1743 TEST_F(ExtensionServiceTest, InstallUserScript) { 1797 TEST_F(ExtensionServiceTest, InstallUserScript) {
1744 // The details of script conversion are tested elsewhere, this just tests 1798 // The details of script conversion are tested elsewhere, this just tests
1745 // integration with ExtensionService. 1799 // integration with ExtensionService.
1746 InitializeEmptyExtensionService(); 1800 InitializeEmptyExtensionService();
1747 1801
1748 base::FilePath path = data_dir_ 1802 base::FilePath path = data_dir_
(...skipping 1654 matching lines...) Expand 10 before | Expand all | Expand 10 after
3403 MockExtensionProvider* provider = 3457 MockExtensionProvider* provider =
3404 new MockExtensionProvider(service_, 3458 new MockExtensionProvider(service_,
3405 Manifest::EXTERNAL_POLICY_DOWNLOAD); 3459 Manifest::EXTERNAL_POLICY_DOWNLOAD);
3406 AddMockExternalProvider(provider); 3460 AddMockExternalProvider(provider);
3407 provider->UpdateOrAddExtension(good_crx, "1.0.0.0", 3461 provider->UpdateOrAddExtension(good_crx, "1.0.0.0",
3408 data_dir_.AppendASCII("good.crx")); 3462 data_dir_.AppendASCII("good.crx"));
3409 3463
3410 // Reloading extensions should find our externally registered extension 3464 // Reloading extensions should find our externally registered extension
3411 // and install it. 3465 // and install it.
3412 service_->CheckForExternalUpdates(); 3466 service_->CheckForExternalUpdates();
3413 loop_.RunUntilIdle(); 3467 content::WindowedNotificationObserver(
3468 chrome::NOTIFICATION_CRX_INSTALLER_DONE,
3469 content::NotificationService::AllSources()).Wait();
3414 3470
3415 // Extension should be installed despite blacklist. 3471 // Extension should be installed despite blacklist.
3416 ASSERT_EQ(1u, service_->extensions()->size()); 3472 ASSERT_EQ(1u, service_->extensions()->size());
3417 EXPECT_TRUE(service_->GetExtensionById(good_crx, false)); 3473 EXPECT_TRUE(service_->GetExtensionById(good_crx, false));
3418 3474
3419 // Blacklist update should not uninstall the extension. 3475 // Blacklist update should not uninstall the extension.
3420 { 3476 {
3421 ListPrefUpdate update(profile_->GetPrefs(), 3477 ListPrefUpdate update(profile_->GetPrefs(),
3422 prefs::kExtensionInstallDenyList); 3478 prefs::kExtensionInstallDenyList);
3423 ListValue* blacklist = update.Get(); 3479 ListValue* blacklist = update.Get();
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after
3581 MockExtensionProvider* provider = 3637 MockExtensionProvider* provider =
3582 new MockExtensionProvider(service_, 3638 new MockExtensionProvider(service_,
3583 Manifest::EXTERNAL_POLICY_DOWNLOAD); 3639 Manifest::EXTERNAL_POLICY_DOWNLOAD);
3584 AddMockExternalProvider(provider); 3640 AddMockExternalProvider(provider);
3585 provider->UpdateOrAddExtension(page_action, "1.0.0.0", 3641 provider->UpdateOrAddExtension(page_action, "1.0.0.0",
3586 data_dir_.AppendASCII("page_action.crx")); 3642 data_dir_.AppendASCII("page_action.crx"));
3587 } 3643 }
3588 3644
3589 // Providers are set up. Let them run. 3645 // Providers are set up. Let them run.
3590 service_->CheckForExternalUpdates(); 3646 service_->CheckForExternalUpdates();
3591 loop_.RunUntilIdle(); 3647
3648 int count = 2;
3649 content::WindowedNotificationObserver(
3650 chrome::NOTIFICATION_CRX_INSTALLER_DONE,
3651 base::Bind(&WaitForCountNotificationsCallback, &count)).Wait();
3592 3652
3593 ASSERT_EQ(2u, service_->extensions()->size()); 3653 ASSERT_EQ(2u, service_->extensions()->size());
3594 EXPECT_TRUE(service_->GetExtensionById(good_crx, false)); 3654 EXPECT_TRUE(service_->GetExtensionById(good_crx, false));
3595 EXPECT_TRUE(service_->GetExtensionById(page_action, false)); 3655 EXPECT_TRUE(service_->GetExtensionById(page_action, false));
3596 ExtensionPrefs* prefs = service_->extension_prefs(); 3656 ExtensionPrefs* prefs = service_->extension_prefs();
3597 ASSERT_TRUE(!prefs->IsExternalExtensionAcknowledged(good_crx)); 3657 ASSERT_TRUE(!prefs->IsExternalExtensionAcknowledged(good_crx));
3598 ASSERT_TRUE(prefs->IsExternalExtensionAcknowledged(page_action)); 3658 ASSERT_TRUE(prefs->IsExternalExtensionAcknowledged(page_action));
3599 } 3659 }
3600 3660
3601 #if !defined(OS_CHROMEOS) 3661 #if !defined(OS_CHROMEOS)
(...skipping 19 matching lines...) Expand all
3621 new extensions::ExternalTestingLoader(json_data, data_dir_), 3681 new extensions::ExternalTestingLoader(json_data, data_dir_),
3622 Manifest::INTERNAL, 3682 Manifest::INTERNAL,
3623 Manifest::INVALID_LOCATION, 3683 Manifest::INVALID_LOCATION,
3624 Extension::FROM_WEBSTORE | Extension::WAS_INSTALLED_BY_DEFAULT); 3684 Extension::FROM_WEBSTORE | Extension::WAS_INSTALLED_BY_DEFAULT);
3625 3685
3626 AddMockExternalProvider(provider); 3686 AddMockExternalProvider(provider);
3627 } 3687 }
3628 3688
3629 ASSERT_EQ(0u, service_->extensions()->size()); 3689 ASSERT_EQ(0u, service_->extensions()->size());
3630 service_->CheckForExternalUpdates(); 3690 service_->CheckForExternalUpdates();
3631 loop_.RunUntilIdle(); 3691 content::WindowedNotificationObserver(
3692 chrome::NOTIFICATION_CRX_INSTALLER_DONE,
3693 content::NotificationService::AllSources()).Wait();
3632 3694
3633 ASSERT_EQ(1u, service_->extensions()->size()); 3695 ASSERT_EQ(1u, service_->extensions()->size());
3634 EXPECT_TRUE(service_->GetExtensionById(good_crx, false)); 3696 EXPECT_TRUE(service_->GetExtensionById(good_crx, false));
3635 const Extension* extension = service_->GetExtensionById(good_crx, false); 3697 const Extension* extension = service_->GetExtensionById(good_crx, false);
3636 EXPECT_TRUE(extension->from_webstore()); 3698 EXPECT_TRUE(extension->from_webstore());
3637 EXPECT_TRUE(extension->was_installed_by_default()); 3699 EXPECT_TRUE(extension->was_installed_by_default());
3638
3639 } 3700 }
3640 #endif 3701 #endif
3641 3702
3642 // Tests disabling extensions 3703 // Tests disabling extensions
3643 TEST_F(ExtensionServiceTest, DisableExtension) { 3704 TEST_F(ExtensionServiceTest, DisableExtension) {
3644 InitializeEmptyExtensionService(); 3705 InitializeEmptyExtensionService();
3645 3706
3646 InstallCRX(data_dir_.AppendASCII("good.crx"), INSTALL_NEW); 3707 InstallCRX(data_dir_.AppendASCII("good.crx"), INSTALL_NEW);
3647 EXPECT_FALSE(service_->extensions()->is_empty()); 3708 EXPECT_FALSE(service_->extensions()->is_empty());
3648 EXPECT_TRUE(service_->GetExtensionById(good_crx, true)); 3709 EXPECT_TRUE(service_->GetExtensionById(good_crx, true));
(...skipping 597 matching lines...) Expand 10 before | Expand all | Expand 10 after
4246 4307
4247 // Register a test extension externally using the mock registry provider. 4308 // Register a test extension externally using the mock registry provider.
4248 base::FilePath source_path = data_dir_.AppendASCII("good.crx"); 4309 base::FilePath source_path = data_dir_.AppendASCII("good.crx");
4249 4310
4250 // Add the extension. 4311 // Add the extension.
4251 provider->UpdateOrAddExtension(good_crx, "1.0.0.0", source_path); 4312 provider->UpdateOrAddExtension(good_crx, "1.0.0.0", source_path);
4252 4313
4253 // Reloading extensions should find our externally registered extension 4314 // Reloading extensions should find our externally registered extension
4254 // and install it. 4315 // and install it.
4255 service_->CheckForExternalUpdates(); 4316 service_->CheckForExternalUpdates();
4256 loop_.RunUntilIdle(); 4317 content::WindowedNotificationObserver(
4318 chrome::NOTIFICATION_CRX_INSTALLER_DONE,
4319 content::NotificationService::AllSources()).Wait();
4257 4320
4258 ASSERT_EQ(0u, GetErrors().size()); 4321 ASSERT_EQ(0u, GetErrors().size());
4259 ASSERT_EQ(1u, loaded_.size()); 4322 ASSERT_EQ(1u, loaded_.size());
4260 ASSERT_EQ(location, loaded_[0]->location()); 4323 ASSERT_EQ(location, loaded_[0]->location());
4261 ASSERT_EQ("1.0.0.0", loaded_[0]->version()->GetString()); 4324 ASSERT_EQ("1.0.0.0", loaded_[0]->version()->GetString());
4262 ValidatePrefKeyCount(1); 4325 ValidatePrefKeyCount(1);
4263 ValidateIntegerPref(good_crx, "state", Extension::ENABLED); 4326 ValidateIntegerPref(good_crx, "state", Extension::ENABLED);
4264 ValidateIntegerPref(good_crx, "location", location); 4327 ValidateIntegerPref(good_crx, "location", location);
4265 4328
4266 // Reload extensions without changing anything. The extension should be 4329 // Reload extensions without changing anything. The extension should be
4267 // loaded again. 4330 // loaded again.
4268 loaded_.clear(); 4331 loaded_.clear();
4269 service_->ReloadExtensions(); 4332 service_->ReloadExtensions();
4270 loop_.RunUntilIdle(); 4333 loop_.RunUntilIdle();
4271 ASSERT_EQ(0u, GetErrors().size()); 4334 ASSERT_EQ(0u, GetErrors().size());
4272 ASSERT_EQ(1u, loaded_.size()); 4335 ASSERT_EQ(1u, loaded_.size());
4273 ValidatePrefKeyCount(1); 4336 ValidatePrefKeyCount(1);
4274 ValidateIntegerPref(good_crx, "state", Extension::ENABLED); 4337 ValidateIntegerPref(good_crx, "state", Extension::ENABLED);
4275 ValidateIntegerPref(good_crx, "location", location); 4338 ValidateIntegerPref(good_crx, "location", location);
4276 4339
4277 // Now update the extension with a new version. We should get upgraded. 4340 // Now update the extension with a new version. We should get upgraded.
4278 source_path = source_path.DirName().AppendASCII("good2.crx"); 4341 source_path = source_path.DirName().AppendASCII("good2.crx");
4279 provider->UpdateOrAddExtension(good_crx, "1.0.0.1", source_path); 4342 provider->UpdateOrAddExtension(good_crx, "1.0.0.1", source_path);
4280 4343
4281 loaded_.clear(); 4344 loaded_.clear();
4282 service_->CheckForExternalUpdates(); 4345 service_->CheckForExternalUpdates();
4283 loop_.RunUntilIdle(); 4346 content::WindowedNotificationObserver(
4347 chrome::NOTIFICATION_CRX_INSTALLER_DONE,
4348 content::NotificationService::AllSources()).Wait();
4284 ASSERT_EQ(0u, GetErrors().size()); 4349 ASSERT_EQ(0u, GetErrors().size());
4285 ASSERT_EQ(1u, loaded_.size()); 4350 ASSERT_EQ(1u, loaded_.size());
4286 ASSERT_EQ("1.0.0.1", loaded_[0]->version()->GetString()); 4351 ASSERT_EQ("1.0.0.1", loaded_[0]->version()->GetString());
4287 ValidatePrefKeyCount(1); 4352 ValidatePrefKeyCount(1);
4288 ValidateIntegerPref(good_crx, "state", Extension::ENABLED); 4353 ValidateIntegerPref(good_crx, "state", Extension::ENABLED);
4289 ValidateIntegerPref(good_crx, "location", location); 4354 ValidateIntegerPref(good_crx, "location", location);
4290 4355
4291 // Uninstall the extension and reload. Nothing should happen because the 4356 // Uninstall the extension and reload. Nothing should happen because the
4292 // preference should prevent us from reinstalling. 4357 // preference should prevent us from reinstalling.
4293 std::string id = loaded_[0]->id(); 4358 std::string id = loaded_[0]->id();
(...skipping 16 matching lines...) Expand all
4310 ValidatePrefKeyCount(1); 4375 ValidatePrefKeyCount(1);
4311 ValidateIntegerPref(good_crx, "state", 4376 ValidateIntegerPref(good_crx, "state",
4312 Extension::EXTERNAL_EXTENSION_UNINSTALLED); 4377 Extension::EXTERNAL_EXTENSION_UNINSTALLED);
4313 ValidateIntegerPref(good_crx, "location", location); 4378 ValidateIntegerPref(good_crx, "location", location);
4314 4379
4315 // Now clear the preference and reinstall. 4380 // Now clear the preference and reinstall.
4316 SetPrefInteg(good_crx, "state", Extension::ENABLED); 4381 SetPrefInteg(good_crx, "state", Extension::ENABLED);
4317 4382
4318 loaded_.clear(); 4383 loaded_.clear();
4319 service_->CheckForExternalUpdates(); 4384 service_->CheckForExternalUpdates();
4320 loop_.RunUntilIdle(); 4385 content::WindowedNotificationObserver(
4386 chrome::NOTIFICATION_CRX_INSTALLER_DONE,
4387 content::NotificationService::AllSources()).Wait();
4321 ASSERT_EQ(1u, loaded_.size()); 4388 ASSERT_EQ(1u, loaded_.size());
4322 } 4389 }
4323 ValidatePrefKeyCount(1); 4390 ValidatePrefKeyCount(1);
4324 ValidateIntegerPref(good_crx, "state", Extension::ENABLED); 4391 ValidateIntegerPref(good_crx, "state", Extension::ENABLED);
4325 ValidateIntegerPref(good_crx, "location", location); 4392 ValidateIntegerPref(good_crx, "location", location);
4326 4393
4327 if (management_policy_->MustRemainEnabled(loaded_[0].get(), NULL)) { 4394 if (management_policy_->MustRemainEnabled(loaded_[0].get(), NULL)) {
4328 EXPECT_EQ(2, provider->visit_count()); 4395 EXPECT_EQ(2, provider->visit_count());
4329 } else { 4396 } else {
4330 // Now test an externally triggered uninstall (deleting the registry key or 4397 // Now test an externally triggered uninstall (deleting the registry key or
4331 // the pref entry). 4398 // the pref entry).
4332 provider->RemoveExtension(good_crx); 4399 provider->RemoveExtension(good_crx);
4333 4400
4334 loaded_.clear(); 4401 loaded_.clear();
4335 service_->OnExternalProviderReady(provider); 4402 service_->OnExternalProviderReady(provider);
4336 loop_.RunUntilIdle(); 4403 loop_.RunUntilIdle();
4337 ASSERT_EQ(0u, loaded_.size()); 4404 ASSERT_EQ(0u, loaded_.size());
4338 ValidatePrefKeyCount(0); 4405 ValidatePrefKeyCount(0);
4339 4406
4340 // The extension should also be gone from the install directory. 4407 // The extension should also be gone from the install directory.
4341 ASSERT_FALSE(file_util::PathExists(install_path)); 4408 ASSERT_FALSE(file_util::PathExists(install_path));
4342 4409
4343 // Now test the case where user uninstalls and then the extension is removed 4410 // Now test the case where user uninstalls and then the extension is removed
4344 // from the external provider. 4411 // from the external provider.
4345 provider->UpdateOrAddExtension(good_crx, "1.0.0.1", source_path); 4412 provider->UpdateOrAddExtension(good_crx, "1.0.0.1", source_path);
4346 service_->CheckForExternalUpdates(); 4413 service_->CheckForExternalUpdates();
4347 loop_.RunUntilIdle(); 4414 content::WindowedNotificationObserver(
4415 chrome::NOTIFICATION_CRX_INSTALLER_DONE,
4416 content::NotificationService::AllSources()).Wait();
4348 4417
4349 ASSERT_EQ(1u, loaded_.size()); 4418 ASSERT_EQ(1u, loaded_.size());
4350 ASSERT_EQ(0u, GetErrors().size()); 4419 ASSERT_EQ(0u, GetErrors().size());
4351 4420
4352 // User uninstalls. 4421 // User uninstalls.
4353 loaded_.clear(); 4422 loaded_.clear();
4354 service_->UninstallExtension(id, false, NULL); 4423 service_->UninstallExtension(id, false, NULL);
4355 loop_.RunUntilIdle(); 4424 loop_.RunUntilIdle();
4356 ASSERT_EQ(0u, loaded_.size()); 4425 ASSERT_EQ(0u, loaded_.size());
4357 4426
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
4488 4557
4489 // Register a test extension externally using the mock registry provider. 4558 // Register a test extension externally using the mock registry provider.
4490 base::FilePath source_path = data_dir_.AppendASCII("good.crx"); 4559 base::FilePath source_path = data_dir_.AppendASCII("good.crx");
4491 provider->UpdateOrAddExtension(good_crx, "1.0.0.0", source_path); 4560 provider->UpdateOrAddExtension(good_crx, "1.0.0.0", source_path);
4492 4561
4493 // Two checks for external updates should find the extension, and install it 4562 // Two checks for external updates should find the extension, and install it
4494 // once. 4563 // once.
4495 provider->set_visit_count(0); 4564 provider->set_visit_count(0);
4496 service_->CheckForExternalUpdates(); 4565 service_->CheckForExternalUpdates();
4497 service_->CheckForExternalUpdates(); 4566 service_->CheckForExternalUpdates();
4498 loop_.RunUntilIdle(); 4567 content::WindowedNotificationObserver(
4568 chrome::NOTIFICATION_CRX_INSTALLER_DONE,
4569 content::NotificationService::AllSources()).Wait();
4499 EXPECT_EQ(2, provider->visit_count()); 4570 EXPECT_EQ(2, provider->visit_count());
4500 ASSERT_EQ(0u, GetErrors().size()); 4571 ASSERT_EQ(0u, GetErrors().size());
4501 ASSERT_EQ(1u, loaded_.size()); 4572 ASSERT_EQ(1u, loaded_.size());
4502 ASSERT_EQ(Manifest::EXTERNAL_PREF, loaded_[0]->location()); 4573 ASSERT_EQ(Manifest::EXTERNAL_PREF, loaded_[0]->location());
4503 ASSERT_EQ("1.0.0.0", loaded_[0]->version()->GetString()); 4574 ASSERT_EQ("1.0.0.0", loaded_[0]->version()->GetString());
4504 ValidatePrefKeyCount(1); 4575 ValidatePrefKeyCount(1);
4505 ValidateIntegerPref(good_crx, "state", Extension::ENABLED); 4576 ValidateIntegerPref(good_crx, "state", Extension::ENABLED);
4506 ValidateIntegerPref(good_crx, "location", Manifest::EXTERNAL_PREF); 4577 ValidateIntegerPref(good_crx, "location", Manifest::EXTERNAL_PREF);
4507 4578
4508 provider->RemoveExtension(good_crx); 4579 provider->RemoveExtension(good_crx);
(...skipping 1372 matching lines...) Expand 10 before | Expand all | Expand 10 after
5881 EXPECT_TRUE(AddPendingSyncInstall()); 5952 EXPECT_TRUE(AddPendingSyncInstall());
5882 ASSERT_EQ(Manifest::INTERNAL, GetPendingLocation()); 5953 ASSERT_EQ(Manifest::INTERNAL, GetPendingLocation());
5883 EXPECT_TRUE(GetPendingIsFromSync()); 5954 EXPECT_TRUE(GetPendingIsFromSync());
5884 ASSERT_FALSE(IsCrxInstalled()); 5955 ASSERT_FALSE(IsCrxInstalled());
5885 5956
5886 // Install pending as external prefs json would. 5957 // Install pending as external prefs json would.
5887 AddPendingExternalPrefFileInstall(); 5958 AddPendingExternalPrefFileInstall();
5888 ASSERT_EQ(Manifest::EXTERNAL_PREF, GetPendingLocation()); 5959 ASSERT_EQ(Manifest::EXTERNAL_PREF, GetPendingLocation());
5889 ASSERT_FALSE(IsCrxInstalled()); 5960 ASSERT_FALSE(IsCrxInstalled());
5890 5961
5891 // Another request from sync should be ignorred. 5962 // Another request from sync should be ignored.
5892 EXPECT_FALSE(AddPendingSyncInstall()); 5963 EXPECT_FALSE(AddPendingSyncInstall());
5893 ASSERT_EQ(Manifest::EXTERNAL_PREF, GetPendingLocation()); 5964 ASSERT_EQ(Manifest::EXTERNAL_PREF, GetPendingLocation());
5894 ASSERT_FALSE(IsCrxInstalled()); 5965 ASSERT_FALSE(IsCrxInstalled());
5895 5966
5896 WaitForCrxInstall(crx_path_, INSTALL_NEW); 5967 WaitForCrxInstall(crx_path_, INSTALL_NEW);
5897 ASSERT_TRUE(IsCrxInstalled()); 5968 ASSERT_TRUE(IsCrxInstalled());
5898 } 5969 }
5899 5970
5900 // Test that an install of an external CRX from an update overrides 5971 // Test that an install of an external CRX from an update overrides
5901 // an install of the same extension from sync. 5972 // an install of the same extension from sync.
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
5968 service_->CheckForExternalUpdates(); 6039 service_->CheckForExternalUpdates();
5969 loop_.RunUntilIdle(); 6040 loop_.RunUntilIdle();
5970 EXPECT_FALSE(extensions::HasExternalInstallError(service_)); 6041 EXPECT_FALSE(extensions::HasExternalInstallError(service_));
5971 6042
5972 // A hosted app, installed externally. 6043 // A hosted app, installed externally.
5973 // This should NOT trigger an alert. 6044 // This should NOT trigger an alert.
5974 provider->UpdateOrAddExtension(hosted_app, "1.0.0.0", 6045 provider->UpdateOrAddExtension(hosted_app, "1.0.0.0",
5975 data_dir_.AppendASCII("hosted_app.crx")); 6046 data_dir_.AppendASCII("hosted_app.crx"));
5976 6047
5977 service_->CheckForExternalUpdates(); 6048 service_->CheckForExternalUpdates();
5978 loop_.RunUntilIdle(); 6049 content::WindowedNotificationObserver(
6050 chrome::NOTIFICATION_CRX_INSTALLER_DONE,
6051 content::NotificationService::AllSources()).Wait();
5979 EXPECT_FALSE(extensions::HasExternalInstallError(service_)); 6052 EXPECT_FALSE(extensions::HasExternalInstallError(service_));
5980 6053
5981 // Another normal extension, but installed externally. 6054 // Another normal extension, but installed externally.
5982 // This SHOULD trigger an alert. 6055 // This SHOULD trigger an alert.
5983 provider->UpdateOrAddExtension(page_action, "1.0.0.0", 6056 provider->UpdateOrAddExtension(page_action, "1.0.0.0",
5984 data_dir_.AppendASCII("page_action.crx")); 6057 data_dir_.AppendASCII("page_action.crx"));
5985 6058
5986 service_->CheckForExternalUpdates(); 6059 service_->CheckForExternalUpdates();
5987 loop_.RunUntilIdle(); 6060 content::WindowedNotificationObserver(
6061 chrome::NOTIFICATION_CRX_INSTALLER_DONE,
6062 content::NotificationService::AllSources()).Wait();
5988 EXPECT_TRUE(extensions::HasExternalInstallError(service_)); 6063 EXPECT_TRUE(extensions::HasExternalInstallError(service_));
5989 } 6064 }
5990 6065
5991 // Test that external extensions are initially disabled, and that enabling 6066 // Test that external extensions are initially disabled, and that enabling
5992 // them clears the prompt. 6067 // them clears the prompt.
5993 TEST_F(ExtensionServiceTest, ExternalInstallInitiallyDisabled) { 6068 TEST_F(ExtensionServiceTest, ExternalInstallInitiallyDisabled) {
5994 FeatureSwitch::ScopedOverride prompt( 6069 FeatureSwitch::ScopedOverride prompt(
5995 FeatureSwitch::prompt_for_external_extensions(), true); 6070 FeatureSwitch::prompt_for_external_extensions(), true);
5996 6071
5997 InitializeEmptyExtensionService(); 6072 InitializeEmptyExtensionService();
5998 MockExtensionProvider* provider = 6073 MockExtensionProvider* provider =
5999 new MockExtensionProvider(service_, Manifest::EXTERNAL_PREF); 6074 new MockExtensionProvider(service_, Manifest::EXTERNAL_PREF);
6000 AddMockExternalProvider(provider); 6075 AddMockExternalProvider(provider);
6001 6076
6002 provider->UpdateOrAddExtension(page_action, "1.0.0.0", 6077 provider->UpdateOrAddExtension(page_action, "1.0.0.0",
6003 data_dir_.AppendASCII("page_action.crx")); 6078 data_dir_.AppendASCII("page_action.crx"));
6004 6079
6005 service_->CheckForExternalUpdates(); 6080 service_->CheckForExternalUpdates();
6006 loop_.RunUntilIdle(); 6081 content::WindowedNotificationObserver(
6082 chrome::NOTIFICATION_CRX_INSTALLER_DONE,
6083 content::NotificationService::AllSources()).Wait();
6007 EXPECT_TRUE(extensions::HasExternalInstallError(service_)); 6084 EXPECT_TRUE(extensions::HasExternalInstallError(service_));
6008 EXPECT_FALSE(service_->IsExtensionEnabled(page_action)); 6085 EXPECT_FALSE(service_->IsExtensionEnabled(page_action));
6009 6086
6010 const Extension* extension = 6087 const Extension* extension =
6011 service_->disabled_extensions()->GetByID(page_action); 6088 service_->disabled_extensions()->GetByID(page_action);
6012 EXPECT_TRUE(extension); 6089 EXPECT_TRUE(extension);
6013 EXPECT_EQ(page_action, extension->id()); 6090 EXPECT_EQ(page_action, extension->id());
6014 6091
6015 service_->EnableExtension(page_action); 6092 service_->EnableExtension(page_action);
6016 EXPECT_FALSE(extensions::HasExternalInstallError(service_)); 6093 EXPECT_FALSE(extensions::HasExternalInstallError(service_));
(...skipping 11 matching lines...) Expand all
6028 AddMockExternalProvider(provider); 6105 AddMockExternalProvider(provider);
6029 6106
6030 provider->UpdateOrAddExtension(page_action, "1.0.0.0", 6107 provider->UpdateOrAddExtension(page_action, "1.0.0.0",
6031 data_dir_.AppendASCII("page_action.crx")); 6108 data_dir_.AppendASCII("page_action.crx"));
6032 provider->UpdateOrAddExtension(good_crx, "1.0.0.0", 6109 provider->UpdateOrAddExtension(good_crx, "1.0.0.0",
6033 data_dir_.AppendASCII("good.crx")); 6110 data_dir_.AppendASCII("good.crx"));
6034 provider->UpdateOrAddExtension(theme_crx, "2.0", 6111 provider->UpdateOrAddExtension(theme_crx, "2.0",
6035 data_dir_.AppendASCII("theme.crx")); 6112 data_dir_.AppendASCII("theme.crx"));
6036 6113
6037 service_->CheckForExternalUpdates(); 6114 service_->CheckForExternalUpdates();
6038 loop_.RunUntilIdle(); 6115 int count = 3;
6116 content::WindowedNotificationObserver(
6117 chrome::NOTIFICATION_CRX_INSTALLER_DONE,
6118 base::Bind(&WaitForCountNotificationsCallback, &count)).Wait();
6039 EXPECT_TRUE(extensions::HasExternalInstallError(service_)); 6119 EXPECT_TRUE(extensions::HasExternalInstallError(service_));
6040 EXPECT_FALSE(service_->IsExtensionEnabled(page_action)); 6120 EXPECT_FALSE(service_->IsExtensionEnabled(page_action));
6041 EXPECT_FALSE(service_->IsExtensionEnabled(good_crx)); 6121 EXPECT_FALSE(service_->IsExtensionEnabled(good_crx));
6042 EXPECT_FALSE(service_->IsExtensionEnabled(theme_crx)); 6122 EXPECT_FALSE(service_->IsExtensionEnabled(theme_crx));
6043 6123
6044 service_->EnableExtension(page_action); 6124 service_->EnableExtension(page_action);
6045 EXPECT_TRUE(extensions::HasExternalInstallError(service_)); 6125 EXPECT_TRUE(extensions::HasExternalInstallError(service_));
6046 EXPECT_FALSE(extensions::HasExternalInstallBubble(service_)); 6126 EXPECT_FALSE(extensions::HasExternalInstallBubble(service_));
6047 service_->EnableExtension(theme_crx); 6127 service_->EnableExtension(theme_crx);
6048 EXPECT_TRUE(extensions::HasExternalInstallError(service_)); 6128 EXPECT_TRUE(extensions::HasExternalInstallError(service_));
(...skipping 17 matching lines...) Expand all
6066 PackCRX(data_dir_.AppendASCII("update_from_webstore"), 6146 PackCRX(data_dir_.AppendASCII("update_from_webstore"),
6067 data_dir_.AppendASCII("update_from_webstore.pem"), 6147 data_dir_.AppendASCII("update_from_webstore.pem"),
6068 crx_path); 6148 crx_path);
6069 6149
6070 MockExtensionProvider* provider = 6150 MockExtensionProvider* provider =
6071 new MockExtensionProvider(service_, Manifest::EXTERNAL_PREF); 6151 new MockExtensionProvider(service_, Manifest::EXTERNAL_PREF);
6072 AddMockExternalProvider(provider); 6152 AddMockExternalProvider(provider);
6073 provider->UpdateOrAddExtension(updates_from_webstore, "1", crx_path); 6153 provider->UpdateOrAddExtension(updates_from_webstore, "1", crx_path);
6074 6154
6075 service_->CheckForExternalUpdates(); 6155 service_->CheckForExternalUpdates();
6076 loop_.RunUntilIdle(); 6156 content::WindowedNotificationObserver(
6157 chrome::NOTIFICATION_CRX_INSTALLER_DONE,
6158 content::NotificationService::AllSources()).Wait();
6077 EXPECT_TRUE(extensions::HasExternalInstallError(service_)); 6159 EXPECT_TRUE(extensions::HasExternalInstallError(service_));
6078 EXPECT_TRUE(extensions::HasExternalInstallBubble(service_)); 6160 EXPECT_TRUE(extensions::HasExternalInstallBubble(service_));
6079 EXPECT_FALSE(service_->IsExtensionEnabled(updates_from_webstore)); 6161 EXPECT_FALSE(service_->IsExtensionEnabled(updates_from_webstore));
6080 } 6162 }
6081 6163
6082 // Test that there is no bubble for external extensions if the profile is new. 6164 // Test that there is no bubble for external extensions if the profile is new.
6083 TEST_F(ExtensionServiceTest, ExternalInstallUpdatesFromWebstoreNewProfile) { 6165 TEST_F(ExtensionServiceTest, ExternalInstallUpdatesFromWebstoreNewProfile) {
6084 FeatureSwitch::ScopedOverride prompt( 6166 FeatureSwitch::ScopedOverride prompt(
6085 FeatureSwitch::prompt_for_external_extensions(), true); 6167 FeatureSwitch::prompt_for_external_extensions(), true);
6086 6168
6087 InitializeEmptyExtensionService(); 6169 InitializeEmptyExtensionService();
6088 6170
6089 base::FilePath crx_path = temp_dir_.path().AppendASCII("webstore.crx"); 6171 base::FilePath crx_path = temp_dir_.path().AppendASCII("webstore.crx");
6090 PackCRX(data_dir_.AppendASCII("update_from_webstore"), 6172 PackCRX(data_dir_.AppendASCII("update_from_webstore"),
6091 data_dir_.AppendASCII("update_from_webstore.pem"), 6173 data_dir_.AppendASCII("update_from_webstore.pem"),
6092 crx_path); 6174 crx_path);
6093 6175
6094 MockExtensionProvider* provider = 6176 MockExtensionProvider* provider =
6095 new MockExtensionProvider(service_, Manifest::EXTERNAL_PREF); 6177 new MockExtensionProvider(service_, Manifest::EXTERNAL_PREF);
6096 AddMockExternalProvider(provider); 6178 AddMockExternalProvider(provider);
6097 provider->UpdateOrAddExtension(updates_from_webstore, "1", crx_path); 6179 provider->UpdateOrAddExtension(updates_from_webstore, "1", crx_path);
6098 6180
6099 service_->CheckForExternalUpdates(); 6181 service_->CheckForExternalUpdates();
6100 loop_.RunUntilIdle(); 6182 content::WindowedNotificationObserver(
6183 chrome::NOTIFICATION_CRX_INSTALLER_DONE,
6184 content::NotificationService::AllSources()).Wait();
6101 EXPECT_TRUE(extensions::HasExternalInstallError(service_)); 6185 EXPECT_TRUE(extensions::HasExternalInstallError(service_));
6102 EXPECT_FALSE(extensions::HasExternalInstallBubble(service_)); 6186 EXPECT_FALSE(extensions::HasExternalInstallBubble(service_));
6103 EXPECT_FALSE(service_->IsExtensionEnabled(updates_from_webstore)); 6187 EXPECT_FALSE(service_->IsExtensionEnabled(updates_from_webstore));
6104 } 6188 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698