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