Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(89)

Side by Side Diff: chrome/browser/extensions/updater/extension_updater_unittest.cc

Issue 2768573002: Send traffic-management headers from extension updater. (Closed)
Patch Set: Change the code according to mek's comments. Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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(),
769 ManifestFetchData::FetchPriority::BACKGROUND);
769 770
770 std::map<std::string, std::string> params; 771 std::map<std::string, std::string> params;
771 VerifyQueryAndExtractParameters(fetch_data->full_url().query(), &params); 772 VerifyQueryAndExtractParameters(fetch_data->full_url().query(), &params);
772 EXPECT_EQ(id, params["id"]); 773 EXPECT_EQ(id, params["id"]);
773 EXPECT_EQ(version, params["v"]); 774 EXPECT_EQ(version, params["v"]);
774 EXPECT_EQ(0U, params.count("ap")); 775 EXPECT_EQ(0U, params.count("ap"));
775 } 776 }
776 777
777 void TestUpdateUrlDataSimple() { 778 void TestUpdateUrlDataSimple() {
778 const std::string id = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"; 779 const std::string id = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
779 const std::string version = "1.0"; 780 const std::string version = "1.0";
780 781
781 // Make sure that an update URL data string causes an appropriate ap= 782 // Make sure that an update URL data string causes an appropriate ap=
782 // option to appear in the x= parameter. 783 // option to appear in the x= parameter.
783 std::unique_ptr<ManifestFetchData> fetch_data( 784 std::unique_ptr<ManifestFetchData> fetch_data(
784 CreateManifestFetchData(GURL("http://localhost/foo"))); 785 CreateManifestFetchData(GURL("http://localhost/foo")));
785 fetch_data->AddExtension(id, version, &kNeverPingedData, "bar", 786 fetch_data->AddExtension(id, version, &kNeverPingedData, "bar",
786 std::string()); 787 std::string(),
788 ManifestFetchData::FetchPriority::BACKGROUND);
787 std::map<std::string, std::string> params; 789 std::map<std::string, std::string> params;
788 VerifyQueryAndExtractParameters(fetch_data->full_url().query(), &params); 790 VerifyQueryAndExtractParameters(fetch_data->full_url().query(), &params);
789 EXPECT_EQ(id, params["id"]); 791 EXPECT_EQ(id, params["id"]);
790 EXPECT_EQ(version, params["v"]); 792 EXPECT_EQ(version, params["v"]);
791 EXPECT_EQ("bar", params["ap"]); 793 EXPECT_EQ("bar", params["ap"]);
792 } 794 }
793 795
794 void TestUpdateUrlDataCompound() { 796 void TestUpdateUrlDataCompound() {
795 const std::string id = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"; 797 const std::string id = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
796 const std::string version = "1.0"; 798 const std::string version = "1.0";
797 799
798 // Make sure that an update URL data string causes an appropriate ap= 800 // Make sure that an update URL data string causes an appropriate ap=
799 // option to appear in the x= parameter. 801 // option to appear in the x= parameter.
800 std::unique_ptr<ManifestFetchData> fetch_data( 802 std::unique_ptr<ManifestFetchData> fetch_data(
801 CreateManifestFetchData(GURL("http://localhost/foo"))); 803 CreateManifestFetchData(GURL("http://localhost/foo")));
802 fetch_data->AddExtension(id, version, &kNeverPingedData, "a=1&b=2&c", 804 fetch_data->AddExtension(id, version, &kNeverPingedData, "a=1&b=2&c",
803 std::string()); 805 std::string(),
806 ManifestFetchData::FetchPriority::BACKGROUND);
804 std::map<std::string, std::string> params; 807 std::map<std::string, std::string> params;
805 VerifyQueryAndExtractParameters(fetch_data->full_url().query(), &params); 808 VerifyQueryAndExtractParameters(fetch_data->full_url().query(), &params);
806 EXPECT_EQ(id, params["id"]); 809 EXPECT_EQ(id, params["id"]);
807 EXPECT_EQ(version, params["v"]); 810 EXPECT_EQ(version, params["v"]);
808 EXPECT_EQ("a%3D1%26b%3D2%26c", params["ap"]); 811 EXPECT_EQ("a%3D1%26b%3D2%26c", params["ap"]);
809 } 812 }
810 813
811 void TestUpdateUrlDataFromGallery(const std::string& gallery_url) { 814 void TestUpdateUrlDataFromGallery(
815 const std::string& gallery_url,
816 ManifestFetchData::FetchPriority fetch_priority,
817 int num_extensions) {
812 net::TestURLFetcherFactory factory; 818 net::TestURLFetcherFactory factory;
813 819
814 MockService service(prefs_.get()); 820 MockService service(prefs_.get());
815 MockExtensionDownloaderDelegate delegate; 821 MockExtensionDownloaderDelegate delegate;
816 ExtensionDownloader downloader(&delegate, service.request_context()); 822 ExtensionDownloader downloader(&delegate, service.request_context());
817 ExtensionList extensions; 823 ExtensionList extensions;
818 std::string url(gallery_url); 824 std::string url(gallery_url);
819 825
820 service.CreateTestExtensions(1, 1, &extensions, &url, Manifest::INTERNAL); 826 service.CreateTestExtensions(1, num_extensions, &extensions, &url,
827 Manifest::INTERNAL);
821 828
822 const std::string& id = extensions[0]->id(); 829 for (int i = 0; i < num_extensions; ++i) {
823 EXPECT_CALL(delegate, GetPingDataForExtension(id, _)); 830 const std::string& id = extensions[i]->id();
831 EXPECT_CALL(delegate, GetPingDataForExtension(id, _));
824 832
825 downloader.AddExtension(*extensions[0], 0); 833 downloader.AddExtension(*extensions[i], 0, fetch_priority);
834 }
835
826 downloader.StartAllPending(NULL); 836 downloader.StartAllPending(NULL);
827 net::TestURLFetcher* fetcher = 837 net::TestURLFetcher* fetcher =
828 factory.GetFetcherByID(ExtensionDownloader::kManifestFetcherId); 838 factory.GetFetcherByID(ExtensionDownloader::kManifestFetcherId);
829 ASSERT_TRUE(fetcher); 839 ASSERT_TRUE(fetcher);
830 // Make sure that extensions that update from the gallery ignore any 840 // Make sure that extensions that update from the gallery ignore any
831 // update URL data. 841 // update URL data.
832 const std::string& update_url = fetcher->GetOriginalURL().spec(); 842 const std::string& update_url = fetcher->GetOriginalURL().spec();
833 std::string::size_type x = update_url.find("x="); 843 std::string::size_type x = update_url.find("x=");
834 EXPECT_NE(std::string::npos, x); 844 EXPECT_NE(std::string::npos, x);
835 std::string::size_type ap = update_url.find("ap%3D", x); 845 std::string::size_type ap = update_url.find("ap%3D", x);
836 EXPECT_EQ(std::string::npos, ap); 846 EXPECT_EQ(std::string::npos, ap);
847
848 net::HttpRequestHeaders fetch_headers;
849 fetcher->GetExtraRequestHeaders(&fetch_headers);
850 EXPECT_TRUE(fetch_headers.HasHeader(
851 ExtensionDownloader::kUpdateInteractivityHeader));
852 EXPECT_TRUE(
853 fetch_headers.HasHeader(ExtensionDownloader::kUpdateAppIdHeader));
854 EXPECT_TRUE(
855 fetch_headers.HasHeader(ExtensionDownloader::kUpdateUpdaterHeader));
856
857 std::string interactivity_value;
858 fetch_headers.GetHeader(ExtensionDownloader::kUpdateInteractivityHeader,
859 &interactivity_value);
860
861 std::string expected_interactivity_value =
862 fetch_priority == ManifestFetchData::FetchPriority::FOREGROUND ? "fg"
863 : "bg";
864 EXPECT_EQ(expected_interactivity_value, interactivity_value);
865
866 std::string appid_value;
867 fetch_headers.GetHeader(ExtensionDownloader::kUpdateAppIdHeader,
868 &appid_value);
869 if (num_extensions > 1) {
870 for (int i = 0; i < num_extensions; ++i) {
871 EXPECT_TRUE(
872 testing::IsSubstring("", "", extensions[i]->id(), appid_value));
873 }
874 } else {
875 EXPECT_EQ(extensions[0]->id(), appid_value);
876 }
877
878 std::string updater_value;
879 fetch_headers.GetHeader(ExtensionDownloader::kUpdateUpdaterHeader,
880 &updater_value);
881 std::string expected_updater_value = base::StringPrintf(
882 "%s-%s", UpdateQueryParams::GetProdIdString(UpdateQueryParams::CRX),
883 UpdateQueryParams::GetProdVersion().c_str());
884 EXPECT_EQ(expected_updater_value, updater_value);
837 } 885 }
838 886
839 void TestInstallSource() { 887 void TestInstallSource() {
840 const std::string id = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"; 888 const std::string id = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
841 const std::string version = "1.0"; 889 const std::string version = "1.0";
842 const std::string install_source = "instally"; 890 const std::string install_source = "instally";
843 891
844 // Make sure that an installsource= appears in the x= parameter. 892 // Make sure that an installsource= appears in the x= parameter.
845 std::unique_ptr<ManifestFetchData> fetch_data( 893 std::unique_ptr<ManifestFetchData> fetch_data(
846 CreateManifestFetchData(GURL("http://localhost/foo"))); 894 CreateManifestFetchData(GURL("http://localhost/foo")));
847 fetch_data->AddExtension(id, version, &kNeverPingedData, 895 fetch_data->AddExtension(id, version, &kNeverPingedData,
848 kEmptyUpdateUrlData, install_source); 896 kEmptyUpdateUrlData, install_source,
897 ManifestFetchData::FetchPriority::BACKGROUND);
849 std::map<std::string, std::string> params; 898 std::map<std::string, std::string> params;
850 VerifyQueryAndExtractParameters(fetch_data->full_url().query(), &params); 899 VerifyQueryAndExtractParameters(fetch_data->full_url().query(), &params);
851 EXPECT_EQ(id, params["id"]); 900 EXPECT_EQ(id, params["id"]);
852 EXPECT_EQ(version, params["v"]); 901 EXPECT_EQ(version, params["v"]);
853 EXPECT_EQ(install_source, params["installsource"]); 902 EXPECT_EQ(install_source, params["installsource"]);
854 } 903 }
855 904
856 void TestDetermineUpdates() { 905 void TestDetermineUpdates() {
857 TestingProfile profile; 906 TestingProfile profile;
858 MockExtensionDownloaderDelegate delegate; 907 MockExtensionDownloaderDelegate delegate;
859 ExtensionDownloader downloader(&delegate, profile.GetRequestContext()); 908 ExtensionDownloader downloader(&delegate, profile.GetRequestContext());
860 909
861 // Check passing an empty list of parse results to DetermineUpdates 910 // Check passing an empty list of parse results to DetermineUpdates
862 std::unique_ptr<ManifestFetchData> fetch_data( 911 std::unique_ptr<ManifestFetchData> fetch_data(
863 CreateManifestFetchData(GURL("http://localhost/foo"))); 912 CreateManifestFetchData(GURL("http://localhost/foo")));
864 UpdateManifest::Results updates; 913 UpdateManifest::Results updates;
865 std::vector<int> updateable; 914 std::vector<int> updateable;
866 downloader.DetermineUpdates(*fetch_data, updates, &updateable); 915 downloader.DetermineUpdates(*fetch_data, updates, &updateable);
867 EXPECT_TRUE(updateable.empty()); 916 EXPECT_TRUE(updateable.empty());
868 917
869 // Create two updates - expect that DetermineUpdates will return the first 918 // Create two updates - expect that DetermineUpdates will return the first
870 // one (v1.0 installed, v1.1 available) but not the second one (both 919 // one (v1.0 installed, v1.1 available) but not the second one (both
871 // installed and available at v2.0). 920 // installed and available at v2.0).
872 const std::string id1 = crx_file::id_util::GenerateId("1"); 921 const std::string id1 = crx_file::id_util::GenerateId("1");
873 const std::string id2 = crx_file::id_util::GenerateId("2"); 922 const std::string id2 = crx_file::id_util::GenerateId("2");
874 fetch_data->AddExtension(id1, "1.0.0.0", &kNeverPingedData, 923 fetch_data->AddExtension(id1, "1.0.0.0", &kNeverPingedData,
875 kEmptyUpdateUrlData, std::string()); 924 kEmptyUpdateUrlData, std::string(),
925 ManifestFetchData::FetchPriority::BACKGROUND);
876 AddParseResult(id1, "1.1", "http://localhost/e1_1.1.crx", &updates); 926 AddParseResult(id1, "1.1", "http://localhost/e1_1.1.crx", &updates);
877 fetch_data->AddExtension(id2, "2.0.0.0", &kNeverPingedData, 927 fetch_data->AddExtension(id2, "2.0.0.0", &kNeverPingedData,
878 kEmptyUpdateUrlData, std::string()); 928 kEmptyUpdateUrlData, std::string(),
929 ManifestFetchData::FetchPriority::BACKGROUND);
879 AddParseResult(id2, "2.0.0.0", "http://localhost/e2_2.0.crx", &updates); 930 AddParseResult(id2, "2.0.0.0", "http://localhost/e2_2.0.crx", &updates);
880 931
881 EXPECT_CALL(delegate, IsExtensionPending(_)).WillRepeatedly(Return(false)); 932 EXPECT_CALL(delegate, IsExtensionPending(_)).WillRepeatedly(Return(false));
882 EXPECT_CALL(delegate, GetExtensionExistingVersion(id1, _)) 933 EXPECT_CALL(delegate, GetExtensionExistingVersion(id1, _))
883 .WillOnce(DoAll(SetArgPointee<1>("1.0.0.0"), 934 .WillOnce(DoAll(SetArgPointee<1>("1.0.0.0"),
884 Return(true))); 935 Return(true)));
885 EXPECT_CALL(delegate, GetExtensionExistingVersion(id2, _)) 936 EXPECT_CALL(delegate, GetExtensionExistingVersion(id2, _))
886 .WillOnce(DoAll(SetArgPointee<1>("2.0.0.0"), 937 .WillOnce(DoAll(SetArgPointee<1>("2.0.0.0"),
887 Return(true))); 938 Return(true)));
888 939
(...skipping 18 matching lines...) Expand all
907 UpdateManifest::Results updates; 958 UpdateManifest::Results updates;
908 959
909 std::list<std::string> ids_for_update_check; 960 std::list<std::string> ids_for_update_check;
910 pending_extension_manager->GetPendingIdsForUpdateCheck( 961 pending_extension_manager->GetPendingIdsForUpdateCheck(
911 &ids_for_update_check); 962 &ids_for_update_check);
912 963
913 std::list<std::string>::const_iterator it; 964 std::list<std::string>::const_iterator it;
914 for (it = ids_for_update_check.begin(); 965 for (it = ids_for_update_check.begin();
915 it != ids_for_update_check.end(); ++it) { 966 it != ids_for_update_check.end(); ++it) {
916 fetch_data->AddExtension(*it, "1.0.0.0", &kNeverPingedData, 967 fetch_data->AddExtension(*it, "1.0.0.0", &kNeverPingedData,
917 kEmptyUpdateUrlData, std::string()); 968 kEmptyUpdateUrlData, std::string(),
969 ManifestFetchData::FetchPriority::BACKGROUND);
918 AddParseResult(*it, "1.1", "http://localhost/e1_1.1.crx", &updates); 970 AddParseResult(*it, "1.1", "http://localhost/e1_1.1.crx", &updates);
919 } 971 }
920 972
921 // The delegate will tell the downloader that all the extensions are 973 // The delegate will tell the downloader that all the extensions are
922 // pending. 974 // pending.
923 EXPECT_CALL(delegate, IsExtensionPending(_)).WillRepeatedly(Return(true)); 975 EXPECT_CALL(delegate, IsExtensionPending(_)).WillRepeatedly(Return(true));
924 976
925 std::vector<int> updateable; 977 std::vector<int> updateable;
926 downloader.DetermineUpdates(*fetch_data, updates, &updateable); 978 downloader.DetermineUpdates(*fetch_data, updates, &updateable);
927 // All the apps should be updateable. 979 // All the apps should be updateable.
(...skipping 17 matching lines...) Expand all
945 std::unique_ptr<ManifestFetchData> fetch1( 997 std::unique_ptr<ManifestFetchData> fetch1(
946 CreateManifestFetchData(kUpdateUrl)); 998 CreateManifestFetchData(kUpdateUrl));
947 std::unique_ptr<ManifestFetchData> fetch2( 999 std::unique_ptr<ManifestFetchData> fetch2(
948 CreateManifestFetchData(kUpdateUrl)); 1000 CreateManifestFetchData(kUpdateUrl));
949 std::unique_ptr<ManifestFetchData> fetch3( 1001 std::unique_ptr<ManifestFetchData> fetch3(
950 CreateManifestFetchData(kUpdateUrl)); 1002 CreateManifestFetchData(kUpdateUrl));
951 std::unique_ptr<ManifestFetchData> fetch4( 1003 std::unique_ptr<ManifestFetchData> fetch4(
952 CreateManifestFetchData(kUpdateUrl)); 1004 CreateManifestFetchData(kUpdateUrl));
953 ManifestFetchData::PingData zeroDays(0, 0, true, 0); 1005 ManifestFetchData::PingData zeroDays(0, 0, true, 0);
954 fetch1->AddExtension("1111", "1.0", &zeroDays, kEmptyUpdateUrlData, 1006 fetch1->AddExtension("1111", "1.0", &zeroDays, kEmptyUpdateUrlData,
955 std::string()); 1007 std::string(),
1008 ManifestFetchData::FetchPriority::BACKGROUND);
956 fetch2->AddExtension("2222", "2.0", &zeroDays, kEmptyUpdateUrlData, 1009 fetch2->AddExtension("2222", "2.0", &zeroDays, kEmptyUpdateUrlData,
957 std::string()); 1010 std::string(),
1011 ManifestFetchData::FetchPriority::BACKGROUND);
958 fetch3->AddExtension("3333", "3.0", &zeroDays, kEmptyUpdateUrlData, 1012 fetch3->AddExtension("3333", "3.0", &zeroDays, kEmptyUpdateUrlData,
959 std::string()); 1013 std::string(),
1014 ManifestFetchData::FetchPriority::BACKGROUND);
960 fetch4->AddExtension("4444", "4.0", &zeroDays, kEmptyUpdateUrlData, 1015 fetch4->AddExtension("4444", "4.0", &zeroDays, kEmptyUpdateUrlData,
961 std::string()); 1016 std::string(),
1017 ManifestFetchData::FetchPriority::BACKGROUND);
962 1018
963 // This will start the first fetcher and queue the others. The next in queue 1019 // 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 1020 // 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. 1021 // don't necessarily run in the order that they are started from here.
966 GURL fetch1_url = fetch1->full_url(); 1022 GURL fetch1_url = fetch1->full_url();
967 GURL fetch2_url = fetch2->full_url(); 1023 GURL fetch2_url = fetch2->full_url();
968 GURL fetch3_url = fetch3->full_url(); 1024 GURL fetch3_url = fetch3->full_url();
969 GURL fetch4_url = fetch4->full_url(); 1025 GURL fetch4_url = fetch4->full_url();
970 downloader.StartUpdateCheck(std::move(fetch1)); 1026 downloader.StartUpdateCheck(std::move(fetch1));
971 downloader.StartUpdateCheck(std::move(fetch2)); 1027 downloader.StartUpdateCheck(std::move(fetch2));
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
1083 MockExtensionDownloaderDelegate delegate; 1139 MockExtensionDownloaderDelegate delegate;
1084 ExtensionDownloader downloader(&delegate, service.request_context()); 1140 ExtensionDownloader downloader(&delegate, service.request_context());
1085 downloader.manifests_queue_.set_backoff_policy(&kNoBackoffPolicy); 1141 downloader.manifests_queue_.set_backoff_policy(&kNoBackoffPolicy);
1086 1142
1087 GURL kUpdateUrl("http://localhost/manifest1"); 1143 GURL kUpdateUrl("http://localhost/manifest1");
1088 1144
1089 std::unique_ptr<ManifestFetchData> fetch( 1145 std::unique_ptr<ManifestFetchData> fetch(
1090 CreateManifestFetchData(kUpdateUrl)); 1146 CreateManifestFetchData(kUpdateUrl));
1091 ManifestFetchData::PingData zeroDays(0, 0, true, 0); 1147 ManifestFetchData::PingData zeroDays(0, 0, true, 0);
1092 fetch->AddExtension("1111", "1.0", &zeroDays, kEmptyUpdateUrlData, 1148 fetch->AddExtension("1111", "1.0", &zeroDays, kEmptyUpdateUrlData,
1093 std::string()); 1149 std::string(),
1150 ManifestFetchData::FetchPriority::BACKGROUND);
1094 1151
1095 // This will start the first fetcher. 1152 // This will start the first fetcher.
1096 downloader.StartUpdateCheck(std::move(fetch)); 1153 downloader.StartUpdateCheck(std::move(fetch));
1097 RunUntilIdle(); 1154 RunUntilIdle();
1098 1155
1099 // ExtensionDownloader should retry kMaxRetries times and then fail. 1156 // ExtensionDownloader should retry kMaxRetries times and then fail.
1100 EXPECT_CALL(delegate, OnExtensionDownloadFailed( 1157 EXPECT_CALL(delegate, OnExtensionDownloadFailed(
1101 "1111", ExtensionDownloaderDelegate::MANIFEST_FETCH_FAILED, _, _)); 1158 "1111", ExtensionDownloaderDelegate::MANIFEST_FETCH_FAILED, _, _));
1102 for (int i = 0; i <= ExtensionDownloader::kMaxRetries; ++i) { 1159 for (int i = 0; i <= ExtensionDownloader::kMaxRetries; ++i) {
1103 // All fetches will fail. 1160 // All fetches will fail.
1104 fetcher = factory.GetFetcherByID(ExtensionDownloader::kManifestFetcherId); 1161 fetcher = factory.GetFetcherByID(ExtensionDownloader::kManifestFetcherId);
1105 EXPECT_TRUE(fetcher != NULL && fetcher->delegate() != NULL); 1162 EXPECT_TRUE(fetcher != NULL && fetcher->delegate() != NULL);
1106 EXPECT_TRUE(fetcher->GetLoadFlags() == kExpectedLoadFlags); 1163 EXPECT_TRUE(fetcher->GetLoadFlags() == kExpectedLoadFlags);
1107 fetcher->set_url(kUpdateUrl); 1164 fetcher->set_url(kUpdateUrl);
1108 fetcher->set_status(net::URLRequestStatus()); 1165 fetcher->set_status(net::URLRequestStatus());
1109 // Code 5xx causes ExtensionDownloader to retry. 1166 // Code 5xx causes ExtensionDownloader to retry.
1110 fetcher->set_response_code(500); 1167 fetcher->set_response_code(500);
1111 fetcher->delegate()->OnURLFetchComplete(fetcher); 1168 fetcher->delegate()->OnURLFetchComplete(fetcher);
1112 RunUntilIdle(); 1169 RunUntilIdle();
1113 } 1170 }
1114 Mock::VerifyAndClearExpectations(&delegate); 1171 Mock::VerifyAndClearExpectations(&delegate);
1115 1172
1116 1173
1117 // For response codes that are not in the 5xx range ExtensionDownloader 1174 // For response codes that are not in the 5xx range ExtensionDownloader
1118 // should not retry. 1175 // should not retry.
1119 fetch.reset(CreateManifestFetchData(kUpdateUrl)); 1176 fetch.reset(CreateManifestFetchData(kUpdateUrl));
1120 fetch->AddExtension("1111", "1.0", &zeroDays, kEmptyUpdateUrlData, 1177 fetch->AddExtension("1111", "1.0", &zeroDays, kEmptyUpdateUrlData,
1121 std::string()); 1178 std::string(),
1179 ManifestFetchData::FetchPriority::BACKGROUND);
1122 1180
1123 // This will start the first fetcher. 1181 // This will start the first fetcher.
1124 downloader.StartUpdateCheck(std::move(fetch)); 1182 downloader.StartUpdateCheck(std::move(fetch));
1125 RunUntilIdle(); 1183 RunUntilIdle();
1126 1184
1127 EXPECT_CALL(delegate, OnExtensionDownloadFailed( 1185 EXPECT_CALL(delegate, OnExtensionDownloadFailed(
1128 "1111", ExtensionDownloaderDelegate::MANIFEST_FETCH_FAILED, _, _)); 1186 "1111", ExtensionDownloaderDelegate::MANIFEST_FETCH_FAILED, _, _));
1129 // The first fetch will fail, and require retrying. 1187 // The first fetch will fail, and require retrying.
1130 fetcher = factory.GetFetcherByID(ExtensionDownloader::kManifestFetcherId); 1188 fetcher = factory.GetFetcherByID(ExtensionDownloader::kManifestFetcherId);
1131 EXPECT_TRUE(fetcher != NULL && fetcher->delegate() != NULL); 1189 EXPECT_TRUE(fetcher != NULL && fetcher->delegate() != NULL);
(...skipping 640 matching lines...) Expand 10 before | Expand all | Expand 10 after
1772 nullptr, 1830 nullptr,
1773 service.GetDownloaderFactory()); 1831 service.GetDownloaderFactory());
1774 updater.Start(); 1832 updater.Start();
1775 updater.EnsureDownloaderCreated(); 1833 updater.EnsureDownloaderCreated();
1776 1834
1777 std::unique_ptr<ManifestFetchData> fetch_data( 1835 std::unique_ptr<ManifestFetchData> fetch_data(
1778 CreateManifestFetchData(update_url)); 1836 CreateManifestFetchData(update_url));
1779 const Extension* extension = tmp[0].get(); 1837 const Extension* extension = tmp[0].get();
1780 fetch_data->AddExtension(extension->id(), extension->VersionString(), 1838 fetch_data->AddExtension(extension->id(), extension->VersionString(),
1781 &kNeverPingedData, kEmptyUpdateUrlData, 1839 &kNeverPingedData, kEmptyUpdateUrlData,
1782 std::string()); 1840 std::string(),
1841 ManifestFetchData::FetchPriority::BACKGROUND);
1783 UpdateManifest::Results results; 1842 UpdateManifest::Results results;
1784 results.daystart_elapsed_seconds = 750; 1843 results.daystart_elapsed_seconds = 750;
1785 1844
1786 updater.downloader_->HandleManifestResults(fetch_data.get(), &results); 1845 updater.downloader_->HandleManifestResults(fetch_data.get(), &results);
1787 Time last_ping_day = 1846 Time last_ping_day =
1788 service.extension_prefs()->LastPingDay(extension->id()); 1847 service.extension_prefs()->LastPingDay(extension->id());
1789 EXPECT_FALSE(last_ping_day.is_null()); 1848 EXPECT_FALSE(last_ping_day.is_null());
1790 int64_t seconds_diff = (Time::Now() - last_ping_day).InSeconds(); 1849 int64_t seconds_diff = (Time::Now() - last_ping_day).InSeconds();
1791 EXPECT_LT(seconds_diff - results.daystart_elapsed_seconds, 5); 1850 EXPECT_LT(seconds_diff - results.daystart_elapsed_seconds, 5);
1792 } 1851 }
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
1879 ASSERT_TRUE(base::StringToInt(reason_string, &reason)); 1938 ASSERT_TRUE(base::StringToInt(reason_string, &reason));
1880 // Make sure it's a power of 2. 1939 // Make sure it's a power of 2.
1881 ASSERT_TRUE(reason < 2 || !(reason & (reason - 1))) << reason; 1940 ASSERT_TRUE(reason < 2 || !(reason & (reason - 1))) << reason;
1882 found_reasons |= reason; 1941 found_reasons |= reason;
1883 } 1942 }
1884 EXPECT_EQ(disable_reasons, found_reasons); 1943 EXPECT_EQ(disable_reasons, found_reasons);
1885 } 1944 }
1886 } 1945 }
1887 } 1946 }
1888 1947
1948 void TestManifestAddExtension(
1949 ManifestFetchData::FetchPriority data_priority,
1950 ManifestFetchData::FetchPriority extension_priority,
1951 ManifestFetchData::FetchPriority expected_priority) {
1952 const std::string id = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
1953 const std::string version = "1.0";
1954
1955 std::unique_ptr<ManifestFetchData> fetch_data(
1956 CreateManifestFetchData(GURL("http://localhost/foo"), data_priority));
1957 ASSERT_TRUE(fetch_data->AddExtension(id, version, &kNeverPingedData,
1958 std::string(), std::string(),
1959 extension_priority));
1960 ASSERT_EQ(expected_priority, fetch_data->fetch_priority());
1961 }
1962
1963 void TestManifestMerge(ManifestFetchData::FetchPriority data_priority,
1964 ManifestFetchData::FetchPriority other_priority,
1965 ManifestFetchData::FetchPriority expected_priority) {
1966 std::unique_ptr<ManifestFetchData> fetch_data(
1967 CreateManifestFetchData(GURL("http://localhost/foo"), data_priority));
1968
1969 std::unique_ptr<ManifestFetchData> fetch_other(
1970 CreateManifestFetchData(GURL("http://localhost/foo"), other_priority));
1971
1972 fetch_data->Merge(*fetch_other);
1973 ASSERT_EQ(expected_priority, fetch_data->fetch_priority());
1974 }
1975
1889 protected: 1976 protected:
1890 std::unique_ptr<TestExtensionPrefs> prefs_; 1977 std::unique_ptr<TestExtensionPrefs> prefs_;
1891 1978
1892 ManifestFetchData* CreateManifestFetchData(const GURL& update_url) { 1979 ManifestFetchData* CreateManifestFetchData(
1980 const GURL& update_url,
1981 ManifestFetchData::FetchPriority fetch_priority) {
1893 return new ManifestFetchData(update_url, 0, "", 1982 return new ManifestFetchData(update_url, 0, "",
1894 UpdateQueryParams::Get(UpdateQueryParams::CRX), 1983 UpdateQueryParams::Get(UpdateQueryParams::CRX),
1895 ManifestFetchData::PING); 1984 ManifestFetchData::PING, fetch_priority);
1985 }
1986
1987 ManifestFetchData* CreateManifestFetchData(const GURL& update_url) {
1988 return CreateManifestFetchData(
1989 update_url, ManifestFetchData::FetchPriority::BACKGROUND);
1896 } 1990 }
1897 1991
1898 private: 1992 private:
1899 content::TestBrowserThreadBundle thread_bundle_; 1993 content::TestBrowserThreadBundle thread_bundle_;
1900 content::InProcessUtilityThreadHelper in_process_utility_thread_helper_; 1994 content::InProcessUtilityThreadHelper in_process_utility_thread_helper_;
1901 ScopedTestingLocalState testing_local_state_; 1995 ScopedTestingLocalState testing_local_state_;
1902 1996
1903 #if defined OS_CHROMEOS 1997 #if defined OS_CHROMEOS
1904 chromeos::ScopedTestDeviceSettingsService test_device_settings_service_; 1998 chromeos::ScopedTestDeviceSettingsService test_device_settings_service_;
1905 chromeos::ScopedTestCrosSettings test_cros_settings_; 1999 chromeos::ScopedTestCrosSettings test_cros_settings_;
(...skipping 10 matching lines...) Expand all
1916 } 2010 }
1917 2011
1918 TEST_F(ExtensionUpdaterTest, TestExtensionUpdateCheckRequestsPending) { 2012 TEST_F(ExtensionUpdaterTest, TestExtensionUpdateCheckRequestsPending) {
1919 TestExtensionUpdateCheckRequests(true); 2013 TestExtensionUpdateCheckRequests(true);
1920 } 2014 }
1921 2015
1922 TEST_F(ExtensionUpdaterTest, TestUpdateUrlData) { 2016 TEST_F(ExtensionUpdaterTest, TestUpdateUrlData) {
1923 TestUpdateUrlDataEmpty(); 2017 TestUpdateUrlDataEmpty();
1924 TestUpdateUrlDataSimple(); 2018 TestUpdateUrlDataSimple();
1925 TestUpdateUrlDataCompound(); 2019 TestUpdateUrlDataCompound();
1926 TestUpdateUrlDataFromGallery( 2020 TestUpdateUrlDataFromGallery(extension_urls::GetWebstoreUpdateUrl().spec(),
1927 extension_urls::GetWebstoreUpdateUrl().spec()); 2021 ManifestFetchData::FetchPriority::BACKGROUND, 1);
2022 TestUpdateUrlDataFromGallery(extension_urls::GetWebstoreUpdateUrl().spec(),
2023 ManifestFetchData::FetchPriority::FOREGROUND, 1);
2024 TestUpdateUrlDataFromGallery(extension_urls::GetWebstoreUpdateUrl().spec(),
2025 ManifestFetchData::FetchPriority::BACKGROUND, 2);
2026 TestUpdateUrlDataFromGallery(extension_urls::GetWebstoreUpdateUrl().spec(),
2027 ManifestFetchData::FetchPriority::FOREGROUND, 4);
1928 } 2028 }
1929 2029
1930 TEST_F(ExtensionUpdaterTest, TestInstallSource) { 2030 TEST_F(ExtensionUpdaterTest, TestInstallSource) {
1931 TestInstallSource(); 2031 TestInstallSource();
1932 } 2032 }
1933 2033
1934 TEST_F(ExtensionUpdaterTest, TestDetermineUpdates) { 2034 TEST_F(ExtensionUpdaterTest, TestDetermineUpdates) {
1935 TestDetermineUpdates(); 2035 TestDetermineUpdates();
1936 } 2036 }
1937 2037
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after
2125 MockExtensionDownloaderDelegate delegate; 2225 MockExtensionDownloaderDelegate delegate;
2126 std::unique_ptr<ExtensionDownloader> downloader( 2226 std::unique_ptr<ExtensionDownloader> downloader(
2127 new ExtensionDownloader(&delegate, service.request_context())); 2227 new ExtensionDownloader(&delegate, service.request_context()));
2128 EXPECT_EQ(0u, ManifestFetchersCount(downloader.get())); 2228 EXPECT_EQ(0u, ManifestFetchersCount(downloader.get()));
2129 2229
2130 // First, verify that adding valid extensions does invoke the callbacks on 2230 // First, verify that adding valid extensions does invoke the callbacks on
2131 // the delegate. 2231 // the delegate.
2132 std::string id = crx_file::id_util::GenerateId("foo"); 2232 std::string id = crx_file::id_util::GenerateId("foo");
2133 EXPECT_CALL(delegate, GetPingDataForExtension(id, _)).WillOnce(Return(false)); 2233 EXPECT_CALL(delegate, GetPingDataForExtension(id, _)).WillOnce(Return(false));
2134 EXPECT_TRUE(downloader->AddPendingExtension( 2234 EXPECT_TRUE(downloader->AddPendingExtension(
2135 id, GURL("http://example.com/update"), false, 0)); 2235 id, GURL("http://example.com/update"), false, 0,
2236 ManifestFetchData::FetchPriority::BACKGROUND));
2136 downloader->StartAllPending(NULL); 2237 downloader->StartAllPending(NULL);
2137 Mock::VerifyAndClearExpectations(&delegate); 2238 Mock::VerifyAndClearExpectations(&delegate);
2138 EXPECT_EQ(1u, ManifestFetchersCount(downloader.get())); 2239 EXPECT_EQ(1u, ManifestFetchersCount(downloader.get()));
2139 2240
2140 // Extensions with invalid update URLs should be rejected. 2241 // Extensions with invalid update URLs should be rejected.
2141 id = crx_file::id_util::GenerateId("foo2"); 2242 id = crx_file::id_util::GenerateId("foo2");
2142 EXPECT_FALSE(downloader->AddPendingExtension(id, GURL("http:google.com:foo"), 2243 EXPECT_FALSE(downloader->AddPendingExtension(
2143 false, 0)); 2244 id, GURL("http:google.com:foo"), false, 0,
2245 ManifestFetchData::FetchPriority::BACKGROUND));
2144 downloader->StartAllPending(NULL); 2246 downloader->StartAllPending(NULL);
2145 EXPECT_EQ(1u, ManifestFetchersCount(downloader.get())); 2247 EXPECT_EQ(1u, ManifestFetchersCount(downloader.get()));
2146 2248
2147 // Extensions with empty IDs should be rejected. 2249 // Extensions with empty IDs should be rejected.
2148 EXPECT_FALSE( 2250 EXPECT_FALSE(downloader->AddPendingExtension(
2149 downloader->AddPendingExtension(std::string(), GURL(), false, 0)); 2251 std::string(), GURL(), false, 0,
2252 ManifestFetchData::FetchPriority::BACKGROUND));
2150 downloader->StartAllPending(NULL); 2253 downloader->StartAllPending(NULL);
2151 EXPECT_EQ(1u, ManifestFetchersCount(downloader.get())); 2254 EXPECT_EQ(1u, ManifestFetchersCount(downloader.get()));
2152 2255
2153 // TODO(akalin): Test that extensions with empty update URLs 2256 // TODO(akalin): Test that extensions with empty update URLs
2154 // converted from user scripts are rejected. 2257 // converted from user scripts are rejected.
2155 2258
2156 // Reset the ExtensionDownloader so that it drops the current fetcher. 2259 // Reset the ExtensionDownloader so that it drops the current fetcher.
2157 downloader.reset( 2260 downloader.reset(
2158 new ExtensionDownloader(&delegate, service.request_context())); 2261 new ExtensionDownloader(&delegate, service.request_context()));
2159 EXPECT_EQ(0u, ManifestFetchersCount(downloader.get())); 2262 EXPECT_EQ(0u, ManifestFetchersCount(downloader.get()));
2160 2263
2161 // Extensions with empty update URLs should have a default one 2264 // Extensions with empty update URLs should have a default one
2162 // filled in. 2265 // filled in.
2163 id = crx_file::id_util::GenerateId("foo3"); 2266 id = crx_file::id_util::GenerateId("foo3");
2164 EXPECT_CALL(delegate, GetPingDataForExtension(id, _)).WillOnce(Return(false)); 2267 EXPECT_CALL(delegate, GetPingDataForExtension(id, _)).WillOnce(Return(false));
2165 EXPECT_TRUE(downloader->AddPendingExtension(id, GURL(), false, 0)); 2268 EXPECT_TRUE(downloader->AddPendingExtension(
2269 id, GURL(), false, 0, ManifestFetchData::FetchPriority::BACKGROUND));
2166 downloader->StartAllPending(NULL); 2270 downloader->StartAllPending(NULL);
2167 EXPECT_EQ(1u, ManifestFetchersCount(downloader.get())); 2271 EXPECT_EQ(1u, ManifestFetchersCount(downloader.get()));
2168 2272
2169 net::TestURLFetcher* fetcher = 2273 net::TestURLFetcher* fetcher =
2170 factory.GetFetcherByID(ExtensionDownloader::kManifestFetcherId); 2274 factory.GetFetcherByID(ExtensionDownloader::kManifestFetcherId);
2171 ASSERT_TRUE(fetcher); 2275 ASSERT_TRUE(fetcher);
2172 EXPECT_FALSE(fetcher->GetOriginalURL().is_empty()); 2276 EXPECT_FALSE(fetcher->GetOriginalURL().is_empty());
2173 } 2277 }
2174 2278
2175 TEST_F(ExtensionUpdaterTest, TestStartUpdateCheckMemory) { 2279 TEST_F(ExtensionUpdaterTest, TestStartUpdateCheckMemory) {
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
2268 next_check_time.ToInternalValue()); 2372 next_check_time.ToInternalValue());
2269 ServiceForManifestTests service(prefs_.get()); 2373 ServiceForManifestTests service(prefs_.get());
2270 ExtensionUpdater updater(&service, service.extension_prefs(), 2374 ExtensionUpdater updater(&service, service.extension_prefs(),
2271 service.pref_service(), service.profile(), 2375 service.pref_service(), service.profile(),
2272 kDefaultUpdateFrequencySeconds, nullptr, 2376 kDefaultUpdateFrequencySeconds, nullptr,
2273 service.GetDownloaderFactory()); 2377 service.GetDownloaderFactory());
2274 updater.Start(); 2378 updater.Start();
2275 updater.Stop(); 2379 updater.Stop();
2276 } 2380 }
2277 2381
2382 TEST_F(ExtensionUpdaterTest, TestManifestFetchDataAddExtension) {
2383 TestManifestAddExtension(ManifestFetchData::FetchPriority::BACKGROUND,
2384 ManifestFetchData::FetchPriority::BACKGROUND,
2385 ManifestFetchData::FetchPriority::BACKGROUND);
2386
2387 TestManifestAddExtension(ManifestFetchData::FetchPriority::BACKGROUND,
2388 ManifestFetchData::FetchPriority::FOREGROUND,
2389 ManifestFetchData::FetchPriority::FOREGROUND);
2390
2391 TestManifestAddExtension(ManifestFetchData::FetchPriority::FOREGROUND,
2392 ManifestFetchData::FetchPriority::BACKGROUND,
2393 ManifestFetchData::FetchPriority::FOREGROUND);
2394
2395 TestManifestAddExtension(ManifestFetchData::FetchPriority::FOREGROUND,
2396 ManifestFetchData::FetchPriority::FOREGROUND,
2397 ManifestFetchData::FetchPriority::FOREGROUND);
2398 }
2399
2400 TEST_F(ExtensionUpdaterTest, TestManifestFetchDataMerge) {
2401 TestManifestMerge(ManifestFetchData::FetchPriority::BACKGROUND,
2402 ManifestFetchData::FetchPriority::BACKGROUND,
2403 ManifestFetchData::FetchPriority::BACKGROUND);
2404
2405 TestManifestMerge(ManifestFetchData::FetchPriority::BACKGROUND,
2406 ManifestFetchData::FetchPriority::FOREGROUND,
2407 ManifestFetchData::FetchPriority::FOREGROUND);
2408
2409 TestManifestMerge(ManifestFetchData::FetchPriority::FOREGROUND,
2410 ManifestFetchData::FetchPriority::BACKGROUND,
2411 ManifestFetchData::FetchPriority::FOREGROUND);
2412
2413 TestManifestMerge(ManifestFetchData::FetchPriority::FOREGROUND,
2414 ManifestFetchData::FetchPriority::FOREGROUND,
2415 ManifestFetchData::FetchPriority::FOREGROUND);
2416 }
2417
2278 // TODO(asargent) - (http://crbug.com/12780) add tests for: 2418 // TODO(asargent) - (http://crbug.com/12780) add tests for:
2279 // -prodversionmin (shouldn't update if browser version too old) 2419 // -prodversionmin (shouldn't update if browser version too old)
2280 // -manifests & updates arriving out of order / interleaved 2420 // -manifests & updates arriving out of order / interleaved
2281 // -malformed update url (empty, file://, has query, has a # fragment, etc.) 2421 // -malformed update url (empty, file://, has query, has a # fragment, etc.)
2282 // -An extension gets uninstalled while updates are in progress (so it doesn't 2422 // -An extension gets uninstalled while updates are in progress (so it doesn't
2283 // "come back from the dead") 2423 // "come back from the dead")
2284 // -An extension gets manually updated to v3 while we're downloading v2 (ie 2424 // -An extension gets manually updated to v3 while we're downloading v2 (ie
2285 // you don't get downgraded accidentally) 2425 // you don't get downgraded accidentally)
2286 // -An update manifest mentions multiple updates 2426 // -An update manifest mentions multiple updates
2287 2427
2288 } // namespace extensions 2428 } // namespace extensions
OLDNEW
« no previous file with comments | « chrome/browser/extensions/updater/extension_updater.cc ('k') | components/update_client/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698