| 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 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 120 0, | 120 0, |
| 121 | 121 |
| 122 // Time to keep an entry from being discarded even when it | 122 // Time to keep an entry from being discarded even when it |
| 123 // has no significant state, -1 to never discard. | 123 // has no significant state, -1 to never discard. |
| 124 -1, | 124 -1, |
| 125 | 125 |
| 126 // Don't use initial delay unless the last request was an error. | 126 // Don't use initial delay unless the last request was an error. |
| 127 false, | 127 false, |
| 128 }; | 128 }; |
| 129 | 129 |
| 130 const char kEmptyUpdateUrlData[] = ""; | |
| 131 | |
| 132 const char kAuthUserQueryKey[] = "authuser"; | 130 const char kAuthUserQueryKey[] = "authuser"; |
| 133 | 131 |
| 134 int kExpectedLoadFlags = | 132 int kExpectedLoadFlags = |
| 135 net::LOAD_DO_NOT_SEND_COOKIES | | 133 net::LOAD_DO_NOT_SEND_COOKIES | |
| 136 net::LOAD_DO_NOT_SAVE_COOKIES | | 134 net::LOAD_DO_NOT_SAVE_COOKIES | |
| 137 net::LOAD_DISABLE_CACHE; | 135 net::LOAD_DISABLE_CACHE; |
| 138 | 136 |
| 139 int kExpectedLoadFlagsForDownloadWithCookies = net::LOAD_DISABLE_CACHE; | 137 int kExpectedLoadFlagsForDownloadWithCookies = net::LOAD_DISABLE_CACHE; |
| 140 | 138 |
| 141 // Fake authentication constants | 139 // Fake authentication constants |
| (...skipping 614 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 756 | 754 |
| 757 void TestUpdateUrlDataEmpty() { | 755 void TestUpdateUrlDataEmpty() { |
| 758 const std::string id = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"; | 756 const std::string id = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"; |
| 759 const std::string version = "1.0"; | 757 const std::string version = "1.0"; |
| 760 | 758 |
| 761 // Make sure that an empty update URL data string does not cause a ap= | 759 // Make sure that an empty update URL data string does not cause a ap= |
| 762 // option to appear in the x= parameter. | 760 // option to appear in the x= parameter. |
| 763 std::unique_ptr<ManifestFetchData> fetch_data( | 761 std::unique_ptr<ManifestFetchData> fetch_data( |
| 764 CreateManifestFetchData(GURL("http://localhost/foo"))); | 762 CreateManifestFetchData(GURL("http://localhost/foo"))); |
| 765 fetch_data->AddExtension(id, version, &kNeverPingedData, std::string(), | 763 fetch_data->AddExtension(id, version, &kNeverPingedData, std::string(), |
| 766 std::string()); | 764 nullptr); |
| 767 | 765 |
| 768 std::map<std::string, std::string> params; | 766 std::map<std::string, std::string> params; |
| 769 VerifyQueryAndExtractParameters(fetch_data->full_url().query(), ¶ms); | 767 VerifyQueryAndExtractParameters(fetch_data->full_url().query(), ¶ms); |
| 770 EXPECT_EQ(id, params["id"]); | 768 EXPECT_EQ(id, params["id"]); |
| 771 EXPECT_EQ(version, params["v"]); | 769 EXPECT_EQ(version, params["v"]); |
| 772 EXPECT_EQ(0U, params.count("ap")); | 770 EXPECT_EQ(0U, params.count("ap")); |
| 773 } | 771 } |
| 774 | 772 |
| 775 void TestUpdateUrlDataSimple() { | 773 void TestUpdateUrlDataSimple() { |
| 776 const std::string id = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"; | 774 const std::string id = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"; |
| 777 const std::string version = "1.0"; | 775 const std::string version = "1.0"; |
| 778 | 776 |
| 779 // Make sure that an update URL data string causes an appropriate ap= | 777 // Make sure that an update URL data string causes an appropriate ap= |
| 780 // option to appear in the x= parameter. | 778 // option to appear in the x= parameter. |
| 781 std::unique_ptr<ManifestFetchData> fetch_data( | 779 std::unique_ptr<ManifestFetchData> fetch_data( |
| 782 CreateManifestFetchData(GURL("http://localhost/foo"))); | 780 CreateManifestFetchData(GURL("http://localhost/foo"))); |
| 783 fetch_data->AddExtension(id, version, &kNeverPingedData, "bar", | 781 ManifestFetchData::ExtraParams extra; |
| 784 std::string()); | 782 extra.update_url_data = std::string("bar"); |
| 783 fetch_data->AddExtension(id, version, &kNeverPingedData, std::string(), |
| 784 &extra); |
| 785 std::map<std::string, std::string> params; | 785 std::map<std::string, std::string> params; |
| 786 VerifyQueryAndExtractParameters(fetch_data->full_url().query(), ¶ms); | 786 VerifyQueryAndExtractParameters(fetch_data->full_url().query(), ¶ms); |
| 787 EXPECT_EQ(id, params["id"]); | 787 EXPECT_EQ(id, params["id"]); |
| 788 EXPECT_EQ(version, params["v"]); | 788 EXPECT_EQ(version, params["v"]); |
| 789 EXPECT_EQ("bar", params["ap"]); | 789 EXPECT_EQ("bar", params["ap"]); |
| 790 } | 790 } |
| 791 | 791 |
| 792 void TestUpdateUrlDataCompound() { | 792 void TestUpdateUrlDataCompound() { |
| 793 const std::string id = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"; | 793 const std::string id = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"; |
| 794 const std::string version = "1.0"; | 794 const std::string version = "1.0"; |
| 795 | 795 |
| 796 // Make sure that an update URL data string causes an appropriate ap= | 796 // Make sure that an update URL data string causes an appropriate ap= |
| 797 // option to appear in the x= parameter. | 797 // option to appear in the x= parameter. |
| 798 std::unique_ptr<ManifestFetchData> fetch_data( | 798 std::unique_ptr<ManifestFetchData> fetch_data( |
| 799 CreateManifestFetchData(GURL("http://localhost/foo"))); | 799 CreateManifestFetchData(GURL("http://localhost/foo"))); |
| 800 fetch_data->AddExtension(id, version, &kNeverPingedData, "a=1&b=2&c", | 800 ManifestFetchData::ExtraParams extra; |
| 801 std::string()); | 801 extra.update_url_data = std::string("a=1&b=2&c"); |
| 802 fetch_data->AddExtension(id, version, &kNeverPingedData, std::string(), |
| 803 &extra); |
| 802 std::map<std::string, std::string> params; | 804 std::map<std::string, std::string> params; |
| 803 VerifyQueryAndExtractParameters(fetch_data->full_url().query(), ¶ms); | 805 VerifyQueryAndExtractParameters(fetch_data->full_url().query(), ¶ms); |
| 804 EXPECT_EQ(id, params["id"]); | 806 EXPECT_EQ(id, params["id"]); |
| 805 EXPECT_EQ(version, params["v"]); | 807 EXPECT_EQ(version, params["v"]); |
| 806 EXPECT_EQ("a%3D1%26b%3D2%26c", params["ap"]); | 808 EXPECT_EQ("a%3D1%26b%3D2%26c", params["ap"]); |
| 807 } | 809 } |
| 808 | 810 |
| 809 void TestUpdateUrlDataFromGallery(const std::string& gallery_url) { | 811 void TestUpdateUrlDataFromGallery(const std::string& gallery_url) { |
| 810 net::TestURLFetcherFactory factory; | 812 net::TestURLFetcherFactory factory; |
| 811 | 813 |
| (...skipping 23 matching lines...) Expand all Loading... |
| 835 } | 837 } |
| 836 | 838 |
| 837 void TestInstallSource() { | 839 void TestInstallSource() { |
| 838 const std::string id = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"; | 840 const std::string id = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"; |
| 839 const std::string version = "1.0"; | 841 const std::string version = "1.0"; |
| 840 const std::string install_source = "instally"; | 842 const std::string install_source = "instally"; |
| 841 | 843 |
| 842 // Make sure that an installsource= appears in the x= parameter. | 844 // Make sure that an installsource= appears in the x= parameter. |
| 843 std::unique_ptr<ManifestFetchData> fetch_data( | 845 std::unique_ptr<ManifestFetchData> fetch_data( |
| 844 CreateManifestFetchData(GURL("http://localhost/foo"))); | 846 CreateManifestFetchData(GURL("http://localhost/foo"))); |
| 845 fetch_data->AddExtension(id, version, &kNeverPingedData, | 847 fetch_data->AddExtension(id, version, &kNeverPingedData, install_source, |
| 846 kEmptyUpdateUrlData, install_source); | 848 nullptr); |
| 847 std::map<std::string, std::string> params; | 849 std::map<std::string, std::string> params; |
| 848 VerifyQueryAndExtractParameters(fetch_data->full_url().query(), ¶ms); | 850 VerifyQueryAndExtractParameters(fetch_data->full_url().query(), ¶ms); |
| 849 EXPECT_EQ(id, params["id"]); | 851 EXPECT_EQ(id, params["id"]); |
| 850 EXPECT_EQ(version, params["v"]); | 852 EXPECT_EQ(version, params["v"]); |
| 851 EXPECT_EQ(install_source, params["installsource"]); | 853 EXPECT_EQ(install_source, params["installsource"]); |
| 852 } | 854 } |
| 853 | 855 |
| 854 void TestDetermineUpdates() { | 856 void TestDetermineUpdates() { |
| 855 TestingProfile profile; | 857 TestingProfile profile; |
| 856 MockExtensionDownloaderDelegate delegate; | 858 MockExtensionDownloaderDelegate delegate; |
| 857 ExtensionDownloader downloader(&delegate, profile.GetRequestContext()); | 859 ExtensionDownloader downloader(&delegate, profile.GetRequestContext()); |
| 858 | 860 |
| 859 // Check passing an empty list of parse results to DetermineUpdates | 861 // Check passing an empty list of parse results to DetermineUpdates |
| 860 std::unique_ptr<ManifestFetchData> fetch_data( | 862 std::unique_ptr<ManifestFetchData> fetch_data( |
| 861 CreateManifestFetchData(GURL("http://localhost/foo"))); | 863 CreateManifestFetchData(GURL("http://localhost/foo"))); |
| 862 UpdateManifest::Results updates; | 864 UpdateManifest::Results updates; |
| 863 std::vector<int> updateable; | 865 std::vector<int> updateable; |
| 864 downloader.DetermineUpdates(*fetch_data, updates, &updateable); | 866 downloader.DetermineUpdates(*fetch_data, updates, &updateable); |
| 865 EXPECT_TRUE(updateable.empty()); | 867 EXPECT_TRUE(updateable.empty()); |
| 866 | 868 |
| 867 // Create two updates - expect that DetermineUpdates will return the first | 869 // Create two updates - expect that DetermineUpdates will return the first |
| 868 // one (v1.0 installed, v1.1 available) but not the second one (both | 870 // one (v1.0 installed, v1.1 available) but not the second one (both |
| 869 // installed and available at v2.0). | 871 // installed and available at v2.0). |
| 870 const std::string id1 = crx_file::id_util::GenerateId("1"); | 872 const std::string id1 = crx_file::id_util::GenerateId("1"); |
| 871 const std::string id2 = crx_file::id_util::GenerateId("2"); | 873 const std::string id2 = crx_file::id_util::GenerateId("2"); |
| 872 fetch_data->AddExtension(id1, "1.0.0.0", &kNeverPingedData, | 874 fetch_data->AddExtension(id1, "1.0.0.0", &kNeverPingedData, std::string(), |
| 873 kEmptyUpdateUrlData, std::string()); | 875 nullptr); |
| 874 AddParseResult(id1, "1.1", "http://localhost/e1_1.1.crx", &updates); | 876 AddParseResult(id1, "1.1", "http://localhost/e1_1.1.crx", &updates); |
| 875 fetch_data->AddExtension(id2, "2.0.0.0", &kNeverPingedData, | 877 fetch_data->AddExtension(id2, "2.0.0.0", &kNeverPingedData, std::string(), |
| 876 kEmptyUpdateUrlData, std::string()); | 878 nullptr); |
| 877 AddParseResult(id2, "2.0.0.0", "http://localhost/e2_2.0.crx", &updates); | 879 AddParseResult(id2, "2.0.0.0", "http://localhost/e2_2.0.crx", &updates); |
| 878 | 880 |
| 879 EXPECT_CALL(delegate, IsExtensionPending(_)).WillRepeatedly(Return(false)); | 881 EXPECT_CALL(delegate, IsExtensionPending(_)).WillRepeatedly(Return(false)); |
| 880 EXPECT_CALL(delegate, GetExtensionExistingVersion(id1, _)) | 882 EXPECT_CALL(delegate, GetExtensionExistingVersion(id1, _)) |
| 881 .WillOnce(DoAll(SetArgPointee<1>("1.0.0.0"), | 883 .WillOnce(DoAll(SetArgPointee<1>("1.0.0.0"), |
| 882 Return(true))); | 884 Return(true))); |
| 883 EXPECT_CALL(delegate, GetExtensionExistingVersion(id2, _)) | 885 EXPECT_CALL(delegate, GetExtensionExistingVersion(id2, _)) |
| 884 .WillOnce(DoAll(SetArgPointee<1>("2.0.0.0"), | 886 .WillOnce(DoAll(SetArgPointee<1>("2.0.0.0"), |
| 885 Return(true))); | 887 Return(true))); |
| 886 | 888 |
| (...skipping 17 matching lines...) Expand all Loading... |
| 904 CreateManifestFetchData(GURL("http://localhost/foo"))); | 906 CreateManifestFetchData(GURL("http://localhost/foo"))); |
| 905 UpdateManifest::Results updates; | 907 UpdateManifest::Results updates; |
| 906 | 908 |
| 907 std::list<std::string> ids_for_update_check; | 909 std::list<std::string> ids_for_update_check; |
| 908 pending_extension_manager->GetPendingIdsForUpdateCheck( | 910 pending_extension_manager->GetPendingIdsForUpdateCheck( |
| 909 &ids_for_update_check); | 911 &ids_for_update_check); |
| 910 | 912 |
| 911 std::list<std::string>::const_iterator it; | 913 std::list<std::string>::const_iterator it; |
| 912 for (it = ids_for_update_check.begin(); | 914 for (it = ids_for_update_check.begin(); |
| 913 it != ids_for_update_check.end(); ++it) { | 915 it != ids_for_update_check.end(); ++it) { |
| 914 fetch_data->AddExtension(*it, "1.0.0.0", &kNeverPingedData, | 916 fetch_data->AddExtension(*it, "1.0.0.0", &kNeverPingedData, std::string(), |
| 915 kEmptyUpdateUrlData, std::string()); | 917 nullptr); |
| 916 AddParseResult(*it, "1.1", "http://localhost/e1_1.1.crx", &updates); | 918 AddParseResult(*it, "1.1", "http://localhost/e1_1.1.crx", &updates); |
| 917 } | 919 } |
| 918 | 920 |
| 919 // The delegate will tell the downloader that all the extensions are | 921 // The delegate will tell the downloader that all the extensions are |
| 920 // pending. | 922 // pending. |
| 921 EXPECT_CALL(delegate, IsExtensionPending(_)).WillRepeatedly(Return(true)); | 923 EXPECT_CALL(delegate, IsExtensionPending(_)).WillRepeatedly(Return(true)); |
| 922 | 924 |
| 923 std::vector<int> updateable; | 925 std::vector<int> updateable; |
| 924 downloader.DetermineUpdates(*fetch_data, updates, &updateable); | 926 downloader.DetermineUpdates(*fetch_data, updates, &updateable); |
| 925 // All the apps should be updateable. | 927 // All the apps should be updateable. |
| (...skipping 16 matching lines...) Expand all Loading... |
| 942 | 944 |
| 943 std::unique_ptr<ManifestFetchData> fetch1( | 945 std::unique_ptr<ManifestFetchData> fetch1( |
| 944 CreateManifestFetchData(kUpdateUrl)); | 946 CreateManifestFetchData(kUpdateUrl)); |
| 945 std::unique_ptr<ManifestFetchData> fetch2( | 947 std::unique_ptr<ManifestFetchData> fetch2( |
| 946 CreateManifestFetchData(kUpdateUrl)); | 948 CreateManifestFetchData(kUpdateUrl)); |
| 947 std::unique_ptr<ManifestFetchData> fetch3( | 949 std::unique_ptr<ManifestFetchData> fetch3( |
| 948 CreateManifestFetchData(kUpdateUrl)); | 950 CreateManifestFetchData(kUpdateUrl)); |
| 949 std::unique_ptr<ManifestFetchData> fetch4( | 951 std::unique_ptr<ManifestFetchData> fetch4( |
| 950 CreateManifestFetchData(kUpdateUrl)); | 952 CreateManifestFetchData(kUpdateUrl)); |
| 951 ManifestFetchData::PingData zeroDays(0, 0, true, 0); | 953 ManifestFetchData::PingData zeroDays(0, 0, true, 0); |
| 952 fetch1->AddExtension("1111", "1.0", &zeroDays, kEmptyUpdateUrlData, | 954 fetch1->AddExtension("1111", "1.0", &zeroDays, std::string(), nullptr); |
| 953 std::string()); | 955 fetch2->AddExtension("2222", "2.0", &zeroDays, std::string(), nullptr); |
| 954 fetch2->AddExtension("2222", "2.0", &zeroDays, kEmptyUpdateUrlData, | 956 fetch3->AddExtension("3333", "3.0", &zeroDays, std::string(), nullptr); |
| 955 std::string()); | 957 fetch4->AddExtension("4444", "4.0", &zeroDays, std::string(), nullptr); |
| 956 fetch3->AddExtension("3333", "3.0", &zeroDays, kEmptyUpdateUrlData, | |
| 957 std::string()); | |
| 958 fetch4->AddExtension("4444", "4.0", &zeroDays, kEmptyUpdateUrlData, | |
| 959 std::string()); | |
| 960 | 958 |
| 961 // This will start the first fetcher and queue the others. The next in queue | 959 // This will start the first fetcher and queue the others. The next in queue |
| 962 // is started as each fetcher receives its response. Note that the fetchers | 960 // is started as each fetcher receives its response. Note that the fetchers |
| 963 // don't necessarily run in the order that they are started from here. | 961 // don't necessarily run in the order that they are started from here. |
| 964 GURL fetch1_url = fetch1->full_url(); | 962 GURL fetch1_url = fetch1->full_url(); |
| 965 GURL fetch2_url = fetch2->full_url(); | 963 GURL fetch2_url = fetch2->full_url(); |
| 966 GURL fetch3_url = fetch3->full_url(); | 964 GURL fetch3_url = fetch3->full_url(); |
| 967 GURL fetch4_url = fetch4->full_url(); | 965 GURL fetch4_url = fetch4->full_url(); |
| 968 downloader.StartUpdateCheck(std::move(fetch1)); | 966 downloader.StartUpdateCheck(std::move(fetch1)); |
| 969 downloader.StartUpdateCheck(std::move(fetch2)); | 967 downloader.StartUpdateCheck(std::move(fetch2)); |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1080 MockService service(prefs_.get()); | 1078 MockService service(prefs_.get()); |
| 1081 MockExtensionDownloaderDelegate delegate; | 1079 MockExtensionDownloaderDelegate delegate; |
| 1082 ExtensionDownloader downloader(&delegate, service.request_context()); | 1080 ExtensionDownloader downloader(&delegate, service.request_context()); |
| 1083 downloader.manifests_queue_.set_backoff_policy(&kNoBackoffPolicy); | 1081 downloader.manifests_queue_.set_backoff_policy(&kNoBackoffPolicy); |
| 1084 | 1082 |
| 1085 GURL kUpdateUrl("http://localhost/manifest1"); | 1083 GURL kUpdateUrl("http://localhost/manifest1"); |
| 1086 | 1084 |
| 1087 std::unique_ptr<ManifestFetchData> fetch( | 1085 std::unique_ptr<ManifestFetchData> fetch( |
| 1088 CreateManifestFetchData(kUpdateUrl)); | 1086 CreateManifestFetchData(kUpdateUrl)); |
| 1089 ManifestFetchData::PingData zeroDays(0, 0, true, 0); | 1087 ManifestFetchData::PingData zeroDays(0, 0, true, 0); |
| 1090 fetch->AddExtension("1111", "1.0", &zeroDays, kEmptyUpdateUrlData, | 1088 fetch->AddExtension("1111", "1.0", &zeroDays, std::string(), nullptr); |
| 1091 std::string()); | |
| 1092 | 1089 |
| 1093 // This will start the first fetcher. | 1090 // This will start the first fetcher. |
| 1094 downloader.StartUpdateCheck(std::move(fetch)); | 1091 downloader.StartUpdateCheck(std::move(fetch)); |
| 1095 RunUntilIdle(); | 1092 RunUntilIdle(); |
| 1096 | 1093 |
| 1097 // ExtensionDownloader should retry kMaxRetries times and then fail. | 1094 // ExtensionDownloader should retry kMaxRetries times and then fail. |
| 1098 EXPECT_CALL(delegate, OnExtensionDownloadFailed( | 1095 EXPECT_CALL(delegate, OnExtensionDownloadFailed( |
| 1099 "1111", ExtensionDownloaderDelegate::MANIFEST_FETCH_FAILED, _, _)); | 1096 "1111", ExtensionDownloaderDelegate::MANIFEST_FETCH_FAILED, _, _)); |
| 1100 for (int i = 0; i <= ExtensionDownloader::kMaxRetries; ++i) { | 1097 for (int i = 0; i <= ExtensionDownloader::kMaxRetries; ++i) { |
| 1101 // All fetches will fail. | 1098 // All fetches will fail. |
| 1102 fetcher = factory.GetFetcherByID(ExtensionDownloader::kManifestFetcherId); | 1099 fetcher = factory.GetFetcherByID(ExtensionDownloader::kManifestFetcherId); |
| 1103 EXPECT_TRUE(fetcher != NULL && fetcher->delegate() != NULL); | 1100 EXPECT_TRUE(fetcher != NULL && fetcher->delegate() != NULL); |
| 1104 EXPECT_TRUE(fetcher->GetLoadFlags() == kExpectedLoadFlags); | 1101 EXPECT_TRUE(fetcher->GetLoadFlags() == kExpectedLoadFlags); |
| 1105 fetcher->set_url(kUpdateUrl); | 1102 fetcher->set_url(kUpdateUrl); |
| 1106 fetcher->set_status(net::URLRequestStatus()); | 1103 fetcher->set_status(net::URLRequestStatus()); |
| 1107 // Code 5xx causes ExtensionDownloader to retry. | 1104 // Code 5xx causes ExtensionDownloader to retry. |
| 1108 fetcher->set_response_code(500); | 1105 fetcher->set_response_code(500); |
| 1109 fetcher->delegate()->OnURLFetchComplete(fetcher); | 1106 fetcher->delegate()->OnURLFetchComplete(fetcher); |
| 1110 RunUntilIdle(); | 1107 RunUntilIdle(); |
| 1111 } | 1108 } |
| 1112 Mock::VerifyAndClearExpectations(&delegate); | 1109 Mock::VerifyAndClearExpectations(&delegate); |
| 1113 | 1110 |
| 1114 | 1111 |
| 1115 // For response codes that are not in the 5xx range ExtensionDownloader | 1112 // For response codes that are not in the 5xx range ExtensionDownloader |
| 1116 // should not retry. | 1113 // should not retry. |
| 1117 fetch.reset(CreateManifestFetchData(kUpdateUrl)); | 1114 fetch.reset(CreateManifestFetchData(kUpdateUrl)); |
| 1118 fetch->AddExtension("1111", "1.0", &zeroDays, kEmptyUpdateUrlData, | 1115 fetch->AddExtension("1111", "1.0", &zeroDays, std::string(), nullptr); |
| 1119 std::string()); | |
| 1120 | 1116 |
| 1121 // This will start the first fetcher. | 1117 // This will start the first fetcher. |
| 1122 downloader.StartUpdateCheck(std::move(fetch)); | 1118 downloader.StartUpdateCheck(std::move(fetch)); |
| 1123 RunUntilIdle(); | 1119 RunUntilIdle(); |
| 1124 | 1120 |
| 1125 EXPECT_CALL(delegate, OnExtensionDownloadFailed( | 1121 EXPECT_CALL(delegate, OnExtensionDownloadFailed( |
| 1126 "1111", ExtensionDownloaderDelegate::MANIFEST_FETCH_FAILED, _, _)); | 1122 "1111", ExtensionDownloaderDelegate::MANIFEST_FETCH_FAILED, _, _)); |
| 1127 // The first fetch will fail, and require retrying. | 1123 // The first fetch will fail, and require retrying. |
| 1128 fetcher = factory.GetFetcherByID(ExtensionDownloader::kManifestFetcherId); | 1124 fetcher = factory.GetFetcherByID(ExtensionDownloader::kManifestFetcherId); |
| 1129 EXPECT_TRUE(fetcher != NULL && fetcher->delegate() != NULL); | 1125 EXPECT_TRUE(fetcher != NULL && fetcher->delegate() != NULL); |
| (...skipping 641 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1771 kUpdateFrequencySecs, | 1767 kUpdateFrequencySecs, |
| 1772 nullptr, | 1768 nullptr, |
| 1773 service.GetDownloaderFactory()); | 1769 service.GetDownloaderFactory()); |
| 1774 updater.Start(); | 1770 updater.Start(); |
| 1775 updater.EnsureDownloaderCreated(); | 1771 updater.EnsureDownloaderCreated(); |
| 1776 | 1772 |
| 1777 std::unique_ptr<ManifestFetchData> fetch_data( | 1773 std::unique_ptr<ManifestFetchData> fetch_data( |
| 1778 CreateManifestFetchData(update_url)); | 1774 CreateManifestFetchData(update_url)); |
| 1779 const Extension* extension = tmp[0].get(); | 1775 const Extension* extension = tmp[0].get(); |
| 1780 fetch_data->AddExtension(extension->id(), extension->VersionString(), | 1776 fetch_data->AddExtension(extension->id(), extension->VersionString(), |
| 1781 &kNeverPingedData, kEmptyUpdateUrlData, | 1777 &kNeverPingedData, std::string(), nullptr); |
| 1782 std::string()); | |
| 1783 UpdateManifest::Results results; | 1778 UpdateManifest::Results results; |
| 1784 results.daystart_elapsed_seconds = 750; | 1779 results.daystart_elapsed_seconds = 750; |
| 1785 | 1780 |
| 1786 updater.downloader_->HandleManifestResults(fetch_data.get(), &results); | 1781 updater.downloader_->HandleManifestResults(fetch_data.get(), &results); |
| 1787 Time last_ping_day = | 1782 Time last_ping_day = |
| 1788 service.extension_prefs()->LastPingDay(extension->id()); | 1783 service.extension_prefs()->LastPingDay(extension->id()); |
| 1789 EXPECT_FALSE(last_ping_day.is_null()); | 1784 EXPECT_FALSE(last_ping_day.is_null()); |
| 1790 int64_t seconds_diff = (Time::Now() - last_ping_day).InSeconds(); | 1785 int64_t seconds_diff = (Time::Now() - last_ping_day).InSeconds(); |
| 1791 EXPECT_LT(seconds_diff - results.daystart_elapsed_seconds, 5); | 1786 EXPECT_LT(seconds_diff - results.daystart_elapsed_seconds, 5); |
| 1792 } | 1787 } |
| (...skipping 331 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2124 MockService service(prefs_.get()); | 2119 MockService service(prefs_.get()); |
| 2125 MockExtensionDownloaderDelegate delegate; | 2120 MockExtensionDownloaderDelegate delegate; |
| 2126 std::unique_ptr<ExtensionDownloader> downloader( | 2121 std::unique_ptr<ExtensionDownloader> downloader( |
| 2127 new ExtensionDownloader(&delegate, service.request_context())); | 2122 new ExtensionDownloader(&delegate, service.request_context())); |
| 2128 EXPECT_EQ(0u, ManifestFetchersCount(downloader.get())); | 2123 EXPECT_EQ(0u, ManifestFetchersCount(downloader.get())); |
| 2129 | 2124 |
| 2130 // First, verify that adding valid extensions does invoke the callbacks on | 2125 // First, verify that adding valid extensions does invoke the callbacks on |
| 2131 // the delegate. | 2126 // the delegate. |
| 2132 std::string id = crx_file::id_util::GenerateId("foo"); | 2127 std::string id = crx_file::id_util::GenerateId("foo"); |
| 2133 EXPECT_CALL(delegate, GetPingDataForExtension(id, _)).WillOnce(Return(false)); | 2128 EXPECT_CALL(delegate, GetPingDataForExtension(id, _)).WillOnce(Return(false)); |
| 2134 EXPECT_TRUE( | 2129 EXPECT_TRUE(downloader->AddPendingExtension( |
| 2135 downloader->AddPendingExtension(id, GURL("http://example.com/update"), | 2130 id, GURL("http://example.com/update"), false, 0)); |
| 2136 0)); | |
| 2137 downloader->StartAllPending(NULL); | 2131 downloader->StartAllPending(NULL); |
| 2138 Mock::VerifyAndClearExpectations(&delegate); | 2132 Mock::VerifyAndClearExpectations(&delegate); |
| 2139 EXPECT_EQ(1u, ManifestFetchersCount(downloader.get())); | 2133 EXPECT_EQ(1u, ManifestFetchersCount(downloader.get())); |
| 2140 | 2134 |
| 2141 // Extensions with invalid update URLs should be rejected. | 2135 // Extensions with invalid update URLs should be rejected. |
| 2142 id = crx_file::id_util::GenerateId("foo2"); | 2136 id = crx_file::id_util::GenerateId("foo2"); |
| 2143 EXPECT_FALSE( | 2137 EXPECT_FALSE(downloader->AddPendingExtension(id, GURL("http:google.com:foo"), |
| 2144 downloader->AddPendingExtension(id, GURL("http:google.com:foo"), 0)); | 2138 false, 0)); |
| 2145 downloader->StartAllPending(NULL); | 2139 downloader->StartAllPending(NULL); |
| 2146 EXPECT_EQ(1u, ManifestFetchersCount(downloader.get())); | 2140 EXPECT_EQ(1u, ManifestFetchersCount(downloader.get())); |
| 2147 | 2141 |
| 2148 // Extensions with empty IDs should be rejected. | 2142 // Extensions with empty IDs should be rejected. |
| 2149 EXPECT_FALSE(downloader->AddPendingExtension(std::string(), GURL(), 0)); | 2143 EXPECT_FALSE( |
| 2144 downloader->AddPendingExtension(std::string(), GURL(), false, 0)); |
| 2150 downloader->StartAllPending(NULL); | 2145 downloader->StartAllPending(NULL); |
| 2151 EXPECT_EQ(1u, ManifestFetchersCount(downloader.get())); | 2146 EXPECT_EQ(1u, ManifestFetchersCount(downloader.get())); |
| 2152 | 2147 |
| 2153 // TODO(akalin): Test that extensions with empty update URLs | 2148 // TODO(akalin): Test that extensions with empty update URLs |
| 2154 // converted from user scripts are rejected. | 2149 // converted from user scripts are rejected. |
| 2155 | 2150 |
| 2156 // Reset the ExtensionDownloader so that it drops the current fetcher. | 2151 // Reset the ExtensionDownloader so that it drops the current fetcher. |
| 2157 downloader.reset( | 2152 downloader.reset( |
| 2158 new ExtensionDownloader(&delegate, service.request_context())); | 2153 new ExtensionDownloader(&delegate, service.request_context())); |
| 2159 EXPECT_EQ(0u, ManifestFetchersCount(downloader.get())); | 2154 EXPECT_EQ(0u, ManifestFetchersCount(downloader.get())); |
| 2160 | 2155 |
| 2161 // Extensions with empty update URLs should have a default one | 2156 // Extensions with empty update URLs should have a default one |
| 2162 // filled in. | 2157 // filled in. |
| 2163 id = crx_file::id_util::GenerateId("foo3"); | 2158 id = crx_file::id_util::GenerateId("foo3"); |
| 2164 EXPECT_CALL(delegate, GetPingDataForExtension(id, _)).WillOnce(Return(false)); | 2159 EXPECT_CALL(delegate, GetPingDataForExtension(id, _)).WillOnce(Return(false)); |
| 2165 EXPECT_TRUE(downloader->AddPendingExtension(id, GURL(), 0)); | 2160 EXPECT_TRUE(downloader->AddPendingExtension(id, GURL(), false, 0)); |
| 2166 downloader->StartAllPending(NULL); | 2161 downloader->StartAllPending(NULL); |
| 2167 EXPECT_EQ(1u, ManifestFetchersCount(downloader.get())); | 2162 EXPECT_EQ(1u, ManifestFetchersCount(downloader.get())); |
| 2168 | 2163 |
| 2169 net::TestURLFetcher* fetcher = | 2164 net::TestURLFetcher* fetcher = |
| 2170 factory.GetFetcherByID(ExtensionDownloader::kManifestFetcherId); | 2165 factory.GetFetcherByID(ExtensionDownloader::kManifestFetcherId); |
| 2171 ASSERT_TRUE(fetcher); | 2166 ASSERT_TRUE(fetcher); |
| 2172 EXPECT_FALSE(fetcher->GetOriginalURL().is_empty()); | 2167 EXPECT_FALSE(fetcher->GetOriginalURL().is_empty()); |
| 2173 } | 2168 } |
| 2174 | 2169 |
| 2175 TEST_F(ExtensionUpdaterTest, TestStartUpdateCheckMemory) { | 2170 TEST_F(ExtensionUpdaterTest, TestStartUpdateCheckMemory) { |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2263 // -prodversionmin (shouldn't update if browser version too old) | 2258 // -prodversionmin (shouldn't update if browser version too old) |
| 2264 // -manifests & updates arriving out of order / interleaved | 2259 // -manifests & updates arriving out of order / interleaved |
| 2265 // -malformed update url (empty, file://, has query, has a # fragment, etc.) | 2260 // -malformed update url (empty, file://, has query, has a # fragment, etc.) |
| 2266 // -An extension gets uninstalled while updates are in progress (so it doesn't | 2261 // -An extension gets uninstalled while updates are in progress (so it doesn't |
| 2267 // "come back from the dead") | 2262 // "come back from the dead") |
| 2268 // -An extension gets manually updated to v3 while we're downloading v2 (ie | 2263 // -An extension gets manually updated to v3 while we're downloading v2 (ie |
| 2269 // you don't get downgraded accidentally) | 2264 // you don't get downgraded accidentally) |
| 2270 // -An update manifest mentions multiple updates | 2265 // -An update manifest mentions multiple updates |
| 2271 | 2266 |
| 2272 } // namespace extensions | 2267 } // namespace extensions |
| OLD | NEW |