OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/extensions/extension_service_unittest.h" | 5 #include "chrome/browser/extensions/extension_service_unittest.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <set> | 8 #include <set> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 1211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1222 path, Extension::EXTERNAL_PREF); | 1222 path, Extension::EXTERNAL_PREF); |
1223 loop_.RunAllPending(); | 1223 loop_.RunAllPending(); |
1224 ASSERT_TRUE(NULL == service_->GetExtensionById(good_crx, false)); | 1224 ASSERT_TRUE(NULL == service_->GetExtensionById(good_crx, false)); |
1225 ValidateIntegerPref(good_crx, "location", | 1225 ValidateIntegerPref(good_crx, "location", |
1226 Extension::EXTERNAL_EXTENSION_UNINSTALLED); | 1226 Extension::EXTERNAL_EXTENSION_UNINSTALLED); |
1227 | 1227 |
1228 // Try adding the same extension from an external update URL. | 1228 // Try adding the same extension from an external update URL. |
1229 service_->pending_extension_manager()->AddFromExternalUpdateUrl( | 1229 service_->pending_extension_manager()->AddFromExternalUpdateUrl( |
1230 good_crx, | 1230 good_crx, |
1231 GURL("http:://fake.update/url"), | 1231 GURL("http:://fake.update/url"), |
1232 Extension::EXTERNAL_PREF_DOWNLOAD); | 1232 Extension::EXTERNAL_PREF_DOWNLOAD, |
| 1233 false); |
1233 | 1234 |
1234 ASSERT_FALSE(service_->pending_extension_manager()->IsIdPending(good_crx)); | 1235 ASSERT_FALSE(service_->pending_extension_manager()->IsIdPending(good_crx)); |
1235 } | 1236 } |
1236 | 1237 |
1237 // Test that uninstalling an external extension does not crash when | 1238 // Test that uninstalling an external extension does not crash when |
1238 // the extension could not be loaded. | 1239 // the extension could not be loaded. |
1239 // This extension shown in preferences file requires an experimental permission. | 1240 // This extension shown in preferences file requires an experimental permission. |
1240 // It could not be loaded without such permission. | 1241 // It could not be loaded without such permission. |
1241 TEST_F(ExtensionServiceTest, UninstallingNotLoadedExtension) { | 1242 TEST_F(ExtensionServiceTest, UninstallingNotLoadedExtension) { |
1242 FilePath source_install_dir = data_dir_ | 1243 FilePath source_install_dir = data_dir_ |
(...skipping 988 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2231 #define MAYBE_UpdatePendingExternalCrx FAILS_UpdatePendingExternalCrx | 2232 #define MAYBE_UpdatePendingExternalCrx FAILS_UpdatePendingExternalCrx |
2232 #else | 2233 #else |
2233 #define MAYBE_UpdatePendingExternalCrx UpdatePendingExternalCrx | 2234 #define MAYBE_UpdatePendingExternalCrx UpdatePendingExternalCrx |
2234 #endif | 2235 #endif |
2235 // Test updating a pending CRX as if the source is an external extension | 2236 // Test updating a pending CRX as if the source is an external extension |
2236 // with an update URL. In this case we don't know if the CRX is a theme | 2237 // with an update URL. In this case we don't know if the CRX is a theme |
2237 // or not. | 2238 // or not. |
2238 TEST_F(ExtensionServiceTest, MAYBE_UpdatePendingExternalCrx) { | 2239 TEST_F(ExtensionServiceTest, MAYBE_UpdatePendingExternalCrx) { |
2239 InitializeEmptyExtensionService(); | 2240 InitializeEmptyExtensionService(); |
2240 service_->pending_extension_manager()->AddFromExternalUpdateUrl( | 2241 service_->pending_extension_manager()->AddFromExternalUpdateUrl( |
2241 theme_crx, GURL(), Extension::EXTERNAL_PREF_DOWNLOAD); | 2242 theme_crx, GURL(), Extension::EXTERNAL_PREF_DOWNLOAD, false); |
2242 | 2243 |
2243 EXPECT_TRUE(service_->pending_extension_manager()->IsIdPending(theme_crx)); | 2244 EXPECT_TRUE(service_->pending_extension_manager()->IsIdPending(theme_crx)); |
2244 | 2245 |
2245 FilePath path = data_dir_.AppendASCII("theme.crx"); | 2246 FilePath path = data_dir_.AppendASCII("theme.crx"); |
2246 UpdateExtension(theme_crx, path, ENABLED); | 2247 UpdateExtension(theme_crx, path, ENABLED); |
2247 | 2248 |
2248 EXPECT_FALSE(service_->pending_extension_manager()->IsIdPending(theme_crx)); | 2249 EXPECT_FALSE(service_->pending_extension_manager()->IsIdPending(theme_crx)); |
2249 | 2250 |
2250 const Extension* extension = service_->GetExtensionById(theme_crx, true); | 2251 const Extension* extension = service_->GetExtensionById(theme_crx, true); |
2251 ASSERT_TRUE(extension); | 2252 ASSERT_TRUE(extension); |
(...skipping 16 matching lines...) Expand all Loading... |
2268 kGoodInstallSilently)); | 2269 kGoodInstallSilently)); |
2269 | 2270 |
2270 // Check that there is a pending crx, with is_from_sync set to true. | 2271 // Check that there is a pending crx, with is_from_sync set to true. |
2271 PendingExtensionInfo pending_extension_info; | 2272 PendingExtensionInfo pending_extension_info; |
2272 ASSERT_TRUE(service_->pending_extension_manager()->GetById( | 2273 ASSERT_TRUE(service_->pending_extension_manager()->GetById( |
2273 kGoodId, &pending_extension_info)); | 2274 kGoodId, &pending_extension_info)); |
2274 EXPECT_TRUE(pending_extension_info.is_from_sync()); | 2275 EXPECT_TRUE(pending_extension_info.is_from_sync()); |
2275 | 2276 |
2276 // Add a crx to be updated, with the same ID, from a non-sync source. | 2277 // Add a crx to be updated, with the same ID, from a non-sync source. |
2277 service_->pending_extension_manager()->AddFromExternalUpdateUrl( | 2278 service_->pending_extension_manager()->AddFromExternalUpdateUrl( |
2278 kGoodId, GURL(kGoodUpdateURL), Extension::EXTERNAL_PREF_DOWNLOAD); | 2279 kGoodId, GURL(kGoodUpdateURL), Extension::EXTERNAL_PREF_DOWNLOAD, false); |
2279 | 2280 |
2280 // Check that there is a pending crx, with is_from_sync set to false. | 2281 // Check that there is a pending crx, with is_from_sync set to false. |
2281 ASSERT_TRUE(service_->pending_extension_manager()->GetById( | 2282 ASSERT_TRUE(service_->pending_extension_manager()->GetById( |
2282 kGoodId, &pending_extension_info)); | 2283 kGoodId, &pending_extension_info)); |
2283 EXPECT_FALSE(pending_extension_info.is_from_sync()); | 2284 EXPECT_FALSE(pending_extension_info.is_from_sync()); |
2284 EXPECT_EQ(Extension::EXTERNAL_PREF_DOWNLOAD, | 2285 EXPECT_EQ(Extension::EXTERNAL_PREF_DOWNLOAD, |
2285 pending_extension_info.install_source()); | 2286 pending_extension_info.install_source()); |
2286 | 2287 |
2287 // Add a crx to be installed from the update mechanism. | 2288 // Add a crx to be installed from the update mechanism. |
2288 EXPECT_FALSE(service_->pending_extension_manager()->AddFromSync( | 2289 EXPECT_FALSE(service_->pending_extension_manager()->AddFromSync( |
(...skipping 1408 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3697 PendingExtensionInfo info; | 3698 PendingExtensionInfo info; |
3698 EXPECT_TRUE( | 3699 EXPECT_TRUE( |
3699 service_->pending_extension_manager()->GetById(good_crx, &info)); | 3700 service_->pending_extension_manager()->GetById(good_crx, &info)); |
3700 EXPECT_EQ(extension_sync_data.update_url, info.update_url()); | 3701 EXPECT_EQ(extension_sync_data.update_url, info.update_url()); |
3701 EXPECT_TRUE(info.is_from_sync()); | 3702 EXPECT_TRUE(info.is_from_sync()); |
3702 EXPECT_TRUE(info.install_silently()); | 3703 EXPECT_TRUE(info.install_silently()); |
3703 EXPECT_EQ(Extension::INTERNAL, info.install_source()); | 3704 EXPECT_EQ(Extension::INTERNAL, info.install_source()); |
3704 // TODO(akalin): Figure out a way to test |info.ShouldAllowInstall()|. | 3705 // TODO(akalin): Figure out a way to test |info.ShouldAllowInstall()|. |
3705 } | 3706 } |
3706 | 3707 |
| 3708 TEST_F(ExtensionServiceTest, HigherPriorityInstall) { |
| 3709 InitializeEmptyExtensionService(); |
| 3710 |
| 3711 FilePath path = data_dir_.AppendASCII("good.crx"); |
| 3712 InstallCrx(path, true); |
| 3713 ValidatePrefKeyCount(1u); |
| 3714 ValidateIntegerPref(good_crx, "state", Extension::ENABLED); |
| 3715 ValidateIntegerPref(good_crx, "location", Extension::INTERNAL); |
| 3716 |
| 3717 PendingExtensionManager* pending = service_->pending_extension_manager(); |
| 3718 EXPECT_FALSE(pending->IsIdPending(kGoodId)); |
| 3719 |
| 3720 // Skip install when the location is the same. |
| 3721 service_->OnExternalExtensionUpdateUrlFound(kGoodId, GURL(kGoodUpdateURL), |
| 3722 Extension::INTERNAL); |
| 3723 EXPECT_FALSE(pending->IsIdPending(kGoodId)); |
| 3724 // Force install when the location has higher priority. |
| 3725 service_->OnExternalExtensionUpdateUrlFound(kGoodId, GURL(kGoodUpdateURL), |
| 3726 Extension::EXTERNAL_POLICY_DOWNLOAD); |
| 3727 EXPECT_TRUE(pending->IsIdPending(kGoodId)); |
| 3728 pending->Remove(kGoodId); |
| 3729 // Skip install when the location has lower priority. |
| 3730 service_->OnExternalExtensionUpdateUrlFound(kGoodId, GURL(kGoodUpdateURL), |
| 3731 Extension::INTERNAL); |
| 3732 EXPECT_FALSE(pending->IsIdPending(kGoodId)); |
| 3733 } |
| 3734 |
3707 // Test that when multiple sources try to install an extension, | 3735 // Test that when multiple sources try to install an extension, |
3708 // we consistently choose the right one. To make tests easy to read, | 3736 // we consistently choose the right one. To make tests easy to read, |
3709 // methods that fake requests to install crx files in several ways | 3737 // methods that fake requests to install crx files in several ways |
3710 // are provided. | 3738 // are provided. |
3711 class ExtensionSourcePriorityTest : public ExtensionServiceTest { | 3739 class ExtensionSourcePriorityTest : public ExtensionServiceTest { |
3712 public: | 3740 public: |
3713 void SetUp() { | 3741 void SetUp() { |
3714 ExtensionServiceTest::SetUp(); | 3742 ExtensionServiceTest::SetUp(); |
3715 | 3743 |
3716 // All tests use a single extension. Put the id and path in member vars | 3744 // All tests use a single extension. Put the id and path in member vars |
3717 // that all methods can read. | 3745 // that all methods can read. |
3718 crx_id_ = kGoodId; | 3746 crx_id_ = kGoodId; |
3719 crx_path_ = data_dir_.AppendASCII("good.crx"); | 3747 crx_path_ = data_dir_.AppendASCII("good.crx"); |
3720 } | 3748 } |
3721 | 3749 |
3722 // Fake an external source adding a URL to fetch an extension from. | 3750 // Fake an external source adding a URL to fetch an extension from. |
3723 void AddPendingExternalPrefUrl() { | 3751 void AddPendingExternalPrefUrl() { |
3724 service_->pending_extension_manager()->AddFromExternalUpdateUrl( | 3752 service_->pending_extension_manager()->AddFromExternalUpdateUrl( |
3725 crx_id_, GURL(), Extension::EXTERNAL_PREF_DOWNLOAD); | 3753 crx_id_, GURL(), Extension::EXTERNAL_PREF_DOWNLOAD, false); |
3726 } | 3754 } |
3727 | 3755 |
3728 // Fake an external file from external_extensions.json. | 3756 // Fake an external file from external_extensions.json. |
3729 void AddPendingExternalPrefFileInstall() { | 3757 void AddPendingExternalPrefFileInstall() { |
3730 scoped_ptr<Version> version; | 3758 scoped_ptr<Version> version; |
3731 version.reset(Version::GetVersionFromString("1.0.0.0")); | 3759 version.reset(Version::GetVersionFromString("1.0.0.0")); |
3732 | 3760 |
3733 service_->OnExternalExtensionFileFound( | 3761 service_->OnExternalExtensionFileFound( |
3734 crx_id_, version.get(), crx_path_, Extension::EXTERNAL_PREF); | 3762 crx_id_, version.get(), crx_path_, Extension::EXTERNAL_PREF); |
3735 } | 3763 } |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3848 ASSERT_FALSE(AddPendingSyncInstall()); | 3876 ASSERT_FALSE(AddPendingSyncInstall()); |
3849 | 3877 |
3850 // Wait for the external source to install. | 3878 // Wait for the external source to install. |
3851 WaitForCrxInstall(crx_path_, true); | 3879 WaitForCrxInstall(crx_path_, true); |
3852 ASSERT_TRUE(IsCrxInstalled()); | 3880 ASSERT_TRUE(IsCrxInstalled()); |
3853 | 3881 |
3854 // Now that the extension is installed, sync request should fail | 3882 // Now that the extension is installed, sync request should fail |
3855 // because the extension is already installed. | 3883 // because the extension is already installed. |
3856 ASSERT_FALSE(AddPendingSyncInstall()); | 3884 ASSERT_FALSE(AddPendingSyncInstall()); |
3857 } | 3885 } |
OLD | NEW |