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 "chrome/browser/extensions/updater/extension_updater.h" | 5 #include "chrome/browser/extensions/updater/extension_updater.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include <list> | 10 #include <list> |
(...skipping 747 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
758 | 758 |
759 void TestUpdateUrlDataEmpty() { | 759 void TestUpdateUrlDataEmpty() { |
760 const std::string id = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"; | 760 const std::string id = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"; |
761 const std::string version = "1.0"; | 761 const std::string version = "1.0"; |
762 | 762 |
763 // Make sure that an empty update URL data string does not cause a ap= | 763 // Make sure that an empty update URL data string does not cause a ap= |
764 // option to appear in the x= parameter. | 764 // option to appear in the x= parameter. |
765 std::unique_ptr<ManifestFetchData> fetch_data( | 765 std::unique_ptr<ManifestFetchData> fetch_data( |
766 CreateManifestFetchData(GURL("http://localhost/foo"))); | 766 CreateManifestFetchData(GURL("http://localhost/foo"))); |
767 fetch_data->AddExtension(id, version, &kNeverPingedData, std::string(), | 767 fetch_data->AddExtension(id, version, &kNeverPingedData, std::string(), |
768 std::string()); | 768 std::string(), false); |
769 | 769 |
770 std::map<std::string, std::string> params; | 770 std::map<std::string, std::string> params; |
771 VerifyQueryAndExtractParameters(fetch_data->full_url().query(), ¶ms); | 771 VerifyQueryAndExtractParameters(fetch_data->full_url().query(), ¶ms); |
772 EXPECT_EQ(id, params["id"]); | 772 EXPECT_EQ(id, params["id"]); |
773 EXPECT_EQ(version, params["v"]); | 773 EXPECT_EQ(version, params["v"]); |
774 EXPECT_EQ(0U, params.count("ap")); | 774 EXPECT_EQ(0U, params.count("ap")); |
775 } | 775 } |
776 | 776 |
777 void TestUpdateUrlDataSimple() { | 777 void TestUpdateUrlDataSimple() { |
778 const std::string id = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"; | 778 const std::string id = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"; |
779 const std::string version = "1.0"; | 779 const std::string version = "1.0"; |
780 | 780 |
781 // Make sure that an update URL data string causes an appropriate ap= | 781 // Make sure that an update URL data string causes an appropriate ap= |
782 // option to appear in the x= parameter. | 782 // option to appear in the x= parameter. |
783 std::unique_ptr<ManifestFetchData> fetch_data( | 783 std::unique_ptr<ManifestFetchData> fetch_data( |
784 CreateManifestFetchData(GURL("http://localhost/foo"))); | 784 CreateManifestFetchData(GURL("http://localhost/foo"))); |
785 fetch_data->AddExtension(id, version, &kNeverPingedData, "bar", | 785 fetch_data->AddExtension(id, version, &kNeverPingedData, "bar", |
786 std::string()); | 786 std::string(), false); |
787 std::map<std::string, std::string> params; | 787 std::map<std::string, std::string> params; |
788 VerifyQueryAndExtractParameters(fetch_data->full_url().query(), ¶ms); | 788 VerifyQueryAndExtractParameters(fetch_data->full_url().query(), ¶ms); |
789 EXPECT_EQ(id, params["id"]); | 789 EXPECT_EQ(id, params["id"]); |
790 EXPECT_EQ(version, params["v"]); | 790 EXPECT_EQ(version, params["v"]); |
791 EXPECT_EQ("bar", params["ap"]); | 791 EXPECT_EQ("bar", params["ap"]); |
792 } | 792 } |
793 | 793 |
794 void TestUpdateUrlDataCompound() { | 794 void TestUpdateUrlDataCompound() { |
795 const std::string id = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"; | 795 const std::string id = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"; |
796 const std::string version = "1.0"; | 796 const std::string version = "1.0"; |
797 | 797 |
798 // Make sure that an update URL data string causes an appropriate ap= | 798 // Make sure that an update URL data string causes an appropriate ap= |
799 // option to appear in the x= parameter. | 799 // option to appear in the x= parameter. |
800 std::unique_ptr<ManifestFetchData> fetch_data( | 800 std::unique_ptr<ManifestFetchData> fetch_data( |
801 CreateManifestFetchData(GURL("http://localhost/foo"))); | 801 CreateManifestFetchData(GURL("http://localhost/foo"))); |
802 fetch_data->AddExtension(id, version, &kNeverPingedData, "a=1&b=2&c", | 802 fetch_data->AddExtension(id, version, &kNeverPingedData, "a=1&b=2&c", |
803 std::string()); | 803 std::string(), false); |
804 std::map<std::string, std::string> params; | 804 std::map<std::string, std::string> params; |
805 VerifyQueryAndExtractParameters(fetch_data->full_url().query(), ¶ms); | 805 VerifyQueryAndExtractParameters(fetch_data->full_url().query(), ¶ms); |
806 EXPECT_EQ(id, params["id"]); | 806 EXPECT_EQ(id, params["id"]); |
807 EXPECT_EQ(version, params["v"]); | 807 EXPECT_EQ(version, params["v"]); |
808 EXPECT_EQ("a%3D1%26b%3D2%26c", params["ap"]); | 808 EXPECT_EQ("a%3D1%26b%3D2%26c", params["ap"]); |
809 } | 809 } |
810 | 810 |
811 void TestUpdateUrlDataFromGallery(const std::string& gallery_url) { | 811 void TestUpdateUrlDataFromGallery(const std::string& gallery_url, |
| 812 bool on_demand_update) { |
812 net::TestURLFetcherFactory factory; | 813 net::TestURLFetcherFactory factory; |
813 | 814 |
814 MockService service(prefs_.get()); | 815 MockService service(prefs_.get()); |
815 MockExtensionDownloaderDelegate delegate; | 816 MockExtensionDownloaderDelegate delegate; |
816 ExtensionDownloader downloader(&delegate, service.request_context()); | 817 ExtensionDownloader downloader(&delegate, service.request_context()); |
817 ExtensionList extensions; | 818 ExtensionList extensions; |
818 std::string url(gallery_url); | 819 std::string url(gallery_url); |
819 | 820 |
820 service.CreateTestExtensions(1, 1, &extensions, &url, Manifest::INTERNAL); | 821 service.CreateTestExtensions(1, 1, &extensions, &url, Manifest::INTERNAL); |
821 | 822 |
822 const std::string& id = extensions[0]->id(); | 823 const std::string& id = extensions[0]->id(); |
823 EXPECT_CALL(delegate, GetPingDataForExtension(id, _)); | 824 EXPECT_CALL(delegate, GetPingDataForExtension(id, _)); |
824 | 825 |
825 downloader.AddExtension(*extensions[0], 0); | 826 downloader.AddExtension(*extensions[0], 0, on_demand_update); |
826 downloader.StartAllPending(NULL); | 827 downloader.StartAllPending(NULL); |
827 net::TestURLFetcher* fetcher = | 828 net::TestURLFetcher* fetcher = |
828 factory.GetFetcherByID(ExtensionDownloader::kManifestFetcherId); | 829 factory.GetFetcherByID(ExtensionDownloader::kManifestFetcherId); |
829 ASSERT_TRUE(fetcher); | 830 ASSERT_TRUE(fetcher); |
830 // Make sure that extensions that update from the gallery ignore any | 831 // Make sure that extensions that update from the gallery ignore any |
831 // update URL data. | 832 // update URL data. |
832 const std::string& update_url = fetcher->GetOriginalURL().spec(); | 833 const std::string& update_url = fetcher->GetOriginalURL().spec(); |
833 std::string::size_type x = update_url.find("x="); | 834 std::string::size_type x = update_url.find("x="); |
834 EXPECT_NE(std::string::npos, x); | 835 EXPECT_NE(std::string::npos, x); |
835 std::string::size_type ap = update_url.find("ap%3D", x); | 836 std::string::size_type ap = update_url.find("ap%3D", x); |
836 EXPECT_EQ(std::string::npos, ap); | 837 EXPECT_EQ(std::string::npos, ap); |
| 838 |
| 839 net::HttpRequestHeaders fetch_headers; |
| 840 fetcher->GetExtraRequestHeaders(&fetch_headers); |
| 841 EXPECT_TRUE(fetch_headers.HasHeader( |
| 842 ExtensionDownloader::kUpdateInteractivityHeader)); |
| 843 EXPECT_TRUE( |
| 844 fetch_headers.HasHeader(ExtensionDownloader::kUpdateAppIdHeader)); |
| 845 EXPECT_TRUE( |
| 846 fetch_headers.HasHeader(ExtensionDownloader::kUpdateUpdaterHeader)); |
| 847 |
| 848 std::string interactivity_value; |
| 849 fetch_headers.GetHeader(ExtensionDownloader::kUpdateInteractivityHeader, |
| 850 &interactivity_value); |
| 851 EXPECT_EQ(on_demand_update ? "fg" : "bg", interactivity_value); |
| 852 |
| 853 std::string appid_value; |
| 854 fetch_headers.GetHeader(ExtensionDownloader::kUpdateAppIdHeader, |
| 855 &appid_value); |
| 856 EXPECT_EQ(extensions[0]->id(), appid_value); |
| 857 |
| 858 std::string updater_value; |
| 859 fetch_headers.GetHeader(ExtensionDownloader::kUpdateUpdaterHeader, |
| 860 &updater_value); |
| 861 std::string expected_updater_value = base::StringPrintf( |
| 862 "%s-%s", UpdateQueryParams::GetProdIdString(UpdateQueryParams::CRX), |
| 863 UpdateQueryParams::GetProdVersion().c_str()); |
| 864 EXPECT_EQ(expected_updater_value, updater_value); |
837 } | 865 } |
838 | 866 |
839 void TestInstallSource() { | 867 void TestInstallSource() { |
840 const std::string id = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"; | 868 const std::string id = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"; |
841 const std::string version = "1.0"; | 869 const std::string version = "1.0"; |
842 const std::string install_source = "instally"; | 870 const std::string install_source = "instally"; |
843 | 871 |
844 // Make sure that an installsource= appears in the x= parameter. | 872 // Make sure that an installsource= appears in the x= parameter. |
845 std::unique_ptr<ManifestFetchData> fetch_data( | 873 std::unique_ptr<ManifestFetchData> fetch_data( |
846 CreateManifestFetchData(GURL("http://localhost/foo"))); | 874 CreateManifestFetchData(GURL("http://localhost/foo"))); |
847 fetch_data->AddExtension(id, version, &kNeverPingedData, | 875 fetch_data->AddExtension(id, version, &kNeverPingedData, |
848 kEmptyUpdateUrlData, install_source); | 876 kEmptyUpdateUrlData, install_source, false); |
849 std::map<std::string, std::string> params; | 877 std::map<std::string, std::string> params; |
850 VerifyQueryAndExtractParameters(fetch_data->full_url().query(), ¶ms); | 878 VerifyQueryAndExtractParameters(fetch_data->full_url().query(), ¶ms); |
851 EXPECT_EQ(id, params["id"]); | 879 EXPECT_EQ(id, params["id"]); |
852 EXPECT_EQ(version, params["v"]); | 880 EXPECT_EQ(version, params["v"]); |
853 EXPECT_EQ(install_source, params["installsource"]); | 881 EXPECT_EQ(install_source, params["installsource"]); |
854 } | 882 } |
855 | 883 |
856 void TestDetermineUpdates() { | 884 void TestDetermineUpdates() { |
857 TestingProfile profile; | 885 TestingProfile profile; |
858 MockExtensionDownloaderDelegate delegate; | 886 MockExtensionDownloaderDelegate delegate; |
859 ExtensionDownloader downloader(&delegate, profile.GetRequestContext()); | 887 ExtensionDownloader downloader(&delegate, profile.GetRequestContext()); |
860 | 888 |
861 // Check passing an empty list of parse results to DetermineUpdates | 889 // Check passing an empty list of parse results to DetermineUpdates |
862 std::unique_ptr<ManifestFetchData> fetch_data( | 890 std::unique_ptr<ManifestFetchData> fetch_data( |
863 CreateManifestFetchData(GURL("http://localhost/foo"))); | 891 CreateManifestFetchData(GURL("http://localhost/foo"))); |
864 UpdateManifest::Results updates; | 892 UpdateManifest::Results updates; |
865 std::vector<int> updateable; | 893 std::vector<int> updateable; |
866 downloader.DetermineUpdates(*fetch_data, updates, &updateable); | 894 downloader.DetermineUpdates(*fetch_data, updates, &updateable); |
867 EXPECT_TRUE(updateable.empty()); | 895 EXPECT_TRUE(updateable.empty()); |
868 | 896 |
869 // Create two updates - expect that DetermineUpdates will return the first | 897 // Create two updates - expect that DetermineUpdates will return the first |
870 // one (v1.0 installed, v1.1 available) but not the second one (both | 898 // one (v1.0 installed, v1.1 available) but not the second one (both |
871 // installed and available at v2.0). | 899 // installed and available at v2.0). |
872 const std::string id1 = crx_file::id_util::GenerateId("1"); | 900 const std::string id1 = crx_file::id_util::GenerateId("1"); |
873 const std::string id2 = crx_file::id_util::GenerateId("2"); | 901 const std::string id2 = crx_file::id_util::GenerateId("2"); |
874 fetch_data->AddExtension(id1, "1.0.0.0", &kNeverPingedData, | 902 fetch_data->AddExtension(id1, "1.0.0.0", &kNeverPingedData, |
875 kEmptyUpdateUrlData, std::string()); | 903 kEmptyUpdateUrlData, std::string(), false); |
876 AddParseResult(id1, "1.1", "http://localhost/e1_1.1.crx", &updates); | 904 AddParseResult(id1, "1.1", "http://localhost/e1_1.1.crx", &updates); |
877 fetch_data->AddExtension(id2, "2.0.0.0", &kNeverPingedData, | 905 fetch_data->AddExtension(id2, "2.0.0.0", &kNeverPingedData, |
878 kEmptyUpdateUrlData, std::string()); | 906 kEmptyUpdateUrlData, std::string(), false); |
879 AddParseResult(id2, "2.0.0.0", "http://localhost/e2_2.0.crx", &updates); | 907 AddParseResult(id2, "2.0.0.0", "http://localhost/e2_2.0.crx", &updates); |
880 | 908 |
881 EXPECT_CALL(delegate, IsExtensionPending(_)).WillRepeatedly(Return(false)); | 909 EXPECT_CALL(delegate, IsExtensionPending(_)).WillRepeatedly(Return(false)); |
882 EXPECT_CALL(delegate, GetExtensionExistingVersion(id1, _)) | 910 EXPECT_CALL(delegate, GetExtensionExistingVersion(id1, _)) |
883 .WillOnce(DoAll(SetArgPointee<1>("1.0.0.0"), | 911 .WillOnce(DoAll(SetArgPointee<1>("1.0.0.0"), |
884 Return(true))); | 912 Return(true))); |
885 EXPECT_CALL(delegate, GetExtensionExistingVersion(id2, _)) | 913 EXPECT_CALL(delegate, GetExtensionExistingVersion(id2, _)) |
886 .WillOnce(DoAll(SetArgPointee<1>("2.0.0.0"), | 914 .WillOnce(DoAll(SetArgPointee<1>("2.0.0.0"), |
887 Return(true))); | 915 Return(true))); |
888 | 916 |
(...skipping 18 matching lines...) Expand all Loading... |
907 UpdateManifest::Results updates; | 935 UpdateManifest::Results updates; |
908 | 936 |
909 std::list<std::string> ids_for_update_check; | 937 std::list<std::string> ids_for_update_check; |
910 pending_extension_manager->GetPendingIdsForUpdateCheck( | 938 pending_extension_manager->GetPendingIdsForUpdateCheck( |
911 &ids_for_update_check); | 939 &ids_for_update_check); |
912 | 940 |
913 std::list<std::string>::const_iterator it; | 941 std::list<std::string>::const_iterator it; |
914 for (it = ids_for_update_check.begin(); | 942 for (it = ids_for_update_check.begin(); |
915 it != ids_for_update_check.end(); ++it) { | 943 it != ids_for_update_check.end(); ++it) { |
916 fetch_data->AddExtension(*it, "1.0.0.0", &kNeverPingedData, | 944 fetch_data->AddExtension(*it, "1.0.0.0", &kNeverPingedData, |
917 kEmptyUpdateUrlData, std::string()); | 945 kEmptyUpdateUrlData, std::string(), false); |
918 AddParseResult(*it, "1.1", "http://localhost/e1_1.1.crx", &updates); | 946 AddParseResult(*it, "1.1", "http://localhost/e1_1.1.crx", &updates); |
919 } | 947 } |
920 | 948 |
921 // The delegate will tell the downloader that all the extensions are | 949 // The delegate will tell the downloader that all the extensions are |
922 // pending. | 950 // pending. |
923 EXPECT_CALL(delegate, IsExtensionPending(_)).WillRepeatedly(Return(true)); | 951 EXPECT_CALL(delegate, IsExtensionPending(_)).WillRepeatedly(Return(true)); |
924 | 952 |
925 std::vector<int> updateable; | 953 std::vector<int> updateable; |
926 downloader.DetermineUpdates(*fetch_data, updates, &updateable); | 954 downloader.DetermineUpdates(*fetch_data, updates, &updateable); |
927 // All the apps should be updateable. | 955 // All the apps should be updateable. |
(...skipping 17 matching lines...) Expand all Loading... |
945 std::unique_ptr<ManifestFetchData> fetch1( | 973 std::unique_ptr<ManifestFetchData> fetch1( |
946 CreateManifestFetchData(kUpdateUrl)); | 974 CreateManifestFetchData(kUpdateUrl)); |
947 std::unique_ptr<ManifestFetchData> fetch2( | 975 std::unique_ptr<ManifestFetchData> fetch2( |
948 CreateManifestFetchData(kUpdateUrl)); | 976 CreateManifestFetchData(kUpdateUrl)); |
949 std::unique_ptr<ManifestFetchData> fetch3( | 977 std::unique_ptr<ManifestFetchData> fetch3( |
950 CreateManifestFetchData(kUpdateUrl)); | 978 CreateManifestFetchData(kUpdateUrl)); |
951 std::unique_ptr<ManifestFetchData> fetch4( | 979 std::unique_ptr<ManifestFetchData> fetch4( |
952 CreateManifestFetchData(kUpdateUrl)); | 980 CreateManifestFetchData(kUpdateUrl)); |
953 ManifestFetchData::PingData zeroDays(0, 0, true, 0); | 981 ManifestFetchData::PingData zeroDays(0, 0, true, 0); |
954 fetch1->AddExtension("1111", "1.0", &zeroDays, kEmptyUpdateUrlData, | 982 fetch1->AddExtension("1111", "1.0", &zeroDays, kEmptyUpdateUrlData, |
955 std::string()); | 983 std::string(), false); |
956 fetch2->AddExtension("2222", "2.0", &zeroDays, kEmptyUpdateUrlData, | 984 fetch2->AddExtension("2222", "2.0", &zeroDays, kEmptyUpdateUrlData, |
957 std::string()); | 985 std::string(), false); |
958 fetch3->AddExtension("3333", "3.0", &zeroDays, kEmptyUpdateUrlData, | 986 fetch3->AddExtension("3333", "3.0", &zeroDays, kEmptyUpdateUrlData, |
959 std::string()); | 987 std::string(), false); |
960 fetch4->AddExtension("4444", "4.0", &zeroDays, kEmptyUpdateUrlData, | 988 fetch4->AddExtension("4444", "4.0", &zeroDays, kEmptyUpdateUrlData, |
961 std::string()); | 989 std::string(), false); |
962 | 990 |
963 // This will start the first fetcher and queue the others. The next in queue | 991 // This will start the first fetcher and queue the others. The next in queue |
964 // is started as each fetcher receives its response. Note that the fetchers | 992 // is started as each fetcher receives its response. Note that the fetchers |
965 // don't necessarily run in the order that they are started from here. | 993 // don't necessarily run in the order that they are started from here. |
966 GURL fetch1_url = fetch1->full_url(); | 994 GURL fetch1_url = fetch1->full_url(); |
967 GURL fetch2_url = fetch2->full_url(); | 995 GURL fetch2_url = fetch2->full_url(); |
968 GURL fetch3_url = fetch3->full_url(); | 996 GURL fetch3_url = fetch3->full_url(); |
969 GURL fetch4_url = fetch4->full_url(); | 997 GURL fetch4_url = fetch4->full_url(); |
970 downloader.StartUpdateCheck(std::move(fetch1)); | 998 downloader.StartUpdateCheck(std::move(fetch1)); |
971 downloader.StartUpdateCheck(std::move(fetch2)); | 999 downloader.StartUpdateCheck(std::move(fetch2)); |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1083 MockExtensionDownloaderDelegate delegate; | 1111 MockExtensionDownloaderDelegate delegate; |
1084 ExtensionDownloader downloader(&delegate, service.request_context()); | 1112 ExtensionDownloader downloader(&delegate, service.request_context()); |
1085 downloader.manifests_queue_.set_backoff_policy(&kNoBackoffPolicy); | 1113 downloader.manifests_queue_.set_backoff_policy(&kNoBackoffPolicy); |
1086 | 1114 |
1087 GURL kUpdateUrl("http://localhost/manifest1"); | 1115 GURL kUpdateUrl("http://localhost/manifest1"); |
1088 | 1116 |
1089 std::unique_ptr<ManifestFetchData> fetch( | 1117 std::unique_ptr<ManifestFetchData> fetch( |
1090 CreateManifestFetchData(kUpdateUrl)); | 1118 CreateManifestFetchData(kUpdateUrl)); |
1091 ManifestFetchData::PingData zeroDays(0, 0, true, 0); | 1119 ManifestFetchData::PingData zeroDays(0, 0, true, 0); |
1092 fetch->AddExtension("1111", "1.0", &zeroDays, kEmptyUpdateUrlData, | 1120 fetch->AddExtension("1111", "1.0", &zeroDays, kEmptyUpdateUrlData, |
1093 std::string()); | 1121 std::string(), false); |
1094 | 1122 |
1095 // This will start the first fetcher. | 1123 // This will start the first fetcher. |
1096 downloader.StartUpdateCheck(std::move(fetch)); | 1124 downloader.StartUpdateCheck(std::move(fetch)); |
1097 RunUntilIdle(); | 1125 RunUntilIdle(); |
1098 | 1126 |
1099 // ExtensionDownloader should retry kMaxRetries times and then fail. | 1127 // ExtensionDownloader should retry kMaxRetries times and then fail. |
1100 EXPECT_CALL(delegate, OnExtensionDownloadFailed( | 1128 EXPECT_CALL(delegate, OnExtensionDownloadFailed( |
1101 "1111", ExtensionDownloaderDelegate::MANIFEST_FETCH_FAILED, _, _)); | 1129 "1111", ExtensionDownloaderDelegate::MANIFEST_FETCH_FAILED, _, _)); |
1102 for (int i = 0; i <= ExtensionDownloader::kMaxRetries; ++i) { | 1130 for (int i = 0; i <= ExtensionDownloader::kMaxRetries; ++i) { |
1103 // All fetches will fail. | 1131 // All fetches will fail. |
1104 fetcher = factory.GetFetcherByID(ExtensionDownloader::kManifestFetcherId); | 1132 fetcher = factory.GetFetcherByID(ExtensionDownloader::kManifestFetcherId); |
1105 EXPECT_TRUE(fetcher != NULL && fetcher->delegate() != NULL); | 1133 EXPECT_TRUE(fetcher != NULL && fetcher->delegate() != NULL); |
1106 EXPECT_TRUE(fetcher->GetLoadFlags() == kExpectedLoadFlags); | 1134 EXPECT_TRUE(fetcher->GetLoadFlags() == kExpectedLoadFlags); |
1107 fetcher->set_url(kUpdateUrl); | 1135 fetcher->set_url(kUpdateUrl); |
1108 fetcher->set_status(net::URLRequestStatus()); | 1136 fetcher->set_status(net::URLRequestStatus()); |
1109 // Code 5xx causes ExtensionDownloader to retry. | 1137 // Code 5xx causes ExtensionDownloader to retry. |
1110 fetcher->set_response_code(500); | 1138 fetcher->set_response_code(500); |
1111 fetcher->delegate()->OnURLFetchComplete(fetcher); | 1139 fetcher->delegate()->OnURLFetchComplete(fetcher); |
1112 RunUntilIdle(); | 1140 RunUntilIdle(); |
1113 } | 1141 } |
1114 Mock::VerifyAndClearExpectations(&delegate); | 1142 Mock::VerifyAndClearExpectations(&delegate); |
1115 | 1143 |
1116 | 1144 |
1117 // For response codes that are not in the 5xx range ExtensionDownloader | 1145 // For response codes that are not in the 5xx range ExtensionDownloader |
1118 // should not retry. | 1146 // should not retry. |
1119 fetch.reset(CreateManifestFetchData(kUpdateUrl)); | 1147 fetch.reset(CreateManifestFetchData(kUpdateUrl)); |
1120 fetch->AddExtension("1111", "1.0", &zeroDays, kEmptyUpdateUrlData, | 1148 fetch->AddExtension("1111", "1.0", &zeroDays, kEmptyUpdateUrlData, |
1121 std::string()); | 1149 std::string(), false); |
1122 | 1150 |
1123 // This will start the first fetcher. | 1151 // This will start the first fetcher. |
1124 downloader.StartUpdateCheck(std::move(fetch)); | 1152 downloader.StartUpdateCheck(std::move(fetch)); |
1125 RunUntilIdle(); | 1153 RunUntilIdle(); |
1126 | 1154 |
1127 EXPECT_CALL(delegate, OnExtensionDownloadFailed( | 1155 EXPECT_CALL(delegate, OnExtensionDownloadFailed( |
1128 "1111", ExtensionDownloaderDelegate::MANIFEST_FETCH_FAILED, _, _)); | 1156 "1111", ExtensionDownloaderDelegate::MANIFEST_FETCH_FAILED, _, _)); |
1129 // The first fetch will fail, and require retrying. | 1157 // The first fetch will fail, and require retrying. |
1130 fetcher = factory.GetFetcherByID(ExtensionDownloader::kManifestFetcherId); | 1158 fetcher = factory.GetFetcherByID(ExtensionDownloader::kManifestFetcherId); |
1131 EXPECT_TRUE(fetcher != NULL && fetcher->delegate() != NULL); | 1159 EXPECT_TRUE(fetcher != NULL && fetcher->delegate() != NULL); |
(...skipping 641 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1773 nullptr, | 1801 nullptr, |
1774 service.GetDownloaderFactory()); | 1802 service.GetDownloaderFactory()); |
1775 updater.Start(); | 1803 updater.Start(); |
1776 updater.EnsureDownloaderCreated(); | 1804 updater.EnsureDownloaderCreated(); |
1777 | 1805 |
1778 std::unique_ptr<ManifestFetchData> fetch_data( | 1806 std::unique_ptr<ManifestFetchData> fetch_data( |
1779 CreateManifestFetchData(update_url)); | 1807 CreateManifestFetchData(update_url)); |
1780 const Extension* extension = tmp[0].get(); | 1808 const Extension* extension = tmp[0].get(); |
1781 fetch_data->AddExtension(extension->id(), extension->VersionString(), | 1809 fetch_data->AddExtension(extension->id(), extension->VersionString(), |
1782 &kNeverPingedData, kEmptyUpdateUrlData, | 1810 &kNeverPingedData, kEmptyUpdateUrlData, |
1783 std::string()); | 1811 std::string(), false); |
1784 UpdateManifest::Results results; | 1812 UpdateManifest::Results results; |
1785 results.daystart_elapsed_seconds = 750; | 1813 results.daystart_elapsed_seconds = 750; |
1786 | 1814 |
1787 updater.downloader_->HandleManifestResults(fetch_data.get(), &results); | 1815 updater.downloader_->HandleManifestResults(fetch_data.get(), &results); |
1788 Time last_ping_day = | 1816 Time last_ping_day = |
1789 service.extension_prefs()->LastPingDay(extension->id()); | 1817 service.extension_prefs()->LastPingDay(extension->id()); |
1790 EXPECT_FALSE(last_ping_day.is_null()); | 1818 EXPECT_FALSE(last_ping_day.is_null()); |
1791 int64_t seconds_diff = (Time::Now() - last_ping_day).InSeconds(); | 1819 int64_t seconds_diff = (Time::Now() - last_ping_day).InSeconds(); |
1792 EXPECT_LT(seconds_diff - results.daystart_elapsed_seconds, 5); | 1820 EXPECT_LT(seconds_diff - results.daystart_elapsed_seconds, 5); |
1793 } | 1821 } |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1886 } | 1914 } |
1887 } | 1915 } |
1888 } | 1916 } |
1889 | 1917 |
1890 protected: | 1918 protected: |
1891 std::unique_ptr<TestExtensionPrefs> prefs_; | 1919 std::unique_ptr<TestExtensionPrefs> prefs_; |
1892 | 1920 |
1893 ManifestFetchData* CreateManifestFetchData(const GURL& update_url) { | 1921 ManifestFetchData* CreateManifestFetchData(const GURL& update_url) { |
1894 return new ManifestFetchData(update_url, 0, "", | 1922 return new ManifestFetchData(update_url, 0, "", |
1895 UpdateQueryParams::Get(UpdateQueryParams::CRX), | 1923 UpdateQueryParams::Get(UpdateQueryParams::CRX), |
1896 ManifestFetchData::PING); | 1924 ManifestFetchData::PING, false); |
1897 } | 1925 } |
1898 | 1926 |
1899 private: | 1927 private: |
1900 content::TestBrowserThreadBundle thread_bundle_; | 1928 content::TestBrowserThreadBundle thread_bundle_; |
1901 content::InProcessUtilityThreadHelper in_process_utility_thread_helper_; | 1929 content::InProcessUtilityThreadHelper in_process_utility_thread_helper_; |
1902 ScopedTestingLocalState testing_local_state_; | 1930 ScopedTestingLocalState testing_local_state_; |
1903 | 1931 |
1904 #if defined OS_CHROMEOS | 1932 #if defined OS_CHROMEOS |
1905 chromeos::ScopedTestDeviceSettingsService test_device_settings_service_; | 1933 chromeos::ScopedTestDeviceSettingsService test_device_settings_service_; |
1906 chromeos::ScopedTestCrosSettings test_cros_settings_; | 1934 chromeos::ScopedTestCrosSettings test_cros_settings_; |
(...skipping 10 matching lines...) Expand all Loading... |
1917 } | 1945 } |
1918 | 1946 |
1919 TEST_F(ExtensionUpdaterTest, TestExtensionUpdateCheckRequestsPending) { | 1947 TEST_F(ExtensionUpdaterTest, TestExtensionUpdateCheckRequestsPending) { |
1920 TestExtensionUpdateCheckRequests(true); | 1948 TestExtensionUpdateCheckRequests(true); |
1921 } | 1949 } |
1922 | 1950 |
1923 TEST_F(ExtensionUpdaterTest, TestUpdateUrlData) { | 1951 TEST_F(ExtensionUpdaterTest, TestUpdateUrlData) { |
1924 TestUpdateUrlDataEmpty(); | 1952 TestUpdateUrlDataEmpty(); |
1925 TestUpdateUrlDataSimple(); | 1953 TestUpdateUrlDataSimple(); |
1926 TestUpdateUrlDataCompound(); | 1954 TestUpdateUrlDataCompound(); |
1927 TestUpdateUrlDataFromGallery( | 1955 TestUpdateUrlDataFromGallery(extension_urls::GetWebstoreUpdateUrl().spec(), |
1928 extension_urls::GetWebstoreUpdateUrl().spec()); | 1956 false); |
| 1957 TestUpdateUrlDataFromGallery(extension_urls::GetWebstoreUpdateUrl().spec(), |
| 1958 true); |
1929 } | 1959 } |
1930 | 1960 |
1931 TEST_F(ExtensionUpdaterTest, TestInstallSource) { | 1961 TEST_F(ExtensionUpdaterTest, TestInstallSource) { |
1932 TestInstallSource(); | 1962 TestInstallSource(); |
1933 } | 1963 } |
1934 | 1964 |
1935 TEST_F(ExtensionUpdaterTest, TestDetermineUpdates) { | 1965 TEST_F(ExtensionUpdaterTest, TestDetermineUpdates) { |
1936 TestDetermineUpdates(); | 1966 TestDetermineUpdates(); |
1937 } | 1967 } |
1938 | 1968 |
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2126 MockExtensionDownloaderDelegate delegate; | 2156 MockExtensionDownloaderDelegate delegate; |
2127 std::unique_ptr<ExtensionDownloader> downloader( | 2157 std::unique_ptr<ExtensionDownloader> downloader( |
2128 new ExtensionDownloader(&delegate, service.request_context())); | 2158 new ExtensionDownloader(&delegate, service.request_context())); |
2129 EXPECT_EQ(0u, ManifestFetchersCount(downloader.get())); | 2159 EXPECT_EQ(0u, ManifestFetchersCount(downloader.get())); |
2130 | 2160 |
2131 // First, verify that adding valid extensions does invoke the callbacks on | 2161 // First, verify that adding valid extensions does invoke the callbacks on |
2132 // the delegate. | 2162 // the delegate. |
2133 std::string id = crx_file::id_util::GenerateId("foo"); | 2163 std::string id = crx_file::id_util::GenerateId("foo"); |
2134 EXPECT_CALL(delegate, GetPingDataForExtension(id, _)).WillOnce(Return(false)); | 2164 EXPECT_CALL(delegate, GetPingDataForExtension(id, _)).WillOnce(Return(false)); |
2135 EXPECT_TRUE(downloader->AddPendingExtension( | 2165 EXPECT_TRUE(downloader->AddPendingExtension( |
2136 id, GURL("http://example.com/update"), false, 0)); | 2166 id, GURL("http://example.com/update"), false, 0, false)); |
2137 downloader->StartAllPending(NULL); | 2167 downloader->StartAllPending(NULL); |
2138 Mock::VerifyAndClearExpectations(&delegate); | 2168 Mock::VerifyAndClearExpectations(&delegate); |
2139 EXPECT_EQ(1u, ManifestFetchersCount(downloader.get())); | 2169 EXPECT_EQ(1u, ManifestFetchersCount(downloader.get())); |
2140 | 2170 |
2141 // Extensions with invalid update URLs should be rejected. | 2171 // Extensions with invalid update URLs should be rejected. |
2142 id = crx_file::id_util::GenerateId("foo2"); | 2172 id = crx_file::id_util::GenerateId("foo2"); |
2143 EXPECT_FALSE(downloader->AddPendingExtension(id, GURL("http:google.com:foo"), | 2173 EXPECT_FALSE(downloader->AddPendingExtension(id, GURL("http:google.com:foo"), |
2144 false, 0)); | 2174 false, 0, false)); |
2145 downloader->StartAllPending(NULL); | 2175 downloader->StartAllPending(NULL); |
2146 EXPECT_EQ(1u, ManifestFetchersCount(downloader.get())); | 2176 EXPECT_EQ(1u, ManifestFetchersCount(downloader.get())); |
2147 | 2177 |
2148 // Extensions with empty IDs should be rejected. | 2178 // Extensions with empty IDs should be rejected. |
2149 EXPECT_FALSE( | 2179 EXPECT_FALSE( |
2150 downloader->AddPendingExtension(std::string(), GURL(), false, 0)); | 2180 downloader->AddPendingExtension(std::string(), GURL(), false, 0, false)); |
2151 downloader->StartAllPending(NULL); | 2181 downloader->StartAllPending(NULL); |
2152 EXPECT_EQ(1u, ManifestFetchersCount(downloader.get())); | 2182 EXPECT_EQ(1u, ManifestFetchersCount(downloader.get())); |
2153 | 2183 |
2154 // TODO(akalin): Test that extensions with empty update URLs | 2184 // TODO(akalin): Test that extensions with empty update URLs |
2155 // converted from user scripts are rejected. | 2185 // converted from user scripts are rejected. |
2156 | 2186 |
2157 // Reset the ExtensionDownloader so that it drops the current fetcher. | 2187 // Reset the ExtensionDownloader so that it drops the current fetcher. |
2158 downloader.reset( | 2188 downloader.reset( |
2159 new ExtensionDownloader(&delegate, service.request_context())); | 2189 new ExtensionDownloader(&delegate, service.request_context())); |
2160 EXPECT_EQ(0u, ManifestFetchersCount(downloader.get())); | 2190 EXPECT_EQ(0u, ManifestFetchersCount(downloader.get())); |
2161 | 2191 |
2162 // Extensions with empty update URLs should have a default one | 2192 // Extensions with empty update URLs should have a default one |
2163 // filled in. | 2193 // filled in. |
2164 id = crx_file::id_util::GenerateId("foo3"); | 2194 id = crx_file::id_util::GenerateId("foo3"); |
2165 EXPECT_CALL(delegate, GetPingDataForExtension(id, _)).WillOnce(Return(false)); | 2195 EXPECT_CALL(delegate, GetPingDataForExtension(id, _)).WillOnce(Return(false)); |
2166 EXPECT_TRUE(downloader->AddPendingExtension(id, GURL(), false, 0)); | 2196 EXPECT_TRUE(downloader->AddPendingExtension(id, GURL(), false, 0, false)); |
2167 downloader->StartAllPending(NULL); | 2197 downloader->StartAllPending(NULL); |
2168 EXPECT_EQ(1u, ManifestFetchersCount(downloader.get())); | 2198 EXPECT_EQ(1u, ManifestFetchersCount(downloader.get())); |
2169 | 2199 |
2170 net::TestURLFetcher* fetcher = | 2200 net::TestURLFetcher* fetcher = |
2171 factory.GetFetcherByID(ExtensionDownloader::kManifestFetcherId); | 2201 factory.GetFetcherByID(ExtensionDownloader::kManifestFetcherId); |
2172 ASSERT_TRUE(fetcher); | 2202 ASSERT_TRUE(fetcher); |
2173 EXPECT_FALSE(fetcher->GetOriginalURL().is_empty()); | 2203 EXPECT_FALSE(fetcher->GetOriginalURL().is_empty()); |
2174 } | 2204 } |
2175 | 2205 |
2176 TEST_F(ExtensionUpdaterTest, TestStartUpdateCheckMemory) { | 2206 TEST_F(ExtensionUpdaterTest, TestStartUpdateCheckMemory) { |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2280 // -prodversionmin (shouldn't update if browser version too old) | 2310 // -prodversionmin (shouldn't update if browser version too old) |
2281 // -manifests & updates arriving out of order / interleaved | 2311 // -manifests & updates arriving out of order / interleaved |
2282 // -malformed update url (empty, file://, has query, has a # fragment, etc.) | 2312 // -malformed update url (empty, file://, has query, has a # fragment, etc.) |
2283 // -An extension gets uninstalled while updates are in progress (so it doesn't | 2313 // -An extension gets uninstalled while updates are in progress (so it doesn't |
2284 // "come back from the dead") | 2314 // "come back from the dead") |
2285 // -An extension gets manually updated to v3 while we're downloading v2 (ie | 2315 // -An extension gets manually updated to v3 while we're downloading v2 (ie |
2286 // you don't get downgraded accidentally) | 2316 // you don't get downgraded accidentally) |
2287 // -An update manifest mentions multiple updates | 2317 // -An update manifest mentions multiple updates |
2288 | 2318 |
2289 } // namespace extensions | 2319 } // namespace extensions |
OLD | NEW |