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 793 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
804 fetch_data->AddExtension(id, version, &kNeverPingedData, "a=1&b=2&c", | 804 fetch_data->AddExtension(id, version, &kNeverPingedData, "a=1&b=2&c", |
805 std::string(), | 805 std::string(), |
806 ManifestFetchData::FetchPriority::BACKGROUND); | 806 ManifestFetchData::FetchPriority::BACKGROUND); |
807 std::map<std::string, std::string> params; | 807 std::map<std::string, std::string> params; |
808 VerifyQueryAndExtractParameters(fetch_data->full_url().query(), ¶ms); | 808 VerifyQueryAndExtractParameters(fetch_data->full_url().query(), ¶ms); |
809 EXPECT_EQ(id, params["id"]); | 809 EXPECT_EQ(id, params["id"]); |
810 EXPECT_EQ(version, params["v"]); | 810 EXPECT_EQ(version, params["v"]); |
811 EXPECT_EQ("a%3D1%26b%3D2%26c", params["ap"]); | 811 EXPECT_EQ("a%3D1%26b%3D2%26c", params["ap"]); |
812 } | 812 } |
813 | 813 |
814 void TestUpdateUrlDataFromGallery( | 814 void TestUpdateUrlDataFromUrl( |
815 const std::string& gallery_url, | 815 const std::string& update_url, |
816 ManifestFetchData::FetchPriority fetch_priority, | 816 ManifestFetchData::FetchPriority fetch_priority, |
817 int num_extensions) { | 817 int num_extensions, |
| 818 bool should_include_traffic_management_headers) { |
818 net::TestURLFetcherFactory factory; | 819 net::TestURLFetcherFactory factory; |
819 | 820 |
820 MockService service(prefs_.get()); | 821 MockService service(prefs_.get()); |
821 MockExtensionDownloaderDelegate delegate; | 822 MockExtensionDownloaderDelegate delegate; |
822 ExtensionDownloader downloader(&delegate, service.request_context()); | 823 ExtensionDownloader downloader(&delegate, service.request_context()); |
823 ExtensionList extensions; | 824 ExtensionList extensions; |
824 std::string url(gallery_url); | |
825 | 825 |
826 service.CreateTestExtensions(1, num_extensions, &extensions, &url, | 826 service.CreateTestExtensions(1, num_extensions, &extensions, &update_url, |
827 Manifest::INTERNAL); | 827 Manifest::INTERNAL); |
828 | 828 |
829 for (int i = 0; i < num_extensions; ++i) { | 829 for (int i = 0; i < num_extensions; ++i) { |
830 const std::string& id = extensions[i]->id(); | 830 const std::string& id = extensions[i]->id(); |
831 EXPECT_CALL(delegate, GetPingDataForExtension(id, _)); | 831 EXPECT_CALL(delegate, GetPingDataForExtension(id, _)); |
832 | 832 |
833 downloader.AddExtension(*extensions[i], 0, fetch_priority); | 833 downloader.AddExtension(*extensions[i], 0, fetch_priority); |
834 } | 834 } |
835 | 835 |
836 downloader.StartAllPending(NULL); | 836 downloader.StartAllPending(NULL); |
837 net::TestURLFetcher* fetcher = | 837 net::TestURLFetcher* fetcher = |
838 factory.GetFetcherByID(ExtensionDownloader::kManifestFetcherId); | 838 factory.GetFetcherByID(ExtensionDownloader::kManifestFetcherId); |
839 ASSERT_TRUE(fetcher); | 839 ASSERT_TRUE(fetcher); |
840 // Make sure that extensions that update from the gallery ignore any | 840 // Make sure that extensions that update from the gallery ignore any |
841 // update URL data. | 841 // update URL data. |
842 const std::string& update_url = fetcher->GetOriginalURL().spec(); | 842 const std::string& fetcher_url = fetcher->GetOriginalURL().spec(); |
843 std::string::size_type x = update_url.find("x="); | 843 std::string::size_type x = fetcher_url.find("x="); |
844 EXPECT_NE(std::string::npos, x); | 844 EXPECT_NE(std::string::npos, x); |
845 std::string::size_type ap = update_url.find("ap%3D", x); | 845 std::string::size_type ap = fetcher_url.find("ap%3D", x); |
846 EXPECT_EQ(std::string::npos, ap); | 846 EXPECT_EQ(std::string::npos, ap); |
847 | 847 |
848 net::HttpRequestHeaders fetch_headers; | 848 net::HttpRequestHeaders fetch_headers; |
849 fetcher->GetExtraRequestHeaders(&fetch_headers); | 849 fetcher->GetExtraRequestHeaders(&fetch_headers); |
850 EXPECT_TRUE(fetch_headers.HasHeader( | 850 EXPECT_EQ(should_include_traffic_management_headers, |
851 ExtensionDownloader::kUpdateInteractivityHeader)); | 851 fetch_headers.HasHeader( |
852 EXPECT_TRUE( | 852 ExtensionDownloader::kUpdateInteractivityHeader)); |
853 fetch_headers.HasHeader(ExtensionDownloader::kUpdateAppIdHeader)); | 853 EXPECT_EQ(should_include_traffic_management_headers, |
854 EXPECT_TRUE( | 854 fetch_headers.HasHeader(ExtensionDownloader::kUpdateAppIdHeader)); |
| 855 EXPECT_EQ( |
| 856 should_include_traffic_management_headers, |
855 fetch_headers.HasHeader(ExtensionDownloader::kUpdateUpdaterHeader)); | 857 fetch_headers.HasHeader(ExtensionDownloader::kUpdateUpdaterHeader)); |
856 | 858 |
857 std::string interactivity_value; | 859 if (should_include_traffic_management_headers) { |
858 fetch_headers.GetHeader(ExtensionDownloader::kUpdateInteractivityHeader, | 860 std::string interactivity_value; |
859 &interactivity_value); | 861 fetch_headers.GetHeader(ExtensionDownloader::kUpdateInteractivityHeader, |
| 862 &interactivity_value); |
860 | 863 |
861 std::string expected_interactivity_value = | 864 std::string expected_interactivity_value = |
862 fetch_priority == ManifestFetchData::FetchPriority::FOREGROUND ? "fg" | 865 fetch_priority == ManifestFetchData::FetchPriority::FOREGROUND ? "fg" |
863 : "bg"; | 866 : "bg"; |
864 EXPECT_EQ(expected_interactivity_value, interactivity_value); | 867 EXPECT_EQ(expected_interactivity_value, interactivity_value); |
865 | 868 |
866 std::string appid_value; | 869 std::string appid_value; |
867 fetch_headers.GetHeader(ExtensionDownloader::kUpdateAppIdHeader, | 870 fetch_headers.GetHeader(ExtensionDownloader::kUpdateAppIdHeader, |
868 &appid_value); | 871 &appid_value); |
869 if (num_extensions > 1) { | 872 if (num_extensions > 1) { |
870 for (int i = 0; i < num_extensions; ++i) { | 873 for (int i = 0; i < num_extensions; ++i) { |
871 EXPECT_TRUE( | 874 EXPECT_TRUE( |
872 testing::IsSubstring("", "", extensions[i]->id(), appid_value)); | 875 testing::IsSubstring("", "", extensions[i]->id(), appid_value)); |
| 876 } |
| 877 } else { |
| 878 EXPECT_EQ(extensions[0]->id(), appid_value); |
873 } | 879 } |
874 } else { | 880 |
875 EXPECT_EQ(extensions[0]->id(), appid_value); | 881 std::string updater_value; |
| 882 fetch_headers.GetHeader(ExtensionDownloader::kUpdateUpdaterHeader, |
| 883 &updater_value); |
| 884 const std::string expected_updater_value = base::StringPrintf( |
| 885 "%s-%s", UpdateQueryParams::GetProdIdString(UpdateQueryParams::CRX), |
| 886 UpdateQueryParams::GetProdVersion().c_str()); |
| 887 EXPECT_EQ(expected_updater_value, updater_value); |
876 } | 888 } |
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); | |
885 } | 889 } |
886 | 890 |
887 void TestInstallSource() { | 891 void TestInstallSource() { |
888 const std::string id = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"; | 892 const std::string id = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"; |
889 const std::string version = "1.0"; | 893 const std::string version = "1.0"; |
890 const std::string install_source = "instally"; | 894 const std::string install_source = "instally"; |
891 | 895 |
892 // Make sure that an installsource= appears in the x= parameter. | 896 // Make sure that an installsource= appears in the x= parameter. |
893 std::unique_ptr<ManifestFetchData> fetch_data( | 897 std::unique_ptr<ManifestFetchData> fetch_data( |
894 CreateManifestFetchData(GURL("http://localhost/foo"))); | 898 CreateManifestFetchData(GURL("http://localhost/foo"))); |
(...skipping 1115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2010 } | 2014 } |
2011 | 2015 |
2012 TEST_F(ExtensionUpdaterTest, TestExtensionUpdateCheckRequestsPending) { | 2016 TEST_F(ExtensionUpdaterTest, TestExtensionUpdateCheckRequestsPending) { |
2013 TestExtensionUpdateCheckRequests(true); | 2017 TestExtensionUpdateCheckRequests(true); |
2014 } | 2018 } |
2015 | 2019 |
2016 TEST_F(ExtensionUpdaterTest, TestUpdateUrlData) { | 2020 TEST_F(ExtensionUpdaterTest, TestUpdateUrlData) { |
2017 TestUpdateUrlDataEmpty(); | 2021 TestUpdateUrlDataEmpty(); |
2018 TestUpdateUrlDataSimple(); | 2022 TestUpdateUrlDataSimple(); |
2019 TestUpdateUrlDataCompound(); | 2023 TestUpdateUrlDataCompound(); |
2020 TestUpdateUrlDataFromGallery(extension_urls::GetWebstoreUpdateUrl().spec(), | 2024 std::string gallery_url_spec = extension_urls::GetWebstoreUpdateUrl().spec(); |
2021 ManifestFetchData::FetchPriority::BACKGROUND, 1); | 2025 TestUpdateUrlDataFromUrl( |
2022 TestUpdateUrlDataFromGallery(extension_urls::GetWebstoreUpdateUrl().spec(), | 2026 gallery_url_spec, ManifestFetchData::FetchPriority::BACKGROUND, 1, true); |
2023 ManifestFetchData::FetchPriority::FOREGROUND, 1); | 2027 TestUpdateUrlDataFromUrl( |
2024 TestUpdateUrlDataFromGallery(extension_urls::GetWebstoreUpdateUrl().spec(), | 2028 gallery_url_spec, ManifestFetchData::FetchPriority::FOREGROUND, 1, true); |
2025 ManifestFetchData::FetchPriority::BACKGROUND, 2); | 2029 TestUpdateUrlDataFromUrl( |
2026 TestUpdateUrlDataFromGallery(extension_urls::GetWebstoreUpdateUrl().spec(), | 2030 gallery_url_spec, ManifestFetchData::FetchPriority::BACKGROUND, 2, true); |
2027 ManifestFetchData::FetchPriority::FOREGROUND, 4); | 2031 TestUpdateUrlDataFromUrl( |
| 2032 gallery_url_spec, ManifestFetchData::FetchPriority::FOREGROUND, 4, true); |
| 2033 TestUpdateUrlDataFromUrl("http://example.com/update", |
| 2034 ManifestFetchData::FetchPriority::FOREGROUND, 4, |
| 2035 false); |
2028 } | 2036 } |
2029 | 2037 |
2030 TEST_F(ExtensionUpdaterTest, TestInstallSource) { | 2038 TEST_F(ExtensionUpdaterTest, TestInstallSource) { |
2031 TestInstallSource(); | 2039 TestInstallSource(); |
2032 } | 2040 } |
2033 | 2041 |
2034 TEST_F(ExtensionUpdaterTest, TestDetermineUpdates) { | 2042 TEST_F(ExtensionUpdaterTest, TestDetermineUpdates) { |
2035 TestDetermineUpdates(); | 2043 TestDetermineUpdates(); |
2036 } | 2044 } |
2037 | 2045 |
(...skipping 381 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2419 // -prodversionmin (shouldn't update if browser version too old) | 2427 // -prodversionmin (shouldn't update if browser version too old) |
2420 // -manifests & updates arriving out of order / interleaved | 2428 // -manifests & updates arriving out of order / interleaved |
2421 // -malformed update url (empty, file://, has query, has a # fragment, etc.) | 2429 // -malformed update url (empty, file://, has query, has a # fragment, etc.) |
2422 // -An extension gets uninstalled while updates are in progress (so it doesn't | 2430 // -An extension gets uninstalled while updates are in progress (so it doesn't |
2423 // "come back from the dead") | 2431 // "come back from the dead") |
2424 // -An extension gets manually updated to v3 while we're downloading v2 (ie | 2432 // -An extension gets manually updated to v3 while we're downloading v2 (ie |
2425 // you don't get downgraded accidentally) | 2433 // you don't get downgraded accidentally) |
2426 // -An update manifest mentions multiple updates | 2434 // -An update manifest mentions multiple updates |
2427 | 2435 |
2428 } // namespace extensions | 2436 } // namespace extensions |
OLD | NEW |