| 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 221 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 232 | 232 |
| 233 } // namespace | 233 } // namespace |
| 234 | 234 |
| 235 // Base class for further specialized test classes. | 235 // Base class for further specialized test classes. |
| 236 class MockService : public TestExtensionService { | 236 class MockService : public TestExtensionService { |
| 237 public: | 237 public: |
| 238 explicit MockService(TestExtensionPrefs* prefs) | 238 explicit MockService(TestExtensionPrefs* prefs) |
| 239 : prefs_(prefs), | 239 : prefs_(prefs), |
| 240 pending_extension_manager_(*this), | 240 pending_extension_manager_(*this), |
| 241 blacklist_(prefs_->prefs()) { | 241 blacklist_(prefs_->prefs()) { |
| 242 profile_.CreateRequestContext(); | |
| 243 } | 242 } |
| 244 | 243 |
| 245 virtual ~MockService() {} | 244 virtual ~MockService() {} |
| 246 | 245 |
| 247 virtual PendingExtensionManager* pending_extension_manager() OVERRIDE { | 246 virtual PendingExtensionManager* pending_extension_manager() OVERRIDE { |
| 248 ADD_FAILURE() << "Subclass should override this if it will " | 247 ADD_FAILURE() << "Subclass should override this if it will " |
| 249 << "be accessed by a test."; | 248 << "be accessed by a test."; |
| 250 return &pending_extension_manager_; | 249 return &pending_extension_manager_; |
| 251 } | 250 } |
| 252 | 251 |
| (...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 491 std::string decoded = net::UnescapeURLComponent( | 490 std::string decoded = net::UnescapeURLComponent( |
| 492 params["x"], net::UnescapeRule::URL_SPECIAL_CHARS); | 491 params["x"], net::UnescapeRule::URL_SPECIAL_CHARS); |
| 493 ExtractParameters(decoded, result); | 492 ExtractParameters(decoded, result); |
| 494 } | 493 } |
| 495 | 494 |
| 496 // All of our tests that need to use private APIs of ExtensionUpdater live | 495 // All of our tests that need to use private APIs of ExtensionUpdater live |
| 497 // inside this class (which is a friend to ExtensionUpdater). | 496 // inside this class (which is a friend to ExtensionUpdater). |
| 498 class ExtensionUpdaterTest : public testing::Test { | 497 class ExtensionUpdaterTest : public testing::Test { |
| 499 public: | 498 public: |
| 500 ExtensionUpdaterTest() | 499 ExtensionUpdaterTest() |
| 501 : test_browser_thread_bundle_( | 500 : thread_bundle_( |
| 502 content::TestBrowserThreadBundle::IO_MAINLOOP) { | 501 content::TestBrowserThreadBundle::IO_MAINLOOP) { |
| 503 } | 502 } |
| 504 | 503 |
| 505 virtual ~ExtensionUpdaterTest() { | |
| 506 } | |
| 507 | |
| 508 virtual void SetUp() OVERRIDE { | 504 virtual void SetUp() OVERRIDE { |
| 509 prefs_.reset(new TestExtensionPrefs(base::MessageLoopProxy::current())); | 505 prefs_.reset(new TestExtensionPrefs(base::MessageLoopProxy::current())); |
| 510 content::RenderProcessHost::SetRunRendererInProcess(true); | 506 content::RenderProcessHost::SetRunRendererInProcess(true); |
| 511 } | 507 } |
| 512 | 508 |
| 513 virtual void TearDown() OVERRIDE { | 509 virtual void TearDown() OVERRIDE { |
| 514 // Some tests create URLRequestContextGetters, whose destruction must run | 510 // Some tests create URLRequestContextGetters, whose destruction must run |
| 515 // on the IO thread. Make sure the IO loop spins before shutdown so that | 511 // on the IO thread. Make sure the IO loop spins before shutdown so that |
| 516 // those objects are released. | 512 // those objects are released. |
| 517 RunUntilIdle(); | 513 RunUntilIdle(); |
| (...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 744 kEmptyUpdateUrlData, install_source); | 740 kEmptyUpdateUrlData, install_source); |
| 745 std::map<std::string, std::string> params; | 741 std::map<std::string, std::string> params; |
| 746 VerifyQueryAndExtractParameters(fetch_data.full_url().query(), ¶ms); | 742 VerifyQueryAndExtractParameters(fetch_data.full_url().query(), ¶ms); |
| 747 EXPECT_EQ(id, params["id"]); | 743 EXPECT_EQ(id, params["id"]); |
| 748 EXPECT_EQ(version, params["v"]); | 744 EXPECT_EQ(version, params["v"]); |
| 749 EXPECT_EQ(install_source, params["installsource"]); | 745 EXPECT_EQ(install_source, params["installsource"]); |
| 750 } | 746 } |
| 751 | 747 |
| 752 void TestDetermineUpdates() { | 748 void TestDetermineUpdates() { |
| 753 TestingProfile profile; | 749 TestingProfile profile; |
| 754 profile.CreateRequestContext(); | |
| 755 MockExtensionDownloaderDelegate delegate; | 750 MockExtensionDownloaderDelegate delegate; |
| 756 ExtensionDownloader downloader(&delegate, profile.GetRequestContext()); | 751 ExtensionDownloader downloader(&delegate, profile.GetRequestContext()); |
| 757 | 752 |
| 758 // Check passing an empty list of parse results to DetermineUpdates | 753 // Check passing an empty list of parse results to DetermineUpdates |
| 759 ManifestFetchData fetch_data(GURL("http://localhost/foo"), 0); | 754 ManifestFetchData fetch_data(GURL("http://localhost/foo"), 0); |
| 760 UpdateManifest::Results updates; | 755 UpdateManifest::Results updates; |
| 761 std::vector<int> updateable; | 756 std::vector<int> updateable; |
| 762 downloader.DetermineUpdates(fetch_data, updates, &updateable); | 757 downloader.DetermineUpdates(fetch_data, updates, &updateable); |
| 763 EXPECT_TRUE(updateable.empty()); | 758 EXPECT_TRUE(updateable.empty()); |
| 764 | 759 |
| (...skipping 23 matching lines...) Expand all Loading... |
| 788 } | 783 } |
| 789 | 784 |
| 790 void TestDetermineUpdatesPending() { | 785 void TestDetermineUpdatesPending() { |
| 791 // Create a set of test extensions | 786 // Create a set of test extensions |
| 792 ServiceForManifestTests service(prefs_.get()); | 787 ServiceForManifestTests service(prefs_.get()); |
| 793 PendingExtensionManager* pending_extension_manager = | 788 PendingExtensionManager* pending_extension_manager = |
| 794 service.pending_extension_manager(); | 789 service.pending_extension_manager(); |
| 795 SetupPendingExtensionManagerForTest(3, GURL(), pending_extension_manager); | 790 SetupPendingExtensionManagerForTest(3, GURL(), pending_extension_manager); |
| 796 | 791 |
| 797 TestingProfile profile; | 792 TestingProfile profile; |
| 798 profile.CreateRequestContext(); | |
| 799 MockExtensionDownloaderDelegate delegate; | 793 MockExtensionDownloaderDelegate delegate; |
| 800 ExtensionDownloader downloader(&delegate, profile.GetRequestContext()); | 794 ExtensionDownloader downloader(&delegate, profile.GetRequestContext()); |
| 801 | 795 |
| 802 ManifestFetchData fetch_data(GURL("http://localhost/foo"), 0); | 796 ManifestFetchData fetch_data(GURL("http://localhost/foo"), 0); |
| 803 UpdateManifest::Results updates; | 797 UpdateManifest::Results updates; |
| 804 | 798 |
| 805 std::list<std::string> ids_for_update_check; | 799 std::list<std::string> ids_for_update_check; |
| 806 pending_extension_manager->GetPendingIdsForUpdateCheck( | 800 pending_extension_manager->GetPendingIdsForUpdateCheck( |
| 807 &ids_for_update_check); | 801 &ids_for_update_check); |
| 808 | 802 |
| (...skipping 686 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1495 service.extension_prefs()->LastPingDay(extension->id()); | 1489 service.extension_prefs()->LastPingDay(extension->id()); |
| 1496 EXPECT_FALSE(last_ping_day.is_null()); | 1490 EXPECT_FALSE(last_ping_day.is_null()); |
| 1497 int64 seconds_diff = (Time::Now() - last_ping_day).InSeconds(); | 1491 int64 seconds_diff = (Time::Now() - last_ping_day).InSeconds(); |
| 1498 EXPECT_LT(seconds_diff - results.daystart_elapsed_seconds, 5); | 1492 EXPECT_LT(seconds_diff - results.daystart_elapsed_seconds, 5); |
| 1499 } | 1493 } |
| 1500 | 1494 |
| 1501 protected: | 1495 protected: |
| 1502 scoped_ptr<TestExtensionPrefs> prefs_; | 1496 scoped_ptr<TestExtensionPrefs> prefs_; |
| 1503 | 1497 |
| 1504 private: | 1498 private: |
| 1505 content::TestBrowserThreadBundle test_browser_thread_bundle_; | 1499 content::TestBrowserThreadBundle thread_bundle_; |
| 1506 | 1500 |
| 1507 #if defined OS_CHROMEOS | 1501 #if defined OS_CHROMEOS |
| 1508 chromeos::ScopedTestDeviceSettingsService test_device_settings_service_; | 1502 chromeos::ScopedTestDeviceSettingsService test_device_settings_service_; |
| 1509 chromeos::ScopedTestCrosSettings test_cros_settings_; | 1503 chromeos::ScopedTestCrosSettings test_cros_settings_; |
| 1510 chromeos::ScopedTestUserManager test_user_manager_; | 1504 chromeos::ScopedTestUserManager test_user_manager_; |
| 1511 #endif | 1505 #endif |
| 1512 }; | 1506 }; |
| 1513 | 1507 |
| 1514 // Because we test some private methods of ExtensionUpdater, it's easier for the | 1508 // Because we test some private methods of ExtensionUpdater, it's easier for the |
| 1515 // actual test code to live in ExtenionUpdaterTest methods instead of TEST_F | 1509 // actual test code to live in ExtenionUpdaterTest methods instead of TEST_F |
| (...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1759 // -prodversionmin (shouldn't update if browser version too old) | 1753 // -prodversionmin (shouldn't update if browser version too old) |
| 1760 // -manifests & updates arriving out of order / interleaved | 1754 // -manifests & updates arriving out of order / interleaved |
| 1761 // -malformed update url (empty, file://, has query, has a # fragment, etc.) | 1755 // -malformed update url (empty, file://, has query, has a # fragment, etc.) |
| 1762 // -An extension gets uninstalled while updates are in progress (so it doesn't | 1756 // -An extension gets uninstalled while updates are in progress (so it doesn't |
| 1763 // "come back from the dead") | 1757 // "come back from the dead") |
| 1764 // -An extension gets manually updated to v3 while we're downloading v2 (ie | 1758 // -An extension gets manually updated to v3 while we're downloading v2 (ie |
| 1765 // you don't get downgraded accidentally) | 1759 // you don't get downgraded accidentally) |
| 1766 // -An update manifest mentions multiple updates | 1760 // -An update manifest mentions multiple updates |
| 1767 | 1761 |
| 1768 } // namespace extensions | 1762 } // namespace extensions |
| OLD | NEW |