| 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 2395 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2406 InitializeEmptyExtensionService(); | 2406 InitializeEmptyExtensionService(); |
| 2407 | 2407 |
| 2408 const std::string kFakeId(all_zero); | 2408 const std::string kFakeId(all_zero); |
| 2409 const GURL kFakeUpdateURL("http:://fake.update/url"); | 2409 const GURL kFakeUpdateURL("http:://fake.update/url"); |
| 2410 const bool kFakeInstallSilently(true); | 2410 const bool kFakeInstallSilently(true); |
| 2411 | 2411 |
| 2412 EXPECT_TRUE(service_->pending_extension_manager()->AddFromSync( | 2412 EXPECT_TRUE(service_->pending_extension_manager()->AddFromSync( |
| 2413 kFakeId, kFakeUpdateURL, &IsExtension, | 2413 kFakeId, kFakeUpdateURL, &IsExtension, |
| 2414 kFakeInstallSilently)); | 2414 kFakeInstallSilently)); |
| 2415 | 2415 |
| 2416 PendingExtensionInfo pending_extension_info; | 2416 const PendingExtensionInfo* pending_extension_info; |
| 2417 ASSERT_TRUE(service_->pending_extension_manager()->GetById( | 2417 ASSERT_TRUE((pending_extension_info = service_->pending_extension_manager()-> |
| 2418 kFakeId, &pending_extension_info)); | 2418 GetById(kFakeId))); |
| 2419 EXPECT_EQ(kFakeUpdateURL, pending_extension_info.update_url()); | 2419 EXPECT_EQ(kFakeUpdateURL, pending_extension_info->update_url()); |
| 2420 EXPECT_EQ(&IsExtension, pending_extension_info.should_allow_install_); | 2420 EXPECT_EQ(&IsExtension, pending_extension_info->should_allow_install_); |
| 2421 EXPECT_EQ(kFakeInstallSilently, pending_extension_info.install_silently()); | 2421 EXPECT_EQ(kFakeInstallSilently, pending_extension_info->install_silently()); |
| 2422 } | 2422 } |
| 2423 | 2423 |
| 2424 namespace { | 2424 namespace { |
| 2425 const char kGoodId[] = "ldnnhddmnhbkjipkidpdiheffobcpfmf"; | 2425 const char kGoodId[] = "ldnnhddmnhbkjipkidpdiheffobcpfmf"; |
| 2426 const char kGoodUpdateURL[] = "http://good.update/url"; | 2426 const char kGoodUpdateURL[] = "http://good.update/url"; |
| 2427 const bool kGoodIsFromSync = true; | 2427 const bool kGoodIsFromSync = true; |
| 2428 const bool kGoodInstallSilently = true; | 2428 const bool kGoodInstallSilently = true; |
| 2429 } // namespace | 2429 } // namespace |
| 2430 | 2430 |
| 2431 // Test updating a pending extension. | 2431 // Test updating a pending extension. |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2509 // but a sync update should not overwrite a non-sync update. | 2509 // but a sync update should not overwrite a non-sync update. |
| 2510 TEST_F(ExtensionServiceTest, UpdatePendingExternalCrxWinsOverSync) { | 2510 TEST_F(ExtensionServiceTest, UpdatePendingExternalCrxWinsOverSync) { |
| 2511 InitializeEmptyExtensionService(); | 2511 InitializeEmptyExtensionService(); |
| 2512 | 2512 |
| 2513 // Add a crx to be installed from the update mechanism. | 2513 // Add a crx to be installed from the update mechanism. |
| 2514 EXPECT_TRUE(service_->pending_extension_manager()->AddFromSync( | 2514 EXPECT_TRUE(service_->pending_extension_manager()->AddFromSync( |
| 2515 kGoodId, GURL(kGoodUpdateURL), &IsExtension, | 2515 kGoodId, GURL(kGoodUpdateURL), &IsExtension, |
| 2516 kGoodInstallSilently)); | 2516 kGoodInstallSilently)); |
| 2517 | 2517 |
| 2518 // Check that there is a pending crx, with is_from_sync set to true. | 2518 // Check that there is a pending crx, with is_from_sync set to true. |
| 2519 PendingExtensionInfo pending_extension_info; | 2519 const PendingExtensionInfo* pending_extension_info; |
| 2520 ASSERT_TRUE(service_->pending_extension_manager()->GetById( | 2520 ASSERT_TRUE((pending_extension_info = service_->pending_extension_manager()-> |
| 2521 kGoodId, &pending_extension_info)); | 2521 GetById(kGoodId))); |
| 2522 EXPECT_TRUE(pending_extension_info.is_from_sync()); | 2522 EXPECT_TRUE(pending_extension_info->is_from_sync()); |
| 2523 | 2523 |
| 2524 // Add a crx to be updated, with the same ID, from a non-sync source. | 2524 // Add a crx to be updated, with the same ID, from a non-sync source. |
| 2525 EXPECT_TRUE(service_->pending_extension_manager()->AddFromExternalUpdateUrl( | 2525 EXPECT_TRUE(service_->pending_extension_manager()->AddFromExternalUpdateUrl( |
| 2526 kGoodId, GURL(kGoodUpdateURL), Extension::EXTERNAL_PREF_DOWNLOAD)); | 2526 kGoodId, GURL(kGoodUpdateURL), Extension::EXTERNAL_PREF_DOWNLOAD)); |
| 2527 | 2527 |
| 2528 // Check that there is a pending crx, with is_from_sync set to false. | 2528 // Check that there is a pending crx, with is_from_sync set to false. |
| 2529 ASSERT_TRUE(service_->pending_extension_manager()->GetById( | 2529 ASSERT_TRUE((pending_extension_info = service_->pending_extension_manager()-> |
| 2530 kGoodId, &pending_extension_info)); | 2530 GetById(kGoodId))); |
| 2531 EXPECT_FALSE(pending_extension_info.is_from_sync()); | 2531 EXPECT_FALSE(pending_extension_info->is_from_sync()); |
| 2532 EXPECT_EQ(Extension::EXTERNAL_PREF_DOWNLOAD, | 2532 EXPECT_EQ(Extension::EXTERNAL_PREF_DOWNLOAD, |
| 2533 pending_extension_info.install_source()); | 2533 pending_extension_info->install_source()); |
| 2534 | 2534 |
| 2535 // Add a crx to be installed from the update mechanism. | 2535 // Add a crx to be installed from the update mechanism. |
| 2536 EXPECT_FALSE(service_->pending_extension_manager()->AddFromSync( | 2536 EXPECT_FALSE(service_->pending_extension_manager()->AddFromSync( |
| 2537 kGoodId, GURL(kGoodUpdateURL), &IsExtension, | 2537 kGoodId, GURL(kGoodUpdateURL), &IsExtension, |
| 2538 kGoodInstallSilently)); | 2538 kGoodInstallSilently)); |
| 2539 | 2539 |
| 2540 // Check that the external, non-sync update was not overridden. | 2540 // Check that the external, non-sync update was not overridden. |
| 2541 ASSERT_TRUE(service_->pending_extension_manager()->GetById( | 2541 ASSERT_TRUE((pending_extension_info = service_->pending_extension_manager()-> |
| 2542 kGoodId, &pending_extension_info)); | 2542 GetById(kGoodId))); |
| 2543 EXPECT_FALSE(pending_extension_info.is_from_sync()); | 2543 EXPECT_FALSE(pending_extension_info->is_from_sync()); |
| 2544 EXPECT_EQ(Extension::EXTERNAL_PREF_DOWNLOAD, | 2544 EXPECT_EQ(Extension::EXTERNAL_PREF_DOWNLOAD, |
| 2545 pending_extension_info.install_source()); | 2545 pending_extension_info->install_source()); |
| 2546 } | 2546 } |
| 2547 | 2547 |
| 2548 // Updating a theme should fail if the updater is explicitly told that | 2548 // Updating a theme should fail if the updater is explicitly told that |
| 2549 // the CRX is not a theme. | 2549 // the CRX is not a theme. |
| 2550 TEST_F(ExtensionServiceTest, UpdatePendingCrxThemeMismatch) { | 2550 TEST_F(ExtensionServiceTest, UpdatePendingCrxThemeMismatch) { |
| 2551 InitializeEmptyExtensionService(); | 2551 InitializeEmptyExtensionService(); |
| 2552 EXPECT_TRUE(service_->pending_extension_manager()->AddFromSync( | 2552 EXPECT_TRUE(service_->pending_extension_manager()->AddFromSync( |
| 2553 theme_crx, GURL(), &IsExtension, true)); | 2553 theme_crx, GURL(), &IsExtension, true)); |
| 2554 | 2554 |
| 2555 EXPECT_TRUE(service_->pending_extension_manager()->IsIdPending(theme_crx)); | 2555 EXPECT_TRUE(service_->pending_extension_manager()->IsIdPending(theme_crx)); |
| (...skipping 1926 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4482 list[0] = sync_change; | 4482 list[0] = sync_change; |
| 4483 | 4483 |
| 4484 | 4484 |
| 4485 EXPECT_TRUE(service_->IsExtensionEnabled(good_crx)); | 4485 EXPECT_TRUE(service_->IsExtensionEnabled(good_crx)); |
| 4486 EXPECT_FALSE(service_->IsIncognitoEnabled(good_crx)); | 4486 EXPECT_FALSE(service_->IsIncognitoEnabled(good_crx)); |
| 4487 service_->ProcessSyncChanges(FROM_HERE, list); | 4487 service_->ProcessSyncChanges(FROM_HERE, list); |
| 4488 EXPECT_TRUE(service_->updater()->WillCheckSoon()); | 4488 EXPECT_TRUE(service_->updater()->WillCheckSoon()); |
| 4489 EXPECT_FALSE(service_->IsExtensionEnabled(good_crx)); | 4489 EXPECT_FALSE(service_->IsExtensionEnabled(good_crx)); |
| 4490 EXPECT_TRUE(service_->IsIncognitoEnabled(good_crx)); | 4490 EXPECT_TRUE(service_->IsIncognitoEnabled(good_crx)); |
| 4491 | 4491 |
| 4492 PendingExtensionInfo info; | 4492 const PendingExtensionInfo* info; |
| 4493 EXPECT_TRUE( | 4493 EXPECT_TRUE((info = service_->pending_extension_manager()-> |
| 4494 service_->pending_extension_manager()->GetById(good_crx, &info)); | 4494 GetById(good_crx))); |
| 4495 EXPECT_EQ(ext_specifics->update_url(), info.update_url().spec()); | 4495 EXPECT_EQ(ext_specifics->update_url(), info->update_url().spec()); |
| 4496 EXPECT_TRUE(info.is_from_sync()); | 4496 EXPECT_TRUE(info->is_from_sync()); |
| 4497 EXPECT_TRUE(info.install_silently()); | 4497 EXPECT_TRUE(info->install_silently()); |
| 4498 EXPECT_EQ(Extension::INTERNAL, info.install_source()); | 4498 EXPECT_EQ(Extension::INTERNAL, info->install_source()); |
| 4499 // TODO(akalin): Figure out a way to test |info.ShouldAllowInstall()|. | 4499 // TODO(akalin): Figure out a way to test |info.ShouldAllowInstall()|. |
| 4500 } | 4500 } |
| 4501 | 4501 |
| 4502 TEST_F(ExtensionServiceTest, InstallPriorityExternalUpdateUrl) { | 4502 TEST_F(ExtensionServiceTest, InstallPriorityExternalUpdateUrl) { |
| 4503 InitializeEmptyExtensionService(); | 4503 InitializeEmptyExtensionService(); |
| 4504 | 4504 |
| 4505 FilePath path = data_dir_.AppendASCII("good.crx"); | 4505 FilePath path = data_dir_.AppendASCII("good.crx"); |
| 4506 InstallCRX(path, INSTALL_NEW); | 4506 InstallCRX(path, INSTALL_NEW); |
| 4507 ValidatePrefKeyCount(1u); | 4507 ValidatePrefKeyCount(1u); |
| 4508 ValidateIntegerPref(good_crx, "state", Extension::ENABLED); | 4508 ValidateIntegerPref(good_crx, "state", Extension::ENABLED); |
| (...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4711 InitializeEmptyExtensionService(); | 4711 InitializeEmptyExtensionService(); |
| 4712 | 4712 |
| 4713 PendingExtensionManager* pending = service_->pending_extension_manager(); | 4713 PendingExtensionManager* pending = service_->pending_extension_manager(); |
| 4714 EXPECT_FALSE(pending->IsIdPending(kGoodId)); | 4714 EXPECT_FALSE(pending->IsIdPending(kGoodId)); |
| 4715 | 4715 |
| 4716 // An external provider starts installing from a local crx. | 4716 // An external provider starts installing from a local crx. |
| 4717 EXPECT_TRUE( | 4717 EXPECT_TRUE( |
| 4718 service_->OnExternalExtensionFileFound( | 4718 service_->OnExternalExtensionFileFound( |
| 4719 kGoodId, &kVersion123, kInvalidPathToCrx, | 4719 kGoodId, &kVersion123, kInvalidPathToCrx, |
| 4720 Extension::EXTERNAL_PREF, kCreationFlags, kDontMarkAcknowledged)); | 4720 Extension::EXTERNAL_PREF, kCreationFlags, kDontMarkAcknowledged)); |
| 4721 PendingExtensionInfo info; | 4721 const PendingExtensionInfo* info; |
| 4722 EXPECT_TRUE(pending->GetById(kGoodId, &info)); | 4722 EXPECT_TRUE((info = pending->GetById(kGoodId))); |
| 4723 EXPECT_TRUE(info.version().IsValid()); | 4723 EXPECT_TRUE(info->version().IsValid()); |
| 4724 EXPECT_TRUE(info.version().Equals(kVersion123)); | 4724 EXPECT_TRUE(info->version().Equals(kVersion123)); |
| 4725 | 4725 |
| 4726 // Adding a newer version overrides the currently pending version. | 4726 // Adding a newer version overrides the currently pending version. |
| 4727 EXPECT_TRUE( | 4727 EXPECT_TRUE( |
| 4728 service_->OnExternalExtensionFileFound( | 4728 service_->OnExternalExtensionFileFound( |
| 4729 kGoodId, &kVersion124, kInvalidPathToCrx, | 4729 kGoodId, &kVersion124, kInvalidPathToCrx, |
| 4730 Extension::EXTERNAL_PREF, kCreationFlags, kDontMarkAcknowledged)); | 4730 Extension::EXTERNAL_PREF, kCreationFlags, kDontMarkAcknowledged)); |
| 4731 EXPECT_TRUE(pending->GetById(kGoodId, &info)); | 4731 EXPECT_TRUE((info = pending->GetById(kGoodId))); |
| 4732 EXPECT_TRUE(info.version().IsValid()); | 4732 EXPECT_TRUE(info->version().IsValid()); |
| 4733 EXPECT_TRUE(info.version().Equals(kVersion124)); | 4733 EXPECT_TRUE(info->version().Equals(kVersion124)); |
| 4734 | 4734 |
| 4735 // Adding an older version fails. | 4735 // Adding an older version fails. |
| 4736 EXPECT_FALSE( | 4736 EXPECT_FALSE( |
| 4737 service_->OnExternalExtensionFileFound( | 4737 service_->OnExternalExtensionFileFound( |
| 4738 kGoodId, &kVersion123, kInvalidPathToCrx, | 4738 kGoodId, &kVersion123, kInvalidPathToCrx, |
| 4739 Extension::EXTERNAL_PREF, kCreationFlags, kDontMarkAcknowledged)); | 4739 Extension::EXTERNAL_PREF, kCreationFlags, kDontMarkAcknowledged)); |
| 4740 EXPECT_TRUE(pending->GetById(kGoodId, &info)); | 4740 EXPECT_TRUE((info = pending->GetById(kGoodId))); |
| 4741 EXPECT_TRUE(info.version().IsValid()); | 4741 EXPECT_TRUE(info->version().IsValid()); |
| 4742 EXPECT_TRUE(info.version().Equals(kVersion124)); | 4742 EXPECT_TRUE(info->version().Equals(kVersion124)); |
| 4743 | 4743 |
| 4744 // Adding an older version fails even when coming from a higher-priority | 4744 // Adding an older version fails even when coming from a higher-priority |
| 4745 // location. | 4745 // location. |
| 4746 EXPECT_FALSE( | 4746 EXPECT_FALSE( |
| 4747 service_->OnExternalExtensionFileFound( | 4747 service_->OnExternalExtensionFileFound( |
| 4748 kGoodId, &kVersion123, kInvalidPathToCrx, | 4748 kGoodId, &kVersion123, kInvalidPathToCrx, |
| 4749 Extension::EXTERNAL_REGISTRY, kCreationFlags, kDontMarkAcknowledged)); | 4749 Extension::EXTERNAL_REGISTRY, kCreationFlags, kDontMarkAcknowledged)); |
| 4750 EXPECT_TRUE(pending->GetById(kGoodId, &info)); | 4750 EXPECT_TRUE((info = pending->GetById(kGoodId))); |
| 4751 EXPECT_TRUE(info.version().IsValid()); | 4751 EXPECT_TRUE(info->version().IsValid()); |
| 4752 EXPECT_TRUE(info.version().Equals(kVersion124)); | 4752 EXPECT_TRUE(info->version().Equals(kVersion124)); |
| 4753 | 4753 |
| 4754 // Adding the latest version from the webstore overrides a specific version. | 4754 // Adding the latest version from the webstore overrides a specific version. |
| 4755 GURL kUpdateUrl("http://example.com/update"); | 4755 GURL kUpdateUrl("http://example.com/update"); |
| 4756 EXPECT_TRUE( | 4756 EXPECT_TRUE( |
| 4757 service_->OnExternalExtensionUpdateUrlFound( | 4757 service_->OnExternalExtensionUpdateUrlFound( |
| 4758 kGoodId, kUpdateUrl, Extension::EXTERNAL_POLICY_DOWNLOAD)); | 4758 kGoodId, kUpdateUrl, Extension::EXTERNAL_POLICY_DOWNLOAD)); |
| 4759 EXPECT_TRUE(pending->GetById(kGoodId, &info)); | 4759 EXPECT_TRUE((info = pending->GetById(kGoodId))); |
| 4760 EXPECT_FALSE(info.version().IsValid()); | 4760 EXPECT_FALSE(info->version().IsValid()); |
| 4761 } | 4761 } |
| 4762 | 4762 |
| 4763 // This makes sure we can package and install CRX files that use whitelisted | 4763 // This makes sure we can package and install CRX files that use whitelisted |
| 4764 // permissions. | 4764 // permissions. |
| 4765 TEST_F(ExtensionServiceTest, InstallWhitelistedExtension) { | 4765 TEST_F(ExtensionServiceTest, InstallWhitelistedExtension) { |
| 4766 std::string test_id = "hdkklepkcpckhnpgjnmbdfhehckloojk"; | 4766 std::string test_id = "hdkklepkcpckhnpgjnmbdfhehckloojk"; |
| 4767 CommandLine::ForCurrentProcess()->AppendSwitchASCII( | 4767 CommandLine::ForCurrentProcess()->AppendSwitchASCII( |
| 4768 switches::kWhitelistedExtensionID, test_id); | 4768 switches::kWhitelistedExtensionID, test_id); |
| 4769 | 4769 |
| 4770 InitializeEmptyExtensionService(); | 4770 InitializeEmptyExtensionService(); |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4823 scoped_ptr<Version> version; | 4823 scoped_ptr<Version> version; |
| 4824 version.reset(Version::GetVersionFromString("1.0.0.0")); | 4824 version.reset(Version::GetVersionFromString("1.0.0.0")); |
| 4825 | 4825 |
| 4826 // Get path to the CRX with id |kGoodId|. | 4826 // Get path to the CRX with id |kGoodId|. |
| 4827 return service_->OnExternalExtensionUpdateUrlFound( | 4827 return service_->OnExternalExtensionUpdateUrlFound( |
| 4828 crx_id_, GURL(), Extension::EXTERNAL_POLICY_DOWNLOAD); | 4828 crx_id_, GURL(), Extension::EXTERNAL_POLICY_DOWNLOAD); |
| 4829 } | 4829 } |
| 4830 | 4830 |
| 4831 // Get the install source of a pending extension. | 4831 // Get the install source of a pending extension. |
| 4832 Extension::Location GetPendingLocation() { | 4832 Extension::Location GetPendingLocation() { |
| 4833 PendingExtensionInfo info; | 4833 const PendingExtensionInfo* info; |
| 4834 EXPECT_TRUE(service_->pending_extension_manager()->GetById(crx_id_, &info)); | 4834 EXPECT_TRUE((info = service_->pending_extension_manager()-> |
| 4835 return info.install_source(); | 4835 GetById(crx_id_))); |
| 4836 return info->install_source(); |
| 4836 } | 4837 } |
| 4837 | 4838 |
| 4838 // Is an extension pending from a sync request? | 4839 // Is an extension pending from a sync request? |
| 4839 bool GetPendingIsFromSync() { | 4840 bool GetPendingIsFromSync() { |
| 4840 PendingExtensionInfo info; | 4841 const PendingExtensionInfo* info; |
| 4841 EXPECT_TRUE(service_->pending_extension_manager()->GetById(crx_id_, &info)); | 4842 EXPECT_TRUE((info = service_->pending_extension_manager()-> |
| 4842 return info.is_from_sync(); | 4843 GetById(crx_id_))); |
| 4844 return info->is_from_sync(); |
| 4843 } | 4845 } |
| 4844 | 4846 |
| 4845 // Is the CRX id these tests use pending? | 4847 // Is the CRX id these tests use pending? |
| 4846 bool IsCrxPending() { | 4848 bool IsCrxPending() { |
| 4847 return service_->pending_extension_manager()->IsIdPending(crx_id_); | 4849 return service_->pending_extension_manager()->IsIdPending(crx_id_); |
| 4848 } | 4850 } |
| 4849 | 4851 |
| 4850 // Is an extension installed? | 4852 // Is an extension installed? |
| 4851 bool IsCrxInstalled() { | 4853 bool IsCrxInstalled() { |
| 4852 return (service_->GetExtensionById(crx_id_, true) != NULL); | 4854 return (service_->GetExtensionById(crx_id_, true) != NULL); |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4963 provider->UpdateOrAddExtension(hosted_app, "1.0.0.0", | 4965 provider->UpdateOrAddExtension(hosted_app, "1.0.0.0", |
| 4964 data_dir_.AppendASCII("hosted_app.crx")); | 4966 data_dir_.AppendASCII("hosted_app.crx")); |
| 4965 | 4967 |
| 4966 service_->CheckForExternalUpdates(); | 4968 service_->CheckForExternalUpdates(); |
| 4967 loop_.RunAllPending(); | 4969 loop_.RunAllPending(); |
| 4968 | 4970 |
| 4969 ASSERT_TRUE(service_->PopulateExtensionGlobalError( | 4971 ASSERT_TRUE(service_->PopulateExtensionGlobalError( |
| 4970 extension_global_error.get())); | 4972 extension_global_error.get())); |
| 4971 ASSERT_EQ(1u, extension_global_error->get_external_extension_ids()->size()); | 4973 ASSERT_EQ(1u, extension_global_error->get_external_extension_ids()->size()); |
| 4972 } | 4974 } |
| OLD | NEW |