OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/extensions/extension_service_unittest.h" | 5 #include "chrome/browser/extensions/extension_service_unittest.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <set> | 8 #include <set> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 2485 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2496 InitializeEmptyExtensionService(); | 2496 InitializeEmptyExtensionService(); |
2497 | 2497 |
2498 const std::string kFakeId(all_zero); | 2498 const std::string kFakeId(all_zero); |
2499 const GURL kFakeUpdateURL("http:://fake.update/url"); | 2499 const GURL kFakeUpdateURL("http:://fake.update/url"); |
2500 const bool kFakeInstallSilently(true); | 2500 const bool kFakeInstallSilently(true); |
2501 | 2501 |
2502 EXPECT_TRUE(service_->pending_extension_manager()->AddFromSync( | 2502 EXPECT_TRUE(service_->pending_extension_manager()->AddFromSync( |
2503 kFakeId, kFakeUpdateURL, &IsExtension, | 2503 kFakeId, kFakeUpdateURL, &IsExtension, |
2504 kFakeInstallSilently)); | 2504 kFakeInstallSilently)); |
2505 | 2505 |
2506 const PendingExtensionInfo* pending_extension_info; | 2506 const extensions::PendingExtensionInfo* pending_extension_info; |
2507 ASSERT_TRUE((pending_extension_info = service_->pending_extension_manager()-> | 2507 ASSERT_TRUE((pending_extension_info = service_->pending_extension_manager()-> |
2508 GetById(kFakeId))); | 2508 GetById(kFakeId))); |
2509 EXPECT_EQ(kFakeUpdateURL, pending_extension_info->update_url()); | 2509 EXPECT_EQ(kFakeUpdateURL, pending_extension_info->update_url()); |
2510 EXPECT_EQ(&IsExtension, pending_extension_info->should_allow_install_); | 2510 EXPECT_EQ(&IsExtension, pending_extension_info->should_allow_install_); |
2511 EXPECT_EQ(kFakeInstallSilently, pending_extension_info->install_silently()); | 2511 EXPECT_EQ(kFakeInstallSilently, pending_extension_info->install_silently()); |
2512 } | 2512 } |
2513 | 2513 |
2514 namespace { | 2514 namespace { |
2515 const char kGoodId[] = "ldnnhddmnhbkjipkidpdiheffobcpfmf"; | 2515 const char kGoodId[] = "ldnnhddmnhbkjipkidpdiheffobcpfmf"; |
2516 const char kGoodUpdateURL[] = "http://good.update/url"; | 2516 const char kGoodUpdateURL[] = "http://good.update/url"; |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2599 // but a sync update should not overwrite a non-sync update. | 2599 // but a sync update should not overwrite a non-sync update. |
2600 TEST_F(ExtensionServiceTest, UpdatePendingExternalCrxWinsOverSync) { | 2600 TEST_F(ExtensionServiceTest, UpdatePendingExternalCrxWinsOverSync) { |
2601 InitializeEmptyExtensionService(); | 2601 InitializeEmptyExtensionService(); |
2602 | 2602 |
2603 // Add a crx to be installed from the update mechanism. | 2603 // Add a crx to be installed from the update mechanism. |
2604 EXPECT_TRUE(service_->pending_extension_manager()->AddFromSync( | 2604 EXPECT_TRUE(service_->pending_extension_manager()->AddFromSync( |
2605 kGoodId, GURL(kGoodUpdateURL), &IsExtension, | 2605 kGoodId, GURL(kGoodUpdateURL), &IsExtension, |
2606 kGoodInstallSilently)); | 2606 kGoodInstallSilently)); |
2607 | 2607 |
2608 // Check that there is a pending crx, with is_from_sync set to true. | 2608 // Check that there is a pending crx, with is_from_sync set to true. |
2609 const PendingExtensionInfo* pending_extension_info; | 2609 const extensions::PendingExtensionInfo* pending_extension_info; |
2610 ASSERT_TRUE((pending_extension_info = service_->pending_extension_manager()-> | 2610 ASSERT_TRUE((pending_extension_info = service_->pending_extension_manager()-> |
2611 GetById(kGoodId))); | 2611 GetById(kGoodId))); |
2612 EXPECT_TRUE(pending_extension_info->is_from_sync()); | 2612 EXPECT_TRUE(pending_extension_info->is_from_sync()); |
2613 | 2613 |
2614 // Add a crx to be updated, with the same ID, from a non-sync source. | 2614 // Add a crx to be updated, with the same ID, from a non-sync source. |
2615 EXPECT_TRUE(service_->pending_extension_manager()->AddFromExternalUpdateUrl( | 2615 EXPECT_TRUE(service_->pending_extension_manager()->AddFromExternalUpdateUrl( |
2616 kGoodId, GURL(kGoodUpdateURL), Extension::EXTERNAL_PREF_DOWNLOAD)); | 2616 kGoodId, GURL(kGoodUpdateURL), Extension::EXTERNAL_PREF_DOWNLOAD)); |
2617 | 2617 |
2618 // Check that there is a pending crx, with is_from_sync set to false. | 2618 // Check that there is a pending crx, with is_from_sync set to false. |
2619 ASSERT_TRUE((pending_extension_info = service_->pending_extension_manager()-> | 2619 ASSERT_TRUE((pending_extension_info = service_->pending_extension_manager()-> |
(...skipping 2144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4764 list[0] = sync_change; | 4764 list[0] = sync_change; |
4765 | 4765 |
4766 | 4766 |
4767 EXPECT_TRUE(service_->IsExtensionEnabled(good_crx)); | 4767 EXPECT_TRUE(service_->IsExtensionEnabled(good_crx)); |
4768 EXPECT_FALSE(service_->IsIncognitoEnabled(good_crx)); | 4768 EXPECT_FALSE(service_->IsIncognitoEnabled(good_crx)); |
4769 service_->ProcessSyncChanges(FROM_HERE, list); | 4769 service_->ProcessSyncChanges(FROM_HERE, list); |
4770 EXPECT_TRUE(service_->updater()->WillCheckSoon()); | 4770 EXPECT_TRUE(service_->updater()->WillCheckSoon()); |
4771 EXPECT_FALSE(service_->IsExtensionEnabled(good_crx)); | 4771 EXPECT_FALSE(service_->IsExtensionEnabled(good_crx)); |
4772 EXPECT_TRUE(service_->IsIncognitoEnabled(good_crx)); | 4772 EXPECT_TRUE(service_->IsIncognitoEnabled(good_crx)); |
4773 | 4773 |
4774 const PendingExtensionInfo* info; | 4774 const extensions::PendingExtensionInfo* info; |
4775 EXPECT_TRUE((info = service_->pending_extension_manager()-> | 4775 EXPECT_TRUE((info = service_->pending_extension_manager()-> |
4776 GetById(good_crx))); | 4776 GetById(good_crx))); |
4777 EXPECT_EQ(ext_specifics->update_url(), info->update_url().spec()); | 4777 EXPECT_EQ(ext_specifics->update_url(), info->update_url().spec()); |
4778 EXPECT_TRUE(info->is_from_sync()); | 4778 EXPECT_TRUE(info->is_from_sync()); |
4779 EXPECT_TRUE(info->install_silently()); | 4779 EXPECT_TRUE(info->install_silently()); |
4780 EXPECT_EQ(Extension::INTERNAL, info->install_source()); | 4780 EXPECT_EQ(Extension::INTERNAL, info->install_source()); |
4781 // TODO(akalin): Figure out a way to test |info.ShouldAllowInstall()|. | 4781 // TODO(akalin): Figure out a way to test |info.ShouldAllowInstall()|. |
4782 } | 4782 } |
4783 | 4783 |
4784 TEST_F(ExtensionServiceTest, InstallPriorityExternalUpdateUrl) { | 4784 TEST_F(ExtensionServiceTest, InstallPriorityExternalUpdateUrl) { |
4785 InitializeEmptyExtensionService(); | 4785 InitializeEmptyExtensionService(); |
4786 | 4786 |
4787 FilePath path = data_dir_.AppendASCII("good.crx"); | 4787 FilePath path = data_dir_.AppendASCII("good.crx"); |
4788 InstallCRX(path, INSTALL_NEW); | 4788 InstallCRX(path, INSTALL_NEW); |
4789 ValidatePrefKeyCount(1u); | 4789 ValidatePrefKeyCount(1u); |
4790 ValidateIntegerPref(good_crx, "state", Extension::ENABLED); | 4790 ValidateIntegerPref(good_crx, "state", Extension::ENABLED); |
4791 ValidateIntegerPref(good_crx, "location", Extension::INTERNAL); | 4791 ValidateIntegerPref(good_crx, "location", Extension::INTERNAL); |
4792 | 4792 |
4793 PendingExtensionManager* pending = service_->pending_extension_manager(); | 4793 extensions::PendingExtensionManager* pending = |
| 4794 service_->pending_extension_manager(); |
4794 EXPECT_FALSE(pending->IsIdPending(kGoodId)); | 4795 EXPECT_FALSE(pending->IsIdPending(kGoodId)); |
4795 | 4796 |
4796 // Skip install when the location is the same. | 4797 // Skip install when the location is the same. |
4797 EXPECT_FALSE( | 4798 EXPECT_FALSE( |
4798 service_->OnExternalExtensionUpdateUrlFound( | 4799 service_->OnExternalExtensionUpdateUrlFound( |
4799 kGoodId, GURL(kGoodUpdateURL), Extension::INTERNAL)); | 4800 kGoodId, GURL(kGoodUpdateURL), Extension::INTERNAL)); |
4800 EXPECT_FALSE(pending->IsIdPending(kGoodId)); | 4801 EXPECT_FALSE(pending->IsIdPending(kGoodId)); |
4801 | 4802 |
4802 // Install when the location has higher priority. | 4803 // Install when the location has higher priority. |
4803 EXPECT_TRUE( | 4804 EXPECT_TRUE( |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4844 ASSERT_EQ(Extension::EXTERNAL_REGISTRY, | 4845 ASSERT_EQ(Extension::EXTERNAL_REGISTRY, |
4845 Extension::GetHigherPriorityLocation(Extension::EXTERNAL_REGISTRY, | 4846 Extension::GetHigherPriorityLocation(Extension::EXTERNAL_REGISTRY, |
4846 Extension::EXTERNAL_PREF)); | 4847 Extension::EXTERNAL_PREF)); |
4847 ASSERT_EQ(Extension::EXTERNAL_REGISTRY, | 4848 ASSERT_EQ(Extension::EXTERNAL_REGISTRY, |
4848 Extension::GetHigherPriorityLocation(Extension::EXTERNAL_REGISTRY, | 4849 Extension::GetHigherPriorityLocation(Extension::EXTERNAL_REGISTRY, |
4849 Extension::INTERNAL)); | 4850 Extension::INTERNAL)); |
4850 ASSERT_EQ(Extension::EXTERNAL_PREF, | 4851 ASSERT_EQ(Extension::EXTERNAL_PREF, |
4851 Extension::GetHigherPriorityLocation(Extension::EXTERNAL_PREF, | 4852 Extension::GetHigherPriorityLocation(Extension::EXTERNAL_PREF, |
4852 Extension::INTERNAL)); | 4853 Extension::INTERNAL)); |
4853 | 4854 |
4854 PendingExtensionManager* pending = service_->pending_extension_manager(); | 4855 extensions::PendingExtensionManager* pending = |
| 4856 service_->pending_extension_manager(); |
4855 EXPECT_FALSE(pending->IsIdPending(kGoodId)); | 4857 EXPECT_FALSE(pending->IsIdPending(kGoodId)); |
4856 | 4858 |
4857 // Simulate an external source adding the extension as INTERNAL. | 4859 // Simulate an external source adding the extension as INTERNAL. |
4858 EXPECT_TRUE( | 4860 EXPECT_TRUE( |
4859 service_->OnExternalExtensionFileFound( | 4861 service_->OnExternalExtensionFileFound( |
4860 kGoodId, &older_version, kInvalidPathToCrx, | 4862 kGoodId, &older_version, kInvalidPathToCrx, |
4861 Extension::INTERNAL, kCreationFlags, kDontMarkAcknowledged)); | 4863 Extension::INTERNAL, kCreationFlags, kDontMarkAcknowledged)); |
4862 EXPECT_TRUE(pending->IsIdPending(kGoodId)); | 4864 EXPECT_TRUE(pending->IsIdPending(kGoodId)); |
4863 WaitForCrxInstall(kInvalidPathToCrx, INSTALL_FAILED); | 4865 WaitForCrxInstall(kInvalidPathToCrx, INSTALL_FAILED); |
4864 | 4866 |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4982 TEST_F(ExtensionServiceTest, ConcurrentExternalLocalFile) { | 4984 TEST_F(ExtensionServiceTest, ConcurrentExternalLocalFile) { |
4983 Version kVersion123("1.2.3"); | 4985 Version kVersion123("1.2.3"); |
4984 Version kVersion124("1.2.4"); | 4986 Version kVersion124("1.2.4"); |
4985 Version kVersion125("1.2.5"); | 4987 Version kVersion125("1.2.5"); |
4986 const FilePath kInvalidPathToCrx = FilePath(); | 4988 const FilePath kInvalidPathToCrx = FilePath(); |
4987 const int kCreationFlags = 0; | 4989 const int kCreationFlags = 0; |
4988 const bool kDontMarkAcknowledged = false; | 4990 const bool kDontMarkAcknowledged = false; |
4989 | 4991 |
4990 InitializeEmptyExtensionService(); | 4992 InitializeEmptyExtensionService(); |
4991 | 4993 |
4992 PendingExtensionManager* pending = service_->pending_extension_manager(); | 4994 extensions::PendingExtensionManager* pending = |
| 4995 service_->pending_extension_manager(); |
4993 EXPECT_FALSE(pending->IsIdPending(kGoodId)); | 4996 EXPECT_FALSE(pending->IsIdPending(kGoodId)); |
4994 | 4997 |
4995 // An external provider starts installing from a local crx. | 4998 // An external provider starts installing from a local crx. |
4996 EXPECT_TRUE( | 4999 EXPECT_TRUE( |
4997 service_->OnExternalExtensionFileFound( | 5000 service_->OnExternalExtensionFileFound( |
4998 kGoodId, &kVersion123, kInvalidPathToCrx, | 5001 kGoodId, &kVersion123, kInvalidPathToCrx, |
4999 Extension::EXTERNAL_PREF, kCreationFlags, kDontMarkAcknowledged)); | 5002 Extension::EXTERNAL_PREF, kCreationFlags, kDontMarkAcknowledged)); |
5000 const PendingExtensionInfo* info; | 5003 const extensions::PendingExtensionInfo* info; |
5001 EXPECT_TRUE((info = pending->GetById(kGoodId))); | 5004 EXPECT_TRUE((info = pending->GetById(kGoodId))); |
5002 EXPECT_TRUE(info->version().IsValid()); | 5005 EXPECT_TRUE(info->version().IsValid()); |
5003 EXPECT_TRUE(info->version().Equals(kVersion123)); | 5006 EXPECT_TRUE(info->version().Equals(kVersion123)); |
5004 | 5007 |
5005 // Adding a newer version overrides the currently pending version. | 5008 // Adding a newer version overrides the currently pending version. |
5006 EXPECT_TRUE( | 5009 EXPECT_TRUE( |
5007 service_->OnExternalExtensionFileFound( | 5010 service_->OnExternalExtensionFileFound( |
5008 kGoodId, &kVersion124, kInvalidPathToCrx, | 5011 kGoodId, &kVersion124, kInvalidPathToCrx, |
5009 Extension::EXTERNAL_PREF, kCreationFlags, kDontMarkAcknowledged)); | 5012 Extension::EXTERNAL_PREF, kCreationFlags, kDontMarkAcknowledged)); |
5010 EXPECT_TRUE((info = pending->GetById(kGoodId))); | 5013 EXPECT_TRUE((info = pending->GetById(kGoodId))); |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5098 | 5101 |
5099 // Fake a policy install. | 5102 // Fake a policy install. |
5100 bool AddPendingPolicyInstall() { | 5103 bool AddPendingPolicyInstall() { |
5101 // Get path to the CRX with id |kGoodId|. | 5104 // Get path to the CRX with id |kGoodId|. |
5102 return service_->OnExternalExtensionUpdateUrlFound( | 5105 return service_->OnExternalExtensionUpdateUrlFound( |
5103 crx_id_, GURL(), Extension::EXTERNAL_POLICY_DOWNLOAD); | 5106 crx_id_, GURL(), Extension::EXTERNAL_POLICY_DOWNLOAD); |
5104 } | 5107 } |
5105 | 5108 |
5106 // Get the install source of a pending extension. | 5109 // Get the install source of a pending extension. |
5107 Extension::Location GetPendingLocation() { | 5110 Extension::Location GetPendingLocation() { |
5108 const PendingExtensionInfo* info; | 5111 const extensions::PendingExtensionInfo* info; |
5109 EXPECT_TRUE((info = service_->pending_extension_manager()-> | 5112 EXPECT_TRUE((info = service_->pending_extension_manager()-> |
5110 GetById(crx_id_))); | 5113 GetById(crx_id_))); |
5111 return info->install_source(); | 5114 return info->install_source(); |
5112 } | 5115 } |
5113 | 5116 |
5114 // Is an extension pending from a sync request? | 5117 // Is an extension pending from a sync request? |
5115 bool GetPendingIsFromSync() { | 5118 bool GetPendingIsFromSync() { |
5116 const PendingExtensionInfo* info; | 5119 const extensions::PendingExtensionInfo* info; |
5117 EXPECT_TRUE((info = service_->pending_extension_manager()-> | 5120 EXPECT_TRUE((info = service_->pending_extension_manager()-> |
5118 GetById(crx_id_))); | 5121 GetById(crx_id_))); |
5119 return info->is_from_sync(); | 5122 return info->is_from_sync(); |
5120 } | 5123 } |
5121 | 5124 |
5122 // Is the CRX id these tests use pending? | 5125 // Is the CRX id these tests use pending? |
5123 bool IsCrxPending() { | 5126 bool IsCrxPending() { |
5124 return service_->pending_extension_manager()->IsIdPending(crx_id_); | 5127 return service_->pending_extension_manager()->IsIdPending(crx_id_); |
5125 } | 5128 } |
5126 | 5129 |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5238 // This should NOT trigger an alert. | 5241 // This should NOT trigger an alert. |
5239 provider->UpdateOrAddExtension(hosted_app, "1.0.0.0", | 5242 provider->UpdateOrAddExtension(hosted_app, "1.0.0.0", |
5240 data_dir_.AppendASCII("hosted_app.crx")); | 5243 data_dir_.AppendASCII("hosted_app.crx")); |
5241 | 5244 |
5242 service_->CheckForExternalUpdates(); | 5245 service_->CheckForExternalUpdates(); |
5243 loop_.RunAllPending(); | 5246 loop_.RunAllPending(); |
5244 | 5247 |
5245 ASSERT_TRUE(service_->PopulateExtensionErrorUI(extension_error_ui.get())); | 5248 ASSERT_TRUE(service_->PopulateExtensionErrorUI(extension_error_ui.get())); |
5246 ASSERT_EQ(1u, extension_error_ui->get_external_extension_ids()->size()); | 5249 ASSERT_EQ(1u, extension_error_ui->get_external_extension_ids()->size()); |
5247 } | 5250 } |
OLD | NEW |