| OLD | NEW |
| 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.h" | 5 #include "chrome/browser/extensions/extension_service.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 #include <map> | 10 #include <map> |
| (...skipping 2445 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2456 EXPECT_FALSE(service()->pending_extension_manager()->IsIdPending(kGoodId)); | 2456 EXPECT_FALSE(service()->pending_extension_manager()->IsIdPending(kGoodId)); |
| 2457 | 2457 |
| 2458 const Extension* extension = service()->GetExtensionById(kGoodId, true); | 2458 const Extension* extension = service()->GetExtensionById(kGoodId, true); |
| 2459 EXPECT_TRUE(extension); | 2459 EXPECT_TRUE(extension); |
| 2460 } | 2460 } |
| 2461 | 2461 |
| 2462 TEST_F(ExtensionServiceTest, UpdatePendingExtensionWrongVersion) { | 2462 TEST_F(ExtensionServiceTest, UpdatePendingExtensionWrongVersion) { |
| 2463 InitializeEmptyExtensionService(); | 2463 InitializeEmptyExtensionService(); |
| 2464 base::Version other_version("0.1"); | 2464 base::Version other_version("0.1"); |
| 2465 ASSERT_TRUE(other_version.IsValid()); | 2465 ASSERT_TRUE(other_version.IsValid()); |
| 2466 ASSERT_FALSE(other_version.Equals(base::Version(kGoodVersion))); | 2466 ASSERT_NE(other_version, base::Version(kGoodVersion)); |
| 2467 EXPECT_TRUE( | 2467 EXPECT_TRUE( |
| 2468 service()->pending_extension_manager()->AddFromSync( | 2468 service()->pending_extension_manager()->AddFromSync( |
| 2469 kGoodId, | 2469 kGoodId, |
| 2470 GURL(kGoodUpdateURL), | 2470 GURL(kGoodUpdateURL), |
| 2471 other_version, | 2471 other_version, |
| 2472 &IsExtension, | 2472 &IsExtension, |
| 2473 kGoodRemoteInstall, | 2473 kGoodRemoteInstall, |
| 2474 kGoodInstalledByCustodian)); | 2474 kGoodInstalledByCustodian)); |
| 2475 EXPECT_TRUE(service()->pending_extension_manager()->IsIdPending(kGoodId)); | 2475 EXPECT_TRUE(service()->pending_extension_manager()->IsIdPending(kGoodId)); |
| 2476 | 2476 |
| (...skipping 3003 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5480 const Extension* ext = InstallCRX(path, INSTALL_NEW); | 5480 const Extension* ext = InstallCRX(path, INSTALL_NEW); |
| 5481 ValidatePrefKeyCount(1u); | 5481 ValidatePrefKeyCount(1u); |
| 5482 ValidateIntegerPref(good_crx, "state", Extension::ENABLED); | 5482 ValidateIntegerPref(good_crx, "state", Extension::ENABLED); |
| 5483 ValidateIntegerPref(good_crx, "location", Manifest::INTERNAL); | 5483 ValidateIntegerPref(good_crx, "location", Manifest::INTERNAL); |
| 5484 | 5484 |
| 5485 // Now test the logic of OnExternalExtensionFileFound() when the extension | 5485 // Now test the logic of OnExternalExtensionFileFound() when the extension |
| 5486 // being added is already installed. | 5486 // being added is already installed. |
| 5487 | 5487 |
| 5488 // Tests assume |older_version| is less than the installed version, and | 5488 // Tests assume |older_version| is less than the installed version, and |
| 5489 // |newer_version| is greater. Verify this: | 5489 // |newer_version| is greater. Verify this: |
| 5490 ASSERT_TRUE(older_version.IsOlderThan(ext->VersionString())); | 5490 ASSERT_LT(older_version, *ext->version()); |
| 5491 ASSERT_TRUE(ext->version()->IsOlderThan(newer_version.GetString())); | 5491 ASSERT_GT(newer_version, *ext->version()); |
| 5492 | 5492 |
| 5493 // An external install for the same location should fail if the version is | 5493 // An external install for the same location should fail if the version is |
| 5494 // older, or the same, and succeed if the version is newer. | 5494 // older, or the same, and succeed if the version is newer. |
| 5495 | 5495 |
| 5496 // Older than the installed version... | 5496 // Older than the installed version... |
| 5497 EXPECT_FALSE(service()->OnExternalExtensionFileFound( | 5497 EXPECT_FALSE(service()->OnExternalExtensionFileFound( |
| 5498 kGoodId, | 5498 kGoodId, |
| 5499 &older_version, | 5499 &older_version, |
| 5500 kInvalidPathToCrx, | 5500 kInvalidPathToCrx, |
| 5501 Manifest::INTERNAL, | 5501 Manifest::INTERNAL, |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5594 kGoodId, | 5594 kGoodId, |
| 5595 &kVersion123, | 5595 &kVersion123, |
| 5596 kInvalidPathToCrx, | 5596 kInvalidPathToCrx, |
| 5597 Manifest::EXTERNAL_PREF, | 5597 Manifest::EXTERNAL_PREF, |
| 5598 kCreationFlags, | 5598 kCreationFlags, |
| 5599 kDontMarkAcknowledged, | 5599 kDontMarkAcknowledged, |
| 5600 kDontInstallImmediately)); | 5600 kDontInstallImmediately)); |
| 5601 const extensions::PendingExtensionInfo* info; | 5601 const extensions::PendingExtensionInfo* info; |
| 5602 EXPECT_TRUE((info = pending->GetById(kGoodId))); | 5602 EXPECT_TRUE((info = pending->GetById(kGoodId))); |
| 5603 EXPECT_TRUE(info->version().IsValid()); | 5603 EXPECT_TRUE(info->version().IsValid()); |
| 5604 EXPECT_TRUE(info->version().Equals(kVersion123)); | 5604 EXPECT_EQ(info->version(), kVersion123); |
| 5605 | 5605 |
| 5606 // Adding a newer version overrides the currently pending version. | 5606 // Adding a newer version overrides the currently pending version. |
| 5607 EXPECT_TRUE(service()->OnExternalExtensionFileFound( | 5607 EXPECT_TRUE(service()->OnExternalExtensionFileFound( |
| 5608 kGoodId, | 5608 kGoodId, |
| 5609 &kVersion124, | 5609 &kVersion124, |
| 5610 kInvalidPathToCrx, | 5610 kInvalidPathToCrx, |
| 5611 Manifest::EXTERNAL_PREF, | 5611 Manifest::EXTERNAL_PREF, |
| 5612 kCreationFlags, | 5612 kCreationFlags, |
| 5613 kDontMarkAcknowledged, | 5613 kDontMarkAcknowledged, |
| 5614 kDontInstallImmediately)); | 5614 kDontInstallImmediately)); |
| 5615 EXPECT_TRUE((info = pending->GetById(kGoodId))); | 5615 EXPECT_TRUE((info = pending->GetById(kGoodId))); |
| 5616 EXPECT_TRUE(info->version().IsValid()); | 5616 EXPECT_TRUE(info->version().IsValid()); |
| 5617 EXPECT_TRUE(info->version().Equals(kVersion124)); | 5617 EXPECT_EQ(info->version(), kVersion124); |
| 5618 | 5618 |
| 5619 // Adding an older version fails. | 5619 // Adding an older version fails. |
| 5620 EXPECT_FALSE(service()->OnExternalExtensionFileFound( | 5620 EXPECT_FALSE(service()->OnExternalExtensionFileFound( |
| 5621 kGoodId, | 5621 kGoodId, |
| 5622 &kVersion123, | 5622 &kVersion123, |
| 5623 kInvalidPathToCrx, | 5623 kInvalidPathToCrx, |
| 5624 Manifest::EXTERNAL_PREF, | 5624 Manifest::EXTERNAL_PREF, |
| 5625 kCreationFlags, | 5625 kCreationFlags, |
| 5626 kDontMarkAcknowledged, | 5626 kDontMarkAcknowledged, |
| 5627 kDontInstallImmediately)); | 5627 kDontInstallImmediately)); |
| 5628 EXPECT_TRUE((info = pending->GetById(kGoodId))); | 5628 EXPECT_TRUE((info = pending->GetById(kGoodId))); |
| 5629 EXPECT_TRUE(info->version().IsValid()); | 5629 EXPECT_TRUE(info->version().IsValid()); |
| 5630 EXPECT_TRUE(info->version().Equals(kVersion124)); | 5630 EXPECT_EQ(info->version(), kVersion124); |
| 5631 | 5631 |
| 5632 // Adding an older version fails even when coming from a higher-priority | 5632 // Adding an older version fails even when coming from a higher-priority |
| 5633 // location. | 5633 // location. |
| 5634 EXPECT_FALSE(service()->OnExternalExtensionFileFound( | 5634 EXPECT_FALSE(service()->OnExternalExtensionFileFound( |
| 5635 kGoodId, | 5635 kGoodId, |
| 5636 &kVersion123, | 5636 &kVersion123, |
| 5637 kInvalidPathToCrx, | 5637 kInvalidPathToCrx, |
| 5638 Manifest::EXTERNAL_REGISTRY, | 5638 Manifest::EXTERNAL_REGISTRY, |
| 5639 kCreationFlags, | 5639 kCreationFlags, |
| 5640 kDontMarkAcknowledged, | 5640 kDontMarkAcknowledged, |
| 5641 kDontInstallImmediately)); | 5641 kDontInstallImmediately)); |
| 5642 EXPECT_TRUE((info = pending->GetById(kGoodId))); | 5642 EXPECT_TRUE((info = pending->GetById(kGoodId))); |
| 5643 EXPECT_TRUE(info->version().IsValid()); | 5643 EXPECT_TRUE(info->version().IsValid()); |
| 5644 EXPECT_TRUE(info->version().Equals(kVersion124)); | 5644 EXPECT_EQ(info->version(), kVersion124); |
| 5645 | 5645 |
| 5646 // Adding the latest version from the webstore overrides a specific version. | 5646 // Adding the latest version from the webstore overrides a specific version. |
| 5647 GURL kUpdateUrl("http://example.com/update"); | 5647 GURL kUpdateUrl("http://example.com/update"); |
| 5648 EXPECT_TRUE(service()->OnExternalExtensionUpdateUrlFound( | 5648 EXPECT_TRUE(service()->OnExternalExtensionUpdateUrlFound( |
| 5649 kGoodId, | 5649 kGoodId, |
| 5650 std::string(), | 5650 std::string(), |
| 5651 kUpdateUrl, | 5651 kUpdateUrl, |
| 5652 Manifest::EXTERNAL_POLICY_DOWNLOAD, | 5652 Manifest::EXTERNAL_POLICY_DOWNLOAD, |
| 5653 Extension::NO_FLAGS, | 5653 Extension::NO_FLAGS, |
| 5654 false)); | 5654 false)); |
| (...skipping 607 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6262 | 6262 |
| 6263 service()->Observe(chrome::NOTIFICATION_PROFILE_DESTRUCTION_STARTED, | 6263 service()->Observe(chrome::NOTIFICATION_PROFILE_DESTRUCTION_STARTED, |
| 6264 content::Source<Profile>(profile()), | 6264 content::Source<Profile>(profile()), |
| 6265 content::NotificationService::NoDetails()); | 6265 content::NotificationService::NoDetails()); |
| 6266 EXPECT_EQ(UnloadedExtensionInfo::REASON_PROFILE_SHUTDOWN, unloaded_reason_); | 6266 EXPECT_EQ(UnloadedExtensionInfo::REASON_PROFILE_SHUTDOWN, unloaded_reason_); |
| 6267 EXPECT_EQ(0u, registry()->enabled_extensions().size()); | 6267 EXPECT_EQ(0u, registry()->enabled_extensions().size()); |
| 6268 EXPECT_EQ(0u, registry()->disabled_extensions().size()); | 6268 EXPECT_EQ(0u, registry()->disabled_extensions().size()); |
| 6269 EXPECT_EQ(0u, registry()->terminated_extensions().size()); | 6269 EXPECT_EQ(0u, registry()->terminated_extensions().size()); |
| 6270 EXPECT_EQ(0u, registry()->blacklisted_extensions().size()); | 6270 EXPECT_EQ(0u, registry()->blacklisted_extensions().size()); |
| 6271 } | 6271 } |
| OLD | NEW |