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 12 matching lines...) Expand all Loading... |
23 #include "base/strings/stringprintf.h" | 23 #include "base/strings/stringprintf.h" |
24 #include "base/threading/thread.h" | 24 #include "base/threading/thread.h" |
25 #include "base/version.h" | 25 #include "base/version.h" |
26 #include "chrome/browser/chrome_notification_types.h" | 26 #include "chrome/browser/chrome_notification_types.h" |
27 #include "chrome/browser/extensions/crx_installer.h" | 27 #include "chrome/browser/extensions/crx_installer.h" |
28 #include "chrome/browser/extensions/extension_error_reporter.h" | 28 #include "chrome/browser/extensions/extension_error_reporter.h" |
29 #include "chrome/browser/extensions/extension_sync_data.h" | 29 #include "chrome/browser/extensions/extension_sync_data.h" |
30 #include "chrome/browser/extensions/test_extension_prefs.h" | 30 #include "chrome/browser/extensions/test_extension_prefs.h" |
31 #include "chrome/browser/extensions/test_extension_service.h" | 31 #include "chrome/browser/extensions/test_extension_service.h" |
32 #include "chrome/browser/extensions/test_extension_system.h" | 32 #include "chrome/browser/extensions/test_extension_system.h" |
| 33 #include "chrome/browser/extensions/updater/chrome_manifest_fetch_data_delegate.
h" |
33 #include "chrome/browser/extensions/updater/extension_downloader.h" | 34 #include "chrome/browser/extensions/updater/extension_downloader.h" |
34 #include "chrome/browser/extensions/updater/extension_downloader_delegate.h" | 35 #include "chrome/browser/extensions/updater/extension_downloader_delegate.h" |
35 #include "chrome/browser/extensions/updater/extension_updater.h" | 36 #include "chrome/browser/extensions/updater/extension_updater.h" |
36 #include "chrome/browser/extensions/updater/manifest_fetch_data.h" | |
37 #include "chrome/browser/extensions/updater/request_queue_impl.h" | 37 #include "chrome/browser/extensions/updater/request_queue_impl.h" |
38 #include "chrome/browser/google/google_brand.h" | 38 #include "chrome/browser/google/google_brand.h" |
39 #include "chrome/browser/prefs/pref_service_syncable.h" | 39 #include "chrome/browser/prefs/pref_service_syncable.h" |
40 #include "chrome/common/pref_names.h" | 40 #include "chrome/common/pref_names.h" |
41 #include "chrome/test/base/testing_profile.h" | 41 #include "chrome/test/base/testing_profile.h" |
42 #include "components/omaha_query_params/omaha_query_params.h" | 42 #include "components/omaha_query_params/omaha_query_params.h" |
43 #include "content/public/browser/notification_details.h" | 43 #include "content/public/browser/notification_details.h" |
44 #include "content/public/browser/notification_observer.h" | 44 #include "content/public/browser/notification_observer.h" |
45 #include "content/public/browser/notification_registrar.h" | 45 #include "content/public/browser/notification_registrar.h" |
46 #include "content/public/browser/notification_service.h" | 46 #include "content/public/browser/notification_service.h" |
47 #include "content/public/browser/notification_source.h" | 47 #include "content/public/browser/notification_source.h" |
48 #include "content/public/test/test_browser_thread_bundle.h" | 48 #include "content/public/test/test_browser_thread_bundle.h" |
49 #include "content/public/test/test_utils.h" | 49 #include "content/public/test/test_utils.h" |
50 #include "extensions/browser/extension_prefs.h" | 50 #include "extensions/browser/extension_prefs.h" |
51 #include "extensions/browser/extension_registry.h" | 51 #include "extensions/browser/extension_registry.h" |
52 #include "extensions/browser/extension_system.h" | 52 #include "extensions/browser/extension_system.h" |
| 53 #include "extensions/browser/updater/manifest_fetch_data.h" |
53 #include "extensions/common/extension.h" | 54 #include "extensions/common/extension.h" |
54 #include "extensions/common/id_util.h" | 55 #include "extensions/common/id_util.h" |
55 #include "extensions/common/manifest_constants.h" | 56 #include "extensions/common/manifest_constants.h" |
56 #include "google_apis/gaia/fake_identity_provider.h" | 57 #include "google_apis/gaia/fake_identity_provider.h" |
57 #include "google_apis/gaia/fake_oauth2_token_service.h" | 58 #include "google_apis/gaia/fake_oauth2_token_service.h" |
58 #include "libxml/globals.h" | 59 #include "libxml/globals.h" |
59 #include "net/base/backoff_entry.h" | 60 #include "net/base/backoff_entry.h" |
60 #include "net/base/escape.h" | 61 #include "net/base/escape.h" |
61 #include "net/base/load_flags.h" | 62 #include "net/base/load_flags.h" |
62 #include "net/http/http_request_headers.h" | 63 #include "net/http/http_request_headers.h" |
(...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
349 } | 350 } |
350 | 351 |
351 protected: | 352 protected: |
352 TestExtensionPrefs* const prefs_; | 353 TestExtensionPrefs* const prefs_; |
353 TestingProfile profile_; | 354 TestingProfile profile_; |
354 PendingExtensionManager pending_extension_manager_; | 355 PendingExtensionManager pending_extension_manager_; |
355 | 356 |
356 private: | 357 private: |
357 scoped_ptr<ExtensionDownloader> CreateExtensionDownloader( | 358 scoped_ptr<ExtensionDownloader> CreateExtensionDownloader( |
358 ExtensionDownloaderDelegate* delegate) { | 359 ExtensionDownloaderDelegate* delegate) { |
359 return make_scoped_ptr(new ExtensionDownloader( | 360 scoped_ptr<ExtensionDownloader> downloader(new ExtensionDownloader( |
360 downloader_delegate_override_ ? downloader_delegate_override_ | 361 downloader_delegate_override_ ? downloader_delegate_override_ |
361 : delegate, | 362 : delegate, |
362 request_context())); | 363 request_context())); |
| 364 downloader->SetManifestFetchDataDelegate( |
| 365 make_scoped_ptr<ManifestFetchDataDelegate>( |
| 366 new ChromeManifestFetchDataDelegate)); |
| 367 return downloader.Pass(); |
363 } | 368 } |
364 | 369 |
365 scoped_ptr<ExtensionDownloader> CreateExtensionDownloaderWithIdentity( | 370 scoped_ptr<ExtensionDownloader> CreateExtensionDownloaderWithIdentity( |
366 ExtensionDownloaderDelegate* delegate) { | 371 ExtensionDownloaderDelegate* delegate) { |
367 scoped_ptr<FakeIdentityProvider> fake_identity_provider; | 372 scoped_ptr<FakeIdentityProvider> fake_identity_provider; |
368 fake_token_service_.reset(new FakeOAuth2TokenService()); | 373 fake_token_service_.reset(new FakeOAuth2TokenService()); |
369 fake_identity_provider.reset(new FakeIdentityProvider( | 374 fake_identity_provider.reset(new FakeIdentityProvider( |
370 fake_token_service_.get())); | 375 fake_token_service_.get())); |
371 fake_identity_provider->LogIn(kFakeAccountId); | 376 fake_identity_provider->LogIn(kFakeAccountId); |
372 fake_token_service_->AddAccount(kFakeAccountId); | 377 fake_token_service_->AddAccount(kFakeAccountId); |
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
586 // inside this class (which is a friend to ExtensionUpdater). | 591 // inside this class (which is a friend to ExtensionUpdater). |
587 class ExtensionUpdaterTest : public testing::Test { | 592 class ExtensionUpdaterTest : public testing::Test { |
588 public: | 593 public: |
589 ExtensionUpdaterTest() | 594 ExtensionUpdaterTest() |
590 : thread_bundle_( | 595 : thread_bundle_( |
591 content::TestBrowserThreadBundle::IO_MAINLOOP) { | 596 content::TestBrowserThreadBundle::IO_MAINLOOP) { |
592 } | 597 } |
593 | 598 |
594 virtual void SetUp() OVERRIDE { | 599 virtual void SetUp() OVERRIDE { |
595 prefs_.reset(new TestExtensionPrefs(base::MessageLoopProxy::current())); | 600 prefs_.reset(new TestExtensionPrefs(base::MessageLoopProxy::current())); |
| 601 manifest_fetch_data_delegate_.reset(new ChromeManifestFetchDataDelegate()); |
596 } | 602 } |
597 | 603 |
598 virtual void TearDown() OVERRIDE { | 604 virtual void TearDown() OVERRIDE { |
599 // Some tests create URLRequestContextGetters, whose destruction must run | 605 // Some tests create URLRequestContextGetters, whose destruction must run |
600 // on the IO thread. Make sure the IO loop spins before shutdown so that | 606 // on the IO thread. Make sure the IO loop spins before shutdown so that |
601 // those objects are released. | 607 // those objects are released. |
602 RunUntilIdle(); | 608 RunUntilIdle(); |
603 prefs_.reset(); | 609 prefs_.reset(); |
604 } | 610 } |
605 | 611 |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
693 } | 699 } |
694 EXPECT_EQ("", params["uc"]); | 700 EXPECT_EQ("", params["uc"]); |
695 } | 701 } |
696 | 702 |
697 void TestUpdateUrlDataEmpty() { | 703 void TestUpdateUrlDataEmpty() { |
698 const std::string id = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"; | 704 const std::string id = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"; |
699 const std::string version = "1.0"; | 705 const std::string version = "1.0"; |
700 | 706 |
701 // Make sure that an empty update URL data string does not cause a ap= | 707 // Make sure that an empty update URL data string does not cause a ap= |
702 // option to appear in the x= parameter. | 708 // option to appear in the x= parameter. |
703 ManifestFetchData fetch_data(GURL("http://localhost/foo"), 0); | 709 scoped_ptr<ManifestFetchData> fetch_data( |
704 fetch_data.AddExtension( | 710 CreateManifestFetchData(GURL("http://localhost/foo"))); |
| 711 fetch_data->AddExtension( |
705 id, version, &kNeverPingedData, std::string(), std::string()); | 712 id, version, &kNeverPingedData, std::string(), std::string()); |
706 | 713 |
707 std::map<std::string, std::string> params; | 714 std::map<std::string, std::string> params; |
708 VerifyQueryAndExtractParameters(fetch_data.full_url().query(), ¶ms); | 715 VerifyQueryAndExtractParameters(fetch_data->full_url().query(), ¶ms); |
709 EXPECT_EQ(id, params["id"]); | 716 EXPECT_EQ(id, params["id"]); |
710 EXPECT_EQ(version, params["v"]); | 717 EXPECT_EQ(version, params["v"]); |
711 EXPECT_EQ(0U, params.count("ap")); | 718 EXPECT_EQ(0U, params.count("ap")); |
712 } | 719 } |
713 | 720 |
714 void TestUpdateUrlDataSimple() { | 721 void TestUpdateUrlDataSimple() { |
715 const std::string id = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"; | 722 const std::string id = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"; |
716 const std::string version = "1.0"; | 723 const std::string version = "1.0"; |
717 | 724 |
718 // Make sure that an update URL data string causes an appropriate ap= | 725 // Make sure that an update URL data string causes an appropriate ap= |
719 // option to appear in the x= parameter. | 726 // option to appear in the x= parameter. |
720 ManifestFetchData fetch_data(GURL("http://localhost/foo"), 0); | 727 scoped_ptr<ManifestFetchData> fetch_data( |
721 fetch_data.AddExtension( | 728 CreateManifestFetchData(GURL("http://localhost/foo"))); |
| 729 fetch_data->AddExtension( |
722 id, version, &kNeverPingedData, "bar", std::string()); | 730 id, version, &kNeverPingedData, "bar", std::string()); |
723 std::map<std::string, std::string> params; | 731 std::map<std::string, std::string> params; |
724 VerifyQueryAndExtractParameters(fetch_data.full_url().query(), ¶ms); | 732 VerifyQueryAndExtractParameters(fetch_data->full_url().query(), ¶ms); |
725 EXPECT_EQ(id, params["id"]); | 733 EXPECT_EQ(id, params["id"]); |
726 EXPECT_EQ(version, params["v"]); | 734 EXPECT_EQ(version, params["v"]); |
727 EXPECT_EQ("bar", params["ap"]); | 735 EXPECT_EQ("bar", params["ap"]); |
728 } | 736 } |
729 | 737 |
730 void TestUpdateUrlDataCompound() { | 738 void TestUpdateUrlDataCompound() { |
731 const std::string id = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"; | 739 const std::string id = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"; |
732 const std::string version = "1.0"; | 740 const std::string version = "1.0"; |
733 | 741 |
734 // Make sure that an update URL data string causes an appropriate ap= | 742 // Make sure that an update URL data string causes an appropriate ap= |
735 // option to appear in the x= parameter. | 743 // option to appear in the x= parameter. |
736 ManifestFetchData fetch_data(GURL("http://localhost/foo"), 0); | 744 scoped_ptr<ManifestFetchData> fetch_data( |
737 fetch_data.AddExtension( | 745 CreateManifestFetchData(GURL("http://localhost/foo"))); |
| 746 fetch_data->AddExtension( |
738 id, version, &kNeverPingedData, "a=1&b=2&c", std::string()); | 747 id, version, &kNeverPingedData, "a=1&b=2&c", std::string()); |
739 std::map<std::string, std::string> params; | 748 std::map<std::string, std::string> params; |
740 VerifyQueryAndExtractParameters(fetch_data.full_url().query(), ¶ms); | 749 VerifyQueryAndExtractParameters(fetch_data->full_url().query(), ¶ms); |
741 EXPECT_EQ(id, params["id"]); | 750 EXPECT_EQ(id, params["id"]); |
742 EXPECT_EQ(version, params["v"]); | 751 EXPECT_EQ(version, params["v"]); |
743 EXPECT_EQ("a%3D1%26b%3D2%26c", params["ap"]); | 752 EXPECT_EQ("a%3D1%26b%3D2%26c", params["ap"]); |
744 } | 753 } |
745 | 754 |
746 void TestUpdateUrlDataFromGallery(const std::string& gallery_url) { | 755 void TestUpdateUrlDataFromGallery(const std::string& gallery_url) { |
747 net::TestURLFetcherFactory factory; | 756 net::TestURLFetcherFactory factory; |
748 | 757 |
749 MockService service(prefs_.get()); | 758 MockService service(prefs_.get()); |
750 MockExtensionDownloaderDelegate delegate; | 759 MockExtensionDownloaderDelegate delegate; |
(...skipping 19 matching lines...) Expand all Loading... |
770 std::string::size_type ap = update_url.find("ap%3D", x); | 779 std::string::size_type ap = update_url.find("ap%3D", x); |
771 EXPECT_EQ(std::string::npos, ap); | 780 EXPECT_EQ(std::string::npos, ap); |
772 } | 781 } |
773 | 782 |
774 void TestInstallSource() { | 783 void TestInstallSource() { |
775 const std::string id = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"; | 784 const std::string id = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"; |
776 const std::string version = "1.0"; | 785 const std::string version = "1.0"; |
777 const std::string install_source = "instally"; | 786 const std::string install_source = "instally"; |
778 | 787 |
779 // Make sure that an installsource= appears in the x= parameter. | 788 // Make sure that an installsource= appears in the x= parameter. |
780 ManifestFetchData fetch_data(GURL("http://localhost/foo"), 0); | 789 scoped_ptr<ManifestFetchData> fetch_data( |
781 fetch_data.AddExtension(id, version, &kNeverPingedData, | 790 CreateManifestFetchData(GURL("http://localhost/foo"))); |
782 kEmptyUpdateUrlData, install_source); | 791 fetch_data->AddExtension( |
| 792 id, version, &kNeverPingedData, kEmptyUpdateUrlData, install_source); |
783 std::map<std::string, std::string> params; | 793 std::map<std::string, std::string> params; |
784 VerifyQueryAndExtractParameters(fetch_data.full_url().query(), ¶ms); | 794 VerifyQueryAndExtractParameters(fetch_data->full_url().query(), ¶ms); |
785 EXPECT_EQ(id, params["id"]); | 795 EXPECT_EQ(id, params["id"]); |
786 EXPECT_EQ(version, params["v"]); | 796 EXPECT_EQ(version, params["v"]); |
787 EXPECT_EQ(install_source, params["installsource"]); | 797 EXPECT_EQ(install_source, params["installsource"]); |
788 } | 798 } |
789 | 799 |
790 void TestDetermineUpdates() { | 800 void TestDetermineUpdates() { |
791 TestingProfile profile; | 801 TestingProfile profile; |
792 MockExtensionDownloaderDelegate delegate; | 802 MockExtensionDownloaderDelegate delegate; |
793 ExtensionDownloader downloader(&delegate, profile.GetRequestContext()); | 803 ExtensionDownloader downloader(&delegate, profile.GetRequestContext()); |
794 | 804 |
795 // Check passing an empty list of parse results to DetermineUpdates | 805 // Check passing an empty list of parse results to DetermineUpdates |
796 ManifestFetchData fetch_data(GURL("http://localhost/foo"), 0); | 806 scoped_ptr<ManifestFetchData> fetch_data( |
| 807 CreateManifestFetchData(GURL("http://localhost/foo"))); |
797 UpdateManifest::Results updates; | 808 UpdateManifest::Results updates; |
798 std::vector<int> updateable; | 809 std::vector<int> updateable; |
799 downloader.DetermineUpdates(fetch_data, updates, &updateable); | 810 downloader.DetermineUpdates(*fetch_data, updates, &updateable); |
800 EXPECT_TRUE(updateable.empty()); | 811 EXPECT_TRUE(updateable.empty()); |
801 | 812 |
802 // Create two updates - expect that DetermineUpdates will return the first | 813 // Create two updates - expect that DetermineUpdates will return the first |
803 // one (v1.0 installed, v1.1 available) but not the second one (both | 814 // one (v1.0 installed, v1.1 available) but not the second one (both |
804 // installed and available at v2.0). | 815 // installed and available at v2.0). |
805 const std::string id1 = id_util::GenerateId("1"); | 816 const std::string id1 = id_util::GenerateId("1"); |
806 const std::string id2 = id_util::GenerateId("2"); | 817 const std::string id2 = id_util::GenerateId("2"); |
807 fetch_data.AddExtension( | 818 fetch_data->AddExtension( |
808 id1, "1.0.0.0", &kNeverPingedData, kEmptyUpdateUrlData, std::string()); | 819 id1, "1.0.0.0", &kNeverPingedData, kEmptyUpdateUrlData, std::string()); |
809 AddParseResult(id1, "1.1", "http://localhost/e1_1.1.crx", &updates); | 820 AddParseResult(id1, "1.1", "http://localhost/e1_1.1.crx", &updates); |
810 fetch_data.AddExtension( | 821 fetch_data->AddExtension( |
811 id2, "2.0.0.0", &kNeverPingedData, kEmptyUpdateUrlData, std::string()); | 822 id2, "2.0.0.0", &kNeverPingedData, kEmptyUpdateUrlData, std::string()); |
812 AddParseResult(id2, "2.0.0.0", "http://localhost/e2_2.0.crx", &updates); | 823 AddParseResult(id2, "2.0.0.0", "http://localhost/e2_2.0.crx", &updates); |
813 | 824 |
814 EXPECT_CALL(delegate, IsExtensionPending(_)).WillRepeatedly(Return(false)); | 825 EXPECT_CALL(delegate, IsExtensionPending(_)).WillRepeatedly(Return(false)); |
815 EXPECT_CALL(delegate, GetExtensionExistingVersion(id1, _)) | 826 EXPECT_CALL(delegate, GetExtensionExistingVersion(id1, _)) |
816 .WillOnce(DoAll(SetArgPointee<1>("1.0.0.0"), | 827 .WillOnce(DoAll(SetArgPointee<1>("1.0.0.0"), |
817 Return(true))); | 828 Return(true))); |
818 EXPECT_CALL(delegate, GetExtensionExistingVersion(id2, _)) | 829 EXPECT_CALL(delegate, GetExtensionExistingVersion(id2, _)) |
819 .WillOnce(DoAll(SetArgPointee<1>("2.0.0.0"), | 830 .WillOnce(DoAll(SetArgPointee<1>("2.0.0.0"), |
820 Return(true))); | 831 Return(true))); |
821 | 832 |
822 downloader.DetermineUpdates(fetch_data, updates, &updateable); | 833 downloader.DetermineUpdates(*fetch_data, updates, &updateable); |
823 EXPECT_EQ(1u, updateable.size()); | 834 EXPECT_EQ(1u, updateable.size()); |
824 EXPECT_EQ(0, updateable[0]); | 835 EXPECT_EQ(0, updateable[0]); |
825 } | 836 } |
826 | 837 |
827 void TestDetermineUpdatesPending() { | 838 void TestDetermineUpdatesPending() { |
828 // Create a set of test extensions | 839 // Create a set of test extensions |
829 ServiceForManifestTests service(prefs_.get()); | 840 ServiceForManifestTests service(prefs_.get()); |
830 PendingExtensionManager* pending_extension_manager = | 841 PendingExtensionManager* pending_extension_manager = |
831 service.pending_extension_manager(); | 842 service.pending_extension_manager(); |
832 SetupPendingExtensionManagerForTest(3, GURL(), pending_extension_manager); | 843 SetupPendingExtensionManagerForTest(3, GURL(), pending_extension_manager); |
833 | 844 |
834 TestingProfile profile; | 845 TestingProfile profile; |
835 MockExtensionDownloaderDelegate delegate; | 846 MockExtensionDownloaderDelegate delegate; |
836 ExtensionDownloader downloader(&delegate, profile.GetRequestContext()); | 847 ExtensionDownloader downloader(&delegate, profile.GetRequestContext()); |
837 | 848 |
838 ManifestFetchData fetch_data(GURL("http://localhost/foo"), 0); | 849 scoped_ptr<ManifestFetchData> fetch_data( |
| 850 CreateManifestFetchData(GURL("http://localhost/foo"))); |
839 UpdateManifest::Results updates; | 851 UpdateManifest::Results updates; |
840 | 852 |
841 std::list<std::string> ids_for_update_check; | 853 std::list<std::string> ids_for_update_check; |
842 pending_extension_manager->GetPendingIdsForUpdateCheck( | 854 pending_extension_manager->GetPendingIdsForUpdateCheck( |
843 &ids_for_update_check); | 855 &ids_for_update_check); |
844 | 856 |
845 std::list<std::string>::const_iterator it; | 857 std::list<std::string>::const_iterator it; |
846 for (it = ids_for_update_check.begin(); | 858 for (it = ids_for_update_check.begin(); |
847 it != ids_for_update_check.end(); ++it) { | 859 it != ids_for_update_check.end(); ++it) { |
848 fetch_data.AddExtension(*it, | 860 fetch_data->AddExtension(*it, |
849 "1.0.0.0", | 861 "1.0.0.0", |
850 &kNeverPingedData, | 862 &kNeverPingedData, |
851 kEmptyUpdateUrlData, | 863 kEmptyUpdateUrlData, |
852 std::string()); | 864 std::string()); |
853 AddParseResult(*it, "1.1", "http://localhost/e1_1.1.crx", &updates); | 865 AddParseResult(*it, "1.1", "http://localhost/e1_1.1.crx", &updates); |
854 } | 866 } |
855 | 867 |
856 // The delegate will tell the downloader that all the extensions are | 868 // The delegate will tell the downloader that all the extensions are |
857 // pending. | 869 // pending. |
858 EXPECT_CALL(delegate, IsExtensionPending(_)).WillRepeatedly(Return(true)); | 870 EXPECT_CALL(delegate, IsExtensionPending(_)).WillRepeatedly(Return(true)); |
859 | 871 |
860 std::vector<int> updateable; | 872 std::vector<int> updateable; |
861 downloader.DetermineUpdates(fetch_data, updates, &updateable); | 873 downloader.DetermineUpdates(*fetch_data, updates, &updateable); |
862 // All the apps should be updateable. | 874 // All the apps should be updateable. |
863 EXPECT_EQ(3u, updateable.size()); | 875 EXPECT_EQ(3u, updateable.size()); |
864 for (std::vector<int>::size_type i = 0; i < updateable.size(); ++i) { | 876 for (std::vector<int>::size_type i = 0; i < updateable.size(); ++i) { |
865 EXPECT_EQ(static_cast<int>(i), updateable[i]); | 877 EXPECT_EQ(static_cast<int>(i), updateable[i]); |
866 } | 878 } |
867 } | 879 } |
868 | 880 |
869 void TestMultipleManifestDownloading() { | 881 void TestMultipleManifestDownloading() { |
870 net::TestURLFetcherFactory factory; | 882 net::TestURLFetcherFactory factory; |
871 factory.set_remove_fetcher_on_delete(true); | 883 factory.set_remove_fetcher_on_delete(true); |
872 net::TestURLFetcher* fetcher = NULL; | 884 net::TestURLFetcher* fetcher = NULL; |
873 MockService service(prefs_.get()); | 885 MockService service(prefs_.get()); |
874 MockExtensionDownloaderDelegate delegate; | 886 MockExtensionDownloaderDelegate delegate; |
875 ExtensionDownloader downloader(&delegate, service.request_context()); | 887 ExtensionDownloader downloader(&delegate, service.request_context()); |
876 downloader.manifests_queue_.set_backoff_policy(&kNoBackoffPolicy); | 888 downloader.manifests_queue_.set_backoff_policy(&kNoBackoffPolicy); |
877 | 889 |
878 GURL kUpdateUrl("http://localhost/manifest1"); | 890 GURL kUpdateUrl("http://localhost/manifest1"); |
879 | 891 |
880 scoped_ptr<ManifestFetchData> fetch1(new ManifestFetchData(kUpdateUrl, 0)); | 892 scoped_ptr<ManifestFetchData> fetch1(CreateManifestFetchData(kUpdateUrl)); |
881 scoped_ptr<ManifestFetchData> fetch2(new ManifestFetchData(kUpdateUrl, 0)); | 893 scoped_ptr<ManifestFetchData> fetch2(CreateManifestFetchData(kUpdateUrl)); |
882 scoped_ptr<ManifestFetchData> fetch3(new ManifestFetchData(kUpdateUrl, 0)); | 894 scoped_ptr<ManifestFetchData> fetch3(CreateManifestFetchData(kUpdateUrl)); |
883 scoped_ptr<ManifestFetchData> fetch4(new ManifestFetchData(kUpdateUrl, 0)); | 895 scoped_ptr<ManifestFetchData> fetch4(CreateManifestFetchData(kUpdateUrl)); |
884 ManifestFetchData::PingData zeroDays(0, 0, true); | 896 ManifestFetchData::PingData zeroDays(0, 0, true); |
885 fetch1->AddExtension( | 897 fetch1->AddExtension( |
886 "1111", "1.0", &zeroDays, kEmptyUpdateUrlData, std::string()); | 898 "1111", "1.0", &zeroDays, kEmptyUpdateUrlData, std::string()); |
887 fetch2->AddExtension( | 899 fetch2->AddExtension( |
888 "2222", "2.0", &zeroDays, kEmptyUpdateUrlData, std::string()); | 900 "2222", "2.0", &zeroDays, kEmptyUpdateUrlData, std::string()); |
889 fetch3->AddExtension( | 901 fetch3->AddExtension( |
890 "3333", "3.0", &zeroDays, kEmptyUpdateUrlData, std::string()); | 902 "3333", "3.0", &zeroDays, kEmptyUpdateUrlData, std::string()); |
891 fetch4->AddExtension( | 903 fetch4->AddExtension( |
892 "4444", "4.0", &zeroDays, kEmptyUpdateUrlData, std::string()); | 904 "4444", "4.0", &zeroDays, kEmptyUpdateUrlData, std::string()); |
893 | 905 |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1010 net::TestURLFetcherFactory factory; | 1022 net::TestURLFetcherFactory factory; |
1011 net::TestURLFetcher* fetcher = NULL; | 1023 net::TestURLFetcher* fetcher = NULL; |
1012 NotificationsObserver observer; | 1024 NotificationsObserver observer; |
1013 MockService service(prefs_.get()); | 1025 MockService service(prefs_.get()); |
1014 MockExtensionDownloaderDelegate delegate; | 1026 MockExtensionDownloaderDelegate delegate; |
1015 ExtensionDownloader downloader(&delegate, service.request_context()); | 1027 ExtensionDownloader downloader(&delegate, service.request_context()); |
1016 downloader.manifests_queue_.set_backoff_policy(&kNoBackoffPolicy); | 1028 downloader.manifests_queue_.set_backoff_policy(&kNoBackoffPolicy); |
1017 | 1029 |
1018 GURL kUpdateUrl("http://localhost/manifest1"); | 1030 GURL kUpdateUrl("http://localhost/manifest1"); |
1019 | 1031 |
1020 scoped_ptr<ManifestFetchData> fetch(new ManifestFetchData(kUpdateUrl, 0)); | 1032 scoped_ptr<ManifestFetchData> fetch(CreateManifestFetchData(kUpdateUrl)); |
1021 ManifestFetchData::PingData zeroDays(0, 0, true); | 1033 ManifestFetchData::PingData zeroDays(0, 0, true); |
1022 fetch->AddExtension( | 1034 fetch->AddExtension( |
1023 "1111", "1.0", &zeroDays, kEmptyUpdateUrlData, std::string()); | 1035 "1111", "1.0", &zeroDays, kEmptyUpdateUrlData, std::string()); |
1024 | 1036 |
1025 // This will start the first fetcher. | 1037 // This will start the first fetcher. |
1026 downloader.StartUpdateCheck(fetch.Pass()); | 1038 downloader.StartUpdateCheck(fetch.Pass()); |
1027 RunUntilIdle(); | 1039 RunUntilIdle(); |
1028 | 1040 |
1029 // ExtensionDownloader should retry kMaxRetries times and then fail. | 1041 // ExtensionDownloader should retry kMaxRetries times and then fail. |
1030 EXPECT_CALL(delegate, OnExtensionDownloadFailed( | 1042 EXPECT_CALL(delegate, OnExtensionDownloadFailed( |
1031 "1111", ExtensionDownloaderDelegate::MANIFEST_FETCH_FAILED, _, _)); | 1043 "1111", ExtensionDownloaderDelegate::MANIFEST_FETCH_FAILED, _, _)); |
1032 for (int i = 0; i <= ExtensionDownloader::kMaxRetries; ++i) { | 1044 for (int i = 0; i <= ExtensionDownloader::kMaxRetries; ++i) { |
1033 // All fetches will fail. | 1045 // All fetches will fail. |
1034 fetcher = factory.GetFetcherByID(ExtensionDownloader::kManifestFetcherId); | 1046 fetcher = factory.GetFetcherByID(ExtensionDownloader::kManifestFetcherId); |
1035 EXPECT_TRUE(fetcher != NULL && fetcher->delegate() != NULL); | 1047 EXPECT_TRUE(fetcher != NULL && fetcher->delegate() != NULL); |
1036 EXPECT_TRUE(fetcher->GetLoadFlags() == kExpectedLoadFlags); | 1048 EXPECT_TRUE(fetcher->GetLoadFlags() == kExpectedLoadFlags); |
1037 fetcher->set_url(kUpdateUrl); | 1049 fetcher->set_url(kUpdateUrl); |
1038 fetcher->set_status(net::URLRequestStatus()); | 1050 fetcher->set_status(net::URLRequestStatus()); |
1039 // Code 5xx causes ExtensionDownloader to retry. | 1051 // Code 5xx causes ExtensionDownloader to retry. |
1040 fetcher->set_response_code(500); | 1052 fetcher->set_response_code(500); |
1041 fetcher->delegate()->OnURLFetchComplete(fetcher); | 1053 fetcher->delegate()->OnURLFetchComplete(fetcher); |
1042 RunUntilIdle(); | 1054 RunUntilIdle(); |
1043 } | 1055 } |
1044 Mock::VerifyAndClearExpectations(&delegate); | 1056 Mock::VerifyAndClearExpectations(&delegate); |
1045 | 1057 |
1046 | 1058 |
1047 // For response codes that are not in the 5xx range ExtensionDownloader | 1059 // For response codes that are not in the 5xx range ExtensionDownloader |
1048 // should not retry. | 1060 // should not retry. |
1049 fetch.reset(new ManifestFetchData(kUpdateUrl, 0)); | 1061 fetch.reset(CreateManifestFetchData(kUpdateUrl)); |
1050 fetch->AddExtension( | 1062 fetch->AddExtension( |
1051 "1111", "1.0", &zeroDays, kEmptyUpdateUrlData, std::string()); | 1063 "1111", "1.0", &zeroDays, kEmptyUpdateUrlData, std::string()); |
1052 | 1064 |
1053 // This will start the first fetcher. | 1065 // This will start the first fetcher. |
1054 downloader.StartUpdateCheck(fetch.Pass()); | 1066 downloader.StartUpdateCheck(fetch.Pass()); |
1055 RunUntilIdle(); | 1067 RunUntilIdle(); |
1056 | 1068 |
1057 EXPECT_CALL(delegate, OnExtensionDownloadFailed( | 1069 EXPECT_CALL(delegate, OnExtensionDownloadFailed( |
1058 "1111", ExtensionDownloaderDelegate::MANIFEST_FETCH_FAILED, _, _)); | 1070 "1111", ExtensionDownloaderDelegate::MANIFEST_FETCH_FAILED, _, _)); |
1059 // The first fetch will fail, and require retrying. | 1071 // The first fetch will fail, and require retrying. |
(...skipping 633 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1693 ExtensionUpdater updater(&service, | 1705 ExtensionUpdater updater(&service, |
1694 service.extension_prefs(), | 1706 service.extension_prefs(), |
1695 service.pref_service(), | 1707 service.pref_service(), |
1696 service.profile(), | 1708 service.profile(), |
1697 kUpdateFrequencySecs, | 1709 kUpdateFrequencySecs, |
1698 NULL, | 1710 NULL, |
1699 service.GetDownloaderFactory()); | 1711 service.GetDownloaderFactory()); |
1700 updater.Start(); | 1712 updater.Start(); |
1701 updater.EnsureDownloaderCreated(); | 1713 updater.EnsureDownloaderCreated(); |
1702 | 1714 |
1703 ManifestFetchData fetch_data(update_url, 0); | 1715 scoped_ptr<ManifestFetchData> fetch_data( |
| 1716 CreateManifestFetchData(update_url)); |
1704 const Extension* extension = tmp[0].get(); | 1717 const Extension* extension = tmp[0].get(); |
1705 fetch_data.AddExtension(extension->id(), | 1718 fetch_data->AddExtension(extension->id(), |
1706 extension->VersionString(), | 1719 extension->VersionString(), |
1707 &kNeverPingedData, | 1720 &kNeverPingedData, |
1708 kEmptyUpdateUrlData, | 1721 kEmptyUpdateUrlData, |
1709 std::string()); | 1722 std::string()); |
1710 UpdateManifest::Results results; | 1723 UpdateManifest::Results results; |
1711 results.daystart_elapsed_seconds = 750; | 1724 results.daystart_elapsed_seconds = 750; |
1712 | 1725 |
1713 updater.downloader_->HandleManifestResults(fetch_data, &results); | 1726 updater.downloader_->HandleManifestResults(*fetch_data, &results); |
1714 Time last_ping_day = | 1727 Time last_ping_day = |
1715 service.extension_prefs()->LastPingDay(extension->id()); | 1728 service.extension_prefs()->LastPingDay(extension->id()); |
1716 EXPECT_FALSE(last_ping_day.is_null()); | 1729 EXPECT_FALSE(last_ping_day.is_null()); |
1717 int64 seconds_diff = (Time::Now() - last_ping_day).InSeconds(); | 1730 int64 seconds_diff = (Time::Now() - last_ping_day).InSeconds(); |
1718 EXPECT_LT(seconds_diff - results.daystart_elapsed_seconds, 5); | 1731 EXPECT_LT(seconds_diff - results.daystart_elapsed_seconds, 5); |
1719 } | 1732 } |
1720 | 1733 |
1721 protected: | 1734 protected: |
1722 scoped_ptr<TestExtensionPrefs> prefs_; | 1735 scoped_ptr<TestExtensionPrefs> prefs_; |
1723 | 1736 |
| 1737 ManifestFetchData* CreateManifestFetchData(const GURL& update_url) { |
| 1738 return new ManifestFetchData( |
| 1739 update_url, 0, manifest_fetch_data_delegate_.get()); |
| 1740 } |
| 1741 |
1724 private: | 1742 private: |
1725 content::TestBrowserThreadBundle thread_bundle_; | 1743 content::TestBrowserThreadBundle thread_bundle_; |
1726 content::InProcessUtilityThreadHelper in_process_utility_thread_helper_; | 1744 content::InProcessUtilityThreadHelper in_process_utility_thread_helper_; |
| 1745 scoped_ptr<ManifestFetchDataDelegate> manifest_fetch_data_delegate_; |
1727 | 1746 |
1728 #if defined OS_CHROMEOS | 1747 #if defined OS_CHROMEOS |
1729 chromeos::ScopedTestDeviceSettingsService test_device_settings_service_; | 1748 chromeos::ScopedTestDeviceSettingsService test_device_settings_service_; |
1730 chromeos::ScopedTestCrosSettings test_cros_settings_; | 1749 chromeos::ScopedTestCrosSettings test_cros_settings_; |
1731 chromeos::ScopedTestUserManager test_user_manager_; | 1750 chromeos::ScopedTestUserManager test_user_manager_; |
1732 #endif | 1751 #endif |
1733 }; | 1752 }; |
1734 | 1753 |
1735 // Because we test some private methods of ExtensionUpdater, it's easier for the | 1754 // Because we test some private methods of ExtensionUpdater, it's easier for the |
1736 // actual test code to live in ExtenionUpdaterTest methods instead of TEST_F | 1755 // actual test code to live in ExtenionUpdaterTest methods instead of TEST_F |
(...skipping 259 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1996 ASSERT_TRUE(fetcher); | 2015 ASSERT_TRUE(fetcher); |
1997 EXPECT_FALSE(fetcher->GetOriginalURL().is_empty()); | 2016 EXPECT_FALSE(fetcher->GetOriginalURL().is_empty()); |
1998 } | 2017 } |
1999 | 2018 |
2000 TEST_F(ExtensionUpdaterTest, TestStartUpdateCheckMemory) { | 2019 TEST_F(ExtensionUpdaterTest, TestStartUpdateCheckMemory) { |
2001 net::TestURLFetcherFactory factory; | 2020 net::TestURLFetcherFactory factory; |
2002 MockService service(prefs_.get()); | 2021 MockService service(prefs_.get()); |
2003 MockExtensionDownloaderDelegate delegate; | 2022 MockExtensionDownloaderDelegate delegate; |
2004 ExtensionDownloader downloader(&delegate, service.request_context()); | 2023 ExtensionDownloader downloader(&delegate, service.request_context()); |
2005 | 2024 |
2006 StartUpdateCheck(&downloader, new ManifestFetchData(GURL(), 0)); | 2025 StartUpdateCheck(&downloader, CreateManifestFetchData(GURL())); |
2007 // This should delete the newly-created ManifestFetchData. | 2026 // This should delete the newly-created ManifestFetchData. |
2008 StartUpdateCheck(&downloader, new ManifestFetchData(GURL(), 0)); | 2027 StartUpdateCheck(&downloader, CreateManifestFetchData(GURL())); |
2009 // This should add into |manifests_pending_|. | 2028 // This should add into |manifests_pending_|. |
2010 StartUpdateCheck(&downloader, new ManifestFetchData(GURL( | 2029 StartUpdateCheck(&downloader, |
2011 GURL("http://www.google.com")), 0)); | 2030 CreateManifestFetchData(GURL("http://www.google.com"))); |
2012 // The dtor of |downloader| should delete the pending fetchers. | 2031 // The dtor of |downloader| should delete the pending fetchers. |
2013 } | 2032 } |
2014 | 2033 |
2015 TEST_F(ExtensionUpdaterTest, TestCheckSoon) { | 2034 TEST_F(ExtensionUpdaterTest, TestCheckSoon) { |
2016 ServiceForManifestTests service(prefs_.get()); | 2035 ServiceForManifestTests service(prefs_.get()); |
2017 net::TestURLFetcherFactory factory; | 2036 net::TestURLFetcherFactory factory; |
2018 ExtensionUpdater updater(&service, | 2037 ExtensionUpdater updater(&service, |
2019 service.extension_prefs(), | 2038 service.extension_prefs(), |
2020 service.pref_service(), | 2039 service.pref_service(), |
2021 service.profile(), | 2040 service.profile(), |
(...skipping 19 matching lines...) Expand all Loading... |
2041 // -prodversionmin (shouldn't update if browser version too old) | 2060 // -prodversionmin (shouldn't update if browser version too old) |
2042 // -manifests & updates arriving out of order / interleaved | 2061 // -manifests & updates arriving out of order / interleaved |
2043 // -malformed update url (empty, file://, has query, has a # fragment, etc.) | 2062 // -malformed update url (empty, file://, has query, has a # fragment, etc.) |
2044 // -An extension gets uninstalled while updates are in progress (so it doesn't | 2063 // -An extension gets uninstalled while updates are in progress (so it doesn't |
2045 // "come back from the dead") | 2064 // "come back from the dead") |
2046 // -An extension gets manually updated to v3 while we're downloading v2 (ie | 2065 // -An extension gets manually updated to v3 while we're downloading v2 (ie |
2047 // you don't get downgraded accidentally) | 2066 // you don't get downgraded accidentally) |
2048 // -An update manifest mentions multiple updates | 2067 // -An update manifest mentions multiple updates |
2049 | 2068 |
2050 } // namespace extensions | 2069 } // namespace extensions |
OLD | NEW |