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 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
146 const GURL&, | 146 const GURL&, |
147 const std::string&, | 147 const std::string&, |
148 const PingResult&, | 148 const PingResult&, |
149 const std::set<int>&)); | 149 const std::set<int>&)); |
150 MOCK_METHOD2(GetPingDataForExtension, | 150 MOCK_METHOD2(GetPingDataForExtension, |
151 bool(const std::string&, ManifestFetchData::PingData*)); | 151 bool(const std::string&, ManifestFetchData::PingData*)); |
152 MOCK_METHOD1(GetUpdateUrlData, std::string(const std::string&)); | 152 MOCK_METHOD1(GetUpdateUrlData, std::string(const std::string&)); |
153 MOCK_METHOD1(IsExtensionPending, bool(const std::string&)); | 153 MOCK_METHOD1(IsExtensionPending, bool(const std::string&)); |
154 MOCK_METHOD2(GetExtensionExistingVersion, | 154 MOCK_METHOD2(GetExtensionExistingVersion, |
155 bool(const std::string&, std::string*)); | 155 bool(const std::string&, std::string*)); |
| 156 virtual bool ShouldForceUpdate(const std::string&, std::string*) { |
| 157 return false; |
| 158 } |
156 | 159 |
157 void Wait() { | 160 void Wait() { |
158 scoped_refptr<content::MessageLoopRunner> runner = | 161 scoped_refptr<content::MessageLoopRunner> runner = |
159 new content::MessageLoopRunner; | 162 new content::MessageLoopRunner; |
160 quit_closure_ = runner->QuitClosure(); | 163 quit_closure_ = runner->QuitClosure(); |
161 runner->Run(); | 164 runner->Run(); |
162 quit_closure_.Reset(); | 165 quit_closure_.Reset(); |
163 } | 166 } |
164 | 167 |
165 void Quit() { | 168 void Quit() { |
(...skipping 440 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
606 | 609 |
607 void RunUntilIdle() { | 610 void RunUntilIdle() { |
608 prefs_->pref_service()->CommitPendingWrite(); | 611 prefs_->pref_service()->CommitPendingWrite(); |
609 base::RunLoop().RunUntilIdle(); | 612 base::RunLoop().RunUntilIdle(); |
610 } | 613 } |
611 | 614 |
612 void SimulateTimerFired(ExtensionUpdater* updater) { | 615 void SimulateTimerFired(ExtensionUpdater* updater) { |
613 EXPECT_TRUE(updater->timer_.IsRunning()); | 616 EXPECT_TRUE(updater->timer_.IsRunning()); |
614 updater->timer_.Stop(); | 617 updater->timer_.Stop(); |
615 updater->TimerFired(); | 618 updater->TimerFired(); |
| 619 content::RunAllBlockingPoolTasksUntilIdle(); |
616 } | 620 } |
617 | 621 |
618 // Adds a Result with the given data to results. | 622 // Adds a Result with the given data to results. |
619 void AddParseResult(const std::string& id, | 623 void AddParseResult(const std::string& id, |
620 const std::string& version, | 624 const std::string& version, |
621 const std::string& url, | 625 const std::string& url, |
622 UpdateManifest::Results* results) { | 626 UpdateManifest::Results* results) { |
623 UpdateManifest::Result result; | 627 UpdateManifest::Result result; |
624 result.extension_id = id; | 628 result.extension_id = id; |
625 result.version = version; | 629 result.version = version; |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
696 } | 700 } |
697 | 701 |
698 void TestUpdateUrlDataEmpty() { | 702 void TestUpdateUrlDataEmpty() { |
699 const std::string id = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"; | 703 const std::string id = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"; |
700 const std::string version = "1.0"; | 704 const std::string version = "1.0"; |
701 | 705 |
702 // Make sure that an empty update URL data string does not cause a ap= | 706 // Make sure that an empty update URL data string does not cause a ap= |
703 // option to appear in the x= parameter. | 707 // option to appear in the x= parameter. |
704 ManifestFetchData fetch_data(GURL("http://localhost/foo"), 0); | 708 ManifestFetchData fetch_data(GURL("http://localhost/foo"), 0); |
705 fetch_data.AddExtension( | 709 fetch_data.AddExtension( |
706 id, version, &kNeverPingedData, std::string(), std::string()); | 710 id, version, &kNeverPingedData, std::string(), std::string(), false); |
707 | 711 |
708 std::map<std::string, std::string> params; | 712 std::map<std::string, std::string> params; |
709 VerifyQueryAndExtractParameters(fetch_data.full_url().query(), ¶ms); | 713 VerifyQueryAndExtractParameters(fetch_data.full_url().query(), ¶ms); |
710 EXPECT_EQ(id, params["id"]); | 714 EXPECT_EQ(id, params["id"]); |
711 EXPECT_EQ(version, params["v"]); | 715 EXPECT_EQ(version, params["v"]); |
712 EXPECT_EQ(0U, params.count("ap")); | 716 EXPECT_EQ(0U, params.count("ap")); |
713 } | 717 } |
714 | 718 |
715 void TestUpdateUrlDataSimple() { | 719 void TestUpdateUrlDataSimple() { |
716 const std::string id = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"; | 720 const std::string id = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"; |
717 const std::string version = "1.0"; | 721 const std::string version = "1.0"; |
718 | 722 |
719 // Make sure that an update URL data string causes an appropriate ap= | 723 // Make sure that an update URL data string causes an appropriate ap= |
720 // option to appear in the x= parameter. | 724 // option to appear in the x= parameter. |
721 ManifestFetchData fetch_data(GURL("http://localhost/foo"), 0); | 725 ManifestFetchData fetch_data(GURL("http://localhost/foo"), 0); |
722 fetch_data.AddExtension( | 726 fetch_data.AddExtension( |
723 id, version, &kNeverPingedData, "bar", std::string()); | 727 id, version, &kNeverPingedData, "bar", std::string(), false); |
724 std::map<std::string, std::string> params; | 728 std::map<std::string, std::string> params; |
725 VerifyQueryAndExtractParameters(fetch_data.full_url().query(), ¶ms); | 729 VerifyQueryAndExtractParameters(fetch_data.full_url().query(), ¶ms); |
726 EXPECT_EQ(id, params["id"]); | 730 EXPECT_EQ(id, params["id"]); |
727 EXPECT_EQ(version, params["v"]); | 731 EXPECT_EQ(version, params["v"]); |
728 EXPECT_EQ("bar", params["ap"]); | 732 EXPECT_EQ("bar", params["ap"]); |
729 } | 733 } |
730 | 734 |
731 void TestUpdateUrlDataCompound() { | 735 void TestUpdateUrlDataCompound() { |
732 const std::string id = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"; | 736 const std::string id = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"; |
733 const std::string version = "1.0"; | 737 const std::string version = "1.0"; |
734 | 738 |
735 // Make sure that an update URL data string causes an appropriate ap= | 739 // Make sure that an update URL data string causes an appropriate ap= |
736 // option to appear in the x= parameter. | 740 // option to appear in the x= parameter. |
737 ManifestFetchData fetch_data(GURL("http://localhost/foo"), 0); | 741 ManifestFetchData fetch_data(GURL("http://localhost/foo"), 0); |
738 fetch_data.AddExtension( | 742 fetch_data.AddExtension( |
739 id, version, &kNeverPingedData, "a=1&b=2&c", std::string()); | 743 id, version, &kNeverPingedData, "a=1&b=2&c", std::string(), false); |
740 std::map<std::string, std::string> params; | 744 std::map<std::string, std::string> params; |
741 VerifyQueryAndExtractParameters(fetch_data.full_url().query(), ¶ms); | 745 VerifyQueryAndExtractParameters(fetch_data.full_url().query(), ¶ms); |
742 EXPECT_EQ(id, params["id"]); | 746 EXPECT_EQ(id, params["id"]); |
743 EXPECT_EQ(version, params["v"]); | 747 EXPECT_EQ(version, params["v"]); |
744 EXPECT_EQ("a%3D1%26b%3D2%26c", params["ap"]); | 748 EXPECT_EQ("a%3D1%26b%3D2%26c", params["ap"]); |
745 } | 749 } |
746 | 750 |
747 void TestUpdateUrlDataFromGallery(const std::string& gallery_url) { | 751 void TestUpdateUrlDataFromGallery(const std::string& gallery_url) { |
748 net::TestURLFetcherFactory factory; | 752 net::TestURLFetcherFactory factory; |
749 | 753 |
(...skipping 23 matching lines...) Expand all Loading... |
773 } | 777 } |
774 | 778 |
775 void TestInstallSource() { | 779 void TestInstallSource() { |
776 const std::string id = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"; | 780 const std::string id = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"; |
777 const std::string version = "1.0"; | 781 const std::string version = "1.0"; |
778 const std::string install_source = "instally"; | 782 const std::string install_source = "instally"; |
779 | 783 |
780 // Make sure that an installsource= appears in the x= parameter. | 784 // Make sure that an installsource= appears in the x= parameter. |
781 ManifestFetchData fetch_data(GURL("http://localhost/foo"), 0); | 785 ManifestFetchData fetch_data(GURL("http://localhost/foo"), 0); |
782 fetch_data.AddExtension(id, version, &kNeverPingedData, | 786 fetch_data.AddExtension(id, version, &kNeverPingedData, |
783 kEmptyUpdateUrlData, install_source); | 787 kEmptyUpdateUrlData, install_source, false); |
784 std::map<std::string, std::string> params; | 788 std::map<std::string, std::string> params; |
785 VerifyQueryAndExtractParameters(fetch_data.full_url().query(), ¶ms); | 789 VerifyQueryAndExtractParameters(fetch_data.full_url().query(), ¶ms); |
786 EXPECT_EQ(id, params["id"]); | 790 EXPECT_EQ(id, params["id"]); |
787 EXPECT_EQ(version, params["v"]); | 791 EXPECT_EQ(version, params["v"]); |
788 EXPECT_EQ(install_source, params["installsource"]); | 792 EXPECT_EQ(install_source, params["installsource"]); |
789 } | 793 } |
790 | 794 |
791 void TestDetermineUpdates() { | 795 void TestDetermineUpdates() { |
792 TestingProfile profile; | 796 TestingProfile profile; |
793 MockExtensionDownloaderDelegate delegate; | 797 MockExtensionDownloaderDelegate delegate; |
794 ExtensionDownloader downloader(&delegate, profile.GetRequestContext()); | 798 ExtensionDownloader downloader(&delegate, profile.GetRequestContext()); |
795 | 799 |
796 // Check passing an empty list of parse results to DetermineUpdates | 800 // Check passing an empty list of parse results to DetermineUpdates |
797 ManifestFetchData fetch_data(GURL("http://localhost/foo"), 0); | 801 ManifestFetchData fetch_data(GURL("http://localhost/foo"), 0); |
798 UpdateManifest::Results updates; | 802 UpdateManifest::Results updates; |
799 std::vector<int> updateable; | 803 std::vector<int> updateable; |
800 downloader.DetermineUpdates(fetch_data, updates, &updateable); | 804 downloader.DetermineUpdates(fetch_data, updates, &updateable); |
801 EXPECT_TRUE(updateable.empty()); | 805 EXPECT_TRUE(updateable.empty()); |
802 | 806 |
803 // Create two updates - expect that DetermineUpdates will return the first | 807 // Create two updates - expect that DetermineUpdates will return the first |
804 // one (v1.0 installed, v1.1 available) but not the second one (both | 808 // one (v1.0 installed, v1.1 available) but not the second one (both |
805 // installed and available at v2.0). | 809 // installed and available at v2.0). |
806 const std::string id1 = crx_file::id_util::GenerateId("1"); | 810 const std::string id1 = crx_file::id_util::GenerateId("1"); |
807 const std::string id2 = crx_file::id_util::GenerateId("2"); | 811 const std::string id2 = crx_file::id_util::GenerateId("2"); |
808 fetch_data.AddExtension( | 812 fetch_data.AddExtension( |
809 id1, "1.0.0.0", &kNeverPingedData, kEmptyUpdateUrlData, std::string()); | 813 id1, "1.0.0.0", &kNeverPingedData, kEmptyUpdateUrlData, std::string(), |
| 814 false); |
810 AddParseResult(id1, "1.1", "http://localhost/e1_1.1.crx", &updates); | 815 AddParseResult(id1, "1.1", "http://localhost/e1_1.1.crx", &updates); |
811 fetch_data.AddExtension( | 816 fetch_data.AddExtension( |
812 id2, "2.0.0.0", &kNeverPingedData, kEmptyUpdateUrlData, std::string()); | 817 id2, "2.0.0.0", &kNeverPingedData, kEmptyUpdateUrlData, std::string(), |
| 818 false); |
813 AddParseResult(id2, "2.0.0.0", "http://localhost/e2_2.0.crx", &updates); | 819 AddParseResult(id2, "2.0.0.0", "http://localhost/e2_2.0.crx", &updates); |
814 | 820 |
815 EXPECT_CALL(delegate, IsExtensionPending(_)).WillRepeatedly(Return(false)); | 821 EXPECT_CALL(delegate, IsExtensionPending(_)).WillRepeatedly(Return(false)); |
816 EXPECT_CALL(delegate, GetExtensionExistingVersion(id1, _)) | 822 EXPECT_CALL(delegate, GetExtensionExistingVersion(id1, _)) |
817 .WillOnce(DoAll(SetArgPointee<1>("1.0.0.0"), | 823 .WillOnce(DoAll(SetArgPointee<1>("1.0.0.0"), |
818 Return(true))); | 824 Return(true))); |
819 EXPECT_CALL(delegate, GetExtensionExistingVersion(id2, _)) | 825 EXPECT_CALL(delegate, GetExtensionExistingVersion(id2, _)) |
820 .WillOnce(DoAll(SetArgPointee<1>("2.0.0.0"), | 826 .WillOnce(DoAll(SetArgPointee<1>("2.0.0.0"), |
821 Return(true))); | 827 Return(true))); |
822 | 828 |
(...skipping 20 matching lines...) Expand all Loading... |
843 pending_extension_manager->GetPendingIdsForUpdateCheck( | 849 pending_extension_manager->GetPendingIdsForUpdateCheck( |
844 &ids_for_update_check); | 850 &ids_for_update_check); |
845 | 851 |
846 std::list<std::string>::const_iterator it; | 852 std::list<std::string>::const_iterator it; |
847 for (it = ids_for_update_check.begin(); | 853 for (it = ids_for_update_check.begin(); |
848 it != ids_for_update_check.end(); ++it) { | 854 it != ids_for_update_check.end(); ++it) { |
849 fetch_data.AddExtension(*it, | 855 fetch_data.AddExtension(*it, |
850 "1.0.0.0", | 856 "1.0.0.0", |
851 &kNeverPingedData, | 857 &kNeverPingedData, |
852 kEmptyUpdateUrlData, | 858 kEmptyUpdateUrlData, |
853 std::string()); | 859 std::string(), |
| 860 false); |
854 AddParseResult(*it, "1.1", "http://localhost/e1_1.1.crx", &updates); | 861 AddParseResult(*it, "1.1", "http://localhost/e1_1.1.crx", &updates); |
855 } | 862 } |
856 | 863 |
857 // The delegate will tell the downloader that all the extensions are | 864 // The delegate will tell the downloader that all the extensions are |
858 // pending. | 865 // pending. |
859 EXPECT_CALL(delegate, IsExtensionPending(_)).WillRepeatedly(Return(true)); | 866 EXPECT_CALL(delegate, IsExtensionPending(_)).WillRepeatedly(Return(true)); |
860 | 867 |
861 std::vector<int> updateable; | 868 std::vector<int> updateable; |
862 downloader.DetermineUpdates(fetch_data, updates, &updateable); | 869 downloader.DetermineUpdates(fetch_data, updates, &updateable); |
863 // All the apps should be updateable. | 870 // All the apps should be updateable. |
(...skipping 13 matching lines...) Expand all Loading... |
877 downloader.manifests_queue_.set_backoff_policy(&kNoBackoffPolicy); | 884 downloader.manifests_queue_.set_backoff_policy(&kNoBackoffPolicy); |
878 | 885 |
879 GURL kUpdateUrl("http://localhost/manifest1"); | 886 GURL kUpdateUrl("http://localhost/manifest1"); |
880 | 887 |
881 scoped_ptr<ManifestFetchData> fetch1(new ManifestFetchData(kUpdateUrl, 0)); | 888 scoped_ptr<ManifestFetchData> fetch1(new ManifestFetchData(kUpdateUrl, 0)); |
882 scoped_ptr<ManifestFetchData> fetch2(new ManifestFetchData(kUpdateUrl, 0)); | 889 scoped_ptr<ManifestFetchData> fetch2(new ManifestFetchData(kUpdateUrl, 0)); |
883 scoped_ptr<ManifestFetchData> fetch3(new ManifestFetchData(kUpdateUrl, 0)); | 890 scoped_ptr<ManifestFetchData> fetch3(new ManifestFetchData(kUpdateUrl, 0)); |
884 scoped_ptr<ManifestFetchData> fetch4(new ManifestFetchData(kUpdateUrl, 0)); | 891 scoped_ptr<ManifestFetchData> fetch4(new ManifestFetchData(kUpdateUrl, 0)); |
885 ManifestFetchData::PingData zeroDays(0, 0, true); | 892 ManifestFetchData::PingData zeroDays(0, 0, true); |
886 fetch1->AddExtension( | 893 fetch1->AddExtension( |
887 "1111", "1.0", &zeroDays, kEmptyUpdateUrlData, std::string()); | 894 "1111", "1.0", &zeroDays, kEmptyUpdateUrlData, std::string(), false); |
888 fetch2->AddExtension( | 895 fetch2->AddExtension( |
889 "2222", "2.0", &zeroDays, kEmptyUpdateUrlData, std::string()); | 896 "2222", "2.0", &zeroDays, kEmptyUpdateUrlData, std::string(), false); |
890 fetch3->AddExtension( | 897 fetch3->AddExtension( |
891 "3333", "3.0", &zeroDays, kEmptyUpdateUrlData, std::string()); | 898 "3333", "3.0", &zeroDays, kEmptyUpdateUrlData, std::string(), false); |
892 fetch4->AddExtension( | 899 fetch4->AddExtension( |
893 "4444", "4.0", &zeroDays, kEmptyUpdateUrlData, std::string()); | 900 "4444", "4.0", &zeroDays, kEmptyUpdateUrlData, std::string(), false); |
894 | 901 |
895 // This will start the first fetcher and queue the others. The next in queue | 902 // This will start the first fetcher and queue the others. The next in queue |
896 // is started as each fetcher receives its response. Note that the fetchers | 903 // is started as each fetcher receives its response. Note that the fetchers |
897 // don't necessarily run in the order that they are started from here. | 904 // don't necessarily run in the order that they are started from here. |
898 GURL fetch1_url = fetch1->full_url(); | 905 GURL fetch1_url = fetch1->full_url(); |
899 GURL fetch2_url = fetch2->full_url(); | 906 GURL fetch2_url = fetch2->full_url(); |
900 GURL fetch3_url = fetch3->full_url(); | 907 GURL fetch3_url = fetch3->full_url(); |
901 GURL fetch4_url = fetch4->full_url(); | 908 GURL fetch4_url = fetch4->full_url(); |
902 downloader.StartUpdateCheck(fetch1.Pass()); | 909 downloader.StartUpdateCheck(fetch1.Pass()); |
903 downloader.StartUpdateCheck(fetch2.Pass()); | 910 downloader.StartUpdateCheck(fetch2.Pass()); |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1014 MockService service(prefs_.get()); | 1021 MockService service(prefs_.get()); |
1015 MockExtensionDownloaderDelegate delegate; | 1022 MockExtensionDownloaderDelegate delegate; |
1016 ExtensionDownloader downloader(&delegate, service.request_context()); | 1023 ExtensionDownloader downloader(&delegate, service.request_context()); |
1017 downloader.manifests_queue_.set_backoff_policy(&kNoBackoffPolicy); | 1024 downloader.manifests_queue_.set_backoff_policy(&kNoBackoffPolicy); |
1018 | 1025 |
1019 GURL kUpdateUrl("http://localhost/manifest1"); | 1026 GURL kUpdateUrl("http://localhost/manifest1"); |
1020 | 1027 |
1021 scoped_ptr<ManifestFetchData> fetch(new ManifestFetchData(kUpdateUrl, 0)); | 1028 scoped_ptr<ManifestFetchData> fetch(new ManifestFetchData(kUpdateUrl, 0)); |
1022 ManifestFetchData::PingData zeroDays(0, 0, true); | 1029 ManifestFetchData::PingData zeroDays(0, 0, true); |
1023 fetch->AddExtension( | 1030 fetch->AddExtension( |
1024 "1111", "1.0", &zeroDays, kEmptyUpdateUrlData, std::string()); | 1031 "1111", "1.0", &zeroDays, kEmptyUpdateUrlData, std::string(), false); |
1025 | 1032 |
1026 // This will start the first fetcher. | 1033 // This will start the first fetcher. |
1027 downloader.StartUpdateCheck(fetch.Pass()); | 1034 downloader.StartUpdateCheck(fetch.Pass()); |
1028 RunUntilIdle(); | 1035 RunUntilIdle(); |
1029 | 1036 |
1030 // ExtensionDownloader should retry kMaxRetries times and then fail. | 1037 // ExtensionDownloader should retry kMaxRetries times and then fail. |
1031 EXPECT_CALL(delegate, OnExtensionDownloadFailed( | 1038 EXPECT_CALL(delegate, OnExtensionDownloadFailed( |
1032 "1111", ExtensionDownloaderDelegate::MANIFEST_FETCH_FAILED, _, _)); | 1039 "1111", ExtensionDownloaderDelegate::MANIFEST_FETCH_FAILED, _, _)); |
1033 for (int i = 0; i <= ExtensionDownloader::kMaxRetries; ++i) { | 1040 for (int i = 0; i <= ExtensionDownloader::kMaxRetries; ++i) { |
1034 // All fetches will fail. | 1041 // All fetches will fail. |
1035 fetcher = factory.GetFetcherByID(ExtensionDownloader::kManifestFetcherId); | 1042 fetcher = factory.GetFetcherByID(ExtensionDownloader::kManifestFetcherId); |
1036 EXPECT_TRUE(fetcher != NULL && fetcher->delegate() != NULL); | 1043 EXPECT_TRUE(fetcher != NULL && fetcher->delegate() != NULL); |
1037 EXPECT_TRUE(fetcher->GetLoadFlags() == kExpectedLoadFlags); | 1044 EXPECT_TRUE(fetcher->GetLoadFlags() == kExpectedLoadFlags); |
1038 fetcher->set_url(kUpdateUrl); | 1045 fetcher->set_url(kUpdateUrl); |
1039 fetcher->set_status(net::URLRequestStatus()); | 1046 fetcher->set_status(net::URLRequestStatus()); |
1040 // Code 5xx causes ExtensionDownloader to retry. | 1047 // Code 5xx causes ExtensionDownloader to retry. |
1041 fetcher->set_response_code(500); | 1048 fetcher->set_response_code(500); |
1042 fetcher->delegate()->OnURLFetchComplete(fetcher); | 1049 fetcher->delegate()->OnURLFetchComplete(fetcher); |
1043 RunUntilIdle(); | 1050 RunUntilIdle(); |
1044 } | 1051 } |
1045 Mock::VerifyAndClearExpectations(&delegate); | 1052 Mock::VerifyAndClearExpectations(&delegate); |
1046 | 1053 |
1047 | 1054 |
1048 // For response codes that are not in the 5xx range ExtensionDownloader | 1055 // For response codes that are not in the 5xx range ExtensionDownloader |
1049 // should not retry. | 1056 // should not retry. |
1050 fetch.reset(new ManifestFetchData(kUpdateUrl, 0)); | 1057 fetch.reset(new ManifestFetchData(kUpdateUrl, 0)); |
1051 fetch->AddExtension( | 1058 fetch->AddExtension( |
1052 "1111", "1.0", &zeroDays, kEmptyUpdateUrlData, std::string()); | 1059 "1111", "1.0", &zeroDays, kEmptyUpdateUrlData, std::string(), false); |
1053 | 1060 |
1054 // This will start the first fetcher. | 1061 // This will start the first fetcher. |
1055 downloader.StartUpdateCheck(fetch.Pass()); | 1062 downloader.StartUpdateCheck(fetch.Pass()); |
1056 RunUntilIdle(); | 1063 RunUntilIdle(); |
1057 | 1064 |
1058 EXPECT_CALL(delegate, OnExtensionDownloadFailed( | 1065 EXPECT_CALL(delegate, OnExtensionDownloadFailed( |
1059 "1111", ExtensionDownloaderDelegate::MANIFEST_FETCH_FAILED, _, _)); | 1066 "1111", ExtensionDownloaderDelegate::MANIFEST_FETCH_FAILED, _, _)); |
1060 // The first fetch will fail, and require retrying. | 1067 // The first fetch will fail, and require retrying. |
1061 fetcher = factory.GetFetcherByID(ExtensionDownloader::kManifestFetcherId); | 1068 fetcher = factory.GetFetcherByID(ExtensionDownloader::kManifestFetcherId); |
1062 EXPECT_TRUE(fetcher != NULL && fetcher->delegate() != NULL); | 1069 EXPECT_TRUE(fetcher != NULL && fetcher->delegate() != NULL); |
(...skipping 534 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1597 ExtensionUpdater updater(&service, | 1604 ExtensionUpdater updater(&service, |
1598 service.extension_prefs(), | 1605 service.extension_prefs(), |
1599 service.pref_service(), | 1606 service.pref_service(), |
1600 service.profile(), | 1607 service.profile(), |
1601 kUpdateFrequencySecs, | 1608 kUpdateFrequencySecs, |
1602 NULL, | 1609 NULL, |
1603 service.GetDownloaderFactory()); | 1610 service.GetDownloaderFactory()); |
1604 ExtensionUpdater::CheckParams params; | 1611 ExtensionUpdater::CheckParams params; |
1605 updater.Start(); | 1612 updater.Start(); |
1606 updater.CheckNow(params); | 1613 updater.CheckNow(params); |
| 1614 content::RunAllBlockingPoolTasksUntilIdle(); |
1607 | 1615 |
1608 // Make the updater do manifest fetching, and note the urls it tries to | 1616 // Make the updater do manifest fetching, and note the urls it tries to |
1609 // fetch. | 1617 // fetch. |
1610 std::vector<GURL> fetched_urls; | 1618 std::vector<GURL> fetched_urls; |
1611 net::TestURLFetcher* fetcher = | 1619 net::TestURLFetcher* fetcher = |
1612 factory.GetFetcherByID(ExtensionDownloader::kManifestFetcherId); | 1620 factory.GetFetcherByID(ExtensionDownloader::kManifestFetcherId); |
1613 EXPECT_TRUE(fetcher != NULL && fetcher->delegate() != NULL); | 1621 EXPECT_TRUE(fetcher != NULL && fetcher->delegate() != NULL); |
1614 fetched_urls.push_back(fetcher->GetOriginalURL()); | 1622 fetched_urls.push_back(fetcher->GetOriginalURL()); |
1615 | 1623 |
1616 fetcher->set_url(fetched_urls[0]); | 1624 fetcher->set_url(fetched_urls[0]); |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1700 service.GetDownloaderFactory()); | 1708 service.GetDownloaderFactory()); |
1701 updater.Start(); | 1709 updater.Start(); |
1702 updater.EnsureDownloaderCreated(); | 1710 updater.EnsureDownloaderCreated(); |
1703 | 1711 |
1704 ManifestFetchData fetch_data(update_url, 0); | 1712 ManifestFetchData fetch_data(update_url, 0); |
1705 const Extension* extension = tmp[0].get(); | 1713 const Extension* extension = tmp[0].get(); |
1706 fetch_data.AddExtension(extension->id(), | 1714 fetch_data.AddExtension(extension->id(), |
1707 extension->VersionString(), | 1715 extension->VersionString(), |
1708 &kNeverPingedData, | 1716 &kNeverPingedData, |
1709 kEmptyUpdateUrlData, | 1717 kEmptyUpdateUrlData, |
1710 std::string()); | 1718 std::string(), |
| 1719 false); |
1711 UpdateManifest::Results results; | 1720 UpdateManifest::Results results; |
1712 results.daystart_elapsed_seconds = 750; | 1721 results.daystart_elapsed_seconds = 750; |
1713 | 1722 |
1714 updater.downloader_->HandleManifestResults(fetch_data, &results); | 1723 updater.downloader_->HandleManifestResults(fetch_data, &results); |
1715 Time last_ping_day = | 1724 Time last_ping_day = |
1716 service.extension_prefs()->LastPingDay(extension->id()); | 1725 service.extension_prefs()->LastPingDay(extension->id()); |
1717 EXPECT_FALSE(last_ping_day.is_null()); | 1726 EXPECT_FALSE(last_ping_day.is_null()); |
1718 int64 seconds_diff = (Time::Now() - last_ping_day).InSeconds(); | 1727 int64 seconds_diff = (Time::Now() - last_ping_day).InSeconds(); |
1719 EXPECT_LT(seconds_diff - results.daystart_elapsed_seconds, 5); | 1728 EXPECT_LT(seconds_diff - results.daystart_elapsed_seconds, 5); |
1720 } | 1729 } |
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1898 // These expectations fail if the delegate's methods are invoked for the | 1907 // These expectations fail if the delegate's methods are invoked for the |
1899 // first extension, which has a non-matching id. | 1908 // first extension, which has a non-matching id. |
1900 EXPECT_CALL(delegate, | 1909 EXPECT_CALL(delegate, |
1901 GetUpdateUrlData(updateable_id)).WillOnce(Return("")); | 1910 GetUpdateUrlData(updateable_id)).WillOnce(Return("")); |
1902 EXPECT_CALL(delegate, GetPingDataForExtension(updateable_id, _)); | 1911 EXPECT_CALL(delegate, GetPingDataForExtension(updateable_id, _)); |
1903 | 1912 |
1904 service.set_extensions(extensions, ExtensionList()); | 1913 service.set_extensions(extensions, ExtensionList()); |
1905 ExtensionUpdater::CheckParams params; | 1914 ExtensionUpdater::CheckParams params; |
1906 updater.Start(); | 1915 updater.Start(); |
1907 updater.CheckNow(params); | 1916 updater.CheckNow(params); |
| 1917 content::RunAllBlockingPoolTasksUntilIdle(); |
1908 } | 1918 } |
1909 | 1919 |
1910 TEST_F(ExtensionUpdaterTest, TestUpdatingDisabledExtensions) { | 1920 TEST_F(ExtensionUpdaterTest, TestUpdatingDisabledExtensions) { |
1911 net::TestURLFetcherFactory factory; | 1921 net::TestURLFetcherFactory factory; |
1912 ServiceForManifestTests service(prefs_.get()); | 1922 ServiceForManifestTests service(prefs_.get()); |
1913 ExtensionUpdater updater(&service, | 1923 ExtensionUpdater updater(&service, |
1914 service.extension_prefs(), | 1924 service.extension_prefs(), |
1915 service.pref_service(), | 1925 service.pref_service(), |
1916 service.profile(), | 1926 service.profile(), |
1917 kUpdateFrequencySecs, | 1927 kUpdateFrequencySecs, |
(...skipping 18 matching lines...) Expand all Loading... |
1936 EXPECT_CALL(delegate, GetUpdateUrlData(enabled_id)).WillOnce(Return("")); | 1946 EXPECT_CALL(delegate, GetUpdateUrlData(enabled_id)).WillOnce(Return("")); |
1937 EXPECT_CALL(delegate, GetPingDataForExtension(enabled_id, _)); | 1947 EXPECT_CALL(delegate, GetPingDataForExtension(enabled_id, _)); |
1938 EXPECT_CALL(delegate, | 1948 EXPECT_CALL(delegate, |
1939 GetUpdateUrlData(disabled_id)).WillOnce(Return("")); | 1949 GetUpdateUrlData(disabled_id)).WillOnce(Return("")); |
1940 EXPECT_CALL(delegate, GetPingDataForExtension(disabled_id, _)); | 1950 EXPECT_CALL(delegate, GetPingDataForExtension(disabled_id, _)); |
1941 | 1951 |
1942 service.set_extensions(enabled_extensions, disabled_extensions); | 1952 service.set_extensions(enabled_extensions, disabled_extensions); |
1943 ExtensionUpdater::CheckParams params; | 1953 ExtensionUpdater::CheckParams params; |
1944 updater.Start(); | 1954 updater.Start(); |
1945 updater.CheckNow(params); | 1955 updater.CheckNow(params); |
| 1956 content::RunAllBlockingPoolTasksUntilIdle(); |
1946 } | 1957 } |
1947 | 1958 |
1948 TEST_F(ExtensionUpdaterTest, TestManifestFetchesBuilderAddExtension) { | 1959 TEST_F(ExtensionUpdaterTest, TestManifestFetchesBuilderAddExtension) { |
1949 net::TestURLFetcherFactory factory; | 1960 net::TestURLFetcherFactory factory; |
1950 MockService service(prefs_.get()); | 1961 MockService service(prefs_.get()); |
1951 MockExtensionDownloaderDelegate delegate; | 1962 MockExtensionDownloaderDelegate delegate; |
1952 scoped_ptr<ExtensionDownloader> downloader( | 1963 scoped_ptr<ExtensionDownloader> downloader( |
1953 new ExtensionDownloader(&delegate, service.request_context())); | 1964 new ExtensionDownloader(&delegate, service.request_context())); |
1954 EXPECT_EQ(0u, ManifestFetchersCount(downloader.get())); | 1965 EXPECT_EQ(0u, ManifestFetchersCount(downloader.get())); |
1955 | 1966 |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2042 // -prodversionmin (shouldn't update if browser version too old) | 2053 // -prodversionmin (shouldn't update if browser version too old) |
2043 // -manifests & updates arriving out of order / interleaved | 2054 // -manifests & updates arriving out of order / interleaved |
2044 // -malformed update url (empty, file://, has query, has a # fragment, etc.) | 2055 // -malformed update url (empty, file://, has query, has a # fragment, etc.) |
2045 // -An extension gets uninstalled while updates are in progress (so it doesn't | 2056 // -An extension gets uninstalled while updates are in progress (so it doesn't |
2046 // "come back from the dead") | 2057 // "come back from the dead") |
2047 // -An extension gets manually updated to v3 while we're downloading v2 (ie | 2058 // -An extension gets manually updated to v3 while we're downloading v2 (ie |
2048 // you don't get downgraded accidentally) | 2059 // you don't get downgraded accidentally) |
2049 // -An update manifest mentions multiple updates | 2060 // -An update manifest mentions multiple updates |
2050 | 2061 |
2051 } // namespace extensions | 2062 } // namespace extensions |
OLD | NEW |