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 <list> | 5 #include <list> |
6 #include <map> | 6 #include <map> |
7 #include <set> | 7 #include <set> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
47 #include "chrome/common/extensions/manifest_url_handler.h" | 47 #include "chrome/common/extensions/manifest_url_handler.h" |
48 #include "chrome/common/omaha_query_params.h" | 48 #include "chrome/common/omaha_query_params.h" |
49 #include "chrome/common/pref_names.h" | 49 #include "chrome/common/pref_names.h" |
50 #include "chrome/test/base/testing_profile.h" | 50 #include "chrome/test/base/testing_profile.h" |
51 #include "content/public/browser/notification_details.h" | 51 #include "content/public/browser/notification_details.h" |
52 #include "content/public/browser/notification_observer.h" | 52 #include "content/public/browser/notification_observer.h" |
53 #include "content/public/browser/notification_registrar.h" | 53 #include "content/public/browser/notification_registrar.h" |
54 #include "content/public/browser/notification_service.h" | 54 #include "content/public/browser/notification_service.h" |
55 #include "content/public/browser/notification_source.h" | 55 #include "content/public/browser/notification_source.h" |
56 #include "content/public/test/test_browser_thread.h" | 56 #include "content/public/test/test_browser_thread.h" |
| 57 #include "extensions/common/id_util.h" |
57 #include "libxml/globals.h" | 58 #include "libxml/globals.h" |
58 #include "net/base/backoff_entry.h" | 59 #include "net/base/backoff_entry.h" |
59 #include "net/base/escape.h" | 60 #include "net/base/escape.h" |
60 #include "net/base/load_flags.h" | 61 #include "net/base/load_flags.h" |
61 #include "net/url_request/test_url_fetcher_factory.h" | 62 #include "net/url_request/test_url_fetcher_factory.h" |
62 #include "net/url_request/url_request_status.h" | 63 #include "net/url_request/url_request_status.h" |
63 #include "testing/gmock/include/gmock/gmock.h" | 64 #include "testing/gmock/include/gmock/gmock.h" |
64 #include "testing/gtest/include/gtest/gtest.h" | 65 #include "testing/gtest/include/gtest/gtest.h" |
65 | 66 |
66 using base::Time; | 67 using base::Time; |
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
256 TestExtensionPrefs* const prefs_; | 257 TestExtensionPrefs* const prefs_; |
257 PendingExtensionManager pending_extension_manager_; | 258 PendingExtensionManager pending_extension_manager_; |
258 TestingProfile profile_; | 259 TestingProfile profile_; |
259 Blacklist blacklist_; | 260 Blacklist blacklist_; |
260 | 261 |
261 private: | 262 private: |
262 DISALLOW_COPY_AND_ASSIGN(MockService); | 263 DISALLOW_COPY_AND_ASSIGN(MockService); |
263 }; | 264 }; |
264 | 265 |
265 | 266 |
266 std::string GenerateId(std::string input) { | |
267 std::string result; | |
268 EXPECT_TRUE(Extension::GenerateId(input, &result)); | |
269 return result; | |
270 } | |
271 | |
272 bool ShouldInstallExtensionsOnly(const Extension& extension) { | 267 bool ShouldInstallExtensionsOnly(const Extension& extension) { |
273 return extension.GetType() == Manifest::TYPE_EXTENSION; | 268 return extension.GetType() == Manifest::TYPE_EXTENSION; |
274 } | 269 } |
275 | 270 |
276 bool ShouldInstallThemesOnly(const Extension& extension) { | 271 bool ShouldInstallThemesOnly(const Extension& extension) { |
277 return extension.is_theme(); | 272 return extension.is_theme(); |
278 } | 273 } |
279 | 274 |
280 bool ShouldAlwaysInstall(const Extension& extension) { | 275 bool ShouldAlwaysInstall(const Extension& extension) { |
281 return true; | 276 return true; |
282 } | 277 } |
283 | 278 |
284 // Loads some pending extension records into a pending extension manager. | 279 // Loads some pending extension records into a pending extension manager. |
285 void SetupPendingExtensionManagerForTest( | 280 void SetupPendingExtensionManagerForTest( |
286 int count, | 281 int count, |
287 const GURL& update_url, | 282 const GURL& update_url, |
288 PendingExtensionManager* pending_extension_manager) { | 283 PendingExtensionManager* pending_extension_manager) { |
289 for (int i = 1; i <= count; ++i) { | 284 for (int i = 1; i <= count; ++i) { |
290 PendingExtensionInfo::ShouldAllowInstallPredicate should_allow_install = | 285 PendingExtensionInfo::ShouldAllowInstallPredicate should_allow_install = |
291 (i % 2 == 0) ? &ShouldInstallThemesOnly : &ShouldInstallExtensionsOnly; | 286 (i % 2 == 0) ? &ShouldInstallThemesOnly : &ShouldInstallExtensionsOnly; |
292 const bool kIsFromSync = true; | 287 const bool kIsFromSync = true; |
293 const bool kInstallSilently = true; | 288 const bool kInstallSilently = true; |
294 std::string id = GenerateId(base::StringPrintf("extension%i", i)); | 289 std::string id = id_util::GenerateId(base::StringPrintf("extension%i", i)); |
295 | 290 |
296 pending_extension_manager->AddForTesting( | 291 pending_extension_manager->AddForTesting( |
297 PendingExtensionInfo(id, | 292 PendingExtensionInfo(id, |
298 update_url, | 293 update_url, |
299 Version(), | 294 Version(), |
300 should_allow_install, | 295 should_allow_install, |
301 kIsFromSync, | 296 kIsFromSync, |
302 kInstallSilently, | 297 kInstallSilently, |
303 Manifest::INTERNAL)); | 298 Manifest::INTERNAL)); |
304 } | 299 } |
(...skipping 429 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
734 // Check passing an empty list of parse results to DetermineUpdates | 729 // Check passing an empty list of parse results to DetermineUpdates |
735 ManifestFetchData fetch_data(GURL("http://localhost/foo"), 0); | 730 ManifestFetchData fetch_data(GURL("http://localhost/foo"), 0); |
736 UpdateManifest::Results updates; | 731 UpdateManifest::Results updates; |
737 std::vector<int> updateable; | 732 std::vector<int> updateable; |
738 downloader.DetermineUpdates(fetch_data, updates, &updateable); | 733 downloader.DetermineUpdates(fetch_data, updates, &updateable); |
739 EXPECT_TRUE(updateable.empty()); | 734 EXPECT_TRUE(updateable.empty()); |
740 | 735 |
741 // Create two updates - expect that DetermineUpdates will return the first | 736 // Create two updates - expect that DetermineUpdates will return the first |
742 // one (v1.0 installed, v1.1 available) but not the second one (both | 737 // one (v1.0 installed, v1.1 available) but not the second one (both |
743 // installed and available at v2.0). | 738 // installed and available at v2.0). |
744 const std::string id1 = GenerateId("1"); | 739 const std::string id1 = id_util::GenerateId("1"); |
745 const std::string id2 = GenerateId("2"); | 740 const std::string id2 = id_util::GenerateId("2"); |
746 fetch_data.AddExtension(id1, "1.0.0.0", | 741 fetch_data.AddExtension(id1, "1.0.0.0", |
747 &kNeverPingedData, kEmptyUpdateUrlData, ""); | 742 &kNeverPingedData, kEmptyUpdateUrlData, ""); |
748 AddParseResult(id1, "1.1", | 743 AddParseResult(id1, "1.1", |
749 "http://localhost/e1_1.1.crx", &updates); | 744 "http://localhost/e1_1.1.crx", &updates); |
750 fetch_data.AddExtension(id2, "2.0.0.0", | 745 fetch_data.AddExtension(id2, "2.0.0.0", |
751 &kNeverPingedData, kEmptyUpdateUrlData, ""); | 746 &kNeverPingedData, kEmptyUpdateUrlData, ""); |
752 AddParseResult(id2, "2.0.0.0", | 747 AddParseResult(id2, "2.0.0.0", |
753 "http://localhost/e2_2.0.crx", &updates); | 748 "http://localhost/e2_2.0.crx", &updates); |
754 | 749 |
755 EXPECT_CALL(delegate, IsExtensionPending(_)).WillRepeatedly(Return(false)); | 750 EXPECT_CALL(delegate, IsExtensionPending(_)).WillRepeatedly(Return(false)); |
(...skipping 872 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1628 TEST_F(ExtensionUpdaterTest, TestManifestFetchesBuilderAddExtension) { | 1623 TEST_F(ExtensionUpdaterTest, TestManifestFetchesBuilderAddExtension) { |
1629 net::TestURLFetcherFactory factory; | 1624 net::TestURLFetcherFactory factory; |
1630 MockService service(prefs_.get()); | 1625 MockService service(prefs_.get()); |
1631 MockExtensionDownloaderDelegate delegate; | 1626 MockExtensionDownloaderDelegate delegate; |
1632 scoped_ptr<ExtensionDownloader> downloader( | 1627 scoped_ptr<ExtensionDownloader> downloader( |
1633 new ExtensionDownloader(&delegate, service.request_context())); | 1628 new ExtensionDownloader(&delegate, service.request_context())); |
1634 EXPECT_EQ(0u, ManifestFetchersCount(downloader.get())); | 1629 EXPECT_EQ(0u, ManifestFetchersCount(downloader.get())); |
1635 | 1630 |
1636 // First, verify that adding valid extensions does invoke the callbacks on | 1631 // First, verify that adding valid extensions does invoke the callbacks on |
1637 // the delegate. | 1632 // the delegate. |
1638 std::string id = GenerateId("foo"); | 1633 std::string id = id_util::GenerateId("foo"); |
1639 EXPECT_CALL(delegate, GetPingDataForExtension(id, _)).WillOnce(Return(false)); | 1634 EXPECT_CALL(delegate, GetPingDataForExtension(id, _)).WillOnce(Return(false)); |
1640 EXPECT_TRUE( | 1635 EXPECT_TRUE( |
1641 downloader->AddPendingExtension(id, GURL("http://example.com/update"), | 1636 downloader->AddPendingExtension(id, GURL("http://example.com/update"), |
1642 0)); | 1637 0)); |
1643 downloader->StartAllPending(); | 1638 downloader->StartAllPending(); |
1644 Mock::VerifyAndClearExpectations(&delegate); | 1639 Mock::VerifyAndClearExpectations(&delegate); |
1645 EXPECT_EQ(1u, ManifestFetchersCount(downloader.get())); | 1640 EXPECT_EQ(1u, ManifestFetchersCount(downloader.get())); |
1646 | 1641 |
1647 // Extensions with invalid update URLs should be rejected. | 1642 // Extensions with invalid update URLs should be rejected. |
1648 id = GenerateId("foo2"); | 1643 id = id_util::GenerateId("foo2"); |
1649 EXPECT_FALSE( | 1644 EXPECT_FALSE( |
1650 downloader->AddPendingExtension(id, GURL("http:google.com:foo"), 0)); | 1645 downloader->AddPendingExtension(id, GURL("http:google.com:foo"), 0)); |
1651 downloader->StartAllPending(); | 1646 downloader->StartAllPending(); |
1652 EXPECT_EQ(1u, ManifestFetchersCount(downloader.get())); | 1647 EXPECT_EQ(1u, ManifestFetchersCount(downloader.get())); |
1653 | 1648 |
1654 // Extensions with empty IDs should be rejected. | 1649 // Extensions with empty IDs should be rejected. |
1655 EXPECT_FALSE(downloader->AddPendingExtension("", GURL(), 0)); | 1650 EXPECT_FALSE(downloader->AddPendingExtension("", GURL(), 0)); |
1656 downloader->StartAllPending(); | 1651 downloader->StartAllPending(); |
1657 EXPECT_EQ(1u, ManifestFetchersCount(downloader.get())); | 1652 EXPECT_EQ(1u, ManifestFetchersCount(downloader.get())); |
1658 | 1653 |
1659 // TODO(akalin): Test that extensions with empty update URLs | 1654 // TODO(akalin): Test that extensions with empty update URLs |
1660 // converted from user scripts are rejected. | 1655 // converted from user scripts are rejected. |
1661 | 1656 |
1662 // Reset the ExtensionDownloader so that it drops the current fetcher. | 1657 // Reset the ExtensionDownloader so that it drops the current fetcher. |
1663 downloader.reset( | 1658 downloader.reset( |
1664 new ExtensionDownloader(&delegate, service.request_context())); | 1659 new ExtensionDownloader(&delegate, service.request_context())); |
1665 EXPECT_EQ(0u, ManifestFetchersCount(downloader.get())); | 1660 EXPECT_EQ(0u, ManifestFetchersCount(downloader.get())); |
1666 | 1661 |
1667 // Extensions with empty update URLs should have a default one | 1662 // Extensions with empty update URLs should have a default one |
1668 // filled in. | 1663 // filled in. |
1669 id = GenerateId("foo3"); | 1664 id = id_util::GenerateId("foo3"); |
1670 EXPECT_CALL(delegate, GetPingDataForExtension(id, _)).WillOnce(Return(false)); | 1665 EXPECT_CALL(delegate, GetPingDataForExtension(id, _)).WillOnce(Return(false)); |
1671 EXPECT_TRUE(downloader->AddPendingExtension(id, GURL(), 0)); | 1666 EXPECT_TRUE(downloader->AddPendingExtension(id, GURL(), 0)); |
1672 downloader->StartAllPending(); | 1667 downloader->StartAllPending(); |
1673 EXPECT_EQ(1u, ManifestFetchersCount(downloader.get())); | 1668 EXPECT_EQ(1u, ManifestFetchersCount(downloader.get())); |
1674 | 1669 |
1675 net::TestURLFetcher* fetcher = | 1670 net::TestURLFetcher* fetcher = |
1676 factory.GetFetcherByID(ExtensionDownloader::kManifestFetcherId); | 1671 factory.GetFetcherByID(ExtensionDownloader::kManifestFetcherId); |
1677 ASSERT_TRUE(fetcher); | 1672 ASSERT_TRUE(fetcher); |
1678 EXPECT_FALSE(fetcher->GetOriginalURL().is_empty()); | 1673 EXPECT_FALSE(fetcher->GetOriginalURL().is_empty()); |
1679 } | 1674 } |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1718 // -prodversionmin (shouldn't update if browser version too old) | 1713 // -prodversionmin (shouldn't update if browser version too old) |
1719 // -manifests & updates arriving out of order / interleaved | 1714 // -manifests & updates arriving out of order / interleaved |
1720 // -malformed update url (empty, file://, has query, has a # fragment, etc.) | 1715 // -malformed update url (empty, file://, has query, has a # fragment, etc.) |
1721 // -An extension gets uninstalled while updates are in progress (so it doesn't | 1716 // -An extension gets uninstalled while updates are in progress (so it doesn't |
1722 // "come back from the dead") | 1717 // "come back from the dead") |
1723 // -An extension gets manually updated to v3 while we're downloading v2 (ie | 1718 // -An extension gets manually updated to v3 while we're downloading v2 (ie |
1724 // you don't get downgraded accidentally) | 1719 // you don't get downgraded accidentally) |
1725 // -An update manifest mentions multiple updates | 1720 // -An update manifest mentions multiple updates |
1726 | 1721 |
1727 } // namespace extensions | 1722 } // namespace extensions |
OLD | NEW |